1
0
Fork 0

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:
Peter Veenstra 2005-04-19 15:30:03 +00:00
parent 77f14da8f0
commit 4295bf213b
2 changed files with 82 additions and 62 deletions

View file

@ -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

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.cpp,v 1.25 2005-03-25 12:00:52 qbix79 Exp $ */
/* $Id: setup.cpp,v 1.26 2005-04-19 15:30:03 qbix79 Exp $ */
#include "dosbox.h"
#include "cross.h"
@ -168,7 +168,15 @@ void Section_prop::PrintData(FILE* outfile){
}
}
bool Section_prop::HasProperty(const char* _property) {
for(it tel=properties.begin();tel!=properties.end();tel++){
if(!strcasecmp((*tel)->propname.c_str(),_property)){
return true;
}
}
return false;
}
void Section_line::HandleInputline(char* line){
data+=line;
data+="\n";
@ -178,13 +186,17 @@ void Section_line::PrintData(FILE* outfile) {
fprintf(outfile,"%s",data.c_str());
}
bool Section_line::HasProperty(const char* _property) {
return false;
}
void Config::PrintConfig(const char* configfilename){
char temp[50];char helpline[256];
FILE* outfile=fopen(configfilename,"w+t");
if(outfile==NULL) return;
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
/* Print out the Section header */
strcpy(temp,(*tel)->sectionname.c_str());
strcpy(temp,(*tel)->GetName());
lowcase(temp);
fprintf(outfile,"[%s]\n",temp);
upcase(temp);
@ -207,12 +219,6 @@ void Config::PrintConfig(const char* configfilename){
fclose(outfile);
}
Section* Config::AddSection(const char* _name,void (*_initfunction)(Section*)){
Section* blah = new Section(_name);
blah->AddInitFunction(_initfunction);
sectionlist.push_back(blah);
return blah;
}
Section_prop* Config::AddSection_prop(const char* _name,void (*_initfunction)(Section*),bool canchange){
Section_prop* blah = new Section_prop(_name);
@ -235,6 +241,23 @@ void Config::Init(){
}
}
void Section::ExecuteInit(bool initall) {
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 Section::ExecuteDestroy(bool destroyall) {
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++;
}
}
Config::~Config() {
reverse_it cnt=sectionlist.rbegin();
while (cnt!=sectionlist.rend()) {
@ -245,11 +268,18 @@ Config::~Config() {
Section* Config::GetSection(const char* _sectionname){
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
if (!strcasecmp((*tel)->sectionname.c_str(),_sectionname)) return (*tel);
if (!strcasecmp((*tel)->GetName(),_sectionname)) return (*tel);
}
return NULL;
}
Section* Config::GetSectionFromProperty(const char* prop)
{
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
if ((*tel)->HasProperty(prop)) return (*tel);
}
return NULL;
}
bool Config::ParseConfigFile(const char* configfilename){
ifstream in(configfilename);
if (!in) return false;