μHAL (v2.7.9)
Part of the IPbus software repository
ValMem.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
40 #ifndef _uhal_ValMem_hpp_
41 #define _uhal_ValMem_hpp_
42 
43 
44 #include <cstddef> // for size_t
45 #include <deque>
46 #include <stdint.h> // for uint32_t, uint8_t
47 #include <vector>
48 
49 #include <boost/shared_ptr.hpp>
50 
51 #include "uhal/log/exception.hpp"
52 #include "uhal/definitions.hpp"
53 
54 
55 
56 namespace uhal
57 {
58  namespace exception
59  {
61  UHAL_DEFINE_EXCEPTION_CLASS ( NonValidatedMemory , "Exception class to handle the case of attempted access on unvalidated memory." )
63  UHAL_DEFINE_EXCEPTION_CLASS ( ValMemImutabilityViolation , "Exception class to handle the case of attempted modification of validated memory." )
64  }
65 
66  // Forward declare ClientInterface so it can be our friend
67  class ClientInterface;
68 
69 
70  // Forward declaration so we can define friends
71  class ValHeader;
72  // Forward declaration so we can define friends
73  template< typename T > class ValWord;
74  // Forward declaration so we can define friends
75  template< typename T > class ValVector;
76 
77 
79  struct _ValHeader_
80  {
81  public:
83  bool valid;
85  std::deque<uint32_t> IPbusHeaders;
86 
87  protected:
89  friend class ValHeader;
95  _ValHeader_ ( const bool& aValid );
96  };
97 
98 
99 
101  template< typename T >
102  struct _ValWord_ : public _ValHeader_
103  {
104  public:
106  T value;
108  uint32_t mask;
109 
110  protected:
112  friend class ValWord<T>;
120  _ValWord_ ( const T& aValue , const bool& aValid , const uint32_t aMask );
121  };
122 
123 
125  template< typename T >
126  struct _ValVector_ : public _ValHeader_
127  {
128  public:
130  std::vector<T> value;
131 
132  protected:
134  friend class ValVector<T>;
141  _ValVector_ ( const std::vector<T>& aValue , const bool& aValid );
142  };
143 
144 
145 
147  class ValHeader
148  {
150  friend class ClientInterface;
151 
152  public:
154  ValHeader();
155 
160  template< typename T >
161  ValHeader ( const ValWord<T>& aValWord );
162 
167  template< typename T >
168  ValHeader ( const ValVector<T>& aValVector );
169 
174  bool valid();
179  void valid ( bool aValid );
180 
181  protected:
184  };
185 
186 
188  template< typename T >
189  class ValWord
190  {
191 
193  friend class ClientInterface;
194 
196  friend class ValHeader;
197 
198  public:
204  ValWord ( const T& aValue , const uint32_t& aMask = defs::NOMASK );
205 
210  ValWord ( const ValWord<T>& aVal );
211 
213  ValWord();
214 
219  bool valid();
220 
225  void valid ( bool aValid );
226 
232  ValWord& operator = ( const T& aValue );
233 
238  operator T();
239 
244  T value() const;
245 
250  void value ( const T& aValue );
251 
256  const uint32_t& mask() const;
257 
262  void mask ( const uint32_t& aMask );
263 
264  private:
267 
268  };
269 
270 
272  template< typename T >
273  class ValVector
274  {
276  friend class ClientInterface;
277 
279  friend class ValHeader;
280 
281  public:
283  typedef typename std::vector< T >::iterator iterator;
285  typedef typename std::vector< T >::const_iterator const_iterator;
287  typedef typename std::vector< T >::reverse_iterator reverse_iterator;
289  typedef typename std::vector< T >::const_reverse_iterator const_reverse_iterator;
290 
291  public:
296  ValVector ( const std::vector<T>& aValues );
297 
302  ValVector ( const ValVector& aValues );
303 
308  ValVector ( const uint32_t& aSize );
309 
311  ValVector();
312 
317  bool valid();
318 
323  void valid ( bool aValid );
324 
330  template <class InputIterator> void assign ( InputIterator aBegin , InputIterator aEnd );
331 
336  void push_back ( const T& aValue );
337 
343  const T& operator[] ( std::size_t aIndex ) const;
344 
350  const T& at ( std::size_t aIndex ) const;
351 
356  std::size_t size() const;
357 
359  void clear();
360 
365  const_iterator begin() const;
366 
371  const_iterator end() const;
372 
377  const_reverse_iterator rbegin() const;
378 
383  const_reverse_iterator rend() const;
384 
389  std::vector<T> value() const;
390 
395  void value ( const std::vector<T>& aValue );
396 
397  private:
400 
401  };
402 
403 }
404 
406 
407 #endif
408 
uhal::ValVector
A class which wraps a block of data and marks whether or not it is valid.
Definition: ValMem.hpp:75
UHAL_DEFINE_EXCEPTION_CLASS
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
uhal::ValVector::iterator
std::vector< T >::iterator iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:283
boost::shared_ptr
Definition: DerivedNodeFactory.hpp:52
definitions.hpp
uhal::ValHeader::mMembers
boost::shared_ptr< _ValHeader_ > mMembers
A shared pointer to a ValWord struct, so that every copy of this ValWord points to the same underlyin...
Definition: ValMem.hpp:183
uhal::_ValWord_::value
T value
A register for storing data.
Definition: ValMem.hpp:106
uhal::ClientInterface
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
Definition: ClientInterface.hpp:100
uhal::ValHeader
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:148
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::ValWord::mMembers
boost::shared_ptr< _ValWord_< T > > mMembers
A shared pointer to a ValWord struct, so that every copy of this ValWord points to the same underlyin...
Definition: ValMem.hpp:266
uhal::_ValHeader_::IPbusHeaders
std::deque< uint32_t > IPbusHeaders
The IPbus header associated with the transaction that returned this data.
Definition: ValMem.hpp:85
uhal::ValVector::const_reverse_iterator
std::vector< T >::const_reverse_iterator const_reverse_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:289
uhal::_ValHeader_::valid
bool valid
A flag for marking whether the data is actually valid.
Definition: ValMem.hpp:83
uhal::ValVector::const_iterator
std::vector< T >::const_iterator const_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:285
uhal::ValVector::reverse_iterator
std::vector< T >::reverse_iterator reverse_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:287
uhal::_ValHeader_
A helper struct wrapping an IPbus header and a valid flag.
Definition: ValMem.hpp:80
uhal::ValWord
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:73
uhal::_ValVector_
A Template helper struct wrapping a block of IPbus header, a register for storing a block of data and...
Definition: ValMem.hpp:127
uhal::_ValWord_
A Template helper struct wrapping an IPbus header, a register for storing a single word of data,...
Definition: ValMem.hpp:103
ValMem.hxx
exception.hpp
uhal::defs::NOMASK
const uint32_t NOMASK
define what it means to have no mask
Definition: definitions.hpp:56
uhal::ValVector::mMembers
boost::shared_ptr< _ValVector_< T > > mMembers
A shared pointer to a ValVector struct, so that every copy of this ValVector points to the same under...
Definition: ValMem.hpp:399