OpenLexocad  28.0
PropertyBundle.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 typedef std::map<std::string, Core::Property*> PropertyMap;
6 typedef std::map<std::string, Core::PropertyValue> PropertyValueMap;
7 
8 
9 namespace Core
10 {
11 template <typename T = Core::PropertyContainer>
13 {
14 public:
17  {
18  // Do we have this type already?
20  if (Core::Property::getRegisteredProperties(T::getClassTypeId(), pvm))
21  {
22  // Add properties from registry
23  Core::PropertyValueMap::const_iterator it;
24  for (it = pvm.begin(); it != pvm.end(); ++it)
25  {
26  Core::PropertyValue pv = it->second;
28  }
29  }
30  else
31  {
32  // Make new
33  T* t = new T;
34  if (t)
35  {
36  // const Core::PropertyMap& pm = t->getPropertyMap();
38  t->getPropertyMap(pm);
39  Core::PropertyMap::const_iterator it;
40  for (it = pm.begin(); it != pm.end(); ++it)
41  {
42  Core::Property* p = it->second;
43  std::string pName = it->first;
44  Core::PropertyValue pv(pName, p->getTypeId(), p->getVariant());
45  pvm[pName] = pv;
47  }
48 
49  // Add to registry
50  Core::Property::registerProperties(T::getClassTypeId(), pvm);
51  delete t;
52  }
53  }
54  }
57 
59  template <typename PropType>
60  bool addProperty(const std::string& name, const Core::Variant& defaultValue)
61  {
62  return Core::PropertyContainer::addProperty(PropType::getClassTypeId(), name, defaultValue);
63  }
64 
66  {
67  if (*this == other)
68  return *this;
71  return *this;
72  }
73 
74  bool operator==(const PropertyBundle<T>& other) const { return Core::PropertyContainer::hasSameValuesAs(&other); }
75 
76  bool operator!=(const PropertyBundle<T>& other) const { return !(*this == other); }
77 
78 
79 private:
80 };
81 
82 } // namespace Core
Core::PropertyBundle::operator=
PropertyBundle< T > & operator=(const PropertyBundle< T > &other)
Definition: PropertyBundle.h:65
Core::PropertyMap
std::unordered_map< std::string, Core::Property * > PropertyMap
Definition: PropertyValue.h:25
PropertyValueMap
std::map< std::string, Core::PropertyValue > PropertyValueMap
Definition: PropertyBundle.h:6
Core::PropertyContainer::hasSameValuesAs
bool hasSameValuesAs(const PropertyContainer *container) const
Returns 'true' if all values in 'container' match the corresponding property in this PropertyContaine...
Core::PropertyContainer::addProperty
bool addProperty(Core::Property *p, const std::string &name)
Core::PropertyBundle::PropertyBundle
PropertyBundle(const PropertyBundle< T > &other)
Copy constructor.
Definition: PropertyBundle.h:56
Core::PropertyBundle::PropertyBundle
PropertyBundle()
Creates a PropertyBundle from a PropertyContainer type and copies all properties from the PropertyCon...
Definition: PropertyBundle.h:16
Core::PropertyContainer::addPropertiesFrom
void addPropertiesFrom(const Core::PropertyContainer *other)
Adds copy of all properties from other to this PropertyContainer.
Core::PropertyBundle::operator==
bool operator==(const PropertyBundle< T > &other) const
Definition: PropertyBundle.h:74
Core::PropertyBundle::addProperty
bool addProperty(const std::string &name, const Core::Variant &defaultValue)
Adds a property to the bundle. Returns 'true' on success, 'false' on failure.
Definition: PropertyBundle.h:60
PropertyMap
std::map< std::string, Core::Property * > PropertyMap
Definition: PropertyBundle.h:5
Core::PropertyContainer
Definition: PropertyContainer.h:93
Core::Property::getRegisteredProperties
static bool getRegisteredProperties(Base::Type t, Core::PropertyValueMap &pvm)
Returns the properties with default values of type t;.
PropertyContainer.h
Core
Definition: Base.h:5
Core::Variant
Definition: Variant.h:78
Core::PropertyBundle::operator!=
bool operator!=(const PropertyBundle< T > &other) const
Definition: PropertyBundle.h:76
Core::Property::registerProperties
static void registerProperties(Base::Type t, const Core::PropertyValueMap &pvm)
Registers the properties with default values for type 't'.
Core::PropertyContainer::removeAllProperties
void removeAllProperties()
Removes all properties from the PropertyContainer and deletes them.
Core::Property::getVariant
virtual Core::Variant getVariant(void) const =0
Core::PropertyValue::propertyType
Base::Type propertyType
Definition: PropertyValue.h:20
Core::PropertyValue::value
Core::Variant value
Definition: PropertyValue.h:21
Core::PropertyValue
Definition: PropertyValue.h:13
Core::Property
Definition: Property.h:72
Core::PropertyValue::propertyName
std::string propertyName
Definition: PropertyValue.h:19
Base::BaseClass::getTypeId
virtual Type getTypeId(void) const
Core::PropertyBundle
Definition: PropertyBundle.h:13
Core::PropertyValueMap
std::unordered_map< std::string, Core::PropertyValue > PropertyValueMap
Definition: PropertyValue.h:26