LCOV - code coverage report
Current view: top level - backends - uuids.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7822d31adece Lines: 13 13 100.0 %
Date: 2019-05-23 11:15:29 Functions: 6 6 100.0 %
Branches: 4 4 100.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file uuids.h
       2                 :            :  * @brief Class for handling UUIDs
       3                 :            :  */
       4                 :            : /* Copyright 2008 Lemur Consulting Ltd
       5                 :            :  * Copyright 2009,2010,2013,2016,2018 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_UUIDS_H
      23                 :            : #define XAPIAN_INCLUDED_UUIDS_H
      24                 :            : 
      25                 :            : #include <cstring>
      26                 :            : #include <string>
      27                 :            : 
      28                 :            : class Uuid {
      29                 :            :   public:
      30                 :            :     /// The size of a UUID in bytes.
      31                 :            :     static constexpr unsigned BINARY_SIZE = 16;
      32                 :            : 
      33                 :            :     /// The size of a UUID string in bytes (not including trailing '\0').
      34                 :            :     static constexpr unsigned STRING_SIZE = 36;
      35                 :            : 
      36                 :       4717 :     Uuid() {}
      37                 :            : 
      38                 :            :     void generate();
      39                 :            : 
      40                 :            :     void parse(const char* in);
      41                 :            : 
      42                 :          4 :     void parse(const std::string& in) { return parse(in.data()); }
      43                 :            : 
      44                 :            :     // Not currently used.
      45                 :          1 :     void clear() {
      46                 :          1 :         std::memset(uuid_data, 0, BINARY_SIZE);
      47                 :          1 :     }
      48                 :            : 
      49                 :            :     // Not currently used.
      50                 :          4 :     bool is_null() const {
      51         [ +  + ]:         20 :         for (char ch : uuid_data) {
      52         [ +  + ]:         19 :             if (ch)
      53                 :          3 :                 return false;
      54                 :            :         }
      55                 :          1 :         return true;
      56                 :            :     }
      57                 :            : 
      58                 :            :     std::string to_string() const;
      59                 :            : 
      60                 :      10406 :     const char* data() const {
      61                 :      10406 :         return reinterpret_cast<const char*>(uuid_data);
      62                 :            :     }
      63                 :            : 
      64                 :       3458 :     void assign(const char* p) { std::memcpy(uuid_data, p, BINARY_SIZE); }
      65                 :            : 
      66                 :            :   private:
      67                 :            :     /// The UUID data.
      68                 :            :     unsigned char uuid_data[BINARY_SIZE];
      69                 :            : };
      70                 :            : 
      71                 :            : #endif /* XAPIAN_INCLUDED_UUIDS_H */

Generated by: LCOV version 1.11