| 1 |
#include "SimpleSerializable2.hh" |
| 2 |
|
| 3 |
// The following header defines functions used to read/write built-in |
| 4 |
// types as well as arrays, vectors, and strings. Always use these functions |
| 5 |
// to implement the I/O for your own classes instead of using std::ostream |
| 6 |
// facilities directly. This will ensure interface consistency and will |
| 7 |
// simplify future updates. |
| 8 |
#include "geners/binaryIO.hh" |
| 9 |
|
| 10 |
// The following header defines several useful exception classes |
| 11 |
#include "geners/IOException.hh" |
| 12 |
|
| 13 |
using namespace gs; |
| 14 |
|
| 15 |
bool SimpleSerializable2::write(std::ostream& of) const |
| 16 |
{ |
| 17 |
write_pod(of, datum_); |
| 18 |
return !of.fail(); |
| 19 |
} |
| 20 |
|
| 21 |
SimpleSerializable2* SimpleSerializable2::read(const ClassId& id, |
| 22 |
std::istream& in) |
| 23 |
{ |
| 24 |
// Here, we ensure that a correct class id argument was provided. |
| 25 |
// While a wrong class id argument should never be generated if |
| 26 |
// the item is simply read back from a "geners" archive, this check |
| 27 |
// might help to detect problems with other serialization scenarios. |
| 28 |
// |
| 29 |
static const ClassId myClassId(ClassId::makeId<SimpleSerializable2>()); |
| 30 |
myClassId.ensureSameId(id); |
| 31 |
|
| 32 |
// Read back the object info |
| 33 |
double d(0.0); |
| 34 |
read_pod(in, &d); |
| 35 |
|
| 36 |
// Check the status of the stream |
| 37 |
if (in.fail()) throw IOReadFailure("In SimpleSerializable2::read: " |
| 38 |
"input stream failure"); |
| 39 |
return new SimpleSerializable2(d); |
| 40 |
} |