9 DBCFile(const std::string
&filename
);
12 // Open database. It must be openened before it can be used.
15 // Database exceptions
19 Exception(const std::string
&message
): message(message
)
23 const std::string
&getMessage() {return message
;}
27 class NotFound
: public Exception
30 NotFound(): Exception("Key was not found")
33 // Iteration over database
38 float getFloat(size_t field
) const
40 assert(field
< file
.fieldCount
);
41 return *reinterpret_cast<float*>(offset
+field
*4);
43 unsigned int getUInt(size_t field
) const
45 assert(field
< file
.fieldCount
);
46 return *reinterpret_cast<unsigned int*>(offset
+field
*4);
48 int getInt(size_t field
) const
50 assert(field
< file
.fieldCount
);
51 return *reinterpret_cast<int*>(offset
+field
*4);
53 const char *getString(size_t field
) const
55 assert(field
< file
.fieldCount
);
56 size_t stringOffset
= getUInt(field
);
57 assert(stringOffset
< file
.stringSize
);
58 return reinterpret_cast<char*>(file
.stringTable
+ stringOffset
);
61 Record(DBCFile
&file
, unsigned char *offset
): file(file
), offset(offset
) {}
62 unsigned char *offset
;
66 friend class DBCFile::Iterator
;
68 /** Iterator that iterates over records
73 Iterator(DBCFile
&file
, unsigned char *offset
):
74 record(file
, offset
) {}
75 /// Advance (prefix only)
76 Iterator
& operator++() {
77 record
.offset
+= record
.file
.recordSize
;
80 /// Return address of current instance
81 Record
const & operator*() const { return record
; }
82 const Record
* operator->() const {
86 bool operator==(const Iterator
&b
) const
88 return record
.offset
== b
.record
.offset
;
90 bool operator!=(const Iterator
&b
) const
92 return record
.offset
!= b
.record
.offset
;
99 Record
getRecord(size_t id
);
100 /// Get begin iterator over records
102 /// Get begin iterator over records
105 size_t getRecordCount() const { return recordCount
;}
106 size_t getFieldCount() const { return fieldCount
; }
109 std::string filename
;
115 unsigned char *stringTable
;