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 
23 namespace ns3 {
24 
26  : m_value (false)
27 {
28 }
30  : m_value (value)
31 {
32 }
33 void
34 BooleanValue::Set (bool value)
35 {
36  m_value = value;
37 }
38 bool
39 BooleanValue::Get (void) const
40 {
41  return m_value;
42 }
43 BooleanValue::operator bool () const
44 {
45  return m_value;
46 }
47 
48 std::ostream & operator << (std::ostream &os, const BooleanValue &value)
49 {
50  if (value.Get ())
51  {
52  os << "true";
53  }
54  else
55  {
56  os << "false";
57  }
58  return os;
59 }
60 
61 Ptr<AttributeValue>
62 BooleanValue::Copy (void) const
63 {
64  return Create<BooleanValue> (*this);
65 }
66 std::string
68 {
69  if (m_value)
70  {
71  return "true";
72  }
73  else
74  {
75  return "false";
76  }
77 }
78 bool
80 {
81  if (value == "true" ||
82  value == "1" ||
83  value == "t")
84  {
85  m_value = true;
86  return true;
87  }
88  else if (value == "false" ||
89  value == "0" ||
90  value == "f")
91  {
92  m_value = false;
93  return true;
94  }
95  else
96  {
97  return false;
98  }
99 }
100 
101 
103 
104 } // namespace ns3