ARB
ed4_search.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ed4_search.hxx //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #ifndef ED4_SEARCH_HXX
13 #define ED4_SEARCH_HXX
14 
18 };
19 
23 };
24 
28 };
29 
30 // --------------------------------------------------------------------------------
31 
32 #define MAX_MISMATCHES 5
33 
44  SEARCH_PATTERNS, // counter
46 };
47 
48 extern const char *ED4_SearchPositionTypeId[];
49 
51  e4_assert(direction==-1 || direction==1);
52  e4_assert(pattern>=0 && pattern<(SEARCH_PATTERNS+1));
53  return (direction==1) + pattern*2;
54 }
55 
56 // #define TEST_SEARCH_POSITION
57 
58 
59 
61  // one found position
62  int start_pos, end_pos;
63  int mismatch[MAX_MISMATCHES]; // contains positions of mismatches (or -1)
64  ED4_SearchPositionType whatsFound;
65  GB_CSTR comment;
66  ED4_SearchPosition *next;
67 
68  static char *lastShownComment;
69 
70  int cmp(const ED4_SearchPosition& sp2) const {
71  int c = start_pos - sp2.get_start_pos();
72  if (!c) c = end_pos - sp2.get_end_pos();
73  return c;
74  }
75 
76 public:
77 
78  ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES]);
79  ~ED4_SearchPosition() { delete next; }
80 
81  ED4_SearchPosition(const ED4_SearchPosition& other); // copy-ctor ('next' is always zero)
83 
85  ED4_SearchPosition *remove(ED4_SearchPositionType typeToRemove);
86 
87  ED4_SearchPosition *get_next() const { return next; }
88  int get_start_pos() const { return start_pos; }
89  int get_end_pos() const { return end_pos; }
90  ED4_SearchPositionType get_whatsFound() const { return whatsFound; }
91  GB_CSTR get_comment() const;
92 
93  const int *getMismatches() const { return mismatch; }
94 
95  int containsPos(int pos) const { return start_pos<=pos && end_pos>=pos; }
96 
97  ED4_SearchPosition *get_next_at(int pos) const;
98 
99 #ifdef TEST_SEARCH_POSITION
100  int ok() const;
101 #endif
102 };
103 
105 
107  // list head
108 
109  int arraySize; // ==0 -> 'first' is a list
110  // >0 -> 'array' is an array of 'ED4_SearchPosition*' with 'arraySize' elements
111 
112  ED4_SearchPosition *first; // ==0 -> no results, this list is sorted by start_pos, end_pos
113  ED4_SearchPosition **array; // ==0 -> no results, same sorting as 'first'
114  int timeOf[SEARCH_PATTERNS];
115 
116  static int timeOfLastSearch[SEARCH_PATTERNS]; // timestamp used at last search
117  static int timeOfNextSearch[SEARCH_PATTERNS]; // timestamp used at next search
118  static int shown[SEARCH_PATTERNS]; // copy of ED4_AWAR_xxx_SEARCH_SHOW
119  static int bufferSize;
120  static char *buffer; // buffer for buildColorString
121  static int initialized;
122 
123  int is_list() const { return arraySize==0; }
124  int is_array() const { return arraySize>0; }
125 
126  void to_array(); // ensures that result is in array-format (used to improve search performance)
127  void to_list(); // ensures that result is in list-format (used to improve insert performance)
128 
129 public:
130 
133 
134  void search(const ED4_sequence_terminal *seq_terminal);
136 
137  ED4_SearchPosition *get_first() const { return first; }
141  ED4_SearchPosition *get_shown_at(int pos) const;
142 
144  void searchAgain();
145 
146  char *buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end);
147 };
148 
149 // global functions
150 
151 class ED4_window;
152 void ED4_search_cb(UNFIXED, int searchDescriptor, ED4_window *ed4w);
153 
156 
157 void ED4_create_search_awars(AW_root *root);
158 
159 #else
160 #error ed4_search.hxx included twice
161 #endif // ED4_SEARCH_HXX
162 
const char * GB_ERROR
Definition: arb_core.h:25
GB_TYPES type
ED4_SearchPosition * get_next() const
Definition: ed4_search.hxx:87
static void setNewSearch(ED4_SearchPositionType type)
int get_end_pos() const
Definition: ed4_search.hxx:89
GB_CSTR get_comment() const
Definition: ED4_search.cxx:856
ED4_SearchPosition * get_first_at(ED4_SearchPositionType type, int start, int end) const
Definition: ED4_search.cxx:990
ED4_SEARCH_TU
Definition: ed4_search.hxx:20
const int * getMismatches() const
Definition: ed4_search.hxx:93
#define e4_assert(bed)
Definition: ed4_class.hxx:14
struct Unfixed_cb_parameter * UNFIXED
Definition: cb_base.h:15
static HelixNrInfo * start
int containsPos(int pos) const
Definition: ed4_search.hxx:95
ED4_SearchPosition * get_first() const
Definition: ed4_search.hxx:137
ED4_SearchPosition * insert(ED4_SearchPosition *toAdd)
Definition: ED4_search.cxx:793
ED4_SEARCH_GAPS
Definition: ed4_search.hxx:25
DECLARE_ASSIGNMENT_OPERATOR(ED4_SearchPosition)
ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES])
Definition: ED4_search.cxx:775
ED4_SearchPositionType get_whatsFound() const
Definition: ed4_search.hxx:90
ED4_SearchPosition * get_first_starting_after(ED4_SearchPositionType type, int pos, int mustBeShown) const
char * buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end)
void addSearchPosition(ED4_SearchPosition *pos)
Definition: ED4_search.cxx:927
ED4_SEARCH_CASE
Definition: ed4_search.hxx:15
int get_start_pos() const
Definition: ed4_search.hxx:88
const char * ED4_SearchPositionTypeId[]
Definition: ED4_search.cxx:35
void search(const ED4_sequence_terminal *seq_terminal)
Definition: ED4_search.cxx:943
#define MAX_MISMATCHES
Definition: ed4_search.hxx:32
ED4_SearchPosition * get_shown_at(int pos) const
int ED4_encodeSearchDescriptor(int direction, ED4_SearchPositionType pattern)
Definition: ed4_search.hxx:50
ED4_SearchPosition * get_last_starting_before(ED4_SearchPositionType type, int pos, int mustBeShown) const
static int pattern[maxsites+1]
void ED4_search_cb(UNFIXED, int searchDescriptor, ED4_window *ed4w)
AW_window_menu_modes * aww
Definition: ed4_class.hxx:705
ED4_SearchPositionType
Definition: ed4_search.hxx:34
void ED4_popup_search_window(AW_window *aww, ED4_SearchPositionType type)
GB_ERROR ED4_repeat_last_search(class ED4_window *ed4w)
void ED4_create_search_awars(AW_root *root)
Definition: ED4_search.cxx:735
const char * GB_CSTR
Definition: arbdb_base.h:25
ED4_SearchPosition * get_next_at(int pos) const
Definition: ED4_search.cxx:865