A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
25 NS_LOG_COMPONENT_DEFINE ("Uinteger");
26 
27 namespace ns3 {
28 
29 ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (uint64_t,Uinteger);
30 
31 namespace internal {
32 
33 Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max, std::string name)
34 {
35  NS_LOG_FUNCTION (min << max << name);
36  struct Checker : public AttributeChecker
37  {
38  Checker (uint64_t minValue, uint64_t maxValue, std::string name)
39  : m_minValue (minValue),
40  m_maxValue (maxValue),
41  m_name (name) {}
42  virtual bool Check (const AttributeValue &value) const {
43  NS_LOG_FUNCTION (&value);
44  const UintegerValue *v = dynamic_cast<const UintegerValue *> (&value);
45  if (v == 0)
46  {
47  return false;
48  }
49  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
50  }
51  virtual std::string GetValueTypeName (void) const {
53  return "ns3::UintegerValue";
54  }
55  virtual bool HasUnderlyingTypeInformation (void) const {
57  return true;
58  }
59  virtual std::string GetUnderlyingTypeInformation (void) const {
61  std::ostringstream oss;
62  oss << m_name << " " << m_minValue << ":" << m_maxValue;
63  return oss.str ();
64  }
65  virtual Ptr<AttributeValue> Create (void) const {
67  return ns3::Create<UintegerValue> ();
68  }
69  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
70  NS_LOG_FUNCTION (&source << &destination);
71  const UintegerValue *src = dynamic_cast<const UintegerValue *> (&source);
72  UintegerValue *dst = dynamic_cast<UintegerValue *> (&destination);
73  if (src == 0 || dst == 0)
74  {
75  return false;
76  }
77  *dst = *src;
78  return true;
79  }
80  uint64_t m_minValue;
81  uint64_t m_maxValue;
82  std::string m_name;
83  } *checker = new Checker (min, max, name);
84  return Ptr<const AttributeChecker> (checker, false);
85 }
86 
87 } // namespace internal
88 
89 } // namespace ns3
Represent the type of an attribute.
Definition: attribute.h:154
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a value for an Attribute.
Definition: attribute.h:56
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< const AttributeChecker > MakeUintegerChecker(uint64_t min, uint64_t max, std::string name)
Definition: uinteger.cc:33
uint64_t Get(void) const
Ptr< T > Create(void)
Definition: ptr.h:232
Hold an unsigned integer type.
Definition: uinteger.h:46
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(double, Double)
Ptr< T > Copy(Ptr< T > object)
Definition: ptr.h:388