//------------------------------------------------------------
// $Id: getvals.cc,v 1.1.1.1 1999/11/25 06:26:12 yamauchi Exp $
//------------------------------------------------------------
// get values
//	(M\pi)^2  String -> int, double, Vector3
//	1996/7/18
//	(C) 1996--1998 Copyright YAMAUCHI Hitoshi 山内 斉
//	この関数群は、Srting を利用しているので別扱い
//------------------------------------------------------------
#include <float.h>  // for FLT_MAX
#include <limits.h> // for INT_MIN
#include "getvals.h"

//------------------------------
// String -> int 
//	if fail INT_MIN を返す
//------------------------------
int getInt(const myString& intValStr)
{
    char *ptr = NULL;
    double ret = strtod((const char*)intValStr, &ptr);
    if(*ptr != '\0') /// fail to strtod
    {
        cout << "Error! : fail to str -> double. at getInt(" 
	    << intValStr << ")" << endl;
	return(INT_MIN);
    }else
    {
	if(double(int(ret)) == ret)
	{
	    return(int(ret));
	}else
	{
	    cout << "Error! : this is not int (" << intValStr << ")" << endl;
	    return(INT_MIN);
	}
    }
}

//------------------------------
// get double value from strings
//------------------------------
double getDouble(const myString& doubleValStr)
{
    char *ptr = NULL;
    double ret = strtod((const char*)doubleValStr, &ptr);
    if(*ptr != '\0') /// fail to strtod
    {
        cout << "Error! : fail to str -> double. at getDouble(" 
	    << doubleValStr << ")" << endl;
	return(2 * FLT_MAX);
    }else
    {
        return(ret);
    }
}
