1 | #ifndef __qwt3d_io_2003_07_04_23_27__
|
---|
2 | #define __qwt3d_io_2003_07_04_23_27__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include <algorithm>
|
---|
6 |
|
---|
7 | #include <qstring.h>
|
---|
8 | #include <qstringlist.h>
|
---|
9 | #include "qwt3d_global.h"
|
---|
10 |
|
---|
11 | namespace Qwt3D
|
---|
12 | {
|
---|
13 |
|
---|
14 | class Plot3D;
|
---|
15 | /**
|
---|
16 | IO provides a generic interface for standard and user written I/O handlers.
|
---|
17 | It also provides functionality for the registering of such handlers in the
|
---|
18 | framework.\n
|
---|
19 | The interface mimics roughly Qt's QImageIO functions for defining
|
---|
20 | image input/output functions.
|
---|
21 | */
|
---|
22 | class QWT3D_EXPORT IO
|
---|
23 | {
|
---|
24 |
|
---|
25 | public:
|
---|
26 | /*!
|
---|
27 | The function type that can be processed by the define... members.
|
---|
28 | An extension is the IO::Functor.
|
---|
29 | */
|
---|
30 | typedef bool (*Function)(Plot3D*, QString const& fname);
|
---|
31 |
|
---|
32 |
|
---|
33 | /*!
|
---|
34 | This class gives more flexibility in implementing
|
---|
35 | userdefined IO handlers than the simple IO::Function type.
|
---|
36 | */
|
---|
37 | class Functor
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | virtual ~Functor() {}
|
---|
41 | /*! Must clone the content of *this for an object of a derived class with
|
---|
42 | \c new and return the pointer. Like operator() the predefined Functors
|
---|
43 | hide this function from the user, still allowing IO access
|
---|
44 | (friend declaration)
|
---|
45 | */
|
---|
46 | virtual Functor* clone() const = 0;
|
---|
47 | /*! The workhorse of the user-defined implementation. Eventually, the
|
---|
48 | framework will call this operator.
|
---|
49 | */
|
---|
50 | virtual bool operator()(Plot3D* plot, QString const& fname) = 0;
|
---|
51 | };
|
---|
52 |
|
---|
53 | static bool defineInputHandler( QString const& format, Function func);
|
---|
54 | static bool defineOutputHandler( QString const& format, Function func);
|
---|
55 | static bool defineInputHandler( QString const& format, Functor const& func);
|
---|
56 | static bool defineOutputHandler( QString const& format, Functor const& func);
|
---|
57 | static bool save(Plot3D*, QString const& fname, QString const& format);
|
---|
58 | static bool load(Plot3D*, QString const& fname, QString const& format);
|
---|
59 | static QStringList inputFormatList();
|
---|
60 | static QStringList outputFormatList();
|
---|
61 | static Functor* outputHandler(QString const& format);
|
---|
62 | static Functor* inputHandler(QString const& format);
|
---|
63 |
|
---|
64 | private:
|
---|
65 | IO(){}
|
---|
66 |
|
---|
67 | //! Lightweight Functor encapsulating an IO::Function
|
---|
68 | class Wrapper : public Functor
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | //! Performs actual input
|
---|
72 | Functor* clone() const { return new Wrapper(*this); }
|
---|
73 | //! Creates a Wrapper object from a function pointer
|
---|
74 | explicit Wrapper(Function h) : hdl(h) {}
|
---|
75 | //! Returns a pointer to the wrapped function
|
---|
76 | bool operator()(Plot3D* plot, QString const& fname)
|
---|
77 | {
|
---|
78 | return (hdl) ? (*hdl)(plot, fname) : false;
|
---|
79 | }
|
---|
80 | private:
|
---|
81 | Function hdl;
|
---|
82 | };
|
---|
83 |
|
---|
84 | struct Entry
|
---|
85 | {
|
---|
86 | Entry();
|
---|
87 | ~Entry();
|
---|
88 |
|
---|
89 | Entry(Entry const& e);
|
---|
90 | void operator=(Entry const& e);
|
---|
91 |
|
---|
92 | Entry(QString const& s, Functor const& f);
|
---|
93 | Entry(QString const& s, Function f);
|
---|
94 |
|
---|
95 | QString fmt;
|
---|
96 | Functor* iofunc;
|
---|
97 | };
|
---|
98 |
|
---|
99 | struct FormatCompare
|
---|
100 | {
|
---|
101 | explicit FormatCompare(Entry const& e);
|
---|
102 | bool operator() (Entry const& e);
|
---|
103 |
|
---|
104 | Entry e_;
|
---|
105 | };
|
---|
106 |
|
---|
107 | struct FormatCompare2
|
---|
108 | {
|
---|
109 | explicit FormatCompare2(QString s);
|
---|
110 | bool operator() (Entry const& e);
|
---|
111 |
|
---|
112 | QString s_;
|
---|
113 | };
|
---|
114 |
|
---|
115 | typedef std::vector<Entry> Container;
|
---|
116 | typedef Container::iterator IT;
|
---|
117 |
|
---|
118 | static bool add_unique(Container& l, Entry const& e);
|
---|
119 | static IT find(Container& l, QString const& fmt);
|
---|
120 | static Container& rlist();
|
---|
121 | static Container& wlist();
|
---|
122 | static void setupHandler();
|
---|
123 | };
|
---|
124 |
|
---|
125 | //! Provides Qt's Pixmap output facilities
|
---|
126 | class QWT3D_EXPORT PixmapWriter : public IO::Functor
|
---|
127 | {
|
---|
128 | friend class IO;
|
---|
129 | public:
|
---|
130 | PixmapWriter() : quality_(-1) {}
|
---|
131 | void setQuality(int val);
|
---|
132 | private:
|
---|
133 | IO::Functor* clone() const {return new PixmapWriter(*this);}
|
---|
134 | bool operator()(Plot3D* plot, QString const& fname);
|
---|
135 | QString fmt_;
|
---|
136 | int quality_;
|
---|
137 | };
|
---|
138 |
|
---|
139 | } //ns
|
---|
140 |
|
---|
141 | #endif
|
---|