mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:23:23 +00:00
core: remove membufferpp
This the C++ version of membuffer. Since everything is C++, it can just be made the default. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
db4b972897
commit
ead58cd039
13 changed files with 40 additions and 53 deletions
|
@ -90,7 +90,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
|
|||
int i;
|
||||
bool need_pagebreak = false;
|
||||
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
if (plain) {
|
||||
ssrf = "";
|
||||
|
@ -280,7 +280,7 @@ void export_depths(const char *filename, bool selected_only)
|
|||
int i;
|
||||
const char *unit = NULL;
|
||||
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
for_each_dive (i, dive) {
|
||||
if (selected_only && !dive->selected)
|
||||
|
|
|
@ -20,7 +20,7 @@ int verbose;
|
|||
|
||||
void report_info(const char *fmt, ...)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
VA_BUF(&buf, fmt);
|
||||
strip_mb(&buf);
|
||||
|
@ -31,7 +31,7 @@ static void (*error_cb)(char *) = NULL;
|
|||
|
||||
int report_error(const char *fmt, ...)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
VA_BUF(&buf, fmt);
|
||||
strip_mb(&buf);
|
||||
|
|
|
@ -346,7 +346,7 @@ static int try_to_git_merge(struct git_info *info, git_reference **local_p, git_
|
|||
git_commit *local_commit, *remote_commit, *base_commit;
|
||||
git_index *merged_index;
|
||||
git_merge_options merge_options;
|
||||
struct membufferpp msg;
|
||||
membuffer msg;
|
||||
|
||||
if (verbose) {
|
||||
char outlocal[41], outremote[41];
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
#include "units.h"
|
||||
#include "membuffer.h"
|
||||
|
||||
membufferpp::membufferpp()
|
||||
: membuffer{0, 0, nullptr}
|
||||
membuffer::membuffer()
|
||||
{
|
||||
}
|
||||
|
||||
membufferpp::~membufferpp()
|
||||
membuffer::~membuffer()
|
||||
{
|
||||
free_buffer(this);
|
||||
}
|
||||
|
@ -144,7 +143,7 @@ void put_vformat(struct membuffer *b, const char *fmt, va_list args)
|
|||
/* Silly helper using membuffer */
|
||||
char *vformat_string(const char *fmt, va_list args)
|
||||
{
|
||||
struct membuffer mb = { 0 };
|
||||
struct membuffer mb;
|
||||
put_vformat(&mb, fmt, args);
|
||||
return detach_cstring(&mb);
|
||||
}
|
||||
|
@ -300,7 +299,7 @@ void put_quoted(struct membuffer *b, const char *text, int is_attribute, int is_
|
|||
char *add_to_string_va(char *old, const char *fmt, va_list args)
|
||||
{
|
||||
char *res;
|
||||
struct membufferpp o, n;
|
||||
membuffer o, n;
|
||||
put_vformat(&n, fmt, args);
|
||||
put_format(&o, "%s\n%s", old ?: "", mb_cstring(&n));
|
||||
res = strdup(mb_cstring(&o));
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
* 'membuffer' functions will manage memory allocation avoiding performance
|
||||
* issues related to superfluous re-allocation. See 'make_room' function
|
||||
*
|
||||
* Before using it membuffer struct should be properly initialized
|
||||
*
|
||||
* struct membuffer mb = { 0 };
|
||||
*
|
||||
* Internal membuffer buffer will not by default contain null terminator,
|
||||
* adding it should be done using 'mb_cstring' function
|
||||
*
|
||||
|
@ -28,10 +24,6 @@
|
|||
* ptr = detach_cstring();
|
||||
*
|
||||
* where the caller now has a C string and is supposed to free it.
|
||||
*
|
||||
* Otherwise allocated memory should be freed
|
||||
*
|
||||
* free_buffer(&mb);
|
||||
*/
|
||||
#ifndef MEMBUFFER_H
|
||||
#define MEMBUFFER_H
|
||||
|
@ -42,14 +34,10 @@
|
|||
#include "units.h"
|
||||
|
||||
struct membuffer {
|
||||
unsigned int len, alloc;
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
// In C++ code use this - it automatically frees the buffer, when going out of scope.
|
||||
struct membufferpp : public membuffer {
|
||||
membufferpp();
|
||||
~membufferpp();
|
||||
unsigned int len = 0, alloc = 0;
|
||||
char *buffer = nullptr;
|
||||
membuffer();
|
||||
~membuffer();
|
||||
};
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
|
|
@ -512,7 +512,7 @@ struct dir {
|
|||
static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, git_filemode_t mode)
|
||||
{
|
||||
int ret;
|
||||
membufferpp uniquename;
|
||||
membuffer uniquename;
|
||||
|
||||
if (mkunique && git_treebuilder_get(dir, name)) {
|
||||
char hex[8];
|
||||
|
@ -559,7 +559,7 @@ static struct dir *new_directory(git_repository *repo, struct dir *parent, struc
|
|||
|
||||
static struct dir *mktree(git_repository *repo, struct dir *dir, const char *fmt, ...)
|
||||
{
|
||||
membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
VA_BUF(&buf, fmt);
|
||||
for (auto &subdir: dir->subdirs) {
|
||||
|
@ -609,7 +609,7 @@ static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer
|
|||
{
|
||||
int ret;
|
||||
git_oid blob_id;
|
||||
struct membufferpp name;
|
||||
membuffer name;
|
||||
|
||||
ret = git_blob_create_frombuffer(&blob_id, repo, b->buffer, b->len);
|
||||
if (ret)
|
||||
|
@ -623,7 +623,7 @@ static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer
|
|||
static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct dive *dive, struct divecomputer *dc, int idx)
|
||||
{
|
||||
int ret;
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
save_dc(&buf, dive, dc);
|
||||
ret = blob_insert(repo, tree, &buf, "Divecomputer%c%03u", idx ? '-' : 0, idx);
|
||||
|
@ -635,7 +635,7 @@ static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct
|
|||
static int save_one_picture(git_repository *repo, struct dir *dir, struct picture *pic)
|
||||
{
|
||||
int offset = pic->offset.seconds;
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
char sign = '+';
|
||||
unsigned h;
|
||||
|
||||
|
@ -669,7 +669,7 @@ static int save_pictures(git_repository *repo, struct dir *dir, struct dive *div
|
|||
static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *dive, struct tm *tm, bool cached_ok)
|
||||
{
|
||||
struct divecomputer *dc;
|
||||
struct membufferpp buf, name;
|
||||
membuffer buf, name;
|
||||
struct dir *subdir;
|
||||
int ret, nr;
|
||||
|
||||
|
@ -769,7 +769,7 @@ static int save_trip_description(git_repository *repo, struct dir *dir, dive_tri
|
|||
{
|
||||
int ret;
|
||||
git_oid blob_id;
|
||||
struct membufferpp desc;
|
||||
membuffer desc;
|
||||
|
||||
put_format(&desc, "date %04u-%02u-%02u\n",
|
||||
tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
|
||||
|
@ -809,7 +809,7 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip_t *tr
|
|||
int i;
|
||||
struct dive *dive;
|
||||
struct dir *subdir;
|
||||
struct membufferpp name;
|
||||
membuffer name;
|
||||
timestamp_t first, last;
|
||||
|
||||
/* Create trip directory */
|
||||
|
@ -890,7 +890,7 @@ static void save_one_fingerprint(struct membuffer *b, int i)
|
|||
|
||||
static void save_settings(git_repository *repo, struct dir *tree)
|
||||
{
|
||||
struct membufferpp b;
|
||||
membuffer b;
|
||||
|
||||
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
|
||||
for (int i = 0; i < nr_devices(divelog.devices); i++)
|
||||
|
@ -918,15 +918,15 @@ static void save_settings(git_repository *repo, struct dir *tree)
|
|||
static void save_divesites(git_repository *repo, struct dir *tree)
|
||||
{
|
||||
struct dir *subdir;
|
||||
struct membufferpp dirname;
|
||||
membuffer dirname;
|
||||
put_format(&dirname, "01-Divesites");
|
||||
subdir = new_directory(repo, tree, &dirname);
|
||||
|
||||
purge_empty_dive_sites(divelog.sites);
|
||||
for (int i = 0; i < divelog.sites->nr; i++) {
|
||||
struct membufferpp b;
|
||||
membuffer b;
|
||||
struct dive_site *ds = get_dive_site(i, divelog.sites);
|
||||
struct membufferpp site_file_name;
|
||||
membuffer site_file_name;
|
||||
put_format(&site_file_name, "Site-%08x", ds->uuid);
|
||||
show_utf8(&b, "name ", ds->name.c_str(), "\n");
|
||||
show_utf8(&b, "description ", ds->description.c_str(), "\n");
|
||||
|
@ -997,15 +997,15 @@ static void format_one_filter_preset(int preset_id, struct membuffer *b)
|
|||
|
||||
static void save_filter_presets(git_repository *repo, struct dir *tree)
|
||||
{
|
||||
struct membufferpp dirname;
|
||||
membuffer dirname;
|
||||
struct dir *filter_dir;
|
||||
put_format(&dirname, "02-Filterpresets");
|
||||
filter_dir = new_directory(repo, tree, &dirname);
|
||||
|
||||
for (int i = 0; i < filter_presets_count(); i++)
|
||||
{
|
||||
membufferpp preset_name;
|
||||
membufferpp preset_buffer;
|
||||
membuffer preset_name;
|
||||
membuffer preset_buffer;
|
||||
|
||||
put_format(&preset_name, "Preset-%03d", i);
|
||||
format_one_filter_preset(i, &preset_buffer);
|
||||
|
@ -1221,7 +1221,7 @@ static int create_new_commit(struct git_info *info, git_oid *tree_id, bool creat
|
|||
/* Else we do want to create the new branch, but with the old commit */
|
||||
commit = (git_commit *) parent;
|
||||
} else {
|
||||
struct membufferpp commit_msg;
|
||||
membuffer commit_msg;
|
||||
|
||||
create_commit_message(&commit_msg, create_empty);
|
||||
if (git_commit_create_v(&commit_id, info->repo, NULL, author, author, NULL, mb_cstring(&commit_msg), tree, parent != NULL, parent)) {
|
||||
|
|
|
@ -482,7 +482,7 @@ void export_HTML(const char *file_name, const char *photos_dir, const bool selec
|
|||
{
|
||||
FILE *f;
|
||||
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
export_list(&buf, photos_dir, selected_only, list_only);
|
||||
|
||||
f = subsurface_fopen(file_name, "w+");
|
||||
|
@ -498,7 +498,7 @@ void export_translation(const char *file_name)
|
|||
{
|
||||
FILE *f;
|
||||
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
//export translated words here
|
||||
put_format(&buf, "translate={");
|
||||
|
|
|
@ -239,7 +239,7 @@ void save_subtitles_buffer(struct membuffer *b, struct dive *dive, int offset, i
|
|||
|
||||
int save_profiledata(const char *filename, bool select_only)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
FILE *f;
|
||||
int error = 0;
|
||||
|
||||
|
|
|
@ -558,7 +558,7 @@ void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize)
|
|||
|
||||
int save_dive(FILE *f, struct dive *dive, bool anonymize)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
|
||||
save_one_dive_to_mb(&buf, dive, anonymize);
|
||||
flush_buffer(&buf, f);
|
||||
|
@ -812,7 +812,7 @@ static void try_to_backup(const char *filename)
|
|||
|
||||
int save_dives_logic(const char *filename, const bool select_only, bool anonymize)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
struct git_info info;
|
||||
FILE *f;
|
||||
int error = 0;
|
||||
|
@ -854,7 +854,7 @@ int export_dives_xslt(const char *filename, const bool selected, const int units
|
|||
static int export_dives_xslt_doit(const char *filename, struct xml_params *params, bool selected, int units, const char *export_xslt, bool anonymize)
|
||||
{
|
||||
FILE *f;
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
xmlDoc *doc;
|
||||
xsltStylesheetPtr xslt = NULL;
|
||||
xmlDoc *transformed;
|
||||
|
@ -933,7 +933,7 @@ static void save_dive_sites_buffer(struct membuffer *b, const struct dive_site *
|
|||
|
||||
int save_dive_sites_logic(const char *filename, const struct dive_site *sites[], int nr_sites, bool anonymize)
|
||||
{
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
FILE *f;
|
||||
int error = 0;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
|
|||
char *membuf;
|
||||
xmlDoc *transformed;
|
||||
struct zip_source *s;
|
||||
struct membufferpp mb;
|
||||
membuffer mb;
|
||||
struct xml_params *params = alloc_xml_params();
|
||||
|
||||
/*
|
||||
|
|
|
@ -27,7 +27,7 @@ uploadDiveShare::uploadDiveShare():
|
|||
void uploadDiveShare::doUpload(bool selected, const QString &uid, bool noPublic)
|
||||
{
|
||||
//generate json
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
export_list(&buf, NULL, selected, false);
|
||||
QByteArray json_data(buf.buffer, buf.len);
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ void export_worldmap_HTML(const char *file_name, const bool selected_only)
|
|||
{
|
||||
FILE *f;
|
||||
|
||||
struct membufferpp buf;
|
||||
membuffer buf;
|
||||
export_doit(&buf, selected_only);
|
||||
|
||||
f = subsurface_fopen(file_name, "w+");
|
||||
|
|
|
@ -131,7 +131,7 @@ void TabDivePhotos::saveSubtitles()
|
|||
// Only videos have non-zero duration
|
||||
if (!duration)
|
||||
continue;
|
||||
struct membufferpp b;
|
||||
membuffer b;
|
||||
save_subtitles_buffer(&b, parent.currentDive, offset, duration);
|
||||
const char *data = mb_cstring(&b);
|
||||
subtitlefile.open(QIODevice::WriteOnly);
|
||||
|
|
Loading…
Add table
Reference in a new issue