Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / pipeline_max / storage_array.h
blob1f72f82135d5067eb37d913e07d3d66ad4d5f150
1 /**
2 * \file storage_array.h
3 * \brief CStorageArray
4 * \date 2012-08-21 11:33GMT
5 * \author Jan Boon (Kaetemi)
6 * CStorageArray
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_ARRAY_H
29 #define PIPELINE_STORAGE_ARRAY_H
30 #include <nel/misc/types_nl.h>
32 // STL includes
33 #include <vector>
35 // NeL includes
36 #include <nel/misc/ucstring.h>
37 #include <nel/misc/string_common.h>
39 // Project includes
40 #include "storage_object.h"
42 namespace PIPELINE {
43 namespace MAX {
45 ////////////////////////////////////////////////////////////////////////
46 ////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////
49 /**
50 * \brief CStorageArray
51 * \date 2012-08-21 11:33GMT
52 * \author Jan Boon (Kaetemi)
53 * WARNING: sizeof(TType) should match the serialized size,
54 * otherwise you must specialize the getSize and setSize functions!
56 template <typename T>
57 class CStorageArray : public IStorageObject
59 public:
60 // public data
61 typedef T TType;
62 typedef std::vector<TType> TTypeArray;
63 TTypeArray Value;
65 // inherited
66 virtual std::string className() const;
67 virtual void serial(NLMISC::IStream &stream);
68 virtual void toString(std::ostream &ostream, const std::string &pad = "") const;
70 public: // should be protected but that doesn't compile, nice c++!
71 // Sets size when reading
72 virtual void setSize(sint32 size);
73 // Gets the size when writing, return false if unknown
74 virtual bool getSize(sint32 &size) const;
75 }; /* class CStorageArray */
77 template <typename T>
78 std::string CStorageArray<T>::className() const
80 return "StorageArray";
83 template <typename T>
84 void CStorageArray<T>::serial(NLMISC::IStream &stream)
86 for (typename TTypeArray::iterator it = Value.begin(), end = Value.end(); it != end; ++it)
88 stream.serial(*it);
92 template <typename T>
93 void CStorageArray<T>::toString(std::ostream &ostream, const std::string &pad) const
95 ostream << "(" << className() << ") [" << Value.size() << "] { "; // << s << " } ";
96 uint i = 0;
97 for (typename TTypeArray::const_iterator it = Value.begin(), end = Value.end(); it != end; ++it)
99 std::string s = NLMISC::toString(*it);
100 //ostream << "\n" << pad << i << ": " << s;
101 ostream << "{ " << s << " } ";
102 ++i;
104 ostream << "} ";
107 template <typename T>
108 void CStorageArray<T>::setSize(sint32 size)
110 if (size % (sizeof(TType)) != 0)
111 nlerror("Size %i is not a multiple of value type size %i", size, sizeof(TType));
112 Value.resize(size / sizeof(TType));
115 template <typename T>
116 bool CStorageArray<T>::getSize(sint32 &size) const
118 size = Value.size() * sizeof(TType);
119 return true;
122 ////////////////////////////////////////////////////////////////////////
123 ////////////////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////////////////
126 template <typename T>
127 class CStorageArraySizePre : public CStorageArray<T>
129 public:
130 virtual std::string className() const;
131 virtual void serial(NLMISC::IStream &stream);
132 virtual void setSize(sint32 size);
133 virtual bool getSize(sint32 &size) const;
136 template <typename T>
137 std::string CStorageArraySizePre<T>::className() const
139 return "StorageArraySizePre";
142 template <typename T>
143 void CStorageArraySizePre<T>::serial(NLMISC::IStream &stream)
145 uint32 size = this->Value.size();
146 stream.serial(size);
147 nlassert(this->Value.size() == size);
148 CStorageArray<T>::serial(stream);
151 template <typename T>
152 void CStorageArraySizePre<T>::setSize(sint32 size)
154 CStorageArray<T>::setSize(size - sizeof(uint32));
157 template <typename T>
158 bool CStorageArraySizePre<T>::getSize(sint32 &size) const
160 size = CStorageArray<T>::getSize(size) + sizeof(uint32);
161 return true;
164 ////////////////////////////////////////////////////////////////////////
165 ////////////////////////////////////////////////////////////////////////
166 ////////////////////////////////////////////////////////////////////////
168 /// Same as CStorageArraySizePre but with no sizeof checks.
169 /// Use when serializing variable sizes in type T.
170 template <typename T>
171 class CStorageArrayDynSize : public CStorageArray<T>
173 public:
174 virtual std::string className() const;
175 virtual void serial(NLMISC::IStream &stream);
176 virtual void setSize(sint32 size);
177 virtual bool getSize(sint32 &size) const;
180 template <typename T>
181 std::string CStorageArrayDynSize<T>::className() const
183 return "StorageArrayDynSize";
186 template <typename T>
187 void CStorageArrayDynSize<T>::serial(NLMISC::IStream &stream)
189 uint32 size = this->Value.size();
190 stream.serial(size);
191 this->Value.resize(size);
192 CStorageArray<T>::serial(stream);
195 template <typename T>
196 void CStorageArrayDynSize<T>::setSize(sint32 size)
198 // Nothing to do here!
201 template <typename T>
202 bool CStorageArrayDynSize<T>::getSize(sint32 &size) const
204 // Nothing to do here!
205 return false;
208 ////////////////////////////////////////////////////////////////////////
209 ////////////////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////////////////
212 } /* namespace MAX */
213 } /* namespace PIPELINE */
215 #endif /* #ifndef PIPELINE_STORAGE_ARRAY_H */
217 /* end of file */