Migliorata la add dei TArray

Cambiato metodo add_to degli importi


git-svn-id: svn://10.65.10.50/trunk@1491 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-06-21 15:35:44 +00:00
parent 5e5cbf3d6b
commit 95edf6412b
10 changed files with 51 additions and 28 deletions

View File

@ -1,5 +1,6 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <array.h> #include <array.h>
#include <strings.h> #include <strings.h>
@ -60,7 +61,7 @@ bool TArray::destroy(
delete _data[i]; delete _data[i];
_data[i] = NULL; _data[i] = NULL;
} }
_items = 0; _items = _next = 0;
} }
else else
{ {
@ -72,26 +73,33 @@ bool TArray::destroy(
} }
TArray::TArray(int arraysize) : _size(0), _items(0), _data(NULL) TArray::TArray(int arraysize) : _size(0), _items(0), _next(0), _data(NULL)
{ {
if (arraysize) resize(arraysize); if (arraysize) resize(arraysize);
} }
TArray::TArray() : _size(0), _items(0), _data(NULL) TArray::TArray() : _size(0), _items(0), _next(0), _data(NULL)
{ {
} }
TArray::TArray(const TArray& a) : _size(0), _items(0), _data(NULL) TArray::TArray(const TArray& a) : _size(0), _items(0), _next(0), _data(NULL)
{ {
(*this) = a; (*this) = a;
} }
TArray& TArray::operator= (const TArray& a) TArray& TArray::operator= (const TArray& a)
{ {
if (_items > 0) destroy(); destroy();
if (_size < a.size()) resize(a.size()); if (size() < a.size())
for (_items = 0; _items < a.items(); _items++) resize(a.size());
_data[_items] = a[_items].dup(); for (int i = a.size()-1; i >= 0; i--)
{
const TObject* o = a.objptr(i);
if (o != NULL) _data[i] = o->dup();
}
_items = a.items();
_next = a._next;
return *this; return *this;
} }
@ -176,7 +184,8 @@ int TArray::add(
// //
// @xref <mf TArray::insert> // @xref <mf TArray::insert>
{ {
if (index < 0) for (index = 0; index < size() && _data[index]; index++); if (index < 0) for (index = _next; index < size() && _data[index]; index++);
if (index >= size()) resize(int(3L*index/2) + 1); if (index >= size()) resize(int(3L*index/2) + 1);
if (_data[index] != NULL) if (_data[index] != NULL)
@ -193,8 +202,16 @@ int TArray::add(
} }
_data[index] = object; _data[index] = object;
if (object != NULL) _items++; if (object != NULL)
{
_items++;
_next = index+1;
}
else
{
if (index < _next)
_next = index;
}
return index; return index;
} }
@ -254,6 +271,8 @@ TObject* TArray::remove(
{ {
_data[index] = NULL; _data[index] = NULL;
_items--; _items--;
if (index < _next)
_next = index;
} }
if (dopack) pack(); if (dopack) pack();
return o; return o;
@ -293,6 +312,7 @@ void TArray::pack()
next++; next++;
} }
} }
_next = next;
} }
// @func Funzione per permettere il confonto tra 2 oggetti. // @func Funzione per permettere il confonto tra 2 oggetti.

View File

@ -31,6 +31,8 @@ class TArray : public TObject
int _size; int _size;
// @cmember Numero di elementi presenti nell'array // @cmember Numero di elementi presenti nell'array
int _items; int _items;
// @cmember Prossimo elemento libero nell'array
int _next;
// @access Protected Member // @access Protected Member
protected: protected:

View File

@ -164,8 +164,7 @@ public:
// if code == NULL it's a base form // if code == NULL it's a base form
// otherwise it's integrated by a file definition // otherwise it's integrated by a file definition
TForm(const char* form, long code = 0L, int editlevel = 0, TForm(const char* form, long code = 0L, int editlevel = 0, const char* desc = "");
const char* desc = "");
virtual ~TForm(); virtual ~TForm();
}; };

View File

@ -258,7 +258,6 @@ void TMask::read_mask(const char* name, int num, int max)
_pagewin[MAX_PAGES] = read_page(scanner, TRUE); _pagewin[MAX_PAGES] = read_page(scanner, TRUE);
} }
} }
main_app().end_wait();
if (_pages < 1) if (_pages < 1)
fatal_box("Impossibile leggere la maschera %s", name); fatal_box("Impossibile leggere la maschera %s", name);
@ -267,6 +266,8 @@ void TMask::read_mask(const char* name, int num, int max)
if (!_sheetmask) if (!_sheetmask)
_total_time = clock()-start_t; _total_time = clock()-start_t;
main_app().end_wait();
} }

View File

@ -335,12 +335,13 @@ TMask_field* TSpreadsheet::col2field(int pos) const
{ {
int num; int num;
XI_OBJ** column = xi_get_member_list(_list, &num); XI_OBJ** column = xi_get_member_list(_list, &num);
CHECKD(pos >= 0 && pos < num, "Bad column number", pos);
TMask_field* good = NULL; TMask_field* good = NULL;
for (short id = column[pos]->cid; ; id += 100) for (short id = column[pos]->cid; ; id += 100)
{ {
TMask_field* f = field(id); TMask_field* f = field(id);
if (f == NULL) break; // End of search if (f == NULL) break; // Search failed
good = f; // We've found a field with the proper ID ... good = f; // We've found a field with the proper ID ...
if (f->active()) break; // ... and it's active: end of search if (f->active()) break; // ... and it's active: end of search
} }
@ -377,7 +378,7 @@ void TSpreadsheet::set_focus_cell(int riga, int colonna)
if (!cell_disabled(r, colonna-1)) if (!cell_disabled(r, colonna-1))
break; break;
if (colonna < _columns) if (colonna <= _columns)
{ {
XI_OBJ cell; XI_OBJ cell;
XI_MAKE_CELL(&cell, _list, riga, colonna); XI_MAKE_CELL(&cell, _list, riga, colonna);

View File

@ -991,12 +991,12 @@ void TDistrib::init (
// Importo // Importo
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
const TImporto& TImporto::add_to(TToken_string& s) const const TImporto& TImporto::add_to(TToken_string& s, int pos) const
{ {
const bool dare = sezione() == 'D'; const bool dare = sezione() == 'D';
const char* v = valore().string(); const char* v = valore().string();
s.add(dare ? v : "", 0); s.add(dare ? v : "", pos);
s.add(dare ? "" : v, 1); s.add(dare ? "" : v, pos+1);
return *this; return *this;
} }

View File

@ -270,9 +270,9 @@ public:
// @cmember Assegna sezione ed importo all'oggetto // @cmember Assegna sezione ed importo all'oggetto
const TImporto& set(char s, const real& v); const TImporto& set(char s, const real& v);
// @cmember Setta i primi due elementi della <c TToken_string> // @cmember Setta i due elementi pos e pos+1 della <c TToken_string>
// al valore dell'importo, lasciando bianco il dare (0) o l'avere(1) // al valore dell'importo, lasciando bianco il dare (pos) o l'avere (pos+1)
const TImporto& add_to(TToken_string& s) const; const TImporto& add_to(TToken_string& s, int pos) const;
// @cmember Costruttore // @cmember Costruttore
TImporto(char s = 'D', const real& v = ZERO) TImporto(char s = 'D', const real& v = ZERO)

View File

@ -1,4 +1,4 @@
// $Id: relation.cpp,v 1.47 1995-06-19 14:08:55 alex Exp $ // $Id: relation.cpp,v 1.48 1995-06-21 15:35:41 guy Exp $
// relation.cpp // relation.cpp
// fv 12/8/93 // fv 12/8/93
// relation class for isam files // relation class for isam files
@ -1118,8 +1118,9 @@ TRecnotype TCursor::readrec()
int TCursor::lock(TReclock l) int TCursor::lock(TReclock l)
{ {
CLockRec(&file().filehnd()->f, _pos, l); SecDef* sd = &file().filehnd()->f;
return file().filehnd()->f.IOR; CLockRec(sd, _pos, l);
return sd->IOR;
} }
TRecnotype TCursor::operator =(const TRecnotype pos) TRecnotype TCursor::operator =(const TRecnotype pos)

View File

@ -272,7 +272,6 @@ static BOOLEAN event_hook(HWND hwnd,
if (msg == WM_WAKEUP && wparam == main_app().waiting()) if (msg == WM_WAKEUP && wparam == main_app().waiting())
main_app().wake_up(); main_app().wake_up();
break; break;
break;
} }
return TRUE; // Continua col processo normale return TRUE; // Continua col processo normale