source: tags/cvs_2_svn/EDIT4/ed4_search.hxx

Last change on this file was 4843, checked in by westram, 17 years ago
  • const fixes
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : ed4_search.hxx                                    //
4//   Purpose   :                                                   //
5//   Time-stamp: <Sat Sep/01/2007 10:00 MET Coder@ReallySoft.de>   //
6//                                                                 //
7//   Coded by Ralf Westram (coder@reallysoft.de)                   //
8//   Institute of Microbiology (Technical University Munich)       //
9//   http://www.arb-home.de/                                       //
10//                                                                 //
11// =============================================================== //
12
13#ifndef ED4_SEARCH_HXX
14#define ED4_SEARCH_HXX
15
16typedef enum {
17    ED4_SC_CASE_SENSITIVE,
18    ED4_SC_CASE_INSENSITIVE
19} ED4_SEARCH_CASE;
20
21typedef enum {
22    ED4_ST_T_NOT_EQUAL_U,
23    ED4_ST_T_EQUAL_U
24} ED4_SEARCH_TU;
25
26typedef enum {
27    ED4_SG_CONSIDER_GAPS,
28    ED4_SG_IGNORE_GAPS
29} ED4_SEARCH_GAPS;
30
31void       ED4_search(AW_window *aww, AW_CL searchDescriptor);
32GB_ERROR   ED4_repeat_last_search(void);
33AW_window *ED4_create_search_window(AW_root *root, AW_CL type);
34void       ED4_create_search_awars(AW_root *root);
35
36// --------------------------------------------------------------------------------
37
38#define SEARCH_PATTERNS 9
39#define MAX_MISMATCHES  5
40
41typedef enum
42    {
43    ED4_USER1_PATTERN,
44    ED4_USER2_PATTERN,
45    ED4_PROBE_PATTERN,
46    ED4_PRIMER1_PATTERN,
47    ED4_PRIMER2_PATTERN,
48    ED4_PRIMER3_PATTERN,
49    ED4_SIG1_PATTERN,
50    ED4_SIG2_PATTERN,
51    ED4_SIG3_PATTERN,
52    ED4_ANY_PATTERN
53
54} ED4_SearchPositionType;
55
56extern const char *ED4_SearchPositionTypeId[];
57
58inline int ED4_encodeSearchDescriptor(int direction, ED4_SearchPositionType pattern)
59{
60    e4_assert(direction==-1 || direction==1);
61    e4_assert(pattern>=0 && pattern<(SEARCH_PATTERNS+1));
62    return (direction==1) + pattern*2;
63}
64
65// #define TEST_SEARCH_POSITION
66
67
68
69class ED4_SearchPosition // one found position
70{
71    int start_pos, end_pos;
72    int mismatch[MAX_MISMATCHES]; // contains positions of mismatches (or -1)
73    ED4_SearchPositionType whatsFound;
74    GB_CSTR comment;
75    ED4_SearchPosition *next;
76
77    static char *lastShownComment;
78
79    int cmp(const ED4_SearchPosition& sp2) const
80    {
81        int c = start_pos - sp2.get_start_pos();
82        if (!c) c = end_pos - sp2.get_end_pos();
83        return c;
84    }
85
86public:
87
88    ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES]);
89    ~ED4_SearchPosition() { delete next; }
90
91    ED4_SearchPosition(const ED4_SearchPosition& other); // copy-ctor ('next' is always zero)
92
93    ED4_SearchPosition *insert(ED4_SearchPosition *toAdd);
94    ED4_SearchPosition *remove(ED4_SearchPositionType typeToRemove);
95
96    ED4_SearchPosition *get_next() const          { return next; }
97    int get_start_pos() const                     { return start_pos; }
98    int get_end_pos() const                       { return end_pos; }
99    ED4_SearchPositionType get_whatsFound() const { return whatsFound; }
100    GB_CSTR get_comment() const;
101
102    const int *getMismatches() const              { return mismatch; }
103
104    int containsPos(int pos) const { return start_pos<=pos && end_pos>=pos; }
105
106    ED4_SearchPosition *get_next_at(int pos) const;
107
108#ifdef TEST_SEARCH_POSITION
109    int ok() const;
110#endif
111};
112
113class ED4_sequence_terminal;
114
115class ED4_SearchResults // list head
116{
117    int arraySize;              // ==0 -> 'first' is a list
118    // >0 -> 'array' is an array of 'ED4_SearchPosition*' with 'arraySize' elements
119
120    ED4_SearchPosition *first;  // ==0 -> no results, this list is sorted by start_pos, end_pos
121    ED4_SearchPosition **array; // ==0 -> no results, same sorting as 'first'
122    int timeOf[SEARCH_PATTERNS];
123
124    static int timeOfLastSearch[SEARCH_PATTERNS]; // timestamp used at last search
125    static int timeOfNextSearch[SEARCH_PATTERNS]; // timestamp used at next search
126    static int shown[SEARCH_PATTERNS]; // copy of ED4_AWAR_xxx_SEARCH_SHOW
127    static int bufferSize;
128    static char *buffer; // buffer for buildColorString
129    static int initialized;
130
131    ED4_SearchResults(const ED4_SearchResults&) { e4_assert(0); }
132
133    int is_list() const { return arraySize==0; }
134    int is_array() const { return arraySize>0; }
135
136    void to_array() const;      // ensures that result is in array-format (used to improve search performance)
137    void to_list() const;       // ensures that result is in list-format (used to improve insert performance)
138
139public:
140
141    ED4_SearchResults();
142    ~ED4_SearchResults();
143
144    void search(const ED4_sequence_terminal *seq_terminal);
145    void addSearchPosition(ED4_SearchPosition *pos);
146
147    ED4_SearchPosition *get_first() const { return first; }
148    ED4_SearchPosition *get_first_at(ED4_SearchPositionType type, int start, int end) const;
149    ED4_SearchPosition *get_first_starting_after(ED4_SearchPositionType type, int pos, int mustBeShown) const;
150    ED4_SearchPosition *get_last_starting_before(ED4_SearchPositionType type, int pos, int mustBeShown) const;
151    ED4_SearchPosition *get_shown_at(int pos) const;
152
153    static void setNewSearch(ED4_SearchPositionType type);
154    void searchAgain();
155
156    char *buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end);
157};
158
159
160#else
161#error ed4_search.hxx included twice
162#endif // ED4_SEARCH_HXX
163
Note: See TracBrowser for help on using the repository browser.