2 * AdPlug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (c) 1999 - 2003 Simon Peter <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * database.h - AdPlug database class
20 * Copyright (c) 2002 Riven the Mage <riven@ok.ru>
21 * Copyright (c) 2002, 2003 Simon Peter <dn.tlp@gmx.net>
24 #ifndef H_ADPLUG_DATABASE
25 #define H_ADPLUG_DATABASE
43 bool operator==(const CKey &key);
46 void make(binistream &in);
52 typedef enum { Plain, SongInfo, ClockSpeed } RecordType;
56 std::string filetype, comment;
58 static CRecord *factory(RecordType type);
59 static CRecord *factory(binistream &in);
64 void write(binostream &out);
66 bool user_read(std::istream &in, std::ostream &out);
67 bool user_write(std::ostream &out);
70 virtual void read_own(binistream &in) = 0;
71 virtual void write_own(binostream &out) = 0;
72 virtual unsigned long get_size() = 0;
73 virtual bool user_read_own(std::istream &in, std::ostream &out) = 0;
74 virtual bool user_write_own(std::ostream &out) = 0;
80 bool load(std::string db_name);
81 bool load(binistream &f);
82 bool save(std::string db_name);
83 bool save(binostream &f);
85 bool insert(CRecord *record);
87 void wipe(CRecord *record);
90 CRecord *search(CKey const &key);
91 bool lookup(CKey const &key);
93 CRecord *get_record();
102 static const unsigned short hash_radix;
113 DB_Bucket(unsigned long nindex, CRecord *newrecord, DB_Bucket *newchain = 0);
117 DB_Bucket **db_linear;
118 DB_Bucket **db_hashed;
120 unsigned long linear_index, linear_logic_length, linear_length;
122 unsigned long make_hash(CKey const &key);
125 class CPlainRecord: public CAdPlugDatabase::CRecord
128 CPlainRecord() { type = Plain; }
131 virtual void read_own(binistream &in) {}
132 virtual void write_own(binostream &out) {}
133 virtual unsigned long get_size() { return 0; }
134 virtual bool user_read_own(std::istream &in, std::ostream &out) { return true; }
135 virtual bool user_write_own(std::ostream &out) { return true; }
138 class CInfoRecord: public CAdPlugDatabase::CRecord
147 virtual void read_own(binistream &in);
148 virtual void write_own(binostream &out);
149 virtual unsigned long get_size();
150 virtual bool user_read_own(std::istream &in, std::ostream &out);
151 virtual bool user_write_own(std::ostream &out);
154 class CClockRecord: public CAdPlugDatabase::CRecord
162 virtual void read_own(binistream &in);
163 virtual void write_own(binostream &out);
164 virtual unsigned long get_size();
165 virtual bool user_read_own(std::istream &in, std::ostream &out);
166 virtual bool user_write_own(std::ostream &out);