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 #ifndef BOOLEAN_H 00021 #define BOOLEAN_H 00022 00023 #include "attribute.h" 00024 #include "attribute-helper.h" 00025 00026 namespace ns3 { 00027 00028 /** 00029 * \ingroup attribute 00030 * 00031 * \brief Hold a bool native type 00032 * 00033 * \anchor bool 00034 * 00035 * This class can be used to hold bool variables 00036 * which must go through the Attribute system. 00037 */ 00038 class BooleanValue : public AttributeValue 00039 { 00040 public: 00041 BooleanValue (); 00042 BooleanValue (bool value); 00043 void Set (bool value); 00044 bool Get (void) const; 00045 template <typename T> 00046 bool GetAccessor (T &v) const; 00047 00048 operator bool () const; 00049 00050 virtual Ptr<AttributeValue> Copy (void) const; 00051 virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const; 00052 virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker); 00053 private: 00054 bool m_value; 00055 }; 00056 00057 template <typename T> 00058 bool BooleanValue::GetAccessor (T &v) const 00059 { 00060 v = T (m_value); 00061 return true; 00062 } 00063 00064 std::ostream & operator << (std::ostream &os, const BooleanValue &value); 00065 00066 ATTRIBUTE_CHECKER_DEFINE (Boolean); 00067 ATTRIBUTE_ACCESSOR_DEFINE (Boolean); 00068 00069 } // namespace ns3 00070 00071 #endif /* BOOLEAN_H */