GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Functions

A commodity is something of value that is easily tradeable or sellable; for example, currencies, stocks, bonds, grain, copper, and oil are all commodities. More...

Files

file  gnc-commodity.h
 Commodity handling public routines.
 
file  gnc-commodity.hpp
 Commodity handling public routines (C++ api)
 

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.
 
#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
 
using CommVec = std::vector< gnc_commodity * >
 

Functions

GType gnc_commodity_get_type (void)
 
GType gnc_commodity_namespace_get_type (void)
 
void gnc_quote_source_set_fq_installed (const char *version_string, const std::vector< std::string > &sources_list)
 Update gnucash internal tables based on what Finance::Quote sources are installed.
 
bool gnc_commodity_table_rename_namespace (const gnc_commodity_table *table, const char *namespace_name, const char *new_namespace_name)
 This function renames a namespace.
 

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.
 
const char * gnc_quote_source_fq_version (void)
 This function returns the version of the Finance::Quote module installed on a user's computer.
 
gint gnc_quote_source_num_entries (QuoteSourceType type)
 Return the number of entries for a given type of quote source.
 
gnc_quote_source * gnc_quote_source_add_new (const char *name, gboolean supported)
 Create a new quote source.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Monetary value, commodity identity and numeric value

typedef GList MonetaryList
 

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.
 
void gnc_commodity_destroy (gnc_commodity *cm)
 Destroy a commodity.
 
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

gboolean gnc_commodity_get_auto_quote_control_flag (const gnc_commodity *cm)
 
const char * gnc_commodity_get_mnemonic (const gnc_commodity *cm)
 Retrieve the mnemonic for the specified commodity.
 
const char * gnc_commodity_get_namespace (const gnc_commodity *cm)
 Retrieve the namespace for the specified commodity.
 
gnc_commodity_namespace * gnc_commodity_get_namespace_ds (const gnc_commodity *cm)
 Retrieve the namespace data structure for the specified commodity.
 
const char * gnc_commodity_get_fullname (const gnc_commodity *cm)
 Retrieve the full name for the specified commodity.
 
const char * gnc_commodity_get_printname (const gnc_commodity *cm)
 Retrieve the 'print' name for the specified commodity.
 
const char * gnc_commodity_get_cusip (const gnc_commodity *cm)
 Retrieve the 'exchange code' for the specified commodity.
 
const char * gnc_commodity_get_unique_name (const gnc_commodity *cm)
 Retrieve the 'unique' name for the specified commodity.
 
int gnc_commodity_get_fraction (const gnc_commodity *cm)
 Retrieve the fraction for the specified commodity.
 
gboolean gnc_commodity_get_quote_flag (const gnc_commodity *cm)
 Retrieve the automatic price quote flag for the specified commodity.
 
gnc_quote_source * gnc_commodity_get_quote_source (const gnc_commodity *cm)
 Retrieve the automatic price quote source for the specified commodity.
 
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.
 
const char * gnc_commodity_get_user_symbol (const gnc_commodity *cm)
 Retrieve the user-defined symbol for the specified commodity.
 
const char * gnc_commodity_get_default_symbol (const gnc_commodity *cm)
 Retrieve the default symbol for the specified commodity.
 
const char * gnc_commodity_get_nice_symbol (const gnc_commodity *cm)
 Retrieve a symbol for the specified commodity, suitable for display to the user.
 

Commodity Accessor Routines - Set

void gnc_commodity_set_auto_quote_control_flag (gnc_commodity *cm, const gboolean flag)
 
void gnc_commodity_set_mnemonic (gnc_commodity *cm, const char *mnemonic)
 Set the mnemonic for the specified commodity.
 
void gnc_commodity_set_namespace (gnc_commodity *cm, const char *new_namespace)
 Set the namespace for the specified commodity.
 
void gnc_commodity_set_fullname (gnc_commodity *cm, const char *fullname)
 Set the full name for the specified commodity.
 
void gnc_commodity_set_cusip (gnc_commodity *cm, const char *cusip)
 Set the 'exchange code' for the specified commodity.
 
void gnc_commodity_set_fraction (gnc_commodity *cm, int smallest_fraction)
 Set the fraction for the specified commodity.
 
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.
 
void gnc_commodity_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 Set the automatic price quote flag for the specified commodity.
 
void gnc_commodity_set_quote_source (gnc_commodity *cm, gnc_quote_source *src)
 Set the automatic price quote source for the specified commodity.
 
void gnc_commodity_set_quote_tz (gnc_commodity *cm, const char *tz)
 Set the automatic price quote timezone for the specified commodity.
 
void gnc_commodity_set_user_symbol (gnc_commodity *cm, const char *user_symbol)
 Set a user-defined symbol for the specified commodity.
 

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.
 
void gnc_commodity_decrement_usage_count (gnc_commodity *cm)
 Decrement a commodity's internal counter that tracks how many accounts are using that commodity.
 

Commodity Comparison

gboolean gnc_commodity_equiv (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equivalent.
 
gboolean gnc_commodity_equal (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equal.
 
int gnc_commodity_compare (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns 0 if the two commodities are equal, 1 otherwise.
 
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.
 
gboolean gnc_commodity_is_iso (const gnc_commodity *cm)
 Checks to see if the specified commodity is an ISO 4217 recognized currency.
 
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.
 

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.
 
void gnc_commodity_table_remove (gnc_commodity_table *table, gnc_commodity *comm)
 Remove a commodity from the commodity table.
 
gboolean gnc_commodity_table_add_default_data (gnc_commodity_table *table, QofBook *book)
 Add all the standard namespaces and currencies to the commodity table.
 

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.
 
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.
 
GList * gnc_commodity_namespace_get_commodity_list (const gnc_commodity_namespace *ns)
 Return a list of all commodity data structures in the specified namespace.
 
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.
 
GList * gnc_commodity_table_get_namespaces (const gnc_commodity_table *t)
 Return a list of all namespaces in the commodity table.
 
GList * gnc_commodity_table_get_namespaces_list (const gnc_commodity_table *t)
 Return a list of all namespace data structures in the commodity table.
 
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.
 
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.
 
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.
 

Commodity Table Accessor functions

guint gnc_commodity_table_get_size (const gnc_commodity_table *tbl)
 Returns the number of commodities in the commodity table.
 
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.
 
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.
 
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.
 

Commodity Table Private/Internal-Use Only Routines

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.
 
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.
 
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)
 
#define gnc_commodity_get_kvp_frame(cm)    qof_instance_get_slots(QOF_INSTANCE(cm))
 Get the internal KVP from of the currency.
 

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.
 
void gnc_monetary_list_free (MonetaryList *list)
 Free a monetary list and all the items it points to.
 

Detailed Description

A commodity is something of value that is easily tradeable or sellable; for example, currencies, stocks, bonds, grain, copper, and oil are all commodities.

This file provides an API for defining a commodities, and for working with collections of commodities. All GnuCash financial transactions must identify the commodity that is being traded.

Warning
The system used here does not follow the object handling and identification system (GncGUID's, Entities, etc.) that the other parts of GnuCash use. The API really should be ported over. This would allow us to get rid of the commodity table routines defined below.

Macro Definition Documentation

◆ GNC_COMMODITY

#define GNC_COMMODITY (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY, gnc_commodity))

Definition at line 63 of file gnc-commodity.h.

129{
130 SOURCE_SINGLE = 0,
141 SOURCE_MAX,
142 SOURCE_CURRENCY = SOURCE_MAX,
144
151gboolean gnc_quote_source_fq_installed (void);
152
159const char* gnc_quote_source_fq_version (void);
160
168
180gnc_quote_source *gnc_quote_source_add_new(const char * name, gboolean supported);
181
190/*@ dependent @*/
191gnc_quote_source *gnc_quote_source_lookup_by_internal(const char * internal_name);
192
203gnc_quote_source *gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint index);
204
213gboolean gnc_quote_source_get_supported (const gnc_quote_source *source);
214
222QuoteSourceType gnc_quote_source_get_type (const gnc_quote_source *source);
223
231gint gnc_quote_source_get_index (const gnc_quote_source *source);
232
241/*@ dependent @*/
242const char *gnc_quote_source_get_user_name (const gnc_quote_source *source);
243
252/*@ dependent @*/
253const char *gnc_quote_source_get_internal_name (const gnc_quote_source *source);
254
294/*@ dependent @*/
295gnc_commodity * gnc_commodity_new(QofBook *book,
296 /*@ null @*/ const char * fullname,
297 /*@ null @*/ const char * commodity_namespace,
298 /*@ null @*/ const char * mnemonic,
299 /*@ null @*/ const char * cusip,
300 int fraction);
301
307void gnc_commodity_destroy(gnc_commodity * cm);
308
310void gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src);
311
313gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book);
322gboolean gnc_commodity_get_auto_quote_control_flag (const gnc_commodity *cm);
323
333const char * gnc_commodity_get_mnemonic(const gnc_commodity * cm);
334
344const char * gnc_commodity_get_namespace(const gnc_commodity * cm);
345
354gnc_commodity_namespace *gnc_commodity_get_namespace_ds(const gnc_commodity * cm);
355
365const char * gnc_commodity_get_fullname(const gnc_commodity * cm);
366
377const char * gnc_commodity_get_printname(const gnc_commodity * cm);
378
394const char * gnc_commodity_get_cusip(const gnc_commodity * cm);
395
407const char * gnc_commodity_get_unique_name(const gnc_commodity * cm);
408
419int gnc_commodity_get_fraction(const gnc_commodity * cm);
420
430gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm);
431
440/*@ dependent @*/
441gnc_quote_source* gnc_commodity_get_quote_source(const gnc_commodity *cm);
442/*@ dependent @*/
443gnc_quote_source* gnc_commodity_get_default_quote_source(const gnc_commodity *cm);
444
455const char* gnc_commodity_get_quote_tz(const gnc_commodity *cm);
456
467const char* gnc_commodity_get_user_symbol(const gnc_commodity *cm);
468
478const char* gnc_commodity_get_default_symbol(const gnc_commodity *cm);
479
490const char*gnc_commodity_get_nice_symbol(const gnc_commodity *cm);
497void gnc_commodity_set_auto_quote_control_flag (gnc_commodity *cm, const gboolean flag);
498
509void gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic);
510
521void gnc_commodity_set_namespace(gnc_commodity * cm, const char * new_namespace);
522
533void gnc_commodity_set_fullname(gnc_commodity * cm, const char * fullname);
534
549void gnc_commodity_set_cusip(gnc_commodity * cm, const char * cusip);
550
561void gnc_commodity_set_fraction(gnc_commodity * cm, int smallest_fraction);
562
577void gnc_commodity_user_set_quote_flag(gnc_commodity *cm,
578 const gboolean flag);
579
589void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag);
590
600void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src);
601
613void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz);
614
623void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol);
636void
637gnc_commodity_increment_usage_count(gnc_commodity *cm);
638
645void
646gnc_commodity_decrement_usage_count(gnc_commodity *cm);
660gboolean gnc_commodity_equiv(const gnc_commodity * a, const gnc_commodity * b);
661
666gboolean gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b);
667
675int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b);
676
681int gnc_commodity_compare_void(const void * a, const void * b);
695gboolean gnc_commodity_namespace_is_iso(const char *commodity_namespace);
696
702gboolean gnc_commodity_is_iso(const gnc_commodity * cm);
703
710gboolean gnc_commodity_is_currency(const gnc_commodity *cm);
711
715/* =============================================================== */
722/*@ dependent @*/
723gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book);
724
726/* ---------------------------------------------------------- */
730gnc_commodity * gnc_commodity_table_lookup(const gnc_commodity_table * table,
731 const char * commodity_namespace,
732 const char * mnemonic);
733gnc_commodity *
734gnc_commodity_table_lookup_unique(const gnc_commodity_table *table,
735 const char * unique_name);
736gnc_commodity * gnc_commodity_table_find_full(const gnc_commodity_table * t,
737 const char * commodity_namespace,
738 const char * fullname);
739
740/*@ dependent @*/
741gnc_commodity * gnc_commodity_find_commodity_by_guid(const GncGUID *guid,
742 QofBook *book);
743
745/* ---------------------------------------------------------- */
746
765/*@ dependent @*/
766gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table * table,
767 gnc_commodity * comm);
768
775void gnc_commodity_table_remove(gnc_commodity_table * table,
776 gnc_commodity * comm);
777
786gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book);
787
789/* ---------------------------------------------------------- */
800const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns) ;
801
813const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns) ;
814
815
822GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace * ns);
823
824
833int gnc_commodity_table_has_namespace(const gnc_commodity_table * table,
834 const char * commodity_namespace);
835
843GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table * t);
844
852GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table * t);
853
864gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table * table,
865 const char * commodity_namespace,
866 QofBook *book);
867
876gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table * table,
877 const char * commodity_namespace);
878
888void gnc_commodity_table_delete_namespace(gnc_commodity_table * table,
889 const char * commodity_namespace);
891/* ---------------------------------------------------------- */
902guint gnc_commodity_table_get_size(const gnc_commodity_table* tbl);
903
917 const gnc_commodity_table * table, const char * commodity_namespace);
918
937 const gnc_commodity_table * table);
938
949gboolean gnc_commodity_table_foreach_commodity(const gnc_commodity_table * table,
950 gboolean (*f)(gnc_commodity *cm,
951 gpointer user_data),
952 gpointer user_data);
956/* ---------------------------------------------------------- */
965gnc_commodity_table * gnc_commodity_table_new(void);
966void gnc_commodity_table_destroy(gnc_commodity_table * table);
967
973gnc_commodity * gnc_commodity_obtain_twin (const gnc_commodity *findlike, QofBook *book);
974
979gboolean gnc_commodity_table_register (void);
980
981void gnc_commodity_begin_edit (gnc_commodity *cm);
982void gnc_commodity_commit_edit (gnc_commodity *cm);
983
987#define gnc_commodity_get_kvp_frame(cm) \
988 qof_instance_get_slots(QOF_INSTANCE(cm))
989
995struct _gnc_monetary
996{
997 gnc_commodity *commodity;
998 gnc_numeric value;
999};
1000
1001typedef struct _gnc_monetary gnc_monetary;
1002
1003/* A list of monetary values. This could be a hash table, but as currently
1004* used it rarely contains more than one or two different commodities so
1005* it doesn't seem worth the trouble.
1006*/
1007typedef GList MonetaryList;
1008
1012static inline
1013gnc_monetary gnc_monetary_create(gnc_commodity *commod, gnc_numeric val)
1014{
1015 gnc_monetary out;
1016 out.commodity = commod;
1017 out.value = val;
1018 return out;
1019}
1025static inline
1026gnc_commodity * gnc_monetary_commodity(gnc_monetary a)
1027{
1028 return a.commodity;
1029}
1030
1031static inline
1032gnc_numeric gnc_monetary_value(gnc_monetary a)
1033{
1034 return a.value;
1035}
1043MonetaryList *gnc_monetary_list_add_monetary(MonetaryList *list, gnc_monetary mon);
1044
1046static inline
1047MonetaryList *gnc_monetary_list_add_value(MonetaryList *list,
1048 gnc_commodity *commod,
1049 gnc_numeric value)
1050{
1052 gnc_monetary_create(commod, value));
1053}
1054
1056MonetaryList *gnc_monetary_list_delete_zeros(MonetaryList *list);
1057
1059void gnc_monetary_list_free(MonetaryList *list);
1064#ifdef __cplusplus
1065} /* extern "C" */
1066#endif
1067
1068#endif /* GNC_COMMODITY_H */
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.
const char * gnc_quote_source_fq_version(void)
This function returns the version of the Finance::Quote module installed on a user's computer.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
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.
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.
guint gnc_commodity_table_get_size(const gnc_commodity_table *tbl)
Returns the number of commodities in the commodity table.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
int gnc_commodity_compare(const gnc_commodity *a, const gnc_commodity *b)
This routine returns 0 if the two commodities are equal, 1 otherwise.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
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...
const char * gnc_commodity_get_user_symbol(const gnc_commodity *cm)
Retrieve the user-defined symbol for the specified commodity.
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.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
gboolean gnc_quote_source_fq_installed(void)
This function indicates whether or not the Finance::Quote module is installed on a user's computer.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *new_namespace)
Set the namespace for the specified commodity.
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 ...
gnc_quote_source * gnc_quote_source_add_new(const char *name, gboolean supported)
Create a new quote source.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
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.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
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.
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.
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *ns)
Return a list of all commodity data structures in the specified namespace.
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
MonetaryList * gnc_monetary_list_add_monetary(MonetaryList *list, gnc_monetary mon)
Add a gnc_monetary to the list.
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...
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.
gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book)
Add all the standard namespaces and currencies to the commodity table.
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
Retrieve the automatic price quote timezone for the specified commodity.
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
Retrieve the default symbol for the specified commodity.
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
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_l...
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
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.
void gnc_commodity_set_fraction(gnc_commodity *cm, int smallest_fraction)
Set the fraction for the specified commodity.
gboolean gnc_commodity_table_register(void)
You should probably not be using gnc_commodity_table_register() It is an internal routine for registe...
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source for the specified commodity.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
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.
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 th...
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.
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
Increment a commodity's internal counter that tracks how many accounts are using that commodity.
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *t)
Return a list of all namespaces in the commodity table.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
Delete all the zero-value entries from a list.
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *t)
Return a list of all namespace data structures in the commodity table.
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
Set a user-defined symbol for the specified commodity.
void gnc_commodity_decrement_usage_count(gnc_commodity *cm)
Decrement a commodity's internal counter that tracks how many accounts are using that commodity.
gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
allocate and copy
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.
void gnc_monetary_list_free(MonetaryList *list)
Free a monetary list and all the items it points to.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
gnc_commodity_namespace * gnc_commodity_get_namespace_ds(const gnc_commodity *cm)
Retrieve the namespace data structure for the specified commodity.
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.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
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.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
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.
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.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
Copy src into dest.
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.
gint gnc_quote_source_num_entries(QuoteSourceType type)
Return the number of entries for a given type of quote source.
@ SOURCE_MULTI
This quote source may pull from multiple web sites.
@ SOURCE_SINGLE
This quote source pulls from a single specific web site.
@ SOURCE_CURRENCY
The special currency quote source.
@ SOURCE_UNKNOWN
This is a locally installed quote source that gnucash knows nothing about.
The type used to store guids in C.
Definition guid.h:75
QofBook reference.
Definition qofbook-p.hpp:47

◆ GNC_COMMODITY_CLASS

#define GNC_COMMODITY_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY, gnc_commodityClass))

Definition at line 65 of file gnc-commodity.h.

◆ GNC_COMMODITY_GET_CLASS

#define GNC_COMMODITY_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY, gnc_commodityClass))

Definition at line 71 of file gnc-commodity.h.

◆ gnc_commodity_get_kvp_frame

#define gnc_commodity_get_kvp_frame (   cm)     qof_instance_get_slots(QOF_INSTANCE(cm))

Get the internal KVP from of the currency.

You should rather use the individual accessors for individual properties

Definition at line 987 of file gnc-commodity.h.

◆ GNC_COMMODITY_MAX_FRACTION

#define GNC_COMMODITY_MAX_FRACTION   1000000000

Max fraction is 10^9 because 10^10 would require changing it to an int64_t.

Definition at line 116 of file gnc-commodity.h.

◆ GNC_COMMODITY_NAMESPACE

#define GNC_COMMODITY_NAMESPACE (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespace))

Definition at line 77 of file gnc-commodity.h.

◆ GNC_COMMODITY_NAMESPACE_CLASS

#define GNC_COMMODITY_NAMESPACE_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))

Definition at line 79 of file gnc-commodity.h.

◆ GNC_COMMODITY_NAMESPACE_GET_CLASS

#define GNC_COMMODITY_NAMESPACE_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))

Definition at line 85 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_CURRENCY

#define GNC_COMMODITY_NS_CURRENCY   "CURRENCY"

Definition at line 107 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_ISO

#define GNC_COMMODITY_NS_ISO   "ISO4217"

Definition at line 106 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_ISO_GUI

#define GNC_COMMODITY_NS_ISO_GUI   NC_("Commodity Type", "Currencies")

Definition at line 111 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_LEGACY

#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.

The LEGACY name is only used by the file i/o routines, and is converted to another commodity namespace before it is seen by the rest of the system. The ISO namespace represents currencies. With the exception of the NASDAQ namespace (which is used once in the binary importer) the rest of the namespace declarations are only used to populate an option menu in the commodity selection window.

Definition at line 103 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_NONCURRENCY

#define GNC_COMMODITY_NS_NONCURRENCY   "NONCURRENCY"

Definition at line 108 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_NONISO_GUI

#define GNC_COMMODITY_NS_NONISO_GUI   NC_("Commodity Type", "All non-currency")

Definition at line 110 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_TEMPLATE

#define GNC_COMMODITY_NS_TEMPLATE   "template"

Definition at line 104 of file gnc-commodity.h.

◆ GNC_COMMODITY_TABLE

#define GNC_COMMODITY_TABLE   "gnc_commodity_table"

Definition at line 90 of file gnc-commodity.h.

◆ GNC_IS_COMMODITY

#define GNC_IS_COMMODITY (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY))

Definition at line 67 of file gnc-commodity.h.

◆ GNC_IS_COMMODITY_CLASS

#define GNC_IS_COMMODITY_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY))

Definition at line 69 of file gnc-commodity.h.

◆ GNC_IS_COMMODITY_NAMESPACE

#define GNC_IS_COMMODITY_NAMESPACE (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY_NAMESPACE))

Definition at line 81 of file gnc-commodity.h.

◆ GNC_IS_COMMODITY_NAMESPACE_CLASS

#define GNC_IS_COMMODITY_NAMESPACE_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY_NAMESPACE))

Definition at line 83 of file gnc-commodity.h.

◆ GNC_TYPE_COMMODITY

#define GNC_TYPE_COMMODITY   (gnc_commodity_get_type ())

Definition at line 62 of file gnc-commodity.h.

◆ GNC_TYPE_COMMODITY_NAMESPACE

#define GNC_TYPE_COMMODITY_NAMESPACE   (gnc_commodity_namespace_get_type ())

Definition at line 76 of file gnc-commodity.h.

Typedef Documentation

◆ CommodityList

typedef GList CommodityList

Definition at line 118 of file gnc-commodity.h.

◆ CommVec

using CommVec = std::vector<gnc_commodity*>

Definition at line 41 of file gnc-commodity.hpp.

◆ MonetaryList

typedef GList MonetaryList

Definition at line 1007 of file gnc-commodity.h.

Enumeration Type Documentation

◆ QuoteSourceType

The quote source type enum account types are used to determine how the transaction data in the account is displayed.

These values can be safely changed from one release to the next.

Enumerator
SOURCE_SINGLE 

This quote source pulls from a single specific web site.

For example, the yahoo_australia source only pulls from the yahoo web site.

SOURCE_MULTI 

This quote source may pull from multiple web sites.

For example, the australia source may pull from ASX, yahoo, etc.

SOURCE_UNKNOWN 

This is a locally installed quote source that gnucash knows nothing about.

May pull from single or multiple locations.

SOURCE_CURRENCY 

The special currency quote source.

Definition at line 128 of file gnc-commodity.h.

129{
130 SOURCE_SINGLE = 0,
141 SOURCE_MAX,
142 SOURCE_CURRENCY = SOURCE_MAX,

Function Documentation

◆ gnc_commodity_begin_edit()

void gnc_commodity_begin_edit ( gnc_commodity *  cm)

Definition at line 493 of file gnc-commodity.cpp.

494{
495 qof_begin_edit(&cm->inst);
496}
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ gnc_commodity_clone()

gnc_commodity * gnc_commodity_clone ( const gnc_commodity *  src,
QofBook dest_book 
)

allocate and copy

Definition at line 895 of file gnc-commodity.cpp.

896{
897 gnc_commodityPrivate* src_priv;
898 gnc_commodityPrivate* dest_priv;
899
900 auto dest = GNC_COMMODITY (g_object_new(GNC_TYPE_COMMODITY, nullptr));
901 qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
902 src_priv = GET_PRIVATE(src);
903 dest_priv = GET_PRIVATE(dest);
904
905 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
906 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
907 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
908 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
909
910 dest_priv->name_space = src_priv->name_space;
911
912 dest_priv->fraction = src_priv->fraction;
913 dest_priv->quote_flag = src_priv->quote_flag;
914
916
917 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
918
919 reset_printname(dest_priv);
920 reset_unique_name(dest_priv);
921
922 return dest;
923}
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.

◆ gnc_commodity_commit_edit()

void gnc_commodity_commit_edit ( gnc_commodity *  cm)

Definition at line 513 of file gnc-commodity.cpp.

514{
515 if (!qof_commit_edit (QOF_INSTANCE(cm))) return;
516 qof_commit_edit_part2 (&cm->inst, commit_err, noop, comm_free);
517}
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers

◆ gnc_commodity_compare()

int gnc_commodity_compare ( const gnc_commodity *  a,
const gnc_commodity *  b 
)

This routine returns 0 if the two commodities are equal, 1 otherwise.

Commodities are equal if they have the same namespace, mnemonic, fullname, exchange private code and fraction. This function is useful for list-traversal comparison purposes where The semantics are 0, <0, or >0 (equal, greater than, less than) rather than "true or false"

Definition at line 1504 of file gnc-commodity.cpp.

1505{
1506 if (a == b) return 0;
1507 if (a && !b) return 1;
1508 if (b && !a) return -1;
1509 if (auto rv = g_strcmp0 (gnc_commodity_get_unique_name (a), gnc_commodity_get_unique_name (b)))
1510 return rv;
1511 return qof_instance_guid_compare(a, b);
1512}
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.

◆ gnc_commodity_compare_void()

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.

Definition at line 1516 of file gnc-commodity.cpp.

1517{
1518 return gnc_commodity_compare(GNC_COMMODITY (a), GNC_COMMODITY (b));
1519}

◆ gnc_commodity_copy()

void gnc_commodity_copy ( gnc_commodity *  dest,
const gnc_commodity *  src 
)

Copy src into dest.

Definition at line 878 of file gnc-commodity.cpp.

879{
880 gnc_commodityPrivate* src_priv = GET_PRIVATE(src);
881 gnc_commodityPrivate* dest_priv = GET_PRIVATE(dest);
882
883 gnc_commodity_set_fullname (dest, src_priv->fullname);
884 gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
885 dest_priv->name_space = src_priv->name_space;
886 gnc_commodity_set_fraction (dest, src_priv->fraction);
887 gnc_commodity_set_cusip (dest, src_priv->cusip);
888 gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
890 gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
891 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
892}

◆ gnc_commodity_decrement_usage_count()

void gnc_commodity_decrement_usage_count ( gnc_commodity *  cm)

Decrement a commodity's internal counter that tracks how many accounts are using that commodity.

For currencies, this may have the side effect of disabling the commodity's quote flag.

Parameters
cmA pointer to a commodity data structure.

Definition at line 1439 of file gnc-commodity.cpp.

1440{
1442
1443 ENTER("(cm=%p)", cm);
1444
1445 if (!cm)
1446 {
1447 LEAVE("");
1448 return;
1449 }
1450
1451 priv = GET_PRIVATE(cm);
1452
1453 if (priv->usage_count == 0)
1454 {
1455 PWARN("usage_count already zero");
1456 LEAVE("");
1457 return;
1458 }
1459
1460 priv->usage_count--;
1461 if ((priv->usage_count == 0) && priv->quote_flag
1462 && gnc_commodity_get_auto_quote_control_flag(cm)
1463 && gnc_commodity_is_iso(cm))
1464 {
1465 /* if this is a currency with auto quote control enabled and no more
1466 * accounts reference this currency, disable quote retrieval */
1468 }
1469 LEAVE("(usage_count=%d)", priv->usage_count);
1470}
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

◆ gnc_commodity_destroy()

void gnc_commodity_destroy ( gnc_commodity *  cm)

Destroy a commodity.

Release all memory attached to this data structure.

Note
This function does not (can not) check to see if the commodity is referenced anywhere.
Parameters
cmThe commodity to destroy.

Definition at line 870 of file gnc-commodity.cpp.

871{
872 gnc_commodity_begin_edit(cm);
873 qof_instance_set_destroying(cm, TRUE);
874 gnc_commodity_commit_edit(cm);
875}

◆ gnc_commodity_equal()

gboolean gnc_commodity_equal ( const gnc_commodity *  a,
const gnc_commodity *  b 
)

This routine returns TRUE if the two commodities are equal.

Commodities are equal if they have the same namespace, mnemonic, fullname, exchange private code and fraction.

Definition at line 1499 of file gnc-commodity.cpp.

1500{
1501 return gnc_commodity_compare(a, b) == 0;
1502}

◆ gnc_commodity_equiv()

gboolean gnc_commodity_equiv ( const gnc_commodity *  a,
const gnc_commodity *  b 
)

This routine returns TRUE if the two commodities are equivalent.

Commodities are equivalent if they have the same namespace and mnemonic. Equivalent commodities may belong to different exchanges, may have different fullnames, and may have different fractions.

Definition at line 1482 of file gnc-commodity.cpp.

1483{
1484 gnc_commodityPrivate* priv_a;
1485 gnc_commodityPrivate* priv_b;
1486
1487 if (a == b) return TRUE;
1488 if (!a || !b) return FALSE;
1489
1490 priv_a = GET_PRIVATE(a);
1491 priv_b = GET_PRIVATE(b);
1492 if (priv_a->name_space != priv_b->name_space) return FALSE;
1493 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1494
1495 return TRUE;
1496}

◆ gnc_commodity_find_commodity_by_guid()

gnc_commodity * gnc_commodity_find_commodity_by_guid ( const GncGUID guid,
QofBook book 
)

Definition at line 2181 of file gnc-commodity.cpp.

2182{
2183 QofCollection *col;
2184 if (!guid || !book) return nullptr;
2185 col = qof_book_get_collection (book, GNC_ID_COMMODITY);
2186 return (gnc_commodity *) qof_collection_lookup_entity (col, guid);
2187}
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition qofid.cpp:209

◆ gnc_commodity_get_auto_quote_control_flag()

gboolean gnc_commodity_get_auto_quote_control_flag ( const gnc_commodity *  cm)

Definition at line 1017 of file gnc-commodity.cpp.

1018{
1019 if (!cm) return FALSE;
1020 auto str{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE (cm), {"auto_quote_control"})};
1021 return !str || g_strcmp0 (*str, "false");
1022}

◆ gnc_commodity_get_cusip()

const char * gnc_commodity_get_cusip ( const gnc_commodity *  cm)

Retrieve the 'exchange code' for the specified commodity.

This will be a pointer to a null terminated string of the form "AXQ14728", etc. This field is often used when presenting information to the user.

Note
This is a unique code that specifies a particular item or set of shares of a commodity, not a code that specifies a stock exchange. That is the namespace field.
Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the exchange code for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 995 of file gnc-commodity.cpp.

996{
997 if (!cm) return nullptr;
998 return GET_PRIVATE(cm)->cusip;
999}

◆ gnc_commodity_get_default_quote_source()

gnc_quote_source * gnc_commodity_get_default_quote_source ( const gnc_commodity *  cm)

Definition at line 1052 of file gnc-commodity.cpp.

1053{
1054 if (cm && gnc_commodity_is_iso(cm))
1055 return &currency_quote_sources.front();
1056 /* Should make this a user option at some point. */
1057 return gnc_quote_source_lookup_by_internal("alphavantage");
1058}

◆ gnc_commodity_get_default_symbol()

const char * gnc_commodity_get_default_symbol ( const gnc_commodity *  cm)

Retrieve the default symbol for the specified commodity.

This will be a pointer to a nul terminated string like "£", "US$", etc. Note that for the locale currency, you probably want to look at the system-provided symbol first. See gnc_commodity_get_nice_symbol.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the default symbol for this commodity.

Definition at line 1087 of file gnc-commodity.cpp.

1088{
1089 if (!cm) return nullptr;
1090 return GET_PRIVATE(cm)->default_symbol;
1091}

◆ gnc_commodity_get_fraction()

int gnc_commodity_get_fraction ( const gnc_commodity *  cm)

Retrieve the fraction for the specified commodity.

This will be an integer value specifying the number of fractional units that one of these commodities can be divided into. Should always be a power of 10.

Parameters
cmA pointer to a commodity data structure.
Returns
The number of fractional units that one of these commodities can be divided into.

Definition at line 1006 of file gnc-commodity.cpp.

1007{
1008 if (!cm) return 0;
1009 return GET_PRIVATE(cm)->fraction;
1010}

◆ gnc_commodity_get_fullname()

const char * gnc_commodity_get_fullname ( const gnc_commodity *  cm)

Retrieve the full name for the specified commodity.

This will be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the full name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 971 of file gnc-commodity.cpp.

972{
973 if (!cm) return nullptr;
974 return GET_PRIVATE(cm)->fullname;
975}

◆ gnc_commodity_get_mnemonic()

const char * gnc_commodity_get_mnemonic ( const gnc_commodity *  cm)

Retrieve the mnemonic for the specified commodity.

This will be a pointer to a null terminated string of the form "ACME", "QWER", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the mnemonic for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 930 of file gnc-commodity.cpp.

931{
932 if (!cm) return nullptr;
933 return GET_PRIVATE(cm)->mnemonic;
934}

◆ gnc_commodity_get_namespace()

const char * gnc_commodity_get_namespace ( const gnc_commodity *  cm)

Retrieve the namespace for the specified commodity.

This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the namespace for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 953 of file gnc-commodity.cpp.

954{
955 if (!cm) return nullptr;
956 return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
957}

◆ gnc_commodity_get_namespace_ds()

gnc_commodity_namespace * gnc_commodity_get_namespace_ds ( const gnc_commodity *  cm)

Retrieve the namespace data structure for the specified commodity.

This will be a pointer to another data structure.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the namespace data structure for this commodity.

Definition at line 960 of file gnc-commodity.cpp.

961{
962 if (!cm) return nullptr;
963 return GET_PRIVATE(cm)->name_space;
964}

◆ gnc_commodity_get_nice_symbol()

const char * gnc_commodity_get_nice_symbol ( const gnc_commodity *  cm)

Retrieve a symbol for the specified commodity, suitable for display to the user.

This will be a pointer to a nul terminated string like "£", "US$", etc. That function is locale-aware and will base its choice of symbol on the user-configured symbol, the locale a

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the symbol for this commodity.

Definition at line 1097 of file gnc-commodity.cpp.

1098{
1099 const char *nice_symbol;
1100 struct lconv *lc;
1101 if (!cm) return nullptr;
1102
1103 nice_symbol = gnc_commodity_get_user_symbol(cm);
1104 if (nice_symbol && *nice_symbol)
1105 return nice_symbol;
1106
1107 lc = gnc_localeconv();
1108 nice_symbol = lc->currency_symbol;
1109 if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1110 return nice_symbol;
1111
1112 nice_symbol = gnc_commodity_get_default_symbol(cm);
1113 if (nice_symbol && *nice_symbol)
1114 return nice_symbol;
1115
1116 return gnc_commodity_get_mnemonic(cm);
1117}

◆ gnc_commodity_get_printname()

const char * gnc_commodity_get_printname ( const gnc_commodity *  cm)

Retrieve the 'print' name for the specified commodity.

This will be a pointer to a null terminated string of the form "Acme Systems, Inc. (ACME)", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the print name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 941 of file gnc-commodity.cpp.

942{
943 if (!cm) return nullptr;
944 return GET_PRIVATE(cm)->printname;
945}

◆ gnc_commodity_get_quote_flag()

gboolean gnc_commodity_get_quote_flag ( const gnc_commodity *  cm)

Retrieve the automatic price quote flag for the specified commodity.

This flag indicates whether stock quotes should be retrieved for the specified stock.

Parameters
cmA pointer to a commodity data structure.
Returns
TRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1029 of file gnc-commodity.cpp.

1030{
1031 if (!cm) return FALSE;
1032 return (GET_PRIVATE(cm)->quote_flag);
1033}

◆ gnc_commodity_get_quote_source()

gnc_quote_source * gnc_commodity_get_quote_source ( const gnc_commodity *  cm)

Retrieve the automatic price quote source for the specified commodity.

This will be a pointer to a null terminated string of the form "Yahoo (Asia)", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the price quote source for this commodity.

Definition at line 1040 of file gnc-commodity.cpp.

1041{
1043
1044 if (!cm) return nullptr;
1045 priv = GET_PRIVATE(cm);
1046 if (!priv->quote_source && gnc_commodity_is_iso(cm))
1047 return &currency_quote_sources.front();
1048 return priv->quote_source;
1049}

◆ gnc_commodity_get_quote_tz()

const char * gnc_commodity_get_quote_tz ( const gnc_commodity *  cm)

Retrieve the automatic price quote timezone for the specified commodity.

This will be a pointer to a null terminated string of the form "America/New_York", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the price quote timezone for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1065 of file gnc-commodity.cpp.

1066{
1067 if (!cm) return nullptr;
1068 return GET_PRIVATE(cm)->quote_tz;
1069}

◆ gnc_commodity_get_unique_name()

const char * gnc_commodity_get_unique_name ( const gnc_commodity *  cm)

Retrieve the 'unique' name for the specified commodity.

This will be a pointer to a null terminated string of the form "AMEX::ACME", etc. This field is often used when performing comparisons or other functions invisible to the user.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the 'unique' name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 983 of file gnc-commodity.cpp.

984{
985 if (!cm) return nullptr;
986 return GET_PRIVATE(cm)->unique_name;
987}

◆ gnc_commodity_get_user_symbol()

const char * gnc_commodity_get_user_symbol ( const gnc_commodity *  cm)

Retrieve the user-defined symbol for the specified commodity.

This will be a pointer to a nul terminated string like "£", "US$", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the user-defined symbol for this commodity. NULL means that the user didn't define any symbol, and that fallback to e.g. the mnemonic is in order. This string is owned by the engine and should not be freed by the caller.

Definition at line 1075 of file gnc-commodity.cpp.

1076{
1077 g_return_val_if_fail (GNC_IS_COMMODITY (cm), nullptr);
1078
1079 auto sym{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(cm), {"user_symbol"})};
1080 return sym ? *sym : nullptr;
1081}

◆ gnc_commodity_increment_usage_count()

void gnc_commodity_increment_usage_count ( gnc_commodity *  cm)

Increment a commodity's internal counter that tracks how many accounts are using that commodity.

For currencies, this may have the side effect of enabling the commodity's quote flag.

Parameters
cmA pointer to a commodity data structure.

Definition at line 1404 of file gnc-commodity.cpp.

1405{
1407
1408 ENTER("(cm=%p)", cm);
1409
1410 if (!cm)
1411 {
1412 LEAVE("");
1413 return;
1414 }
1415
1416 priv = GET_PRIVATE(cm);
1417
1418 if ((priv->usage_count == 0) && !priv->quote_flag
1419 && gnc_commodity_get_auto_quote_control_flag(cm)
1420 && gnc_commodity_is_iso(cm))
1421 {
1422 /* compatibility hack - Gnucash 1.8 gets currency quotes when a
1423 non-default currency is assigned to an account. */
1424 gnc_commodity_begin_edit(cm);
1427 gnc_commodity_get_default_quote_source(cm));
1428 gnc_commodity_commit_edit(cm);
1429 }
1430 priv->usage_count++;
1431 LEAVE("(usage_count=%d)", priv->usage_count);
1432}

◆ gnc_commodity_is_currency()

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.

Parameters
cmThe commodity to check.
Returns
TRUE if the commodity represents a currency, FALSE otherwise.

Definition at line 1955 of file gnc-commodity.cpp.

1956{
1957 const char *ns_name;
1958 if (!cm) return FALSE;
1959
1960 ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1961 return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
1962 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
1963}
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...

◆ gnc_commodity_is_iso()

gboolean gnc_commodity_is_iso ( const gnc_commodity *  cm)

Checks to see if the specified commodity is an ISO 4217 recognized currency.

Parameters
cmThe commodity to check.
Returns
TRUE if the commodity represents a currency, FALSE otherwise.

Definition at line 1943 of file gnc-commodity.cpp.

1944{
1946
1947 if (!cm) return FALSE;
1948
1949 priv = GET_PRIVATE(cm);
1950 if ( !priv->name_space) return FALSE;
1951 return priv->name_space->iso4217;
1952}

◆ gnc_commodity_namespace_get_commodity_list()

GList * gnc_commodity_namespace_get_commodity_list ( const gnc_commodity_namespace *  ns)

Return a list of all commodity data structures in the specified namespace.

Returns
A pointer to the list of structures. NULL if an invalid argument was supplied.
Note
This list is owned by the caller who must free the list.

Definition at line 1543 of file gnc-commodity.cpp.

1544{
1545 if (!name_space)
1546 return nullptr;
1547
1548 return g_list_copy (name_space->cm_list);
1549}

◆ gnc_commodity_namespace_get_gui_name()

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.

Parameters
nsA pointer to the namespace data structure.
Returns
A pointer to the gui friendly name of the namespace. This string is owned by the engine and should not be freed by the caller.

@notes The returned string is marked for translation, but not translated yet. If you want it translated pass the return value on to gettext.

Definition at line 1533 of file gnc-commodity.cpp.

1534{
1535 if (ns == nullptr)
1536 return nullptr;
1537 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1538 return GNC_COMMODITY_NS_ISO_GUI;
1539 return ns->name;
1540}

◆ gnc_commodity_namespace_get_name()

const char * gnc_commodity_namespace_get_name ( const gnc_commodity_namespace *  ns)

Return the textual name of a namespace data structure.

Parameters
nsA pointer to the namespace data structure.
Returns
A pointer to the name of the namespace. This string is owned by the engine and should not be freed by the caller.

Definition at line 1525 of file gnc-commodity.cpp.

1526{
1527 if (ns == nullptr)
1528 return nullptr;
1529 return ns->name;
1530}

◆ gnc_commodity_namespace_is_iso()

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.

Parameters
commodity_namespaceThe string to check.
Returns
TRUE if the string indicates an ISO currency, FALSE otherwise.

Definition at line 1552 of file gnc-commodity.cpp.

1553{
1554 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1555 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1556}

◆ gnc_commodity_new()

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.

This function allocates a new commodity data structure, populates it with the data provided, and then generates the dynamic names that exist as part of a commodity.

Note
This function does not check to see if the commodity exists before adding a new commodity.
Parameters
bookThe book that the new commodity will belong to.
fullnameThe complete name of this commodity. E.G. "Acme Systems, Inc."
commodity_namespaceAn aggregation of commodities. E.G. ISO4217, Nasdaq, Downbelow, etc.
mnemonicAn abbreviation for this stock. For publicly traced stocks, this field should contain the stock ticker symbol. This field is used to get online price quotes, so it must match the stock ticker symbol used by the exchange where you want to get automatic stock quote updates. E.G. ACME, ACME.US, etc.
cusipA string containing the CUSIP code or similar UNIQUE code for this commodity like the ISIN. The stock ticker is NOT appropriate as that goes in the mnemonic field.
fractionThe smallest division of this commodity allowed. I.E. If this is 1, then the commodity must be traded in whole units; if 100 then the commodity may be traded in 0.01 units, etc.
Returns
A pointer to the new commodity.

Definition at line 777 of file gnc-commodity.cpp.

780{
781 auto retval = GNC_COMMODITY(g_object_new(GNC_TYPE_COMMODITY, nullptr));
782
783 qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
784 gnc_commodity_begin_edit(retval);
785
786 if ( name_space != nullptr )
787 {
788 /* Prevent setting anything except template in namespace template. */
789 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
790 g_strcmp0 (mnemonic, "template") != 0)
791 {
792 PWARN("Converting commodity %s from namespace template to "
793 "namespace User", mnemonic);
794 name_space = "User";
795 }
796 gnc_commodity_set_namespace(retval, name_space);
797 if (gnc_commodity_namespace_is_iso(name_space))
798 {
801 }
802 }
803 gnc_commodity_set_fullname(retval, fullname);
804 gnc_commodity_set_mnemonic(retval, mnemonic);
805 gnc_commodity_set_cusip(retval, cusip);
806 gnc_commodity_set_fraction(retval, fraction);
807 mark_commodity_dirty (retval);
808 gnc_commodity_commit_edit(retval);
809
810 qof_event_gen (&retval->inst, QOF_EVENT_CREATE, nullptr);
811
812 return retval;
813}
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231

◆ gnc_commodity_obtain_twin()

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.

This routine is primarily useful for setting up clones of things across multiple books.

Definition at line 1592 of file gnc-commodity.cpp.

1593{
1594 gnc_commodity *twin;
1595 const char * ucom;
1596 gnc_commodity_table * comtbl;
1597
1598 if (!from) return nullptr;
1599 comtbl = gnc_commodity_table_get_table (book);
1600 if (!comtbl) return nullptr;
1601
1602 ucom = gnc_commodity_get_unique_name (from);
1603 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1604 if (!twin)
1605 {
1606 twin = gnc_commodity_clone (from, book);
1607 twin = gnc_commodity_table_insert (comtbl, twin);
1608 }
1609 return twin;
1610}

◆ gnc_commodity_set_auto_quote_control_flag()

void gnc_commodity_set_auto_quote_control_flag ( gnc_commodity *  cm,
const gboolean  flag 
)

Definition at line 1235 of file gnc-commodity.cpp.

1237{
1238 ENTER ("(cm=%p, flag=%d)", cm, flag);
1239
1240 if (!cm)
1241 {
1242 LEAVE("");
1243 return;
1244 }
1245 gnc_commodity_begin_edit(cm);
1246 auto val = flag ? std::nullopt : std::make_optional<const char*>(g_strdup("false"));
1247 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE (cm), val, {"auto_quote_control"});
1248 mark_commodity_dirty(cm);
1249 gnc_commodity_commit_edit(cm);
1250 LEAVE("");
1251}

◆ gnc_commodity_set_cusip()

void gnc_commodity_set_cusip ( gnc_commodity *  cm,
const char *  cusip 
)

Set the 'exchange code' for the specified commodity.

This should be a pointer to a null terminated string of the form "AXQ14728", etc.

Note
This is a unique code that specifies a particular item or set of shares of a commodity, not a code that specifies a stock exchange. That is the namespace field.
Parameters
cmA pointer to a commodity data structure.
cusipA pointer to the cusip or other exchange specific data for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1199 of file gnc-commodity.cpp.

1201{
1203
1204 if (!cm) return;
1205
1206 priv = GET_PRIVATE(cm);
1207 if (priv->cusip == cusip) return;
1208
1209 gnc_commodity_begin_edit(cm);
1210 CACHE_REMOVE (priv->cusip);
1211 priv->cusip = CACHE_INSERT (cusip);
1212 mark_commodity_dirty(cm);
1213 gnc_commodity_commit_edit(cm);
1214}

◆ gnc_commodity_set_fraction()

void gnc_commodity_set_fraction ( gnc_commodity *  cm,
int  smallest_fraction 
)

Set the fraction for the specified commodity.

This should be an integer value specifying the number of fractional units that one of these commodities can be divided into. Should always be a power of 10.

Parameters
cmA pointer to a commodity data structure.
smallest_fractionThe number of fractional units that one of these commodities can be divided into.

Definition at line 1221 of file gnc-commodity.cpp.

1222{
1223 if (!cm) return;
1224 gnc_commodity_begin_edit(cm);
1225 GET_PRIVATE(cm)->fraction = fraction;
1226 mark_commodity_dirty(cm);
1227 gnc_commodity_commit_edit(cm);
1228}

◆ gnc_commodity_set_fullname()

void gnc_commodity_set_fullname ( gnc_commodity *  cm,
const char *  fullname 
)

Set the full name for the specified commodity.

This should be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.

Parameters
cmA pointer to a commodity data structure.
fullnameA pointer to the full name for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1177 of file gnc-commodity.cpp.

1178{
1180
1181 if (!cm) return;
1182 priv = GET_PRIVATE(cm);
1183 if (priv->fullname == fullname) return;
1184
1185 CACHE_REMOVE (priv->fullname);
1186 priv->fullname = CACHE_INSERT (fullname);
1187
1188 gnc_commodity_begin_edit(cm);
1189 mark_commodity_dirty(cm);
1190 reset_printname(priv);
1191 gnc_commodity_commit_edit(cm);
1192}

◆ gnc_commodity_set_mnemonic()

void gnc_commodity_set_mnemonic ( gnc_commodity *  cm,
const char *  mnemonic 
)

Set the mnemonic for the specified commodity.

This should be a pointer to a null terminated string of the form "ACME", "QWER", etc.

Parameters
cmA pointer to a commodity data structure.
mnemonicA pointer to the mnemonic for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1124 of file gnc-commodity.cpp.

1125{
1127
1128 if (!cm) return;
1129 priv = GET_PRIVATE(cm);
1130 if (priv->mnemonic == mnemonic) return;
1131
1132 gnc_commodity_begin_edit(cm);
1133 CACHE_REMOVE (priv->mnemonic);
1134 priv->mnemonic = CACHE_INSERT(mnemonic);
1135
1136 mark_commodity_dirty (cm);
1137 reset_printname(priv);
1138 reset_unique_name(priv);
1139 gnc_commodity_commit_edit(cm);
1140}

◆ gnc_commodity_set_namespace()

void gnc_commodity_set_namespace ( gnc_commodity *  cm,
const char *  new_namespace 
)

Set the namespace for the specified commodity.

This should be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.

Parameters
cmA pointer to a commodity data structure.
new_namespaceA pointer to the namespace for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1147 of file gnc-commodity.cpp.

1148{
1149 QofBook *book;
1150 gnc_commodity_table *table;
1151 gnc_commodity_namespace *nsp;
1153
1154 if (!cm) return;
1155 priv = GET_PRIVATE(cm);
1156 book = qof_instance_get_book (&cm->inst);
1158 nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1159 if (priv->name_space == nsp)
1160 return;
1161
1162 gnc_commodity_begin_edit(cm);
1163 priv->name_space = nsp;
1164 if (nsp->iso4217)
1165 priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1166 mark_commodity_dirty(cm);
1167 reset_printname(priv);
1168 reset_unique_name(priv);
1169 gnc_commodity_commit_edit(cm);
1170}
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.

◆ gnc_commodity_set_quote_flag()

void gnc_commodity_set_quote_flag ( gnc_commodity *  cm,
const gboolean  flag 
)

Set the automatic price quote flag for the specified commodity.

This flag indicates whether stock quotes should be retrieved for the specified stock.

Parameters
cmA pointer to a commodity data structure.
flagTRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1294 of file gnc-commodity.cpp.

1295{
1296 ENTER ("(cm=%p, flag=%d)", cm, flag);
1297
1298 if (!cm) return;
1299 gnc_commodity_begin_edit(cm);
1300 GET_PRIVATE(cm)->quote_flag = flag;
1301 mark_commodity_dirty(cm);
1302 gnc_commodity_commit_edit(cm);
1303 LEAVE(" ");
1304}

◆ gnc_commodity_set_quote_source()

void gnc_commodity_set_quote_source ( gnc_commodity *  cm,
gnc_quote_source *  src 
)

Set the automatic price quote source for the specified commodity.

This should be a pointer to a null terminated string of the form "Yahoo (Asia)", etc. Legal values can be found in the quote_sources array in the file gnc-ui-util.c.

Parameters
cmA pointer to a commodity data structure.
srcA pointer to the price quote source for this commodity.

Definition at line 1311 of file gnc-commodity.cpp.

1312{
1313 ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->get_internal_name() : "unknown");
1314
1315 if (!cm) return;
1316 gnc_commodity_begin_edit(cm);
1317 GET_PRIVATE(cm)->quote_source = src;
1318 mark_commodity_dirty(cm);
1319 gnc_commodity_commit_edit(cm);
1320 LEAVE(" ");
1321}

◆ gnc_commodity_set_quote_tz()

void gnc_commodity_set_quote_tz ( gnc_commodity *  cm,
const char *  tz 
)

Set the automatic price quote timezone for the specified commodity.

This should be a pointer to a null terminated string of the form "America/New_York", etc. Legal values can be found in the known_timezones array in the file src/gnome-utils/dialog-commodity.c.

Parameters
cmA pointer to a commodity data structure.
tzA pointer to the price quote timezone for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1328 of file gnc-commodity.cpp.

1329{
1331
1332 if (!cm) return;
1333
1334 ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1335
1336 priv = GET_PRIVATE(cm);
1337
1338 if (tz == priv->quote_tz)
1339 {
1340 LEAVE("Already correct TZ");
1341 return;
1342 }
1343
1344 gnc_commodity_begin_edit(cm);
1345 CACHE_REMOVE (priv->quote_tz);
1346 priv->quote_tz = CACHE_INSERT (tz);
1347 mark_commodity_dirty(cm);
1348 gnc_commodity_commit_edit(cm);
1349 LEAVE(" ");
1350}

◆ gnc_commodity_set_user_symbol()

void gnc_commodity_set_user_symbol ( gnc_commodity *  cm,
const char *  user_symbol 
)

Set a user-defined symbol for the specified commodity.

This should be a pointer to a nul terminated string like "£", "US$", etc.

Parameters
cmA pointer to a commodity data structure.
tzA pointer to the symbol for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1357 of file gnc-commodity.cpp.

1358{
1359 struct lconv *lc;
1360
1361 if (!cm) return;
1362
1363 ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1364
1365 lc = gnc_localeconv();
1366 if (!user_symbol || !*user_symbol)
1367 user_symbol = nullptr;
1368 else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1369 !g_strcmp0(lc->currency_symbol, user_symbol))
1370 /* if the user gives the ISO symbol for the locale currency or the
1371 * default symbol, actually remove the user symbol */
1372 user_symbol = nullptr;
1373 else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1374 user_symbol = nullptr;
1375
1376 gnc_commodity_begin_edit (cm);
1377
1378 auto val = user_symbol ? std::make_optional<const char*>(g_strdup(user_symbol)) : std::nullopt;
1379 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(cm), val, {"user_symbol"});
1380
1381 mark_commodity_dirty(cm);
1382 gnc_commodity_commit_edit(cm);
1383
1384 LEAVE(" ");
1385}

◆ gnc_commodity_table_add_default_data()

gboolean gnc_commodity_table_add_default_data ( gnc_commodity_table *  table,
QofBook book 
)

Add all the standard namespaces and currencies to the commodity table.

This routine creates the namespaces for the NYSE, NASDAQ, etc. It also adds all of the ISO 4217 currencies to the commodity table.

Parameters
tableA pointer to the commodity table.
bookUnused.

Definition at line 2319 of file gnc-commodity.cpp.

2320{
2321 QofCollection *col;
2322 gnc_commodity* c;
2323
2324 ENTER ("table=%p", table);
2325 gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book);
2326 c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1);
2328
2329#include "iso-4217-currencies.c"
2330
2331 /* We've just created the default namespaces and currencies. Mark
2332 * these collections as clean because there is no USER entered data
2333 * in these collections as of yet. */
2334 col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2336 col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2338
2339 LEAVE ("table=%p", table);
2340 return TRUE;
2341}
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
Definition qofid.cpp:238

◆ gnc_commodity_table_add_namespace()

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.

If the new namespace already exists, nothing happens.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to be added.
bookThe book that the new namespace will belong to.
Returns
A pointer to the newly created namespace.

Definition at line 2108 of file gnc-commodity.cpp.

2111{
2112 gnc_commodity_namespace * ns = nullptr;
2113
2114 if (!table) return nullptr;
2115
2116 name_space = gnc_commodity_table_map_namespace(name_space);
2117 ns = gnc_commodity_table_find_namespace(table, name_space);
2118 if (!ns)
2119 {
2120 ns = static_cast<gnc_commodity_namespace*>(g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, nullptr));
2121 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2122 ns->name = CACHE_INSERT(static_cast<const char*>(name_space));
2123 ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2124 qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2125 qof_event_gen (&ns->inst, QOF_EVENT_CREATE, nullptr);
2126
2127 g_hash_table_insert(table->ns_table,
2128 (gpointer) ns->name,
2129 (gpointer) ns);
2130 table->ns_list = g_list_append(table->ns_list, ns);
2131 qof_event_gen (&ns->inst, QOF_EVENT_ADD, nullptr);
2132 }
2133 return ns;
2134}

◆ gnc_commodity_table_delete_namespace()

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.

If the namespace does not exist, nothing happens.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe namespace to be deleted.
Note
This routine will destroy any commodities that exist as part of this namespace. Use it carefully.

Definition at line 2204 of file gnc-commodity.cpp.

2206{
2207 gnc_commodity_namespace * ns;
2208
2209 if (!table) return;
2210
2211 ns = gnc_commodity_table_find_namespace(table, name_space);
2212 if (!ns)
2213 return;
2214
2215 qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, nullptr);
2216 g_hash_table_remove(table->ns_table, name_space);
2217 table->ns_list = g_list_remove(table->ns_list, ns);
2218
2219 g_list_free(ns->cm_list);
2220 ns->cm_list = nullptr;
2221
2222 g_hash_table_foreach_remove(ns->cm_table, ns_helper, nullptr);
2223 g_hash_table_destroy(ns->cm_table);
2224 CACHE_REMOVE(ns->name);
2225
2226 qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, nullptr);
2227 /* qof_instance_release(&ns->inst); */
2228 g_object_unref(ns);
2229}

◆ gnc_commodity_table_destroy()

void gnc_commodity_table_destroy ( gnc_commodity_table *  table)

Definition at line 2287 of file gnc-commodity.cpp.

2288{
2289 gnc_commodity_namespace * ns;
2290 GList *item, *next;
2291
2292 if (!t) return;
2293 ENTER ("table=%p", t);
2294
2295 for (item = t->ns_list; item; item = next)
2296 {
2297 next = g_list_next(item);
2298 ns = static_cast<gnc_commodity_namespace*>(item->data);
2300 }
2301
2302 g_list_free(t->ns_list);
2303 t->ns_list = nullptr;
2304 g_hash_table_destroy(t->ns_table);
2305 t->ns_table = nullptr;
2306 LEAVE ("table=%p", t);
2307 g_free(t);
2308}

◆ gnc_commodity_table_find_full()

gnc_commodity * gnc_commodity_table_find_full ( const gnc_commodity_table *  t,
const char *  commodity_namespace,
const char *  fullname 
)

Definition at line 1720 of file gnc-commodity.cpp.

1723{
1724 gnc_commodity * retval = nullptr;
1725 GList * all;
1726 GList * iterator;
1727
1728 if (!fullname || (fullname[0] == '\0'))
1729 return nullptr;
1730
1731 all = gnc_commodity_table_get_commodities(table, name_space);
1732
1733 for (iterator = all; iterator; iterator = iterator->next)
1734 {
1735 auto commodity = GNC_COMMODITY (iterator->data);
1736 if (!strcmp(fullname,
1737 gnc_commodity_get_printname(commodity)))
1738 {
1739 retval = commodity;
1740 break;
1741 }
1742 }
1743
1744 g_list_free (all);
1745
1746 return retval;
1747}

◆ gnc_commodity_table_find_namespace()

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.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to be added.
Returns
The a pointer to the namespace found, or NULL if the namespace doesn't exist.

Definition at line 2169 of file gnc-commodity.cpp.

2171{
2172 if (!table || !name_space)
2173 return nullptr;
2174
2175 name_space = gnc_commodity_table_map_namespace(name_space);
2176 return static_cast<gnc_commodity_namespace*>(g_hash_table_lookup(table->ns_table, (gpointer)name_space));
2177}

◆ gnc_commodity_table_foreach_commodity()

gboolean gnc_commodity_table_foreach_commodity ( const gnc_commodity_table *  table,
gboolean(*)(gnc_commodity *cm, gpointer user_data)  f,
gpointer  user_data 
)

Call a function once for each commodity in the commodity table.

This table walk returns whenever the end of the table is reached, or the function returns FALSE.

Parameters
tableA pointer to the commodity table
fThe function to call for each commodity.
user_dataA pointer that is passed into the function unchanged by the table walk routine.

◆ gnc_commodity_table_get_commodities()

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.

Parameters
tableA pointer to the commodity table
commodity_namespaceA string indicating which commodities should be returned. It is a required argument.
Returns
A pointer to the list of commodities. NULL if an invalid argument was supplied, or the namespace could not be found.
Note
It is the callers responsibility to free the list.

Definition at line 1991 of file gnc-commodity.cpp.

1993{
1994 gnc_commodity_namespace * ns = nullptr;
1995
1996 if (!table)
1997 return nullptr;
1998 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
1999 return commodity_table_get_all_noncurrency_commodities(table);
2000 ns = gnc_commodity_table_find_namespace(table, name_space);
2001 if (!ns)
2002 return nullptr;
2003
2004 return g_hash_table_values(ns->cm_table);
2005}

◆ gnc_commodity_table_get_namespaces()

GList * gnc_commodity_table_get_namespaces ( const gnc_commodity_table *  t)

Return a list of all namespaces in the commodity table.

This returns both system and user defined namespaces.

Returns
A pointer to the list of names. NULL if an invalid argument was supplied.
Note
It is the callers responsibility to free the list.

Definition at line 1919 of file gnc-commodity.cpp.

1920{
1921 if (!table)
1922 return nullptr;
1923
1924 return g_hash_table_keys(table->ns_table);
1925}

◆ gnc_commodity_table_get_namespaces_list()

GList * gnc_commodity_table_get_namespaces_list ( const gnc_commodity_table *  t)

Return a list of all namespace data structures in the commodity table.

This returns both system and user defined namespace structures.

Returns
A pointer to the list of structures. NULL if an invalid argument was supplied.
Note
This list is owned by the caller who must free the list.

Definition at line 1928 of file gnc-commodity.cpp.

1929{
1930 if (!table)
1931 return nullptr;
1932
1933 return g_list_copy (table->ns_list);
1934}

◆ gnc_commodity_table_get_quotable_commodities()

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.

It will scan the entire commodity table (or a subset) and check each commodity to see if the price_quote_flag field has been set. All matching commodities are queued onto a list, and the head of that list is returned. Use the command-line given expression as a filter on the commodities to be returned. If non-null, only commodities in namespace that match the specified regular expression are checked. If none was given, all commodities are checked.

Parameters
tableA pointer to the commodity table
Returns
A pointer to a list of commodities. NULL if invalid arguments were supplied or if there no commodities are flagged for quote retrieval.
Note
It is the callers responsibility to free the list.

Definition at line 2037 of file gnc-commodity.cpp.

2038{
2039 gnc_commodity_namespace * ns = nullptr;
2040 const char *name_space;
2041 GList * nslist, * tmp;
2042 GList * l = nullptr;
2043 regex_t pattern;
2044 const char *expression = gnc_prefs_get_namespace_regexp();
2045
2046 ENTER("table=%p, expression=%s", table, expression);
2047 if (!table)
2048 return nullptr;
2049
2050 if (expression && *expression)
2051 {
2052 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2053 {
2054 LEAVE("Cannot compile regex");
2055 return nullptr;
2056 }
2057
2059 for (tmp = nslist; tmp; tmp = tmp->next)
2060 {
2061 name_space = static_cast<const char*>(tmp->data);
2062 if (regexec(&pattern, name_space, 0, nullptr, 0) == 0)
2063 {
2064 DEBUG("Running list of %s commodities", name_space);
2065 ns = gnc_commodity_table_find_namespace(table, name_space);
2066 if (ns)
2067 {
2068 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2069 }
2070 }
2071 }
2072 g_list_free(nslist);
2073 regfree(&pattern);
2074 }
2075 else
2076 {
2077 gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2078 (gpointer) &l);
2079 }
2080 LEAVE("list head %p", l);
2081 return l;
2082}
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264

◆ gnc_commodity_table_get_size()

guint gnc_commodity_table_get_size ( const gnc_commodity_table *  tbl)

Returns the number of commodities in the commodity table.

Parameters
tblA pointer to the commodity table
Returns
The number of commodities in the table. 0 if there are no commodities, or the routine was passed a bad argument.

Definition at line 1635 of file gnc-commodity.cpp.

1636{
1637 guint count = 0;
1638 g_return_val_if_fail(tbl, 0);
1639 g_return_val_if_fail(tbl->ns_table, 0);
1640
1641 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1642
1643 return count;
1644}

◆ gnc_commodity_table_get_table()

gnc_commodity_table * gnc_commodity_table_get_table ( QofBook book)

Returns the commodity table associated with a book.

Definition at line 1585 of file gnc-commodity.cpp.

1586{
1587 if (!book) return nullptr;
1588 return static_cast<gnc_commodity_table*>(qof_book_get_data (book, GNC_COMMODITY_TABLE));
1589}

◆ gnc_commodity_table_has_namespace()

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.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to check.
Returns
1 if the namespace exists. 0 if it doesn't exist, or the routine was passed a bad argument.

Definition at line 1862 of file gnc-commodity.cpp.

1864{
1865 gnc_commodity_namespace * nsp = nullptr;
1866
1867 if (!table || !name_space)
1868 {
1869 return 0;
1870 }
1871
1872 nsp = gnc_commodity_table_find_namespace(table, name_space);
1873 if (nsp)
1874 {
1875 return 1;
1876 }
1877 else
1878 {
1879 return 0;
1880 }
1881}

◆ gnc_commodity_table_insert()

gnc_commodity * gnc_commodity_table_insert ( gnc_commodity_table *  table,
gnc_commodity *  comm 
)

Add a new commodity to the commodity table.

This routine handles the cases where the commodity already exists in the database (does nothing), or another entries has the same namespace and mnemonic (updates the existing entry).

Parameters
tableA pointer to the commodity table
commA pointer to the commodity to add.
Returns
The added commodity. Null on error.
Note
The commodity pointer passed to this function should not be used after its return, as it may have been destroyed. Use the return value which is guaranteed to be valid.

Definition at line 1756 of file gnc-commodity.cpp.

1758{
1759 gnc_commodity_namespace * nsp = nullptr;
1760 gnc_commodity *c;
1761 const char *ns_name;
1763 QofBook *book;
1764
1765 if (!table) return nullptr;
1766 if (!comm) return nullptr;
1767
1768 priv = GET_PRIVATE(comm);
1769
1770 ENTER ("(table=%p, comm=%p) %s %s", table, comm,
1771 (priv->mnemonic == nullptr ? "(null)" : priv->mnemonic),
1772 (priv->fullname == nullptr ? "(null)" : priv->fullname));
1773 ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1774 c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1775
1776 if (c)
1777 {
1778 if (c == comm)
1779 {
1780 LEAVE("already in table");
1781 return c;
1782 }
1783
1784 /* Backward compatibility support for currencies that have
1785 * recently changed. */
1786 if (priv->name_space->iso4217)
1787 {
1788 auto it = gnc_new_iso_codes.find (priv->mnemonic);
1789 if (it != gnc_new_iso_codes.end())
1790 gnc_commodity_set_mnemonic(comm, it->second.c_str());
1791 }
1792 gnc_commodity_copy (c, comm);
1793 gnc_commodity_destroy (comm);
1794 LEAVE("found at %p", c);
1795 return c;
1796 }
1797
1798 /* Prevent setting anything except template in namespace template. */
1799 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1800 g_strcmp0 (priv->mnemonic, "template") != 0)
1801 {
1802 PWARN("Converting commodity %s from namespace template to "
1803 "namespace User", priv->mnemonic);
1804 gnc_commodity_set_namespace (comm, "User");
1805 ns_name = "User";
1806 mark_commodity_dirty (comm);
1807 }
1808
1809 book = qof_instance_get_book (&comm->inst);
1810 nsp = gnc_commodity_table_add_namespace(table, ns_name, book);
1811
1812 PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1813 nsp->cm_table, nsp->name);
1814 g_hash_table_insert(nsp->cm_table,
1815 (gpointer)CACHE_INSERT(priv->mnemonic),
1816 (gpointer)comm);
1817 nsp->cm_list = g_list_append(nsp->cm_list, comm);
1818
1819 qof_event_gen (&comm->inst, QOF_EVENT_ADD, nullptr);
1820 LEAVE ("(table=%p, comm=%p)", table, comm);
1821 return comm;
1822}
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256

◆ gnc_commodity_table_lookup()

gnc_commodity * gnc_commodity_table_lookup ( const gnc_commodity_table *  table,
const char *  commodity_namespace,
const char *  mnemonic 
)

Definition at line 1652 of file gnc-commodity.cpp.

1654{
1655 gnc_commodity_namespace * nsp = nullptr;
1656
1657 if (!table || !name_space || !mnemonic) return nullptr;
1658
1659 nsp = gnc_commodity_table_find_namespace(table, name_space);
1660
1661 if (nsp)
1662 {
1663 /*
1664 * Backward compatibility support for currencies that have
1665 * recently changed.
1666 */
1667 if (nsp->iso4217)
1668 {
1669 auto it = gnc_new_iso_codes.find (mnemonic);
1670 if (it != gnc_new_iso_codes.end())
1671 mnemonic = it->second.c_str();
1672 }
1673 return GNC_COMMODITY(g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic));
1674 }
1675 else
1676 {
1677 return nullptr;
1678 }
1679}

◆ gnc_commodity_table_lookup_unique()

gnc_commodity * gnc_commodity_table_lookup_unique ( const gnc_commodity_table *  table,
const char *  unique_name 
)

Definition at line 1687 of file gnc-commodity.cpp.

1689{
1690 char *name_space;
1691 char *mnemonic;
1692 gnc_commodity *commodity;
1693
1694 if (!table || !unique_name) return nullptr;
1695
1696 name_space = g_strdup (unique_name);
1697 mnemonic = strstr (name_space, "::");
1698 if (!mnemonic)
1699 {
1700 g_free (name_space);
1701 return nullptr;
1702 }
1703
1704 *mnemonic = '\0';
1705 mnemonic += 2;
1706
1707 commodity = gnc_commodity_table_lookup (table, name_space, mnemonic);
1708
1709 g_free (name_space);
1710
1711 return commodity;
1712}

◆ gnc_commodity_table_new()

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.

You should probably be using gnc_commodity_table_get_table()

Definition at line 1572 of file gnc-commodity.cpp.

1573{
1574 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1575 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1576 retval->ns_list = nullptr;
1577 return retval;
1578}

◆ gnc_commodity_table_register()

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.

Definition at line 2428 of file gnc-commodity.cpp.

2429{
2430 if (!qof_object_register (&commodity_object_def))
2431 return FALSE;
2432 if (!qof_object_register (&namespace_object_def))
2433 return FALSE;
2434 return qof_object_register (&commodity_table_object_def);
2435}
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.

◆ gnc_commodity_table_remove()

void gnc_commodity_table_remove ( gnc_commodity_table *  table,
gnc_commodity *  comm 
)

Remove a commodity from the commodity table.

If the commodity to remove doesn't exist, nothing happens.

Parameters
tableA pointer to the commodity table
commA pointer to the commodity to remove.

Definition at line 1830 of file gnc-commodity.cpp.

1832{
1833 gnc_commodity_namespace * nsp;
1834 gnc_commodity *c;
1836 const char *ns_name;
1837
1838 if (!table) return;
1839 if (!comm) return;
1840
1841 priv = GET_PRIVATE(comm);
1842 ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1843 c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1844 if (c != comm) return;
1845
1846 qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, nullptr);
1847
1849 if (!nsp) return;
1850
1851 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1852 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1853 /* XXX minor mem leak, should remove the key as well */
1854}

◆ gnc_commodity_table_rename_namespace()

bool gnc_commodity_table_rename_namespace ( const gnc_commodity_table *  table,
const char *  namespace_name,
const char *  new_namespace_name 
)

This function renames a namespace.

Parameters
tableA pointer to the commodity table
namespace_nameThe name of the namespace to rename.
new_namespace_nameThe new name for the namespace.
Returns
Return true if rename successful.

Definition at line 2137 of file gnc-commodity.cpp.

2140{
2141 if (!table || !namespace_name || !new_namespace_name ||
2142 (g_strcmp0 (namespace_name, new_namespace_name) == 0) ||
2143 (g_strcmp0 (new_namespace_name, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
2144 (g_strcmp0 (new_namespace_name, _(GNC_COMMODITY_NS_ISO_GUI)) == 0) ||
2145 gnc_commodity_table_find_namespace (table, new_namespace_name))
2146 return false;
2147
2148 auto ns = gnc_commodity_table_find_namespace (table, namespace_name);
2149 if (!ns)
2150 return false;
2151
2152 ns->name = CACHE_INSERT(static_cast<const char*>(new_namespace_name));
2153
2154 g_hash_table_insert (table->ns_table,
2155 (gpointer) ns->name,
2156 (gpointer) ns);
2157
2158 g_hash_table_remove (table->ns_table,
2159 (gpointer) namespace_name);
2160
2161 CACHE_REMOVE(namespace_name);
2162
2163 qof_instance_set_dirty (&ns->inst);
2164 qof_event_gen (&ns->inst, QOF_EVENT_MODIFY, nullptr);
2165 return true;
2166}

◆ gnc_commodity_user_set_quote_flag()

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.

This flag indicates whether stock quotes should be retrieved for the specified stock.

It is necessary to have a separate function to distinguish when this setting is being modified by a user so that the auto-enabling/auto-disabling of currencies can be handled properly.

Parameters
cmA pointer to a commodity data structure.
flagTRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1258 of file gnc-commodity.cpp.

1259{
1261
1262 ENTER ("(cm=%p, flag=%d)", cm, flag);
1263
1264 if (!cm)
1265 {
1266 LEAVE("");
1267 return;
1268 }
1269
1270 priv = GET_PRIVATE(cm);
1271 gnc_commodity_begin_edit(cm);
1273 if (gnc_commodity_is_iso(cm))
1274 {
1275 /* For currencies, disable auto quote control if the quote flag is being
1276 * changed from its default value and enable it if the quote flag is being
1277 * reset to its default value. The defaults for the quote flag are
1278 * disabled if no accounts are using the currency, and true otherwise.
1279 * Thus enable auto quote control if flag is FALSE and there are not any
1280 * accounts using this currency OR flag is TRUE and there are accounts
1281 * using this currency; otherwise disable auto quote control */
1282 gnc_commodity_set_auto_quote_control_flag(cm,
1283 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1284 }
1285 gnc_commodity_commit_edit(cm);
1286 LEAVE("");
1287}

◆ gnc_monetary_list_add_monetary()

MonetaryList * gnc_monetary_list_add_monetary ( MonetaryList *  list,
gnc_monetary  mon 
)

Add a gnc_monetary to the list.

Definition at line 2443 of file gnc-commodity.cpp.

2444{
2445 MonetaryList *l = list, *tmp;
2446 for (tmp = list; tmp; tmp = tmp->next)
2447 {
2448 auto list_mon = static_cast<gnc_monetary*>(tmp->data);
2449 if (gnc_commodity_equiv(list_mon->commodity, add_mon.commodity))
2450 {
2451 list_mon->value = gnc_numeric_add(list_mon->value, add_mon.value,
2452 GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
2453 break;
2454 }
2455 }
2456
2457 /* See if we found an entry, and add one if not */
2458 if (tmp == nullptr)
2459 {
2460 auto new_mon = static_cast<gnc_monetary*>(g_new0(gnc_monetary, 1));
2461 *new_mon = add_mon;
2462 l = g_list_prepend(l, new_mon);
2463 }
2464
2465 return l;
2466}
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.

◆ gnc_monetary_list_delete_zeros()

MonetaryList * gnc_monetary_list_delete_zeros ( MonetaryList *  list)

Delete all the zero-value entries from a list.

Delete all the zero-value entries from a list.

Return list pointer will be a null pointer if there are no non-zero entries

Definition at line 2471 of file gnc-commodity.cpp.

2472{
2473 MonetaryList *node, *next;
2474 for (node = list; node; node = next)
2475 {
2476 auto mon = static_cast<gnc_monetary*>(node->data);
2477 next = node->next;
2478 if (gnc_numeric_zero_p(mon->value))
2479 {
2480 g_free(mon);
2481 list = g_list_delete_link(list, node);
2482 }
2483 }
2484 return list;
2485}
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.

◆ gnc_monetary_list_free()

void gnc_monetary_list_free ( MonetaryList *  list)

Free a monetary list and all the items it points to.

Free a monetary list and all the items it points to.

Definition at line 2489 of file gnc-commodity.cpp.

2490{
2491 MonetaryList *tmp;
2492 for (tmp = list; tmp; tmp = tmp->next)
2493 {
2494 g_free(tmp->data);
2495 }
2496
2497 g_list_free(list);
2498}

◆ gnc_quote_source_add_new()

gnc_quote_source * gnc_quote_source_add_new ( const char *  name,
gboolean  supported 
)

Create a new quote source.

This is called by the F::Q startup code or the XML parsing code to add new entries to the list of available quote sources.

Parameters
nameThe internal name for this new quote source.
supportedTRUE if this quote source is supported by F::Q. Should only be set by the F::Q startup routine.
Returns
A pointer to the newly created quote source.

Definition at line 319 of file gnc-commodity.cpp.

320{
321 DEBUG("Creating new source %s", (!source_name ? "(null)" : source_name));
322 /* This name can be changed if/when support for this price source is
323 * integrated into gnucash. */
324 /* This name is permanent and must be kept the same if/when support
325 * for this price source is integrated into gnucash (i.e. for a
326 * nice user name). */
327 return &new_quote_sources.emplace_back (supported, SOURCE_UNKNOWN, source_name, source_name);
328}

◆ gnc_quote_source_fq_installed()

gboolean gnc_quote_source_fq_installed ( void  )

This function indicates whether or not the Finance::Quote module is installed on a user's computer.

This includes any other related modules that gnucash need to process F::Q information.

Returns
TRUE is F::Q is installed properly.

Definition at line 267 of file gnc-commodity.cpp.

268{
269 return (!fq_version.empty());
270}

◆ gnc_quote_source_fq_version()

const char * gnc_quote_source_fq_version ( void  )

This function returns the version of the Finance::Quote module installed on a user's computer.

If no proper installation is found it will return NULL.

Returns
a version string or NULL

Definition at line 280 of file gnc-commodity.cpp.

281{
282 return fq_version.c_str();
283}

◆ gnc_quote_source_get_index()

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.

Parameters
sourceThe quote source in question.
Returns
The index of this quote source in its type.

Definition at line 390 of file gnc-commodity.cpp.

391{
392 if (!source)
393 {
394 PWARN ("bad source");
395 return 0;
396 }
397
398 auto& sources = get_quote_source_from_type (source->get_type());
399 auto is_source = [&source](const auto& findif_source)
400 { return &findif_source == source; };
401
402 auto iter = std::find_if (sources.begin(), sources.end(), is_source);
403 if (iter != sources.end())
404 return std::distance (sources.begin(), iter);
405
406 PWARN ("couldn't locate source");
407 return 0;
408}

◆ gnc_quote_source_get_internal_name()

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.

This is the name used by both gnucash and by Finance::Quote. E.G. "yahoo_australia" or "australia"

Parameters
sourceThe quote source in question.
Returns
The internal name.

Definition at line 438 of file gnc-commodity.cpp.

439{
440 ENTER("%p", source);
441 if (!source)
442 {
443 LEAVE("bad source");
444 return nullptr;
445 }
446 LEAVE("internal name %s", source->get_internal_name());
447 return source->get_internal_name();
448}

◆ gnc_quote_source_get_supported()

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.

Parameters
sourceThe quote source in question.
Returns
TRUE if the user's computer supports this quote source.

Definition at line 411 of file gnc-commodity.cpp.

412{
413 ENTER("%p", source);
414 if (!source)
415 {
416 LEAVE("bad source");
417 return FALSE;
418 }
419
420 LEAVE("%s supported", source && source->get_supported() ? "" : "not ");
421 return source->get_supported();
422}

◆ gnc_quote_source_get_type()

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.

(SINGLE, MULTI, UNKNOWN)

Parameters
sourceThe quote source in question.
Returns
The type of this quote source.

Definition at line 376 of file gnc-commodity.cpp.

377{
378 ENTER("%p", source);
379 if (!source)
380 {
381 LEAVE("bad source");
382 return SOURCE_SINGLE;
383 }
384
385 LEAVE("type is %d", source->get_type());
386 return source->get_type();
387}

◆ gnc_quote_source_get_user_name()

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.

E.G. "Yahoo Australia" or "Australia (Yahoo, ASX, ...)"

Parameters
sourceThe quote source in question.
Returns
The user friendly name.

Definition at line 425 of file gnc-commodity.cpp.

426{
427 ENTER("%p", source);
428 if (!source)
429 {
430 LEAVE("bad source");
431 return nullptr;
432 }
433 LEAVE("user name %s", source->get_user_name());
434 return source->get_user_name();
435}

◆ gnc_quote_source_lookup_by_internal()

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.

Parameters
internal_nameThe name of this quote source.
Returns
A pointer to the price quote source that has the specified internal name.

Definition at line 352 of file gnc-commodity.cpp.

353{
354 if (!name || !*name)
355 return nullptr;
356
357 for (const auto& [_, sources] : quote_sources_map)
358 {
359 auto source_it = std::find_if (sources.begin(), sources.end(),
360 [name] (const auto& qs)
361 { return (g_strcmp0(name, qs.get_internal_name()) == 0); });
362 if (source_it != sources.end())
363 return &(*source_it);
364 }
365
366 DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
367 return nullptr;
368}

◆ gnc_quote_source_lookup_by_ti()

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.

Parameters
typeThe type of this quote source.
indexThe index of this quote source within its type.
Returns
A pointer to the price quote source that has the specified type/index.

Definition at line 336 of file gnc-commodity.cpp.

337{
338 ENTER("type/index is %d/%d", type, index);
339 auto& sources = get_quote_source_from_type (type);
340 if ((size_t) index < sources.size())
341 {
342 auto it = std::next(sources.begin(), index);
343 LEAVE("found %s", it->get_user_name());
344 return &*it;
345 }
346
347 LEAVE("not found");
348 return nullptr;
349}

◆ gnc_quote_source_num_entries()

gint gnc_quote_source_num_entries ( QuoteSourceType  type)

Return the number of entries for a given type of quote source.

Parameters
typeThe quote source type whose count should be returned.
Returns
The number of entries for this type of quote source.

Definition at line 303 of file gnc-commodity.cpp.

304{
305 return get_quote_source_from_type(type).size();
306}

◆ gnc_quote_source_set_fq_installed()

void gnc_quote_source_set_fq_installed ( const char *  version_string,
const std::vector< std::string > &  sources_list 
)

Update gnucash internal tables based on what Finance::Quote sources are installed.

Sources that have been explicitly coded into gnucash are marked sensitive/insensitive based upon whether they are present. New sources that gnucash doesn't know about are added to its internal tables.

Parameters
sources_listA list of strings containing the source names as they are known to F::Q.

Definition at line 458 of file gnc-commodity.cpp.

460{
461 ENTER(" ");
462
463 if (sources_list.empty())
464 return;
465
466 if (version_string)
467 fq_version = version_string;
468 else
469 fq_version.clear();
470
471 for (const auto& source_name_str : sources_list)
472 {
473 auto source_name = source_name_str.c_str();
474 auto source = gnc_quote_source_lookup_by_internal(source_name);
475
476 if (source)
477 {
478 DEBUG("Found source %s: %s", source_name, source->get_user_name());
479 source->set_supported (true);
480 continue;
481 }
482
483 gnc_quote_source_add_new(source_name, TRUE);
484 }
485 LEAVE(" ");
486}