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