DDS  ver. 3.6
def.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // Helpers and definitions (typedefs)
4 //
5 #ifndef _DDS_DEF_H_
6 #define _DDS_DEF_H_
7 
8 // STD
9 #include <array>
10 #include <map>
11 #include <set>
12 #include <sstream>
13 #include <string>
14 #include <vector>
15 // BOOST
16 #include <boost/algorithm/string/case_conv.hpp>
17 #include <boost/program_options/errors.hpp>
18 
19 namespace dds::misc
20 {
21 // Unicode support
22 #if defined(_GLIBCPP_USE_WCHAR_T) && defined(_UNICODE)
23 
30  typedef const wchar_t* LPCTSTR;
37  typedef std::basic_string<wchar_t> tstring;
38  typedef std::basic_stringstream<wchar_t> tstringstream;
47 #define _T(s) L##s
48 
56  typedef wchar_t TCHAR;
57 
58 #else
59 
66  typedef const char* LPCTSTR;
73  typedef std::basic_string<char> tstring;
74  typedef std::basic_stringstream<char> tstringstream;
82 #define _T(s) s
83 
91  typedef char TCHAR;
92 
93 #endif
94 
100  typedef const char* LPCSTR;
106  typedef std::set<std::string> StringSet_t;
112  typedef std::vector<std::string> StringVector_t;
118  typedef std::vector<char> CHARVector_t;
124  typedef std::vector<unsigned char> BYTEVector_t;
131  typedef std::map<size_t, std::string> UIntStringMap_t;
138  typedef std::map<std::string, size_t> StringUIntMap_t;
139 
142  {
152  log_stdout_clean, // nothing will be pre-append to the output
154  };
155  const std::array<std::string, 11> g_LogSeverityLevelString{
156  { "p_l", "p_m", "p_h", "dbg", "inf", "wrn", "err", "fat", "cout", "cout", "cerr" }
157  };
158  //=============================================================================
159  // A custom streamer to help boost program options to convert string options to ELogSeverityLevel
160  inline std::istream& operator>>(std::istream& _in, ELogSeverityLevel& _logSeverityLevel)
161  {
162  std::string token;
163  _in >> token;
165 
166  auto found = std::find(g_LogSeverityLevelString.begin(), g_LogSeverityLevelString.end(), token);
167  if (found == g_LogSeverityLevelString.end())
168  throw boost::program_options::invalid_option_value(token);
169 
170  _logSeverityLevel = static_cast<ELogSeverityLevel>(std::distance(g_LogSeverityLevelString.begin(), found));
171  return _in;
172  }
173 
174  inline std::ostream& operator<<(std::ostream& _out, ELogSeverityLevel _logSeverityLevel)
175  {
176  const size_t idx = static_cast<size_t>(_logSeverityLevel);
177  _out << g_LogSeverityLevelString.at(idx);
178  return _out;
179  }
180 }; // namespace dds::misc
181 
182 #endif // _DDS_DEF_H_
std::set< std::string > StringSet_t
An STL set of strings.
Definition: def.h:106
Definition: def.h:143
Definition: def.h:148
Definition: def.h:144
std::ostream & operator<<(std::ostream &_out, ELogSeverityLevel _logSeverityLevel)
Definition: def.h:174
const char * LPCSTR
A long pointer to constant string.
Definition: def.h:100
std::map< std::string, size_t > StringUIntMap_t
An STL map, which is mapping pairs of string (as a key) and size_t (as a value)
Definition: def.h:138
std::vector< std::string > StringVector_t
An STL vector of strings.
Definition: def.h:112
std::basic_string< char > tstring
It wraps wchar_t, when _GLIBCPP_USE_WCHAR_T and _UNICODE are defined and char otherwise.
Definition: def.h:73
const char * LPCTSTR
Long Pointer to a Constant null-Terminated String.
Definition: def.h:66
std::vector< char > CHARVector_t
An STL vector of char(s).
Definition: def.h:118
Definition: def.h:151
std::vector< unsigned char > BYTEVector_t
An STL vector of bytes.
Definition: def.h:124
const std::array< std::string, 11 > g_LogSeverityLevelString
Definition: def.h:155
Definition: def.h:145
ELogSeverityLevel
Log Severity levels.
Definition: def.h:141
char TCHAR
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:91
Definition: def.h:152
std::basic_stringstream< char > tstringstream
Definition: def.h:74
Definition: def.h:147
std::map< size_t, std::string > UIntStringMap_t
An STL map, which is mapping pairs of size_t (as a key) and string (as a value).
Definition: def.h:131
Definition: def.h:153
Definition: def.h:146
std::istream & operator>>(std::istream &_in, ELogSeverityLevel &_logSeverityLevel)
Definition: def.h:160
Definition: def.h:150
_T & to_lower(_T &_str)
convert string to lower case.
Definition: MiscUtils.h:249
Definition: def.h:149
Definition: BoostHelper.h:14