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
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2008 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #include "integer.h"
    21 #include "fatal-error.h"
    22 #include <sstream>
    23 
    24 namespace ns3 {
    25 
    26 ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (int64_t, Integer);
    27 
    28 namespace internal {
    29 
    30 Ptr<const AttributeChecker>
    31 MakeIntegerChecker (int64_t min, int64_t max, std::string name)
    32 {
    33   struct IntegerChecker : public AttributeChecker
    34   {
    35     IntegerChecker (int64_t minValue, int64_t maxValue, std::string name)
    36       : m_minValue (minValue),
    37         m_maxValue (maxValue),
    38         m_name (name) {}
    39     virtual bool Check (const AttributeValue &value) const {
    40       const IntegerValue *v = dynamic_cast<const IntegerValue *> (&value);
    41       if (v == 0)
    42 	{
    43 	  return false;
    44 	}
    45       return v->Get () >= m_minValue && v->Get () <= m_maxValue;
    46     }
    47     virtual std::string GetValueTypeName (void) const {
    48       return "ns3::IntegerValue";
    49     }
    50     virtual bool HasUnderlyingTypeInformation (void) const {
    51       return true;
    52     }
    53     virtual std::string GetUnderlyingTypeInformation (void) const {
    54       std::ostringstream oss;
    55       oss << m_name << " " << m_minValue << ":" << m_maxValue;
    56       return oss.str ();
    57     }
    58     virtual Ptr<AttributeValue> Create (void) const {
    59       return ns3::Create<IntegerValue> ();
    60     }
    61     virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const {
    62       const IntegerValue *source = dynamic_cast<const IntegerValue *> (&src);
    63       IntegerValue *destination = dynamic_cast<IntegerValue *> (&dst);
    64       if (source == 0 || destination == 0)
    65         {
    66           return false;
    67         }
    68       *destination = *source;
    69       return true;
    70     }
    71     int64_t m_minValue;
    72     int64_t m_maxValue;
    73     std::string m_name;
    74   } *checker = new IntegerChecker (min, max, name);
    75   return Ptr<AttributeChecker> (checker, false);
    76 }
    77 
    78 } // namespace internal
    79 
    80 } // namespace ns3