1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
////////////////////////////////////////////////////////////////////////
// Copyright (c) Nehmulos 2011-2014
// This file is part of N0 Strain Serialization Library.
//
// N0Strain-Serialization-Library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// N0Strain-Serialization-Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with N0Strain-Serialization-Library. If not, see https://gnu.org/licenses/lgpl-3.0
////////////////////////////////////////////////////////////////////////
#ifndef DESCRIBED_OBJECT_H_
#define DESCRIBED_OBJECT_H_
////////////////////////////////////////////////////////////////////////////////////////////////
/// Derive from this class to serialize your class' members and pointer from and to this class.
///
/// 1) To serialize your Class
/// just inherit this class
/// 2) and implement the virtual functions:
/// serialize, getClassID
/// 3) add a classIds enum with all classIds to your Constants file
/// 4) add a createObjectForId function that returns a "new" SerializedObject pointer
/// for a given classId and set Serializer::createObjectForClassId to this function
////////////////////////////////////////////////////////////////////////////////////////////////
#include "N0SlibConstants.h"
#include <vector>
namespace nw {
class Describer;
class DescribedObject {
public:
DescribedObject();
virtual ~DescribedObject();
/// implement serialize to read or write your class' members.
/// use the given Serializer's functions for this task.
virtual void describeObject(Describer *file) = 0;
/// return an unsigned int that identifies your class.
virtual ClassId getClassId() = 0;
// Old stuff from old projects, "that's how we serialized back in 2010! Ohh good ol' times!"
//
// virtual void readFromFile(FILE* file) = 0;
// virtual void writeToFile(FILE* file) = 0;
//
// int getId();
//
// //static stuff
// static vector<SerializedObject *> getAllSerializedObjects();
// static SerializedObject *getSerializedObjectForId(int id);
// static int getIDForSerializedObject(SerializedObject *object);
//
// static unsigned int getNumberOfSerializedObjects();
// static void stopIndexing();
// static void startIndexing();
// //makes sure the first id of indexedObjects is 0
// static void addSerializedObjectsToBeginning(
// vector<SerializedObject*> indexedObjects);
//
//private:
// static vector<SerializedObject*> allGameObjects;
// static bool indexingStopped;
};
} // namespace nw
#endif /* DESCRIBED_OBJECT_H_ */