GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Macros | Typedefs | Functions

Files

file  qofid.h
 QOF entity type identification system.
 

Macros

#define QOF_ID_NONE   NULL
 
#define QOF_ID_NULL   "null"
 
#define QOF_ID_BOOK   "Book"
 
#define QOF_ID_SESSION   "Session"
 
#define QSTRCMP(da, db)
 
#define QOF_CHECK_TYPE(obj, type)
 
#define QOF_CHECK_CAST(obj, e_type, c_type)
 

Typedefs

typedef const gchar * QofIdType
 
typedef const gchar * QofIdTypeConst
 
typedef const gchar * QofLogModule
 
typedef struct QofCollection_s QofCollection
 

Functions

gboolean qof_get_alt_dirty_mode (void)
 
void qof_set_alt_dirty_mode (gboolean enabled)
 

Collections of Entities

typedef void(* QofInstanceForeachCB )(QofInstance *, gpointer user_data)
 
QofCollection * qof_collection_new (QofIdType type)
 
guint qof_collection_count (const QofCollection *col)
 
void qof_collection_destroy (QofCollection *col)
 
QofIdType qof_collection_get_type (const QofCollection *)
 
QofInstanceqof_collection_lookup_entity (const QofCollection *, const GncGUID *)
 
void qof_collection_foreach (const QofCollection *, QofInstanceForeachCB, gpointer user_data)
 
gpointer qof_collection_get_data (const QofCollection *col)
 
void qof_collection_set_data (QofCollection *col, gpointer user_data)
 
gboolean qof_collection_is_dirty (const QofCollection *col)
 

QOF_TYPE_COLLECT: Linking one entity to many of one type

Note
These are NOT the same as the main collections in the book.

QOF_TYPE_COLLECT is a secondary collection, used to select entities of one object type as references of another entity.

See Also
QOF_TYPE_CHOICE.
gboolean qof_collection_add_entity (QofCollection *coll, QofInstance *ent)
 Add an entity to a QOF_TYPE_COLLECT. More...
 
void qof_collection_remove_entity (QofInstance *ent)
 
gint qof_collection_compare (QofCollection *target, QofCollection *merge)
 Compare two secondary collections. More...
 
QofCollection * qof_collection_from_glist (QofIdType type, const GList *glist)
 Create a secondary collection from a GList. More...
 

Detailed Description

This file defines an API that adds types to the GncGUID's. GncGUID's with types can be used to identify and reference typed entities.

The idea here is that a GncGUID can be used to uniquely identify some thing. By adding a type, one can then talk about the type of thing identified. By adding a collection, one can then work with a handle to a collection of things of a given type, each uniquely identified by a given ID. QOF Entities can be used independently of any other part of the system. In particular, Entities can be useful even if one is not using the Query ond Object parts of the QOF system.

Identifiers are globally-unique and permanent, i.e., once an entity has been assigned an identifier, it retains that same identifier for its lifetime. Identifiers can be encoded as hex strings.

GncGUID Identifiers are 'typed' with strings. The native ids used by QOF are defined below.

  1. An id with type QOF_ID_NONE does not refer to any entity.
  2. An id with type QOF_ID_NULL does not refer to any entity, and will never refer to any entity. =# An identifier with any other type may refer to an actual entity, but that is not guaranteed as that entity does not have to exist within the current book. (See ::PARTIAL_QOFBOOK). Also, creating a new entity from a data source involves creating a temporary GncGUID and then setting the value from the data source. If an id does refer to an entity, the type of the entity will match the type of the identifier.

If you have a type name, and you want to have a way of finding a collection that is associated with that type, then you must use Books.

Entities can refer to other entities as well as to the basic
QOF types, using the qofclass parameters.

Macro Definition Documentation

#define QOF_CHECK_CAST (   obj,
  e_type,
  c_type 
)
Value:
( \
QOF_CHECK_TYPE((obj),(e_type)) ? \
(c_type *) (obj) : \
(c_type *) ({ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
"Error: Bad QofInstance at %s:%d", __FILE__, __LINE__); \
(obj); \
}))
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define QOF_CHECK_TYPE(obj, type)
Definition: qofid.h:124

cast object to the indicated type, print error message if its bad

Definition at line 129 of file qofid.h.

#define QOF_CHECK_TYPE (   obj,
  type 
)
Value:
(((obj) != NULL) && \
(0 == QSTRCMP((type),(((QofInstance *)(obj))->e_type))))
#define QSTRCMP(da, db)
Definition: qofid.h:103

return TRUE if object is of the given type

Definition at line 124 of file qofid.h.

#define QSTRCMP (   da,
  db 
)
Value:
({ \
gint val = 0; \
if ((da) && (db)) { \
if ((da) != (db)) { \
val = strcmp ((da), (db)); \
} \
} else \
if ((!(da)) && (db)) { \
val = -1; \
} else \
if ((da) && (!(db))) { \
val = 1; \
} \
val; /* block assumes value of last statement */ \
})

Inline string comparision; compiler will optimize away most of this

Definition at line 103 of file qofid.h.

Typedef Documentation

typedef const gchar* QofIdType

QofIdType declaration

Definition at line 85 of file qofid.h.

typedef const gchar* QofIdTypeConst

QofIdTypeConst declaration

Definition at line 87 of file qofid.h.

typedef void(* QofInstanceForeachCB)(QofInstance *, gpointer user_data)

Callback type for qof_collection_foreach

Definition at line 186 of file qofid.h.

typedef const gchar* QofLogModule

QofLogModule declaration

Definition at line 89 of file qofid.h.

Function Documentation

gboolean qof_collection_add_entity ( QofCollection *  coll,
QofInstance ent 
)

Add an entity to a QOF_TYPE_COLLECT.

Note
These are NOT the same as the main collections in the book.

Entities can be freely added and merged across these secondary collections, they will not be removed from the original collection as they would by using ::qof_instance_insert_entity or ::qof_instance_remove_entity.

gint qof_collection_compare ( QofCollection *  target,
QofCollection *  merge 
)

Compare two secondary collections.

Performs a deep comparision of the collections. Each QofInstance in each collection is looked up in the other collection, via the GncGUID.

Returns
0 if the collections are identical or both are NULL otherwise -1 if target is NULL or either collection contains an entity with an invalid GncGUID or if the types of the two collections do not match, or +1 if merge is NULL or if any entity exists in one collection but not in the other.
guint qof_collection_count ( const QofCollection *  col)

return the number of entities in the collection.

void qof_collection_destroy ( QofCollection *  col)

destroy the collection

void qof_collection_foreach ( const QofCollection *  ,
QofInstanceForeachCB  ,
gpointer  user_data 
)

Call the callback for each entity in the collection.

QofCollection* qof_collection_from_glist ( QofIdType  type,
const GList *  glist 
)

Create a secondary collection from a GList.

Parameters
typeThe QofIdType of the QofCollection and of all entities in the GList.
glistGList of entities of the same QofIdType.
Returns
NULL if any of the entities fail to match the QofCollection type, else a pointer to the collection on success.
gpointer qof_collection_get_data ( const QofCollection *  col)

Store and retreive arbitrary object-defined data

XXX We need to add a callback for when the collection is being destroyed, so that the user has a chance to clean up anything that was put in the 'data' member here.

QofIdType qof_collection_get_type ( const QofCollection *  )

return the type that the collection stores

gboolean qof_collection_is_dirty ( const QofCollection *  col)

Return value of 'dirty' flag on collection

QofInstance* qof_collection_lookup_entity ( const QofCollection *  ,
const GncGUID  
)

Find the entity going only from its guid

QofCollection* qof_collection_new ( QofIdType  type)

create a new collection of entities of type

gboolean qof_get_alt_dirty_mode ( void  )

QofCollection declaration

Parameters
e_typeQofIdType
is_dirtygboolean
hash_of_entitiesGHashTable
datagpointer, place where object class can hang arbitrary data Is QOF operating in "alternate" dirty mode?

In normal mode, whenever an instance is dirtied, the collection (and therefore the book) is immediately marked as dirty. In alternate mode, the collection is only marked dirty when a dirty instance is committed. If a dirty instance is freed instead of committed, the dirty state of collection (and therefore the book) is never changed.

void qof_set_alt_dirty_mode ( gboolean  enabled)

Set QOF into "alternate" dirty mode. In normal mode, whenever an instance is dirtied, the collection (and therefore the book) is immediately marked as dirty. In alternate mode, the collection is only marked dirty when a dirty instance is committed. If a dirty instance is freed instead of committed, the dirty state of collection (and therefore the book) is never changed.