DataDirector API
DDD_AttributeBase.h
Go to the documentation of this file.
1 #ifndef _DDD_AttributeBase_h_
2 #define _DDD_AttributeBase_h_
3 
4 /*! \file DDD_AttributeBase.h
5 
6  \par Copyright Information
7 
8  Copyright (c) 2012 The DiSTI Corporation.<br>
9  11301 Corporate Blvd; Suite 100<br>
10  Orlando, Florida 32817<br>
11  USA<br>
12  <br>
13  All rights reserved.<br>
14 
15  This Software contains proprietary trade secrets of DiSTI and may not be
16 reproduced, in whole or part, in any form, or by any means of electronic,
17 mechanical, or otherwise, without the written permission of DiSTI. Said
18 permission may be derived through the purchase of applicable DiSTI product
19 licenses which detail the distribution rights of this content and any
20 Derivative Works based on this or other copyrighted DiSTI Software.
21 
22  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
23 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
24 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
25 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
27 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
28 
29  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
30 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
31 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
32 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
33 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
34 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
35 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
36 EXCEED FIVE DOLLARS (US$5.00).
37 
38  The aforementioned terms and restrictions are governed by the laws of the
39 State of Florida and the United States of America.
40 
41 */
42 
43 #include <string>
44 #include "dynamic_ptr_array.h"
45 #include "DDD_Include.h"
46 #include <exception>
47 #include <stdexcept>
48 
49 namespace disti
50 {
51 class DDD_AttributeBase;
52 
53 
54 /** \defgroup GroupAttributes DataDirector Attributes */
55 
56 /** \brief DDD_AttributeContainer. A virtual interface class for containers of attributes. */
57 class DDD_EXPORT DDD_AttributeContainer
58 {
59 public:
60  virtual const char *GetName() = 0;
61 };
62 
63 /** \brief A virtual interface class for observers of attributes.
64  AttributeObserver-derived objects are able to be notified when an attribute changes.
65  */
66 class DDD_EXPORT DDD_AttributeObserver
67 {
68 public:
69  /** A callback method that will be called when the attribute being observed changes
70  * if this observer has registered to be notified on attribute change
71  * \param attribute A pointer to the attribute that changed
72  */
73  virtual void OnAttributeChanged(DDD_AttributeBase *attribute) = 0;
74 };
75 
76 /** \brief Exception thrown whenever attempt to convert an attribute failed. */
77 class DDD_AttributeConversionException : public std::runtime_error
78 {
79 public:
80  DDD_AttributeConversionException(const char *reason) : std::runtime_error(reason) { }
81 };
82 
83 
84 /** \brief A virtual interface class for all DataDirector attribute types.
85  * \ingroup GroupAttributes
86  */
87 class DDD_EXPORT DDD_AttributeBase
88 {
89 public:
90 
91  /** The ConnectionState enum is used both to describe the current connection state
92  * of an attribute and the allowable/valid connectablity states of the attribute
93  */
95  {
96  NOT_CONNECTED = 0, /**< The attribute is currently not connected */
97  CONNECTED_INPUT = 1<<1, /**< The attribute is connected as an input */
98  CONNECTED_OUTPUT = 1<<2, /**< The attribute is connected as an output */
99  CONNECTED_IN_OUT = (CONNECTED_INPUT | CONNECTED_OUTPUT) /**< The attribute is connected as both an input and output */
100  };
101 
102  /** The DataType enum describes the base data type used by an attribute. Its main purpose is to facilitate efficient
103  * typed access to attribute data */
104  enum DataType
105  {
106  STRING = 0, /**< String datatype */
107  INT, /**< Integer datatype (32-bit) */
108  UINT, /**< Unsigned Integer datatype (32-bit) */
109  DOUBLE, /**< Double-precision floating point datatype */
110  BOOLEAN, /**< Boolean datatype */
111  BYTEBUFFER /**< ByteBuffer datatype */
112  };
113 
114  /** constructor
115  * \param name The instance name of the attribute
116  * \param container The container that will own the attribute
117  * \param validConnectionStates The allowable connection states for the attribute (i.e. how can it be connected?)
118  * \param persistent True if it's a persistent attribute
119  * \param revertable If not NULL, it's a pointer to the revertable attribute for this attribute
120  */
121  DDD_AttributeBase(const std::string &name, DDD_AttributeContainer *container,int validConnectionStates,bool persistent,DDD_AttributeBase *revertable);
122 
123  /** destructor */
124  virtual ~DDD_AttributeBase();
125 
126  /** \return Returns true if this attribute can be connected as an input */
127  bool CanConnectAsInput() { return ((_validConnectionStates&CONNECTED_INPUT) != 0);}
128 
129  /** \return Returns true if this attribute can be connected as an output */
130  bool CanConnectAsOutput() {return ((_validConnectionStates&CONNECTED_OUTPUT) != 0);}
131 
132  /** \return Returns the valid connection states of the attribute as a bitmask */
133  int GetValidConnectionStates() { return _validConnectionStates; }
134 
135  /** \return Returns the current connection state of the attribute as a bitmask */
136  ConnectionState GetConnectionState();
137 
138  /** Sets the current connection state of the attribute
139  * \param state The connection state to set
140  */
141  void SetConnectionState(ConnectionState state);
142 
143  /** Adds the state to the connectability mask for this attribute
144  * \param state The connection state to set
145  */
146  void AddConnectionState(ConnectionState state);
147 
148  /** \return Returns true if the connection state supports supplied connection type
149  * \param state Type of connection to check for (CONNECTED_INPUT, CONNECTED_OUTPUT)
150  */
151  bool ConnectionStateSupports(ConnectionState state);
152 
153  /** \return Returns the instance name of this attribute */
154  const char* Name() const;
155 
156  /** \return Returns a pointer to the container that owns this attribute
157  */
158  DDD_AttributeContainer* GetContainer();
159 
160  /** Increases the Reference count of this attribute. The Reference Count tracks the number of
161  * connections that reference the attribute.
162  */
163  void IncreaseRefCount();
164 
165  /** Decreases the Reference count of this attribute. The Reference Count tracks the number of
166  * connections that reference the attribute.
167  */
168  void DecreaseRefCount();
169 
170  /** \return Returns the Reference count of this attribute. The Reference Count tracks the number of
171  * connections that reference the attribute.
172  */
173  int RefCount();
174 
175  // pure virtual methods
176  /** \return Returns the value of this attribute in string format */
177  virtual std::string GetValueString() const = 0;
178 
179  /** Sets the value of this attribute using a string value
180  * \param value The new value of the attribute
181  * \param notify Whether or not to notify attribute observers
182  * \throws DDD_AttributeConversionException
183  */
184  virtual void SetValueString(const std::string &value,bool notify, DDD_AttributeObserver *originator) = 0;
185 
186  /** \return Returns the value of this attribute as an int
187  * \throws DDD_AttributeConversionException
188  */
189  virtual int GetValueInt(void) const = 0;
190 
191  /** Sets the value of this attribute using an int value
192  * \param value The new value of the attribute
193  * \param notify Whether or not to notify attribute observers
194  * \throws DDD_AttributeConversionException
195  */
196  virtual void SetValueInt(const int value,bool notify, DDD_AttributeObserver *originator) = 0;
197 
198  /** \return Returns the value of this attribute as an unsigned int */
199  virtual unsigned int GetValueUInt(void) const = 0;
200 
201  /** Sets the value of this attribute using an unsigned int value
202  * \param value The new value of the attribute
203  * \param notify Whether or not to notify attribute observers
204  * \throws DDD_AttributeConversionException
205  */
206  virtual void SetValueUInt(const unsigned int value,bool notify, DDD_AttributeObserver *originator) = 0;
207 
208  /** \return Returns the value of this attribute as double
209  * \throws DDD_AttributeConversionException
210  */
211  virtual double GetValueDouble(void) const = 0;
212 
213  /** Sets the value of this attribute using a double value
214  * \param value The new value of the attribute
215  * \param notify Whether or not to notify attribute observers
216  * \throws DDD_AttributeConversionException
217  */
218  virtual void SetValueDouble(const double value,bool notify, DDD_AttributeObserver *originator) = 0;
219 
220  /** \return Returns the value of this attribute as an boolean
221  * \throws DDD_AttributeConversionException
222  */
223  virtual bool GetValueBool(void) const = 0;
224 
225  /** Sets the value of this attribute using a bool value
226  * \param value The new value of the attribute
227  * \param notify Whether or not to notify attribute observers
228  * \throws DDD_AttributeConversionException
229  */
230  virtual void SetValueBool(const bool value,bool notify, DDD_AttributeObserver *originator) = 0;
231 
232  /** \return Returns the value of this attribute as an byteBuffer
233  * \param value Newly-allocated buffer returned
234  * \length length of buffer
235  * \note To avoid leaks, the data returned by value should be deleted when appropriate by the calling module.
236  * \throws DDD_AttributeConversionException
237  */
238  virtual void GetValueByteBuffer(char **value, unsigned int &length) = 0;
239 
240  /** Sets the value of this attribute using a byte buffer value
241  * \param value The new buffer value of the attribute
242  * \length length of buffer
243  * \param notify Whether or not to notify attribute observers
244  * \throws DDD_AttributeConversionException
245  */
246  virtual void SetValueByteBuffer(const char *value, unsigned int length, bool notify, DDD_AttributeObserver *originator) = 0;
247 
248  /** \return Returns the preferred data type of the attribute
249  * \throws DDD_AttributeConversionException
250  */
251  virtual DataType GetPreferredDataType() const = 0;
252 
253  // static enum utilities
254  /** \return Converts the data type enum to a string
255  * \param type The data type enum
256  */
257  static const char* DataTypeToString(DataType type);
258 
259  /** \return Converts the data type string to an enum
260  * \param string The data type as a string
261  */
262  static DataType StringToDataType(const char* string);
263 
264  /** Adds an observer to this attribute that will be notified whenever this attribute changes
265  * \param observer The observer to add. The observer to add must not already be observing this attribute.
266  * \return True if the observer was successfully added, false otherwise
267  * \pre The observer to add must not already be observing this attribute.
268  */
269  bool AddObserver(DDD_AttributeObserver *observer);
270 
271  /** Removes an observer from the observer list
272  * \param observer The observer to remove.
273  * \return True if the observer was found and removed, false if it wasn't found
274  */
275  bool RemoveObserver(DDD_AttributeObserver *observer);
276 
277  /** \return Returns the "EditorSemantic" which suggests to the editor what type of widget
278  * to use when editing this attribute
279  */
280  std::string EditorSemantic();
281 
282  /** Sets the "EditorSemantic" which suggests to the editor what type of widget
283  * to use when editing this attribute.
284  * \param semantic The string to set
285  */
286  void EditorSemantic(const std::string &semantic);
287 
288  /** \return Returns a printf style format string which the editor may use when
289  * editing this attribute
290  */
291  std::string EditorFormatString();
292 
293  /** Sets the printf style format string which the editor may use when editing this attribute
294  * \param formatStr The format string to set
295  */
296  void EditorFormatString(const std::string &formatStr);
297 
298  /** \returnReturns the connectability status of the attribute as a string
299  */
300  std::string Connectability();
301 
302  /** Sets the "revertable" attribute for this attribute. Revertable attributes are "reverted" to an initial value
303  * whenever the Data Director is Resumed()
304  * \param flag New revertable flag
305  */
306  void SetRevertable(DDD_AttributeBase *attr) { _revertable = attr; }
307 
308  /** \return Gets the "revertable" attribute for this attribute. Revertable attributes are "reverted" to an initial value
309  * whenever the Data Director is Resumed()
310  */
311  DDD_AttributeBase *GetRevertable(void) const { return _revertable; }
312 
313  /** Sets the "persistent" flag for this attribute. Persistent attributes are not deleted by the "DeleteDynamicAttributes"
314  * method of DDD_AttributeList
315  * \param flag New persistent flag
316  */
317  void SetPersistent(bool flag) { _persistent = flag; }
318 
319  /** \return Gets the "persistent" flag for this attribute. Persistent attributes are not deleted
320  * by the "DeleteDynamicAttributes" method of DDD_AttributeList
321  */
322  bool IsPersistent(void) const { return _persistent; }
323 
324  /** Causes this attribute to "revert" to it's revert value */
325  void RevertValue();
326 
327 
328  /** Notifies all observers of this attribute that the value has changed */
329  void NotifyValueChanged(DDD_AttributeObserver *originator);
330 
331 
332 protected:
333 
334 
335  typedef DynamicPtrArray<DDD_AttributeObserver*> ObserverList;
336 
337  ObserverList _observerList; /**< The list of observers to notify when this attribute changes */
338  DDD_AttributeContainer* _container; /**< The container that owns this attribute */
339 
340  int _refCount; /**< The number of connections that reference this attribute */
341  bool _visiting; /**< True while attribute is being visited...prevents loops */
342  std::string _name; /**< The instance name of this attribute */
343 
344  ConnectionState _connectionState; /**< The current connection state of this attribute */
345  int _validConnectionStates; /**< The valid connectability states possible for this attribute */
346 
347  std::string _editorSemantic; /**< String defining what type of widget to use in the editor */
348  std::string _editorFormatString; /**< printf style format string to use in the editor */
349 
350  DDD_AttributeBase *_revertable; /**< If the attribute is a "Revertable" attribute, pointer to attribute to revert to */
351  bool _persistent; /**< True if the attribute is a "Persistent" attribute. */
352 };
353 
354 
355 } // end namespace disti
356 
357 #endif
358 
DDD_AttributeContainer. A virtual interface class for containers of attributes.
Definition: DDD_AttributeBase.h:57
ObserverList _observerList
Definition: DDD_AttributeBase.h:337
DDD_AttributeBase * _revertable
Definition: DDD_AttributeBase.h:350
A virtual interface class for all DataDirector attribute types.
Definition: DDD_AttributeBase.h:87
int _validConnectionStates
Definition: DDD_AttributeBase.h:345
bool _visiting
Definition: DDD_AttributeBase.h:341
std::string _editorSemantic
Definition: DDD_AttributeBase.h:347
DataType
Definition: DDD_AttributeBase.h:104
DDD_AttributeBase * GetRevertable(void) const
Definition: DDD_AttributeBase.h:311
std::string _editorFormatString
Definition: DDD_AttributeBase.h:348
A virtual interface class for observers of attributes. AttributeObserver-derived objects are able to ...
Definition: DDD_AttributeBase.h:66
bool IsPersistent(void) const
Definition: DDD_AttributeBase.h:322
void SetPersistent(bool flag)
Definition: DDD_AttributeBase.h:317
int _refCount
Definition: DDD_AttributeBase.h:340
Definition: DDD_AttributeBase.h:109
int GetValidConnectionStates()
Definition: DDD_AttributeBase.h:133
std::string _name
Definition: DDD_AttributeBase.h:342
void SetRevertable(DDD_AttributeBase *attr)
Definition: DDD_AttributeBase.h:306
Definition: DDD_AttributeBase.h:108
bool CanConnectAsOutput()
Definition: DDD_AttributeBase.h:130
Definition: DDD_AttributeBase.h:107
bool _persistent
Definition: DDD_AttributeBase.h:351
The disti::DynamicPtrArray class. A templated array of objects pointers capable of dynamically growin...
DDD_AttributeContainer * _container
Definition: DDD_AttributeBase.h:338
Definition: DDD_AttributeBase.h:110
ConnectionState
Definition: DDD_AttributeBase.h:94
Exception thrown whenever attempt to convert an attribute failed.
Definition: DDD_AttributeBase.h:77
Definition: AttributeChangedEmitter.h:46
bool CanConnectAsInput()
Definition: DDD_AttributeBase.h:127
ConnectionState _connectionState
Definition: DDD_AttributeBase.h:344