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