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  {}
60  virtual bool Check (const AttributeValue &value) const
61  {
62  NS_LOG_FUNCTION (&value);
63  const DoubleValue *v = dynamic_cast<const DoubleValue *> (&value);
64  if (v == 0)
65  {
66  return false;
67  }
68  return v->Get () >= m_minValue && v->Get () <= m_maxValue;
69  }
70  virtual std::string GetValueTypeName (void) const
71  {
73  return "ns3::DoubleValue";
74  }
75  virtual bool HasUnderlyingTypeInformation (void) const
76  {
78  return true;
79  }
80  virtual std::string GetUnderlyingTypeInformation (void) const
81  {
83  std::ostringstream oss;
84  oss << m_name << " " << m_minValue << ":" << m_maxValue;
85  return oss.str ();
86  }
87  virtual Ptr<AttributeValue> Create (void) const
88  {
90  return ns3::Create<DoubleValue> ();
91  }
92  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const
93  {
94  NS_LOG_FUNCTION (&source << &destination);
95  const DoubleValue *src = dynamic_cast<const DoubleValue *> (&source);
96  DoubleValue *dst = dynamic_cast<DoubleValue *> (&destination);
97  if (src == 0 || dst == 0)
98  {
99  return false;
100  }
101  *dst = *src;
102  return true;
103  }
104  double m_minValue;
105  double m_maxValue;
106  std::string m_name;
107  } *checker = new Checker (min, max, name);
108  return Ptr<const AttributeChecker> (checker, false);
109 }
110 
111 } // namespace internal
112 
113 } // 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 "...
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:205
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:518
double max(double x, double y)
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...
double min(double x, double y)
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:690