Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBretcode Class Reference

Handle numerical return code combined with a set of text messages. More...

#include "CTBretcode.hxx"

List of all members.

Public Methods

 CTBretcode ()
 CTBretcode (int i_code)
 CTBretcode (int i_code, const char *c_text1)
 CTBretcode (int i_code, const char *c_text1, const char *c_text2)
 CTBretcode (int i_code, const char *c_text1, const char *c_text2, const char *c_text3)
 CTBretcode (int i_code, int i_errno)
 CTBretcode (int i_code, const char *c_text1, int i_errno)
 CTBretcode (int i_code, const CTBretcode &rc)
 CTBretcode (int i_code, const char *c_text1, const CTBretcode &rc)
 CTBretcode (const CTBretcode &rhs)
void Set (int i_code)
void Set (int i_code, const char *c_text1)
void Set (int i_code, const char *c_text1, const char *c_text2)
void Set (int i_code, const char *c_text1, const char *c_text2, const char *c_text3)
void Set (int i_code, int i_errno)
void Set (int i_code, const char *c_text1, int i_errno)
void Set (int i_code, const CTBretcode &rc)
void Set (int i_code, const char *c_text1, const CTBretcode &rc)
int Code () const
int Errno () const
const char * Text1 () const
const char * Text2 () const
const char * Text3 () const
void ToStream (ostream &os=cout) const
bool operator! () const
 operator int () const
 operator const char * () const
CTBretcode & operator= (const CTBretcode &rhs)
CTBretcode & operator= (int i_code)

Private Attributes

int mi_code
int mi_errno
const char * mc_text1
const char * mc_text2
const char * mc_text3

Related Functions

(Note that these are not member functions.)

ostream & operator<< (ostream &os, const CTBretcode &obj)


Detailed Description

Handle numerical return code combined with a set of text messages.

This class allows to pass both a numerical return code, the system errno and a set of up to 3 text messages in an efficient way. The numerical return code is usually used to control the flow in the calling routine, while the text messages and the stored errno value are by and large used to generate notifications.

CTBretcode handles one integer return code and three strings, in the following called text1, text2, and text3. The first string should be a textural representation of the return code, while the other two can be used to express qualifications and specializations.

The implementation of CTBretcode assumes that all const char* pointers passed to constructors and Set() methods refer to character strings with infinite life time. In general one should only pass pointers to string constants or a string literal for any of the c_text arguments.

The text messages should in general have no embedded or trailing newlines. However, the ToStream() method is tolerant to trailing newlines.

There is a range of constructors to setup the code and text fields, and also a set of Set() methods with corresponding argument lists.

Two constructors and corresponding Set() methods allow to setup a CTBretcode object with a text message derived from a system error code, usually taken from errno.

Two constructor and corresponding Set() methods allow to use the text messages from another CTBretcode object. This is in particular useful when a return code is passed through several layers of calls.

Definition at line 16 of file CTBretcode.hxx.


Constructor & Destructor Documentation

CTBretcode::CTBretcode [inline]
 

Default constructor: sets code=0.

Definition at line 17 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code [inline]
 

Constructor: set code, no text.

Definition at line 28 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const char * c_text1
[inline]
 

Constructor: set code and text1.

Definition at line 39 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const char * c_text1,
const char * c_text2
[inline]
 

Constructor: set code, text1, and text2.

Definition at line 50 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const char * c_text1,
const char * c_text2,
const char * c_text3
[inline]
 

Constructor: set code, text1, text2, and text3.

Definition at line 62 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
int i_errno
[inline]
 

Constructor: set code and errno.

This form is useful after a standart library routine returned with an error. The message text, when printed with ToStream , will be derived from i_errno and thus not indicate the environment of the error.

    if(tcgetattr(mi_fd, &m_oldtios) == -1) {
      return CTBretcode(err_xxx,errno);
    }

Definition at line 84 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const char * c_text1,
int i_errno
[inline]
 

Constructor: set code, errno, and text1.

This form is useful after a standart library routine returned with an error.

    if(tcgetattr(mi_fd, &m_oldtios) == -1) {
      return CTBretcode(err_xxx,"tcgetattr failed",errno);
    }
The return code will be err_xxx, the primary message text, here "tcgetattr failed", describes the environment of the problem while the secondary message text will be derived from the value of errno and will describe the details.

Definition at line 108 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const CTBretcode & rc
[inline]
 

Constructor: set code, use text from rc.

This form allows to set the code but take all the text messages from another CTBretcode object. This can be useful when passing a return code up in a call hierarchy, like in

    CTBretcode rc;
    ..
      rc = foo();
      if (!rc) return CTBretcode(err_xxx,rc);

Definition at line 130 of file CTBretcode.icc.

CTBretcode::CTBretcode int i_code,
const char * c_text1,
const CTBretcode & rc
[inline]
 

Constructor: set code and text1, get text2 and text3 from rc.

This form allows to set the code and the primary message and setup the secondary and ternary message from another CTBretcode object. Note, that text2 is taken from rc.Text1() and text3 from rc.Text2(). This can be useful when passing a return code up in a call hierarchy, like in

    CTBretcode rc;
    ..
      rc = foo();
      if (rc) return CTBretcode(err_xxx,"error in foo()",rc);

Definition at line 153 of file CTBretcode.icc.

CTBretcode::CTBretcode const CTBretcode & rhs [inline]
 

Copy constructor.

Definition at line 165 of file CTBretcode.icc.


Member Function Documentation

void CTBretcode::Set int i_code [inline]
 

Set code to i_code, clear errno and all text.

Definition at line 176 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const char * c_text1
[inline]
 

Set code and text1.

Definition at line 189 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const char * c_text1,
const char * c_text2
[inline]
 

Set code, text1, and text2.

Definition at line 202 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const char * c_text1,
const char * c_text2,
const char * c_text3
[inline]
 

Set code, text1, text2, and text3.

Definition at line 216 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
int i_errno
[inline]
 

Set code and errno.

See also corresponding contructor CTBretcode(int i_code, int i_errno).

Definition at line 233 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const char * c_text1,
int i_errno
[inline]
 

Set code, errno and text1.

See also corresponding constructor CTBretcode(int i_code, const char* c_text1, int i_errno).

Definition at line 250 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const CTBretcode & rc
[inline]
 

Set code, use text from rc.

Definition at line 263 of file CTBretcode.icc.

void CTBretcode::Set int i_code,
const char * c_text1,
const CTBretcode & rc
[inline]
 

Set code and text1, get text2 and text3 from rc.

Definition at line 276 of file CTBretcode.icc.

int CTBretcode::Code const [inline]
 

Returns numerical return code.

Definition at line 290 of file CTBretcode.icc.

int CTBretcode::Errno const [inline]
 

Returns stored errno.

Definition at line 298 of file CTBretcode.icc.

const char * CTBretcode::Text1 const [inline]
 

Returns 1st text message.

Definition at line 306 of file CTBretcode.icc.

const char * CTBretcode::Text2 const [inline]
 

Returns 2nd text message.

Definition at line 314 of file CTBretcode.icc.

const char * CTBretcode::Text3 const [inline]
 

Returns 3rd text message.

Definition at line 322 of file CTBretcode.icc.

void CTBretcode::ToStream ostream & os = cout const
 

ostream insertion.

The CTBretcode object is represented with one line per text message, like

    text1
    - text2
    - text3
    - text(errno)
If no text1 and no errno was defined, a one line message of the form
    Return code: nnn
is generated. This method generates one and only one newline after each defined text message.

Definition at line 96 of file CTBretcode.cxx.

Referenced by operator<<().

bool CTBretcode::operator! const [inline]
 

Returns true if code==0.

This operator method allows to use a CTBretcode like a conventional integer return code:

    CTBretcode rc;
    ..
      rc = foo();
      if (!rc) {
        ..          // executed if foo() succeded
      }

Definition at line 342 of file CTBretcode.icc.

CTBretcode::operator int const [inline]
 

Convert to int: returns numerical return code.

Definition at line 350 of file CTBretcode.icc.

CTBretcode::operator const char * const
 

Convert to char* : returns 1st text message or errno text if code != 0.

This conversion method returns a null if Code() is zero, otherwise the Text1() text, a pointer to a string derived from Errno() , and in case Errno() is zero, a zero length string ("").

This somewhat contrived semantics is necessary to have consistent behavior with operator int() and operator!() .

Definition at line 132 of file CTBretcode.cxx.

CTBretcode & CTBretcode::operator= const CTBretcode & rhs [inline]
 

Copy CTBretcode object.

Definition at line 358 of file CTBretcode.icc.

CTBretcode & CTBretcode::operator= int i_code [inline]
 

Set code to i_code, clear errno and all text.

Definition at line 371 of file CTBretcode.icc.


Friends And Related Function Documentation

ostream & operator<< ostream & os,
const CTBretcode & obj
[related]
 

ostream insertion operator, forwards to ToStream().

Definition at line 387 of file CTBretcode.icc.


Member Data Documentation

int CTBretcode::mi_code [private]
 

return code.

Definition at line 70 of file CTBretcode.hxx.

int CTBretcode::mi_errno [private]
 

associated errno.

Definition at line 71 of file CTBretcode.hxx.

const char* CTBretcode::mc_text1 [private]
 

1st message text.

Definition at line 72 of file CTBretcode.hxx.

const char* CTBretcode::mc_text2 [private]
 

2nd message text.

Definition at line 73 of file CTBretcode.hxx.

const char* CTBretcode::mc_text3 [private]
 

3rd message text.

Definition at line 74 of file CTBretcode.hxx.


The documentation for this class was generated from the following files:
Generated at Fri Oct 24 18:14:04 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001