//---------------------------------------------------------------------- // // ZMexAugmented.h // // This class derives from a regular ZMexception class. It logs through // the ErrorLogger package and contains an object of some user // specified type which can be used in determining whether to log // the exception or continue processing it. // // 08-02-99 jvr Created // 04-09-01 mf Work-around for gcc inability to use method in default // arguments by tripling and doubling up ctors. // //---------------------------------------------------------------------- #ifndef ZM_EXAUGMENTED_H #define ZM_EXAUGMENTED_H #include "Exceptions/ZMexception.h" #include "Exceptions/ZMexClassInfo.h" #include "ErrorLogger/ErrorObj.h" #include "ErrorLogger/ErrorLog.h" #include "ZMutility/sstream" #include template class ZMexAugmented: public Parent { public: typedef T T_type; //Constructor that creates its ErrorObj on its own or from a inputted string // // Basic form - all four arguments present // ZMexAugmented( T_type& extra, std::string ExName, const ZMexSeverity howBad, int count ) : Parent( "" , (howBad == ZMexSEVERITYenumLAST ? _classInfo.severity() : howBad) , count ), myErrObj( new ErrorObj(convertSev(), ExName) ), newErrObj(true), extraObj(extra) { } //Constructor that creates its ErrorObj on its own or from a inputted string // // Shorter form - count and perhaps severity defaulted. // ZMexAugmented( T_type& extra, std::string ExName, const ZMexSeverity howBad = ZMexSEVERITYenumLAST ) : Parent( "" , (howBad == ZMexSEVERITYenumLAST ? _classInfo.severity() : howBad) , _classInfo.nextCount() ), myErrObj( new ErrorObj(convertSev(), ExName) ), newErrObj(true), extraObj(extra) { } //Constructor that creates its ErrorObj on its own or from a inputted string // // Shortest (and probably typical) form - only extra object provided. // ZMexAugmented( T_type& extra ) : Parent( _classInfo.name() , _classInfo.severity() , _classInfo.nextCount() ), myErrObj( new ErrorObj(convertSev(), ExName) ), newErrObj(true), extraObj(extra) { } //Constructor with ErrorObj parameter // // Basic form - all four arguments present // ZMexAugmented( T_type& extra, ErrorObj& errObj, const ZMexSeverity howBad, int count ) : Parent( "" , (howBad == ZMexSEVERITYenumLAST ? _classInfo.severity() : howBad) , count ), myErrObj( &errObj ), newErrObj(false), extraObj(extra) { } //Constructor with ErrorObj parameter // // Shorter form - count (and possibly severity) defaulted // ZMexAugmented( T_type& extra, ErrorObj& errObj, const ZMexSeverity howBad = ZMexSEVERITYenumLAST ) : Parent( "" , (howBad == ZMexSEVERITYenumLAST ? _classInfo.severity() : howBad) , _classInfo.nextCount() ), myErrObj( &errObj ), newErrObj(false), extraObj(extra) { } //Copy constructor ZMexAugmented( const ZMexAugmented& exception ) : Parent( dynamic_cast (exception)), myErrObj( new ErrorObj(*(exception.myErrObj))), newErrObj(true), extraObj(exception.extraObj){ } virtual ~ZMexAugmented() { if ( newErrObj ) { delete myErrObj; myErrObj = '\0'; } } //this gives a segmentation fault static void setName(std::string newName) { _classInfo.setName(newName); } static void setFacility(std::string newFacility) { _classInfo.setFacility(newFacility); } static void setSeverity(ZMexSeverity newSeverity) { _classInfo.setSeverity(newSeverity); } static ZMexHandler setHandler( const ZMexHandler & newHandler ){ return _classInfo.setHandler( newHandler); } static ZMexHandler getHandler() { return _classInfo.getHandler(); } static ZMexLogger setLogger( const ZMexLogger & newLogger ) { return _classInfo.setLogger( newLogger ); } static ZMexLogger getLogger() { return _classInfo.getLogger(); } static bool isTypeOf( const ZMexception & x ) { return ( (_classInfo.name() == x.name()) && (_classInfo.facility() == x.facility() ) ); } static bool isBaseOf( const ZMexception & x ) { return ( x.isDerivedFrom (_classInfo.name(), _classInfo.facility()) ); } static bool isZMexception(){ ZMexception x("temp"); return (dynamic_cast(&x)); } static void logNMore( const int N ) { _classInfo.logNMore( N ); } virtual ZM_COVARIANT_TYPE(ZMexception, ZMexAugmented) * clone() const { return new ZMexAugmented( *this ); } virtual ZMexClassInfo & classInfo() const { return ZMexAugmented::_classInfo; } virtual ZMexAction handleMe() const { /* DEBUG cerr << #Class "::handleMe()" << endl; */ ZMexAction result = ZMexAugmented::classInfo().getHandler().takeCareOf( *this ); return (result == ZMexHANDLEVIAPARENT) ? Parent::handleMe() : result; } virtual ZMexLogResult logMe() const { /* DEBUG cerr << #Class "::logMe()" << endl; */ ZMexLogResult result = ZMexAugmented::classInfo().getLogger().emit( *this ); return (result == ZMexLOGVIAPARENT) ? Parent::logMe() : result; } virtual bool isDerivedFrom( const std::string aName, const std::string aFacility ) const { Parent tempParent("temp", ZMexNORMAL, count()-1); return aName == name() && aFacility == facility() ? true : tempParent.isDerivedFrom( aName, aFacility ); } static void setErrorLogger(ErrorLog& log) { myLogger = log; } virtual ErrorObj& getErrorObj() { return *myErrObj; } virtual T_type& getExtraObj() { return extraObj; } virtual void logObject() const { //I had to add this function to myLogger(*myErrObj); //ZMexceptions.h too } //logMessage() defined in .icc file virtual std::string logMessage( const std::string optText ) const; ELseverityLevel convertSev() { if ( severity() == ZMexNORMAL ) return ELincidental; if ( severity() == ZMexINFO ) return ELinfo; if ( severity() == ZMexWARNING ) return ELwarning; if ( severity() == ZMexERROR ) return ELerror; if ( severity() == ZMexSEVERE ) return ELsevere; if ( severity() == ZMexFATAL ) return ELabort; return ELfatal; } private: ErrorObj* myErrObj; bool newErrObj; public: static ErrorLog myLogger; T_type extraObj; static ZMexClassInfo _classInfo; }; #define ZM_EXAUGMENTED_ICC #include "ErrLogEx/ZMexAugmented.icc" #undef ZM_EXAUGMENTED_ICC #endif