A Discrete-Event Network Simulator
API
attribute-construction-list.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Mathieu Lacage
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
18  */
20 
21 #include "log.h"
22 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("AttributeConstructionList");
33 
35 {
36  NS_LOG_FUNCTION(this);
37 }
38 
39 void
42  Ptr<AttributeValue> value)
43 {
44  // get rid of any previous value stored in this
45  // vector of values.
46  NS_LOG_FUNCTION(this << name << checker << value);
47 
48  for (auto k = m_list.begin(); k != m_list.end(); k++)
49  {
50  if (k->checker == checker)
51  {
52  m_list.erase(k);
53  break;
54  }
55  }
56  // store the new value.
57  Item attr;
58  attr.checker = checker;
59  attr.value = value;
60  attr.name = name;
61  m_list.push_back(attr);
62 }
63 
66 {
67  NS_LOG_FUNCTION(this << checker);
68  for (auto k = m_list.begin(); k != m_list.end(); k++)
69  {
70  NS_LOG_DEBUG("Found " << k->name << " " << k->checker << " " << k->value);
71  if (k->checker == checker)
72  {
73  return k->value;
74  }
75  }
76  return nullptr;
77 }
78 
81 {
82  NS_LOG_FUNCTION(this);
83  return m_list.begin();
84 }
85 
88 {
89  NS_LOG_FUNCTION(this);
90  return m_list.end();
91 }
92 
93 } // namespace ns3
ns3::AttributeConstructionList declaration.
Ptr< AttributeValue > Find(Ptr< const AttributeChecker > checker) const
Find an Attribute in the list from its AttributeChecker.
void Add(std::string name, Ptr< const AttributeChecker > checker, Ptr< AttributeValue > value)
Add an Attribute to the list.
std::list< Item > m_list
The list of Items.
std::list< Item >::const_iterator CIterator
Iterator type.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string name
The name of the Attribute.
Ptr< const AttributeChecker > checker
Checker used to validate serialized values.
Ptr< AttributeValue > value
The value of the Attribute.