src/core/model/attribute-construction-list.cc
changeset 7399 520706f801e8
child 9134 7a750f032acd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/model/attribute-construction-list.cc	Wed Aug 03 13:58:10 2011 -0400
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Mathieu Lacage
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
+ */
+#include "attribute-construction-list.h"
+#include "log.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE("AttributeConstructionList");
+
+AttributeConstructionList::AttributeConstructionList ()
+{}
+
+void 
+AttributeConstructionList::Add (std::string name, Ptr<const AttributeChecker> checker, Ptr<AttributeValue> value)
+{
+  // get rid of any previous value stored in this
+  // vector of values.
+  for (std::list<struct Item>::iterator k = m_list.begin (); k != m_list.end (); k++)
+    {
+      if (k->checker == checker)
+        {
+          m_list.erase (k);
+          break;
+        }
+    }
+  // store the new value.
+  struct Item attr;
+  attr.checker = checker;
+  attr.value = value;
+  attr.name = name;
+  m_list.push_back (attr);
+
+}
+Ptr<AttributeValue> 
+AttributeConstructionList::Find (Ptr<const AttributeChecker> checker) const
+{
+  NS_LOG_FUNCTION (checker);
+  for (CIterator k = m_list.begin (); k != m_list.end (); k++)
+    {
+      NS_LOG_DEBUG ("Found " << k->name << " " << k->checker << " " << k->value);
+      if (k->checker == checker)
+        {
+	  return k->value;
+	}
+    }  
+  return 0;
+}
+
+AttributeConstructionList::CIterator 
+AttributeConstructionList::Begin (void) const
+{
+  return m_list.begin();
+}
+AttributeConstructionList::CIterator
+AttributeConstructionList::End (void) const
+{
+  return m_list.end();
+}
+
+} // namespace ns3