core: convert picture.c to C++

The last C-file in core. Yippie.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-04 17:31:04 +02:00 committed by bstoeger
parent 7d3977481a
commit 9065bf8622
6 changed files with 9 additions and 10 deletions

View file

@ -65,7 +65,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/load-git.cpp \ core/load-git.cpp \
core/parse-xml.cpp \ core/parse-xml.cpp \
core/parse.cpp \ core/parse.cpp \
core/picture.c \ core/picture.cpp \
core/pictureobj.cpp \ core/pictureobj.cpp \
core/sample.cpp \ core/sample.cpp \
core/import-suunto.cpp \ core/import-suunto.cpp \

View file

@ -136,7 +136,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
parse-xml.cpp parse-xml.cpp
parse.cpp parse.cpp
parse.h parse.h
picture.c picture.cpp
picture.h picture.h
pictureobj.cpp pictureobj.cpp
pictureobj.h pictureobj.h

View file

@ -1773,7 +1773,7 @@ static int parse_picture_entry(struct git_parser_state *state, const git_tree_en
/* add_picture took ownership of the data - /* add_picture took ownership of the data -
* clear out our copy just to be sure. */ * clear out our copy just to be sure. */
state->active_pic = empty_picture; state->active_pic = picture();
return 0; return 0;
} }

View file

@ -71,7 +71,7 @@ void event_end(struct parser_state *state)
{ {
struct divecomputer *dc = get_dc(state); struct divecomputer *dc = get_dc(state);
if (state->cur_event.type == 123) { if (state->cur_event.type == 123) {
struct picture pic = empty_picture; struct picture pic;
pic.filename = strdup(state->cur_event.name); pic.filename = strdup(state->cur_event.name);
/* theoretically this could fail - but we didn't support multi year offsets */ /* theoretically this could fail - but we didn't support multi year offsets */
pic.offset.seconds = state->cur_event.time.seconds; pic.offset.seconds = state->cur_event.time.seconds;
@ -313,7 +313,7 @@ void picture_end(struct parser_state *state)
{ {
add_picture(&state->cur_dive->pictures, state->cur_picture); add_picture(&state->cur_dive->pictures, state->cur_picture);
/* dive_add_picture took ownership, we can just clear out copy of the data */ /* dive_add_picture took ownership, we can just clear out copy of the data */
state->cur_picture = empty_picture; state->cur_picture = picture();
} }
cylinder_t *cylinder_start(struct parser_state *state) cylinder_t *cylinder_start(struct parser_state *state)

View file

@ -139,7 +139,7 @@ struct picture *create_picture(const char *filename, timestamp_t shift_time, boo
if (!match_all && !dive_check_picture_time(*dive, timestamp)) if (!match_all && !dive_check_picture_time(*dive, timestamp))
return NULL; return NULL;
struct picture *picture = malloc(sizeof(struct picture)); struct picture *picture = (struct picture *)malloc(sizeof(struct picture));
picture->filename = strdup(filename); picture->filename = strdup(filename);
picture->offset.seconds = metadata.timestamp - (*dive)->when + shift_time; picture->offset.seconds = metadata.timestamp - (*dive)->when + shift_time;
picture->location = metadata.location; picture->location = metadata.location;

View file

@ -13,11 +13,10 @@ extern "C" {
struct dive; struct dive;
struct picture { struct picture {
char *filename; char *filename = nullptr;
offset_t offset; offset_t offset = { 0 };
location_t location; location_t location = { { 0 }, { 0 } };
}; };
static const struct picture empty_picture = { NULL, { 0 }, { { 0 }, { 0 } } };
/* loop through all pictures of a dive */ /* loop through all pictures of a dive */
#define FOR_EACH_PICTURE(_dive) \ #define FOR_EACH_PICTURE(_dive) \