|
GnuCash c935c2f+
|
Each price in the database represents an "instantaneous" quote for a given commodity with respect to another commodity. More...
Macros | |
| #define | PRICE_TYPE_LAST "last" |
| #define | PRICE_TYPE_UNK "unknown" |
| #define | PRICE_TYPE_TRN "transaction" |
Typedefs | |
| typedef GList | PriceList |
Enumerations | |
| enum | PriceSource { PRICE_SOURCE_EDIT_DLG , PRICE_SOURCE_FQ , PRICE_SOURCE_USER_PRICE , PRICE_SOURCE_XFER_DLG_VAL , PRICE_SOURCE_SPLIT_REG , PRICE_SOURCE_SPLIT_IMPORT , PRICE_SOURCE_STOCK_SPLIT , PRICE_SOURCE_STOCK_TRANSACTION , PRICE_SOURCE_INVOICE , PRICE_SOURCE_TEMP , PRICE_SOURCE_INVALID } |
| Price source enum. More... | |
Constructors | |
| GNCPrice * | gnc_price_create (QofBook *book) |
| gnc_price_create - returns a newly allocated and initialized price with a reference count of 1. | |
| GNCPrice * | gnc_price_clone (GNCPrice *p, QofBook *book) |
| gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price, p. | |
| GNCPrice * | gnc_price_invert (GNCPrice *p) |
| Return a newly-allocated price that's the inverse of the given price, p. | |
Memory Management | |
| void | gnc_price_ref (GNCPrice *p) |
| gnc_price_ref - indicate your need for a given price to stick around (i.e. | |
| void | gnc_price_unref (GNCPrice *p) |
| gnc_price_unref - indicate you're finished with a price (i.e. | |
Setters | |
All of the setters store copies of the data given, with the exception of the commodity field which just stores the pointer given. It is assumed that commodities are a global resource and are pointer unique. Invocations of the setters should be wrapped with calls to gnc_price_begin_edit() and commit_edit(). The begin/commit calls help ensure that the local price db is synchronized with the backend. | |
| void | gnc_price_begin_edit (GNCPrice *p) |
| void | gnc_price_commit_edit (GNCPrice *p) |
| void | gnc_price_set_commodity (GNCPrice *p, gnc_commodity *c) |
| void | gnc_price_set_currency (GNCPrice *p, gnc_commodity *c) |
| void | gnc_price_set_time64 (GNCPrice *p, time64 t) |
| void | gnc_price_set_source (GNCPrice *p, PriceSource source) |
| void | gnc_price_set_source_string (GNCPrice *p, const char *s) |
| void | gnc_price_set_typestr (GNCPrice *p, const char *type) |
| void | gnc_price_set_value (GNCPrice *p, gnc_numeric value) |
Getters | |
All of the getters return data that's internal to the GNCPrice, not copies, so don't free these values. | |
| GNCPrice * | gnc_price_lookup (const GncGUID *guid, QofBook *book) |
| gnc_commodity * | gnc_price_get_commodity (const GNCPrice *p) |
| gnc_commodity * | gnc_price_get_currency (const GNCPrice *p) |
| time64 | gnc_price_get_time64 (const GNCPrice *p) |
| PriceSource | gnc_price_get_source (const GNCPrice *p) |
| const char * | gnc_price_get_source_string (const GNCPrice *p) |
| const char * | gnc_price_get_typestr (const GNCPrice *p) |
| gnc_numeric | gnc_price_get_value (const GNCPrice *p) |
| gboolean | gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2) |
| #define | gnc_price_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X)) |
| #define | gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_INSTANCE(X)))) |
| #define | gnc_price_get_book(X) qof_instance_get_book(QOF_INSTANCE(X)) |
Internal/Debugging | |
| void | gnc_price_print (GNCPrice *db, FILE *f, int indent) |
| This simple function can be useful for debugging the price code. | |
| void | gnc_pricedb_print_contents (GNCPriceDB *db, FILE *f) |
| This simple function can be useful for debugging the pricedb code. | |
GNCPrice lists | |
The database communicates multiple prices in and out via gnc price lists. These are just time sorted GLists of GNCPrice pointers. Functions for manipulating these lists are provided. These functions are helpful in that they handle maintaining proper reference counts on behalf of the price list for every price being held in a given list. I.e. insert "refs" the prices being inserted, remove and destroy "unref" the prices that will no longer be referred to by the list. | |
| gboolean | gnc_price_list_insert (PriceList **prices, GNCPrice *p, gboolean check_dupl) |
| gnc_price_list_insert - insert a price into the given list, calling gnc_price_ref on it during the process. | |
| gboolean | gnc_price_list_remove (PriceList **prices, GNCPrice *p) |
| gnc_price_list_remove - remove the price, p, from the given list, calling gnc_price_unref on it during the process. | |
| void | gnc_price_list_destroy (PriceList *prices) |
| gnc_price_list_destroy - destroy the given price list, calling gnc_price_unref on all the prices included in the list. | |
| gboolean | gnc_price_list_equal (PriceList *prices1, PriceList *prices2) |
Denominator Constants Price policy: In order to avoid rounding | |
problems, currency prices (often called exchange rates) are saved in terms of the smaller currency, so that price > 1, with a fixed denominator of 1/1000. Commodity prices in currency are always expressed as value per unit of the commodity with a fixed denominator of the pricing currency's SCU * 10000. | |
| #define | CURRENCY_DENOM 10000 |
| #define | COMMODITY_DENOM_MULT 10000 |
Each price in the database represents an "instantaneous" quote for a given commodity with respect to another commodity.
For example, a given price might represent the value of LNUX in USD on 2001-02-03.
GNCPrices are reference counted. When you gnc_price_create one or clone it, the new price's count is set to 1. When you are finished with a price, call gnc_price_unref. If you hand the price pointer to some other code that needs to keep it, make sure it calls gnc_price_ref to indicate its interest in that price, and calls gnc_price_unref when it's finished with the price. For those unfamiliar with reference counting, basically each price stores an integer count which starts at 1 and is incremented every time someone calls gnc_price_ref. Conversely, the count is decremented every time someone calls gnc_price_unref. If the count ever reaches 0, the price is destroyed.
All of the getters return data that's internal to the GNCPrice, not copies, so don't free these values.
All of the setters store copies of the data given, with the exception of the commodity field which just stores the pointer given. It is assumed that commodities are a global resource and are pointer unique.
| #define COMMODITY_DENOM_MULT 10000 |
Definition at line 286 of file gnc-pricedb.h.
| #define CURRENCY_DENOM 10000 |
Definition at line 285 of file gnc-pricedb.h.
| #define gnc_price_get_book | ( | X | ) | qof_instance_get_book(QOF_INSTANCE(X)) |
Definition at line 270 of file gnc-pricedb.h.
| #define gnc_price_get_guid | ( | X | ) | qof_entity_get_guid(QOF_INSTANCE(X)) |
Definition at line 268 of file gnc-pricedb.h.
| #define gnc_price_return_guid | ( | X | ) | (*(qof_entity_get_guid(QOF_INSTANCE(X)))) |
Definition at line 269 of file gnc-pricedb.h.
| #define PRICE_TYPE_LAST "last" |
Definition at line 184 of file gnc-pricedb.h.
| #define PRICE_TYPE_TRN "transaction" |
Definition at line 186 of file gnc-pricedb.h.
| #define PRICE_TYPE_UNK "unknown" |
Definition at line 185 of file gnc-pricedb.h.
| typedef GList PriceList |
Definition at line 162 of file gnc-pricedb.h.
| enum PriceSource |
Price source enum.
Be sure to keep in sync with the source_name array in gnc-pricedb.c. These are in preference order, so for example a quote with PRICE_SOURCE_EDIT_DLG will overwrite one with PRICE_SOURCE_FQ but not the other way around.
Definition at line 169 of file gnc-pricedb.h.
| void gnc_price_begin_edit | ( | GNCPrice * | p | ) |
Definition at line 411 of file gnc-pricedb.cpp.
| GNCPrice * gnc_price_clone | ( | GNCPrice * | p, |
| QofBook * | book | ||
| ) |
gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price, p.
The returned clone will have a reference count of 1.
Definition at line 354 of file gnc-pricedb.cpp.
| void gnc_price_commit_edit | ( | GNCPrice * | p | ) |
Definition at line 425 of file gnc-pricedb.cpp.
| GNCPrice * gnc_price_create | ( | QofBook * | book | ) |
gnc_price_create - returns a newly allocated and initialized price with a reference count of 1.
Definition at line 295 of file gnc-pricedb.cpp.
| gboolean gnc_price_equal | ( | const GNCPrice * | p1, |
| const GNCPrice * | p2 | ||
| ) |
Definition at line 635 of file gnc-pricedb.cpp.
| gnc_commodity * gnc_price_get_commodity | ( | const GNCPrice * | p | ) |
Definition at line 583 of file gnc-pricedb.cpp.
| gnc_commodity * gnc_price_get_currency | ( | const GNCPrice * | p | ) |
Definition at line 628 of file gnc-pricedb.cpp.
| PriceSource gnc_price_get_source | ( | const GNCPrice * | p | ) |
Definition at line 596 of file gnc-pricedb.cpp.
| const char * gnc_price_get_source_string | ( | const GNCPrice * | p | ) |
Definition at line 603 of file gnc-pricedb.cpp.
| time64 gnc_price_get_time64 | ( | const GNCPrice * | p | ) |
Definition at line 590 of file gnc-pricedb.cpp.
| const char * gnc_price_get_typestr | ( | const GNCPrice * | p | ) |
Definition at line 610 of file gnc-pricedb.cpp.
| gnc_numeric gnc_price_get_value | ( | const GNCPrice * | p | ) |
Definition at line 617 of file gnc-pricedb.cpp.
| GNCPrice * gnc_price_invert | ( | GNCPrice * | p | ) |
Return a newly-allocated price that's the inverse of the given price, p.
Inverse means that the commodity and currency are swapped and the value is the numeric inverse of the original's. The source is set to PRICE_SOURCE_TEMP to prevent it being saved in the pricedb.
| p | The price to invert |
Definition at line 392 of file gnc-pricedb.cpp.
| void gnc_price_list_destroy | ( | PriceList * | prices | ) |
gnc_price_list_destroy - destroy the given price list, calling gnc_price_unref on all the prices included in the list.
Definition at line 742 of file gnc-pricedb.cpp.
| gboolean gnc_price_list_equal | ( | PriceList * | prices1, |
| PriceList * | prices2 | ||
| ) |
Definition at line 748 of file gnc-pricedb.cpp.
| gboolean gnc_price_list_insert | ( | PriceList ** | prices, |
| GNCPrice * | p, | ||
| gboolean | check_dupl | ||
| ) |
gnc_price_list_insert - insert a price into the given list, calling gnc_price_ref on it during the process.
Definition at line 706 of file gnc-pricedb.cpp.
| gboolean gnc_price_list_remove | ( | PriceList ** | prices, |
| GNCPrice * | p | ||
| ) |
gnc_price_list_remove - remove the price, p, from the given list, calling gnc_price_unref on it during the process.
Definition at line 723 of file gnc-pricedb.cpp.
Definition at line 573 of file gnc-pricedb.cpp.
| void gnc_price_print | ( | GNCPrice * | db, |
| FILE * | f, | ||
| int | indent | ||
| ) |
This simple function can be useful for debugging the price code.
Definition at line 2751 of file gnc-pricedb.cpp.
| void gnc_price_ref | ( | GNCPrice * | p | ) |
gnc_price_ref - indicate your need for a given price to stick around (i.e.
increase its reference count by 1).
Definition at line 324 of file gnc-pricedb.cpp.
| void gnc_price_set_commodity | ( | GNCPrice * | p, |
| gnc_commodity * | c | ||
| ) |
Definition at line 457 of file gnc-pricedb.cpp.
| void gnc_price_set_currency | ( | GNCPrice * | p, |
| gnc_commodity * | c | ||
| ) |
Definition at line 479 of file gnc-pricedb.cpp.
| void gnc_price_set_source | ( | GNCPrice * | p, |
| PriceSource | source | ||
| ) |
Definition at line 520 of file gnc-pricedb.cpp.
| void gnc_price_set_source_string | ( | GNCPrice * | p, |
| const char * | s | ||
| ) |
Definition at line 530 of file gnc-pricedb.cpp.
| void gnc_price_set_time64 | ( | GNCPrice * | p, |
| time64 | t | ||
| ) |
Definition at line 500 of file gnc-pricedb.cpp.
| void gnc_price_set_typestr | ( | GNCPrice * | p, |
| const char * | type | ||
| ) |
Definition at line 544 of file gnc-pricedb.cpp.
| void gnc_price_set_value | ( | GNCPrice * | p, |
| gnc_numeric | value | ||
| ) |
Definition at line 557 of file gnc-pricedb.cpp.
| void gnc_price_unref | ( | GNCPrice * | p | ) |
gnc_price_unref - indicate you're finished with a price (i.e.
decrease its reference count by 1).
Definition at line 331 of file gnc-pricedb.cpp.
| void gnc_pricedb_print_contents | ( | GNCPriceDB * | db, |
| FILE * | f | ||
| ) |
This simple function can be useful for debugging the pricedb code.
Definition at line 2807 of file gnc-pricedb.cpp.