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 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("Uinteger");
34 
36 
37 namespace internal {
38 
48 Ptr<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  virtual bool Check (const AttributeValue &value) const {
58  NS_LOG_FUNCTION (&value);
59  const UintegerValue *v = dynamic_cast<const UintegerValue *> (&value);
60  if (v == 0)
61  {
62  return false;
63  }
64  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
65  }
66  virtual std::string GetValueTypeName (void) const {
68  return "ns3::UintegerValue";
69  }
70  virtual bool HasUnderlyingTypeInformation (void) const {
72  return true;
73  }
74  virtual std::string GetUnderlyingTypeInformation (void) const {
76  std::ostringstream oss;
77  oss << m_name << " " << m_minValue << ":" << m_maxValue;
78  return oss.str ();
79  }
80  virtual Ptr<AttributeValue> Create (void) const {
82  return ns3::Create<UintegerValue> ();
83  }
84  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
85  NS_LOG_FUNCTION (&source << &destination);
86  const UintegerValue *src = dynamic_cast<const UintegerValue *> (&source);
87  UintegerValue *dst = dynamic_cast<UintegerValue *> (&destination);
88  if (src == 0 || dst == 0)
89  {
90  return false;
91  }
92  *dst = *src;
93  return true;
94  }
95  uint64_t m_minValue;
96  uint64_t m_maxValue;
97  std::string m_name;
98  } *checker = new Checker (min, max, name);
99  return Ptr<const AttributeChecker> (checker, false);
100 }
101 
102 } // namespace internal
103 
104 } // namespace ns3
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
Represent the type of an attribute.
Definition: attribute.h:166
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define min(a, b)
Definition: 80211b.c:44
Hold a value for an Attribute.
Definition: attribute.h:68
Unsigned integer attribute value declarations and template implementations.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint64_t Get(void) const
Definition: uinteger.cc:35
#define max(a, b)
Definition: 80211b.c:45
Hold an unsigned integer type.
Definition: uinteger.h:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Definition: ptr.h:514
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class Value of the underlying class t...
Debug message logging.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:686