Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

gnExceptionCode.h

Go to the documentation of this file.
00001 #ifndef _gnExceptionCode_h_
00002 #define _gnExceptionCode_h_
00003 
00004 #include "gn/gnDefs.h"
00005 #include <string>
00006 
00007 class GNDLLEXPORT gnExceptionCode{
00008 public:
00009         gnExceptionCode(uint32 code, const char* name);
00010         boolean operator==(gnExceptionCode& gnec);
00011         boolean operator!=(gnExceptionCode& gnec);
00012         uint32 GetInt(){ return m_code; }
00013         string GetName(){ return m_name; }
00014 private:
00015         gnExceptionCode();
00016         //prevent instances from being copied
00017         gnExceptionCode(const gnExceptionCode& gnec);
00018         gnExceptionCode& operator=(gnExceptionCode& gnec);
00019         uint32 m_code;
00020         string m_name;
00021 };
00022 
00023 inline
00024 gnExceptionCode::gnExceptionCode(uint32 code, const char* name) :
00025 m_code(code), m_name(name)
00026 {}
00027 
00028 inline
00029 boolean gnExceptionCode::operator==(gnExceptionCode& gnec){
00030         return m_code == gnec.m_code;
00031 }
00032 
00033 inline
00034 boolean gnExceptionCode::operator!=(gnExceptionCode& gnec){
00035         return m_code != gnec.m_code;
00036 }
00037 
00038 GNDLLEXPORT
00039 uint32& GetNewExceptionCode();
00040 
00041 inline
00042 uint32& GetNewExceptionCode(){
00043         //static initializer is called only once
00044         static uint32 new_code = 0;
00045         //increment it each time the function is called
00046         new_code++;
00047         return new_code;
00048 };
00049 
00050 //Creates an exception code with the given name
00051 //currently it chooses a unique id for each exception
00052 //this may have to be changed in the future if the integer
00053 //associated with each exception must be the same across compiles
00054 #define CREATE_EXCEPTION(E_NAME) \
00055 GNDLLEXPORT \
00056 inline \
00057 static gnExceptionCode& E_NAME(){ \
00058         static gnExceptionCode* m_excp = new gnExceptionCode(GetNewExceptionCode(), #E_NAME); \
00059         return *m_excp; \
00060 }
00061 
00062 //define a bunch of exception codes
00063 //this must be done in a header file to work correctly
00064 
00068 CREATE_EXCEPTION(IndexOutOfBounds)
00072 CREATE_EXCEPTION(SeqIndexOutOfBounds)
00076 CREATE_EXCEPTION(FragmentIndexOutOfBounds)
00080 CREATE_EXCEPTION(ContigIndexOutOfBounds)
00084 CREATE_EXCEPTION(HeaderIndexOutOfBounds)
00088 CREATE_EXCEPTION(SpecIndexOutOfBounds)
00092 CREATE_EXCEPTION(FeatureIndexOutOfBounds)
00096 CREATE_EXCEPTION(FileNotOpened)
00100 CREATE_EXCEPTION(URLNotFound)
00104 CREATE_EXCEPTION(FileUnreadable)
00108 CREATE_EXCEPTION(IOStreamFailed)
00112 CREATE_EXCEPTION(NullPointer)
00113 
00114 
00115 #endif  //_gnExceptionCode_h_

Generated at Fri Nov 30 15:36:51 2001 for libGenome by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001