A Discrete-Event Network Simulator
API
attribute.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
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@sophia.inria.fr>
19  */
20 #include "attribute.h"
21 #include "log.h"
22 #include "fatal-error.h"
23 #include "string.h"
24 #include <sstream>
25 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("AttributeValue");
36 
38 {}
40 {}
41 
42 
44 {}
46 {}
47 
49 {}
51 {}
52 
55 {
56  NS_LOG_FUNCTION (this << &value);
57  if (Check (value))
58  {
59  return value.Copy ();
60  }
61  // attempt to convert to string.
62  const StringValue *str = dynamic_cast<const StringValue *> (&value);
63  if (str == 0)
64  {
65  return 0;
66  }
67  // attempt to convert back to value.
69  bool ok = v->DeserializeFromString (str->Get (), this);
70  if (!ok)
71  {
72  return 0;
73  }
74  ok = Check (*v);
75  if (!ok)
76  {
77  return 0;
78  }
79  return v;
80 }
81 
83 {
84  NS_LOG_FUNCTION (this);
85 }
88 {
89  NS_LOG_FUNCTION (this);
90  return Create<EmptyAttributeValue> ();
91 }
92 std::string
94 {
95  NS_LOG_FUNCTION (this << checker);
96  return "";
97 }
98 bool
100 {
101  NS_LOG_FUNCTION (this << value << checker);
102  return true;
103 }
104 
106 {}
107 
109 {}
110 
111 bool
113 {
114  (void) object;
115  (void) value;
116  return true;
117 }
118 
119 bool
120 EmptyAttributeAccessor::Get (const ObjectBase * object, AttributeValue &attribute) const
121 {
122  (void) object;
123  (void) attribute;
124  return true;
125 }
126 
127 bool
129 {
130  return false;
131 }
132 
133 bool
135 {
136  return false;
137 }
138 
140 {}
141 
143 {}
144 
145 bool
147 {
148  (void) value;
149  return true;
150 }
151 
152 std::string
154 {
155  return "EmptyAttribute";
156 }
157 
158 bool
160 {
161  return false;
162 }
163 
164 std::string
166 {
167  return "";
168 }
169 
172 {
173  static EmptyAttributeValue t;
174  return Ptr<AttributeValue> (&t, false);
175 }
176 
177 bool
178 EmptyAttributeChecker::Copy (const AttributeValue &source, AttributeValue &destination) const
179 {
180  (void) source;
181  (void) destination;
182  return true;
183 }
184 
185 
186 } // namespace ns3
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
allow setting and getting the value of an attribute.
Definition: attribute.h:115
virtual ~AttributeAccessor()
Definition: attribute.cc:45
Represent the type of an attribute.
Definition: attribute.h:167
virtual Ptr< AttributeValue > Create(void) const =0
virtual ~AttributeChecker()
Definition: attribute.cc:50
virtual bool Check(const AttributeValue &value) const =0
Ptr< AttributeValue > CreateValidValue(const AttributeValue &value) const
Create a valid value from the argument value, or reinterpret the argument as a string.
Definition: attribute.cc:54
Hold a value for an Attribute.
Definition: attribute.h:69
virtual ~AttributeValue()
Definition: attribute.cc:39
virtual bool HasGetter(void) const
Definition: attribute.cc:128
virtual bool HasSetter(void) const
Definition: attribute.cc:134
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
Definition: attribute.cc:112
virtual bool Get(const ObjectBase *object, AttributeValue &attribute) const
Definition: attribute.cc:120
virtual Ptr< AttributeValue > Create(void) const
Definition: attribute.cc:171
virtual std::string GetUnderlyingTypeInformation(void) const
Definition: attribute.cc:165
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const
Copy the source to the destination.
Definition: attribute.cc:178
virtual bool HasUnderlyingTypeInformation(void) const
Definition: attribute.cc:159
virtual bool Check(const AttributeValue &value) const
Definition: attribute.cc:146
virtual std::string GetValueTypeName(void) const
Definition: attribute.cc:153
A class for an empty attribute value.
Definition: attribute.h:233
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: attribute.cc:93
EmptyAttributeValue()
Default constructor.
Definition: attribute.cc:82
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: attribute.cc:99
virtual Ptr< AttributeValue > Copy(void) const
Definition: attribute.cc:87
Anchor the ns-3 type and attribute system.
Definition: object-base.h:120
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Hold variables of type string.
Definition: string.h:41
std::string Get(void) const
Definition: string.cc:31
NS_FATAL_x macro definitions.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.
ns3::StringValue attribute value declarations.