f7c11b5f6c
git-svn-id: svn://10.65.10.50/trunk@1296 c028cbd2-c16b-5b4b-a496-9718f37d4682
153 lines
5.0 KiB
C++
Executable File
153 lines
5.0 KiB
C++
Executable File
#ifndef __ARRAY_H
|
|
#define __ARRAY_H
|
|
|
|
#ifndef __OBJECT_H
|
|
#include <object.h>
|
|
#endif
|
|
|
|
#ifndef NULL
|
|
#define NULL 0L
|
|
#endif
|
|
|
|
class TArray;
|
|
|
|
// @doc EXTERNAL
|
|
//
|
|
// @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
|
|
|
|
// @access Protected Member
|
|
|
|
protected:
|
|
|
|
// @cmember void | resize | (int newdim) | Modifica la dimensione dell'array.
|
|
void resize(int newdim);
|
|
|
|
// @access Public member
|
|
|
|
public:
|
|
// @cmember void | TArray | (int arraysize) | Costruttore. Crea un array (chiama <mf TArray::resize>)
|
|
TArray(int arraysize);
|
|
// @cmember void | TArray | ( ) | 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
|
|
TArray(const TArray&);
|
|
|
|
// @cmember virtual | ~TArray | () | Distruttore
|
|
virtual ~TArray() ;
|
|
// @cmember virtual const char * | class_name | () const | Ritorna il nome della classe
|
|
virtual const char* class_name() const ;
|
|
// @cmember virtual word | class_id | () const | Ritorna l'id della class
|
|
virtual word class_id() const ;
|
|
// @cmember virtual void | print_on | (ostream& out) const | Stampa un array
|
|
virtual void print_on(ostream& out) const ;
|
|
// @cmember virtual bool | ok | () const | TRUE se l'array non e' vuoto
|
|
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
|
|
int last() const;
|
|
|
|
// @cmember TObject& | operator[] | (int index) const | Ritorna l'oggetto puntato da index
|
|
TObject& operator[] (int index) const ;
|
|
// @cmember TObject* | objptr | () const | Ritorna l'oggetto di posto index
|
|
TObject* objptr(int index) const ;
|
|
// @cmember Tarray& | operator= | (const TArray& a) | Confronta se i due array sono uguali
|
|
TArray& operator= (const TArray& a);
|
|
|
|
// @cmember virtual bool | destroy | (int index, bool pack) | Rimuove uno o tutti gli elementi (default)
|
|
virtual bool destroy(int index = -1, bool pack = FALSE);
|
|
// @cmember virtual int | add | (TObject* obj, int index) | 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
|
|
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
|
|
int add(const TObject& object, int index = -1) ;
|
|
// @cmember int | insert | (const TObject& object, int index) | 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
|
|
TObject* remove(int index, bool pack = FALSE);
|
|
// @cmember void | swap | (int i1, int i2) | Scambia di posto gli elemnti i1 e i2 dell'array
|
|
void swap(int i1, int i2);
|
|
// @cmember void | pack | () | 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>
|
|
void sort(COMPARE_FUNCTION = NULL);
|
|
};
|
|
|
|
//ANDREA
|
|
inline TObject* TArray::objptr(int index) const
|
|
{
|
|
return (index < _size && index >= 0) ? _data[index] : NULL;
|
|
}
|
|
|
|
inline TObject& TArray::operator[] (int index) const
|
|
{
|
|
TObject* o = objptr(index);
|
|
#ifdef DBG
|
|
if (o == NULL)
|
|
fatal_box("Can't access NULL array item: %d of %d", index, size());
|
|
#endif
|
|
return *o;
|
|
}
|
|
|
|
class TBit_array : public TObject
|
|
{
|
|
word _size;
|
|
byte* _bit;
|
|
|
|
protected:
|
|
virtual bool ok() const;
|
|
virtual void print_on(ostream& out) const;
|
|
|
|
void resize(word size);
|
|
void copy(const TBit_array& ba);
|
|
word index(long n) const { return word(n >> 3); }
|
|
byte mask(long n) const { return 1 << (n & 0x7); }
|
|
|
|
public:
|
|
TBit_array(long size = 0);
|
|
TBit_array(const TBit_array& ba);
|
|
virtual ~TBit_array();
|
|
|
|
TBit_array& operator=(const TBit_array& ba);
|
|
bool operator[] (long n) const;
|
|
TBit_array& operator |=(const TBit_array& b);
|
|
|
|
long first_one() const;
|
|
long last_one() const;
|
|
long ones() const;
|
|
|
|
void set(long n);
|
|
void reset(long n);
|
|
void not(long n);
|
|
|
|
void set(long n, bool on) { on ? set(n) : reset(n); }
|
|
void set();
|
|
void reset();
|
|
void set(const char* numbers);
|
|
};
|
|
|
|
|
|
#endif
|