DDS  ver. 3.4
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 DEF_H
6 #define 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 #pragma clang diagnostic push
17 #pragma clang diagnostic ignored "-Wunused-local-typedef"
18 #include <boost/algorithm/string/case_conv.hpp>
19 #pragma clang diagnostic pop
20 #include <boost/program_options/errors.hpp>
21 
22 namespace MiscCommon
23 {
24 // Unicode support
25 #if defined(_GLIBCPP_USE_WCHAR_T) && defined(_UNICODE)
26 
33  typedef const wchar_t* LPCTSTR;
40  typedef std::basic_string<wchar_t> tstring;
41  typedef std::basic_stringstream<wchar_t> tstringstream;
50 #define _T(s) L##s
51 
59  typedef wchar_t TCHAR;
60 
61 #else
62 
69  typedef const char* LPCTSTR;
76  typedef std::basic_string<char> tstring;
77  typedef std::basic_stringstream<char> tstringstream;
85 #define _T(s) s
86 
94  typedef char TCHAR;
95 
96 #endif
97 
103  typedef const char* LPCSTR;
109  typedef std::set<std::string> StringSet_t;
115  typedef std::vector<std::string> StringVector_t;
121  typedef std::vector<char> CHARVector_t;
127  typedef std::vector<unsigned char> BYTEVector_t;
134  typedef std::map<size_t, std::string> UIntStringMap_t;
141  typedef std::map<std::string, size_t> StringUIntMap_t;
142 
145  {
155  log_stdout_clean, // nothing will be pre-append to the output
157  };
158  const std::array<std::string, 11> g_LogSeverityLevelString{
159  { "p_l", "p_m", "p_h", "dbg", "inf", "wrn", "err", "fat", "cout", "cout", "cerr" }
160  };
161  //=============================================================================
162  // A custom streamer to help boost program options to convert string options to ELogSeverityLevel
163  inline std::istream& operator>>(std::istream& _in, ELogSeverityLevel& _logSeverityLevel)
164  {
165  std::string token;
166  _in >> token;
168 
169  auto found = std::find(g_LogSeverityLevelString.begin(), g_LogSeverityLevelString.end(), token);
170  if (found == g_LogSeverityLevelString.end())
171  throw boost::program_options::invalid_option_value(token);
172 
173  _logSeverityLevel = static_cast<ELogSeverityLevel>(std::distance(g_LogSeverityLevelString.begin(), found));
174  return _in;
175  }
176 
177  inline std::ostream& operator<<(std::ostream& _out, ELogSeverityLevel _logSeverityLevel)
178  {
179  const size_t idx = static_cast<size_t>(_logSeverityLevel);
180  _out << g_LogSeverityLevelString.at(idx);
181  return _out;
182  }
183 }; // namespace MiscCommon
184 
185 #endif
Definition: def.h:156
Definition: def.h:154
ELogSeverityLevel
Log Severity levels.
Definition: def.h:144
std::vector< std::string > StringVector_t
An STL vector of strings.
Definition: def.h:115
Definition: def.h:151
Definition: def.h:155
_T & to_lower(_T &_str)
convert string to lower case.
Definition: MiscUtils.h:249
std::istream & operator>>(std::istream &_in, ELogSeverityLevel &_logSeverityLevel)
Definition: def.h:163
Definition: def.h:147
Definition: def.h:148
std::ostream & operator<<(std::ostream &_out, ELogSeverityLevel _logSeverityLevel)
Definition: def.h:177
const std::array< std::string, 11 > g_LogSeverityLevelString
Definition: def.h:158
std::basic_stringstream< char > tstringstream
Definition: def.h:77
const char * LPCSTR
A long pointer to constant string.
Definition: def.h:103
char TCHAR
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:94
std::vector< char > CHARVector_t
An STL vector of char(s).
Definition: def.h:121
Definition: def.h:146
Definition: def.h:153
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:134
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:141
Definition: def.h:152
Definition: def.h:149
const char * LPCTSTR
Long Pointer to a Constant null-Terminated String.
Definition: def.h:69
std::vector< unsigned char > BYTEVector_t
An STL vector of bytes.
Definition: def.h:127
Definition: def.h:150
std::basic_string< char > tstring
It wraps wchar_t, when _GLIBCPP_USE_WCHAR_T and _UNICODE are defined and char otherwise.
Definition: def.h:76
std::set< std::string > StringSet_t
An STL set of strings.
Definition: def.h:109
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21