cgma
|
00001 //- Class: SettingHandler 00002 //- Description: SettingHandler class - used for save and restore settings 00003 //- Owner: Wesley Gill 00004 //- Checked By: 00005 //- Version 00006 00007 #ifndef SETTINGHANDLER_HPP 00008 #define SETTINGHANDLER_HPP 00009 00010 #include "CubitString.hpp" 00011 #include "CubitDefines.h" 00012 #include "SettingHolder.hpp" 00013 #include <map> 00014 #include <vector> 00015 #include "CGMUtilConfigure.h" 00016 00017 00018 class CUBIT_UTIL_EXPORT SettingHandler 00019 { 00020 friend class SettingHolder; 00021 public: 00022 ~SettingHandler(); 00023 static SettingHandler* instance(); // make an instance of SettingHandler 00024 00025 static void delete_instance(); //deletes instance if it exists 00026 00027 void add_setting(const char* name, void (*setFn) (int), int (*getFn)()); 00028 void add_setting(const char* name, void (*setFn) (double), double (*getFn)()); 00029 void add_setting(const char* name, void (*setFn) (CubitBoolean), CubitBoolean (*getFn)()); 00030 void add_setting(const char* name, void (*setFn) (CubitString), CubitString (*getFn)()); 00031 00032 void get_settings_list( std::vector< std::pair<CubitString, SettingHolder*> > &list); 00033 00034 void print_settings(); // Output all settings using PRINT_INFO 00035 void save_settings(const char *filename); //Save settings into a file specified by the user 00036 void save_settings(); //Save settings into a default file 00037 void restore_settings(const char *filename); // Restore settings stored in a file 00038 00039 SettingHolder* get_setting_holder(CubitString name); 00040 inline SettingType get_setting_type(SettingHolder *setting); 00041 00042 inline int get_setting_int(SettingHolder *setting); 00043 inline double get_setting_double(SettingHolder *setting); 00044 inline CubitBoolean get_setting_bool(SettingHolder *setting); 00045 inline CubitString get_setting_string(SettingHolder *setting); 00046 inline int get_setting_debug_value(SettingHolder *setting); 00047 00048 inline void set_setting_int(SettingHolder *setting, int int_value); 00049 inline void set_setting_double(SettingHolder *setting, double double_value); 00050 inline void set_setting_bool(SettingHolder *setting, CubitBoolean bool_value); 00051 inline void set_setting_string(SettingHolder *setting, CubitString string_value); 00052 inline void set_setting_debug_value(SettingHolder *setting, int debug_value); 00053 00054 private: 00055 00056 void (*debug_set_function)(const int index, const int value); //Pointer to the debug set function 00057 int (*debug_get_function)(const int index); //Pointer to the debug set function 00058 00059 //Private constructor for singleton pattern 00060 SettingHandler(); 00061 00062 static SettingHandler* instance_; 00063 00064 //The debug flags are added to the map in the constuctor of the MessageFlag class. Although 00065 //the MessageFlag constructor should only be called once(Singleton) it is called multiple times. 00066 //This causes an error because you cannot add the same setting to the map more than once. This boolean 00067 //prevents this problem from occuring. 00068 CubitBoolean debug_flags_added; 00069 00070 std::map<CubitString, SettingHolder*> mSettingsList; 00071 00072 00073 }; 00074 00075 inline SettingType SettingHandler::get_setting_type(SettingHolder *setting) 00076 { return setting->setting_type; } 00077 00078 inline int SettingHandler::get_setting_int(SettingHolder *setting) 00079 { return (setting->get_int_function)(); } 00080 00081 inline double SettingHandler::get_setting_double(SettingHolder *setting) 00082 { return (setting->get_double_function)(); } 00083 00084 inline CubitBoolean SettingHandler::get_setting_bool(SettingHolder *setting) 00085 { return (setting->get_bool_function)(); } 00086 00087 inline CubitString SettingHandler::get_setting_string(SettingHolder *setting) 00088 { return (setting->get_string_function)(); } 00089 00090 //inline int SettingHandler::get_setting_debug_value(SettingHolder *setting) 00091 //{ return debug_get_function(setting->index); } 00092 00093 inline void SettingHandler::set_setting_int(SettingHolder *setting, int int_value) 00094 { (setting->set_int_function)(int_value); } 00095 00096 inline void SettingHandler::set_setting_double(SettingHolder *setting, double double_value) 00097 { (setting->set_double_function)(double_value); } 00098 00099 inline void SettingHandler::set_setting_bool(SettingHolder *setting, CubitBoolean bool_value) 00100 { (setting->set_bool_function)(bool_value); } 00101 00102 inline void SettingHandler::set_setting_string(SettingHolder *setting, CubitString string_value) 00103 { (setting->set_string_function)(string_value); } 00104 00105 //inline void SettingHandler::set_setting_debug_value(SettingHolder *setting, int debug_value) 00106 //{ (*debug_set_function)(setting->index, debug_value); } 00107 00108 #endif 00109 00110 00111 00112 00113 00114 00115