1 /* === S Y N F I G ========================================================= */
3 ** \brief It is the base class for all the importers.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
50 using namespace synfig;
52 Importer::Book* synfig::Importer::book_;
54 map<String,Importer::LooseHandle> *__open_importers;
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
61 Importer::subsys_init()
64 __open_importers=new map<String,Importer::LooseHandle>();
69 Importer::subsys_stop()
72 delete __open_importers;
83 Importer::open(const String &filename)
87 synfig::error(_("Importer::open(): Cannot open empty filename"));
91 // If we already have an importer open under that filename,
92 // then use it instead.
93 if(__open_importers->count(filename))
95 //synfig::info("Found importer already open, using it...");
96 return (*__open_importers)[filename];
99 if(filename_extension(filename) == "")
101 synfig::error(_("Importer::open(): Couldn't find extension"));
105 String ext(filename_extension(filename));
106 if (ext.size()) ext = ext.substr(1); // skip initial '.'
107 std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
110 if(!Importer::book().count(ext))
112 synfig::error(_("Importer::open(): Unknown file type -- ")+ext);
117 Importer::Handle importer;
118 importer=Importer::book()[ext](filename.c_str());
119 (*__open_importers)[filename]=importer;
129 Importer::Importer():
135 Importer::~Importer()
137 // Remove ourselves from the open importer list
138 map<String,Importer::LooseHandle>::iterator iter;
139 for(iter=__open_importers->begin();iter!=__open_importers->end();++iter)
140 if(iter->second==this)
142 __open_importers->erase(iter);