Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / pipeline_max / storage_object.h
blobe05fb755b31abd551630b9f1c3e87e6cefa26582
1 /**
2 * \file storage_object.h
3 * \brief CStorageObject
4 * \date 2012-08-18 09:02GMT
5 * \author Jan Boon (Kaetemi)
6 * CStorageObject
7 */
9 /*
10 * Copyright (C) 2012 by authors
12 * This file is part of RYZOM CORE PIPELINE.
13 * RYZOM CORE PIPELINE is free software: you can redistribute it
14 * and/or modify it under the terms of the GNU Affero General Public
15 * License as published by the Free Software Foundation, either
16 * version 3 of the License, or (at your option) any later version.
18 * RYZOM CORE PIPELINE is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
23 * You should have received a copy of the GNU Affero General Public
24 * License along with RYZOM CORE PIPELINE. If not, see
25 * <http://www.gnu.org/licenses/>.
28 #ifndef PIPELINE_STORAGE_OBJECT_H
29 #define PIPELINE_STORAGE_OBJECT_H
30 #include <nel/misc/types_nl.h>
32 // STL includes
33 #include <sstream>
35 // NeL includes
36 #include <nel/misc/stream.h>
38 // Project includes
40 namespace PIPELINE {
41 namespace MAX {
43 class CStorageChunks;
45 struct EStorage : public NLMISC::Exception
47 EStorage() : NLMISC::Exception("PIPELINE::MAX::EStorage") { }
48 EStorage(const char *msg) : NLMISC::Exception(msg) { }
49 virtual ~EStorage() throw() { }
52 struct EStorageParse : public EStorage
54 EStorageParse() : EStorage("PIPELINE::MAX::EStorageParse") { }
55 EStorageParse(const char *msg) : EStorage(msg) { }
56 virtual ~EStorageParse() throw() { }
59 enum TParseLevel
61 PARSE_INTERNAL = 0x00000001, // Directly parse basic class formats
62 PARSE_BUILTIN = 0x00000002, // Parse all builtin classes
63 // PARSE_NELDATA = 0x00000004, // Parse all structures related to nel specific data (nel material, node properties, etcetera)
64 // PARSE_NEL3D = 0x00000008, // Parse classes to initialize their nel3d equivalent classes
67 // IStorageObject : exposes serial(CStorageStream &stream) and dump(const std::string &pad)
68 class IStorageObject : public NLMISC::IStreamable
70 public:
71 IStorageObject();
72 virtual ~IStorageObject();
74 virtual std::string getClassName() { return className(); } // inherited from NLMISC::IClassable through NLMISC::IStreamable
75 virtual std::string className() const = 0; // renamed for constness
76 // virtual void serial(NLMISC::IStream &stream); // inherited from NLMISC::IStreamable
77 std::string toString();
78 virtual void toString(std::ostream &ostream, const std::string &pad = "") const = 0;
80 public: // should be protected but that doesn't compile, nice c++!
81 // Sets size when reading
82 virtual void setSize(sint32 size);
83 // Gets the size when writing, return false if unknown
84 virtual bool getSize(sint32 &size) const;
85 // Only true when inherting from CStorageContainer
86 virtual bool isContainer() const;
89 // CStorageContainer : serializes a container chunk
90 class CStorageContainer : public IStorageObject
92 public:
93 // public data
94 typedef std::pair<uint16, IStorageObject *> TStorageObjectWithId;
95 typedef std::list<TStorageObjectWithId> TStorageObjectContainer;
96 typedef TStorageObjectContainer::iterator TStorageObjectIterator;
97 typedef TStorageObjectContainer::const_iterator TStorageObjectConstIt;
99 protected:
100 // protected data
101 TStorageObjectContainer m_Chunks;
102 bool m_ChunksOwnsPointers;
104 public:
105 CStorageContainer();
106 virtual ~CStorageContainer();
108 // inherited
109 virtual std::string className() const;
110 virtual void serial(NLMISC::IStream &stream); // only used to wrap a container inside another stream
111 virtual void toString(std::ostream &ostream, const std::string &pad = "") const;
113 // utility
114 void serial(NLMISC::IStream &stream, uint size); // without wrapping, known size
116 // virtual
117 // Parse this class with given version and parse level filter
118 virtual void parse(uint16 version, uint filter = 0);
119 // Clean up built data or duplicate unparsed source data, call after serializing build and after parse
120 virtual void clean();
121 // Build the storage structure needed to store the parsed data back
122 virtual void build(uint16 version, uint filter = 0);
123 // Give ownership of the chunks back to the m_Chunks, must call build first, call instead of clean, reduces the parse level back to 0
124 virtual void disown();
126 public:
127 // read access
128 inline const TStorageObjectContainer &chunks() const { return m_Chunks; }
129 IStorageObject *findStorageObject(uint16 id, uint nb = 0) const; // find storage object with given id, nb count in case there are more
130 IStorageObject *findLastStorageObject(uint16 id) const;
132 public: // should be protected but that doesn't compile, nice c++!
133 // inherited
134 virtual bool isContainer() const;
136 protected:
137 // override in subclasses, default to parent if not handled
138 virtual void serial(CStorageChunks &chunks);
139 // Create a storage object by id, override to provide custom serialization
140 virtual IStorageObject *createChunkById(uint16 id, bool container);
144 // CStorageRaw : serializes raw data, use for unknown data
145 class CStorageRaw : public IStorageObject
147 public:
148 // public data
149 typedef std::vector<uint8> TType;
150 TType Value;
152 public:
153 CStorageRaw();
154 virtual ~CStorageRaw();
156 // inherited
157 virtual std::string className() const;
158 virtual void serial(NLMISC::IStream &stream);
159 virtual void toString(std::ostream &ostream, const std::string &pad = "") const;
161 public: // should be protected but that doesn't compile, nice c++!
162 // Sets size when reading
163 virtual void setSize(sint32 size);
164 // Gets the size when writing, return false if unknown
165 virtual bool getSize(sint32 &size) const;
169 } /* namespace MAX */
170 } /* namespace PIPELINE */
172 #endif /* #ifndef PIPELINE_STORAGE_OBJECT_H */
174 /* end of file */