GnuCash  5.6-150-g038405b370+
gnc-optiondb.hpp
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-optiondb.hpp -- Collection of GncOption objects *
3  * Copyright (C) 2019 John Ralls <jralls@ceridwen.us> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21  * *
22 \********************************************************************/
33 #ifndef GNC_OPTIONDB_HPP_
34 #define GNC_OPTIONDB_HPP_
35 
36 #include <string>
37 #include <functional>
38 #include <exception>
39 #include <optional>
40 #include <iostream>
41 
42 #include <config.h>
43 #include "Account.h"
44 #include "gnc-budget.h"
45 #include "gnc-commodity.h"
46 #include "gncInvoice.h"
47 #include "gncTaxTable.h"
48 #include "gnc-option.hpp"
49 #include "gnc-datetime.hpp"
50 
51 
52 class GncOptionDB;
53 using GncOptionDBPtr = std::unique_ptr<GncOptionDB>;
54 using GncOptionAccountList = std::vector<GncGUID>;
55 
56 using GncOptionAccountTypeList = std::vector<GNCAccountType>;
57 using GncMultichoiceOptionEntry = std::tuple<const std::string,
58  const std::string,
59  GncOptionMultichoiceKeyType>;
60 using GncMultichoiceOptionChoices = std::vector<GncMultichoiceOptionEntry>;
61 
77 GncOptionAccountList
78 gnc_account_list_from_types(QofBook *book,
79  const GncOptionAccountTypeList& types);
80 
91 void gnc_register_string_option(GncOptionDB* db, const char* section,
92  const char* name, const char* key,
93  const char* doc_string, std::string value);
94 
98 inline void gnc_register_string_option(const GncOptionDBPtr& db,
99  const char* section, const char* name,
100  const char* key, const char* doc_string,
101  std::string value)
102 {
103  gnc_register_string_option(db.get(), section, name, key,
104  doc_string, value);
105 }
106 
117 void gnc_register_text_option(GncOptionDB* db, const char* section,
118  const char* name, const char* key,
119  const char* doc_string, std::string value);
120 
124 inline void gnc_register_text_option(const GncOptionDBPtr& db,
125  const char* section,
126  const char* name, const char* key,
127  const char* doc_string, std::string value)
128 {
129  gnc_register_text_option(db.get(), section, name, key, doc_string, value);
130 }
131 
142 void gnc_register_font_option(GncOptionDB* db, const char* section,
143  const char* name, const char* key,
144  const char* doc_string, std::string value);
145 
149 inline void gnc_register_font_option(const GncOptionDBPtr& db,
150  const char* section, const char* name,
151  const char* key, const char* doc_string,
152  std::string value)
153 {
154  gnc_register_font_option(db.get(), section, name, key, doc_string, value);
155 }
156 
167 void gnc_register_budget_option(GncOptionDB* db, const char* section,
168  const char* name, const char* key,
169  const char* doc_string, GncBudget* value);
170 
174 inline void gnc_register_budget_option(const GncOptionDBPtr& db,
175  const char* section, const char* name,
176  const char* key, const char* doc_string,
177  GncBudget* value)
178 {
179  gnc_register_budget_option(db.get(), section, name, key, doc_string, value);
180 }
181 
193  const char* section, const char* name,
194  const char* key, const char* doc_string,
195  gnc_commodity* value);
196 
200 inline void gnc_register_commodity_option(const GncOptionDBPtr& db,
201  const char* section,
202  const char* name, const char* key,
203  const char* doc_string,
204  gnc_commodity* value)
205 {
206  gnc_register_commodity_option(db.get(), section, name, key,
207  doc_string, value);
208 }
215  const char* section, const char* name,
216  const char* key, const char* doc_string,
217  const char* value);
218 
222 inline void gnc_register_commodity_option(const GncOptionDBPtr& db,
223  const char* section,
224  const char* name, const char* key,
225  const char* doc_string,
226  const char* value)
227 {
228  gnc_register_commodity_option(db.get(), section, name, key,
229  doc_string, value);
230 }
231 
243  const char* section, const char* name,
244  const char* key, const char* doc_string,
245  bool value);
246 
250 inline void gnc_register_simple_boolean_option(const GncOptionDBPtr& db,
251  const char* section,
252  const char* name,
253  const char* key,
254  const char* doc_string,
255  bool value)
256 {
257  gnc_register_simple_boolean_option(db.get(), section, name, key,
258  doc_string, value);
259 }
260 
271 void gnc_register_pixmap_option(GncOptionDB* db, const char* section,
272  const char* name, const char* key,
273  const char* doc_string, std::string value);
274 
278 inline void gnc_register_pixmap_option(GncOptionDBPtr& db, const char* section,
279  const char* name, const char* key,
280  const char* doc_string,
281  std::string value)
282 {
283  gnc_register_pixmap_option(db.get(), section, name, key, doc_string, value);
284 }
285 
298  const char* section,
299  const char* name, const char* key,
300  const char* doc_string,
301  const GncOptionAccountList& value,
302  GncOptionAccountTypeList&& allowed);
303 
307 inline void gnc_register_account_list_limited_option(GncOptionDBPtr& db,
308  const char* section,
309  const char* name, const char* key,
310  const char* doc_string,
311  const GncOptionAccountList& value,
312  GncOptionAccountTypeList&& allowed)
313 {
314  gnc_register_account_list_limited_option(db.get(), section, name, key,
315  doc_string, value,
316  std::move(allowed));
317 }
318 
330  const char* section,
331  const char* name, const char* key,
332  const char* doc_string,
333  const GncOptionAccountList& value);
334 
338 inline void gnc_register_account_list_option(GncOptionDBPtr& db,
339  const char* section,
340  const char* name, const char* key,
341  const char* doc_string,
342  const GncOptionAccountList& value)
343 {
344  gnc_register_account_list_option(db.get(), section, name, key,
345  doc_string, value);
346 }
347 
360  const char* section,
361  const char* name, const char* key,
362  const char* doc_string,
363  const Account* value,
364  GncOptionAccountTypeList&& allowed);
365 
369 inline void gnc_register_account_sel_limited_option(GncOptionDBPtr& db,
370  const char* section,
371  const char* name, const char* key,
372  const char* doc_string,
373  const Account* value,
374  GncOptionAccountTypeList&& allowed)
375 {
376  gnc_register_account_sel_limited_option(db.get(), section, name, key,
377  doc_string, value,
378  std::move(allowed));
379 }
380 
392  const char* section, const char* name,
393  const char* key, const char* doc_string,
394  const char* default_val,
395  GncMultichoiceOptionChoices&& value);
396 
400 inline void gnc_register_multichoice_option(GncOptionDBPtr& db,
401  const char* section, const char* name,
402  const char* key, const char* doc_string,
403  const char* default_val,
404  GncMultichoiceOptionChoices&& value)
405 {
406  gnc_register_multichoice_option(db.get(), section, name,
407  key, doc_string, default_val,
408  std::move(value));
409 }
410 
422 void gnc_register_list_option(GncOptionDB* db, const char* section,
423  const char* name, const char* key,
424  const char* doc_string, const char* value,
425  GncMultichoiceOptionChoices&& list);
426 
430 inline void gnc_register_list_option(GncOptionDBPtr& db, const char* section,
431  const char* name, const char* key,
432  const char* doc_string, const char* value,
433  GncMultichoiceOptionChoices&& list)
434 {
435  gnc_register_list_option(db.get(), section, name, key, doc_string,
436  value, std::move(list));
437 }
438 
454 template <typename ValueType>
456  const char* section, const char* name,
457  const char* key, const char* doc_string,
458  ValueType value, ValueType min,
459  ValueType max, ValueType step);
460 
464 template <typename ValueType>
465 void gnc_register_number_range_option(GncOptionDBPtr& db,
466  const char* section, const char* name,
467  const char* key, const char* doc_string,
468  ValueType value, ValueType min,
469  ValueType max, ValueType step)
470 {
471  gnc_register_number_range_option<ValueType>(db.get(), section, name,
472  key, doc_string, value,
473  min, max, step);
474 }
475 
487  const char* section, const char* name,
488  const char* key,
489  const char* doc_string,
490  int value);
491 
493  const char* section, const char* name,
494  const char* key,
495  const char* doc_string,
496  float value)
497 {
498  gnc_register_number_plot_size_option(db, section, name, key,
499  doc_string, static_cast<int>(value));
500 }
501 
502 
506 inline void gnc_register_number_plot_size_option(const GncOptionDBPtr& db,
507  const char* section,
508  const char* name,
509  const char* key,
510  const char* doc_string,
511  int value)
512 {
513  gnc_register_number_plot_size_option(db.get(), section, name, key,
514  doc_string, value);
515 }
516 
517 inline void gnc_register_number_plot_size_option(const GncOptionDBPtr& db,
518  const char* section,
519  const char* name,
520  const char* key,
521  const char* doc_string,
522  float value)
523 {
524  gnc_register_number_plot_size_option(db.get(), section, name, key,
525  doc_string, static_cast<int>(value));
526 }
527 
538 void gnc_register_query_option(GncOptionDB* db, const char* section,
539  const char* name, const QofQuery* value);
540 
544 inline void gnc_register_query_option(GncOptionDBPtr& db, const char* section,
545  const char* name,
546  const QofQuery* value)
547 {
548  gnc_register_query_option(db.get(), section, name, value);
549 }
550 
562 void gnc_register_owner_option(GncOptionDB* db, const char* section,
563  const char* name, const char* key,
564  const char* doc_string, const GncOwner* value,
565  GncOwnerType type);
566 
570 inline void gnc_register_owner_option(GncOptionDBPtr& db, const char* section,
571  const char* name, const char* key,
572  const char* doc_string,
573  const GncOwner* value,
574  GncOwnerType type)
575 {
576  gnc_register_owner_option(db.get(), section, name, key, doc_string, value, type);
577 }
578 
589 void gnc_register_color_option(GncOptionDB* db, const char* section,
590  const char* name, const char* key,
591  const char* doc_string, std::string value);
592 
596 inline void gnc_register_color_option(GncOptionDBPtr& db, const char* section,
597  const char* name, const char* key,
598  const char* doc_string,
599  std::string value)
600 {
601  gnc_register_color_option(db.get(), section, name, key, doc_string, value);
602 }
603 
604 void gnc_register_internal_option(GncOptionDBPtr& db,
605  const char* section, const char* name,
606  const std::string& value);
607 
608 void gnc_register_internal_option(GncOptionDBPtr& db,
609  const char* section, const char* name,
610  bool value);
611 
612 void gnc_register_report_placement_option(GncOptionDBPtr& db,
613  const char* section, const char* name);
614 
625 void gnc_register_currency_option(GncOptionDB* db, const char* section,
626  const char* name, const char* key,
627  const char* doc_string, gnc_commodity* value);
628 
632 inline void gnc_register_currency_option(const GncOptionDBPtr& db,
633  const char* section,
634  const char* name, const char* key,
635  const char* doc_string,
636  gnc_commodity* value)
637 {
638  gnc_register_currency_option(db.get(), section, name, key,
639  doc_string, value);
640 }
641 
647  const char* section,
648  const char* name, const char* key,
649  const char* doc_string,
650  const char* value);
651 
652 inline void gnc_register_currency_option(const GncOptionDBPtr& db,
653  const char* section,
654  const char* name, const char* key,
655  const char* doc_string,
656  const char* value)
657 {
658  gnc_register_currency_option(db.get(), section, name, key,
659  doc_string, value);
660 }
661 
672 void gnc_register_invoice_option(GncOptionDB* db, const char* section,
673  const char* name, const char* key,
674  const char* doc_string, GncInvoice* value);
675 
679 inline void gnc_register_invoice_option(const GncOptionDBPtr& db,
680  const char* section,
681  const char* name, const char* key,
682  const char* doc_string,
683  GncInvoice* value)
684 {
685  gnc_register_invoice_option(db.get(), section, name, key,
686  doc_string, value);
687 }
688 
699 void gnc_register_taxtable_option(GncOptionDB* db, const char* section,
700  const char* name, const char* key,
701  const char* doc_string, GncTaxTable* value);
702 
706 inline void gnc_register_taxtable_option(const GncOptionDBPtr& db,
707  const char* section, const char* name,
708  const char* key,
709  const char* doc_string,
710  GncTaxTable* value)
711 {
712  gnc_register_taxtable_option(db.get(), section, name, key,
713  doc_string, value);
714 }
715 
725 void gnc_register_invoice_print_report_option(GncOptionDB* db, const char* section,
726  const char* name, const char* key,
727  const char* doc_string, std::string value);
728 
732 inline void gnc_register_invoice_print_report_option(const GncOptionDBPtr& db,
733  const char* section, const char* name,
734  const char* key, const char* doc_string,
735  std::string value)
736 {
737  gnc_register_invoice_print_report_option(db.get(), section, name, key,
738  doc_string, value);
739 }
740 
751 void gnc_register_counter_option(GncOptionDB* db, const char* section,
752  const char* name, const char* key,
753  const char* doc_string, int value);
754 
758 inline void gnc_register_counter_option(const GncOptionDBPtr& db,
759  const char* section, const char* name,
760  const char* key, const char* doc_string,
761  double value)
762 {
763  gnc_register_counter_option(db.get(), section, name, key,
764  doc_string, value);
765 }
766 
778  const char* section, const char* name,
779  const char* key, const char* doc_string,
780  std::string value);
781 
785 inline void gnc_register_counter_format_option(GncOptionDBPtr& db,
786  const char* section,
787  const char* name,
788  const char* key,
789  const char* doc_string,
790  std::string value)
791 {
792  gnc_register_counter_format_option(db.get(), section, name, key,
793  doc_string, value);
794 }
795 
807  const char* section, const char* name,
808  const char* key, const char* doc_string,
809  GncOptionDateFormat&& value);
810 
814 inline void gnc_register_dateformat_option(GncOptionDBPtr& db,
815  const char* section,
816  const char* name, const char* key,
817  const char* doc_string,
818  GncOptionDateFormat&& value)
819 {
820  gnc_register_dateformat_option(db.get(), section, name, key,
821  doc_string, std::move(value));
822 }
823 
824 enum RelativeDateUI : uint8_t
825 {
826  ABSOLUTE,
827  RELATIVE,
828  BOTH
829 };
830 
842 void gnc_register_date_option(GncOptionDB* db, const char* section,
843  const char* name, const char* key,
844  const char* doc_string,
845  RelativeDatePeriod period =
846  RelativeDatePeriod::TODAY,
847  RelativeDateUI ui = RelativeDateUI::BOTH);
848 
852 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
853  const char* name, const char* key,
854  const char* doc_string,
855  RelativeDatePeriod period =
856  RelativeDatePeriod::TODAY,
857  RelativeDateUI ui = RelativeDateUI::BOTH)
858 {
859  gnc_register_date_option(db.get(), section, name, key, doc_string,
860  period, ui);
861 }
862 
874 void gnc_register_date_option(GncOptionDB* db, const char* section,
875  const char* name, const char* key,
876  const char* doc_string, time64 time,
877  RelativeDateUI ui = RelativeDateUI::BOTH);
878 
882 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
883  const char* name, const char* key,
884  const char* doc_string, time64 time,
885  RelativeDateUI ui = RelativeDateUI::BOTH)
886 {
887  gnc_register_date_option(db.get(), section, name, key, doc_string,
888  time, ui);
889 }
890 
902 void gnc_register_date_option(GncOptionDB* db, const char* section,
903  const char* name, const char* key,
904  const char* doc_string,
905  RelativeDatePeriodVec& period_set,
906  bool both = true);
907 
911 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
912  const char* name, const char* key,
913  const char* doc_string,
914  RelativeDatePeriodVec& period_set,
915  bool both = true)
916 {
917  gnc_register_date_option(db.get(), section, name, key, doc_string,
918  period_set, both);
919 }
920 
932  const char* section,
933  const char* name, const char* key,
934  const char* doc_string, bool both = true);
935 
939 inline void gnc_register_start_date_option(GncOptionDBPtr& db,
940  const char* section,
941  const char* name, const char* key,
942  const char* doc_string, bool both = true)
943 {
944  gnc_register_start_date_option(db.get(), section, name, key, doc_string,
945  both);
946 }
947 
958 void gnc_register_end_date_option(GncOptionDB* db, const char* section,
959  const char* name, const char* key,
960  const char* doc_string, bool both = true);
961 
965 inline void gnc_register_end_date_option(GncOptionDBPtr& db, const char* section,
966  const char* name, const char* key,
967  const char* doc_string, bool both = true)
968 {
969  gnc_register_end_date_option(db.get(), section, name, key, doc_string,
970  both);
971 }
972 
973 
974 
975 #endif //GNC_OPTIONDB_HPP_
Holds all of the options for a book, report, or stylesheet, organized by GncOptionSections.
void gnc_register_simple_boolean_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool value)
Create a new simple boolean option and register it in the options database.
void gnc_register_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, RelativeDatePeriod period=RelativeDatePeriod::TODAY, RelativeDateUI ui=RelativeDateUI::BOTH)
Create a new date option and register it in the options database.
void gnc_register_invoice_print_report_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new print report option and register it in the options database.
STRUCTS.
GnuCash Budgets.
void gnc_register_number_range_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, ValueType value, ValueType min, ValueType max, ValueType step)
Create a new number range option and register it in the options database.
void gnc_register_counter_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, int value)
Create a new counter option and register it in the options database.
void gnc_register_multichoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *default_val, GncMultichoiceOptionChoices &&value)
Create a new multichoice option and register it in the options database.
C++ Public interface for individual options.
void gnc_register_query_option(GncOptionDB *db, const char *section, const char *name, const QofQuery *value)
Create a new QofQuery option and register it in the options database.
void gnc_register_number_plot_size_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, int value)
Create a new plot-size option and register it in the options database.
Account handling public routines.
void gnc_register_account_sel_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const Account *value, GncOptionAccountTypeList &&allowed)
Create a limited account selection option and register it in the options database.
void gnc_register_start_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both=true)
Create a new start-date option and register it in the options database.
void gnc_register_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *value, GncMultichoiceOptionChoices &&list)
Create a new list option and register it in the options database.
RelativeDatePeriod
Reporting periods relative to the current date.
void gnc_register_color_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new color option and register it in the options database.
void gnc_register_string_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new string option and register it in the options database.
void gnc_register_account_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value)
Create a new account list option and register it in the options database.
void gnc_register_commodity_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new commodity option and register it in the options database.
Tax Table programming interface.
void gnc_register_end_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both=true)
Create a new end-date option and register it in the options database.
Business Invoice Interface.
void gnc_register_taxtable_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncTaxTable *value)
Create a new taxtable option and register it in the options database.
void gnc_register_font_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new font option and register it in the options database.
void gnc_register_pixmap_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new pixmap option and register it in the options database.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
void gnc_register_budget_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncBudget *value)
Create a new budget option and register it in the options database.
void gnc_register_currency_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new currency option and register it in the options database.
void gnc_register_dateformat_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncOptionDateFormat &&value)
Create a new date format option and register it in the options database.
A Query.
Definition: qofquery.cpp:74
void gnc_register_invoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncInvoice *value)
Create a new invoice option and register it in the options database.
GncOptionAccountList gnc_account_list_from_types(QofBook *book, const GncOptionAccountTypeList &types)
Extract a list of accounts in the book having one of the GNCAccountTypes in types.
void gnc_register_counter_format_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new counter format option and register it in the options database.
void gnc_register_text_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new text option and register it in the options database.
Commodity handling public routines.
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following Code that handles refcount, parent, child, invisible and children is identical to that in ::GncBillTerm
void gnc_register_owner_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOwner *value, GncOwnerType type)
Create a new GncOwner option and register it in the options database.
void gnc_register_account_list_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value, GncOptionAccountTypeList &&allowed)
Create a new limited account list option and register it in the options database. ...