src/core/rectangle-default-value.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 18 Jul 2007 17:06:36 +0200
changeset 1603 e54bfec07c72
parent 1568 8629dec7b11e
child 1604 bf85a8c213d5
permissions -rw-r--r--
make sure we schedule the start event correctly

/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2007 INRIA
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
 */

#include "rectangle-default-value.h"

namespace ns3 {

RectangleDefaultValue::RectangleDefaultValue (std::string name,
					      std::string help,
					      double xMin, double xMax,
					      double yMin, double yMax)
  : DefaultValueBase (name, help),
    m_xMinDefault (xMin),
    m_xMaxDefault (xMax),
    m_yMinDefault (yMin),
    m_yMaxDefault (yMax),
    m_xMin (xMin),
    m_xMax (xMax),
    m_yMin (yMin),
    m_yMax (yMax)
{
  DefaultValueList::Add (this);
}

double 
RectangleDefaultValue::GetMinX (void) const
{
  return m_xMin;
}
double 
RectangleDefaultValue::GetMinY (void) const
{
  return m_yMin;
}
double 
RectangleDefaultValue::GetMaxX (void) const
{
  return m_xMax;
}
double 
RectangleDefaultValue::GetMaxY (void) const
{
  return m_yMax;
}
bool 
RectangleDefaultValue::DoParseValue (const std::string &value)
{
  std::string::size_type xMinStart = 0;
  std::string::size_type xMinEnd = value.find_first_of(":", xMinStart);
  std::string::size_type xMaxStart = xMinEnd + 1;
  std::string::size_type xMaxEnd = value.find_first_of(":", xMaxStart);
  std::string::size_type yMinStart = xMaxEnd + 1;
  std::string::size_type yMinEnd = value.find_first_of(":", yMinStart);
  std::string::size_type yMaxStart = yMinEnd + 1;
  std::string::size_type yMaxEnd = std::string::npos;

  std::string xMinString = value.substr (xMinStart, xMinEnd);
  std::string xMaxString = value.substr (xMaxStart, xMaxEnd);
  std::string yMinString = value.substr (yMinStart, yMinEnd);
  std::string yMaxString = value.substr (yMaxStart, yMaxEnd);

  std::istringstream iss;
  iss.str (xMinString);
  iss >> m_xMin;
  iss.str (xMaxString);
  iss >> m_xMax;
  iss.str (yMinString);
  iss >> m_yMin;
  iss.str (yMaxString);
  iss >> m_yMax;

  return !iss.bad () && !iss.fail ();
}
std::string 
RectangleDefaultValue::DoGetType (void) const
{
  return "(xMin:xMax:yMin:yMax)";
}
std::string 
RectangleDefaultValue::DoGetDefaultValue (void) const
{
  std::ostringstream oss;
  oss << m_xMinDefault << ":" << m_xMaxDefault << ":" << m_yMinDefault << ":" << m_yMaxDefault;
  return oss.str ();
}


} // namespace ns3