GnuCash  5.6-150-g038405b370+
gnucash-core-app.hpp
1 /*
2  * gnucash-core-app.hpp -- Core application object for gnucash binaries
3  *
4  * Copyright (C) 2020 Geert Janssens <geert@kobaltwit.be>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA gnu@gnu.org
22  */
23 
24 #ifndef GNUCASH_CORE_APP_HPP
25 #define GNUCASH_CORE_APP_HPP
26 
27 #ifdef __MINGW32__
28 // Avoid cmath missing function decl.
29 #undef _GLIBCXX_USE_C99_MATH_TR1
30 #if (__GNUC__ > 14) || (__GNUC__ == 14 && __GNUC_MINOR__ >= 1)
31 #undef _GLIBCXX_USE_C99_MATH_FUNCS
32 #endif
33 #endif
34 
35 #include <boost/optional.hpp>
36 #include <boost/program_options.hpp>
37 #include <string>
38 #include <vector>
39 
40 namespace Gnucash {
41 
42 namespace bpo = boost::program_options;
43 
44 class CoreApp
45 {
46 public:
47  CoreApp (const char* app_name);
48 
49  void parse_command_line (int argc, char **argv);
50  void start (void);
51 
52 protected:
53  std::string m_app_name;
54  std::string m_tagline;
55  boost::optional <std::string> m_log_to_filename;
56  boost::optional <std::string> m_file_to_load;
57 
58  bpo::options_description m_opt_desc_all;
59  std::unique_ptr<bpo::options_description> m_opt_desc_display;
60  bpo::variables_map m_opt_map;
61  bpo::positional_options_description m_pos_opt_desc;
62 
63 private:
64  void add_common_program_options (void);
65 
66  /* Command-line option variables */
67  bool m_show_help = false;
68  bool m_show_version = false;
69  bool m_show_paths = false;
70  bool m_debug = false;
71  bool m_extra = false;
72  boost::optional <std::string> m_gsettings_prefix;
73  std::vector <std::string> m_log_flags;
74 
75  char *sys_locale = nullptr;
76 };
77 
78 using MessageCb = std::function<void(const char*)>;
79 
80 void gnc_load_scm_config (MessageCb update_message);
81 }
82 #endif