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:
parent
d39536d7d0
commit
6794ce15e5
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue