dosbox-wii/include/setup.h

234 lines
7.4 KiB
C
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-03 00:28:34 +02:00
* Copyright (C) 2002-2007 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:37:32 +02:00
/* $Id: setup.h,v 1.27 2007/06/14 08:23:46 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:
2009-05-03 00:28:34 +02:00
CommandLine(int argc,char const * const argv[]);
CommandLine(char const * const name,char const * const cmdline);
2009-05-02 23:20:05 +02:00
const char * GetFileName(){ return file_name.c_str();}
2009-05-03 00:18:08 +02:00
2009-05-03 00:28:34 +02:00
bool FindExist(char const * const name,bool remove=false);
bool FindHex(char const * const name,int & value,bool remove=false);
bool FindInt(char const * const name,int & value,bool remove=false);
bool FindString(char const * const 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-03 00:28:34 +02:00
bool FindStringBegin(char const * const begin,std::string & value, bool remove=false);
bool FindStringRemain(char const * const 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-03 00:28:34 +02:00
void Shift(unsigned int amount=1);
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;
2009-05-03 00:28:34 +02:00
bool FindEntry(char const * const name,cmd_it & it,bool neednext=false);
2009-05-02 23:20:05 +02:00
};
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:
2009-05-03 00:28:34 +02:00
Property(char const * const _propname):propname(_propname) { }
2009-05-02 23:20:05 +02:00
virtual void SetValue(char* input)=0;
2009-05-03 00:28:34 +02:00
virtual void GetValuestring(char* str) const=0;
Value GetValue() const { 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:
2009-05-03 00:28:34 +02:00
Prop_int(char const * const _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);
2009-05-03 00:28:34 +02:00
void GetValuestring(char* str) const;
2009-05-02 23:20:05 +02:00
~Prop_int(){ }
2009-05-02 23:03:37 +02:00
};
2009-05-02 23:53:27 +02:00
class Prop_float:public Property {
public:
2009-05-03 00:28:34 +02:00
Prop_float(char const * const _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);
2009-05-03 00:28:34 +02:00
void GetValuestring(char* str) const;
2009-05-02 23:53:27 +02:00
~Prop_float(){ }
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Prop_bool:public Property {
public:
2009-05-03 00:28:34 +02:00
Prop_bool(char const * const _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);
2009-05-03 00:28:34 +02:00
void GetValuestring(char* str) const;
2009-05-02 23:20:05 +02:00
~Prop_bool(){ }
};
2009-05-02 23:03:37 +02:00
2009-05-02 23:20:05 +02:00
class Prop_string:public Property{
public:
2009-05-03 00:28:34 +02:00
Prop_string(char const * const _propname, char const * const _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);
2009-05-03 00:28:34 +02:00
void GetValuestring(char* str) const;
2009-05-02 23:20:05 +02:00
};
class Prop_hex:public Property {
public:
2009-05-03 00:28:34 +02:00
Prop_hex(char const * const _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:28:34 +02:00
void GetValuestring(char* str) const;
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;
2009-05-03 00:28:34 +02:00
Function_wrapper(SectionFunction const _fun,bool _ch){
2009-05-03 00:18:08 +02:00
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:
2009-05-03 00:28:34 +02:00
Section(char const * const _sectionname):sectionname(_sectionname) { }
2009-05-03 00:18:08 +02:00
2009-05-03 00:37:32 +02:00
void AddInitFunction(SectionFunction func,bool canchange=false);
void AddDestroyFunction(SectionFunction func,bool canchange=false);
2009-05-03 00:18:08 +02:00
void ExecuteInit(bool initall=true);
void ExecuteDestroy(bool destroyall=true);
2009-05-03 00:28:34 +02:00
const char* GetName() const {return sectionname.c_str();}
2009-05-03 00:18:08 +02:00
2009-05-03 00:28:34 +02:00
virtual char const * GetPropValue(char const * const _property) const =0;
2009-05-03 00:18:08 +02:00
virtual void HandleInputline(char * _line)=0;
2009-05-03 00:28:34 +02:00
virtual void PrintData(FILE* outfile) const =0;
2009-05-03 00:18:08 +02:00
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;
2009-05-03 00:28:34 +02:00
typedef std::list<Property*>::const_iterator const_it;
2009-05-03 00:18:08 +02:00
public:
2009-05-03 00:28:34 +02:00
Section_prop(char const * const _sectionname):Section(_sectionname){}
void Add_int(char const * const _propname, int _value=0);
void Add_string(char const * const _propname, char const * const _value=NULL);
void Add_bool(char const * const _propname, bool _value=false);
void Add_hex(char const * const _propname, int _value=0);
void Add_float(char const * const _propname, float _value=0.0);
int Get_int(char const * const _propname) const;
const char* Get_string(char const * const _propname) const;
bool Get_bool(char const * const _propname) const;
int Get_hex(char const * const _propname) const;
float Get_float(char const * const _propname) const;
2009-05-02 23:20:05 +02:00
void HandleInputline(char *gegevens);
2009-05-03 00:28:34 +02:00
void PrintData(FILE* outfile) const;
virtual char const * GetPropValue(char const * const _property) const;
2009-05-03 00:18:08 +02:00
//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:
2009-05-03 00:28:34 +02:00
Section_line(char const * const _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);
2009-05-03 00:28:34 +02:00
void PrintData(FILE* outfile) const;
virtual const char* GetPropValue(char const * const _property) const;
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;
2009-05-03 00:28:34 +02:00
typedef std::list<Section*>::const_iterator const_it;
typedef std::list<Section*>::const_reverse_iterator const_reverse_it;
2009-05-03 00:18:08 +02:00
void (* _start_function)(void);
2009-05-02 23:20:05 +02:00
public:
2009-05-03 00:28:34 +02:00
Config(CommandLine * cmd):cmdline(cmd){}
2009-05-02 23:20:05 +02:00
~Config();
2009-05-03 00:28:34 +02:00
Section_line * AddSection_line(char const * const _name,void (*_initfunction)(Section*));
Section_prop * AddSection_prop(char const * const _name,void (*_initfunction)(Section*),bool canchange=false);
2009-05-02 23:20:05 +02:00
2009-05-03 00:28:34 +02:00
Section* GetSection(char const* const _sectionname) const;
Section* GetSectionFromProperty(char const * const prop) const;
2009-05-02 23:20:05 +02:00
void SetStartUp(void (*_function)(void));
void Init();
void ShutDown();
void StartUp();
2009-05-03 00:28:34 +02:00
void PrintConfig(char const * const configfilename) const;
bool ParseConfigFile(char const * const 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) {};
2009-05-03 00:28:34 +02:00
virtual ~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
2009-05-03 00:18:08 +02:00
/* Returns true if succesful.*/
2009-05-03 00:28:34 +02:00
virtual bool Change_Config(Section* /*newconfig*/) {return false;} ;
2009-05-03 00:18:08 +02:00
};
2009-05-02 23:03:37 +02:00
#endif