SheafSystem  0.0.0.0
record_map.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #ifndef RECORD_MAP_H
22 #define RECORD_MAP_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef POD_TYPES_H
29 #include "SheafSystem/pod_types.h"
30 #endif
31 
32 #ifndef STD_UNORDERED_MAP_H
33 #include "SheafSystem/std_unordered_map.h"
34 #endif
35 
36 #ifndef STD_STRING_H
37 #include "SheafSystem/std_string.h"
38 #endif
39 
40 namespace sheaf
41 {
42 
43 // Forward declarations to support friend declaration.
44 
45 template <typename T1, typename T2>
46 class record_map;
47 
51 //template <typename T1, typename T2>
52 //ostream& operator << (ostream &os, record_map<T1, T2>& p);
53 
62 template<typename internal_index_type, typename external_index_type>
63 class record_map
64 {
65  // ===========================================================
67  // ===========================================================
69 
70 public:
71 
75  record_map();
76 
80  record_map(const record_map& xother);
81 
85  record_map& operator=(const record_map& xother);
86 
90  virtual ~record_map();
91 
95  virtual bool invariant() const;
96 
100  external_index_type external_id(internal_index_type xinternal_id) const;
101 
105  internal_index_type internal_id(external_index_type xexternal_id) const;
106 
110  void put_ids(internal_index_type xinternal_id,
111  external_index_type xexternal_id);
112 
116  bool internal_ids_sequential() const;
117 
121  bool external_ids_sequential() const;
122 
128  external_index_type put_internal_id(internal_index_type xinternal_id);
129 
134  internal_index_type put_external_id(external_index_type xexternal_id);
135 
139  bool contains_internal_id(internal_index_type xint_id) const;
140 
144  bool contains_external_id(external_index_type xext_id) const;
145 
149  bool operator==(const record_map& xother) const;
150 
154  size_type ct() const;
155 
159  bool is_empty() const;
160 
164  void clear();
165 
169  void remove_internal_id(internal_index_type xinternal_id);
170 
174  void remove_external_id(external_index_type xexternal_id);
175 
182  internal_index_type scratch_internal_id() const;
183 
187  void put_scratch_internal_id(internal_index_type xid);
188 
195  external_index_type scratch_external_id() const;
196 
200  void put_scratch_external_id(external_index_type xid);
201 
205  internal_index_type internal_id_ub() const;
206 
210  external_index_type external_id_ub() const;
211 
218  bool ub_is_max() const;
219 
223  typedef typename
224  unordered::unordered_map<internal_index_type, external_index_type>::const_iterator const_iterator;
225 
229  const_iterator begin() const;
230 
234  const_iterator end() const;
235 
240  void print() const;
241 
246  void print(std::ostream& xos,
248 
249 protected:
250 
251 private:
252 
256  typedef unordered::unordered_map<internal_index_type, external_index_type> external_map_type;
257 
261  external_map_type _to_external;
262 
266  typedef unordered::unordered_map<external_index_type, internal_index_type> internal_map_type;
267 
271  internal_map_type _to_internal;
272 
276  bool _internal_ids_sequential;
277 
281  bool _external_ids_sequential;
282 
288  internal_index_type _scratch_internal_id;
289 
295  external_index_type _scratch_external_id;
296 
300  internal_index_type _internal_id_ub;
301 
305  external_index_type _external_id_ub;
306 
310  bool _entry_removed;
311 
315  void unguarded_put_ids(internal_index_type xinternal_id,
316  external_index_type xexternal_id);
317 
318 
320 };
321 
322 // ===========================================================
323 // NON-MEMBER FUNCTIONS
324 // ===========================================================
325 
326 template<typename internal_index_type, typename external_index_type>
327 std::ostream&
328 operator<<(std::ostream& xos, const record_map<internal_index_type, external_index_type>& xp);
329 
330 
331 } // namespace sheaf
332 
333 #endif // ifndef RECORD_MAP_H
internal_index_type internal_id(external_index_type xexternal_id) const
The internal id corresponding to xexternal_id.
external_index_type external_id(internal_index_type xinternal_id) const
The external id corresponding to xinternal_id.
void put_scratch_external_id(external_index_type xid)
Sets the value of the external id scratch register to xid.
bool operator==(const record_map &xother) const
True if same external_id and internal_id.
void put_scratch_internal_id(internal_index_type xid)
Sets the value of the internal id scratch register to xid.
bool is_empty() const
True if there are no entries in the map.
const_iterator end() const
The end of the range of internal ids contained in this.
bool contains_internal_id(internal_index_type xint_id) const
True if this map contains an entry for internal index xint_id.
record_map()
Default constructor.
external_index_type external_id_ub() const
The maximum external id in this map.
bool external_ids_sequential() const
True if sequentially assigning external ids.
size_type ct() const
The number of entries in the map.
internal_index_type internal_id_ub() const
The maximum internal id in this map.
const_iterator begin() const
The beginning of the range of internal ids contained in this.
internal_index_type scratch_internal_id() const
The value of the internal id scratch register. The scratch register is a convenient place for a clien...
bool ub_is_max() const
True if internal_id_ub and external_id_ub are in fact maxima; i.e. if there exists an entry (int_id...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void clear()
Removes all entries.
bool internal_ids_sequential() const
True if sequentially assigning internal ids.
void remove_internal_id(internal_index_type xinternal_id)
Removes xinternal_id and its external image from the map.
virtual bool invariant() const
The class invariant.
unordered::unordered_map< internal_index_type, external_index_type >::const_iterator const_iterator
The type of const iterator for this.
Definition: record_map.h:224
Namespace for the sheaves component of the sheaf system.
external_index_type scratch_external_id() const
The value of the external id scratch register. The scratch register is a convenient place for a clien...
void put_ids(internal_index_type xinternal_id, external_index_type xexternal_id)
Defines the mapping between xinternal_id and xexternal_id.
external_index_type put_internal_id(internal_index_type xinternal_id)
Defines a mapping between xinternal_id and a sequentially assigned external id. Returns the external ...
bool contains_external_id(external_index_type xext_id) const
True if this map contains an entry for external index xext_id.
Insert record_map& p into ostream& os.
Definition: record_map.h:46
void remove_external_id(external_index_type xexternal_id)
Removes xexternal_id and its internal image from the map.
virtual ~record_map()
Destructor.
internal_index_type put_external_id(external_index_type xexternal_id)
Defines a mapping between xexternal_id and a sequentially assigned internal id.
void print() const
Prints the data members of this on cout. Intended for use debugging.
record_map & operator=(const record_map &xother)
Assignment operator.