1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef NL_DB_REFERENCE_FILE_H
18 #define NL_DB_REFERENCE_FILE_H
20 #include <nel/misc/types_nl.h>
21 #include <nel/misc/stream.h>
22 #include <nel/misc/debug.h>
23 #include <nel/misc/path.h>
27 #include "pd_server_utils.h"
32 * \author Benjamin Legros
33 * \author Nevrax France
36 class CDBReferenceFile
: public CMixedStreamFile
46 /// Setup file name and path
47 void setup(const std::string
& name
, const std::string
& path
, uint32 baseIndex
, uint32 overIndex
, uint32 rowSize
);
49 /// Clear initial setup
53 bool initialised() const { return _Init
; }
60 * Builds an empty file
69 * Prewrite reference file.
70 * At least, read file header to known the base and index index in file
72 bool prewrite(bool failIfNotExist
= false);
75 * Update Start/End Delta Ids
77 bool updateDeltaIds(uint32 startId
, uint32 endId
);
80 * Get Start/End Delta Ids
82 void getUpdateDeltaIds(uint32
& startId
, uint32
& endId
);
85 * Update a row in the reference file
86 * \param index is the absolute row index to update, not relative to file base index
87 * \param data is the data buffer to store in file
89 bool update(uint32 index
, const uint8
* rowdata
);
92 * Postwrite reference file
93 * Mark file as valid, close file, flush anything still alive...
103 * Preload reference file.
104 * At least, read file header to known the base and index index in file
109 * Read a row in the reference file
110 * \param index is the absolute row index to read, not relative to file base index
111 * \param data is the data buffer to store data read from file
113 bool read(uint32 index
, uint8
* rowdata
);
122 * Get standard row header size
124 static uint32
getRowHeaderSize() { return sizeof(uint32
); }
127 * Get reference file name
129 static std::string
getRefFileName(uint32 tableId
, uint32 refFile
) { return NLMISC::toString("%04X_%04X.%s", tableId
, refFile
, getRefFileExt().c_str()); }
132 * Get reference file name
134 static bool isRefFile(const std::string
& filename
, uint32
& tableId
, uint32
& refFile
)
136 return sscanf(NLMISC::CFile::getFilename(filename
).c_str(), "%X_%X.dbref", &tableId
, &refFile
) == 2;
140 * Get reference file name extension
142 static std::string
getRefFileExt() { return "dbref"; }
145 uint32
getBaseIndex() const { return _Header
.BaseIndex
; }
148 uint32
getEndIndex() const { return _Header
.EndIndex
; }
151 uint32
getTimestamp() const { return _Header
.Timestamp
; }
154 void setDeltaIds(uint32 startId
, uint32 endId
) { _Header
.StartDeltaId
= startId
; _Header
.EndDeltaId
= endId
; }
157 void getDeltaIds(uint32
& startId
, uint32
& endId
) { startId
= _Header
.StartDeltaId
; endId
= _Header
.EndDeltaId
; }
179 /// End Index, last index in file plus 1
182 /// Over Index, last index file can contain plus 1, base index in next reference file
185 /// Row size, only declared size
188 /// Row Size, in byte (all headers included)
194 /// Start Delta Id, used to check delta concatenation
197 /// End Delta Id, used to check delta concatenation
200 void serial(NLMISC::IStream
& s
)
202 s
.serialCheck(NELID("RHdr"));
203 uint version
= s
.serialVersion(0);
209 s
.serial(FullRowSize
);
212 s
.serial(StartDeltaId
);
213 s
.serial(EndDeltaId
);
226 /// Header of the reference
238 /// Data start position
241 /// Serial file header
244 uint32
getSeekPos(uint32 index
) { return _DataStart
+ _Header
.FullRowSize
*(index
-_Header
.BaseIndex
); }
250 #endif // NL_DB_REFERENCE_FILE_H
252 /* End of db_reference_file.h */