lib: convert threader/container to c++
Did change the code much, but it's now compiled as c++
This commit is contained in:
@ -63,8 +63,8 @@ libmu_la_SOURCES= \
|
||||
mu-bookmarks.h \
|
||||
mu-contacts.cc \
|
||||
mu-contacts.hh \
|
||||
mu-container.c \
|
||||
mu-container.h \
|
||||
mu-container.cc \
|
||||
mu-container.hh \
|
||||
mu-data.hh \
|
||||
mu-flags.c \
|
||||
mu-flags.h \
|
||||
@ -100,8 +100,8 @@ libmu_la_SOURCES= \
|
||||
mu-server.hh \
|
||||
mu-store.cc \
|
||||
mu-store.hh \
|
||||
mu-threader.c \
|
||||
mu-threader.h \
|
||||
mu-threader.cc \
|
||||
mu-threader.hh \
|
||||
mu-tokenizer.cc \
|
||||
mu-tokenizer.hh \
|
||||
mu-tree.hh \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2011-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -16,11 +16,11 @@
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
#include "mu-container.hh"
|
||||
|
||||
#include <string.h> /* for memset */
|
||||
#include <math.h> /* for log, ceil */
|
||||
|
||||
#include "mu-container.h"
|
||||
#include "mu-msg.h"
|
||||
#include "mu-msg-iter.h"
|
||||
|
||||
@ -323,7 +323,7 @@ mu_container_from_list (GSList *lst)
|
||||
if (!lst)
|
||||
return NULL;
|
||||
|
||||
tail = list_last_data (lst);
|
||||
tail = (MuContainer*)list_last_data (lst);
|
||||
for (c = cur = (MuContainer*)lst->data; cur; lst = g_slist_next(lst)) {
|
||||
cur->next = lst ? (MuContainer*)lst->data : NULL;
|
||||
cur->last = tail;
|
||||
@ -545,7 +545,11 @@ path_to_string (Path *p, const char* frmt)
|
||||
for (u = 0, str = NULL; p->_data[u] != 0; ++u) {
|
||||
|
||||
char segm[16];
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
g_snprintf (segm, sizeof(segm), frmt, p->_data[u] - 1);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
if (!str)
|
||||
str = g_strdup (segm);
|
||||
@ -17,50 +17,47 @@
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_CONTAINER_H__
|
||||
#define __MU_CONTAINER_H__
|
||||
#ifndef MU_CONTAINER_HH__
|
||||
#define MU_CONTAINER_HH__
|
||||
|
||||
#include <glib.h>
|
||||
#include <mu-msg.h>
|
||||
#include <utils/mu-utils.hh>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
enum _MuContainerFlag {
|
||||
enum MuContainerFlag {
|
||||
MU_CONTAINER_FLAG_NONE = 0,
|
||||
MU_CONTAINER_FLAG_DELETE = 1 << 0,
|
||||
MU_CONTAINER_FLAG_SPLICE = 1 << 1,
|
||||
MU_CONTAINER_FLAG_DUP = 1 << 2
|
||||
};
|
||||
typedef enum _MuContainerFlag MuContainerFlag;
|
||||
MU_ENABLE_BITOPS(MuContainerFlag);
|
||||
|
||||
/*
|
||||
* MuContainer data structure, as seen in JWZs document:
|
||||
* http://www.jwz.org/doc/threading.html
|
||||
*/
|
||||
struct _MuContainer {
|
||||
struct _MuContainer *parent, *child, *next;
|
||||
struct MuContainer {
|
||||
struct MuContainer *parent, *child, *next;
|
||||
|
||||
/* note: we cache the last of the string of next->next->...
|
||||
* `mu_container_append_siblings' shows up high in the
|
||||
* profiles since it needs to walk to the end, and this give
|
||||
* O(n*n) behavior.
|
||||
* */
|
||||
struct _MuContainer *last;
|
||||
struct MuContainer *last;
|
||||
|
||||
/* Node in the subtree rooted at this node which comes first
|
||||
* in the descending sort order, e.g. the latest message if
|
||||
* sorting by date. We compare the leaders when ordering
|
||||
* subtrees. */
|
||||
struct _MuContainer *leader;
|
||||
struct MuContainer *leader;
|
||||
|
||||
MuMsg *msg;
|
||||
const char *msgid;
|
||||
|
||||
unsigned docid;
|
||||
MuContainerFlag flags;
|
||||
|
||||
};
|
||||
typedef struct _MuContainer MuContainer;
|
||||
|
||||
|
||||
/**
|
||||
@ -223,6 +220,4 @@ MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid,
|
||||
GHashTable* mu_container_thread_info_hash_new (MuContainer *root_set,
|
||||
size_t matchnum);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_CONTAINER_H__*/
|
||||
#endif /*MU_CONTAINER_HH__*/
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include "mu-msg.h"
|
||||
#include "mu-msg-iter.h"
|
||||
#include "mu-threader.h"
|
||||
#include "mu-threader.hh"
|
||||
|
||||
struct ltstr {
|
||||
bool operator () (const std::string &s1,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
/*
|
||||
** Copyright (C) 2012-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -17,11 +16,12 @@
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
#include "mu-threader.hh"
|
||||
|
||||
#include <math.h> /* for log, ceil */
|
||||
#include <string.h> /* for memset */
|
||||
|
||||
#include "mu-threader.h"
|
||||
#include "mu-container.h"
|
||||
#include "mu-container.hh"
|
||||
#include "utils/mu-str.h"
|
||||
|
||||
/* msg threading implementation based on JWZ's algorithm, as described in:
|
||||
@ -137,7 +137,7 @@ find_or_create_referred (GHashTable *id_table, const char *msgid,
|
||||
|
||||
g_return_val_if_fail (msgid, NULL);
|
||||
|
||||
c = g_hash_table_lookup (id_table, msgid);
|
||||
c = (MuContainer*)g_hash_table_lookup (id_table, msgid);
|
||||
*created = !c;
|
||||
if (!c) {
|
||||
c = mu_container_new (NULL, 0, msgid);
|
||||
@ -172,7 +172,7 @@ find_or_create (GHashTable *id_table, MuMsg *msg, guint docid)
|
||||
|
||||
/* XXX the '<none>' works around a crash; find a better
|
||||
* solution */
|
||||
c = g_hash_table_lookup (id_table, msgid);
|
||||
c = (MuContainer*)g_hash_table_lookup (id_table, msgid);
|
||||
|
||||
/* If id_table contains an empty MuContainer for this ID: * *
|
||||
* Store this message in the MuContainer's message slot. */
|
||||
@ -1,7 +1,5 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
|
||||
/*
|
||||
** Copyright (C) 2012-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -19,14 +17,12 @@
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_THREADER_H__
|
||||
#define __MU_THREADER_H__
|
||||
#ifndef MU_THREADER_HH__
|
||||
#define MU_THREADER_HH__
|
||||
|
||||
#include <glib.h>
|
||||
#include <mu-msg-iter.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* takes an iter and the total number of matches, and from this
|
||||
* generates a hash-table with information about the thread structure
|
||||
@ -50,7 +46,4 @@ G_BEGIN_DECLS
|
||||
GHashTable *mu_threader_calculate (MuMsgIter *iter, size_t matches,
|
||||
MuMsgFieldId sortfield, gboolean revert);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_THREADER_H__*/
|
||||
#endif /*MU_THREADER_HH__*/
|
||||
@ -1,5 +1,3 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
|
||||
/*
|
||||
** Copyright (C) 2014 Jakub Sitnicki <jsitnicki@gmail.com>
|
||||
**
|
||||
@ -19,14 +17,11 @@
|
||||
**
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "test-mu-common.hh"
|
||||
#include "mu-container.h"
|
||||
#include "mu-container.hh"
|
||||
|
||||
static gboolean
|
||||
container_has_children (const MuContainer *c)
|
||||
|
||||
@ -197,15 +197,15 @@ copy_test_data (void)
|
||||
gchar *dir, *cmd;
|
||||
|
||||
dir = test_mu_common_get_random_tmpdir();
|
||||
cmd = g_strdup_printf ("mkdir -m 0700 %s", dir);
|
||||
cmd = g_strdup_printf ("mkdir -p -m 0700 %s", dir);
|
||||
if (g_test_verbose())
|
||||
g_print ("cmd: %s\n", cmd);
|
||||
g_debug ("cmd: %s\n", cmd);
|
||||
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
||||
g_free (cmd);
|
||||
|
||||
cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir);
|
||||
if (g_test_verbose())
|
||||
g_print ("cmd: %s\n", cmd);
|
||||
g_debug ("cmd: %s\n", cmd);
|
||||
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
||||
g_free (cmd);
|
||||
|
||||
@ -228,7 +228,7 @@ dir_cb (const char *fullpath, gboolean enter, WalkData *data)
|
||||
++data->_dir_left;
|
||||
|
||||
if (g_test_verbose())
|
||||
g_print ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving",
|
||||
g_debug ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving",
|
||||
fullpath, enter ? data->_dir_entered : data->_dir_left);
|
||||
|
||||
return MU_OK;
|
||||
|
||||
@ -49,8 +49,6 @@ static bool
|
||||
call (const Command::CommandMap& cmap, const std::string& str) try
|
||||
{
|
||||
const auto sexp{Sexp::make_parse(str)};
|
||||
g_message ("invoking %s", to_string(sexp).c_str());
|
||||
|
||||
invoke (cmap, sexp);
|
||||
|
||||
return true;
|
||||
@ -75,8 +73,6 @@ test_command()
|
||||
"My command,",
|
||||
{}});
|
||||
|
||||
std::cout << "****** " << cmap << "\n";
|
||||
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\")"));
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)"));
|
||||
|
||||
@ -127,6 +123,8 @@ test_command_fail()
|
||||
}
|
||||
|
||||
|
||||
static void black_hole() {}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[]) try
|
||||
{
|
||||
@ -137,6 +135,12 @@ main (int argc, char *argv[]) try
|
||||
g_test_add_func ("/utils/command-parser/command2", test_command2);
|
||||
g_test_add_func ("/utils/command-parser/command-fail", test_command_fail);
|
||||
|
||||
g_log_set_handler (NULL,
|
||||
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
|
||||
G_LOG_FLAG_RECURSION),
|
||||
(GLogFunc)black_hole, NULL);
|
||||
|
||||
|
||||
return g_test_run ();
|
||||
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
#include "utils/mu-date.h"
|
||||
|
||||
#include "mu-cmd.hh"
|
||||
#include "mu-threader.h"
|
||||
#include "mu-threader.hh"
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user