Documentation typo
[synfig.git] / synfig-core / src / synfig / importer.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file importer.h
3 **      \brief It is the base class for all the importers.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_IMPORTER_H
26 #define __SYNFIG_IMPORTER_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <cstdio>
31 #include <map>
32 #include <ETL/handle>
33 #include "string.h"
34 #include "time.h"
35 #include "gamma.h"
36
37 /* === M A C R O S ========================================================= */
38
39 //! Defines various variables and the create method, common for all importers.
40 //! To be used in the private part of the importer class definition.
41 #define SYNFIG_IMPORTER_MODULE_EXT public: static const char name__[], version__[], ext__[],cvs_id__[]; static Importer *create(const char *filename);
42
43 //! Sets the name of the importer.
44 #define SYNFIG_IMPORTER_SET_NAME(class,x) const char class::name__[]=x
45
46 //! Sets the primary file extension of the importer.
47 #define SYNFIG_IMPORTER_SET_EXT(class,x) const char class::ext__[]=x
48
49 //! Sets the version of the importer.
50 #define SYNFIG_IMPORTER_SET_VERSION(class,x) const char class::version__[]=x
51
52 //! Sets the CVS ID of the importer.
53 #define SYNFIG_IMPORTER_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
54
55 //! Defines de implementation of the create method for the importer
56 //! \param filename The file name to be imported by the importer.
57 #define SYNFIG_IMPORTER_INIT(class) synfig::Importer* class::create(const char *filename) { return new class(filename); }
58
59 /* === T Y P E D E F S ===================================================== */
60
61 /* === C L A S S E S & S T R U C T S ======================================= */
62
63 namespace synfig {
64
65 class Surface;
66 class ProgressCallback;
67
68 /*!     \class Importer
69 **      \brief Used for importing bitmaps of various formats, including animations.
70 *
71 *       It is the base class for all the importers. It defines the has a static Book
72 *       pointer class that is a map for the importers factory creators and the strings
73 *       of the extension that the importer can understand. It allows to create the a
74 *       pointer to a particular importer just by using the extension of the name of file
75 *       to import. Also it creates a virtual member get_frame that must be declared in
76 *       the inherited classes.
77 *       \see module.h
78 **      \
79 */
80 class Importer : public etl::shared_object
81 {
82 public:
83         //! Type that represents a pointer to a Importer's constructor.
84         //! As a pointer to the constructor, it represents a "factory" of importers.
85         typedef Importer* (*Factory)(const char *filename);
86         typedef std::map<String,Factory> Book;
87         static Book* book_;
88
89         static Book& book();
90
91         //! Initializes the Import module by creating a book of importers names
92         //! and its creators and the list of open importers
93         static bool subsys_init();
94         //! Stops the Import module by deleting the book and the list of open
95         //! importers
96         static bool subsys_stop();
97
98         typedef etl::handle<Importer> Handle;
99         typedef etl::loose_handle<Importer> LooseHandle;
100         typedef etl::handle<const Importer> ConstHandle;
101
102 private:
103         //! Gamma of the importer.
104         //! \todo Do not hardcode the gamma to 2.2
105         Gamma gamma_;
106
107 protected:
108         Importer();
109
110 public:
111
112         Gamma& gamma() { return gamma_; }
113         const Gamma& gamma()const { return gamma_; }
114
115         virtual ~Importer();
116
117         //! Gets a frame and puts it into \a surface
118         /*!     \param  surface Reference to surface to put frame into
119         **      \param  time    For animated importers, determines which frame to get.
120         **              For static importers, this parameter is unused.
121         **      \param  callback Pointer to callback class for progress, errors, etc.
122         **      \return \c true on success, \c false on error
123         **      \see ProgressCallback, Surface
124         */
125         virtual bool get_frame(Surface &surface,Time time, ProgressCallback *callback=NULL)=0;
126         virtual bool get_frame(Surface &surface,Time time,
127                                                    bool &trimmed __attribute__ ((unused)),
128                                                    unsigned int &width __attribute__ ((unused)),
129                                                    unsigned int &height __attribute__ ((unused)),
130                                                    unsigned int &top __attribute__ ((unused)),
131                                                    unsigned int &left __attribute__ ((unused)),
132                                                    ProgressCallback *callback=NULL)
133         {
134                 return get_frame(surface,time,callback);
135         }
136
137         //! Returns \c true if the importer pays attention to the \a time parameter of get_frame()
138         virtual bool is_animated() { return false; }
139
140         //! Attempts to open \a filename, and returns a handle to the associated Importer
141         static Handle open(const String &filename);
142 };
143
144 }; // END of namespace synfig
145
146 /* === E N D =============================================================== */
147
148 #endif