|
||||||||||||
|
Pair things up. This routine inserts a kvp value into each instance containing the guid of the other. In this way, if one has one of the pair, one can always find the other by looking up it's guid. Typically, you will want to use qof_instance_lookup_twin() to find the twin. (The current implementation assumes the two instances belong to different books, and will not add gemini kvp's unless the books differ. Note that the gemini kvp includes the book guid as well, so that the right book can be found. Definition at line 200 of file qofinstance.c. 00201 { 00202 time_t now; 00203 00204 /* Books must differ for a gemini to be meaningful */ 00205 if (!from || !to || (from->book == to->book)) return; 00206 00207 now = time(0); 00208 00209 /* Make a note of where the copy came from */ 00210 gnc_kvp_bag_add (to->kvp_data, "gemini", now, 00211 "inst_guid", &from->entity.guid, 00212 "book_guid", &from->book->inst.entity.guid, 00213 NULL); 00214 gnc_kvp_bag_add (from->kvp_data, "gemini", now, 00215 "inst_guid", &to->entity.guid, 00216 "book_guid", &to->book->inst.entity.guid, 00217 NULL); 00218 00219 to->dirty = TRUE; 00220 }
|
|
|
Return the book pointer Definition at line 89 of file qofinstance.c.
|
|
|
Return the GUID of this instance Definition at line 82 of file qofinstance.c.
|
|
|
Return the last time this instance was modified. If QofInstances are used with the QofObject storage backends, then the instance update times are reserved for use by the backend, for managing multi-user updates. Non-backend code should not set the update times. Definition at line 103 of file qofinstance.c. 00104 { 00105 if (!inst) 00106 { 00107 Timespec ts = {0,-1}; 00108 return ts; 00109 } 00110 return inst->last_update; 00111 }
|
|
|
Return the pointer to the kvp_data Definition at line 96 of file qofinstance.c.
|
|
||||||||||||||||
|
Initialise the memory associated with an instance Definition at line 55 of file qofinstance.c. 00056 { 00057 QofCollection *col; 00058 00059 inst->book = book; 00060 inst->kvp_data = kvp_frame_new(); 00061 inst->last_update.tv_sec = 0; 00062 inst->last_update.tv_nsec = -1; 00063 inst->editlevel = 0; 00064 inst->do_free = FALSE; 00065 inst->dirty = FALSE; 00066 00067 col = qof_book_get_collection (book, type); 00068 qof_entity_init (&inst->entity, type, col); 00069 }
|
|
|
Return value of is_dirty flag Definition at line 127 of file qofinstance.c. 00128 { 00129 QofCollection *coll; 00130 00131 if (!inst) { return FALSE; } 00132 coll = inst->entity.collection; 00133 if(qof_collection_is_dirty(coll)) { return inst->dirty; } 00134 inst->dirty = FALSE; 00135 return FALSE; 00136 }
|
|
||||||||||||
|
The qof_instance_lookup_twin() routine will find the "twin" of this instance 'src' in the given other 'book' (if the twin exists). When instances are gemini'ed or cloned, both of the pair are marked with the guid of thier copy, thus allowing the sibling-copy of an instance to be found. Since the sibling may end up in a different book, we need a way of finding it, given only that we know the book, and that we know its twin. That's what this routine does. Given some book 'book', and an instance 'src', it will find the sibling instance of 'src' that is in 'book', and return it. If not found, it returns NULL. This routine uses the 'gemini' kvp values to do its work. Definition at line 223 of file qofinstance.c. 00224 { 00225 QofCollection *col; 00226 KvpFrame *fr; 00227 GUID * twin_guid; 00228 QofInstance * twin; 00229 00230 if (!src || !target_book) return NULL; 00231 ENTER (" "); 00232 00233 fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini", 00234 "book_guid", &target_book->inst.entity.guid); 00235 00236 twin_guid = kvp_frame_get_guid (fr, "inst_guid"); 00237 00238 col = qof_book_get_collection (target_book, src->entity.e_type); 00239 twin = (QofInstance *) qof_collection_lookup_entity (col, twin_guid); 00240 00241 LEAVE (" found twin=%p", twin); 00242 return twin; 00243 }
|
|
|
release the data associated with this instance. Dont actually free the memory associated with the instance. Definition at line 72 of file qofinstance.c. 00073 { 00074 kvp_frame_delete (inst->kvp_data); 00075 inst->editlevel = 0; 00076 inst->do_free = FALSE; 00077 inst->dirty = FALSE; 00078 qof_entity_release (&inst->entity); 00079 }
|
|
|
Set the dirty flag. Sets this instance AND the collection as dirty. Definition at line 139 of file qofinstance.c. 00140 { 00141 QofCollection *coll; 00142 00143 inst->dirty = TRUE; 00144 coll = inst->entity.collection; 00145 qof_collection_mark_dirty(coll); 00146 }
|
|
||||||||||||
|
Compare two instances, based on thier 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 114 of file qofinstance.c. 00115 { 00116 if (!left && !right) return 0; 00117 if (!left) return -1; 00118 if (!right) return +1; 00119 if (left->last_update.tv_sec < right->last_update.tv_sec) return -1; 00120 if (left->last_update.tv_sec > right->last_update.tv_sec) return +1; 00121 if (left->last_update.tv_nsec < right->last_update.tv_nsec) return -1; 00122 if (left->last_update.tv_nsec > right->last_update.tv_nsec) return +1; 00123 return 0; 00124 }
|
1.4.5