Honeycomb  0.1
Component-Model Framework
PropertyList.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 
6 namespace honey
7 {
8 
11 
13 template<class T>
14 class Property<vector<T>> : public PropertyBase, public vector<T>
15 {
16 public:
17  typedef vector<T> List;
20 
21  Property(const String& name) : PropertyBase(name), List(1) {}
22  Property(const String& name, const List& list) : PropertyBase(name), List(list) {}
23  Property(const String& name, List&& list) : PropertyBase(name), List(move(list)) {}
24  Property(const String& name, szt size, const T& val = T()) : PropertyBase(name), List(size, val) {}
25  template<class Iter>
26  Property(const String& name, Iter&& first, Iter&& last) : PropertyBase(name), List(forward<Iter>(first), forward<Iter>(last)) {}
27  Property(const Property& rhs) : PropertyBase(rhs._name), List(rhs) {}
28 
29  static const NameId& s_type();
30  virtual const NameId& type() const { return s_type(); }
31  virtual Property& clone() const { return *new Property(*this); }
32 
33  Property& operator=(const Property& rhs) { List::operator=(rhs); return *this; }
34  Property& operator=(const List& rhs) { List::operator=(rhs); return *this; }
35  Property& operator=(List&& rhs) { List::operator=(move(rhs)); return *this; }
37  Property& operator=(const T& rhs) { assert(this->size()); (*this)[0] = rhs; return *this; }
38  Property& operator=(T&& rhs) { assert(this->size()); (*this)[0] = move(rhs); return *this; }
39 
41  operator T&() { return (*this)[0]; }
42  operator const T&() const { return (*this)[0]; }
43 };
44 
46 typedef vector<int> IntList;
47 template<> inline auto Property<IntList>::s_type() -> const NameId& { static NameId _("IntList"); return _; }
48 
50 typedef vector<Real> RealList;
51 template<> inline auto Property<RealList>::s_type() -> const NameId& { static NameId _("RealList"); return _; }
52 
54 template<> inline auto Property<String::List>::s_type() -> const NameId& { static NameId _("String::List"); return _; }
55 
57 
58 }
Property & operator=(const T &rhs)
Assign to first element in list.
Definition: PropertyList.h:37
Property(const String &name)
Definition: Property.h:43
Holds both a name string and its hashed value, and unlike Id the name is never compiled out...
Definition: Id.h:144
const NameId _name
Definition: Property.h:32
Property & operator=(const Property &rhs)
Definition: PropertyList.h:33
Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically...
Definition: SharedPtr.h:175
Property(const String &name, List &&list)
Definition: PropertyList.h:23
Property(const String &name)
Definition: PropertyList.h:21
Property(const String &name, szt size, const T &val=T())
Definition: PropertyList.h:24
static auto _
Definition: Module.cpp:8
vector< T > List
Definition: PropertyList.h:17
vector< Real > RealList
Real list property.
Definition: PropertyList.h:50
const String & name() const
Get property name.
Definition: Property.h:23
SharedPtr< Property > Ptr
Definition: PropertyList.h:18
Base class for all properties.
Definition: Property.h:14
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Property(const String &name, const List &list)
Definition: PropertyList.h:22
Property(const String &name, Iter &&first, Iter &&last)
Definition: PropertyList.h:26
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
Property & operator=(const List &rhs)
Definition: PropertyList.h:34
Property & operator=(T &&rhs)
Definition: PropertyList.h:38
int size(const StdContainer &cont)
Safely get the size of a std container as a signed integer.
Definition: StdUtil.h:19
virtual Property & clone() const
Create a clone of this property.
Definition: PropertyList.h:31
static const NameId & s_type()
Static function to get property type info.
virtual const NameId & type() const
Get property type info.
Definition: PropertyList.h:30
vector< int > IntList
Integer list property.
Definition: PropertyList.h:46
Property(const Property &rhs)
Definition: PropertyList.h:27
SharedPtr< const Property > ConstPtr
Definition: PropertyList.h:19
Global Honeycomb namespace.
Generic property.
Definition: Property.h:37
Property & operator=(List &&rhs)
Definition: PropertyList.h:35