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