summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-04-01 17:00:00 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-04-01 17:00:00 +0000
commit208ccdf9782984702f79b8ba416e67dd1e2c2dfa (patch)
tree79d15123aa526c49c6386db6245fbfc6b7a63eaf /src/util
parentupdate to trunk (diff)
parentpartial 2geom update: (diff)
downloadinkscape-208ccdf9782984702f79b8ba416e67dd1e2c2dfa.tar.gz
inkscape-208ccdf9782984702f79b8ba416e67dd1e2c2dfa.zip
update to trunk
(bzr r12588.1.32)
Diffstat (limited to '')
-rw-r--r--src/util/Makefile_insert2
-rw-r--r--src/util/signal-blocker.h70
-rw-r--r--src/util/units.cpp13
-rw-r--r--src/util/units.h8
-rw-r--r--src/util/unordered-containers.h49
-rw-r--r--src/util/ziptool.cpp (renamed from src/dom/util/ziptool.cpp)0
-rw-r--r--src/util/ziptool.h (renamed from src/dom/util/ziptool.h)0
7 files changed, 106 insertions, 36 deletions
diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert
index 4066ffd5d..7169fa8f7 100644
--- a/src/util/Makefile_insert
+++ b/src/util/Makefile_insert
@@ -1,6 +1,8 @@
## Makefile.am fragment sourced by src/Makefile.am.
ink_common_sources += \
+ util/ziptool.h \
+ util/ziptool.cpp \
util/accumulators.h \
util/compose.hpp \
util/copy.h \
diff --git a/src/util/signal-blocker.h b/src/util/signal-blocker.h
new file mode 100644
index 000000000..06d9736f2
--- /dev/null
+++ b/src/util/signal-blocker.h
@@ -0,0 +1,70 @@
+/*
+ * Base RAII blocker for sgic++ signals.
+ *
+ * Authors:
+ * Jon A. Cruz <jon@joncruz.org>
+ *
+ * Copyright (C) 2014 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_H
+#define SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_H
+
+#include <string>
+#include <sigc++/connection.h>
+
+/**
+ * Base RAII blocker for sgic++ signals.
+ */
+class SignalBlocker
+{
+public:
+ /**
+ * Creates a new instance that if the signal is currently unblocked will block
+ * it until this instance is destructed and then will unblock it.
+ */
+ SignalBlocker( sigc::connection *connection ) :
+ _connection(connection),
+ _wasBlocked(_connection->blocked())
+ {
+ if (!_wasBlocked)
+ {
+ _connection->block();
+ }
+ }
+
+ /**
+ * Destructor that will unblock the signal if it was blocked initially by this
+ * instance.
+ */
+ ~SignalBlocker()
+ {
+ if (!_wasBlocked)
+ {
+ _connection->block(false);
+ }
+ }
+
+private:
+ // noncopyable, nonassignable
+ SignalBlocker(SignalBlocker const &other);
+ SignalBlocker& operator=(SignalBlocker const &other);
+
+ sigc::connection *_connection;
+ bool _wasBlocked;
+};
+
+#endif // SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_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/units.cpp b/src/util/units.cpp
index 40cce028d..d2053f60b 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -505,16 +505,23 @@ double Quantity::convert(double from_dist, char const *from, char const *to)
return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to));
}
-bool Quantity::operator<(Quantity const &other) const
+bool Quantity::operator<(Quantity const &rhs) const
{
- if (unit->type != other.unit->type) {
+ if (unit->type != rhs.unit->type) {
g_warning("Incompatible units");
return false;
}
- return quantity < other.value(unit);
+ return quantity < rhs.value(unit);
}
bool Quantity::operator==(Quantity const &other) const
{
+ /** \fixme This is overly strict. I think we should change this to:
+ if (unit->type != other.unit->type) {
+ g_warning("Incompatible units");
+ return false;
+ }
+ return are_near(quantity, other.value(unit));
+ */
return (*unit == *other.unit) && (quantity == other.quantity);
}
diff --git a/src/util/units.h b/src/util/units.h
index 597371369..efe1dbec7 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -16,6 +16,7 @@
#include <map>
#include <boost/operators.hpp>
#include <glibmm/ustring.h>
+#include <2geom/coord.h>
#include "svg/svg-length.h"
#include "unordered-containers.h"
@@ -112,10 +113,15 @@ public:
static double convert(double from_dist, char const *from, char const *to);
/** Comparison operators. */
- bool operator<(Quantity const &other) const;
+ bool operator<(Quantity const &rhs) const;
bool operator==(Quantity const &other) const;
};
+inline bool are_near(Quantity const &a, Quantity const &b, double eps=Geom::EPSILON)
+{
+ return Geom::are_near(a.quantity, b.value(a.unit), eps);
+}
+
class UnitTable {
public:
/**
diff --git a/src/util/unordered-containers.h b/src/util/unordered-containers.h
index 70d36c4dc..b92f2e7ea 100644
--- a/src/util/unordered-containers.h
+++ b/src/util/unordered-containers.h
@@ -19,8 +19,24 @@
#include <glibmm/ustring.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
-#if defined(HAVE_TR1_UNORDERED_SET)
+#if defined(HAVE_NATIVE_UNORDERED_SET)
+# include <unordered_set>
+# include <unordered_map>
+# define INK_UNORDERED_SET std::unordered_set
+# define INK_UNORDERED_MAP std::unordered_map
+# define INK_HASH std::hash
+
+namespace std {
+template <>
+struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size_t> {
+ std::size_t operator()(Glib::ustring const &s) const {
+ return hash<std::string>()(s.raw());
+ }
+};
+} // namespace std
+
+#elif defined(HAVE_TR1_UNORDERED_SET)
# include <tr1/unordered_set>
# include <tr1/unordered_map>
# define INK_UNORDERED_SET std::tr1::unordered_set
@@ -53,37 +69,6 @@ struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size
}
};
} // namespace boost
-
-#elif defined(HAVE_EXT_HASH_SET)
-
-# include <functional>
-# include <ext/hash_set>
-# include <ext/hash_map>
-# define INK_UNORDERED_SET __gnu_cxx::hash_set
-# define INK_UNORDERED_MAP __gnu_cxx::hash_map
-# define INK_HASH __gnu_cxx::hash
-
-#include <cstddef>
-
-namespace __gnu_cxx {
-// hash function for pointers
-// TR1 and Boost have this defined by default, __gnu_cxx doesn't
-template<typename T>
-struct hash<T *> : public std::unary_function<T *, std::size_t> {
- std::size_t operator()(T *p) const {
- // Taken from Boost
- std::size_t x = static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(p));
- return x + (x >> 3);
- }
-};
-
-template <>
-struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size_t> {
- std::size_t operator()(Glib::ustring const &s) const {
- return hash<std::string>()(s.raw());
- }
-};
-} // namespace __gnu_cxx
#endif
#else
diff --git a/src/dom/util/ziptool.cpp b/src/util/ziptool.cpp
index cf024008f..cf024008f 100644
--- a/src/dom/util/ziptool.cpp
+++ b/src/util/ziptool.cpp
diff --git a/src/dom/util/ziptool.h b/src/util/ziptool.h
index dbae8ac60..dbae8ac60 100644
--- a/src/dom/util/ziptool.h
+++ b/src/util/ziptool.h