Debian Codegraph @

tests/SerializableDerivedC.cc

raw
1 #include <cassert>
2
3 #include "SerializableDerivedC.hh"
4
5 #include "geners/binaryIO.hh"
6 #include "geners/CPP11_auto_ptr.hh"
7 #include "geners/IOException.hh"
8
9 bool SerializableDerivedC::write(std::ostream& of) const
10 {
11 gs::write_pod(of, b());
12 gs::write_pod(of, u_);
13 return !of.fail();
14 }
15
16 SerializableDerivedC* SerializableDerivedC::read(const gs::ClassId& id,
17 std::istream& in)
18 {
19 // We do not expect any other class to be derived from
20 // this one (note that the destructor is not virtual).
21 // Because of this, we only need to handle the case
22 // of correct class id.
23 static const gs::ClassId myId(gs::ClassId::makeId<SerializableDerivedC>());
24 myId.ensureSameId(id);
25
26 double b(0.0);
27 gs::read_pod(in, &b);
28 unsigned u;
29 gs::read_pod(in, &u);
30 if (in.fail())
31 throw gs::IOReadFailure("In SerializableDerivedC::read: "
32 "input stream failure");
33 return new SerializableDerivedC(u, b);
34 }