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: davidc $ #
00014 #       $Date: 2016/11/03 14:54:41 $ #
00015 #   $Revision: 1.15 $ #
00016 # $NoKeywords::                                                            $ #
00017 ##############################################################################
00018 */
00019 
00020 #ifndef MS_TINYCDB_HPP
00021 #define MS_TINYCDB_HPP
00022 
00023 #ifdef _WIN32
00024 #pragma warning(disable:4251)   // Don't want all classes to be exported
00025 #pragma warning(disable:4786)   // Debug symbols too long
00026 #   ifndef _MATRIX_USE_STATIC_LIB
00027 #       ifdef MS_MASCOTRESFILE_EXPORTS
00028 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00029 #       else
00030 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00031 #       endif
00032 #   else
00033 #       define MS_MASCOTRESFILE_API
00034 #   endif
00035 #else
00036 #   define MS_MASCOTRESFILE_API
00037 #endif
00038 
00039 
00040 // Includes from the standard template library
00041 #include <string>
00042 #include <vector>
00043 
00044 // These values are the key names for special cases
00045 // User defined keys must not begin with "=0."
00046 #define CDBIDX_DUPE_ACCESSION   "=0.1"
00047 #define CDBIDX_VERSION          "=0.2"
00048 #define CDBIDX_FILE_TOO_LARGE   "=0.3"
00049 #define CDBIDX_SRC_FILE_SIZE    "=0.4"
00050 #define CDBIDX_SRC_FILE_DATE    "=0.5"
00051 #define CDBIDX_BUGFIX_10627     "=0.6"
00052 
00053 
00054 // Need to be a bit less than 2Gb / 4Gb so that we can write the error strings...
00055 #define MAX_CDB_SIZE                 (OFFSET64_C(0xFFFFFFFFFFFF) - OFFSET64_C(0x1000000)) // 281,474,959,933,439 = 256 TB
00056 #define MAX_CDB_SIZE_STR             "256TB"
00057 #define OLD_MAX_CDB_SIZE_STR_4GB     "4Gb"
00058 #define OLD_MAX_32_BIT_CDB_SIZE      (0x7FFFFFFF - 0x1000000)
00059 #define OLD_MAX_32_BIT_CDB_SIZE_STR  "2Gb"
00060 
00061 
00062 // Forward declarations, so no need to include cdb.h
00063 struct cdb;
00064 struct cdb_make;
00065 
00066 
00067 namespace matrix_science {
00068 
00073 
00074 
00138     class MS_MASCOTRESFILE_API ms_tinycdb : public ms_errors
00139     {
00140         public:
00142             ms_tinycdb(const char * indexFileName,
00143                        const char * versionNumber, 
00144                        const char * sourceFileName);
00145 
00147             ~ms_tinycdb();
00148 
00149 
00151             std::string getIndexFileName() const;
00152 
00154             void setIndexFileName(const char * filename);
00155 
00157             bool openIndexFile(const bool mayRetryBuilding);
00158 
00160             void closeIndexFile();
00161 
00163             bool isPossibleToCreate() const;
00164 
00166             bool isOpenForReading() const;
00167 
00169             bool isCreating() const;
00170 
00172             bool prepareToCreate();
00173 
00175             bool saveValueForKey(const char * keyName, 
00176                                  const char * value,
00177                                  const unsigned int keyNameLen = 0,
00178                                  const unsigned int valueLen = 0);
00179 
00181             bool finishCreate();
00182 
00184             std::string getValueFromKey(const std::string & keyName, const int count = 0);
00185 
00187             std::vector<std::string> getAllValuesFromKey(const std::string & keyName);
00188 
00190             OFFSET64_T getFileOffsetFromKey(const std::string & keyName);
00191 
00193             bool saveFileOffsetForKey(const std::string & keyName, OFFSET64_T offset);
00194 
00196             int getIntFromKey(const std::string & keyName);
00197 
00199             int getIntFromKey(const std::string & keyName, bool & found);
00200 
00202             bool saveIntForKey(const std::string & keyName, int value);
00203 
00205             int makeExists(const char * key) const;
00206 
00207 
00208         protected:  
00209             // Not safe to copy or assign this object.
00210             ms_tinycdb(const ms_tinycdb & rhs);
00211 #ifndef SWIG
00212             ms_tinycdb & operator=(const ms_tinycdb & rhs);
00213 #endif
00214         private:
00215             std::string  indexFileName_;
00216             std::string  versionNumber_;
00217             std::string  sourceFileName_;
00218             bool         isPossibleToCreate_;
00219             int          fdCDB_;
00220             struct cdb      * cdb_;
00221             struct cdb_make * cdbm_;
00222             bool         creatingCDB_;
00223             OFFSET64_T   calcFileSize_;
00224             bool         addKeyErrorReported_;
00225             bool         tooLargeErrorReported_;
00226             bool         cdbInitOK_;
00227 
00228             bool lockFile(int hFile);
00229             bool unlockFile(int hFile);
00230     }; // end of tools_group
00232 } // matrix_science
00233 
00234 #endif // MS_TINYCDB_HPP
00235 
00236 /*------------------------------- End of File -------------------------------*/
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51