GnuCash
5.6-150-g038405b370+
|
A KvpFrame is a set of associations between character strings (keys) and KvpValues. More...
Data Structures | |
struct | KvpFrameImpl |
Implements KvpFrame. More... | |
class | KvpFrameImpl::cstring_comparer |
struct | KvpValue |
Implements KvpValue using boost::variant. More... | |
Typedefs | |
using | Path = std::vector< std::string > |
using | KvpEntry = std::pair< std::vector< std::string >, KvpValue * > |
using | KvpFrameImpl::map_type = std::map< const char *, KvpValue *, cstring_comparer > |
Functions | |
bool | KvpFrameImpl::cstring_comparer::operator() (const char *one, const char *two) const |
KvpFrameImpl::KvpFrameImpl (const KvpFrameImpl &) noexcept | |
Performs a deep copy. | |
KvpFrameImpl::~KvpFrameImpl () noexcept | |
Perform a deep delete. | |
KvpValue * | KvpFrameImpl::set (Path path, KvpValue *newvalue) noexcept |
Set the value with the key in the immediate frame, replacing and returning the old value if it exists or nullptr if it doesn't. More... | |
KvpValue * | KvpFrameImpl::set_path (Path path, KvpValue *newvalue) noexcept |
Set the value with the key in a subframe following the keys in path, replacing and returning the old value if it exists or nullptr if it doesn't. More... | |
std::string | KvpFrameImpl::to_string () const noexcept |
Make a string representation of the frame. More... | |
std::string | KvpFrameImpl::to_string (std::string const &) const noexcept |
Make a string representation of the frame with the specified string prefixed to every item in the frame. More... | |
std::vector< std::string > | KvpFrameImpl::get_keys () const noexcept |
Report the keys in the immediate frame. More... | |
KvpValue * | KvpFrameImpl::get_slot (Path keys) noexcept |
Get the value for the tail of the path or nullptr if it doesn't exist. More... | |
template<typename func_type , typename data_type > | |
void | KvpFrameImpl::for_each_slot_temp (func_type const &, data_type &) const noexcept |
The function should be of the form: <anything> func (char const *, KvpValue *, data_type &); Do not pass nullptr as the function. | |
template<typename func_type > | |
void | KvpFrameImpl::for_each_slot_temp (func_type const &) const noexcept |
template<typename func_type , typename data_type > | |
void | KvpFrameImpl::for_each_slot_prefix (std::string const &prefix, func_type const &, data_type &) const noexcept |
Like for_each_slot, but doesn't traverse nested values. More... | |
template<typename func_type > | |
void | KvpFrameImpl::for_each_slot_prefix (std::string const &prefix, func_type const &) const noexcept |
std::vector< KvpEntry > | KvpFrameImpl::flatten_kvp (void) const noexcept |
Returns all keys and values of this frame recursively, flattening the frame-containing values. | |
bool | KvpFrameImpl::empty () const noexcept |
Test for emptiness. More... | |
map_type::iterator | KvpFrameImpl::begin () |
map_type::iterator | KvpFrameImpl::end () |
int | compare (const KvpValueImpl *, const KvpValue *) noexcept |
Friends | |
int | KvpFrameImpl::compare (const KvpFrameImpl &, const KvpFrameImpl &) noexcept |
If the first KvpFrameImpl has an item that the second does not, 1 is returned. More... | |
int | compare (const KvpFrameImpl &, const KvpFrameImpl &) noexcept |
If the first KvpFrameImpl has an item that the second does not, 1 is returned. More... | |
int | compare (const KvpFrameImpl *, const KvpFrameImpl *) noexcept |
void | gvalue_from_kvp_value (const KvpValue *kval, GValue *val) |
Convert a kvp_value into a GValue. More... | |
KvpValue * | kvp_value_from_gvalue (const GValue *gval) |
Convert a gvalue into a kvpvalue. More... | |
void | qof_book_load_options (QofBook *book, GncOptionLoad load_cb, GncOptionDB *odb) |
Load a GncOptionsDB from KVP data. More... | |
void | qof_book_save_options (QofBook *book, GncOptionSave save_cb, GncOptionDB *odb, gboolean clear) |
Save a GncOptionsDB back to the book's KVP. More... | |
void | qof_book_set_option (QofBook *book, KvpValue *value, GSList *path) |
Save a single option value. More... | |
KvpValue * | qof_book_get_option (QofBook *book, GSList *path) |
Read a single option value. More... | |
void | qof_book_options_delete (QofBook *book, GSList *path) |
Delete the options. More... | |
gboolean | qof_instance_has_kvp (QofInstance *inst) |
Report whether a QofInstance has anything stored in KVP. More... | |
void | qof_instance_set_kvp (QofInstance *, GValue const *value, unsigned count,...) |
Sets a KVP slot to a value from a GValue. More... | |
void | qof_instance_get_kvp (QofInstance *, GValue *value, unsigned count,...) |
Retrieves the contents of a KVP slot into a provided GValue. More... | |
A KvpFrame is a set of associations between character strings (keys) and KvpValues.
A KvpValue is notionally a union with possible types enumerated in the KvpValue::Type enum, and includes, among other things, ints, doubles, strings, guids, lists, time and numeric values. KvpValues may also be other frames, so KVP is inherently hierarchical.
Values are stored in a 'slot' associated with a key. Pointers passed as arguments into set_slot and get_slot are the responsibility of the caller. Pointers returned by get_slot are owned by the kvp_frame. Make copies as needed.
A 'path' is a sequence of keys that can be followed to a value. Paths are passed as either '/'-delimited strings or as std::vectors of keys. Unlike file system paths, the tokens '.' and '..' have no special meaning.
KVP is an implementation detail whose direct use should be avoided; create an abstraction object in libqof to keep KVP encapsulated here and ensure that KVP modifications are written to the database. Two generic abstractions are provided:
KVP Values used By GnuCash provides a catolog of KVP entries including what objects they're part of and how they're used.
KVP is used to extend the class structure without directly reflecting the extension in the database or xML schema. The backend will directly load and store KVP slots without any checking, which allows older versions of GnuCash to load the database without complaint and without damaging the KVP data that they don't understand.
When a feature is entirely implemented in KVP and doesn't affect the meaning of the books or other features, this isn't a problem, but when it's not true then it should be registered in Features so that older versions of GnuCash will refuse to load the database.
|
noexcept |
If the first KvpFrameImpl has an item that the second does not, 1 is returned.
The first item within the two KvpFrameImpl that is not similar, that comparison is returned. If all the items within the first KvpFrameImpl match items within the second, but the second has more elements, -1 is returned. Otherwise, 0 is returned.
Definition at line 216 of file kvp-frame.cpp.
|
inlinenoexcept |
Test for emptiness.
Definition at line 226 of file kvp-frame.hpp.
|
noexcept |
Like for_each_slot, but doesn't traverse nested values.
This will only loop over root-level values whose keys match the specified prefix.
|
noexcept |
Report the keys in the immediate frame.
Be sensible about using this, it isn't a very efficient way to iterate.
Definition at line 188 of file kvp-frame.cpp.
|
noexcept |
Get the value for the tail of the path or nullptr if it doesn't exist.
path | Path of keys leading to the desired value. |
Definition at line 144 of file kvp-frame.cpp.
void gvalue_from_kvp_value | ( | const KvpValue * | kval, |
GValue * | val | ||
) |
Convert a kvp_value into a GValue.
Frames aren't converted.
kval | A KvpValue. |
val | The GValue in which to store the converted value. |
Definition at line 237 of file kvp-frame.cpp.
KvpValue* kvp_value_from_gvalue | ( | const GValue * | gval | ) |
Convert a gvalue into a kvpvalue.
gval | A GValue of a type KvpValue can digest. |
Definition at line 280 of file kvp-frame.cpp.
KvpValue* qof_book_get_option | ( | QofBook * | book, |
GSList * | path | ||
) |
Read a single option value.
Used from Scheme, the KvpValue<–>SCM translation is handled by the functions in kvp-scm.c and automated by SWIG. The starting element is set as KVP_OPTION_PATH in qofbookslots.h.
book | The book. |
path | A GSList of keys which form a path under KVP_OPTION_PATH. |
Definition at line 1374 of file qofbook.cpp.
void qof_book_load_options | ( | QofBook * | book, |
GncOptionLoad | load_cb, | ||
GncOptionDB * | odb | ||
) |
Load a GncOptionsDB from KVP data.
book | The book. |
load_cb | A callback function that does the loading. |
odb | The GncOptionDB to load. |
Definition at line 1316 of file qofbook.cpp.
void qof_book_options_delete | ( | QofBook * | book, |
GSList * | path | ||
) |
Delete the options.
Primarily used from Scheme to clear out the options before saving a new set.
book | The book. |
list | A GList of keys which from a path under KVP_OPTION_PATH. If GList is Null, the whole option is deleted. |
Definition at line 1381 of file qofbook.cpp.
void qof_book_save_options | ( | QofBook * | book, |
GncOptionSave | save_cb, | ||
GncOptionDB * | odb, | ||
gboolean | clear | ||
) |
Save a GncOptionsDB back to the book's KVP.
book | The book. |
save_cb | A callback function that does the saving. |
odb | The GncOptionsDB to save from. |
clear | Should the GncOptionsDB be emptied after the save? |
Definition at line 1322 of file qofbook.cpp.
void qof_book_set_option | ( | QofBook * | book, |
KvpValue * | value, | ||
GSList * | path | ||
) |
Save a single option value.
Used from Scheme, the KvpValue<–>SCM translation is handled by the functions in kvp-scm.c and automated by SWIG. The starting element is set as KVP_OPTION_PATH in qofbookslots.h.
book | The book. |
value | The KvpValue to store. |
path | A GSList of keys which form a path under KVP_OPTION_PATH. |
Definition at line 1361 of file qofbook.cpp.
void qof_instance_get_kvp | ( | QofInstance * | , |
GValue * | value, | ||
unsigned | count, | ||
... | |||
) |
Retrieves the contents of a KVP slot into a provided GValue.
inst | The QofInstance |
key | The path to the slot. |
value | A GValue into which to store the value of the slot. It will be set to the correct type. |
Definition at line 1099 of file qofinstance.cpp.
gboolean qof_instance_has_kvp | ( | QofInstance * | inst | ) |
Report whether a QofInstance has anything stored in KVP.
inst | The QofInstance |
Definition at line 1045 of file qofinstance.cpp.
void qof_instance_set_kvp | ( | QofInstance * | , |
GValue const * | value, | ||
unsigned | count, | ||
... | |||
) |
Sets a KVP slot to a value from a GValue.
Intermediate container frames will be created if necessary. Commits the change to the QofInstance.
inst | The QofInstance on which to set the value. |
key | The path to the slot. |
value | A GValue containing an item of a type which KvpValue knows how to store. |
Definition at line 1056 of file qofinstance.cpp.
|
noexcept |
Set the value with the key in the immediate frame, replacing and returning the old value if it exists or nullptr if it doesn't.
Takes ownership of new value and releases ownership of the returned old value. Values must be allocated on the free store with operator new.
key | The key to insert/replace. |
newvalue | The value to set at key. |
key | The key to insert/replace. |
invalid_argument | if the path doesn't exist. |
path | The path of subframes leading to the frame in which to insert/replace. |
newvalue | The value to set at key. |
Definition at line 120 of file kvp-frame.cpp.
|
noexcept |
Set the value with the key in a subframe following the keys in path, replacing and returning the old value if it exists or nullptr if it doesn't.
Creates any missing intermediate frames.Takes ownership of new value and releases ownership of the returned old value. Values must be allocated on the free store with operator new.
path | The path of subframes as a std::vector leading to the frame in which to insert/replace. |
newvalue | The value to set at key. |
Definition at line 133 of file kvp-frame.cpp.
|
noexcept |
Make a string representation of the frame.
Mostly useful for debugging.
Definition at line 158 of file kvp-frame.cpp.
|
noexcept |
Make a string representation of the frame with the specified string prefixed to every item in the frame.
Definition at line 164 of file kvp-frame.cpp.
|
friend |
If the first KvpFrameImpl has an item that the second does not, 1 is returned.
The first item within the two KvpFrameImpl that is not similar, that comparison is returned. If all the items within the first KvpFrameImpl match items within the second, but the second has more elements, -1 is returned. Otherwise, 0 is returned.
Definition at line 216 of file kvp-frame.cpp.