ARB
SEC_drawn_pos.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : SEC_drawn_pos.hxx //
4 // Purpose : store all drawn positions //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in August 2007 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #ifndef SEC_DRAWN_POS_HXX
13 #define SEC_DRAWN_POS_HXX
14 
15 #ifndef _GLIBCXX_MAP
16 #include <map>
17 #endif
18 #ifndef AW_POSITION_HXX
19 #include <aw_position.hxx>
20 #endif
21 
22 using namespace AW;
23 
24 typedef std::map<size_t, Position> PosMap;
25 
27  PosMap drawnAt;
28 
29 public:
30  void clear() { drawnAt.clear(); }
31  void announce(size_t abs, const Position& drawn) { drawnAt[abs] = drawn; }
32 
33  bool empty() const { return drawnAt.empty(); }
34  const PosMap::const_iterator begin() const { return drawnAt.begin(); }
35  const PosMap::const_iterator end() const { return drawnAt.end(); }
36 
37  const Position *drawn_at(size_t abs) const {
38  PosMap::const_iterator found = drawnAt.find(abs);
39  return (found == drawnAt.end()) ? NULp : &(found->second);
40  }
41 
42  const Position& drawn_before(size_t abspos, size_t *before_abs) const {
43  sec_assert(!empty());
44  PosMap::const_iterator found = drawnAt.lower_bound(abspos); // first pos which is >= abs
45 
46  if (found == drawnAt.end() || --found == drawnAt.end()) {
47  found = ++drawnAt.rbegin().base();
48  }
49 
50  if (before_abs) *before_abs = found->first;
51  return *&found->second;
52  }
53 
54  const Position& drawn_after(size_t abspos, size_t *after_abs) const {
55  sec_assert(!empty());
56  PosMap::const_iterator found = drawnAt.upper_bound(abspos); // first pos which is > abspos
57 
58  if (found == drawnAt.end()) { // no position drawn behind abs
59  found = drawnAt.begin(); // wrap to start
60  }
61 
62  if (after_abs) *after_abs = found->first;
63  return *&found->second;
64  }
65 
66  const Position& drawn_at_or_after(size_t abspos) const {
67  const Position *at = drawn_at(abspos);
68  return at ? *at : drawn_after(abspos, NULp);
69  }
70 
71 };
72 
73 
74 #else
75 #error SEC_drawn_pos.hxx included twice
76 #endif // SEC_DRAWN_POS_HXX
bool empty() const
const Position & drawn_before(size_t abspos, size_t *before_abs) const
const Position & drawn_at_or_after(size_t abspos) const
const PosMap::const_iterator end() const
const Position & drawn_after(size_t abspos, size_t *after_abs) const
void announce(size_t abs, const Position &drawn)
#define abs(x)
Definition: f2c.h:151
const Position * drawn_at(size_t abs) const
#define NULp
Definition: cxxforward.h:97
std::map< size_t, Position > PosMap
#define sec_assert(cond)
Definition: SEC_defs.hxx:19
const PosMap::const_iterator begin() const