NodeMapRef.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 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 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_NODEMAPREF_H
32 #define GENAPI_NODEMAPREF_H
33 
34 #include <GenICamVersion.h>
35 #include <Base/GCString.h>
36 #include <Base/GCException.h>
37 
38 #include <GenApi/Pointer.h>
39 #include <GenApi/INodeMap.h>
40 #include <GenApi/IDestroy.h>
41 #include <GenApi/NodeMapFactory.h>
42 
43 #include <cstdlib>
44 
45 namespace GENAPI_NAMESPACE
46 {
47 
48 # ifdef _WIN32
49 
50  // see below in the Linux branch
51  inline IDestroy *CastToIDestroy(INodeMap *pNodeMap)
52  {
53  return dynamic_cast<IDestroy *>(pNodeMap);
54  }
55 
56 # else
59 # endif
60 
66  template<class TCameraParams>
67  class CNodeMapRefT : public TCameraParams
68  {
69  public:
71  CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device");
72 
74  CNodeMapRefT(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device");
75 
77  CNodeMapRefT(const CNodeMapRefT& Them);
78 
80  CNodeMapRefT& operator=(const CNodeMapRefT& Them);
81 
83  CNodeMapRefT& operator=(INodeMap* pNodeMap);
84 
86  virtual ~CNodeMapRefT();
87 
89  void _Destroy();
90 
92  void _LoadXMLFromFile(const GENICAM_NAMESPACE::gcstring &FileName);
93 
95  void _LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName);
96 
98  void _LoadXMLFromZIPData(const void* zipData, size_t zipSize);
99 
101  void _LoadXMLFromFileInject(const GENICAM_NAMESPACE::gcstring &TargetFileName, const GENICAM_NAMESPACE::gcstring &InjectFileName);
102 
104  void _LoadXMLFromString(const GENICAM_NAMESPACE::gcstring& XMLData);
105 
107  void _LoadXMLFromStringInject(const GENICAM_NAMESPACE::gcstring& TargetXMLDataconst, const GENICAM_NAMESPACE::gcstring& InjectXMLData);
108 
110 
114  virtual void _GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const;
115 
118 
120  virtual void _Poll(int64_t ElapsedTime);
121 
123  static bool _ClearXMLCache();
124 
125  //----------------------------------------------------------------
126  // INodeMap
127  //----------------------------------------------------------------
128 
130  virtual void _GetNodes(NodeList_t &Nodes) const;
131 
133  virtual INode* _GetNode(const GENICAM_NAMESPACE::gcstring& key) const;
134 
137 
139  virtual bool _ConcatenatedWrite(CNodeWriteConcatenator*, bool featureStreaming = true, GENICAM_NAMESPACE::gcstring_vector* pErrorList = NULL);
140 
142  virtual void _InvalidateNodes() const;
143 
145  virtual bool _Connect(IPort* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const;
146 
148  virtual bool _Connect(IPort* pPort) const;
149 
151  virtual bool _ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL ) const;
153  virtual bool _Connect(IPortStacked* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const;
154 
156  virtual bool _Connect(IPortStacked* pPort) const;
157 
160 
161  private:
164 
165  //ATTENTION: not thread safe
167  void Release();
168  void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount);
169  };
170 
171 
172 
173  template<class TCameraParams>
175  : _Ptr(NULL)
176  , _DeviceName(DeviceName)
177  , _pRefCount(NULL)
178  {
179  }
180 
181  template<class TCameraParams>
183  : _Ptr(NULL)
184  , _DeviceName(DeviceName)
185  , _pRefCount(NULL)
186  {
187  assert(pNodeMap);
188  Attach(pNodeMap, DeviceName, pNodeMap ? new int(0) : NULL);
189  }
190 
191  template<class TCameraParams>
193  : TCameraParams()
194  , _Ptr(NULL)
195  , _DeviceName()
196  , _pRefCount(NULL)
197  {
198  Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
199  }
200 
201  //ATTENTION: not thread safe
202  template<class TCameraParams>
204  {
205  // Must be empty
206  assert(_Ptr == NULL);
207  assert(_pRefCount == NULL);
208 
209  //always copy device name
210  if (&_DeviceName != &DeviceName) //if not assigning member itself
211  {
212  _DeviceName = DeviceName;
213  }
214 
215  // Attach
216  if (pNodeMap)
217  {
218  assert(pRefCount);
219  if (pRefCount)
220  {
221  ++*pRefCount;
222 
223  //assign new node map data
224  _Ptr = pNodeMap;
225  _pRefCount = pRefCount;
226 
227  // Initialize the references
228  TCameraParams::_Initialize(_Ptr);
229  }
230  }
231  }
232 
233  //ATTENTION: not thread safe
234  template<class TCameraParams>
236  {
237  if (_Ptr)
238  {
239  // Copy node map data for eventual later destruction
240  INodeMap* pToDel = _Ptr;
241  int* pRefCount = _pRefCount;
242 
243  // Clear
244  _pRefCount = NULL;
245  _Ptr = NULL;
246  _DeviceName = "Device";
247 
248  assert(pRefCount);
249  // Check if destruction is required
250  if (pRefCount)
251  {
252  assert(*pRefCount > 0);
253  --*pRefCount;
254  if (*pRefCount == 0)
255  {
256  // We do not need this anymore, all references are gone
257  delete pRefCount;
258  pRefCount = NULL;
259 
260  // Destroy the node map finally
261  GENAPI_NAMESPACE::IDestroy *pDestroy = CastToIDestroy(pToDel);
262  assert(pDestroy);
263  pDestroy->Destroy(); //must not throw
264  }
265  }
266  }
267  else
268  {
269  // Must not have a refcount when no node map is there.
270  assert(_pRefCount == NULL);
271  }
272  }
273 
274  template<class TCameraParams>
276  {
277  Release();
278  assert(pNodeMap);
279  if (pNodeMap)
280  {
281  Attach(pNodeMap, pNodeMap->GetDeviceName(), new int(0));
282  }
283 
284  return *this;
285  }
286 
287  template<class TCameraParams>
289  {
290  Release();
291  Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
292  return *this;
293  }
294 
295  template<class TCameraParams>
297  {
298  Release();
299  }
300 
301  template<class TCameraParams>
303  {
304  Release();
305  }
306 
307 
308  template<class TCameraParams>
310  {
311  // FileName environment is replaced in CNodeMapFactory ctor
312 
313  // Load the DLL
314  if(_Ptr)
315  throw RUNTIME_EXCEPTION("Node map already created");
316 
317  // Load the XML file
318  CNodeMapFactory nodeMapData(ContentType_Xml, FileName);
319  Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
320  }
321 
322  template<class TCameraParams>
324  {
325  // FileName environment is replaced in CNodeMapFactory ctor
326 
327  // Load the DLL
328  if(_Ptr)
329  throw RUNTIME_EXCEPTION("Node map already created");
330 
331  // Load the XML file
332  CNodeMapFactory nodeMapData(ContentType_ZippedXml, ZipFileName);
333  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
334  }
335 
336  template<class TCameraParams>
338  {
339  // xxxFileName environment is replaced in CNodeMapFactory ctor
340 
341  // Load the DLL
342  if(_Ptr)
343  throw RUNTIME_EXCEPTION("Node map already created");
344 
345  // Load the XML file
346  CNodeMapFactory nodeMapData(ContentType_Xml, TargetFileName);
347  CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectFileName);
348  nodeMapData.AddInjectionData(injectNodeMapData);
349  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
350  }
351 
352  template<class TCameraParams>
354  {
355  // Load the DLL
356  if(_Ptr)
357  throw RUNTIME_EXCEPTION("Node map already created");
358 
359  // Load the XML file
360  CNodeMapFactory nodeMapData(ContentType_Xml, XMLData.c_str(), XMLData.size()); //avoid string copy
361  Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
362  }
363 
364 
365  template<class TCameraParams>
366  inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPData(const void* zipData, size_t zipSize)
367  {
368  // Load the DLL
369  if(_Ptr)
370  throw RUNTIME_EXCEPTION("Node map already created");
371 
372  // Load the XML file
373  CNodeMapFactory nodeMapData(ContentType_ZippedXml, zipData, zipSize);
374  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
375  }
376 
377  template<class TCameraParams>
379  {
380  // Load the DLL
381  if(_Ptr)
382  throw RUNTIME_EXCEPTION("Node map already created");
383 
384  // Load the XML file
385  CNodeMapFactory nodeMapData(ContentType_Xml, TargetXMLData.c_str(), TargetXMLData.size()); //avoid string copy
386  CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectXMLData.c_str(), InjectXMLData.size()); //avoid string copy
387  nodeMapData.AddInjectionData(injectNodeMapData);
388  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
389  }
390 
391  template<class TCameraParams>
392  inline void CNodeMapRefT<TCameraParams>::_GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
393  {
395  }
396 
397  template<class TCameraParams>
399  {
400  if(_Ptr)
401  return _Ptr->GetDeviceName();
402  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
403  }
404 
405  template<class TCameraParams>
407  {
408  if(_Ptr)
409  return _Ptr->Poll(ElapsedTime);
410  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
411  }
412 
413  template<class TCameraParams>
415  {
416  if(_Ptr)
417  return _Ptr->GetNodes(Nodes);
418  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
419  }
420 
421  template<class TCameraParams>
423  {
424  if (_Ptr)
425  return _Ptr->NewNodeWriteConcatenator();
426  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
427  }
428 
429  template<class TCameraParams>
430  inline bool CNodeMapRefT<TCameraParams>::_ConcatenatedWrite(CNodeWriteConcatenator* pConcatenatedWrite, bool featureStreaming, GENICAM_NAMESPACE::gcstring_vector* pErrorList)
431  {
432  if (_Ptr)
433  return _Ptr->ConcatenatedWrite(pConcatenatedWrite, featureStreaming, pErrorList);
434  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
435  }
436 
437  template<class TCameraParams>
439  {
440  if(_Ptr)
441  return _Ptr->GetNode(key);
442  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
443  }
444 
445  template<class TCameraParams>
447  {
448  if(_Ptr)
449  return _Ptr->InvalidateNodes();
450  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
451  }
452 
453  template<class TCameraParams>
454  inline bool CNodeMapRefT<TCameraParams>::_ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList ) const
455  {
456  if (_Ptr)
457  return _Ptr->ParseSwissKnifes(pErrorList);
458  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
459  }
460 
461  template<class TCameraParams>
463  {
464  if(_Ptr)
465  return _Ptr->Connect(pPort, PortName);
466  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
467  }
468 
469  template<class TCameraParams>
471  {
472  if(_Ptr)
473  return _Ptr->Connect(pPort);
474  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
475  }
476 
477  template<class TCameraParams>
479  {
480  if (_Ptr)
481  return _Ptr->Connect(pPort, PortName);
482  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
483  }
484 
485  template<class TCameraParams>
487  {
488  if (_Ptr)
489  return _Ptr->Connect(pPort);
490  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
491  }
492 
493  template<class TCameraParams>
495  {
497  }
498 
504  {
505  protected:
507  };
508 
509 
516  class CNodeMapRef : public CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>
517  {
518  public:
520  CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
522  {
523  }
524 
526  CNodeMapRef(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
527  : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(pNodeMap, DeviceName)
528  {
529  }
530 
534  {
535  }
536 
539  {
541  return *this;
542  }
543 
546  {
548  return *this;
549  }
550  };
551 
552 }
553 
554 #endif // ifndef GENAPI_NODEMAPPTR_H
The node map factory is used for creating node maps from camera description files.
void _LoadXMLFromFile(const GENICAM_NAMESPACE::gcstring &FileName)
Creates the object from a XML file with given file name.
Definition: NodeMapRef.h:309
virtual INode * _GetNode(const GENICAM_NAMESPACE::gcstring &key) const
Retrieves the node from the central map by name.
Definition: NodeMapRef.h:438
virtual void _Poll(int64_t ElapsedTime)
Fires nodes which have a polling time.
Definition: NodeMapRef.h:406
virtual size_t size(void) const
CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:520
Definition of interface IDestroy.
Empty base class used by class CNodeMapRef as generic template argument.
Definition: NodeMapRef.h:503
void AddInjectionData(CNodeMapFactory &injectionData)
Adds a node map factory representing a camera description file to inject.
void _LoadXMLFromFileInject(const GENICAM_NAMESPACE::gcstring &TargetFileName, const GENICAM_NAMESPACE::gcstring &InjectFileName)
Creates the object from a XML target and an inject file with given file name.
Definition: NodeMapRef.h:337
Zipped XML camera description file text.
virtual bool _ConcatenatedWrite(CNodeWriteConcatenator *, bool featureStreaming=true, GENICAM_NAMESPACE::gcstring_vector *pErrorList=NULL)
Execute the transaction.
Definition: NodeMapRef.h:430
CNodeMapRef & operator=(INodeMap *pNodeMap)
Assignment of an INodeMap*.
Definition: NodeMapRef.h:545
void _Destroy()
Destroys the node map.
Definition: NodeMapRef.h:302
__int64 int64_t
Definition: config-win32.h:21
CNodeMapRef(const CNodeMapRef &Them)
Copy constructor.
Definition: NodeMapRef.h:532
static bool ClearCache()
Deletes all preprocessed camera description files from the cache.
GENICAM_INTERFACE INodeMap
Interface to access the node map.
Definition: INode.h:52
GENAPI_DECL IDestroy * CastToIDestroy(INodeMap *pNodeMap)
makes sure the dynamic_cast operator is implemented in the DLL (due to a Linux bug) ...
#define GENAPI_DECL
Definition: GenApiDll.h:55
virtual void _GetNodes(NodeList_t &Nodes) const
Retrieves all nodes in the node map.
Definition: NodeMapRef.h:414
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition: GCException.h:247
virtual bool _Connect(IPort *pPort, const GENICAM_NAMESPACE::gcstring &PortName) const
Connects a port to a port node with given name.
Definition: NodeMapRef.h:462
central versioning counters
CNodeMapRef(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:526
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IPortStacked
Interface for ports.
Definition: IPortStacked.h:63
INodeMap * _Ptr
Pointer to the NodeMap.
Definition: NodeMapRef.h:159
node_vector NodeList_t
a list of node references
Definition: INode.h:55
void _LoadXMLFromStringInject(const GENICAM_NAMESPACE::gcstring &TargetXMLDataconst, const GENICAM_NAMESPACE::gcstring &InjectXMLData)
Creates the object from XML data given in a string with injection.
Definition: NodeMapRef.h:378
#define ACCESS_EXCEPTION
Fires a access exception, e.g. throw ACCESS_EXCEPTION("Not everybody")
Definition: GCException.h:253
Smartpointer template for NodeMaps with create function.
Definition: NodeMapRef.h:67
virtual void _Initialize(GENAPI_NAMESPACE::INodeMap *)
Definition: NodeMapRef.h:506
void _LoadXMLFromString(const GENICAM_NAMESPACE::gcstring &XMLData)
Creates the object from XML data given in a string.
Definition: NodeMapRef.h:353
Definition of interface INodeMap.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IDestroy
Interface to destroy an object.
Definition: IDestroy.h:35
virtual bool _ParseSwissKnifes(GENICAM_NAMESPACE::gcstring_vector *pErrorList=NULL) const
Parse all Swissknife equations.
Definition: NodeMapRef.h:454
virtual GENICAM_NAMESPACE::gcstring _GetDeviceName() const
Get device name.
Definition: NodeMapRef.h:398
Definition of the node map factory.
virtual void _InvalidateNodes() const
Invalidates all nodes.
Definition: NodeMapRef.h:446
INodeMap * CreateNodeMap(const GENICAM_NAMESPACE::gcstring &DeviceName="Device", bool DoReleaseCameraDescriptionFileData=true)
Creates a node map from the preprocessed memory internal representation of the camera description fil...
void _LoadXMLFromZIPData(const void *zipData, size_t zipSize)
Creates the object from a ZIP&#39;d XML file given in a string.
Definition: NodeMapRef.h:366
void _LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName)
Creates the object from a ZIP&#39;d XML file with given file name.
Definition: NodeMapRef.h:323
void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int *pRefCount)
Definition: NodeMapRef.h:203
GENICAM_NAMESPACE::gcstring _DeviceName
The name of this device.
Definition: NodeMapRef.h:163
Definition of template CPointer.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IPort
Interface for ports.
Definition: IPort.h:57
virtual CNodeWriteConcatenator * _NewNodeWriteConcatenator() const
Create a new write concatenator object.
Definition: NodeMapRef.h:422
A string class which is a clone of std::string.
Definition: GCString.h:52
static bool _ClearXMLCache()
Clears the cache of the camera description files.
Definition: NodeMapRef.h:494
Portable string implementation.
XML camera description file text.
CNodeMapRef & operator=(const CNodeMapRef &Them)
Assignment.
Definition: NodeMapRef.h:538
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
void GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
virtual ~CNodeMapRefT()
Destructor.
Definition: NodeMapRef.h:296
CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:174
CNodeMapRefT & operator=(const CNodeMapRefT &Them)
Assignment.
Definition: NodeMapRef.h:288
virtual const char * c_str(void) const
Lexical analyzer for CIntSwissKnife.
Definition: Autovector.h:48
Smartpointer for NodeMaps with create function.
Definition: NodeMapRef.h:516
virtual void _GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
Gets a list of supported schema versions.
Definition: NodeMapRef.h:392


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:41