From 52a0d3571f56187d8801793b36a5511966e1d9a0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 27 Jan 2013 09:39:13 +0000 Subject: Added IniStream methods to read Vector2f keys. --- src/filesystem/inistream.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/filesystem/inistream.h | 8 ++++++++ 2 files changed, 46 insertions(+) (limited to 'src') diff --git a/src/filesystem/inistream.cc b/src/filesystem/inistream.cc index 15c8ee0..0235440 100644 --- a/src/filesystem/inistream.cc +++ b/src/filesystem/inistream.cc @@ -138,6 +138,44 @@ bool IniStream::got_key_label(const char * keylabel, std::string & labelstring) } } +bool IniStream::got_key_vector2f(const char * keylabel, math::Vector2f & v) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { + std::istringstream is(value_current); + float x, y; + if ((is >> x) && (is >> y)) { + v.assign(x, y); + } else { + v.clear(); + } + return true; + } else { + return false; + } +} + + +bool IniStream::got_key_vector2f_opt(const char * keylabel, math::Vector2f & v) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { + std::istringstream is(value_current); + float x, y; + if (is >> x) { + if (!(is >> y)) { + v.assign(x, x); + } else { + v.assign(x, y); + } + } else { + v.clear(); + } + + return true; + } else { + return false; + } +} + bool IniStream::got_key_vector3f(const char * keylabel, math::Vector3f & v) { if (last_read_was_key && (key_current.compare(keylabel) == 0)) { diff --git a/src/filesystem/inistream.h b/src/filesystem/inistream.h index 8788719..6aba4dc 100644 --- a/src/filesystem/inistream.h +++ b/src/filesystem/inistream.h @@ -10,6 +10,7 @@ #include #include +#include "math/vector2f.h" #include "math/vector3f.h" #include "math/color.h" #include "filesystem/filestream.h" @@ -80,6 +81,13 @@ public: bool got_key_long(const char * keylabel, long & l); + bool got_key_vector2f(const char * keylabel, math::Vector2f & v); + + /** + * @brief special version that reads 1 or 2 arguments + **/ + bool got_key_vector2f_opt(const char * keylabel, math::Vector2f & v); + bool got_key_vector3f(const char * keylabel, math::Vector3f & v); /** -- cgit v1.2.3