00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MS_TINYCDB_HPP
00021 #define MS_TINYCDB_HPP
00022
00023
00024
00025
00026 #include <string>
00027 #include <vector>
00028
00029
00030
00031 #define CDBIDX_DUPE_ACCESSION "=0.1"
00032 #define CDBIDX_VERSION "=0.2"
00033 #define CDBIDX_FILE_TOO_LARGE "=0.3"
00034 #define CDBIDX_SRC_FILE_SIZE "=0.4"
00035 #define CDBIDX_SRC_FILE_DATE "=0.5"
00036 #define CDBIDX_BUGFIX_10627 "=0.6"
00037
00038
00039
00040 #define MAX_CDB_SIZE (OFFSET64_C(0xFFFFFFFFFFFF) - OFFSET64_C(0x1000000)) // 281,474,959,933,439 = 256 TB
00041 #define MAX_CDB_SIZE_STR "256TB"
00042 #define OLD_MAX_CDB_SIZE_STR_4GB "4Gb"
00043 #define OLD_MAX_32_BIT_CDB_SIZE (0x7FFFFFFF - 0x1000000)
00044 #define OLD_MAX_32_BIT_CDB_SIZE_STR "2Gb"
00045
00046
00047
00048 struct cdb;
00049 struct cdb_make;
00050
00051
00052 namespace matrix_science {
00053
00058
00059
00123 class MS_MASCOTRESFILE_API ms_tinycdb : public ms_errors
00124 {
00125 public:
00127 ms_tinycdb(const char * indexFileName,
00128 const char * versionNumber,
00129 const char * sourceFileName);
00130
00132 ~ms_tinycdb();
00133
00134
00136 std::string getIndexFileName() const;
00137
00139 void setIndexFileName(const char * filename);
00140
00142 bool openIndexFile(const bool mayRetryBuilding);
00143
00145 void closeIndexFile();
00146
00148 bool isPossibleToCreate() const;
00149
00151 bool isOpenForReading() const;
00152
00154 bool isCreating() const;
00155
00157 bool prepareToCreate();
00158
00160 bool saveValueForKey(const char * keyName,
00161 const char * value,
00162 const unsigned int keyNameLen = 0,
00163 const unsigned int valueLen = 0);
00164
00166 bool finishCreate();
00167
00169 std::string getValueFromKey(const std::string & keyName, const int count = 0);
00170
00172 std::vector<std::string> getAllValuesFromKey(const std::string & keyName);
00173
00175 OFFSET64_T getFileOffsetFromKey(const std::string & keyName);
00176
00178 bool saveFileOffsetForKey(const std::string & keyName, OFFSET64_T offset);
00179
00181 int getIntFromKey(const std::string & keyName);
00182
00184 int getIntFromKey(const std::string & keyName, bool & found);
00185
00187 bool saveIntForKey(const std::string & keyName, int value);
00188
00190 int makeExists(const char * key) const;
00191
00192
00193 protected:
00194
00195 ms_tinycdb(const ms_tinycdb & rhs);
00196 #ifndef SWIG
00197 ms_tinycdb & operator=(const ms_tinycdb & rhs);
00198 #endif
00199 private:
00200 std::string indexFileName_;
00201 std::string versionNumber_;
00202 std::string sourceFileName_;
00203 bool isPossibleToCreate_;
00204 int fdCDB_;
00205 struct cdb * cdb_;
00206 struct cdb_make * cdbm_;
00207 bool creatingCDB_;
00208 OFFSET64_T calcFileSize_;
00209 bool addKeyErrorReported_;
00210 bool tooLargeErrorReported_;
00211 bool cdbInitOK_;
00212
00213 bool lockFile(int hFile);
00214 bool unlockFile(int hFile);
00215 };
00217 }
00218
00219 #endif // MS_TINYCDB_HPP
00220
00221