Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Properties.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision: 10745 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2011-01-26 10:23:50 +0100 (Mi, 26 Jan 2011) $ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef PROPERTIES_HH
51 #define PROPERTIES_HH
52 
62 #include <vector>
63 #include <map>
64 #include <string>
65 
67 
68 
74 template<typename T>
76 {
77  friend class Properties;
78 
79 protected:
80  typedef T value_type;
81 
82 public:
83  PropertyHandleT(int _idx = -1);
84  virtual ~PropertyHandleT();
85 
86  inline bool isValid();
87 
88 protected:
89  int idx_;
90 };
91 
101 {
102 protected:
110  {
111  friend class Properties;
112  public:
113  BaseProperty();
114  virtual ~BaseProperty();
115 
116  protected:
122  virtual void insert_at(int _index) = 0;
123  virtual void remove_at(int _index) = 0;
124  virtual void clear() = 0;
125 
126  };
127 
134  template<typename T>
135  class PropertyT : public BaseProperty
136  {
137  friend class Properties;
138 
139  public:
140  PropertyT(unsigned long _size = 0);
141  virtual ~PropertyT();
142 
143  public:
144  inline T &operator[](int _index);
145 
146  protected:
152  void insert_at(int _index);
153  void remove_at(int _index);
154  void clear();
156 
157  protected:
158  std::vector<T> values_;
159  };
160 
161 public:
162  Properties();
163  virtual ~Properties();
164 
165 public:
171  template<typename T> bool add_property(PropertyHandleT<T> &_hProp, std::string _name);
172  template<typename T> bool get_property(PropertyHandleT<T> &_hProp, std::string _name);
173  bool has_property(std::string _name);
174  template<typename T> bool remove_property(PropertyHandleT<T> &_hProp);
175  void clear_properties();
177 
183  template<typename T> T &property(PropertyHandleT<T> &_hProp, int _index);
185 
186 protected:
192  void insert_property_at(int _index);
193  void remove_property_at(int _index);
194  void clean_properties();
196 
197 protected:
198  std::map<std::string, int> property_names_;
199  std::vector<BaseProperty*> properties_;
200  unsigned long size_;
201 };
202 
213 //=============================================================================
214 //=============================================================================
215 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTIES_C)
216 #define PROPERTIES_TEMPLATES
217 #include "PropertiesT.cc"
218 #endif
219 //=============================================================================
220 #endif // PROPERTIES_HH defined
221 //=============================================================================
222 
std::vector< BaseProperty * > properties_
A vector holding the properties.
Definition: Properties.hh:199
bool get_property(PropertyHandleT< T > &_hProp, std::string _name)
Initiates the property handle.
Definition: PropertiesT.cc:113
The base class for all property template instances.
Definition: Properties.hh:109
The properties storage class.
Definition: Properties.hh:100
bool isValid()
Returns true if the handle is valid, false otherwise.
Definition: PropertiesT.cc:224
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
Definition: Properties.cc:113
unsigned long size_
The number of fields in each property, used when new properties have to be created.
Definition: Properties.hh:200
PropertyHandleT(int _idx=-1)
Constructs a new property handle.
Definition: PropertiesT.cc:200
bool add_property(PropertyHandleT< T > &_hProp, std::string _name)
Adds a new property.
Definition: PropertiesT.cc:72
void remove_property_at(int _index)
Removes a property for an object that is being deleted from the derived class.
Definition: Properties.cc:130
T & property(PropertyHandleT< T > &_hProp, int _index)
Direct access to the properties values.
Definition: PropertiesT.cc:178
A container storing a single property for all objects.
Definition: Properties.hh:135
std::vector< T > values_
Stores a property for every object in the class derived from the Properties class. Access by index.
Definition: Properties.hh:158
int idx_
The properties index.
Definition: Properties.hh:89
void clean_properties()
While preserving the properties themself, all values in the property are deleted. ...
Definition: Properties.cc:79
bool remove_property(PropertyHandleT< T > &_hProp)
Deletes a property including all values.
Definition: PropertiesT.cc:137
std::map< std::string, int > property_names_
The property names, key holding the name, value the properties index in Properties::properties_.
Definition: Properties.hh:198
#define DLLEXPORT
bool has_property(std::string _name)
Returns true if a property with the given name exists.
Definition: Properties.cc:145
virtual ~PropertyHandleT()
Destructor.
Definition: PropertiesT.cc:211
void clear_properties()
Deletes all properties, including their values.
Definition: Properties.cc:93
The property handle, use it to access the properties.
Definition: Properties.hh:75