Buffer Interface
BFGTLUtilities.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef INCLUDED__BITFLOW__B_F_G_T_L__UTILITIES__HPP
3 #define INCLUDED__BITFLOW__B_F_G_T_L__UTILITIES__HPP
4 
5 #include "BFGTLUtilApi.h"
6 
7 #include "BFException.hpp"
8 
9 #include <string>
10 #include <vector>
11 
113 // Externally defined classes.
115 {
116  class BufferInterface;
117 }
118 
119 // The BFGTLUtilities namespace.
120 namespace BFGTLUtilities
121 {
122  // Static method to determine if the base library can be loaded.
123  BFDLL BFBOOL BFCAPI LibIsGood (void);
124 
125  // Forward declation(s).
126  struct BaseNode;
127 
128  // The BFGTL Camera Device.
129  class BFDLL Device
130  {
131  public:
132  // Default constructor.
133  Device (BFVOID);
134 
135  // Destructor.
136  ~Device (BFVOID);
137 
138  // Returns the number of BitFlow boards installed on this system.
139  static BFU32 boardCount (BFVOID);
140 
141  // Open the Device corresponding to specified BufferInterface. The Device must be closed prior
142  // to closing the BufferInterface. Closes the current Device first, if necessary.
143  BFVOID open (BufferAcquisition::BufferInterface const& bufin);
144 
145  // Open the BFGTL Camera Device corresponding to the given board handle. The Device must be
146  // closed prior to closing the board handle. Closes the current Device first, if necessary.
147  BFVOID open (Bd hBoard);
148 
149  // Open a BFGTL Camera Device for the given board number. Closes the current Device first,
150  // if necessary.
151  BFVOID open (const BFU32 brdNum);
152 
153  // Open a BFGTL Camera Device for the given Board switch and Connector. Closes the current
154  // Device first, if necessary.
155  BFVOID openSWConnector (const BFU32 Switch, const BFU32 Connector);
156 
157  // Close the BFGTL Camera Device.
158  BFVOID close (BFVOID);
159 
160  // Return whether or not a BFGTL Camera Device has been opened or not.
161  BFBOOL isOpen (BFVOID) const;
162 
163  // Inverse of isOpen.
164  bool operator! (BFVOID) const;
165 
166  // Equivalent to isOpen.
167  operator bool (BFVOID) const;
168 
169  // Return the opened board handle. If opened by board number or switch connector, this
170  // is an internally allocated handle. If opened by Bd handle, this is the externally
171  // supplied handle. If closed, returns nullptr.
172  Bd getBoardHandle (BFVOID) const;
173 
174  // Return the opened board number. Returns ~BFU32(0), if the board isn't open, or wasn't
175  // opened with a board number (see getBoardSWConnector).
176  BFU32 getBoardNumber (BFVOID) const;
177 
178  // Retrieve the opened board switch and connector. Retrieves ~BFU32(0), if the board isn't
179  // open, or wasn't opened with openSWConnector (see getBoardNumber).
180  BFVOID getBoardSWConnector (BFU32 &Switch, BFU32 &Connector) const;
181 
182  // Retrieve a list of all available Camera Device node names.
183  std::vector<std::string> getNodeNames (BFVOID) const;
184 
185  // Iteratively retrieve the list of available Camera Device node names.
186  BFBOOL enumerateNodeName (const BFSIZET index, BFCHAR *const nameBuf, BFSIZET *const pNameSize) const;
187 
188  // Determine whether or not the named node exists.
189  BFBOOL nodeExists (std::string const& name) const;
190  BFBOOL nodeExists (const BFCHAR *const name) const;
191 
192  // Retrieve a Camera Device node from a given node name.
193  BaseNode getNode (std::string const& name) const;
194  BaseNode getNode (const BFCHAR *const name) const;
195 
196  private:
197  struct PrivateData;
198  PrivateData *m_pd;
199 
200  // Non-copyable.
201  Device (Device const&);
202  Device& operator= (Device const&);
203  };
204 
205  // NodeType codes.
206  enum class NodeType
207  {
208  Unknown = BFGTL_TYPE_UNKNOWN,
209 
210  Value = BFGTL_NODE_TYPE_VALUE,
211  Base = BFGTL_NODE_TYPE_BASE,
212  Integer = BFGTL_NODE_TYPE_INTEGER,
213  Boolean = BFGTL_NODE_TYPE_BOOLEAN,
214  Command = BFGTL_NODE_TYPE_COMMAND,
215  Float = BFGTL_NODE_TYPE_FLOAT,
216  String = BFGTL_NODE_TYPE_STRING,
217  Register = BFGTL_NODE_TYPE_REGISTER,
218  Category = BFGTL_NODE_TYPE_CATEGORY,
219  Enumeration = BFGTL_NODE_TYPE_ENUMERATION,
220  EnumEntry = BFGTL_NODE_TYPE_ENUM_ENTRY,
221  Port = BFGTL_NODE_TYPE_PORT,
222  };
223 
224  // Node accessibility codes.
225  enum class Access
226  {
227  Unknown = BFGTL_ACCESS_UNKNOWN,
228 
229  NI = BFGTL_ACCESS_NI, // Not Implemented
230  NA = BFGTL_ACCESS_NA, // Not Accessible
231  RO = BFGTL_ACCESS_RO, // Read Only
232  WO = BFGTL_ACCESS_WO, // Write Only
233  RW = BFGTL_ACCESS_RW, // Read/Write
234  };
235 
236  // The base class of all node types.
237  struct BFDLL BaseNode
238  {
239  private:
240  // Private constructor for our friend, Device::getNode.
241  BaseNode (Bd hBoard, Device const& device, const BFGTLNode node);
242  BaseNode friend ::BFGTLUtilities::Device::getNode (std::string const& name) const;
243  BaseNode friend ::BFGTLUtilities::Device::getNode (const BFCHAR *const name) const;
244 
245  public:
246  static const NodeType Type = NodeType::Base;
247 
248  // Constructors.
249  BaseNode (BFVOID);
250 
251  BaseNode (BaseNode const& to_alias);
252  BaseNode (BaseNode &&to_take);
253 
254  // Destructor.
255  virtual ~BaseNode (BFVOID);
256 
257  // Copy methods.
258  BaseNode& operator= (BaseNode const& to_alias);
259  BaseNode& operator= (BaseNode &&to_take);
260 
261  // This instance represents a node.
262  bool isValid (BFVOID) const;
263  operator bool (BFVOID) const;
264 
265  // This instance is null.
266  bool isNull (BFVOID) const;
267  bool operator! (BFVOID) const;
268 
269  // Determine if this node is equivalent to a different node. Null instances
270  // are not considered equivalent.
271  bool operator== (BaseNode const& other) const;
272  bool operator!= (BaseNode const& other) const;
273 
274  // Retrieve the node name.
275  std::string name (BFVOID) const;
276  bool getName (BFCHAR *const hBuf, BFSIZET *const pSize) const;
277 
278  // Retrieve the node display name.
279  std::string displayName (BFVOID) const;
280  bool getDisplayName (BFCHAR *const hBuf, BFSIZET *const pSize) const;
281 
282  // Retrieve the node tool-tip.
283  std::string toolTip (BFVOID) const;
284  bool getToolTip (BFCHAR *const hBuf, BFSIZET *const pSize) const;
285 
286  // Retrieve the node description.
287  std::string description (BFVOID) const;
288  bool getDescription (BFCHAR *const hBuf, BFSIZET *const pSize) const;
289 
290  // Retrieve the node type.
291  NodeType type (BFVOID) const;
292 
293  // Retrieve the node accessibility.
294  Access access (BFVOID) const;
295 
296  // Whether or not to ignore any cached data.
297  bool ignoreCache (BFVOID) const;
298  BFVOID setIgnoreCache (const bool ignore);
299 
300  protected:
301  virtual void copy (BaseNode const& to_alias);
302  virtual void copy (BaseNode &&to_take);
303 
304  struct PrivateData;
305  PrivateData *m_pd;
306  };
307 
308  // Private implementation classes.
309  namespace PRIVATE_IMP
310  {
311  template <class NodeT, NodeType NODE_TYPE>
312  struct NodeImpT : public NodeT, public virtual BaseNode
313  {
314  static const NodeType Type = NODE_TYPE;
315 
316  inline static bool is_convertible (BaseNode const& other)
317  {
318  const NodeType ot = other.type();
319  if (NodeType::Value == Type)
320  return NodeType::Unknown != ot && NodeType::Base != ot;
321  else
322  return Type == ot;
323  }
324 
325  // Constructors.
327 
328  NodeImpT (NodeImpT const& to_alias)
329  : BaseNode ( to_alias )
330  { }
331  NodeImpT (NodeImpT &&to_alias)
332  : BaseNode ( std::move(to_alias) )
333  { }
334 
335  NodeImpT (BaseNode const& to_alias)
336  : BaseNode ( is_convertible(to_alias) ? to_alias : BaseNode() )
337  { }
338  NodeImpT (BaseNode &&to_take)
339  : BaseNode ( std::move(is_convertible(to_take) ? to_take : BaseNode()) )
340  { }
341 
342  NodeImpT& operator= (BaseNode const& to_alias)
343  {
344  copy(to_alias);
345  return *this;
346  }
347 
349  {
350  copy( std::move(to_take) );
351  return *this;
352  }
353 
354  private:
355  virtual void copy (BaseNode const& to_alias)
356  {
357  BaseNode::copy( is_convertible(to_alias) ? to_alias : BaseNode() );
358  }
359  virtual void copy (BaseNode &&to_take)
360  {
361  BaseNode::copy( std::move(is_convertible(to_take) ? to_take : BaseNode()) );
362  }
363  };
364 
365  // The base of all value node types.
366  struct BFDLL ValueNodeBase : public virtual BaseNode
367  {
368  // Get the node value as a string.
369  std::string toString (BFVOID) const;
370  bool getToString (BFCHAR *const hBuf, BFSIZET *const pSize) const;
371 
372  // Set the node value from a string.
373  BFVOID fromString (std::string const& strVal);
374  BFVOID fromString (const BFCHAR *const strVal);
375  };
376 
377  // Structure to get/set integer node values.
378  struct BFDLL IntegerNodeBase : public ValueNodeBase
379  {
380  typedef BFS64 Value;
381 
382  // Convenience accessors.
383  Value value (BFVOID) const;
384  Value minimum (BFVOID) const;
385  Value maximum (BFVOID) const;
386  Value increment (BFVOID) const;
387 
388  // Convenience modifier.
389  BFVOID setValue (const Value val);
390  };
391 
392  // Structure to get/set boolean node values.
393  struct BFDLL BooleanNodeBase : public ValueNodeBase
394  {
395  typedef bool Value;
396 
397  // Convenience accessors.
398  Value value (BFVOID) const;
399 
400  // Convenience modifier.
401  BFVOID setValue (const Value val);
402  };
403 
404  // Structure to get/set command node values.
405  struct BFDLL CommandNodeBase : public ValueNodeBase
406  {
407  // Convenience execution methods.
408  BFVOID execute (BFVOID);
409  BFVOID operator() (BFVOID);
410  };
411 
412  // Structure to get/set floating-point node values.
413  struct BFDLL FloatNodeBase : public ValueNodeBase
414  {
415  typedef BFDOUBLE Value;
416 
417  // Convenience accessors.
418  Value value (BFVOID) const;
419  Value minimum (BFVOID) const;
420  Value maximum (BFVOID) const;
421  Value increment (BFVOID) const;
422 
423  // Convenience modifier.
424  BFVOID setValue (const Value val);
425  };
426 
427  // Structure to get/set string node values.
428  struct BFDLL StringNodeBase : public ValueNodeBase
429  {
430  typedef std::string Value;
431 
432  // Convenience accessors.
433  Value value (BFVOID) const;
434  bool getValue (BFCHAR *const hBuf, BFSIZET *const pSize) const;
435  BFS64 max_length (BFVOID) const;
436 
437  // Convenience modifier.
438  BFVOID setValue (Value const& val);
439  BFVOID setValue (const BFCHAR *const val);
440  };
441 
442  // Structure to get/set register node values.
443  struct BFDLL RegisterNodeBase : public ValueNodeBase
444  {
445  typedef std::vector<BFU8> DataArray;
446 
447  // Convenience data accessor.
448  BFS64 address (BFVOID) const;
449  BFS64 length (BFVOID) const;
450  DataArray data (BFVOID) const;
451  void getData (BFU8 *const dataBuf, const BFSIZET bufLen) const;
452 
453  // Convenience modifier.
454  BFVOID setData (DataArray const& val);
455  BFVOID setData (const BFU8 *const dataBuf, const BFSIZET bufLen);
456  };
457 
458  // Structure to get/set category node values.
459  struct BFDLL CategoryNodeBase : public ValueNodeBase
460  {
461  typedef std::vector<std::string> FeatureNames;
462  typedef BaseNode Feature;
463  typedef std::vector<Feature> Features;
464 
465  // Convenience category features accessor.
466  BFS64 featureCount (BFVOID) const;
467 
468  FeatureNames featureNames (BFVOID) const;
469  bool enumerateFeatureName (const BFS64 index, BFCHAR *const hBuf, BFSIZET *const pSize) const;
470 
471  Features features (BFVOID) const;
472  bool getFeature (const BFS64 index, Feature *const pFeature) const;
473  };
474 
475  // Structure to get/set enumeration node values.
476 
477  // Forward declaration.
478  struct EnumEntryNodeBase;
479 
480  struct BFDLL EnumerationNodeBase : public ValueNodeBase
481  {
482  typedef BFS64 Value;
483  typedef std::vector<std::string> EntryStrings;
484  typedef std::vector<Value> EntryValues;
486  typedef std::vector<Entry> Entries;
487 
488  // Convenience accessors.
489  Value entryValue (BFVOID) const;
490 
491  std::string entryName (BFVOID) const;
492  bool getEntryName (BFCHAR *const hBuf, BFSIZET *const pSize) const;
493 
494  std::string entrySymbolic (BFVOID) const;
495  bool getEntrySymbolic (BFCHAR *const hBuf, BFSIZET *const pSize) const;
496 
497  BFS64 entryCount (BFVOID) const;
498 
499  EntryValues entryValues (BFVOID) const;
500  bool enumerateEntryValue (const BFS64 index, Value *const pVal) const;
501 
502  EntryStrings entryNames (BFVOID) const;
503  bool enumerateEntryName (const BFS64 index, BFCHAR *const hBuf, BFSIZET *const pSize) const;
504 
505  EntryStrings entrySymbolics (BFVOID) const;
506  bool enumerateEntrySymbolic (const BFS64 index, BFCHAR *const hBuf, BFSIZET *const pSize) const;
507 
508  Entry entry (BFVOID) const;
509 
510  Entries entries (BFVOID) const;
511  bool enumerateEntry (const BFS64 index, Entry *const pEntry) const;
512 
513  // Convenience modifiers.
514  BFVOID setEntryValue (const Value val);
515 
516  BFVOID setEntryName (std::string const& name);
517  BFVOID setEntryName (const BFCHAR *const name);
518 
519  BFVOID setEntrySymbolic (std::string const& symbolic);
520  BFVOID setEntrySymbolic (const BFCHAR *const symbolic);
521  };
522 
523  // Structure to get/set enumeration entry node values.
524  struct BFDLL EnumEntryNodeBase : public ValueNodeBase
525  {
526  // Convenience accessors.
527  BFS64 value (BFVOID) const;
528 
529  std::string symbolic (BFVOID) const;
530  bool getSymbolic (BFCHAR *const hBuf, BFSIZET *const pSize) const;
531  };
532 
533  // Structure to get/set port node values.
534  struct BFDLL PortNodeBase : public virtual BaseNode
535  { };
536  }
537 
538  // Typed node classes.
561 }
562 
563 #endif // INCLUDED__BITFLOW__B_F_G_T_L__UTILITIES__HPP
#define BFCAPI
Definition: BFTypeNT.h:125
NodeImpT(BaseNode const &to_alias)
Definition: BFGTLUtilities.hpp:335
std::vector< Value > EntryValues
Definition: BFGTLUtilities.hpp:484
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::IntegerNodeBase, NodeType::Integer > IntegerNode
Definition: BFGTLUtilities.hpp:542
static bool is_convertible(BaseNode const &other)
Definition: BFGTLUtilities.hpp:316
Base class for BFGTLUtilities::Device node access and modification.
Definition: BFGTLUtilities.hpp:237
Definition: BFGTLUtilities.hpp:534
virtual void copy(BaseNode const &to_alias)
Definition: BFGTLUtilities.cpp:416
Definition: BFGTLUtilities.hpp:443
Definition: BFGTLUtilities.hpp:480
NodeType
Definition: BFGTLUtilities.hpp:206
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::RegisterNodeBase, NodeType::Register > RegisterNode
Definition: BFGTLUtilities.hpp:552
char BFCHAR
Definition: BFTypeNT.h:33
unsigned long BFU32
Definition: BFTypeNT.h:55
static const NodeType Type
Definition: BFGTLUtilities.hpp:314
Definition: BFGTLUtilities.hpp:393
Definition: BFGTLUtilities.hpp:524
Definition: BFGTLUtilities.hpp:459
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::BooleanNodeBase, NodeType::Boolean > BooleanNode
Definition: BFGTLUtilities.hpp:544
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::StringNodeBase, NodeType::String > StringNode
Definition: BFGTLUtilities.hpp:550
NodeImpT(NodeImpT const &to_alias)
Definition: BFGTLUtilities.hpp:328
Definition: BFGTLUtilities.hpp:428
BFS64 Value
Definition: BFGTLUtilities.hpp:380
Access
Definition: BFGTLUtilities.hpp:225
STL namespace.
std::vector< BFU8 > DataArray
Definition: BFGTLUtilities.hpp:445
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::CommandNodeBase, NodeType::Command > CommandNode
Definition: BFGTLUtilities.hpp:546
std::vector< std::string > FeatureNames
Definition: BFGTLUtilities.hpp:461
NodeImpT(BaseNode &&to_take)
Definition: BFGTLUtilities.hpp:338
BFS64 Value
Definition: BFGTLUtilities.hpp:482
PrivateData * m_pd
Definition: BFGTLUtilities.hpp:304
Definition: BFGTLUtilities.hpp:366
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::CategoryNodeBase, NodeType::Category > CategoryNode
Definition: BFGTLUtilities.hpp:554
std::vector< Entry > Entries
Definition: BFGTLUtilities.hpp:486
BFDOUBLE Value
Definition: BFGTLUtilities.hpp:415
NodeImpT(NodeImpT &&to_alias)
Definition: BFGTLUtilities.hpp:331
Class library for BitFlow frame grabber acquisition.
Definition: BFGTLUtilities.hpp:114
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::EnumEntryNodeBase, NodeType::EnumEntry > EnumEntryNode
Definition: BFGTLUtilities.hpp:558
std::string Value
Definition: BFGTLUtilities.hpp:430
Interface to access and modify features on a GenCam device.
Definition: BFGTLUtilities.hpp:129
NodeType type(BFVOID) const
Definition: BFGTLUtilities.cpp:639
void *** Bd
Definition: BFType.h:88
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::ValueNodeBase, NodeType::Value > ValueNode
Definition: BFGTLUtilities.hpp:540
Definition: BFGTLUtilities.hpp:405
std::vector< Feature > Features
Definition: BFGTLUtilities.hpp:463
long long BFS64
Definition: BFTypeNT.h:54
BaseNode Feature
Definition: BFGTLUtilities.hpp:462
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::PortNodeBase, NodeType::Port > PortNode
Definition: BFGTLUtilities.hpp:560
size_t BFSIZET
Definition: BFTypeNT.h:93
NodeImpT(BFVOID)
Definition: BFGTLUtilities.hpp:326
BFBOOL BFCAPI LibIsGood(void)
Definition: BFGTLUtilities.cpp:17
double BFDOUBLE
Definition: BFTypeNT.h:41
void BFVOID
Definition: BFTypeNT.h:32
Definition: BFGTLUtilities.hpp:312
unsigned char BFU8
Definition: BFTypeNT.h:59
Definition: BFGTLUtilities.hpp:378
NodeImpT< EnumEntryNodeBase, NodeType::EnumEntry > Entry
Definition: BFGTLUtilities.hpp:485
bool Value
Definition: BFGTLUtilities.hpp:395
Definition: BFGTLUtilities.hpp:413
std::vector< std::string > EntryStrings
Definition: BFGTLUtilities.hpp:483
Base class for buffered acquisition using a BitFlow frame grabber.
Definition: BufferInterface.h:63
int BFBOOL
Definition: BFTypeNT.h:34
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::EnumerationNodeBase, NodeType::Enumeration > EnumerationNode
Definition: BFGTLUtilities.hpp:556
PRIVATE_IMP::NodeImpT< PRIVATE_IMP::FloatNodeBase, NodeType::Float > FloatNode
Definition: BFGTLUtilities.hpp:548
Class library for GenCam camera device access via BFGTL.
NodeImpT & operator=(BaseNode const &to_alias)
Definition: BFGTLUtilities.hpp:342