Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ne_map.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ne_map.h
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // ne_map.h - common implementation of node_map and edge_map
5 //
6 //==========================================================================
7 // $Id: ne_map.h,v 1.20 2005/06/14 12:22:12 raitner Exp $
8 
9 #ifndef GTL_NE_MAP_H
10 #define GTL_NE_MAP_H
11 
12 #include <GTL/GTL.h>
13 
14 #include <vector>
15 #include <cassert>
16 
17 //--------------------------------------------------------------------------
18 // Class declaration
19 //--------------------------------------------------------------------------
20 
22 
30 template <class Key, class Value, class Graph, class Alloc = allocator<Value> >
31 class ne_map
32 {
33 protected:
34 
35  //================================================== Constructors
36 
41  ne_map();
42 
54  explicit ne_map(const Graph &g, Value def=Value());
55 
56  //================================================== Operations
57 
58 public:
59 
67  void init(const Graph &, Value def=Value());
68 
72 #if defined(__GTL_MSVCC) && _MSC_VER < 1310
73  typedef Value& value_reference;
74 #else
75  typedef typename vector<Value, Alloc>::reference value_reference;
76 #endif
77 
81 #if defined(__GTL_MSVCC) && _MSC_VER < 1310
82  typedef const Value& const_value_reference;
83 #else
84  typedef typename vector<Value, Alloc>::const_reference const_value_reference;
85 #endif
86 
105 
122 
126  void clear ();
127 
128  //================================================== Implementation
129 
130 private:
131  vector<Value, Alloc> data;
132 };
133 
134 // Implementation Begin
135 
136 template <class Key, class Value, class Graph, class Alloc>
138 {
139 }
140 
141 template <class Key, class Value, class Graph, class Alloc>
143  data(g.number_of_ids(Key()), t2)
144 {
145 }
146 
147 template <class Key, class Value, class Graph, class Alloc>
149 {
150  int n = g.number_of_ids(Key());
151  data.resize(n);
152  fill_n(data.begin(), n, t2);
153 }
154 
155 template <class Key, class Value, class Graph, class Alloc>
157 {
158  if(t1.id() >= (signed)data.size())
159  {
160  if (t1.id() >= (signed)data.capacity()) {
161  data.reserve((6 * t1.id()) / 5 + 1);
162  }
163 
164  data.insert(data.end(), t1.id()+1-data.size(), Value());
165  }
166  return data.operator[](t1.id());
167 }
168 
169 template <class Key, class Value, class Graph, class Alloc>
171 {
172  assert(t1.id() < (signed)data.size());
173  return data.operator[](t1.id());
174 }
175 
176 template <class Key, class Value, class Graph, class Alloc>
178 {
179  data.clear();
180 }
181 
182 // Implementation End
183 
185 
186 #endif // GTL_NE_MAP_H
187 
188 //--------------------------------------------------------------------------
189 // end of file
190 //--------------------------------------------------------------------------