Scid  4.6.5
dbasepool.h
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2015 Fulvio Benini
3 
4 * This file is part of Scid (Shane's Chess Information Database).
5 *
6 * Scid is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
10 * Scid 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Scid. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef DBASEPOOL_H
20 #define DBASEPOOL_H
21 
22 #include <vector>
23 struct scidBaseT;
24 
25 
26 namespace DBasePool {
27 
28 
29 /**
30  * init() - initialize the pool of databases.
31  *
32  * Call this function just once at the beginning of the program.
33  */
34 void init();
35 
36 
37 /**
38  * closeAll() - close all the databases in the pool.
39  *
40  * Call this function just once before ending the program.
41  * This function close all the managed databases ensuring that
42  * resources are released and changes are flushed to disks.
43  */
44 void closeAll();
45 
46 
47 /**
48  * find() - search for a database.
49  * @filename: the filename of the wanted database.
50  * Database in native Scid format do not use extension ("example").
51  * Other databases require file extension ("example.pgn").
52  *
53  * Return:
54  * - the handle of the database corresponding to @filename.
55  * - 0 if not found.
56  */
57 int find(const char* filename);
58 
59 
60 /**
61  * getBase() - get a database from the pool.
62  * @baseHandle: the handle of the wanted database.
63  *
64  * Return:
65  * - a pointer to the scidBaseT object corresponding to @baseHandle.
66  * - 0 (nullptr) if @baseHandle is invalid.
67  */
68 scidBaseT* getBase(int baseHandle);
69 
70 
71 /**
72  * getClipBase() - return the handle of the clipbase
73  *
74  * The clipbase is a special memory database that is always open and valid.
75  * Return:
76  * - the handle of the clipbase.
77  */
78 int getClipBase();
79 
80 
81 /**
82  * getFreeSlot() - search for a free database slot.
83  *
84  * Return:
85  * - a pointer to an available scidBaseT object.
86  * - 0 (nullptr) if there are no free slots.
87  */
89 
90 
91 /**
92  * getHandles() - get the handles of opened databases.
93  *
94  * Return:
95  * - a std::vector containing the handles of opened databases.
96  */
97 std::vector<int> getHandles();
98 
99 
100 /**
101  * switchCurrent() - DEPRECATED.
102  * @dbase: a pointer to the new "current" database.
103  * If 0 the function just return the "current" database handle.
104  *
105  * Some legacy code assume that exist only one database.
106  * The hack to use that code is to make a database the "current" one.
107  * Return:
108  * - the handle of the new "current" database.
109  */
110 int switchCurrent(scidBaseT* dbase = 0);
111 
112 
113 } // End of namespace DBasePool
114 
115 
116 #endif
int switchCurrent(scidBaseT *dbase=0)
switchCurrent() - DEPRECATED.
Definition: dbasepool.cpp:84
void init()
init() - initialize the pool of databases.
Definition: dbasepool.cpp:37
scidBaseT * getBase(int baseHandle)
getBase() - get a database from the pool.
Definition: dbasepool.cpp:59
int find(const char *filename)
find() - search for a database.
Definition: dbasepool.cpp:51
void closeAll()
closeAll() - close all the databases in the pool.
Definition: dbasepool.cpp:46
scidBaseT * getFreeSlot()
getFreeSlot() - search for a free database slot.
Definition: dbasepool.cpp:69
int getClipBase()
getClipBase() - return the handle of the clipbase
Definition: dbasepool.cpp:65
std::vector< int > getHandles()
getHandles() - get the handles of opened databases.
Definition: dbasepool.cpp:76