1 /* === S Y N F I G ========================================================= */
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 ======================================================= */
26 #define SYNFIG_NO_ANGLE
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
52 using namespace synfig;
54 Importer::Book* synfig::Importer::book_;
56 map<String,Importer::LooseHandle> *__open_importers;
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
63 Importer::subsys_init()
66 __open_importers=new map<String,Importer::LooseHandle>();
71 Importer::subsys_stop()
74 delete __open_importers;
85 Importer::open(const String &filename)
89 synfig::error(_("Importer::open(): Cannot open empty filename"));
93 // If we already have an importer open under that filename,
94 // then use it instead.
95 if(__open_importers->count(filename))
97 //synfig::info("Found importer already open, using it...");
98 return (*__open_importers)[filename];
101 if(filename_extension(filename) == "")
103 synfig::error(_("Importer::open(): Couldn't find extension"));
107 String ext(filename_extension(filename));
108 if (ext.size()) ext = ext.substr(1); // skip initial '.'
109 std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
112 if(!Importer::book().count(ext))
114 synfig::error(_("Importer::open(): Unknown file type -- ")+ext);
119 Importer::Handle importer;
120 importer=Importer::book()[ext](filename.c_str());
121 (*__open_importers)[filename]=importer;
131 Importer::Importer():
137 Importer::~Importer()
139 // Remove ourselves from the open importer list
140 map<String,Importer::LooseHandle>::iterator iter;
141 for(iter=__open_importers->begin();iter!=__open_importers->end();++iter)
142 if(iter->second==this)
144 __open_importers->erase(iter);