CMS 3D CMS Logo

CodedException.h

Go to the documentation of this file.
00001 #ifndef Utilities_CodedException_h
00002 #define Utilities_CodedException_h
00003 
00013 #include "FWCore/Utilities/interface/Exception.h"
00014 
00015 #include <string>
00016 #include <map>
00017 
00018 #define EDM_MAP_ENTRY(map, ns, name) map[ns::name]=#name
00019 #define EDM_MAP_ENTRY_NONS(map, name) map[name]=#name
00020 
00021 namespace edm {
00022   template <class Code>
00023   class CodedException : public cms::Exception
00024   {
00025   public:
00026     explicit CodedException(Code category);
00027 
00028     CodedException(Code category,
00029                    const std::string& message);
00030 
00031     CodedException(Code category,
00032                    const std::string& message,
00033                    const cms::Exception& another);
00034 
00035     CodedException(const CodedException& other);
00036 
00037     virtual ~CodedException() throw();
00038 
00039     Code categoryCode() const { return category_; }
00040 
00041     int returnCode() const { return static_cast<int>(category_); }
00042 
00043     static std::string codeToString(Code);
00044 
00045     typedef std::map<Code,std::string> CodeMap; 
00046   private:
00047 
00048     Code category_;
00049   };
00050 
00051 
00053 
00054 #if 0
00055   template <class Code>
00056   void CodedException<Code>::loadTable() { }
00057 #endif
00058 
00059   template <class Code>
00060   std::string CodedException<Code>::codeToString(Code c)
00061   {
00062     extern void getCodeTable(CodeMap*&);
00063     CodeMap* trans;
00064     getCodeTable(trans);
00065     typename CodeMap::const_iterator i(trans->find(c));
00066     return i!=trans->end() ? i->second : std::string("UnknownCode");
00067   }
00068 
00069 
00070   template <class Code>
00071   CodedException<Code>::CodedException(Code aCategory):
00072     cms::Exception(codeToString(aCategory)),
00073     category_(aCategory)
00074   {
00075   }
00076 
00077   template <class Code>
00078   CodedException<Code>::CodedException(Code aCategory,
00079                                        const std::string& message):
00080     cms::Exception(codeToString(aCategory),message),
00081     category_(aCategory)
00082   {
00083   }
00084 
00085   template <class Code>
00086   CodedException<Code>::CodedException(Code aCategory,
00087                                        const std::string& message,
00088                                        const cms::Exception& another):
00089     cms::Exception(codeToString(aCategory),message,another),
00090     category_(aCategory)
00091   {
00092   }
00093 
00094   template <class Code>
00095   CodedException<Code>::CodedException(const CodedException& other):
00096     cms::Exception(other),
00097     category_(other.category_)
00098   {
00099   }
00100 
00101   template <class Code>
00102   CodedException<Code>::~CodedException() throw()
00103   {
00104   }
00105 
00106 }
00107 
00108 #endif

Generated on Tue Jun 9 17:36:41 2009 for CMSSW by  doxygen 1.5.4