mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: default initialize units-type objects to 0
Makes the code much nicer to read. Default initialize cylinder_t to the empty cylinder. This produces lots of warnings, because most structure are now not PODs anymore and shouldn't be erased using memset(). These memset()s will be removed one-by-one and replaced by proper constructors. The whole ordeal made it necessary to add a constructor to struct event. To simplify things the whole optimization of the variable-size event names was removed. In upcoming commits this will be replaced by std::string anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b82fdd1d20
commit
408b31b6ce
34 changed files with 128 additions and 148 deletions
|
@ -6,6 +6,19 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
event::event() : next(nullptr), type(SAMPLE_EVENT_NONE), flags(0), value(0),
|
||||
divemode(OC), deleted(false), hidden(false)
|
||||
{
|
||||
memset(name, 0, MAX_EVENT_NAME);
|
||||
/* That overwrites divemode. Is this a smart thing to do? */
|
||||
gas.index = -1;
|
||||
gas.mix = gasmix_air;
|
||||
}
|
||||
|
||||
event::~event()
|
||||
{
|
||||
}
|
||||
|
||||
int event_is_gaschange(const struct event *ev)
|
||||
{
|
||||
return ev->type == SAMPLE_EVENT_GASCHANGE ||
|
||||
|
@ -23,11 +36,8 @@ struct event *clone_event(const struct event *src_ev)
|
|||
if (!src_ev)
|
||||
return NULL;
|
||||
|
||||
size_t size = sizeof(*src_ev) + strlen(src_ev->name) + 1;
|
||||
ev = (struct event*) malloc(size);
|
||||
if (!ev)
|
||||
exit(1);
|
||||
memcpy(ev, src_ev, size);
|
||||
ev = new event;
|
||||
*ev = *src_ev;
|
||||
ev->next = NULL;
|
||||
|
||||
return ev;
|
||||
|
@ -37,7 +47,7 @@ void free_events(struct event *ev)
|
|||
{
|
||||
while (ev) {
|
||||
struct event *next = ev->next;
|
||||
free(ev);
|
||||
delete ev;
|
||||
ev = next;
|
||||
}
|
||||
}
|
||||
|
@ -46,14 +56,9 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
|
|||
{
|
||||
int gas_index = -1;
|
||||
struct event *ev;
|
||||
unsigned int size, len = strlen(name);
|
||||
|
||||
size = sizeof(*ev) + len + 1;
|
||||
ev = (struct event*) malloc(size);
|
||||
if (!ev)
|
||||
return NULL;
|
||||
memset(ev, 0, size);
|
||||
memcpy(ev->name, name, len);
|
||||
ev = new event;
|
||||
strncpy(ev->name, name, MAX_EVENT_NAME - 1);
|
||||
ev->time.seconds = time;
|
||||
ev->type = type;
|
||||
ev->flags = flags;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue