SeaBreeze
FeatureAdapterTemplate.h
Go to the documentation of this file.
1 /***************************************************/
34 #ifndef FEATUREADAPTERTEMPLATE_H
35 #define FEATUREADAPTERTEMPLATE_H
36 
38 #include "common/buses/Bus.h"
42 #include <string>
43 
44 namespace seabreeze {
45  namespace api {
46 
47  template <class T> class FeatureAdapterTemplate
48  : public FeatureAdapterInterface {
49  public:
50  FeatureAdapterTemplate(T *featureInterface, const FeatureFamily &f,
51  Protocol *p, Bus *b, unsigned short instanceIndex) {
52  this->feature = featureInterface;
53  this->family = f;
54  this->protocol = p;
55  this->bus = b;
56  this->index = instanceIndex;
57 
58  /* Create a unique ID based on the feature type and index. This
59  * might be expanded in the future to use one of the bytes for
60  * the feature type or index as a module number.
61  */
62  this->ID = (family.getType() << 16) | (instanceIndex & 0x00FFFF);
63 
64  if(0 == this->feature || 0 == this->protocol || 0 == this->bus) {
65  std::string error("Null feature interface, protocol, or bus is not allowed.");
66  throw IllegalArgumentException(error);
67  }
68  }
69  virtual ~FeatureAdapterTemplate() { /* Do nothing -- others delete feature */ }
70  T *getFeature() { return this->feature; }
71 
72  virtual FeatureFamily &getFeatureFamily() { return this->family; }
73 
74  virtual long getID() { return this->ID; }
75 
76  protected:
77  T *feature;
78  FeatureFamily family;
79  Protocol *protocol;
80  Bus *bus;
81  unsigned short index;
82  unsigned long ID;
83  };
84  }
85 }
86 
87 #endif
Definition: FeatureAdapterInterface.h:41
Definition: FeatureAdapterTemplate.h:47
Definition: Protocol.h:44
Definition: FeatureFamily.h:39
Definition: Bus.h:48
Encapsulates all SeaBreeze classes.
Definition: DeviceFactory.h:42
Definition: IllegalArgumentException.h:43