DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Conversion.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/Conversion.h to include/dbe/Conversion.hpp).
5
6#ifndef DBE_CONVERSION_H_
7#define DBE_CONVERSION_H_
8
9#include "dbe/Exceptions.hpp"
10
11#include "conffwk/Schema.hpp"
12#include "logging/Logging.hpp"
13
14#include <string>
15#include <vector>
16#include <sstream>
17#include <type_traits>
18
19#include <QStringList>
20
21namespace dbe
22{
23
24namespace convert
25{
26//------------------------------------------------------------------------------------------
33template<typename T> inline std::string valtostr ( T const & value )
34{
35 return std::to_string ( value );
36}
37
38template<> inline std::string valtostr<std::string> ( std::string const & x )
39{
40 return x;
41}
42
43template<> inline std::string valtostr<bool> ( bool const & s )
44{
45 std::ostringstream ss;
46 ss << std::boolalpha << s;
47 return ss.str();
48}
49//------------------------------------------------------------------------------------------
50
51//------------------------------------------------------------------------------------------
58template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
59inline std::string valtostr ( T const & value,
61{
63 {
64 return std::to_string ( value );
65 }
66 else
67 {
68 std::ostringstream ss;
69
71 {
72 ss << std::hex << std::showbase << +((typename std::make_unsigned<T>::type) value);
73 }
74 else if ( format == dunedaq::conffwk::oct_int_format )
75 {
76 ss << std::oct << std::showbase << +((typename std::make_unsigned<T>::type) value);
77 }
78 else if ( format == dunedaq::conffwk::na_int_format )
79 {
80 ss << value;
81 TLOG_DEBUG(1) << " This conversion should not happen for value " << ss.str() ;
82 }
83
84 return ss.str();
85 }
86}
87
88// Specialization for boolean (the std::make_unsigned is not defined for booleans)
89template<> inline std::string valtostr<bool> ( bool const & value,
91{
92 Q_UNUSED ( format );
93 return valtostr<bool>(value);
94}
95
96// This is for floating point types
97template<typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0>
98inline std::string valtostr ( T const & value,
100{
101 Q_UNUSED ( format );
102 return std::to_string(value);
103}
104
105// This is for simple strings
106inline std::string valtostr ( std::string const & value,
107 dunedaq::conffwk::int_format_t const format )
108{
109 Q_UNUSED ( format );
110 return value;
111}
112//------------------------------------------------------------------------------------------
113
114//------------------------------------------------------------------------------------------
115template<typename T>
116T to ( QStringList const & DataList )
117{
118 Q_UNUSED ( DataList )
119
120 T Dummy;
121 return Dummy;
122}
123
124template<typename T>
125T to ( QStringList const & DataList, dunedaq::conffwk::int_format_t Format )
126{
127 Q_UNUSED ( Format )
128 Q_UNUSED ( DataList )
129
130 T Dummy;
131 return Dummy;
132}
133
134template<typename T>
135T to ( std::vector<std::string> const & x )
136{
137 return x;
138}
139//------------------------------------------------------------------------------------------
140
141//------------------------------------------------------------------------------------------
143
144template<> QStringList to ( std::vector<std::string> const & DataList );
145
146template<> bool to<bool> ( QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
147template<> std::vector<bool> to<std::vector<bool>> ( QStringList const & DataList,
149template<> std::string to<std::string> ( QStringList const & DataList );
150template<> std::vector<std::string> to<std::vector<std::string>> (
151 QStringList const & DataList );
152template<> std::string to<std::string> ( QStringList const & DataList,
154template<> std::vector<std::string> to<std::vector<std::string>> (
155 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
156template<> u_int8_t to<u_int8_t> ( QStringList const & DataList,
158template<> std::vector<u_int8_t> to<std::vector<u_int8_t>> (
159 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
160template<> int8_t to<int8_t> ( QStringList const & DataList,
162template<> std::vector<int8_t> to<std::vector<int8_t>> ( QStringList const & DataList,
164template<> u_int16_t to<u_int16_t> ( QStringList const & DataList,
166template<> std::vector<u_int16_t> to<std::vector<u_int16_t>> (
167 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
168template<> int16_t to<int16_t> ( QStringList const & DataList,
170template<> std::vector<int16_t> to<std::vector<int16_t>> ( QStringList const & DataList,
172template<> u_int32_t to<u_int32_t> ( QStringList const & DataList,
174template<> std::vector<u_int32_t> to<std::vector<u_int32_t>> (
175 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
176template<> int32_t to<int32_t> ( QStringList const & DataList,
178template<> std::vector<int32_t> to<std::vector<int32_t>> ( QStringList const & DataList,
180template<> u_int64_t to<u_int64_t> ( QStringList const & DataList,
182template<> std::vector<u_int64_t> to<std::vector<u_int64_t>> (
183 QStringList const & DataList, dunedaq::conffwk::int_format_t Format );
184template<> int64_t to<int64_t> ( QStringList const & DataList,
186template<> std::vector<int64_t> to<std::vector<int64_t>> ( QStringList const & DataList,
188template<> float to<float> ( QStringList const & DataList,
190template<> std::vector<float> to<std::vector<float>> ( QStringList const & DataList,
192template<> double to<double> ( QStringList const & DataList,
194template<> std::vector<double> to<std::vector<double>> ( QStringList const & DataList,
196//------------------------------------------------------------------------------------------
197
198}
199}
200
201#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.