From 05a2f36cfa6550a457c3a9e358b088077fe4c8da Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 19 Jan 2013 21:43:12 +0000 Subject: Added IniStream::got_key_vector3f_opt() to read vectors with optional coordinates. --- src/filesystem/inistream.cc | 30 ++++++++++++++++++++++++++++-- src/filesystem/inistream.h | 5 +++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/filesystem') diff --git a/src/filesystem/inistream.cc b/src/filesystem/inistream.cc index 54400d0..15c8ee0 100644 --- a/src/filesystem/inistream.cc +++ b/src/filesystem/inistream.cc @@ -144,9 +144,9 @@ bool IniStream::got_key_vector3f(const char * keylabel, math::Vector3f & v) std::istringstream is(value_current); float x, y, z; if ((is >> x) && (is >> y) && (is >> z)) { - v = math::Vector3f(x, y, z); + v.assign(x, y, z); } else { - v = math::Vector3f(); + v.clear(); } return true; } else { @@ -154,6 +154,32 @@ bool IniStream::got_key_vector3f(const char * keylabel, math::Vector3f & v) } } +bool IniStream::got_key_vector3f_opt(const char * keylabel, math::Vector3f & v) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { + std::istringstream is(value_current); + float x, y, z; + if (is >> x) { + if (is >> y) { + if (!(is >> z)) { + z = y; + y = ( x + z ) * 0.5f; + } + } else { + y = x; + z = x; + } + v.assign(x, y, z); + } else { + v.clear(); + } + + return true; + } else { + return false; + } +} + bool IniStream::got_key_float(const char * keylabel, float & f) { if (last_read_was_key && (key_current.compare(keylabel) == 0)) { diff --git a/src/filesystem/inistream.h b/src/filesystem/inistream.h index b4466fd..8788719 100644 --- a/src/filesystem/inistream.h +++ b/src/filesystem/inistream.h @@ -81,6 +81,11 @@ public: bool got_key_long(const char * keylabel, long & l); bool got_key_vector3f(const char * keylabel, math::Vector3f & v); + + /** + * @brief special version that reads 1,2 or 3 arguments + **/ + bool got_key_vector3f_opt(const char * keylabel, math::Vector3f & v); bool got_key_bool(const char * keylabel, bool & b); -- cgit v1.2.3