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