Commit 4874873c authored by Ludovic Courtès's avatar Ludovic Courtès

Include conversions to various types for 'header' values.

parent bc428ec9
......@@ -200,6 +200,8 @@ header::header(std::istream& input)
// Others are key/value associations that we want to use.
if (linestream.peek() != ' ')
{
linestream.flags(std::ios_base::skipws);
std::string key, rest;
linestream >> key;
if (!key.empty())
......@@ -218,6 +220,12 @@ header::header(std::istream& input)
}
else
{
while(!linestream.eof()
&& std::isspace(linestream.peek()))
{
linestream.get();
}
getline(linestream, rest);
_alist[key] = rest;
}
......@@ -228,3 +236,11 @@ header::header(std::istream& input)
else break;
}
}
header::value::operator int() const
{
int result;
std::stringstream input(_value);
input >> result;
return result;
}
......@@ -14,6 +14,7 @@
#include <vector>
#include <iostream>
#include <cassert>
#include <cstring>
// Math Constants exist in Windows but they need to be included
// by defining the constant _USE_MATH_DEFINES
......@@ -397,6 +398,28 @@ class timer
class header
{
public:
class value
{
protected:
std::string &_value;
public:
value(std::string& value): _value(value) { };
const std::string& string() const { return _value; }
operator const std::string&() const { return _value; }
operator int() const;
template<class T, class U>
operator std::pair<T, U>() const
{
std::stringstream input(_value);
T first; U second;
input >> first >> second;
std::pair<T, U> result(first, second);
return result;
}
};
//! \brief Read the ALTA header on INPUT.
header(std::istream &input);
......@@ -408,9 +431,10 @@ class header
}
//! \brief Return the value associated with KEY in this header.
const std::string& operator[](const std::string& key)
value operator[](const std::string& key)
{
return _alist[key];
value v = _alist[key];
return v;
}
protected:
......
......@@ -31,10 +31,9 @@ void vertical_segment::load_data_from_text(std::istream& input,
header header(input);
{
std::stringstream dim(header["DIM"]);
dim >> result._nX >> result._nY;
}
std::pair<int, int> dim = header["DIM"];
result._nX = dim.first;
result._nY = dim.second;
vs.reserve(result.dimY()) ;
for(int k=0; k<result.dimY(); ++k)
......@@ -66,12 +65,8 @@ void vertical_segment::load_data_from_text(std::istream& input,
result._in_param = params::parse_input(header["PARAM_IN"]);
result._out_param = params::parse_output(header["PARAM_OUT"]);
{
int number;
std::stringstream line(header["VS"]);
line >> number;
vs[current_vs] = number; ++current_vs ;
}
vs[current_vs] = header["VS"];
++current_vs;
// Now read the body.
while(input.good())
......
......@@ -194,10 +194,10 @@ function* plugins_manager::get_function(const std::string& filename)
// of the function
header header(file);
{
std::stringstream linestream(header["DIM"]);
linestream >> nX >> nY;
}
std::pair<int, int> dim = header["DIM"];
nX = dim.first;
nY = dim.second;
param_in = params::parse_input(header["PARAM_IN"]);
param_out = params::parse_output(header["PARAM_OUT"]);
args = arguments::create_arguments(header["CMD"]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment