34 #ifndef ERRUT_BOOLTYPE_H
36 #define ERRUT_BOOLTYPE_H
38 #include "errutconfig.h"
45 #define ERRUT_BOOL_T_LEN 2048
46 #define ERRUT_BOOL_T_FAILMSG "Unknown error"
47 #define ERRUT_BOOL_T_SUCCESSMSG "Success"
70 bool_t(
const std::string &err);
79 std::string getErrorString()
const;
82 operator bool()
const;
87 void strncpy(
const char *pSrc);
88 void setErrorString(
const std::string &err);
89 void setErrorString(
const char *pStr);
91 char m_errorString[ERRUT_BOOL_T_LEN];
99 setErrorString(ERRUT_BOOL_T_FAILMSG);
104 setErrorString(pStr);
112 inline void bool_t::strncpy(
const char *pSrc)
115 ::strncpy(m_errorString, pSrc, ERRUT_BOOL_T_LEN);
117 strncpy_s(m_errorString, ERRUT_BOOL_T_LEN, pSrc, _TRUNCATE);
119 m_errorString[ERRUT_BOOL_T_LEN-1] = 0;
124 if (b.m_errorString[0] == 0)
125 m_errorString[0] = 0;
127 strncpy(b.m_errorString);
130 inline void bool_t::setErrorString(
const std::string &s)
132 setErrorString(s.c_str());
135 inline void bool_t::setErrorString(
const char *pStr)
137 if (pStr == 0 || pStr[0] == 0)
138 strncpy(ERRUT_BOOL_T_FAILMSG);
145 if (b.m_errorString[0] == 0)
146 m_errorString[0] = 0;
148 strncpy(b.m_errorString);
155 if (m_errorString[0] == 0)
156 return ERRUT_BOOL_T_SUCCESSMSG;
157 return m_errorString;
160 inline bool_t::operator bool()
const
167 return (m_errorString[0] == 0);
Type to return true/false with error description.
Definition: booltype.h:61
bool_t(bool f=true)
Just set true or false, but leave the error description undefined in case of 'false'.
Definition: booltype.h:94
std::string getErrorString() const
Returns a description of the error.
Definition: booltype.h:153
bool success() const
Returns true or false, depending on the contents of this object.
Definition: booltype.h:165
bool_t & operator=(const bool_t &b)
Assignment operator.
Definition: booltype.h:143