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.
23 * Declares TableMgr class, abstract loader for Table objects (.2DA files)
24 * @author The GemRB Project
37 * Abstract loader for Table objects (.2DA files)
40 class GEM_EXPORT TableMgr
: public Plugin
{
44 /** Returns the actual number of Rows in the Table */
45 virtual ieDword
GetRowCount() const = 0;
46 /** Returns the number of Columns in the Table */
47 virtual ieDword
GetColNamesCount() const = 0;
48 /** Returns the actual number of Columns in a row */
49 virtual ieDword
GetColumnCount(unsigned int row
= 0) const = 0;
50 /** Returns a pointer to a zero terminated 2da element,
51 * 0,0 returns the default value, it may return NULL */
52 virtual const char* QueryField(unsigned int row
= 0, unsigned int column
= 0) const = 0;
53 /** Returns a pointer to a zero terminated 2da element,
54 * uses column name and row name to search the field,
56 virtual const char* QueryField(const char* row
, const char* column
) const = 0;
57 /** Returns default value of table. */
58 virtual const char* QueryDefault() const = 0;
59 virtual int GetColumnIndex(const char* colname
) const = 0;
60 virtual int GetRowIndex(const char* rowname
) const = 0;
61 virtual const char* GetColumnName(unsigned int index
) const = 0;
62 /** Returns a Row Name, returns NULL on error */
63 virtual const char* GetRowName(unsigned int index
) const = 0;
64 virtual int FindTableValue(unsigned int column
, long value
, int start
= 0) const = 0;
66 /** Opens a Table File */
67 virtual bool Open(DataStream
* stream
, bool autoFree
= true) = 0;
71 * Utility class to automatically handle loading a table,
72 * and obtain and free a reference to it.
74 class GEM_EXPORT AutoTable
78 AutoTable(const char* ResRef
);
80 AutoTable(const AutoTable
&);
81 AutoTable
& operator=(const AutoTable
&);
83 bool load(const char* ResRef
);
85 bool ok() const { return table
; }
86 operator bool() const { return table
; }
88 const TableMgr
& operator*() const { return *table
; }
89 const TableMgr
* operator->() const { return &*table
; }
90 const TableMgr
* ptr() const { return &*table
; }
93 Holder
<TableMgr
> table
;
94 unsigned int tableref
;
98 #endif // ! TABLEMGR_H