w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RerrMsg.cpp
Go to the documentation of this file.
1// $Id: RerrMsg.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-21 1090 1.2.1 use constructor delegation
8// 2013-01-12 474 1.2 add meth+text and meth+text+errnum ctors
9// 2011-02-06 359 1.1 use references in interface, fix printf usage
10// 2011-01-15 356 1.0 Initial version
11// ---------------------------------------------------------------------------
12
17#include <string.h>
18#include <stdio.h>
19#include <stdarg.h>
20
21#include "RerrMsg.hpp"
22
23using namespace std;
24
30// all method definitions in namespace Retro
31namespace Retro {
32
33//------------------------------------------+-----------------------------------
35
37 : fMeth(),
38 fText()
39{}
40
41//------------------------------------------+-----------------------------------
43
45 : RerrMsg(rhs.fMeth, rhs.fText)
46{}
47
48//------------------------------------------+-----------------------------------
50
51RerrMsg::RerrMsg(const std::string& meth, const std::string& text)
52 : fMeth(meth),
53 fText(text)
54{}
55
56//------------------------------------------+-----------------------------------
58
59RerrMsg::RerrMsg(const std::string& meth, const std::string& text, int errnum)
60 : RerrMsg(meth, text)
61{
62 AppendErrno(errnum);
63}
64
65//------------------------------------------+-----------------------------------
67
69{}
70
71//------------------------------------------+-----------------------------------
73
74void RerrMsg::Init(const std::string& meth, const std::string& text)
75{
76 fMeth = meth;
77 fText = text;
78 return;
79}
80
81//------------------------------------------+-----------------------------------
83
84void RerrMsg::InitErrno(const std::string& meth,
85 const std::string& text, int errnum)
86{
87 fMeth = meth;
88 fText = text;
89 AppendErrno(errnum);
90 return;
91}
92
93//------------------------------------------+-----------------------------------
95
96void RerrMsg::InitPrintf(const std::string& meth, const char* format, ...)
97{
98 fMeth = meth;
99
100 char buf[1024];
101 buf[0] = 0;
102
103 va_list ap;
104 va_start (ap, format);
105 vsnprintf (buf, sizeof(buf), format, ap);
106 va_end (ap);
107
108 fText = buf;
109
110 return;
111}
112
113//------------------------------------------+-----------------------------------
115
116void RerrMsg::Prepend(const std::string& meth)
117{
118 fMeth = meth + "->" + fMeth;
119 return;
120}
121
122//------------------------------------------+-----------------------------------
124
125void RerrMsg::Append(const std::string& text)
126{
127 fText += text;
128 return;
129}
130
131//------------------------------------------+-----------------------------------
133
134void RerrMsg::AppendErrno(int errnum)
135{
136 fText += strerror(errnum);
137 return;
138}
139
140//------------------------------------------+-----------------------------------
142
143void RerrMsg::AppendPrintf(const char* format, ...)
144{
145 char buf[1024];
146 buf[0] = 0;
147
148 va_list ap;
149 va_start (ap, format);
150 vsnprintf (buf, sizeof(buf), format, ap);
151 va_end (ap);
152
153 fText += buf;
154
155 return;
156}
157
158//------------------------------------------+-----------------------------------
160
161std::string RerrMsg::Message() const
162{
163 return fMeth + ": " + fText;
164}
165
166//------------------------------------------+-----------------------------------
168
170{
171 fMeth.swap(rhs.fMeth);
172 fText.swap(rhs.fText);
173 return;
174}
175
176//------------------------------------------+-----------------------------------
178
180{
181 if (&rhs == this) return *this;
182 fMeth = rhs.fMeth;
183 fText = rhs.fText;
184 return *this;
185}
186
187} // end namespace Retro
FIXME_docs.
Definition: RerrMsg.hpp:25
std::string fText
message text
Definition: RerrMsg.hpp:59
~RerrMsg()
Destructor.
Definition: RerrMsg.cpp:68
RerrMsg & operator=(const RerrMsg &rhs)
FIXME_docs.
Definition: RerrMsg.cpp:179
void Init(const std::string &meth, const std::string &text)
FIXME_docs.
Definition: RerrMsg.cpp:74
void Prepend(const std::string &meth)
FIXME_docs.
Definition: RerrMsg.cpp:116
void AppendErrno(int errnum)
FIXME_docs.
Definition: RerrMsg.cpp:134
std::string fMeth
originating method
Definition: RerrMsg.hpp:58
RerrMsg()
Default constructor.
Definition: RerrMsg.cpp:36
void AppendPrintf(const char *format,...)
FIXME_docs.
Definition: RerrMsg.cpp:143
void Append(const std::string &text)
FIXME_docs.
Definition: RerrMsg.cpp:125
void InitPrintf(const std::string &meth, const char *format,...)
FIXME_docs.
Definition: RerrMsg.cpp:96
void Swap(RerrMsg &rhs)
FIXME_docs.
Definition: RerrMsg.cpp:169
std::string Message() const
FIXME_docs.
Definition: RerrMsg.cpp:161
void InitErrno(const std::string &meth, const std::string &text, int errnum)
FIXME_docs.
Definition: RerrMsg.cpp:84
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47