1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
23 #include "attribute.h"
24 #include "attribute-accessor-helper.h"
32 * \brief hold variables of type 'enum'
34 * This class can be used to hold variables of any kind
37 class EnumValue : public AttributeValue
45 bool GetAccessor (T &v) const;
47 virtual Ptr<AttributeValue> Copy (void) const;
48 virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
49 virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
56 bool EnumValue::GetAccessor (T &v) const
62 class EnumChecker : public AttributeChecker
67 void AddDefault (int v, std::string name);
68 void Add (int v, std::string name);
70 virtual bool Check (const AttributeValue &value) const;
71 virtual std::string GetValueTypeName (void) const;
72 virtual bool HasUnderlyingTypeInformation (void) const;
73 virtual std::string GetUnderlyingTypeInformation (void) const;
74 virtual Ptr<AttributeValue> Create (void) const;
75 virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const;
78 friend class EnumValue;
79 typedef std::list<std::pair<int,std::string> > ValueSet;
83 template <typename T1>
84 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1);
86 template <typename T1, typename T2>
87 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2);
89 Ptr<const AttributeChecker> MakeEnumChecker (int v1, std::string n1,
90 int v2 = 0, std::string n2 = "",
91 int v3 = 0, std::string n3 = "",
92 int v4 = 0, std::string n4 = "",
93 int v5 = 0, std::string n5 = "",
94 int v6 = 0, std::string n6 = "",
95 int v7 = 0, std::string n7 = "",
96 int v8 = 0, std::string n8 = "",
97 int v9 = 0, std::string n9 = "",
98 int v10 = 0, std::string n10 = "",
99 int v11 = 0, std::string n11 = "",
100 int v12 = 0, std::string n12 = "");
107 template <typename T1>
108 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1)
110 return MakeAccessorHelper<EnumValue> (a1);
113 template <typename T1, typename T2>
114 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2)
116 return MakeAccessorHelper<EnumValue> (a1, a2);
121 #endif /* ENUM_VALUE_H */