1994-09-19 09:50:07 +00:00
|
|
|
#ifndef __CONFIG_H
|
1995-01-02 09:33:00 +00:00
|
|
|
#define __CONFIG_H
|
|
|
|
|
1995-02-28 10:25:02 +00:00
|
|
|
#ifndef INCL_XVTH
|
1995-01-02 09:33:00 +00:00
|
|
|
#include <xvt.h>
|
|
|
|
#endif
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
#ifndef __ASSOC_H
|
|
|
|
#include <assoc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class ofstream;
|
|
|
|
|
|
|
|
// questo sara' il principale, per ora non c'e'
|
1994-09-27 10:07:50 +00:00
|
|
|
#define CONFIG_GENERAL 0
|
1994-09-19 09:50:07 +00:00
|
|
|
// file parametri studio (uno per studio, per ora e' il principale)
|
1994-09-27 10:07:50 +00:00
|
|
|
#define CONFIG_STUDIO 1
|
1994-09-19 09:50:07 +00:00
|
|
|
// file parametri ditta (uno per ditta)
|
1994-09-27 10:07:50 +00:00
|
|
|
#define CONFIG_DITTA 2
|
|
|
|
// file conversioni archivi
|
|
|
|
#define CONFIG_FCONV 3
|
1995-02-28 10:25:02 +00:00
|
|
|
// file parametri utente
|
|
|
|
#define CONFIG_USER 4
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TConfig : public TObject
|
|
|
|
{
|
|
|
|
TAssoc_array _data;
|
|
|
|
TFilename _file;
|
|
|
|
bool _dirty, _ispresent;
|
|
|
|
TString _paragraph;
|
|
|
|
|
|
|
|
bool _read_paragraph();
|
|
|
|
void _write_paragraph(ofstream&);
|
|
|
|
void _write_file();
|
|
|
|
void _check_paragraph(const char*);
|
1994-09-22 16:47:50 +00:00
|
|
|
void init(const char *fn, const char* pa);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1994-09-22 16:47:50 +00:00
|
|
|
public:
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
// ritorna valore di variabile nella sezione corrente o in
|
|
|
|
// quella specificata; se non c'e' ritorna ""
|
|
|
|
// passando index >=0 viene appeso al nome variabile per
|
|
|
|
// implementare un mezzo cazzo di array
|
1995-01-02 09:33:00 +00:00
|
|
|
TString& get(const char* var, const char* section = NULL, int index = -1, const char* def = "");
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
// questa ritorna 0 se non c'e', il che e' un po' sfigotto
|
1995-01-02 09:33:00 +00:00
|
|
|
long get_long(const char* var, const char* section = NULL, int index = -1, long def = 0L);
|
1995-01-24 08:52:49 +00:00
|
|
|
|
|
|
|
int get_int(const char* var, const char* section = NULL, int index = -1, int def = 0);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
// questa ritorna FALSE se non c'e', il che e' ancora piu' sfigotto
|
1995-01-02 09:33:00 +00:00
|
|
|
bool get_bool(const char* var, const char* section = NULL, int index = -1, bool def = FALSE);
|
|
|
|
|
|
|
|
COLOR get_color(const char* var, const char* section = NULL, int index = -1, COLOR def = 0);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
// setta variabile nella sezione corrente o specificata
|
|
|
|
// se force == TRUE crea la sezione/variabile se non esiste; altrimenti
|
|
|
|
// da' errore; ritorna TRUE se la sezione/var c'era, FALSE diversamente
|
|
|
|
// index come per get()
|
|
|
|
bool set(const char* var, const char* value, const char* section = NULL,
|
1994-09-22 16:47:50 +00:00
|
|
|
bool force = TRUE, int index = -1);
|
1994-09-19 09:50:07 +00:00
|
|
|
bool set(const char* var, long value, const char* section = NULL,
|
1994-09-22 16:47:50 +00:00
|
|
|
bool force = TRUE, int index = -1);
|
1994-10-26 12:23:12 +00:00
|
|
|
|
|
|
|
bool exist(const char* var, int index = -1);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
// TRUE se il paragrafo corrente e' nuovo
|
|
|
|
bool new_paragraph() { return !_ispresent; }
|
|
|
|
|
|
|
|
// items ritorna quanti elementi dell'array nominato sono
|
|
|
|
// presenti nella sezione indicata
|
|
|
|
// non si risponde di eventuali "buchi" causati da set() errate
|
|
|
|
word items(const char* var, const char* section);
|
|
|
|
|
|
|
|
// il paragrafo iniziale e' il modulo corrente salvo diversa indicazione
|
|
|
|
TConfig(int which_config = CONFIG_GENERAL, const char* paragraph = NULL);
|
1994-09-22 16:47:50 +00:00
|
|
|
TConfig(const char* file, const char* paragraph = NULL);
|
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
// il distruttore riscrive il file con le modifiche se necessrio,
|
|
|
|
virtual ~TConfig();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|