Matrix Science header

ms_tinycdb.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_tinycdb.hpp                                                      #
00004 # 'msparser' toolkit                                                         #
00005 # Used internally in Mascot Parser as well as being available externally     #
00006 #                                                                            #
00007 ##############################################################################
00008 # COPYRIGHT NOTICE                                                           #
00009 # Copyright 1998-2009 Matrix Science Limited  All Rights Reserved.           #
00010 #                                                                            #
00011 ##############################################################################
00012 #    $Archive:: /MowseBranches/ms_mascotresfile_1.2/include/ms_mascotresfi $ #
00013 #     $Author: villek@matrixscience.com $ #
00014 #       $Date: 2018-07-30 16:23:53 +0100 $ #
00015 #   $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $ #
00016 # $NoKeywords::                                                            $ #
00017 ##############################################################################
00018 */
00019 
00020 #ifndef MS_TINYCDB_HPP
00021 #define MS_TINYCDB_HPP
00022 
00023 
00024 
00025 // Includes from the standard template library
00026 #include <string>
00027 #include <vector>
00028 
00029 // These values are the key names for special cases
00030 // User defined keys must not begin with "=0."
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 // Need to be a bit less than 2Gb / 4Gb so that we can write the error strings...
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 // Forward declarations, so no need to include cdb.h
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             // Not safe to copy or assign this object.
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     }; // end of tools_group
00217 } // matrix_science
00218 
00219 #endif // MS_TINYCDB_HPP
00220 
00221 /*------------------------------- End of File -------------------------------*/

Copyright © 2022 Matrix Science Ltd.  All Rights Reserved. Generated on Thu Mar 31 2022 01:12:30