sdhexception.cpp
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 #include "sdhlibrary_settings.h"
31 #include <cstring> // needed in gcc-4.3 for prototypes like strcmp according to http://gcc.gnu.org/gcc-4.3/porting_to.html
32 
33 #if SDH_USE_VCC
34 # pragma warning(disable : 4996)
35 #endif
36 
37 //----------------------------------------------------------------------
38 // System Includes - include with <>
39 //----------------------------------------------------------------------
40 
41 //----------------------------------------------------------------------
42 // Project Includes - include with ""
43 //----------------------------------------------------------------------
44 
45 #include "sdhexception.h"
46 
47 //----------------------------------------------------------------------
48 // Defines, enums, unions, structs,
49 //----------------------------------------------------------------------
50 
52 
53 
54 //----------------------------------------------------------------------
55 // Global variables
56 //----------------------------------------------------------------------
57 
58 
59 //----------------------------------------------------------------------
60 // Function and class member implementation (function definitions)
61 //----------------------------------------------------------------------
62 
63 
65 {
66  msg[0] = '\0';
67 }
68 //----------------------------------------------------------------------
69 
70 
71 cMsg::cMsg( cMsg const & other )
72 {
73  strncpy( msg, other.msg, eMAX_MSG );
74 }
75 //----------------------------------------------------------------------
76 
77 
78 cMsg::cMsg( char const* fmt, ... )
79 {
80  va_list arglist;
81  va_start( arglist, fmt );
82  vsnprintf( msg, eMAX_MSG, fmt, arglist );
83  va_end( arglist );
84 }
85 //----------------------------------------------------------------------
86 
87 
88 char const *cMsg::c_str() const
89 {
90  return msg;
91 }
92 //----------------------------------------------------------------------
93 
95 
96 std::ostream &operator<<(std::ostream &stream, cMsg const &msg)
97 {
98  return stream << msg.c_str();
99 }
100 
102 
103 //======================================================================
104 
105 
106 cSDHLibraryException::cSDHLibraryException( char const * _type, cMsg const & _msg )
107  :
108  // call constructor of base class:
109  std::exception(),
110 
111  // call constructor of members:
112  msg( "%s: %s", _type, _msg.c_str() )
113 {
114  // nothing more to do here
115 }
116 //----------------------------------------------------------------------
117 
118 const char* cSDHLibraryException::what() const throw()
119 {
120  return msg.c_str();
121 }
122 //----------------------------------------------------------------------
123 
124 
126 
127 std::ostream &operator<<(std::ostream &stream, cSDHLibraryException const &e)
128 {
129  return stream << e.what();
130 }
131 
133 
134 //======================================================================
135 
136 
137 
138 //======================================================================
139 /*
140  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
141  (e.g. to explicitely set C++ mode for *.h header files)
142 
143  Local Variables:
144  mode:C++
145  mode:ELSE
146  End:
147 */
148 //======================================================================
cMsg msg
The message object.
Definition: sdhexception.h:137
maximum length in bytes of a message to store
Definition: sdhexception.h:83
NAMESPACE_SDH_START std::ostream & operator<<(std::ostream &stream, cMsg const &msg)
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
#define NAMESPACE_SDH_START
char msg[eMAX_MSG]
Definition: sdhexception.h:86
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
virtual const char * what() const
#define USING_NAMESPACE_SDH
#define NAMESPACE_SDH_END
This file contains settings to make the SDHLibrary compile on differen systems:
cSDHLibraryException(char const *_type, cMsg const &_msg)
char const * c_str() const
Return the C-string representation of the messag in this object.
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77
cMsg()
Default constructor, init message to empty string.


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Sun Aug 18 2019 03:42:20