A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
integer.cc
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
#include "
integer.h
"
21
#include "
fatal-error.h
"
22
#include "
log.h
"
23
#include <sstream>
24
31
namespace
ns3
{
32
33
NS_LOG_COMPONENT_DEFINE
(
"Integer"
);
34
35
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
(int64_t, Integer);
36
37
namespace
internal {
38
48
Ptr<const AttributeChecker>
49
MakeIntegerChecker
(int64_t
min
, int64_t
max
, std::string name)
50
{
51
NS_LOG_FUNCTION
(
min
<<
max
<< name);
52
struct
IntegerChecker
:
public
AttributeChecker
53
{
54
IntegerChecker
(int64_t minValue, int64_t maxValue, std::string name)
55
: m_minValue (minValue),
56
m_maxValue (maxValue),
57
m_name (name)
58
{}
59
virtual
bool
Check (
const
AttributeValue
&value)
const
60
{
61
NS_LOG_FUNCTION
(&value);
62
const
IntegerValue
*v =
dynamic_cast<
const
IntegerValue
*
>
(&value);
63
if
(v == 0)
64
{
65
return
false
;
66
}
67
return
v->
Get
() >= m_minValue && v->
Get
() <= m_maxValue;
68
}
69
virtual
std::string GetValueTypeName (
void
)
const
70
{
71
NS_LOG_FUNCTION_NOARGS
();
72
return
"ns3::IntegerValue"
;
73
}
74
virtual
bool
HasUnderlyingTypeInformation (
void
)
const
75
{
76
NS_LOG_FUNCTION_NOARGS
();
77
return
true
;
78
}
79
virtual
std::string GetUnderlyingTypeInformation (
void
)
const
80
{
81
NS_LOG_FUNCTION_NOARGS
();
82
std::ostringstream oss;
83
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
84
return
oss.str ();
85
}
86
virtual
Ptr<AttributeValue>
Create
(
void
)
const
87
{
88
NS_LOG_FUNCTION_NOARGS
();
89
return
ns3::Create<IntegerValue> ();
90
}
91
virtual
bool
Copy
(
const
AttributeValue
&src,
AttributeValue
&dst)
const
92
{
93
NS_LOG_FUNCTION
(&src << &dst);
94
const
IntegerValue
*source =
dynamic_cast<
const
IntegerValue
*
>
(&src);
95
IntegerValue
*destination =
dynamic_cast<
IntegerValue
*
>
(&dst);
96
if
(source == 0 || destination == 0)
97
{
98
return
false
;
99
}
100
*destination = *source;
101
return
true
;
102
}
103
int64_t m_minValue;
104
int64_t m_maxValue;
105
std::string m_name;
106
} *checker =
new
IntegerChecker
(
min
,
max
, name);
107
return
Ptr<AttributeChecker>
(checker,
false
);
108
}
109
110
}
// namespace internal
111
112
}
// namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
fatal-error.h
NS_FATAL_x macro definitions.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IntegerChecker
AttributeChecker implementation for IntegerValue.
ns3::IntegerValue
Hold a signed integer type.
Definition:
integer.h:44
ns3::internal::MakeIntegerChecker
Ptr< const AttributeChecker > MakeIntegerChecker(int64_t min, int64_t max, std::string name)
Make an Integer attribute checker with embedded numeric type name.
Definition:
integer.cc:49
ns3::AttributeValue
Hold a value for an Attribute.
Definition:
attribute.h:69
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:409
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
ns3::min
double min(double x, double y)
Definition:
cobalt-queue-disc.cc:132
ns3::AttributeChecker
Represent the type of an attribute.
Definition:
attribute.h:167
ns3::Copy
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition:
ptr.h:555
ns3::IntegerValue::Get
int64_t Get(void) const
Definition:
integer.cc:35
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:209
log.h
Debug message logging.
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:244
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
ns3::max
double max(double x, double y)
Definition:
cobalt-queue-disc.cc:137
integer.h
ns3::IntegerValue attribute value declarations and template implementations.
src
core
model
integer.cc
Generated on Fri Oct 1 2021 17:02:57 for ns-3 by
1.8.20