Migliorate segnalazioni d'errore e colorati gli sheet selezionabili

git-svn-id: svn://10.65.10.50/trunk@798 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-12-28 11:01:33 +00:00
parent 29d720bce7
commit 61afb17024
13 changed files with 2016 additions and 1930 deletions

View File

@ -1,113 +1,113 @@
#ifndef __APPLICATION_H
#define __APPLICATION_H
#ifndef INCL_XVTH
#include <xvt.h>
#endif
#ifndef __PRINTER_H
#include <printer.h>
#endif
// @C
// Classe TApplication
// @END
#define MSG_AI "AI" // message auto_insert (relapp)
#define MSG_FS "FS" // message filtered start (relapp)
#define MSG_LN "LN" // message (printapp -> relapp)
#define CHK_ALL -1 // all authorization checks
#define CHK_DONGLE 0 // dongle authorization checks
#define CHK_USER 1 // user authorization checks
class TApplication
{
// @DPRIV
int _bar;
int __argc;
const char** __argv;
TBit_array _dongle_aut;
TBit_array _user_aut;
TString80 _name, _title;
TPrinter* _printer;
long _savefirm;
bool _create_ok;
word _waiting;
static TString16 _user;
protected:
const char* get_module_name() const;
static long task_eh(WINDOW win, EVENT* ep);
virtual long handler(WINDOW win, EVENT* ep);
virtual bool extended_firm() const { return FALSE; } // Extended set_firm dialog box
virtual bool use_files() const { return TRUE; }
virtual bool create(); // Crea la finestra principale
virtual bool menu(MENU_TAG) { return TRUE; } // Controlla il menu
virtual bool build_firm_data(long cod, bool flagcom = FALSE) { return TRUE;}
virtual bool destroy(); // Rimuove l'applicazione
virtual void print();
virtual void on_config_change();
virtual void on_firm_change();
void set_user(const char * user) { _user = user; }
void set_perms();
void terminate();
bool config();
void about() const;
public:
// @FPUB
void setbar(int menubar) { _bar = menubar;} // Modifica la menu-bar
void run(int argc, char* argv[], const char* name);
// @DES Queste funzioni possono essere ridefinite da ogni applicazione
// @FPUB
virtual word class_id() const { return CLASS_APPLICATION; }
void stop_run(); // Forza chiusura applicazione
void check_menu_item(MENU_TAG item); // Check menu
void uncheck_menu_item(MENU_TAG item); // Uncheck
void enable_menu_item(MENU_TAG item, bool on = TRUE);
void disable_menu_item(MENU_TAG item) { enable_menu_item(item, FALSE); }
void dispatch_e_menu(MENU_TAG item);
const TString& name() const { return _name; }
const char** argv() const { return __argv; }
const char* argv(int i) const { return __argv[i]; }
int argc() const { return __argc; }
void set_title(const char* t) { _title = t; }
const TString& title() const { return _title; }
TPrinter* set_printer(TPrinter* p);
TPrinter& printer();
static void check_parameters(int & argc, char *argv[]);
const TString& user() const { return _user; }
bool has_module(int module, int checktype = CHK_ALL) const;
bool set_firm(long cod = -1);
long get_firm() const;
const char* get_firm_dir() const;
void wait_for(word taskid) { _waiting = taskid; }
void wake_up() { _waiting = 0; }
word waiting() const { return _waiting; }
TApplication();
virtual ~TApplication();
};
bool xvt_running(); // xvt is running?
TApplication* MainApp(); // main application (old fashioned: will be removed soon
TApplication& main_app();
#endif // __APPLICATION_H
#ifndef __APPLICATION_H
#define __APPLICATION_H
#ifndef INCL_XVTH
#include <xvt.h>
#endif
#ifndef __PRINTER_H
#include <printer.h>
#endif
// @C
// Classe TApplication
// @END
#define MSG_AI "AI" // message auto_insert (relapp)
#define MSG_FS "FS" // message filtered start (relapp)
#define MSG_LN "LN" // message (printapp -> relapp)
#define CHK_ALL -1 // all authorization checks
#define CHK_DONGLE 0 // dongle authorization checks
#define CHK_USER 1 // user authorization checks
class TApplication
{
// @DPRIV
int _bar;
int __argc;
const char** __argv;
TBit_array _dongle_aut;
TBit_array _user_aut;
TString80 _name, _title;
TPrinter* _printer;
long _savefirm;
bool _create_ok;
word _waiting;
static TString16 _user;
protected:
const char* get_module_name() const;
static long task_eh(WINDOW win, EVENT* ep);
virtual long handler(WINDOW win, EVENT* ep);
virtual bool extended_firm() const { return FALSE; } // Extended set_firm dialog box
virtual bool use_files() const { return TRUE; }
virtual bool create(); // Crea la finestra principale
virtual bool menu(MENU_TAG) { return TRUE; } // Controlla il menu
virtual bool build_firm_data(long cod, bool flagcom = FALSE) { return TRUE;}
virtual bool destroy(); // Rimuove l'applicazione
virtual void print();
virtual void on_config_change();
virtual void on_firm_change();
void set_user(const char * user) { _user = user; }
void set_perms();
void terminate();
bool config();
void about() const;
public:
// @FPUB
void setbar(int menubar) { _bar = menubar;} // Modifica la menu-bar
void run(int argc, char* argv[], const char* name);
// @DES Queste funzioni possono essere ridefinite da ogni applicazione
// @FPUB
virtual word class_id() const { return CLASS_APPLICATION; }
void stop_run(); // Forza chiusura applicazione
void check_menu_item(MENU_TAG item); // Check menu
void uncheck_menu_item(MENU_TAG item); // Uncheck
void enable_menu_item(MENU_TAG item, bool on = TRUE);
void disable_menu_item(MENU_TAG item) { enable_menu_item(item, FALSE); }
void dispatch_e_menu(MENU_TAG item);
const TString& name() const { return _name; }
const char** argv() const { return __argv; }
const char* argv(int i) const { return __argv[i]; }
int argc() const { return __argc; }
void set_title(const char* t) { _title = t; }
const TString& title() const { return _title; }
TPrinter* set_printer(TPrinter* p);
TPrinter& printer();
static void check_parameters(int & argc, char *argv[]);
const TString& user() const { return _user; }
bool has_module(int module, int checktype = CHK_ALL) const;
bool set_firm(long cod = -1);
long get_firm() const;
const char* get_firm_dir() const;
void wait_for(word taskid) { _waiting = taskid; }
void wake_up() { _waiting = 0; }
word waiting() const { return _waiting; }
TApplication();
virtual ~TApplication();
};
bool xvt_running(); // xvt is running?
TApplication* MainApp(); // main application (old fashioned: will be removed soon
TApplication& main_app();
#endif // __APPLICATION_H

View File

@ -1,3 +1,64 @@
<<<<<<< checks.h
#ifndef __CHECKS_H
#define __CHECKS_H
#ifdef __cplusplus
extern "C" {
#endif
/* @FPUB */
int message_box(const char* fmt, ...);
int warning_box(const char* fmt, ...);
int sorry_box(const char* fmt, ...);
int error_box(const char* fmt, ...);
int fatal_box(const char* fmt, ...);
int yesno_box(const char* fmt, ...);
int yesnocancel_box(const char* fmt, ...);
int yesnofatal_box(const char* fmt, ...);
int __trace(const char* fmt, ...);
/* @END */
#ifdef __cplusplus
}
#endif
/* @M
Utilizzate in fase di debug (definire il simbolo DBG in compilazione)
*/
#ifdef DBG
#define CHECK(p, m) ( (p) ? (void)0 : (void) fatal_box( \
"Check failed in %s, line %d:\n\r%s", \
__FILE__, __LINE__, m) )
#define CHECKS(p, m, s0) ( (p) ? (void)0 : (void) fatal_box( \
"Check failed in %s, line %d:\n\r%s%s", \
__FILE__, __LINE__, m, s0) )
#define CHECKD(p, m, d0) ( (p) ? (void)0 : (void) fatal_box( \
"Check failed in %s, line %d:\n\r%s%d", \
__FILE__, __LINE__, m, d0) )
#else
#define CHECK(p, m)
#define CHECKS(p, m, s)
#define CHECKD(p, m, d)
#endif
/* @END */
/* @M
Utilizzata in fase di debug (definire il simbolo TRC in compilazione)
*/
#ifdef TRC
#define TRACE __trace
#else
#define TRACE 1 ? 0 : __trace
#endif
/* @END */
#endif // __CHECKS_H
=======
#ifndef __CHECKS_H
#define __CHECKS_H
@ -57,3 +118,4 @@ Utilizzata in fase di debug (definire il simbolo TRC in compilazione)
/* @END */
#endif // __CHECKS_H
>>>>>>> 1.3

View File

@ -1,34 +1,34 @@
// execp.h; trattasi di -*-c++-*-
// fv 6/10/93
#ifndef __EXECP_H
#define __EXECP_H
#ifndef __OBJECT_H
#include <object.h>
#endif
// Class for external object execution with optional background
// exec under UNIX and swap on EMS under DOS
// Manages restoring the XVT status
// No command line is implemented; user is supposed to use the
// mailbox for this
class TExternal_app : public TObject
{
const char* _path; // app name (must be allocated by user)
int _error; // last error (errno code)
int _exitcode; // last exit code
int _count; // count of calls
public:
bool can_run() const;
int run(bool async = FALSE, bool user = TRUE);
int error() { return _error;};
int exitcode() { return _exitcode;};
int count() { return _count; };
TExternal_app(const char* p);
};
#endif
// execp.h; trattasi di -*-c++-*-
// fv 6/10/93
#ifndef __EXECP_H
#define __EXECP_H
#ifndef __OBJECT_H
#include <object.h>
#endif
// Class for external object execution with optional background
// exec under UNIX and swap on EMS under DOS
// Manages restoring the XVT status
// No command line is implemented; user is supposed to use the
// mailbox for this
class TExternal_app : public TObject
{
const char* _path; // app name (must be allocated by user)
int _error; // last error (errno code)
int _exitcode; // last exit code
int _count; // count of calls
public:
bool can_run() const;
int run(bool async = FALSE, bool user = TRUE);
int error() { return _error;};
int exitcode() { return _exitcode;};
int count() { return _count; };
TExternal_app(const char* p);
};
#endif

View File

@ -770,21 +770,25 @@ bool TForm_list::update()
if (!read()) return ok;
const TString& val =get();
const int pos = _codes.get_pos(val);
int pos = _codes.get_pos(val);
if (pos < 0)
{
ok = error_box("Il campo '%s' non puo' valere '%s'",
ok = yesno_box("Il campo '%s' non puo' valere '%s': continuare ugualmente",
(const char*)key(), (const char*)val);
}
else do_message(pos);
if (!hidden())
{
const char* c = _values.get(pos);
if (c == NULL) c = val;
if (c) string_at(_x, _y, c);
set(_codes.get(pos = 0));
}
if (ok)
{
do_message(pos);
if (!hidden())
{
const char* c = _values.get(pos);
if (c == NULL) c = val;
if (c) string_at(_x, _y, c);
}
}
return ok;
}
@ -881,11 +885,11 @@ bool TPrint_section::update()
const bool esito = field(i).update();
if (!esito) ok = FALSE;
}
const word l = last()-1;
if (l >= _height)
ok = warning_box("Sezione troppo lunga: %d > %d", l, _height);
#ifdef DBG
const int l = last()-1;
if (l >= (int)_height)
warning_box("Sezione troppo lunga: %d > %d", l+1, _height);
#endif
return ok;
}
@ -1046,6 +1050,30 @@ bool TForm::parse_join(TScanner& scanner)
}
TPrint_section* TForm::exist(char s, pagetype t, bool create)
{
TArray* a = NULL;
switch (s)
{
case 'H':
a = &_head; break;
case 'F':
a = &_foot; break;
default:
a = &_body; break;
}
TPrint_section* sec = (TPrint_section*)a->objptr(t);
if (sec == NULL && create)
{
sec = new TPrint_section(this);
a->add(sec, t);
}
return sec;
}
TPrint_section& TForm::section(char s, word p)
{
pagetype pos = odd_page;
@ -1053,11 +1081,11 @@ TPrint_section& TForm::section(char s, word p)
if (p == 1 && exist(s, first_page)) pos = first_page;
if (pos == 0 && (p & 0x1) == 0 && exist(s, even_page)) pos = even_page;
TPrint_section* sec = exist(s, pos);
CHECKD(sec, "Can't find section for page ", p);
TPrint_section* sec = exist(s, pos, TRUE);
return *sec;
}
word TForm::set_header(word p, bool u)
{
TPrinter& printer = main_app().printer();
@ -1081,7 +1109,7 @@ word TForm::set_header(word p, bool u)
word TForm::set_body(word p, bool u)
{
TPrint_section& body = section('B', p);
if (u) body.update();
else body.reset();
@ -1139,7 +1167,7 @@ word TForm::page(const TPrinter& p) const
long TForm::records() const
{
const long r = _cursor ? _cursor->items() : 0;
return 0;
return r;
}
// Stampa gli items dal from a to
@ -1199,7 +1227,7 @@ void TForm::print_section(ostream& out, char s) const
for (pagetype t = odd_page; t <= last_page; t = pagetype(t+1))
{
const TPrint_section* sec = ((TForm*)this)->exist(s, t);
if (sec)
if (sec && sec->ok())
{
const char* name = s == 'H' ? "HEADER" : (s == 'F' ? "FOOTER" : "BODY");
out << "SECTION " << name << ' ' << int(t);
@ -1222,29 +1250,6 @@ void TForm::print_on(ostream& out) const
}
TPrint_section* TForm::exist(char s, pagetype t, bool create)
{
TArray* a = NULL;
switch (s)
{
case 'H':
a = &_head; break;
case 'F':
a = &_foot; break;
default:
a = &_body; break;
}
TPrint_section* sec = (TPrint_section*)a->objptr(t);
if (sec == NULL && create)
{
sec = new TPrint_section(this);
a->add(sec, t);
}
return sec;
}
word TForm::height()
{
word h = 0;

View File

@ -1,114 +1,115 @@
#ifndef __FORM_H
#define __FORM_H
#ifndef __PRINTER_H
#include <printer.h>
#endif
#ifndef __SCANNER_H
#include <scanner.h>
#endif
#ifndef __MASK_H
class TMask;
#endif
#ifndef __RELATION_H
class TRelation;
class TCursor;
#endif
enum pagetype { odd_page, even_page, first_page, last_page };
class TForm;
class TForm_item;
class TPrint_section : public TArray
{
static TMask* _msk;
word _height; // Altezza della sezione
TForm* _form; // Form cui appartiene alla sezione
TArray _item; // Lista dei campi da stampare
const TPrint_section& copy(const TPrint_section& ps);
protected:
virtual void print_on(ostream& out) const;
TForm_item* parse_item(const TString& key);
TForm_item* parse_item(TScanner& scanner);
public:
TPrintrow& row(int num);
TForm* form() const { return _form; }
TForm_item& field(int n) const { return (TForm_item&)_item[n]; }
word fields() const { return _item.items(); }
word height() const { return _height; }
void reset();
bool update();
bool parse(TScanner& scanner);
bool edit(const char* title);
const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); }
TPrint_section(TForm* parent);
TPrint_section(const TPrint_section& ps) { copy(ps); }
virtual ~TPrint_section();
};
class TForm : public TObject
{
friend class TForm_editor;
TFilename _name; // Profile name
TRelation* _relation; // Can be NULL
TCursor* _cursor; // Can be NULL
TArray _head; // Headers
TArray _body; // Bodies
TArray _foot; // Footers
bool _lastpage; // I am about to print the last page
TPrint_section* exist(char s, pagetype t, bool create = FALSE); // Can be NULL
static void header_handler(TPrinter& p);
static void footer_handler(TPrinter& p);
protected:
// H = Header, B = Body, F = Footer, R = Relation
TPrint_section& section(char s = 'B', word page = 1);
word height(); // Height of first page
void print_section(ostream& out, char s) const;
virtual void print_on(ostream& out) const;
bool edit_relation();
bool parse_use(TScanner&);
bool parse_join(TScanner&);
word page(const TPrinter& p) const;
virtual long records() const;
virtual word set_header(word p, bool u);
virtual word set_body(word p, bool u);
virtual word set_footer(word p, bool u);
public:
bool print(long from = 0L, long to = -1L);
const TFilename& name() const { return _name; }
TRelation* relation() const { return _relation; }
TCursor* cursor() const { return _cursor; }
TForm(const char* form);
virtual ~TForm();
};
#endif
#ifndef __FORM_H
#define __FORM_H
#ifndef __PRINTER_H
#include <printer.h>
#endif
#ifndef __SCANNER_H
#include <scanner.h>
#endif
#ifndef __MASK_H
class TMask;
#endif
#ifndef __RELATION_H
class TRelation;
class TCursor;
#endif
enum pagetype { odd_page, even_page, first_page, last_page };
class TForm;
class TForm_item;
class TPrint_section : public TArray
{
static TMask* _msk;
word _height; // Altezza della sezione
TForm* _form; // Form cui appartiene alla sezione
TArray _item; // Lista dei campi da stampare
const TPrint_section& copy(const TPrint_section& ps);
protected:
virtual void print_on(ostream& out) const;
TForm_item* parse_item(const TString& key);
TForm_item* parse_item(TScanner& scanner);
public:
TPrintrow& row(int num);
TForm* form() const { return _form; }
TForm_item& field(int n) const { return (TForm_item&)_item[n]; }
word fields() const { return _item.items(); }
word height() const { return _height; }
virtual bool ok() const { return height() > 0 || fields() > 0; }
void reset();
bool update();
bool parse(TScanner& scanner);
bool edit(const char* title);
const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); }
TPrint_section(TForm* parent);
TPrint_section(const TPrint_section& ps) { copy(ps); }
virtual ~TPrint_section();
};
class TForm : public TObject
{
friend class TForm_editor;
TFilename _name; // Profile name
TRelation* _relation; // Can be NULL
TCursor* _cursor; // Can be NULL
TArray _head; // Headers
TArray _body; // Bodies
TArray _foot; // Footers
bool _lastpage; // I am about to print the last page
TPrint_section* exist(char s, pagetype t, bool create = FALSE); // Can be NULL
static void header_handler(TPrinter& p);
static void footer_handler(TPrinter& p);
protected:
// H = Header, B = Body, F = Footer, R = Relation
TPrint_section& section(char s = 'B', word page = 1);
word height(); // Height of first page
void print_section(ostream& out, char s) const;
virtual void print_on(ostream& out) const;
bool edit_relation();
bool parse_use(TScanner&);
bool parse_join(TScanner&);
word page(const TPrinter& p) const;
virtual long records() const;
virtual word set_header(word p, bool u);
virtual word set_body(word p, bool u);
virtual word set_footer(word p, bool u);
public:
bool print(long from = 0L, long to = -1L);
const TFilename& name() const { return _name; }
TRelation* relation() const { return _relation; }
TCursor* cursor() const { return _cursor; }
TForm(const char* form);
virtual ~TForm();
};
#endif

View File

@ -1,493 +1,493 @@
#ifndef __ISAM_H
#define __ISAM_H
#ifndef __SYSFLD_H
#include <sysfld.h>
#endif
#ifndef FOXPRO
#ifndef __REAL_H
#include <real.h>
#endif
#endif
#ifndef __DATE_H
#include <date.h>
#endif
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __FILES_H
#include <files.h>
#endif
#ifndef __LFFILES_H
#include <lffiles.h>
#endif
// @M
#define FIELDERR -1
const int MAX_KEYS = 8;
// @END
// @C
// Classe TRectype : public TObject
//
// Tipo record
//
// @END
class TRectype : public TSortable
{
friend class TExtrectype;
friend class TRecfield;
friend class TBaseisamfile;
friend class TLocalisamfile;
friend class TIsamtempfile;
// DPRIV
char* _rec; // Puntatore a inizio record
int _logicnum; // Numero logico
int _length; // Lunghezza
isdef* _i; // Puntatore al file isam
bool _isempty; // Se il record e' vuoto
char _tab[5]; // identificatore della tabella
TRecfield * _cod; // campo "COD" della tabella
// @END
protected:
// FPROT
const char* start(int nf) const;
void setempty(bool val) { _isempty = val;} // Rende vero is_empty
virtual TObject* dup() const; // Duplica record
virtual int compare(const TSortable& s) const;
// @END
public:
// FPUB
int items() const;
void setdirty() { setempty(FALSE); }
void settab(const char *tab);
char* string() const { return _rec;} // Ritorna il puntatore all'inizio. NON dovrebbe essere usata!
void discard() { *_rec = char(_deleted);} // Setta il flag di cancellazione
void recall() { *_rec = char(_valid);} // Ripristina il flag di cancellazione
bool isdeleted() const { return *_rec == _deleted;} // Chiede se e' cancellato
int len() const { return _length;} // Ritorna la lunghezza
TFieldtypes type(const char* fieldname) const; // Ritorna il tipo del campo
int length(const char* fieldname) const; // Ritorna lunghezza campo
int ndec(const char* fieldname) const; // Ritorna numero di decimali
bool exist(const char* fieldname) const; // Ritorna l'esistenza del campo
const char* fieldname(int i) const; // Ritorna il nome del campo i
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
#ifndef FOXPRO
int get_int(const char* fieldname) const ;
long get_long(const char* fieldname) const ;
word get_word(const char* fieldname) const ;
char get_char(const char* fieldname) const ;
bool get_bool(const char* fieldname) const ;
real get_real(const char* fieldname) const ;
#endif
TDate get_date(const char* fieldname) const ;
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
const TString& get(const char* fieldname) const ;
// @DES Put tipizzata
// @FPUB
#ifndef FOXPRO
void put(const char* fieldname, int val);
void put(const char* fieldname, long val);
void put(const char* fieldname, word val);
void put(const char* fieldname, const TDate& val);
void put(const char* fieldname, char val);
void put(const char* fieldname, bool val);
void put(const char* fieldname, const real& val);
#endif
// @DES Put NON tipizzata
// @FPUB
void put(const char* fieldname, const char* val);
// void put(const char* fieldname, TString& val);
void zero(const char * fieldname); // Vuota campo puntato da fieldname
void zero(); // Vuota tutto il record
void zero(char c); // Vuota tutto il record usando il carattere c
TRectype& operator =(const TRectype& rec); // assegnazione tra TRectype
TRectype& operator =(const char* rec); // assegnazione tra TRectype
TRectype& operator =(const TBaseisamfile& f);
const isdef* filehnd() const { return _i; } // Ritorna il file isam associato
int num() const { return _logicnum;} // Ritorna il numero logico
bool empty() const {return _isempty;} // Ritorna se e' vuoto
bool valid() const {return _rec[0] == 0;} // Ritorna se il record non e'cancellato
const char* key(int numkey = 1) const; // Ritorna l'espressione della chiave numero numkey
bool ok() const { return _i != NULL;}
TRectype(int logicnum); // Costruisce un record staccato da un file. Bisogna poi chiamare linkfile(). Sarebbe meglio utilizzare una delle altre due
TRectype(const TBaseisamfile* i); // Costruisce record e lo associa al file isam i
TRectype(const TRectype& r); // Costruisce il record a partire da r
virtual ~TRectype();
};
// @C
// Classe TBaseisamfile : public TObject
//
// File isam di base
//
// @END
class TBaseisamfile : public TObject
{
// @DPRIV
isdef* _isamfile; // Descrittore file isam
int _logicnum; // Numero logico del record corrente
int _lasterr; // Ultimo errore
bool _delrec; // Per sapere se rimuovere il record alla fine
bool _delopenrec; // Per sapere se rimuovere il record alla fine dalla lista interna di record
TRectype* _current; // Puntatore a record corrente
TFile _hf;
TFile _hfhd;
bool _historicfile; // Vero se il file e' archivio storico
TRecnotype _lasthf;
TRecnotype _recno;
friend class TRectype;
friend class TLocalisamfile;
friend class TIsamfile;
friend class TIsamtempfile;
friend class TRecfield;
// friend class TCursor;
// @END
// @FPRIV
// friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp);
// friend TRecnotype __filtercursor(TFilecursor* tic);
// friend bool __evalcondition(TBaseisamfile* i,TString& condition);
// friend void __readrec(TFilecursor* tic);
int gethr(TRectype& rec, TDate& atdate);
int addhr(const TRectype& rec, TDate& atdate);
int rewhr(const TRectype& rec, TDate& atdate);
int delhr(const TRectype& rec, TDate& atdate);
protected:
// @FPROT
isdef** ptrfilehnd() const { return (isdef**) &_isamfile;}
void clearfilehnd() { _isamfile = NULL;}
void recover();
int _open(unsigned int mode = _manulock); // Apre isam file con lock
int _close();
const char* filename() const;
public:
// @FPUB
void setkey(int nkey); // Attiva una chiave
int getkey() const; // Ritorna la chiave
void setstatus(int status) { _lasterr = status; } // Setta _lasterr
virtual int first(word lockop = _nolock);
virtual int last(word lockop = _nolock);
virtual int next(word lockop = _nolock);
virtual int next(TDate& atdate);
virtual int prev(word lockop = _nolock);
virtual int prev(TDate& atdate);
virtual int reread(word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int skip(TRecnotype nrec, word lockop = _nolock);
virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int readat(TRecnotype nrec, word lockop = _nolock);
virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock);
virtual int write(TDate& atdate = (TDate&)botime);
virtual int write(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewrite(TDate& atdate = (TDate&)botime);
virtual int rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewriteat(TRecnotype nrec);
virtual int rewriteat(const TRectype& rec, TRecnotype nrec);
virtual int remove(TDate& atdate = (TDate&)botime);
virtual int remove(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual const char* name() const;
TRecnotype recno() const { return _recno;}
int lock(); // Attiva lock di tutto il file
int unlock(); // Disattiva lock di tutto il file
void indexon(); // Accende gli indici
void indexoff(); // Spegne gli indici
int status() const { return _lasterr; } // Ritorna _lasterr
TRectype& curr() const {return *_current;} // Ritorna puntatore a record corrente
bool eof() const { return status() == _iseof || status() == _isemptyfile;} // Vero se siamo a fine file
bool bof() const { return status() == _isbof || status() == _isemptyfile;} // Vero se siamo a inizio file
bool good() const { return status() == NOERR;} // Vero se _lasterr non contiene codici d'errore
bool bad() const { return status() != NOERR;} // Vero se _lasterr contiene codici d'errore
bool empty(); // Vero se il file e' vuoto
int num() const { return _logicnum;} // Ritorna il numero logico del record corrente
const char* description() const;
TRecnotype eod() const { return filehnd()->d->EOD;}
isdef* filehnd() const { return (isdef*) _isamfile;} // Ritorna l'handle del file isam nella tabella
long items() const; // n.o di records nel file
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
#ifndef FOXPRO
int get_int(const char* fieldname) const
{ return curr().get_int(fieldname);}
long get_long(const char* fieldname) const
{ return curr().get_long(fieldname);}
word get_word(const char* fieldname) const
{ return curr().get_word(fieldname);}
char get_char(const char* fieldname) const
{ return curr().get_char(fieldname);}
bool get_bool(const char* fieldname) const
{ return curr().get_bool(fieldname);}
real get_real(const char* fieldname) const
{ return curr().get_real(fieldname);}
#endif
TDate get_date(const char* fieldname) const
{ return curr().get_date(fieldname);}
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
const TString& get(const char* fieldname) const
{ return curr().get(fieldname);}
// @DES Put NON tipizzata
// @FPUB
#ifndef FOXPRO
void put(const char* fieldname, int val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, long val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, word val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, const TDate& val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, char val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, bool val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, const real& val)
{ curr().put(fieldname, val);}
#endif
// @DES Put NON tipizzata
// @FPUB
void put(const char* fieldname, const char* val)
{ curr().put(fieldname, val);}
void zero(const char * fieldname) { curr().zero(fieldname);}
void zero() { curr().zero();}
void zero(char c) { curr().zero(c);}
TRectype& operator =(const TRectype& rec) { return curr() = rec;}
TBaseisamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TBaseisamfile();
};
// @C
// Classe TIsamfile : public TBaseisamfile
//
// File isam
//
// @END
class TIsamfile : public TBaseisamfile
{
public:
// @FPUB
int flags(bool updateeod = FALSE);
int open(unsigned int mode = _manulock) { return _open(mode);} // Apre isam file con lock
int close() { return _close();}
TIsamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TIsamfile();
};
// @C
// Classe TIsamtempfile : public TBaseisamfile
//
// File isam temporaneo
//
// @END
class TIsamtempfile : public TBaseisamfile
{
public:
// @FPUB
int open(char* radix, bool create = TRUE, TRecnotype eod = 0,
TRecnotype eox = 100); // Apre il file. radix e' la radice del path del file, se create e' falso vuol dire che il file esiste gia', e allora eod dice quanti record ci sono; eox quanti bisogna aggiungerne
int close(bool flagdel = TRUE); // Chiude il file e se e' vero flagdel lo cancella
TIsamtempfile(int logicnum, bool linkrecinst = FALSE);
virtual ~TIsamtempfile();
};
// @C
// Classe TSystemisamfile : public TBaseisamfile
//
// @END
class TSystemisamfile : public TIsamfile
{
TArray _flds;
TArray _exps;
bool getlcf(long flev);
bool exec_convapp(long flev, const bool before);
void makelc(TRectype& rec);
public:
// @FPUB
int build(TRecnotype eox); // Costruisce un file isam
int extend(TRecnotype eox); // Estende un file preesistente
long size(TRecnotype eox); // Calcola lo spazio che il file occuperebbe se venisse esteso a eox
int update(TTrec& newrec, bool vis = TRUE);
int packfile(bool vis = TRUE); // Rimuove fisicamente i record cancellati
int packindex(bool vis = TRUE); // La stessa cosa sugli indici
// @DES Importa un file ascii. from e' il nome del file da importare
int load(const char* from, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool extended = FALSE) ;
// @DES Esporta VERSO un file ascii.
int dump(const char* to, int nkey = 1, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool withdeleted = FALSE);
TSystemisamfile(int logicnum, bool linkrecinst = TRUE)
: TIsamfile(logicnum, linkrecinst) {}
virtual ~TSystemisamfile() {}
};
// @C
// Classe TLocalisamfile : public TBaseisamfile
//
// @END
class TLocalisamfile : public TBaseisamfile
{
// @DPRIV
bool _was_open; // Vero se il file e' stato aperto come Localisamfile
bool _isatab; // Vero se il file e' una tabella
public:
// @FPUB
virtual int operator +=(const TRecnotype npos); // Avanza npos record
virtual int operator -=(const TRecnotype npos); // Sposta indietro di npos
virtual int operator ++(); // record successivo
virtual int operator --(); // record precedente
bool tab() const { return _isatab;} // Ritorna vero se tabella
void settab(bool fl = FALSE) { _isatab = fl;} // Setta il flag _isatab
int open(unsigned int mode = _manulock);
int close() ;
// Costruttore. linkrecinst dice se il file deve utilizzare un area record separata oppure la stessa.
TLocalisamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TLocalisamfile();
};
// @C
// Classe TRec_array : public TArray
//
// @END
class TRec_array : public TArray
{
public:
// @FPUB
TRec_array(int dimension, TBaseisamfile& i);
};
// @C
// Classe TRecfield : public TObject
//
// @END
class TRecfield : public TObject
{
// @DPRIV
char _name[12]; // Nome campo
TRectype* _rec; // Puntatore a inizio record
char* _p; // Puntatore a inizio campo
byte _len; // Lunghezza campo
byte _dec; // Numero di decimali
byte _type; // Tipo del campo
// @END
// @FPRIV
void set(int from, int to);
public:
// @FPUB
// @DES Operatore di assegnazione (=) per i vari tipi
// @FPUB
int operator =(int i) ;
long operator =(long l) ;
const TDate& operator =(const TDate& d) ;
const char* operator =(const char* s) ;
#ifndef FOXPRO
const real& operator =(const real& r) ;
#endif // FOXPRO
// @DES Operatore di estrazione per i vari tipi
// @FPUB
operator int() const ;
operator long() const ;
operator const char*() const ;
operator TDate() const ;
#ifndef FOXPRO
operator const real() const ;
#endif // FOXPRO
void setptr(TRecnotype r); // Scrive un campo packed. Sarebbe meglio non usare mai campi packed.
TRecnotype ptr() const; // Legge un campo packed. Sarebbe meglio non usare mai campi packed.
const char* pos() const { return (const char*) _p;} // Ritorna un puntatore all'inizio del campo nel record. Dovrebbe essere protected!
int len() const { return (int) _len;} // Ritorna la lunghezza
int dec() const { return (int) _dec;} // Ritorna il numero di decimali
TFieldtypes type() const { return (TFieldtypes) _type;} // Ritorna il tipo del campo
TRectype& record() const { return *_rec;} // Ritorna puntatore a inizio record
TRecfield(TRectype& rec, const char* name, int from = 0, int to = -1);
};
// @C
// Classe TTransaction
//
// @END
class TTransaction
{
public:
// @FPUB
void begin();
void end(bool success = TRUE);
void abort() { end(FALSE);}
};
#ifdef __ISAM_CPP
#define extern
#endif
// @DPUB
extern TTransaction transaction;
extern TRectype** openrec;
// @END
#undef extern
void set_autoload_new_files(bool on);
#endif // __ISAM_
#ifndef __ISAM_H
#define __ISAM_H
#ifndef __SYSFLD_H
#include <sysfld.h>
#endif
#ifndef FOXPRO
#ifndef __REAL_H
#include <real.h>
#endif
#endif
#ifndef __DATE_H
#include <date.h>
#endif
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __FILES_H
#include <files.h>
#endif
#ifndef __LFFILES_H
#include <lffiles.h>
#endif
// @M
#define FIELDERR -1
const int MAX_KEYS = 8;
// @END
// @C
// Classe TRectype : public TObject
//
// Tipo record
//
// @END
class TRectype : public TSortable
{
friend class TExtrectype;
friend class TRecfield;
friend class TBaseisamfile;
friend class TLocalisamfile;
friend class TIsamtempfile;
// DPRIV
char* _rec; // Puntatore a inizio record
int _logicnum; // Numero logico
int _length; // Lunghezza
isdef* _i; // Puntatore al file isam
bool _isempty; // Se il record e' vuoto
char _tab[5]; // identificatore della tabella
TRecfield * _cod; // campo "COD" della tabella
// @END
protected:
// FPROT
const char* start(int nf) const;
void setempty(bool val) { _isempty = val;} // Rende vero is_empty
virtual TObject* dup() const; // Duplica record
virtual int compare(const TSortable& s) const;
// @END
public:
// FPUB
int items() const;
void setdirty() { setempty(FALSE); }
void settab(const char *tab);
char* string() const { return _rec;} // Ritorna il puntatore all'inizio. NON dovrebbe essere usata!
void discard() { *_rec = char(_deleted);} // Setta il flag di cancellazione
void recall() { *_rec = char(_valid);} // Ripristina il flag di cancellazione
bool isdeleted() const { return *_rec == _deleted;} // Chiede se e' cancellato
int len() const { return _length;} // Ritorna la lunghezza
TFieldtypes type(const char* fieldname) const; // Ritorna il tipo del campo
int length(const char* fieldname) const; // Ritorna lunghezza campo
int ndec(const char* fieldname) const; // Ritorna numero di decimali
bool exist(const char* fieldname) const; // Ritorna l'esistenza del campo
const char* fieldname(int i) const; // Ritorna il nome del campo i
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
#ifndef FOXPRO
int get_int(const char* fieldname) const ;
long get_long(const char* fieldname) const ;
word get_word(const char* fieldname) const ;
char get_char(const char* fieldname) const ;
bool get_bool(const char* fieldname) const ;
real get_real(const char* fieldname) const ;
#endif
TDate get_date(const char* fieldname) const ;
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
const TString& get(const char* fieldname) const ;
// @DES Put tipizzata
// @FPUB
#ifndef FOXPRO
void put(const char* fieldname, int val);
void put(const char* fieldname, long val);
void put(const char* fieldname, word val);
void put(const char* fieldname, const TDate& val);
void put(const char* fieldname, char val);
void put(const char* fieldname, bool val);
void put(const char* fieldname, const real& val);
#endif
// @DES Put NON tipizzata
// @FPUB
void put(const char* fieldname, const char* val);
// void put(const char* fieldname, TString& val);
void zero(const char * fieldname); // Vuota campo puntato da fieldname
void zero(); // Vuota tutto il record
void zero(char c); // Vuota tutto il record usando il carattere c
TRectype& operator =(const TRectype& rec); // assegnazione tra TRectype
TRectype& operator =(const char* rec); // assegnazione tra TRectype
TRectype& operator =(const TBaseisamfile& f);
const isdef* filehnd() const { return _i; } // Ritorna il file isam associato
int num() const { return _logicnum;} // Ritorna il numero logico
bool empty() const {return _isempty;} // Ritorna se e' vuoto
bool valid() const {return _rec[0] == 0;} // Ritorna se il record non e'cancellato
const char* key(int numkey = 1) const; // Ritorna l'espressione della chiave numero numkey
bool ok() const { return _i != NULL;}
TRectype(int logicnum); // Costruisce un record staccato da un file. Bisogna poi chiamare linkfile(). Sarebbe meglio utilizzare una delle altre due
TRectype(const TBaseisamfile* i); // Costruisce record e lo associa al file isam i
TRectype(const TRectype& r); // Costruisce il record a partire da r
virtual ~TRectype();
};
// @C
// Classe TBaseisamfile : public TObject
//
// File isam di base
//
// @END
class TBaseisamfile : public TObject
{
// @DPRIV
isdef* _isamfile; // Descrittore file isam
int _logicnum; // Numero logico del record corrente
int _lasterr; // Ultimo errore
bool _delrec; // Per sapere se rimuovere il record alla fine
bool _delopenrec; // Per sapere se rimuovere il record alla fine dalla lista interna di record
TRectype* _current; // Puntatore a record corrente
TFile _hf;
TFile _hfhd;
bool _historicfile; // Vero se il file e' archivio storico
TRecnotype _lasthf;
TRecnotype _recno;
friend class TRectype;
friend class TLocalisamfile;
friend class TIsamfile;
friend class TIsamtempfile;
friend class TRecfield;
// friend class TCursor;
// @END
// @FPRIV
// friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp);
// friend TRecnotype __filtercursor(TFilecursor* tic);
// friend bool __evalcondition(TBaseisamfile* i,TString& condition);
// friend void __readrec(TFilecursor* tic);
int gethr(TRectype& rec, TDate& atdate);
int addhr(const TRectype& rec, TDate& atdate);
int rewhr(const TRectype& rec, TDate& atdate);
int delhr(const TRectype& rec, TDate& atdate);
protected:
// @FPROT
isdef** ptrfilehnd() const { return (isdef**) &_isamfile;}
void clearfilehnd() { _isamfile = NULL;}
void recover();
int _open(unsigned int mode = _manulock); // Apre isam file con lock
int _close();
const char* filename() const;
public:
// @FPUB
void setkey(int nkey); // Attiva una chiave
int getkey() const; // Ritorna la chiave
void setstatus(int status) { _lasterr = status; } // Setta _lasterr
virtual int first(word lockop = _nolock);
virtual int last(word lockop = _nolock);
virtual int next(word lockop = _nolock);
virtual int next(TDate& atdate);
virtual int prev(word lockop = _nolock);
virtual int prev(TDate& atdate);
virtual int reread(word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int skip(TRecnotype nrec, word lockop = _nolock);
virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int readat(TRecnotype nrec, word lockop = _nolock);
virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock);
virtual int write(TDate& atdate = (TDate&)botime);
virtual int write(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewrite(TDate& atdate = (TDate&)botime);
virtual int rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewriteat(TRecnotype nrec);
virtual int rewriteat(const TRectype& rec, TRecnotype nrec);
virtual int remove(TDate& atdate = (TDate&)botime);
virtual int remove(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual const char* name() const;
TRecnotype recno() const { return _recno;}
int lock(); // Attiva lock di tutto il file
int unlock(); // Disattiva lock di tutto il file
void indexon(); // Accende gli indici
void indexoff(); // Spegne gli indici
int status() const { return _lasterr; } // Ritorna _lasterr
TRectype& curr() const {return *_current;} // Ritorna puntatore a record corrente
bool eof() const { return status() == _iseof || status() == _isemptyfile;} // Vero se siamo a fine file
bool bof() const { return status() == _isbof || status() == _isemptyfile;} // Vero se siamo a inizio file
bool good() const { return status() == NOERR;} // Vero se _lasterr non contiene codici d'errore
bool bad() const { return status() != NOERR;} // Vero se _lasterr contiene codici d'errore
bool empty(); // Vero se il file e' vuoto
int num() const { return _logicnum;} // Ritorna il numero logico del record corrente
const char* description() const;
TRecnotype eod() const { return filehnd()->d->EOD;}
isdef* filehnd() const { return (isdef*) _isamfile;} // Ritorna l'handle del file isam nella tabella
long items() const; // n.o di records nel file
// @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi
// @FPUB
#ifndef FOXPRO
int get_int(const char* fieldname) const
{ return curr().get_int(fieldname);}
long get_long(const char* fieldname) const
{ return curr().get_long(fieldname);}
word get_word(const char* fieldname) const
{ return curr().get_word(fieldname);}
char get_char(const char* fieldname) const
{ return curr().get_char(fieldname);}
bool get_bool(const char* fieldname) const
{ return curr().get_bool(fieldname);}
real get_real(const char* fieldname) const
{ return curr().get_real(fieldname);}
#endif
TDate get_date(const char* fieldname) const
{ return curr().get_date(fieldname);}
// @DES Get non tipizzata. Il campo e' ritornato come TString&
// @FPUB
const TString& get(const char* fieldname) const
{ return curr().get(fieldname);}
// @DES Put NON tipizzata
// @FPUB
#ifndef FOXPRO
void put(const char* fieldname, int val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, long val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, word val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, const TDate& val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, char val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, bool val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, const real& val)
{ curr().put(fieldname, val);}
#endif
// @DES Put NON tipizzata
// @FPUB
void put(const char* fieldname, const char* val)
{ curr().put(fieldname, val);}
void zero(const char * fieldname) { curr().zero(fieldname);}
void zero() { curr().zero();}
void zero(char c) { curr().zero(c);}
TRectype& operator =(const TRectype& rec) { return curr() = rec;}
TBaseisamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TBaseisamfile();
};
// @C
// Classe TIsamfile : public TBaseisamfile
//
// File isam
//
// @END
class TIsamfile : public TBaseisamfile
{
public:
// @FPUB
int flags(bool updateeod = FALSE);
int open(unsigned int mode = _manulock) { return _open(mode);} // Apre isam file con lock
int close() { return _close();}
TIsamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TIsamfile();
};
// @C
// Classe TIsamtempfile : public TBaseisamfile
//
// File isam temporaneo
//
// @END
class TIsamtempfile : public TBaseisamfile
{
public:
// @FPUB
int open(char* radix, bool create = TRUE, TRecnotype eod = 0,
TRecnotype eox = 100); // Apre il file. radix e' la radice del path del file, se create e' falso vuol dire che il file esiste gia', e allora eod dice quanti record ci sono; eox quanti bisogna aggiungerne
int close(bool flagdel = TRUE); // Chiude il file e se e' vero flagdel lo cancella
TIsamtempfile(int logicnum, bool linkrecinst = FALSE);
virtual ~TIsamtempfile();
};
// @C
// Classe TSystemisamfile : public TBaseisamfile
//
// @END
class TSystemisamfile : public TIsamfile
{
TArray _flds;
TArray _exps;
bool getlcf(long flev);
bool exec_convapp(long flev, const bool before);
void makelc(TRectype& rec);
public:
// @FPUB
int build(TRecnotype eox); // Costruisce un file isam
int extend(TRecnotype eox); // Estende un file preesistente
long size(TRecnotype eox); // Calcola lo spazio che il file occuperebbe se venisse esteso a eox
int update(TTrec& newrec, bool vis = TRUE);
int packfile(bool vis = TRUE); // Rimuove fisicamente i record cancellati
int packindex(bool vis = TRUE); // La stessa cosa sugli indici
// @DES Importa un file ascii. from e' il nome del file da importare
int load(const char* from, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool extended = FALSE) ;
// @DES Esporta VERSO un file ascii.
int dump(const char* to, int nkey = 1, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool withdeleted = FALSE);
TSystemisamfile(int logicnum, bool linkrecinst = TRUE)
: TIsamfile(logicnum, linkrecinst) {}
virtual ~TSystemisamfile() {}
};
// @C
// Classe TLocalisamfile : public TBaseisamfile
//
// @END
class TLocalisamfile : public TBaseisamfile
{
// @DPRIV
bool _was_open; // Vero se il file e' stato aperto come Localisamfile
bool _isatab; // Vero se il file e' una tabella
public:
// @FPUB
virtual int operator +=(const TRecnotype npos); // Avanza npos record
virtual int operator -=(const TRecnotype npos); // Sposta indietro di npos
virtual int operator ++(); // record successivo
virtual int operator --(); // record precedente
bool tab() const { return _isatab;} // Ritorna vero se tabella
void settab(bool fl = FALSE) { _isatab = fl;} // Setta il flag _isatab
int open(unsigned int mode = _manulock);
int close() ;
// Costruttore. linkrecinst dice se il file deve utilizzare un area record separata oppure la stessa.
TLocalisamfile(int logicnum, bool linkrecinst = TRUE);
virtual ~TLocalisamfile();
};
// @C
// Classe TRec_array : public TArray
//
// @END
class TRec_array : public TArray
{
public:
// @FPUB
TRec_array(int dimension, TBaseisamfile& i);
};
// @C
// Classe TRecfield : public TObject
//
// @END
class TRecfield : public TObject
{
// @DPRIV
char _name[12]; // Nome campo
TRectype* _rec; // Puntatore a inizio record
char* _p; // Puntatore a inizio campo
byte _len; // Lunghezza campo
byte _dec; // Numero di decimali
byte _type; // Tipo del campo
// @END
// @FPRIV
void set(int from, int to);
public:
// @FPUB
// @DES Operatore di assegnazione (=) per i vari tipi
// @FPUB
int operator =(int i) ;
long operator =(long l) ;
const TDate& operator =(const TDate& d) ;
const char* operator =(const char* s) ;
#ifndef FOXPRO
const real& operator =(const real& r) ;
#endif // FOXPRO
// @DES Operatore di estrazione per i vari tipi
// @FPUB
operator int() const ;
operator long() const ;
operator const char*() const ;
operator TDate() const ;
#ifndef FOXPRO
operator const real() const ;
#endif // FOXPRO
void setptr(TRecnotype r); // Scrive un campo packed. Sarebbe meglio non usare mai campi packed.
TRecnotype ptr() const; // Legge un campo packed. Sarebbe meglio non usare mai campi packed.
const char* pos() const { return (const char*) _p;} // Ritorna un puntatore all'inizio del campo nel record. Dovrebbe essere protected!
int len() const { return (int) _len;} // Ritorna la lunghezza
int dec() const { return (int) _dec;} // Ritorna il numero di decimali
TFieldtypes type() const { return (TFieldtypes) _type;} // Ritorna il tipo del campo
TRectype& record() const { return *_rec;} // Ritorna puntatore a inizio record
TRecfield(TRectype& rec, const char* name, int from = 0, int to = -1);
};
// @C
// Classe TTransaction
//
// @END
class TTransaction
{
public:
// @FPUB
void begin();
void end(bool success = TRUE);
void abort() { end(FALSE);}
};
#ifdef __ISAM_CPP
#define extern
#endif
// @DPUB
extern TTransaction transaction;
extern TRectype** openrec;
// @END
#undef extern
void set_autoload_new_files(bool on);
#endif // __ISAM_

View File

@ -1,4 +1,4 @@
// $Id: maskfld.cpp,v 1.64 1994-12-27 14:58:54 guy Exp $
// $Id: maskfld.cpp,v 1.65 1994-12-28 11:01:21 guy Exp $
#include <xvt.h>
#include <applicat.h>
@ -1963,6 +1963,21 @@ bool TEdit_field::on_hit()
if (_message.objptr(1) && get() == "") do_message(1);
else do_message(0);
return TRUE;
}
bool TEdit_field::default_error_box() const
{
if (_warning.empty())
{
const TString& p = prompt();
if (isalnum(p[0]))
error_box("Valore non valido per %s: '%s'", (const char*)p, (const char*)get());
else
error_box("Valore non valido: '%s'", (const char*)get());
}
else
error_box(_warning);
return FALSE;
}
bool TEdit_field::on_key(KEY key)
@ -1981,7 +1996,8 @@ bool TEdit_field::on_key(KEY key)
if (!ok)
{
if (_warning.not_empty()) error_box(_warning);
if (_warning.not_empty())
error_box(_warning);
return FALSE;
}
@ -1994,16 +2010,7 @@ bool TEdit_field::on_key(KEY key)
ok = _browse->check();
if (!ok)
{
if (_warning.not_empty()) error_box(_warning);
else
#ifdef DBG
error_box("Valore del campo %d non valido: %s", dlg(), (const char*)get());
#else
error_box("Valore non valido: %s", (const char*)get());
#endif
return FALSE;
}
return default_error_box();
ok = on_hit();
if (!ok)
@ -2033,7 +2040,8 @@ bool TEdit_field::on_key(KEY key)
bool ok = validate(K_ENTER); // Check validation expression
if (!ok)
{
if (_warning.not_empty()) error_box(_warning);
if (_warning.not_empty())
error_box(_warning);
return FALSE;
}
@ -2053,11 +2061,7 @@ bool TEdit_field::on_key(KEY key)
ok = query || !(check_type() == CHECK_REQUIRED && get().empty());
if (!ok)
{
if (_warning.not_empty()) error_box(_warning);
else error_box("Valore del campo %d non valido: '%s'", dlg(), (const char*)get());
return FALSE;
}
return default_error_box();
}
break;
case K_F9:

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
#define VERSION 1.2
#define VERSION 1.2

View File

@ -1,71 +1,71 @@
#ifndef __PREFIX_H
#define __PREFIX_H
#ifndef __EXTCTYPE_H
#include <extctype.h>
#endif
#ifndef __FILES_H
#include <files.h>
#endif
#ifndef __STRINGS_H
#include <strings.h>
#endif
// @C
// class TPrefix : public TObject
// @END
class TPrefix : public TObject
{
// @DPRIV
TString _prefix;
int* _dirfl;
int* _recfl;
long _filelevel;
int _items;
SecDef* _fdir;
SecDef* _rdir;
bool test(const char* s) const ;
void put();
public:
// @FPUB
void set(const char* name = NULL, bool force = FALSE, TFilelock mode = _manulock);
bool exist(long codditta) const;
bool test(long codditta) const;
long get_codditta() const ;
bool set_codditta(long codditta, bool force = FALSE);
const char* name() const { return _prefix;}
long filelevel() const {return _filelevel;}
int items() const { return _items; }
const char* description(const char* cod) const;
const char* description(int cod) const;
TPrefix();
virtual ~TPrefix();
};
const char* firm2dir(long codditta);
#ifdef __PREFIX_CPP
#define extern
#endif
// @DPUB
extern TPrefix* prefhndl
// @END
#ifdef __PREFIX_CPP
= NULL ;
#undef extern
#else
;
#endif
#endif // __PREFIX_H
#ifndef __PREFIX_H
#define __PREFIX_H
#ifndef __EXTCTYPE_H
#include <extctype.h>
#endif
#ifndef __FILES_H
#include <files.h>
#endif
#ifndef __STRINGS_H
#include <strings.h>
#endif
// @C
// class TPrefix : public TObject
// @END
class TPrefix : public TObject
{
// @DPRIV
TString _prefix;
int* _dirfl;
int* _recfl;
long _filelevel;
int _items;
SecDef* _fdir;
SecDef* _rdir;
bool test(const char* s) const ;
void put();
public:
// @FPUB
void set(const char* name = NULL, bool force = FALSE, TFilelock mode = _manulock);
bool exist(long codditta) const;
bool test(long codditta) const;
long get_codditta() const ;
bool set_codditta(long codditta, bool force = FALSE);
const char* name() const { return _prefix;}
long filelevel() const {return _filelevel;}
int items() const { return _items; }
const char* description(const char* cod) const;
const char* description(int cod) const;
TPrefix();
virtual ~TPrefix();
};
const char* firm2dir(long codditta);
#ifdef __PREFIX_CPP
#define extern
#endif
// @DPUB
extern TPrefix* prefhndl
// @END
#ifdef __PREFIX_CPP
= NULL ;
#undef extern
#else
;
#endif
#endif // __PREFIX_H

View File

@ -459,14 +459,26 @@ bool TSheet::update_row(long n)
for (int j = 0; (s = t.get()) != NULL; x += _size[j++]+1)
{
int x1 = x;
bool dis = FALSE;
bool changed = FALSE;
if (n >= 0)
{
if (_checkable && j == 0)
s = _checked[n] ? "X" : " ";
{
const bool c = _checked[n];
s = c ? "X" : " ";
if (c)
{
changed = TRUE;
set_color(COLOR_RED, COLOR_LTGRAY);
}
}
dis = _disabled[n];
if (dis) set_color(COLOR_CYAN, COLOR_GRAY);
const bool c = _disabled[n];
if (c)
{
set_color(COLOR_GRAY, COLOR_LTGRAY);
changed = TRUE;
}
switch (_type[j])
{
@ -484,7 +496,8 @@ bool TSheet::update_row(long n)
x1 += (_size[j]-strlen(s)) >> 1; // Centra le testate
stringat(x1, y, s);
if (dis) set_color(COLOR_BLACK, COLOR_GRAY);
if (changed)
set_color(COLOR_BLACK, COLOR_LTGRAY);
}
return TRUE;

View File

@ -1,166 +1,166 @@
#ifndef __SHEET_H
#define __SHEET_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __RELATION_H
class TCursor;
#endif
#ifndef __MASKFLD_H
class TEdit_field;
#endif
// @C
// class TSheet : public TScroll_window
// @END
class TSheet : public TScroll_window
{
// @DPRIV
enum { MAX_BUT = 8, MAX_COL = 128 };
TString_array _page;
byte _columns;
byte _size[MAX_COL], _type[MAX_COL];
long _curr, _last_update;
short _visible_rows;
bool _checkable;
bool _check_enabled;
TBit_array _checked, _disabled;
WINDOW _button[MAX_BUT];
KEY _key[MAX_BUT];
byte _buttonmask;
protected:
// @FPROT
bool head_on() const { return _columns > 1; }
bool buttons_on() const { return *_button != NULL_WIN; }
short visible_rows() const { return _visible_rows; }
virtual short reserved_rows() const;
void build_page(long first = -1);
PNT log2dev(long x, long y) const;
virtual void handler(WINDOW win, EVENT* ep);
virtual bool on_key(KEY);
virtual void update();
virtual void open();
void set_first(long n);
bool is_visible(long n) const { return n >= first() && n < first()+visible_rows(); }
int width() const;
int row_to_page(long n) const;
int row_to_win(long n) const;
long first() const { return origin().y; }
bool update_row(long n);
void invert_row(long n);
void set_row(const TToken_string& row, byte n);
virtual void repos_buttons() const;
virtual void page_build(long first, byte num) pure;
void print();
public:
// @FPUB
TSheet(short x, short y, short dx, short dy,
const char* title, const char* head, byte buttons = 0,
long first = 0L, WINDOW parent = NULL_WIN);
void add_button(short id, const char* caption, KEY key = K_ESC);
virtual long items() const pure;
virtual TToken_string& row(long s = -1);
long selected() const { return _curr; }
void select(long n);
bool checked(long n) const { return _checked[n]; }
void check(long n, bool on = TRUE);
void uncheck(long n) { check(n, FALSE); }
void enable_check(bool yn = TRUE) { _check_enabled = yn; }
void disable_check() { enable_check(FALSE); }
void enable(long n = -1, bool on = TRUE);
void disable(long n = -1) { enable(n, FALSE); }
bool enabled(long n) const { return !_disabled[n]; }
bool disabled(long n) const { return _disabled[n]; }
bool one_checked() const { return _checked.first_one() != -1; }
long checked() const { return _checked.ones(); }
};
class TArray_sheet : public TSheet
{
TString_array _data;
protected:
virtual void page_build(long first, byte num);
TToken_string& data(long n) { return _data.row((int)n); }
TString_array& rows_array() { return _data; }
public:
TArray_sheet(short x, short y, short dx, short dy, const char* caption,
const char* head, byte buttons = 0, WINDOW parent = NULL_WIN);
virtual long items() const { return _data.items(); }
long add(const TToken_string& s);
long add(TToken_string* s);
long insert(const TToken_string& s, long n);
virtual TToken_string& row(long s = -1) { return (s < 0) ? data(selected()) : data(s); }
bool destroy(int i = -1) { uncheck(-1); return _data.destroy(i, TRUE); }
};
class TCursor_sheet : public TSheet
{
TArray _fields; // Array of TRecfield
long _records;
protected:
TCursor* _cursor;
virtual void page_build(long first, byte rows);
public:
TCursor_sheet(TCursor* cursor, const char* fields,
const char* title, const char* head, byte buttons = 0);
virtual ~TCursor_sheet() {}
virtual long items() const { return _records; }
virtual KEY run();
};
class TBrowse_sheet : public TCursor_sheet
{
TEdit_field* const _field;
protected:
virtual void handler(WINDOW win, EVENT* ep);
virtual short reserved_rows() const;
virtual void repos_buttons() const;
virtual bool on_key(KEY k);
TEdit_field& field() { return *_field; }
public:
TBrowse_sheet(TCursor* cursor, const char* fields,
const char* title, const char* head, byte buttons,
TEdit_field* f, TToken_string* siblings = NULL);
virtual ~TBrowse_sheet() {}
virtual KEY run();
};
#endif
#ifndef __SHEET_H
#define __SHEET_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __RELATION_H
class TCursor;
#endif
#ifndef __MASKFLD_H
class TEdit_field;
#endif
// @C
// class TSheet : public TScroll_window
// @END
class TSheet : public TScroll_window
{
// @DPRIV
enum { MAX_BUT = 8, MAX_COL = 128 };
TString_array _page;
byte _columns;
byte _size[MAX_COL], _type[MAX_COL];
long _curr, _last_update;
short _visible_rows;
bool _checkable;
bool _check_enabled;
TBit_array _checked, _disabled;
WINDOW _button[MAX_BUT];
KEY _key[MAX_BUT];
byte _buttonmask;
protected:
// @FPROT
bool head_on() const { return _columns > 1; }
bool buttons_on() const { return *_button != NULL_WIN; }
short visible_rows() const { return _visible_rows; }
virtual short reserved_rows() const;
void build_page(long first = -1);
PNT log2dev(long x, long y) const;
virtual void handler(WINDOW win, EVENT* ep);
virtual bool on_key(KEY);
virtual void update();
virtual void open();
void set_first(long n);
bool is_visible(long n) const { return n >= first() && n < first()+visible_rows(); }
int width() const;
int row_to_page(long n) const;
int row_to_win(long n) const;
long first() const { return origin().y; }
bool update_row(long n);
void invert_row(long n);
void set_row(const TToken_string& row, byte n);
virtual void repos_buttons() const;
virtual void page_build(long first, byte num) pure;
void print();
public:
// @FPUB
TSheet(short x, short y, short dx, short dy,
const char* title, const char* head, byte buttons = 0,
long first = 0L, WINDOW parent = NULL_WIN);
void add_button(short id, const char* caption, KEY key = K_ESC);
virtual long items() const pure;
virtual TToken_string& row(long s = -1);
long selected() const { return _curr; }
void select(long n);
bool checked(long n) const { return _checked[n]; }
void check(long n, bool on = TRUE);
void uncheck(long n) { check(n, FALSE); }
void enable_check(bool yn = TRUE) { _check_enabled = yn; }
void disable_check() { enable_check(FALSE); }
void enable(long n = -1, bool on = TRUE);
void disable(long n = -1) { enable(n, FALSE); }
bool enabled(long n) const { return !_disabled[n]; }
bool disabled(long n) const { return _disabled[n]; }
bool one_checked() const { return _checked.first_one() != -1; }
long checked() const { return _checked.ones(); }
};
class TArray_sheet : public TSheet
{
TString_array _data;
protected:
virtual void page_build(long first, byte num);
TToken_string& data(long n) { return _data.row((int)n); }
TString_array& rows_array() { return _data; }
public:
TArray_sheet(short x, short y, short dx, short dy, const char* caption,
const char* head, byte buttons = 0, WINDOW parent = NULL_WIN);
virtual long items() const { return _data.items(); }
long add(const TToken_string& s);
long add(TToken_string* s);
long insert(const TToken_string& s, long n);
virtual TToken_string& row(long s = -1) { return (s < 0) ? data(selected()) : data(s); }
bool destroy(int i = -1) { uncheck(-1); return _data.destroy(i, TRUE); }
};
class TCursor_sheet : public TSheet
{
TArray _fields; // Array of TRecfield
long _records;
protected:
TCursor* _cursor;
virtual void page_build(long first, byte rows);
public:
TCursor_sheet(TCursor* cursor, const char* fields,
const char* title, const char* head, byte buttons = 0);
virtual ~TCursor_sheet() {}
virtual long items() const { return _records; }
virtual KEY run();
};
class TBrowse_sheet : public TCursor_sheet
{
TEdit_field* const _field;
protected:
virtual void handler(WINDOW win, EVENT* ep);
virtual short reserved_rows() const;
virtual void repos_buttons() const;
virtual bool on_key(KEY k);
TEdit_field& field() { return *_field; }
public:
TBrowse_sheet(TCursor* cursor, const char* fields,
const char* title, const char* head, byte buttons,
TEdit_field* f, TToken_string* siblings = NULL);
virtual ~TBrowse_sheet() {}
virtual KEY run();
};
#endif

View File

@ -1,306 +1,306 @@
#ifndef __STRINGS_H
#define __STRINGS_H
#ifndef __STRING_H
#include <string.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
// @C
// Classe TString : public TObject
// @END
class TString : public TObject
{
protected:
// @DPROT
char* _str; // Puntatore alla stringa
int _size; // Lunghezza
// @END
// @FPROT
int make_room(int size); // Cerca spazio per altri size caratteri
TString& set(const char*); // Inizializza con la stringa puntata da char* di lunghezza size
TString(char* str, int size) : _str(str), _size(size) {}
public:
// @FPUB
virtual void resize(int size, bool cpy); // Ri/alloca la stringa
TString();
TString(int size); // Default constructor for a string of given size
TString(const char* s); // Costruttore a partire da una stringa s
TString(const TString& s); // Costruttore da un oggetto TString s
virtual ~TString(); // Deallocates the string
///////////////////////////////////////////////////////////
// @DES Methods derived from TObject
///////////////////////////////////////////////////////////
// @FPUB
virtual const char* class_name() const; // Ritorna il nome della classe
virtual word class_id() const; // Ritorna l'identificatore della classe
virtual bool ok() const { return _str != NULL; }
virtual TObject* dup() const;
virtual void print_on(ostream& out) const;
virtual void read_from(istream& in);
virtual word hash() const; // Return hash value
///////////////////////////////////////////////////////////
// @DES Query methods
///////////////////////////////////////////////////////////
// @FPUB
operator const char*() const { return (const char*)_str; } // *(TString) -> _str
char& operator[](int i) // TString[i] -> _str[i]
{
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
return _str[i];
}
char operator[](int i) const // TString[i] -> _str[i]
{
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
return _str[i];
}
int size() const { return _size; }
int len() const { return strlen(_str); }
bool empty() const { return *_str == '\0'; }
bool not_empty() const { return *_str != '\0'; }
int find(char, int from = 0) const; // Ritorna la posizione del carattere char nell'oggetto TString
int find(const char* s, int from = 0) const; // Ritorna la posizione della stringa s nell'oggetto TString
const TString& left(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da sinistra
const TString& mid(int from, int count = -1) const; // Ritorna l'oggetto TString composto dai count caratteri a partire da from
const TString& sub(int from, int to = -1) const; // Ritorna la stringa da FROM a TO (escluso)
const TString& right(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da destra
///////////////////////////////////////////////////////////
// @DES Modifying methods
///////////////////////////////////////////////////////////
// @FPUB
TString& fill(char c, int n = -1); // Riempie con n caratteri c
TString& spaces(int n = -1) { return fill(' ', n); }
TString& overwrite(const char* s, int pos = 0); // Sovrascrive la stringa s dalla posizione pos
TString& insert(const char* s, int pos = 0); // Inserisce la stringa s dalla posizione pos
TString& strip(const char* k); // Elimina tutti i caratteri contenuti in k
TString& strip_spaces(); // Elimina tutti gli spazi non contenuti tra apici singoli o doppi
TString& ltrim(int n = 0); // Elimina gli spazi da sinistra se n=0 altrimenti elimina i primi n caratteri (da sinistra).
TString& rtrim(int n = 0); // Elimina gli spazi da destra se n=0 altrimenti elimina i primi n caratteri (da destra).
TString& trim(); // ltrim e rtrim
TString& right_just(int n = -1, char c = ' '); // Giustifica a destra
TString& center_just(int n = -1, char c = ' '); // Centra
TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra
TString& picture(const char* pic, const char* s);
virtual TString& format(const char* fmt, ...);
TString& cut(int n); // Inserisce un '\0' alla posizione n-esima.
TString& upper(); // Mette la stringa in maiuscolo
TString& lower(); // Mette la stringa in minuscolo
///////////////////////////////////////////////////////////
// @DES Standard operators
///////////////////////////////////////////////////////////
// @FPUB
const TString& operator =(const TString& s) { return set(s._str); }
const TString& operator =(const char* s) { return set(s); }
TString& operator <<(const char*);
TString& operator <<(char);
TString& operator <<(int);
TString& operator <<(long);
TString& operator <<(double);
TString& operator <<(const TObject& obj);
TString& operator <<(const TString& str); // For efficiency only
bool operator ==(const char* s) const { return strcmp(_str, s) == 0; }
bool operator ==(char* s) const { return strcmp(_str, s) == 0; }
bool operator ==(const TString& s) const { return strcmp(_str, s._str) == 0; }
bool operator !=(const char* s) const { return strcmp(_str, s) != 0; }
bool operator !=(char* s) const { return strcmp(_str, s) != 0; }
bool operator !=(const TString& s) const { return strcmp(_str, s._str) != 0; }
bool operator <(const char* s) const { return strcmp(_str, s) < 0; }
bool operator >(const char* s) const { return strcmp(_str, s) > 0; }
bool operator >=(const char* s) const { return strcmp(_str, s) >= 0; }
bool operator <=(const char* s) const { return strcmp(_str, s) <= 0; }
bool match(const char* s) const;
bool compare(const char* s, int max = -1, bool ignorecase = FALSE) const;
};
// @C
// Classe TFixed_string : public TString
// @END
class TFixed_string : public TString
{
protected:
virtual void resize(int size, bool cpy); // Causa un errore fatale!
public:
TFixed_string(const char* str, int size = -1);
virtual ~TFixed_string();
virtual TString& format(const char* fmt, ...);
const TString& operator =(const TString& s) { return set((const char*)s); }
const TString& operator=(const char* str) { return set(str); }
void strncpy(const char* s, int n);
};
class TString16 : public TFixed_string
{
char _str16[17];
public:
TString16(const char* s = "") : TFixed_string(_str16, 17) { set(s); }
TString16(const TString& s) : TFixed_string(_str16, 17) { set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
const TString& operator =(const char* s) { return set(s); }
};
class TString80 : public TFixed_string
{
char _str80[81];
public:
TString80(const char* s = "") : TFixed_string(_str80, 81) { set(s); }
TString80(const TString& s) : TFixed_string(_str80, 81) { set(s); }
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
};
class TString256 : public TFixed_string
{
char _str256[257];
public:
TString256(const char* s = "") : TFixed_string(_str256, 257) { set(s); }
TString256(const TString& s) : TFixed_string(_str256, 257) { set(s); }
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
};
// @C
// Classe TFilename : public TString80 (256 su Windows'95)
// @END
class TFilename : public TString80
{
public:
// @FPUB
TFilename(const char* n = "") : TString80(n) {}
TFilename(const TString& n) : TString80((const char*)n) {}
TFilename(const TFilename& n) : TString80((const char*)n) {}
// assegnazione tra TFile e stringa
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
virtual bool ok() const; // Controlla il formato del nome del file
const char* ext() const; // Ritorna l'estensione
void ext(const char*); // Imposta come estensione la stringa puntata da char*
const char* name() const; // Ritorna il nome del file
const char* path() const; // Ritorna il nome del direttorio
const TFilename& temp(const char* prefix = NULL); // Genera il nome di un file temporaneo
const TFilename& tempdir(); // Genera il nome della directory temporanea
};
// @C
// Classe TToken_string : public TString
// @END
class TToken_string : public TString
{
// @DPRIV
char _separator; // Carattere separatore
int _last; // Puntatore all'ultimo
protected:
// @FPROT
virtual TObject* dup() const; // Crea un duplicato della token string
bool set_item(const char* v, int n);
public:
// @FPUB
TToken_string(const char* = "", char separator = '|');
TToken_string(int n, char separator = '|');
TToken_string(const TToken_string& s);
void separator(char s) { _separator = s; } // Setta il separatore a s
void restart() { _last = empty() ? -1 : 0; } // Rimette all'inizio il puntatore
const TString& operator =(const char* s) { set(s);restart();return *this; }
const TString& operator =(const TString& s) { set(s);restart();return *this; }
void add(const char* s, int n = -1); // Aggiunge una stringa
void add(char c, int pos = -1); // Aggiunge un char
void add(long n, int pos = -1); // Aggiunge un intero
void add(int n, int pos = -1); // Aggiunge un intero
void destroy(int pos); // Toglie la stringa pos
const char* get(); // Ritorna il prossimo token
const char* get(int n); // Ritorna un token (-1 = prossimo; -2 = ultimo; n = ennesimo)
char get_char(int n = -1); // Ritorna un carattere
int get_int(int n = -1); // Ritorna un intero
long get_long(int n = -1); // Ritorna un intero esteso
int get_pos(const char* s); // Ritorna la posizione dell'item s
int items() const; // Ritorna il numero di token presenti
bool empty_items() const; // Controlla se tutti i token sono nulli
};
///////////////////////////////////////////////////////////
// @DES Paragraph
///////////////////////////////////////////////////////////
class TParagraph_string : public TToken_string
{
int _width;
bool _fixed;
protected:
void tokenize();
public:
TParagraph_string(const char* s, int width);
const TString& operator =(const char* s);
void set_width(int width) { _width = width; }
};
///////////////////////////////////////////////////////////
// @DES TString_array
///////////////////////////////////////////////////////////
class TString_array : public TArray
{
public:
TToken_string& row(int n) { return (TToken_string&)operator[](n); }
int add(TToken_string* s, int n = -1) { return TArray::add(s, n); }
int add(const TToken_string& s, int n = -1);
int add(const char* s, int n = -1);
TString_array(int size = 8) : TArray(size) {}
virtual ~TString_array() {}
};
#endif
#ifndef __STRINGS_H
#define __STRINGS_H
#ifndef __STRING_H
#include <string.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
// @C
// Classe TString : public TObject
// @END
class TString : public TObject
{
protected:
// @DPROT
char* _str; // Puntatore alla stringa
int _size; // Lunghezza
// @END
// @FPROT
int make_room(int size); // Cerca spazio per altri size caratteri
TString& set(const char*); // Inizializza con la stringa puntata da char* di lunghezza size
TString(char* str, int size) : _str(str), _size(size) {}
public:
// @FPUB
virtual void resize(int size, bool cpy); // Ri/alloca la stringa
TString();
TString(int size); // Default constructor for a string of given size
TString(const char* s); // Costruttore a partire da una stringa s
TString(const TString& s); // Costruttore da un oggetto TString s
virtual ~TString(); // Deallocates the string
///////////////////////////////////////////////////////////
// @DES Methods derived from TObject
///////////////////////////////////////////////////////////
// @FPUB
virtual const char* class_name() const; // Ritorna il nome della classe
virtual word class_id() const; // Ritorna l'identificatore della classe
virtual bool ok() const { return _str != NULL; }
virtual TObject* dup() const;
virtual void print_on(ostream& out) const;
virtual void read_from(istream& in);
virtual word hash() const; // Return hash value
///////////////////////////////////////////////////////////
// @DES Query methods
///////////////////////////////////////////////////////////
// @FPUB
operator const char*() const { return (const char*)_str; } // *(TString) -> _str
char& operator[](int i) // TString[i] -> _str[i]
{
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
return _str[i];
}
char operator[](int i) const // TString[i] -> _str[i]
{
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
return _str[i];
}
int size() const { return _size; }
int len() const { return strlen(_str); }
bool empty() const { return *_str == '\0'; }
bool not_empty() const { return *_str != '\0'; }
int find(char, int from = 0) const; // Ritorna la posizione del carattere char nell'oggetto TString
int find(const char* s, int from = 0) const; // Ritorna la posizione della stringa s nell'oggetto TString
const TString& left(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da sinistra
const TString& mid(int from, int count = -1) const; // Ritorna l'oggetto TString composto dai count caratteri a partire da from
const TString& sub(int from, int to = -1) const; // Ritorna la stringa da FROM a TO (escluso)
const TString& right(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da destra
///////////////////////////////////////////////////////////
// @DES Modifying methods
///////////////////////////////////////////////////////////
// @FPUB
TString& fill(char c, int n = -1); // Riempie con n caratteri c
TString& spaces(int n = -1) { return fill(' ', n); }
TString& overwrite(const char* s, int pos = 0); // Sovrascrive la stringa s dalla posizione pos
TString& insert(const char* s, int pos = 0); // Inserisce la stringa s dalla posizione pos
TString& strip(const char* k); // Elimina tutti i caratteri contenuti in k
TString& strip_spaces(); // Elimina tutti gli spazi non contenuti tra apici singoli o doppi
TString& ltrim(int n = 0); // Elimina gli spazi da sinistra se n=0 altrimenti elimina i primi n caratteri (da sinistra).
TString& rtrim(int n = 0); // Elimina gli spazi da destra se n=0 altrimenti elimina i primi n caratteri (da destra).
TString& trim(); // ltrim e rtrim
TString& right_just(int n = -1, char c = ' '); // Giustifica a destra
TString& center_just(int n = -1, char c = ' '); // Centra
TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra
TString& picture(const char* pic, const char* s);
virtual TString& format(const char* fmt, ...);
TString& cut(int n); // Inserisce un '\0' alla posizione n-esima.
TString& upper(); // Mette la stringa in maiuscolo
TString& lower(); // Mette la stringa in minuscolo
///////////////////////////////////////////////////////////
// @DES Standard operators
///////////////////////////////////////////////////////////
// @FPUB
const TString& operator =(const TString& s) { return set(s._str); }
const TString& operator =(const char* s) { return set(s); }
TString& operator <<(const char*);
TString& operator <<(char);
TString& operator <<(int);
TString& operator <<(long);
TString& operator <<(double);
TString& operator <<(const TObject& obj);
TString& operator <<(const TString& str); // For efficiency only
bool operator ==(const char* s) const { return strcmp(_str, s) == 0; }
bool operator ==(char* s) const { return strcmp(_str, s) == 0; }
bool operator ==(const TString& s) const { return strcmp(_str, s._str) == 0; }
bool operator !=(const char* s) const { return strcmp(_str, s) != 0; }
bool operator !=(char* s) const { return strcmp(_str, s) != 0; }
bool operator !=(const TString& s) const { return strcmp(_str, s._str) != 0; }
bool operator <(const char* s) const { return strcmp(_str, s) < 0; }
bool operator >(const char* s) const { return strcmp(_str, s) > 0; }
bool operator >=(const char* s) const { return strcmp(_str, s) >= 0; }
bool operator <=(const char* s) const { return strcmp(_str, s) <= 0; }
bool match(const char* s) const;
bool compare(const char* s, int max = -1, bool ignorecase = FALSE) const;
};
// @C
// Classe TFixed_string : public TString
// @END
class TFixed_string : public TString
{
protected:
virtual void resize(int size, bool cpy); // Causa un errore fatale!
public:
TFixed_string(const char* str, int size = -1);
virtual ~TFixed_string();
virtual TString& format(const char* fmt, ...);
const TString& operator =(const TString& s) { return set((const char*)s); }
const TString& operator=(const char* str) { return set(str); }
void strncpy(const char* s, int n);
};
class TString16 : public TFixed_string
{
char _str16[17];
public:
TString16(const char* s = "") : TFixed_string(_str16, 17) { set(s); }
TString16(const TString& s) : TFixed_string(_str16, 17) { set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
const TString& operator =(const char* s) { return set(s); }
};
class TString80 : public TFixed_string
{
char _str80[81];
public:
TString80(const char* s = "") : TFixed_string(_str80, 81) { set(s); }
TString80(const TString& s) : TFixed_string(_str80, 81) { set(s); }
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
};
class TString256 : public TFixed_string
{
char _str256[257];
public:
TString256(const char* s = "") : TFixed_string(_str256, 257) { set(s); }
TString256(const TString& s) : TFixed_string(_str256, 257) { set(s); }
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
};
// @C
// Classe TFilename : public TString80 (256 su Windows'95)
// @END
class TFilename : public TString80
{
public:
// @FPUB
TFilename(const char* n = "") : TString80(n) {}
TFilename(const TString& n) : TString80((const char*)n) {}
TFilename(const TFilename& n) : TString80((const char*)n) {}
// assegnazione tra TFile e stringa
const TString& operator =(const char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
virtual bool ok() const; // Controlla il formato del nome del file
const char* ext() const; // Ritorna l'estensione
void ext(const char*); // Imposta come estensione la stringa puntata da char*
const char* name() const; // Ritorna il nome del file
const char* path() const; // Ritorna il nome del direttorio
const TFilename& temp(const char* prefix = NULL); // Genera il nome di un file temporaneo
const TFilename& tempdir(); // Genera il nome della directory temporanea
};
// @C
// Classe TToken_string : public TString
// @END
class TToken_string : public TString
{
// @DPRIV
char _separator; // Carattere separatore
int _last; // Puntatore all'ultimo
protected:
// @FPROT
virtual TObject* dup() const; // Crea un duplicato della token string
bool set_item(const char* v, int n);
public:
// @FPUB
TToken_string(const char* = "", char separator = '|');
TToken_string(int n, char separator = '|');
TToken_string(const TToken_string& s);
void separator(char s) { _separator = s; } // Setta il separatore a s
void restart() { _last = empty() ? -1 : 0; } // Rimette all'inizio il puntatore
const TString& operator =(const char* s) { set(s);restart();return *this; }
const TString& operator =(const TString& s) { set(s);restart();return *this; }
void add(const char* s, int n = -1); // Aggiunge una stringa
void add(char c, int pos = -1); // Aggiunge un char
void add(long n, int pos = -1); // Aggiunge un intero
void add(int n, int pos = -1); // Aggiunge un intero
void destroy(int pos); // Toglie la stringa pos
const char* get(); // Ritorna il prossimo token
const char* get(int n); // Ritorna un token (-1 = prossimo; -2 = ultimo; n = ennesimo)
char get_char(int n = -1); // Ritorna un carattere
int get_int(int n = -1); // Ritorna un intero
long get_long(int n = -1); // Ritorna un intero esteso
int get_pos(const char* s); // Ritorna la posizione dell'item s
int items() const; // Ritorna il numero di token presenti
bool empty_items() const; // Controlla se tutti i token sono nulli
};
///////////////////////////////////////////////////////////
// @DES Paragraph
///////////////////////////////////////////////////////////
class TParagraph_string : public TToken_string
{
int _width;
bool _fixed;
protected:
void tokenize();
public:
TParagraph_string(const char* s, int width);
const TString& operator =(const char* s);
void set_width(int width) { _width = width; }
};
///////////////////////////////////////////////////////////
// @DES TString_array
///////////////////////////////////////////////////////////
class TString_array : public TArray
{
public:
TToken_string& row(int n) { return (TToken_string&)operator[](n); }
int add(TToken_string* s, int n = -1) { return TArray::add(s, n); }
int add(const TToken_string& s, int n = -1);
int add(const char* s, int n = -1);
TString_array(int size = 8) : TArray(size) {}
virtual ~TString_array() {}
};
#endif