mathieu@2581: /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ mathieu@2581: /* mathieu@2581: * Copyright (c) 2008 INRIA mathieu@2581: * mathieu@2581: * This program is free software; you can redistribute it and/or modify mathieu@2581: * it under the terms of the GNU General Public License version 2 as mathieu@2581: * published by the Free Software Foundation; mathieu@2581: * mathieu@2581: * This program is distributed in the hope that it will be useful, mathieu@2581: * but WITHOUT ANY WARRANTY; without even the implied warranty of mathieu@2581: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the mathieu@2581: * GNU General Public License for more details. mathieu@2581: * mathieu@2581: * You should have received a copy of the GNU General Public License mathieu@2581: * along with this program; if not, write to the Free Software mathieu@2581: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA mathieu@2581: * mathieu@2581: * Authors: Mathieu Lacage mathieu@2581: */ mathieu@2381: #ifndef ENUM_VALUE_H mathieu@2381: #define ENUM_VALUE_H mathieu@2381: mathieu@2438: #include "attribute.h" mathieu@2449: #include "attribute-accessor-helper.h" mathieu@2381: #include mathieu@2381: mathieu@2381: namespace ns3 { mathieu@2381: mathieu@2584: /** tomh@3182: * \ingroup attribute tomh@3182: * mathieu@2584: * \brief hold variables of type 'enum' mathieu@2584: * mathieu@2584: * This class can be used to hold variables of any kind mathieu@2584: * of enum. mathieu@2584: */ mathieu@2965: class EnumValue : public AttributeValue mathieu@2381: { mathieu@2381: public: mathieu@2965: EnumValue (); mathieu@2965: EnumValue (int v); mathieu@2381: void Set (int v); mathieu@2381: int Get (void) const; mathieu@3763: template mathieu@3763: bool GetAccessor (T &v) const; mathieu@2381: mathieu@2965: virtual Ptr Copy (void) const; mathieu@2427: virtual std::string SerializeToString (Ptr checker) const; mathieu@2427: virtual bool DeserializeFromString (std::string value, Ptr checker); mathieu@2381: mathieu@2381: private: mathieu@2381: int m_v; mathieu@2381: }; mathieu@2381: mathieu@3763: template mathieu@3763: bool EnumValue::GetAccessor (T &v) const mathieu@3763: { mathieu@3763: v = T (m_v); mathieu@3763: return true; mathieu@3763: } mathieu@3763: mathieu@2427: class EnumChecker : public AttributeChecker mathieu@2381: { mathieu@2381: public: mathieu@2427: EnumChecker (); mathieu@2381: mathieu@2381: void AddDefault (int v, std::string name); mathieu@2381: void Add (int v, std::string name); mathieu@2381: mathieu@2965: virtual bool Check (const AttributeValue &value) const; mathieu@2969: virtual std::string GetValueTypeName (void) const; mathieu@2969: virtual bool HasUnderlyingTypeInformation (void) const; mathieu@2969: virtual std::string GetUnderlyingTypeInformation (void) const; mathieu@2965: virtual Ptr Create (void) const; mathieu@2965: virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const; mathieu@2381: mathieu@2381: private: mathieu@2965: friend class EnumValue; mathieu@2381: typedef std::list > ValueSet; mathieu@2381: ValueSet m_valueSet; mathieu@2381: }; mathieu@2381: mathieu@2427: template mathieu@2436: Ptr MakeEnumAccessor (T1 a1); mathieu@2427: mathieu@2427: template mathieu@2436: Ptr MakeEnumAccessor (T1 a1, T2 a2); mathieu@2427: mathieu@2436: Ptr MakeEnumChecker (int v1, std::string n1, mathieu@2436: int v2 = 0, std::string n2 = "", mathieu@2436: int v3 = 0, std::string n3 = "", mathieu@2436: int v4 = 0, std::string n4 = "", mathieu@2436: int v5 = 0, std::string n5 = "", mathieu@2436: int v6 = 0, std::string n6 = "", mathieu@2436: int v7 = 0, std::string n7 = "", mathieu@2436: int v8 = 0, std::string n8 = "", mathieu@2436: int v9 = 0, std::string n9 = "", mathieu@2436: int v10 = 0, std::string n10 = "", mathieu@2436: int v11 = 0, std::string n11 = "", mathieu@2436: int v12 = 0, std::string n12 = ""); mathieu@2381: mathieu@2381: mathieu@2381: } // namespace ns3 mathieu@2381: mathieu@2381: namespace ns3 { mathieu@2381: mathieu@2427: template mathieu@2436: Ptr MakeEnumAccessor (T1 a1) mathieu@2381: { mathieu@2965: return MakeAccessorHelper (a1); mathieu@2427: } mathieu@2427: mathieu@2427: template mathieu@2436: Ptr MakeEnumAccessor (T1 a1, T2 a2) mathieu@2427: { mathieu@2965: return MakeAccessorHelper (a1, a2); mathieu@2381: } mathieu@2381: mathieu@2381: } // namespace ns3 mathieu@2381: mathieu@2381: #endif /* ENUM_VALUE_H */