add UnsafeAttributeList
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 11 Jun 2008 16:19:01 -0700
changeset 3892 f985e116b696
parent 3891 590b21d7fcdd
child 3893 94f771c1373a
add UnsafeAttributeList
src/core/attribute-list.cc
src/core/attribute-list.h
--- a/src/core/attribute-list.cc	Wed Jun 11 16:18:38 2008 -0700
+++ b/src/core/attribute-list.cc	Wed Jun 11 16:19:01 2008 -0700
@@ -256,4 +256,59 @@
   return true;
 }
 
+UnsafeAttributeList::UnsafeAttributeList ()
+{}
+UnsafeAttributeList::UnsafeAttributeList (const UnsafeAttributeList &o)
+{
+  for (uint32_t i = 0; i < o.m_attributes.size (); ++i)
+    {
+      Set (o.m_attributes[i].first, *(o.m_attributes[i].second));
+    }
+}
+UnsafeAttributeList &
+UnsafeAttributeList::operator = (const UnsafeAttributeList &o)
+{
+  m_attributes.clear ();
+  for (uint32_t i = 0; i < o.m_attributes.size (); ++i)
+    {
+      Set (o.m_attributes[i].first, *(o.m_attributes[i].second));
+    }
+  return *this;
+}
+
+UnsafeAttributeList::~UnsafeAttributeList ()
+{
+  m_attributes.clear ();
+}
+void 
+UnsafeAttributeList::Set (std::string name, const AttributeValue &param)
+{
+  if (name == "")
+    {
+      return;
+    }
+  for (uint32_t i = 0; i < m_attributes.size (); ++i)
+    {
+      if (m_attributes[i].first == name)
+        {
+          m_attributes[i].second = param.Copy ();
+          return;
+        }
+    }
+  m_attributes.push_back (std::make_pair (name, param.Copy ()));
+}
+
+AttributeList 
+UnsafeAttributeList::GetSafe (std::string tidName) const
+{
+  AttributeList list;
+  for (uint32_t i = 0; i < m_attributes.size (); ++i)
+    {
+      TypeId tid = TypeId::LookupByName (tidName);
+      list.SetWithTid (tid, m_attributes[i].first, *m_attributes[i].second);
+    }
+  return list;
+}
+
+
 } // namespace ns3
--- a/src/core/attribute-list.h	Wed Jun 11 16:18:38 2008 -0700
+++ b/src/core/attribute-list.h	Wed Jun 11 16:19:01 2008 -0700
@@ -108,6 +108,21 @@
   Attrs m_attributes;
 };
 
+class UnsafeAttributeList
+{
+public:
+  UnsafeAttributeList ();
+  UnsafeAttributeList (const UnsafeAttributeList &o);
+  UnsafeAttributeList &operator = (const UnsafeAttributeList &o);
+  ~UnsafeAttributeList ();
+  
+  void Set (std::string name, const AttributeValue &param);
+
+  AttributeList GetSafe (std::string name) const;
+private:
+  std::vector<std::pair<std::string,Ptr<AttributeValue> > > m_attributes;
+};
+
 } // namespace ns3
 
 #endif /* ATTRIBUTE_LIST_H */