A Discrete-Event Network Simulator
API
double.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #include "double.h"
20 
21 #include "log.h"
22 #include "object.h"
23 
24 #include <sstream>
25 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("Double");
36 
38 
40 namespace internal
41 {
42 
53 MakeDoubleChecker(double min, double max, std::string name)
54 {
55  NS_LOG_FUNCTION(min << max << name);
56 
57  struct Checker : public AttributeChecker
58  {
59  Checker(double minValue, double maxValue, std::string name)
60  : m_minValue(minValue),
61  m_maxValue(maxValue),
62  m_name(name)
63  {
64  }
65 
66  bool Check(const AttributeValue& value) const override
67  {
68  NS_LOG_FUNCTION(&value);
69  const auto v = dynamic_cast<const DoubleValue*>(&value);
70  if (v == nullptr)
71  {
72  return false;
73  }
74  return v->Get() >= m_minValue && v->Get() <= m_maxValue;
75  }
76 
77  std::string GetValueTypeName() const override
78  {
80  return "ns3::DoubleValue";
81  }
82 
83  bool HasUnderlyingTypeInformation() const override
84  {
86  return true;
87  }
88 
89  std::string GetUnderlyingTypeInformation() const override
90  {
92  std::ostringstream oss;
93  oss << m_name << " " << m_minValue << ":" << m_maxValue;
94  return oss.str();
95  }
96 
97  Ptr<AttributeValue> Create() const override
98  {
100  return ns3::Create<DoubleValue>();
101  }
102 
103  bool Copy(const AttributeValue& source, AttributeValue& destination) const override
104  {
105  NS_LOG_FUNCTION(&source << &destination);
106  const auto src = dynamic_cast<const DoubleValue*>(&source);
107  auto dst = dynamic_cast<DoubleValue*>(&destination);
108  if (src == nullptr || dst == nullptr)
109  {
110  return false;
111  }
112  *dst = *src;
113  return true;
114  }
115 
116  double m_minValue;
117  double m_maxValue;
118  std::string m_name;
119  }* checker = new Checker(min, max, name);
120 
121  return Ptr<const AttributeChecker>(checker, false);
122 }
123 
124 } // namespace internal
125 
126 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
Represent the type of an attribute.
Definition: attribute.h:168
Hold a value for an Attribute.
Definition: attribute.h:70
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double Get() const
Definition: double.cc:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
ns3::DoubleValue attribute value declarations and template implementations.
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
Define the class methods belonging to the attribute value class nameValue of the underlying class typ...
#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 NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition: ptr.h:442
Debug message logging.
void(* Double)(double oldValue, double newValue)
TracedValue Callback signature for POD.
Definition: traced-value.h:91
Ptr< const AttributeChecker > MakeDoubleChecker(double min, double max, std::string name)
Make a Double attribute checker with embedded numeric type name.
Definition: double.cc:53
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:610
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.