xrootd
XrdSsiErrInfo.hh
Go to the documentation of this file.
1 #ifndef __XRDSSIERRINFO_HH__
2 #define __XRDSSIERRINFO_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d S s i E r r I n f o . h h */
6 /* */
7 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <string>
33 #include <string.h>
34 
35 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 
41 {
42 public:
43 
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 
48  void Clr() {errText.clear(); errArg = errNum = 0;}
49 
50 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 
58 const
59 std::string &Get(int &eNum) const {eNum = errNum; return errText;}
60 
61 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
66 
67 const
68 std::string &Get() const {return errText;}
69 
70 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 
76  int GetArg() const {return errArg;}
77 
78 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 
84  bool hasError() const {return errNum != 0;}
85 
86 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
91 
92  bool isOK() const {return errNum == 0;}
93 
94 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 
103  void Set(const char *eMsg=0, int eNum=0, int eArg=0)
104  {errText = (eMsg && *eMsg ? eMsg : Errno2Text(eNum));
105  errNum = eNum;
106  errArg = eArg;
107  }
108 
109  void Set(const std::string &eMsg, int eNum=0, int eArg=0)
110  {errText = (eMsg.empty() ? Errno2Text(eNum) : eMsg);
111  errNum = eNum;
112  errArg = eArg;
113  }
114 
115 //------------------------------------------------------------------------------
117 //------------------------------------------------------------------------------
118 
120  {if (&rhs != this) Set(rhs.errText, rhs.errNum, rhs.errArg);
121  return *this;
122  }
123 
124 //------------------------------------------------------------------------------
126 //------------------------------------------------------------------------------
127 
129  {Set(oP.errText, oP.errNum, oP.errArg);}
130 
131 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
134 
136 
138 
139 private:
140 const char* Errno2Text(int ecode);
141 
142 std::string errText;
143 int errNum;
144 int errArg;
145 };
146 #endif
std::string errText
Definition: XrdSsiErrInfo.hh:142
void Clr()
Reset and clear error information.
Definition: XrdSsiErrInfo.hh:48
XrdSsiErrInfo & operator=(XrdSsiErrInfo const &rhs)
Assignment operator.
Definition: XrdSsiErrInfo.hh:119
int errArg
Definition: XrdSsiErrInfo.hh:144
const char * Errno2Text(int ecode)
void Set(const char *eMsg=0, int eNum=0, int eArg=0)
Definition: XrdSsiErrInfo.hh:103
XrdSsiErrInfo(XrdSsiErrInfo const &oP)
Copy constructor.
Definition: XrdSsiErrInfo.hh:128
~XrdSsiErrInfo()
Definition: XrdSsiErrInfo.hh:137
int errNum
Definition: XrdSsiErrInfo.hh:143
void Set(const std::string &eMsg, int eNum=0, int eArg=0)
Definition: XrdSsiErrInfo.hh:109
bool hasError() const
Definition: XrdSsiErrInfo.hh:84
Definition: XrdSsiErrInfo.hh:40
bool isOK() const
Definition: XrdSsiErrInfo.hh:92
XrdSsiErrInfo()
Constructor and Destructor.
Definition: XrdSsiErrInfo.hh:135
const std::string & Get() const
Definition: XrdSsiErrInfo.hh:68
int GetArg() const
Definition: XrdSsiErrInfo.hh:76
const std::string & Get(int &eNum) const
Definition: XrdSsiErrInfo.hh:59