vfs: check userland buffers before reading them.
[haiku.git] / src / apps / icon-o-matic / import_export / flat_icon / FlatIconExporter.h
blob455c7aabff660de38eb0e595119cb5d32506e3f3
1 /*
2 * Copyright 2006-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
8 #ifndef FLAT_ICON_EXPORTER_H
9 #define FLAT_ICON_EXPORTER_H
12 #include "Exporter.h"
15 class BMessage;
16 class BNode;
17 class BPositionIO;
19 _BEGIN_ICON_NAMESPACE
20 class Gradient;
21 class LittleEndianBuffer;
22 class PathContainer;
23 class ShapeContainer;
24 class StyleContainer;
25 class VectorPath;
26 _END_ICON_NAMESPACE
29 #define PRINT_STATISTICS 1
31 #if PRINT_STATISTICS
32 # include <Point.h>
33 # include <hash_set>
35 #if __GNUC__ >= 4
36 using __gnu_cxx::hash_set;
37 #endif
39 class PointHash {
40 public:
41 int operator()(const BPoint& point) const
43 return (int)point.x * 17 + (int)point.y;
47 typedef hash_set<BPoint, PointHash> PointSet;
48 #endif
50 class FlatIconExporter : public Exporter {
51 public:
52 FlatIconExporter();
53 virtual ~FlatIconExporter();
55 // Exporter interface
56 virtual status_t Export(const Icon* icon,
57 BPositionIO* stream);
59 virtual const char* MIMEType();
61 // FlatIconExporter
62 status_t Export(const Icon* icon, BNode* node,
63 const char* attrName);
65 private:
66 status_t _Export(LittleEndianBuffer& buffer,
67 const Icon* icon);
69 status_t _WriteStyles(LittleEndianBuffer& buffer,
70 StyleContainer* styles);
71 status_t _WritePaths(LittleEndianBuffer& buffer,
72 PathContainer* paths);
73 status_t _WriteShapes(LittleEndianBuffer& buffer,
74 StyleContainer* styles,
75 PathContainer* paths,
76 ShapeContainer* shapes);
78 bool _WriteGradient(LittleEndianBuffer& buffer,
79 const Gradient* gradient);
81 bool _AnalysePath(VectorPath* path,
82 uint8 pointCount,
83 int32& straightCount,
84 int32& lineCount,
85 int32& curveCount);
87 #if PRINT_STATISTICS
88 int32 fStyleSectionSize;
89 int32 fGradientSize;
90 int32 fGradientTransformSize;
91 int32 fPathSectionSize;
92 int32 fShapeSectionSize;
94 PointSet fUsedPoints;
95 int32 fPointCount;
96 #endif // PRINT_STATISTICS
99 #endif // FLAT_ICON_EXPORTER_H