A Discrete-Event Network Simulator
API
boolean.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 "boolean.h"
20 
21 #include "fatal-error.h"
22 #include "log.h"
23 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("Boolean");
34 
36  : m_value(false)
37 {
38  NS_LOG_FUNCTION(this);
39 }
40 
42  : m_value(value)
43 {
44  NS_LOG_FUNCTION(this << value);
45 }
46 
47 void
48 BooleanValue::Set(bool value)
49 {
50  NS_LOG_FUNCTION(this << value);
51  m_value = value;
52 }
53 
54 bool
56 {
57  NS_LOG_FUNCTION(this);
58  return m_value;
59 }
60 
61 BooleanValue::operator bool() const
62 {
63  return m_value;
64 }
65 
66 std::ostream&
67 operator<<(std::ostream& os, const BooleanValue& value)
68 {
69  if (value.Get())
70  {
71  os << "true";
72  }
73  else
74  {
75  os << "false";
76  }
77  return os;
78 }
79 
80 Ptr<AttributeValue>
82 {
83  NS_LOG_FUNCTION(this);
84 
85  return Create<BooleanValue>(*this);
86 }
87 
88 std::string
90 {
91  NS_LOG_FUNCTION(this << checker);
92 
93  if (m_value)
94  {
95  return "true";
96  }
97  else
98  {
99  return "false";
100  }
101 }
102 
103 bool
105 {
106  NS_LOG_FUNCTION(this << value << checker);
107 
108  if (value == "true" || value == "1" || value == "t")
109  {
110  m_value = true;
111  return true;
112  }
113  else if (value == "false" || value == "0" || value == "f")
114  {
115  m_value = false;
116  return true;
117  }
118  else
119  {
120  return false;
121  }
122 }
123 
125 
126 } // namespace ns3
ns3::BooleanValue attribute value declarations.
bool Get() const
Definition: boolean.cc:55
Ptr< AttributeValue > Copy() const override
Definition: boolean.cc:81
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition: boolean.cc:104
void Set(bool value)
Definition: boolean.cc:48
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition: boolean.cc:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
NS_FATAL_x macro definitions.
#define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(type, name)
Define the MaketypeChecker function for class type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159