Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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  * @param 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  * @returns
54  * - the handle of the database corresponding to @e 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  * @param baseHandle: the handle of the wanted database.
63  *
64  * @returns
65  * - the handle of the database corresponding to @e filename.
66  * - a pointer to the scidBaseT object corresponding to @e baseHandle.
67  * - 0 (nullptr) if @e baseHandle is invalid.
68  */
69 scidBaseT* getBase(int baseHandle);
70 
71 
72 /**
73  * getClipBase() - return the handle of the clipbase
74  *
75  * The clipbase is a special memory database that is always open and valid.
76  * @returns
77  * - the handle of the database corresponding to @e filename.
78  * - the handle of the clipbase.
79  */
80 int getClipBase();
81 
82 
83 /**
84  * getFreeSlot() - search for a free database slot.
85  *
86  * @returns
87  * - the handle of the database corresponding to @e filename.
88  * - a pointer to an available scidBaseT object.
89  * - 0 (nullptr) if there are no free slots.
90  */
92 
93 
94 /**
95  * getHandles() - get the handles of opened databases.
96  *
97  * @returns
98  * - the handle of the database corresponding to @e filename.
99  * - a std::vector containing the handles of opened databases.
100  */
101 std::vector<int> getHandles();
102 
103 
104 /**
105  * switchCurrent() - DEPRECATED.
106  * @param dbase: a pointer to the new "current" database.
107  * If 0 the function just return the "current" database handle.
108  *
109  * Some legacy code assume that exist only one database.
110  * The hack to use that code is to make a database the "current" one.
111  * @returns
112  * - the handle of the database corresponding to @e filename.
113  * - the handle of the new "current" database.
114  */
115 int switchCurrent(scidBaseT* dbase = 0);
116 
117 
118 } // End of namespace DBasePool
119 
120 
121 #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