37#if defined(_WIN32) || defined(_WIN64)
38#define UBSYSTEM_WINDOWS
49#elif defined(__APPLE__)
54#include <sys/syscall.h>
56#elif (defined(__amd64) || defined(__amd64__) || defined(__unix__)) && !defined(__AIX__)
69#error "ub_system::UnknownMachine"
72#if defined(__unix__) && defined(__CYGWIN__)
73#define UBSYSTEM_CYGWIN
75#elif defined(__unix__)
76#include <sys/syscall.h>
79#if defined(min) || defined(max)
80#error add NOMINMAX to preprocessor defines
96#include <boost/thread.hpp>
102#define _QUOTEME(x) #x
103#define QUOTEME(x) _QUOTEME(x)
127#if defined(UBSYSTEM_WINDOWS)
129#elif (defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)) && !defined(UBSYSTEM_CYGWIN)
131#elif defined(UBSYSTEM_CYGWIN)
134#error "ub_system::sleepMSec - UnknownMachine"
140#if defined(UBSYSTEM_WINDOWS) || defined(UBSYSTEM_CYGWIN)
142#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) && !defined(UBSYSTEM_CYGWIN)
145#error "ub_system::sleepS - UnknownMachine"
173 std::stringstream
text;
174 for (
int i =
sizeof(value) * 8 - 1 ;
i >= 0;
i--) {
175 text << (
char)(((value >>
i) & 1) +
'0');
176 if (
i % 4 == 0 &&
i > 0)
187 std::istringstream
iss(
s);
192 static_cast<std::string
>(
typeid(
x).name()) +
">"));
201 std::ostringstream oss;
202 oss << std::setprecision(precision);
211 std::transform(
tmp.begin(),
tmp.end(),
tmp.begin(),
static_cast<int (*)(
int)
>(std::toupper));
220 std::transform(
tmp.begin(),
tmp.end(),
tmp.begin(),
static_cast<int (*)(
int)
>(std::tolower));
242 return std::string(
"");
245 return static_cast<std::string
>(
str);
248inline bool isDirectory(
const std::string &dir,
const unsigned & = 3)
253 std::string path = ub_system::replaceInString(dir,
"\\",
"/");
255#if defined UBSYSTEM_WINDOWS
257 if (
_access(path.c_str(), 0) == -1)
260 if (
_waccess(path.c_str(), 0) == -1)
263#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)
277#if defined(CAB_BOOST)
282 UBLOG(
logDEBUG5,
"ub_system::makeDirectory - start, dir=" << dir);
286 std::string path = ub_system::replaceInString(dir,
"\\",
"/");
290 if (path[path.size() - 1] !=
'/')
294 while ((
pos = path.find(
"/",
pos + 1)) != std::string::npos) {
295 std::string
tmpdir = path.substr(0,
pos);
296#if defined(CAB_BOOST)
299#if defined UBSYSTEM_WINDOWS
307 UBLOG(
logDEBUG5,
"ub_system::makeDirectory - dir=\"" <<
tmpdir <<
"\" - doesn't exist or makedir failed");
311#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)
314 UBLOG(
logDEBUG5,
"ub_system::makeDirectory - dir=\"" <<
tmpdir <<
" - directory created successfully.");
321#error "ub_system::makeDirectory - UnknownMachine"
327#if defined(CAB_BOOST)
332#if defined(CAB_BOOST)
335 std::string
command =
"rmdir \"" + dir +
"\"";
336 return std::system(
command.c_str());
348 std::size_t last =
tmp.rfind(
"/");
349 if (last != std::string::npos)
367 std::size_t last =
tmp.rfind(
"/");
368 if (last != std::string::npos && (last + 1) <
tmp.size())
369 tmp.erase(0, last + 1);
373 last =
tmp.rfind(
".");
374 if (last != std::string::npos)
383#if defined UBSYSTEM_WINDOWS
385#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)
388#error "int ub_system::getProcessID() - UnknownMachine"
394#if defined UBSYSTEM_WINDOWS || defined(UBSYSTEM_CYGWIN)
396#elif defined(UBSYSTEM_APPLE)
399 return (
unsigned long)
tid;
400#elif defined(UBSYSTEM_LINUX)
402#elif defined(UBSYSTEM_AIX)
403 return (
unsigned long)
getpid();
405#error "unsigned long ub_system::getCurrentThreadID() - UnknownMachine"
412 if ((*(
char *)&
word) != 0x21)
425 std::stringstream
tmp;
428 tmp <<
localTime->tm_year + 1900 <<
"." << std::setw(2) <<
localTime->tm_mon + 1 <<
"." << std::setw(2)
430 <<
"." << std::setw(2) <<
localTime->tm_sec;
454#if defined(UBSYSTEM_WINDOWS) || defined(UBSYSTEM_CYGWIN)
459 for (
int i = 0;
i < 150;
i++) {
465#elif (defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)) && !defined(UBSYSTEM_CYGWIN)
469 return std::string(
Name);
476template <
bool C,
typename Ta,
typename Tb>
480template <
typename Ta,
typename Tb>
488template <
typename Ta,
typename Tb>
509template <
typename Pair>
517template <
typename Pair>
527#define UB_STATIC_ASSERT(expr) static_cast<void>(sizeof(ub_system::ub_static_assert<expr>));
std::shared_ptr< T > SPtr
#define UBLOG(level, logtext)
std::string toUpperString(const std::string &str)
unsigned long getCurrentThreadID()
void unsetBit(T &value, const T &bitmask)
bool makeDirectory(const std::string &dir)
void setBit(T &value, const T &bitmask)
std::string toString(const T &x, int precision=15)
std::string getBitString(const T &value)
int removeDirectory(const std::string &dir)
std::string getTimeStamp()
bool isDirectory(const std::string &dir, const unsigned &=3)
void sleepMs(const unsigned int &msec)
void sleepS(const unsigned int &sec)
std::string toLowerString(const std::string &str)
std::string getMachineName()
std::string getPathFromString(const std::string &fileStringWithPath)
void swapByteOrder(unsigned char *toSwap, int length)
T stringTo(const std::string &s)
bool bitCheck(const T &value, const T &bitmask)
std::string getEnv(const std::string &var)
std::string getFilenameFromString(const std::string &fileStringWithPath, bool withExtension=true)
const result_type & operator()(const argument_type &p) const
typename Pair::first_type result_type
typename Pair::second_type result_type
const result_type & operator()(const argument_type &p) const