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 {
39 }
41 {
42 }
43 
44 
46 {
47 }
49 {
50 }
51 
53 {
54 }
56 {
57 }
58 
61 {
62  NS_LOG_FUNCTION (this << &value);
63  if (Check (value))
64  {
65  return value.Copy ();
66  }
67  // attempt to convert to string.
68  const StringValue *str = dynamic_cast<const StringValue *> (&value);
69  if (str == 0)
70  {
71  return 0;
72  }
73  // attempt to convert back to value.
75  bool ok = v->DeserializeFromString (str->Get (), this);
76  if (!ok)
77  {
78  return 0;
79  }
80  ok = Check (*v);
81  if (!ok)
82  {
83  return 0;
84  }
85  return v;
86 }
87 
89 {
90  NS_LOG_FUNCTION (this);
91 }
94 {
95  NS_LOG_FUNCTION (this);
96  return Create<EmptyAttributeValue> ();
97 }
98 std::string
100 {
101  NS_LOG_FUNCTION (this << checker);
102  return "";
103 }
104 bool
106 {
107  NS_LOG_FUNCTION (this << value << checker);
108  return true;
109 }
110 
112 {
113 }
114 
116 {
117 }
118 
119 bool
121 {
122  (void) object;
123  (void) value;
124  return true;
125 }
126 
127 bool
128 EmptyAttributeAccessor::Get (const ObjectBase * object, AttributeValue &attribute) const
129 {
130  (void) object;
131  (void) attribute;
132  return true;
133 }
134 
135 bool
137 {
138  return false;
139 }
140 
141 bool
143 {
144  return false;
145 }
146 
148 {
149 }
150 
152 {
153 }
154 
155 bool
157 {
158  (void) value;
159  return true;
160 }
161 
162 std::string
164 {
165  return "EmptyAttribute";
166 }
167 
168 bool
170 {
171  return false;
172 }
173 
174 std::string
176 {
177  return "";
178 }
179 
182 {
183  static EmptyAttributeValue t;
184  return Ptr<AttributeValue> (&t, false);
185 }
186 
187 bool
188 EmptyAttributeChecker::Copy (const AttributeValue &source, AttributeValue &destination) const
189 {
190  (void) source;
191  (void) destination;
192  return true;
193 }
194 
195 
196 } // namespace ns3
NS_FATAL_x macro definitions.
virtual bool HasGetter(void) const
Definition: attribute.cc:136
Represent the type of an attribute.
Definition: attribute.h:166
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 "...
Hold variables of type string.
Definition: string.h:41
virtual std::string GetValueTypeName(void) const
Definition: attribute.cc:163
ns3::StringValue attribute value declarations.
Hold a value for an Attribute.
Definition: attribute.h:68
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
Definition: attribute.cc:120
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: attribute.cc:105
Anchor the ns-3 type and attribute system.
Definition: object-base.h:119
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:60
EmptyAttributeValue()
Default constructor.
Definition: attribute.cc:88
std::string Get(void) const
Definition: string.cc:31
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const
Copy the source to the destination.
Definition: attribute.cc:188
A class for an empty attribute value.
Definition: attribute.h:232
virtual ~AttributeAccessor()
Definition: attribute.cc:48
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
allow setting and getting the value of an attribute.
Definition: attribute.h:114
virtual ~AttributeValue()
Definition: attribute.cc:40
virtual Ptr< AttributeValue > Copy(void) const =0
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool HasSetter(void) const
Definition: attribute.cc:142
virtual Ptr< AttributeValue > Create(void) const =0
virtual ~AttributeChecker()
Definition: attribute.cc:55
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: attribute.cc:99
virtual Ptr< AttributeValue > Create(void) const
Definition: attribute.cc:181
virtual Ptr< AttributeValue > Copy(void) const
Definition: attribute.cc:93
virtual bool HasUnderlyingTypeInformation(void) const
Definition: attribute.cc:169
virtual std::string GetUnderlyingTypeInformation(void) const
Definition: attribute.cc:175
virtual bool Check(const AttributeValue &value) const
Definition: attribute.cc:156
Debug message logging.
virtual bool Check(const AttributeValue &value) const =0
virtual bool Get(const ObjectBase *object, AttributeValue &attribute) const
Definition: attribute.cc:128