include/settings.h

Go to the documentation of this file.
00001 #ifndef _SETTINGS_H
00002 #define _SETTINGS_H
00003 
00004 
00005 extern "C"
00006 {
00007 #include <sys/types.h>
00008 #include <sys/stat.h>
00009 #include <unistd.h>
00010 }
00011 
00012 
00013 #include <SDL/SDL.h>
00014 #include <vector>
00015 #include <string>
00016 #include <iostream>
00017 #include <stdlib.h>
00018 
00019 #ifdef __APPLE__
00020        #include "config_mac.h"
00021 #endif
00022 
00023 #include "configfile.h"
00024 
00025 using namespace std;
00026 
00027 class VIDEOMODES
00028 {
00029 private:
00030         vector<SDL_Rect> modes;
00031         int sel;
00032         bool bpp32;
00033         bool fullscreen;
00034 
00035 public:
00036         VIDEOMODES()
00037         {
00038                 modes.clear();
00039                 sel = 0;
00040                 bpp32 = fullscreen = false;
00041         }
00042         ~VIDEOMODES() {}
00043 
00044         vector<SDL_Rect> GetModes() { return modes; }
00045         int GetSel() { return sel; }
00046         bool GetBpp32() { return bpp32; }
00047         bool GetFullscreen() { return fullscreen; }
00048 
00049         void SetModes( vector<SDL_Rect> new_modes ) { modes = new_modes; }
00050         void SetSel( int new_sel ) { sel = new_sel; }
00051         void SetBpp32( int new_bpp32 ) { bpp32 = new_bpp32; }
00052         void SetFullscreen( int new_fullscreen ) { fullscreen = new_fullscreen; }
00053 };
00054 
00055 
00056 template<class option_t>
00057 class OPTION
00058 {
00059 private:
00060         vector<string> option_list;
00061         vector<option_t> value_list;
00062         string name;
00063         string title;
00064         string desc;
00065         string cat;
00066         string true_value;
00067         string false_value;
00068         string accepts;
00069         float min_value;
00070         float max_value;
00071         option_t default_value;
00072 
00073 public:
00074         OPTION()
00075         {
00076                 name = title = desc = cat = true_value = false_value = accepts = "";
00077                 min_value = 0.0;
00078                 max_value = 1.0;
00079                 option_list.clear();
00080                 value_list.clear();
00081         }
00082 
00083         ~OPTION() {}
00084 
00085         vector<string> GetOptionList() { return option_list; }
00086         vector<option_t> GetValueList() { return value_list; }
00087         string GetName() { return name; }
00088         string GetTitle() { return title; }
00089         string GetDesc() { return desc; }
00090         string GetCat() { return cat; }
00091         string GetTrueValue() { return true_value; }
00092         string GetFalseValue() { return false_value; }
00093         string GetAccepts() { return accepts; }
00094         float GetMinValue() { return min_value; }
00095         float GetMaxValue() { return max_value; }
00096         option_t GetDefaultValue() { return default_value; }
00097         void SetOptionList( vector<string> new_option_list ) { option_list = new_option_list; }
00098         void SetValueList( vector<option_t> new_value_list ) { value_list = new_value_list; }
00099         void SetName( string new_name ) { name = new_name; }
00100         void SetTitle( string new_title ) { title = new_title; }
00101         void SetDesc( string new_desc ) { desc = new_desc; }
00102         void SetCat( string new_cat ) { cat = new_cat; }
00103         void SetTrueValue( string new_true_value ) { true_value = new_true_value; }
00104         void SetFalseValue( string new_false_value ) { false_value = new_false_value; }
00105         void SetAccepts( string new_accepts ) { accepts = new_accepts; }
00106         void SetMinValue( float new_min_value ) { min_value = new_min_value; }
00107         void SetMaxValue( float new_max_value ) { max_value = new_max_value; }
00108         void SetDefaultValue( option_t new_default_value ) { default_value = new_default_value; }
00109 };
00110 
00111 
00112 class SETTINGS
00113 {
00114 public:
00115         SETTINGS();
00116         ~SETTINGS();
00117 
00118         void SaveSettings(CONFIGFILE &c);
00119         void Init();
00120         void ParseOptionFile();
00121         void ParseDynamicOptions();
00122 
00123         bool Get( string var_name, float & out_var );
00124 //      bool Get( string var_name, float * out_var );
00125         bool Get( string var_name, int & out_var );
00126         bool Get( string var_name, string & out_var );
00127         bool Get( string var_name, bool & out_var );
00128 
00129         bool Set( string var_name, float in_var );
00130 //      bool Set( string var_name, float * in_var );
00131         bool Set( string var_name, int in_var );
00132         bool Set( string var_name, string in_var );
00133         bool Set( string var_name, bool in_var );
00134 
00135         OPTION<float> GetFloatOption( string cat, string name );
00136         OPTION<int> GetIntOption( string cat, string name );
00137         OPTION<bool> GetBoolOption( string cat, string name );
00138         OPTION<string> GetStringOption( string cat, string name );
00139 
00140         string GetSettingsDir();
00141         string GetHomeDir();
00142         string GetDataDir();
00143         string GetDataDir( string filename );
00144         string GetLocaleDir ();
00145         string GetGameVersion() { return VERSION; }
00146         string GetConfigFileVersion();
00147         string GetFullDataPath( string filename );
00148         void SetDataDir( string new_data_dir );
00149         void SetDefaultDataDir( string new_data_dir );
00150         vector<string> LoadCarPartsSettings();
00151         void SaveCarPartsSettings( vector<string> &p_list );
00152         string GetCarPartName( string part_path );
00153         string GetSkinPath();
00154 
00155 private:
00156         void ParseSettings(CONFIGFILE &c);
00157         bool FileExists(string path);
00158         //bool DirExists(string path);
00159         void CreateDir(string path);
00160         void FindHomeDir();
00161         void GetValidVideoModes();
00162 
00163         CONFIGFILE configfile;
00164         CONFIGFILE default_configfile;
00165         CONFIGFILE options_configfile;
00166         CONFIGFILE car_parts;
00167 
00168         VIDEOMODES valid_display_modes;
00169 
00170         vector<string> parts_list;
00171 /*
00172         vector<string> float_settings;
00173         vector<string> vec_settings;
00174         vector<string> int_settings;
00175         vector<string> bool_settings;
00176         vector<string> string_settings;
00177 */      vector< OPTION<float> > float_options;
00178         vector< OPTION<int> > int_options;
00179         vector< OPTION<bool> > bool_options;
00180         vector< OPTION<string> > string_options;
00181 
00182 
00183         string settings_path;
00184         string data_directory;
00185         string locale_directory;
00186         string settings_directory;
00187         string home_directory;
00188         string config_version;
00189 
00190         bool spew;
00191 };
00192 
00193 #endif /* _SETTINGS_H */

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6