From 35a96bde514a8897f6f0fcc41c5833bf63df2e2a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:29:01 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- src/util/CMakeLists.txt | 40 + src/util/README | 9 + src/util/const_char_ptr.h | 51 + src/util/copy.h | 49 + src/util/ege-appear-time-tracker.cpp | 163 ++ src/util/ege-appear-time-tracker.h | 90 + src/util/ege-tags.cpp | 171 ++ src/util/ege-tags.h | 122 ++ src/util/enums.h | 134 ++ src/util/expression-evaluator.cpp | 396 +++++ src/util/expression-evaluator.h | 196 +++ src/util/find-if-before.h | 52 + src/util/find-last-if.h | 52 + src/util/fixed_point.h | 112 ++ src/util/format.h | 57 + src/util/forward-pointer-iterator.h | 122 ++ src/util/list-container-test.h | 258 +++ src/util/list-container.h | 353 ++++ src/util/list-copy.h | 46 + src/util/list.h | 413 +++++ src/util/longest-common-suffix.h | 115 ++ src/util/reference.h | 50 + src/util/reverse-list.h | 69 + src/util/share.cpp | 45 + src/util/share.h | 112 ++ src/util/signal-blocker.h | 71 + src/util/ucompose.hpp | 452 +++++ src/util/units.cpp | 578 +++++++ src/util/units.h | 231 +++ src/util/ziptool.cpp | 3039 ++++++++++++++++++++++++++++++++++ src/util/ziptool.h | 575 +++++++ 31 files changed, 8223 insertions(+) create mode 100644 src/util/CMakeLists.txt create mode 100644 src/util/README create mode 100644 src/util/const_char_ptr.h create mode 100644 src/util/copy.h create mode 100644 src/util/ege-appear-time-tracker.cpp create mode 100644 src/util/ege-appear-time-tracker.h create mode 100644 src/util/ege-tags.cpp create mode 100644 src/util/ege-tags.h create mode 100644 src/util/enums.h create mode 100644 src/util/expression-evaluator.cpp create mode 100644 src/util/expression-evaluator.h create mode 100644 src/util/find-if-before.h create mode 100644 src/util/find-last-if.h create mode 100644 src/util/fixed_point.h create mode 100644 src/util/format.h create mode 100644 src/util/forward-pointer-iterator.h create mode 100644 src/util/list-container-test.h create mode 100644 src/util/list-container.h create mode 100644 src/util/list-copy.h create mode 100644 src/util/list.h create mode 100644 src/util/longest-common-suffix.h create mode 100644 src/util/reference.h create mode 100644 src/util/reverse-list.h create mode 100644 src/util/share.cpp create mode 100644 src/util/share.h create mode 100644 src/util/signal-blocker.h create mode 100644 src/util/ucompose.hpp create mode 100644 src/util/units.cpp create mode 100644 src/util/units.h create mode 100644 src/util/ziptool.cpp create mode 100644 src/util/ziptool.h (limited to 'src/util') diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt new file mode 100644 index 0000000..4815590 --- /dev/null +++ b/src/util/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +set(util_SRC + ege-appear-time-tracker.cpp + ege-tags.cpp + expression-evaluator.cpp + share.cpp + units.cpp + ziptool.cpp + + + # ------- + # Headers + const_char_ptr.h + copy.h + ege-appear-time-tracker.h + ege-tags.h + enums.h + expression-evaluator.h + find-if-before.h + find-last-if.h + fixed_point.h + format.h + forward-pointer-iterator.h + list-container-test.h + list-container.h + list-copy.h + list.h + longest-common-suffix.h + reference.h + reverse-list.h + share.h + signal-blocker.h + ucompose.hpp + units.h + ziptool.h +) + +add_inkscape_lib(util_LIB "${util_SRC}") +# add_inkscape_source("${util_SRC}") diff --git a/src/util/README b/src/util/README new file mode 100644 index 0000000..254e3fa --- /dev/null +++ b/src/util/README @@ -0,0 +1,9 @@ + + +This directory contains a variety of utility code. + +To do: + +* Merge with 'helper' into this directory. +* Move individual files to more appropriate directories. +* Split into three sub-directories: numeric, color, svg. diff --git a/src/util/const_char_ptr.h b/src/util/const_char_ptr.h new file mode 100644 index 0000000..872ca67 --- /dev/null +++ b/src/util/const_char_ptr.h @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Provides `const_char_ptr` + */ +/* + * Authors: + * Sergei Izmailov + * + * Copyright (C) 2020 Sergei Izmailov + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ +#ifndef SEEN_INKSCAPE_UTIL_CONST_CHAR_PTR_H +#define SEEN_INKSCAPE_UTIL_CONST_CHAR_PTR_H +#include +#include +#include "share.h" + +namespace Inkscape { +namespace Util { + +/** + * Non-owning reference to 'const char*' + * Main-purpose: avoid overloads of type `f(char*, str&)`, `f(str&, char*)`, `f(char*, char*)`, ... + */ +class const_char_ptr{ +public: + const_char_ptr() noexcept: m_data(nullptr){}; + const_char_ptr(std::nullptr_t): const_char_ptr() {}; + const_char_ptr(const char* const data) noexcept: m_data(data) {}; + const_char_ptr(const Glib::ustring& str) noexcept: const_char_ptr(str.c_str()) {}; + const_char_ptr(const std::string& str) noexcept: const_char_ptr(str.c_str()) {}; + const_char_ptr(const ptr_shared& shared) : const_char_ptr(static_cast(shared)) {}; + + const char * data() const noexcept { return m_data; } +private: + const char * const m_data = nullptr; +}; +} +} +#endif // SEEN_INKSCAPE_UTIL_CONST_CHAR_PTR_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: \ No newline at end of file diff --git a/src/util/copy.h b/src/util/copy.h new file mode 100644 index 0000000..6068132 --- /dev/null +++ b/src/util/copy.h @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Inkscape::Traits::Copy - traits class to determine types to use when copying + * + * Authors: + * MenTaLguY + * + * Copyright (C) 2004 MenTaLguY + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INKSCAPE_TRAITS_COPY_H +#define SEEN_INKSCAPE_TRAITS_COPY_H + +namespace Inkscape { + +namespace Traits { + +template +struct Copy { + typedef T Type; +}; + +template +struct Copy { + typedef T Type; +}; + +template +struct Copy { + typedef T &Type; +}; + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/util/ege-appear-time-tracker.cpp b/src/util/ege-appear-time-tracker.cpp new file mode 100644 index 0000000..d3c0899 --- /dev/null +++ b/src/util/ege-appear-time-tracker.cpp @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Appear Time Tracker. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "ege-appear-time-tracker.h" +#include +#include + + +namespace ege +{ + +namespace { + +void unhookHandler( gulong &id, GtkWidget *obj ) +{ + if ( id ) { + if ( obj ) { + g_signal_handler_disconnect( G_OBJECT(obj), id ); + } + id = 0; + } +} + +} // namespace + + +AppearTimeTracker::AppearTimeTracker(GTimer *timer, GtkWidget *widget, gchar const* name) : + _name(name ? name : ""), + _timer(timer), + _widget(widget), + _topMost(widget), + _autodelete(false), + _mapId(0), + _realizeId(0), + _hierarchyId(0) + +{ + while (gtk_widget_get_parent(_topMost)) { + _topMost = gtk_widget_get_parent(_topMost); + } + _mapId = g_signal_connect( G_OBJECT(_topMost), "map-event", G_CALLBACK(mapCB), this ); + _realizeId = g_signal_connect( G_OBJECT(_topMost), "realize", G_CALLBACK(realizeCB), this ); + _hierarchyId = g_signal_connect( G_OBJECT(_widget), "hierarchy-changed", G_CALLBACK(hierarchyCB), this ); +} + +AppearTimeTracker::~AppearTimeTracker() +{ + if ( _timer ) { + g_timer_destroy(_timer); + _timer = nullptr; + } + + unhookHandler( _mapId, _topMost ); + unhookHandler( _realizeId, _topMost ); + unhookHandler( _hierarchyId, _widget ); +} + +void AppearTimeTracker::stop() { + if (_timer) { + g_timer_stop(_timer); + } +} + +void AppearTimeTracker::setAutodelete(bool autodelete) +{ + if ( autodelete != _autodelete ) { + _autodelete = autodelete; + } +} + +void AppearTimeTracker::report(gchar const* msg) +{ + gulong msCount = 0; + gdouble secs = g_timer_elapsed( _timer, &msCount ); + g_message("Time ended at %2.3f with [%s] on [%s]", secs, msg, _name.c_str()); +} + +void AppearTimeTracker::handleHierarchyChange( GtkWidget * /*prevTop*/ ) +{ + GtkWidget *newTop = _widget; + while (gtk_widget_get_parent(newTop)) { + newTop = gtk_widget_get_parent(newTop); + } + + if ( newTop != _topMost ) { + unhookHandler( _mapId, _topMost ); + unhookHandler( _realizeId, _topMost ); + + _topMost = newTop; + _mapId = g_signal_connect( G_OBJECT(_topMost), "map-event", G_CALLBACK(mapCB), this ); + _realizeId = g_signal_connect( G_OBJECT(_topMost), "realize", G_CALLBACK(realizeCB), this ); + } +} + +gboolean AppearTimeTracker::mapCB(GtkWidget * /*widget*/, GdkEvent * /*event*/, gpointer userData) +{ + AppearTimeTracker *tracker = reinterpret_cast(userData); + tracker->report("MAP"); + if ( tracker->_autodelete ) { + delete tracker; + } + return FALSE; +} + +void AppearTimeTracker::realizeCB(GtkWidget * /*widget*/, gpointer userData) +{ + AppearTimeTracker *tracker = reinterpret_cast(userData); + tracker->report("REALIZE"); +} + +void AppearTimeTracker::hierarchyCB(GtkWidget * /*widget*/, GtkWidget *prevTop, gpointer userData) +{ + AppearTimeTracker *tracker = reinterpret_cast(userData); + tracker->handleHierarchyChange( prevTop ); +} + +} // namespace ege + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/util/ege-appear-time-tracker.h b/src/util/ege-appear-time-tracker.h new file mode 100644 index 0000000..4318e62 --- /dev/null +++ b/src/util/ege-appear-time-tracker.h @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later +#ifndef SEEN_APPEAR_TIME_TRACKER_H +#define SEEN_APPEAR_TIME_TRACKER_H + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Appear Time Tracker. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include +#include + +typedef union _GdkEvent GdkEvent; +typedef struct _GtkWidget GtkWidget; + +namespace ege +{ + +class AppearTimeTracker { +public: + AppearTimeTracker(GTimer *timer, GtkWidget *widget, gchar const* name); + ~AppearTimeTracker(); + + void stop(); + + bool isAutodelete() const { return _autodelete; } + void setAutodelete(bool autodelete); + +private: + Glib::ustring _name; + GTimer *_timer; + GtkWidget *_widget; + GtkWidget *_topMost; + bool _autodelete; + gulong _mapId; + gulong _realizeId; + gulong _hierarchyId; + + static gboolean mapCB(GtkWidget *widget, GdkEvent *event, gpointer userData); + static void realizeCB(GtkWidget *widget, gpointer userData); + static void hierarchyCB(GtkWidget *widget, GtkWidget *prevTop, gpointer userData); + + void report(gchar const* msg); + void handleHierarchyChange( GtkWidget *prevTop ); +}; + +} // namespace ege + +#endif // SEEN_APPEAR_TIME_TRACKER_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/util/ege-tags.cpp b/src/util/ege-tags.cpp new file mode 100644 index 0000000..f8acab8 --- /dev/null +++ b/src/util/ege-tags.cpp @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is EGE Tagging Support. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include + +#if !defined(_) +#define _(s) gettext(s) +#endif // !defined(_) + +#include +#include +#include +#include + +#include "ege-tags.h" + +#include + +namespace ege +{ + +Label::Label(std::string lang, std::string value) : + lang(std::move(lang)), + value(std::move(value)) +{ +} + +Label::~Label() += default; + +// ========================================================================= + +Tag::~Tag() += default; + +Tag::Tag(std::string key) : + key(std::move(key)) +{ +} + +// ========================================================================= + +TagSet::TagSet() : + lang(), + tags(), + counts() +{ +} + +TagSet::~TagSet() += default; + +void TagSet::setLang(std::string const& lang) +{ + if (lang != this->lang) { + this->lang = lang; + } +} + + +struct sameLang : public std::binary_function { + bool operator()(Label const& x, Label const& y) const { return (x.lang == y.lang); } +}; + + +bool TagSet::addTag(Tag const& tag) +{ + bool present = false; + + for ( std::vector::iterator it = tags.begin(); (it != tags.end()) && !present; ++it ) { + if (tag.key == it->key) { + present = true; + + for (const auto & label : tag.labels) { + std::vector