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;
65 virtual int FindTableValue(unsigned int column
, const char* value
, int start
= 0) const = 0;
67 /** Opens a Table File */
68 virtual bool Open(DataStream
* stream
, bool autoFree
= true) = 0;
72 * Utility class to automatically handle loading a table,
73 * and obtain and free a reference to it.
75 class GEM_EXPORT AutoTable
79 AutoTable(const char* ResRef
);
81 AutoTable(const AutoTable
&);
82 AutoTable
& operator=(const AutoTable
&);
84 bool load(const char* ResRef
);
86 bool ok() const { return table
; }
87 operator bool() const { return table
; }
89 const TableMgr
& operator*() const { return *table
; }
90 const TableMgr
* operator->() const { return &*table
; }
91 const TableMgr
* ptr() const { return &*table
; }
94 Holder
<TableMgr
> table
;
95 unsigned int tableref
;
99 #endif // ! TABLEMGR_H