DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Conversion.hpp
Go to the documentation of this file.
1#ifndef DBE_CONVERSION_H_
2#define DBE_CONVERSION_H_
3
4#include "dbe/Exceptions.hpp"
5
6#include "conffwk/Schema.hpp"
7#include "logging/Logging.hpp"
8
9#include <string>
10#include <vector>
11#include <sstream>
12#include <type_traits>
13
14#include <QStringList>
15
16namespace dbe
17{
18
19namespace convert
20{
21//------------------------------------------------------------------------------------------
28template<typename T> inline std::string valtostr ( T const & value )
29{
30 return std::to_string ( value );
31}
32
33template<> inline std::string valtostr<std::string> ( std::string const & x )
34{
35 return x;
36}
37
38template<> inline std::string valtostr<bool> ( bool const & s )
39{
40 std::ostringstream ss;
41 ss << std::boolalpha << s;
42 return ss.str();
43}
44//------------------------------------------------------------------------------------------
45
46//------------------------------------------------------------------------------------------
53template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
54inline std::string valtostr ( T const & value,
56{
58 {
59 return std::to_string ( value );
60 }
61 else
62 {
63 std::ostringstream ss;
64
66 {
67 ss << std::hex << std::showbase << +((typename std::make_unsigned<T>::type) value);
68 }
69 else if ( format == dunedaq::conffwk::oct_int_format )
70 {
71 ss << std::oct << std::showbase << +((typename std::make_unsigned<T>::type) value);
72 }
73 else if ( format == dunedaq::conffwk::na_int_format )
74 {
75 ss << value;
76 TLOG_DEBUG(1) << " This conversion should not happen for value " << ss.str() ;
77 }
78
79 return ss.str();
80 }
81}
82
83// Specialization for boolean (the std::make_unsigned is not defined for booleans)
84template<> inline std::string valtostr<bool> ( bool const & value,
86{
87 Q_UNUSED ( format );
88 return valtostr<bool>(value);
89}
90
91// This is for floating point types
92template<typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0>
93inline std::string valtostr ( T const & value,
95{
96 Q_UNUSED ( format );
97 return std::to_string(value);
98}
99
100// This is for simple strings
101inline std::string valtostr ( std::string const & value,
102 dunedaq::conffwk::int_format_t const format )
103{
104 Q_UNUSED ( format );
105 return value;
106}
107//------------------------------------------------------------------------------------------
108
109//------------------------------------------------------------------------------------------
110template<typename T>
111T to ( QStringList const & DataList )
112{
113 Q_UNUSED ( DataList )
114
115 T Dummy;
116 return Dummy;
117}
118
119template<typename T>
120T to ( QStringList const & DataList, dunedaq::conffwk::int_format_t Format )
121{
122 Q_UNUSED ( Format )
123 Q_UNUSED ( DataList )
124
125 T Dummy;
126 return Dummy;
127}
128
129template<typename T>
130T to ( std::vector<std::string> const & x )
131{
132 return x;
133}
134//------------------------------------------------------------------------------------------
135
136//------------------------------------------------------------------------------------------
138
139template<> QStringList to ( std::vector<std::string> const & DataList );
140
141template<> bool to<bool> ( QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
142template<> std::vector<bool> to<std::vector<bool>> ( QStringList const & DataList,
144template<> std::string to<std::string> ( QStringList const & DataList );
145template<> std::vector<std::string> to<std::vector<std::string>> (
146 QStringList const & DataList );
147template<> std::string to<std::string> ( QStringList const & DataList,
149template<> std::vector<std::string> to<std::vector<std::string>> (
150 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
151template<> u_int8_t to<u_int8_t> ( QStringList const & DataList,
153template<> std::vector<u_int8_t> to<std::vector<u_int8_t>> (
154 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
155template<> int8_t to<int8_t> ( QStringList const & DataList,
157template<> std::vector<int8_t> to<std::vector<int8_t>> ( QStringList const & DataList,
159template<> u_int16_t to<u_int16_t> ( QStringList const & DataList,
161template<> std::vector<u_int16_t> to<std::vector<u_int16_t>> (
162 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
163template<> int16_t to<int16_t> ( QStringList const & DataList,
165template<> std::vector<int16_t> to<std::vector<int16_t>> ( QStringList const & DataList,
167template<> u_int32_t to<u_int32_t> ( QStringList const & DataList,
169template<> std::vector<u_int32_t> to<std::vector<u_int32_t>> (
170 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
171template<> int32_t to<int32_t> ( QStringList const & DataList,
173template<> std::vector<int32_t> to<std::vector<int32_t>> ( QStringList const & DataList,
175template<> u_int64_t to<u_int64_t> ( QStringList const & DataList,
177template<> std::vector<u_int64_t> to<std::vector<u_int64_t>> (
178 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
179template<> int64_t to<int64_t> ( QStringList const & DataList,
181template<> std::vector<int64_t> to<std::vector<int64_t>> ( QStringList const & DataList,
183template<> float to<float> ( QStringList const & DataList,
185template<> std::vector<float> to<std::vector<float>> ( QStringList const & DataList,
187template<> double to<double> ( QStringList const & DataList,
189template<> std::vector<double> to<std::vector<double>> ( QStringList const & DataList,
191//------------------------------------------------------------------------------------------
192
193}
194}
195
196#endif // DBE_CONVERSION_H_
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
int8_t to< int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
std::string valtostr(T const &value)
u_int64_t to< u_int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
int16_t to< int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int8_t to< u_int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
std::string valtostr< bool >(bool const &s)
int64_t to< int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
T to(QStringList const &DataList)
std::string to< std::string >(QStringList const &DataList)
int32_t to< int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
std::string valtostr< std::string >(std::string const &x)
u_int32_t to< u_int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
double to< double >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int16_t to< u_int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
float to< float >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
bool to< bool >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Include QT Headers.