Files
unison/src/core/model/boolean.cc

124 lines
2.4 KiB
C++
Raw Normal View History

2008-03-10 00:38:48 +01:00
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
2008-02-21 18:57:34 +01:00
#include "boolean.h"
#include "fatal-error.h"
#include "log.h"
/**
* \file
* \ingroup attribute_Boolean
* Boolean attribute value implementaations.
*/
2008-01-30 17:28:18 +01:00
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("Boolean");
BooleanValue::BooleanValue ()
2008-02-21 00:19:31 +01:00
: m_value (false)
2011-05-13 14:52:27 -04:00
{
NS_LOG_FUNCTION (this);
2011-05-13 14:52:27 -04:00
}
BooleanValue::BooleanValue (bool value)
2008-01-30 17:28:18 +01:00
: m_value (value)
2011-05-13 14:52:27 -04:00
{
NS_LOG_FUNCTION (this << value);
2011-05-13 14:52:27 -04:00
}
void
BooleanValue::Set (bool value)
2008-01-30 17:28:18 +01:00
{
NS_LOG_FUNCTION (this << value);
2008-01-30 17:28:18 +01:00
m_value = value;
}
2011-05-13 14:52:27 -04:00
bool
BooleanValue::Get (void) const
2008-01-30 17:28:18 +01:00
{
NS_LOG_FUNCTION (this);
2008-01-30 17:28:18 +01:00
return m_value;
}
BooleanValue::operator bool () const
2008-01-30 17:28:18 +01:00
{
2008-02-21 00:19:31 +01:00
return m_value;
2008-01-30 17:28:18 +01:00
}
2008-02-21 00:19:31 +01:00
std::ostream & operator << (std::ostream &os, const BooleanValue &value)
2008-01-30 17:28:18 +01:00
{
2008-02-21 00:19:31 +01:00
if (value.Get ())
2008-01-30 17:28:18 +01:00
{
2008-02-21 00:19:31 +01:00
os << "true";
2008-01-30 17:28:18 +01:00
}
else
{
2008-02-21 00:19:31 +01:00
os << "false";
2008-01-30 17:28:18 +01:00
}
2008-02-21 00:19:31 +01:00
return os;
2008-01-30 17:28:18 +01:00
}
Ptr<AttributeValue>
BooleanValue::Copy (void) const
{
NS_LOG_FUNCTION (this);
return Create<BooleanValue> (*this);
}
std::string
BooleanValue::SerializeToString (Ptr<const AttributeChecker> checker) const
2008-01-30 17:28:18 +01:00
{
NS_LOG_FUNCTION (this << checker);
if (m_value)
2008-01-30 17:28:18 +01:00
{
return "true";
}
else
{
return "false";
2008-01-30 17:28:18 +01:00
}
}
bool
BooleanValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
{
NS_LOG_FUNCTION (this << value << checker);
if (value == "true" ||
value == "1" ||
value == "t")
2008-01-30 17:28:18 +01:00
{
m_value = true;
return true;
}
else if (value == "false" ||
value == "0" ||
value == "f")
{
m_value = false;
return true;
2008-01-30 17:28:18 +01:00
}
else
{
return false;
2011-05-13 14:52:27 -04:00
}
}
2008-01-30 17:28:18 +01:00
ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (Boolean,"bool");
2008-02-18 00:18:45 +01:00
2008-01-30 17:28:18 +01:00
} // namespace ns3