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
integer.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 "
integer.h
"
9
10
#include "
log.h
"
11
12
#include <sstream>
13
14
/**
15
* @file
16
* @ingroup attribute_Integer
17
* ns3::MakeIntegerChecker implementation.
18
*/
19
20
namespace
ns3
21
{
22
23
NS_LOG_COMPONENT_DEFINE
(
"Integer"
);
24
25
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
(int64_t, Integer);
26
27
namespace
internal
28
{
29
30
/**
31
* @ingroup attribute_Integer
32
* Make an Integer attribute checker with embedded numeric type name.
33
*
34
* @param [in] min The minimum allowed value.
35
* @param [in] max The maximum allowed value.
36
* @param [in] name The original type name ("int8_t", "int16_t", _etc_.).
37
* @returns The AttributeChecker.
38
*/
39
Ptr<const AttributeChecker>
40
MakeIntegerChecker
(int64_t min, int64_t max, std::string name)
41
{
42
NS_LOG_FUNCTION
(min << max << name);
43
44
struct
IntegerChecker
:
public
AttributeChecker
45
{
46
IntegerChecker
(int64_t minValue, int64_t maxValue, std::string name)
47
: m_minValue(minValue),
48
m_maxValue(maxValue),
49
m_name(name)
50
{
51
}
52
53
bool
Check(
const
AttributeValue
& value)
const override
54
{
55
NS_LOG_FUNCTION
(&value);
56
const
auto
v
=
dynamic_cast<
const
IntegerValue
*
>
(&value);
57
if
(
v
==
nullptr
)
58
{
59
return
false
;
60
}
61
return
v
->Get() >= m_minValue &&
v
->Get() <= m_maxValue;
62
}
63
64
std::string GetValueTypeName()
const override
65
{
66
NS_LOG_FUNCTION_NOARGS
();
67
return
"ns3::IntegerValue"
;
68
}
69
70
bool
HasUnderlyingTypeInformation()
const override
71
{
72
NS_LOG_FUNCTION_NOARGS
();
73
return
true
;
74
}
75
76
std::string GetUnderlyingTypeInformation()
const override
77
{
78
NS_LOG_FUNCTION_NOARGS
();
79
std::ostringstream oss;
80
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
81
return
oss.str();
82
}
83
84
Ptr<AttributeValue>
Create
()
const override
85
{
86
NS_LOG_FUNCTION_NOARGS
();
87
return
ns3::Create<IntegerValue>
();
88
}
89
90
bool
Copy
(
const
AttributeValue
& src,
AttributeValue
& dst)
const override
91
{
92
NS_LOG_FUNCTION
(&src << &dst);
93
const
auto
source =
dynamic_cast<
const
IntegerValue
*
>
(&src);
94
auto
destination =
dynamic_cast<
IntegerValue
*
>
(&dst);
95
if
(source ==
nullptr
|| destination ==
nullptr
)
96
{
97
return
false
;
98
}
99
*destination = *source;
100
return
true
;
101
}
102
103
int64_t m_minValue;
104
int64_t m_maxValue;
105
std::string m_name;
106
}* checker =
new
IntegerChecker
(min, max, name);
107
108
return
Ptr<AttributeChecker>
(checker,
false
);
109
}
110
111
}
// namespace internal
112
113
}
// namespace ns3
v
uint32_t v
Definition
cairo-wideint.c:749
ns3::AttributeChecker
Represent the type of an attribute.
Definition
attribute.h:157
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
IntegerChecker
AttributeChecker implementation for IntegerValue.
ns3::IntegerValue
Hold a signed integer type.
Definition
integer.h:34
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
ns3::MakeIntegerChecker
Ptr< const AttributeChecker > MakeIntegerChecker()
Definition
integer.h:99
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:194
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:231
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:454
integer.h
ns3::IntegerValue attribute value declarations and template implementations.
log.h
Debug message logging.
ns3::internal
Namespace for implementation details.
Definition
attribute-container.h:300
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:629
src
core
model
integer.cc
Generated on
for ns-3 by
1.15.0