16 namespace property {
namespace priv
23 class PropertyObject :
public Object
43 auto res = _propMap.insert(make_pair(prop.
id(), ptr));
44 if (res.second)
return;
45 res.first->second = ptr;
52 bool hasProp(
const Id&
id)
const {
return _propMap.find(
id) != _propMap.end(); }
58 auto it = _propMap.find(
id);
68 auto it = _propMap.find(
id);
69 if (it != _propMap.end())
74 prop = &property::priv::create<T>(name);
78 sout() <<
"Component type mismatch: "
80 <<
" ; Found: " <<
prop->type());
95 template<class T, class T_ = typename mt::removeRef<T>::type>
98 template<class T, class T_ = typename mt::removeRef<T>::type>
102 const PropertyMap&
props() {
return _propMap; }
103 const PropertyMapConst&
props()
const {
return reinterpret_cast<const PropertyMapConst&
>(_propMap); }
111 auto it = _propMap.find(
id);
112 return it != _propMap.end() ? removeProp(it) :
nullptr;
118 while (!_propMap.empty()) { f(*removeProp(_propMap.begin())); }
123 Property<T>& prop_(
const Id&
id)
const
125 auto it = _propMap.find(
id);
126 if (it == _propMap.end())
throw_ PropertyError() <<
"Property not found. Id: " << id;
127 PropertyBase* prop = it->second;
129 sout() <<
"Component type mismatch: "
131 <<
" ; Found: " << prop->type());
132 return static_cast<Property<T>&
>(*prop);
135 PropertyBase& prop_(
const Id&
id)
const
137 auto it = _propMap.find(
id);
138 if (it == _propMap.end())
throw_ PropertyError() <<
"Property not found. Id: " << id;
150 PropertyMap _propMap;
stdutil::unordered_map< Id, PropertyBase::Ptr, SmallAllocator > PropertyMap
Definition: PropertyObject.h:27
PropertyObject()
Definition: PropertyObject.h:30
Property< T > & prop(const Id &id)
Get property with id of type T. Throws PropertyError if property doesn't exist.
Definition: PropertyObject.h:86
Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically...
Definition: SharedPtr.h:175
virtual ~PropertyObject()
Releases all contained properties.
Definition: PropertyObject.h:33
bool hasProp(const Id &id) const
Check if object contains property with id and type T.
Definition: PropertyObject.h:56
PropertyBase::Ptr removeProp(const Id &id)
Remove a single property with id. Returns property if found and removed.
Definition: PropertyObject.h:109
void removeProps(const function< void(PropertyBase &)> &f=[](PropertyBase &){})
Remove all properties. Calls functor for each removed property.
Definition: PropertyObject.h:116
std::unordered_map< Key, Value, std::hash< Key >, std::equal_to< Key >, Alloc< pair< const Key, Value >>> unordered_map
std::unordered_map with custom allocator
Definition: StdUtil.h:83
const PropertyMap & props()
Get all properties.
Definition: PropertyObject.h:102
const PropertyBase & prop(const Id &id) const
Definition: PropertyObject.h:92
PropertyBase::Ptr removeProp(PropertyBase &prop)
Remove a single property. Returns property if found and removed.
Definition: PropertyObject.h:106
Property< T_ > & prop(const Id &id, T &&val)
Assign property with id to value. Throws PropertyError if property doesn't exist. Returns assigned pr...
Definition: PropertyObject.h:99
const PropertyMapConst & props() const
Definition: PropertyObject.h:103
#define EXCEPTION(Class)
Declares methods required for every subclass of honey::Exception.
Definition: Exception.h:17
SharedPtr< PropertyBase > Ptr
Definition: Property.h:17
ostringstream sout()
Shorthand to create ostringstream.
Definition: Stream.h:15
Definition: PropertyObject.h:13
const Property< T > & prop(const Id &id) const
Definition: PropertyObject.h:88
Property< T_ > & prop(const String &name, T &&val)
Assign property with name to value. Adds property if it doesn't exist. Returns assigned property...
Definition: PropertyObject.h:96
Base class for all properties.
Definition: Property.h:14
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
std::enable_if< std::is_default_constructible< Com >::value &&!std::is_abstract< Com >::value, Component & >::type create()
Called by registry to create a component. May be specialized for a component type.
Definition: Component.h:75
#define idnull
Null id.
Definition: Id.h:124
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
Base exception class. Exceptions inherited from this class provide debug info and can be thrown polym...
Definition: Exception.h:45
stdutil::unordered_map< Id, PropertyBase::ConstPtr, SmallAllocator > PropertyMapConst
Definition: PropertyObject.h:28
void addProp(PropertyBase &prop)
Add a property reference. Any existing property with the same id will be released and replaced...
Definition: PropertyObject.h:39
#define throw_
Use in place of throw keyword to throw a honey::Exception object polymorphically and provide debug in...
Definition: Exception.h:11
const Id & id() const
Get property id.
Definition: Property.h:25
static const NameId & s_type()
Static function to get property type info.
void addProp(PropertyBase *prop)
Wrapper for pointer arg.
Definition: PropertyObject.h:49
Holds a name string and its hashed value for fast comparison ops. See String Identifier.
Definition: Id.h:25
Property< T > & prop(const String &name)
Get property with name of type T. Adds property if it doesn't exist.
Definition: PropertyObject.h:64
bool hasProp(const Id &id) const
Check if object contains property with id.
Definition: PropertyObject.h:52
Global Honeycomb namespace.
Generic property.
Definition: Property.h:37
PropertyBase & prop(const Id &id)
Get property with id. Throws PropertyError if property doesn't exist.
Definition: PropertyObject.h:91