Patch level : 12.0 1040

Files correlati     : tutto in
Commento            :

Aggiornato il modulo intra

Interno :

Primo rilascio mancano  la generazione riepiloghi e l'invio delle righe di servizio
This commit is contained in:
Alessandro Bonazzi 2021-03-16 13:36:05 +01:00
parent a1e246518e
commit 800cf412cf
2 changed files with 280 additions and 215 deletions

View File

@ -1069,41 +1069,54 @@ TTextfile::~TTextfile ()
// TTracciatoInvio // TTracciatoInvio
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int pos, int len, int dec, int fldno) void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int len, int dec)
{ {
switch (type) switch (type)
{ {
case AN: case AN:
break; break;
case CB: case CB:
CHECKD(len == 1, "Booleano di lunghezza sospetta ", len); if (len == 0)
// type = NU; len = 1;
type = NU;
break; break;
case CF: case CF:
CHECKD(len == 16, "Codice fiscale di lunghezza sospetta ", len);
type = AN; type = AN;
len = 16;
break; break;
case PI:
case CN: case CN:
CHECKD(len == 11, "Codice fiscale numerico di lunghezza sospetta ", len);
type = NU; type = NU;
len = 11;
break; break;
case DA: case DA:
CHECKD(len == 6, "Mese+Anno di lunghezza sospetta ", len);
type = NU; type = NU;
len = 4;
break; break;
case D6:
type = NU;
len = 6;
break;
case DT: case DT:
CHECKD(len == 8, "Data di lunghezza sospetta ", len);
type = NU; type = NU;
len = 8;
break; break;
case NP:
type = NU;
case NU: case NU:
break; break;
case PN: case PN:
case PR: case PR:
CHECKD(len == 2, "provincia di lunghezza sospetta ", len);
type = AN; type = AN;
len = 2;
break; break;
case QU: case QU:
CHECK(len > dec + 1, "numero di decimali incoerente"); CHECK(len > dec + 1, "numero di decimali incoerente");
break;
case FV:
len = strlen(name);
// CHECK(strlen(name) == len, "lunghezza campo fisso incoerente");
break;
default: default:
CHECK(false, "tipo campo sospetto"); CHECK(false, "tipo campo sospetto");
break; break;
@ -1112,127 +1125,106 @@ void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int pos,
TFieldInvio* info = new TFieldInvio; TFieldInvio* info = new TFieldInvio;
info->_desc = name; info->_desc = name;
info->_type = type; info->_type = type;
info->_pos = pos; info->_pos = _len + 1;
info->_len = len; info->_len = len;
info->_dec = dec; info->_dec = dec;
_len += len;
if (fldno <= 0) _fields.add(name, info);
fldno = _fields.add(info) + 1;
else
_fields.add(info, fldno - 1);
} }
const TFieldInvio& TTracciatoInvio::field(int pos) const const TFieldInvio& TTracciatoInvio::field(const char * name) const
{ {
TFieldInvio* info = (TFieldInvio*)_fields.objptr(pos - 1); TFieldInvio* info = (TFieldInvio*)_fields.objptr(name);
#ifdef DBG #ifdef DBG
if (info == NULL) if (info == nullptr)
fatal_box("Non esiste il campo %d sul tipo record %c", pos, _tipo); fatal_box("Non esiste il campo %s sul tipo record %c", name, _tipo);
#endif #endif
return *info; return *info;
} }
void TTracciatoInvio::auto_fill(TString& buffer) const void TTracciatoInvio::zero(TString& buffer)
{ {
buffer.fill(' ', TOTAL_SIZE); buffer.fill(' ', TOTAL_SIZE);
char* ptr = buffer.get_buffer(); char* ptr = buffer.get_buffer();
for (int f = _fields.last(); f >= 0; f = _fields.pred(f))
FOR_EACH_ASSOC_OBJECT( _fields, hash, name, obj)
{ {
const TFieldInvio& info = (const TFieldInvio&)_fields[f]; const TFieldInvio& info = (const TFieldInvio&)_fields[name];
if (info._type == NU || info._type == CB || info._type == DA || info._type == DT || info._type == CN) if (info._type == NU || info._type == CB || info._type == DA || info._type == DT || info._type == CN)
memset(ptr + info._pos - 1, '0', info._len); memset(ptr + info._pos - 1, '0', info._len);
else
if (info._type == FV)
buffer.overwrite(info._desc, info._pos -1, info._len);
} }
buffer[0] = _tipo; buffer[0] = _tipo;
buffer.overwrite("A\r\n", TOTAL_SIZE - 3); buffer.overwrite("A\r\n", TOTAL_SIZE - 3);
} }
TTracciatoInvio::TTracciatoInvio(char tipo) : _tipo(tipo) TTracciatoInvio::TTracciatoInvio(char tipo) : _tipo(tipo), _len(0)
{ {
if (strchr("ABCEFHJZ[", tipo) == NULL) if (strchr("ABCEFHJZ[", tipo) == NULL)
NFCHECK("Tipo record non valido: %c", tipo); NFCHECK("Tipo record non valido: %c", tipo);
add_field("Tipo record", AN, 1, 1); // 1 add_field("Tipo record", AN, 1); // 1
} }
TTracciatoInvio::~TTracciatoInvio() TTracciatoInvio::~TTracciatoInvio()
{ {
} }
/*
///////////////////////////////////////////////////////////
// TTracciatiInvio
///////////////////////////////////////////////////////////
TTracciatiInvio _trcInvio; TTracciatiInvio _trcInvio;
const TTracciatoInvio& TTracciatiInvio::add_tracciato(TTracciatoInvio * tracciato) TTracciatiInvio & tracciati() { return _trcInvio; }
{
int pos = tracciato->tipo() - 'A';
const TTracciatoInvio* trc = (TTracciatoInvio*)_trc.objptr(pos);
if (trc == nullptr) class TTracciatiInvio : public TObject
_trc.add(tracciato, pos);
return *tracciato;
}
class TTracciatoInvioFileDati : public TTracciatoInvio
{ {
TArray _trc;
public: public:
TTracciatoInvioFileDati(const TRectype& rec); const TTracciatoInvio* tracciato(TTracciatoInvio * trc);
virtual ~TTracciatoInvioFileDati() {} const TTracciatoInvio& tracciato(TRecordInvio & rec);
int tipo2pos(int tipo) const;
bool exist(int tipo) const { return _trc.objptr(tipo2pos(tipo)) != nullptr; }
void destroy();
TTracciatiInvio();
virtual ~TTracciatiInvio();
}; };
TTracciatoInvioFileDati::TTracciatoInvioFileDati(const TRectype& rec) TTracciatiInvio & tracciati();
{
for (int i = 0; i < rec.items(); i++)
{
const TString16 fieldname(rec.rec_des().Fd[i].Name);
TFieldtypes t = rec.type(fieldname);
int pos = 0;
switch (t) const TTracciatoInvio * TTracciatiInvio::tracciato(TTracciatoInvio * trc)
{ {
case _nullfld: char tipo = trc->tipo();
break; int pos = tipo2pos(tipo);
case _alfafld: // @emem Campo di tipo alfanumerico
add_field(fieldname, AN, pos++, rec.length(fieldname)); if (!exist(tipo))
break; _trc.add(trc, pos);
case _intfld: // @emem Campo di tipo intero return (const TTracciatoInvio*)_trc.objptr(pos);
case _longfld: // @emem Campo di tipo intero lungo
add_field(fieldname, NU, pos++, rec.length(fieldname));
break;
case _realfld: // @emem Campo di tipo reale (vedi <c real>)
add_field(fieldname, NU/*QU*/, pos++, rec.length(fieldname));
break;
case _datefld: // @emem Campo di tipo data (vedi <c TDate>)
add_field(fieldname, DT, pos++, rec.length(fieldname));
break;
case _wordfld: // @emem Campo di tipo intero senza segno
add_field(fieldname, NU, pos++, rec.length(fieldname));
break;
case _charfld: // @emem Campo di tipo carattere
add_field(fieldname, AN, pos++, 1);
break;
case _boolfld: // @emem Campo di tipo booleano
add_field(fieldname, CB, pos++, rec.length(fieldname));
break;
case _intzerofld: // @emem Campo di tipo intero zero filled
case _longzerofld: // @emem Campo di tipo intero lungo zero filled
add_field(fieldname, NU, pos++, rec.length(fieldname));
break;
case _memofld:
add_field(fieldname, AN, pos++, rec.length(fieldname));
break;
}
}
} }
TTracciatiInvio & tracciati() {return _trcInvio;} const TTracciatoInvio& TTracciatiInvio::tracciato(TRecordInvio & rec)
{
char tipo = rec.tipo_record();
int pos = tipo2pos(tipo);
const TTracciatoInvio& TTracciatiInvio::tracciato(char tipo) if (!exist(tipo))
_trc.add(rec.add_tracciato(), pos);
return *(const TTracciatoInvio*)_trc.objptr(pos);
}
int TTracciatiInvio::tipo2pos(int tipo) const
{ {
CHECK((tipo >= 'A' && tipo <= 'Z') || tipo == '[', "Tipo record non valido"); CHECK((tipo >= 'A' && tipo <= 'Z') || tipo == '[', "Tipo record non valido");
const int pos = tipo - 'A'; return tipo - 'A';
const TTracciatoInvio* trc = (TTracciatoInvio*)_trc.objptr(pos);
if (trc == NULL)
trc = &tracciati().add_tracciato(new TTracciatoInvio(tipo));
return *trc;
} }
void TTracciatiInvio::destroy() void TTracciatiInvio::destroy()
@ -1248,20 +1240,56 @@ TTracciatiInvio::~TTracciatiInvio()
{ {
destroy(); // Non viene mai chiamato! destroy(); // Non viene mai chiamato!
} }
*/
TTracciatoInvioFileDati::TTracciatoInvioFileDati(const TRectype& rec)
{
for (int i = 0; i < rec.items(); i++)
{
const TString16 fieldname(rec.rec_des().Fd[i].Name);
TFieldtypes t = rec.type(fieldname);
switch (t)
{
case _nullfld:
break;
case _alfafld: // @emem Campo di tipo alfanumerico
add_field(fieldname, AN, rec.length(fieldname));
break;
case _intfld: // @emem Campo di tipo intero
case _longfld: // @emem Campo di tipo intero lungo
add_field(fieldname, NU, rec.length(fieldname));
break;
case _realfld: // @emem Campo di tipo reale (vedi <c real>)
add_field(fieldname, QU, rec.length(fieldname), rec.ndec(fieldname));
break;
case _datefld: // @emem Campo di tipo data (vedi <c TDate>)
add_field(fieldname, DT, rec.length(fieldname));
break;
case _wordfld: // @emem Campo di tipo intero senza segno
add_field(fieldname, NU, rec.length(fieldname));
break;
case _charfld: // @emem Campo di tipo carattere
add_field(fieldname, AN, 1);
break;
case _boolfld: // @emem Campo di tipo booleano
add_field(fieldname, CB, rec.length(fieldname));
break;
case _intzerofld: // @emem Campo di tipo intero zero filled
case _longzerofld: // @emem Campo di tipo intero lungo zero filled
add_field(fieldname, NU, rec.length(fieldname));
break;
case _memofld:
add_field(fieldname, AN, 512);
break;
}
}
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TRecordInvio // TRecordInvio
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
const TTracciatoInvio& TRecordInvio::tracciato() const
{
return _trcInvio.tracciato(tipo_record());
}
void TRecordInvio::print_on(ostream& outs) const
{
outs.write(_buffer, TOTAL_SIZE);
}
void TRecordInvio::read_from(istream& ins) void TRecordInvio::read_from(istream& ins)
{ {
@ -1269,14 +1297,11 @@ void TRecordInvio::read_from(istream& ins)
ins.read(_buffer.get_buffer(), TOTAL_SIZE); ins.read(_buffer.get_buffer(), TOTAL_SIZE);
} }
const TFieldInvio& TRecordInvio::get_field(int pos) const
{
return tracciato().field(pos);
}
void TRecordInvio::set(const TFieldInvio& fld, const char* val) void TRecordInvio::set(const TFieldInvio& fld, const char* val)
{ {
TString256 str(val); // Ci sono campi di 100 caratteri! TString str(val); // Ci sono campi di 100 caratteri!
if (fld._type == AN) if (fld._type == AN)
str.upper(); str.upper();
if (fld._type == QU) if (fld._type == QU)
@ -1317,42 +1342,55 @@ void TRecordInvio::set(const TFieldInvio& fld, const char* val)
_buffer.overwrite(str, fld._pos - 1); _buffer.overwrite(str, fld._pos - 1);
} }
void TRecordInvio::set(int pos, const char* val) void TRecordInvio::set(const char* name, const char* val)
{ {
const TFieldInvio& fld = tracciato().field(pos); const TFieldInvio& fld = tracciato().field(name);
set(fld, val); set(fld, val);
} }
void TRecordInvio::set(int pos, int val) void TRecordInvio::set(const char* name, int val)
{ {
const TFieldInvio& fld = tracciato().field(pos); const TFieldInvio& fld = tracciato().field(name);
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
CHECKS(fld._type == NU, "Invalid numeric field ", name);
TString16 str; str.format("%d", val); TString16 str; str.format("%d", val);
set(fld, str); set(fld, str);
} }
void TRecordInvio::set(int pos, long val) void TRecordInvio::set(const char* name, long val)
{ {
const TFieldInvio& fld = tracciato().field(pos); const TFieldInvio& fld = tracciato().field(name);
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
CHECKS(fld._type == NU, "Invalid numeric field ", name);
TString16 str; str.format("%ld", val); TString16 str; str.format("%ld", val);
set(fld, str); set(fld, str);
} }
void TRecordInvio::set(int pos, const real& val) void TRecordInvio::set(const char* name, const real& val)
{ {
const TFieldInvio& fld = tracciato().field(pos); const TFieldInvio& fld = tracciato().field(name);
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
CHECKS(fld._type == NU, "Invalid numeric field ", name);
const char* str = val.string(fld._len, 0); const char* str = val.string(fld._len, 0);
set(fld, str); set(fld, str);
} }
void TRecordInvio::set(int pos, const TDate& val) void TRecordInvio::set(const char* name, const TDate& val)
{ {
const TFieldInvio& fld = tracciato().field(pos); const TFieldInvio& fld = tracciato().field(name);
CHECKD(fld._type == NU && (fld._len == 6 || fld._len == 8),
"Invalid date field ", pos); CHECKS(fld._type == NU && (fld._len == 6 || fld._len == 8),
"Invalid date field ", name);
const char* str; const char* str;
if (fld._len == 8) if (fld._len == 8)
str = val.string(full, '\0', full, full, gma_date); str = val.string(full, '\0', full, full, gma_date);
else else
@ -1360,38 +1398,47 @@ void TRecordInvio::set(int pos, const TDate& val)
set(fld, str); set(fld, str);
} }
void TRecordInvio::set(int pos, char val) void TRecordInvio::set(const char* name, char val)
{ {
const TFieldInvio& fld = get_field(pos); const TFieldInvio& fld = get_field(name);
CHECKD(fld._type == AN && fld._len == 1, "Invalid char field ", pos);
CHECKS(fld._type == AN && fld._len == 1, "Invalid char field ", name);
const char str[2] = { val, '\0' }; const char str[2] = { val, '\0' };
set(fld, str); set(fld, str);
} }
void TRecordInvio::set(int pos, bool val) void TRecordInvio::set(const char* name, bool val)
{ {
const TFieldInvio& fld = get_field(pos); const TFieldInvio& fld = get_field(name);
CHECKD((fld._type == CB || fld._type == NU) && fld._len == 1, "Invalid boolean field ", pos);
CHECKS((fld._type == CB || fld._type == NU) && fld._len == 1, "Invalid boolean field ", name);
set(fld, val ? "1" : "0"); set(fld, val ? "1" : "0");
} }
const char* TRecordInvio::get(int pos, TString& str) const const char* TRecordInvio::get(const char* name, TString& str) const
{ {
const TFieldInvio& fld = get_field(pos); const TFieldInvio& fld = get_field(name);
str = _buffer.mid(fld._pos - 1, fld._len); str = _buffer.mid(fld._pos - 1, fld._len);
return str.trim(); return str.trim();
} }
int TRecordInvio::get_int(int pos) const int TRecordInvio::get_int(const char* name) const
{ {
TString16 str; get(pos, str); TString16 str; get(name, str);
return atoi(str); return atoi(str);
} }
char TRecordInvio::get_char(int pos) const char TRecordInvio::get_char(const char* name) const
{ {
const TFieldInvio& fld = get_field(pos); const TFieldInvio& fld = get_field(name);
CHECKD(fld._type == AN, "Invalid char field ", pos);
CHECKS(fld._type == AN, "Invalid char field ", name);
return _buffer[fld._pos - 1]; return _buffer[fld._pos - 1];
} }
@ -1411,10 +1458,21 @@ int TRecordInvio::calculate_blocks(const char* val) const
void TRecordInvio::tipo_record(char tipo) void TRecordInvio::tipo_record(char tipo)
{ {
_buffer[0] = tipo; tracciato().auto_fill(_buffer); _buffer[0] = tipo;
} }
// Azzera tutti i campi non posizionali dei record di tipo E const TRecordInvio& TRecordInvio::operator = (const TRecordInvio& rec)
{
_buffer = rec._buffer;
if (tipo_record() != rec.tipo_record())
{
safe_delete(_tracciato);
tracciato();
}
return *this;
}
// Azzera tutti i campi non posizionali
void TRecordInvio::azzera_campi_non_posizionali() void TRecordInvio::azzera_campi_non_posizionali()
{ {
CHECK(ha_campi_non_posizionali(), "Impossibile azzerare un record senza campi non posizionali"); CHECK(ha_campi_non_posizionali(), "Impossibile azzerare un record senza campi non posizionali");
@ -1422,30 +1480,41 @@ void TRecordInvio::azzera_campi_non_posizionali()
memset(buf, ' ', USEABLE_SIZE); memset(buf, ' ', USEABLE_SIZE);
} }
// Aggiunge un campo non posizionale ai record di tipo E,F,G,H,J // Aggiunge un campo non posizionale ai record
bool TRecordInvio::np_put(const char* code, const char* val) bool TRecordInvio::np_put(const char* code, const char* val)
{ {
CHECK(ha_campi_non_posizionali(), "Impossibile aggiungere campi non posizionali"); CHECK(ha_campi_non_posizionali(), "Impossibile aggiungere campi non posizionali");
CHECKS(code && strlen(code) == CODE_SIZE, "Invalid field code ", code); CHECKS(code && strlen(code) == CODE_SIZE, "Invalid field code ", code);
//CHECKS(val && *val, "Can't add empty field ", code); //CHECKS(val && *val, "Can't add empty field ", code);
if (!(val && *val))
return false;
// Cerca il primo posto libero bool ok = true;
int pos;
for (pos = HEADER_SIZE; pos < HEADER_SIZE + USEABLE_SIZE; pos += BLOCK_SIZE)
{
if (_buffer[pos] == ' ')
break;
}
const int free_blocks = (USEABLE_SIZE - pos) / BLOCK_SIZE;
const int needed_blocks = calculate_blocks(val);
const bool ok = free_blocks >= needed_blocks;
if (ok) // Se ci sono abbastanza blocchi liberi if (val && *val)
{ {
// Cerca il primo posto libero
int pos;
for (pos = HEADER_SIZE; pos < HEADER_SIZE + USEABLE_SIZE; pos += BLOCK_SIZE)
{
if (_buffer[pos] == ' ')
break;
}
const int free_blocks = (USEABLE_SIZE - pos) / BLOCK_SIZE;
const int needed_blocks = calculate_blocks(val);
bool ok = free_blocks >= needed_blocks;
TString80 str(val); str.upper(); TString80 str(val); str.upper();
const int lenstr = str.len();
if (!ok) // Se non ci sono abbastanza blocchi liberi
{
ok = true;
change_record();
pos = HEADER_SIZE;
if (str.len() > USEABLE_SIZE)
str.cut(USEABLE_SIZE);
}
int lenstr = str.len();
for (int i = 0; i < lenstr; ) for (int i = 0; i < lenstr; )
{ {
_buffer.overwrite(code, pos); _buffer.overwrite(code, pos);
@ -1468,53 +1537,53 @@ bool TRecordInvio::np_put(const char* code, const char* val)
bool TRecordInvio::np_put(const char* code, long val) bool TRecordInvio::np_put(const char* code, long val)
{ {
TString16 str; str.format("%16ld", val); TString16 str;
str.format("%16ld", val);
return np_put(code, str); return np_put(code, str);
} }
bool TRecordInvio::np_put(const char* code, const real& val) bool TRecordInvio::np_put(const char* code, const real& val)
{ {
bool done = !val.is_zero(); if (!val.is_zero())
if (done)
{ {
const TString& str = val.stringa(16, 2); const TString& str = val.stringa(16, 2);
done = np_put(code, str);
return np_put(code, str);
} }
return done; return true;
} }
bool TRecordInvio::np_put(const char* code, char val) bool TRecordInvio::np_put(const char* code, char val)
{ {
bool done = val > ' '; if (val > ' ')
if (done)
{ {
const char str[2] = { val, '\0' }; const char str[2] = { val, '\0' };
done = np_put(code, str);
return np_put(code, str);
} }
return done; return true;
} }
bool TRecordInvio::np_put(const char* code, const TDate& date) bool TRecordInvio::np_put(const char* code, const TDate& date)
{ {
bool done = date.ok(); if (date.ok())
if (done)
{ {
TString16 str; TString16 str;
str.format("%8s%02d%02d%04d", "", date.day(), date.month(), date.year()); str.format("%8s%02d%02d%04d", "", date.day(), date.month(), date.year());
done = np_put(code, str); return np_put(code, str);
} }
return done; return true;
} }
bool TRecordInvio::np_put(const char* code, bool cb) bool TRecordInvio::np_put(const char* code, bool cb)
{ {
bool done = false;
if (cb) if (cb)
{ {
TString16 str; str.format("%16d", 1); TString16 str; str.format("%16d", 1);
done = np_put(code, str); return np_put(code, str);
} }
return done; return true;
} }
bool TRecordInvio::np_get(int pos, TString& key, TString& val) const bool TRecordInvio::np_get(int pos, TString& key, TString& val) const
@ -1561,9 +1630,6 @@ bool TRecordInvio::valid() const
return ok; return ok;
} }
TRecordInvio::TRecordInvio(const TRectype& rec) : _buffer(TOTAL_SIZE, ' ') TRecordInvio::TRecordInvio(const TRectype& rec) : _buffer(TOTAL_SIZE, ' '), _tracciato(nullptr)
{ {
tracciati().add_tracciato(new TTracciatoInvioFileDati(rec)); }
}

View File

@ -216,7 +216,7 @@ enum { CODE_SIZE = 8, FIELD_SIZE = 16, BLOCK_SIZE = 24, HEADER_SIZE = 89, USEABL
// TRecordInvio // TRecordInvio
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
enum InvioFieldType { AN, CF, CN, PI, DA, DT, NU, PN, PR, CB, VP, VN, QU }; enum InvioFieldType { AN, CF, CN, PI, DA, D6, DT, NU, NP, PN, PR, CB, VP, VN, QU, FV /* FixVal */};
struct TFieldInvio : public TObject struct TFieldInvio : public TObject
{ {
@ -230,71 +230,55 @@ struct TFieldInvio : public TObject
class TTracciatoInvio : public TObject class TTracciatoInvio : public TObject
{ {
char _tipo; char _tipo;
TArray _fields; int _len;
TAssoc_array _fields;
protected: protected:
void add_field(const char* name, InvioFieldType tipo, int pos, int len, int dec = 0, int filedno = 0); void add_field(const char* name, InvioFieldType tipo, int len = 0, int dec = 0);
void add_filler(int pos, int len, InvioFieldType tipo = AN) { add_field("Filler", tipo, pos, len); } void add_fixedval(const char* name, int len, int filedno = 0) { add_field(name, FV, len); }
void add_filler(int len, InvioFieldType tipo = AN) { add_field("Filler", tipo, len); }
TTracciatoInvio() {} TTracciatoInvio() {}
void set_tipo(char t) { _tipo = t; } void set_tipo(char t) { _tipo = t; }
public: public:
bool exists(int pos) const { return _fields.objptr(pos - 1) != NULL; } bool exists(const char * name) const { return _fields.objptr(name) != nullptr; }
const TFieldInvio& field(int pos) const; const TFieldInvio& field(const char *name) const;
void auto_fill(TString& buffer) const; void zero(TString& buffer);
int campi_posizionali() const { return _fields.last() + 1; } int campi_posizionali() const { return _fields.items() + 1; }
char tipo() const { return _tipo; } char tipo() const { return _tipo; }
int len() const { return _len; }
TTracciatoInvio(char tipo); TTracciatoInvio(char tipo);
virtual ~TTracciatoInvio(); virtual ~TTracciatoInvio();
}; };
///////////////////////////////////////////////////////////
// TTracciatiInvio
///////////////////////////////////////////////////////////
class TTracciatiInvio : public TObject
{
TArray _trc;
public:
const TTracciatoInvio& tracciato(char tipo);
const TTracciatoInvio& add_tracciato(TTracciatoInvio * tracciato);
void destroy();
TTracciatiInvio();
virtual ~TTracciatiInvio();
};
TTracciatiInvio & tracciati();
class TRecordInvio : public TObject class TRecordInvio : public TObject
{ {
TString _buffer; TString _buffer;
TTracciatoInvio * _tracciato ;
protected: // TObject protected: // TObject
virtual TObject* dup() const { return new TRecordInvio(*this); } virtual TObject* dup() const { return new TRecordInvio(*this); }
virtual void print_on(ostream& outs) const; virtual void print_on(ostream& outs) const { outs.write(_buffer, TOTAL_SIZE); }
virtual void read_from(istream& ins); virtual void read_from(istream& ins);
protected: // TObject protected: // TObject
//virtual const TTracciatoInvio& add_tracciato(char tipo); virtual const TTracciatoInvio& tracciato() const { return *_tracciato; }
virtual const TTracciatoInvio& tracciato() const; const TFieldInvio& get_field(const char* name) const { return tracciato().field(name); }
const TFieldInvio& get_field(int pos) const;
void set(const TFieldInvio& fld, const char* val); void set(const TFieldInvio& fld, const char* val);
int calculate_blocks(const char* val) const; int calculate_blocks(const char* val) const;
public: public:
void set(int pos, const char* val); void zero() { ((TTracciatoInvio &)tracciato()).zero(_buffer); }
void set(int pos, int val);
void set(int pos, long val); void set(const char* name, const char* val);
void set(int pos, const real& val); void set(const char* name, int val);
void set(int pos, const TDate& val); void set(const char* name, long val);
void set(int pos, char val); void set(const char* name, const real& val);
void set(int pos, bool val); void set(const char* name, const TDate& val);
void set(const char* name, char val);
void set(const char* name, bool val);
bool np_put(const char* code, const char* val); bool np_put(const char* code, const char* val);
bool np_put(const char* code, const real& val); bool np_put(const char* code, const real& val);
bool np_put(const char* code, long val); bool np_put(const char* code, long val);
@ -302,20 +286,20 @@ public:
bool np_put(const char* code, const TDate& date); bool np_put(const char* code, const TDate& date);
bool np_put(const char* code, bool cb); bool np_put(const char* code, bool cb);
const char* get(int pos, TString& str) const; virtual bool change_record() { return false; }
int get_int(int pos) const;
char get_char(int pos) const; const char* get(const char* name, TString& str) const;
int get_int(const char* name) const;
char get_char(const char* name) const;
bool np_get(int pos, TString& key, TString& val) const; bool np_get(int pos, TString& key, TString& val) const;
bool np_get_real(int pos, TString& key, real& val) const; bool np_get_real(int pos, TString& key, real& val) const;
const TRecordInvio& operator=(const TRecordInvio& rec) const TRecordInvio& operator = (const TRecordInvio& rec);
{
_buffer = rec._buffer; return *this;
}
char tipo_record() const { return _buffer[0]; } char tipo_record() const { return _buffer[0]; }
void tipo_record(char tipo); void tipo_record(char tipo);
int len() const { return tracciato().len(); }
int campi_posizionali() const { return tracciato().campi_posizionali(); } int campi_posizionali() const { return tracciato().campi_posizionali(); }
void azzera_campi_non_posizionali(); void azzera_campi_non_posizionali();
@ -324,12 +308,27 @@ public:
virtual bool valid() const; virtual bool valid() const;
TRecordInvio() : _buffer(TOTAL_SIZE, ' ') {} TRecordInvio(char tipo) : _buffer(TOTAL_SIZE, ' '), _tracciato(nullptr) { tipo_record(tipo); }
TRecordInvio(char tipo) : _buffer(TOTAL_SIZE, ' ') { tipo_record(tipo); } TRecordInvio(const TRecordInvio& rec) : _buffer(rec._buffer), _tracciato(nullptr) { tracciato(); }
TRecordInvio(const TRecordInvio& rec) : _buffer(rec._buffer) { }
TRecordInvio(const TRectype& rec); TRecordInvio(const TRectype& rec);
virtual ~TRecordInvio() { }
}; };
class TTracciatoInvioFileDati : public TTracciatoInvio
{
public:
TTracciatoInvioFileDati(const TRectype& rec);
virtual ~TTracciatoInvioFileDati() {}
};
class TRecordInvioFileDati : public TRecordInvio
{
protected: // TObject
virtual TObject* dup() const { return new TRecordInvioFileDati(*this); }
public:
TRecordInvioFileDati(const TRectype& rec) : TRecordInvio('[') { }
virtual ~TRecordInvioFileDati() { }
};
#endif #endif