A Discrete-Event Network Simulator
API
attribute-construction-list.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Mathieu Lacage
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  * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
19  */
21 #include "log.h"
22 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE("AttributeConstructionList");
32 
34 {
35  NS_LOG_FUNCTION (this);
36 }
37 
38 void
40 {
41  // get rid of any previous value stored in this
42  // vector of values.
43  NS_LOG_FUNCTION (this << name << checker << value);
44 
45  for (std::list<struct Item>::iterator k = m_list.begin (); k != m_list.end (); k++)
46  {
47  if (k->checker == checker)
48  {
49  m_list.erase (k);
50  break;
51  }
52  }
53  // store the new value.
54  struct Item attr;
55  attr.checker = checker;
56  attr.value = value;
57  attr.name = name;
58  m_list.push_back (attr);
59 
60 }
63 {
64  NS_LOG_FUNCTION (this << checker);
65  for (CIterator k = m_list.begin (); k != m_list.end (); k++)
66  {
67  NS_LOG_DEBUG ("Found " << k->name << " " << k->checker << " " << k->value);
68  if (k->checker == checker)
69  {
70  return k->value;
71  }
72  }
73  return 0;
74 }
75 
78 {
79  NS_LOG_FUNCTION (this);
80  return m_list.begin();
81 }
84 {
85  NS_LOG_FUNCTION (this);
86  return m_list.end();
87 }
88 
89 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< const AttributeChecker > checker
Checker used to validate serialized values.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Ptr< AttributeValue > value
The value of the Attribute.
ns3::AttributeConstructionList declaration.
std::list< struct Item > m_list
The list of Items.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::list< struct Item >::const_iterator CIterator
Iterator type.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Ptr< AttributeValue > Find(Ptr< const AttributeChecker > checker) const
Find an Attribute in the list from its AttributeChecker.
Debug message logging.
void Add(std::string name, Ptr< const AttributeChecker > checker, Ptr< AttributeValue > value)
Add an Attribute to the list.
std::string name
The name of the Attribute.