Rename TypedVector to Vector, matching dit.

This commit is contained in:
Hisham Muhammad 2006-05-30 13:45:40 +00:00
parent 7b2265b242
commit a853faaa2d
17 changed files with 257 additions and 257 deletions

View File

@ -88,7 +88,7 @@ HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) {
this->settings->changed = true; this->settings->changed = true;
Header* header = this->settings->header; Header* header = this->settings->header;
CRT_setColors(mark); CRT_setColors(mark);
ListBox* lbMenu = (ListBox*) TypedVector_get(this->scr->items, 0); ListBox* lbMenu = (ListBox*) Vector_get(this->scr->items, 0);
Header_draw(header); Header_draw(header);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(lbMenu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); RichString_setAttr(&(lbMenu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);

View File

@ -16,7 +16,7 @@ typedef struct ColumnsListBox_ {
ListBox super; ListBox super;
Settings* settings; Settings* settings;
TypedVector* columns; Vector* columns;
ScreenManager* scr; ScreenManager* scr;
} ColumnsListBox; } ColumnsListBox;

View File

@ -19,8 +19,8 @@ typedef enum HeaderSide_ {
} HeaderSide; } HeaderSide;
typedef struct Header_ { typedef struct Header_ {
TypedVector* leftMeters; Vector* leftMeters;
TypedVector* rightMeters; Vector* rightMeters;
ProcessList* pl; ProcessList* pl;
bool margin; bool margin;
int height; int height;
@ -35,21 +35,21 @@ typedef struct Header_ {
Header* Header_new(ProcessList* pl) { Header* Header_new(ProcessList* pl) {
Header* this = malloc(sizeof(Header)); Header* this = malloc(sizeof(Header));
this->leftMeters = TypedVector_new(METER_CLASS, true, DEFAULT_SIZE); this->leftMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE);
this->rightMeters = TypedVector_new(METER_CLASS, true, DEFAULT_SIZE); this->rightMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE);
this->margin = true; this->margin = true;
this->pl = pl; this->pl = pl;
return this; return this;
} }
void Header_delete(Header* this) { void Header_delete(Header* this) {
TypedVector_delete(this->leftMeters); Vector_delete(this->leftMeters);
TypedVector_delete(this->rightMeters); Vector_delete(this->rightMeters);
free(this); free(this);
} }
void Header_createMeter(Header* this, char* name, HeaderSide side) { void Header_createMeter(Header* this, char* name, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
@ -62,44 +62,44 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
} }
for (MeterType** type = Meter_types; *type; type++) { for (MeterType** type = Meter_types; *type; type++) {
if (String_eq(name, (*type)->name)) { if (String_eq(name, (*type)->name)) {
TypedVector_add(meters, Meter_new(this->pl, param, *type)); Vector_add(meters, Meter_new(this->pl, param, *type));
break; break;
} }
} }
} }
void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) { void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
Meter* meter = (Meter*) TypedVector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
Meter_setMode(meter, mode); Meter_setMode(meter, mode);
} }
Meter* Header_addMeter(Header* this, MeterType* type, int param, HeaderSide side) { Meter* Header_addMeter(Header* this, MeterType* type, int param, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
Meter* meter = Meter_new(this->pl, param, type); Meter* meter = Meter_new(this->pl, param, type);
TypedVector_add(meters, meter); Vector_add(meters, meter);
return meter; return meter;
} }
int Header_size(Header* this, HeaderSide side) { int Header_size(Header* this, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
return TypedVector_size(meters); return Vector_size(meters);
} }
char* Header_readMeterName(Header* this, int i, HeaderSide side) { char* Header_readMeterName(Header* this, int i, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
Meter* meter = (Meter*) TypedVector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
int nameLen = strlen(meter->type->name); int nameLen = strlen(meter->type->name);
int len = nameLen + 100; int len = nameLen + 100;
@ -113,21 +113,21 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) {
} }
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) { MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
TypedVector* meters = side == LEFT_HEADER Vector* meters = side == LEFT_HEADER
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
Meter* meter = (Meter*) TypedVector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
return meter->mode; return meter->mode;
} }
void Header_defaultMeters(Header* this) { void Header_defaultMeters(Header* this) {
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &AllCPUsMeter)); Vector_add(this->leftMeters, Meter_new(this->pl, 0, &AllCPUsMeter));
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &MemoryMeter)); Vector_add(this->leftMeters, Meter_new(this->pl, 0, &MemoryMeter));
TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &SwapMeter)); Vector_add(this->leftMeters, Meter_new(this->pl, 0, &SwapMeter));
TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &TasksMeter)); Vector_add(this->rightMeters, Meter_new(this->pl, 0, &TasksMeter));
TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &LoadAverageMeter)); Vector_add(this->rightMeters, Meter_new(this->pl, 0, &LoadAverageMeter));
TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &UptimeMeter)); Vector_add(this->rightMeters, Meter_new(this->pl, 0, &UptimeMeter));
} }
void Header_draw(Header* this) { void Header_draw(Header* this) {
@ -138,13 +138,13 @@ void Header_draw(Header* this) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
mvhline(y, 0, ' ', COLS); mvhline(y, 0, ' ', COLS);
} }
for (int y = (pad / 2), i = 0; i < TypedVector_size(this->leftMeters); i++) { for (int y = (pad / 2), i = 0; i < Vector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) TypedVector_get(this->leftMeters, i); Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
meter->draw(meter, pad, y, COLS / 2 - (pad * 2 - 1) - 1); meter->draw(meter, pad, y, COLS / 2 - (pad * 2 - 1) - 1);
y += meter->h; y += meter->h;
} }
for (int y = (pad / 2), i = 0; i < TypedVector_size(this->rightMeters); i++) { for (int y = (pad / 2), i = 0; i < Vector_size(this->rightMeters); i++) {
Meter* meter = (Meter*) TypedVector_get(this->rightMeters, i); Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
meter->draw(meter, COLS / 2 + pad, y, COLS / 2 - (pad * 2 - 1) - 1); meter->draw(meter, COLS / 2 + pad, y, COLS / 2 - (pad * 2 - 1) - 1);
y += meter->h; y += meter->h;
} }
@ -155,12 +155,12 @@ int Header_calculateHeight(Header* this) {
int leftHeight = pad; int leftHeight = pad;
int rightHeight = pad; int rightHeight = pad;
for (int i = 0; i < TypedVector_size(this->leftMeters); i++) { for (int i = 0; i < Vector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) TypedVector_get(this->leftMeters, i); Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
leftHeight += meter->h; leftHeight += meter->h;
} }
for (int i = 0; i < TypedVector_size(this->rightMeters); i++) { for (int i = 0; i < Vector_size(this->rightMeters); i++) {
Meter* meter = (Meter*) TypedVector_get(this->rightMeters, i); Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
rightHeight += meter->h; rightHeight += meter->h;
} }
this->pad = pad; this->pad = pad;

View File

@ -21,8 +21,8 @@ typedef enum HeaderSide_ {
} HeaderSide; } HeaderSide;
typedef struct Header_ { typedef struct Header_ {
TypedVector* leftMeters; Vector* leftMeters;
TypedVector* rightMeters; Vector* rightMeters;
ProcessList* pl; ProcessList* pl;
bool margin; bool margin;
int height; int height;

View File

@ -7,7 +7,7 @@ in the source distribution for its full text.
#include "Object.h" #include "Object.h"
#include "ListBox.h" #include "ListBox.h"
#include "TypedVector.h" #include "Vector.h"
#include "CRT.h" #include "CRT.h"
#include "RichString.h" #include "RichString.h"
@ -36,7 +36,7 @@ struct ListBox_ {
Object super; Object super;
int x, y, w, h; int x, y, w, h;
WINDOW* window; WINDOW* window;
TypedVector* items; Vector* items;
int selected; int selected;
int scrollV, scrollH; int scrollV, scrollH;
int oldSelected; int oldSelected;
@ -81,7 +81,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
this->w = w; this->w = w;
this->h = h; this->h = h;
this->eventHandler = NULL; this->eventHandler = NULL;
this->items = TypedVector_new(type, owner, DEFAULT_SIZE); this->items = Vector_new(type, owner, DEFAULT_SIZE);
this->scrollV = 0; this->scrollV = 0;
this->scrollH = 0; this->scrollH = 0;
this->selected = 0; this->selected = 0;
@ -93,7 +93,7 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
void ListBox_done(ListBox* this) { void ListBox_done(ListBox* this) {
assert (this != NULL); assert (this != NULL);
RichString_delete(this->header); RichString_delete(this->header);
TypedVector_delete(this->items); Vector_delete(this->items);
} }
inline void ListBox_setRichHeader(ListBox* this, RichString header) { inline void ListBox_setRichHeader(ListBox* this, RichString header) {
@ -135,7 +135,7 @@ void ListBox_resize(ListBox* this, int w, int h) {
void ListBox_prune(ListBox* this) { void ListBox_prune(ListBox* this) {
assert (this != NULL); assert (this != NULL);
TypedVector_prune(this->items); Vector_prune(this->items);
this->scrollV = 0; this->scrollV = 0;
this->selected = 0; this->selected = 0;
this->oldSelected = 0; this->oldSelected = 0;
@ -145,35 +145,35 @@ void ListBox_prune(ListBox* this) {
void ListBox_add(ListBox* this, Object* o) { void ListBox_add(ListBox* this, Object* o) {
assert (this != NULL); assert (this != NULL);
TypedVector_add(this->items, o); Vector_add(this->items, o);
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_insert(ListBox* this, int i, Object* o) { void ListBox_insert(ListBox* this, int i, Object* o) {
assert (this != NULL); assert (this != NULL);
TypedVector_insert(this->items, i, o); Vector_insert(this->items, i, o);
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_set(ListBox* this, int i, Object* o) { void ListBox_set(ListBox* this, int i, Object* o) {
assert (this != NULL); assert (this != NULL);
TypedVector_set(this->items, i, o); Vector_set(this->items, i, o);
} }
Object* ListBox_get(ListBox* this, int i) { Object* ListBox_get(ListBox* this, int i) {
assert (this != NULL); assert (this != NULL);
return TypedVector_get(this->items, i); return Vector_get(this->items, i);
} }
Object* ListBox_remove(ListBox* this, int i) { Object* ListBox_remove(ListBox* this, int i) {
assert (this != NULL); assert (this != NULL);
this->needsRedraw = true; this->needsRedraw = true;
Object* removed = TypedVector_remove(this->items, i); Object* removed = Vector_remove(this->items, i);
if (this->selected > 0 && this->selected >= TypedVector_size(this->items)) if (this->selected > 0 && this->selected >= Vector_size(this->items))
this->selected--; this->selected--;
return removed; return removed;
} }
@ -181,13 +181,13 @@ Object* ListBox_remove(ListBox* this, int i) {
Object* ListBox_getSelected(ListBox* this) { Object* ListBox_getSelected(ListBox* this) {
assert (this != NULL); assert (this != NULL);
return TypedVector_get(this->items, this->selected); return Vector_get(this->items, this->selected);
} }
void ListBox_moveSelectedUp(ListBox* this) { void ListBox_moveSelectedUp(ListBox* this) {
assert (this != NULL); assert (this != NULL);
TypedVector_moveUp(this->items, this->selected); Vector_moveUp(this->items, this->selected);
if (this->selected > 0) if (this->selected > 0)
this->selected--; this->selected--;
} }
@ -195,8 +195,8 @@ void ListBox_moveSelectedUp(ListBox* this) {
void ListBox_moveSelectedDown(ListBox* this) { void ListBox_moveSelectedDown(ListBox* this) {
assert (this != NULL); assert (this != NULL);
TypedVector_moveDown(this->items, this->selected); Vector_moveDown(this->items, this->selected);
if (this->selected + 1 < TypedVector_size(this->items)) if (this->selected + 1 < Vector_size(this->items))
this->selected++; this->selected++;
} }
@ -209,13 +209,13 @@ int ListBox_getSelectedIndex(ListBox* this) {
int ListBox_getSize(ListBox* this) { int ListBox_getSize(ListBox* this) {
assert (this != NULL); assert (this != NULL);
return TypedVector_size(this->items); return Vector_size(this->items);
} }
void ListBox_setSelected(ListBox* this, int selected) { void ListBox_setSelected(ListBox* this, int selected) {
assert (this != NULL); assert (this != NULL);
selected = MAX(0, MIN(TypedVector_size(this->items) - 1, selected)); selected = MAX(0, MIN(Vector_size(this->items) - 1, selected));
this->selected = selected; this->selected = selected;
} }
@ -223,7 +223,7 @@ void ListBox_draw(ListBox* this, bool focus) {
assert (this != NULL); assert (this != NULL);
int first, last; int first, last;
int itemCount = TypedVector_size(this->items); int itemCount = Vector_size(this->items);
int scrollH = this->scrollH; int scrollH = this->scrollH;
int y = this->y; int x = this->x; int y = this->y; int x = this->x;
first = this->scrollV; first = this->scrollV;
@ -269,7 +269,7 @@ void ListBox_draw(ListBox* this, bool focus) {
if (this->needsRedraw) { if (this->needsRedraw) {
for(int i = first, j = 0; j < this->h && i < last; i++, j++) { for(int i = first, j = 0; j < this->h && i < last; i++, j++) {
Object* itemObj = TypedVector_get(this->items, i); Object* itemObj = Vector_get(this->items, i);
RichString itemRef = RichString_new(); RichString itemRef = RichString_new();
itemObj->display(itemObj, &itemRef); itemObj->display(itemObj, &itemRef);
int amt = MIN(itemRef.len - scrollH, this->w); int amt = MIN(itemRef.len - scrollH, this->w);
@ -291,10 +291,10 @@ void ListBox_draw(ListBox* this, bool focus) {
this->needsRedraw = false; this->needsRedraw = false;
} else { } else {
Object* oldObj = TypedVector_get(this->items, this->oldSelected); Object* oldObj = Vector_get(this->items, this->oldSelected);
RichString oldRef = RichString_new(); RichString oldRef = RichString_new();
oldObj->display(oldObj, &oldRef); oldObj->display(oldObj, &oldRef);
Object* newObj = TypedVector_get(this->items, this->selected); Object* newObj = Vector_get(this->items, this->selected);
RichString newRef = RichString_new(); RichString newRef = RichString_new();
newObj->display(newObj, &newRef); newObj->display(newObj, &newRef);
mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w); mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w);
@ -315,7 +315,7 @@ void ListBox_onKey(ListBox* this, int key) {
assert (this != NULL); assert (this != NULL);
switch (key) { switch (key) {
case KEY_DOWN: case KEY_DOWN:
if (this->selected + 1 < TypedVector_size(this->items)) if (this->selected + 1 < Vector_size(this->items))
this->selected++; this->selected++;
break; break;
case KEY_UP: case KEY_UP:
@ -339,7 +339,7 @@ void ListBox_onKey(ListBox* this, int key) {
break; break;
case KEY_NPAGE: case KEY_NPAGE:
this->selected += this->h; this->selected += this->h;
int size = TypedVector_size(this->items); int size = Vector_size(this->items);
if (this->selected >= size) if (this->selected >= size)
this->selected = size - 1; this->selected = size - 1;
break; break;
@ -347,7 +347,7 @@ void ListBox_onKey(ListBox* this, int key) {
this->selected = 0; this->selected = 0;
break; break;
case KEY_END: case KEY_END:
this->selected = TypedVector_size(this->items) - 1; this->selected = Vector_size(this->items) - 1;
break; break;
} }
} }

View File

@ -10,7 +10,7 @@ in the source distribution for its full text.
*/ */
#include "Object.h" #include "Object.h"
#include "TypedVector.h" #include "Vector.h"
#include "CRT.h" #include "CRT.h"
#include "RichString.h" #include "RichString.h"
@ -39,7 +39,7 @@ struct ListBox_ {
Object super; Object super;
int x, y, w, h; int x, y, w, h;
WINDOW* window; WINDOW* window;
TypedVector* items; Vector* items;
int selected; int selected;
int scrollV, scrollH; int scrollV, scrollH;
int oldSelected; int oldSelected;

View File

@ -15,14 +15,14 @@ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \
Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c \ Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c \
MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \ ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
SignalsListBox.c String.c SwapMeter.c TasksMeter.c TypedVector.c \ SignalsListBox.c String.c SwapMeter.c TasksMeter.c Vector.c \
UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h \ UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h \
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \ ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h \ DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h \
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \ ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \ MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h \ Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h \
TypedVector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \ Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h \ ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h \
AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c \ AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c \
ColumnsListBox.h ColumnsListBox.h

View File

@ -14,13 +14,13 @@ typedef struct MetersListBox_ {
ListBox super; ListBox super;
Settings* settings; Settings* settings;
TypedVector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersListBox; } MetersListBox;
}*/ }*/
MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector* meters, ScreenManager* scr) { MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
MetersListBox* this = (MetersListBox*) malloc(sizeof(MetersListBox)); MetersListBox* this = (MetersListBox*) malloc(sizeof(MetersListBox));
ListBox* super = (ListBox*) this; ListBox* super = (ListBox*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
@ -31,8 +31,8 @@ MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector*
this->scr = scr; this->scr = scr;
super->eventHandler = MetersListBox_EventHandler; super->eventHandler = MetersListBox_EventHandler;
ListBox_setHeader(super, header); ListBox_setHeader(super, header);
for (int i = 0; i < TypedVector_size(meters); i++) { for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) TypedVector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
ListBox_add(super, (Object*) Meter_toListItem(meter)); ListBox_add(super, (Object*) Meter_toListItem(meter));
} }
return this; return this;
@ -58,7 +58,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case KEY_F(4): case KEY_F(4):
case 't': case 't':
{ {
Meter* meter = (Meter*) TypedVector_get(this->meters, selected); Meter* meter = (Meter*) Vector_get(this->meters, selected);
int mode = meter->mode + 1; int mode = meter->mode + 1;
if (mode == LAST_METERMODE) mode = 1; if (mode == LAST_METERMODE) mode = 1;
Meter_setMode(meter, mode); Meter_setMode(meter, mode);
@ -70,7 +70,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case '[': case '[':
case '-': case '-':
{ {
TypedVector_moveUp(this->meters, selected); Vector_moveUp(this->meters, selected);
ListBox_moveSelectedUp(super); ListBox_moveSelectedUp(super);
result = HANDLED; result = HANDLED;
break; break;
@ -79,7 +79,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case ']': case ']':
case '+': case '+':
{ {
TypedVector_moveDown(this->meters, selected); Vector_moveDown(this->meters, selected);
ListBox_moveSelectedDown(super); ListBox_moveSelectedDown(super);
result = HANDLED; result = HANDLED;
break; break;
@ -87,8 +87,8 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case KEY_F(9): case KEY_F(9):
case KEY_DC: case KEY_DC:
{ {
if (selected < TypedVector_size(this->meters)) { if (selected < Vector_size(this->meters)) {
TypedVector_remove(this->meters, selected); Vector_remove(this->meters, selected);
ListBox_remove(super, selected); ListBox_remove(super, selected);
} }
result = HANDLED; result = HANDLED;

View File

@ -16,12 +16,12 @@ typedef struct MetersListBox_ {
ListBox super; ListBox super;
Settings* settings; Settings* settings;
TypedVector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersListBox; } MetersListBox;
MetersListBox* MetersListBox_new(Settings* settings, char* header, TypedVector* meters, ScreenManager* scr); MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
void MetersListBox_delete(Object* object); void MetersListBox_delete(Object* object);

View File

@ -12,7 +12,7 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#include "Process.h" #include "Process.h"
#include "TypedVector.h" #include "Vector.h"
#include "UsersTable.h" #include "UsersTable.h"
#include "Hashtable.h" #include "Hashtable.h"
@ -56,8 +56,8 @@ in the source distribution for its full text.
/*{ /*{
typedef struct ProcessList_ { typedef struct ProcessList_ {
TypedVector* processes; Vector* processes;
TypedVector* processes2; Vector* processes2;
Hashtable* processTable; Hashtable* processTable;
Process* prototype; Process* prototype;
UsersTable* usersTable; UsersTable* usersTable;
@ -168,13 +168,13 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
ProcessList* ProcessList_new(UsersTable* usersTable) { ProcessList* ProcessList_new(UsersTable* usersTable) {
ProcessList* this; ProcessList* this;
this = malloc(sizeof(ProcessList)); this = malloc(sizeof(ProcessList));
this->processes = TypedVector_new(PROCESS_CLASS, true, DEFAULT_SIZE); this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE);
this->processTable = Hashtable_new(20, false); this->processTable = Hashtable_new(20, false);
this->prototype = Process_new(this); this->prototype = Process_new(this);
this->usersTable = usersTable; this->usersTable = usersTable;
/* tree-view auxiliary buffers */ /* tree-view auxiliary buffers */
this->processes2 = TypedVector_new(PROCESS_CLASS, true, DEFAULT_SIZE); this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE);
#ifdef DEBUG #ifdef DEBUG
this->traceFile = fopen("/tmp/htop-proc-trace", "w"); this->traceFile = fopen("/tmp/htop-proc-trace", "w");
@ -206,7 +206,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
} }
this->fields = calloc(sizeof(ProcessField), LAST_PROCESSFIELD+1); this->fields = calloc(sizeof(ProcessField), LAST_PROCESSFIELD+1);
// TODO: turn 'fields' into a TypedVector, // TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects). // (and ProcessFields into proper objects).
for (int i = 0; defaultHeaders[i]; i++) { for (int i = 0; defaultHeaders[i]; i++) {
this->fields[i] = defaultHeaders[i]; this->fields[i] = defaultHeaders[i];
@ -226,8 +226,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
void ProcessList_delete(ProcessList* this) { void ProcessList_delete(ProcessList* this) {
Hashtable_delete(this->processTable); Hashtable_delete(this->processTable);
TypedVector_delete(this->processes); Vector_delete(this->processes);
TypedVector_delete(this->processes2); Vector_delete(this->processes2);
Process_delete((Object*)this->prototype); Process_delete((Object*)this->prototype);
free(this->totalTime); free(this->totalTime);
@ -271,11 +271,11 @@ RichString ProcessList_printHeader(ProcessList* this) {
void ProcessList_prune(ProcessList* this) { void ProcessList_prune(ProcessList* this) {
TypedVector_prune(this->processes); Vector_prune(this->processes);
} }
void ProcessList_add(ProcessList* this, Process* p) { void ProcessList_add(ProcessList* this, Process* p) {
TypedVector_add(this->processes, p); Vector_add(this->processes, p);
Hashtable_put(this->processTable, p->pid, p); Hashtable_put(this->processTable, p->pid, p);
} }
@ -283,64 +283,64 @@ void ProcessList_remove(ProcessList* this, Process* p) {
Hashtable_remove(this->processTable, p->pid); Hashtable_remove(this->processTable, p->pid);
ProcessField pf = this->sortKey; ProcessField pf = this->sortKey;
this->sortKey = PID; this->sortKey = PID;
int index = TypedVector_indexOf(this->processes, p); int index = Vector_indexOf(this->processes, p);
TypedVector_remove(this->processes, index); Vector_remove(this->processes, index);
this->sortKey = pf; this->sortKey = pf;
} }
Process* ProcessList_get(ProcessList* this, int index) { Process* ProcessList_get(ProcessList* this, int index) {
return (Process*) (TypedVector_get(this->processes, index)); return (Process*) (Vector_get(this->processes, index));
} }
int ProcessList_size(ProcessList* this) { int ProcessList_size(ProcessList* this) {
return (TypedVector_size(this->processes)); return (Vector_size(this->processes));
} }
/* private */ /* private */
void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) { void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) {
TypedVector* children = TypedVector_new(PROCESS_CLASS, false, DEFAULT_SIZE); Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE);
for (int i = 0; i < TypedVector_size(this->processes); i++) { for (int i = 0; i < Vector_size(this->processes); i++) {
Process* process = (Process*) (TypedVector_get(this->processes, i)); Process* process = (Process*) (Vector_get(this->processes, i));
if (process->ppid == pid) { if (process->ppid == pid) {
Process* process = (Process*) (TypedVector_take(this->processes, i)); Process* process = (Process*) (Vector_take(this->processes, i));
TypedVector_add(children, process); Vector_add(children, process);
i--; i--;
} }
} }
int size = TypedVector_size(children); int size = Vector_size(children);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Process* process = (Process*) (TypedVector_get(children, i)); Process* process = (Process*) (Vector_get(children, i));
if (direction == 1) if (direction == 1)
TypedVector_add(this->processes2, process); Vector_add(this->processes2, process);
else else
TypedVector_insert(this->processes2, 0, process); Vector_insert(this->processes2, 0, process);
int nextIndent = indent; int nextIndent = indent;
if (i < size - 1) if (i < size - 1)
nextIndent = indent | (1 << level); nextIndent = indent | (1 << level);
ProcessList_buildTree(this, process->pid, level+1, nextIndent, direction); ProcessList_buildTree(this, process->pid, level+1, nextIndent, direction);
process->indent = indent | (1 << level); process->indent = indent | (1 << level);
} }
TypedVector_delete(children); Vector_delete(children);
} }
void ProcessList_sort(ProcessList* this) { void ProcessList_sort(ProcessList* this) {
if (!this->treeView) { if (!this->treeView) {
TypedVector_sort(this->processes); Vector_sort(this->processes);
} else { } else {
int direction = this->direction; int direction = this->direction;
int sortKey = this->sortKey; int sortKey = this->sortKey;
this->sortKey = PID; this->sortKey = PID;
this->direction = 1; this->direction = 1;
TypedVector_sort(this->processes); Vector_sort(this->processes);
this->sortKey = sortKey; this->sortKey = sortKey;
this->direction = direction; this->direction = direction;
Process* init = (Process*) (TypedVector_take(this->processes, 0)); Process* init = (Process*) (Vector_take(this->processes, 0));
assert(init->pid == 1); assert(init->pid == 1);
init->indent = 0; init->indent = 0;
TypedVector_add(this->processes2, init); Vector_add(this->processes2, init);
ProcessList_buildTree(this, init->pid, 0, 0, direction); ProcessList_buildTree(this, init->pid, 0, 0, direction);
TypedVector* t = this->processes; Vector* t = this->processes;
this->processes = this->processes2; this->processes = this->processes2;
this->processes2 = t; this->processes2 = t;
} }
@ -642,8 +642,8 @@ void ProcessList_scan(ProcessList* this) {
fclose(status); fclose(status);
// mark all process as "dirty" // mark all process as "dirty"
for (int i = 0; i < TypedVector_size(this->processes); i++) { for (int i = 0; i < Vector_size(this->processes); i++) {
Process* p = (Process*) TypedVector_get(this->processes, i); Process* p = (Process*) Vector_get(this->processes, i);
p->updated = false; p->updated = false;
} }
@ -655,8 +655,8 @@ void ProcessList_scan(ProcessList* this) {
ProcessList_processEntries(this, PROCDIR, 0, period); ProcessList_processEntries(this, PROCDIR, 0, period);
signal(11, SIG_DFL); signal(11, SIG_DFL);
for (int i = TypedVector_size(this->processes) - 1; i >= 0; i--) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) TypedVector_get(this->processes, i); Process* p = (Process*) Vector_get(this->processes, i);
if (p->updated == false) if (p->updated == false)
ProcessList_remove(this, p); ProcessList_remove(this, p);
else else

View File

@ -15,7 +15,7 @@ in the source distribution for its full text.
#endif #endif
#include "Process.h" #include "Process.h"
#include "TypedVector.h" #include "Vector.h"
#include "UsersTable.h" #include "UsersTable.h"
#include "Hashtable.h" #include "Hashtable.h"
@ -56,8 +56,8 @@ in the source distribution for its full text.
typedef struct ProcessList_ { typedef struct ProcessList_ {
TypedVector* processes; Vector* processes;
TypedVector* processes2; Vector* processes2;
Hashtable* processTable; Hashtable* processTable;
Process* prototype; Process* prototype;
UsersTable* usersTable; UsersTable* usersTable;

View File

@ -8,7 +8,7 @@ in the source distribution for its full text.
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ListBox.h" #include "ListBox.h"
#include "Object.h" #include "Object.h"
#include "TypedVector.h" #include "Vector.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "debug.h" #include "debug.h"
@ -29,8 +29,8 @@ typedef struct ScreenManager_ {
int x2; int x2;
int y2; int y2;
Orientation orientation; Orientation orientation;
TypedVector* items; Vector* items;
TypedVector* fuBars; Vector* fuBars;
int itemCount; int itemCount;
FunctionBar* fuBar; FunctionBar* fuBar;
bool owner; bool owner;
@ -47,16 +47,16 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->y2 = y2; this->y2 = y2;
this->fuBar = NULL; this->fuBar = NULL;
this->orientation = orientation; this->orientation = orientation;
this->items = TypedVector_new(LISTBOX_CLASS, owner, DEFAULT_SIZE); this->items = Vector_new(LISTBOX_CLASS, owner, DEFAULT_SIZE);
this->fuBars = TypedVector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE); this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE);
this->itemCount = 0; this->itemCount = 0;
this->owner = owner; this->owner = owner;
return this; return this;
} }
void ScreenManager_delete(ScreenManager* this) { void ScreenManager_delete(ScreenManager* this) {
TypedVector_delete(this->items); Vector_delete(this->items);
TypedVector_delete(this->fuBars); Vector_delete(this->fuBars);
free(this); free(this);
} }
@ -68,7 +68,7 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
if (this->orientation == HORIZONTAL) { if (this->orientation == HORIZONTAL) {
int lastX = 0; int lastX = 0;
if (this->itemCount > 0) { if (this->itemCount > 0) {
ListBox* last = (ListBox*) TypedVector_get(this->items, this->itemCount - 1); ListBox* last = (ListBox*) Vector_get(this->items, this->itemCount - 1);
lastX = last->x + last->w + 1; lastX = last->x + last->w + 1;
} }
if (size > 0) { if (size > 0) {
@ -79,11 +79,11 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
ListBox_move(item, lastX, this->y1); ListBox_move(item, lastX, this->y1);
} }
// TODO: VERTICAL // TODO: VERTICAL
TypedVector_add(this->items, item); Vector_add(this->items, item);
if (fuBar) if (fuBar)
TypedVector_add(this->fuBars, fuBar); Vector_add(this->fuBars, fuBar);
else else
TypedVector_add(this->fuBars, FunctionBar_new(0, NULL, NULL, NULL)); Vector_add(this->fuBars, FunctionBar_new(0, NULL, NULL, NULL));
if (!this->fuBar && fuBar) this->fuBar = fuBar; if (!this->fuBar && fuBar) this->fuBar = fuBar;
item->needsRedraw = true; item->needsRedraw = true;
this->itemCount++; this->itemCount++;
@ -91,8 +91,8 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
ListBox* ScreenManager_remove(ScreenManager* this, int index) { ListBox* ScreenManager_remove(ScreenManager* this, int index) {
assert(this->itemCount > index); assert(this->itemCount > index);
ListBox* lb = (ListBox*) TypedVector_remove(this->items, index); ListBox* lb = (ListBox*) Vector_remove(this->items, index);
TypedVector_remove(this->fuBars, index); Vector_remove(this->fuBars, index);
this->fuBar = NULL; this->fuBar = NULL;
this->itemCount--; this->itemCount--;
return lb; return lb;
@ -112,12 +112,12 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
int items = this->itemCount; int items = this->itemCount;
int lastX = 0; int lastX = 0;
for (int i = 0; i < items - 1; i++) { for (int i = 0; i < items - 1; i++) {
ListBox* lb = (ListBox*) TypedVector_get(this->items, i); ListBox* lb = (ListBox*) Vector_get(this->items, i);
ListBox_resize(lb, lb->w, LINES-y1+y2); ListBox_resize(lb, lb->w, LINES-y1+y2);
ListBox_move(lb, lastX, y1); ListBox_move(lb, lastX, y1);
lastX = lb->x + lb->w + 1; lastX = lb->x + lb->w + 1;
} }
ListBox* lb = (ListBox*) TypedVector_get(this->items, items-1); ListBox* lb = (ListBox*) Vector_get(this->items, items-1);
ListBox_resize(lb, COLS-x1+x2-lastX, LINES-y1+y2); ListBox_resize(lb, COLS-x1+x2-lastX, LINES-y1+y2);
ListBox_move(lb, lastX, y1); ListBox_move(lb, lastX, y1);
} }
@ -126,7 +126,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; int focus = 0;
ListBox* lbFocus = (ListBox*) TypedVector_get(this->items, focus); ListBox* lbFocus = (ListBox*) Vector_get(this->items, focus);
if (this->fuBar) if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL); FunctionBar_draw(this->fuBar, NULL);
@ -134,7 +134,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
while (!quit) { while (!quit) {
int items = this->itemCount; int items = this->itemCount;
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
ListBox* lb = (ListBox*) TypedVector_get(this->items, i); ListBox* lb = (ListBox*) Vector_get(this->items, i);
ListBox_draw(lb, i == focus); ListBox_draw(lb, i == focus);
if (i < items) { if (i < items) {
if (this->orientation == HORIZONTAL) { if (this->orientation == HORIZONTAL) {
@ -142,7 +142,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
} }
} }
} }
FunctionBar* bar = (FunctionBar*) TypedVector_get(this->fuBars, focus); FunctionBar* bar = (FunctionBar*) Vector_get(this->fuBars, focus);
if (bar) if (bar)
this->fuBar = bar; this->fuBar = bar;
if (this->fuBar) if (this->fuBar)
@ -159,7 +159,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x); ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x);
} else { } else {
for (int i = 0; i < this->itemCount; i++) { for (int i = 0; i < this->itemCount; i++) {
ListBox* lb = (ListBox*) TypedVector_get(this->items, i); ListBox* lb = (ListBox*) Vector_get(this->items, i);
if (mevent.x > lb->x && mevent.x <= lb->x+lb->w && if (mevent.x > lb->x && mevent.x <= lb->x+lb->w &&
mevent.y > lb->y && mevent.y <= lb->y+lb->h) { mevent.y > lb->y && mevent.y <= lb->y+lb->h) {
focus = i; focus = i;
@ -196,7 +196,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryLeft: tryLeft:
if (focus > 0) if (focus > 0)
focus--; focus--;
lbFocus = (ListBox*) TypedVector_get(this->items, focus); lbFocus = (ListBox*) Vector_get(this->items, focus);
if (ListBox_getSize(lbFocus) == 0 && focus > 0) if (ListBox_getSize(lbFocus) == 0 && focus > 0)
goto tryLeft; goto tryLeft;
break; break;
@ -205,7 +205,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryRight: tryRight:
if (focus < this->itemCount - 1) if (focus < this->itemCount - 1)
focus++; focus++;
lbFocus = (ListBox*) TypedVector_get(this->items, focus); lbFocus = (ListBox*) Vector_get(this->items, focus);
if (ListBox_getSize(lbFocus) == 0 && focus < this->itemCount - 1) if (ListBox_getSize(lbFocus) == 0 && focus < this->itemCount - 1)
goto tryRight; goto tryRight;
break; break;

View File

@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "ListBox.h" #include "ListBox.h"
#include "Object.h" #include "Object.h"
#include "TypedVector.h" #include "Vector.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "debug.h" #include "debug.h"
@ -31,10 +31,10 @@ typedef struct ScreenManager_ {
int x2; int x2;
int y2; int y2;
Orientation orientation; Orientation orientation;
TypedVector* items; Vector* items;
int itemCount; int itemCount;
FunctionBar* fuBar; FunctionBar* fuBar;
TypedVector* fuBars; Vector* fuBars;
bool owner; bool owner;
} ScreenManager; } ScreenManager;

View File

@ -1,69 +0,0 @@
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_TypedVector
#define HEADER_TypedVector
/*
htop
(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Object.h"
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "debug.h"
#include <assert.h>
#ifndef DEFAULT_SIZE
#define DEFAULT_SIZE -1
#endif
typedef void(*TypedVector_procedure)(void*);
typedef struct TypedVector_ {
Object **array;
int arraySize;
int growthRate;
int items;
char* vectorType;
bool owner;
} TypedVector;
TypedVector* TypedVector_new(char* vectorType_, bool owner, int size);
void TypedVector_delete(TypedVector* this);
void TypedVector_prune(TypedVector* this);
void TypedVector_sort(TypedVector* this);
void TypedVector_insert(TypedVector* this, int index, void* data_);
Object* TypedVector_take(TypedVector* this, int index);
Object* TypedVector_remove(TypedVector* this, int index);
void TypedVector_moveUp(TypedVector* this, int index);
void TypedVector_moveDown(TypedVector* this, int index);
void TypedVector_set(TypedVector* this, int index, void* data_);
inline Object* TypedVector_get(TypedVector* this, int index);
inline int TypedVector_size(TypedVector* this);
void TypedVector_merge(TypedVector* this, TypedVector* v2);
void TypedVector_add(TypedVector* this, void* data_);
inline int TypedVector_indexOf(TypedVector* this, void* search_);
void TypedVector_foreach(TypedVector* this, TypedVector_procedure f);
#endif

View File

@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "TypedVector.h" #include "Vector.h"
#include "Object.h" #include "Object.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -20,25 +20,25 @@ in the source distribution for its full text.
#define DEFAULT_SIZE -1 #define DEFAULT_SIZE -1
#endif #endif
typedef void(*TypedVector_procedure)(void*); typedef void(*Vector_procedure)(void*);
typedef struct TypedVector_ { typedef struct Vector_ {
Object **array; Object **array;
int arraySize; int arraySize;
int growthRate; int growthRate;
int items; int items;
char* vectorType; char* vectorType;
bool owner; bool owner;
} TypedVector; } Vector;
}*/ }*/
TypedVector* TypedVector_new(char* vectorType_, bool owner, int size) { Vector* Vector_new(char* vectorType_, bool owner, int size) {
TypedVector* this; Vector* this;
if (size == DEFAULT_SIZE) if (size == DEFAULT_SIZE)
size = 10; size = 10;
this = (TypedVector*) malloc(sizeof(TypedVector)); this = (Vector*) malloc(sizeof(Vector));
this->growthRate = size; this->growthRate = size;
this->array = (Object**) calloc(size, sizeof(Object*)); this->array = (Object**) calloc(size, sizeof(Object*));
this->arraySize = size; this->arraySize = size;
@ -48,7 +48,7 @@ TypedVector* TypedVector_new(char* vectorType_, bool owner, int size) {
return this; return this;
} }
void TypedVector_delete(TypedVector* this) { void Vector_delete(Vector* this) {
if (this->owner) { if (this->owner) {
for (int i = 0; i < this->items; i++) for (int i = 0; i < this->items; i++)
if (this->array[i]) if (this->array[i])
@ -59,7 +59,7 @@ void TypedVector_delete(TypedVector* this) {
} }
/* private */ /* private */
bool TypedVector_isConsistent(TypedVector* this) { bool Vector_isConsistent(Vector* this) {
if (this->owner) { if (this->owner) {
for (int i = 0; i < this->items; i++) for (int i = 0; i < this->items; i++)
if (this->array[i] && this->array[i]->class != this->vectorType) if (this->array[i] && this->array[i]->class != this->vectorType)
@ -70,8 +70,8 @@ bool TypedVector_isConsistent(TypedVector* this) {
} }
} }
void TypedVector_prune(TypedVector* this) { void Vector_prune(Vector* this) {
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
int i; int i;
for (i = 0; i < this->items; i++) for (i = 0; i < this->items; i++)
@ -83,8 +83,8 @@ void TypedVector_prune(TypedVector* this) {
this->items = 0; this->items = 0;
} }
void TypedVector_sort(TypedVector* this) { void Vector_sort(Vector* this) {
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
int i, j; int i, j;
for (i = 1; i < this->items; i++) { for (i = 1; i < this->items; i++) {
void* t = this->array[i]; void* t = this->array[i];
@ -92,7 +92,7 @@ void TypedVector_sort(TypedVector* this) {
this->array[j+1] = this->array[j]; this->array[j+1] = this->array[j];
this->array[j+1] = t; this->array[j+1] = t;
} }
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
/* /*
for (int i = 0; i < this->items; i++) { for (int i = 0; i < this->items; i++) {
@ -108,8 +108,8 @@ void TypedVector_sort(TypedVector* this) {
} }
/* private */ /* private */
void TypedVector_checkArraySize(TypedVector* this) { void Vector_checkArraySize(Vector* this) {
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
if (this->items >= this->arraySize) { if (this->items >= this->arraySize) {
int i; int i;
i = this->arraySize; i = this->arraySize;
@ -118,40 +118,40 @@ void TypedVector_checkArraySize(TypedVector* this) {
for (; i < this->arraySize; i++) for (; i < this->arraySize; i++)
this->array[i] = NULL; this->array[i] = NULL;
} }
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
void TypedVector_insert(TypedVector* this, int index, void* data_) { void Vector_insert(Vector* this, int index, void* data_) {
assert(index >= 0); assert(index >= 0);
assert(((Object*)data_)->class == this->vectorType); assert(((Object*)data_)->class == this->vectorType);
Object* data = data_; Object* data = data_;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
TypedVector_checkArraySize(this); Vector_checkArraySize(this);
assert(this->array[this->items] == NULL); assert(this->array[this->items] == NULL);
for (int i = this->items; i >= index; i--) { for (int i = this->items; i >= index; i--) {
this->array[i+1] = this->array[i]; this->array[i+1] = this->array[i];
} }
this->array[index] = data; this->array[index] = data;
this->items++; this->items++;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
Object* TypedVector_take(TypedVector* this, int index) { Object* Vector_take(Vector* this, int index) {
assert(index >= 0 && index < this->items); assert(index >= 0 && index < this->items);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
Object* removed = this->array[index]; Object* removed = this->array[index];
assert (removed != NULL); assert (removed != NULL);
this->items--; this->items--;
for (int i = index; i < this->items; i++) for (int i = index; i < this->items; i++)
this->array[i] = this->array[i+1]; this->array[i] = this->array[i+1];
this->array[this->items] = NULL; this->array[this->items] = NULL;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
return removed; return removed;
} }
Object* TypedVector_remove(TypedVector* this, int index) { Object* Vector_remove(Vector* this, int index) {
Object* removed = TypedVector_take(this, index); Object* removed = Vector_take(this, index);
if (this->owner) { if (this->owner) {
removed->delete(removed); removed->delete(removed);
return NULL; return NULL;
@ -159,9 +159,9 @@ Object* TypedVector_remove(TypedVector* this, int index) {
return removed; return removed;
} }
void TypedVector_moveUp(TypedVector* this, int index) { void Vector_moveUp(Vector* this, int index) {
assert(index >= 0 && index < this->items); assert(index >= 0 && index < this->items);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
if (index == 0) if (index == 0)
return; return;
Object* temp = this->array[index]; Object* temp = this->array[index];
@ -169,9 +169,9 @@ void TypedVector_moveUp(TypedVector* this, int index) {
this->array[index - 1] = temp; this->array[index - 1] = temp;
} }
void TypedVector_moveDown(TypedVector* this, int index) { void Vector_moveDown(Vector* this, int index) {
assert(index >= 0 && index < this->items); assert(index >= 0 && index < this->items);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
if (index == this->items - 1) if (index == this->items - 1)
return; return;
Object* temp = this->array[index]; Object* temp = this->array[index];
@ -179,13 +179,13 @@ void TypedVector_moveDown(TypedVector* this, int index) {
this->array[index + 1] = temp; this->array[index + 1] = temp;
} }
void TypedVector_set(TypedVector* this, int index, void* data_) { void Vector_set(Vector* this, int index, void* data_) {
assert(index >= 0); assert(index >= 0);
assert(((Object*)data_)->class == this->vectorType); assert(((Object*)data_)->class == this->vectorType);
Object* data = data_; Object* data = data_;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
TypedVector_checkArraySize(this); Vector_checkArraySize(this);
if (index >= this->items) { if (index >= this->items) {
this->items = index+1; this->items = index+1;
} else { } else {
@ -198,44 +198,44 @@ void TypedVector_set(TypedVector* this, int index, void* data_) {
} }
} }
this->array[index] = data; this->array[index] = data;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
inline Object* TypedVector_get(TypedVector* this, int index) { inline Object* Vector_get(Vector* this, int index) {
assert(index < this->items); assert(index < this->items);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
return this->array[index]; return this->array[index];
} }
inline int TypedVector_size(TypedVector* this) { inline int Vector_size(Vector* this) {
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
return this->items; return this->items;
} }
void TypedVector_merge(TypedVector* this, TypedVector* v2) { void Vector_merge(Vector* this, Vector* v2) {
int i; int i;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
for (i = 0; i < v2->items; i++) for (i = 0; i < v2->items; i++)
TypedVector_add(this, v2->array[i]); Vector_add(this, v2->array[i]);
v2->items = 0; v2->items = 0;
TypedVector_delete(v2); Vector_delete(v2);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
void TypedVector_add(TypedVector* this, void* data_) { void Vector_add(Vector* this, void* data_) {
assert(data_ && ((Object*)data_)->class == this->vectorType); assert(data_ && ((Object*)data_)->class == this->vectorType);
Object* data = data_; Object* data = data_;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
TypedVector_set(this, this->items, data); Vector_set(this, this->items, data);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
inline int TypedVector_indexOf(TypedVector* this, void* search_) { inline int Vector_indexOf(Vector* this, void* search_) {
assert(((Object*)search_)->class == this->vectorType); assert(((Object*)search_)->class == this->vectorType);
Object* search = search_; Object* search = search_;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
int i; int i;
@ -247,11 +247,11 @@ inline int TypedVector_indexOf(TypedVector* this, void* search_) {
return -1; return -1;
} }
void TypedVector_foreach(TypedVector* this, TypedVector_procedure f) { void Vector_foreach(Vector* this, Vector_procedure f) {
int i; int i;
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
for (i = 0; i < this->items; i++) for (i = 0; i < this->items; i++)
f(this->array[i]); f(this->array[i]);
assert(TypedVector_isConsistent(this)); assert(Vector_isConsistent(this));
} }

69
Vector.h Normal file
View File

@ -0,0 +1,69 @@
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_Vector
#define HEADER_Vector
/*
htop
(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Object.h"
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "debug.h"
#include <assert.h>
#ifndef DEFAULT_SIZE
#define DEFAULT_SIZE -1
#endif
typedef void(*Vector_procedure)(void*);
typedef struct Vector_ {
Object **array;
int arraySize;
int growthRate;
int items;
char* vectorType;
bool owner;
} Vector;
Vector* Vector_new(char* vectorType_, bool owner, int size);
void Vector_delete(Vector* this);
void Vector_prune(Vector* this);
void Vector_sort(Vector* this);
void Vector_insert(Vector* this, int index, void* data_);
Object* Vector_take(Vector* this, int index);
Object* Vector_remove(Vector* this, int index);
void Vector_moveUp(Vector* this, int index);
void Vector_moveDown(Vector* this, int index);
void Vector_set(Vector* this, int index, void* data_);
inline Object* Vector_get(Vector* this, int index);
inline int Vector_size(Vector* this);
void Vector_merge(Vector* this, Vector* v2);
void Vector_add(Vector* this, void* data_);
inline int Vector_indexOf(Vector* this, void* search_);
void Vector_foreach(Vector* this, Vector_procedure f);
#endif

2
htop.c
View File

@ -512,7 +512,7 @@ int main(int argc, char** argv) {
ListBox* lbu = ListBox_new(0, 0, 0, 0, LISTITEM_CLASS, true); ListBox* lbu = ListBox_new(0, 0, 0, 0, LISTITEM_CLASS, true);
ListBox_setHeader(lbu, "Show processes of:"); ListBox_setHeader(lbu, "Show processes of:");
UsersTable_foreach(ut, addUserToList, lbu); UsersTable_foreach(ut, addUserToList, lbu);
TypedVector_sort(lbu->items); Vector_sort(lbu->items);
ListItem* allUsers = ListItem_new("All users", -1); ListItem* allUsers = ListItem_new("All users", -1);
ListBox_insert(lbu, 0, (Object*) allUsers); ListBox_insert(lbu, 0, (Object*) allUsers);
char* fuFunctions[2] = {"Show ", "Cancel "}; char* fuFunctions[2] = {"Show ", "Cancel "};