src/core/boolean.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 3182 61fe7fe81ebd
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@2453
    20
#ifndef BOOLEAN_H
mathieu@2453
    21
#define BOOLEAN_H
mathieu@2371
    22
mathieu@2438
    23
#include "attribute.h"
mathieu@2451
    24
#include "attribute-helper.h"
mathieu@2371
    25
mathieu@2371
    26
namespace ns3 {
mathieu@2371
    27
mathieu@2584
    28
/**
tomh@3182
    29
 * \ingroup attribute
tomh@3182
    30
 *
mathieu@2584
    31
 * \brief Hold a bool native type
mathieu@2584
    32
 *
mathieu@2928
    33
 * \anchor bool
mathieu@2928
    34
 *
mathieu@2584
    35
 * This class can be used to hold bool variables
mathieu@2584
    36
 * which must go through the Attribute system.
mathieu@2584
    37
 */
mathieu@2965
    38
class BooleanValue : public AttributeValue
mathieu@2371
    39
{
mathieu@2371
    40
public:
mathieu@2965
    41
  BooleanValue ();
mathieu@2965
    42
  BooleanValue (bool value);
mathieu@2371
    43
  void Set (bool value);
mathieu@2371
    44
  bool Get (void) const;
mathieu@3763
    45
  template <typename T>
mathieu@3763
    46
  bool GetAccessor (T &v) const;
mathieu@2965
    47
  
mathieu@2441
    48
  operator bool () const;
mathieu@2372
    49
mathieu@2965
    50
  virtual Ptr<AttributeValue> Copy (void) const;
mathieu@2965
    51
  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
mathieu@2965
    52
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
mathieu@2371
    53
private:
mathieu@2371
    54
  bool m_value;
mathieu@2371
    55
};
mathieu@2371
    56
mathieu@3763
    57
template <typename T>
mathieu@3763
    58
bool BooleanValue::GetAccessor (T &v) const
mathieu@3763
    59
{
mathieu@3763
    60
  v = T (m_value);
mathieu@3763
    61
  return true;
mathieu@3763
    62
}
mathieu@3763
    63
mathieu@2965
    64
std::ostream & operator << (std::ostream &os, const BooleanValue &value);
mathieu@2410
    65
mathieu@2441
    66
ATTRIBUTE_CHECKER_DEFINE (Boolean);
mathieu@2441
    67
ATTRIBUTE_ACCESSOR_DEFINE (Boolean);
mathieu@2371
    68
mathieu@2371
    69
} // namespace ns3
mathieu@2371
    70
mathieu@2453
    71
#endif /* BOOLEAN_H */