ARB
ed4_edit_string.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ed4_edit_string.hxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #ifndef ED4_EDIT_STRING_HXX
12 #define ED4_EDIT_STRING_HXX
13 
14 #ifndef ED4_DEFS_HXX
15 #include "ed4_defs.hxx"
16 #endif
17 #ifndef CHARTABLE_H
18 #include <chartable.h>
19 #endif
20 
21 class ED4_remap;
22 
23 const char SEQ_POINT = '.';
24 
25 inline bool ED4_is_gap_character(char chr) { return BaseFrequencies::isGap(safeCharIndex(chr)); } // defined via user setting (ED4_AWAR_GAP_CHARS)
26 void ED4_setup_gaps_and_alitype(const char *gap_chars, GB_alignment_type alitype);
27 
28 struct ED4_work_info {
31  char *string; // pointer to consensus; only if editing the consensus
32  long char_position; // screen position after cursor
33 
34  bool rightward; // contains direction of editing (0 = leftward, 1 = rightward)
35 
37 
38  bool is_sequence; // ==1 -> special handling for sequences
39  bool cannot_handle; // if TRUE then cannot edit
40 
43 
44  long out_seq_position; // sequence position (after editing)
45 
46  char *out_string; // nur falls new malloc
47 
48  int repeat_count; // only for keystrokes: contains # of times key should be repeated
49 
50  ED4_terminal *working_terminal; // this contains the terminal
51 };
52 
53 class ED4_Edit_String : virtual Noncopyable {
54  GBDATA *gbd;
55 
56  char *seq;
57  long seq_len;
58 
59  char *old_seq;
60  long old_seq_len;
61 
62  ED4_remap *remap;
63 
64  static int nrepeat; // @@@ reimplement repeat mechanism? this is a bad hack :-(
65  static int nrepeat_is_already_set;
66  static int nrepeat_zero_requested;
67 
68  int legal_curpos(long pos) const { return pos>=0 && pos<=seq_len; }
69  int legal_seqpos(long pos) const { return pos>=0 && pos<seq_len; }
70 
71  GB_ERROR moveBase(long source_position, long dest_position, unsigned char gap_to_use); // moves a base from source_position to dest_position
72 
73  GB_ERROR shiftBases(long source_pos, long source_endpos, long dest_position,
74  int direction, long *dest_endpos, unsigned char gap_to_use); // shifts a line of bases from source_position to dest_position
75 
76  long get_next_base(long seq_position, int direction);
77  long get_next_gap(long seq_position, int direction);
78 
79  long get_next_visible_base(long position, int direction);
80  long get_next_visible_gap(long position, int direction);
81  long get_next_visible_pos(long position, int direction);
82 
83  GB_ERROR insert(char *, long position, int direction, int removeAtNextGap);
84  GB_ERROR remove(int len, long position, int direction, int insertAtNextGap);
85  GB_ERROR replace(char *text, long position, int direction);
86  GB_ERROR swap_gaps(long position, char ch);
87 
88  GB_ERROR command(AW_key_mod keymod, AW_key_code keycode, char key, int direction, ED4_EDITMODE mode, bool is_consensus,
89  long &cursorpos, bool& changed_flag, ED4_CursorJumpType& cursor_jump, bool& cannot_handle, bool& write_fault, GBDATA *gb_data, bool is_sequence);
90 
91  unsigned char get_gap_type(long pos, int direction);
92 
93 public:
94 
97  void finish_edit();
99 
100  int use_nrepeat() { // external functions use this to get and use nrepeat
101  int nrep = nrepeat==0 ? 1 : nrepeat;
102  nrepeat = 0;
103  return nrep;
104  }
105 };
106 
107 #else
108 #error ed4_edit_string.hxx included twice
109 #endif // ED4_EDIT_STRING_HXX
ED4_EDITMODE
Definition: ed4_defs.hxx:30
ED4_terminal * working_terminal
ED4_EDITMODE mode
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
Definition: dupstr.h:73
GB_ERROR edit(ED4_work_info *info) __ATTR__USERESULT
static bool isGap(char c)
Definition: chartable.h:248
GB_alignment_type
Definition: arbdb_base.h:61
ED4_CursorJumpType
Definition: ed4_defs.hxx:284
AW_key_code
Definition: aw_keysym.hxx:14
#define __ATTR__USERESULT
Definition: attributes.h:58
ED4_CursorJumpType cursor_jump
const char SEQ_POINT
bool ED4_is_gap_character(char chr)
AW_key_mod
Definition: aw_keysym.hxx:46
void ED4_setup_gaps_and_alitype(const char *gap_chars, GB_alignment_type alitype)
Definition: ED4_main.cxx:253
static int info[maxsites+1]