#include "io.hh"
class A
{
private:
int i;
bool is_constructed;
public:
A()
{
this->i = 0;
this->is_constructed = false;
}
A(int i)
{
this->i = i;
this->is_constructed = true;
}
friend Writer& operator << (Writer& w, const A& a)
{
ASSERT(a.is_constructed);
w << "(A " << a.i << ')';
return w;
}
friend Reader& operator >> (Reader& r, A& a)
{
r >> '(' >> "A" >> a.i >> ')';
a.is_constructed = true;
return r;
}
friend bool operator == (const A& a1, const A& a2)
{
return a1.i == a2.i;
}
void OK()
{
ASSERT(is_constructed);
}
};
class B
{
private:
int i;
string s;
bool is_constructed;
public:
B()
{
this->i = 0;
this->s = "";
this->is_constructed = false;
}
B(int i, string s)
{
this->i = i;
this->s = s;
this->is_constructed = true;
}
friend Writer& operator << (Writer& w, const B& b)
{
ASSERT(b.is_constructed);
w << "(B " << b.i << ' ' << b.s << ')';
return w;
}
friend Reader& operator >> (Reader& r, B& b)
{
r >> '(' >> "B" >> b.i >> b.s >> ')';
b.is_constructed = true;
return r;
}
friend bool operator == (const B& b1, const B& b2)
{
return (b1.i == b2.i) && strings_equal(b1.s, b2.s);
}
void OK()
{
ASSERT(is_constructed);
}
};
class C
{
private:
int i;
string s;
string q;
bool is_constructed;
public:
C()
{
this->i = 0;
this->s = "";
this->q = "";
this->is_constructed = false;
}
C(int i, string s, string q)
{
this->i = i;
this->s = s;
this->q = q;
this->is_constructed = true;
}
friend Writer& operator << (Writer& w, const C& c)
{
ASSERT(c.is_constructed);
w << "(C " << c.i << ' ' << c.s << ' ' << quoted(c.q) << ')';
return w;
}
friend Reader& operator >> (Reader& r, C& c)
{
r >> '(' >> "C" >> c.i >> c.s;
c.q = r.gulp_quoted_string();
r >> ')';
c.is_constructed = true;
return r;
}
friend bool operator == (const C& c1, const C& c2)
{
return (c1.i == c2.i) && strings_equal(c1.s, c2.s) && strings_equal(c1.q, c2.q);
}
void OK()
{
ASSERT(is_constructed);
}
};
int main()
{
cout << "**** BEGIN t-write-read.exe\n";
string filename = "t-write-read.el";
{
cout << "*** BEGIN test 1\n";
A a(12);
B b(24,"cat");
C c(56,"banana","I am a quoted string");
File_Writer w(filename);
w << a;
w << b;
w << c;
a.OK();
b.OK();
c.OK();
cout << "*** END test 1\n";
}
{
cout << "*** BEGIN test 2\n";
A a;
B b;
C c;
File_Reader r(filename);
r >> a;
r >> b;
r >> c;
a.OK();
b.OK();
c.OK();
PRINT(a);
PRINT(b);
PRINT(c);
ASSERT(a == A(12));
ASSERT(b == B(24,"cat"));
ASSERT(c == C(56,"banana","I am a quoted string"));
cout << "*** END test 2\n";
}
cout << "**** All tests suceeded!\n";
cout << "**** END t-write-read.exe\n";
return EXIT_SUCCESS;
}
END_OF_MAIN();