LCOV - code coverage report
Current view: top level - libgnucash/engine - qofinstance-p.h (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                 :             :  * qofinstance-p.h -- private fields common to all object instances *
       3                 :             :  *                                                                  *
       4                 :             :  * This program is free software; you can redistribute it and/or    *
       5                 :             :  * modify it under the terms of the GNU General Public License as   *
       6                 :             :  * published by the Free Software Foundation; either version 2 of   *
       7                 :             :  * the License, or (at your option) any later version.              *
       8                 :             :  *                                                                  *
       9                 :             :  * This program is distributed in the hope that it will be useful,  *
      10                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
      11                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
      12                 :             :  * GNU General Public License for more details.                     *
      13                 :             :  *                                                                  *
      14                 :             :  * You should have received a copy of the GNU General Public License*
      15                 :             :  * along with this program; if not, contact:                        *
      16                 :             :  *                                                                  *
      17                 :             :  * Free Software Foundation           Voice:  +1-617-542-5942       *
      18                 :             :  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
      19                 :             :  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
      20                 :             :  *                                                                  *
      21                 :             : \********************************************************************/
      22                 :             : /*
      23                 :             :  * Object instance holds many common fields that most
      24                 :             :  * gnucash objects use.
      25                 :             :  *
      26                 :             :  * Copyright (C) 2003 Linas Vepstas <linas@linas.org>
      27                 :             :  * Copyright (c) 2007 David Hampton <hampton@employees.org>
      28                 :             :  * Copyright 2017 Aaron Laws <dartme18@gmail.com>
      29                 :             :  */
      30                 :             : 
      31                 :             : #ifndef QOF_INSTANCE_P_H
      32                 :             : #define QOF_INSTANCE_P_H
      33                 :             : 
      34                 :             : #include "qofinstance.h"
      35                 :             : 
      36                 :             : #ifdef __cplusplus
      37                 :             : #include "kvp-frame.hpp"
      38                 :             : #include <string>
      39                 :             : #include <optional>
      40                 :             : extern "C"
      41                 :             : {
      42                 :             : #endif
      43                 :             : 
      44                 :             : /** Set the collection this instance belongs to.  This function should never
      45                 :             :  *  be called by user code. Instead call the qof_collection_insert_entity()
      46                 :             :  *  function. */
      47                 :             : void qof_instance_set_collection (gconstpointer ptr, QofCollection *col);
      48                 :             : 
      49                 :             : void qof_instance_set_slots (QofInstance *, KvpFrame *);
      50                 :             : 
      51                 :             : /*  Set the last_update time. Reserved for use by the SQL backend;
      52                 :             :  *  used for comparing version in local memory to that in remote
      53                 :             :  *  server.
      54                 :             :  */
      55                 :             : void qof_instance_set_last_update (QofInstance *inst, time64 time);
      56                 :             : 
      57                 :             : /** Set the dirty flag of just the instance. Don't modify the
      58                 :             :  *  collection flag at all. */
      59                 :             : void qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag);
      60                 :             : 
      61                 :             : /** Set the GncGUID of this instance */
      62                 :             : void qof_instance_set_guid (gpointer inst, const GncGUID *guid);
      63                 :             : 
      64                 :             : /** Copy the GncGUID from one instance to another.  This routine should
      65                 :             :  *  be used with extreme caution, since GncGUID values are everywhere
      66                 :             :  *  assumed to be unique. */
      67                 :             : void qof_instance_copy_guid (gpointer to, gconstpointer from);
      68                 :             : 
      69                 :             : //QofIdType qof_instance_get_e_type (const QofInstance *inst);
      70                 :             : //void qof_instance_set_e_type (QofInstance *ent, QofIdType e_type);
      71                 :             : 
      72                 :             : /** Return the pointer to the kvp_data */
      73                 :             : /*@ dependent @*/
      74                 :             : KvpFrame* qof_instance_get_slots (const QofInstance *);
      75                 :             : void qof_instance_set_editlevel(gpointer inst, gint level);
      76                 :             : void qof_instance_increase_editlevel (gpointer ptr);
      77                 :             : void qof_instance_decrease_editlevel (gpointer ptr);
      78                 :             : void qof_instance_reset_editlevel (gpointer ptr);
      79                 :             : /** Set the flag that indicates whether or not this object is about to
      80                 :             :  *  be destroyed.
      81                 :             :  *
      82                 :             :  *  @param ptr The object whose flag should be set.
      83                 :             :  *
      84                 :             :  *  @param value The new value to be set for this object. */
      85                 :             : void qof_instance_set_destroying (gpointer ptr, gboolean value);
      86                 :             : 
      87                 :             : /** \brief Set the dirty flag
      88                 :             : Sets this instance AND the collection as dirty.
      89                 :             : */
      90                 :             : void qof_instance_set_dirty(QofInstance* inst);
      91                 :             : 
      92                 :             : /* reset the dirty flag */
      93                 :             : void qof_instance_mark_clean (QofInstance *);
      94                 :             : /** Get the version number on this instance.  The version number is
      95                 :             :  *  used to manage multi-user updates. */
      96                 :             : gint32 qof_instance_get_version (gconstpointer inst);
      97                 :             : 
      98                 :             : /** Set the version number on this instance.  The version number is
      99                 :             :  *  used to manage multi-user updates. */
     100                 :             : void qof_instance_set_version (gpointer inst, gint32 value);
     101                 :             : /** Copy the version number on this instance.  The version number is
     102                 :             :  *  used to manage multi-user updates. */
     103                 :             : void qof_instance_copy_version (gpointer to, gconstpointer from);
     104                 :             : 
     105                 :             : /** Get the instance version_check number */
     106                 :             : guint32 qof_instance_get_version_check (gconstpointer inst);
     107                 :             : /** Set the instance version_check number */
     108                 :             : void qof_instance_set_version_check (gpointer inst, guint32 value);
     109                 :             : /** copy the instance version_check number */
     110                 :             : void qof_instance_copy_version_check (gpointer to, gconstpointer from);
     111                 :             : void qof_instance_set_idata(gpointer inst, guint32 idata);
     112                 :             : /* Convenience functions to save some typing in property handlers */
     113                 :             : /** @ingroup KVP
     114                 :             :  * @{ */
     115                 :             : /** Report whether a QofInstance has anything stored in KVP
     116                 :             :  * @param inst The QofInstance
     117                 :             :  * @return TRUE if Kvp isn't empty.
     118                 :             :  */
     119                 :             : gboolean qof_instance_has_kvp (QofInstance *inst);
     120                 :             : 
     121                 :             : /** Sets a KVP slot to a value from a GValue. Intermediate container
     122                 :             :  * frames will be created if necessary. Commits the change to the QofInstance.
     123                 :             :  * @param inst: The QofInstance on which to set the value.
     124                 :             :  * @param key: The path to the slot.
     125                 :             :  * @param value: A GValue containing an item of a type which KvpValue knows
     126                 :             :  *           how to store.
     127                 :             :  */
     128                 :             : void qof_instance_set_kvp (QofInstance *, GValue const * value, unsigned count, ...);
     129                 :             : 
     130                 :             : /** Retrieves the contents of a KVP slot into a provided GValue.
     131                 :             :  * @param inst: The QofInstance
     132                 :             :  * @param key: The path to the slot.
     133                 :             :  * @param value: A GValue into which to store the value of the slot. It will be
     134                 :             :  *               set to the correct type.
     135                 :             :  */
     136                 :             : void qof_instance_get_kvp (QofInstance *, GValue * value, unsigned count, ...);
     137                 :             : 
     138                 :             : /** @} Close out the DOxygen ingroup */
     139                 :             : /* Functions to isolate the KVP mechanism inside QOF for cases where
     140                 :             : GValue * operations won't work.
     141                 :             :  */
     142                 :             : void qof_instance_copy_kvp (QofInstance *to, const QofInstance *from);
     143                 :             : void qof_instance_swap_kvp (QofInstance *a, QofInstance *b);
     144                 :             : int qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b);
     145                 :             : /** Returns a g_strdup'd string which must be g_freed. */
     146                 :             : char* qof_instance_kvp_as_string (const QofInstance *inst);
     147                 :             : void qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
     148                 :             :                                 time64 time, const char* key,
     149                 :             :                                 const GncGUID *guid);
     150                 :             : void qof_instance_kvp_remove_guid (const QofInstance *inst, const char *path,
     151                 :             :                                    const char* key, const GncGUID *guid);
     152                 :             : gboolean qof_instance_kvp_has_guid (const QofInstance *inst, const char *path,
     153                 :             :                                     const char* key, const GncGUID *guid);
     154                 :             : void qof_instance_kvp_merge_guids (const QofInstance *target,
     155                 :             :                                    const QofInstance *donor, const char* path);
     156                 :             : gboolean qof_instance_has_slot (const QofInstance *inst, const char *path);
     157                 :             : void qof_instance_slot_delete (const QofInstance *, const char * path);
     158                 :             : void qof_instance_slot_delete_if_empty (const QofInstance *, const char * path);
     159                 :             : void qof_instance_foreach_slot (const QofInstance *inst, const char *head,
     160                 :             :                                 const char *category, void(*proc)(const char*,
     161                 :             :                                 const GValue*, void*), void* data);
     162                 :             : #ifdef __cplusplus
     163                 :             : } /* extern "C" */
     164                 :             : 
     165                 :             : void qof_instance_get_path_kvp (QofInstance *, GValue *, std::vector<std::string> const &);
     166                 :             : 
     167                 :             : void qof_instance_set_path_kvp (QofInstance *, GValue const *, std::vector<std::string> const &);
     168                 :             : 
     169                 :             : template <typename T> std::optional<T>
     170                 :             : qof_instance_get_path_kvp (QofInstance*, const Path&);
     171                 :             : 
     172                 :             : template <typename T> void
     173                 :             : qof_instance_set_path_kvp (QofInstance*, std::optional<T>, const Path&);
     174                 :             : 
     175                 :             : bool qof_instance_has_path_slot (QofInstance const *, std::vector<std::string> const &);
     176                 :             : 
     177                 :             : void qof_instance_slot_path_delete (QofInstance const *, std::vector<std::string> const &);
     178                 :             : 
     179                 :             : void qof_instance_slot_path_delete_if_empty (QofInstance const *, std::vector<std::string> const &);
     180                 :             : 
     181                 :             : /** Returns all keys that match the given prefix and their corresponding values.*/
     182                 :             : std::vector <std::pair <std::string, KvpValue*>>
     183                 :             : qof_instance_get_slots_prefix (QofInstance const *, std::string const & prefix);
     184                 :             : 
     185                 :             : /**
     186                 :             :  * Similar to qof_instance_foreach_slot, but we don't traverse the depth of the key value frame,
     187                 :             :  * we only check the root level for keys that match the specified prefix.
     188                 :             :  */
     189                 :             : template<typename func_type, typename data_type>
     190                 :          13 : void qof_instance_foreach_slot_prefix(QofInstance const * inst, std::string const & path_prefix,
     191                 :             :         func_type const & func, data_type & data)
     192                 :             : {
     193                 :          13 :     inst->kvp_data->for_each_slot_prefix(path_prefix, func, data);
     194                 :          13 : }
     195                 :             : 
     196                 :             : #endif
     197                 :             : 
     198                 :             : #endif /* QOF_INSTANCE_P_H */
        

Generated by: LCOV version 2.0-1