libsaria: Completely replace old InFile() class

My InFile2() class is clearer and simpler, so I've replaced InFile()
with it.
This commit is contained in:
Bryan Schumaker 2011-12-25 21:24:02 -05:00
parent 5e308202a0
commit d39536d7d0
5 changed files with 23 additions and 109 deletions

View File

@ -40,35 +40,18 @@ class OutFile
void write_ino(ino_t, bool);
};
class InFile
class InFile : public ifstream
{
private:
ifstream in;
public:
InFile(string);
~InFile();
bool good();
string read_str();
int read_int();
float read_float();
unsigned int read_ui();
long unsigned int read_lui();
ino_t read_ino();
};
class InFile2 : public ifstream
{
public:
InFile2(string);
~InFile2();
void operator>>(string &);
template <class T>
void operator>>(T &);
};
template <class T>
void InFile2::operator>>(T &item)
void InFile::operator>>(T &item)
{
ifstream *in = (ifstream *)this;
*in >> item;

View File

@ -10,7 +10,7 @@ LibraryPath::LibraryPath(InFile &in, string dir)
unsigned int size;
path = dir;
size = in.read_lui();
in >> size;
println("Library path dir: " + path);
println("Library path size: %d", size);
@ -37,10 +37,10 @@ static void do_load()
if (!in.good())
return;
size = in.read_lui();
in >> size;
for (unsigned int i = 0; i < size; i++) {
dir = in.read_str();
in >> dir;
path_list->push_back(LibraryPath(in, dir));
}

View File

@ -87,74 +87,6 @@ void OutFile::write_ino(ino_t inode, bool end)
}
InFile::InFile(string path)
{
string in_file = get_saria_dir() + "/" + path;
in.open(in_file.c_str());
if (in.good())
println("Reading save file: " + in_file);
}
InFile::~InFile()
{
in.close();
}
bool InFile::good()
{
return in.good();
}
string InFile::read_str()
{
int len;
string str = "";
in >> len;
if (len == 0)
return str;
len++;
in.get();
char c[len];
in.get(c, len);
return c;
}
int InFile::read_int()
{
int i;
in >> i;
return i;
}
float InFile::read_float()
{
float f;
in >> f;
return f;
}
unsigned int InFile::read_ui()
{
unsigned int i;
in >> i;
return i;
}
long unsigned int InFile::read_lui()
{
long unsigned int i;
in >> i;
return i;
}
ino_t InFile::read_ino()
{
ino_t i;
in >> i;
return i;
}
InFile2::InFile2(string path)
{
string in_file = get_saria_dir() + "/" + path;
open(in_file.c_str());
@ -162,12 +94,12 @@ InFile2::InFile2(string path)
println("Error opening file: " + in_file);
}
InFile2::~InFile2()
InFile::~InFile()
{
close();
}
void InFile2::operator>>(string &res)
void InFile::operator>>(string &res)
{
int len;
res = "";

View File

@ -70,21 +70,20 @@ TrackTag::TrackTag(string file, ino_t ino)
TrackTag::TrackTag(InFile &in)
{
inode = in.read_ino();
filepath = in.read_str();
title = in.read_str();
artist = in.read_str();
album = in.read_str();
comment = in.read_str();
genre = in.read_str();
lenstr = in.read_str();
year = in.read_ui();
track = in.read_ui();
length = in.read_int();
bitrate = in.read_int();
sample = in.read_int();
channels = in.read_int();
in >> inode;
in >> filepath;
in >> title;
in >> artist;
in >> album;
in >> comment;
in >> genre;
in >> lenstr;
in >> year;
in >> track;
in >> length;
in >> bitrate;
in >> sample;
in >> channels;
format_tags();
}

View File

@ -20,7 +20,7 @@ struct Preference {
static map<string, Preference> preferences;
static void load_pref(InFile2 &in)
static void load_pref(InFile &in)
{
Preference p;
string key;
@ -79,7 +79,7 @@ namespace libsaria
void prefs::load()
{
unsigned int size = 0;
InFile2 in("preferences");
InFile in("preferences");
if (!in.good())
return;