Free Electron
RecordMap.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __data_RecordMap_h__
8 #define __data_RecordMap_h__
9 
10 namespace fe
11 {
12 
13 
14 template <class T>
15 class RecordMap : public WatcherI
16 {
17  public:
18  typedef std::map<T, Record> t_T_record;
19 
20  RecordMap(const Accessor<T> aKey);
21 virtual ~RecordMap(void);
22 
23  //* as WatcherI
24  void add(const Record &record);
25  void remove(const Record &record);
26  void clear(void);
27 
28  Record lookup(const T &t);
29 
30  public:
31  std::map<T, Record> m_table;
32  Accessor<T> m_aKey;
33 };
34 
35 template <class T>
36 RecordMap<T>::RecordMap(const Accessor<T> aKey)
37 {
38  m_aKey = aKey;
39 }
40 
41 template <class T>
42 RecordMap<T>::~RecordMap(void)
43 {
44 }
45 
46 template <class T>
47 void RecordMap<T>::add(const Record &record)
48 {
49  if(m_aKey.check(record))
50  {
51  m_table[m_aKey(record)] = record;
52  }
53 }
54 
55 template <class T>
56 void RecordMap<T>::remove(const Record &record)
57 {
58  if(m_aKey.check(record))
59  {
60  typename t_T_record::iterator it = m_table.find(m_aKey(record));
61  if(it != m_table.end())
62  {
63  if(record == it->second)
64  {
65  m_table.erase(it);
66  }
67  }
68  }
69 }
70 
71 template <class T>
72 void RecordMap<T>::clear(void)
73 {
74  m_table.clear();
75 }
76 
77 template <class T>
78 Record RecordMap<T>::lookup(const T &t)
79 {
80  typename t_T_record::iterator it = m_table.find(t);
81  if(it == m_table.end())
82  {
83  Record invalid;
84  return invalid;
85  }
86  else
87  {
88  return it->second;
89  }
90 }
91 
92 } /* namespace */
93 
94 #endif /* __data_RecordMap_h__ */
95 
kernel
Definition: namespace.dox:3