root/trunk/EDIT4/ed4_search.hxx

Revision 8619, 5.5 KB (checked in by westram, 5 weeks ago)

merge from e4fix [8239] [8275] [8276] [8277] [8286] [8288] [8289] [8290] [8293] [8295] [8296] [8298] [8299]

  • define window-contexts by instanciating context-objects
    • ED4_LocalWinContext (used where calls are triggered via a window)
    • ED4_MostRecentWinContext (uses "last used window"; used when window is not known)
    • dump backtrace on missing context
  • window-context changes
    • ED4_search_cb (ensure search is performed in correct window)
    • ED4_set_iupac
  • fixed ED4_compression_changed_cb (now updates all windows when compression changes)
  • made several functions context independent
    • ED4_calc_terminal_extentions uses any device (that of first window)
    • ED4_expose_recalculations no longer does update_scrolled_rectangle (now performed by caller; caller knows the context)
  • added special class ED4_WinContextFree (denies access to global context for derived classes)
  • each cursor remembers the window where its located
  • declared ED4_window and ED4_cursor as ED4_WinContextFree (the window is their explicit context)
    • replaced invalid references to global context by uses of explicit context (get_device() + window())


  • cleaned ED4-object-deletion (what a mess)
    • rewrote ED4_terminal::kill_object using Delete()
    • regenerate group-ids during refresh (after deletion took place)
    • DRYed delete mechanisms
    • announce_deletion down to ED4_base_position (to invalidate its cache)
  • 'Get' selected species failed to
    • update bases-tables of parent-managers (that was one cause for folding errors!)
    • regenerate group-ids
  • syncronize mode in all edit windows
  • use position/size from awars when creating a 2nd window with identical ID
  • removed some useless virtualization
  • denglish (actual->current)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
15enum ED4_SEARCH_CASE {
16    ED4_SC_CASE_SENSITIVE,
17    ED4_SC_CASE_INSENSITIVE
18};
19
20enum ED4_SEARCH_TU {
21    ED4_ST_T_NOT_EQUAL_U,
22    ED4_ST_T_EQUAL_U
23};
24
25enum ED4_SEARCH_GAPS {
26    ED4_SG_CONSIDER_GAPS,
27    ED4_SG_IGNORE_GAPS
28};
29
30void ED4_search_cb(AW_window *aww, AW_CL searchDescriptor, AW_CL cl_ed4w);
31
32GB_ERROR ED4_repeat_last_search(class ED4_window *ed4w);
33AW_window *ED4_create_search_window(AW_root *root, AW_CL cl_type_and_ed4w);
34
35void ED4_create_search_awars(AW_root *root);
36
37// --------------------------------------------------------------------------------
38
39#define SEARCH_PATTERNS 9
40#define MAX_MISMATCHES  5
41
42enum ED4_SearchPositionType {
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
55struct ED4_search_type_and_ed4w {
56    ED4_SearchPositionType  type;
57    ED4_window             *ed4w;
58
59    ED4_search_type_and_ed4w(ED4_SearchPositionType type_, ED4_window *ed4w_)
60        : type(type_), ed4w(ed4w_) {}
61};
62
63extern const char *ED4_SearchPositionTypeId[];
64
65inline int ED4_encodeSearchDescriptor(int direction, ED4_SearchPositionType pattern)
66{
67    e4_assert(direction==-1 || direction==1);
68    e4_assert(pattern>=0 && pattern<(SEARCH_PATTERNS+1));
69    return (direction==1) + pattern*2;
70}
71
72// #define TEST_SEARCH_POSITION
73
74
75
76class ED4_SearchPosition {
77    // one found position
78    int start_pos, end_pos;
79    int mismatch[MAX_MISMATCHES]; // contains positions of mismatches (or -1)
80    ED4_SearchPositionType whatsFound;
81    GB_CSTR comment;
82    ED4_SearchPosition *next;
83
84    static char *lastShownComment;
85
86    int cmp(const ED4_SearchPosition& sp2) const
87    {
88        int c = start_pos - sp2.get_start_pos();
89        if (!c) c = end_pos - sp2.get_end_pos();
90        return c;
91    }
92
93public:
94
95    ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES]);
96    ~ED4_SearchPosition() { delete next; }
97
98    ED4_SearchPosition(const ED4_SearchPosition& other); // copy-ctor ('next' is always zero)
99    DECLARE_ASSIGNMENT_OPERATOR(ED4_SearchPosition);
100
101    ED4_SearchPosition *insert(ED4_SearchPosition *toAdd);
102    ED4_SearchPosition *remove(ED4_SearchPositionType typeToRemove);
103
104    ED4_SearchPosition *get_next() const          { return next; }
105    int get_start_pos() const                     { return start_pos; }
106    int get_end_pos() const                       { return end_pos; }
107    ED4_SearchPositionType get_whatsFound() const { return whatsFound; }
108    GB_CSTR get_comment() const;
109
110    const int *getMismatches() const              { return mismatch; }
111
112    int containsPos(int pos) const { return start_pos<=pos && end_pos>=pos; }
113
114    ED4_SearchPosition *get_next_at(int pos) const;
115
116#ifdef TEST_SEARCH_POSITION
117    int ok() const;
118#endif
119};
120
121class ED4_sequence_terminal;
122
123class ED4_SearchResults : virtual Noncopyable {
124    // list head
125
126    int arraySize;              // ==0 -> 'first' is a list
127    // >0 -> 'array' is an array of 'ED4_SearchPosition*' with 'arraySize' elements
128
129    ED4_SearchPosition *first;  // ==0 -> no results, this list is sorted by start_pos, end_pos
130    ED4_SearchPosition **array; // ==0 -> no results, same sorting as 'first'
131    int timeOf[SEARCH_PATTERNS];
132
133    static int timeOfLastSearch[SEARCH_PATTERNS]; // timestamp used at last search
134    static int timeOfNextSearch[SEARCH_PATTERNS]; // timestamp used at next search
135    static int shown[SEARCH_PATTERNS]; // copy of ED4_AWAR_xxx_SEARCH_SHOW
136    static int bufferSize;
137    static char *buffer; // buffer for buildColorString
138    static int initialized;
139
140    int is_list() const { return arraySize==0; }
141    int is_array() const { return arraySize>0; }
142
143    void to_array() const;      // ensures that result is in array-format (used to improve search performance)
144    void to_list() const;       // ensures that result is in list-format (used to improve insert performance)
145
146public:
147
148    ED4_SearchResults();
149    ~ED4_SearchResults();
150
151    void search(const ED4_sequence_terminal *seq_terminal);
152    void addSearchPosition(ED4_SearchPosition *pos);
153
154    ED4_SearchPosition *get_first() const { return first; }
155    ED4_SearchPosition *get_first_at(ED4_SearchPositionType type, int start, int end) const;
156    ED4_SearchPosition *get_first_starting_after(ED4_SearchPositionType type, int pos, int mustBeShown) const;
157    ED4_SearchPosition *get_last_starting_before(ED4_SearchPositionType type, int pos, int mustBeShown) const;
158    ED4_SearchPosition *get_shown_at(int pos) const;
159
160    static void setNewSearch(ED4_SearchPositionType type);
161    void searchAgain();
162
163    char *buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end);
164};
165
166
167#else
168#error ed4_search.hxx included twice
169#endif // ED4_SEARCH_HXX
Note: See TracBrowser for help on using the browser.