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 <sstream>
23
24
namespace
ns3 {
25
26
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME
(int64_t, Integer);
27
28
namespace
internal {
29
30
Ptr<const AttributeChecker>
31
MakeIntegerChecker
(int64_t min, int64_t max, std::string name)
32
{
33
struct
IntegerChecker :
public
AttributeChecker
34
{
35
IntegerChecker (int64_t minValue, int64_t maxValue, std::string name)
36
: m_minValue (minValue),
37
m_maxValue (maxValue),
38
m_name (name) {}
39
virtual
bool
Check (
const
AttributeValue
&value)
const
{
40
const
IntegerValue
*v =
dynamic_cast<
const
IntegerValue
*
>
(&value);
41
if
(v == 0)
42
{
43
return
false
;
44
}
45
return
v->
Get
() >= m_minValue && v->
Get
() <= m_maxValue;
46
}
47
virtual
std::string GetValueTypeName (
void
)
const
{
48
return
"ns3::IntegerValue"
;
49
}
50
virtual
bool
HasUnderlyingTypeInformation (
void
)
const
{
51
return
true
;
52
}
53
virtual
std::string GetUnderlyingTypeInformation (
void
)
const
{
54
std::ostringstream oss;
55
oss << m_name <<
" "
<< m_minValue <<
":"
<< m_maxValue;
56
return
oss.str ();
57
}
58
virtual
Ptr<AttributeValue>
Create
(
void
)
const
{
59
return
ns3::Create<IntegerValue> ();
60
}
61
virtual
bool
Copy
(
const
AttributeValue
&src,
AttributeValue
&dst)
const
{
62
const
IntegerValue
*source =
dynamic_cast<
const
IntegerValue
*
>
(&src);
63
IntegerValue
*destination =
dynamic_cast<
IntegerValue
*
>
(&dst);
64
if
(source == 0 || destination == 0)
65
{
66
return
false
;
67
}
68
*destination = *source;
69
return
true
;
70
}
71
int64_t m_minValue;
72
int64_t m_maxValue;
73
std::string m_name;
74
} *checker =
new
IntegerChecker (min, max, name);
75
return
Ptr<AttributeChecker>
(checker,
false
);
76
}
77
78
}
// namespace internal
79
80
}
// namespace ns3
src
core
model
integer.cc
Generated on Tue Oct 9 2012 16:45:34 for ns-3 by
1.8.1.2