A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
double.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 "double.h"
21 #include "object.h"
22 #include "log.h"
23 #include <sstream>
24 
25 NS_LOG_COMPONENT_DEFINE ("Double");
26 
27 namespace ns3 {
28 
30 
31 namespace internal {
32 
33 Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max, std::string name)
34 {
35  NS_LOG_FUNCTION (min << max << name);
36 
37  struct Checker : public AttributeChecker
38  {
39  Checker (double minValue, double 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 DoubleValue *v = dynamic_cast<const DoubleValue *> (&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::DoubleValue";
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<DoubleValue> ();
69  }
70  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
71  NS_LOG_FUNCTION (&source << &destination);
72  const DoubleValue *src = dynamic_cast<const DoubleValue *> (&source);
73  DoubleValue *dst = dynamic_cast<DoubleValue *> (&destination);
74  if (src == 0 || dst == 0)
75  {
76  return false;
77  }
78  *dst = *src;
79  return true;
80  }
81  double m_minValue;
82  double m_maxValue;
83  std::string m_name;
84  } *checker = new Checker (min, max, name);
85  return Ptr<const 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
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
Ptr< T > Create(void)
Definition: ptr.h:231
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(double, Double)
double Get(void) const
Hold a floating point type.
Definition: double.h:41
Ptr< const AttributeChecker > MakeDoubleChecker(double min, double max, std::string name)
Definition: double.cc:33
NS_LOG_COMPONENT_DEFINE("Double")
Ptr< T > Copy(Ptr< T > object)
Definition: ptr.h:387