parts/doxygen/config.h
Go to the documentation of this file.00001
#ifndef CONFIG_H
00002
#define CONFIG_H
00003
00004
#include <qstrlist.h>
00005
#include <qfile.h>
00006
#include <qdict.h>
00007
#include <qptrlist.h>
00008
#include <qtextstream.h>
00009
00013 class ConfigOption
00014 {
00015
friend class Config;
00016
00017
public:
00018
00020 enum OptionType
00021 {
00022
O_Info,
00023
O_List,
00024
O_Enum,
00025
O_String,
00026
O_Int,
00027
O_Bool,
00028
O_Obsolete
00029 };
00030
enum
00031 {
00035 MAX_OPTION_LENGTH = 23
00036 };
00037 ConfigOption(OptionType t) :
m_kind(t)
00038 {
00039
m_spaces.fill(
' ',40);
00040 }
00041 virtual ~ConfigOption()
00042 {
00043 }
00044
00046 OptionType kind()
const {
return m_kind; }
00047 QCString name()
const {
return m_name; }
00048 QCString docs()
const {
return m_doc; }
00049
00050 QCString dependsOn()
const {
return m_dependency; }
00051 void addDependency(
const char *dep) {
m_dependency = dep; }
00052
00053
protected:
00054
virtual void writeTemplate(
QTextStream &t,
bool sl,
bool upd) = 0;
00055 virtual void convertStrToVal() {}
00056
virtual void substEnvVars() = 0;
00057 virtual void init() {}
00058
00059
QCString convertToComment(
const QCString &s);
00060
void writeBoolValue(
QTextStream &t,
bool v);
00061
void writeIntValue(
QTextStream &t,
int i);
00062
void writeStringValue(
QTextStream &t,
QCString &s);
00063
void writeStringList(
QTextStream &t,
QStrList &l);
00064
00065 QCString m_spaces;
00066 QCString m_name;
00067 QCString m_doc;
00068 QCString m_dependency;
00069 OptionType m_kind;
00070 };
00071
00075 class ConfigInfo :
public ConfigOption
00076 {
00077
public:
00078 ConfigInfo(
const char *name,
const char *doc)
00079 :
ConfigOption(O_Info)
00080 {
00081 m_name = name;
00082 m_doc = doc;
00083 }
00084 void writeTemplate(
QTextStream &t,
bool sl,
bool)
00085 {
00086
if (!sl)
00087 {
00088 t <<
"\n";
00089 }
00090 t <<
"#---------------------------------------------------------------------------\n";
00091 t <<
"# " << m_doc <<
endl;
00092 t <<
"#---------------------------------------------------------------------------\n";
00093 }
00094 void substEnvVars() {}
00095 };
00096
00100 class ConfigList :
public ConfigOption
00101 {
00102
public:
00103 enum WidgetType {
String,
File,
Dir,
FileAndDir };
00104 ConfigList(
const char *name,
const char *doc)
00105 :
ConfigOption(O_List)
00106 {
00107 m_name = name;
00108 m_doc = doc;
00109
m_widgetType =
String;
00110 }
00111 void addValue(
const char *v) {
m_value.append(v); }
00112 void setWidgetType(WidgetType w) {
m_widgetType = w; }
00113 WidgetType widgetType()
const {
return m_widgetType; }
00114 QStrList *
valueRef() {
return &
m_value; }
00115 void writeTemplate(
QTextStream &t,
bool sl,
bool)
00116 {
00117
if (!sl)
00118 {
00119 t <<
endl;
00120 t << convertToComment(m_doc);
00121 t <<
endl;
00122 }
00123 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) <<
"= ";
00124 writeStringList(t,
m_value);
00125 t <<
"\n";
00126 }
00127
void substEnvVars();
00128 void init() {
m_value.clear(); }
00129
private:
00130 QStrList m_value;
00131 WidgetType m_widgetType;
00132 };
00133
00137 class ConfigEnum :
public ConfigOption
00138 {
00139
public:
00140 ConfigEnum(
const char *name,
const char *doc,
const char *defVal)
00141 :
ConfigOption(O_Enum)
00142 {
00143 m_name = name;
00144 m_doc = doc;
00145
m_value = defVal;
00146
m_defValue = defVal;
00147 }
00148 void addValue(
const char *v) {
m_valueRange.append(v); }
00149 QStrListIterator iterator()
00150 {
00151
return QStrListIterator(
m_valueRange);
00152 }
00153 QCString *
valueRef() {
return &
m_value; }
00154
void substEnvVars();
00155 void writeTemplate(
QTextStream &t,
bool sl,
bool)
00156 {
00157
if (!sl)
00158 {
00159 t <<
endl;
00160 t << convertToComment(m_doc);
00161 t <<
endl;
00162 }
00163 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) <<
"= ";
00164 writeStringValue(t,
m_value);
00165 t <<
"\n";
00166 }
00167 void init() {
m_value =
m_defValue.copy(); }
00168
00169
private:
00170 QStrList m_valueRange;
00171 QCString m_value;
00172 QCString m_defValue;
00173 };
00174
00178 class ConfigString :
public ConfigOption
00179 {
00180
public:
00181 enum WidgetType {
String,
File,
Dir };
00182 ConfigString(
const char *name,
const char *doc)
00183 :
ConfigOption(O_String)
00184 {
00185 m_name = name;
00186 m_doc = doc;
00187
m_widgetType =
String;
00188 }
00189 ~ConfigString()
00190 {
00191 }
00192 void setWidgetType(WidgetType w) {
m_widgetType = w; }
00193 WidgetType widgetType()
const {
return m_widgetType; }
00194 void setDefaultValue(
const char *v) {
m_defValue = v; }
00195 QCString *
valueRef() {
return &
m_value; }
00196 void writeTemplate(
QTextStream &t,
bool sl,
bool)
00197 {
00198
if (!sl)
00199 {
00200 t <<
endl;
00201 t << convertToComment(m_doc);
00202 t <<
endl;
00203 }
00204 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) <<
"= ";
00205 writeStringValue(t,
m_value);
00206 t <<
"\n";
00207 }
00208
void substEnvVars();
00209 void init() {
m_value =
m_defValue.copy(); }
00210
00211
private:
00212 QCString m_value;
00213 QCString m_defValue;
00214 WidgetType m_widgetType;
00215 };
00216
00220 class ConfigInt :
public ConfigOption
00221 {
00222
public:
00223 ConfigInt(
const char *name,
const char *doc,
int minVal,
int maxVal,
int defVal)
00224 :
ConfigOption(O_Int)
00225 {
00226 m_name = name;
00227 m_doc = doc;
00228
m_value = defVal;
00229
m_defValue = defVal;
00230
m_minVal = minVal;
00231
m_maxVal = maxVal;
00232 }
00233 QCString *
valueStringRef() {
return &
m_valueString; }
00234 int *
valueRef() {
return &
m_value; }
00235 int minVal()
const {
return m_minVal; }
00236 int maxVal()
const {
return m_maxVal; }
00237
void convertStrToVal();
00238
void substEnvVars();
00239 void writeTemplate(
QTextStream &t,
bool sl,
bool upd)
00240 {
00241
if (!sl)
00242 {
00243 t <<
endl;
00244 t << convertToComment(m_doc);
00245 t <<
endl;
00246 }
00247 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) <<
"= ";
00248
if (upd && !
m_valueString.isEmpty())
00249 {
00250 writeStringValue(t,
m_valueString);
00251 }
00252
else
00253 {
00254 writeIntValue(t,
m_value);
00255 }
00256 t <<
"\n";
00257 }
00258 void init() {
m_value =
m_defValue; }
00259
private:
00260 int m_value;
00261 int m_defValue;
00262 int m_minVal;
00263 int m_maxVal;
00264 QCString m_valueString;
00265 };
00266
00270 class ConfigBool :
public ConfigOption
00271 {
00272
public:
00273 ConfigBool(
const char *name,
const char *doc,
bool defVal)
00274 :
ConfigOption(O_Bool)
00275 {
00276 m_name = name;
00277 m_doc = doc;
00278
m_value = defVal;
00279
m_defValue = defVal;
00280 }
00281 QCString *
valueStringRef() {
return &
m_valueString; }
00282 bool *
valueRef() {
return &
m_value; }
00283
void convertStrToVal();
00284
void substEnvVars();
00285 void setValueString(
const QCString &v) {
m_valueString = v; }
00286 void writeTemplate(
QTextStream &t,
bool sl,
bool upd)
00287 {
00288
if (!sl)
00289 {
00290 t <<
endl;
00291 t << convertToComment(m_doc);
00292 t <<
endl;
00293 }
00294 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) <<
"= ";
00295
if (upd && !
m_valueString.isEmpty())
00296 {
00297 writeStringValue(t,
m_valueString);
00298 }
00299
else
00300 {
00301 writeBoolValue(t,
m_value);
00302 }
00303 t <<
"\n";
00304 }
00305 void init() {
m_value =
m_defValue; }
00306
private:
00307 bool m_value;
00308 bool m_defValue;
00309 QCString m_valueString;
00310 };
00311
00315 class ConfigObsolete :
public ConfigOption
00316 {
00317
public:
00318 ConfigObsolete(OptionType t) :
ConfigOption(t) {}
00319 void writeTemplate(
QTextStream &,
bool,
bool) {}
00320 void substEnvVars() {}
00321 };
00322
00323
00324
00325 #define Config_getString(val) Config::instance()->getString(__FILE__,__LINE__,val)
00326 #define Config_getInt(val) Config::instance()->getInt(__FILE__,__LINE__,val)
00327 #define Config_getList(val) Config::instance()->getList(__FILE__,__LINE__,val)
00328 #define Config_getEnum(val) Config::instance()->getEnum(__FILE__,__LINE__,val)
00329 #define Config_getBool(val) Config::instance()->getBool(__FILE__,__LINE__,val)
00330
00342 class Config
00343 {
00344
public:
00346
00348
00350 static Config *
instance()
00351 {
00352
if (
m_instance==0)
m_instance =
new Config;
00353
return m_instance;
00354 }
00356 static void deleteInstance()
00357 {
00358
delete m_instance;
00359 }
00360
00364 QPtrListIterator<ConfigOption> iterator()
00365 {
00366
return QPtrListIterator<ConfigOption>(*m_options);
00367 }
00368
00378
QCString &getString(
const char *fileName,
int num,
const char *name)
const;
00379
00384
QStrList &getList(
const char *fileName,
int num,
const char *name)
const;
00385
00390
QCString &getEnum(
const char *fileName,
int num,
const char *name)
const;
00391
00396
int &getInt(
const char *fileName,
int num,
const char *name)
const;
00397
00402
bool &getBool(
const char *fileName,
int num,
const char *name)
const;
00403
00407 ConfigOption *
get(
const char *name)
const
00408
{
00409
return m_dict->find(name);
00410 }
00411
00412
00421 ConfigInfo *
addInfo(
const char *name,
const char *doc)
00422 {
00423
ConfigInfo *result =
new ConfigInfo(name,doc);
00424
m_options->append(result);
00425
return result;
00426 }
00427
00431 ConfigString *
addString(
const char *name,
00432
const char *doc)
00433 {
00434
ConfigString *result =
new ConfigString(name,doc);
00435
m_options->append(result);
00436
m_dict->insert(name,result);
00437
return result;
00438 }
00439
00444 ConfigEnum *
addEnum(
const char *name,
00445
const char *doc,
00446
const char *defVal)
00447 {
00448
ConfigEnum *result =
new ConfigEnum(name,doc,defVal);
00449
m_options->append(result);
00450
m_dict->insert(name,result);
00451
return result;
00452 }
00453
00457 ConfigList *
addList(
const char *name,
00458
const char *doc)
00459 {
00460
ConfigList *result =
new ConfigList(name,doc);
00461
m_options->append(result);
00462
m_dict->insert(name,result);
00463
return result;
00464 }
00465
00471 ConfigInt *
addInt(
const char *name,
00472
const char *doc,
00473
int minVal,
int maxVal,
int defVal)
00474 {
00475
ConfigInt *result =
new ConfigInt(name,doc,minVal,maxVal,defVal);
00476
m_options->append(result);
00477
m_dict->insert(name,result);
00478
return result;
00479 }
00480
00485 ConfigBool *
addBool(
const char *name,
00486
const char *doc,
00487
bool defVal)
00488 {
00489
ConfigBool *result =
new ConfigBool(name,doc,defVal);
00490
m_options->append(result);
00491
m_dict->insert(name,result);
00492
return result;
00493 }
00495 ConfigOption *
addObsolete(
const char *name)
00496 {
00497
ConfigObsolete *option =
new ConfigObsolete(ConfigOption::O_Obsolete);
00498
m_dict->insert(name,option);
00499
m_obsolete->append(option);
00500
return option;
00501 }
00508
void writeTemplate(
QFile *f,
bool shortIndex,
bool updateOnly);
00509
00511
00513
00517
void convertStrToVal();
00518
00522
void substituteEnvironmentVars();
00523
00527
void check();
00528
00530
void init();
00531
00536
bool parse(
const char *fn);
00537
00541
void create();
00542
00543
protected:
00544
00545 Config()
00546 {
00547
m_options =
new QPtrList<ConfigOption>;
00548
m_obsolete =
new QPtrList<ConfigOption>;
00549
m_dict =
new QDict<ConfigOption>(257);
00550
m_options->setAutoDelete(TRUE);
00551
m_obsolete->setAutoDelete(TRUE);
00552
m_initialized = FALSE;
00553
create();
00554 }
00555 ~Config()
00556 {
00557
delete m_options;
00558
delete m_obsolete;
00559
delete m_dict;
00560 }
00561
00562
private:
00563 QPtrList<ConfigOption> *
m_options;
00564 QPtrList<ConfigOption> *
m_obsolete;
00565 QDict<ConfigOption> *
m_dict;
00566
static Config *
m_instance;
00567 bool m_initialized;
00568 };
00569
00570
#endif
This file is part of the documentation for KDevelop Version 3.0.4.