39 #include "qofbook-p.h" 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_pointer (
"collection",
155 "A collection of like objects of which this " 156 "particular object is amember. E.g.. A " 157 "collection of accounts, or a collection of " 161 g_object_class_install_property
164 g_param_spec_object (
"book",
166 "The book that contains this object.",
170 g_object_class_install_property
173 g_param_spec_pointer (
"last-update",
174 "Object Last Update",
175 "A pointer to the last time this object was " 176 "updated. This value is present for use by " 177 "backends and shouldn't be written by other " 181 g_object_class_install_property
184 g_param_spec_int (
"editlevel",
186 "The object edit level.",
190 g_object_class_install_property
193 g_param_spec_boolean (
"destroying",
195 "This flag is set to TRUE if the object is " 196 "about to be destroyed.",
200 g_object_class_install_property
203 g_param_spec_boolean (
"dirty",
205 "This flag is set to TRUE if the object has " 210 g_object_class_install_property
213 g_param_spec_boolean (
"infant",
215 "This flag is set to TRUE if the object has " 216 "never been added to a book. This implies " 217 "that its destruction does not affect the " 218 "state of the book, and therefore the saved " 219 "state of the data file.",
223 g_object_class_install_property
226 g_param_spec_int (
"version",
228 "The version number of the current instance state.",
234 g_object_class_install_property
237 g_param_spec_uint (
"version-check",
239 "The version check number of the current instance state.",
245 g_object_class_install_property
248 g_param_spec_uint (
"idata",
250 "Per instance backend private data.",
260 priv = GET_PRIVATE(inst);
261 priv->book =
nullptr;
262 inst->kvp_data =
new KvpFrame;
263 priv->last_update = 0;
265 priv->do_free = FALSE;
277 g_return_if_fail(QOF_IS_INSTANCE(inst));
278 priv = GET_PRIVATE(inst);
279 g_return_if_fail(!priv->book);
283 g_return_if_fail(col !=
nullptr);
289 if (g_strcmp0(col_type, type))
291 PERR (
"attempt to insert \"%s\" into \"%s\"", type, col_type);
294 priv = GET_PRIVATE(inst);
304 PWARN(
"duplicate id created, trying again");
314 qof_instance_dispose (GObject *instp)
319 priv = GET_PRIVATE(instp);
321 qof_collection_remove_entity(inst);
323 CACHE_REMOVE(inst->
e_type);
326 G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp);
330 qof_instance_finalize_real (GObject *instp)
335 delete inst->kvp_data;
336 inst->kvp_data =
nullptr;
338 priv = GET_PRIVATE(inst);
340 priv->do_free = FALSE;
351 qof_instance_get_property (GObject *
object,
359 g_return_if_fail(QOF_IS_INSTANCE(
object));
361 inst = QOF_INSTANCE(
object);
362 priv = GET_PRIVATE(inst);
367 g_value_set_boxed(value, &priv->
guid);
369 case PROP_COLLECTION:
373 g_value_take_object(value, priv->book);
375 case PROP_LAST_UPDATE:
376 g_value_set_pointer(value, &priv->last_update);
379 g_value_set_int(value, priv->editlevel);
381 case PROP_DESTROYING:
382 g_value_set_boolean(value, priv->do_free);
385 g_value_set_boolean(value, qof_instance_get_dirty(inst));
388 g_value_set_boolean(value, priv->infant);
391 g_value_set_int(value, priv->version);
393 case PROP_VERSION_CHECK:
394 g_value_set_uint(value, priv->version_check);
397 g_value_set_uint(value, priv->idata);
400 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
406 qof_instance_set_property (GObject *
object,
414 g_return_if_fail(QOF_IS_INSTANCE(
object));
416 inst = QOF_INSTANCE(
object);
421 qof_instance_set_guid(inst,
422 static_cast<GncGUID*>(g_value_get_boxed(value)));
424 case PROP_COLLECTION:
425 qof_instance_set_collection(inst, static_cast<QofCollection*>(g_value_get_pointer(value)));
429 static_cast<QofBook*>(g_value_get_object(value)));
431 case PROP_LAST_UPDATE:
432 t = *(
static_cast<Time64*
>(g_value_get_pointer(value)));
433 qof_instance_set_last_update(inst, t.t);
435 case PROP_DESTROYING:
436 qof_instance_set_destroying(inst, g_value_get_boolean(value));
439 qof_instance_set_dirty(inst);
442 qof_instance_set_version(inst, g_value_get_int(value));
444 case PROP_VERSION_CHECK:
445 qof_instance_set_version_check(inst, g_value_get_uint(value));
448 qof_instance_set_idata(inst, g_value_get_uint(value));
451 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
461 if (!inst)
return nullptr;
462 g_return_val_if_fail(QOF_IS_INSTANCE(inst),
guid_null());
463 priv = GET_PRIVATE(inst);
464 return &(priv->
guid);
474 qof_instance_set_guid (gpointer ptr,
const GncGUID *guid)
480 g_return_if_fail(QOF_IS_INSTANCE(ptr));
482 inst = QOF_INSTANCE(ptr);
483 priv = GET_PRIVATE(inst);
488 qof_collection_remove_entity(inst);
494 qof_instance_copy_guid (gpointer to, gconstpointer from)
496 g_return_if_fail(QOF_IS_INSTANCE(to));
497 g_return_if_fail(QOF_IS_INSTANCE(from));
499 GET_PRIVATE(to)->guid = GET_PRIVATE(from)->guid;
507 g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), -1);
508 g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), 1);
510 priv1 = GET_PRIVATE(ptr1);
511 priv2 = GET_PRIVATE(ptr2);
513 return guid_compare(&priv1->
guid, &priv2->
guid);
520 g_return_val_if_fail(QOF_IS_INSTANCE(ptr),
nullptr);
521 return GET_PRIVATE(ptr)->collection;
525 qof_instance_set_collection (gconstpointer ptr, QofCollection *col)
527 g_return_if_fail(QOF_IS_INSTANCE(ptr));
528 GET_PRIVATE(ptr)->collection = col;
534 if (!inst)
return nullptr;
535 g_return_val_if_fail(QOF_IS_INSTANCE(inst),
nullptr);
536 return GET_PRIVATE(inst)->book;
542 g_return_if_fail(QOF_IS_INSTANCE(inst));
543 GET_PRIVATE(inst)->book = book;
549 g_return_if_fail(QOF_IS_INSTANCE(ptr1));
550 g_return_if_fail(QOF_IS_INSTANCE(ptr2));
552 GET_PRIVATE(ptr1)->book = GET_PRIVATE(ptr2)->book;
560 g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), FALSE);
561 g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), FALSE);
563 priv1 = GET_PRIVATE(ptr1);
564 priv2 = GET_PRIVATE(ptr2);
566 return (priv1->book == priv2->book);
573 if (!inst)
return nullptr;
574 return inst->kvp_data;
578 qof_instance_set_slots (
QofInstance *inst, KvpFrame *frm)
584 priv = GET_PRIVATE(inst);
585 if (inst->kvp_data && (inst->kvp_data != frm))
587 delete inst->kvp_data;
591 inst->kvp_data = frm;
598 GET_PRIVATE(inst)->last_update = t;
602 qof_instance_get_editlevel (gconstpointer ptr)
604 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), 0);
605 return GET_PRIVATE(ptr)->editlevel;
608 void qof_instance_increase_editlevel (gpointer ptr)
610 g_return_if_fail(QOF_IS_INSTANCE(ptr));
611 GET_PRIVATE(ptr)->editlevel++;
614 void qof_instance_decrease_editlevel (gpointer ptr)
616 g_return_if_fail(QOF_IS_INSTANCE(ptr));
617 GET_PRIVATE(ptr)->editlevel--;
620 void qof_instance_reset_editlevel (gpointer ptr)
622 g_return_if_fail(QOF_IS_INSTANCE(ptr));
623 GET_PRIVATE(ptr)->editlevel = 0;
631 if (!left && !right)
return 0;
632 if (!left)
return -1;
633 if (!right)
return +1;
635 lpriv = GET_PRIVATE(left);
636 rpriv = GET_PRIVATE(right);
637 return lpriv->last_update < rpriv->last_update ? -1 :
638 lpriv->last_update > rpriv->last_update ? 1 : 0;
644 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
645 return GET_PRIVATE(ptr)->do_free;
649 qof_instance_set_destroying (gpointer ptr, gboolean value)
651 g_return_if_fail(QOF_IS_INSTANCE(ptr));
652 GET_PRIVATE(ptr)->do_free = value;
658 g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
659 return GET_PRIVATE(ptr)->dirty;
663 qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag)
665 g_return_if_fail(QOF_IS_INSTANCE(inst));
666 GET_PRIVATE(inst)->dirty = flag;
673 GET_PRIVATE(inst)->dirty = FALSE;
677 qof_instance_print_dirty (
const QofInstance *inst, gpointer dummy)
681 priv = GET_PRIVATE(inst);
686 printf(
"%s instance %s is dirty.\n", inst->
e_type, guidstr);
700 priv = GET_PRIVATE(inst);
709 priv = GET_PRIVATE(inst);
716 g_return_val_if_fail(QOF_IS_INSTANCE(inst), FALSE);
717 return GET_PRIVATE(inst)->infant;
721 qof_instance_get_version (gconstpointer inst)
723 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
724 return GET_PRIVATE(inst)->version;
728 qof_instance_set_version (gpointer inst, gint32 vers)
730 g_return_if_fail(QOF_IS_INSTANCE(inst));
731 GET_PRIVATE(inst)->version = vers;
735 qof_instance_copy_version (gpointer to, gconstpointer from)
737 g_return_if_fail(QOF_IS_INSTANCE(to));
738 g_return_if_fail(QOF_IS_INSTANCE(from));
739 GET_PRIVATE(to)->version = GET_PRIVATE(from)->version;
743 qof_instance_get_version_check (gconstpointer inst)
745 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
746 return GET_PRIVATE(inst)->version_check;
750 qof_instance_set_version_check (gpointer inst, guint32 value)
752 g_return_if_fail(QOF_IS_INSTANCE(inst));
753 GET_PRIVATE(inst)->version_check = value;
757 qof_instance_copy_version_check (gpointer to, gconstpointer from)
759 g_return_if_fail(QOF_IS_INSTANCE(to));
760 g_return_if_fail(QOF_IS_INSTANCE(from));
761 GET_PRIVATE(to)->version_check = GET_PRIVATE(from)->version_check;
770 g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
771 return GET_PRIVATE(inst)->idata;
774 void qof_instance_set_idata(gpointer inst, guint32 idata)
780 g_return_if_fail(QOF_IS_INSTANCE(inst));
781 GET_PRIVATE(inst)->idata = idata;
789 g_return_val_if_fail( inst !=
nullptr,
nullptr );
791 if ( QOF_INSTANCE_GET_CLASS(inst)->get_display_name !=
nullptr )
793 return QOF_INSTANCE_GET_CLASS(inst)->get_display_name(inst);
798 return g_strdup_printf(
"Object %s %p",
811 get_referring_object_instance_helper(
QofInstance* inst, gpointer user_data)
815 if (*pInst ==
nullptr)
822 get_referring_object_helper(QofCollection* coll, gpointer user_data)
827 qof_collection_foreach(coll, get_referring_object_instance_helper, &first_instance);
829 if (first_instance !=
nullptr)
832 data->list = g_list_concat(data->list, new_list);
841 g_return_val_if_fail( inst !=
nullptr,
nullptr );
848 get_referring_object_helper,
854 get_typed_referring_object_instance_helper(
QofInstance* inst, gpointer user_data)
860 data->list = g_list_prepend(data->list, inst);
869 g_return_val_if_fail( coll !=
nullptr,
nullptr );
870 g_return_val_if_fail( ref !=
nullptr,
nullptr );
875 qof_collection_foreach(coll, get_typed_referring_object_instance_helper, &data);
882 g_return_val_if_fail( inst !=
nullptr,
nullptr );
883 g_return_val_if_fail( ref !=
nullptr,
nullptr );
885 if ( QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list !=
nullptr )
887 return QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list(inst, ref);
903 g_return_val_if_fail( inst !=
nullptr, FALSE );
904 g_return_val_if_fail( ref !=
nullptr, FALSE );
906 if ( QOF_INSTANCE_GET_CLASS(inst)->refers_to_object !=
nullptr )
908 return QOF_INSTANCE_GET_CLASS(inst)->refers_to_object(inst, ref);
922 g_return_if_fail (QOF_IS_INSTANCE (inst));
924 va_start (ap, first_prop);
925 g_object_get_valist (G_OBJECT (inst), first_prop, ap);
933 g_return_if_fail (QOF_IS_INSTANCE (inst));
935 qof_instance_set_dirty (inst);
936 va_start (ap, first_prop);
937 g_object_set_valist (G_OBJECT (inst), first_prop, ap);
951 if (!inst)
return FALSE;
953 priv = GET_PRIVATE(inst);
955 if (1 < priv->editlevel)
return FALSE;
956 if (0 >= priv->editlevel)
972 if (!inst)
return FALSE;
974 priv = GET_PRIVATE(inst);
976 if (0 < priv->editlevel)
return FALSE;
978 if (0 > priv->editlevel)
980 PERR (
"unbalanced call - resetting (was %d)", priv->editlevel);
994 priv = GET_PRIVATE(inst);
997 !(priv->infant && priv->do_free)) {
1011 errcode = be->get_error();
1013 while (errcode != ERR_BACKEND_NO_ERR);
1016 errcode = be->get_error();
1017 if (errcode != ERR_BACKEND_NO_ERR)
1020 priv->do_free = FALSE;
1023 be->set_error (errcode);
1025 on_error(inst, errcode);
1029 priv->infant = FALSE;
1047 return (inst->kvp_data !=
nullptr && !inst->kvp_data->empty());
1050 void qof_instance_set_path_kvp (
QofInstance * inst, GValue
const * value, std::vector<std::string>
const & path)
1058 std::vector<std::string> path;
1060 va_start (args, count);
1061 for (
unsigned i{0}; i < count; ++i)
1062 path.push_back (va_arg (args,
char const *));
1067 template <
typename T> std::optional<T>
1068 qof_instance_get_path_kvp (
QofInstance* inst,
const Path& path)
1070 g_return_val_if_fail (QOF_IS_INSTANCE(inst), std::nullopt);
1071 auto kvp_value{inst->kvp_data->get_slot(path)};
1072 return kvp_value ? std::make_optional<T>(kvp_value->get<T>()) :
std::nullopt;
1075 template <
typename T>
void 1076 qof_instance_set_path_kvp (
QofInstance* inst, std::optional<T> value,
const Path& path)
1078 g_return_if_fail (QOF_IS_INSTANCE(inst));
1079 delete inst->kvp_data->set_path(path, value ?
new KvpValue(*value) :
nullptr);
1080 qof_instance_set_dirty (inst);
1083 template std::optional<const char*> qof_instance_get_path_kvp <const char*> (
QofInstance*,
const Path&);
1084 template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (
QofInstance*,
const Path&);
1085 template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (
QofInstance*,
const Path&);
1086 template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (
QofInstance*,
const Path&);
1088 template void qof_instance_set_path_kvp <const char*> (
QofInstance*, std::optional<const char*>,
const Path& path);
1089 template void qof_instance_set_path_kvp <gnc_numeric> (
QofInstance*, std::optional<gnc_numeric>,
const Path& path);
1090 template void qof_instance_set_path_kvp <GncGUID*> (
QofInstance*, std::optional<GncGUID*>,
const Path& path);
1091 template void qof_instance_set_path_kvp <int64_t> (
QofInstance*, std::optional<int64_t>,
const Path& path);
1093 void qof_instance_get_path_kvp (
QofInstance * inst, GValue * value, std::vector<std::string>
const & path)
1101 std::vector<std::string> path;
1103 va_start (args, count);
1104 for (
unsigned i{0}; i < count; ++i)
1105 path.push_back (va_arg (args,
char const *));
1113 delete to->kvp_data;
1114 to->kvp_data =
new KvpFrame(*from->kvp_data);
1120 std::swap(a->kvp_data, b->kvp_data);
1126 return compare(a->kvp_data, b->kvp_data);
1130 qof_instance_kvp_as_string (
const QofInstance *inst)
1132 auto str{inst->kvp_data->to_string()};
1133 return g_strdup(str.c_str());
1137 qof_instance_kvp_add_guid (
const QofInstance *inst,
const char* path,
1138 time64 time,
const char *key,
1141 g_return_if_fail (inst->kvp_data !=
nullptr);
1143 auto container =
new KvpFrame;
1145 container->set({key},
new KvpValue(const_cast<GncGUID*>(guid)));
1146 container->set({
"date"},
new KvpValue(t));
1147 delete inst->kvp_data->set_path({path},
new KvpValue(container));
1150 inline static gboolean
1151 kvp_match_guid (KvpValue *v, std::vector<std::string>
const & path,
const GncGUID *guid)
1153 if (v->get_type() != KvpValue::Type::FRAME)
1155 auto frame = v->get<KvpFrame*>();
1156 auto val = frame->get_slot(path);
1157 if (val ==
nullptr || val->get_type() != KvpValue::Type::GUID)
1159 auto this_guid = val->get<
GncGUID*>();
1165 qof_instance_kvp_has_guid (
const QofInstance *inst,
const char *path,
1166 const char* key,
const GncGUID *guid)
1168 g_return_val_if_fail (inst->kvp_data !=
nullptr, FALSE);
1169 g_return_val_if_fail (guid !=
nullptr, FALSE);
1171 auto v = inst->kvp_data->get_slot({path});
1172 if (v ==
nullptr)
return FALSE;
1174 switch (v->get_type())
1176 case KvpValue::Type::FRAME:
1177 return kvp_match_guid (v, {key}, guid);
1179 case KvpValue::Type::GLIST:
1181 auto list = v->get<GList*>();
1182 for (
auto node = list; node !=
nullptr; node = node->next)
1184 auto val =
static_cast<KvpValue*
>(node->data);
1185 if (kvp_match_guid (val, {key}, guid))
1193 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1200 qof_instance_kvp_remove_guid (
const QofInstance *inst,
const char *path,
1201 const char *key,
const GncGUID *guid)
1203 g_return_if_fail (inst->kvp_data !=
nullptr);
1204 g_return_if_fail (guid !=
nullptr);
1206 auto v = inst->kvp_data->get_slot({path});
1207 if (v ==
nullptr)
return;
1209 switch (v->get_type())
1211 case KvpValue::Type::FRAME:
1212 if (kvp_match_guid (v, {key}, guid))
1214 delete inst->kvp_data->set_path({path},
nullptr);
1218 case KvpValue::Type::GLIST:
1220 auto list = v->get<GList*>();
1221 for (
auto node = list; node !=
nullptr; node = node->next)
1223 auto val =
static_cast<KvpValue*
>(node->data);
1224 if (kvp_match_guid (val, {key}, guid))
1226 list = g_list_delete_link (list, node);
1235 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1242 qof_instance_kvp_merge_guids (
const QofInstance *target,
1245 g_return_if_fail (target !=
nullptr);
1246 g_return_if_fail (donor !=
nullptr);
1248 if (! qof_instance_has_slot (donor, path))
return;
1249 auto v = donor->kvp_data->get_slot({path});
1250 if (v ==
nullptr)
return;
1252 auto target_val = target->kvp_data->get_slot({path});
1253 switch (v->get_type())
1255 case KvpValue::Type::FRAME:
1259 target->kvp_data->set_path({path}, v);
1260 donor->kvp_data->set({path},
nullptr);
1262 case KvpValue::Type::GLIST:
1265 auto list = target_val->get<GList*>();
1266 list = g_list_concat(list, v->get<GList*>());
1267 target_val->set(list);
1270 target->kvp_data->set({path}, v);
1271 donor->kvp_data->set({path},
nullptr);
1274 PWARN (
"Instance KVP on path %s contains the wrong type.", path);
1279 bool qof_instance_has_path_slot (
QofInstance const * inst, std::vector<std::string>
const & path)
1281 return inst->kvp_data->get_slot (path) !=
nullptr;
1285 qof_instance_has_slot (
const QofInstance *inst,
const char *path)
1287 return inst->kvp_data->get_slot({path}) !=
nullptr;
1290 void qof_instance_slot_path_delete (
QofInstance const * inst, std::vector<std::string>
const & path)
1292 delete inst->kvp_data->set (path,
nullptr);
1296 qof_instance_slot_delete (
QofInstance const *inst,
char const * path)
1298 delete inst->kvp_data->set ({path},
nullptr);
1301 void qof_instance_slot_path_delete_if_empty (
QofInstance const * inst, std::vector<std::string>
const & path)
1303 auto slot = inst->kvp_data->get_slot (path);
1306 auto frame = slot->get <KvpFrame*> ();
1307 if (frame && frame->empty())
1308 delete inst->kvp_data->set (path,
nullptr);
1313 qof_instance_slot_delete_if_empty (
QofInstance const *inst,
char const * path)
1315 auto slot = inst->kvp_data->get_slot ({path});
1318 auto frame = slot->get <KvpFrame*> ();
1319 if (frame && frame->empty ())
1320 delete inst->kvp_data->set ({path},
nullptr);
1324 std::vector <std::pair <std::string, KvpValue*>>
1325 qof_instance_get_slots_prefix (
QofInstance const * inst, std::string
const & prefix)
1327 std::vector <std::pair <std::string, KvpValue*>> ret;
1328 inst->kvp_data->for_each_slot_temp ([&prefix, &ret] (std::string
const & key, KvpValue * val) {
1329 if (key.find (prefix) == 0)
1330 ret.emplace_back (key, val);
1338 void (*proc)(
const char*,
const GValue*,
void*);
1344 wrap_gvalue_function (
const char* key, KvpValue *val, wrap_param & param)
1347 if (val->get_type() != KvpValue::Type::FRAME)
1351 g_value_init (&gv, G_TYPE_STRING);
1352 g_value_set_string (&gv,
nullptr);
1354 param.proc(key, &gv, param.user_data);
1355 g_value_unset (&gv);
1359 qof_instance_foreach_slot (
const QofInstance *inst,
const char* head,
const char* category,
1360 void (*proc)(
const char*,
const GValue*,
void*),
void* data)
1362 std::vector<std::string> path {head};
1364 path.emplace_back (category);
1366 auto slot = inst->kvp_data->get_slot(path);
1367 if (slot ==
nullptr || slot->get_type() != KvpValue::Type::FRAME)
1369 auto frame = slot->get<KvpFrame*>();
1370 wrap_param new_data {proc, data};
1371 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.