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 "log.h"
11#include "string.h"
12
13/**
14 * @file
15 * @ingroup attributes
16 * ns3::AttributeValue, ns3::AttributeAccessor and
17 * ns3::AttributeChecker implementations.
18 */
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("AttributeValue");
24
28
32
36
40
44
48
51{
52 NS_LOG_FUNCTION(this << &value);
53 if (Check(value))
54 {
55 return value.Copy();
56 }
57 // attempt to convert to string.
58 const auto str = dynamic_cast<const StringValue*>(&value);
59 if (str == nullptr)
60 {
61 return nullptr;
62 }
63 // attempt to convert back to value.
65 bool ok = v->DeserializeFromString(str->Get(), this);
66 if (!ok)
67 {
68 return nullptr;
69 }
70 ok = Check(*v);
71 if (!ok)
72 {
73 return nullptr;
74 }
75 return v;
76}
77
82
89
90std::string
92{
93 NS_LOG_FUNCTION(this << checker);
94 return "";
95}
96
97bool
99{
100 NS_LOG_FUNCTION(this << value << checker);
101 return true;
102}
103
108
112
113bool
115 const AttributeValue& value [[maybe_unused]]) const
116{
117 return true;
118}
119
120bool
121EmptyAttributeAccessor::Get(const ObjectBase* object [[maybe_unused]],
122 AttributeValue& attribute [[maybe_unused]]) const
123{
124 return true;
125}
126
127bool
129{
130 return false;
131}
132
133bool
135{
136 return false;
137}
138
143
147
148bool
149EmptyAttributeChecker::Check(const AttributeValue& value [[maybe_unused]]) const
150{
151 return true;
152}
153
154std::string
156{
157 return "EmptyAttribute";
158}
159
160bool
162{
163 return false;
164}
165
166std::string
171
174{
175 static EmptyAttributeValue t;
176 return Ptr<AttributeValue>(&t, false);
177}
178
179bool
180EmptyAttributeChecker::Copy(const AttributeValue& source [[maybe_unused]],
181 AttributeValue& destination [[maybe_unused]]) const
182{
183 return true;
184}
185
186} // namespace ns3
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
uint32_t v
virtual ~AttributeAccessor()
Definition attribute.cc:37
virtual ~AttributeChecker()
Definition attribute.cc:45
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:50
virtual Ptr< AttributeValue > Create() const =0
Hold a value for an Attribute.
Definition attribute.h:59
virtual ~AttributeValue()
Definition attribute.cc:29
bool Get(const ObjectBase *object, AttributeValue &attribute) const override
Definition attribute.cc:121
bool Set(ObjectBase *object, const AttributeValue &value) const override
Definition attribute.cc:114
bool HasSetter() const override
Definition attribute.cc:134
bool HasGetter() const override
Definition attribute.cc:128
std::string GetValueTypeName() const override
Definition attribute.cc:155
bool Check(const AttributeValue &value) const override
Definition attribute.cc:149
Ptr< AttributeValue > Create() const override
Definition attribute.cc:173
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
Definition attribute.cc:180
bool HasUnderlyingTypeInformation() const override
Definition attribute.cc:161
~EmptyAttributeChecker() override
Definition attribute.cc:144
std::string GetUnderlyingTypeInformation() const override
Definition attribute.cc:167
A class for an empty attribute value.
Definition attribute.h:231
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition attribute.cc:91
EmptyAttributeValue()
Default constructor.
Definition attribute.cc:78
Ptr< AttributeValue > Copy() const override
Definition attribute.cc:84
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition attribute.cc:98
Anchor the ns-3 type and attribute system.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Hold variables of type string.
Definition string.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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:454
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::StringValue attribute value declarations.