Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PMError Class Reference

Transport class for error values. More...

#include <PMError.h>

List of all members.

Public Types

enum  ErrClass {
  C_Error = 0, C_InstSrcError = 10*_valrange, C_MediaError = 11*_valrange, C_InstTargetError = 12*_valrange,
  C_YouError = 14*_valrange, C_ModulePkgError = 15*_valrange
}
enum  Error { E_TBD = C_Error+1 }

Public Member Functions

 PMError (const unsigned e=E_ok)
 PMError (const unsigned e, const std::string &details)
 operator unsigned () const
std::string errstr () const
ErrClass errClass () const
void addDetails (const std::string &)
void setDetails (const std::string &details)
std::string details () const
std::string asString () const

Static Public Member Functions

static std::string errstr (const unsigned e)
static ErrClass errClass (const unsigned e)

Public Attributes

unsigned _errval
std::string _errdetails

Static Public Attributes

static const unsigned E_ok = 0
static const unsigned E_error = 1
static const std::string OKstring
static const std::string ERRORstring

Static Private Member Functions

static std::string defaulterrstr (const std::string &cl, const std::string &txt)

Static Private Attributes

static const unsigned _valrange = 0x400
static const unsigned _valmask = _valrange-1
static const unsigned _repmask = ~_valmask
static const std::string errstrPrefix

Friends

std::ostream & operator<< (std::ostream &str, const PMError &obj)


Detailed Description

Transport class for error values.

Quite simple approach. Error values are unsigned. E_ok (== 0) means no error.

Conversion of error values to string, or writing to ostreams, per default prints the error number as ERROR(10242) ("ERROR" is translatable). For E_ok OK (also translatable) is printed.

Primitive support for error classes: Assume a class InstSrcError providing nothing but an enum of common InstSrc error values. Returning those error values through PMError, errors originating from this class will be reported as ERROR(InstSrc:short description of error), if an error text is provided, otherwise ERROR(InstSrc:10242).

An optional details string may be provided to give further explanation.

To accomplish this extend enum ErrClass and define a new first error value for InstSrcError in multiples of _valrange (currently 1024). Extend the switches in PMError::errClass and PMError::errstr by cases for the new enum value. By this _valrange error numbers starting at C_InstSrcError are assigned to class InstSrcError.

     enum ErrClass {
       ...
       C_InstSrcError = 10*_valrange
     };
 

Now define class InstSrcError.

errclass defines the string to be used as error class name. errtext must return the text describing the error, or the numerical value as string. Error values will be printed as ERROR(errclass:errtext(err)).

 include <y2pm/PMError.h>

 ///////////////////////////////////////////////////////////////////
 //
 //	CLASS NAME : InstSrcError
 //
 class InstSrcError {

   private:

     friend class PMError;

     static const std::string errclass;

     static std::string errtext( const unsigned e );

   public:

     enum Error {
       E_ok    = PMError::E_ok,           // E_ok is always 0
       E_error = PMError::C_InstSrcError, // C_InstSrcError first error value for InstSrcError
       E_no_media,
       ...
     };
 };

 ///////////////////////////////////////////////////////////////////
 
Implementation will look like this:
 include <y2pm/InstSrcError.h>

 using namespace std;

 ///////////////////////////////////////////////////////////////////
 ifndef N_
 #  define N_(STR) STR
 endif
 ///////////////////////////////////////////////////////////////////

 // define the error class name
 const std::string InstSrcError::errclass( "InstSrc" );

 ///////////////////////////////////////////////////////////////////
 //
 //
 //	METHOD NAME : InstSrcError::errtext
 //	METHOD TYPE : std::string
 //
 //	DESCRIPTION : Return textual description or numerical value
 //     as string;
 //
 std::string InstSrcError::errtext( const unsigned e )
 {
   switch ( (Error)e ) {

   case E_ok:       return PMError::OKstring;
   case E_error:    return N_("error");
   case E_no_media: return N_("no media");
   ...

   ///////////////////////////////////////////////////////////////////
   // no default: let compiler warn '... not handled in switch'
   ///////////////////////////////////////////////////////////////////
   };

   return stringutil::numstring( e );
 }
 


Member Enumeration Documentation

enum PMError::ErrClass
 

Enumerator:
C_Error 
C_InstSrcError 
C_MediaError 
C_InstTargetError 
C_YouError 
C_ModulePkgError 

enum PMError::Error
 

Enumerator:
E_TBD 


Constructor & Destructor Documentation

PMError::PMError const unsigned  e = E_ok  )  [inline]
 

Default Constructor. Assign errorvalue, defaults to E_ok.

PMError::PMError const unsigned  e,
const std::string &  details
[inline]
 

Constructor. Assign error value and details.


Member Function Documentation

void PMError::addDetails const std::string &   ) 
 

Add a string to the details string.

string PMError::asString  )  const
 

Returns:
The full error string icl. details: ERROR(InstSrc:short_description)[details if set]

std::string PMError::defaulterrstr const std::string &  cl,
const std::string &  txt
[static, private]
 

std::string PMError::details  )  const [inline]
 

Returns:
The details string.

ErrClass PMError::errClass  )  const [inline]
 

Returns:
The error values error class.

PMError::ErrClass PMError::errClass const unsigned  e  )  [static]
 

Returns:
The error values error class.

std::string PMError::errstr  )  const [inline]
 

Returns:
The error string without details: ERROR(InstSrc:short_description)

std::string PMError::errstr const unsigned  e  )  [static]
 

Returns:
The error string without details: ERROR(InstSrc:short_description)

PMError::operator unsigned  )  const [inline]
 

Conversion to unsigned error value.

void PMError::setDetails const std::string &  details  )  [inline]
 

Assign a details string


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  str,
const PMError obj
[friend]
 

Stream output asString.


Member Data Documentation

std::string PMError::_errdetails
 

unsigned PMError::_errval
 

const unsigned PMError::_repmask = ~_valmask [static, private]
 

const unsigned PMError::_valmask = _valrange-1 [static, private]
 

const unsigned PMError::_valrange = 0x400 [static, private]
 

const unsigned PMError::E_error = 1 [static]
 

const unsigned PMError::E_ok = 0 [static]
 

const std::string PMError::ERRORstring [static]
 

const std::string PMError::errstrPrefix [static, private]
 

const std::string PMError::OKstring [static]
 


The documentation for this class was generated from the following files:
Generated on Mon Sep 12 21:52:14 2005 for yast2-packagemanager by  doxygen 1.4.4