summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-03-31 20:41:48 +0000
committerMarkus Engel <markus.engel@tum.de>2013-03-31 20:41:48 +0000
commit2d08d8037d3b7b52fcbd66ef4e65ff432ad2d97d (patch)
tree2be2540bb44c2e18df126e8b0a0f2072a854867b /src
parentTurned all functions concerning SPSpiral into member functions. (diff)
downloadinkscape-2d08d8037d3b7b52fcbd66ef4e65ff432ad2d97d.tar.gz
inkscape-2d08d8037d3b7b52fcbd66ef4e65ff432ad2d97d.zip
Added TypeInfo class.
(bzr r11608.1.62)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_insert1
-rw-r--r--src/type-info.cpp49
-rw-r--r--src/type-info.h31
3 files changed, 81 insertions, 0 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert
index c6955c92a..226364b49 100644
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
@@ -249,6 +249,7 @@ ink_common_sources += \
tools-switch.cpp tools-switch.h \
transf_mat_3x4.cpp transf_mat_3x4.h \
tweak-context.h tweak-context.cpp \
+ type-info.h type-info.cpp \
unclump.cpp unclump.h \
undo-stack-observer.h \
unicoderange.cpp unicoderange.h \
diff --git a/src/type-info.cpp b/src/type-info.cpp
new file mode 100644
index 000000000..dac61e786
--- /dev/null
+++ b/src/type-info.cpp
@@ -0,0 +1,49 @@
+#include "type-info.h"
+
+
+TypeInfo::TypeInfo(const std::type_info& type_info) : type_info(&type_info) {
+}
+
+TypeInfo::TypeInfo(const TypeInfo& tinfo) : type_info(tinfo.type_info) {
+}
+
+TypeInfo& TypeInfo::operator=(const TypeInfo& rhs) {
+ this->type_info = rhs.type_info;
+ return *this;
+}
+
+bool TypeInfo::before(const TypeInfo& tinfo) const {
+ return this->type_info->before(*tinfo.type_info);
+}
+
+const char* TypeInfo::name() const {
+ return this->type_info->name();
+}
+
+const std::type_info& TypeInfo::get() const {
+ return *this->type_info;
+}
+
+bool operator==(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return lhs.get() == rhs.get();
+}
+
+bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return !(lhs == rhs);
+}
+
+bool operator<(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return lhs.before(rhs);
+}
+
+bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return !(lhs > rhs);
+}
+
+bool operator>(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return rhs < lhs;
+}
+
+bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs) {
+ return !(lhs < rhs);
+}
diff --git a/src/type-info.h b/src/type-info.h
new file mode 100644
index 000000000..3340e08e5
--- /dev/null
+++ b/src/type-info.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <typeinfo>
+
+/**
+ * A wrapper around typeinfo. Inspired by Andrei Alexandrescu's "Modern C++ Design".
+ * Used as a temporary replacement for glib's type-checking system as long as SPObject
+ * must not be polymorphic / new objects are instantiated by g_object_new.
+ */
+class TypeInfo {
+public:
+ TypeInfo(const std::type_info& type_info);
+ TypeInfo(const TypeInfo& tinfo);
+
+ TypeInfo& operator=(const TypeInfo& tinfo);
+
+ bool before(const TypeInfo& tinfo) const;
+ const char* name() const;
+
+ const std::type_info& get() const;
+
+private:
+ const std::type_info* type_info;
+};
+
+bool operator==(const TypeInfo& lhs, const TypeInfo& rhs);
+bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs);
+bool operator<(const TypeInfo& lhs, const TypeInfo& rhs);
+bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs);
+bool operator>(const TypeInfo& lhs, const TypeInfo& rhs);
+bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs);