GnuCash  3.0-89-gc4e5e18+
Files | Data Structures | Macros | Functions

Qof Instances are a derived type of QofInstance. More...

Files

file  qofinstance.h
 Object instance holds common fields that most gnucash objects use.
 

Data Structures

struct  QofInstance
 
struct  QofInstanceClass
 

Macros

#define QOF_TYPE_INSTANCE   (qof_instance_get_type ())
 
#define QOF_INSTANCE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_INSTANCE, QofInstance))
 
#define QOF_INSTANCE_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_INSTANCE, QofInstanceClass))
 
#define QOF_IS_INSTANCE(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_INSTANCE))
 
#define QOF_IS_INSTANCE_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_INSTANCE))
 
#define QOF_INSTANCE_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_INSTANCE, QofInstanceClass))
 
#define qof_instance_is_dirty   qof_instance_get_dirty
 Return value of is_dirty flag.
 

Functions

GType qof_instance_get_type (void)
 Return the GType of a QofInstance.
 
void qof_instance_init_data (QofInstance *, QofIdType, QofBook *)
 Initialise the settings associated with an instance.
 
QofBook * qof_instance_get_book (gconstpointer)
 Return the book pointer.
 
void qof_instance_set_book (gconstpointer inst, QofBook *book)
 Set the book pointer.
 
void qof_instance_copy_book (gpointer ptr1, gconstpointer ptr2)
 Copy the book from one QofInstances to another. More...
 
gboolean qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2)
 See if two QofInstances share the same book. More...
 
const GncGUIDqof_instance_get_guid (gconstpointer)
 Return the GncGUID of this instance.
 
const GncGUIDqof_entity_get_guid (gconstpointer)
 
QofCollection * qof_instance_get_collection (gconstpointer inst)
 Return the collection this instance belongs to.
 
gint qof_instance_guid_compare (const gconstpointer ptr1, const gconstpointer ptr2)
 Compare the GncGUID values of two instances. More...
 
gint qof_instance_get_editlevel (gconstpointer ptr)
 
int qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
 Compare two instances, based on their last update times. More...
 
gboolean qof_instance_get_destroying (gconstpointer ptr)
 Retrieve the flag that indicates whether or not this object is about to be destroyed. More...
 
gboolean qof_instance_get_dirty_flag (gconstpointer ptr)
 Retrieve the flag that indicates whether or not this object has been modified. More...
 
void qof_instance_print_dirty (const QofInstance *entity, gpointer dummy)
 
gboolean qof_instance_get_dirty (QofInstance *)
 
gboolean qof_instance_get_infant (const QofInstance *inst)
 
void qof_instance_get (const QofInstance *inst, const gchar *first_param,...)
 Wrapper for g_object_get.
 
void qof_instance_set (QofInstance *inst, const gchar *first_param,...)
 Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
 
guint32 qof_instance_get_idata (gconstpointer inst)
 get the instance tag number used for kvp management in sql backends. More...
 
gchar * qof_instance_get_display_name (const QofInstance *inst)
 Returns a displayable name for this object. More...
 
GList * qof_instance_get_referring_object_list (const QofInstance *inst)
 Returns a list of objects which refer to a specific object. More...
 
gboolean qof_instance_refers_to_object (const QofInstance *inst, const QofInstance *ref)
 Does this object refer to a specific object.
 
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. More...
 
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. More...
 

Detailed Description

Qof Instances are a derived type of QofInstance.

The Instance adds some common features and functions that most objects will want to use.

Function Documentation

◆ qof_entity_get_guid()

const GncGUID* qof_entity_get_guid ( gconstpointer  )
Deprecated:
Use qof_instance_get_guid instead.

Works like qof_instance_get_guid, but returns NULL on NULL

Definition at line 474 of file qofinstance.cpp.

475 {
476  return ent ? qof_instance_get_guid(ent) : guid_null();
477 }
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
Definition: guid.cpp:131

◆ qof_instance_books_equal()

gboolean qof_instance_books_equal ( gconstpointer  ptr1,
gconstpointer  ptr2 
)

See if two QofInstances share the same book.

Definition at line 562 of file qofinstance.cpp.

563 {
564  const QofInstancePrivate *priv1, *priv2;
565 
566  g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), FALSE);
567  g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), FALSE);
568 
569  priv1 = GET_PRIVATE(ptr1);
570  priv2 = GET_PRIVATE(ptr2);
571 
572  return (priv1->book == priv2->book);
573 }

◆ qof_instance_copy_book()

void qof_instance_copy_book ( gpointer  ptr1,
gconstpointer  ptr2 
)

Copy the book from one QofInstances to another.

Definition at line 553 of file qofinstance.cpp.

554 {
555  g_return_if_fail(QOF_IS_INSTANCE(ptr1));
556  g_return_if_fail(QOF_IS_INSTANCE(ptr2));
557 
558  GET_PRIVATE(ptr1)->book = GET_PRIVATE(ptr2)->book;
559 }

◆ qof_instance_get_destroying()

gboolean qof_instance_get_destroying ( gconstpointer  ptr)

Retrieve the flag that indicates whether or not this object is about to be destroyed.

Parameters
ptrThe object whose flag should be retrieved.
Returns
TRUE if the object has been marked for destruction. FALSE if the object is not marked for destruction, or if a bad parameter is passed to the function.

Definition at line 651 of file qofinstance.cpp.

652 {
653  g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
654  return GET_PRIVATE(ptr)->do_free;
655 }

◆ qof_instance_get_dirty_flag()

gboolean qof_instance_get_dirty_flag ( gconstpointer  ptr)

Retrieve the flag that indicates whether or not this object has been modified.

This is specifically the flag on the object. It does not perform any other checking which might normally be performed when testing to see if an object is dirty. If there is any question, use the qof_instance_is_dirty() function instead.

Parameters
ptrThe object whose flag should be retrieved.
Returns
TRUE if the object has been modified and not saved. FALSE if the object has not been modified, or if a bad parameter is passed to the function.

Definition at line 665 of file qofinstance.cpp.

666 {
667  g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
668  return GET_PRIVATE(ptr)->dirty;
669 }

◆ qof_instance_get_display_name()

gchar* qof_instance_get_display_name ( const QofInstance *  inst)

Returns a displayable name for this object.

The returned string must be freed by the caller.

Definition at line 798 of file qofinstance.cpp.

799 {
800  g_return_val_if_fail( inst != NULL, NULL );
801 
802  if ( QOF_INSTANCE_GET_CLASS(inst)->get_display_name != NULL )
803  {
804  return QOF_INSTANCE_GET_CLASS(inst)->get_display_name(inst);
805  }
806  else
807  {
808  /* Not implemented - return default string */
809  return g_strdup_printf("Object %s %p",
811  inst);
812  }
813 }
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.
QofIdType qof_collection_get_type(const QofCollection *col)
return the type that the collection stores
Definition: qofid.cpp:75

◆ qof_instance_get_idata()

guint32 qof_instance_get_idata ( gconstpointer  inst)

get the instance tag number used for kvp management in sql backends.

Definition at line 775 of file qofinstance.cpp.

776 {
777  if (!inst)
778  {
779  return 0;
780  }
781  g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
782  return GET_PRIVATE(inst)->idata;
783 }

◆ qof_instance_get_referring_object_list()

GList* qof_instance_get_referring_object_list ( const QofInstance *  inst)

Returns a list of objects which refer to a specific object.

The list must be freed by the caller, but the objects on the list must not.

Definition at line 848 of file qofinstance.cpp.

849 {
851 
852  g_return_val_if_fail( inst != NULL, NULL );
853 
854  /* scan all collections */
855  data.inst = inst;
856  data.list = NULL;
857 
858  qof_book_foreach_collection(qof_instance_get_book(inst),
859  get_referring_object_helper,
860  &data);
861  return data.list;
862 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.

◆ qof_instance_get_referring_object_list_from_collection()

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.

The list must be freed by the caller but the objects on the list must not.

Definition at line 876 of file qofinstance.cpp.

877 {
879 
880  g_return_val_if_fail( coll != NULL, NULL );
881  g_return_val_if_fail( ref != NULL, NULL );
882 
883  data.inst = ref;
884  data.list = NULL;
885 
886  qof_collection_foreach(coll, get_typed_referring_object_instance_helper, &data);
887  return data.list;
888 }
void qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Call the callback for each entity in the collection.
Definition: qofid.cpp:321

◆ qof_instance_get_typed_referring_object_list()

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.

For example, when called as qof_instance_get_typed_referring_object_list(taxtable, account); it will return the list of taxtables which refer to a specific account. The result should be the same regardless of which taxtable object is used. The list must be freed by the caller but the objects on the list must not.

Definition at line 891 of file qofinstance.cpp.

892 {
893  g_return_val_if_fail( inst != NULL, NULL );
894  g_return_val_if_fail( ref != NULL, NULL );
895 
896  if ( QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list != NULL )
897  {
898  return QOF_INSTANCE_GET_CLASS(inst)->get_typed_referring_object_list(inst, ref);
899  }
900  else
901  {
902  /* Not implemented - by default, loop through all objects of this object's type and check
903  them individually. */
904  QofCollection* coll;
905 
906  coll = qof_instance_get_collection(inst);
908  }
909 }
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. ...
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.

◆ qof_instance_guid_compare()

gint qof_instance_guid_compare ( const gconstpointer  ptr1,
const gconstpointer  ptr2 
)

Compare the GncGUID values of two instances.

This routine returns 0 if the two values are equal, <0 if the first is smaller than the second, or >0 if the second is smaller tan the first.

Definition at line 509 of file qofinstance.cpp.

510 {
511  const QofInstancePrivate *priv1, *priv2;
512 
513  g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), -1);
514  g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), 1);
515 
516  priv1 = GET_PRIVATE(ptr1);
517  priv2 = GET_PRIVATE(ptr2);
518 
519  return guid_compare(&priv1->guid, &priv2->guid);
520 }
GncGUID guid
GncGUID for the entity.
Definition: qofinstance.cpp:77

◆ qof_instance_version_cmp()

int qof_instance_version_cmp ( const QofInstance *  left,
const QofInstance *  right 
)

Compare two instances, based on their last update times.

Returns a negative, zero or positive value, respectively, if 'left' is earlier, same as or later than 'right'. Accepts NULL pointers, NULL's are by definition earlier than any value.

Definition at line 633 of file qofinstance.cpp.

634 {
635  QofInstancePrivate *lpriv, *rpriv;
636 
637  if (!left && !right) return 0;
638  if (!left) return -1;
639  if (!right) return +1;
640 
641  lpriv = GET_PRIVATE(left);
642  rpriv = GET_PRIVATE(right);
643  if (lpriv->last_update.tv_sec < rpriv->last_update.tv_sec) return -1;
644  if (lpriv->last_update.tv_sec > rpriv->last_update.tv_sec) return +1;
645  if (lpriv->last_update.tv_nsec < rpriv->last_update.tv_nsec) return -1;
646  if (lpriv->last_update.tv_nsec > rpriv->last_update.tv_nsec) return +1;
647  return 0;
648 }