Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
MarkerBuilder.h
1 /*
2  * stree::MarkerBuilder class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2013, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_STREE_MARKERBUILDER_H_
22 #define ELM_STREE_MARKERBUILDER_H_
23 
24 #include <elm/stree/Builder.h>
25 #include <elm/avl/Map.h>
26 
27 namespace elm { namespace stree {
28 
29 template <class K, class T, class C = Comparator<K> >
30 class MarkerBuilder: public Builder<K, T, C> {
31  typedef typename Builder<K, T, C>::node_t node_t;
32 public:
33 
34  void add(const K& mark, const T& val) {
35  marks.put(mark, val);
36  }
37 
38  void make(stree::Tree<K, T, C>& tree) {
39 
40  // allocate the memory
41  node_t *nodes = Builder<K, T, C>::allocate(marks.count());
42 
43  // insert the bounds
44  int i = 0;
45  auto iter = marks.pairs().begin();
46  Pair<K, T> l = *iter;
47  for(iter++; iter(); iter++) {
48  Pair<K, T> u = *iter;
49  nodes[i] = node_t(l.fst, u.fst);
50  nodes[i++].data = l.snd;
51  l = u;
52  }
53 
54  // build the tree
55  int root = Builder<K, T, C>::make(nodes, i, 0, i - 1);
56 
57  // perform the transfer
58  tree.set(root, nodes);
59  }
60 
61 private:
62  avl::Map<K, T, C> marks;
63 };
64 
65 } } // elm::stree
66 
67 #endif /* ELM_STREE_MARKERBUILDER_H_ */
elm::stree::MarkerBuilder::make
void make(stree::Tree< K, T, C > &tree)
Definition: MarkerBuilder.h:38
elm::avl::Map
Definition: Map.h:33
elm::iter
Definition: util_WAHVector.cpp:157
elm::iter
void iter(const C &c, const F &f)
Definition: util.h:95
elm::Pair::snd
T2 snd
Definition: Pair.h:36
elm::stree::Builder
Definition: Builder.h:29
elm::stree::Tree::set
void set(int _root, node_t *_nodes)
Definition: Tree.h:53
elm::Pair< K, T >
elm::stree::Builder::allocate
node_t * allocate(t::uint32 n)
Definition: Builder.h:33
elm
Definition: adapter.h:26
elm::stree::MarkerBuilder::add
void add(const K &mark, const T &val)
Definition: MarkerBuilder.h:34
elm::stree::Tree
Definition: Tree.h:31
elm::stree::MarkerBuilder
Definition: MarkerBuilder.h:30
elm::stree::Tree::node_t
Definition: Tree.h:35
elm::stree::Builder::make
int make(node_t *nodes, int &s, int start, int end)
Definition: Builder.h:38
elm::stree::Tree::node_t::data
T data
Definition: Tree.h:48
elm::Pair::fst
T1 fst
Definition: Pair.h:35