src/core/enum.h
changeset 2965 4b28e9740e3b
parent 2599 fcc1728eb669
child 2969 9d05d2a95dfa
equal deleted inserted replaced
2964:4e8cb1577144 2965:4b28e9740e3b
    30  * \brief hold variables of type 'enum'
    30  * \brief hold variables of type 'enum'
    31  *
    31  *
    32  * This class can be used to hold variables of any kind
    32  * This class can be used to hold variables of any kind
    33  * of enum.
    33  * of enum.
    34  */
    34  */
    35 class Enum : public AttributeValue
    35 class EnumValue : public AttributeValue
    36 {
    36 {
    37 public:
    37 public:
    38   Enum ();
    38   EnumValue ();
    39   Enum (int v);
    39   EnumValue (int v);
    40   void Set (int v);
    40   void Set (int v);
    41   int Get (void) const;
    41   int Get (void) const;
    42 
    42 
    43   virtual Attribute Copy (void) const;
    43   virtual Ptr<AttributeValue> Copy (void) const;
    44   virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
    44   virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
    45   virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
    45   virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
    46 
    46 
    47   Enum (Attribute value);
       
    48   operator Attribute () const;
       
    49 private:
    47 private:
    50   int m_v;
    48   int m_v;
    51 };
    49 };
    52 
    50 
    53 class EnumChecker : public AttributeChecker
    51 class EnumChecker : public AttributeChecker
    56   EnumChecker ();
    54   EnumChecker ();
    57 
    55 
    58   void AddDefault (int v, std::string name);
    56   void AddDefault (int v, std::string name);
    59   void Add (int v, std::string name);
    57   void Add (int v, std::string name);
    60 
    58 
    61   virtual bool Check (Attribute value) const;
    59   virtual bool Check (const AttributeValue &value) const;
    62   virtual std::string GetType (void) const;
    60   virtual std::string GetType (void) const;
    63   virtual bool HasTypeConstraints (void) const;
    61   virtual bool HasTypeConstraints (void) const;
    64   virtual std::string GetTypeConstraints (void) const;
    62   virtual std::string GetTypeConstraints (void) const;
    65   virtual Attribute Create (void) const;
    63   virtual Ptr<AttributeValue> Create (void) const;
       
    64   virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const;
    66 
    65 
    67 private:
    66 private:
    68   friend class Enum;
    67   friend class EnumValue;
    69   typedef std::list<std::pair<int,std::string> > ValueSet;
    68   typedef std::list<std::pair<int,std::string> > ValueSet;
    70   ValueSet m_valueSet;
    69   ValueSet m_valueSet;
    71 };
    70 };
    72 
    71 
    73 template <typename T1>
    72 template <typename T1>
    95 namespace ns3 {
    94 namespace ns3 {
    96 
    95 
    97 template <typename T1>
    96 template <typename T1>
    98 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1)
    97 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1)
    99 {
    98 {
   100   return MakeAccessorHelper<Enum> (a1);
    99   return MakeAccessorHelper<EnumValue> (a1);
   101 }
   100 }
   102 
   101 
   103 template <typename T1, typename T2>
   102 template <typename T1, typename T2>
   104 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2)
   103 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2)
   105 {
   104 {
   106   return MakeAccessorHelper<Enum> (a1, a2);
   105   return MakeAccessorHelper<EnumValue> (a1, a2);
   107 }
   106 }
   108 
   107 
   109 } // namespace ns3
   108 } // namespace ns3
   110 
   109 
   111 #endif /* ENUM_VALUE_H */
   110 #endif /* ENUM_VALUE_H */