A Discrete-Event Network Simulator
API
attribute.h
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 #ifndef ATTRIBUTE_H
21 #define ATTRIBUTE_H
22 
23 #include <string>
24 #include <stdint.h>
25 #include "ptr.h"
26 #include "simple-ref-count.h"
27 
35 namespace ns3 {
36 
37 class AttributeAccessor;
38 class AttributeChecker;
39 class Attribute;
40 class ObjectBase;
41 
68 class AttributeValue : public SimpleRefCount<AttributeValue>
69 {
70 public:
71  AttributeValue ();
72  virtual ~AttributeValue ();
73 
77  virtual Ptr<AttributeValue> Copy (void) const = 0;
87  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const = 0;
101  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker) = 0;
102 };
103 
114 class AttributeAccessor : public SimpleRefCount<AttributeAccessor>
115 {
116 public:
118  virtual ~AttributeAccessor ();
119 
128  virtual bool Set (ObjectBase * object, const AttributeValue &value) const = 0;
138  virtual bool Get (const ObjectBase * object, AttributeValue &attribute) const = 0;
139 
144  virtual bool HasGetter (void) const = 0;
149  virtual bool HasSetter (void) const = 0;
150 };
151 
166 class AttributeChecker : public SimpleRefCount<AttributeChecker>
167 {
168 public:
169  AttributeChecker ();
170  virtual ~AttributeChecker ();
171 
186  virtual bool Check (const AttributeValue &value) const = 0;
195  virtual std::string GetValueTypeName (void) const = 0;
203  virtual bool HasUnderlyingTypeInformation (void) const = 0;
208  virtual std::string GetUnderlyingTypeInformation (void) const = 0;
216  virtual Ptr<AttributeValue> Create (void) const = 0;
224  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const = 0;
225 };
226 
233 {
234 public:
237 private:
241  virtual Ptr<AttributeValue> Copy (void) const;
248  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
257  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
258 };
259 
266 {
267 public:
270  virtual bool Set (ObjectBase * object, const AttributeValue &value) const;
271  virtual bool Get (const ObjectBase * object, AttributeValue &attribute) const;
272  virtual bool HasGetter (void) const;
273  virtual bool HasSetter (void) const;
274 };
275 
283 static inline Ptr<const AttributeAccessor>
285 {
287 }
288 
296 {
297 public:
300  virtual bool Check (const AttributeValue &value) const;
301  virtual std::string GetValueTypeName (void) const;
302  virtual bool HasUnderlyingTypeInformation (void) const;
303  virtual std::string GetUnderlyingTypeInformation (void) const;
304  virtual Ptr<AttributeValue> Create (void) const;
305  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const;
306 };
307 
315 static inline Ptr<AttributeChecker>
317 {
318  return Ptr<AttributeChecker> (new EmptyAttributeChecker (), false);
319 }
320 
321 } // namespace ns3
322 
323 #endif /* ATTRIBUTE_H */
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const =0
Copy the source to the destination.
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
virtual std::string GetValueTypeName(void) const
Definition: attribute.cc:163
ns3::Ptr smart pointer declaration and implementation.
Hold a value for an Attribute.
Definition: attribute.h:68
virtual bool Get(const ObjectBase *object, AttributeValue &attribute) const =0
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
Definition: attribute.cc:120
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: attribute.cc:105
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
Definition: attribute.h:284
virtual bool HasGetter(void) const =0
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
virtual bool HasUnderlyingTypeInformation(void) const =0
virtual bool HasSetter(void) const =0
EmptyAttributeValue()
Default constructor.
Definition: attribute.cc:88
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const
Copy the source to the destination.
Definition: attribute.cc:188
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const =0
A class for an empty attribute value.
Definition: attribute.h:232
virtual ~AttributeAccessor()
Definition: attribute.cc:48
virtual std::string GetValueTypeName(void) const =0
allow setting and getting the value of an attribute.
Definition: attribute.h:114
An accessor for EmptyAttributeValue.
Definition: attribute.h:265
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 bool Set(ObjectBase *object, const AttributeValue &value) const =0
virtual Ptr< AttributeValue > Create(void) const =0
A checker for EmptyAttributeValue.
Definition: attribute.h:295
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 DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)=0
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
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
Definition: attribute.h:316
virtual bool Check(const AttributeValue &value) const =0
virtual std::string GetUnderlyingTypeInformation(void) const =0
A template-based reference counting class.
virtual bool Get(const ObjectBase *object, AttributeValue &attribute) const
Definition: attribute.cc:128
ns3::SimpleRefCount declaration and template implementation.