00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #include "boolean.h" 00021 #include "fatal-error.h" 00022 00023 namespace ns3 { 00024 00025 BooleanValue::BooleanValue () 00026 : m_value (false) 00027 {} 00028 BooleanValue::BooleanValue (bool value) 00029 : m_value (value) 00030 {} 00031 void 00032 BooleanValue::Set (bool value) 00033 { 00034 m_value = value; 00035 } 00036 bool 00037 BooleanValue::Get (void) const 00038 { 00039 return m_value; 00040 } 00041 BooleanValue::operator bool () const 00042 { 00043 return m_value; 00044 } 00045 00046 std::ostream & operator << (std::ostream &os, const BooleanValue &value) 00047 { 00048 if (value.Get ()) 00049 { 00050 os << "true"; 00051 } 00052 else 00053 { 00054 os << "false"; 00055 } 00056 return os; 00057 } 00058 00059 Ptr<AttributeValue> 00060 BooleanValue::Copy (void) const 00061 { 00062 return Create<BooleanValue> (*this); 00063 } 00064 std::string 00065 BooleanValue::SerializeToString (Ptr<const AttributeChecker> checker) const 00066 { 00067 if (m_value) 00068 { 00069 return "true"; 00070 } 00071 else 00072 { 00073 return "false"; 00074 } 00075 } 00076 bool 00077 BooleanValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker) 00078 { 00079 if (value == "true" || 00080 value == "1" || 00081 value == "t") 00082 { 00083 m_value = true; 00084 return true; 00085 } 00086 else if (value == "false" || 00087 value == "0" || 00088 value == "f") 00089 { 00090 m_value = false; 00091 return true; 00092 } 00093 else 00094 { 00095 return false; 00096 } 00097 } 00098 00099 00100 ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (Boolean,"bool"); 00101 00102 } // namespace ns3