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 
00067 CREATE_EXCEPTION(IndexOutOfBounds)
00071 CREATE_EXCEPTION(SeqIndexOutOfBounds)
00075 CREATE_EXCEPTION(FragmentIndexOutOfBounds)
00079 CREATE_EXCEPTION(ContigIndexOutOfBounds)
00083 CREATE_EXCEPTION(HeaderIndexOutOfBounds)
00087 CREATE_EXCEPTION(SpecIndexOutOfBounds)
00091 CREATE_EXCEPTION(FeatureIndexOutOfBounds)
00095 CREATE_EXCEPTION(FileNotOpened)
00099 CREATE_EXCEPTION(URLNotFound)
00103 CREATE_EXCEPTION(FileUnreadable)
00107 CREATE_EXCEPTION(IOStreamFailed)
00111 CREATE_EXCEPTION(NullPointer)
00112 
00113 
00114 #endif  //_gnExceptionCode_h_

Generated at Thu Apr 4 01:52:02 2002 for libGenome by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001