src/core/integer.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@2454
    20
#include "integer.h"
mathieu@2377
    21
#include "fatal-error.h"
mathieu@2375
    22
#include <sstream>
mathieu@2375
    23
mathieu@2375
    24
namespace ns3 {
mathieu@2375
    25
mathieu@2965
    26
ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (int64_t, Integer);
mathieu@2439
    27
mathieu@2599
    28
namespace internal {
mathieu@2375
    29
mathieu@2436
    30
Ptr<const AttributeChecker>
mathieu@2599
    31
MakeIntegerChecker (int64_t min, int64_t max, std::string name)
mathieu@2428
    32
{
mathieu@2439
    33
  struct IntegerChecker : public AttributeChecker
mathieu@2428
    34
  {
mathieu@2599
    35
    IntegerChecker (int64_t minValue, int64_t maxValue, std::string name)
mathieu@2428
    36
      : m_minValue (minValue),
mathieu@2599
    37
        m_maxValue (maxValue),
mathieu@2599
    38
        m_name (name) {}
mathieu@2965
    39
    virtual bool Check (const AttributeValue &value) const {
mathieu@2965
    40
      const IntegerValue *v = dynamic_cast<const IntegerValue *> (&value);
mathieu@2428
    41
      if (v == 0)
mathieu@2428
    42
	{
mathieu@2428
    43
	  return false;
mathieu@2428
    44
	}
mathieu@2965
    45
      return v->Get () >= m_minValue && v->Get () <= m_maxValue;
mathieu@2428
    46
    }
mathieu@2969
    47
    virtual std::string GetValueTypeName (void) const {
mathieu@2969
    48
      return "ns3::IntegerValue";
mathieu@2599
    49
    }
mathieu@2969
    50
    virtual bool HasUnderlyingTypeInformation (void) const {
mathieu@2599
    51
      return true;
mathieu@2599
    52
    }
mathieu@2969
    53
    virtual std::string GetUnderlyingTypeInformation (void) const {
mathieu@2599
    54
      std::ostringstream oss;
mathieu@2969
    55
      oss << m_name << " " << m_minValue << ":" << m_maxValue;
mathieu@2599
    56
      return oss.str ();
mathieu@2599
    57
    }
mathieu@2965
    58
    virtual Ptr<AttributeValue> Create (void) const {
mathieu@2965
    59
      return ns3::Create<IntegerValue> ();
mathieu@2965
    60
    }
mathieu@2965
    61
    virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const {
mathieu@2965
    62
      const IntegerValue *source = dynamic_cast<const IntegerValue *> (&src);
mathieu@2965
    63
      IntegerValue *destination = dynamic_cast<IntegerValue *> (&dst);
mathieu@2965
    64
      if (source == 0 || destination == 0)
mathieu@2965
    65
        {
mathieu@2965
    66
          return false;
mathieu@2965
    67
        }
mathieu@2965
    68
      *destination = *source;
mathieu@2965
    69
      return true;
mathieu@2520
    70
    }
mathieu@2428
    71
    int64_t m_minValue;
mathieu@2428
    72
    int64_t m_maxValue;
mathieu@2599
    73
    std::string m_name;
mathieu@2599
    74
  } *checker = new IntegerChecker (min, max, name);
mathieu@2428
    75
  return Ptr<AttributeChecker> (checker, false);
mathieu@2428
    76
}
mathieu@2428
    77
mathieu@2599
    78
} // namespace internal
mathieu@2375
    79
mathieu@2375
    80
} // namespace ns3