libsaria: Return ifstream reference from operator>>

This allows me to chain calls to the same stream, cleaning up the code.
This commit is contained in:
Bryan Schumaker 2011-12-25 22:20:04 -05:00
parent d39536d7d0
commit 6794ce15e5
3 changed files with 8 additions and 7 deletions

View File

@ -45,16 +45,17 @@ class InFile : public ifstream
public:
InFile(string);
~InFile();
void operator>>(string &);
InFile& operator>>(string &);
template <class T>
void operator>>(T &);
InFile& operator>>(T &);
};
template <class T>
void InFile::operator>>(T &item)
InFile& InFile::operator>>(T &item)
{
ifstream *in = (ifstream *)this;
*in >> item;
return *this;
}
#endif /* LIBSARIA_FILES_H */

View File

@ -99,18 +99,19 @@ InFile::~InFile()
close();
}
void InFile::operator>>(string &res)
InFile& InFile::operator>>(string &res)
{
int len;
res = "";
*this >> len;
if (len == 0)
return;
return *this;
len++;
this->get();
char c[len];
this->get(c, len);
res = c;
return *this;
}

View File

@ -25,8 +25,7 @@ static void load_pref(InFile &in)
Preference p;
string key;
in >> key;
in >> (unsigned int&)p.type;
in >> key >> (unsigned int &)p.type;
switch (p.type) {
case BOOL:
in >> p.value_u.boolean;