src/core/attribute-list.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 3190 51fe9001a679
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #ifndef ATTRIBUTE_LIST_H
    21 #define ATTRIBUTE_LIST_H
    22 
    23 #include <string>
    24 #include <vector>
    25 #include "attribute.h"
    26 #include "type-id.h"
    27 
    28 namespace ns3 {
    29 
    30 /**
    31  * \ingroup attribute
    32  *
    33  * \brief a container of attributes to be used during object's construction
    34  *        and in ns3::Object::Set.
    35  *
    36  */
    37 class AttributeList
    38 {
    39 public:
    40   AttributeList ();
    41   AttributeList (const AttributeList &o);
    42   AttributeList &operator = (const AttributeList &o);
    43   ~AttributeList ();
    44   /**
    45    * \param name the full name of the attribute to set
    46    * \param value the value to set
    47    *
    48    * This method checks that a attribute with the requested
    49    * name exists and that the value specified is an acceptable
    50    * value of that attribute. If any of these checks fails,
    51    * the program terminates with a message.
    52    */
    53   void Set (std::string name, const AttributeValue &value);
    54   /**
    55    * \param name the full name of the attribute to set
    56    * \param value the value to set
    57    * \returns true if the requested attribute exists and could be
    58    *          stored, false otherwise.
    59    */
    60   bool SetFailSafe (std::string name, const AttributeValue &value);
    61   /**
    62    * \param tid the TypeId associated to this attribute
    63    * \param name the name (not full!) of the attribute
    64    * \param value the value to set
    65    *
    66    * This method checks that a attribute with the requested
    67    * name exists and that the value specified is an acceptable
    68    * value of that attribute. If any of these checks fails,
    69    * the program terminates with a message.
    70    */
    71   void SetWithTid (TypeId tid, std::string name, const AttributeValue &value);
    72 
    73   /**
    74    * Clear the content of this instance.
    75    */
    76   void Reset (void);
    77 
    78   /**
    79    * \returns the global attribute container
    80    *
    81    * The global attribute container can be used to specify
    82    * a set of attribute values without having to re-specify
    83    * them for each object when it is created. This container
    84    * is checked only during object construction and 
    85    * it is always checked last, after any per-object
    86    * container is checked.
    87    */
    88   static AttributeList *GetGlobal (void);
    89 
    90   std::string SerializeToString (void) const;
    91   bool DeserializeFromString (std::string value);
    92 private:
    93   friend class ObjectBase;
    94   struct Attr {
    95     Ptr<const AttributeChecker> checker;
    96     Ptr<const AttributeValue> value;
    97   };
    98   typedef std::vector<struct Attr> Attrs;
    99   typedef Attrs::iterator Iterator;
   100   typedef Attrs::const_iterator CIterator;
   101 
   102 
   103 
   104   bool DoSet (struct TypeId::AttributeInfo *info, const AttributeValue &param);
   105   void DoSetOne (Ptr<const AttributeChecker> checker, const AttributeValue &param);
   106   std::string LookupAttributeFullNameByChecker (Ptr<const AttributeChecker> checker) const;
   107 
   108   Attrs m_attributes;
   109 };
   110 
   111 class UnsafeAttributeList
   112 {
   113 public:
   114   UnsafeAttributeList ();
   115   UnsafeAttributeList (const UnsafeAttributeList &o);
   116   UnsafeAttributeList &operator = (const UnsafeAttributeList &o);
   117   ~UnsafeAttributeList ();
   118   
   119   void Set (std::string name, const AttributeValue &param);
   120 
   121   AttributeList GetSafe (std::string name) const;
   122 private:
   123   std::vector<std::pair<std::string,Ptr<AttributeValue> > > m_attributes;
   124 };
   125 
   126 } // namespace ns3
   127 
   128 #endif /* ATTRIBUTE_LIST_H */