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 
136  virtual void _InvalidateNodes() const;
137 
139  virtual bool _Connect(IPort* pPort, const GENICAM_NAMESPACE::gcstring& PortName) const;
140 
142  virtual bool _Connect(IPort* pPort) const;
143 
145  virtual bool _ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL ) const;
148 
149  private:
152 
153  //ATTENTION: not thread safe
155  void Release();
156  void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int* pRefCount);
157  };
158 
159 
160 
161  template<class TCameraParams>
163  : _Ptr(NULL)
164  , _DeviceName(DeviceName)
165  , _pRefCount(NULL)
166  {
167  }
168 
169  template<class TCameraParams>
171  : _Ptr(NULL)
172  , _DeviceName(DeviceName)
173  , _pRefCount(NULL)
174  {
175  assert(pNodeMap);
176  Attach(pNodeMap, DeviceName, pNodeMap ? new int(0) : NULL);
177  }
178 
179  template<class TCameraParams>
181  : TCameraParams()
182  , _Ptr(NULL)
183  , _DeviceName()
184  , _pRefCount(NULL)
185  {
186  Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
187  }
188 
189  //ATTENTION: not thread safe
190  template<class TCameraParams>
192  {
193  // Must be empty
194  assert(_Ptr == NULL);
195  assert(_pRefCount == NULL);
196 
197  //always copy device name
198  if (&_DeviceName != &DeviceName) //if not assigning member itself
199  {
200  _DeviceName = DeviceName;
201  }
202 
203  // Attach
204  if (pNodeMap)
205  {
206  assert(pRefCount);
207  if (pRefCount)
208  {
209  ++*pRefCount;
210 
211  //assign new node map data
212  _Ptr = pNodeMap;
213  _pRefCount = pRefCount;
214 
215  // Initialize the references
216  TCameraParams::_Initialize(_Ptr);
217  }
218  }
219  }
220 
221  //ATTENTION: not thread safe
222  template<class TCameraParams>
224  {
225  if (_Ptr)
226  {
227  // Copy node map data for eventual later destruction
228  INodeMap* pToDel = _Ptr;
229  int* pRefCount = _pRefCount;
230 
231  // Clear
232  _pRefCount = NULL;
233  _Ptr = NULL;
234  _DeviceName = "Device";
235 
236  assert(pRefCount);
237  // Check if destruction is required
238  if (pRefCount)
239  {
240  assert(*pRefCount > 0);
241  --*pRefCount;
242  if (*pRefCount == 0)
243  {
244  // We do not need this anymore, all references are gone
245  delete pRefCount;
246  pRefCount = NULL;
247 
248  // Destroy the node map finally
249  GENAPI_NAMESPACE::IDestroy *pDestroy = CastToIDestroy(pToDel);
250  assert(pDestroy);
251  pDestroy->Destroy(); //must not throw
252  }
253  }
254  }
255  else
256  {
257  // Must not have a refcount when no node map is there.
258  assert(_pRefCount == NULL);
259  }
260  }
261 
262  template<class TCameraParams>
264  {
265  Release();
266  assert(pNodeMap);
267  if (pNodeMap)
268  {
269  Attach(pNodeMap, pNodeMap->GetDeviceName(), new int(0));
270  }
271 
272  return *this;
273  }
274 
275  template<class TCameraParams>
277  {
278  Release();
279  Attach(Them._Ptr, Them._DeviceName, Them._pRefCount);
280  return *this;
281  }
282 
283  template<class TCameraParams>
285  {
286  Release();
287  }
288 
289  template<class TCameraParams>
291  {
292  Release();
293  }
294 
295 
296  template<class TCameraParams>
298  {
299  // FileName environment is replaced in CNodeMapFactory ctor
300 
301  // Load the DLL
302  if(_Ptr)
303  throw RUNTIME_EXCEPTION("Node map already created");
304 
305  // Load the XML file
306  CNodeMapFactory nodeMapData(ContentType_Xml, FileName);
307  Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
308  }
309 
310  template<class TCameraParams>
312  {
313  // FileName environment is replaced in CNodeMapFactory ctor
314 
315  // Load the DLL
316  if(_Ptr)
317  throw RUNTIME_EXCEPTION("Node map already created");
318 
319  // Load the XML file
320  CNodeMapFactory nodeMapData(ContentType_ZippedXml, ZipFileName);
321  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
322  }
323 
324  template<class TCameraParams>
326  {
327  // xxxFileName environment is replaced in CNodeMapFactory ctor
328 
329  // Load the DLL
330  if(_Ptr)
331  throw RUNTIME_EXCEPTION("Node map already created");
332 
333  // Load the XML file
334  CNodeMapFactory nodeMapData(ContentType_Xml, TargetFileName);
335  CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectFileName);
336  nodeMapData.AddInjectionData(injectNodeMapData);
337  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
338  }
339 
340  template<class TCameraParams>
342  {
343  // Load the DLL
344  if(_Ptr)
345  throw RUNTIME_EXCEPTION("Node map already created");
346 
347  // Load the XML file
348  CNodeMapFactory nodeMapData(ContentType_Xml, XMLData.c_str(), XMLData.size()); //avoid string copy
349  Attach(nodeMapData.CreateNodeMap(_DeviceName), _DeviceName, new int(0));
350  }
351 
352 
353  template<class TCameraParams>
354  inline void CNodeMapRefT<TCameraParams>::_LoadXMLFromZIPData(const void* zipData, size_t zipSize)
355  {
356  // Load the DLL
357  if(_Ptr)
358  throw RUNTIME_EXCEPTION("Node map already created");
359 
360  // Load the XML file
361  CNodeMapFactory nodeMapData(ContentType_ZippedXml, zipData, zipSize);
362  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
363  }
364 
365  template<class TCameraParams>
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_Xml, TargetXMLData.c_str(), TargetXMLData.size()); //avoid string copy
374  CNodeMapFactory injectNodeMapData(ContentType_Xml, InjectXMLData.c_str(), InjectXMLData.size()); //avoid string copy
375  nodeMapData.AddInjectionData(injectNodeMapData);
376  Attach(nodeMapData.CreateNodeMap(), _DeviceName, new int(0));
377  }
378 
379  template<class TCameraParams>
380  inline void CNodeMapRefT<TCameraParams>::_GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
381  {
383  }
384 
385  template<class TCameraParams>
387  {
388  if(_Ptr)
389  return _Ptr->GetDeviceName();
390  else
391  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
392  }
393 
394  template<class TCameraParams>
396  {
397  if(_Ptr)
398  return _Ptr->Poll(ElapsedTime);
399  else
400  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
401  }
402 
403  template<class TCameraParams>
405  {
406  if(_Ptr)
407  return _Ptr->GetNodes(Nodes);
408  else
409  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
410  }
411 
412  template<class TCameraParams>
414  {
415  if(_Ptr)
416  return _Ptr->GetNode(key);
417  else
418  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
419  }
420 
421  template<class TCameraParams>
423  {
424  if(_Ptr)
425  return _Ptr->InvalidateNodes();
426  else
427  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
428  }
429 
430  template<class TCameraParams>
431  inline bool CNodeMapRefT<TCameraParams>::_ParseSwissKnifes( GENICAM_NAMESPACE::gcstring_vector *pErrorList ) const
432  {
433  bool ret = false;
434  if (_Ptr)
435  ret = _Ptr->ParseSwissKnifes(pErrorList);
436  else
437  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
438  return ret;
439  }
440 
441  template<class TCameraParams>
443  {
444  if(_Ptr)
445  return _Ptr->Connect(pPort, PortName);
446  else
447  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
448  }
449 
450  template<class TCameraParams>
452  {
453  if(_Ptr)
454  return _Ptr->Connect(pPort);
455  else
456  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
457  }
458 
459 
460  template<class TCameraParams>
462  {
464  }
465 
471  {
472  protected:
474  };
475 
476 
483  class CNodeMapRef : public CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>
484  {
485  public:
487  CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
489  {
490  }
491 
493  CNodeMapRef(INodeMap* pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName = "Device")
494  : CNodeMapRefT<GENAPI_NAMESPACE::CGeneric_XMLLoaderParams>(pNodeMap, DeviceName)
495  {
496  }
497 
501  {
502  }
503 
506  {
508  return *this;
509  }
510 
513  {
515  return *this;
516  }
517  };
518 
519 }
520 
521 #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:297
virtual INode * _GetNode(const GENICAM_NAMESPACE::gcstring &key) const
Retrieves the node from the central map by name.
Definition: NodeMapRef.h:413
virtual void _Poll(int64_t ElapsedTime)
Fires nodes which have a polling time.
Definition: NodeMapRef.h:395
virtual size_t size(void) const
CNodeMapRef(const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:487
Definition of interface IDestroy.
Empty base class used by class CNodeMapRef as generic template argument.
Definition: NodeMapRef.h:470
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:325
Zipped XML camera description file text.
interface GENAPI_DECL_ABSTRACT IPort
Interface for ports.
Definition: IPort.h:57
CNodeMapRef & operator=(INodeMap *pNodeMap)
Assignment of an INodeMap*.
Definition: NodeMapRef.h:512
void _Destroy()
Destroys the node map.
Definition: NodeMapRef.h:290
__int64 int64_t
Definition: config-win32.h:21
CNodeMapRef(const CNodeMapRef &Them)
Copy constructor.
Definition: NodeMapRef.h:499
interface GENAPI_DECL_ABSTRACT INodeMap
Interface to access the node map.
Definition: INodeMap.h:56
static bool ClearCache()
Deletes all preprocessed camera description files from the cache.
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:404
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition: GCException.h:246
virtual bool _Connect(IPort *pPort, const GENICAM_NAMESPACE::gcstring &PortName) const
Connects a port to a port node with given name.
Definition: NodeMapRef.h:442
central versioning counters
CNodeMapRef(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:493
INodeMap * _Ptr
Pointer to the NodeMap.
Definition: NodeMapRef.h:147
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:366
#define ACCESS_EXCEPTION
Fires a access exception, e.g. throw ACCESS_EXCEPTION("Not everybody")
Definition: GCException.h:252
Smartpointer template for NodeMaps with create function.
Definition: NodeMapRef.h:67
virtual void _Initialize(GENAPI_NAMESPACE::INodeMap *)
Definition: NodeMapRef.h:473
void _LoadXMLFromString(const GENICAM_NAMESPACE::gcstring &XMLData)
Creates the object from XML data given in a string.
Definition: NodeMapRef.h:341
Definition of interface INodeMap.
virtual bool _ParseSwissKnifes(GENICAM_NAMESPACE::gcstring_vector *pErrorList=NULL) const
Parse all Swissknife equations.
Definition: NodeMapRef.h:431
virtual GENICAM_NAMESPACE::gcstring _GetDeviceName() const
Get device name.
Definition: NodeMapRef.h:386
Definition of the node map factory.
virtual void _InvalidateNodes() const
Invalidates all nodes.
Definition: NodeMapRef.h:422
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:354
void _LoadXMLFromZIPFile(const GENICAM_NAMESPACE::gcstring &ZipFileName)
Creates the object from a ZIP&#39;d XML file with given file name.
Definition: NodeMapRef.h:311
void Attach(INodeMap *pNodeMap, const GENICAM_NAMESPACE::gcstring &DeviceName, int *pRefCount)
Definition: NodeMapRef.h:191
GENICAM_NAMESPACE::gcstring _DeviceName
The name of this device.
Definition: NodeMapRef.h:151
Definition of template CPointer.
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:461
Portable string implementation.
XML camera description file text.
CNodeMapRef & operator=(const CNodeMapRef &Them)
Assignment.
Definition: NodeMapRef.h:505
void GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
interface GENAPI_DECL_ABSTRACT INode
Interface common to all nodes.
Definition: INode.h:60
virtual ~CNodeMapRefT()
Destructor.
Definition: NodeMapRef.h:284
CNodeMapRefT(const GENICAM_NAMESPACE::gcstring &DeviceName="Device")
Constructor.
Definition: NodeMapRef.h:162
CNodeMapRefT & operator=(const CNodeMapRefT &Them)
Assignment.
Definition: NodeMapRef.h:276
virtual const char * c_str(void) const
Part of the generic device API.
Definition: Autovector.h:48
Smartpointer for NodeMaps with create function.
Definition: NodeMapRef.h:483
virtual void _GetSupportedSchemaVersions(GENICAM_NAMESPACE::gcstring_vector &SchemaVersions) const
Gets a list of supported schema versions.
Definition: NodeMapRef.h:380
interface GENAPI_DECL_ABSTRACT IDestroy
Interface to destroy an object.
Definition: IDestroy.h:35


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54