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
double.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 "
double.h
"
9
10
#include "
log.h
"
11
#include "
object.h
"
12
13
#include <sstream>
14
15
/**
16
* @file
17
* @ingroup attribute_Double
18
* ns3::DoubleValue attribute value implementation.
19
*/
20
21
namespace
ns3
22
{
23
24
NS_LOG_COMPONENT_DEFINE
(
"Double"
);
25
26
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
(
double
, Double);
27
28
/** Namespace for implementation details. */
29
namespace
internal
30
{
31
32
/**
33
* @ingroup attribute_Double
34
* Make a Double attribute checker with embedded numeric type name.
35
*
36
* @param [in] min The minimum allowed value.
37
* @param [in] max The maximum allowed value.
38
* @param [in] name The original type name ("float", "double").
39
* @returns The AttributeChecker.
40
*/
41
Ptr<const AttributeChecker>
42
MakeDoubleChecker
(
double
min,
double
max, std::string name)
43
{
44
NS_LOG_FUNCTION
(min << max << name);
45
46
struct
Checker :
public
AttributeChecker
47
{
48
Checker(
double
minValue,
double
maxValue, std::string name)
49
: m_minValue(minValue),
50
m_maxValue(maxValue),
51
m_name(name)
52
{
53
}
54
55
bool
Check(
const
AttributeValue
& value)
const override
56
{
57
NS_LOG_FUNCTION
(&value);
58
const
auto
v =
dynamic_cast<
const
DoubleValue
*
>
(&value);
59
if
(v ==
nullptr
)
60
{
61
return
false
;
62
}
63
return
v->
Get
() >= m_minValue && v->Get() <= m_maxValue;
64
}
65
66
std::string GetValueTypeName()
const override
67
{
68
NS_LOG_FUNCTION_NOARGS
();
69
return
"ns3::DoubleValue"
;
70
}
71
72
bool
HasUnderlyingTypeInformation()
const override
73
{
74
NS_LOG_FUNCTION_NOARGS
();
75
return
true
;
76
}
77
78
std::string GetUnderlyingTypeInformation()
const override
79
{
80
NS_LOG_FUNCTION_NOARGS
();
81
std::ostringstream oss;
82
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
83
return
oss.str();
84
}
85
86
Ptr<AttributeValue>
Create
()
const override
87
{
88
NS_LOG_FUNCTION_NOARGS
();
89
return
ns3::Create<DoubleValue>
();
90
}
91
92
bool
Copy
(
const
AttributeValue
& source,
AttributeValue
& destination)
const override
93
{
94
NS_LOG_FUNCTION
(&source << &destination);
95
const
auto
src =
dynamic_cast<
const
DoubleValue
*
>
(&source);
96
auto
dst =
dynamic_cast<
DoubleValue
*
>
(&destination);
97
if
(src ==
nullptr
|| dst ==
nullptr
)
98
{
99
return
false
;
100
}
101
*dst = *src;
102
return
true
;
103
}
104
105
double
m_minValue;
106
double
m_maxValue;
107
std::string m_name;
108
}* checker =
new
Checker(min, max, name);
109
110
return
Ptr<const AttributeChecker>
(checker,
false
);
111
}
112
113
}
// namespace internal
114
115
}
// 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::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::DoubleValue::Get
double Get() const
Definition
double.cc:26
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
double.h
ns3::DoubleValue attribute value declarations and template implementations.
ns3::MakeDoubleChecker
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition
double.h:82
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
object.h
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
src
core
model
double.cc
Generated on Fri Dec 13 2024 18:20:37 for ns-3 by
1.11.0