7 #include <mxcomp/variant.h>
12 using MapT = std::map<std::string, std::unique_ptr<Variant> >;
13 using ListT = std::vector< std::unique_ptr<Variant> >;
14 using VariantT = Variant_<MapT, ListT, std::string, double, int, bool>;
20 static Variant* Create(
const T& t) {
27 virtual Variant* at(
const std::string& name);
29 Variant& operator[](
const std::string& name);
32 template<
typename T>
Variant& append(
const T&);
34 virtual bool hasValue(
const std::string& name);
36 virtual Type getType()
const;
37 virtual int asInt()
const;
38 virtual void asString(std::string& str)
const;
39 virtual size_t size()
const override;
42 Variant& operator=(
const std::initializer_list<T>&);
48 Variant& Variant::operator=(
const std::initializer_list<T>& t){
49 ListT& list = this->as<ListT>();
50 list.resize(t.size());
51 for(
size_t i = 0;i < t.size();i++)
52 list[i] = t.begin()[i];
57 Variant& Variant::operator=(
const T& t){
58 VariantT::operator =(t);
62 template<
typename T> Variant& Variant::append(
const T& t){
63 ListT& list = this->as<ListT>();
64 list.push_back( std::unique_ptr<Variant>(
new Variant() ) );
66 return *list.back().get();