00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef GENAPI_EXCEPTION_H
00031 #define GENAPI_EXCEPTION_H
00032
00033 #include "Base/GCException.h"
00034 #include "INodePrivate.h"
00035
00036 namespace GENAPI_NAMESPACE
00037 {
00038
00040 typedef enum
00041 {
00042 meUndefined,
00043 meGetAccessMode,
00044 meToString,
00045 meFromString,
00046 meGetValue,
00047 meSetValue,
00048 meGetMin,
00049 meGetMax,
00050 meGetInc,
00051 meExecute,
00052 meIsDone,
00053 meSetIntValue,
00054 meGetIntValue,
00055 meSet,
00056 meGet,
00057 meGetIncMode,
00058 meGetListOfValidValues
00059 } EMethod;
00060
00061 class EMethodClass
00062 {
00063 public:
00065 static void ToString(GENICAM_NAMESPACE::gcstring &ValueStr, EMethod *pValue)
00066 {
00067 assert( pValue );
00068
00069 if( *pValue == meGetAccessMode )
00070 ValueStr = "GetAccessMode";
00071 else if( *pValue == meToString )
00072 ValueStr = "ToString";
00073 else if( *pValue == meFromString )
00074 ValueStr = "FromString";
00075 else if( *pValue == meGetValue )
00076 ValueStr = "GetValue";
00077 else if( *pValue == meSetValue )
00078 ValueStr = "SetValue";
00079 else if( *pValue == meGetMin )
00080 ValueStr = "GetMin";
00081 else if( *pValue == meGetMax )
00082 ValueStr = "GetMax";
00083 else if( *pValue == meGetInc )
00084 ValueStr = "GetInc";
00085 else if( *pValue == meExecute )
00086 ValueStr = "Execute";
00087 else if( *pValue == meIsDone )
00088 ValueStr = "IsDone";
00089 else if( *pValue == meSetIntValue )
00090 ValueStr = "SetIntValue";
00091 else if( *pValue == meGetIntValue )
00092 ValueStr = "GetIntValue";
00093 else if( *pValue == meSet )
00094 ValueStr = "Set";
00095 else if( *pValue == meGet )
00096 ValueStr = "Get";
00097 else
00098 ValueStr = "_UndefinedMethod";
00099 }
00100
00102 static GENICAM_NAMESPACE::gcstring ToString(EMethod Value)
00103 {
00104 GENICAM_NAMESPACE::gcstring Result;
00105 ToString(Result, &Value);
00106 return Result;
00107 }
00108 };
00109
00110 GENICAM_NAMESPACE::gcstring getEntryPoint(INodeMap* nodeMap);
00111
00112 template <class E>
00113 class ExceptionReporterNode : public GENICAM_NAMESPACE::ExceptionReporter<E>
00114 {
00115 public:
00116 ExceptionReporterNode( const char* sourceFileName, unsigned int sourceLine, const INodePrivate* pNodePrivate, const char* pExceptionType )
00117 : GENICAM_NAMESPACE::ExceptionReporter<E>( sourceFileName, sourceLine )
00118 , m_pNodePrivate( pNodePrivate )
00119 , m_ExceptionType( pExceptionType )
00120 { }
00121
00122 E Report( const char* pFormat, ... )
00123 {
00124 using namespace GENICAM_NAMESPACE;
00125
00126 char pBuffer[ 256 ];
00127 va_list vap;
00128 va_start( vap, pFormat );
00129
00130 #if defined (_MSC_VER)
00131 vsnprintf_s( pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap );
00132 #else
00133 vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
00134 #endif
00135 va_end(vap);
00136 return E( pBuffer,
00137 GENICAM_NAMESPACE::ExceptionReporter<E>::m_SourceFileName.c_str(), GENICAM_NAMESPACE::ExceptionReporter<E>::m_SourceLine,
00138 getEntryPoint(m_pNodePrivate->GetNodeMap()).c_str(),
00139 m_pNodePrivate->GetName().c_str(),
00140 m_ExceptionType.c_str()
00141 );
00142 }
00143
00144 private:
00145
00146 const INodePrivate *m_pNodePrivate;
00147
00149 GENICAM_NAMESPACE::gcstring m_ExceptionType;
00150
00151 };
00152
00154 # define GENERIC_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__, this, "GenericException" ).Report
00155
00157 # define INVALID_ARGUMENT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, this, "InvalidArgumentException" ).Report
00158
00160 # define OUT_OF_RANGE_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, this, "OutOfRangeException" ).Report
00161
00163 # define PROPERTY_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, this, "PropertyException" ).Report
00164
00166 # define RUNTIME_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, this, "RuntimeException" ).Report
00167
00169 # define LOGICAL_ERROR_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, this, "LogicalErrorException" ).Report
00170
00172 # define ACCESS_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, this, "AccessException" ).Report
00173
00175 # define TIMEOUT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__, this, "TimeoutException" ).Report
00176
00178 # define DYNAMICCAST_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, this, "DynamicCastException" ).Report
00179
00181 # define CHECK_RANGE_I64_NODE(_Value, _Min, _Max, _Inc) \
00182 if((int64_t)(_Value) < (int64_t)(_Min)) \
00183 throw OUT_OF_RANGE_EXCEPTION_NODE("Value = %" FMT_I64 "d must be equal or greater than Min = %" FMT_I64 "d.", (int64_t)(_Value), (int64_t)(_Min)); \
00184 else if((int64_t)(_Value) > (int64_t)(_Max)) \
00185 throw OUT_OF_RANGE_EXCEPTION_NODE("Value = %" FMT_I64 "d must be equal or smaller than Max = %" FMT_I64 "d.", (int64_t)(_Value), (int64_t)(_Max)); \
00186 else if ( 0 >= _Inc ) \
00187 throw LOGICAL_ERROR_EXCEPTION_NODE("Increment must be larger than 0."); \
00188 else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
00189 throw OUT_OF_RANGE_EXCEPTION_NODE("The difference between Value = %" FMT_I64 "d and Min = %" FMT_I64 "d must be dividable without rest by Inc = %" FMT_I64 "d.", (int64_t)(_Value), (int64_t)(_Min), (int64_t)(_Inc));
00190
00192 # define CHECK_RANGE_FLT_NODE(_Value, _Min, _Max) \
00193 if ((_Value) < (_Min)) \
00194 throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be greater than or equal %f.", (_Value), (_Min) ); \
00195 else if ((_Value) > (_Max)) \
00196 throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be smaller than or equal %f.", (_Value), (_Max) );
00197
00198
00199 }
00200
00201 #endif // GENAPI_EXCEPTION_H
00202