A Discrete-Event Network Simulator
API
uinteger.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 "uinteger.h"
21#include "fatal-error.h"
22#include "log.h"
23#include <sstream>
24
31namespace ns3 {
32
33NS_LOG_COMPONENT_DEFINE ("Uinteger");
34
36
37namespace internal {
38
48Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max, std::string name)
49{
50 NS_LOG_FUNCTION (min << max << name);
51 struct Checker : public AttributeChecker
52 {
53 Checker (uint64_t minValue, uint64_t maxValue, std::string name)
54 : m_minValue (minValue),
55 m_maxValue (maxValue),
56 m_name (name)
57 {}
58 virtual bool Check (const AttributeValue &value) const
59 {
60 NS_LOG_FUNCTION (&value);
61 const UintegerValue *v = dynamic_cast<const UintegerValue *> (&value);
62 if (v == 0)
63 {
64 return false;
65 }
66 return v->Get () >= m_minValue && v->Get () <= m_maxValue;
67 }
68 virtual std::string GetValueTypeName (void) const
69 {
71 return "ns3::UintegerValue";
72 }
73 virtual bool HasUnderlyingTypeInformation (void) const
74 {
76 return true;
77 }
78 virtual std::string GetUnderlyingTypeInformation (void) const
79 {
81 std::ostringstream oss;
82 oss << m_name << " " << m_minValue << ":" << m_maxValue;
83 return oss.str ();
84 }
85 virtual Ptr<AttributeValue> Create (void) const
86 {
88 return ns3::Create<UintegerValue> ();
89 }
90 virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const
91 {
92 NS_LOG_FUNCTION (&source << &destination);
93 const UintegerValue *src = dynamic_cast<const UintegerValue *> (&source);
94 UintegerValue *dst = dynamic_cast<UintegerValue *> (&destination);
95 if (src == 0 || dst == 0)
96 {
97 return false;
98 }
99 *dst = *src;
100 return true;
101 }
102 uint64_t m_minValue;
103 uint64_t m_maxValue;
104 std::string m_name;
105 } *checker = new Checker (min, max, name);
106 return Ptr<const AttributeChecker> (checker, false);
107}
108
109} // namespace internal
110
111} // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Represent the type of an attribute.
Definition: attribute.h:167
Hold a value for an Attribute.
Definition: attribute.h:69
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Hold an unsigned integer type.
Definition: uinteger.h:44
uint64_t Get(void) const
Definition: uinteger.cc:35
NS_FATAL_x macro definitions.
Ptr< const AttributeChecker > MakeUintegerChecker(uint64_t min, uint64_t max, std::string name)
Make an Uinteger attribute checker with embedded numeric type name.
Definition: uinteger.cc:48
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition: ptr.h:409
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:555
ns3::UintegerValue attribute value declarations and template implementations.