gnc-pricedb.h

Go to the documentation of this file.
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 
00154 /* ================================================================ */
00155 
00160 typedef struct gnc_price_lookup_s GNCPriceLookup;
00161 typedef GList PriceList;
00162 
00163 /* ------------------ */
00169 GNCPrice *gnc_price_create(QofBook *book);
00170 
00174 GNCPrice *gnc_price_clone(GNCPrice* p, QofBook *book);
00177 /* ------------------ */
00183 void      gnc_price_ref(GNCPrice *p);
00184 
00187 void      gnc_price_unref(GNCPrice *p);
00190 /* ------------------ */
00194 /* As mentioned above, all of the setters store copies of the data
00195  * given, with the exception of the commodity field which just stores
00196  * the pointer given.  It is assumed that commodities are a global
00197  * resource and are pointer unique. 
00198  *
00199  * Invocations of the setters should be wrapped with calls to
00200  * gnc_price_begin_edit() and commit_edit().  The begin/commit
00201  * calls help ensure that the local price db is synchronized with 
00202  * the backend.
00203  */
00204 void gnc_price_begin_edit (GNCPrice *p);
00205 void gnc_price_commit_edit (GNCPrice *p);
00206 
00207 void gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c);
00208 void gnc_price_set_currency(GNCPrice *p, gnc_commodity *c);
00209 void gnc_price_set_time(GNCPrice *p, Timespec t);
00210 void gnc_price_set_source(GNCPrice *p, const char *source);
00211 void gnc_price_set_typestr(GNCPrice *p, const char* type);
00212 void gnc_price_set_value(GNCPrice *p, gnc_numeric value);
00215 /* ------------------ */
00221 GNCPrice *      gnc_price_lookup (const GUID *guid, QofBook *book);
00222 gnc_commodity * gnc_price_get_commodity(const GNCPrice *p);
00223 gnc_commodity * gnc_price_get_currency(const GNCPrice *p);
00224 Timespec        gnc_price_get_time(const GNCPrice *p);
00225 const char *    gnc_price_get_source(const GNCPrice *p);
00226 const char *    gnc_price_get_typestr(const GNCPrice *p);
00227 gnc_numeric     gnc_price_get_value(const GNCPrice *p);
00228 gboolean        gnc_price_equal(const GNCPrice *p1, const GNCPrice *p2);
00229 
00230 #define gnc_price_get_guid(X)    qof_entity_get_guid(QOF_INSTANCE(X))
00231 #define gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_INSTANCE(X))))
00232 #define gnc_price_get_book(X)    qof_instance_get_book(QOF_INSTANCE(X))
00233 
00235 /* ================================================================ */
00250 gboolean gnc_price_list_insert(PriceList **prices, GNCPrice *p,
00251                                gboolean check_dupl);
00252 
00255 gboolean gnc_price_list_remove(PriceList **prices, GNCPrice *p);
00256 
00259 void     gnc_price_list_destroy(PriceList *prices);
00260 
00261 gboolean gnc_price_list_equal(PriceList *prices1, PriceList *prices2);
00265 /* ================================================================ */
00278 typedef struct gnc_price_db_s GNCPriceDB;
00279 
00280 /* XXX backwards-compat defines, remove these someday */
00281 #define gnc_book_get_pricedb  gnc_pricedb_get_db
00282 
00284 GNCPriceDB * gnc_pricedb_get_db(QofBook *book);
00285 GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col);
00286 
00290 void gnc_pricedb_destroy(GNCPriceDB *db);
00291 
00293 void gnc_pricedb_begin_edit (GNCPriceDB *);
00294 void gnc_pricedb_commit_edit (GNCPriceDB *);
00295 
00299 void gnc_pricedb_set_bulk_update(GNCPriceDB *db, gboolean bulk_update);
00300 
00304 gboolean     gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p);
00305 
00308 gboolean     gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p);
00309 
00310 gboolean     gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff,
00311                                            const gboolean delete_user, gboolean delete_last);
00312 
00316 GNCPrice   * gnc_pricedb_lookup_latest(GNCPriceDB *db,
00317                                        const gnc_commodity *commodity,
00318                                        const gnc_commodity *currency);
00319 
00323 PriceList * gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db,
00324                                                  const gnc_commodity *commodity);
00325 
00329 gboolean     gnc_pricedb_has_prices(GNCPriceDB *db,
00330                                     const gnc_commodity *commodity,
00331                                     const gnc_commodity *currency);
00332 
00336 PriceList * gnc_pricedb_get_prices(GNCPriceDB *db,
00337                                  const gnc_commodity *commodity,
00338                                  const gnc_commodity *currency);
00339 
00343 PriceList * gnc_pricedb_lookup_at_time(GNCPriceDB *db,
00344                                      const gnc_commodity *commodity,
00345                                      const gnc_commodity *currency,
00346                                      Timespec t);
00347 
00351 PriceList * gnc_pricedb_lookup_at_time_any_currency(GNCPriceDB *db,
00352                                                   const gnc_commodity *c,
00353                                                   Timespec t);
00354 
00358 PriceList * gnc_pricedb_lookup_day(GNCPriceDB *db,
00359                                  const gnc_commodity *commodity,
00360                                  const gnc_commodity *currency,
00361                                  Timespec t);
00362 
00366 PriceList * gnc_pricedb_lookup_day_any_currency(GNCPriceDB *db,
00367                                               const gnc_commodity *c,
00368                                               Timespec t);
00369 
00372 GNCPrice   * gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
00373                                                 const gnc_commodity *c,
00374                                                 const gnc_commodity *currency,
00375                                                 Timespec t);
00376 
00380 PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db,
00381                                                           const gnc_commodity *c,
00382                                                           Timespec t);
00385 GNCPrice * gnc_pricedb_lookup_latest_before(GNCPriceDB *db,
00386                                             gnc_commodity *c,
00387                                             gnc_commodity *currency,
00388                                             Timespec t);
00389 
00393 PriceList * gnc_pricedb_lookup_latest_before_any_currency(GNCPriceDB *db,
00394                                                         gnc_commodity *c,
00395                                                         Timespec t);
00396 
00397 
00400 gnc_numeric
00401 gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb,
00402                                          gnc_numeric balance,
00403                                          const gnc_commodity *balance_currency,
00404                                          const gnc_commodity *new_currency);
00405 
00408 gnc_numeric
00409 gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
00410                                           gnc_numeric balance,
00411                                           const gnc_commodity *balance_currency,
00412                                           const gnc_commodity *new_currency,
00413                                           Timespec t);
00414 
00417 gnc_numeric
00418 gnc_pricedb_convert_balance_latest_before(GNCPriceDB *pdb,
00419                                           gnc_numeric balance,
00420                                           gnc_commodity *balance_currency,
00421                                           gnc_commodity *new_currency,
00422                                           Timespec t);
00423 
00424 
00430 gboolean     gnc_pricedb_foreach_price(GNCPriceDB *db,
00431                                        gboolean (*f)(GNCPrice *p,
00432                                                      gpointer user_data),
00433                                        gpointer user_data,
00434                                        gboolean stable_order);
00435 
00438 guint gnc_pricedb_get_num_prices(GNCPriceDB *db);
00439 
00440 gboolean gnc_pricedb_equal (GNCPriceDB *db1, GNCPriceDB *db2);
00441 
00443 void gnc_price_print(GNCPrice *db, FILE *f, int indent);
00444 void gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f);
00445 
00446 
00451 #define PRICE_COMMODITY  "price-commodity"
00452 #define PRICE_CURRENCY   "price-currency"
00453 #define PRICE_DATE       "price-date"
00454 #define PRICE_SOURCE     "price-source"
00455 #define PRICE_TYPE       "price-type"
00456 #define PRICE_VALUE      "price-value"
00457 
00461 #endif /* GNC_PRICEDB_H */
00462 

Generated on Mon Sep 8 05:04:06 2008 for GnuCash by  doxygen 1.5.2