39 #include "qofbook-p.hpp" 41 #include "kvp-frame.hpp" 42 #include "qofinstance-p.h" 43 #include "qof-backend.hpp" 45 static QofLogModule log_module = QOF_MOD_ENGINE;
105 guint32 version_check;
112 #define GET_PRIVATE(o) \ 113 ((QofInstancePrivate*)qof_instance_get_instance_private((QofInstance*)o)) 115 G_DEFINE_TYPE_WITH_PRIVATE(
QofInstance, qof_instance, G_TYPE_OBJECT)
116 QOF_GOBJECT_FINALIZE(qof_instance);
117 #undef G_PARAM_READWRITE 118 #define G_PARAM_READWRITE static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_WRITABLE) 120 static void qof_instance_get_property (GObject *
object,
124 static void qof_instance_set_property (GObject *
object,
128 static void qof_instance_dispose(GObject*);
129 static void qof_instance_class_init(QofInstanceClass *klass)
131 GObjectClass *object_class = G_OBJECT_CLASS(klass);
132 object_class->finalize = qof_instance_finalize;
133 object_class->dispose = qof_instance_dispose;
134 object_class->set_property = qof_instance_set_property;
135 object_class->get_property = qof_instance_get_property;
137 klass->get_display_name =
nullptr;
138 klass->refers_to_object =
nullptr;
139 klass->get_typed_referring_object_list =
nullptr;
141 g_object_class_install_property
144 g_param_spec_boxed (
"guid",
146 "The object Globally Unique ID.",
150 g_object_class_install_property
153 g_param_spec_object (
"book",
155 "The book that contains this object.",
159 g_object_class_install_property
162 g_param_spec_pointer (
"last-update",
163 "Object Last Update",
164 "A pointer to the last time this object was " 165 "updated. This value is present for use by " 166 "backends and shouldn't be written by other " 170 g_object_class_install_property
173 g_param_spec_int (
"editlevel",
175 "The object edit level.",
179 g_object_class_install_property
182 g_param_spec_boolean (
"destroying",
184 "This flag is set to TRUE if the object is " 185 "about to be destroyed.",
189 g_object_class_install_property
192 g_param_spec_boolean (
"dirty",
194 "This flag is set to TRUE if the object has " 199 g_object_class_install_property
202 g_param_spec_boolean (
"infant",
204 "This flag is set to TRUE if the object has " 205 "never been added to a book. This implies " 206 "that its destruction does not affect the " 207 "state of the book, and therefore the saved " 208 "state of the data file.",
212 g_object_class_install_property
215 g_param_spec_int (
"version",
217 "The version number of the current instance state.",
223 g_object_class_install_property
226 g_param_spec_uint (
"version-check",
228 "The version check number of the current instance state.",
234 g_object_class_install_property
237 g_param_spec_uint (
"idata",
239 "Per instance backend private data.",
249 priv = GET_PRIVATE(inst);
250 priv->book =
nullptr;
251 inst->kvp_data =
new KvpFrame;
252 priv->last_update = 0;
254 priv->do_free = FALSE;
266 g_return_if_fail(QOF_IS_INSTANCE(inst));
267 priv = GET_PRIVATE(inst);
268 g_return_if_fail(!priv->book);
272 g_return_if_fail(col !=
nullptr);
278 if (g_strcmp0(col_type, type))
280 PERR (
"attempt to insert \"%s\" into \"%s\"", type, col_type);
283 priv = GET_PRIVATE(inst);
293 PWARN(
"duplicate id created, trying again");
303 qof_instance_dispose (GObject *instp)
308 priv = GET_PRIVATE(instp);
310 qof_collection_remove_entity(inst);
312 CACHE_REMOVE(inst->
e_type);
315 G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp);
319 qof_instance_finalize_real (GObject *instp)
324 delete inst->kvp_data;
325 inst->kvp_data =
nullptr;
327 priv = GET_PRIVATE(inst);
329 priv->do_free = FALSE;
340 qof_instance_get_property (GObject *
object,
348 g_return_if_fail(QOF_IS_INSTANCE(
object));
350 inst = QOF_INSTANCE(
object);
351 priv = GET_PRIVATE(inst);
356 g_value_set_boxed(value, &priv->
guid);
358 case PROP_COLLECTION:
362 g_value_take_object(value, priv->book);
364 case PROP_LAST_UPDATE:
365 g_value_set_pointer(value, &priv->last_update);
368 g_value_set_int(value, priv->editlevel);
370 case PROP_DESTROYING:
371 g_value_set_boolean(value, priv->do_free);
374 g_value_set_boolean(value, qof_instance_get_dirty(inst));
377 g_value_set_boolean(value, priv->infant);
380 g_value_set_int(value, priv->version);
382 case PROP_VERSION_CHECK:
383 g_value_set_uint(value, priv->version_check);
386 g_value_set_uint(value, priv->idata);
389 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
395 qof_instance_set_property (GObject *
object,
403 g_return_if_fail(QOF_IS_INSTANCE(
object));
405 inst = QOF_INSTANCE(
object);
410 qof_instance_set_guid(inst,
411 static_cast<GncGUID*>(g_value_get_boxed(value)));
413 case PROP_COLLECTION:
414 qof_instance_set_collection(inst, static_cast<QofCollection*>(g_value_get_pointer(value)));
418 static_cast<QofBook*>(g_value_get_object(value)));
420 case PROP_LAST_UPDATE:
421 t = *(
static_cast<Time64*
>(g_value_get_pointer(value)));
422 qof_instance_set_last_update(inst, t.t);
424 case PROP_DESTROYING:
425 qof_instance_set_destroying(inst, g_value_get_boolean(value));
428 qof_instance_set_dirty(inst);
431 qof_instance_set_version(inst, g_value_get_int(value));
433 case PROP_VERSION_CHECK:
434 qof_instance_set_version_check(inst, g_value_get_uint(value));
437 qof_instance_set_idata(inst, g_value_get_uint(value));
440 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
450 if (!inst)
return nullptr;
451 g_return_val_if_fail(QOF_IS_INSTANCE(inst),
guid_null());
452 priv = GET_PRIVATE(inst);
453 return &(priv->
guid);
463 qof_instance_set_guid (gpointer ptr,
const GncGUID *guid)
469 g_return_if_fail(QOF_IS_INSTANCE(ptr));
471 inst = QOF_INSTANCE(ptr);
472 priv = GET_PRIVATE(inst);
477 qof_collection_remove_entity(inst);
483 qof_instance_copy_guid (gpointer to, gconstpointer from)
485 g_return_if_fail(QOF_IS_INSTANCE(to));
486 g_return_if_fail(QOF_IS_INSTANCE(from));
488 GET_PRIVATE(to)->guid = GET_PRIVATE(from)->guid;
496 g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), -1);
497 g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), 1);
499 priv1 = GET_PRIVATE(ptr1);
500 priv2 = GET_PRIVATE(ptr2);
502 return guid_compare(&priv1->
guid, &priv2->
guid);
509 g_return_val_if_fail(QOF_IS_INSTANCE(ptr),
nullptr);
510 return GET_PRIVATE(ptr)->collection;
514 qof_instance_set_collection (gconstpointer ptr, QofCollection *col)
516 g_return_if_fail(QOF_IS_INSTANCE(ptr));
517 GET_PRIVATE(ptr)->collection = col;
523 if (!inst)
return nullptr;
524 g_return_val_if_fail(QOF_IS_INSTANCE(inst),
nullptr);
525 return GET_PRIVATE(inst)->book;
531 g_return_if_fail(QOF_IS_INSTANCE(inst));
532 GET_PRIVATE(inst)->book = book;
538 g_return_if_fail(QOF_IS_INSTANCE(ptr1));
539 g_return_if_fail(QOF_IS_INSTANCE(ptr2));
541 GET_PRIVATE(ptr1)->book = GET_PRIVATE(ptr2)->book;
549 g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), FALSE);
550 g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), FALSE);
552 priv1 = GET_PRIVATE(ptr1);
553 priv2 = GET_PRIVATE(ptr2);
555 return (priv1->book == priv2->book);
562 if (!inst)
return nullptr;
563 return inst->kvp_data;
567 qof_instance_set_slots (
QofInstance *inst, KvpFrame *frm)
573 priv = GET_PRIVATE(inst);
574 if (inst->kvp_data && (inst->kvp_data != frm))
576 delete inst->kvp_data;
580 inst->kvp_data = frm;
587 GET_PRIVATE(inst)->last_update = t;
591 qof_instance_get_editlevel (gconstpointer ptr)
593 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), 0);
594 return GET_PRIVATE(ptr)->editlevel;
597 void qof_instance_increase_editlevel (gpointer ptr)
599 g_return_if_fail(QOF_IS_INSTANCE(ptr));
600 GET_PRIVATE(ptr)->editlevel++;
603 void qof_instance_decrease_editlevel (gpointer ptr)
605 g_return_if_fail(QOF_IS_INSTANCE(ptr));
606 GET_PRIVATE(ptr)->editlevel--;
609 void qof_instance_reset_editlevel (gpointer ptr)
611 g_return_if_fail(QOF_IS_INSTANCE(ptr));
612 GET_PRIVATE(ptr)->editlevel = 0;
620 if (!left && !right)
return 0;
621 if (!left)
return -1;
622 if (!right)
return +1;
624 lpriv = GET_PRIVATE(left);
625 rpriv = GET_PRIVATE(right);
626 return lpriv->last_update < rpriv->last_update ? -1 :
627 lpriv->last_update > rpriv->last_update ? 1 : 0;
633 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
634 return GET_PRIVATE(ptr)->do_free;
638 qof_instance_set_destroying (gpointer ptr, gboolean value)
640 g_return_if_fail(QOF_IS_INSTANCE(ptr));
641 GET_PRIVATE(ptr)->do_free = value;
647 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
648 return GET_PRIVATE(ptr)->dirty;
652 qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag)
654 g_return_if_fail(QOF_IS_INSTANCE(inst));
655 GET_PRIVATE(inst)->dirty = flag;
662 GET_PRIVATE(inst)->dirty = FALSE;
666 qof_instance_print_dirty (
const QofInstance *inst, gpointer dummy)
670 priv = GET_PRIVATE(inst);
675 printf(
"%s instance %s is dirty.\n", inst->
e_type, guidstr);
689 priv = GET_PRIVATE(inst);
698 priv = GET_PRIVATE(inst);
705 g_return_val_if_fail(QOF_IS_INSTANCE(inst), FALSE);
706 return GET_PRIVATE(inst)->infant;
710 qof_instance_get_version (gconstpointer inst)
712 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
713 return GET_PRIVATE(inst)->version;
717 qof_instance_set_version (gpointer inst, gint32 vers)
719 g_return_if_fail(QOF_IS_INSTANCE(inst));
720 GET_PRIVATE(inst)->version = vers;
724 qof_instance_copy_version (gpointer to, gconstpointer from)
726 g_return_if_fail(QOF_IS_INSTANCE(to));
727 g_return_if_fail(QOF_IS_INSTANCE(from));
728 GET_PRIVATE(to)->version = GET_PRIVATE(from)->version;
732 qof_instance_get_version_check (gconstpointer inst)
734 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
735 return GET_PRIVATE(inst)->version_check;
739 qof_instance_set_version_check (gpointer inst, guint32 value)
741 g_return_if_fail(QOF_IS_INSTANCE(inst));
742 GET_PRIVATE(inst)->version_check = value;
746 qof_instance_copy_version_check (gpointer to, gconstpointer from)
748 g_return_if_fail(QOF_IS_INSTANCE(to));
749 g_return_if_fail(QOF_IS_INSTANCE(from));
750 GET_PRIVATE(to)->version_check = GET_PRIVATE(from)->version_check;
759 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
760 return GET_PRIVATE(inst)->idata;
763 void qof_instance_set_idata(gpointer inst, guint32 idata)
769 g_return_if_fail(QOF_IS_INSTANCE(inst));
770 GET_PRIVATE(inst)->idata = idata;
778 g_return_val_if_fail( inst !=
nullptr,
nullptr );
780 if ( QOF_INSTANCE_GET_CLASS(inst)->get_display_name !=
nullptr )
782 return QOF_INSTANCE_GET_CLASS(inst)->get_display_name(inst);
787 return g_strdup_printf(
"Object %s %p",
800 get_referring_object_instance_helper(
QofInstance* inst, gpointer user_data)
804 if (*pInst ==
nullptr)
811 get_referring_object_helper(QofCollection* coll, gpointer user_data)
816 qof_collection_foreach(coll, get_referring_object_instance_helper, &first_instance);
818 if (first_instance !=
nullptr)
821 data->list = g_list_concat(data->list, new_list);
830 g_return_val_if_fail( inst !=
nullptr,
nullptr );
837 get_referring_object_helper,
843 get_typed_referring_object_instance_helper(
QofInstance* inst, gpointer user_data)
849 data->list = g_list_prepend(data->list, inst);
858 g_return_val_if_fail( coll !=
nullptr,
nullptr );
859 g_return_val_if_fail( ref !=
nullptr,
nullptr );
864 qof_collection_foreach(coll, get_typed_referring_object_instance_helper, &data);
871 g_return_val_if_fail( inst !=
nullptr,
nullptr );
872 g_return_val_if_fail( ref !=
nullptr,
nullptr );
874 if ( QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list !=
nullptr )
876 return QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list(inst, ref);
892 g_return_val_if_fail( inst !=
nullptr, FALSE );
893 g_return_val_if_fail( ref !=
nullptr, FALSE );
895 if ( QOF_INSTANCE_GET_CLASS(inst)->refers_to_object !=
nullptr )
897 return QOF_INSTANCE_GET_CLASS(inst)->refers_to_object(inst, ref);
911 g_return_if_fail (QOF_IS_INSTANCE (inst));
913 va_start (ap, first_prop);
914 g_object_get_valist (G_OBJECT (inst), first_prop, ap);
922 g_return_if_fail (QOF_IS_INSTANCE (inst));
924 qof_instance_set_dirty (inst);
925 va_start (ap, first_prop);
926 g_object_set_valist (G_OBJECT (inst), first_prop, ap);
940 if (!inst)
return FALSE;
942 priv = GET_PRIVATE(inst);
944 if (1 < priv->editlevel)
return FALSE;
945 if (0 >= priv->editlevel)
961 if (!inst)
return FALSE;
963 priv = GET_PRIVATE(inst);
965 if (0 < priv->editlevel)
return FALSE;
967 if (0 > priv->editlevel)
969 PERR (
"unbalanced call - resetting (was %d)", priv->editlevel);
983 priv = GET_PRIVATE(inst);
986 !(priv->infant && priv->do_free)) {
1000 errcode = be->get_error();
1002 while (errcode != ERR_BACKEND_NO_ERR);
1005 errcode = be->get_error();
1006 if (errcode != ERR_BACKEND_NO_ERR)
1009 priv->do_free = FALSE;
1012 be->set_error (errcode);
1014 on_error(inst, errcode);
1018 priv->infant = FALSE;
1036 return (inst->kvp_data !=
nullptr && !inst->kvp_data->empty());
1039 void qof_instance_set_path_kvp (
QofInstance * inst, GValue
const * value, std::vector<std::string>
const & path)
1047 std::vector<std::string> path;
1049 va_start (args, count);
1050 for (
unsigned i{0}; i < count; ++i)
1051 path.push_back (va_arg (args,
char const *));
1056 template <
typename T> std::optional<T>
1057 qof_instance_get_path_kvp (
QofInstance* inst,
const Path& path)
1059 g_return_val_if_fail (QOF_IS_INSTANCE(inst), std::nullopt);
1060 auto kvp_value{inst->kvp_data->get_slot(path)};
1061 return kvp_value ? std::make_optional<T>(kvp_value->get<T>()) :
std::nullopt;
1064 template <
typename T>
void 1065 qof_instance_set_path_kvp (
QofInstance* inst, std::optional<T> value,
const Path& path)
1067 g_return_if_fail (QOF_IS_INSTANCE(inst));
1068 delete inst->kvp_data->set_path(path, value ?
new KvpValue(*value) :
nullptr);
1069 qof_instance_set_dirty (inst);
1072 template std::optional<Time64> qof_instance_get_path_kvp <Time64> (
QofInstance*,
const Path&);
1073 template std::optional<GDate> qof_instance_get_path_kvp <GDate> (
QofInstance*,
const Path&);
1074 template std::optional<const char*> qof_instance_get_path_kvp <const char*> (
QofInstance*,
const Path&);
1075 template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (
QofInstance*,
const Path&);
1076 template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (
QofInstance*,
const Path&);
1077 template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (
QofInstance*,
const Path&);
1079 template void qof_instance_set_path_kvp <Time64> (
QofInstance*, std::optional<Time64>,
const Path& path);
1080 template void qof_instance_set_path_kvp <GDate> (
QofInstance*, std::optional<GDate>,
const Path& path);
1081 template void qof_instance_set_path_kvp <const char*> (
QofInstance*, std::optional<const char*>,
const Path& path);
1082 template void qof_instance_set_path_kvp <gnc_numeric> (
QofInstance*, std::optional<gnc_numeric>,
const Path& path);
1083 template void qof_instance_set_path_kvp <GncGUID*> (
QofInstance*, std::optional<GncGUID*>,
const Path& path);
1084 template void qof_instance_set_path_kvp <int64_t> (
QofInstance*, std::optional<int64_t>,
const Path& path);
1086 void qof_instance_get_path_kvp (
QofInstance * inst, GValue * value, std::vector<std::string>
const & path)
1094 std::vector<std::string> path;
1096 va_start (args, count);
1097 for (
unsigned i{0}; i < count; ++i)
1098 path.push_back (va_arg (args,
char const *));
1106 delete to->kvp_data;
1107 to->kvp_data =
new KvpFrame(*from->kvp_data);
1113 std::swap(a->kvp_data, b->kvp_data);
1119 return compare(a->kvp_data, b->kvp_data);
1123 qof_instance_kvp_as_string (
const QofInstance *inst)
1125 auto str{inst->kvp_data->to_string()};
1126 return g_strdup(str.c_str());
1130 qof_instance_kvp_add_guid (
const QofInstance *inst,
const char* path,
1131 time64 time,
const char *key,
1134 g_return_if_fail (inst->kvp_data !=
nullptr);
1136 auto container =
new KvpFrame;
1138 container->set({key},
new KvpValue(const_cast<GncGUID*>(guid)));
1139 container->set({
"date"},
new KvpValue(t));
1140 delete inst->kvp_data->set_path({path},
new KvpValue(container));
1143 inline static gboolean
1144 kvp_match_guid (KvpValue *v, std::vector<std::string>
const & path,
const GncGUID *guid)
1146 if (v->get_type() != KvpValue::Type::FRAME)
1148 auto frame = v->get<KvpFrame*>();
1149 auto val = frame->get_slot(path);
1150 if (val ==
nullptr || val->get_type() != KvpValue::Type::GUID)
1152 auto this_guid = val->get<
GncGUID*>();
1158 qof_instance_kvp_has_guid (
const QofInstance *inst,
const char *path,
1159 const char* key,
const GncGUID *guid)
1161 g_return_val_if_fail (inst->kvp_data !=
nullptr, FALSE);
1162 g_return_val_if_fail (guid !=
nullptr, FALSE);
1164 auto v = inst->kvp_data->get_slot({path});
1165 if (v ==
nullptr)
return FALSE;
1167 switch (v->get_type())
1169 case KvpValue::Type::FRAME:
1170 return kvp_match_guid (v, {key}, guid);
1172 case KvpValue::Type::GLIST:
1174 auto list = v->get<GList*>();
1175 for (
auto node = list; node !=
nullptr; node = node->next)
1177 auto val =
static_cast<KvpValue*
>(node->data);
1178 if (kvp_match_guid (val, {key}, guid))
1186 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1193 qof_instance_kvp_remove_guid (
const QofInstance *inst,
const char *path,
1194 const char *key,
const GncGUID *guid)
1196 g_return_if_fail (inst->kvp_data !=
nullptr);
1197 g_return_if_fail (guid !=
nullptr);
1199 auto v = inst->kvp_data->get_slot({path});
1200 if (v ==
nullptr)
return;
1202 switch (v->get_type())
1204 case KvpValue::Type::FRAME:
1205 if (kvp_match_guid (v, {key}, guid))
1207 delete inst->kvp_data->set_path({path},
nullptr);
1210 case KvpValue::Type::GLIST:
1212 auto list = v->get<GList*>();
1213 for (
auto node = list; node !=
nullptr; node = node->next)
1215 auto val =
static_cast<KvpValue*
>(node->data);
1216 if (kvp_match_guid (val, {key}, guid))
1218 list = g_list_delete_link (list, node);
1227 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1234 qof_instance_kvp_merge_guids (
const QofInstance *target,
1237 g_return_if_fail (target !=
nullptr);
1238 g_return_if_fail (donor !=
nullptr);
1240 if (! qof_instance_has_slot (donor, path))
return;
1241 auto v = donor->kvp_data->get_slot({path});
1242 if (v ==
nullptr)
return;
1244 auto target_val = target->kvp_data->get_slot({path});
1245 switch (v->get_type())
1247 case KvpValue::Type::FRAME:
1251 target->kvp_data->set_path({path}, v);
1252 donor->kvp_data->set({path},
nullptr);
1254 case KvpValue::Type::GLIST:
1257 auto list = target_val->get<GList*>();
1258 list = g_list_concat(list, v->get<GList*>());
1259 target_val->set(list);
1262 target->kvp_data->set({path}, v);
1263 donor->kvp_data->set({path},
nullptr);
1266 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1271 bool qof_instance_has_path_slot (
QofInstance const * inst, std::vector<std::string>
const & path)
1273 return inst->kvp_data->get_slot (path) !=
nullptr;
1277 qof_instance_has_slot (
const QofInstance *inst,
const char *path)
1279 return inst->kvp_data->get_slot({path}) !=
nullptr;
1282 void qof_instance_slot_path_delete (
QofInstance const * inst, std::vector<std::string>
const & path)
1284 delete inst->kvp_data->set (path,
nullptr);
1288 qof_instance_slot_delete (
QofInstance const *inst,
char const * path)
1290 delete inst->kvp_data->set ({path},
nullptr);
1293 void qof_instance_slot_path_delete_if_empty (
QofInstance const * inst, std::vector<std::string>
const & path)
1295 auto slot = inst->kvp_data->get_slot (path);
1298 auto frame = slot->get <KvpFrame*> ();
1299 if (frame && frame->empty())
1300 delete inst->kvp_data->set (path,
nullptr);
1305 qof_instance_slot_delete_if_empty (
QofInstance const *inst,
char const * path)
1307 auto slot = inst->kvp_data->get_slot ({path});
1310 auto frame = slot->get <KvpFrame*> ();
1311 if (frame && frame->empty ())
1312 delete inst->kvp_data->set ({path},
nullptr);
1316 std::vector <std::pair <std::string, KvpValue*>>
1317 qof_instance_get_slots_prefix (
QofInstance const * inst, std::string
const & prefix)
1319 std::vector <std::pair <std::string, KvpValue*>> ret;
1320 inst->kvp_data->for_each_slot_temp ([&prefix, &ret] (std::string
const & key, KvpValue * val) {
1321 if (key.find (prefix) == 0)
1322 ret.emplace_back (key, val);
1330 void (*proc)(
const char*,
const GValue*,
void*);
1336 wrap_gvalue_function (
const char* key, KvpValue *val, wrap_param & param)
1338 GValue gv = G_VALUE_INIT;
1339 if (val->get_type() != KvpValue::Type::FRAME)
1343 g_value_init (&gv, G_TYPE_STRING);
1344 g_value_set_string (&gv,
nullptr);
1346 param.proc(key, &gv, param.user_data);
1347 g_value_unset (&gv);
1351 qof_instance_foreach_slot (
const QofInstance *inst,
const char* head,
const char* category,
1352 void (*proc)(
const char*,
const GValue*,
void*),
void* data)
1354 std::vector<std::string> path {head};
1356 path.emplace_back (category);
1358 auto slot = inst->kvp_data->get_slot(path);
1359 if (slot ==
nullptr || slot->get_type() != KvpValue::Type::FRAME)
1361 auto frame = slot->get<KvpFrame*>();
1362 wrap_param new_data {proc, data};
1363 frame->for_each_slot_temp(&wrap_gvalue_function, new_data);
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
void guid_replace(GncGUID *guid)
Generate a new guid.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
GncGUID guid
GncGUID for the entity.
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
Returns a list of objects from the collection which refer to the specific object. ...
void gvalue_from_kvp_value(const KvpValue *kval, GValue *val)
Convert a kvp_value into a GValue.
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
void qof_instance_set(QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
KvpValue * kvp_value_from_gvalue(const GValue *gval)
Convert a gvalue into a kvpvalue.
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
#define PWARN(format, args...)
Log a warning.
const gchar * QofIdType
QofIdType declaration.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
guint32 qof_instance_get_idata(gconstpointer inst)
get the instance tag number used for kvp management in sql backends.
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object has been modified.
void qof_instance_copy_book(gpointer ptr1, gconstpointer ptr2)
Copy the book from one QofInstances to another.
GList * qof_instance_get_typed_referring_object_list(const QofInstance *inst, const QofInstance *ref)
Returns a list of my type of object which refers to an object.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
void qof_collection_insert_entity(QofCollection *, QofInstance *)
Take entity, remove it from whatever collection its currently in, and place it in a new collection...
const GncGUID * qof_entity_get_guid(gconstpointer ent)
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
See if two QofInstances share the same book.
void qof_book_mark_session_dirty(QofBook *book)
The qof_book_mark_dirty() routine marks the book as having been modified.
GList * qof_instance_get_referring_object_list(const QofInstance *inst)
Returns a list of objects which refer to a specific object.
QofIdType qof_collection_get_type(const QofCollection *col)
return the type that the collection stores
QofIdType e_type
Entity type.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
void qof_instance_set_book(gconstpointer inst, QofBook *book)
Set the book pointer.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
gboolean qof_instance_refers_to_object(const QofInstance *inst, const QofInstance *ref)
Does this object refer to a specific object.
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP.
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
The type used to store guids in C.
QofCollection * collection
Entity collection.
gchar * qof_instance_get_display_name(const QofInstance *inst)
Returns a displayable name for this object.