Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xml_preferences.hpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <ios>
3 #include <fstream>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <errno.h>
7 #include <string>
8 #include <map>
9 #include <sstream>
10 #include <set>
11 #include "tinyxml.h"
12 
13 #include <boost/algorithm/string/case_conv.hpp>
14 #include <boost/filesystem/operations.hpp>
15 #include <boost/filesystem/path.hpp>
16 #include <boost/progress.hpp>
17 #include <boost/regex.hpp>
18 #include <boost/function.hpp>
19 #ifndef __XMLPREFS__
20 #define __XMLPREFS__
21 
22 #define minprefversion = 103; //please increase this every time you modify the preferences function(s). added 11.04.21 dab
23 
24 //#include "runinfo.hpp"
25 #include "para_aux_funcs.hpp"
26 
27 
28 
29 
30 
31 
32 
33 
40 class setting {
41 
42 public:
43 
47  double doubvalue;
49  int intvalue;
51  std::string strvalue;
52 
54  boost::filesystem::path pathvalue;
55 
56 
57 
60  int type; //0 string 1 integer 2 double 3 for path
61 
62 
63 
65  setting() {
66  strvalue = "uninitialized_value";
67  type = -1;
68  intvalue = -10001;
69  doubvalue = -10002.1;};
71  setting(std::string newValue){
72  strvalue = newValue;
73  type = 0;};
75  setting(int newValue){
76  intvalue = newValue;
77  type = 1;};
79  setting(double newValue){
80  doubvalue = newValue;
81  type = 2;};
82 
83  setting(boost::filesystem::path newValue){
84  pathvalue = newValue;
85  type = 3;};
86 
88  std::string typestr(){
89  std::stringstream ss;
90  ss << type;
91  return ss.str();};
93  std::string value(){
94  std::string val;
95  std::stringstream ss;
96 
97  switch (type) {
98  case 0:
99  val = strvalue;
100  break;
101  case 1:
102  ss << intvalue;
103  val = ss.str();
104  break;
105  case 2:
106  ss << doubvalue;
107  val = ss.str();
108  break;
109  case 3:
110  val = pathvalue.string();
111  break;
112  default:
113  val = "badtype";
114  break;
115  };
116  return val;
117  };
118 };
119 
120 
121 /* Create a typedef with a string as the value type and the setting as the key type */
122 
123 typedef std::map<std::string, setting> settingmap;
124 
125 /* Create a typedef with a string as a value type and the settingmap (prior typedef) as the key type */
126 
127 typedef std::map<std::string, settingmap> categorymap;
128 
132 
133 public:
134 
135  /* An enum to store constant values. These could be constants as they don't change within the program */
137 
138  static const char * const possible_savefiles[NUMPOSSIBLE_SAVEFILES]; //set in the cpp file
139  static const char * const mandatory_savefiles[NUMMANDATORY_SAVEFILES];//set in the cpp file
140 
141 
143  int version;
145  categorymap settings; //a map of maps, holding settings in various categories.
146 
147 
149  void save(){
150  save(this->filename);
151  }; //save the xml file
155  void save(boost::filesystem::path save_filename);
166  int check_for_existing_prefs_auto(boost::filesystem::path & load_filename,
167  boost::filesystem::path pFilename);
168 
172  boost::filesystem::path default_name();
173 
177  boost::filesystem::path make_settings_name(boost::filesystem::path basename);
178 
182  void set_name(boost::filesystem::path newfilename){
183  this->filename = newfilename;
184  };
185 
189  void load_interactive();
190 
193  void load(boost::filesystem::path pFilename);
195  void load() {load(this->filename);};
196 
197 
200  ProgSettings(boost::filesystem::path tempfilename) {filename = tempfilename;};
203 
210  void setValue(std::string categoryName, std::string settingName, std::string settingValue){
211  settings[categoryName][settingName] = setting(settingValue);}
217  void setValue(std::string categoryName, std::string settingName, double settingValue){
218  settings[categoryName][settingName] = setting(settingValue);}
225  void setValue(std::string categoryName, std::string settingName, int settingValue){
226  settings[categoryName][settingName] = setting(settingValue);}
227 
228 
229  void setValue(std::string categoryName, std::string settingName, boost::filesystem::path settingValue){
230  settings[categoryName][settingName] = setting(settingValue);}
239  // main program settings, parallelism
241  void GetParallel();
243  void GetArchitecture();
245  void GetSaveProgress();
247  void GetNewFileThresh();
251  void GetStifle();
253  void GetMachineFile();
255  void GetNumProcs();
257  void GetNumFilesTime();
259  void GetDeleteTmpFiles();
261  void GetWriteMCFileUserDef();
263  void GetStartFileName();
265  void GetDataFolderMethod();
268 
269  // path failure prefs
271  void GetRandomMethod();
275  void GetNumIterations();
277  void GetBufferSize();
278 
279 
280  // which files to save
282  void SetSaveFiles();
283 
284 // /** \param datafilename - Determine if datafilename is to be saved or not. */
285 // void GetIndividualFileSave(std::string datafilename);
286 
288  bool CheckPrevSetFiles();
289 
290  // make sure have the step2, bertini program
292  void GetProgramLocationManual(std::string program_name, std::string category_name, std::string setting_name);
294  void FindProgram(std::string program_name, std::string category_name, std::string setting_name);
295 
296  // menu functions
298  void MainMenu();
299 
301  void BertiniMenu();
303  void StepOneMenu();
305  void StepTwoMenu();
307  void PathFailureMenu();
309  void SaveFilesMenu();
311  void ParallelismMenu();
313  void GeneralMenu();
314 
316  void SetSearchMode();
317 
319  void SetSearchIterations();
320 
322  void SetSearchSubmode();
323 
325  void SetSearchPosRealThresh();
326 
327 
329  void SetSearchDesiredNumber();
330 
331 
333  void SearchMenu();
334 
335 
337  void SolverModeMenu();
339  void SystemMenu();
341  void FileMenu();
342 
346  void MetaSettingsMenu();
347  //set defaults
349  void default_main_values();
358 
359  //display all settings in a given category
362  void DisplayCurrentSettings(std::string category_name);
363 
364  //change, add, and remove settings from a category
367  void ChangeSetting(std::string category_name);
370  void AddSetting(std::string category_name);
373  void RemoveSetting(std::string category_name);
374 
376  std::string WriteConfigStepOne();
378  std::string WriteConfigStepTwo();
380  std::string WriteConfigFail();
381 
387  void tightentolerances();
388 
392  void SetStandardStep2();
393 
394 private:
396  boost::filesystem::path filename;
398  bool setRequiredValues();
404  bool haveSetting(std::string category_name, std::string setting_name){
405  return settings[category_name].find(setting_name) != settings[category_name].end();};
406 
407 
408  void RequiredSettingsSwitcharoo( int settingcase );//integers indicating switch cases found in .cpp file
409 
410 
415  int SaveCategoryToXml(std::string catname, settingmap curr_settings , TiXmlElement* root);
416 
420  int ReadCategoryFromXml(std::string catname, TiXmlHandle hroot);
421 
422 
423 protected:
424 
425 
426 };
427 
428 #endif
429 
void GetProgramLocationManual(std::string program_name, std::string category_name, std::string setting_name)
void GetTightenTolerancesPathFailure()
setting(std::string newValue)
std::string WriteConfigFail()
void setValue(std::string categoryName, std::string settingName, boost::filesystem::path settingValue)
static const char *const possible_savefiles[NUMPOSSIBLE_SAVEFILES]
void ChangeSetting(std::string category_name)
bool CheckPrevSetFiles()
void DisplayCurrentSettings(std::string category_name)
A class that stores the information of a setting as used in an xml file.
void FindProgram(std::string program_name, std::string category_name, std::string setting_name)
void RequiredSettingsSwitcharoo(int settingcase)
void default_main_values()
void set_name(boost::filesystem::path newfilename)
int check_for_existing_prefs_auto(boost::filesystem::path &load_filename, boost::filesystem::path pFilename)
void SetSearchIterations()
ProgSettings(boost::filesystem::path tempfilename)
void setValue(std::string categoryName, std::string settingName, int settingValue)
void set_path_failure_settings_from_steptwo()
void GetDataFolderMethod()
void SetSearchDesiredNumber()
bool setRequiredValues()
void default_path_failure_settings()
boost::filesystem::path pathvalue
void GetWriteMCFileUserDef()
std::string value()
void default_basic_bertini_values_steptwo()
bool haveSetting(std::string category_name, std::string setting_name)
void tightentolerances()
double doubvalue
std::map< std::string, settingmap > categorymap
void RemoveSetting(std::string category_name)
int SaveCategoryToXml(std::string catname, settingmap curr_settings, TiXmlElement *root)
boost::filesystem::path filename
boost::filesystem::path default_name()
static const char *const mandatory_savefiles[NUMMANDATORY_SAVEFILES]
setting(double newValue)
void set_path_failure_settings()
std::string WriteConfigStepOne()
int ReadCategoryFromXml(std::string catname, TiXmlHandle hroot)
void AddSetting(std::string category_name)
setting()
Default constructor for setting class.
categorymap settings
A class that stores the general program settings of Paramotopy.
boost::filesystem::path make_settings_name(boost::filesystem::path basename)
std::string strvalue
void default_basic_bertini_values_pathfailure()
void default_basic_bertini_values_stepone()
void setValue(std::string categoryName, std::string settingName, double settingValue)
void ManagePathFailureBertini()
setting(boost::filesystem::path newValue)
void GeneralMenu()
std::map< std::string, setting > settingmap
setting(int newValue)
std::string WriteConfigStepTwo()
void GetTemporaryFileLocation()
void SetSearchPosRealThresh()
std::string typestr()
void GetNewRandomAtNewFolder()
void setValue(std::string categoryName, std::string settingName, std::string settingValue)