otsdaq  v2_05_02_indev
BinaryStringMacros.h
1 #ifndef _ots_BinaryStringMacros_h_
2 #define _ots_BinaryStringMacros_h_
3 
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/Macros/StringMacros.h"
6 
7 #include <map>
8 #include <set>
9 #include <typeinfo> // operator typeid
10 #include <vector>
11 
12 namespace ots
13 {
15 {
16  // clang-format off
17  private: // private constructor because all static members, should never instantiate
18  // this class
19  BinaryStringMacros(void);
20  ~BinaryStringMacros(void);
21 
22  public:
23  // Here is the list of static helper functions:
24  //
25  // binaryStringToHexString
26  // binaryNumberToHexString
27  //
28 
29 
30  //=======================================================
31  static std::string binaryStringToHexString (
32  const void* binaryBuffer,
33  unsigned int numberOfBytes,
34  const std::string& resultPreamble = "",
35  const std::string& resultDelimiter = "");
36 
37  template<class T>
38  static std::string binaryNumberToHexString (
39  const T& binaryBuffer,
40  const std::string& resultPreamble = "0x",
41  const std::string& resultDelimiter = " ");
42  static std::string binaryNumberToHexString (
43  const std::string& binaryBuffer,
44  const std::string& resultPreamble = "0x",
45  const std::string& resultDelimiter = " ");
46  static std::string binaryNumberToHexString (
47  const void* binaryBuffer,
48  unsigned int numberOfBytes,
49  const std::string& resultPreamble = "0x",
50  const std::string& resultDelimiter = " ");
51 
52 
53  //=======================================================
54  template<class T>
55  static void insertValueInBinaryString ( // defined in included .icc source
56  std::string& binaryBuffer,
57  T value,
58  unsigned int bitIndex = 0);
59 
60  // specialized for string value
61  static void insertValueInBinaryString (
62  std::string& binaryBuffer,
63  const std::string& value,
64  unsigned int bitIndex = 0);
65 
66  //=======================================================
67  template<class T>
68  static void extractValueFromBinaryString( // defined in included .icc source
69  const std::string& binaryBuffer,
70  T& value,
71  unsigned int bitIndex = 0);
72 
73  // specialized for string value
74  static void extractValueFromBinaryString(
75  const std::string& binaryBuffer,
76  std::string& value,
77  unsigned int valueNumberOfBits,
78  unsigned int bitIndex = 0);
79 
80  // specialized for generic void* handling (actually does the work)
81  static void extractValueFromBinaryString(
82  const void* binaryBuffer,
83  unsigned int bufferNumberOfBytes,
84  void* value,
85  unsigned int valueNumberOfBits,
86  unsigned int bitIndex = 0);
87 
88 }; // end BinaryStringMacros static class
89 
90 #include "otsdaq/Macros/BinaryStringMacros.icc" //define template functions
91 
92 // clang-format on
93 } // namespace ots
94 #endif