Aggiunta documentazione in linea
git-svn-id: svn://10.65.10.50/trunk@1353 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
e61c0383d4
commit
50cf15b8ba
@ -4,18 +4,17 @@
|
||||
#include <strings.h>
|
||||
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc void | TArray | resize | Modifica la dimensione dell'array.
|
||||
//
|
||||
// @parm int | newdim | Indica la nuova dimensione che deve assumere l'array.
|
||||
//
|
||||
// @comm Alloca la memoria necessaria per contentere i dati della nuova
|
||||
// dimensione inizializzando a NULL tutti i nuovi elementi aggiunti
|
||||
// all'array lasciando inalterati, sia in posizione che in
|
||||
// contenuto gli elementi gia' presenti.
|
||||
// Nel caso si cerca di diminuire la dimensione viene dato un messaggio
|
||||
// di errore.
|
||||
void TArray::resize(int arraysize)
|
||||
|
||||
// @mfunc Modifica la dimensione dell'array.
|
||||
void TArray::resize(
|
||||
int arraysize) // @parm Indica la nuova dimensione che deve assumere l'array.
|
||||
|
||||
// @comm Alloca la memoria necessaria per contentere i dati della nuova
|
||||
// dimensione inizializzando a NULL tutti i nuovi elementi aggiunti
|
||||
// all'array lasciando inalterati, sia in posizione che in
|
||||
// contenuto gli elementi gia' presenti.
|
||||
// <nl>Nel caso si cerchi di diminuire la dimensione viene dato un
|
||||
// messaggio di errore.
|
||||
|
||||
{
|
||||
CHECK(arraysize > size(), "Can't reduce array size.");
|
||||
@ -36,22 +35,21 @@ void TArray::resize(int arraysize)
|
||||
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @mfunc bool | TArray | destroy | Rimuove uno o tutti gli elementi (default)
|
||||
//
|
||||
// @parm int |index | Numero dell'elemento da eliminare (default -1)
|
||||
// @parm bool | pack | Se true richiama la funzione <mf TArray::pack> per compattare
|
||||
// gli elementi dell'array (default FALSE)
|
||||
//
|
||||
// @comm Permette la rimozione di uno (index > 0 ) o di tutti (default) gli
|
||||
// elementi dell'array assegnandone il valore NULL.
|
||||
// Nel caso il parametro pack sia TRUE permette di rendere contigui tutti
|
||||
// gli elementi diversi da NULL tramite la chiamata alla funzione <mf TArray::pack>.
|
||||
//
|
||||
// @rdesc Ritorna uno dei seguenti parametri:
|
||||
//
|
||||
// @flag TRUE | Se l'operazione e' riuscita con successo
|
||||
// @flag FALSE | Se il numero di elementi e' rimasto invariato
|
||||
bool TArray::destroy(int index, bool pack)
|
||||
// @mfunc Rimuove uno o tutti (default) gli elementi
|
||||
bool TArray::destroy(
|
||||
int index, // @parm Numero dell'elemento da eliminare (default -1)
|
||||
bool pack) // @parm Se true richiama la funzione <mf TArray::pack> per compattare gli elementi dell'array (default FALSE)
|
||||
|
||||
// @comm Permette la rimozione di uno (index > 0 ) o di tutti (default) gli
|
||||
// elementi dell'array assegnandone il valore NULL.
|
||||
// <nl>Nel caso il parametro pack sia TRUE permette di rendere contigui
|
||||
// tutti gli elementi diversi da NULL tramite la chiamata alla funzione
|
||||
// <mf TArray::pack>.
|
||||
//
|
||||
// @rdesc Ritorna uno dei seguenti parametri:
|
||||
//
|
||||
// @flag TRUE | Se l'operazione e' riuscita con successo
|
||||
// @flag FALSE | Se il numero di elementi e' rimasto invariato
|
||||
{
|
||||
const int old = _items;
|
||||
|
||||
@ -119,8 +117,14 @@ word TArray::class_id() const
|
||||
return CLASS_ARRAY;
|
||||
}
|
||||
|
||||
//ANDREA
|
||||
void TArray::print_on(ostream& out) const
|
||||
// @mfunc Stampa un array
|
||||
void TArray::print_on(
|
||||
ostream& out) const // @parm indica l'output sul quale reindirizzare la stampa (funzione standard del C++)
|
||||
|
||||
// @comm Permette di stampare sull'output passato come parametro il contenuto
|
||||
// dell'array, preceduto dal numero dell'elemetno a cui si riferisce.
|
||||
// <nl>Nel caso vi siano degli elementi vuoti (valore = NULL) viene
|
||||
// stampato il valore (null).
|
||||
|
||||
{
|
||||
for (int i = 0; i < size(); i++)
|
||||
@ -134,15 +138,43 @@ void TArray::print_on(ostream& out) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @mfunc Controlla se si tratta di un oggetto valido
|
||||
bool TArray::ok() const
|
||||
|
||||
// @rdesc Ritorna uno dei seguenti parametri:
|
||||
//
|
||||
// @flag TRUE | Se l'array contiene degli elementi
|
||||
// @flag FALSE | Se l'array e' vuoto
|
||||
//
|
||||
// @comm Controlla se la dimensione dell'array e' uguale a 0 e se esistono
|
||||
// degli elementi diversi da NULL
|
||||
|
||||
{
|
||||
return(size() != 0 && (_data != NULL));
|
||||
}
|
||||
|
||||
// @mfunc Aggiunge un oggetto ad un array.
|
||||
int TArray::add(
|
||||
TObject *object, // @parm Oggetto da aggiungere nell'array
|
||||
int index) // @parm Posizione in cui aggiungere l'oggetto
|
||||
// @parm TObject | &object | Oggetto da aggiungere nell'array. L'oggetto viene duplicato
|
||||
|
||||
int TArray::add(TObject* object, int index)
|
||||
// @syntax add(TObject* object,int index);
|
||||
// @syntax add(TObject& object,int index);
|
||||
//
|
||||
// @comm Nel caso venga passata una posizione minore di 0 l'elemento viene aggiunto
|
||||
// in coda all'array, diversamente viene l'elemento presente viene
|
||||
// sostitito con l'oggetto passato nei prametri.
|
||||
// <nl>Se e' stato passato un indice minore della dimensione dell'array,
|
||||
// viene aumentata automaticamente la dimensione dell'array stesso tramite
|
||||
// la chiamata alla funzione <mf TArray::resize>.
|
||||
// <nl><nl>ATTENZIONE: Nel caso si passi l'oggetto per indirizzo deve
|
||||
// essere definita la funzione <mf TObject::dup>.
|
||||
//
|
||||
// @rdesc La funzione ritorna la posizione nella quale e' stato aggiunto
|
||||
// l'oggetto.
|
||||
//
|
||||
// @xref <mf TArray::insert>
|
||||
{
|
||||
if (index < 0) for (index = 0; index < size() && _data[index]; index++);
|
||||
if (index >= size()) resize(3*index/2 + 1);
|
||||
@ -166,8 +198,25 @@ int TArray::add(TObject* object, int index)
|
||||
return index;
|
||||
}
|
||||
|
||||
// @mfunc Inserisce un elemento dell'array nella posizione index
|
||||
int TArray::insert(
|
||||
TObject *object, // @parm Oggetto da inserire nell'array
|
||||
int index) // @parm Posizione in cui inserire l'oggetto
|
||||
// @parm TObject | &object | Oggetto da inserire nell'array. L'oggetto viene duplicato
|
||||
|
||||
int TArray::insert(TObject* object, int index)
|
||||
// @syntax insert(TObject* object, int index);
|
||||
// @syntax insert(TObject& object, int index);
|
||||
//
|
||||
// @comm Nel caso l'elemento della posizione passata sia diverso da NULL vengono
|
||||
// spostati di una posizione tutti gli elementi presenti nell'array.
|
||||
// La dimensione dell'array viene automaticamente aumentata nel caso
|
||||
// la stessa non sia sufficiente a contenere il nuovo oggetto.
|
||||
// <nl><nl>ATTENZIONE: Nel caso si passi l'oggetto per indirizzo deve
|
||||
// essere definita la funzione <mf TObject::dup>.
|
||||
//
|
||||
// @rdesc La funzione ritorna la posizione nella quale e' stato inserito l'oggetto.
|
||||
//
|
||||
// @xref <mf TArray::add>
|
||||
{
|
||||
if (objptr(index))
|
||||
{
|
||||
@ -179,6 +228,7 @@ int TArray::insert(TObject* object, int index)
|
||||
return add(object, index);
|
||||
}
|
||||
|
||||
|
||||
int TArray::add(const TObject& object, int index)
|
||||
{
|
||||
TObject* objptr = object.dup();
|
||||
@ -191,7 +241,13 @@ int TArray::insert(const TObject& object, int index)
|
||||
return insert(objptr, index);
|
||||
}
|
||||
|
||||
TObject* TArray::remove(int index, bool dopack)
|
||||
// @mfunc Elimina l'elemento nella posizione index dell'array
|
||||
TObject* TArray::remove(
|
||||
int index, // @parm Indica la posizione dell'elemento da eliminare
|
||||
bool dopack) // @parm Indica se si vuole richiamare la funzione
|
||||
// <mf TArray::pack> (default FALSE) per il compattamento dell'array
|
||||
|
||||
// @rdesc Ritorna l'elemento dell'array eliminato
|
||||
{
|
||||
TObject* o = objptr(index);
|
||||
if (o)
|
||||
@ -218,8 +274,11 @@ int TArray::last() const
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
// @mfunc Rende contigui tutti gli elementi non nulli
|
||||
void TArray::pack()
|
||||
|
||||
// @comm Riordina gli elementi dell'array facendo che tra di loro non ve ne
|
||||
// siano con valore uguale a NULL.
|
||||
{
|
||||
int next = 0;
|
||||
for (int i = 0; i < size(); i++)
|
||||
@ -236,15 +295,32 @@ void TArray::pack()
|
||||
}
|
||||
}
|
||||
|
||||
// @func Funzione per permettere il confonto tra 2 oggetti.
|
||||
//
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag <gt>0 | se <p this> <gt> <p s>
|
||||
// @flag 0 | se <p this> == <p s>
|
||||
// @flag <lt>0 | se <p this> <lt> <p s>
|
||||
// @flag UNDEFINED | se l'ordine non e' definito
|
||||
static int sortable_compare(
|
||||
const TObject** o1, // @parm Primo oggetto da confrontare
|
||||
const TObject** o2) // @parm Secondo oggetto da confrontare
|
||||
|
||||
static int sortable_compare(const TObject** o1, const TObject** o2)
|
||||
// @comm E' utilizzata dalla funzione <mf TArray::sort> come default per
|
||||
// stabilire il criteri di ordinamento degli oggetti passati.
|
||||
{
|
||||
const TSortable* s1 = (const TSortable*)*o1;
|
||||
const TSortable* s2 = (const TSortable*)*o2;
|
||||
return s1->compare(*s2);
|
||||
}
|
||||
|
||||
void TArray::sort(COMPARE_FUNCTION compare)
|
||||
// @mfunc Ordina i TObject secondo il criterio definito in <t COMPARE_FUNCTION>
|
||||
void TArray::sort(
|
||||
COMPARE_FUNCTION compare) // @parm Funzione indicante il criterio di ordinamento (default TSortable)
|
||||
|
||||
// @comm Nel caso non venga passata nessuna funzione che permetta di conforntare
|
||||
// i due oggetti viene utilizzato il criterio <c Tsortable>
|
||||
{
|
||||
typedef int (*qsortfunc)(const void*, const void*);
|
||||
if (compare == NULL) compare = sortable_compare;
|
||||
@ -262,7 +338,13 @@ TBit_array::TBit_array(long size) : _bit(NULL), _size(0)
|
||||
if (size) resize(index(size));
|
||||
}
|
||||
|
||||
void TBit_array::copy(const TBit_array& ba)
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc Copia nell'array l'elemento passato come parametro
|
||||
void TBit_array::copy(
|
||||
const TBit_array& ba) // @parm Oggetto da copiare nell'array
|
||||
|
||||
// @comm Sostituisce all'elemento corrente dell'array l'elemento passato come parametro.
|
||||
{
|
||||
if (_bit)
|
||||
{
|
||||
@ -302,7 +384,16 @@ void TBit_array::reset()
|
||||
}
|
||||
|
||||
// Certified 99%
|
||||
void TBit_array::resize(word size)
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc Modifica la dimensione dell'array.
|
||||
void TBit_array::resize(
|
||||
word size) // @parm Indica la nuova dimensione che deve assumere l'array.
|
||||
|
||||
// @comm Alloca la memoria necessaria per contentere i dati della nuova
|
||||
// dimensione inizializzando a NULL tutti i nuovi elementi aggiunti
|
||||
// all'array lasciando inalterati, sia in posizione che in
|
||||
// contenuto gli elementi gia' presenti.
|
||||
{
|
||||
word oldsize = _size;
|
||||
byte* oldbit = _bit;
|
||||
@ -361,8 +452,18 @@ void TBit_array::not(long n)
|
||||
_bit[i] ^= mask(n);
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
// Certified 90%
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @mfunc Ritorna il numero di 1 presenti nell'array
|
||||
long TBit_array::ones() const
|
||||
|
||||
// @rdesc Numero di 1 trovati.
|
||||
//
|
||||
// @comm Passa tutto l'array di bit e conta quanti degli elementi presenti sono
|
||||
// settati ad 1.
|
||||
//
|
||||
// @xref <mf TBit_array::last_one> <mf TBit_array::first_one>
|
||||
{
|
||||
long one = 0;
|
||||
for (word i = 0; i < _size; i++)
|
||||
@ -378,7 +479,20 @@ long TBit_array::ones() const
|
||||
}
|
||||
|
||||
// Certified 90%
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @mfunc Ritorna la posizione dell'ultimo 1 nell'array
|
||||
long TBit_array::last_one() const
|
||||
|
||||
// @rdesc Ritorna i seguenti valori:
|
||||
//
|
||||
// @flag >0 | Posizione nella quale si trova l'ultimo 1
|
||||
// @flag -1 | Se non sono presenti bit settati ad 1
|
||||
//
|
||||
// @comm Cerca all'interno dell'array di bit la posizione dell'ultimo bit
|
||||
// settato ad 1
|
||||
//
|
||||
// @xref <mf TBit_array::first_one> <mf TBit_array::ones>
|
||||
{
|
||||
for (word i = _size; i--;)
|
||||
{
|
||||
@ -393,7 +507,18 @@ long TBit_array::last_one() const
|
||||
}
|
||||
|
||||
// Certified 90%
|
||||
// @mfunc Ritorna la posizione del primo 1 nell'array
|
||||
long TBit_array::first_one() const
|
||||
|
||||
// @rdesc Ritorna i seguenti valori:
|
||||
//
|
||||
// @flag >0 | Posizione nella quale si trova il primo 1
|
||||
// @flag -1 | Se non sono presenti bit settati ad 1
|
||||
//
|
||||
// @comm Cerca all'interno dell'array di bit la posizione del primo bit
|
||||
// settato ad 1
|
||||
//
|
||||
// @xref <mf TBit_array::last_one> <mf TBit_array::ones>
|
||||
{
|
||||
for (word i = 0; i < _size; i++)
|
||||
{
|
||||
@ -407,7 +532,18 @@ long TBit_array::first_one() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc Controlla se si tratta di un oggetto valido
|
||||
bool TBit_array::ok() const
|
||||
|
||||
// @rdesc Ritorna uno dei seguenti parametri:
|
||||
//
|
||||
// @flag TRUE | Se l'array contiene degli elementi
|
||||
// @flag FALSE | Se l'array e' vuoto
|
||||
//
|
||||
// @comm Controlla se la dimensione dell'array e' maggiore di 0 e se esistono
|
||||
// degli elementi diversi da NULL
|
||||
{
|
||||
return _bit != NULL && _size > 0;
|
||||
}
|
||||
@ -420,12 +556,17 @@ void TBit_array::set(const char* numbers)
|
||||
if (isdigit(*n)) set(atol(n));
|
||||
}
|
||||
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc Stampa un array
|
||||
void TBit_array::print_on(
|
||||
ostream& out) const // @parm Indica l'output sul quale reindirizzare la stampa (funzione standard del C++)
|
||||
|
||||
void TBit_array::print_on(ostream& out) const
|
||||
// @comm Stampa tutti gli indici degli elementi diversi da 0
|
||||
{
|
||||
const long last = _size<<3;
|
||||
for (long i = 1; i < last; i++)
|
||||
if (operator[](i)) out << ' ' << i;
|
||||
if (operator[](i)) out << ' ' << i;
|
||||
}
|
||||
|
||||
|
||||
|
106
include/array.h
106
include/array.h
@ -15,87 +15,86 @@ class TArray;
|
||||
//
|
||||
// @type COMPARE_FUNCTION | Prototipo funzione di confronto tra elementi della
|
||||
// clsse <c TObject> da passare al metodo sort dei <c TArray>
|
||||
|
||||
typedef (*COMPARE_FUNCTION)(const TObject**, const TObject**);
|
||||
|
||||
// @class TArray | Classe per la definizione degli array
|
||||
//
|
||||
// @base public | TObject
|
||||
|
||||
class TArray : public TObject
|
||||
{
|
||||
|
||||
// @access Private Member
|
||||
|
||||
TObject** _data; // @cmember TObject** | _data | | Array di puntatori ad oggetti
|
||||
int _size; // @cmember int | _size | | Dimensione dell'array
|
||||
int _items; // @cmember int |_items | | Numero di elementi presenti nell'array
|
||||
// @cmember Array di puntatori ad oggetti
|
||||
TObject** _data;
|
||||
// @cmember Dimensione dell'array
|
||||
int _size;
|
||||
// @cmember Numero di elementi presenti nell'array
|
||||
int _items;
|
||||
|
||||
// @access Protected Member
|
||||
|
||||
protected:
|
||||
|
||||
// @cmember void | resize | (int newdim) | Modifica la dimensione dell'array.
|
||||
// @cmember Modifica la dimensione dell'array.
|
||||
void resize(int newdim);
|
||||
|
||||
// @access Public member
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @cmember void | TArray | (int arraysize) | Costruttore. Crea un array (chiama <mf TArray::resize>)
|
||||
// @cmember Costruttore. Crea un array (chiama <mf TArray::resize>)
|
||||
TArray(int arraysize);
|
||||
// @cmember void | TArray | ( ) | Costruttore. Crea un array (non chiama <mf TArray::resize>)
|
||||
// @cmember Costruttore. Crea un array (non chiama <mf TArray::resize>)
|
||||
TArray();
|
||||
// @cmember void | TArray | (const TArray&) | Costruttore. Copia tutto l'array e ne duplica gli elementi
|
||||
// @cmember Costruttore. Copia tutto l'array e ne duplica gli elementi
|
||||
TArray(const TArray&);
|
||||
|
||||
// @cmember virtual | ~TArray | () | Distruttore
|
||||
// @cmember Distruttore
|
||||
virtual ~TArray() ;
|
||||
// @cmember virtual const char * | class_name | () const | Ritorna il nome della classe
|
||||
// @cmember Ritorna il nome della classe
|
||||
virtual const char* class_name() const ;
|
||||
// @cmember virtual word | class_id | () const | Ritorna l'id della class
|
||||
// @cmember Ritorna l'id della class
|
||||
virtual word class_id() const ;
|
||||
// @cmember virtual void | print_on | (ostream& out) const | Stampa un array
|
||||
// @cmember Stampa un array
|
||||
virtual void print_on(ostream& out) const ;
|
||||
// @cmember virtual bool | ok | () const | TRUE se l'array non e' vuoto
|
||||
// @cmember Controlla se si tratta di un oggetto valido
|
||||
virtual bool ok() const ;
|
||||
|
||||
// @cmember int | size | () const | Ritorna la grandezza dell'array
|
||||
int size() const { return _size; }
|
||||
// @cmember int | items | () const | Ritorna numero di oggetti nell'array
|
||||
int items() const { return _items; }
|
||||
// @cmember int | last | () const | Ritorna l'indice dell'ultimo oggetto
|
||||
// @cmember Ritorna la grandezza dell'array
|
||||
int size() const
|
||||
{ return _size; }
|
||||
// @cmember Ritorna numero di oggetti nell'array
|
||||
int items() const
|
||||
{ return _items; }
|
||||
// @cmember Ritorna l'indice dell'ultimo oggetto
|
||||
int last() const;
|
||||
|
||||
// @cmember TObject& | operator[] | (int index) const | Ritorna l'oggetto puntato da index
|
||||
// @cmember Ritorna l'oggetto puntato da index
|
||||
TObject& operator[] (int index) const ;
|
||||
// @cmember TObject* | objptr | () const | Ritorna l'oggetto di posto index
|
||||
// @cmember Ritorna l'oggetto di posto index
|
||||
TObject* objptr(int index) const ;
|
||||
// @cmember Tarray& | operator= | (const TArray& a) | Confronta se i due array sono uguali
|
||||
// @cmember Assegna all'array l'oggetto passato
|
||||
TArray& operator= (const TArray& a);
|
||||
|
||||
// @cmember virtual bool | destroy | (int index, bool pack) | Rimuove uno o tutti gli elementi (default)
|
||||
// @cmember Rimuove uno o tutti (default) gli elementi
|
||||
virtual bool destroy(int index = -1, bool pack = FALSE);
|
||||
// @cmember virtual int | add | (TObject* obj, int index) | Aggiunge un oggetto ad un array.
|
||||
// @cmember Aggiunge un oggetto ad un array.
|
||||
virtual int add(TObject* obj, int index = -1) ;
|
||||
// @cmember virtual int | insert | (TObject* obj, int index) | Inserisce un elemento dell'array nella poszione index
|
||||
// @cmember Inserisce un elemento dell'array nella posizione index
|
||||
virtual int insert(TObject* obj, int index = 0);
|
||||
|
||||
// (casino se non ha dup() definita)
|
||||
// @cmember int | add | (const TObject& object, int index) | Aggiunge un oggetto all'array. L'oggetto viene duplicato
|
||||
// @cmember Aggiunge un oggetto all'array. L'oggetto viene duplicato
|
||||
int add(const TObject& object, int index = -1) ;
|
||||
// @cmember int | insert | (const TObject& object, int index) | Inserisce un oggetto alla posizione index
|
||||
// @cmember Inserisce un oggetto alla posizione index
|
||||
int insert(const TObject& object, int index = 0);
|
||||
// @cmember TObject* | remove | (int index, bool pack) | Elimina l'elemento nella poszione index dell'array
|
||||
// @cmember Elimina l'elemento nella posizione index dell'array
|
||||
TObject* remove(int index, bool pack = FALSE);
|
||||
// @cmember void | swap | (int i1, int i2) | Scambia di posto gli elemnti i1 e i2 dell'array
|
||||
// @cmember Scambia di posto due elementi dell'array
|
||||
void swap(int i1, int i2);
|
||||
// @cmember void | pack | () | Rende contigui tutti gli elementi non nulli
|
||||
// @cmember Rende contigui tutti gli elementi non nulli
|
||||
void pack();
|
||||
// @cmember void | sort | (COMPARE_FUNCTION) | Ordina i TObject (TSortable per default) secondo il criterio definito in <t COMPARE_FUNCTION>
|
||||
// @cmember Ordina i TObject secondo il criterio definito in <t COMPARE_FUNCTION>
|
||||
void sort(COMPARE_FUNCTION = NULL);
|
||||
};
|
||||
|
||||
//ANDREA
|
||||
inline TObject* TArray::objptr(int index) const
|
||||
{
|
||||
return (index < _size && index >= 0) ? _data[index] : NULL;
|
||||
@ -110,41 +109,74 @@ inline TObject& TArray::operator[] (int index) const
|
||||
#endif
|
||||
return *o;
|
||||
}
|
||||
|
||||
// @class TBit_array | Come la classe <c TArray> ma i suoi elementi sono bit;
|
||||
// questo permette di costruire array piu' piccoli rispetto
|
||||
// alla classe TArray.
|
||||
//
|
||||
// @base public | TObject
|
||||
class TBit_array : public TObject
|
||||
{
|
||||
|
||||
// @access Private Member
|
||||
|
||||
// @cmember dimensione dell'array
|
||||
word _size;
|
||||
// @cmember bit in cui sono contenuti i dati
|
||||
byte* _bit;
|
||||
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Controlla se si tratta di un oggetto valido
|
||||
virtual bool ok() const;
|
||||
// @cmember Stampa un array
|
||||
virtual void print_on(ostream& out) const;
|
||||
|
||||
// @cmember Modifica la dimensione dell'array.
|
||||
void resize(word size);
|
||||
// @cmember Copia nell'array l'elemento passato come parametro
|
||||
void copy(const TBit_array& ba);
|
||||
// @cmember Ritorna il numero del byte contenente il bit n
|
||||
word index(long n) const { return word(n >> 3); }
|
||||
// @cmember Ritorna la posizione del bit n all'interno del byte
|
||||
byte mask(long n) const { return 1 << (n & 0x7); }
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @cmember Costruttore. Crea un array di (chiama <mf TBit_array::resize>)
|
||||
TBit_array(long size = 0);
|
||||
// @cmember Costruttore. Crea un array di (chiama <mf TBit_array::copy>)
|
||||
TBit_array(const TBit_array& ba);
|
||||
// @cmember Distruttore
|
||||
virtual ~TBit_array();
|
||||
|
||||
// @cmember Assegna all'array l'oggetto passato
|
||||
TBit_array& operator=(const TBit_array& ba);
|
||||
// @cmember Ritorna l'oggetto puntato da n
|
||||
bool operator[] (long n) const;
|
||||
// @cmember Ritorna l'or logico tra due Bit_array modificando l'oggetto corrente
|
||||
TBit_array& operator |=(const TBit_array& b);
|
||||
|
||||
// @cmember Ritorna la posizione del primo 1 nell'array (-1 se non lo trova)
|
||||
long first_one() const;
|
||||
// @cmember Ritorna la posizione dell'ultimo 1 nell'array (-1 se non lo trova)
|
||||
long last_one() const;
|
||||
// @cmember Ritorna il numero di 1 presenti nell'array
|
||||
long ones() const;
|
||||
|
||||
// @cmember Setta ad 1 il bit n-esimo dell'array
|
||||
void set(long n);
|
||||
// @cmember Setta a 0 il bit n-esimo dell'array
|
||||
void reset(long n);
|
||||
// @cmember Not logico del bit n-esimo dell'array
|
||||
void not(long n);
|
||||
|
||||
// @cmember Setta il bit n-esimo a seconda del valore passato come secondo elemento
|
||||
void set(long n, bool on) { on ? set(n) : reset(n); }
|
||||
// @cmember Setta ad 1 tutti i bit dell'array
|
||||
void set();
|
||||
// @cmember Setta a 0 tutti i bit dell'array
|
||||
void reset();
|
||||
// @cmember Data una stringa setta ad 1 gli elementi indicati della stringa
|
||||
void set(const char* numbers);
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,21 @@
|
||||
#include <assoc.h>
|
||||
|
||||
THash_object* TAssoc_array::_lookup(const char* k, bool& isnew, bool insert)
|
||||
// @doc EXTERNAL
|
||||
|
||||
// @mfunc Cerca l'oggetto con chiave <p k>
|
||||
THash_object* TAssoc_array::_lookup(
|
||||
const char* k, // @parm Chiave da cercare
|
||||
bool& isnew, // @parm Viene asseganto TRUE se si tratta di una nuova chiave
|
||||
bool insert) // @parm Permette di inserire la chiave
|
||||
|
||||
// @comm Ricerca all'interno della tabella hash l'oggetto con la chiave <p k>,
|
||||
// nel caso non venga trovato <p isnew> ritorna TRUE (si tratta di un
|
||||
// oggetto nuovo) e viene inserito nella tabella se il parametro <p insert>
|
||||
// e' settato a TRUE.
|
||||
//
|
||||
// @rdesc Ritorna l'oggetto corrispondente alla chiave passate come parametro.
|
||||
// <nl>Il parametro <p isnew> assume il valore TRUE se si tratta di un
|
||||
// nuovo oggetto.
|
||||
{
|
||||
const TFixed_string key(k);
|
||||
const word hv = key.hash() % HASH_SIZE;
|
||||
@ -35,8 +50,25 @@ void TAssoc_array::destroy()
|
||||
_cnt = _row = _col = 0;
|
||||
}
|
||||
|
||||
bool TAssoc_array::add(const char* key, TObject* obj,
|
||||
bool force)
|
||||
// @mfunc Aggiunge un oggetto all'array.
|
||||
bool TAssoc_array::add(
|
||||
const char* key, // @parm Chiave d'ordinamento
|
||||
TObject* obj, // @parm Ogetto da inserire (default=NULL)
|
||||
bool force) // @parm Permette di forzare l'inserimento se esiste gia'
|
||||
// un oggetto con la stessa chiave
|
||||
|
||||
// @parm const TObject | &obj | Indirizzo dell'oggetto da aggiungere
|
||||
//
|
||||
// @syntax add(const char* key, TObject* obj, bool force)
|
||||
// @syntax add(const char* key, const TObject& obj, bool force)
|
||||
//
|
||||
// @comm Se l'oggetto da aggiungere esite gia' la chiave guarda il parametro <p force>:
|
||||
// <nl>se <p force> = TRUE lo sostituisce e ritorna TRUE,
|
||||
// <nl>se <p force> = FALSE non sostituisce e ritorna TRUE,
|
||||
// <nl>altrimenti ritorna FALSE.
|
||||
// <nl><nl>Nel caso l'oggetto da aggiungere venga passato per indirizzo
|
||||
// la funzione aggiunge una copia dell'oggetto e quindi deve essere
|
||||
// definita <mf TObject::dup>
|
||||
{
|
||||
bool isnew = FALSE;
|
||||
|
||||
@ -61,7 +93,16 @@ bool TAssoc_array::add(const char* key, const TObject& obj, bool force)
|
||||
return add(key,obj.dup(),force);
|
||||
}
|
||||
|
||||
bool TAssoc_array::remove(const char* k)
|
||||
// @mfunc Elimina un oggetto.
|
||||
bool TAssoc_array::remove(
|
||||
const char* k) // @parm Chiave dell'oggetto da eliminare
|
||||
|
||||
// @comm Cerca nella tabella hash l'oggetto con chiave <p k> e lo elimina.
|
||||
//
|
||||
// @rdesc Ritorna il risultato dell'operazione
|
||||
//
|
||||
// @flag TRUE | Eliminazione avvenuta
|
||||
// @flag FALSE | L'oggetto non e' stato trovato
|
||||
{
|
||||
const TFixed_string key(k);
|
||||
const word hv = key.hash() % HASH_SIZE;
|
||||
@ -81,7 +122,16 @@ bool TAssoc_array::remove(const char* k)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TObject& TAssoc_array::find(const char* key)
|
||||
// @mfunc Trova l'oggetto indicizzato
|
||||
TObject& TAssoc_array::find(
|
||||
const char* key) // @parm Chiave dell'oggetto da trovare
|
||||
|
||||
|
||||
// @comm Cerca l'oggetto indicizzato con chiave <p key>. Viene controllato se
|
||||
// non c'e' (normalmente si usa operator[key])
|
||||
//
|
||||
// @rdesc Ritorna l'oggetto cercato. Se l'oggetto aggiunto era NULL
|
||||
// ritorna error object
|
||||
{
|
||||
bool isnew = FALSE;
|
||||
THash_object* o = _lookup(key, isnew);
|
||||
@ -90,7 +140,11 @@ TObject& TAssoc_array::find(const char* key)
|
||||
else return *(o->_obj);
|
||||
}
|
||||
|
||||
TObject* TAssoc_array::objptr(const char* key)
|
||||
// @mfunc Ritorna l'oggetto con chiave <p key>
|
||||
TObject* TAssoc_array::objptr(
|
||||
const char* key) // @parm Chiave dell'oggetto da ritornare
|
||||
|
||||
// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna NULL
|
||||
{
|
||||
bool isnew;
|
||||
THash_object* o = NULL;
|
||||
@ -99,7 +153,14 @@ TObject* TAssoc_array::objptr(const char* key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool TAssoc_array::is_key(const char* key)
|
||||
// @mfunc Controlla l'esistenza di una chiave
|
||||
bool TAssoc_array::is_key(
|
||||
const char* key) // @parm Chiave da cercarne l'esistenza
|
||||
|
||||
// @rdesc Ritorna il risultato della ricerca
|
||||
//
|
||||
// @flag TRUE | Se la chiave esiste
|
||||
// @flag FALSE | Se la chiave non esiste
|
||||
{
|
||||
bool isnew = FALSE;
|
||||
const THash_object* o = _lookup(key, isnew);
|
||||
@ -107,7 +168,13 @@ bool TAssoc_array::is_key(const char* key)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// @mfunc Ritorna solo l'oggetto
|
||||
TObject* TAssoc_array::get()
|
||||
|
||||
// @rdesc Ritorna il puntatore all'oggetto (se diverso da NULL), altrimenti
|
||||
// ritorna error object
|
||||
//
|
||||
// @xref <mf TAssoc_array::get_hashobj>
|
||||
{
|
||||
const TArray* arr = &_data[_row];
|
||||
|
||||
@ -125,7 +192,15 @@ TObject* TAssoc_array::get()
|
||||
return (o == NULL || o->_obj == NULL) ? &error : o->_obj;
|
||||
}
|
||||
|
||||
// @mfunc Ritorna l'oggetto e la relativa chiave
|
||||
THash_object* TAssoc_array::get_hashobj()
|
||||
|
||||
// @comm Se l'oggetto viene trovato viene richiamata la funzione
|
||||
// <mf TAssoc_array::objptr>
|
||||
//
|
||||
// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna NULL
|
||||
//
|
||||
// @xref <mf TAssoc_array::get>
|
||||
{
|
||||
const TArray* arr = &_data[_row];
|
||||
|
||||
@ -141,4 +216,3 @@ THash_object* TAssoc_array::get_hashobj()
|
||||
|
||||
return (THash_object*)arr->objptr(_col++);
|
||||
}
|
||||
|
||||
|
108
include/assoc.h
108
include/assoc.h
@ -5,83 +5,117 @@
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @class THash_object | Classe per la definizione degli elementi di una tabella
|
||||
hash. Ha come classe friend la classe <c TAssoc_array>
|
||||
//
|
||||
// @base public | TObject
|
||||
class THash_object : public TObject
|
||||
{
|
||||
friend class TAssoc_array;
|
||||
|
||||
// @access Private Member
|
||||
|
||||
// @cmember Chiave d'ordinamento
|
||||
TString _key;
|
||||
// @cmember Oggetto della tabella da ordinare
|
||||
TObject* _obj;
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
|
||||
TString& key() { return _key; }
|
||||
TObject& obj() { return *_obj; }
|
||||
// @cmember Ritorna la chiave di ordinamento
|
||||
TString& key()
|
||||
{ return _key; }
|
||||
// @cmember Ritorna l'oggetto
|
||||
TObject& obj()
|
||||
{ return *_obj; }
|
||||
|
||||
THash_object(const char* k) : _key(k) {}
|
||||
~THash_object() { if (_obj != NULL) delete _obj; }
|
||||
// @cmember Costruttore (inizializza la chiave)
|
||||
THash_object(const char* k) : _key(k), _obj(NULL)
|
||||
{}
|
||||
// @cmember Distruttore
|
||||
~THash_object()
|
||||
{ if (_obj != NULL) delete _obj; }
|
||||
};
|
||||
|
||||
|
||||
// @class TAssoc_array | Tabella hash di oggetti generici
|
||||
//
|
||||
// @base public |TObject
|
||||
class TAssoc_array : public TObject
|
||||
{
|
||||
enum { HASH_SIZE = 113 };
|
||||
word _cnt;
|
||||
word _row;
|
||||
word _col;
|
||||
TArray _data[HASH_SIZE];
|
||||
|
||||
//@access Private Member
|
||||
|
||||
// @cmember Dimensione della tabella hash
|
||||
enum { HASH_SIZE = 113 };
|
||||
// @cmember Numero di oggetti contenuti nella tabella
|
||||
word _cnt;
|
||||
// @cmember Numero di righe della tabella hash
|
||||
word _row;
|
||||
// @cmember Numero di colonne della tabella hash
|
||||
word _col;
|
||||
// @cmember Array contenente i dati veri e propri
|
||||
TArray _data[HASH_SIZE];
|
||||
|
||||
protected:
|
||||
// @access Protected member
|
||||
protected:
|
||||
|
||||
// @cmember Cerca l'oggetto con chiave k
|
||||
THash_object* _lookup(const char* k, bool& isnew, bool insert = FALSE);
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
|
||||
int items() const { return _cnt; }
|
||||
// @cmember Ritorna il numero di elementi presenti
|
||||
int items() const
|
||||
{ return _cnt; }
|
||||
|
||||
// @cmember Cancella tutti gli elementi
|
||||
virtual void destroy();
|
||||
|
||||
// aggiunge oggetto; Se c'era gia' la chiave guarda force:
|
||||
// se force = TRUE lo sostituisce e ritorna TRUE
|
||||
// se force = FALSE non sostituisce e ritorna TRUE
|
||||
// altrimenti ritorna FALSE
|
||||
// @cmember Aggiunge un oggetto. Se era gia' presente guarda il parametro force
|
||||
bool add(const char* key, TObject* obj = NULL, bool force = FALSE);
|
||||
|
||||
// aggiunge copia oggetto (deve avere dup()). Vedi l'altra
|
||||
// per i parametri
|
||||
// @cmember Aggiunge una copia dell'oggetto
|
||||
bool add(const char* key, const TObject& obj, bool force = FALSE);
|
||||
|
||||
// elimina oggetto; ritorna FALSE se non c'era
|
||||
// @cmember Elimina un oggetto
|
||||
bool remove(const char* key);
|
||||
|
||||
// trova oggetto indicizzato; check se non c'e'
|
||||
// normalmente si usa operator[key]
|
||||
// se l'oggetto aggiunto era NULL ritorna error object
|
||||
// @cmember Trova l'oggetto indicizzato
|
||||
TObject& find(const char* key);
|
||||
|
||||
// ritorna puntatore o NULL
|
||||
// @cmember Ritorna l'oggetto con chiave key
|
||||
TObject* objptr(const char* key);
|
||||
|
||||
// TRUE se la chiave c'e', FALSE altrimenti
|
||||
bool is_key(const char* key);
|
||||
// @cmember Controlla l'esistenza di una chiave
|
||||
bool is_key(const char* key);
|
||||
|
||||
// l'indice e' un po' strano ma si usera' questa poiche'
|
||||
// 1) e' intuitivo
|
||||
// 2) fa molto figo
|
||||
TObject& operator[] (const char* key) { return find(key); }
|
||||
// @cmember Ritorna l'indice del oggetto con chiave key (pi— intuitivo di
|
||||
// <mf TAssoc_array::find>
|
||||
TObject& operator[] (const char* key)
|
||||
{ return find(key); }
|
||||
|
||||
// iterazione come TToken_string
|
||||
// si puo' adoperare get() e get_hashobj() intercambiabilmente ma
|
||||
// non sono indipendenti (entrambe avanzano gli stessi contatori)
|
||||
|
||||
TObject* get(); // ritorna solo l'object
|
||||
THash_object* get_hashobj(); // se serve anche la chiave
|
||||
void restart() { _row = 0; _col = 0; }
|
||||
// @cmember Ritorna solo l'oggetto
|
||||
TObject* get();
|
||||
// @cmember Ritorna l'oggetto e la relativa chiave
|
||||
THash_object* get_hashobj();
|
||||
// @cmember Azzera il numero di righe e colonne della tabella hash
|
||||
void restart()
|
||||
{ _row = 0; _col = 0; }
|
||||
|
||||
TAssoc_array() : _cnt(0), _row(0), _col(0) {}
|
||||
// @cmember Costruttore
|
||||
TAssoc_array() : _cnt(0), _row(0), _col(0)
|
||||
{}
|
||||
// @cmember Distruttore
|
||||
virtual ~TAssoc_array() { destroy(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
156
include/object.h
156
include/object.h
@ -16,62 +16,81 @@
|
||||
#ifndef __CHECKS_H
|
||||
#include <checks.h>
|
||||
#endif
|
||||
// @C
|
||||
// Classe Object
|
||||
// @END
|
||||
|
||||
// @N
|
||||
// Base class for all object hierarchy
|
||||
// @END
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Object
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @class TObject | Classe base per la definizione della gerarchia degli oggetti
|
||||
class TObject
|
||||
{
|
||||
// @access Public Member
|
||||
public:
|
||||
// @FPUB
|
||||
virtual ~TObject() {}
|
||||
// @cmember Distruttore
|
||||
virtual ~TObject()
|
||||
{}
|
||||
// @cmember Ritorna il nome della classe
|
||||
virtual const char* class_name() const;
|
||||
// @cmember Ritorna l'id della classe
|
||||
virtual word class_id() const;
|
||||
// @cmember Controlla se si tratta di un oggetto valido (sempre TRUE)
|
||||
virtual bool ok() const;
|
||||
// @cmember Duplica un'oggetto
|
||||
virtual TObject* dup() const;
|
||||
// @cmember Permette di stampare l'oggetto
|
||||
virtual void print_on(ostream& out) const;
|
||||
virtual void read_from(istream&) {}
|
||||
virtual word hash() const { return 0; }
|
||||
// @cmember Permette di leggere l'oggetto da istream
|
||||
virtual void read_from(istream&)
|
||||
{}
|
||||
// @cmember Ritorna il codice hash dell'oggetto
|
||||
virtual word hash() const
|
||||
{ return 0; }
|
||||
};
|
||||
|
||||
|
||||
// @C
|
||||
// Classe TErrorObject
|
||||
// @END
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Error Object
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// @class TError_Object | Classe per poter ritornare un oggetto sempre errato (ok() == false)
|
||||
//
|
||||
// @base public | TObject
|
||||
class TError_Object : public TObject
|
||||
{
|
||||
// @access Public Member
|
||||
public:
|
||||
// @FPUB
|
||||
// @cmember Ritorna il nome dell'oggetto
|
||||
virtual const char* class_name() const;
|
||||
// @cmember Ritorna l'id della classe
|
||||
virtual word class_id() const;
|
||||
// @cmember Controlla se si tratta di un oggetto valido (sempre FALSE)
|
||||
virtual bool ok() const;
|
||||
|
||||
// @xref <c TObject>
|
||||
};
|
||||
|
||||
|
||||
// @C
|
||||
// Classe TSortable
|
||||
// @END
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Error Object
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// @class TSortable | Classe per la comparazione degli oggetti
|
||||
//
|
||||
// @base public | TObject
|
||||
class TSortable : public TObject
|
||||
{
|
||||
// @access Public Memebr
|
||||
public:
|
||||
// @FPUB
|
||||
// @cmember Permette la comparazione degli oggetti
|
||||
// <nl>Ritorna: <gt>0 se <p this> <gt> <p s>
|
||||
// <nl> 0 se <p this> == <p s>
|
||||
// <nl> <lt>0 se <p this> <lt> <p s>
|
||||
// <nl> UNDEFINED se l'ordine non e' definito
|
||||
virtual int compare(const TSortable& s) const pure;
|
||||
// @cmember Ritorna il nome della classe
|
||||
virtual const char* class_name() const;
|
||||
// @cmember Ritorna l'id della classe
|
||||
virtual word class_id() const;
|
||||
};
|
||||
|
||||
@ -80,58 +99,131 @@ public:
|
||||
// inline functions
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// @FIN
|
||||
inline ostream& operator <<(ostream& out, const TObject& obj)
|
||||
// @func inline ostream& | operator <lt><lt> | Permette di reindirizzare l'oggeto per la stampa
|
||||
inline ostream& operator <<(
|
||||
ostream& out, // @parm Indica l'output sul quale stampare l'oggetto
|
||||
const TObject& obj) // @parm Oggetto da stampare
|
||||
|
||||
// @rdesc Ritorna l'output sul quale e' stata reindirizzata la stampa
|
||||
{
|
||||
obj.print_on(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
// @FIN
|
||||
inline istream& operator >>(istream& in, TObject& obj)
|
||||
// @func inline istream& | operator <gt><gt> | Permette di leggere l'oggetto
|
||||
inline istream& operator >>(
|
||||
istream& in, // @parm Input da cui leggere l'oggetto
|
||||
TObject& obj) // @parm Indirizzo in cui posizionare l'oggetto letto
|
||||
|
||||
// @rdesc Ritorna l'input dal quale e' stato letto l'oggetto
|
||||
//
|
||||
// @comm Legge dall'input passato come parametro l'oggetto, nel caso si tratti
|
||||
// di un oggetto on valido viene dato un messaggio di errore.
|
||||
{
|
||||
obj.read_from(in);
|
||||
CHECK(obj.ok(), "Can't read an Object from a stream");
|
||||
return in;
|
||||
}
|
||||
|
||||
inline bool operator ==(const TSortable& a, const TSortable& b)
|
||||
// @func inline bool | operator == | Controlla se 2 oggetti sono uguali
|
||||
//
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se i due oggetti sono uguali
|
||||
// @flag FALSE | Se i due oggetti sono diversi
|
||||
inline bool operator ==(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
|
||||
// @comm Controlla se i due oggetti passati come parametro sono uguali
|
||||
// utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res == 0 || res == UNDEFINED;
|
||||
}
|
||||
|
||||
inline bool operator >(const TSortable& a, const TSortable& b)
|
||||
// @func inline bool | operator <gt> | Controlla se un oggetto e' maggiore dell'altro
|
||||
inline bool operator >(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se <p a> e' maggiore di <p b>
|
||||
// @flag FALSE | Se <p b> e' maggiore o uguale a <p a>
|
||||
//
|
||||
// @comm Controlla se l'oggetti passato come primo parametro e' maggiore del
|
||||
// secondo utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res > 0 || res == UNDEFINED;
|
||||
}
|
||||
|
||||
inline bool operator <(const TSortable& a, const TSortable& b)
|
||||
// @func inline bool | operator <lt> | Controlla se un oggetto e' minore dell'altro
|
||||
inline bool operator <(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se <p a> e' minore di <p b>
|
||||
// @flag FALSE | Se <p b> e' minore o uguale a <p a>
|
||||
//
|
||||
// @comm Controlla se l'oggetti passato come primo parametro e' minore del
|
||||
// secondo utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res < 0 || res == UNDEFINED;
|
||||
}
|
||||
|
||||
inline bool operator >=(const TSortable& a, const TSortable& b)
|
||||
// @func inline bool | operator <gt>= | Controlla se un oggetto e' maggiore o uguale all'altro
|
||||
inline bool operator >=(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se <p a> e' maggiore o uguale a <p b>
|
||||
// @flag FALSE | Se <p b> e' maggiore <p a>
|
||||
//
|
||||
// @comm Controlla se l'oggetti passato come primo parametro e' maggiore o uguale al
|
||||
// secondo utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res >= 0 || res == UNDEFINED;
|
||||
}
|
||||
|
||||
inline bool operator <=(const TSortable& a, const TSortable& b)
|
||||
// @func inline bool | operator <lt>= | Controlla se un oggetto e' minore o uguale all'altro
|
||||
inline bool operator <=(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se <p a> e' minore o uguale a <p b>
|
||||
// @flag FALSE | Se <p b> e' minore <p a>
|
||||
//
|
||||
// @comm Controlla se l'oggetti passato come primo parametro e' minore o uguale al
|
||||
// secondo utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res <= 0 || res == UNDEFINED;
|
||||
}
|
||||
|
||||
inline bool operator !=(const TSortable& a, const TSortable& b)
|
||||
|
||||
// @func inline bool | operator != | Controlla se 2 oggetti sono diversi
|
||||
//
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se i due oggetti sono diversi
|
||||
// @flag FALSE | Se i due oggetti sono uguali
|
||||
inline bool operator !=(
|
||||
const TSortable& a, // @parm Primo oggetto da confrontare
|
||||
const TSortable& b) // @parm Secondo oggetto da confrontare
|
||||
|
||||
// @comm Controlla se i due oggetti passati come parametro sono diversi
|
||||
// utilizzando il criterio di comparazione previsto per l'oggetto.
|
||||
{
|
||||
int res = a.compare(b);
|
||||
return res != 0 && res != UNDEFINED;
|
||||
@ -141,9 +233,7 @@ inline bool operator !=(const TSortable& a, const TSortable& b)
|
||||
#define extern
|
||||
#endif
|
||||
|
||||
// @DPUB
|
||||
extern TError_Object error;
|
||||
// @END
|
||||
|
||||
#undef extern
|
||||
|
||||
|
@ -58,10 +58,16 @@ HIDDEN TString512 spark;
|
||||
inline bool is_space(char c)
|
||||
{ return c >= '\t' && c <= ' '; }
|
||||
|
||||
// Dinamically resizes a string
|
||||
// Certified 99%
|
||||
// It doesn't work for static strings and negative values of size
|
||||
void TString::resize(int size, bool cpy)
|
||||
// @doc EXTERNAL
|
||||
//
|
||||
// @mfunc Rialloca la stringa
|
||||
void TString::resize(
|
||||
int size, // @parm Nuova dimensione della stringa
|
||||
bool cpy) // @parm Se TRUE mantiene il contenuto della stringa e alloca
|
||||
// nuovo spazio
|
||||
|
||||
// @comm Non funzione con le stringhe static e per valori negativi di <p size>
|
||||
{
|
||||
char* s = new char[size+1];
|
||||
if (cpy && _str) strcpy(s, _str);
|
||||
@ -74,9 +80,15 @@ void TString::resize(int size, bool cpy)
|
||||
_size = size;
|
||||
}
|
||||
|
||||
// Set the value for the string
|
||||
// Certified 99% (uses resize)
|
||||
TString& TString::set(const char* s)
|
||||
// @doc INTERNAL
|
||||
//
|
||||
// @mfunc Inizializza con la stringa puntata da char* di lunghezza size
|
||||
// (usa <mf TString::resize>)
|
||||
TString& TString::set(
|
||||
const char* s) // @parm Stringa da inizializzare
|
||||
|
||||
// @rdesc Ritorna l'indirizzo della stringa inizializzata
|
||||
{
|
||||
if (s == NULL) s = "";
|
||||
const int sz = *s ? strlen(s) : 7;
|
||||
@ -86,16 +98,24 @@ TString& TString::set(const char* s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Eventually expands the string for s more chars
|
||||
int TString::make_room(int s)
|
||||
// @mfunc Espande la stringa per altri caratteri
|
||||
int TString::make_room(
|
||||
int s) // @parm Numero di caratteri di cui si cuole aspandere la stringa
|
||||
|
||||
// @comm La stringa viene espansa di un numero di caratteri doppio (per sicurezza) di
|
||||
// quello passato per parametro
|
||||
//
|
||||
// @rdesc Ritorna il numero di caratteri della stringa prima della chiamata
|
||||
{
|
||||
const int lun = len();
|
||||
const int spare = size() - lun;
|
||||
if (spare < s)
|
||||
resize(size() + 2*s, TRUE); // Melius abundare ...
|
||||
resize(size() + 2*s, TRUE);
|
||||
return lun;
|
||||
}
|
||||
|
||||
// @doc EXTERNAL
|
||||
|
||||
TString::TString(const char* s) : _str(NULL), _size(0)
|
||||
{ set(s); }
|
||||
|
||||
@ -171,7 +191,10 @@ TString& TString::operator <<(const TString& str)
|
||||
{ return operator <<(str._str); }
|
||||
|
||||
|
||||
TString& TString::strip(const char* k)
|
||||
// @mfunc Elimina tutti i caratteri contenuti in <p k>
|
||||
TString& TString::strip(
|
||||
const char* k) // @parm Stringa da controllarne l'esitenza nell'oggetto
|
||||
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; _str[i]; i++)
|
||||
@ -219,7 +242,12 @@ const char* TString::class_name() const
|
||||
word TString::class_id() const
|
||||
{ return CLASS_STRING; }
|
||||
|
||||
// @mfunc Duplica una stringa
|
||||
TObject* TString::dup() const
|
||||
|
||||
// @comm Alloca nuovo spazio per duplicare la stringa
|
||||
//
|
||||
// @rdesc Ritorna il puntatore alla stringa duplicata
|
||||
{
|
||||
TString* s = new TString(size());
|
||||
s->set(_str);
|
||||
@ -240,7 +268,23 @@ void TString::print_on(ostream& out) const
|
||||
|
||||
|
||||
// Certified 100%
|
||||
int TString::find(char c, int from) const
|
||||
// @mfunc Ritorna la posizione del carattere o della stringa nell'oggetto TString
|
||||
//
|
||||
// @rdesc Ritorna i seguneti parametri:
|
||||
//
|
||||
// @flag <gt>= 0 | Posizione dell'elemento nella stringa
|
||||
// @flag -1 | L'elemento non e' stato trovato
|
||||
int TString::find(
|
||||
char c, // @parm Carattere da cercare
|
||||
int from) const // @parm Posizione da cui iniziare la ricerca
|
||||
// @parm const char* | s | Stringa da cercare
|
||||
|
||||
// @syntax find(char c, int from);
|
||||
// @syntax find(const char* s, int from);
|
||||
//
|
||||
// @comm Cerca nella stringa, dalla posizione indicata, l'elemento passato.
|
||||
// Nel caso <p from> sia maggiore della lunghezza della stringa manda
|
||||
// un messaggio di errore
|
||||
{
|
||||
CHECKD(from <= len(), "Trying to find past end of string", from);
|
||||
const char* p = strchr(_str + from, c);
|
||||
@ -248,8 +292,12 @@ int TString::find(char c, int from) const
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
bool TString::match(const char* s) const
|
||||
|
||||
// @mfunc Confronta usando i caratteri jolly
|
||||
bool TString::match(
|
||||
const char* s) const // @parm Stringa da confrontare
|
||||
|
||||
// @comm Confronta se la stringa e' parzialmente uguale ad un'altra, cioe' non confrontando
|
||||
// tutti i caratteri, ma solo quelli non jolly
|
||||
{
|
||||
if (strchr(s, '?') == NULL) return operator ==(s);
|
||||
|
||||
@ -282,14 +330,22 @@ int TString::find(const char* s, int from) const
|
||||
|
||||
|
||||
// Certified 99%
|
||||
const TString& TString::left(int count) const
|
||||
// @mfunc Ritorna l'oggetto TString composto dai <p count> caratteri da sinistra
|
||||
const TString& TString::left(
|
||||
int count) const // @parm Indica fino quale carattere restituire la stringa
|
||||
|
||||
// @rdesc Ritorna l'indirizzo della stringa contenente i <p count> caratteri da sinistra
|
||||
{
|
||||
spark.strncpy(_str, count);
|
||||
return spark;
|
||||
}
|
||||
|
||||
// Certified 99%
|
||||
const TString& TString::right(int count) const
|
||||
// @mfunc Ritorna l'oggetto TString composto dai <p count> caratteri da destra
|
||||
const TString& TString::right(
|
||||
int count) const // @parm Indica da quale carattere restituire la stringa
|
||||
|
||||
// @rdesc Ritorna l'indirizzo della stringa contenente i <p count> caratteri da destra
|
||||
{
|
||||
int from = len()-count;
|
||||
if (from < 0) from = 0;
|
||||
@ -299,7 +355,13 @@ const TString& TString::right(int count) const
|
||||
|
||||
|
||||
// Certified 100%
|
||||
const TString& TString::mid(int from, int count) const
|
||||
// @mfunc Ritorna l'oggetto TString composto dai <p count> caratteri a partire
|
||||
// da <p from>
|
||||
const TString& TString::mid(
|
||||
int from, // @parm Posizione dalla quale partire per l'estrazione
|
||||
int count) const // @parm Numero di caratteri da estrarre
|
||||
|
||||
// @rdesc Ritorna l'indirizzo della stringa contenente i <p count> cartteri da <p from>
|
||||
{
|
||||
const int l = len();
|
||||
|
||||
@ -320,7 +382,12 @@ const TString& TString::mid(int from, int count) const
|
||||
|
||||
|
||||
// Certified 100%
|
||||
const TString& TString::sub(int from, int to) const
|
||||
// @mfunc Ritorna la stringa da <p from> a <p to> (escluso)
|
||||
const TString& TString::sub(
|
||||
int from, // @parm Posizione dalla quale estrarre la stringa
|
||||
int to) const // @parm Posizione fin alla quale estrarre la stringa
|
||||
|
||||
// @rdesc Ritorna l'indirizzo della stringa da i <p from> a <p to>
|
||||
{
|
||||
const int count = to-from;
|
||||
return mid(from, count);
|
||||
@ -334,7 +401,17 @@ TString& TString::cut(int n)
|
||||
}
|
||||
|
||||
|
||||
TString& TString::ltrim(int count)
|
||||
// @mfunc Elimina gli spazi da sinistra o i primi n caratteri (da sinistra).
|
||||
TString& TString::ltrim(
|
||||
int count) // @parm Indica il numero di caratteri da eliminare.
|
||||
// Se uguale a 0 elimina tutti gli spazi da sinistra
|
||||
|
||||
// @comm Controlla se <p count> e' 0. Se non lo Š ritorna l'indirizzo della
|
||||
// stringa a partire dal <p count>-esimo carattere; altrimenti controlla
|
||||
// se i primi caratteri sono spazi e li elimina fino a che non trova
|
||||
// un carattere diverso da ' '
|
||||
//
|
||||
// @xref <mf TString::rtrim>
|
||||
{
|
||||
const char* s;
|
||||
|
||||
@ -349,7 +426,16 @@ TString& TString::ltrim(int count)
|
||||
return *this;
|
||||
}
|
||||
|
||||
TString& TString::rtrim(int count)
|
||||
// @mfunc Elimina gli spazi da destra o i primi n caratteri (da destra).
|
||||
TString& TString::rtrim(
|
||||
int count) // @parm Indica il numero di caratteri da eliminare.
|
||||
// Se uguale a 0 elimina tutti gli spazi da destra
|
||||
|
||||
// @comm Controlla se <p count> e' 0. Se non lo Š pone il fine stringa alla
|
||||
// posizione <p count>; altrimenti controlla se gli ultimi caratteri
|
||||
// sono spazi e li elimina fino a che non trova un carattere diverso da ' '
|
||||
//
|
||||
// @xref <mf TString::ltrim>
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
@ -391,7 +477,16 @@ TString& TString::trim()
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
int TString::compare(const char* s, int max, bool ignorecase) const
|
||||
// @mfunc Compara due stringhe (o i primi <p max> caratteri)
|
||||
//
|
||||
// @rdesc Ritrna i seguenti valori:
|
||||
//
|
||||
// @flag 0 | Se le stringhe sono uguali
|
||||
// @flag <gt><lt>0 | Se le stringhe sono diverse
|
||||
int TString::compare(
|
||||
const char* s, // @parm Stringa da comparare
|
||||
int max, // @parm Numero di caratteri da conforntare (default tutta la stringa)
|
||||
bool ignorecase) const // @parm Ignorare la differenza maiuscolo/minuscolo (default FALSE)
|
||||
{
|
||||
int res;
|
||||
if (ignorecase)
|
||||
@ -414,7 +509,18 @@ int TString::compare(const char* s, int max, bool ignorecase) const
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
TString& TString::fill(char c, int n)
|
||||
// @mfunc Riempe la stringa con n caratteri c
|
||||
TString& TString::fill(
|
||||
char c, // @parm Caratteri con cui riempire la stringa
|
||||
int n) // @parm Numero di caratteri da inserire nella stringa
|
||||
// (default per tutta la lungehzza)
|
||||
|
||||
// @comm Se il paramatro <p n> e' maggiore della dimensione della stringa, la
|
||||
// stessa viene ridimensionata (chaimata alla <mf TString::resize>).
|
||||
// <nl>Nel caso non venga passato il parametro <p n> la stringa viene
|
||||
// riempita col carattere <p c> per tutta la lunghezza.
|
||||
//
|
||||
// @rdesc Ritorna l'indirizzo dell stringa
|
||||
{
|
||||
if (n < 0) n = size(); else
|
||||
if (n > size()) resize(n, FALSE);
|
||||
@ -424,7 +530,15 @@ TString& TString::fill(char c, int n)
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
TString& TString::right_just(int n, char c)
|
||||
// @mfunc Giustifica l'oggetto stringa a destra
|
||||
TString& TString::right_just(
|
||||
int n, // @parm Numero di colonne alla quali allineare (defualt larghezza della stringa)
|
||||
char c) // @parm Carattere di riempimento (default ' ')
|
||||
|
||||
// @comm Nel caso venga passato un carattere in <p c>, questo viene inserito
|
||||
// nel resto della stringa (a sinistra della stringa stessa)
|
||||
//
|
||||
// @xref <mf TString::left_just> <mf TString::center_just>
|
||||
{
|
||||
if (n < 0) n = size();
|
||||
trim();
|
||||
@ -436,7 +550,15 @@ TString& TString::right_just(int n, char c)
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
TString& TString::center_just(int n, char c)
|
||||
// @mfunc Centra l'oggetto stringa
|
||||
TString& TString::center_just(
|
||||
int n, // @parm Numero di colonne alla quali allineare (defualt larghezza della stringa)
|
||||
char c) // @parm Carattere di riempimento (default ' ')
|
||||
|
||||
// @comm Nel caso venga passato un carattere in <p c>, questo viene inserito
|
||||
// nel resto della stringa (a destra e a sinistra della stringa stessa)
|
||||
//
|
||||
// @xref <mf TString::left_just> <mf TString::right_just>
|
||||
{
|
||||
if (n < 0) n = size();
|
||||
trim();
|
||||
@ -449,7 +571,15 @@ TString& TString::center_just(int n, char c)
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
TString& TString::left_just(int n, char c)
|
||||
// @mfunc Giustifica l'oggetto stringa a sinistra
|
||||
TString& TString::left_just(
|
||||
int n, // @parm Numero di colonne alla quali allineare (defualt larghezza della stringa)
|
||||
char c) // @parm Carattere di riempimento (default ' ')
|
||||
|
||||
// @comm Nel caso venga passato un carattere in <p c>, questo viene inserito
|
||||
// nel resto della stringa (a destra della stringa stessa)
|
||||
//
|
||||
// @xref <mf TString::right_just> <mf TString::center_just>
|
||||
{
|
||||
if (n < 0) n = size();
|
||||
trim();
|
||||
@ -460,7 +590,10 @@ TString& TString::left_just(int n, char c)
|
||||
return *this;
|
||||
}
|
||||
|
||||
TString& TString::picture(const char* pic, const char* s)
|
||||
// @mfunc Formatta una stringa usando il formato dato da <p pic>
|
||||
TString& TString::picture(
|
||||
const char* pic, // @parm Formato dell stringa
|
||||
const char* s) // @parm Stringa da formattare
|
||||
{
|
||||
if (pic == NULL || *pic == '\0')
|
||||
return set(s);
|
||||
@ -481,7 +614,12 @@ TString& TString::picture(const char* pic, const char* s)
|
||||
}
|
||||
|
||||
// Certified 90% (spark size limited)
|
||||
TString& TString::format(const char* fmt, ...)
|
||||
// @mfunc Manda un output formattato alla stringa oggetto
|
||||
TString& TString::format(
|
||||
const char* fmt, ...) // @parm Stringa da formattare
|
||||
|
||||
// @comm Funziona come la funzione "sprintf" standard del C e ritorna la
|
||||
// stringa formattata con i parametri passati.
|
||||
{
|
||||
va_list pars;
|
||||
va_start(pars, fmt);
|
||||
@ -510,7 +648,14 @@ TString& TString::lower()
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
TString& TString::add_plural(long num, const char* name)
|
||||
// @mfunc Permette di ttrovare il plurale di una stringa
|
||||
TString& TString::add_plural(
|
||||
long num, // @parm Numero di elementi per sapere la desineneza
|
||||
const char* name) // @parm Stringa da modificare
|
||||
|
||||
// @comm A seconda del numero passato in <p num> permette di stabilire la
|
||||
// corretta sintassi della stringa <p name> da scrivere nei messaggi
|
||||
// dati all'utente. Nel caso <p num> sia 0 allora ritorna "nessuno".
|
||||
{
|
||||
const TFixed_string n(name);
|
||||
const char last = n[n.len()-1];
|
||||
@ -534,7 +679,16 @@ TString& TString::add_plural(long num, const char* name)
|
||||
}
|
||||
|
||||
// Certified 90%
|
||||
TString& TString::overwrite(const char* s, int pos)
|
||||
// @mfunc Sovrascrive la stringa <p s> dalla posizione <p pos>
|
||||
TString& TString::overwrite(
|
||||
const char* s, // @parm Stringa da inserire
|
||||
int pos) // @parm Posizione dalla quale iniziare a sovrascrivere
|
||||
|
||||
// @comm Sovrascrive dalla posizione <p pos> fino alla lunghezza di <p s> l'oggetto
|
||||
// stringa. Nel caso la dimensione sia maggiore l'oggetto viene riallocato
|
||||
// dinamicamente
|
||||
//
|
||||
// @xref <mf TString::insert>
|
||||
{
|
||||
const int l = len();
|
||||
if (pos < 0) pos = l;
|
||||
@ -551,7 +705,16 @@ TString& TString::overwrite(const char* s, int pos)
|
||||
|
||||
|
||||
// Certified 90%
|
||||
TString& TString::insert(const char* s, int pos)
|
||||
// @mfunc Inserisce la stringa s dalla posizione pos
|
||||
TString& TString::insert(
|
||||
const char* s, // @parm Stringa da inserire
|
||||
int pos) // @parm Posizione dalla quale iniziare a inserire
|
||||
|
||||
// @comm Inserisce dalla posizione <p pos> la stringa <p s> nell'oggetto
|
||||
// stringa. Nel caso la dimensione sia maggiore l'oggetto viene riallocato
|
||||
// dinamicamente
|
||||
//
|
||||
// @xref <mf TString::overwrite>
|
||||
{
|
||||
if (s && *s)
|
||||
{
|
||||
@ -616,8 +779,13 @@ void TFixed_string::strncpy(const char* s, int n)
|
||||
}
|
||||
|
||||
// Certified 99%
|
||||
// More efficient than TString::format, it does not use spark
|
||||
TString& TFixed_string::format(const char* fmt, ...)
|
||||
// @mfunc Manda un output formattato alla stringa oggetto
|
||||
TString& TFixed_string::format(
|
||||
const char* fmt, ...)// @parm Formato della stringa
|
||||
|
||||
// @comm Funziona come la funzione "sprintf" standard del C e ritorna la
|
||||
// stringa formattata con i parametri passati.
|
||||
// <nl>E' piu' efficiente di <mf TString::format> poiche' non usa spark
|
||||
{
|
||||
va_list pars;
|
||||
va_start(pars, fmt);
|
||||
@ -688,12 +856,22 @@ TFilename& TFilename::add(const char* n)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// @mfunc Controlla il formato del nome del file
|
||||
//
|
||||
// @rdesc Ritorna i seguenti valori
|
||||
//
|
||||
// @flag TRUE | Se il nome del file e' sintatticamente corretto
|
||||
// @flag FALSE | Se il nome del file non e' sintatticamente corretto
|
||||
bool TFilename::ok() const
|
||||
|
||||
// @comm Controlla tutti i casi per cui un nome di file puo' non essere valido.
|
||||
// <nl>Nel caso si lavori in Windows controlla anche che il nome del
|
||||
// disco sia corretto.
|
||||
{
|
||||
const int l = len();
|
||||
|
||||
int len = 0; // lunghezza ultima sottostringa
|
||||
bool ext = FALSE; // trovata estensione
|
||||
int len = 0; // lunghezza ultima sottostringa
|
||||
bool ext = FALSE; // trovata estensione
|
||||
|
||||
for (int c = 0; c < l; c++)
|
||||
{
|
||||
@ -781,7 +959,12 @@ const TFilename& TFilename::tempdir()
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
const TFilename& TFilename::temp(const char* prefix)
|
||||
// @mfunc Genera il nome di un file temporaneo
|
||||
const TFilename& TFilename::temp(
|
||||
const char* prefix) // @parm Eventuale prefisso da assegnare al file temporaneo
|
||||
|
||||
// @comm Nel generare il nome del file controlla se esistone dei caratteri jolly
|
||||
// e li elimina.
|
||||
{
|
||||
tempdir();
|
||||
|
||||
@ -876,7 +1059,19 @@ const char* TToken_string::get()
|
||||
}
|
||||
|
||||
// Certified 50%
|
||||
const char* TToken_string::get(int n)
|
||||
// @mfunc Ritorna un Token
|
||||
//
|
||||
// @rdesc Ritorne la stringa identificata dal Token passato come parametro <p n>
|
||||
const char* TToken_string::get(
|
||||
int n) // @parm Token da ritornare (-1 = prossimo, -2 = ultimo, n = n-simo)
|
||||
|
||||
// @syntax const char* get(int n);
|
||||
// @syntax const char* get();
|
||||
//
|
||||
// @comm Se non viene passato il parametro <p n> ritorna il prossimo Token
|
||||
// (come se <p n> == -1)
|
||||
//
|
||||
// @xref <mf TToken_string::get_char>
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
@ -919,7 +1114,14 @@ const char* TToken_string::get(int n)
|
||||
|
||||
|
||||
// Certified 99%
|
||||
char TToken_string::get_char(int n)
|
||||
// @mfunc Ritorna un carattere
|
||||
//
|
||||
// @rdesc Ritorna il primo carattere del Token richiesto
|
||||
char TToken_string::get_char(
|
||||
int n) // @parm Token da ritornare
|
||||
|
||||
// @comm Chiama la <mf TToken_string::get> con tutti i relativi significati per
|
||||
// il parametro <p n>
|
||||
{
|
||||
const char* const car = get(n);
|
||||
return car ? *car : '\0';
|
||||
@ -1000,9 +1202,23 @@ int TToken_string::items() const
|
||||
return t;
|
||||
}
|
||||
|
||||
// Adds an item to the token string
|
||||
// Certified 99%
|
||||
void TToken_string::add(const char* s, int pos)
|
||||
// @mfunc Aggiunge un elemento alla token string
|
||||
void TToken_string::add(
|
||||
const char* s, // @parm Stringa da aggiungere
|
||||
int pos) // @parm Posizione nella quale aggiungere l'elemento
|
||||
// (default aggiunge come ultimo elemento)
|
||||
// @parm char | c | Caratter da aggiungere
|
||||
// @parm long | n | Long da aggiungere
|
||||
// @parm int | n | Intero da aggiungere
|
||||
|
||||
// @syntax void add(const char* s, int n = -1);
|
||||
// @syntax void add(char c, int pos = -1);
|
||||
// @syntax void add(long n, int pos = -1);
|
||||
// @syntax void add(int n, int pos = -1);
|
||||
//
|
||||
// @comm Permette, a seconda del parametro passato, di aggiungere alla Token
|
||||
// string un nuovo elemnto gi… completo del carattere di separazione
|
||||
{
|
||||
if (s == NULL || *s == '\0') s = " ";
|
||||
if (pos < 0)
|
||||
@ -1121,7 +1337,13 @@ int TString_array::add(const TToken_string& s, int n)
|
||||
return n;
|
||||
}
|
||||
|
||||
int TString_array::find(const char* s, int from) const
|
||||
// @mfunc Cerca una stringa nell'array
|
||||
//
|
||||
// @rdesc Ritorna la posizione nell'array in cui si trova la stringa (-1 se non
|
||||
// e' stata trovata)
|
||||
int TString_array::find(
|
||||
const char* s, // @parm Stringa da cercare
|
||||
int from) const // @parm Posizione dalla quale cercare la stringa
|
||||
{
|
||||
int found = -1;
|
||||
for (int i = from; i < items(); i++)
|
||||
|
@ -9,152 +9,276 @@
|
||||
#include <array.h>
|
||||
#endif
|
||||
|
||||
// @C
|
||||
// Classe TString : public TObject
|
||||
// @END
|
||||
// @doc EXTERNAL
|
||||
|
||||
// @class Classe per la definizione della stringhe
|
||||
//
|
||||
// @base public | TObject
|
||||
class TString : public TObject
|
||||
{
|
||||
protected:
|
||||
// @DPROT
|
||||
char* _str; // Puntatore alla stringa
|
||||
int _size; // Lunghezza
|
||||
// @END
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Puntatore alla stringa
|
||||
char* _str;
|
||||
// @cmember Lunghezza della stringa
|
||||
int _size;
|
||||
|
||||
// @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
|
||||
// @cmember Espande la stringa per altri caratteri
|
||||
int make_room(int size);
|
||||
// @cmember Inizializza con la stringa puntata da char* di lunghezza size
|
||||
TString& set(const char*);
|
||||
|
||||
TString(char* str, int size) : _str(str), _size(size) {}
|
||||
// @cmember Costruttore per consentire la derivazione delle TFixed_string
|
||||
TString(char* str, int size) : _str(str), _size(size)
|
||||
{}
|
||||
|
||||
// @access Public member
|
||||
public:
|
||||
// @FPUB
|
||||
virtual void resize(int size, bool cpy); // Ri/alloca la stringa
|
||||
// @cmember Rialloca la stringa
|
||||
virtual void resize(int size, bool cpy);
|
||||
|
||||
// @cmember Costruttore
|
||||
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
|
||||
// @cmember Costruttore di default per una stringa data
|
||||
TString(int size);
|
||||
// @cmember Costruttore a partire da una stringa s
|
||||
TString(const char* s);
|
||||
// @cmember Costruttore da un oggetto TString s
|
||||
TString(const TString& s);
|
||||
// @cmember Distruttore
|
||||
virtual ~TString();
|
||||
|
||||
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; }
|
||||
// @cmember Ritorna il nome della classe
|
||||
virtual const char* class_name() const;
|
||||
// @cmember Ritorna l'identificatore della classe
|
||||
virtual word class_id() const;
|
||||
// @cmember Controlla se si tratta di una stringa valida (diversa da NULL)
|
||||
virtual bool ok() const
|
||||
{ return _str != NULL; }
|
||||
// @cmember Duplica una stringa
|
||||
virtual TObject* dup() const;
|
||||
// @cmember Stampa una stringa
|
||||
virtual void print_on(ostream& out) const;
|
||||
// @cmember Legge una stringa
|
||||
virtual void read_from(istream& in);
|
||||
virtual word hash() const; // Return hash value
|
||||
// @cmember Ritorna il valore hash della stringa
|
||||
virtual word hash() const;
|
||||
|
||||
operator const char*() const { return (const char*)_str; } // *(TString) -> _str
|
||||
char& operator[](int i) // TString[i] -> _str[i]
|
||||
// @cmember const char * | operator const char*() | | Trasforna una stringa
|
||||
// in puntatore a carattere
|
||||
operator const char*() const
|
||||
{ return (const char*)_str; }
|
||||
// @cmember Ritorna un riferimento al carattere i-esimo della stringa
|
||||
char& operator[](int i)
|
||||
{
|
||||
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
|
||||
return _str[i];
|
||||
}
|
||||
char operator[](int i) const // TString[i] -> _str[i]
|
||||
}
|
||||
// @cmember Ritorna il carattere i-esimo della stringa
|
||||
char operator[](int i) const
|
||||
{
|
||||
CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i);
|
||||
return _str[i];
|
||||
}
|
||||
|
||||
int size() const { return _size; }
|
||||
// @cmember Ritorna la dimensione allocata della stringa
|
||||
int size() const
|
||||
{ return _size; }
|
||||
// @cmember Ritorna la lunghezza della stringa (numero di caratteri)
|
||||
int len() const { return strlen(_str); }
|
||||
bool empty() const { return *_str == '\0'; }
|
||||
bool not_empty() const { return *_str != '\0'; }
|
||||
bool blank() const; // TRUE se e' vuota o contiene solo whitespace
|
||||
// @cmember Controlla se la stringa e' vuota (TRUE se non contiene caratteri)
|
||||
bool empty() const
|
||||
{ return *_str == '\0'; }
|
||||
// @cmember Controlla se la stringa non e' vuota (TRUE se contiene caratteri)
|
||||
bool not_empty() const
|
||||
{ return *_str != '\0'; }
|
||||
// @cmember Controlla se la stringa e' vuota o contiene solo whitespace (TRUE se vuota)
|
||||
bool blank() const;
|
||||
|
||||
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
|
||||
// @cmember Ritorna la posizione del carattere char nell'oggetto TString
|
||||
int find(char, int from = 0) const;
|
||||
// @cmember Ritorna la posizione della stringa s nell'oggetto TString
|
||||
int find(const char* s, int from = 0) const;
|
||||
|
||||
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
|
||||
// @cmember Ritorna l'oggetto TString composto dai count caratteri da sinistra
|
||||
const TString& left(int count) const;
|
||||
// @cmember Ritorna l'oggetto TString composto dai count caratteri a partire da from
|
||||
const TString& mid(int from, int count = -1) const;
|
||||
// @cmember Ritorna la stringa da from a to (escluso)
|
||||
const TString& sub(int from, int to = -1) const;
|
||||
// @cmember Ritorna l'oggetto TString composto dai count caratteri da destra
|
||||
const TString& right(int count) const;
|
||||
|
||||
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
|
||||
// @cmember Riempe la stringa con n caratteri c
|
||||
TString& fill(char c, int n = -1);
|
||||
// @cmember Riempe la stringa con n caratteri spazio (chiama <mf TString::resize>)
|
||||
TString& spaces(int n = -1)
|
||||
{ return fill(' ', n); }
|
||||
// @cmember Sovrascrive la stringa s dalla posizione pos
|
||||
TString& overwrite(const char* s, int pos = 0);
|
||||
// @cmember Inserisce la stringa s dalla posizione pos
|
||||
TString& insert(const char* s, int pos = 0);
|
||||
|
||||
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
|
||||
// @cmember Elimina tutti i caratteri contenuti in k
|
||||
TString& strip(const char* k);
|
||||
// @cmember Elimina tutti gli spazi non contenuti tra apici singoli o doppi
|
||||
TString& strip_spaces();
|
||||
// @cmember Elimina gli spazi da sinistra o i primi n caratteri (da sinistra).
|
||||
TString& ltrim(int n = 0);
|
||||
// @cmember Elimina gli spazi da destra o i primi n caratteri (da destra).
|
||||
TString& rtrim(int n = 0);
|
||||
// @cmember Composizione di <mf TString::ltrim> e <mf TString::rtrim> per eliminare
|
||||
// gli spazi iniziali e finali
|
||||
TString& trim();
|
||||
|
||||
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
|
||||
// @cmember Giustifica l'oggetto stringa a destra
|
||||
TString& right_just(int n = -1, char c = ' ');
|
||||
// @cmember Centra l'oggetto stringa
|
||||
TString& center_just(int n = -1, char c = ' ');
|
||||
// @cmember Giustifica l'oggetto stringa a sinistra
|
||||
TString& left_just(int n = -1, char c = ' ');
|
||||
|
||||
// @cmember Formatta una stringa usando il formato dato da pic
|
||||
TString& picture(const char* pic, const char* s);
|
||||
|
||||
#ifndef __WATCOMC__
|
||||
virtual
|
||||
#endif
|
||||
// @cmember Manda un output formattato alla stringa oggetto
|
||||
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
|
||||
TString& add_plural(long num, const char * name); // aggiunge il plurale di name
|
||||
// @cmember Tronca la stringa alla posizione n-esima.
|
||||
TString& cut(int n);
|
||||
|
||||
const TString& operator =(const TString& s) { return set(s._str); }
|
||||
const TString& operator =(const char* s) { return set(s); }
|
||||
// @cmember Converte la stringa in maiuscolo
|
||||
TString& upper();
|
||||
// @cmember Converte la stringa in minuscolo
|
||||
TString& lower();
|
||||
// @cmember Permette di ttrovare il plurale di una stringa
|
||||
TString& add_plural(long num, const char * name);
|
||||
|
||||
// @cmember Assegna la stringa passata con indirizzo
|
||||
const TString& operator =(const TString& s)
|
||||
{ return set(s._str); }
|
||||
// @cmember Assegna la stringa passata
|
||||
const TString& operator =(const char* s)
|
||||
{ return set(s); }
|
||||
|
||||
// @cmember Concatena una stringa all'oggetto stringa
|
||||
TString& operator <<(const char*);
|
||||
// @cmember Concatena un carattere all'oggetto stringa
|
||||
TString& operator <<(char);
|
||||
// @cmember Concatena un intero all'oggetto stringa
|
||||
TString& operator <<(int);
|
||||
// @cmember Concatena un long all'oggetto stringa
|
||||
TString& operator <<(long);
|
||||
// @cmember Concatena un double all'oggetto stringa
|
||||
TString& operator <<(double);
|
||||
// @cmember Concatena un oggetto all'oggetto stringa
|
||||
TString& operator <<(const TObject& obj);
|
||||
TString& operator <<(const TString& str); // For efficiency only
|
||||
// @cmember Concatena una stringa all'oggetto stringa (usato per aumentare l'efficienza)
|
||||
TString& operator <<(const TString& str);
|
||||
|
||||
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;
|
||||
// @cmember Controlla se due stringhe sono uguali
|
||||
bool operator ==(const char* s) const
|
||||
{ return strcmp(_str, s) == 0; }
|
||||
// @cmember Controlla se due stringhe sono uguali
|
||||
bool operator ==(char* s) const
|
||||
{ return strcmp(_str, s) == 0; }
|
||||
// @cmember Controlla se due oggetti stringa sono uguali
|
||||
bool operator ==(const TString& s) const
|
||||
{ return strcmp(_str, s._str) == 0; }
|
||||
// @cmember Controlla se due stringhe sono diversi
|
||||
bool operator !=(const char* s) const
|
||||
{ return strcmp(_str, s) != 0; }
|
||||
// @cmember Controlla se due stringhe sono diversi
|
||||
bool operator !=(char* s) const
|
||||
{ return strcmp(_str, s) != 0; }
|
||||
// @cmember Controlla se due oggetti stringa sono diverse
|
||||
bool operator !=(const TString& s) const
|
||||
{ return strcmp(_str, s._str) != 0; }
|
||||
// @cmember Controlla se una stringa e piu' lunga di un'altra
|
||||
bool operator <(const char* s) const
|
||||
{ return strcmp(_str, s) < 0; }
|
||||
// @cmember Controlla se una stringa e piu' corta di un'altra
|
||||
bool operator >(const char* s) const
|
||||
{ return strcmp(_str, s) > 0; }
|
||||
// @cmember Controlla se una stringa e piu' lunga o uguale ad un'altra
|
||||
bool operator >=(const char* s) const
|
||||
{ return strcmp(_str, s) >= 0; }
|
||||
// @cmember Controlla se una stringa e piu' corta o uguale ad un'altra
|
||||
bool operator <=(const char* s) const
|
||||
{ return strcmp(_str, s) <= 0; }
|
||||
// @cmember Confronta usando i caratteri jolly
|
||||
bool match(const char* s) const;
|
||||
// @cmember Compara due stringhe (o i primi max caratteri)
|
||||
int compare(const char* s, int max = -1, bool ignorecase = FALSE) const;
|
||||
};
|
||||
|
||||
// @C
|
||||
// Classe TFixed_string : public TString
|
||||
// @END
|
||||
|
||||
// @class TFixed_string | Classe per la definizione di stringhe di lunghezza
|
||||
// fissa e non rilocabili dinamicamente
|
||||
//
|
||||
// @base public | TString
|
||||
class TFixed_string : public TString
|
||||
{
|
||||
protected:
|
||||
virtual void resize(int size, bool cpy); // Causa un errore fatale!
|
||||
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Causa un erroe fatale
|
||||
virtual void resize(int size, bool cpy);
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @cmember Costruttore
|
||||
TFixed_string(const char* str, int size = -1);
|
||||
// @cmember Distruttore
|
||||
virtual ~TFixed_string();
|
||||
|
||||
#ifndef __WATCOMC__
|
||||
virtual
|
||||
#endif
|
||||
// @cmember Manda un output formattato alla stringa oggetto
|
||||
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); }
|
||||
// @cmember Assegna la stringa passata con indirizzo
|
||||
const TString& operator =(const TString& s)
|
||||
{ return set((const char*)s); }
|
||||
// @cmember Assegna la stringa passata
|
||||
const TString& operator =(const char* str)
|
||||
{ return set(str); }
|
||||
// @cmember Copia n caratteri nella stringa oggetto
|
||||
void strncpy(const char* s, int n);
|
||||
};
|
||||
|
||||
// @class TString16 | Definisce le stringhe di 16 caratteri
|
||||
//
|
||||
// @base public | TFixed_string
|
||||
class TString16 : public TFixed_string
|
||||
{
|
||||
// @access Private member
|
||||
|
||||
// @cmember Stringa di 16 caratteri
|
||||
char _str16[17];
|
||||
|
||||
// @access Public Member
|
||||
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); }
|
||||
// @cmember Costruttore
|
||||
TString16(const char* s = "") : TFixed_string(_str16, 17)
|
||||
{ set(s); }
|
||||
// @cmember Costruttore
|
||||
TString16(const TString& s) : TFixed_string(_str16, 17)
|
||||
{ set(s); }
|
||||
// @cmember Assegna una stringa
|
||||
const TString& operator =(const TString& s)
|
||||
{ return set((const char*)s); }
|
||||
// @cmember Assegna una stringa
|
||||
const TString& operator =(const char* s)
|
||||
{ return set(s); }
|
||||
|
||||
// @comm Sono definite anche le classi <c TString80> e <c TString256> per le
|
||||
// stringhe rispettivamente di 80 e 256 caratteri. I class member sono
|
||||
// gli stessi, la differenza e' solo nel numero di caratteri della stringa.
|
||||
};
|
||||
|
||||
class TString80 : public TFixed_string
|
||||
@ -179,121 +303,196 @@ public:
|
||||
const TString& operator =(const TString& s) { return set((const char*)s); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
// @C
|
||||
// Classe TFilename : public TString80 (256 su Windows'95)
|
||||
// @END
|
||||
|
||||
// @class TFilename | Classe per la gestione dei nome dei file
|
||||
//
|
||||
// @base public | TString80 (TString256 per Windows '95)
|
||||
class TFilename : public TString80
|
||||
{
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @FPUB
|
||||
// @cmember Costruttore
|
||||
TFilename(const char* n = "") : TString80(n)
|
||||
{}
|
||||
// @cmember Costruttore
|
||||
TFilename(const TString& n) : TString80((const char*)n)
|
||||
{}
|
||||
// @cmember Costruttore
|
||||
TFilename(const TFilename& n) : TString80((const char*)n)
|
||||
{}
|
||||
|
||||
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); }
|
||||
// @cmember Assegnazione tra TFile e stringa
|
||||
const TString& operator =(const char* s)
|
||||
{ return set(s); }
|
||||
// @cmember Assegnazione tra TFile ed indirizzo della stringa
|
||||
const TString& operator =(const TString& s)
|
||||
{ return set((const char*)s); }
|
||||
|
||||
virtual bool ok() const; // Controlla il formato del nome del file
|
||||
// @cmember Controlla il formato del nome del file
|
||||
virtual bool ok() const;
|
||||
|
||||
const char* ext() const; // Ritorna l'estensione
|
||||
void ext(const char*); // Imposta come estensione la stringa puntata da char*
|
||||
// @cmember Ritorna l'estensione del file
|
||||
const char* ext() const;
|
||||
// @cmember Imposta come estensione la stringa puntata da char*
|
||||
void ext(const char*);
|
||||
|
||||
// @cmember Concatena un nome di file ad una directory
|
||||
TFilename& add(const char* n);
|
||||
|
||||
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
|
||||
// @cmember Ritorna il nome del file
|
||||
const char* name() const;
|
||||
// @cmember Ritorna il nome del direttorio
|
||||
const char* path() const;
|
||||
// @cmember Genera il nome di un file temporaneo
|
||||
const TFilename& temp(const char* prefix = NULL);
|
||||
// @cmember Genera il nome della directory temporanea
|
||||
const TFilename& tempdir();
|
||||
};
|
||||
|
||||
// @C
|
||||
// Classe TToken_string : public TString
|
||||
// @END
|
||||
|
||||
// @class TToken_string | Contiene una stringa formata da piu' stringhe
|
||||
// separate da un carattere (di solito il pipe)
|
||||
//
|
||||
// @base public | TString
|
||||
class TToken_string : public TString
|
||||
{
|
||||
// @DPRIV
|
||||
char _separator; // Carattere separatore
|
||||
int _last; // Puntatore all'ultimo
|
||||
|
||||
// @access Private Member
|
||||
|
||||
// @cmember Carattere separatore
|
||||
char _separator;
|
||||
// @cmember Puntatore all'ultimo
|
||||
int _last;
|
||||
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @FPROT
|
||||
|
||||
virtual TObject* dup() const; // Crea un duplicato della token string
|
||||
// @cmember Crea un duplicato della token string
|
||||
virtual TObject* dup() const;
|
||||
// @cmember Inserisce l'n-esima stringa
|
||||
bool set_item(const char* v, int n);
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @FPUB
|
||||
// @cmember Costruttore
|
||||
TToken_string(const char* = "", char separator = '|');
|
||||
// @cmember Costruttore
|
||||
TToken_string(int n, char separator = '|');
|
||||
// @cmember Costruttore
|
||||
TToken_string(const TToken_string& s);
|
||||
|
||||
void separator(char s) { _separator = s; } // Setta il separatore a s
|
||||
// @cmember Setta il carattere separatore a s
|
||||
void separator(char s)
|
||||
{ _separator = 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; }
|
||||
// @cmember Rimette all'inizio il puntatore
|
||||
void restart()
|
||||
{ _last = empty() ? -1 : 0; }
|
||||
// @cmember Assegna una stringa
|
||||
const TString& operator =(const char* s)
|
||||
{ set(s);restart();return *this; }
|
||||
// @cmember Assegna una stringa
|
||||
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
|
||||
// @cmember Aggiunge una stringa
|
||||
void add(const char* s, int n = -1);
|
||||
// @cmember Aggiunge un carattere
|
||||
void add(char c, int pos = -1);
|
||||
// @cmember Aggiunge un long
|
||||
void add(long n, int pos = -1);
|
||||
// @cmember Aggiunge un intero
|
||||
void add(int n, int pos = -1);
|
||||
// @cmember Toglie la stringa di posizione pos
|
||||
void destroy(int pos);
|
||||
// @cmember Ritorna il prossimo token
|
||||
const char* get();
|
||||
// @cmember Ritorna un token
|
||||
const char* get(int n);
|
||||
// @cmember Ritorna un carattere (chiama <mf TToken_string::get>)
|
||||
char get_char(int n = -1);
|
||||
// @cmember Ritorna un intero (chiama <mf TToken_string::get>)
|
||||
int get_int(int n = -1);
|
||||
// @cmember Ritorna un intero esteso (chiama <mf TToken_string::get>)
|
||||
long get_long(int n = -1);
|
||||
// @cmember Ritorna la posizione dell'item s
|
||||
int get_pos(const char* s);
|
||||
// @cmember Ritorna il numero di token presenti
|
||||
int items() const;
|
||||
// @cmember Controlla se tutti i token sono nulli
|
||||
bool empty_items() const;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// @DES Paragraph
|
||||
// DES Paragraph
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// @class TParagraph_string | Classe che serve per spezzare le stringhe in paragrafi
|
||||
// lunghi al massimo la lunghezza fissata
|
||||
//
|
||||
// @base public | TToken_string
|
||||
class TParagraph_string : public TToken_string
|
||||
{
|
||||
int _width;
|
||||
bool _fixed;
|
||||
// @access Private Member
|
||||
|
||||
// @cmember Lunghezza massima del paragrafo
|
||||
int _width;
|
||||
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Spezza la stringa in paragrafi di lunghezza massima fissata
|
||||
void tokenize();
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
// @cmember Costruttore
|
||||
TParagraph_string(const char* s, int width);
|
||||
// @cmember Assegna una stringa
|
||||
const TString& operator =(const char* s);
|
||||
const TString& operator =(const TString & s) { return operator=((const char *) s);}
|
||||
void set_width(int width) { _width = width; }
|
||||
// @cmember Assegna un oggetto stringa
|
||||
const TString& operator =(const TString & s)
|
||||
{ return operator=((const char *) s);}
|
||||
// @cmember Permette di assegnare la lunghezza massima del paragrafo
|
||||
void set_width(int width)
|
||||
{ _width = width; }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// @DES TString_array
|
||||
// DES TString_array
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// @class TString_array | Array di stringhe
|
||||
//
|
||||
// @base public | TArray
|
||||
class TString_array : public TArray
|
||||
{
|
||||
public:
|
||||
TToken_string& row(int n) { return (TToken_string&)operator[](n); }
|
||||
const TToken_string& row(int n) const { return (TToken_string&)operator[](n); }
|
||||
TToken_string* rowptr(int n) { return (TToken_string*)objptr(n); }
|
||||
|
||||
int add(TToken_string* s, int n = -1) { return TArray::add(s, n); }
|
||||
// @access Public Member
|
||||
public:
|
||||
// @cmember Ritorna la stringa n dell'array (se non c'e' ritorna errore)
|
||||
TToken_string& row(int n)
|
||||
{ return (TToken_string&)operator[](n); }
|
||||
// @cmember Ritorna la stringa n dell'array (se non c'e' ritorna errore)
|
||||
const TToken_string& row(int n) const
|
||||
{ return (TToken_string&)operator[](n); }
|
||||
// @cmember Restituisce il puntatore alla stringa n dell'array (NULL se non esiste)
|
||||
TToken_string* rowptr(int n)
|
||||
{ return (TToken_string*)objptr(n); }
|
||||
|
||||
// @cmember Aggiunge una Token string all'array (chiama <mf TArray::add>)
|
||||
int add(TToken_string* s, int n = -1)
|
||||
{ return TArray::add(s, n); }
|
||||
// @cmember Aggiunge un oggetto stringa all'array (chiama <mf TArray::add>)
|
||||
int add(const TToken_string& s, int n = -1);
|
||||
// @cmember Aggiunge una stringa all'array (chiama <mf TArray::add>)
|
||||
int add(const char* s, int n = -1);
|
||||
// @cmember Cerca una stringa nell'array
|
||||
int find(const char* s, int from = 0) const;
|
||||
|
||||
TString_array(int size = 8) : TArray(size) {}
|
||||
virtual ~TString_array() {}
|
||||
// @cmember Costruttore
|
||||
TString_array(int size = 8) : TArray(size)
|
||||
{}
|
||||
// @cmember Distruttore
|
||||
virtual ~TString_array()
|
||||
{}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user