A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
enum.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
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;
8  *
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.
13  *
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
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef ENUM_VALUE_H
21 #define ENUM_VALUE_H
22 
23 #include "attribute.h"
25 #include <list>
26 
27 namespace ns3 {
28 
37 class EnumValue : public AttributeValue
38 {
39 public:
40  EnumValue ();
41  EnumValue (int v);
42  void Set (int v);
43  int Get (void) const;
44  template <typename T>
45  bool GetAccessor (T &v) const;
46 
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);
50 
51 private:
52  int m_v;
53 };
54 
55 template <typename T>
56 bool EnumValue::GetAccessor (T &v) const
57 {
58  v = T (m_v);
59  return true;
60 }
61 
63 {
64 public:
65  EnumChecker ();
66 
67  void AddDefault (int v, std::string name);
68  void Add (int v, std::string name);
69 
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;
76 
77 private:
78  friend class EnumValue;
79  typedef std::list<std::pair<int,std::string> > ValueSet;
81 };
82 
83 template <typename T1>
85 
86 template <typename T1, typename T2>
88 
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 = "",
101  int v13 = 0, std::string n13 = "",
102  int v14 = 0, std::string n14 = "",
103  int v15 = 0, std::string n15 = "",
104  int v16 = 0, std::string n16 = "",
105  int v17 = 0, std::string n17 = "",
106  int v18 = 0, std::string n18 = "",
107  int v19 = 0, std::string n19 = "",
108  int v20 = 0, std::string n20 = "",
109  int v21 = 0, std::string n21 = "",
110  int v22 = 0, std::string n22 = "");
111 
112 
113 } // namespace ns3
114 
115 namespace ns3 {
116 
117 template <typename T1>
119 {
120  return MakeAccessorHelper<EnumValue> (a1);
121 }
122 
123 template <typename T1, typename T2>
125 {
126  return MakeAccessorHelper<EnumValue> (a1, a2);
127 }
128 
129 } // namespace ns3
130 
131 #endif /* ENUM_VALUE_H */
Represent the type of an attribute.
Definition: attribute.h:154
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Definition: enum.cc:178
Hold a value for an Attribute.
Definition: attribute.h:56
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: enum.cc:58
void Add(int v, std::string name)
Definition: enum.cc:104
int Get(void) const
Definition: enum.cc:46
void Set(int v)
Definition: enum.cc:40
virtual Ptr< AttributeValue > Create(void) const
Definition: enum.cc:156
virtual bool Copy(const AttributeValue &src, AttributeValue &dst) const
Copy the source to the destination.
Definition: enum.cc:163
hold variables of type 'enum'
Definition: enum.h:37
virtual std::string GetUnderlyingTypeInformation(void) const
Definition: enum.cc:140
virtual Ptr< AttributeValue > Copy(void) const
Definition: enum.cc:52
void AddDefault(int v, std::string name)
Definition: enum.cc:98
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: enum.cc:76
std::list< std::pair< int, std::string > > ValueSet
Definition: enum.h:79
virtual bool HasUnderlyingTypeInformation(void) const
Definition: enum.cc:134
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
int m_v
Definition: enum.h:52
ValueSet m_valueSet
Definition: enum.h:80
virtual std::string GetValueTypeName(void) const
Definition: enum.cc:128
virtual bool Check(const AttributeValue &value) const
Definition: enum.cc:110
bool GetAccessor(T &v) const
Definition: enum.h:56