5 #ifndef _DDS_MISCUTILS_H_ 6 #define _DDS_MISCUTILS_H_ 12 #include <boost/filesystem.hpp> 13 #include <boost/process.hpp> 14 #include <boost/program_options/parsers.hpp> 58 auto_setenv(
const std::string& _VarName,
const std::string& _NewValue)
61 m_sVarName = _VarName;
62 m_sNewValue = _NewValue;
64 char* chTmp = getenv(m_sVarName.c_str());
70 setenv(m_sVarName.c_str(), m_sNewValue.c_str(), 1);
78 void set(
const std::string& _VarName,
const std::string& _NewValue)
82 m_sVarName = _VarName;
83 m_sNewValue = _NewValue;
85 char* chTmp = getenv(m_sVarName.c_str());
91 setenv(m_sVarName.c_str(), m_sNewValue.c_str(), 1);
98 unsetenv(m_sVarName.c_str());
102 if (!m_sVarName.empty())
105 setenv(m_sVarName.c_str(), m_sOldValue.c_str(), 1);
110 std::string m_sVarName;
111 std::string m_sNewValue;
112 std::string m_sOldValue;
124 template <
typename _T>
130 if (_pString->empty() || (*_pString)[_pString->size() - 1] != _ItemToAdd)
131 _pString->push_back(_ItemToAdd);
144 template <
typename _T>
147 return _pString->erase(_pString->find_last_not_of(_chWhat) + 1);
158 template <
typename _T>
161 return _pString->erase(0, _pString->find_first_not_of(_chWhat));
172 template <
typename _T>
173 _T&
trim(
_T* _pString,
const typename _T::value_type& _chWhat)
187 template <
typename _T>
190 typename _T::size_type pos = 0;
191 typename _T::size_type withLen = _with.length();
192 typename _T::size_type whatLen = _what.length();
193 while ((pos = _pString->find(_what, pos)) != _T::npos)
195 _pString->replace(pos, _what.length(), _with);
196 if (withLen > whatLen)
197 pos += withLen - whatLen + 1;
209 return std::tolower(c);
216 return std::toupper(c);
219 struct IsDigit : std::unary_function<int, int>
223 return std::isdigit(c);
234 template <
typename _T>
237 std::transform(_str.begin(), _str.end(), _str.begin(),
ToUpper());
248 template <
typename _T>
251 std::transform(_str.begin(), _str.end(), _str.begin(),
ToLower());
263 double mantissa = hr.
size;
264 for (; mantissa >= 1024.; mantissa /= 1024., ++i)
267 mantissa = std::ceil(mantissa * 10.) / 10.;
268 os << mantissa <<
"BKMGTPE"[i];
269 return i == 0 ? os : os <<
"B (" << hr.
size <<
')';
273 #endif // _DDS_MISCUTILS_H_ Definition: MiscUtils.h:219
std::uintmax_t size
Definition: MiscUtils.h:257
_T & trim_left(_T *_pString, const typename _T::value_type &_chWhat)
trims leading characters from the string.
Definition: MiscUtils.h:159
friend std::ostream & operator<<(std::ostream &os, HumanReadable hr)
Definition: MiscUtils.h:260
NONCopyable()
Definition: MiscUtils.h:31
void set(const std::string &_VarName, const std::string &_NewValue)
Definition: MiscUtils.h:78
Definition: MiscUtils.h:255
_T & to_upper(_T &_str)
convert string to upper case.
Definition: MiscUtils.h:235
Definition: MiscUtils.h:212
_T & trim(_T *_pString, const typename _T::value_type &_chWhat)
trims trailing and leading characters from the string.
Definition: MiscUtils.h:173
_T & trim_right(_T *_pString, const typename _T::value_type &_chWhat)
trims trailing characters from the string.
Definition: MiscUtils.h:145
~auto_setenv()
Definition: MiscUtils.h:72
int operator()(int c) const
Definition: MiscUtils.h:221
#define _T(s)
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:82
char operator()(char c) const
Definition: MiscUtils.h:207
auto_setenv(const std::string &_VarName, const std::string &_NewValue)
Definition: MiscUtils.h:58
auto_setenv()
Definition: MiscUtils.h:54
~NONCopyable()
Definition: MiscUtils.h:34
_T & replace(_T *_pString, const _T &_what, const _T &_with)
finds elements in a string match a specified string and replaces it.
Definition: MiscUtils.h:188
void unset()
Definition: MiscUtils.h:93
Class which makes child to be non-copyable object.
Definition: MiscUtils.h:28
_T & to_lower(_T &_str)
convert string to lower case.
Definition: MiscUtils.h:249
A helper class. Helps to automatically track environment variables.
Definition: MiscUtils.h:51
Definition: MiscUtils.h:205
Definition: MiscUtils.h:43
_T * smart_append(_T *_pString, const typename _T::value_type _ItemToAdd)
appends character _ItemToAdd to the string _pString if there is no such suffix on the end of _pString...
Definition: MiscUtils.h:125
char operator()(char c) const
Definition: MiscUtils.h:214
Definition: BoostHelper.h:14