00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #ifndef GENAPI_NODEMAPREF_H
00032 #define GENAPI_NODEMAPREF_H
00033
00034 #include <GenICamVersion.h>
00035 #include <Base/GCString.h>
00036 #include <Base/GCException.h>
00037
00038 #include <GenApi/Pointer.h>
00039 #include <GenApi/INodeMap.h>
00040 #include <GenApi/IDestroy.h>
00041 #include <GenApi/NodeMapFactory.h>
00042
00043 #include <cstdlib>
00044
00045 namespace GENAPI_NAMESPACE
00046 {
00047
00048 # ifdef _WIN32
00049
00050
00051 inline IDestroy *CastToIDestroy(INodeMap *pNodeMap)
00052 {
00053 return dynamic_cast<IDestroy *>(pNodeMap);
00054 }
00055
00056 # else
00057
00058 GENAPI_DECL IDestroy *CastToIDestroy(INodeMap *pNodeMap);
00059 # endif
00060
00066 template<class TCameraParams>
00067 class CNodeMapRefT : public TCameraParams
00068 {
00069 public:
00071 CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device");
00072
00074 CNodeMapRefT(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device");
00075
00077 CNodeMapRefT(const CNodeMapRefT& Them);
00078
00080 CNodeMapRefT& operator=(const CNodeMapRefT& Them);
00081
00083 CNodeMapRefT& operator=(INodeMap* pNodeMap);
00084
00086 virtual ~CNodeMapRefT();
00087
00089 void _Destroy();
00090
00092 void _LoadXMLFromFile(const GENICAM_NAMESPACE::gcstring &FileName);
00093
00095 void _LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName);
00096
00098 void _LoadXMLFromZIPData(const void* zipData, size_t zipSize);
00099
00101 void _LoadXMLFromFileInject(const GENICAM_NAMESPACE::gcstring &TargetFileName, const GENICAM_NAMESPACE::gcstring &InjectFileName);
00102
00104 void _LoadXMLFromString(const GENICAM_NAMESPACE::gcstring& XMLData);
00105
00107 void _LoadXMLFromStringInject(const GENICAM_NAMESPACE::gcstring& TargetXMLDataconst, const GENICAM_NAMESPACE::gcstring& InjectXMLData);
00108
00110
00114 virtual void _GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const;
00115
00117 virtual GENICAM_NAMESPACE::gcstring _GetDeviceName() const;
00118
00120 virtual void _Poll(int64_t ElapsedTime);
00121
00123 static bool _ClearXMLCache();
00124
00125
00126
00127
00128
00130 virtual void _GetNodes(NodeList_t &Nodes) const;
00131
00133 virtual INode* _GetNode(const GENICAM_NAMESPACE::gcstring& key) const;
00134
00136 virtual void _InvalidateNodes() const;
00137
00139 virtual bool _Connect(IPort* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const;
00140
00142 virtual bool _Connect(IPort* pPort) const;
00143
00145 virtual bool _ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL ) const;
00147 INodeMap *_Ptr;
00148
00149 private:
00151 GENICAM_NAMESPACE::gcstring _DeviceName;
00152
00153
00154 int* _pRefCount;
00155 void Release();
00156 void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount);
00157 };
00158
00159
00160
00161 template<class TCameraParams>
00162 inline CNodeMapRefT<TCameraParams>::CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName)
00163 : _Ptr(NULL)
00164 , _DeviceName(DeviceName)
00165 , _pRefCount(NULL)
00166 {
00167 }
00168
00169 template<class TCameraParams>
00170 inline CNodeMapRefT<TCameraParams>::CNodeMapRefT(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName)
00171 : _Ptr(NULL)
00172 , _DeviceName(DeviceName)
00173 , _pRefCount(NULL)
00174 {
00175 assert(pNodeMap);
00176 Attach(pNodeMap, DeviceName, pNodeMap ? new int(0) : NULL);
00177 }
00178
00179 template<class TCameraParams>
00180 GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::CNodeMapRefT(const CNodeMapRefT& Them)
00181 : TCameraParams()
00182 , _Ptr(NULL)
00183 , _DeviceName()
00184 , _pRefCount(NULL)
00185 {
00186 Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
00187 }
00188
00189
00190 template<class TCameraParams>
00191 void GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount)
00192 {
00193
00194 assert(_Ptr == NULL);
00195 assert(_pRefCount == NULL);
00196
00197
00198 if (&_DeviceName != &DeviceName)
00199 {
00200 _DeviceName = DeviceName;
00201 }
00202
00203
00204 if (pNodeMap)
00205 {
00206 assert(pRefCount);
00207 if (pRefCount)
00208 {
00209 ++*pRefCount;
00210
00211
00212 _Ptr = pNodeMap;
00213 _pRefCount = pRefCount;
00214
00215
00216 TCameraParams::_Initialize(_Ptr);
00217 }
00218 }
00219 }
00220
00221
00222 template<class TCameraParams>
00223 void GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::Release()
00224 {
00225 if (_Ptr)
00226 {
00227
00228 INodeMap* pToDel = _Ptr;
00229 int* pRefCount = _pRefCount;
00230
00231
00232 _pRefCount = NULL;
00233 _Ptr = NULL;
00234 _DeviceName = "Device";
00235
00236 assert(pRefCount);
00237
00238 if (pRefCount)
00239 {
00240 assert(*pRefCount > 0);
00241 --*pRefCount;
00242 if (*pRefCount == 0)
00243 {
00244
00245 delete pRefCount;
00246 pRefCount = NULL;
00247
00248
00249 GENAPI_NAMESPACE::IDestroy *pDestroy = CastToIDestroy(pToDel);
00250 assert(pDestroy);
00251 pDestroy->Destroy();
00252 }
00253 }
00254 }
00255 else
00256 {
00257
00258 assert(_pRefCount == NULL);
00259 }
00260 }
00261
00262 template<class TCameraParams>
00263 CNodeMapRefT<TCameraParams>& GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::operator=(INodeMap* pNodeMap)
00264 {
00265 Release();
00266 assert(pNodeMap);
00267 if (pNodeMap)
00268 {
00269 Attach(pNodeMap, pNodeMap->GetDeviceName(), new int(0));
00270 }
00271
00272 return *this;
00273 }
00274
00275 template<class TCameraParams>
00276 CNodeMapRefT<TCameraParams>& GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::operator=(const CNodeMapRefT& Them)
00277 {
00278 Release();
00279 Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
00280 return *this;
00281 }
00282
00283 template<class TCameraParams>
00284 inline CNodeMapRefT<TCameraParams>::~CNodeMapRefT()
00285 {
00286 Release();
00287 }
00288
00289 template<class TCameraParams>
00290 inline void CNodeMapRefT<TCameraParams>::_Destroy()
00291 {
00292 Release();
00293 }
00294
00295
00296 template<class TCameraParams>
00297 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromFile(const GENICAM_NAMESPACE::gcstring &FileName)
00298 {
00299
00300
00301
00302 if(_Ptr)
00303 throw RUNTIME_EXCEPTION("Node map already created");
00304
00305
00306 CNodeMapFactory nodeMapData(ContentType_Xml, FileName);
00307 Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
00308 }
00309
00310 template<class TCameraParams>
00311 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName)
00312 {
00313
00314
00315
00316 if(_Ptr)
00317 throw RUNTIME_EXCEPTION("Node map already created");
00318
00319
00320 CNodeMapFactory nodeMapData(ContentType_ZippedXml, ZipFileName);
00321 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00322 }
00323
00324 template<class TCameraParams>
00325 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromFileInject(const GENICAM_NAMESPACE::gcstring &TargetFileName, const GENICAM_NAMESPACE::gcstring &InjectFileName)
00326 {
00327
00328
00329
00330 if(_Ptr)
00331 throw RUNTIME_EXCEPTION("Node map already created");
00332
00333
00334 CNodeMapFactory nodeMapData(ContentType_Xml, TargetFileName);
00335 CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectFileName);
00336 nodeMapData.AddInjectionData(injectNodeMapData);
00337 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00338 }
00339
00340 template<class TCameraParams>
00341 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromString(const GENICAM_NAMESPACE::gcstring& XMLData)
00342 {
00343
00344 if(_Ptr)
00345 throw RUNTIME_EXCEPTION("Node map already created");
00346
00347
00348 CNodeMapFactory nodeMapData(ContentType_Xml, XMLData.c_str(), XMLData.size());
00349 Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
00350 }
00351
00352
00353 template<class TCameraParams>
00354 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPData(const void* zipData, size_t zipSize)
00355 {
00356
00357 if(_Ptr)
00358 throw RUNTIME_EXCEPTION("Node map already created");
00359
00360
00361 CNodeMapFactory nodeMapData(ContentType_ZippedXml, zipData, zipSize);
00362 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00363 }
00364
00365 template<class TCameraParams>
00366 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromStringInject(const GENICAM_NAMESPACE::gcstring& TargetXMLData, const GENICAM_NAMESPACE::gcstring& InjectXMLData)
00367 {
00368
00369 if(_Ptr)
00370 throw RUNTIME_EXCEPTION("Node map already created");
00371
00372
00373 CNodeMapFactory nodeMapData(ContentType_Xml, TargetXMLData.c_str(), TargetXMLData.size());
00374 CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectXMLData.c_str(), InjectXMLData.size());
00375 nodeMapData.AddInjectionData(injectNodeMapData);
00376 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00377 }
00378
00379 template<class TCameraParams>
00380 inline void CNodeMapRefT<TCameraParams>::_GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
00381 {
00382 CNodeMapFactory().GetSupportedSchemaVersions(SchemaVersions);
00383 }
00384
00385 template<class TCameraParams>
00386 inline GENICAM_NAMESPACE::gcstring CNodeMapRefT<TCameraParams>::_GetDeviceName() const
00387 {
00388 if(_Ptr)
00389 return _Ptr->GetDeviceName();
00390 else
00391 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00392 }
00393
00394 template<class TCameraParams>
00395 inline void CNodeMapRefT<TCameraParams>::_Poll(int64_t ElapsedTime)
00396 {
00397 if(_Ptr)
00398 return _Ptr->Poll(ElapsedTime);
00399 else
00400 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00401 }
00402
00403 template<class TCameraParams>
00404 inline void CNodeMapRefT<TCameraParams>::_GetNodes(NodeList_t &Nodes) const
00405 {
00406 if(_Ptr)
00407 return _Ptr->GetNodes(Nodes);
00408 else
00409 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00410 }
00411
00412 template<class TCameraParams>
00413 inline INode* CNodeMapRefT<TCameraParams>::_GetNode(const GENICAM_NAMESPACE::gcstring& key) const
00414 {
00415 if(_Ptr)
00416 return _Ptr->GetNode(key);
00417 else
00418 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00419 }
00420
00421 template<class TCameraParams>
00422 inline void CNodeMapRefT<TCameraParams>::_InvalidateNodes() const
00423 {
00424 if(_Ptr)
00425 return _Ptr->InvalidateNodes();
00426 else
00427 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00428 }
00429
00430 template<class TCameraParams>
00431 inline bool CNodeMapRefT<TCameraParams>::_ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList ) const
00432 {
00433 bool ret = false;
00434 if (_Ptr)
00435 ret = _Ptr->ParseSwissKnifes(pErrorList);
00436 else
00437 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00438 return ret;
00439 }
00440
00441 template<class TCameraParams>
00442 inline bool CNodeMapRefT<TCameraParams>::_Connect(IPort* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const
00443 {
00444 if(_Ptr)
00445 return _Ptr->Connect(pPort, PortName);
00446 else
00447 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00448 }
00449
00450 template<class TCameraParams>
00451 inline bool CNodeMapRefT<TCameraParams>::_Connect(IPort* pPort) const
00452 {
00453 if(_Ptr)
00454 return _Ptr->Connect(pPort);
00455 else
00456 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00457 }
00458
00459
00460 template<class TCameraParams>
00461 inline bool CNodeMapRefT<TCameraParams>::_ClearXMLCache()
00462 {
00463 return CNodeMapFactory::ClearCache();
00464 }
00465
00470 class CGeneric_XMLLoaderParams
00471 {
00472 protected:
00473 virtual void _Initialize(GENAPI_NAMESPACE::INodeMap*) {}
00474 };
00475
00476
00483 class CNodeMapRef : public CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>
00484 {
00485 public:
00487 CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
00488 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(DeviceName)
00489 {
00490 }
00491
00493 CNodeMapRef(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
00494 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(pNodeMap, DeviceName)
00495 {
00496 }
00497
00499 CNodeMapRef(const CNodeMapRef& Them)
00500 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(Them)
00501 {
00502 }
00503
00505 CNodeMapRef& operator=(const CNodeMapRef& Them)
00506 {
00507 CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>::operator=(Them);
00508 return *this;
00509 }
00510
00512 CNodeMapRef& operator=(INodeMap* pNodeMap)
00513 {
00514 CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>::operator=(pNodeMap);
00515 return *this;
00516 }
00517 };
00518
00519 }
00520
00521 #endif // ifndef GENAPI_NODEMAPPTR_H