3 #define __STORMLIB_SELF__
12 DBCFile(const std::string
&filename
);
15 // Open database. It must be openened before it can be used.
18 // TODO: Add a close function?
20 // Database exceptions
24 Exception(const std::string
&message
): message(message
)
28 const std::string
&getMessage() {return message
;}
34 class NotFound
: public Exception
37 NotFound(): Exception("Key was not found")
41 // Iteration over database
46 Record
& operator= (const Record
& r
)
52 float getFloat(size_t field
) const
54 assert(field
< file
.fieldCount
);
55 return *reinterpret_cast<float*>(offset
+field
*4);
57 unsigned int getUInt(size_t field
) const
59 assert(field
< file
.fieldCount
);
60 return *reinterpret_cast<unsigned int*>(offset
+(field
*4));
62 int getInt(size_t field
) const
64 assert(field
< file
.fieldCount
);
65 return *reinterpret_cast<int*>(offset
+field
*4);
67 unsigned char getByte(size_t ofs
) const
69 assert(ofs
< file
.recordSize
);
70 return *reinterpret_cast<unsigned char*>(offset
+ofs
);
72 const char *getString(size_t field
) const
74 assert(field
< file
.fieldCount
);
75 size_t stringOffset
= getUInt(field
);
76 assert(stringOffset
< file
.stringSize
);
77 //char * tmp = (char*)file.stringTable + stringOffset;
78 //unsigned char * tmp2 = file.stringTable + stringOffset;
79 return reinterpret_cast<char*>(file
.stringTable
+ stringOffset
);
82 Record(DBCFile
&file
, unsigned char *offset
): file(file
), offset(offset
) {}
83 unsigned char *offset
;
87 friend class Iterator
;
90 /* Iterator that iterates over records */
94 Iterator(DBCFile
&file
, unsigned char *offset
):
95 record(file
, offset
) {}
96 /// Advance (prefix only)
97 Iterator
& operator++() {
98 record
.offset
+= record
.file
.recordSize
;
101 /// Return address of current instance
102 Record
const & operator*() const { return record
; }
103 const Record
* operator->() const {
107 bool operator==(const Iterator
&b
) const
109 return record
.offset
== b
.record
.offset
;
111 bool operator!=(const Iterator
&b
) const
113 return record
.offset
!= b
.record
.offset
;
120 Record
getRecord(size_t id
);
121 /// Get begin iterator over records
123 /// Get begin iterator over records
126 size_t getRecordCount() const { return recordCount
;}
127 size_t getFieldCount() const { return fieldCount
; }
130 std::string filename
;
136 unsigned char *stringTable
;