A Discrete-Event Network Simulator
API
boolean.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 "boolean.h"
21#include "fatal-error.h"
22#include "log.h"
23
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("Boolean");
33
35 : m_value (false)
36{
37 NS_LOG_FUNCTION (this);
38}
40 : m_value (value)
41{
42 NS_LOG_FUNCTION (this << value);
43}
44void
46{
47 NS_LOG_FUNCTION (this << value);
48 m_value = value;
49}
50bool
52{
53 NS_LOG_FUNCTION (this);
54 return m_value;
55}
56BooleanValue::operator bool () const
57{
58 return m_value;
59}
60
61std::ostream & operator << (std::ostream &os, const BooleanValue &value)
62{
63 if (value.Get ())
64 {
65 os << "true";
66 }
67 else
68 {
69 os << "false";
70 }
71 return os;
72}
73
74Ptr<AttributeValue>
76{
77 NS_LOG_FUNCTION (this);
78
79 return Create<BooleanValue> (*this);
80}
81std::string
83{
84 NS_LOG_FUNCTION (this << checker);
85
86 if (m_value)
87 {
88 return "true";
89 }
90 else
91 {
92 return "false";
93 }
94}
95bool
97{
98 NS_LOG_FUNCTION (this << value << checker);
99
100 if (value == "true"
101 || value == "1"
102 || value == "t")
103 {
104 m_value = true;
105 return true;
106 }
107 else if (value == "false"
108 || value == "0"
109 || value == "f")
110 {
111 m_value = false;
112 return true;
113 }
114 else
115 {
116 return false;
117 }
118}
119
120
122
123} // namespace ns3
ns3::BooleanValue attribute value declarations.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
void Set(bool value)
Set the value.
Definition: boolean.cc:45
bool m_value
The stored Boolean instance.
Definition: boolean.h:62
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: boolean.cc:82
bool Get(void) const
Definition: boolean.cc:51
virtual Ptr< AttributeValue > Copy(void) const
Definition: boolean.cc:75
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: boolean.cc:96
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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:205
#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:139