Patch level :
Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunto suporto per tipi record non compresi nel file .ini git-svn-id: svn://10.65.10.50/trunk@6945 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
a9a9ba67c5
commit
6ecab4b3e0
@ -183,8 +183,9 @@ void TFile_text::set_gen_parm(TConfig& config, const TString& section)
|
|||||||
|
|
||||||
_typefield = config.get_int("TYPEFIELD",section); // Numero del campo tipo (puo' essere -1)
|
_typefield = config.get_int("TYPEFIELD",section); // Numero del campo tipo (puo' essere -1)
|
||||||
_fixedlen = _fieldsep <= ' '; // && _recordsep.blank();
|
_fixedlen = _fieldsep <= ' '; // && _recordsep.blank();
|
||||||
_typepos = -1;
|
_typepos = config.get_int("TYPEPOS", section, -1, -1);
|
||||||
_typelen = -1;
|
_typelen = config.get_int("TYPELEN", section, -1, -1);
|
||||||
|
CHECKD(_typelen <= 16, "Tipo record di lunghezza spropositata: ", _typelen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TFile_text::set_type_parm(TConfig& config, TString& section)
|
void TFile_text::set_type_parm(TConfig& config, TString& section)
|
||||||
@ -332,17 +333,24 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
|||||||
}
|
}
|
||||||
if (lavoro == "POS")
|
if (lavoro == "POS")
|
||||||
{
|
{
|
||||||
int pos = atoi(obj);
|
const int pos = atoi(obj);
|
||||||
|
if (pos >= 0)
|
||||||
|
{
|
||||||
tc.set_position(pos);
|
tc.set_position(pos);
|
||||||
if (_fixedlen && _typepos < 0 && n == _typefield)
|
if (_typepos < 0 && n == _typefield)
|
||||||
_typepos = pos;
|
_typepos = pos;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lavoro == "LEN")
|
if (lavoro == "LEN")
|
||||||
{
|
{
|
||||||
int len = atoi(obj);
|
const int len = atoi(obj);
|
||||||
if (tc.length() <= 0 && len >= 0 && tc.length() != len)
|
if (tc.length() <= 0 && len > 0)
|
||||||
|
{
|
||||||
tc.set_length(len);
|
tc.set_length(len);
|
||||||
|
if (_typelen < 0 && n == _typefield)
|
||||||
|
_typelen = len;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lavoro == "DEC")
|
if (lavoro == "DEC")
|
||||||
@ -445,11 +453,16 @@ TFile_text::~TFile_text()
|
|||||||
//Legge da file il record text
|
//Legge da file il record text
|
||||||
int TFile_text::read(TRecord_text& rec)
|
int TFile_text::read(TRecord_text& rec)
|
||||||
{
|
{
|
||||||
CHECK(_read_file, "Impossibile leggere da un file chiuso.");
|
if (_read_file == NULL)
|
||||||
|
open('r');
|
||||||
|
|
||||||
|
TToken_string buffer;
|
||||||
|
|
||||||
TToken_string buffer(_recordsize), lavoro;
|
|
||||||
if (_recordsize > 0)
|
if (_recordsize > 0)
|
||||||
{
|
{
|
||||||
|
if (buffer.size() < _recordsize)
|
||||||
|
buffer.spaces(_recordsize);
|
||||||
|
|
||||||
_read_file->read(buffer.get_buffer(), _recordsize);
|
_read_file->read(buffer.get_buffer(), _recordsize);
|
||||||
if (!ok_r()) return 1; //non ritorna errore se fine file ed il record e' completo!
|
if (!ok_r()) return 1; //non ritorna errore se fine file ed il record e' completo!
|
||||||
}
|
}
|
||||||
@ -467,6 +480,7 @@ int TFile_text::read(TRecord_text& rec)
|
|||||||
if (!ok_r())
|
if (!ok_r())
|
||||||
return EOF; //non ritorna errore se fine file ed il record e' completo!
|
return EOF; //non ritorna errore se fine file ed il record e' completo!
|
||||||
}
|
}
|
||||||
|
|
||||||
// prendo il resto del separatore
|
// prendo il resto del separatore
|
||||||
int l = _recordsep.len()-1;
|
int l = _recordsep.len()-1;
|
||||||
for (int j = 0; j < l;c = _read_file-> get (), j++);
|
for (int j = 0; j < l;c = _read_file-> get (), j++);
|
||||||
@ -481,46 +495,50 @@ int TFile_text::read(TRecord_text& rec)
|
|||||||
rec.set_type(tipo);//istanzio il tipo del record text
|
rec.set_type(tipo);//istanzio il tipo del record text
|
||||||
|
|
||||||
TArray& a_tc = tr.tracciati_campo();
|
TArray& a_tc = tr.tracciati_campo();
|
||||||
int items = a_tc.items();
|
const int items = a_tc.items();
|
||||||
buffer.restart();
|
buffer.restart();
|
||||||
for (int i = 0; i < items; i++)
|
for (int i = 0; i < items; i++)
|
||||||
{
|
{
|
||||||
// TTracciato_campo& tc = tr.get(i);
|
const char* lavoro = buffer.get();
|
||||||
lavoro = buffer.get();
|
if (lavoro == NULL)
|
||||||
|
lavoro = "";
|
||||||
rec.add(lavoro, i);
|
rec.add(lavoro, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TString tipo = buffer.mid(_typepos, _typelen);
|
TString16 tipo = buffer.mid(_typepos, _typelen);
|
||||||
tipo.trim();
|
tipo.trim();
|
||||||
rec.set_type(tipo);//istanzio il tipo del record text
|
rec.set_type(tipo);//istanzio il tipo del record text
|
||||||
TTracciato_record* tr = t_rec(tipo);
|
TTracciato_record* tr = t_rec(tipo);
|
||||||
CHECK(tr,"Tipo di tracciato record non riconosciuto");
|
if (tr != NULL)
|
||||||
|
{
|
||||||
//ora che ho il tracciato record devo scandire i tracciati campo e caricare il record text
|
//ora che ho il tracciato record devo scandire i tracciati campo e caricare il record text
|
||||||
TArray& a_tc = tr->tracciati_campo();
|
const TArray& a_tc = tr->tracciati_campo();
|
||||||
int items = a_tc.items();
|
const int items = a_tc.items();
|
||||||
for (int i = 0; i < items; i++)
|
for (int i = 0; i < items; i++)
|
||||||
{
|
{
|
||||||
TTracciato_campo& tc = tr->get(i);
|
TTracciato_campo& tc = tr->get(i);
|
||||||
int pos = tc.position();
|
const int pos = tc.position();
|
||||||
int len = tc.length();
|
const int len = tc.length();
|
||||||
lavoro = buffer.mid(pos, len);
|
const char* lavoro = buffer.mid(pos, len);
|
||||||
rec.add(lavoro, i);
|
rec.add(lavoro, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Scrive su file il record_text (valido anche per header e footer)
|
//Scrive su file il record_text (valido anche per header e footer)
|
||||||
int TFile_text::write(TRecord_text& rec)
|
int TFile_text::write(TRecord_text& rec)
|
||||||
{
|
{
|
||||||
TString buffer;
|
|
||||||
TString campo;
|
TString campo;
|
||||||
|
TToken_string buffer;
|
||||||
|
|
||||||
const TString& type = rec.type();
|
const TString& type = rec.type();
|
||||||
TTracciato_record& tr = *t_rec(type);
|
TTracciato_record& tr = *t_rec(type);
|
||||||
TArray& a_tc = tr.tracciati_campo();
|
TArray& a_tc = tr.tracciati_campo();
|
||||||
int items = rec.items();
|
const int items = rec.items();
|
||||||
if (_typepos>=0)
|
if (_typepos>=0)
|
||||||
rec.add(type,_typepos);
|
rec.add(type,_typepos);
|
||||||
if (_fixedlen) // campi a lunghezza fissa
|
if (_fixedlen) // campi a lunghezza fissa
|
||||||
@ -528,8 +546,7 @@ int TFile_text::write(TRecord_text& rec)
|
|||||||
for (int i = 0; i < items; i++)
|
for (int i = 0; i < items; i++)
|
||||||
{
|
{
|
||||||
TTracciato_campo& tc = tr.get(i);
|
TTracciato_campo& tc = tr.get(i);
|
||||||
campo = rec.row(i);
|
campo = format_textfield(tc, rec.row(i));
|
||||||
campo = format_textfield(tc, campo);
|
|
||||||
buffer.insert(campo, tc.position());
|
buffer.insert(campo, tc.position());
|
||||||
campo.cut(0);
|
campo.cut(0);
|
||||||
}
|
}
|
||||||
@ -539,31 +556,29 @@ int TFile_text::write(TRecord_text& rec)
|
|||||||
// Record a lunghezza var
|
// Record a lunghezza var
|
||||||
*_write_file << buffer;
|
*_write_file << buffer;
|
||||||
*_write_file << _recordsep;
|
*_write_file << _recordsep;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Record a lunghezza fissa
|
// Record a lunghezza fissa
|
||||||
buffer.rpad(_recordsize);
|
buffer.rpad(_recordsize);
|
||||||
buffer.cut(_recordsize);
|
buffer.cut(_recordsize);
|
||||||
*_write_file << buffer;
|
*_write_file << buffer;
|
||||||
}
|
}
|
||||||
if (!ok_w()) return 1;
|
if (!ok_w()) return 1;
|
||||||
buffer.cut(0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TToken_string ts(buffer, _fieldsep);
|
buffer.separator(_fieldsep);
|
||||||
for (int i = 0; i < items; i++)
|
for (int i = 0; i < items; i++)
|
||||||
{
|
{
|
||||||
TTracciato_campo& tc = tr.get(i);
|
TTracciato_campo& tc = tr.get(i);
|
||||||
campo = rec.row(i);
|
campo = format_textfield(tc, rec.row(i));
|
||||||
campo = format_textfield(tc, campo);
|
buffer.add(campo);
|
||||||
ts.add(campo, i);
|
|
||||||
campo.cut(0);
|
|
||||||
}
|
}
|
||||||
CHECK(_write_file, "Impossibile scrivere su un file chiuso.");
|
CHECK(_write_file, "Impossibile scrivere su un file chiuso.");
|
||||||
*_write_file << ts;
|
*_write_file << buffer;
|
||||||
*_write_file << _recordsep;
|
*_write_file << _recordsep;
|
||||||
if (!ok_w()) return 1;
|
if (!ok_w()) return 1;
|
||||||
ts.cut(0);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -728,7 +743,8 @@ int TFile_text::_autosave(TRelation& rel, const TRecord_text& rec, TTracciato_re
|
|||||||
if (err == _isdupkey || err ==_isreinsert)
|
if (err == _isdupkey || err ==_isreinsert)
|
||||||
err = rel.rewrite();
|
err = rel.rewrite();
|
||||||
return err;
|
return err;
|
||||||
} else
|
}
|
||||||
|
|
||||||
return NOERR;
|
return NOERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,9 +773,16 @@ void TFile_text::add_field(TRecord_text& rec, const int ncampo, const char* val)
|
|||||||
{
|
{
|
||||||
TTracciato_record& tr = *t_rec(rec.type());
|
TTracciato_record& tr = *t_rec(rec.type());
|
||||||
TTracciato_campo& tc = tr.get(ncampo);
|
TTracciato_campo& tc = tr.get(ncampo);
|
||||||
TString valore = val;
|
rec.add(val, ncampo);
|
||||||
//valore =format_textfield(tc, valore);
|
}
|
||||||
rec.add(valore, ncampo);
|
|
||||||
|
//Carica nel record_text il campo <name> con il valore <val> già formattato
|
||||||
|
void TFile_text::add_field(TRecord_text& rec, const char* name, const char* val)
|
||||||
|
{
|
||||||
|
TTracciato_record& tr = *t_rec(rec.type());
|
||||||
|
int ncampo = tr.get_pos(name);
|
||||||
|
CHECKS(ncampo >= 0, "Campo inesistente ", name);
|
||||||
|
rec.add(val, ncampo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Formatta la data in base al tracciato
|
//Formatta la data in base al tracciato
|
||||||
|
@ -116,20 +116,24 @@ public:
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
class TRecord_text : public TObject
|
class TRecord_text : public TObject
|
||||||
{
|
{
|
||||||
TString _type;//tipo del record
|
TString16 _type; //tipo del record
|
||||||
TString_array _array;//array che contiene i valori dei campi
|
TString_array _array; //array che contiene i valori dei campi
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TRecord_text() {}
|
|
||||||
TRecord_text(const TString& type): _type(type) {}
|
|
||||||
virtual ~TRecord_text(){}
|
|
||||||
const TString& type() const {return _type;}
|
const TString& type() const {return _type;}
|
||||||
void set_type(const TString& type) {_type = type;}
|
void set_type(const TString& type) {_type = type;}
|
||||||
const TString& row(int pos) const;//usare la get!!!
|
const TString& row(int pos) const;//usare la get!!!
|
||||||
TString& row(int pos);
|
TString& row(int pos);
|
||||||
const TString& get(int pos) const {return row(pos);}//ritorna il campo dell'array della posizione <pos>
|
const TString& get(int pos) const {return row(pos);}//ritorna il campo dell'array della posizione <pos>
|
||||||
void add(const TString& c, int pos = -1);//scrive il campo <c> nell'array alla posizione <pos>
|
void add(const TString& c, int pos = -1);//scrive il campo <c> nell'array alla posizione <pos>
|
||||||
|
|
||||||
const int items() const {return _array.items();}//ritorna il numero di elementi dell'array
|
const int items() const {return _array.items();}//ritorna il numero di elementi dell'array
|
||||||
virtual bool destroy(int index = -1, bool pack = FALSE) {return _array.destroy(index, pack);}
|
virtual bool destroy(int index = -1, bool pack = FALSE)
|
||||||
|
{ return _array.destroy(index, pack); }
|
||||||
|
|
||||||
|
TRecord_text() { }
|
||||||
|
TRecord_text(const TString& type) : _type(type) { }
|
||||||
|
virtual ~TRecord_text(){}
|
||||||
};
|
};
|
||||||
///////////////////////////////// TFile_text //////////////////////////////////////
|
///////////////////////////////// TFile_text //////////////////////////////////////
|
||||||
// Classe per la definizione di un file di testo capace di leggersi e scriversi,//
|
// Classe per la definizione di un file di testo capace di leggersi e scriversi,//
|
||||||
@ -186,8 +190,6 @@ protected:
|
|||||||
virtual bool pre_writerel(TRelation& rel,const TRecord_text& rec) {return TRUE;}
|
virtual bool pre_writerel(TRelation& rel,const TRecord_text& rec) {return TRUE;}
|
||||||
virtual bool can_write(TRecord_text&, TRelation&) {return TRUE;}
|
virtual bool can_write(TRecord_text&, TRelation&) {return TRUE;}
|
||||||
public:
|
public:
|
||||||
TFile_text(const char* file_name, const char* config_name);
|
|
||||||
virtual ~TFile_text();
|
|
||||||
ifstream* read_file() {return _read_file;}
|
ifstream* read_file() {return _read_file;}
|
||||||
ofstream* write_file() {return _write_file;}
|
ofstream* write_file() {return _write_file;}
|
||||||
void set_gen_parm(TConfig& config, const TString& section);//scarica i parametri generali dal file di configurazione
|
void set_gen_parm(TConfig& config, const TString& section);//scarica i parametri generali dal file di configurazione
|
||||||
@ -241,14 +243,19 @@ public:
|
|||||||
int autosave(const TRecord_text& rec, int mainfile=0);
|
int autosave(const TRecord_text& rec, int mainfile=0);
|
||||||
//caricamento automatico della relazione definita nel tracciato dal record_text
|
//caricamento automatico della relazione definita nel tracciato dal record_text
|
||||||
int autosave(int mainfile);
|
int autosave(int mainfile);
|
||||||
int read(TRecord_text & rec);//legge da file di testo il record_text
|
int read(TRecord_text& rec);//legge da file di testo il record_text
|
||||||
int read() {return read(*_current);}//legge da file di testo il record_text corrente
|
int read() {return read(*_current);}//legge da file di testo il record_text corrente
|
||||||
//carica nel record_text il campo alla posizione <ncampo> con il valore <val> già formattato
|
//carica nel record_text il campo alla posizione <ncampo> con il valore <val> già formattato
|
||||||
void add_field(TRecord_text& rec, const int ncampo, const char* val);
|
void add_field(TRecord_text& rec, const int ncampo, const char* val);
|
||||||
|
//carica nel record_text il campo <name> con il valore <val> già formattato
|
||||||
|
void add_field(TRecord_text& rec, const char* name, const char* val);
|
||||||
//scarica dal record_text il campo alla posizione <ncampo>
|
//scarica dal record_text il campo alla posizione <ncampo>
|
||||||
const TString& get_field(const TRecord_text& rec, int ncampo);
|
const TString& get_field(const TRecord_text& rec, int ncampo);
|
||||||
//scarica dal record_text il campo di nome <name>
|
//scarica dal record_text il campo di nome <name>
|
||||||
const TString& get_field(const TRecord_text& rec, const char* name);
|
const TString& get_field(const TRecord_text& rec, const char* name);
|
||||||
|
|
||||||
|
TFile_text(const char* file_name, const char* config_name);
|
||||||
|
virtual ~TFile_text();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__FILETEXT_H
|
#endif //__FILETEXT_H
|
Loading…
x
Reference in New Issue
Block a user