μHAL (v2.7.9)
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 #ifndef _uhal_log_inserters_integer_hpp_
34 #define _uhal_log_inserters_integer_hpp_
35 
36 
37 #include <stdint.h>
38 #include <iostream>
39 
41 
42 
43 namespace uhal
44 {
45 
48  {
49  bin,
50  dec,
51  hex
52  };
53 
56  {
58  variable
59  };
60 
63 
66 
68  template< integer_base BASE = DefaultIntegerBase , integer_format FORMAT = DefaultIntegerFormat , uint32_t WIDTH = 0 > struct IntFmt {};
69 
71  template< typename T , typename FORMAT >
72  class _Integer;
73 
75  template< typename T > _Integer< T , IntFmt<> > Integer ( const T& aT );
76 
78  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 );
79 
81  template< typename T >
82  void sign_helper ( std::ostream& aStr, const T& aInt );
83 
85  template<>
86  void sign_helper ( std::ostream& aStr, const int8_t& aInt );
87 
89  template<>
90  void sign_helper ( std::ostream& aStr, const int16_t& aInt );
91 
93  template<>
94  void sign_helper ( std::ostream& aStr, const int32_t& aInt );
95 
97  template<>
98  void sign_helper ( std::ostream& aStr, const int64_t& aInt );
99 
100 
102  template< typename T , typename FORMAT >
103  class _Integer : public RefWrapper< T >
104  {
105  public:
110  _Integer ( const T& aT );
111 
116  void print ( std::ostream& aStr ) const;
117  };
118 
119 
120  template< typename T , uint32_t WIDTH >
121  class _Integer< T , IntFmt<bin , fixed , WIDTH> > : public RefWrapper< T >
122  {
123  public:
124 
125  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
126  void print ( std::ostream& aStr ) const;
127  };
128 
129  template< typename T , uint32_t WIDTH >
130  class _Integer< T , IntFmt<bin , variable , WIDTH> > : public RefWrapper< T >
131  {
132  public:
133 
134  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
135  void print ( std::ostream& aStr ) const;
136  };
137 
138 
139  template< typename T , uint32_t WIDTH >
140  class _Integer< T , IntFmt<dec , fixed , WIDTH> > : public RefWrapper< T >
141  {
142  public:
143 
144  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
145  void print ( std::ostream& aStr ) const;
146  };
147 
148  template< typename T , uint32_t WIDTH >
149  class _Integer< T , IntFmt<dec , variable , WIDTH> > : public RefWrapper< T >
150  {
151  public:
152 
153  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
154  void print ( std::ostream& aStr ) const;
155  };
156 
157  template< typename T , uint32_t WIDTH >
158  class _Integer< T , IntFmt<hex , fixed , WIDTH> > : public RefWrapper< T >
159  {
160  public:
161 
162  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
163  void print ( std::ostream& aStr ) const;
164  };
165 
166  template< typename T , uint32_t WIDTH >
167  class _Integer< T , IntFmt<hex , variable , WIDTH> > : public RefWrapper< T >
168  {
169  public:
170 
171  _Integer ( const T& aT ) : RefWrapper< T > ( aT ) {}
172  void print ( std::ostream& aStr ) const;
173  };
174 
175 
176 
177  template< typename FORMAT >
178  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint8_t , FORMAT >& aInt );
179 
180  template< typename FORMAT >
181  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int8_t , FORMAT >& aInt );
182 
183  template< typename FORMAT >
184  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint16_t , FORMAT >& aInt );
185 
186  template< typename FORMAT >
187  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int16_t , FORMAT >& aInt );
188 
189  template< typename FORMAT >
190  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint32_t , FORMAT >& aInt );
191 
192  template< typename FORMAT >
193  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int32_t , FORMAT >& aInt );
194 
195  template< typename FORMAT >
196  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< uint64_t , FORMAT >& aInt );
197 
198  template< typename FORMAT >
199  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< int64_t , FORMAT >& aInt );
200 
201 #if __SIZEOF_LONG__ == 4
202  template< typename FORMAT >
203  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< long int , FORMAT >& aInt );
204 #endif
205 
206 #ifdef __APPLE__
207  template< typename FORMAT >
208  std::ostream& operator<< ( std::ostream& aStr , const uhal::_Integer< size_t , FORMAT >& aInt );
209 #endif
210 
211 }
212 
213 
215 
216 #endif
uhal::_Integer::_Integer
_Integer(const T &aT)
Constructor.
uhal::operator<<
std::ostream & operator<<(std::ostream &aStr, const uhal::HttpResponseType &aHttpResponse)
Definition: HttpResponseGrammar.cpp:41
uhal::dec
@ dec
Decimal.
Definition: log_inserters.integer.hpp:50
uhal::_Integer
Forward declare an ultra-lightweight wrapper which does formatting of numbers only on demand.
Definition: log_inserters.integer.hpp:72
uhal::_Integer::print
void print(std::ostream &aStr) const
The function which formats the integer and appends it into the given stream.
uhal::DefaultIntegerBase
static const integer_base DefaultIntegerBase(dec)
Constant which is the default formatting option.
uhal::integer_base
integer_base
Enumerated type specifying the formatting option.
Definition: log_inserters.integer.hpp:48
uhal::_Integer< T, IntFmt< dec, fixed, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:144
uhal::IntFmt
Empty struct which acts as a dummy variable for passing the formatting information around.
Definition: log_inserters.integer.hpp:68
uhal::DefaultIntegerFormat
static const integer_format DefaultIntegerFormat(variable)
Constant which is the default formatting option.
log_inserter_helper.hpp
uhal::_Integer< T, IntFmt< hex, variable, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:171
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::RefWrapper
Definition: log_inserter_helper.hpp:45
uhal::sign_helper
void sign_helper(std::ostream &aStr, const T &aInt)
Helper function for adding the '+'/'-' sign.
Definition: log_inserters.integer.hxx:55
uhal::bin
@ bin
Binary.
Definition: log_inserters.integer.hpp:49
uhal::variable
@ variable
Variable width.
Definition: log_inserters.integer.hpp:58
uhal::integer_format
integer_format
Enumerated type specifying the formatting option.
Definition: log_inserters.integer.hpp:56
uhal::Integer
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
Definition: log_inserters.integer.hxx:43
uhal::hex
@ hex
Hexadecimal.
Definition: log_inserters.integer.hpp:51
uhal::_Integer< T, IntFmt< dec, variable, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:153
uhal::_Integer< T, IntFmt< hex, fixed, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:162
uhal::fixed
@ fixed
Fixed width.
Definition: log_inserters.integer.hpp:57
log_inserters.integer.hxx
uhal::_Integer< T, IntFmt< bin, variable, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:134
uhal::_Integer< T, IntFmt< bin, fixed, WIDTH > >::_Integer
_Integer(const T &aT)
Definition: log_inserters.integer.hpp:125