GnuCash  5.6-150-g038405b370+
Data Structures | Macros | Typedefs | Functions

Commodity handling public routines. More...

#include <glib.h>
#include <glib/gi18n.h>
#include "gnc-engine.h"

Go to the source code of this file.

Data Structures

struct  gnc_monetary
 

Macros

#define GNC_TYPE_COMMODITY   (gnc_commodity_get_type ())
 
#define GNC_COMMODITY(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY, gnc_commodity))
 
#define GNC_COMMODITY_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY, gnc_commodityClass))
 
#define GNC_IS_COMMODITY(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY))
 
#define GNC_IS_COMMODITY_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY))
 
#define GNC_COMMODITY_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY, gnc_commodityClass))
 
#define GNC_TYPE_COMMODITY_NAMESPACE   (gnc_commodity_namespace_get_type ())
 
#define GNC_COMMODITY_NAMESPACE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespace))
 
#define GNC_COMMODITY_NAMESPACE_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
 
#define GNC_IS_COMMODITY_NAMESPACE(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY_NAMESPACE))
 
#define GNC_IS_COMMODITY_NAMESPACE_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY_NAMESPACE))
 
#define GNC_COMMODITY_NAMESPACE_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
 
#define GNC_COMMODITY_TABLE   "gnc_commodity_table"
 
#define GNC_COMMODITY_NS_LEGACY   "GNC_LEGACY_CURRENCIES"
 The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the exchange where it is traded. More...
 
#define GNC_COMMODITY_NS_TEMPLATE   "template"
 
#define GNC_COMMODITY_NS_ISO   "ISO4217"
 
#define GNC_COMMODITY_NS_CURRENCY   "CURRENCY"
 
#define GNC_COMMODITY_NS_NONCURRENCY   "NONCURRENCY"
 
#define GNC_COMMODITY_NS_NONISO_GUI   NC_("Commodity Type", "All non-currency")
 
#define GNC_COMMODITY_NS_ISO_GUI   NC_("Commodity Type", "Currencies")
 
#define GNC_COMMODITY_MAX_FRACTION   1000000000
 Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
 

Typedefs

typedef GList CommodityList
 
Monetary value, commodity identity and numeric value
typedef GList MonetaryList
 

Functions

GType gnc_commodity_get_type (void)
 
GType gnc_commodity_namespace_get_type (void)
 
Commodity Creation
gnc_commodity * gnc_commodity_new (QofBook *book, const char *fullname, const char *commodity_namespace, const char *mnemonic, const char *cusip, int fraction)
 Create a new commodity. More...
 
void gnc_commodity_destroy (gnc_commodity *cm)
 Destroy a commodity. More...
 
void gnc_commodity_copy (gnc_commodity *dest, const gnc_commodity *src)
 Copy src into dest.
 
gnc_commodity * gnc_commodity_clone (const gnc_commodity *src, QofBook *dest_book)
 allocate and copy
 
Commodity Accessor Routines - Get
const char * gnc_commodity_get_mnemonic (const gnc_commodity *cm)
 Retrieve the mnemonic for the specified commodity. More...
 
const char * gnc_commodity_get_namespace (const gnc_commodity *cm)
 Retrieve the namespace for the specified commodity. More...
 
gnc_commodity_namespace * gnc_commodity_get_namespace_ds (const gnc_commodity *cm)
 Retrieve the namespace data structure for the specified commodity. More...
 
const char * gnc_commodity_get_fullname (const gnc_commodity *cm)
 Retrieve the full name for the specified commodity. More...
 
const char * gnc_commodity_get_printname (const gnc_commodity *cm)
 Retrieve the 'print' name for the specified commodity. More...
 
const char * gnc_commodity_get_cusip (const gnc_commodity *cm)
 Retrieve the 'exchange code' for the specified commodity. More...
 
const char * gnc_commodity_get_unique_name (const gnc_commodity *cm)
 Retrieve the 'unique' name for the specified commodity. More...
 
int gnc_commodity_get_fraction (const gnc_commodity *cm)
 Retrieve the fraction for the specified commodity. More...
 
gboolean gnc_commodity_get_quote_flag (const gnc_commodity *cm)
 Retrieve the automatic price quote flag for the specified commodity. More...
 
gnc_quote_source * gnc_commodity_get_quote_source (const gnc_commodity *cm)
 Retrieve the automatic price quote source for the specified commodity. More...
 
gnc_quote_source * gnc_commodity_get_default_quote_source (const gnc_commodity *cm)
 
const char * gnc_commodity_get_quote_tz (const gnc_commodity *cm)
 Retrieve the automatic price quote timezone for the specified commodity. More...
 
const char * gnc_commodity_get_user_symbol (const gnc_commodity *cm)
 Retrieve the user-defined symbol for the specified commodity. More...
 
const char * gnc_commodity_get_default_symbol (const gnc_commodity *cm)
 Retrieve the default symbol for the specified commodity. More...
 
const char * gnc_commodity_get_nice_symbol (const gnc_commodity *cm)
 Retrieve a symbol for the specified commodity, suitable for display to the user. More...
 
Commodity Accessor Routines - Set
void gnc_commodity_set_mnemonic (gnc_commodity *cm, const char *mnemonic)
 Set the mnemonic for the specified commodity. More...
 
void gnc_commodity_set_namespace (gnc_commodity *cm, const char *new_namespace)
 Set the namespace for the specified commodity. More...
 
void gnc_commodity_set_fullname (gnc_commodity *cm, const char *fullname)
 Set the full name for the specified commodity. More...
 
void gnc_commodity_set_cusip (gnc_commodity *cm, const char *cusip)
 Set the 'exchange code' for the specified commodity. More...
 
void gnc_commodity_set_fraction (gnc_commodity *cm, int smallest_fraction)
 Set the fraction for the specified commodity. More...
 
void gnc_commodity_user_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 Set the automatic price quote flag for the specified commodity, based on user input. More...
 
void gnc_commodity_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 Set the automatic price quote flag for the specified commodity. More...
 
void gnc_commodity_set_quote_source (gnc_commodity *cm, gnc_quote_source *src)
 Set the automatic price quote source for the specified commodity. More...
 
void gnc_commodity_set_quote_tz (gnc_commodity *cm, const char *tz)
 Set the automatic price quote timezone for the specified commodity. More...
 
void gnc_commodity_set_user_symbol (gnc_commodity *cm, const char *user_symbol)
 Set a user-defined symbol for the specified commodity. More...
 
Commodity Usage Count Adjustment Routines
void gnc_commodity_increment_usage_count (gnc_commodity *cm)
 Increment a commodity's internal counter that tracks how many accounts are using that commodity. More...
 
void gnc_commodity_decrement_usage_count (gnc_commodity *cm)
 Decrement a commodity's internal counter that tracks how many accounts are using that commodity. More...
 
Commodity Comparison
gboolean gnc_commodity_equiv (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equivalent. More...
 
gboolean gnc_commodity_equal (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equal. More...
 
int gnc_commodity_compare (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns 0 if the two commodities are equal, 1 otherwise. More...
 
int gnc_commodity_compare_void (const void *a, const void *b)
 A wrapper around gnc_commodity_compare() which offers the function declaration that is needed for g_list_find_custom(), which needs void pointers instead of gnc_commodity ones.
 
Currency Checks
gboolean gnc_commodity_namespace_is_iso (const char *commodity_namespace)
 Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies. More...
 
gboolean gnc_commodity_is_iso (const gnc_commodity *cm)
 Checks to see if the specified commodity is an ISO 4217 recognized currency. More...
 
gboolean gnc_commodity_is_currency (const gnc_commodity *cm)
 Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency. More...
 
Commodity Table
gnc_commodity_table * gnc_commodity_table_get_table (QofBook *book)
 Returns the commodity table associated with a book.
 
Commodity Table Lookup functions
gnc_commodity * gnc_commodity_table_lookup (const gnc_commodity_table *table, const char *commodity_namespace, const char *mnemonic)
 
gnc_commodity * gnc_commodity_table_lookup_unique (const gnc_commodity_table *table, const char *unique_name)
 
gnc_commodity * gnc_commodity_table_find_full (const gnc_commodity_table *t, const char *commodity_namespace, const char *fullname)
 
gnc_commodity * gnc_commodity_find_commodity_by_guid (const GncGUID *guid, QofBook *book)
 
Commodity Table Maintenance functions
gnc_commodity * gnc_commodity_table_insert (gnc_commodity_table *table, gnc_commodity *comm)
 Add a new commodity to the commodity table. More...
 
void gnc_commodity_table_remove (gnc_commodity_table *table, gnc_commodity *comm)
 Remove a commodity from the commodity table. More...
 
gboolean gnc_commodity_table_add_default_data (gnc_commodity_table *table, QofBook *book)
 Add all the standard namespaces and currencies to the commodity table. More...
 
Commodity Table Namespace functions
const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
 Return the textual name of a namespace data structure. More...
 
const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns)
 Return the textual name of a namespace data structure in a form suitable to present to the user. More...
 
GList * gnc_commodity_namespace_get_commodity_list (const gnc_commodity_namespace *ns)
 Return a list of all commodity data structures in the specified namespace. More...
 
int gnc_commodity_table_has_namespace (const gnc_commodity_table *table, const char *commodity_namespace)
 Test to see if the indicated namespace exits in the commodity table. More...
 
GList * gnc_commodity_table_get_namespaces (const gnc_commodity_table *t)
 Return a list of all namespaces in the commodity table. More...
 
GList * gnc_commodity_table_get_namespaces_list (const gnc_commodity_table *t)
 Return a list of all namespace data structures in the commodity table. More...
 
gnc_commodity_namespace * gnc_commodity_table_add_namespace (gnc_commodity_table *table, const char *commodity_namespace, QofBook *book)
 This function adds a new string to the list of commodity namespaces. More...
 
gnc_commodity_namespace * gnc_commodity_table_find_namespace (const gnc_commodity_table *table, const char *commodity_namespace)
 This function finds a commodity namespace in the set of existing commodity namespaces. More...
 
void gnc_commodity_table_delete_namespace (gnc_commodity_table *table, const char *commodity_namespace)
 This function deletes a string from the list of commodity namespaces. More...
 
Commodity Table Accessor functions
guint gnc_commodity_table_get_size (const gnc_commodity_table *tbl)
 Returns the number of commodities in the commodity table. More...
 
CommodityList * gnc_commodity_table_get_commodities (const gnc_commodity_table *table, const char *commodity_namespace)
 Return a list of all commodities in the commodity table that are in the given namespace. More...
 
CommodityList * gnc_commodity_table_get_quotable_commodities (const gnc_commodity_table *table)
 This function returns a list of commodities for which price quotes should be retrieved. More...
 
gboolean gnc_commodity_table_foreach_commodity (const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
 Call a function once for each commodity in the commodity table. More...
 
Constructors

Make a gnc_monetary from a gnc_commodity and gnc_numeric

Accessors
Manipulate MonetaryList lists
MonetaryList * gnc_monetary_list_add_monetary (MonetaryList *list, gnc_monetary mon)
 Add a gnc_monetary to the list.
 
MonetaryList * gnc_monetary_list_delete_zeros (MonetaryList *list)
 Delete all the zero-value entries from a list. More...
 
void gnc_monetary_list_free (MonetaryList *list)
 Free a monetary list and all the items it points to. More...
 

Commodity Quote Source functions

enum  QuoteSourceType {
  SOURCE_SINGLE = 0, SOURCE_MULTI, SOURCE_UNKNOWN, SOURCE_MAX,
  SOURCE_CURRENCY = SOURCE_MAX
}
 The quote source type enum account types are used to determine how the transaction data in the account is displayed. More...
 
gboolean gnc_quote_source_fq_installed (void)
 This function indicates whether or not the Finance::Quote module is installed on a user's computer. More...
 
const char * gnc_quote_source_fq_version (void)
 This function returns the version of the Finance::Quote module installed on a user's computer. More...
 
gint gnc_quote_source_num_entries (QuoteSourceType type)
 Return the number of entries for a given type of quote source. More...
 
gnc_quote_source * gnc_quote_source_add_new (const char *name, gboolean supported)
 Create a new quote source. More...
 
gnc_quote_source * gnc_quote_source_lookup_by_internal (const char *internal_name)
 Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by this name. More...
 
gnc_quote_source * gnc_quote_source_lookup_by_ti (QuoteSourceType type, gint index)
 Given the type/index of a quote source, find the data structure identified by this pair. More...
 
gboolean gnc_quote_source_get_supported (const gnc_quote_source *source)
 Given a gnc_quote_source data structure, return the flag that indicates whether this particular quote source is supported by the user's F::Q installation. More...
 
QuoteSourceType gnc_quote_source_get_type (const gnc_quote_source *source)
 Given a gnc_quote_source data structure, return the type of this particular quote source. More...
 
gint gnc_quote_source_get_index (const gnc_quote_source *source)
 Given a gnc_quote_source data structure, return the index of this particular quote source within its type. More...
 
const char * gnc_quote_source_get_user_name (const gnc_quote_source *source)
 Given a gnc_quote_source data structure, return the user friendly name of this quote source. More...
 
const char * gnc_quote_source_get_internal_name (const gnc_quote_source *source)
 Given a gnc_quote_source data structure, return the internal name of this quote source. More...
 

Commodity Table Private/Internal-Use Only Routines

#define gnc_commodity_get_kvp_frame(cm)   qof_instance_get_slots(QOF_INSTANCE(cm))
 Get the internal KVP from of the currency. More...
 
gnc_commodity_table * gnc_commodity_table_new (void)
 You probably shouldn't be using gnc_commodity_table_new() directly, it's for internal use only. More...
 
void gnc_commodity_table_destroy (gnc_commodity_table *table)
 
gnc_commodity * gnc_commodity_obtain_twin (const gnc_commodity *findlike, QofBook *book)
 Given the commodity 'findlike', this routine will find and return the equivalent commodity (commodity with the same 'unique name') in the indicated book. More...
 
gboolean gnc_commodity_table_register (void)
 You should probably not be using gnc_commodity_table_register() It is an internal routine for registering the gncObject for the commodity table.
 
void gnc_commodity_begin_edit (gnc_commodity *cm)
 
void gnc_commodity_commit_edit (gnc_commodity *cm)
 

Detailed Description

Commodity handling public routines.

Author
Copyright (C) 2000 Bill Gribble
Copyright (C) 2001 Linas Vepstas linas.nosp@m.@lin.nosp@m.as.or.nosp@m.g

Definition in file gnc-commodity.h.