OSDN Git Service

Add new file.
[ultramonkey-l7/ultramonkey-l7-v3.git] / include / error_code.h
1 #ifndef ERROR_CODE_H
2 #define ERROR_CODE_H
3 //
4 // (C) Copyright 2009- Norihisa Nakai
5 // Distributed under the Boost Software License, Version 1.0
6 // (See accompanying file LICENSE_1_0.txt http://www.boost.org/LICENSE_1_0.txt)
7
8 #include <string>
9
10 namespace ultramonkey{
11
12 //! @class      error_code
13 //!     @brief  getValue error
14 //! @brief      this class is POD
15 class   error_code{
16 protected:
17         bool            flag;   //!<    errorcode flag
18         std::string     msg;    //!<    errorcode message
19 public:
20         error_code() : flag(false){}    //!< constractor
21         //! setter constractor
22         //! @param[in]  flags
23         //! @param[in]  error message
24         error_code( const bool inflg, const std::string& instr ) : flag( inflag ), msg( instr ){}
25         bool    operator==( const bool in ) const { return ( flag == in ); } //!< operator== orverload
26         bool    operator!=( const bool in ) const { return ( flag != in ); } //!< operator!= orverload
27         bool    operator!() const { return !flag; } //!< operator! orverload
28         typedef void (*unspecified_bool_type)();        //!< if return function
29         static void unspecified_bool_true() {}          //!< if true orverload function
30         operator unspecified_bool_type() const { return flag == 0 ? 0 : unspecified_bool_true; } //!< if() orverload
31         const std::string&      get_message() const { return msg; }             //!< message getter
32         //! error setter
33         //! @param[in]  flags
34         //! @param[in]  error message
35         void    setter( const bool flg, const std::string& instr ){
36                 flag = flg;
37                 msg = instr;
38         }
39 };
40
41 }       // ultramonkey
42
43 #endif // ERROR_CODE_H