A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef ATTRIBUTE_H
20#define ATTRIBUTE_H
21
22#include "ptr.h"
23#include "simple-ref-count.h"
24
25#include <stdint.h>
26#include <string>
27
35namespace ns3
36{
37
38class AttributeAccessor;
39class AttributeChecker;
40class Attribute;
41class ObjectBase;
42
69class AttributeValue : public SimpleRefCount<AttributeValue>
70{
71 public:
73 virtual ~AttributeValue();
74
78 virtual Ptr<AttributeValue> Copy() const = 0;
88 virtual std::string SerializeToString(Ptr<const AttributeChecker> checker) const = 0;
102 virtual bool DeserializeFromString(std::string value, Ptr<const AttributeChecker> checker) = 0;
103};
104
115class AttributeAccessor : public SimpleRefCount<AttributeAccessor>
116{
117 public:
119 virtual ~AttributeAccessor();
120
129 virtual bool Set(ObjectBase* object, const AttributeValue& value) const = 0;
139 virtual bool Get(const ObjectBase* object, AttributeValue& attribute) const = 0;
140
145 virtual bool HasGetter() const = 0;
150 virtual bool HasSetter() const = 0;
151};
152
167class AttributeChecker : public SimpleRefCount<AttributeChecker>
168{
169 public:
171 virtual ~AttributeChecker();
172
187 virtual bool Check(const AttributeValue& value) const = 0;
196 virtual std::string GetValueTypeName() const = 0;
204 virtual bool HasUnderlyingTypeInformation() const = 0;
209 virtual std::string GetUnderlyingTypeInformation() const = 0;
217 virtual Ptr<AttributeValue> Create() const = 0;
225 virtual bool Copy(const AttributeValue& source, AttributeValue& destination) const = 0;
226};
227
242{
243 public:
246
247 private:
251 Ptr<AttributeValue> Copy() const override;
258 std::string SerializeToString(Ptr<const AttributeChecker> checker) const override;
267 bool DeserializeFromString(std::string value, Ptr<const AttributeChecker> checker) override;
268};
269
278{
279 public:
281 ~EmptyAttributeAccessor() override;
282 bool Set(ObjectBase* object, const AttributeValue& value) const override;
283 bool Get(const ObjectBase* object, AttributeValue& attribute) const override;
284 bool HasGetter() const override;
285 bool HasSetter() const override;
286};
287
297{
299}
300
310{
311 public:
313 ~EmptyAttributeChecker() override;
314 bool Check(const AttributeValue& value) const override;
315 std::string GetValueTypeName() const override;
316 bool HasUnderlyingTypeInformation() const override;
317 std::string GetUnderlyingTypeInformation() const override;
318 Ptr<AttributeValue> Create() const override;
319 bool Copy(const AttributeValue& source, AttributeValue& destination) const override;
320};
321
329static inline Ptr<AttributeChecker>
331{
332 return Ptr<AttributeChecker>(new EmptyAttributeChecker(), false);
333}
334
335} // namespace ns3
336
337#endif /* ATTRIBUTE_H */
allow setting and getting the value of an attribute.
Definition: attribute.h:116
virtual bool Get(const ObjectBase *object, AttributeValue &attribute) const =0
virtual bool Set(ObjectBase *object, const AttributeValue &value) const =0
virtual bool HasSetter() const =0
virtual bool HasGetter() const =0
virtual ~AttributeAccessor()
Definition: attribute.cc:51
Represent the type of an attribute.
Definition: attribute.h:168
virtual bool HasUnderlyingTypeInformation() const =0
virtual ~AttributeChecker()
Definition: attribute.cc:59
virtual std::string GetValueTypeName() const =0
virtual bool Check(const AttributeValue &value) const =0
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const =0
Copy the source to the destination.
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:64
virtual std::string GetUnderlyingTypeInformation() const =0
virtual Ptr< AttributeValue > Create() const =0
Hold a value for an Attribute.
Definition: attribute.h:70
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)=0
virtual Ptr< AttributeValue > Copy() const =0
virtual ~AttributeValue()
Definition: attribute.cc:43
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const =0
An accessor for EmptyAttributeValue.
Definition: attribute.h:278
bool Get(const ObjectBase *object, AttributeValue &attribute) const override
Definition: attribute.cc:135
bool Set(ObjectBase *object, const AttributeValue &value) const override
Definition: attribute.cc:128
~EmptyAttributeAccessor() override
Definition: attribute.cc:123
bool HasSetter() const override
Definition: attribute.cc:148
bool HasGetter() const override
Definition: attribute.cc:142
A checker for EmptyAttributeValue.
Definition: attribute.h:310
std::string GetValueTypeName() const override
Definition: attribute.cc:169
bool Check(const AttributeValue &value) const override
Definition: attribute.cc:163
Ptr< AttributeValue > Create() const override
Definition: attribute.cc:187
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
Definition: attribute.cc:194
bool HasUnderlyingTypeInformation() const override
Definition: attribute.cc:175
~EmptyAttributeChecker() override
Definition: attribute.cc:158
std::string GetUnderlyingTypeInformation() const override
Definition: attribute.cc:181
A class for an empty attribute value.
Definition: attribute.h:242
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition: attribute.cc:105
EmptyAttributeValue()
Default constructor.
Definition: attribute.cc:92
Ptr< AttributeValue > Copy() const override
Definition: attribute.cc:98
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition: attribute.cc:112
Anchor the ns-3 type and attribute system.
Definition: object-base.h:173
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template-based reference counting class.
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
Definition: attribute.h:330
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
Definition: attribute.h:296
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.
ns3::SimpleRefCount declaration and template implementation.