dosbox-wii/include/setup.h

230 lines
6.8 KiB
C
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-03 00:18:08 +02:00
* Copyright (C) 2002-2006 The DOSBox Team
2009-05-02 23:03:37 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-05-03 00:02:15 +02:00
* GNU General Public License for more details.
2009-05-02 23:03:37 +02:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2009-05-03 00:18:08 +02:00
/* $Id: setup.h,v 1.22 2006/02/09 11:47:48 qbix79 Exp $ */
2009-05-02 23:53:27 +02:00
2009-05-03 00:18:08 +02:00
#ifndef DOSBOX_SETUP_H
#define DOSBOX_SETUP_H
2009-05-02 23:03:37 +02:00
2009-05-02 23:43:00 +02:00
#ifdef _MSC_VER
2009-05-02 23:20:05 +02:00
#pragma warning ( disable : 4786 )
2009-05-02 23:43:00 +02:00
#endif
2009-05-02 23:20:05 +02:00
2009-05-03 00:18:08 +02:00
#ifndef DOSBOX_CROSS_H
2009-05-02 23:43:00 +02:00
#include "cross.h"
2009-05-03 00:18:08 +02:00
#endif
2009-05-02 23:20:05 +02:00
#include <string>
#include <list>
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class CommandLine {
public:
CommandLine(int argc,char * argv[]);
CommandLine(char * name,char * cmdline);
const char * GetFileName(){ return file_name.c_str();}
2009-05-03 00:18:08 +02:00
2009-05-02 23:20:05 +02:00
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);
bool FindString(char * name,std::string & value,bool remove=false);
2009-05-02 23:43:00 +02:00
bool FindCommand(unsigned int which,std::string & value);
2009-05-02 23:20:05 +02:00
bool FindStringBegin(char * begin,std::string & value, bool remove=false);
2009-05-02 23:27:47 +02:00
bool FindStringRemain(char * name,std::string & value);
2009-05-03 00:18:08 +02:00
bool GetStringRemain(std::string & value);
2009-05-02 23:43:00 +02:00
unsigned int GetCount(void);
2009-05-02 23:03:37 +02:00
private:
2009-05-02 23:20:05 +02:00
typedef std::list<std::string>::iterator cmd_it;
std::list<std::string> cmds;
std::string file_name;
bool FindEntry(char * name,cmd_it & it,bool neednext=false);
};
union Value{
int _hex;
bool _bool;
int _int;
std::string* _string;
2009-05-02 23:53:27 +02:00
float _float;
2009-05-02 23:20:05 +02:00
};
class Property {
public:
Property(const char* _propname):propname(_propname) { }
virtual void SetValue(char* input)=0;
virtual void GetValuestring(char* str)=0;
2009-05-03 00:18:08 +02:00
Value GetValue() { return value;}
2009-05-02 23:20:05 +02:00
virtual ~Property(){ }
2009-05-03 00:18:08 +02:00
std::string propname;
Value value;
2009-05-02 23:20:05 +02:00
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Prop_int:public Property {
public:
Prop_int(const char* _propname, int _value):Property(_propname) {
2009-05-03 00:18:08 +02:00
value._int=_value;
2009-05-02 23:20:05 +02:00
}
void SetValue(char* input);
void GetValuestring(char* str);
~Prop_int(){ }
2009-05-02 23:03:37 +02:00
};
2009-05-02 23:53:27 +02:00
class Prop_float:public Property {
public:
Prop_float(const char* _propname, float _value):Property(_propname){
2009-05-03 00:18:08 +02:00
value._float=_value;
2009-05-02 23:53:27 +02:00
}
void SetValue(char* input);
void GetValuestring(char* str);
~Prop_float(){ }
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Prop_bool:public Property {
public:
Prop_bool(const char* _propname, bool _value):Property(_propname) {
2009-05-03 00:18:08 +02:00
value._bool=_value;
2009-05-02 23:20:05 +02:00
}
void SetValue(char* input);
void GetValuestring(char* str);
~Prop_bool(){ }
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Prop_string:public Property{
public:
Prop_string(const char* _propname, char* _value):Property(_propname) {
2009-05-03 00:18:08 +02:00
value._string=new std::string(_value);
2009-05-02 23:20:05 +02:00
}
~Prop_string(){
2009-05-03 00:18:08 +02:00
delete value._string;
2009-05-02 23:20:05 +02:00
}
void SetValue(char* input);
void GetValuestring(char* str);
};
class Prop_hex:public Property {
public:
Prop_hex(const char* _propname, int _value):Property(_propname) {
2009-05-03 00:18:08 +02:00
value._hex=_value;
2009-05-02 23:20:05 +02:00
}
void SetValue(char* input);
~Prop_hex(){ }
2009-05-03 00:18:08 +02:00
void GetValuestring(char* str);
2009-05-02 23:20:05 +02:00
};
class Section {
2009-05-03 00:18:08 +02:00
private:
2009-05-02 23:20:05 +02:00
typedef void (*SectionFunction)(Section*);
2009-05-03 00:18:08 +02:00
/* Wrapper class around startup and shutdown functions. the variable
* canchange indicates it can be called on configuration changes */
struct Function_wrapper {
SectionFunction function;
bool canchange;
Function_wrapper(SectionFunction _fun,bool _ch){
function=_fun;
canchange=_ch;
2009-05-02 23:20:05 +02:00
}
2009-05-03 00:18:08 +02:00
};
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 char* GetPropValue(const char* _property)=0;
virtual void HandleInputline(char * _line)=0;
virtual void PrintData(FILE* outfile)=0;
virtual ~Section() { /*Children must call executedestroy ! */}
2009-05-02 23:20:05 +02:00
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Section_prop:public Section {
2009-05-03 00:18:08 +02:00
private:
std::list<Property*> properties;
typedef std::list<Property*>::iterator it;
public:
2009-05-02 23:20:05 +02:00
Section_prop(const char* _sectionname):Section(_sectionname){}
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);
void Add_hex(const char* _propname, int _value=0);
2009-05-02 23:53:27 +02:00
void Add_float(const char* _propname, float _value=0.0);
2009-05-02 23:20:05 +02:00
int Get_int(const char* _propname);
const char* Get_string(const char* _propname);
bool Get_bool(const char* _propname);
2009-05-02 23:53:27 +02:00
int Get_hex(const char* _propname);
float Get_float(const char* _propname);
2009-05-02 23:20:05 +02:00
void HandleInputline(char *gegevens);
void PrintData(FILE* outfile);
2009-05-03 00:18:08 +02:00
virtual char* GetPropValue(const char* _property);
//ExecuteDestroy should be here else the destroy functions use destroyed properties
virtual ~Section_prop();
2009-05-02 23:20:05 +02:00
};
class Section_line: public Section{
public:
Section_line(const char* _sectionname):Section(_sectionname){}
2009-05-03 00:18:08 +02:00
~Section_line(){ExecuteDestroy(true);}
2009-05-02 23:20:05 +02:00
void HandleInputline(char* gegevens);
void PrintData(FILE* outfile);
2009-05-03 00:18:08 +02:00
virtual char* GetPropValue(const char* _property);
2009-05-02 23:20:05 +02:00
std::string data;
};
class Config{
2009-05-03 00:18:08 +02:00
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);
2009-05-02 23:20:05 +02:00
public:
Config(CommandLine * cmd){ cmdline=cmd;}
~Config();
Section_line * AddSection_line(const char * _name,void (*_initfunction)(Section*));
2009-05-03 00:18:08 +02:00
Section_prop * AddSection_prop(const char * _name,void (*_initfunction)(Section*),bool canchange=false);
2009-05-02 23:20:05 +02:00
Section* GetSection(const char* _sectionname);
2009-05-03 00:18:08 +02:00
Section* GetSectionFromProperty(const char* prop);
2009-05-02 23:20:05 +02:00
void SetStartUp(void (*_function)(void));
void Init();
void ShutDown();
void StartUp();
void PrintConfig(const char* configfilename);
2009-05-02 23:53:27 +02:00
bool ParseConfigFile(const char* configfilename);
2009-05-02 23:35:44 +02:00
void ParseEnv(char ** envp);
2009-05-02 23:20:05 +02:00
};
2009-05-02 23:03:37 +02:00
2009-05-03 00:18:08 +02:00
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;} ;
};
2009-05-02 23:03:37 +02:00
#endif