LCOV - code coverage report
Current view: top level - backends/flint - flint_version.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 7 7 100.0 %
Date: 2011-08-21 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file flint_version.h
       2                 :            :  * @brief FlintVersion class
       3                 :            :  */
       4                 :            : /* Copyright (C) 2006,2007,2008,2009 Olly Betts
       5                 :            :  *
       6                 :            :  * This program 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; either version 2 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef OM_HGUARD_FLINT_VERSION_H
      22                 :            : #define OM_HGUARD_FLINT_VERSION_H
      23                 :            : 
      24                 :            : #include <cstring>
      25                 :            : #include <string>
      26                 :            : 
      27                 :            : #include "common/safeuuid.h"
      28                 :            : 
      29                 :            : /** The FlintVersion class manages the "iamflint" file.
      30                 :            :  *
      31                 :            :  *  The "iamflint" file (currently) contains a "magic" string identifying
      32                 :            :  *  that this is a flint database and a database format version number.
      33                 :            :  */
      34                 :       1145 : class FlintVersion {
      35                 :            :     /// The filename of the version file.
      36                 :            :     std::string filename;
      37                 :            : 
      38                 :            :     /// The UUID of this database.
      39                 :            :     mutable uuid_t uuid;
      40                 :            : 
      41                 :            :     /// Generate a UUID if we don't already have one.
      42                 :            :     void ensure_uuid() const;
      43                 :            : 
      44                 :            :   public:
      45                 :       1145 :     FlintVersion(const std::string & dbdir)
      46                 :       1145 :         : filename(dbdir + "/iamflint") { }
      47                 :            : 
      48                 :            :     /** Create the version file. */
      49                 :            :     void create();
      50                 :            : 
      51                 :            :     /** Read the version file and check it's a version we understand.
      52                 :            :      *
      53                 :            :      *  @param readonly    true if the database is being opened readonly.
      54                 :            :      * 
      55                 :            :      *  On failure, an exception is thrown.
      56                 :            :      */
      57                 :            :     void read_and_check(bool readonly);
      58                 :            : 
      59                 :            :     /// Return pointer to 16 byte UUID.
      60                 :            :     const char * get_uuid() const {
      61                 :            :         ensure_uuid();
      62                 :            :         return reinterpret_cast<const char *>(uuid);
      63                 :            :     }
      64                 :            : 
      65                 :            :     /// Return UUID in the standard 36 character string format.
      66                 :       1395 :     std::string get_uuid_string() const {
      67                 :            :         char buf[37];
      68                 :       1395 :         ensure_uuid();
      69                 :       1395 :         uuid_unparse_lower(uuid, buf);
      70                 :       1395 :         return std::string(buf, 36);
      71                 :            :     }
      72                 :            : 
      73                 :            :     /// Set the UUID from 16 byte binary value @a data.
      74                 :            :     void set_uuid(void * data) {
      75                 :            :         std::memcpy(uuid, data, 16);
      76                 :            :     }
      77                 :            : 
      78                 :            :     /** Set the UUID from the standard 36 character string format.
      79                 :            :      *
      80                 :            :      *  @return true if @a s was successfully parsed; false otherwise.
      81                 :            :      */
      82                 :            :     bool set_uuid_string(const std::string & s) {
      83                 :            :         return uuid_parse(s.c_str(), uuid);
      84                 :            :     }
      85                 :            : };
      86                 :            : 
      87                 :            : #endif

Generated by: LCOV version 1.8