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 <sstream>
23 
24 namespace ns3 {
25 
26 ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (uint64_t,Uinteger);
27 
28 namespace internal {
29 
30 Ptr<const AttributeChecker> MakeUintegerChecker (uint64_t min, uint64_t max, std::string name)
31 {
32  struct Checker : public AttributeChecker
33  {
34  Checker (uint64_t minValue, uint64_t maxValue, std::string name)
35  : m_minValue (minValue),
36  m_maxValue (maxValue),
37  m_name (name) {}
38  virtual bool Check (const AttributeValue &value) const {
39  const UintegerValue *v = dynamic_cast<const UintegerValue *> (&value);
40  if (v == 0)
41  {
42  return false;
43  }
44  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
45  }
46  virtual std::string GetValueTypeName (void) const {
47  return "ns3::UintegerValue";
48  }
49  virtual bool HasUnderlyingTypeInformation (void) const {
50  return true;
51  }
52  virtual std::string GetUnderlyingTypeInformation (void) const {
53  std::ostringstream oss;
54  oss << m_name << " " << m_minValue << ":" << m_maxValue;
55  return oss.str ();
56  }
57  virtual Ptr<AttributeValue> Create (void) const {
58  return ns3::Create<UintegerValue> ();
59  }
60  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
61  const UintegerValue *src = dynamic_cast<const UintegerValue *> (&source);
62  UintegerValue *dst = dynamic_cast<UintegerValue *> (&destination);
63  if (src == 0 || dst == 0)
64  {
65  return false;
66  }
67  *dst = *src;
68  return true;
69  }
70  uint64_t m_minValue;
71  uint64_t m_maxValue;
72  std::string m_name;
73  } *checker = new Checker (min, max, name);
74  return Ptr<const AttributeChecker> (checker, false);
75 }
76 
77 } // namespace internal
78 
79 } // namespace ns3