00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ENUM_VALUE_H
00021 #define ENUM_VALUE_H
00022
00023 #include "attribute.h"
00024 #include "attribute-accessor-helper.h"
00025 #include <list>
00026
00027 namespace ns3 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class EnumValue : public AttributeValue
00038 {
00039 public:
00040 EnumValue ();
00041 EnumValue (int v);
00042 void Set (int v);
00043 int Get (void) const;
00044 template <typename T>
00045 bool GetAccessor (T &v) const;
00046
00047 virtual Ptr<AttributeValue> Copy (void) const;
00048 virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
00049 virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
00050
00051 private:
00052 int m_v;
00053 };
00054
00055 template <typename T>
00056 bool EnumValue::GetAccessor (T &v) const
00057 {
00058 v = T (m_v);
00059 return true;
00060 }
00061
00062 class EnumChecker : public AttributeChecker
00063 {
00064 public:
00065 EnumChecker ();
00066
00067 void AddDefault (int v, std::string name);
00068 void Add (int v, std::string name);
00069
00070 virtual bool Check (const AttributeValue &value) const;
00071 virtual std::string GetValueTypeName (void) const;
00072 virtual bool HasUnderlyingTypeInformation (void) const;
00073 virtual std::string GetUnderlyingTypeInformation (void) const;
00074 virtual Ptr<AttributeValue> Create (void) const;
00075 virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const;
00076
00077 private:
00078 friend class EnumValue;
00079 typedef std::list<std::pair<int,std::string> > ValueSet;
00080 ValueSet m_valueSet;
00081 };
00082
00083 template <typename T1>
00084 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1);
00085
00086 template <typename T1, typename T2>
00087 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2);
00088
00089 Ptr<const AttributeChecker> MakeEnumChecker (int v1, std::string n1,
00090 int v2 = 0, std::string n2 = "",
00091 int v3 = 0, std::string n3 = "",
00092 int v4 = 0, std::string n4 = "",
00093 int v5 = 0, std::string n5 = "",
00094 int v6 = 0, std::string n6 = "",
00095 int v7 = 0, std::string n7 = "",
00096 int v8 = 0, std::string n8 = "",
00097 int v9 = 0, std::string n9 = "",
00098 int v10 = 0, std::string n10 = "",
00099 int v11 = 0, std::string n11 = "",
00100 int v12 = 0, std::string n12 = "");
00101
00102
00103 }
00104
00105 namespace ns3 {
00106
00107 template <typename T1>
00108 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1)
00109 {
00110 return MakeAccessorHelper<EnumValue> (a1);
00111 }
00112
00113 template <typename T1, typename T2>
00114 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2)
00115 {
00116 return MakeAccessorHelper<EnumValue> (a1, a2);
00117 }
00118
00119 }
00120
00121 #endif