1 /* === S Y N F I G ========================================================= */
5 ** $Id: importer.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
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(find(filename.begin(),filename.end(),'.')==filename.end())
102 synfig::error(_("Importer::open(): Couldn't find extension"));
106 String ext=string(filename.begin()+filename.find_last_of('.')+1,filename.end());
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);