-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.h
107 lines (89 loc) · 3.1 KB
/
Factory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef FACTORY_H
#define FACTORY_H
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#include "Circle.h"
#include "Rect.h"
#include "Line.h"
#include "Path.h"
#include "Text.h"
#include "Ellipse.h"
#include "Polygon.h"
#include "Polyline.h"
#include "Group.h"
#include "Transform.h"
#include <memory>
#include <unordered_map>
#include <functional>
#include <locale>
#include <codecvt>
// Factory for creating SVG elements
class SVGElementFactory {
public:
virtual std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const = 0;
virtual ~SVGElementFactory() = default;
};
// Factory for creating rectangles
class RectFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating circles
class CircleFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating ellipses
class EllipseFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating lines
class LineFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating paths
class PathFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating polygons
class PolygonFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating polylines
class PolylineFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Factory for creating texts
class TextFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
class GroupFactory : public SVGElementFactory {
public:
std::unique_ptr<SVGElements> createElement(rapidxml::xml_node<>* node) const override;
};
// Registry for SVG element factories
class SVGFactoryRegistry {
private:
std::unordered_map<std::string, std::function<std::unique_ptr<SVGElements>(rapidxml::xml_node<>*)>> factoryMap;
public:
void registerFactory(const std::string& name, std::function<std::unique_ptr<SVGElements>(rapidxml::xml_node<>*)> factory);
std::unique_ptr<SVGElements> createElementFromFactory(const std::string& name, rapidxml::xml_node<>* node);
};
class SVGFactoryRegistrar {
public:
template<class FactoryType>
void registerFactories(SVGFactoryRegistry& registry, const std::string& factoryName) {
registry.registerFactory(factoryName, [](rapidxml::xml_node<>* node) {
FactoryType factory;
return factory.createElement(node);
});
}
void registerAllFactories(SVGFactoryRegistry& registry);
};
std::unordered_map<std::string, std::string> parseStyle(const std::string& style);
#endif // FACTORY_H