Added new functions so you can find Sections from property names.
Moved a few implementations from the header to the cpp file Reordered some stuff so every thing is present when it's encountered (inside a class) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2179
This commit is contained in:
parent
77f14da8f0
commit
4295bf213b
2 changed files with 82 additions and 62 deletions
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: setup.h,v 1.18 2005-03-25 11:43:36 qbix79 Exp $ */
|
||||
/* $Id: setup.h,v 1.19 2005-04-19 15:29:59 qbix79 Exp $ */
|
||||
|
||||
#ifndef DOSBOX_SETUP_H
|
||||
#define DOSBOX_SETUP_H
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
CommandLine(int argc,char * argv[]);
|
||||
CommandLine(char * name,char * cmdline);
|
||||
const char * GetFileName(){ return file_name.c_str();}
|
||||
|
||||
|
||||
bool FindExist(char * name,bool remove=false);
|
||||
bool FindHex(char * name,int & value,bool remove=false);
|
||||
bool FindInt(char * name,int & value,bool remove=false);
|
||||
|
@ -122,25 +122,8 @@ public:
|
|||
void GetValuestring(char* str);
|
||||
};
|
||||
|
||||
class Section;
|
||||
class Module_base {
|
||||
/* Base for all hardware and software "devices" */
|
||||
protected:
|
||||
Section* m_configuration;
|
||||
public:
|
||||
Module_base(Section* configuration){m_configuration=configuration;};
|
||||
// Module_base(Section* configuration, SaveState* state) {};
|
||||
~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
|
||||
/* Returns true if succesful.*/
|
||||
virtual bool Change_Config(Section* newconfig) {return false;} ;
|
||||
};
|
||||
|
||||
|
||||
class Section {
|
||||
public:
|
||||
Section(const char* _sectionname) { sectionname=_sectionname; }
|
||||
virtual ~Section(){ExecuteDestroy(true); }
|
||||
|
||||
private:
|
||||
typedef void (*SectionFunction)(Section*);
|
||||
/* Wrapper class around startup and shutdown functions. the variable
|
||||
* canchange indicates it can be called on configuration changes */
|
||||
|
@ -152,36 +135,31 @@ public:
|
|||
canchange=_ch;
|
||||
}
|
||||
};
|
||||
void AddInitFunction(SectionFunction func,bool canchange=false) {initfunctions.push_back(Function_wrapper(func,canchange));}
|
||||
void AddDestroyFunction(SectionFunction func,bool canchange=false) {destroyfunctions.push_front(Function_wrapper(func,canchange));}
|
||||
void ExecuteInit(bool initall=true) {
|
||||
typedef std::list<Function_wrapper>::iterator func_it;
|
||||
for (func_it tel=initfunctions.begin(); tel!=initfunctions.end(); tel++){
|
||||
if(initall || (*tel).canchange) (*tel).function(this);
|
||||
}
|
||||
}
|
||||
void ExecuteDestroy(bool destroyall=true) {
|
||||
typedef std::list<Function_wrapper>::iterator func_it;
|
||||
for (func_it tel=destroyfunctions.begin(); tel!=destroyfunctions.end(); ){
|
||||
if(destroyall || (*tel).canchange) {
|
||||
(*tel).function(this);
|
||||
tel=destroyfunctions.erase(tel); //Remove destroyfunction once used
|
||||
} else tel++;
|
||||
}
|
||||
}
|
||||
std::list<Function_wrapper> initfunctions;
|
||||
std::list<Function_wrapper> destroyfunctions;
|
||||
std::string sectionname;
|
||||
public:
|
||||
Section(const char* _sectionname) { sectionname=_sectionname; }
|
||||
|
||||
void AddInitFunction(SectionFunction func,bool canchange=false) {initfunctions.push_back(Function_wrapper(func,canchange));}
|
||||
void AddDestroyFunction(SectionFunction func,bool canchange=false) {destroyfunctions.push_front(Function_wrapper(func,canchange));}
|
||||
void ExecuteInit(bool initall=true);
|
||||
void ExecuteDestroy(bool destroyall=true);
|
||||
const char* GetName() {return sectionname.c_str();}
|
||||
|
||||
virtual bool HasProperty(const char* _property)=0;
|
||||
virtual void HandleInputline(char * _line){}
|
||||
virtual void PrintData(FILE* outfile) {}
|
||||
std::string sectionname;
|
||||
virtual ~Section(){ExecuteDestroy(true); }
|
||||
};
|
||||
|
||||
|
||||
class Section_prop:public Section {
|
||||
public:
|
||||
private:
|
||||
std::list<Property*> properties;
|
||||
typedef std::list<Property*>::iterator it;
|
||||
public:
|
||||
Section_prop(const char* _sectionname):Section(_sectionname){}
|
||||
//ExecuteDestroy should be here else the destroy functions use destroyed properties
|
||||
~Section_prop(){ExecuteDestroy(true);}
|
||||
void Add_int(const char* _propname, int _value=0);
|
||||
void Add_string(const char* _propname, char* _value=NULL);
|
||||
void Add_bool(const char* _propname, bool _value=false);
|
||||
|
@ -195,9 +173,9 @@ class Section_prop:public Section {
|
|||
float Get_float(const char* _propname);
|
||||
void HandleInputline(char *gegevens);
|
||||
void PrintData(FILE* outfile);
|
||||
|
||||
std::list<Property*> properties;
|
||||
typedef std::list<Property*>::iterator it;
|
||||
virtual bool HasProperty(const char* _property);
|
||||
//ExecuteDestroy should be here else the destroy functions use destroyed properties
|
||||
virtual ~Section_prop(){ExecuteDestroy(true);}
|
||||
};
|
||||
|
||||
class Section_line: public Section{
|
||||
|
@ -206,20 +184,27 @@ public:
|
|||
~Section_line(){ExecuteDestroy(true);}
|
||||
void HandleInputline(char* gegevens);
|
||||
void PrintData(FILE* outfile);
|
||||
virtual bool HasProperty(const char* _property);
|
||||
std::string data;
|
||||
};
|
||||
|
||||
class Config{
|
||||
public:
|
||||
CommandLine * cmdline;
|
||||
private:
|
||||
std::list<Section*> sectionlist;
|
||||
typedef std::list<Section*>::iterator it;
|
||||
typedef std::list<Section*>::reverse_iterator reverse_it;
|
||||
void (* _start_function)(void);
|
||||
public:
|
||||
Config(CommandLine * cmd){ cmdline=cmd;}
|
||||
~Config();
|
||||
CommandLine * cmdline;
|
||||
|
||||
Section * AddSection(const char * _name,void (*_initfunction)(Section*));
|
||||
Section_line * AddSection_line(const char * _name,void (*_initfunction)(Section*));
|
||||
Section_prop * AddSection_prop(const char * _name,void (*_initfunction)(Section*),bool canchange=false);
|
||||
|
||||
Section* GetSection(const char* _sectionname);
|
||||
Section* GetSectionFromProperty(const char* prop);
|
||||
|
||||
void SetStartUp(void (*_function)(void));
|
||||
void Init();
|
||||
|
@ -228,12 +213,17 @@ public:
|
|||
void PrintConfig(const char* configfilename);
|
||||
bool ParseConfigFile(const char* configfilename);
|
||||
void ParseEnv(char ** envp);
|
||||
|
||||
std::list<Section*> sectionlist;
|
||||
typedef std::list<Section*>::iterator it;
|
||||
typedef std::list<Section*>::reverse_iterator reverse_it;
|
||||
private:
|
||||
void (* _start_function)(void);
|
||||
};
|
||||
|
||||
class Module_base {
|
||||
/* Base for all hardware and software "devices" */
|
||||
protected:
|
||||
Section* m_configuration;
|
||||
public:
|
||||
Module_base(Section* configuration){m_configuration=configuration;};
|
||||
// Module_base(Section* configuration, SaveState* state) {};
|
||||
~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
|
||||
/* Returns true if succesful.*/
|
||||
virtual bool Change_Config(Section* newconfig) {return false;} ;
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue