Commit de0e9344 authored by Ludovic Courtès's avatar Ludovic Courtès

header: Constify operator[], and define the undefined value.

parent 6d52539b
......@@ -184,6 +184,8 @@ unsigned int timer::current_time() const
}
const header::value header::value::_undefined("");
header::header(std::istream& input)
{
while(input.good())
......
......@@ -401,9 +401,10 @@ class header
class value
{
protected:
std::string &_value;
const std::string &_value;
static const value _undefined;
public:
value(std::string& value): _value(value) { };
value(const std::string& value): _value(value) { };
const std::string& string() const { return _value; }
operator const std::string&() const { return _value; }
operator int() const;
......@@ -418,6 +419,12 @@ class header
std::pair<T, U> result(first, second);
return result;
}
//! \brief Return true if this is the undefined value.
bool is_undefined() const { return this == &_undefined; }
//! \brief Return the undefined value.
static const value& undefined() { return _undefined; }
};
//! \brief Read the ALTA header on INPUT.
......@@ -431,10 +438,15 @@ class header
}
//! \brief Return the value associated with KEY in this header.
value operator[](const std::string& key)
value operator[](const std::string& key) const
{
value v = _alist[key];
return v;
std::map<std::string, std::string>::const_iterator i;
i = _alist.find(key);
if (i == _alist.end())
{
return value::undefined();
}
return value(i->second);
}
protected:
......
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