LCOV - code coverage report
Current view: top level - libgnucash/engine - gnc-backend-prov.hpp (source / functions) Coverage Total Hit
Test: gnucash.info Lines: 100.0 % 3 3
Test Date: 2025-02-07 16:25:45 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /********************************************************************\
       2                 :             :  * qofbackend-prov.hpp -- Manage creation of a QofBackend subclass.  *
       3                 :             :  *                                                                  *
       4                 :             :  * Copyright 2016 John Ralls <jralls@ceridwen.us>                   *
       5                 :             :  *                                                                  *
       6                 :             :  * This program is free software; you can redistribute it and/or    *
       7                 :             :  * modify it under the terms of the GNU General Public License as   *
       8                 :             :  * published by the Free Software Foundation; either version 2 of   *
       9                 :             :  * the License, or (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, contact:                        *
      18                 :             :  *                                                                  *
      19                 :             :  * Free Software Foundation           Voice:  +1-617-542-5942       *
      20                 :             :  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
      21                 :             :  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
      22                 :             :  *                                                                  *
      23                 :             : \********************************************************************/
      24                 :             : 
      25                 :             : #ifndef __GNC_BACKEND_PROV_HPP__
      26                 :             : #define  __GNC_BACKEND_PROV_HPP__
      27                 :             : 
      28                 :             : #include <memory>
      29                 :             : 
      30                 :             : struct QofBackendProvider
      31                 :             : {
      32                 :         234 :     QofBackendProvider(const char* name, const char* type) :
      33                 :         234 :         provider_name {name}, access_method {type} {}
      34                 :             :     QofBackendProvider(QofBackendProvider&) = delete;
      35                 :             :     QofBackendProvider(QofBackendProvider&&) = delete;
      36                 :         192 :     virtual ~QofBackendProvider() {}
      37                 :             : 
      38                 :             :     /** Return a new, fully initialized backend.
      39                 :             :      *
      40                 :             :      * If the backend supports configuration, all configuration options
      41                 :             :      * should be initialised to usable values here.
      42                 :             :      * */
      43                 :             :     virtual QofBackend * create_backend(void) = 0;
      44                 :             : 
      45                 :             :     /** \brief Distinguish two providers with same access method.
      46                 :             : 
      47                 :             :       More than 1 backend can be registered under the same access_method,
      48                 :             :       so each one is passed the path to the data (e.g. a file) and
      49                 :             :       should return TRUE only:
      50                 :             :     -# if the backend recognises the type as one that it can load and write or
      51                 :             :     -# if the path contains no data but can be used (e.g. a new session).
      52                 :             : 
      53                 :             :       \note If the backend can cope with more than one type, the backend
      54                 :             :       should not try to store or cache the sub-type for this data.
      55                 :             :       It is sufficient only to return TRUE if any ONE of the supported
      56                 :             :       types match the incoming data. The backend should not assume that
      57                 :             :       returning TRUE will mean that the data will naturally follow.
      58                 :             :       */
      59                 :             :     /*@ null @*/
      60                 :             :     virtual bool type_check(const char*) = 0;
      61                 :             :     /** Some arbitrary name given for this particular backend provider */
      62                 :             :     const char * provider_name;
      63                 :             : 
      64                 :             :     /** The access method that this provider provides, for example,
      65                 :             :      *  file:// http:// postgres:// or sqlite://, but without the :// at the end
      66                 :             :      */
      67                 :             :     const char * access_method;
      68                 :             : };
      69                 :             : 
      70                 :             : using QofBackendProvider_ptr = std::unique_ptr<QofBackendProvider>;
      71                 :             : 
      72                 :             : /** Let the system know about a new provider of backends.  This function
      73                 :             :  *  is typically called by the provider library at library load time.
      74                 :             :  *  This function allows the backend library to tell the QOF infrastructure
      75                 :             :  *  that it can handle URL's of a certain type.  Note that a single
      76                 :             :  *  backend library may register more than one provider, if it is
      77                 :             :  *  capable of handling more than one URL access method.
      78                 :             :  */
      79                 :             : void qof_backend_register_provider (QofBackendProvider_ptr&&);
      80                 :             : 
      81                 :             : void qof_backend_unregister_all_providers ();
      82                 :             : 
      83                 :             : #endif // __GNC_BACKEND_PROV_HPP__
        

Generated by: LCOV version 2.0-1