1 /* === S Y N F I G ========================================================= */
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #define SYNFIG_NO_ANGLE
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
51 using namespace synfig;
53 Importer::Book* synfig::Importer::book_;
55 map<String,Importer::LooseHandle> *__open_importers;
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
62 Importer::subsys_init()
65 __open_importers=new map<String,Importer::LooseHandle>();
70 Importer::subsys_stop()
73 delete __open_importers;
84 Importer::open(const String &filename)
88 synfig::error(_("Importer::open(): Cannot open empty filename"));
92 // If we already have an importer open under that filename,
93 // then use it instead.
94 if(__open_importers->count(filename))
96 //synfig::info("Found importer already open, using it...");
97 return (*__open_importers)[filename];
100 if(filename_extension(filename) == "")
102 synfig::error(_("Importer::open(): Couldn't find extension"));
106 String ext(filename_extension(filename));
107 if (ext.size()) ext = ext.substr(1); // skip initial '.'
108 std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
111 if(!Importer::book().count(ext))
113 synfig::error(_("Importer::open(): Unknown file type -- ")+ext);
118 Importer::Handle importer;
119 importer=Importer::book()[ext](filename.c_str());
120 (*__open_importers)[filename]=importer;
130 Importer::Importer():
136 Importer::~Importer()
138 // Remove ourselves from the open importer list
139 map<String,Importer::LooseHandle>::iterator iter;
140 for(iter=__open_importers->begin();iter!=__open_importers->end();++iter)
141 if(iter->second==this)
143 __open_importers->erase(iter);