μHAL (v2.6.5)
Part of the IPbus software repository
log_inserters.integer.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 
33 
34 #ifndef _log_inserters_integer_hpp_
35 #define _log_inserters_integer_hpp_
36 
38 
39 #include <stdint.h>
40 #include <iostream>
41 
42 namespace uhal
43 {
44 
49  {
50  bin,
51  dec,
52  hex
53  };
54 
59  {
62  };
63 
67  static const integer_base DefaultIntegerBase ( dec );
68 
73 
77  template< integer_base BASE = DefaultIntegerBase , integer_format FORMAT = DefaultIntegerFormat , uint32_t WIDTH = 0 > struct IntFmt {};
78 
82  template< typename T , typename FORMAT >
83  class _Integer;
84 
88  template< typename T > _Integer< T , IntFmt<> > Integer ( const T& aT );
89 
93  template< typename T , integer_base BASE , integer_format FORMAT , uint32_t WIDTH > _Integer< T , IntFmt<BASE , FORMAT , WIDTH> > Integer ( const T& aT , const IntFmt<BASE , FORMAT , WIDTH>& aFmt );
94 
98  template< typename T >
99  void sign_helper ( std::ostream& aStr, const T& aInt );
100 
104  template<>
105  void sign_helper ( std::ostream& aStr, const int8_t& aInt );
109  template<>
110  void sign_helper ( std::ostream& aStr, const int16_t& aInt );
114  template<>
115  void sign_helper ( std::ostream& aStr, const int32_t& aInt );
119  template<>
120  void sign_helper ( std::ostream& aStr, const int64_t& aInt );
121 
122 
126  template< typename T , typename FORMAT >
127  class _Integer : public RefWrapper< T >
128  {
129  public:
134  _Integer ( const T& aT );
135 
140  void print ( std::ostream& aStr ) const;
141  };
142 
143 
144  template< typename T , uint32_t WIDTH >
145  class _Integer< T , IntFmt<bin , fixed , WIDTH> > : public RefWrapper< T >
146  {
147  public:
148 
149  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
150  void print ( std::ostream& aStr ) const;
151  };
152 
153  template< typename T , uint32_t WIDTH >
154  class _Integer< T , IntFmt<bin , variable , WIDTH> > : public RefWrapper< T >
155  {
156  public:
157 
158  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
159  void print ( std::ostream& aStr ) const;
160  };
161 
162 
163  template< typename T , uint32_t WIDTH >
164  class _Integer< T , IntFmt<dec , fixed , WIDTH> > : public RefWrapper< T >
165  {
166  public:
167 
168  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
169  void print ( std::ostream& aStr ) const;
170  };
171 
172  template< typename T , uint32_t WIDTH >
173  class _Integer< T , IntFmt<dec , variable , WIDTH> > : public RefWrapper< T >
174  {
175  public:
176 
177  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
178  void print ( std::ostream& aStr ) const;
179  };
180 
181  template< typename T , uint32_t WIDTH >
182  class _Integer< T , IntFmt<hex , fixed , WIDTH> > : public RefWrapper< T >
183  {
184  public:
185 
186  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
187  void print ( std::ostream& aStr ) const;
188  };
189 
190  template< typename T , uint32_t WIDTH >
191  class _Integer< T , IntFmt<hex , variable , WIDTH> > : public RefWrapper< T >
192  {
193  public:
194 
195  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
196  void print ( std::ostream& aStr ) const;
197  };
198 
199 
200 
201  template< typename FORMAT >
202  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint8_t , FORMAT >& aInt );
203 
204  template< typename FORMAT >
205  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int8_t , FORMAT >& aInt );
206 
207  template< typename FORMAT >
208  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint16_t , FORMAT >& aInt );
209 
210  template< typename FORMAT >
211  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int16_t , FORMAT >& aInt );
212 
213  template< typename FORMAT >
214  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint32_t , FORMAT >& aInt );
215 
216  template< typename FORMAT >
217  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int32_t , FORMAT >& aInt );
218 
219  template< typename FORMAT >
220  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint64_t , FORMAT >& aInt );
221 
222  template< typename FORMAT >
223  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int64_t , FORMAT >& aInt );
224 
225 #ifdef __APPLE__
226  template< typename FORMAT >
227  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< size_t , FORMAT >& aInt );
228 #endif
229 
230 }
231 
232 
234 
235 #endif
Variable width.
Forward declare an ultra-lightweight wrapper which does formatting of numbers only on demand...
static const integer_format DefaultIntegerFormat(variable)
Constant which is the default formatting option.
integer_base
Enumerated type specifying the formatting option.
Empty struct which acts as a dummy variable for passing the formatting information around...
integer_format
Enumerated type specifying the formatting option.
Hexadecimal.
void print(std::ostream &aStr, const tm *aTm, const uint32_t &aUsec)
Format a time element for for sending to the log.
void sign_helper(std::ostream &aStr, const T &aInt)
Helper function for adding the &#39;+&#39;/&#39;-&#39; sign.
static const integer_base DefaultIntegerBase(dec)
Constant which is the default formatting option.
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...