|
GnuCash 2.4.99
|
00001 /******************************************************************** 00002 * gnc-pricedb.h -- a simple price database for gnucash. * 00003 * * 00004 * This program is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU General Public License as * 00006 * published by the Free Software Foundation; either version 2 of * 00007 * the License, or (at your option) any later version. * 00008 * * 00009 * This program is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License* 00015 * along with this program; if not, contact: * 00016 * * 00017 * Free Software Foundation Voice: +1-617-542-5942 * 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00019 * Boston, MA 02110-1301, USA gnu@gnu.org * 00020 * * 00021 *******************************************************************/ 00022 00023 #ifndef GNC_PRICEDB_H 00024 #define GNC_PRICEDB_H 00025 00026 typedef struct _GncPriceClass GNCPriceClass; 00027 typedef struct _GncPriceDBClass GNCPriceDBClass; 00028 00029 #include <stdio.h> 00030 #include "qof.h" 00031 #include "gnc-commodity.h" 00032 #include "gnc-engine.h" 00033 00034 /* --- type macros --- */ 00035 #define GNC_TYPE_PRICE (gnc_price_get_type ()) 00036 #define GNC_PRICE(o) \ 00037 (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICE, GNCPrice)) 00038 #define GNC_PRICE_CLASS(k) \ 00039 (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICE, GNCPriceClass)) 00040 #define GNC_IS_PRICE(o) \ 00041 (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICE)) 00042 #define GNC_IS_PRICE_CLASS(k) \ 00043 (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICE)) 00044 #define GNC_PRICE_GET_CLASS(o) \ 00045 (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICE, GNCPriceClass)) 00046 GType gnc_price_get_type(void); 00047 00048 /* --- type macros --- */ 00049 #define GNC_TYPE_PRICEDB (gnc_pricedb_get_type ()) 00050 #define GNC_PRICEDB(o) \ 00051 (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICEDB, GNCPriceDB)) 00052 #define GNC_PRICEDB_CLASS(k) \ 00053 (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICEDB, GNCPriceDBClass)) 00054 #define GNC_IS_PRICEDB(o) \ 00055 (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICEDB)) 00056 #define GNC_IS_PRICEDB_CLASS(k) \ 00057 (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICEDB)) 00058 #define GNC_PRICEDB_GET_CLASS(o) \ 00059 (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICEDB, GNCPriceDBClass)) 00060 GType gnc_pricedb_get_type(void); 00061 00062 00150 /* ================================================================ */ 00151 00156 typedef struct gnc_price_lookup_s GNCPriceLookup; 00157 typedef GList PriceList; 00158 00159 /* ------------------ */ 00165 /*@ dependent @*/ 00166 GNCPrice *gnc_price_create(QofBook *book); 00167 00171 GNCPrice *gnc_price_clone(GNCPrice* p, QofBook *book); 00174 /* ------------------ */ 00180 void gnc_price_ref(GNCPrice *p); 00181 00184 void gnc_price_unref(GNCPrice *p); 00187 /* ------------------ */ 00199 void gnc_price_begin_edit (GNCPrice *p); 00200 void gnc_price_commit_edit (GNCPrice *p); 00201 00202 void gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c); 00203 void gnc_price_set_currency(GNCPrice *p, gnc_commodity *c); 00204 void gnc_price_set_time(GNCPrice *p, Timespec t); 00205 void gnc_price_set_source(GNCPrice *p, const char *source); 00206 void gnc_price_set_typestr(GNCPrice *p, const char* type); 00207 void gnc_price_set_value(GNCPrice *p, gnc_numeric value); 00210 /* ------------------ */ 00216 GNCPrice * gnc_price_lookup (const GncGUID *guid, QofBook *book); 00217 /*@ dependent @*/ 00218 gnc_commodity * gnc_price_get_commodity(const GNCPrice *p); 00219 /*@ dependent @*/ 00220 gnc_commodity * gnc_price_get_currency(const GNCPrice *p); 00221 Timespec gnc_price_get_time(const GNCPrice *p); 00222 const char * gnc_price_get_source(const GNCPrice *p); 00223 const char * gnc_price_get_typestr(const GNCPrice *p); 00224 gnc_numeric gnc_price_get_value(const GNCPrice *p); 00225 gboolean gnc_price_equal(const GNCPrice *p1, const GNCPrice *p2); 00226 00227 #define gnc_price_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X)) 00228 #define gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_INSTANCE(X)))) 00229 #define gnc_price_get_book(X) qof_instance_get_book(QOF_INSTANCE(X)) 00230 00235 void gnc_price_print(GNCPrice *db, FILE *f, int indent); 00238 /* ================================================================ */ 00253 gboolean gnc_price_list_insert(PriceList **prices, GNCPrice *p, 00254 gboolean check_dupl); 00255 00258 gboolean gnc_price_list_remove(PriceList **prices, GNCPrice *p); 00259 00262 void gnc_price_list_destroy(PriceList *prices); 00263 00264 gboolean gnc_price_list_equal(PriceList *prices1, PriceList *prices2); 00268 /* ================================================================ */ 00281 typedef struct gnc_price_db_s GNCPriceDB; 00282 00284 /*@ dependent @*/ 00285 GNCPriceDB * gnc_pricedb_get_db(QofBook *book); 00286 GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col); 00287 00291 void gnc_pricedb_destroy(GNCPriceDB *db); 00292 00294 void gnc_pricedb_begin_edit (GNCPriceDB *); 00295 void gnc_pricedb_commit_edit (GNCPriceDB *); 00296 00300 void gnc_pricedb_set_bulk_update(GNCPriceDB *db, gboolean bulk_update); 00301 00305 gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p); 00306 00309 gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p); 00310 00311 gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff, 00312 const gboolean delete_user, gboolean delete_last); 00313 00317 GNCPrice * gnc_pricedb_lookup_latest(GNCPriceDB *db, 00318 const gnc_commodity *commodity, 00319 const gnc_commodity *currency); 00320 00324 PriceList * gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db, 00325 const gnc_commodity *commodity); 00326 00330 gboolean gnc_pricedb_has_prices(GNCPriceDB *db, 00331 const gnc_commodity *commodity, 00332 const gnc_commodity *currency); 00333 00337 PriceList * gnc_pricedb_get_prices(GNCPriceDB *db, 00338 const gnc_commodity *commodity, 00339 const gnc_commodity *currency); 00340 00344 PriceList * gnc_pricedb_lookup_at_time(GNCPriceDB *db, 00345 const gnc_commodity *commodity, 00346 const gnc_commodity *currency, 00347 Timespec t); 00348 00352 PriceList * gnc_pricedb_lookup_day(GNCPriceDB *db, 00353 const gnc_commodity *commodity, 00354 const gnc_commodity *currency, 00355 Timespec t); 00356 00357 00360 GNCPrice * gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db, 00361 const gnc_commodity *c, 00362 const gnc_commodity *currency, 00363 Timespec t); 00364 00368 PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db, 00369 const gnc_commodity *c, 00370 Timespec t); 00373 GNCPrice * gnc_pricedb_lookup_latest_before(GNCPriceDB *db, 00374 gnc_commodity *c, 00375 gnc_commodity *currency, 00376 Timespec t); 00377 00381 PriceList * gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db, 00382 gnc_commodity *c, 00383 Timespec t); 00384 00385 00388 gnc_numeric 00389 gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb, 00390 gnc_numeric balance, 00391 const gnc_commodity *balance_currency, 00392 const gnc_commodity *new_currency); 00393 00396 gnc_numeric 00397 gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb, 00398 gnc_numeric balance, 00399 const gnc_commodity *balance_currency, 00400 const gnc_commodity *new_currency, 00401 Timespec t); 00402 00408 gboolean gnc_pricedb_foreach_price(GNCPriceDB *db, 00409 gboolean (*f)(GNCPrice *p, 00410 gpointer user_data), 00411 gpointer user_data, 00412 gboolean stable_order); 00413 00414 /* The following two convenience functions are used to test the xml backend */ 00417 guint gnc_pricedb_get_num_prices(GNCPriceDB *db); 00419 gboolean gnc_pricedb_equal (GNCPriceDB *db1, GNCPriceDB *db2); 00420 00424 void gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f); 00431 #define PRICE_COMMODITY "price-commodity" 00432 #define PRICE_CURRENCY "price-currency" 00433 #define PRICE_DATE "price-date" 00434 #define PRICE_SOURCE "price-source" 00435 #define PRICE_TYPE "price-type" 00436 #define PRICE_VALUE "price-value" 00437 00441 #endif /* GNC_PRICEDB_H */ 00442
1.7.4