Mark Object pointer to _display function const

This commit is contained in:
Christian Göttsche 2020-10-06 12:28:11 +02:00 committed by cgzones
parent e5fdb80c7d
commit 79ad39c718
17 changed files with 44 additions and 45 deletions

View File

@ -44,8 +44,8 @@ static void MaskItem_delete(Object* cast) {
free(this);
}
static void MaskItem_display(Object* cast, RichString* out) {
MaskItem* this = (MaskItem*)cast;
static void MaskItem_display(const Object* cast, RichString* out) {
const MaskItem* this = (const MaskItem*)cast;
assert (this != NULL);
RichString_append(out, CRT_colors[CHECK_BOX], "[");
if (this->value == 2)

View File

@ -66,9 +66,9 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
static void CPUMeter_display(Object* cast, RichString* out) {
static void CPUMeter_display(const Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
const Meter* this = (const Meter*)cast;
RichString_prune(out);
if (this->param > this->pl->cpuCount) {
RichString_append(out, CRT_colors[METER_TEXT], "absent");

View File

@ -21,8 +21,8 @@ static void CheckItem_delete(Object* cast) {
free(this);
}
static void CheckItem_display(Object* cast, RichString* out) {
CheckItem* this = (CheckItem*)cast;
static void CheckItem_display(const Object* cast, RichString* out) {
const CheckItem* this = (const CheckItem*)cast;
assert (this != NULL);
RichString_write(out, CRT_colors[CHECK_BOX], "[");
if (CheckItem_get(this))
@ -61,7 +61,7 @@ void CheckItem_set(CheckItem* this, bool value) {
this->value = value;
}
bool CheckItem_get(CheckItem* this) {
bool CheckItem_get(const CheckItem* this) {
if (this->ref)
return *(this->ref);
else

View File

@ -24,6 +24,6 @@ CheckItem* CheckItem_newByVal(char* text, bool value);
void CheckItem_set(CheckItem* this, bool value);
bool CheckItem_get(CheckItem* this);
bool CheckItem_get(const CheckItem* this);
#endif

View File

@ -59,7 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
}
static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) {
static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
char buffer[16];
int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE;

View File

@ -22,8 +22,8 @@ static void ListItem_delete(Object* cast) {
free(this);
}
static void ListItem_display(Object* cast, RichString* out) {
ListItem* const this = (ListItem*)cast;
static void ListItem_display(const Object* cast, RichString* out) {
const ListItem* const this = (const ListItem*)cast;
assert (this != NULL);
/*
int len = strlen(this->value)+1;

View File

@ -26,8 +26,8 @@ static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
}
static void LoadAverageMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
static void LoadAverageMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
@ -46,8 +46,8 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f", this->values[0]);
}
static void LoadMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
static void LoadMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
RichString_write(out, CRT_colors[LOAD], buffer);

View File

@ -36,9 +36,9 @@ static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
static void MemoryMeter_display(Object* cast, RichString* out) {
static void MemoryMeter_display(const Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
const Meter* this = (const Meter*)cast;
RichString_write(out, CRT_colors[METER_TEXT], ":");
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);

View File

@ -92,7 +92,7 @@ void Meter_setCaption(Meter* this, const char* caption) {
this->caption = xStrdup(caption);
}
static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) {
static inline void Meter_displayBuffer(const Meter* this, const char* buffer, RichString* out) {
if (Object_displayFn(this)) {
Object_display(this, out);
} else {
@ -428,8 +428,7 @@ static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
static void BlankMeter_display(Object* cast, RichString* out) {
(void) cast;
static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
RichString_prune(out);
}

View File

@ -14,16 +14,16 @@ in the source distribution for its full text.
typedef struct Object_ Object;
typedef void(*Object_Display)(Object*, RichString*);
typedef void(*Object_Display)(const Object*, RichString*);
typedef long(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*);
#define Object_getClass(obj_) ((Object*)(obj_))->klass
#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_
#define Object_getClass(obj_) ((const Object*)(obj_))->klass
#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) class_)
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_)
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))

View File

@ -181,9 +181,9 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
}
}
static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) {
static inline void Process_writeCommand(const Process* this, int attr, int baseattr, RichString* str) {
int start = RichString_size(str), finish = 0;
char* comm = this->comm;
const char* comm = this->comm;
if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
int i, basename = 0;
@ -240,7 +240,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
}
}
void Process_writeField(Process* this, RichString* str, ProcessField field) {
void Process_writeField(const Process* this, RichString* str, ProcessField field) {
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int baseattr = CRT_colors[PROCESS_BASENAME];
@ -366,9 +366,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
RichString_append(str, attr, buffer);
}
void Process_display(Object* cast, RichString* out) {
Process* this = (Process*) cast;
ProcessField* fields = this->settings->fields;
void Process_display(const Object* cast, RichString* out) {
const Process* this = (const Process*) cast;
const ProcessField* fields = this->settings->fields;
RichString_prune(out);
for (int i = 0; fields[i]; i++)
As_Process(this)->writeField(this, out, fields[i]);

View File

@ -113,7 +113,7 @@ typedef struct ProcessFieldData_ {
} ProcessFieldData;
// Implemented in platform-specific code:
void Process_writeField(Process* this, RichString* str, ProcessField field);
void Process_writeField(const Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
void Process_delete(Object* cast);
bool Process_isThread(const Process* this);
@ -122,7 +122,7 @@ extern ProcessPidColumn Process_pidColumns[];
extern char Process_pidFormat[20];
typedef Process*(*Process_New)(struct Settings_*);
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
const ObjectClass super;
@ -158,7 +158,7 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths);
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
void Process_display(Object* cast, RichString* out);
void Process_display(const Object* cast, RichString* out);
void Process_done(Process* this);

View File

@ -34,9 +34,9 @@ static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
static void SwapMeter_display(Object* cast, RichString* out) {
static void SwapMeter_display(const Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
const Meter* this = (const Meter*)cast;
RichString_write(out, CRT_colors[METER_TEXT], ":");
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);

View File

@ -33,9 +33,9 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
}
static void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
Settings* settings = this->pl->settings;
static void TasksMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
const Settings* settings = this->pl->settings;
char buffer[20];
int processes = (int) this->values[2];

View File

@ -41,8 +41,8 @@ static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len)
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
}
static void PressureStallMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
static void PressureStallMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);

View File

@ -55,9 +55,9 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
static void ZfsArcMeter_display(Object* cast, RichString* out) {
static void ZfsArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
const Meter* this = (const Meter*)cast;
if (this->values[5] > 0) {
Meter_humanUnit(buffer, this->total, 50);

View File

@ -38,7 +38,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
}
}
static void ZfsCompressedArcMeter_printRatioString(Meter* this, char* buffer, int size) {
static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]);
}
@ -48,9 +48,9 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si
ZfsCompressedArcMeter_printRatioString(this, buffer, size);
}
static void ZfsCompressedArcMeter_display(Object* cast, RichString* out) {
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
const Meter* this = (const Meter*)cast;
if (this->values[0] > 0) {
Meter_humanUnit(buffer, this->total, 50);