Update of /cvsroot/echempp/GUI/Windows/Qt/EChem++/Model
In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv14828/GUI/Windows/Qt/EChem++/Model
Added Files:
num_get_special.hpp
Log Message:
iostream facet needed for reading special double/float values "inf" and "nan".
Note that this is not supported by std::iostream, so we need to add this facet
via a std::locale.
--- NEW FILE: num_get_special.hpp ---
/*! \file num_get_special.hpp
\brief facet to use with the standard iostream library
to read special values "inf" and "nan" which are *not*
supported by the standard
*/
/* Copyright (C) 2007, Dominik Brugger */
/* This file is part of EChem++.
EChem++ is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
EChem++ 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.
*/
#include <clocale>
#include <cmath> // for special values
#include <locale>
#include <iostream>
template<typename _CharT, typename _InIter>
class num_get_special : public std::num_get<_CharT,_InIter>
{
public:
typedef typename std::num_get<_CharT, _InIter>::iter_type iter_type;
protected:
virtual ~num_get_special() {}
virtual iter_type
do_get(iter_type __beg, iter_type __end, std::ios_base& __io,
std::ios_base::iostate& __err, float& __v) const
{
std::string __xstrc;
__xstrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xstrc);
if(__xstrc == "")
{
// check for special inf,nan
while(__beg != __end && !std::isalnum(*__beg)) ++__beg;
while(__beg != __end && !std::isspace(*__beg) && std::isalnum(*__beg))__xstrc += std::tolower(*__beg++);
if(__xstrc == "inf") __v = INFINITY;
if(__xstrc == "nan") __v = NAN;
}
else
{
std::__convert_to_v(__xstrc.c_str(), __v, __err, std::locale::facet::_S_get_c_locale()); }
return __beg;
}
virtual iter_type
do_get(iter_type __beg, iter_type __end, std::ios_base& __io,
std::ios_base::iostate& __err, double& __d) const
{
std::string __xstrc;
__xstrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xstrc);
if(__xstrc == "")
{
// check for special inf,nan
while(__beg != __end && !std::isalnum(*__beg)) ++__beg;
while(__beg != __end && !std::isspace(*__beg) && std::isalnum(*__beg))__xstrc += std::tolower(*__beg++);
if(__xstrc == "inf") __d = INFINITY;
if(__xstrc == "nan") __d = NAN;
}
else
{
std::__convert_to_v(__xstrc.c_str(), __d, __err, std::locale::facet::_S_get_c_locale());
}
return __beg;
}
};
|