osberror.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008              Ramlan Rusdijanto (rr)
00009              Lilian Qin Lan (lan)
00010 
00011   RCS information
00012    $Name: OSB_060808 $
00013    $Revision: 1.81 $
00014 
00015   License
00016    OSB rating and billing library for communication networks
00017    Copyright (C) 2004, 2005, 2006  OSB systems
00018 
00019    This file may be distributed and/or modify under the terms of the
00020    GNU General Public License (GPL) as published by the Free Software
00021    Foundation which is provided in the file LICENSE.GPL included in the
00022    packaging of this file.
00023 
00024    The file is distributed in the hope that it will be useful, but WITHOUT
00025    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00026    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00027    for more details.
00028 
00029    Holders of a OSB Commercial License may use this file under the terms
00030    and conditions of this commercial license.
00031  */
00032 #ifndef _OSBERROR_H_
00033 #define _OSBERROR_H_
00034 
00035 // ************************************************************************
00036 // included header files
00037 // + standard includes
00038 #include <string>
00039 #include <sstream>
00040 #include <vector>
00041 
00042 // ************************************************************************
00043 // namespace extensions
00044 namespace OSB_LIB {
00045 
00046 // ************************************************************************
00047 // class declarations
00048 
00055     class BaseError {
00056     public:
00058         typedef long ErrorNo;
00060         typedef std::vector<std::string> Args;
00062         static const ErrorNo noError_ = 0;
00063 
00064     public:
00071         explicit BaseError(ErrorNo e);
00073         BaseError(
00074                   ErrorNo no,
00075             const Args&   args
00076         );
00078         virtual ~BaseError();
00079 
00080     protected:
00082         BaseError(const BaseError& rhs);
00084         BaseError& operator=(const BaseError& rhs);
00085 
00086     public:
00093 
00094         BaseError& operator<<(const char* s);
00096         BaseError& operator<<(const std::string& s);
00103         template <typename T>
00104         BaseError& operator<<(const T& t);
00106 
00107     public:
00114         const std::string what() const;
00115 
00125         bool noError() const;
00131         bool isError() const;
00132 
00134         ErrorNo no() const;
00138         std::string code() const;
00145         const std::string msg() const;
00146 
00148         const Args& args() const;
00149 
00156         virtual const char* const prefix() const = 0;
00160         virtual const std::string& fileName() const = 0;
00161 
00162     private:
00164         ErrorNo errorNo_;
00165     protected:
00167         Args args_;
00168     };                                  // class BaseError
00169 
00176     class OsbBaseError : public BaseError {
00177     public:
00179         explicit OsbBaseError(ErrorNo e);
00181         OsbBaseError(
00182                   ErrorNo e,
00183             const Args&   args
00184         );
00185 
00187         virtual ~OsbBaseError() = 0;
00188 
00189     protected:
00191         OsbBaseError(const OsbBaseError& rhs);
00193         OsbBaseError& operator=(const OsbBaseError& rhs);
00194 
00195     private:
00197         static const std::string fileName_;
00198         // doc from base
00199         const std::string& fileName() const;
00200     };                                  // class OsbBaseError
00201 
00208     class OsbError : public OsbBaseError {
00209     public:
00211         OsbError();
00213         explicit OsbError(ErrorNo e);
00215         OsbError(
00216             ErrorNo e,
00217             const Args& args
00218         );
00219 
00221         const char* const prefix() const;
00222 
00223     private:
00225         static const char* const prefix_;
00226     };
00227 
00235     class OsbException : public OsbBaseError {
00236     public:
00238         OsbException(ErrorNo e);
00240         OsbException(
00241                   ErrorNo e,
00242             const Args&   args
00243         );
00245         virtual ~OsbException() = 0;
00246 
00247     protected:
00249         OsbException(const OsbException& rhs);
00251         OsbException& operator=(const OsbException& rhs);
00252 
00253     public:
00255         const char* const prefix() const;
00256 
00257     private:
00259         static const char* const prefix_;
00260     };                                  // class OsbException
00261 
00268     class DefException : public OsbException {
00269     public:
00271         DefException(ErrorNo e);
00273         DefException(
00274                   ErrorNo e,
00275             const Args&   args
00276         );
00277 
00278     public:
00291         template<typename T>
00292         DefException& operator<<(const T& t);
00293     };                                  // class DefException
00294 
00295     // ********************************************************************
00296     // specialized OsbExceptions
00310     class ObjectNotFound : public OsbException {
00311     public:
00313         ObjectNotFound(ErrorNo e);
00314     };
00315 
00323     class ObjectModified : public OsbException {
00324     public:
00326         ObjectModified(ErrorNo e);
00327     };                                  // class ObjectModified
00328 
00336     class ObjectBusy : public OsbException {
00337     public:
00339         ObjectBusy(ErrorNo e);
00340     };                                  // class ObjectBusy
00341 
00349     class ObjectDeleted : public OsbException {
00350     public:
00352         ObjectDeleted(ErrorNo e);
00353     };                                  // class ObjectDeleted
00354 }                                       // namespace OSB_LIB
00355 
00356 // ************************************************************************
00357 // inline definitions
00358 namespace OSB_LIB {
00359 
00360     // ********************************************************************
00361     // class BaseError
00362     inline BaseError::BaseError(ErrorNo e) : errorNo_(e)
00363     {
00364         // empty
00365     }
00366 
00367     inline BaseError::BaseError(
00368               ErrorNo no,
00369         const Args&   args
00370     ) : errorNo_(no), args_(args)
00371     {
00372         // empty
00373     }
00374 
00375     inline BaseError::BaseError(const BaseError& rhs)
00376       : errorNo_(rhs.errorNo_),
00377         args_(rhs.args_)
00378     {
00379         // empty
00380     }
00381 
00382     inline BaseError& BaseError::operator=(const BaseError& rhs)
00383     {
00384         if (&rhs != this) {
00385             errorNo_  = rhs.errorNo_;
00386             args_     = rhs.args_;
00387         }
00388         return *this;
00389     }
00390 
00391     inline BaseError::~BaseError()
00392     {
00393         // empty
00394     }
00395 
00396     inline bool BaseError::noError() const
00397     {
00398         return noError_ == errorNo_;
00399     }
00400 
00401     inline bool BaseError::isError() const
00402     {
00403         return noError_ != errorNo_;
00404     }
00405 
00406     inline BaseError& BaseError::operator<<(const char* s)
00407     {
00408         args_.push_back(s);
00409         return *this;
00410     }
00411 
00412     inline BaseError& BaseError::operator<<(const std::string& s)
00413     {
00414         args_.push_back(s);
00415         return *this;
00416     }
00417 
00418     template <typename T>
00419     inline BaseError& BaseError::operator<<(const T& t)
00420     {
00421         std::ostringstream os;
00422         os << t;
00423         args_.push_back(os.str());
00424         return *this;
00425     }
00426 
00427     // ********************************************************************
00428     // class OsbBaseError
00429     inline OsbBaseError::OsbBaseError(ErrorNo e)
00430       : BaseError(e)
00431     {
00432         // empty
00433     }
00434 
00435     inline OsbBaseError::OsbBaseError(
00436               ErrorNo e,
00437         const Args&   args
00438     ) : BaseError(e, args)
00439     {
00440         // empty
00441     }
00442 
00443     inline OsbBaseError::OsbBaseError(const OsbBaseError& rhs)
00444       : BaseError(rhs)
00445     {
00446         // empty
00447     }
00448 
00449     inline OsbBaseError& OsbBaseError::operator=(const OsbBaseError& rhs)
00450     {
00451         BaseError::operator=(rhs);
00452         return *this;
00453     }
00454 
00455     inline OsbBaseError::~OsbBaseError()
00456     {
00457         // empty
00458     }
00459 
00460     // ********************************************************************
00461     // class OsbError
00462     inline OsbError::OsbError()
00463       : OsbBaseError(noError_)
00464     {
00465         // empty
00466     }
00467 
00468     inline OsbError::OsbError(ErrorNo e)
00469       : OsbBaseError(e)
00470     {
00471         // empty
00472     }
00473 
00474     inline OsbError::OsbError(
00475         ErrorNo e,
00476         const Args& args
00477     ) : OsbBaseError(e, args)
00478     {
00479         // empty
00480     }
00481 
00482     inline const char* const OsbError::prefix() const
00483     {
00484         return prefix_;
00485     }
00486 
00487     // ********************************************************************
00488     // class OsbException
00489     inline OsbException::OsbException(ErrorNo e)
00490       : OsbBaseError(e)
00491     {
00492         // empty
00493     }
00494 
00495     inline OsbException::OsbException(
00496               ErrorNo e,
00497         const Args&   args
00498     ) : OsbBaseError(e, args)
00499     {
00500         // empty
00501     }
00502 
00503     inline OsbException::OsbException(const OsbException& rhs)
00504       : OsbBaseError(rhs)
00505     {
00506         // empty
00507     }
00508 
00509     inline OsbException& OsbException::operator=(const OsbException& rhs)
00510     {
00511         if (this != &rhs) OsbBaseError::operator=(rhs);
00512         return *this;
00513     }
00514 
00515     inline OsbException::~OsbException()
00516     {
00517         // empty
00518     }
00519 
00520     inline const char* const OsbException::prefix() const
00521     {
00522         return prefix_;
00523     }
00524 
00525     // ********************************************************************
00526     // class DefException
00527     inline DefException::DefException(ErrorNo e)
00528       : OsbException(e)
00529     {
00530         // empty
00531     }
00532 
00533     inline DefException::DefException(
00534               ErrorNo e,
00535         const Args&   args
00536     ) : OsbException(e, args)
00537     {
00538         // empty
00539     }
00540 
00541     template<typename T>
00542     inline DefException& DefException::operator<<(const T& t)
00543     {
00544         OsbException::operator<<(t);
00545         return *this;
00546     }
00547 
00548     // ********************************************************************
00549     // specialized OsbExceptions
00550     inline ObjectNotFound::ObjectNotFound(ErrorNo e)
00551       : OsbException(e)
00552     {
00553         // empty
00554     }
00555 
00556     inline ObjectModified::ObjectModified(ErrorNo e)
00557       : OsbException(e)
00558     {
00559         // empty
00560     }
00561 
00562     inline ObjectBusy::ObjectBusy(ErrorNo e)
00563       : OsbException(e)
00564     {
00565         // empty
00566     }
00567 
00568     inline ObjectDeleted::ObjectDeleted(ErrorNo e)
00569       : OsbException(e)
00570     {
00571         // empty
00572     }
00573 }                                       // namespace OSB_LIB
00574 #endif                                  // #ifndef _OSBERROR_H

Generated on Sat Sep 2 14:06:33 2006 for OSB Library by  doxygen 1.4.7