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  {}
59  virtual bool Check (const AttributeValue &value) const
60  {
61  NS_LOG_FUNCTION (&value);
62  const IntegerValue *v = dynamic_cast<const IntegerValue *> (&value);
63  if (v == 0)
64  {
65  return false;
66  }
67  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
68  }
69  virtual std::string GetValueTypeName (void) const
70  {
72  return "ns3::IntegerValue";
73  }
74  virtual bool HasUnderlyingTypeInformation (void) const
75  {
77  return true;
78  }
79  virtual std::string GetUnderlyingTypeInformation (void) const
80  {
82  std::ostringstream oss;
83  oss << m_name << " " << m_minValue << ":" << m_maxValue;
84  return oss.str ();
85  }
86  virtual Ptr<AttributeValue> Create (void) const
87  {
89  return ns3::Create<IntegerValue> ();
90  }
91  virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const
92  {
93  NS_LOG_FUNCTION (&src << &dst);
94  const IntegerValue *source = dynamic_cast<const IntegerValue *> (&src);
95  IntegerValue *destination = dynamic_cast<IntegerValue *> (&dst);
96  if (source == 0 || destination == 0)
97  {
98  return false;
99  }
100  *destination = *source;
101  return true;
102  }
103  int64_t m_minValue;
104  int64_t m_maxValue;
105  std::string m_name;
106  } *checker = new IntegerChecker (min, max, name);
107  return Ptr<AttributeChecker> (checker, false);
108 }
109 
110 } // namespace internal
111 
112 } // 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
AttributeChecker implementation for IntegerValue.
Hold a signed integer type.
Definition: integer.h:44
int64_t Get(void) const
Definition: integer.cc:35
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
NS_FATAL_x macro definitions.
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
#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
ns3::IntegerValue attribute value declarations and template implementations.
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