A Discrete-Event Network Simulator
API
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 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("Double");
34 
36 
38 namespace internal {
39 
49 Ptr<const AttributeChecker> MakeDoubleChecker (double min, double max, std::string name)
50 {
51  NS_LOG_FUNCTION (min << max << name);
52 
53  struct Checker : public AttributeChecker
54  {
55  Checker (double minValue, double maxValue, std::string name)
56  : m_minValue (minValue),
57  m_maxValue (maxValue),
58  m_name (name) {}
59  virtual bool Check (const AttributeValue &value) const {
60  NS_LOG_FUNCTION (&value);
61  const DoubleValue *v = dynamic_cast<const DoubleValue *> (&value);
62  if (v == 0)
63  {
64  return false;
65  }
66  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
67  }
68  virtual std::string GetValueTypeName (void) const {
70  return "ns3::DoubleValue";
71  }
72  virtual bool HasUnderlyingTypeInformation (void) const {
74  return true;
75  }
76  virtual std::string GetUnderlyingTypeInformation (void) const {
78  std::ostringstream oss;
79  oss << m_name << " " << m_minValue << ":" << m_maxValue;
80  return oss.str ();
81  }
82  virtual Ptr<AttributeValue> Create (void) const {
84  return ns3::Create<DoubleValue> ();
85  }
86  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
87  NS_LOG_FUNCTION (&source << &destination);
88  const DoubleValue *src = dynamic_cast<const DoubleValue *> (&source);
89  DoubleValue *dst = dynamic_cast<DoubleValue *> (&destination);
90  if (src == 0 || dst == 0)
91  {
92  return false;
93  }
94  *dst = *src;
95  return true;
96  }
97  double m_minValue;
98  double m_maxValue;
99  std::string m_name;
100  } *checker = new Checker (min, max, name);
101  return Ptr<const AttributeChecker> (checker, false);
102 }
103 
104 } // namespace internal
105 
106 } // namespace ns3
ns3::DoubleValue attribute value declarations and template implementations.
Represent the type of an attribute.
Definition: attribute.h:166
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define min(a, b)
Definition: 80211b.c:42
Hold a value for an Attribute.
Definition: attribute.h:68
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define max(a, b)
Definition: 80211b.c:43
double Get(void) const
Definition: double.cc:35
Ptr< const AttributeChecker > MakeDoubleChecker(double min, double max, std::string name)
Make a Double attribute checker with embedded numeric type name.
Definition: double.cc:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Definition: ptr.h:516
void(* Double)(double oldValue, double newValue)
TracedValue Callback signature for POD.
Definition: traced-value.h:89
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
Debug message logging.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:688