00001
#ifndef __CONFIGURABLE_H
00002
#define __CONFIGURABLE_H
00003
00004
#include <iostream>
00005
#include <list>
00006
#include <utility>
00007
#include <string>
00008
#include "stl_adds.h"
00009
00010
00011
#ifdef AVR
00012
00013
00014
00015
#define ABSTRACT {}
00016
#else
00017 #define ABSTRACT =0
00018
#endif
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 class Configurable {
00064
public:
00065
00066 typedef std::string
paramkey;
00067 typedef double paramval;
00068 typedef std::list< std::pair<paramkey, paramval> >
paramlist;
00069
00070
00071 struct matchId :
public std::unary_function<Configurable*, bool> {
00072 matchId(
int id) : id(id) {}
00073 int id;
00074 bool operator()(
Configurable* c) {
return c->
id ==
id; }
00075 };
00076
00077 Configurable(){
id = rand();}
00078
00079 Configurable(
const std::string& name,
const std::string& revision)
00080 : name(name), revision(revision) {
00081
id = rand();
00082 }
00083 virtual ~Configurable(){}
00084
00085
00086 int getId()
const {
return id;}
00087
00088
00089
00090 virtual paramkey getName()
const {
00091
return name;
00092 }
00093
00094
00095 virtual paramkey getRevision()
const {
00096
return revision;
00097 }
00098
00099
00100 virtual void setName(
const paramkey& name){
00101 this->name = name;
00102 }
00103
00104 virtual void getRevision(
const paramkey& revision) {
00105 this->revision = revision;
00106 }
00107
00108
00109
00110
00111 virtual paramval getParam(
const paramkey& key)
const{
00112 std::cerr << __FUNCTION__ <<
": parameter " << key <<
" unknown\n";
00113
return 0;
00114 }
00115
00116
00117
00118
00119 virtual bool setParam(
const paramkey& key,
paramval val){
00120
return false;
00121 }
00122
00123
00124
00125 virtual paramlist getParamList()
const {
00126
return paramlist();
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
static void insertCVSInfo(paramkey& str,
const char* file,
const char* revision);
00137
00138
#ifndef AVR
00139
00140
bool storeCfg(
const char* filenamestem);
00141
00142
bool restoreCfg(
const char* filenamestem);
00143
void print(FILE* f,
const char* prefix)
const;
00144
void parse(FILE* f);
00145
#endif
00146
private:
00147 int id;
00148 paramkey name;
00149 paramkey revision;
00150 };
00151
00152
00153
#endif