summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-20 21:58:53 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-20 21:58:53 +0000
commit5512f857e2f33f1aa40124dc82b353e5f2e5a0b0 (patch)
tree06e8810178d3d6b4c24a0a7f69c4a327b13a8038 /src
parentmerged from trunk (r12287) (diff)
downloadinkscape-5512f857e2f33f1aa40124dc82b353e5f2e5a0b0.tar.gz
inkscape-5512f857e2f33f1aa40124dc82b353e5f2e5a0b0.zip
Moved factories to different files.
(bzr r11608.1.100)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_insert7
-rw-r--r--src/arc-context.cpp2
-rw-r--r--src/box3d-context.cpp2
-rw-r--r--src/connector-context.cpp2
-rw-r--r--src/desktop.cpp2
-rw-r--r--src/dropper-context.cpp2
-rw-r--r--src/dyna-draw-context.cpp2
-rw-r--r--src/eraser-context.cpp2
-rw-r--r--src/factory.h80
-rw-r--r--src/flood-context.cpp2
-rw-r--r--src/gradient-context.cpp2
-rw-r--r--src/lpe-tool-context.cpp2
-rw-r--r--src/measure-context.cpp2
-rw-r--r--src/mesh-context.cpp2
-rw-r--r--src/pen-context.cpp2
-rw-r--r--src/pencil-context.cpp2
-rw-r--r--src/rect-context.cpp2
-rw-r--r--src/select-context.cpp2
-rw-r--r--src/singleton.h12
-rw-r--r--src/sp-factory.cpp34
-rw-r--r--src/sp-factory.h97
-rw-r--r--src/spiral-context.cpp2
-rw-r--r--src/spray-context.cpp2
-rw-r--r--src/star-context.cpp2
-rw-r--r--src/text-context.cpp2
-rw-r--r--src/tool-factory.h7
-rw-r--r--src/tweak-context.cpp2
-rw-r--r--src/ui/tool/node-tool.cpp2
-rw-r--r--src/zoom-context.cpp2
29 files changed, 129 insertions, 154 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert
index b4b014a34..06e3f2d79 100644
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
@@ -54,6 +54,7 @@ ink_common_sources += \
event-context.cpp event-context.h \
event-log.cpp event-log.h event.h \
extract-uri.cpp extract-uri.h \
+ factory.h \
file.cpp file.h \
fill-or-stroke.h \
filter-chemistry.cpp filter-chemistry.h \
@@ -140,8 +141,9 @@ ink_common_sources += \
seltrans-handles.cpp seltrans-handles.h \
shape-editor.cpp shape-editor.h \
shortcuts.cpp shortcuts.h \
+ singleton.h \
snap.cpp snap.h \
- snap-enums.h snap-candidate.h \
+ snap-enums.h snap-candidate.h \
snapped-curve.cpp snapped-curve.h \
snapped-line.cpp snapped-line.h \
snapped-point.cpp snapped-point.h \
@@ -155,7 +157,7 @@ ink_common_sources += \
sp-defs.cpp sp-defs.h \
sp-desc.cpp sp-desc.h \
sp-ellipse.cpp sp-ellipse.h \
- sp-factory.cpp sp-factory.h \
+ sp-factory.h \
sp-filter.cpp sp-filter.h number-opt-number.h \
sp-filter-primitive.cpp sp-filter-primitive.h \
sp-filter-reference.cpp sp-filter-reference.h \
@@ -240,6 +242,7 @@ ink_common_sources += \
text-context.cpp text-context.h \
text-editing.cpp text-editing.h \
text-tag-attributes.h \
+ tool-factory.h \
tools-switch.cpp tools-switch.h \
transf_mat_3x4.cpp transf_mat_3x4.h \
tweak-context.h tweak-context.cpp \
diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index 3a90ddba3..bb24cba28 100644
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
@@ -54,7 +54,7 @@ static void sp_arc_finish(SPArcContext *ec);
static void sp_arc_cancel(SPArcContext *ec);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createArcContext() {
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index 0e723f7b7..dea91185a 100644
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -57,7 +57,7 @@ static void sp_box3d_drag(Box3DContext &bc, guint state);
static void sp_box3d_finish(Box3DContext *bc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createBox3dContext() {
diff --git a/src/connector-context.cpp b/src/connector-context.cpp
index 1dad3cad9..b7e3942b9 100644
--- a/src/connector-context.cpp
+++ b/src/connector-context.cpp
@@ -164,7 +164,7 @@ static Inkscape::XML::NodeEventVector layer_repr_events = {
};
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createConnectorContext() {
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 9df01b990..493261ea3 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -686,7 +686,7 @@ SPDesktop::change_document (SPDocument *theDocument)
}
-#include "sp-factory.h"
+#include "tool-factory.h"
void SPDesktop::set_event_context2(const std::string& toolName) {
if (event_context) {
diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp
index 4c55400bb..4af1bba2d 100644
--- a/src/dropper-context.cpp
+++ b/src/dropper-context.cpp
@@ -68,7 +68,7 @@ using Inkscape::DocumentUndo;
static GdkCursor *cursor_dropper_fill = NULL;
static GdkCursor *cursor_dropper_stroke = NULL;
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createDropperContext() {
diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp
index 145dc6238..0e9ed570c 100644
--- a/src/dyna-draw-context.cpp
+++ b/src/dyna-draw-context.cpp
@@ -94,7 +94,7 @@ static Geom::Point sp_dyna_draw_get_vpoint(SPDynaDrawContext const *ddc, Geom::P
static void draw_temporary_box(SPDynaDrawContext *dc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createCalligraphicContext() {
diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp
index 7d2abc53f..f256dd8ef 100644
--- a/src/eraser-context.cpp
+++ b/src/eraser-context.cpp
@@ -95,7 +95,7 @@ static Geom::Point sp_eraser_get_npoint(SPEraserContext const *erc, Geom::Point
static Geom::Point sp_eraser_get_vpoint(SPEraserContext const *erc, Geom::Point n);
static void draw_temporary_box(SPEraserContext *dc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createEraserContext() {
diff --git a/src/factory.h b/src/factory.h
new file mode 100644
index 000000000..495db5474
--- /dev/null
+++ b/src/factory.h
@@ -0,0 +1,80 @@
+#pragma once
+
+#include <exception>
+#include <map>
+#include <string>
+
+namespace FactoryExceptions {
+ class TypeNotRegistered : public std::exception {
+ public:
+ TypeNotRegistered(const std::string& typeString) : std::exception(), typeString(typeString) {
+ }
+
+ virtual ~TypeNotRegistered() throw() {
+ }
+
+ const char* what() const throw() {
+ return typeString.c_str();
+ }
+
+ private:
+ const std::string typeString;
+ };
+}
+
+/**
+ * A Factory for creating objects which can be identified by strings.
+ */
+template<class BaseObject>
+class Factory {
+public:
+ typedef BaseObject* CreateFunction();
+
+ bool registerObject(const std::string& id, CreateFunction* createFunction) {
+ return this->objectMap.insert(std::make_pair(id, createFunction)).second;
+ }
+
+ BaseObject* createObject(const std::string& id) const throw(FactoryExceptions::TypeNotRegistered) {
+ typename std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id);
+
+ if (it == this->objectMap.end()) {
+ throw FactoryExceptions::TypeNotRegistered(id);
+ }
+
+ return it->second();
+ }
+
+private:
+ std::map<const std::string, CreateFunction*> objectMap;
+};
+
+
+#include "xml/node.h"
+
+struct NodeTraits {
+ static std::string getTypeString(const Inkscape::XML::Node& node) {
+ std::string name;
+
+ switch (node.type()) {
+ case Inkscape::XML::TEXT_NODE:
+ name = "string";
+ break;
+
+ case Inkscape::XML::ELEMENT_NODE: {
+ gchar const* const sptype = node.attribute("sodipodi:type");
+
+ if (sptype) {
+ name = sptype;
+ } else {
+ name = node.name();
+ }
+ break;
+ }
+ default:
+ name = "";
+ break;
+ }
+
+ return name;
+ }
+};
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index 14cf58501..fccf9c24c 100644
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
@@ -77,7 +77,7 @@ using Inkscape::Display::AssembleARGB32;
static void sp_flood_finish(SPFloodContext *rc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createPaintbucketContext() {
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index a5fe888c1..690d6b5b4 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -54,7 +54,7 @@ using Inkscape::DocumentUndo;
static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint state, guint32 etime);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createGradientContext() {
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index 82190f5a0..e519619f9 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -58,7 +58,7 @@ SubtoolEntry lpesubtools[] = {
};
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createLPEToolContext() {
diff --git a/src/measure-context.cpp b/src/measure-context.cpp
index 1b4d4afe3..2e8a1cd99 100644
--- a/src/measure-context.cpp
+++ b/src/measure-context.cpp
@@ -59,7 +59,7 @@ boost::optional<Geom::Point> lastEnd;
std::vector<Inkscape::Display::TemporaryItem*> measure_tmp_items;
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createMeasureContext() {
diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp
index 73e477a35..a39aa3853 100644
--- a/src/mesh-context.cpp
+++ b/src/mesh-context.cpp
@@ -56,7 +56,7 @@ using Inkscape::DocumentUndo;
static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const pt, guint state, guint32 etime);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createMeshContext() {
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index caaac32db..177aeaca9 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -73,7 +73,7 @@ static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Po
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createPenContext() {
diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index e13e6985c..28ae41974 100644
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
@@ -64,7 +64,7 @@ static bool pencil_within_tolerance = false;
static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; }
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createPencilContext() {
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 382048a3d..b61446b34 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -47,7 +47,7 @@
using Inkscape::DocumentUndo;
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createRectContext() {
diff --git a/src/select-context.cpp b/src/select-context.cpp
index 66b0ebcb1..090f641f3 100644
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
@@ -63,7 +63,7 @@ static gint tolerance = 0;
static bool within_tolerance = false;
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createSelectContext() {
diff --git a/src/singleton.h b/src/singleton.h
new file mode 100644
index 000000000..022e314e4
--- /dev/null
+++ b/src/singleton.h
@@ -0,0 +1,12 @@
+#pragma once
+
+/**
+ * A simple singleton implementation.
+ */
+template<class T>
+struct Singleton {
+ static T& instance() {
+ static T inst;
+ return inst;
+ }
+};
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
deleted file mode 100644
index 27aa6a973..000000000
--- a/src/sp-factory.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "sp-factory.h"
-
-//#include <stdexcept>
-
-//#include "sp-object.h"
-//#include "xml/node.h"
-
-
-//SPFactory::TypeNotRegistered::TypeNotRegistered(const std::string& type)
-// : std::exception(), type(type) {
-//}
-//
-//const char* SPFactory::TypeNotRegistered::what() const throw() {
-// return type.c_str();
-//}
-
-//SPFactory& SPFactory::instance() {
-// static SPFactory factory;
-// return factory;
-//}
-
-//bool SPFactory::registerObject(const std::string& id, CreateFunction* createFunction) {
-// return this->objectMap.insert(std::make_pair(id, createFunction)).second;
-//}
-
-//SPObject* SPFactory::createObject(const std::string& id) const {
-// std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id);
-//
-// if (it == this->objectMap.end()) {
-// throw TypeNotRegistered(id);
-// }
-//
-// return (*it).second();
-//}
diff --git a/src/sp-factory.h b/src/sp-factory.h
index 7eed7b744..50c328aa8 100644
--- a/src/sp-factory.h
+++ b/src/sp-factory.h
@@ -1,100 +1,7 @@
#pragma once
-#include <exception>
-#include <map>
-#include <string>
-
-/**
- * A simple singleton implementation.
- */
-template<class T>
-struct Singleton {
- static T& instance() {
- static T i;
- return i;
- }
-};
-
-
-namespace FactoryExceptions {
- class TypeNotRegistered : public std::exception {
- public:
- TypeNotRegistered(const std::string& typeString) : std::exception(), typeString(typeString) {
- }
-
- virtual ~TypeNotRegistered() throw() {
- }
-
- const char* what() const throw() {
- return typeString.c_str();
- }
-
- private:
- const std::string typeString;
- };
-}
-
-/**
- * A Factory for creating objects which can be identified by strings.
- */
-template<class BaseObject>
-class Factory {
-public:
- typedef BaseObject* CreateFunction();
-
- bool registerObject(const std::string& id, CreateFunction* createFunction) {
- return this->objectMap.insert(std::make_pair(id, createFunction)).second;
- }
-
- BaseObject* createObject(const std::string& id) const throw(FactoryExceptions::TypeNotRegistered) {
- typename std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id);
-
- if (it == this->objectMap.end()) {
- throw FactoryExceptions::TypeNotRegistered(id);
- }
-
- return it->second();
- }
-
-private:
- std::map<const std::string, CreateFunction*> objectMap;
-};
-
+#include "factory.h"
+#include "singleton.h"
class SPObject;
typedef Singleton< Factory<SPObject> > SPFactory;
-
-class SPEventContext;
-typedef Singleton< Factory<SPEventContext> > ToolFactory;
-
-
-
-#include "xml/node.h"
-
-struct NodeTraits {
- static std::string getTypeString(const Inkscape::XML::Node& node) {
- std::string name;
-
- switch (node.type()) {
- case Inkscape::XML::TEXT_NODE:
- name = "string";
- break;
-
- case Inkscape::XML::ELEMENT_NODE: {
- gchar const* const sptype = node.attribute("sodipodi:type");
-
- if (sptype) {
- name = sptype;
- } else {
- name = node.name();
- }
- break;
- }
- default:
- name = "";
- break;
- }
-
- return name;
- }
-};
diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp
index a191eba49..6df7a4036 100644
--- a/src/spiral-context.cpp
+++ b/src/spiral-context.cpp
@@ -50,7 +50,7 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat
static void sp_spiral_finish(SPSpiralContext *sc);
static void sp_spiral_cancel(SPSpiralContext *sc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createSpiralContext() {
diff --git a/src/spray-context.cpp b/src/spray-context.cpp
index 95017810d..9c4a22053 100644
--- a/src/spray-context.cpp
+++ b/src/spray-context.cpp
@@ -78,7 +78,7 @@ using namespace std;
#define DDC_RED_RGBA 0xff0000ff
#define DYNA_MIN_WIDTH 1.0e-6
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createSprayContext() {
diff --git a/src/star-context.cpp b/src/star-context.cpp
index 28eaca309..4116d5e68 100644
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
@@ -54,7 +54,7 @@ static void sp_star_drag (SPStarContext * sc, Geom::Point p, guint state);
static void sp_star_finish (SPStarContext * sc);
static void sp_star_cancel(SPStarContext * sc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createStarContext() {
diff --git a/src/text-context.cpp b/src/text-context.cpp
index 180bb320a..1170f5129 100644
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
@@ -73,7 +73,7 @@ static gint sptc_focus_out(GtkWidget *widget, GdkEventFocus *event, SPTextContex
static void sptc_commit(GtkIMContext *imc, gchar *string, SPTextContext *tc);
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createTextContext() {
diff --git a/src/tool-factory.h b/src/tool-factory.h
new file mode 100644
index 000000000..3892606c6
--- /dev/null
+++ b/src/tool-factory.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "factory.h"
+#include "singleton.h"
+
+class SPEventContext;
+typedef Singleton< Factory<SPEventContext> > ToolFactory;
diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp
index 5790c79b9..d6d5ccd47 100644
--- a/src/tweak-context.cpp
+++ b/src/tweak-context.cpp
@@ -81,7 +81,7 @@ using Inkscape::DocumentUndo;
#define DYNA_MIN_WIDTH 1.0e-6
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createTweakContext() {
diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp
index e72b7c5ba..f994080b0 100644
--- a/src/ui/tool/node-tool.cpp
+++ b/src/ui/tool/node-tool.cpp
@@ -119,7 +119,7 @@ void handleControlUiStyleChange(InkNodeTool *nt);
//} // anonymous namespace
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createNodesContext() {
diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp
index 7a1ae5382..ee72b85ab 100644
--- a/src/zoom-context.cpp
+++ b/src/zoom-context.cpp
@@ -31,7 +31,7 @@ static gint tolerance = 0;
static bool within_tolerance = false;
static bool escaped;
-#include "sp-factory.h"
+#include "tool-factory.h"
namespace {
SPEventContext* createZoomContext() {