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 inline \
00056 static gnExceptionCode& E_NAME(){ \
00057         static gnExceptionCode* m_excp = new gnExceptionCode(GetNewExceptionCode(), #E_NAME); \
00058         return *m_excp; \
00059 }
00060 
00061 //define a bunch of exception codes
00062 //this must be done in a header file to work correctly
00063 
00064 /**
00065  * Thrown when a generic array index is too large or otherwise invalid
00066  */
00067 CREATE_EXCEPTION(IndexOutOfBounds)
00068 /**
00069  * Thrown when a sequence index references an invalid coordinate
00070  */
00071 CREATE_EXCEPTION(SeqIndexOutOfBounds)
00072 /**
00073  * Thrown when a fragment index references an invalid fragment
00074  */
00075 CREATE_EXCEPTION(FragmentIndexOutOfBounds)
00076 /**
00077  * Thrown when a contig index references an invalid contig
00078  */
00079 CREATE_EXCEPTION(ContigIndexOutOfBounds)
00080 /**
00081  * Thrown when a header index references an invalid header
00082  */
00083 CREATE_EXCEPTION(HeaderIndexOutOfBounds)
00084 /**
00085  * Thrown when a spec index references an invalid spec
00086  */
00087 CREATE_EXCEPTION(SpecIndexOutOfBounds)
00088 /**
00089  * Thrown when a feature index references an invalid feature
00090  */
00091 CREATE_EXCEPTION(FeatureIndexOutOfBounds)
00092 /**
00093  * Thrown when a file can't be opened
00094  */
00095 CREATE_EXCEPTION(FileNotOpened)
00096 /**
00097  * Thrown when a URL can't be opened
00098  */
00099 CREATE_EXCEPTION(URLNotFound)
00100 /**
00101  * Thrown when a file's data is corrupt or unreadable
00102  */
00103 CREATE_EXCEPTION(FileUnreadable)
00104 /**
00105  * Thrown when an operation on a stream fails
00106  */
00107 CREATE_EXCEPTION(IOStreamFailed)
00108 /**
00109  * Thrown when an invalid pointer is given
00110  */
00111 CREATE_EXCEPTION(NullPointer)
00112 
00113 
00114 #endif  //_gnExceptionCode_h_

Generated on Mon Feb 3 02:34:39 2003 for libGenome by doxygen1.3-rc3