2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "Platform/Define.h"
22 #include "Utilities/ByteConverter.h"
27 FT_NA
='x', //not used or unknown, 4 byte size
28 FT_NA_BYTE
='X', //not used or unknown, byte
29 FT_STRING
='s', //char*
33 FT_SORT
='d', //sorted by this field, field is not included
34 FT_IND
='n', //the same,but parsed to data
35 FT_LOGIC
='l' //Logical (boolean)
44 bool Load(const char *filename
, const char *fmt
);
49 float getFloat(size_t field
) const
51 assert(field
< file
.fieldCount
);
52 float val
= *reinterpret_cast<float*>(offset
+file
.GetOffset(field
));
56 uint32
getUInt(size_t field
) const
58 assert(field
< file
.fieldCount
);
59 uint32 val
= *reinterpret_cast<uint32
*>(offset
+file
.GetOffset(field
));
63 uint8
getUInt8(size_t field
) const
65 assert(field
< file
.fieldCount
);
66 return *reinterpret_cast<uint8
*>(offset
+file
.GetOffset(field
));
69 const char *getString(size_t field
) const
71 assert(field
< file
.fieldCount
);
72 size_t stringOffset
= getUInt(field
);
73 assert(stringOffset
< file
.stringSize
);
74 return reinterpret_cast<char*>(file
.stringTable
+ stringOffset
);
78 Record(DBCFile
&file_
, unsigned char *offset_
): offset(offset_
), file(file_
) {}
79 unsigned char *offset
;
87 Record
getRecord(size_t id
);
88 /// Get begin iterator over records
90 uint32
GetNumRows() const { return recordCount
;}
91 uint32
GetCols() const { return fieldCount
; }
92 uint32
GetOffset(size_t id
) const { return (fieldsOffset
!= NULL
&& id
< fieldCount
) ? fieldsOffset
[id
] : 0; }
93 bool IsLoaded() {return (data
!=NULL
);}
94 char* AutoProduceData(const char* fmt
, uint32
& count
, char**& indexTable
);
95 char* AutoProduceStrings(const char* fmt
, char* dataTable
);
96 static uint32
GetFormatRecordSize(const char * format
, int32
* index_pos
= NULL
);
103 uint32
*fieldsOffset
;
105 unsigned char *stringTable
;