A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
24 NS_LOG_COMPONENT_DEFINE ("Boolean");
25 
26 namespace ns3 {
27 
29  : m_value (false)
30 {
31  NS_LOG_FUNCTION (this);
32 }
34  : m_value (value)
35 {
36  NS_LOG_FUNCTION (this << value);
37 }
38 void
39 BooleanValue::Set (bool value)
40 {
41  NS_LOG_FUNCTION (this << value);
42  m_value = value;
43 }
44 bool
45 BooleanValue::Get (void) const
46 {
47  NS_LOG_FUNCTION (this);
48  return m_value;
49 }
50 BooleanValue::operator bool () const
51 {
52  return m_value;
53 }
54 
55 std::ostream & operator << (std::ostream &os, const BooleanValue &value)
56 {
57  if (value.Get ())
58  {
59  os << "true";
60  }
61  else
62  {
63  os << "false";
64  }
65  return os;
66 }
67 
68 Ptr<AttributeValue>
69 BooleanValue::Copy (void) const
70 {
71  NS_LOG_FUNCTION (this);
72 
73  return Create<BooleanValue> (*this);
74 }
75 std::string
77 {
78  NS_LOG_FUNCTION (this << checker);
79 
80  if (m_value)
81  {
82  return "true";
83  }
84  else
85  {
86  return "false";
87  }
88 }
89 bool
91 {
92  NS_LOG_FUNCTION (this << value << checker);
93 
94  if (value == "true" ||
95  value == "1" ||
96  value == "t")
97  {
98  m_value = true;
99  return true;
100  }
101  else if (value == "false" ||
102  value == "0" ||
103  value == "f")
104  {
105  m_value = false;
106  return true;
107  }
108  else
109  {
110  return false;
111  }
112 }
113 
114 
116 
117 } // namespace ns3
virtual Ptr< AttributeValue > Copy(void) const
Definition: boolean.cc:69
bool Get(void) const
Definition: boolean.cc:45
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a bool native type.
Definition: boolean.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: boolean.cc:90
ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(Boolean,"bool")
void Set(bool value)
Definition: boolean.cc:39
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: boolean.cc:76