XRootD
XrdOucECMsg.hh
Go to the documentation of this file.
1 #ifndef __OUC_ECMSG_H__
2 #define __OUC_ECMSG_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c E C M s g . h h */
6 /* */
7 /* (c) 2023 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 
33 #include <cstdarg>
34 #include <string>
35 
37 {
38 public:
39 
40 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 
50 XrdOucECMsg& Append(char dlm='\n') {Delim = dlm; return *this;}
51 
52 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 
61 int Get(std::string& ecm, bool rst=true);
62 
63 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 
69 bool hasMsg() const {return !ecMsg.empty();}
70 
71 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
76 
77 std::string& Msg() {return ecMsg;}
78 
79 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
87 
88 void Msg(const char* pfx, const char* txt1,
89  const char* txt2=0, const char* txt3=0,
90  const char* txt4=0, const char* txt5=0);
91 
92 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 
103 void Msgf(const char *pfx, const char *fmt, ...);
104 
105 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 
116 void MsgVA(const char *pfx, const char *fmt, std::va_list aP);
117 
118 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
128 
129 void MsgVec(const char* pfx, char const* const* vecP, int vecN);
130 
131 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
137 
138 void Set(int ecc, const char* ecm="") {eCode = ecc; if (ecm) ecMsg = ecm;}
139 
140 void Set(int ecc, std::string& ecm) {eCode = ecc; ecMsg = ecm;}
141 
142 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
151 
152 int SetErrno(int ecc, int retval=-1, const char *alt=0);
153 
154 //-----------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
157 
158  XrdOucECMsg& operator=(const int rhs) {eCode = rhs; return *this;};
159 
160  XrdOucECMsg& operator=(const std::string& rhs) {ecMsg = rhs; return *this;};
161 
162  XrdOucECMsg& operator=(const char* rhs) {ecMsg = rhs; return *this;};
163 
165  {ecMsg = rhs.ecMsg; eCode = rhs.eCode; return *this;};
166 
167  XrdOucECMsg(const char *msgid=0) : msgID(msgid) {}
169 
170 private:
171 
172 void Setup(const char *pfx, int n);
173 const char* msgID;
174 std::string ecMsg;
175 int eCode = 0;
176 char Delim = 0;
177 };
178 #endif
bool hasMsg() const
Definition: XrdOucECMsg.hh:69
std::string & Msg()
Definition: XrdOucECMsg.hh:77
XrdOucECMsg & operator=(const std::string &rhs)
Definition: XrdOucECMsg.hh:160
XrdOucECMsg & operator=(const int rhs)
Assignment operators for convenience.
Definition: XrdOucECMsg.hh:158
void MsgVA(const char *pfx, const char *fmt, std::va_list aP)
Definition: XrdOucECMsg.cc:112
XrdOucECMsg & operator=(const char *rhs)
Definition: XrdOucECMsg.hh:162
XrdOucECMsg(const char *msgid=0)
Definition: XrdOucECMsg.hh:167
void Set(int ecc, const char *ecm="")
Definition: XrdOucECMsg.hh:138
int Get(std::string &ecm, bool rst=true)
Definition: XrdOucECMsg.cc:41
void Set(int ecc, std::string &ecm)
Definition: XrdOucECMsg.hh:140
void MsgVec(const char *pfx, char const *const *vecP, int vecN)
Definition: XrdOucECMsg.cc:131
XrdOucECMsg & Append(char dlm='\n')
Definition: XrdOucECMsg.hh:50
XrdOucECMsg & operator=(XrdOucECMsg &rhs)
Definition: XrdOucECMsg.hh:164
int SetErrno(int ecc, int retval=-1, const char *alt=0)
Definition: XrdOucECMsg.cc:144
void Msgf(const char *pfx, const char *fmt,...)
Definition: XrdOucECMsg.cc:91