Bitstream Interpretation Library (BIL)  0.1
V5Configuration.cpp
Go to the documentation of this file.
1 
6 #include <iterator>
7 #include <utility>
10 
11 using namespace bil;
12 
13 
15  m_addressLayout(),
16  m_configuration()
17 {
18 
19 }
20 
21 
23  m_addressLayout(layout),
24  m_configuration()
25 {
26 
27 }
28 
29 
31  m_addressLayout(src.m_addressLayout),
32  m_configuration()
33 {
34  // copy all map contents, but set addresses to this address layout
35  container_t::iterator itDst = m_configuration.begin();
36  container_t::const_iterator itSrc = src.m_configuration.begin();
37  const container_t::const_iterator itSrcEnd = src.m_configuration.end();
38  for (; itSrc != itSrcEnd; ++itSrc)
39  {
40  // make temporary copy of source address and set it to new layout
41  V5FrameAddress address = itSrc->first;
42  address.addressLayout(&m_addressLayout);
43  // insert it into destination map
44  itDst = m_configuration.insert(itDst, std::make_pair(address, itSrc->second));
45  }
46 }
47 
48 
50 {
51  // copy address layout
52  m_addressLayout = src.m_addressLayout;
53 
54  // copy all map contents, but set addresses to this address layout
55  m_configuration.clear();
56  container_t::iterator itDst = m_configuration.begin();
57  container_t::const_iterator itSrc = src.m_configuration.begin();
58  const container_t::const_iterator itSrcEnd = src.m_configuration.end();
59  for (; itSrc != itSrcEnd; ++itSrc)
60  {
61  // make temporary copy of source address and set it to new layout
62  V5FrameAddress address = itSrc->first;
63  address.addressLayout(&m_addressLayout);
64  // insert it into destination map
65  itDst = m_configuration.insert(itDst, std::make_pair(address, itSrc->second));
66  }
67 
68  // return self-reference
69  return *this;
70 }
71 
72 
74 {
75  // only take action if layouts differ
76  if (layout == m_addressLayout) return;
77  // delete current contents and copy new layout
78  clear();
79  m_addressLayout = layout;
80 }
81 
82 
84 {
85  return m_addressLayout;
86 }
87 
88 
89 bool V5Configuration::insert(const V5FrameAddress& address, const V5CfgFrame& frame)
90 {
91  // create a temporary copy of given address and set its address layout
92  // pointer to the one currently used
93  V5FrameAddress tempAddr = address;
94  tempAddr.addressLayout(&m_addressLayout);
95  // test its validity under that layout
96  if (!tempAddr.isValid()) throw Exception();
97 
98  // Check if map contains already a frame for given frame address. If so,
99  // copy the new frame into the old one. Else create a new pair using given
100  // frame address and frame.
101  const container_t::iterator lb = m_configuration.lower_bound(tempAddr);
102  if ((m_configuration.end() != lb) && (tempAddr == lb->first))
103  {
104  lb->second = frame;
105  return false;
106  }
107  else
108  {
109  m_configuration.insert(lb, std::make_pair(tempAddr, frame));
110  return true;
111  }
112 }
113 
114 
116 {
117  return (0 != m_configuration.erase(address));
118 }
119 
120 
122 {
123  m_configuration.clear();
124 }
125 
126 
127 size_t V5Configuration::size() const
128 {
129  return m_configuration.size();
130 }
131 
132 
134 {
135  // create vector for holding the address references
136  pairptrs_t ret;
137  ret.reserve(m_configuration.size());
138 
139  // fill it
140  container_t::iterator it = m_configuration.begin();
141  const container_t::iterator itEnd = m_configuration.end();
142  for (; it != itEnd; ++it) ret.push_back(&(*it));
143 
144  // return it
145  return ret;
146 }
147 
148 
150 {
151  // create vector for holding the address references
152  pairconstptrs_t ret;
153  ret.reserve(m_configuration.size());
154 
155  // fill it
156  container_t::const_iterator it = m_configuration.begin();
157  const container_t::const_iterator itEnd = m_configuration.end();
158  for (; it != itEnd; ++it) ret.push_back(&(*it));
159 
160  // return it
161  return ret;
162 }
163 
164 
166 {
167  // search for frame address in map
168  const container_t::iterator it = m_configuration.find(address);
169  // if found, return pointer to associated frame, else 0
170  if (m_configuration.end() == it) return 0;
171  return &(it->second);
172 }
173 
174 
176 {
177  // search for frame address in map
178  const container_t::const_iterator it = m_configuration.find(address);
179  // if found, return pointer to associated frame, else 0
180  if (m_configuration.end() == it) return 0;
181  return &(it->second);
182 }