A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uinteger.cc
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#include "uinteger.h"
20
21#include "fatal-error.h"
22#include "log.h"
23
24#include <sstream>
25
32namespace ns3
33{
34
35NS_LOG_COMPONENT_DEFINE("Uinteger");
36
38
39namespace internal
40{
41
52MakeUintegerChecker(uint64_t min, uint64_t max, std::string name)
53{
54 NS_LOG_FUNCTION(min << max << name);
55
56 struct Checker : public AttributeChecker
57 {
58 Checker(uint64_t minValue, uint64_t maxValue, std::string name)
59 : m_minValue(minValue),
60 m_maxValue(maxValue),
61 m_name(name)
62 {
63 }
64
65 bool Check(const AttributeValue& value) const override
66 {
67 NS_LOG_FUNCTION(&value);
68 const UintegerValue* v = dynamic_cast<const UintegerValue*>(&value);
69 if (v == nullptr)
70 {
71 return false;
72 }
73 return v->Get() >= m_minValue && v->Get() <= m_maxValue;
74 }
75
76 std::string GetValueTypeName() const override
77 {
79 return "ns3::UintegerValue";
80 }
81
82 bool HasUnderlyingTypeInformation() const override
83 {
85 return true;
86 }
87
88 std::string GetUnderlyingTypeInformation() const override
89 {
91 std::ostringstream oss;
92 oss << m_name << " " << m_minValue << ":" << m_maxValue;
93 return oss.str();
94 }
95
96 Ptr<AttributeValue> Create() const override
97 {
99 return ns3::Create<UintegerValue>();
100 }
101
102 bool Copy(const AttributeValue& source, AttributeValue& destination) const override
103 {
104 NS_LOG_FUNCTION(&source << &destination);
105 const UintegerValue* src = dynamic_cast<const UintegerValue*>(&source);
106 UintegerValue* dst = dynamic_cast<UintegerValue*>(&destination);
107 if (src == nullptr || dst == nullptr)
108 {
109 return false;
110 }
111 *dst = *src;
112 return true;
113 }
114
115 uint64_t m_minValue;
116 uint64_t m_maxValue;
117 std::string m_name;
118 }* checker = new Checker(min, max, name);
119
120 return Ptr<const AttributeChecker>(checker, false);
121}
122
123} // namespace internal
124
125} // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
Represent the type of an attribute.
Definition: attribute.h:168
Hold a value for an Attribute.
Definition: attribute.h:70
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
NS_FATAL_x macro definitions.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition: uinteger.h:96
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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:481
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:649
ns3::UintegerValue attribute value declarations and template implementations.