src/core/boolean.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 2965 4b28e9740e3b
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
mathieu@2581
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@2581
     2
/*
mathieu@2581
     3
 * Copyright (c) 2008 INRIA
mathieu@2581
     4
 *
mathieu@2581
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@2581
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@2581
     7
 * published by the Free Software Foundation;
mathieu@2581
     8
 *
mathieu@2581
     9
 * This program is distributed in the hope that it will be useful,
mathieu@2581
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@2581
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@2581
    12
 * GNU General Public License for more details.
mathieu@2581
    13
 *
mathieu@2581
    14
 * You should have received a copy of the GNU General Public License
mathieu@2581
    15
 * along with this program; if not, write to the Free Software
mathieu@2581
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@2581
    17
 *
mathieu@2581
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@2581
    19
 */
mathieu@2452
    20
#include "boolean.h"
mathieu@2372
    21
#include "fatal-error.h"
mathieu@2371
    22
mathieu@2371
    23
namespace ns3 {
mathieu@2371
    24
mathieu@2965
    25
BooleanValue::BooleanValue ()
mathieu@2441
    26
  : m_value (false)
mathieu@2441
    27
{}
mathieu@2965
    28
BooleanValue::BooleanValue (bool value)
mathieu@2371
    29
  : m_value (value)
mathieu@2371
    30
{}
mathieu@2371
    31
void 
mathieu@2965
    32
BooleanValue::Set (bool value)
mathieu@2371
    33
{
mathieu@2371
    34
  m_value = value;
mathieu@2371
    35
}
mathieu@2371
    36
bool 
mathieu@2965
    37
BooleanValue::Get (void) const
mathieu@2371
    38
{
mathieu@2371
    39
  return m_value;
mathieu@2371
    40
}
mathieu@2965
    41
BooleanValue::operator bool () const
mathieu@2371
    42
{
mathieu@2441
    43
  return m_value;
mathieu@2371
    44
}
mathieu@2441
    45
mathieu@2965
    46
std::ostream & operator << (std::ostream &os, const BooleanValue &value)
mathieu@2371
    47
{
mathieu@2441
    48
  if (value.Get ())
mathieu@2371
    49
    {
mathieu@2441
    50
      os << "true";
mathieu@2371
    51
    }
mathieu@2371
    52
  else
mathieu@2371
    53
    {
mathieu@2441
    54
      os << "false";
mathieu@2371
    55
    }
mathieu@2441
    56
  return os;
mathieu@2371
    57
}
mathieu@2965
    58
mathieu@2965
    59
Ptr<AttributeValue> 
mathieu@2965
    60
BooleanValue::Copy (void) const
mathieu@2371
    61
{
mathieu@2965
    62
  return Create<BooleanValue> (*this);
mathieu@2965
    63
}
mathieu@2965
    64
std::string 
mathieu@2965
    65
BooleanValue::SerializeToString (Ptr<const AttributeChecker> checker) const
mathieu@2965
    66
{
mathieu@2965
    67
  if (m_value)
mathieu@2371
    68
    {
mathieu@2965
    69
      return "true";
mathieu@2965
    70
    } 
mathieu@2965
    71
  else
mathieu@2965
    72
    {
mathieu@2965
    73
      return "false";
mathieu@2371
    74
    }
mathieu@2965
    75
}
mathieu@2965
    76
bool 
mathieu@2965
    77
BooleanValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
mathieu@2965
    78
{
mathieu@2965
    79
  if (value == "true" ||
mathieu@2965
    80
      value == "1" ||
mathieu@2965
    81
      value == "t")
mathieu@2371
    82
    {
mathieu@2965
    83
      m_value = true;
mathieu@2965
    84
      return true;
mathieu@2965
    85
    }
mathieu@2965
    86
  else if (value == "false" ||
mathieu@2965
    87
           value == "0" ||
mathieu@2965
    88
           value == "f")
mathieu@2965
    89
    {
mathieu@2965
    90
      m_value = false;
mathieu@2965
    91
      return true;
mathieu@2371
    92
    }
mathieu@2371
    93
  else
mathieu@2371
    94
    {
mathieu@2965
    95
      return false;
mathieu@2371
    96
    }  
mathieu@2372
    97
}
mathieu@2371
    98
mathieu@2965
    99
mathieu@2969
   100
ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (Boolean,"bool");
mathieu@2427
   101
mathieu@2371
   102
} // namespace ns3