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 INodeMap *_Ptr;
00146
00147 private:
00149 GENICAM_NAMESPACE::gcstring _DeviceName;
00150
00151
00152 int* _pRefCount;
00153 void Release();
00154 void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount);
00155 };
00156
00157
00158
00159 template<class TCameraParams>
00160 inline CNodeMapRefT<TCameraParams>::CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName)
00161 : _Ptr(NULL)
00162 , _DeviceName(DeviceName)
00163 , _pRefCount(NULL)
00164 {
00165 }
00166
00167 template<class TCameraParams>
00168 inline CNodeMapRefT<TCameraParams>::CNodeMapRefT(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName)
00169 : _Ptr(NULL)
00170 , _DeviceName(DeviceName)
00171 , _pRefCount(NULL)
00172 {
00173 assert(pNodeMap);
00174 Attach(pNodeMap, DeviceName, pNodeMap ? new int(0) : NULL);
00175 }
00176
00177 template<class TCameraParams>
00178 GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::CNodeMapRefT(const CNodeMapRefT& Them)
00179 : TCameraParams()
00180 , _Ptr(NULL)
00181 , _DeviceName()
00182 , _pRefCount(NULL)
00183 {
00184 Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
00185 }
00186
00187
00188 template<class TCameraParams>
00189 void GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount)
00190 {
00191
00192 assert(_Ptr == NULL);
00193 assert(_pRefCount == NULL);
00194
00195
00196 if (&_DeviceName != &DeviceName)
00197 {
00198 _DeviceName = DeviceName;
00199 }
00200
00201
00202 if (pNodeMap)
00203 {
00204 assert(pRefCount);
00205 if (pRefCount)
00206 {
00207 ++*pRefCount;
00208
00209
00210 _Ptr = pNodeMap;
00211 _pRefCount = pRefCount;
00212
00213
00214 TCameraParams::_Initialize(_Ptr);
00215 }
00216 }
00217 }
00218
00219
00220 template<class TCameraParams>
00221 void GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::Release()
00222 {
00223 if (_Ptr)
00224 {
00225
00226 INodeMap* pToDel = _Ptr;
00227 int* pRefCount = _pRefCount;
00228
00229
00230 _pRefCount = NULL;
00231 _Ptr = NULL;
00232 _DeviceName = "Device";
00233
00234 assert(pRefCount);
00235
00236 if (pRefCount)
00237 {
00238 assert(*pRefCount > 0);
00239 --*pRefCount;
00240 if (*pRefCount == 0)
00241 {
00242
00243 delete pRefCount;
00244 pRefCount = NULL;
00245
00246
00247 GENAPI_NAMESPACE::IDestroy *pDestroy = CastToIDestroy(pToDel);
00248 assert(pDestroy);
00249 pDestroy->Destroy();
00250 }
00251 }
00252 }
00253 else
00254 {
00255
00256 assert(_pRefCount == NULL);
00257 }
00258 }
00259
00260 template<class TCameraParams>
00261 CNodeMapRefT<TCameraParams>& GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::operator=(INodeMap* pNodeMap)
00262 {
00263 Release();
00264 assert(pNodeMap);
00265 if (pNodeMap)
00266 {
00267 Attach(pNodeMap, pNodeMap->GetDeviceName(), new int(0));
00268 }
00269
00270 return *this;
00271 }
00272
00273 template<class TCameraParams>
00274 CNodeMapRefT<TCameraParams>& GENAPI_NAMESPACE::CNodeMapRefT<TCameraParams>::operator=(const CNodeMapRefT& Them)
00275 {
00276 Release();
00277 Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
00278 return *this;
00279 }
00280
00281 template<class TCameraParams>
00282 inline CNodeMapRefT<TCameraParams>::~CNodeMapRefT()
00283 {
00284 Release();
00285 }
00286
00287 template<class TCameraParams>
00288 inline void CNodeMapRefT<TCameraParams>::_Destroy()
00289 {
00290 Release();
00291 }
00292
00293
00294 template<class TCameraParams>
00295 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromFile(const GENICAM_NAMESPACE::gcstring &FileName)
00296 {
00297
00298
00299
00300 if(_Ptr)
00301 throw RUNTIME_EXCEPTION("Node map already created");
00302
00303
00304 CNodeMapFactory nodeMapData(ContentType_Xml, FileName);
00305 Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
00306 }
00307
00308 template<class TCameraParams>
00309 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName)
00310 {
00311
00312
00313
00314 if(_Ptr)
00315 throw RUNTIME_EXCEPTION("Node map already created");
00316
00317
00318 CNodeMapFactory nodeMapData(ContentType_ZippedXml, ZipFileName);
00319 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00320 }
00321
00322 template<class TCameraParams>
00323 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromFileInject(const GENICAM_NAMESPACE::gcstring &TargetFileName, const GENICAM_NAMESPACE::gcstring &InjectFileName)
00324 {
00325
00326
00327
00328 if(_Ptr)
00329 throw RUNTIME_EXCEPTION("Node map already created");
00330
00331
00332 CNodeMapFactory nodeMapData(ContentType_Xml, TargetFileName);
00333 CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectFileName);
00334 nodeMapData.AddInjectionData(injectNodeMapData);
00335 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00336 }
00337
00338 template<class TCameraParams>
00339 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromString(const GENICAM_NAMESPACE::gcstring& XMLData)
00340 {
00341
00342 if(_Ptr)
00343 throw RUNTIME_EXCEPTION("Node map already created");
00344
00345
00346 CNodeMapFactory nodeMapData(ContentType_Xml, XMLData.c_str(), XMLData.size());
00347 Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
00348 }
00349
00350
00351 template<class TCameraParams>
00352 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPData(const void* zipData, size_t zipSize)
00353 {
00354
00355 if(_Ptr)
00356 throw RUNTIME_EXCEPTION("Node map already created");
00357
00358
00359 CNodeMapFactory nodeMapData(ContentType_ZippedXml, zipData, zipSize);
00360 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00361 }
00362
00363 template<class TCameraParams>
00364 inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromStringInject(const GENICAM_NAMESPACE::gcstring& TargetXMLData, const GENICAM_NAMESPACE::gcstring& InjectXMLData)
00365 {
00366
00367 if(_Ptr)
00368 throw RUNTIME_EXCEPTION("Node map already created");
00369
00370
00371 CNodeMapFactory nodeMapData(ContentType_Xml, TargetXMLData.c_str(), TargetXMLData.size());
00372 CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectXMLData.c_str(), InjectXMLData.size());
00373 nodeMapData.AddInjectionData(injectNodeMapData);
00374 Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
00375 }
00376
00377 template<class TCameraParams>
00378 inline void CNodeMapRefT<TCameraParams>::_GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
00379 {
00380 CNodeMapFactory().GetSupportedSchemaVersions(SchemaVersions);
00381 }
00382
00383 template<class TCameraParams>
00384 inline GENICAM_NAMESPACE::gcstring CNodeMapRefT<TCameraParams>::_GetDeviceName() const
00385 {
00386 if(_Ptr)
00387 return _Ptr->GetDeviceName();
00388 else
00389 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00390 }
00391
00392 template<class TCameraParams>
00393 inline void CNodeMapRefT<TCameraParams>::_Poll(int64_t ElapsedTime)
00394 {
00395 if(_Ptr)
00396 return _Ptr->Poll(ElapsedTime);
00397 else
00398 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00399 }
00400
00401 template<class TCameraParams>
00402 inline void CNodeMapRefT<TCameraParams>::_GetNodes(NodeList_t &Nodes) const
00403 {
00404 if(_Ptr)
00405 return _Ptr->GetNodes(Nodes);
00406 else
00407 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00408 }
00409
00410 template<class TCameraParams>
00411 inline INode* CNodeMapRefT<TCameraParams>::_GetNode(const GENICAM_NAMESPACE::gcstring& key) const
00412 {
00413 if(_Ptr)
00414 return _Ptr->GetNode(key);
00415 else
00416 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00417 }
00418
00419 template<class TCameraParams>
00420 inline void CNodeMapRefT<TCameraParams>::_InvalidateNodes() const
00421 {
00422 if(_Ptr)
00423 return _Ptr->InvalidateNodes();
00424 else
00425 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00426 }
00427
00428 template<class TCameraParams>
00429 inline bool CNodeMapRefT<TCameraParams>::_Connect(IPort* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const
00430 {
00431 if(_Ptr)
00432 return _Ptr->Connect(pPort, PortName);
00433 else
00434 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00435 }
00436
00437 template<class TCameraParams>
00438 inline bool CNodeMapRefT<TCameraParams>::_Connect(IPort* pPort) const
00439 {
00440 if(_Ptr)
00441 return _Ptr->Connect(pPort);
00442 else
00443 throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
00444 }
00445
00446
00447 template<class TCameraParams>
00448 inline bool CNodeMapRefT<TCameraParams>::_ClearXMLCache()
00449 {
00450 return CNodeMapFactory::ClearCache();
00451 }
00452
00457 class CGeneric_XMLLoaderParams
00458 {
00459 protected:
00460 virtual void _Initialize(GENAPI_NAMESPACE::INodeMap*) {}
00461 };
00462
00463
00470 class CNodeMapRef : public CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>
00471 {
00472 public:
00474 CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
00475 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(DeviceName)
00476 {
00477 }
00478
00480 CNodeMapRef(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
00481 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(pNodeMap, DeviceName)
00482 {
00483 }
00484
00486 CNodeMapRef(const CNodeMapRef& Them)
00487 : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(Them)
00488 {
00489 }
00490
00492 CNodeMapRef& operator=(const CNodeMapRef& Them)
00493 {
00494 CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>::operator=(Them);
00495 return *this;
00496 }
00497
00499 CNodeMapRef& operator=(INodeMap* pNodeMap)
00500 {
00501 CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>::operator=(pNodeMap);
00502 return *this;
00503 }
00504 };
00505
00506 }
00507
00508 #endif // ifndef GENAPI_NODEMAPPTR_H