A Discrete-Event Network Simulator
API
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 
35 namespace ns3
36 {
37 
38 class AttributeAccessor;
39 class AttributeChecker;
40 class Attribute;
41 class ObjectBase;
42 
69 class 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 
115 class 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 
167 class 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 
234 {
235  public:
238 
239  private:
243  Ptr<AttributeValue> Copy() const override;
250  std::string SerializeToString(Ptr<const AttributeChecker> checker) const override;
259  bool DeserializeFromString(std::string value, Ptr<const AttributeChecker> checker) override;
260 };
261 
268 {
269  public:
271  ~EmptyAttributeAccessor() override;
272  bool Set(ObjectBase* object, const AttributeValue& value) const override;
273  bool Get(const ObjectBase* object, AttributeValue& attribute) const override;
274  bool HasGetter() const override;
275  bool HasSetter() const override;
276 };
277 
285 static inline Ptr<const AttributeAccessor>
287 {
289 }
290 
298 {
299  public:
301  ~EmptyAttributeChecker() override;
302  bool Check(const AttributeValue& value) const override;
303  std::string GetValueTypeName() const override;
304  bool HasUnderlyingTypeInformation() const override;
305  std::string GetUnderlyingTypeInformation() const override;
306  Ptr<AttributeValue> Create() const override;
307  bool Copy(const AttributeValue& source, AttributeValue& destination) const override;
308 };
309 
317 static inline Ptr<AttributeChecker>
319 {
320  return Ptr<AttributeChecker>(new EmptyAttributeChecker(), false);
321 }
322 
323 } // namespace ns3
324 
325 #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:268
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:298
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:234
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:318
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
Definition: attribute.h:286
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.