DataDirector API
DDD_RevertableAttribute.h
Go to the documentation of this file.
1 #ifndef _DDD_RevertableAttribute_h_
2 #define _DDD_RevertableAttribute_h_
3 
4 /*! \file DDD_RevertableAttribute.h
5  \brief The DDD_RevertableAttribute class. Container for
6 
7  \par Copyright Information
8 
9  Copyright (c) 2012 The DiSTI Corporation.<br>
10  11301 Corporate Blvd; Suite 100<br>
11  Orlando, Florida 32817<br>
12  USA<br>
13  <br>
14  All rights reserved.<br>
15 
16  This Software contains proprietary trade secrets of DiSTI and may not be
17 reproduced, in whole or part, in any form, or by any means of electronic,
18 mechanical, or otherwise, without the written permission of DiSTI. Said
19 permission may be derived through the purchase of applicable DiSTI product
20 licenses which detail the distribution rights of this content and any
21 Derivative Works based on this or other copyrighted DiSTI Software.
22 
23  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
24 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
25 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
26 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
28 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
29 
30  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
31 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
32 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
33 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
34 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
35 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
36 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
37 EXCEED FIVE DOLLARS (US$5.00).
38 
39  The aforementioned terms and restrictions are governed by the laws of the
40 State of Florida and the United States of America.
41 
42 */
43 
44 #include "DDD_Include.h"
45 #include "DDD_Base.h"
46 #include "DDD_AttributeBase.h"
47 #include "dynamic_array.h"
48 #include <string>
49 
50 namespace disti
51 {
52 
53 /** \brief Revertable attribute; for dynamic attributes that can be reset to a default value. */
54 class DDD_EXPORT DDD_RevertableAttribute
55 {
56 public:
57  /** Constructor */
58  DDD_RevertableAttribute(DDD_AttributeBase *defaultAttribute, DDD_AttributeBase *attribute) : _defaultAttribute(defaultAttribute), _attribute(attribute) {}
59 
60  /** DefaultAttribute accessor
61  * \return default attribute
62  */
63  DDD_AttributeBase* DefaultAttribute() { return _defaultAttribute; }
64 
65  /** Attribute accessor
66  * \return attribute
67  */
68  DDD_AttributeBase* Attribute() { return _attribute; }
69 
70  /** Attribute mutator
71  * \param attribute Attribute instance to store in this class
72  */
73  void SetAttribute(DDD_AttributeBase *attribute) { _attribute = attribute; }
74 
75  /** Reverts the state of this attribute.
76  * \post _attribute should share the same value as _defaultAttribute
77  */
78  void Revert();
79 
80 private:
81  DDD_AttributeBase *_attribute; /**< attribute instance */
82  DDD_AttributeBase *_defaultAttribute; /**< default value */
83 };
84 
85 /** \brief List of revertable attributes */
86 class DDD_EXPORT DDD_RevertableAttributeList : public DynamicPtrArray<DDD_RevertableAttribute *>
87 {
88 public:
89  /** Destructor */
91 
92  /** Inserts a new attribute into the list using both attributes.
93  * \param defaultAttribute Attribute with default value- this will not be changed by either this list
94  * or DDD_RevertableAttribute
95  * \param attribute Attribute to be reverted.
96  */
97  void Insert(DDD_AttributeBase *defaultAttribute, DDD_AttributeBase *attribute);
98 
99  /** \param attribute
100  */
101  void RemoveAttribute(DDD_AttributeBase* attribute);
102 
103  /** Resets all attributes based on param values.
104  */
105  void RevertAll();
106 
107  /** Sets the attribute, either by searching for Param name
108  * \param attribute New attribute instance replacement. By default, the name of this
109  attribute is matched to the corresponding param name.
110  * \param param If this is specified, this method does a quicker check based on
111  the param pointer.
112  */
113  void SetAttribute(DDD_AttributeBase* attribute, DDD_AttributeBase *param = NULL);
114 
115  /** Clears the attributes, default attributes remain however
116  */
117  void ClearAllAttributes();
118 
119  /** Finds the revertable attribute by name
120  * \param name Name to look for.
121  * \return Pointer to revertable attribute with matching name; NULL if not found
122  */
123  DDD_RevertableAttribute *Find(const std::string &name);
124 
125  /** Finds the revertable attribute by default attribute instance. This is more efficient
126  * than the Find() method since it uses faster pointer comparisons.
127  * \param defaultAttr Default attribute to look for.
128  * \return Pointer to revertable attribute with matching default attribute; NULL if not found
129  */
130  DDD_RevertableAttribute *FindByDefaultAttribute(const DDD_AttributeBase *defaultAttr);
131 
132  /** Finds the revertable attribute by attribute instance.
133  * \param attr Attribute instance to look for.
134  * \return Pointer to revertable attribute with matching attribute; NULL if not found
135  */
136  DDD_RevertableAttribute *FindByAttribute(const DDD_AttributeBase *attr);
137 };
138 
139 
140 } // namespace disti
141 
142 #endif
143 
A templated array of object pointers. The array dynamically resizes as needed.
Definition: dynamic_ptr_array.h:55
DDD_RevertableAttribute(DDD_AttributeBase *defaultAttribute, DDD_AttributeBase *attribute)
Definition: DDD_RevertableAttribute.h:58
A virtual interface class for all DataDirector attribute types.
Definition: DDD_AttributeBase.h:87
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
void SetAttribute(DDD_AttributeBase *attribute)
Definition: DDD_RevertableAttribute.h:73
Revertable attribute; for dynamic attributes that can be reset to a default value.
Definition: DDD_RevertableAttribute.h:54
DDD_AttributeBase * DefaultAttribute()
Definition: DDD_RevertableAttribute.h:63
List of revertable attributes.
Definition: DDD_RevertableAttribute.h:86
Definition: AttributeChangedEmitter.h:46
DDD_AttributeBase * Attribute()
Definition: DDD_RevertableAttribute.h:68