μHAL (v2.6.5)
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 #include <cstddef> // for size_t
44 #include <deque>
45 #include <vector>
46 #include <stdint.h> // for uint32_t, uint8_t
47 
48 #include <boost/shared_ptr.hpp>
49 
50 #include "uhal/log/exception.hpp"
51 #include "uhal/definitions.hpp"
52 
53 
54 
56 
57 namespace uhal
58 {
59  namespace exception
60  {
62  UHAL_DEFINE_EXCEPTION_CLASS ( NonValidatedMemory , "Exception class to handle the case of attempted access on unvalidated memory." )
64  UHAL_DEFINE_EXCEPTION_CLASS ( ValMemImutabilityViolation , "Exception class to handle the case of attempted modification of validated memory." )
65  }
66 
67  // Forward declare ClientInterface so it can be our friend
68  class ClientInterface;
69 
70 
71  // Forward declaration so we can define friends
72  class ValHeader;
73  // Forward declaration so we can define friends
74  template< typename T > class ValWord;
75  // Forward declaration so we can define friends
76  template< typename T > class ValVector;
77 
78 
80  struct _ValHeader_
81  {
82  public:
84  bool valid;
86  std::deque<uint32_t> IPbusHeaders;
87 
88  protected:
90  friend class ValHeader;
96  _ValHeader_ ( const bool& aValid );
97  };
98 
99 
100 
102  template< typename T >
103  struct _ValWord_ : public _ValHeader_
104  {
105  public:
107  T value;
108  // //! A flag for marking whether the data is actually valid
109  // bool valid;
111  uint32_t mask;
112  // //! The IPbus header associated with the transaction that returned this data
113  // uint32_t IPbusHeader;
114 
115  protected:
117  friend class ValWord<T>;
125  _ValWord_ ( const T& aValue , const bool& aValid , const uint32_t aMask );
126  };
127 
128 
130  template< typename T >
131  struct _ValVector_ : public _ValHeader_
132  {
133  public:
135  std::vector<T> value;
136  // //! A flag for marking whether the data is actually valid
137  // bool valid;
138  // //! The IPbus header associated with the transaction that returned this data
139  // std::deque<uint32_t> IPbusHeaders;
140 
141  protected:
143  friend class ValVector<T>;
150  _ValVector_ ( const std::vector<T>& aValue , const bool& aValid );
151  };
152 
153 
154 
156  class ValHeader
157  {
159  friend class ClientInterface;
160 
161  public:
165  ValHeader();
166 
171  template< typename T >
172  ValHeader ( const ValWord<T>& aValWord );
173 
178  template< typename T >
179  ValHeader ( const ValVector<T>& aValVector );
180 
181 
186  bool valid();
191  void valid ( bool aValid );
192 
193  // /**
194  // Return a std::deque containing all the IPbus headers returned during the transaction
195  // @return a std::deque containing all the IPbus headers returned during the transaction
196  // @note This is a deque, since a block transaction may be chunked into many smaller block transactions
197  // */
198  // const std::deque<uint32_t>& returnedHeaders();
199 
200  protected:
203  };
204 
205 
207  template< typename T >
208  class ValWord
209  {
210 
212  friend class ClientInterface;
213 
215  friend class ValHeader;
216 
217  public:
223  ValWord ( const T& aValue , const uint32_t& aMask = defs::NOMASK );
228  ValWord ( const ValWord<T>& aVal );
232  ValWord();
237  bool valid();
242  void valid ( bool aValid );
249  ValWord& operator = ( const T& aValue );
255  operator T();
260  T value() const;
265  void value ( const T& aValue );
270  const uint32_t& mask() const;
275  void mask ( const uint32_t& aMask );
276 
277  // /**
278  // Return a std::deque containing all the IPbus headers returned during the transaction
279  // @return a std::deque containing all the IPbus headers returned during the transaction
280  // @note This is a deque, since a block transaction may be chunked into many smaller block transactions
281  // */
282  // const std::deque<uint32_t>& returnedHeaders();
283 
284  private:
287 
288  };
289 
290 
292  template< typename T >
293  class ValVector
294  {
296  friend class ClientInterface;
297 
299  friend class ValHeader;
300 
301  public:
303  typedef typename std::vector< T >::iterator iterator;
305  typedef typename std::vector< T >::const_iterator const_iterator;
307  typedef typename std::vector< T >::reverse_iterator reverse_iterator;
309  typedef typename std::vector< T >::const_reverse_iterator const_reverse_iterator;
310 
311  public:
316  ValVector ( const std::vector<T>& aValues );
321  ValVector ( const ValVector& aValues );
326  ValVector ( const uint32_t& aSize );
330  ValVector();
335  bool valid();
340  void valid ( bool aValid );
346  template <class InputIterator> void assign ( InputIterator aBegin , InputIterator aEnd );
351  void push_back ( const T& aValue );
357  const T& operator[] ( std::size_t aIndex ) const;
363  const T& at ( std::size_t aIndex ) const;
368  std::size_t size() const;
372  void clear();
377  const_iterator begin() const;
382  const_iterator end() const;
387  const_reverse_iterator rbegin() const;
392  const_reverse_iterator rend() const;
397  std::vector<T> value() const;
402  void value ( const std::vector<T>& aValue );
403 
404  /*
405  / **
406  If the memory has not previously been marked as valid, return a iterator to the beginning of the underlying memory
407  @return a iterator to the beginning of the underlying memory
408  * /
409  iterator begin();
410  / **
411  If the memory has not previously been marked as valid, return a iterator to the end (one past last entry) of the underlying memory
412  @return a iterator to the end (one past last entry) of the underlying memory
413  * /
414  iterator end();
415  / **
416  If the memory has not previously been marked as valid, return a reverse iterator to the reverse beginning (the last entry) of the underlying memory
417  @return a reverse iterator to the reverse beginning (the last entry) of the underlying memory
418  * /
419  reverse_iterator rbegin();
420  / **
421  If the memory has not previously been marked as valid, return a reverse iterator to the reverse end (one before the zero'th entry) of the underlying memory
422  @return a reverse iterator to the reverse end (one before the zero'th entry) of the underlying memory
423  * /
424  reverse_iterator rend();
425  */
426 
427  // /**
428  // Return a std::deque containing all the IPbus headers returned during the transaction
429  // @return a std::deque containing all the IPbus headers returned during the transaction
430  // @note This is a deque, since a block transaction may be chunked into many smaller block transactions
431  // */
432  // const std::deque<uint32_t>& returnedHeaders();
433 
434  private:
437 
438  };
439 
440 }
441 
443 
444 #endif
445 
boost::shared_ptr< _ValHeader_ > mMembers
Return a std::deque containing all the IPbus headers returned during the transaction.
Definition: ValMem.hpp:202
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:74
std::vector< T >::const_iterator const_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:305
std::vector< T >::const_reverse_iterator const_reverse_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:309
A class which wraps a block of data and marks whether or not it is valid.
Definition: ValMem.hpp:76
boost::shared_ptr< _ValWord_< T > > mMembers
Return a std::deque containing all the IPbus headers returned during the transaction.
Definition: ValMem.hpp:286
A Template helper struct wrapping an IPbus header, a register for storing a single word of data...
Definition: ValMem.hpp:103
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
std::vector< T > value
A block of memory for storing data.
Definition: ValMem.hpp:135
const uint32_t NOMASK
define what it means to have no mask
Definition: definitions.hpp:56
A helper struct wrapping an IPbus header and a valid flag.
Definition: ValMem.hpp:80
std::vector< T >::reverse_iterator reverse_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:307
std::vector< T >::iterator iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:303
uint32_t mask
A mask for modifying returned values.
Definition: ValMem.hpp:111
T value
A register for storing data.
Definition: ValMem.hpp:107
boost::shared_ptr< _ValVector_< T > > mMembers
Return a std::deque containing all the IPbus headers returned during the transaction.
Definition: ValMem.hpp:436
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
std::deque< uint32_t > IPbusHeaders
The IPbus header associated with the transaction that returned this data.
Definition: ValMem.hpp:86
lDepths push_back(N_200MB)
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:156
A Template helper struct wrapping a block of IPbus header, a register for storing a block of data and...
Definition: ValMem.hpp:131
bool valid
A flag for marking whether the data is actually valid.
Definition: ValMem.hpp:84