15 #include "loaderFileTypeRegistry.h" 16 #include "loaderFileType.h" 17 #include "config_pgraph.h" 20 #include "string_utils.h" 32 LoaderFileTypeRegistry::
33 LoaderFileTypeRegistry() {
41 LoaderFileTypeRegistry::
42 ~LoaderFileTypeRegistry() {
53 if (find(_types.begin(), _types.end(), type) != _types.end()) {
54 if (loader_cat->is_debug()) {
56 <<
"Attempt to register LoaderFileType " << type->get_name()
57 <<
" (" << type->get_type() <<
") more than once.\n";
62 _types.push_back(type);
64 if (!type->get_extension().empty()) {
65 record_extension(type->get_extension(), type);
70 vector_string::const_iterator wi;
71 for (wi = words.begin(); wi != words.end(); ++wi) {
72 record_extension(*wi, type);
88 string dcextension = downcase(extension);
90 Extensions::const_iterator ei;
91 ei = _extensions.find(dcextension);
92 if (ei != _extensions.end()) {
95 if (loader_cat->is_debug()) {
97 <<
"Attempt to register loader library " << library
98 <<
" (" << dcextension <<
") when extension is already known.\n";
103 DeferredTypes::const_iterator di;
104 di = _deferred_types.find(dcextension);
105 if (di != _deferred_types.end()) {
106 if ((*di).second == library) {
107 if (loader_cat->is_debug()) {
109 <<
"Attempt to register loader library " << library
110 <<
" (" << dcextension <<
") more than once.\n";
114 if (loader_cat->is_debug()) {
116 <<
"Multiple libraries registered that use the extension " 117 << dcextension <<
"\n";
122 _deferred_types[dcextension] = library;
132 return _types.size();
142 nassertr(n >= 0 && n < (
int)_types.size(), NULL);
155 string dcextension = downcase(extension);
157 Extensions::const_iterator ei;
158 ei = _extensions.find(dcextension);
159 if (ei == _extensions.end()) {
162 DeferredTypes::iterator di;
163 di = _deferred_types.find(dcextension);
164 if (di != _deferred_types.end()) {
169 string name = (*di).second;
170 Filename dlname = Filename::dso_filename(
"lib" + name +
".so");
171 _deferred_types.erase(di);
174 <<
"loading file type module: " << name << endl;
175 void *tmp = load_dso(get_plugin_path().get_value(), dlname);
176 if (tmp == (
void *)NULL) {
177 loader_cat->warning()
179 << load_dso_error() << endl;
181 }
else if (loader_cat.is_debug()) {
183 <<
"done loading file type module: " << name << endl;
187 ei = _extensions.find(dcextension);
191 if (ei == _extensions.end()) {
207 write(ostream &out,
int indent_level)
const {
208 if (_types.empty()) {
209 indent(out, indent_level) <<
"(No file types are known).\n";
211 Types::const_iterator ti;
212 for (ti = _types.begin(); ti != _types.end(); ++ti) {
214 string name = type->get_name();
215 indent(out, indent_level) << name;
216 indent(out, max(30 - (
int)name.length(), 0)) <<
" ";
219 if (!type->get_extension().empty()) {
220 out <<
" ." << type->get_extension();
226 vector_string::const_iterator wi;
227 for (wi = words.begin(); wi != words.end(); ++wi) {
239 if (!_deferred_types.empty()) {
240 indent(out, indent_level) <<
"Also available:";
241 DeferredTypes::const_iterator di;
242 for (di = _deferred_types.begin(); di != _deferred_types.end(); ++di) {
243 const string &extension = (*di).first;
244 out <<
" ." << extension;
270 void LoaderFileTypeRegistry::
272 string dcextension = downcase(extension);
273 Extensions::const_iterator ei;
274 ei = _extensions.find(dcextension);
275 if (ei != _extensions.end()) {
276 if (loader_cat->is_debug()) {
278 <<
"Multiple LoaderFileTypes registered that use the extension " 279 << dcextension <<
"\n";
282 _extensions.insert(Extensions::value_type(dcextension, type));
285 _deferred_types.erase(dcextension);
static LoaderFileTypeRegistry * get_global_ptr()
Returns a pointer to the global LoaderFileTypeRegistry object.
void write(ostream &out, int indent_level=0) const
Writes a list of supported file types to the indicated output stream, one per line.
LoaderFileType * get_type(int n) const
Returns the nth type registered.
virtual string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(), that are recognized by this loader.
int get_num_types() const
Returns the total number of types registered.
void register_type(LoaderFileType *type)
Defines a new LoaderFileType in the universe.
void register_deferred_type(const string &extension, const string &library)
Records a type associated with a particular extension to be loaded in the future. ...
The name of a file, such as a texture file or an Egg file.
LoaderFileType * get_type_from_extension(const string &extension)
Determines the type of the file based on the indicated extension (without a leading dot)...
This class maintains the set of all known LoaderFileTypes in the universe.
This is the base class for a family of scene-graph file types that the Loader supports.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...