A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
attribute.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "attribute.h"
9
10#include "fatal-error.h"
11#include "log.h"
12#include "string.h"
13
14#include <sstream>
15
16/**
17 * \file
18 * \ingroup attributes
19 * ns3::AttributeValue, ns3::AttributeAccessor and
20 * ns3::AttributeChecker implementations.
21 */
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("AttributeValue");
27
31
35
39
43
47
51
54{
55 NS_LOG_FUNCTION(this << &value);
56 if (Check(value))
57 {
58 return value.Copy();
59 }
60 // attempt to convert to string.
61 const auto str = dynamic_cast<const StringValue*>(&value);
62 if (str == nullptr)
63 {
64 return nullptr;
65 }
66 // attempt to convert back to value.
68 bool ok = v->DeserializeFromString(str->Get(), this);
69 if (!ok)
70 {
71 return nullptr;
72 }
73 ok = Check(*v);
74 if (!ok)
75 {
76 return nullptr;
77 }
78 return v;
79}
80
85
92
93std::string
95{
96 NS_LOG_FUNCTION(this << checker);
97 return "";
98}
99
100bool
102{
103 NS_LOG_FUNCTION(this << value << checker);
104 return true;
105}
106
111
115
116bool
118 const AttributeValue& value [[maybe_unused]]) const
119{
120 return true;
121}
122
123bool
124EmptyAttributeAccessor::Get(const ObjectBase* object [[maybe_unused]],
125 AttributeValue& attribute [[maybe_unused]]) const
126{
127 return true;
128}
129
130bool
132{
133 return false;
134}
135
136bool
138{
139 return false;
140}
141
146
150
151bool
152EmptyAttributeChecker::Check(const AttributeValue& value [[maybe_unused]]) const
153{
154 return true;
155}
156
157std::string
159{
160 return "EmptyAttribute";
161}
162
163bool
165{
166 return false;
167}
168
169std::string
174
177{
178 static EmptyAttributeValue t;
179 return Ptr<AttributeValue>(&t, false);
180}
181
182bool
183EmptyAttributeChecker::Copy(const AttributeValue& source [[maybe_unused]],
184 AttributeValue& destination [[maybe_unused]]) const
185{
186 return true;
187}
188
189} // namespace ns3
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
allow setting and getting the value of an attribute.
Definition attribute.h:105
virtual ~AttributeAccessor()
Definition attribute.cc:40
Represent the type of an attribute.
Definition attribute.h:157
virtual ~AttributeChecker()
Definition attribute.cc:48
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:53
virtual Ptr< AttributeValue > Create() const =0
Hold a value for an Attribute.
Definition attribute.h:59
virtual ~AttributeValue()
Definition attribute.cc:32
bool Get(const ObjectBase *object, AttributeValue &attribute) const override
Definition attribute.cc:124
bool Set(ObjectBase *object, const AttributeValue &value) const override
Definition attribute.cc:117
bool HasSetter() const override
Definition attribute.cc:137
bool HasGetter() const override
Definition attribute.cc:131
std::string GetValueTypeName() const override
Definition attribute.cc:158
bool Check(const AttributeValue &value) const override
Definition attribute.cc:152
Ptr< AttributeValue > Create() const override
Definition attribute.cc:176
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
Definition attribute.cc:183
bool HasUnderlyingTypeInformation() const override
Definition attribute.cc:164
~EmptyAttributeChecker() override
Definition attribute.cc:147
std::string GetUnderlyingTypeInformation() const override
Definition attribute.cc:170
A class for an empty attribute value.
Definition attribute.h:231
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition attribute.cc:94
EmptyAttributeValue()
Default constructor.
Definition attribute.cc:81
Ptr< AttributeValue > Copy() const override
Definition attribute.cc:87
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition attribute.cc:101
Anchor the ns-3 type and attribute system.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Definition string.h:45
NS_FATAL_x macro definitions.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::StringValue attribute value declarations.