Exception.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006-11 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Fritz Dierks
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
30 #ifndef GENAPI_EXCEPTION_H
31 #define GENAPI_EXCEPTION_H
32 
33 #include "Base/GCException.h"
34 #include "INodePrivate.h"
35 
36 namespace GENAPI_NAMESPACE
37 {
38 
40  typedef enum
41  {
60  } EMethod;
61 
63  {
64  public:
66  static void ToString(GENICAM_NAMESPACE::gcstring &ValueStr, EMethod *pValue)
67  {
68  assert( pValue );
69 
70  if( *pValue == meGetAccessMode )
71  ValueStr = "GetAccessMode";
72  else if( *pValue == meToString )
73  ValueStr = "ToString";
74  else if( *pValue == meFromString )
75  ValueStr = "FromString";
76  else if( *pValue == meGetValue )
77  ValueStr = "GetValue";
78  else if( *pValue == meSetValue )
79  ValueStr = "SetValue";
80  else if( *pValue == meGetMin )
81  ValueStr = "GetMin";
82  else if( *pValue == meGetMax )
83  ValueStr = "GetMax";
84  else if( *pValue == meGetInc )
85  ValueStr = "GetInc";
86  else if( *pValue == meExecute )
87  ValueStr = "Execute";
88  else if( *pValue == meIsDone )
89  ValueStr = "IsDone";
90  else if( *pValue == meSetIntValue )
91  ValueStr = "SetIntValue";
92  else if( *pValue == meGetIntValue )
93  ValueStr = "GetIntValue";
94  else if( *pValue == meSet )
95  ValueStr = "Set";
96  else if( *pValue == meGet )
97  ValueStr = "Get";
98  else if( *pValue == meGetIncMode)
99  ValueStr = "GetIncMode";
100  else if (*pValue == meGetListOfValidValues)
101  ValueStr = "GetListOfValidValues";
102  else if (*pValue == meInvalidateNode)
103  ValueStr = "InvalidateNode";
104  else
105  ValueStr = "_UndefinedMethod";
106  }
107 
110  {
112  ToString(Result, &Value);
113  return Result;
114  }
115  };
116 
118 
119  template <class E>
121  {
122  public:
123  ExceptionReporterNode( const char* sourceFileName, unsigned int sourceLine, const INodePrivate* pNodePrivate, const char* pExceptionType )
124  : GENICAM_NAMESPACE::ExceptionReporter<E>( sourceFileName, sourceLine )
125  , m_pNodePrivate( pNodePrivate )
126  , m_ExceptionType( pExceptionType )
127  { }
128 
129  E Report( const char* pFormat, ... )
130  {
131  using namespace GENICAM_NAMESPACE;
132  // print the actual error description to pBuffer
133  char pBuffer[ 256 ];
134  va_list vap;
135  va_start( vap, pFormat );
136 
137 #if defined (_MSC_VER)
138  vsnprintf_s( pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap );
139 #else
140  vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
141 #endif
142  va_end(vap);
143  return E( pBuffer,
145  getEntryPoint(m_pNodePrivate->GetNodeMap()).c_str(),
146  m_pNodePrivate->GetName().c_str(),
148  );
149  }
150 
151  private:
152  // The current node
154 
157 
158  };
159 
161 # define GENERIC_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__, this, "GenericException" ).Report
162 
164 # define INVALID_ARGUMENT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, this, "InvalidArgumentException" ).Report
165 
167 # define OUT_OF_RANGE_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, this, "OutOfRangeException" ).Report
168 
170 # define PROPERTY_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, this, "PropertyException" ).Report
171 
173 # define RUNTIME_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, this, "RuntimeException" ).Report
174 
176 # define LOGICAL_ERROR_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, this, "LogicalErrorException" ).Report
177 
179 # define ACCESS_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, this, "AccessException" ).Report
180 
182 # define TIMEOUT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__, this, "TimeoutException" ).Report
183 
185 # define DYNAMICCAST_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, this, "DynamicCastException" ).Report
186 
188 # define CHECK_RANGE_I64_NODE(_Value, _Min, _Max, _Inc) \
189  if((int64_t)(_Value) < (int64_t)(_Min)) \
190  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)); \
191  else if((int64_t)(_Value) > (int64_t)(_Max)) \
192  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)); \
193  else if ( 0 >= _Inc ) \
194  throw LOGICAL_ERROR_EXCEPTION_NODE("Increment must be larger than 0."); \
195  else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
196  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));
197 
199 # define CHECK_RANGE_FLT_NODE(_Value, _Min, _Max) \
200  if ((_Value) < (_Min)) \
201  throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be greater than or equal %f.", (_Value), (_Min) ); \
202  else if ((_Value) > (_Max)) \
203  throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be smaller than or equal %f.", (_Value), (_Max) );
204 
205 }
206 
207 #endif // GENAPI_EXCEPTION_H
GENAPI_NAMESPACE::EMethodClass
Definition: Exception.h:62
GENAPI_NAMESPACE
Lexical analyzer for CIntSwissKnife.
Definition: Destructible.h:30
GENAPI_NAMESPACE::meGetInc
@ meGetInc
Definition: Exception.h:50
GENICAM_NAMESPACE::ExceptionReporter::ExceptionReporter
ExceptionReporter(const char *pSourceFileName, int SourceLine)
Definition: GCException.h:172
GENAPI_NAMESPACE::meToString
@ meToString
Definition: Exception.h:44
GENAPI_NAMESPACE::meUndefined
@ meUndefined
Definition: Exception.h:42
GENAPI_NAMESPACE::meGetValue
@ meGetValue
Definition: Exception.h:46
GENAPI_NAMESPACE::ExceptionReporterNode::ExceptionReporterNode
ExceptionReporterNode(const char *sourceFileName, unsigned int sourceLine, const INodePrivate *pNodePrivate, const char *pExceptionType)
Definition: Exception.h:123
GENICAM_NAMESPACE::ExceptionReporter
printf like creation of exceptions
Definition: GCException.h:168
GENICAM_NAMESPACE
Definition: GCArray.h:32
GENAPI_NAMESPACE::ExceptionReporterNode::Report
E Report(const char *pFormat,...)
Definition: Exception.h:129
GENICAM_NAMESPACE::gcstring
A string class which is a clone of std::string.
Definition: GCString.h:52
GENAPI_NAMESPACE::ExceptionReporterNode::m_ExceptionType
GENICAM_NAMESPACE::gcstring m_ExceptionType
The full error message.
Definition: Exception.h:156
GENAPI_NAMESPACE::meGetAccessMode
@ meGetAccessMode
Definition: Exception.h:43
GENAPI_NAMESPACE::meGetListOfValidValues
@ meGetListOfValidValues
Definition: Exception.h:58
GENAPI_NAMESPACE::meSetIntValue
@ meSetIntValue
Definition: Exception.h:53
GENAPI_NAMESPACE::ExceptionReporterNode
Definition: Exception.h:120
GENAPI_NAMESPACE::ExceptionReporterNode::m_pNodePrivate
const INodePrivate * m_pNodePrivate
Definition: Exception.h:153
GENAPI_NAMESPACE::meIsDone
@ meIsDone
Definition: Exception.h:52
GENAPI_NAMESPACE::getEntryPoint
GENICAM_NAMESPACE::gcstring getEntryPoint(INodeMap *nodeMap)
GENAPI_NAMESPACE::INodeMap
GENICAM_INTERFACE INodeMap
Interface to access the node map.
Definition: INode.h:52
GENAPI_NAMESPACE::meSet
@ meSet
Definition: Exception.h:55
GENAPI_NAMESPACE::meGetIncMode
@ meGetIncMode
Definition: Exception.h:57
GENAPI_NAMESPACE::EMethod
EMethod
denotes through which method call the node tree was entered
Definition: Exception.h:40
INodePrivate.h
Definition of interface INodePrivate.
GENAPI_NAMESPACE::meGetIntValue
@ meGetIntValue
Definition: Exception.h:54
GENAPI_NAMESPACE::meGet
@ meGet
Definition: Exception.h:56
GENAPI_NAMESPACE::INodePrivate
GENICAM_INTERFACE INodePrivate
Interface including the methods for node construction common to all nodes.
Definition: INodePrivate.h:54
GENAPI_NAMESPACE::EMethodClass::ToString
static void ToString(GENICAM_NAMESPACE::gcstring &ValueStr, EMethod *pValue)
Converts a string to an int32_t property.
Definition: Exception.h:66
GENAPI_NAMESPACE::meFromString
@ meFromString
Definition: Exception.h:45
GENICAM_NAMESPACE::gcstring::c_str
virtual const char * c_str(void) const
GENAPI_NAMESPACE::meSetValue
@ meSetValue
Definition: Exception.h:47
GENAPI_NAMESPACE::meExecute
@ meExecute
Definition: Exception.h:51
GENAPI_NAMESPACE::meInvalidateNode
@ meInvalidateNode
Definition: Exception.h:59
GCException.h
GENAPI_NAMESPACE::EMethodClass::ToString
static GENICAM_NAMESPACE::gcstring ToString(EMethod Value)
Converts a string to an int32_t property.
Definition: Exception.h:109
GENAPI_NAMESPACE::meGetMin
@ meGetMin
Definition: Exception.h:48
GENAPI_NAMESPACE::meGetMax
@ meGetMax
Definition: Exception.h:49


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11