A Discrete-Event Network Simulator
API
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 
36 
37 namespace internal {
38 
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 {
69  return "ns3::IntegerValue";
70  }
71  virtual bool HasUnderlyingTypeInformation (void) const {
73  return true;
74  }
75  virtual std::string GetUnderlyingTypeInformation (void) const {
77  std::ostringstream oss;
78  oss << m_name << " " << m_minValue << ":" << m_maxValue;
79  return oss.str ();
80  }
81  virtual Ptr<AttributeValue> Create (void) const {
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
NS_FATAL_x macro definitions.
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 "...
Hold a value for an Attribute.
Definition: attribute.h:68
Hold a signed integer type.
Definition: integer.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Definition: ptr.h:516
double max(double x, double y)
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
ns3::IntegerValue attribute value declarations and template implementations.
double min(double x, double y)
AttributeChecker implementation for IntegerValue.
Debug message logging.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:688
int64_t Get(void) const
Definition: integer.cc:35