A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
uinteger.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 "
uinteger.h
"
9
10
#include "
fatal-error.h
"
11
#include "
log.h
"
12
13
#include <sstream>
14
15
/**
16
* \file
17
* \ingroup attribute_Uinteger
18
* ns3::UintegerValue attribute value implementations.
19
*/
20
21
namespace
ns3
22
{
23
24
NS_LOG_COMPONENT_DEFINE
(
"Uinteger"
);
25
26
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
(uint64_t, Uinteger);
27
28
namespace
internal
29
{
30
31
/**
32
* \ingroup attribute_Uinteger
33
* Make an Uinteger attribute checker with embedded numeric type name.
34
*
35
* \param [in] min The minimum allowed value.
36
* \param [in] max The maximum allowed value.
37
* \param [in] name The original type name ("uint8_t", "uint16_t", _etc_.).
38
* \returns The AttributeChecker.
39
*/
40
Ptr<const AttributeChecker>
41
MakeUintegerChecker
(uint64_t min, uint64_t max, std::string name)
42
{
43
NS_LOG_FUNCTION
(min << max << name);
44
45
struct
Checker :
public
AttributeChecker
46
{
47
Checker(uint64_t minValue, uint64_t maxValue, std::string name)
48
: m_minValue(minValue),
49
m_maxValue(maxValue),
50
m_name(name)
51
{
52
}
53
54
bool
Check(
const
AttributeValue
& value)
const override
55
{
56
NS_LOG_FUNCTION
(&value);
57
const
auto
v =
dynamic_cast<
const
UintegerValue
*
>
(&value);
58
if
(v ==
nullptr
)
59
{
60
return
false
;
61
}
62
return
v->
Get
() >= m_minValue && v->Get() <= m_maxValue;
63
}
64
65
std::string GetValueTypeName()
const override
66
{
67
NS_LOG_FUNCTION_NOARGS
();
68
return
"ns3::UintegerValue"
;
69
}
70
71
bool
HasUnderlyingTypeInformation()
const override
72
{
73
NS_LOG_FUNCTION_NOARGS
();
74
return
true
;
75
}
76
77
std::string GetUnderlyingTypeInformation()
const override
78
{
79
NS_LOG_FUNCTION_NOARGS
();
80
std::ostringstream oss;
81
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
82
return
oss.str();
83
}
84
85
Ptr<AttributeValue>
Create
()
const override
86
{
87
NS_LOG_FUNCTION_NOARGS
();
88
return
ns3::Create<UintegerValue>
();
89
}
90
91
bool
Copy
(
const
AttributeValue
& source,
AttributeValue
& destination)
const override
92
{
93
NS_LOG_FUNCTION
(&source << &destination);
94
const
auto
src =
dynamic_cast<
const
UintegerValue
*
>
(&source);
95
auto
dst =
dynamic_cast<
UintegerValue
*
>
(&destination);
96
if
(src ==
nullptr
|| dst ==
nullptr
)
97
{
98
return
false
;
99
}
100
*dst = *src;
101
return
true
;
102
}
103
104
uint64_t m_minValue;
105
uint64_t m_maxValue;
106
std::string m_name;
107
}* checker =
new
Checker(min, max, name);
108
109
return
Ptr<const AttributeChecker>
(checker,
false
);
110
}
111
112
}
// namespace internal
113
114
}
// namespace ns3
ns3::AttributeChecker
Represent the type of an attribute.
Definition
attribute.h:157
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
ns3::UintegerValue::Get
uint64_t Get() const
Definition
uinteger.cc:26
fatal-error.h
NS_FATAL_x macro definitions.
ns3::MakeUintegerChecker
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition
uinteger.h:85
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
Definition
attribute-helper.h:283
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition
log-macros-enabled.h:195
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
log.h
Debug message logging.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Copy
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition
ptr.h:604
uinteger.h
ns3::UintegerValue attribute value declarations and template implementations.
src
core
model
uinteger.cc
Generated on Wed Oct 9 2024 01:03:23 for ns-3 by
1.11.0