A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
virtual
bool
Check (
const
AttributeValue
&value)
const
{
59
NS_LOG_FUNCTION
(&value);
60
const
IntegerValue
*v =
dynamic_cast<
const
IntegerValue
*
>
(&value);
61
if
(v == 0)
62
{
63
return
false
;
64
}
65
return
v->
Get
() >= m_minValue && v->
Get
() <= m_maxValue;
66
}
67
virtual
std::string GetValueTypeName (
void
)
const
{
68
NS_LOG_FUNCTION_NOARGS
();
69
return
"ns3::IntegerValue"
;
70
}
71
virtual
bool
HasUnderlyingTypeInformation (
void
)
const
{
72
NS_LOG_FUNCTION_NOARGS
();
73
return
true
;
74
}
75
virtual
std::string GetUnderlyingTypeInformation (
void
)
const
{
76
NS_LOG_FUNCTION_NOARGS
();
77
std::ostringstream oss;
78
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
79
return
oss.str ();
80
}
81
virtual
Ptr<AttributeValue>
Create
(
void
)
const
{
82
NS_LOG_FUNCTION_NOARGS
();
83
return
ns3::Create<IntegerValue> ();
84
}
85
virtual
bool
Copy
(
const
AttributeValue
&src,
AttributeValue
&dst)
const
{
86
NS_LOG_FUNCTION
(&src << &dst);
87
const
IntegerValue
*source =
dynamic_cast<
const
IntegerValue
*
>
(&src);
88
IntegerValue
*destination =
dynamic_cast<
IntegerValue
*
>
(&dst);
89
if
(source == 0 || destination == 0)
90
{
91
return
false
;
92
}
93
*destination = *source;
94
return
true
;
95
}
96
int64_t m_minValue;
97
int64_t m_maxValue;
98
std::string m_name;
99
} *checker =
new
IntegerChecker
(min, max, name);
100
return
Ptr<AttributeChecker>
(checker,
false
);
101
}
102
103
}
// namespace internal
104
105
}
// namespace ns3
fatal-error.h
NS_FATAL_x macro definitions.
ns3::AttributeChecker
Represent the type of an attribute.
Definition:
attribute.h:166
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
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:213
min
#define min(a, b)
Definition:
80211b.c:44
ns3::AttributeValue
Hold a value for an Attribute.
Definition:
attribute.h:68
ns3::IntegerValue
Hold a signed integer type.
Definition:
integer.h:44
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:176
ns3::IntegerValue::Get
int64_t Get(void) const
Definition:
integer.cc:35
max
#define max(a, b)
Definition:
80211b.c:45
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::Create
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Definition:
ptr.h:514
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class <name>Value of the underlying class t...
Definition:
attribute-helper.h:273
integer.h
Integer attribute value declarations and template implementations.
ns3::IntegerChecker
AttributeChecker implementation for IntegerValue.
log.h
Debug message logging.
ns3::Copy
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition:
ptr.h:686
src
core
model
integer.cc
Generated on Wed Jul 6 2016 17:11:26 for ns-3 by
1.8.6