1 | #ifndef __GEO_SERIALIZER_H__
|
---|
2 | #define __GEO_SERIALIZER_H__
|
---|
3 |
|
---|
4 | #include "GeoBase.h"
|
---|
5 | #include "GeoVector2.h"
|
---|
6 | #include "GeoVector3.h"
|
---|
7 |
|
---|
8 | namespace Geometry
|
---|
9 | {
|
---|
10 | /// Serializer interface
|
---|
11 | /** Serializer is a helper class than manages file input/output.
|
---|
12 | */
|
---|
13 | class Serializer
|
---|
14 | {
|
---|
15 | public:
|
---|
16 |
|
---|
17 | enum Mode
|
---|
18 | {
|
---|
19 | READ,
|
---|
20 | WRITE,
|
---|
21 | APPEND
|
---|
22 | };
|
---|
23 |
|
---|
24 | /// Constructor.
|
---|
25 | Serializer(String name, Mode mode);
|
---|
26 |
|
---|
27 | /// Destructor.
|
---|
28 | virtual ~Serializer();
|
---|
29 |
|
---|
30 | /// Copy constructor.
|
---|
31 | //Serializer(const Serializer&);
|
---|
32 |
|
---|
33 | /// Assignment operator.
|
---|
34 | //Serializer& operator =(const Serializer&);
|
---|
35 |
|
---|
36 | public:
|
---|
37 |
|
---|
38 | void WriteData(const void* const buf, size_t size, size_t count);
|
---|
39 | void WriteArray(const float* const pfloat, size_t count);
|
---|
40 | void WriteArray(const uint16* const pShort, size_t count);
|
---|
41 | void WriteArray(const uint32* const pInt, size_t count);
|
---|
42 | void WriteArray(const bool* const pLong, size_t count);
|
---|
43 | void WriteArray(const Vector3* const pvector3, size_t count);
|
---|
44 | void WriteArray(const Vector2* const pvector3, size_t count);
|
---|
45 |
|
---|
46 | void ReadData(void *buf, size_t size, size_t count);
|
---|
47 | char * ReadData(char *pDest, size_t pDestsize);
|
---|
48 | void ReadArray(bool *pDest, size_t count);
|
---|
49 | void ReadArray(float *pDest, size_t count);
|
---|
50 | void ReadArray(uint16 *pDest, size_t count);
|
---|
51 | void ReadArray(uint32 *pDest, size_t count);
|
---|
52 | void ReadArray(Vector3 *pDest, size_t count);
|
---|
53 | void ReadArray(Vector2 *pDest, size_t count);
|
---|
54 |
|
---|
55 | void WriteData(const String &string);
|
---|
56 | void WriteData(const char *string);
|
---|
57 |
|
---|
58 | virtual size_t GetSize()
|
---|
59 | {
|
---|
60 | return mSize;
|
---|
61 | }
|
---|
62 |
|
---|
63 | int serializereof() {
|
---|
64 | return feof(mFile);
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected:
|
---|
68 |
|
---|
69 | size_t mSize;
|
---|
70 | FILE *mFile;
|
---|
71 | Mode mMode;
|
---|
72 |
|
---|
73 | void FlipToLittleEndian(void *pData, size_t size, size_t count = 1);
|
---|
74 | void FlipFromLittleEndian(void *pData, size_t size, size_t count = 1);
|
---|
75 | void FlipEndian(void *pData, size_t size, size_t count);
|
---|
76 | void FlipEndian(void *pData, size_t size);
|
---|
77 | };
|
---|
78 |
|
---|
79 | }
|
---|
80 |
|
---|
81 | #endif
|
---|
82 |
|
---|