OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librtools/] [RerrMsg.cpp] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
// $Id: RerrMsg.cpp 493 2013-03-01 21:02:33Z mueller $
2 10 wfjm
//
3 19 wfjm
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 10 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 19 wfjm
// 2013-01-12   474   1.2    add meth+text and meth+text+errnum ctors
17 10 wfjm
// 2011-02-06   359   1.1    use references in interface, fix printf usage
18
// 2011-01-15   356   1.0    Initial version
19
// ---------------------------------------------------------------------------
20
 
21
/*!
22
  \file
23 19 wfjm
  \version $Id: RerrMsg.cpp 493 2013-03-01 21:02:33Z mueller $
24 10 wfjm
  \brief   Implemenation of RerrMsg.
25
*/
26
 
27
#include <string.h>
28
#include <stdio.h>
29
#include <stdarg.h>
30
 
31
#include "RerrMsg.hpp"
32
 
33
using namespace std;
34
 
35
/*!
36
  \class Retro::RerrMsg
37
  \brief FIXME_docs
38
*/
39
 
40 19 wfjm
// all method definitions in namespace Retro
41
namespace Retro {
42
 
43 10 wfjm
//------------------------------------------+-----------------------------------
44
//! Default constructor
45
 
46
RerrMsg::RerrMsg()
47
  : fMeth(),
48
    fText()
49
{}
50
 
51
//------------------------------------------+-----------------------------------
52 19 wfjm
//! Copy constructor
53 10 wfjm
 
54
RerrMsg::RerrMsg(const RerrMsg& rhs)
55
  : fMeth(rhs.fMeth),
56
    fText(rhs.fText)
57
{}
58
 
59
//------------------------------------------+-----------------------------------
60 19 wfjm
//! Construct from method and message text
61
 
62
RerrMsg::RerrMsg(const std::string& meth, const std::string& text)
63
  : fMeth(meth),
64
    fText(text)
65
{}
66
 
67
//------------------------------------------+-----------------------------------
68
//! Construct from method and message text and errno
69
 
70
RerrMsg::RerrMsg(const std::string& meth, const std::string& text, int errnum)
71
  : fMeth(meth),
72
    fText(text)
73
{
74
  AppendErrno(errnum);
75
}
76
 
77
//------------------------------------------+-----------------------------------
78 10 wfjm
//! Destructor
79
 
80
RerrMsg::~RerrMsg()
81
{}
82
 
83
//------------------------------------------+-----------------------------------
84
//! FIXME_docs
85
 
86
void RerrMsg::Init(const std::string& meth, const std::string& text)
87
{
88
  fMeth = meth;
89
  fText = text;
90
  return;
91
}
92
 
93
//------------------------------------------+-----------------------------------
94
//! FIXME_docs
95
 
96
void RerrMsg::InitErrno(const std::string& meth,
97
                        const std::string& text, int errnum)
98
{
99
  fMeth = meth;
100
  fText = text;
101
  AppendErrno(errnum);
102
  return;
103
}
104
 
105
//------------------------------------------+-----------------------------------
106
//! FIXME_docs
107
 
108
void RerrMsg::InitPrintf(const std::string& meth, const char* format, ...)
109
{
110
  fMeth = meth;
111
 
112
  char buf[1024];
113
  buf[0] = 0;
114
 
115
  va_list ap;
116
  va_start (ap, format);
117
  vsnprintf (buf, sizeof(buf), format, ap);
118
  va_end (ap);
119
 
120
  fText = buf;
121
 
122
  return;
123
}
124
 
125
//------------------------------------------+-----------------------------------
126
//! FIXME_docs
127
 
128
void RerrMsg::Prepend(const std::string& meth)
129
{
130
  fMeth = meth + "->" + fMeth;
131
  return;
132
}
133
 
134
//------------------------------------------+-----------------------------------
135
//! FIXME_docs
136
 
137
void RerrMsg::Append(const std::string& text)
138
{
139
  fText += text;
140
  return;
141
}
142
 
143
//------------------------------------------+-----------------------------------
144
//! FIXME_docs
145
 
146
void RerrMsg::AppendErrno(int errnum)
147
{
148
  fText += strerror(errnum);
149
  return;
150
}
151
 
152
//------------------------------------------+-----------------------------------
153
//! FIXME_docs
154
 
155
void RerrMsg::AppendPrintf(const char* format, ...)
156
{
157
  char buf[1024];
158
  buf[0] = 0;
159
 
160
  va_list ap;
161
  va_start (ap, format);
162
  vsnprintf (buf, sizeof(buf), format, ap);
163
  va_end (ap);
164
 
165
  fText += buf;
166
 
167
  return;
168
}
169
 
170
//------------------------------------------+-----------------------------------
171
//! FIXME_docs
172
 
173
std::string RerrMsg::Message() const
174
{
175
  return fMeth + ": " + fText;
176
}
177
 
178
//------------------------------------------+-----------------------------------
179
//! FIXME_docs
180
 
181 19 wfjm
void RerrMsg::Swap(RerrMsg& rhs)
182 10 wfjm
{
183
  fMeth.swap(rhs.fMeth);
184
  fText.swap(rhs.fText);
185
  return;
186
}
187
 
188
//------------------------------------------+-----------------------------------
189
//! FIXME_docs
190
 
191
RerrMsg& RerrMsg::operator=(const RerrMsg& rhs)
192
{
193
  if (&rhs == this) return *this;
194
  fMeth = rhs.fMeth;
195
  fText = rhs.fText;
196
  return *this;
197
}
198
 
199 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.