00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef ATTRIBUTE_LIST_H 00021 #define ATTRIBUTE_LIST_H 00022 00023 #include <string> 00024 #include <vector> 00025 #include "attribute.h" 00026 #include "type-id.h" 00027 00028 namespace ns3 { 00029 00030 /** 00031 * \ingroup attribute 00032 * 00033 * \brief a container of attributes to be used during object's construction 00034 * and in ns3::Object::Set. 00035 * 00036 */ 00037 class AttributeList 00038 { 00039 public: 00040 AttributeList (); 00041 AttributeList (const AttributeList &o); 00042 AttributeList &operator = (const AttributeList &o); 00043 ~AttributeList (); 00044 /** 00045 * \param name the full name of the attribute to set 00046 * \param value the value to set 00047 * 00048 * This method checks that a attribute with the requested 00049 * name exists and that the value specified is an acceptable 00050 * value of that attribute. If any of these checks fails, 00051 * the program terminates with a message. 00052 */ 00053 void Set (std::string name, const AttributeValue &value); 00054 /** 00055 * \param name the full name of the attribute to set 00056 * \param value the value to set 00057 * \returns true if the requested attribute exists and could be 00058 * stored, false otherwise. 00059 */ 00060 bool SetFailSafe (std::string name, const AttributeValue &value); 00061 /** 00062 * \param tid the TypeId associated to this attribute 00063 * \param name the name (not full!) of the attribute 00064 * \param value the value to set 00065 * 00066 * This method checks that a attribute with the requested 00067 * name exists and that the value specified is an acceptable 00068 * value of that attribute. If any of these checks fails, 00069 * the program terminates with a message. 00070 */ 00071 void SetWithTid (TypeId tid, std::string name, const AttributeValue &value); 00072 00073 /** 00074 * Clear the content of this instance. 00075 */ 00076 void Reset (void); 00077 00078 /** 00079 * \returns the global attribute container 00080 * 00081 * The global attribute container can be used to specify 00082 * a set of attribute values without having to re-specify 00083 * them for each object when it is created. This container 00084 * is checked only during object construction and 00085 * it is always checked last, after any per-object 00086 * container is checked. 00087 */ 00088 static AttributeList *GetGlobal (void); 00089 00090 std::string SerializeToString (void) const; 00091 bool DeserializeFromString (std::string value); 00092 private: 00093 friend class ObjectBase; 00094 struct Attr { 00095 Ptr<const AttributeChecker> checker; 00096 Ptr<const AttributeValue> value; 00097 }; 00098 typedef std::vector<struct Attr> Attrs; 00099 typedef Attrs::iterator Iterator; 00100 typedef Attrs::const_iterator CIterator; 00101 00102 00103 00104 bool DoSet (struct TypeId::AttributeInfo *info, const AttributeValue ¶m); 00105 void DoSetOne (Ptr<const AttributeChecker> checker, const AttributeValue ¶m); 00106 std::string LookupAttributeFullNameByChecker (Ptr<const AttributeChecker> checker) const; 00107 00108 Attrs m_attributes; 00109 }; 00110 00111 class UnsafeAttributeList 00112 { 00113 public: 00114 UnsafeAttributeList (); 00115 UnsafeAttributeList (const UnsafeAttributeList &o); 00116 UnsafeAttributeList &operator = (const UnsafeAttributeList &o); 00117 ~UnsafeAttributeList (); 00118 00119 void Set (std::string name, const AttributeValue ¶m); 00120 00121 AttributeList GetSafe (std::string name) const; 00122 private: 00123 std::vector<std::pair<std::string,Ptr<AttributeValue> > > m_attributes; 00124 }; 00125 00126 } // namespace ns3 00127 00128 #endif /* ATTRIBUTE_LIST_H */