A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
integer.cc
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
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275