A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
boolean.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "boolean.h"
9
10#include "fatal-error.h"
11#include "log.h"
12
13/**
14 * \file
15 * \ingroup attribute_Boolean
16 * ns3::BooleanValue attribute value implementation.
17 */
18
19namespace ns3
20{
21
23
25 : m_value(false)
26{
27 NS_LOG_FUNCTION(this);
28}
29
31 : m_value(value)
32{
33 NS_LOG_FUNCTION(this << value);
34}
35
36void
38{
39 NS_LOG_FUNCTION(this << value);
40 m_value = value;
41}
42
43bool
45{
46 NS_LOG_FUNCTION(this);
47 return m_value;
48}
49
50BooleanValue::operator bool() const
51{
52 return m_value;
53}
54
55std::ostream&
56operator<<(std::ostream& os, const BooleanValue& value)
57{
58 if (value.Get())
59 {
60 os << "true";
61 }
62 else
63 {
64 os << "false";
65 }
66 return os;
67}
68
69Ptr<AttributeValue>
71{
72 NS_LOG_FUNCTION(this);
73
74 return Create<BooleanValue>(*this);
75}
76
77std::string
79{
80 NS_LOG_FUNCTION(this << checker);
81
82 if (m_value)
83 {
84 return "true";
85 }
86 else
87 {
88 return "false";
89 }
90}
91
92bool
94{
95 NS_LOG_FUNCTION(this << value << checker);
96
97 if (value == "true" || value == "1" || value == "t")
98 {
99 m_value = true;
100 return true;
101 }
102 else if (value == "false" || value == "0" || value == "f")
103 {
104 m_value = false;
105 return true;
106 }
107 else
108 {
109 return false;
110 }
111}
112
114
115} // namespace ns3
ns3::BooleanValue attribute value declarations.
bool Get() const
Definition boolean.cc:44
Ptr< AttributeValue > Copy() const override
Definition boolean.cc:70
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition boolean.cc:93
void Set(bool value)
Definition boolean.cc:37
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition boolean.cc:78
Smart pointer class similar to boost::intrusive_ptr.
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:191
#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:436
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:148