1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef P2DAIMPORTER_H
22 #define P2DAIMPORTER_H
30 typedef std::vector
< char*> RowEntry
;
32 class p2DAImporter
: public TableMgr
{
36 std::vector
< char*> colNames
;
37 std::vector
< char*> rowNames
;
38 std::vector
< char*> ptrs
;
39 std::vector
< RowEntry
> rows
;
44 bool Open(DataStream
* stream
, bool autoFree
= true);
45 /** Returns the actual number of Rows in the Table */
46 inline ieDword
GetRowCount() const
48 return ( ieDword
) rows
.size();
51 inline ieDword
GetColNamesCount() const
53 return (ieDword
) colNames
.size();
56 /** Returns the actual number of Columns in the Table */
57 inline ieDword
GetColumnCount(unsigned int row
= 0) const
59 if (rows
.size() <= row
) {
62 return ( ieDword
) rows
[row
].size();
64 /** Returns a pointer to a zero terminated 2da element,
65 if it cannot return a value, it returns the default */
66 inline const char* QueryField(unsigned int row
= 0, unsigned int column
= 0) const
68 if (rows
.size() <= row
) {
69 return ( char * ) defVal
;
71 if (rows
[row
].size() <= column
) {
72 return ( char * ) defVal
;
74 if (rows
[row
][column
][0]=='*' && !rows
[row
][column
][1]) {
75 return ( char * ) defVal
;
77 return rows
[row
][column
];
79 /** Returns a pointer to a zero terminated 2da element,
80 uses column name and row name to search the field */
81 inline const char* QueryField(const char* row
, const char* column
) const
85 rowi
= GetRowIndex(row
);
88 return ( char * ) defVal
;
91 coli
= GetColumnIndex(column
);
94 return ( char * ) defVal
;
97 return QueryField((unsigned int) rowi
, (unsigned int) coli
);
100 virtual const char* QueryDefault() const
105 inline int GetRowIndex(const char* string
) const
107 for (unsigned int index
= 0; index
< rowNames
.size(); index
++) {
108 if (stricmp( rowNames
[index
], string
) == 0) {
115 inline int GetColumnIndex(const char* string
) const
117 for (unsigned int index
= 0; index
< colNames
.size(); index
++) {
118 if (stricmp( colNames
[index
], string
) == 0) {
125 inline const char* GetColumnName(unsigned int index
) const
127 if (index
< colNames
.size()) {
128 return colNames
[index
];
133 inline const char* GetRowName(unsigned int index
) const
135 if (index
< rowNames
.size()) {
136 return rowNames
[index
];
141 inline int FindTableValue(unsigned int col
, long val
, int start
) const
146 for (row
= start
; row
< max
; row
++) {
147 const char* ret
= QueryField( row
, col
);
149 if (valid_number( ret
, Value
) && (Value
== val
) )