Commit 719d9e62b3ebd45a7f3aeb2b5cda8c040725f9bc

Authored by Jürgen Knödlseder
1 parent 5cfac246

Save application parameters only if they have been loaded

If an application is constructed from the command line arguments with the --help option the application parameters are not loaded, and the destructor saved before the empty parameter container to disk, which effectively emptied the parameter file. Now the desctructor only save the parameters if they have been loaded before.
include/GApplication.hpp
... ... @@ -121,15 +121,16 @@ protected:
121 121 void set_log_filename(void);
122 122  
123 123 // Protected data members
124   - std::string m_name; //!< Application name
125   - std::string m_version; //!< Application version
126   - std::string m_parfile; //!< Parameter filename
127   - std::string m_logfile; //!< Log filename
128   - std::vector<std::string> m_args; //!< Command line arguments
129   - std::time_t m_tstart; //!< Calendar start time of execution
130   - std::clock_t m_cstart; //!< Clock start time of execution
131   - GApplicationPars m_pars; //!< Application parameters
132   - bool m_need_help; //!< --help specified
  124 + std::string m_name; //!< Application name
  125 + std::string m_version; //!< Application version
  126 + std::string m_parfile; //!< Parameter filename
  127 + std::string m_logfile; //!< Log filename
  128 + std::vector<std::string> m_args; //!< Command line arguments
  129 + std::time_t m_tstart; //!< Calendar start time of execution
  130 + std::clock_t m_cstart; //!< Clock start time of execution
  131 + GApplicationPars m_pars; //!< Application parameters
  132 + bool m_pars_loaded; //!< Application parameters loaded
  133 + bool m_need_help; //!< --help specified
133 134 };
134 135  
135 136  
... ...
src/app/GApplication.cpp
... ... @@ -94,6 +94,9 @@ GApplication::GApplication(const std::string&amp; name, const std::string&amp; version)
94 94 // Initialise application parameters
95 95 m_pars.load(par_filename());
96 96  
  97 + // Signal that application parameters have been loaded
  98 + m_pars_loaded = true;
  99 +
97 100 // Set log filename and chattiness
98 101 set_log_filename();
99 102 set_log_chatter();
... ... @@ -158,6 +161,9 @@ GApplication::GApplication(const std::string&amp; name, const std::string&amp; version,
158 161 // Initialise application parameters
159 162 m_pars.load(par_filename(), m_args);
160 163  
  164 + // Signal that application parameters have been loaded
  165 + m_pars_loaded = true;
  166 +
161 167 // Set log filename and chattiness
162 168 set_log_filename();
163 169 set_log_chatter();
... ... @@ -266,6 +272,9 @@ void GApplication::clear(void)
266 272 // Initialise application parameters
267 273 m_pars.load(par_filename());
268 274  
  275 + // Signal that application parameters have been loaded
  276 + m_pars_loaded = true;
  277 +
269 278 // Set log filename and chattiness
270 279 set_log_filename();
271 280 set_log_chatter();
... ... @@ -847,7 +856,8 @@ void GApplication::init_members(void)
847 856 m_logfile.clear();
848 857 m_args.clear();
849 858 m_pars.clear();
850   - m_need_help = false;
  859 + m_pars_loaded = false;
  860 + m_need_help = false;
851 861  
852 862 // Save the execution calendar start time
853 863 std::time(&m_tstart);
... ... @@ -873,15 +883,16 @@ void GApplication::copy_members(const GApplication&amp; app)
873 883 log = app.log;
874 884  
875 885 // Copy protected attributes
876   - m_name = app.m_name;
877   - m_version = app.m_version;
878   - m_parfile = app.m_parfile;
879   - m_logfile = app.m_logfile;
880   - m_args = app.m_args;
881   - m_tstart = app.m_tstart;
882   - m_cstart = app.m_cstart;
883   - m_pars = app.m_pars;
884   - m_need_help = app.m_need_help;
  886 + m_name = app.m_name;
  887 + m_version = app.m_version;
  888 + m_parfile = app.m_parfile;
  889 + m_logfile = app.m_logfile;
  890 + m_args = app.m_args;
  891 + m_tstart = app.m_tstart;
  892 + m_cstart = app.m_cstart;
  893 + m_pars = app.m_pars;
  894 + m_pars_loaded = app.m_pars_loaded;
  895 + m_need_help = app.m_need_help;
885 896  
886 897 // Return
887 898 return;
... ... @@ -893,8 +904,10 @@ void GApplication::copy_members(const GApplication&amp; app)
893 904 ***************************************************************************/
894 905 void GApplication::free_members(void)
895 906 {
896   - // Save application parameters
897   - m_pars.save(par_filename());
  907 + // Save application parameters if they have been loaded
  908 + if (m_pars_loaded) {
  909 + m_pars.save(par_filename());
  910 + }
898 911  
899 912 // Close log file
900 913 logFileClose();
... ...