src/core/enum.h
author Tom Henderson <tomh@tomh.org>
Thu, 29 May 2008 23:24:10 -0700
changeset 3182 61fe7fe81ebd
parent 2969 9d05d2a95dfa
child 3763 e46e361a4262
permissions -rw-r--r--
Doxygen organization
     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"
    24 #include "attribute-accessor-helper.h"
    25 #include <list>
    26 
    27 namespace ns3 {
    28 
    29 /**
    30  * \ingroup attribute
    31  *
    32  * \brief hold variables of type 'enum'
    33  *
    34  * This class can be used to hold variables of any kind
    35  * of enum.
    36  */
    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 
    45   virtual Ptr<AttributeValue> Copy (void) const;
    46   virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
    47   virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
    48 
    49 private:
    50   int m_v;
    51 };
    52 
    53 class EnumChecker : public AttributeChecker
    54 {
    55 public:
    56   EnumChecker ();
    57 
    58   void AddDefault (int v, std::string name);
    59   void Add (int v, std::string name);
    60 
    61   virtual bool Check (const AttributeValue &value) const;
    62   virtual std::string GetValueTypeName (void) const;
    63   virtual bool HasUnderlyingTypeInformation (void) const;
    64   virtual std::string GetUnderlyingTypeInformation (void) const;
    65   virtual Ptr<AttributeValue> Create (void) const;
    66   virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const;
    67 
    68 private:
    69   friend class EnumValue;
    70   typedef std::list<std::pair<int,std::string> > ValueSet;
    71   ValueSet m_valueSet;
    72 };
    73 
    74 template <typename T1>
    75 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1);
    76 
    77 template <typename T1, typename T2>
    78 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2);
    79 
    80 Ptr<const AttributeChecker> MakeEnumChecker (int v1, std::string n1,
    81 					     int v2 = 0, std::string n2 = "",
    82 					     int v3 = 0, std::string n3 = "",
    83 					     int v4 = 0, std::string n4 = "",
    84 					     int v5 = 0, std::string n5 = "",
    85 					     int v6 = 0, std::string n6 = "",
    86 					     int v7 = 0, std::string n7 = "",
    87 					     int v8 = 0, std::string n8 = "",
    88 					     int v9 = 0, std::string n9 = "",
    89 					     int v10 = 0, std::string n10 = "",
    90 					     int v11 = 0, std::string n11 = "",
    91 					     int v12 = 0, std::string n12 = "");
    92 
    93 
    94 } // namespace ns3
    95 
    96 namespace ns3 {
    97 
    98 template <typename T1>
    99 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1)
   100 {
   101   return MakeAccessorHelper<EnumValue> (a1);
   102 }
   103 
   104 template <typename T1, typename T2>
   105 Ptr<const AttributeAccessor> MakeEnumAccessor (T1 a1, T2 a2)
   106 {
   107   return MakeAccessorHelper<EnumValue> (a1, a2);
   108 }
   109 
   110 } // namespace ns3
   111 
   112 #endif /* ENUM_VALUE_H */