Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_tinycdb.hpp
1/*
2##############################################################################
3# file: ms_tinycdb.hpp #
4# 'msparser' toolkit #
5# Used internally in Mascot Parser as well as being available externally #
6# #
7##############################################################################
8# COPYRIGHT NOTICE #
9# Copyright 1998-2009 Matrix Science Limited All Rights Reserved. #
10# #
11##############################################################################
12# $Archive:: /MowseBranches/ms_mascotresfile_1.2/include/ms_mascotresfi $ #
13# $Author: villek@matrixscience.com $ #
14# $Date: 2018-07-30 16:23:53 +0100 $ #
15# $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
16# $NoKeywords:: $ #
17##############################################################################
18*/
19
20#ifndef MS_TINYCDB_HPP
21#define MS_TINYCDB_HPP
22
23
24
25// Includes from the standard template library
26#include <string>
27#include <vector>
28
29// These values are the key names for special cases
30// User defined keys must not begin with "=0."
31#define CDBIDX_DUPE_ACCESSION "=0.1"
32#define CDBIDX_VERSION "=0.2"
33#define CDBIDX_FILE_TOO_LARGE "=0.3"
34#define CDBIDX_SRC_FILE_SIZE "=0.4"
35#define CDBIDX_SRC_FILE_DATE "=0.5"
36#define CDBIDX_BUGFIX_10627 "=0.6"
37
38
39// Need to be a bit less than 2Gb / 4Gb so that we can write the error strings...
40#define MAX_CDB_SIZE (OFFSET64_C(0xFFFFFFFFFFFF) - OFFSET64_C(0x1000000)) // 281,474,959,933,439 = 256 TB
41#define MAX_CDB_SIZE_STR "256TB"
42#define OLD_MAX_CDB_SIZE_STR_4GB "4Gb"
43#define OLD_MAX_32_BIT_CDB_SIZE (0x7FFFFFFF - 0x1000000)
44#define OLD_MAX_32_BIT_CDB_SIZE_STR "2Gb"
45
46
47// Forward declarations, so no need to include cdb.h
48struct cdb;
49struct cdb_make;
50
51
52namespace matrix_science {
53
59
123 class MS_MASCOTRESFILE_API ms_tinycdb : public ms_errors
124 {
125 public:
127 ms_tinycdb(const char * indexFileName,
128 const char * versionNumber,
129 const char * sourceFileName);
130
132 ~ms_tinycdb();
133
134
136 std::string getIndexFileName() const;
137
139 void setIndexFileName(const char * filename);
140
142 bool openIndexFile(const bool mayRetryBuilding);
143
145 void closeIndexFile();
146
148 bool isPossibleToCreate() const;
149
151 bool isOpenForReading() const;
152
154 bool isCreating() const;
155
157 bool prepareToCreate();
158
160 bool saveValueForKey(const char * keyName,
161 const char * value,
162 const unsigned int keyNameLen = 0,
163 const unsigned int valueLen = 0);
164
166 bool finishCreate();
167
169 std::string getValueFromKey(const std::string & keyName, const int count = 0);
170
172 std::vector<std::string> getAllValuesFromKey(const std::string & keyName);
173
175 OFFSET64_T getFileOffsetFromKey(const std::string & keyName);
176
178 bool saveFileOffsetForKey(const std::string & keyName, OFFSET64_T offset);
179
181 int getIntFromKey(const std::string & keyName);
182
184 int getIntFromKey(const std::string & keyName, bool & found);
185
187 bool saveIntForKey(const std::string & keyName, int value);
188
190 int makeExists(const char * key) const;
191
192
193 protected:
194 // Not safe to copy or assign this object.
195 ms_tinycdb(const ms_tinycdb & rhs);
196#ifndef SWIG
197 ms_tinycdb & operator=(const ms_tinycdb & rhs);
198#endif
199 private:
200 std::string indexFileName_;
201 std::string versionNumber_;
202 std::string sourceFileName_;
203 bool isPossibleToCreate_;
204 int fdCDB_;
205 struct cdb * cdb_;
206 struct cdb_make * cdbm_;
207 bool creatingCDB_;
208 OFFSET64_T calcFileSize_;
209 bool addKeyErrorReported_;
210 bool tooLargeErrorReported_;
211 bool cdbInitOK_;
212
213 bool lockFile(int hFile);
214 bool unlockFile(int hFile);
215 }; // end of tools_group
217} // matrix_science
218
219#endif // MS_TINYCDB_HPP
220
221/*------------------------------- End of File -------------------------------*/
This class is used as a base class for several Mascot Parser classes.
Definition: ms_errors.hpp:696
Wrapper for the public domain tinycdb package http://www.corpit.ru/mjt/tinycdb.html by Michael Tokare...
Definition: ms_tinycdb.hpp:124