|
|
@@ -47,22 +47,78 @@ LoaderFileTypeRegistry::
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: LoaderFileTypeRegistry::get_ptr
|
|
|
-// Access: Public, Static
|
|
|
-// Description: Returns a pointer to the global LoaderFileTypeRegistry
|
|
|
-// object.
|
|
|
+// Function: LoaderFileTypeRegistry::register_type
|
|
|
+// Access: Public
|
|
|
+// Description: Defines a new LoaderFileType in the universe.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-LoaderFileTypeRegistry *LoaderFileTypeRegistry::
|
|
|
-get_ptr() {
|
|
|
- if (_global_ptr == (LoaderFileTypeRegistry *)NULL) {
|
|
|
- _global_ptr = new LoaderFileTypeRegistry;
|
|
|
+void LoaderFileTypeRegistry::
|
|
|
+register_type(LoaderFileType *type) {
|
|
|
+ // Make sure we haven't already registered this type.
|
|
|
+ if (find(_types.begin(), _types.end(), type) != _types.end()) {
|
|
|
+ loader_cat->debug()
|
|
|
+ << "Attempt to register LoaderFileType " << type->get_name()
|
|
|
+ << " (" << type->get_type() << ") more than once.\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _types.push_back(type);
|
|
|
+
|
|
|
+ record_extension(type->get_extension(), type);
|
|
|
+
|
|
|
+ vector_string words;
|
|
|
+ extract_words(type->get_additional_extensions(), words);
|
|
|
+ vector_string::const_iterator wi;
|
|
|
+ for (wi = words.begin(); wi != words.end(); ++wi) {
|
|
|
+ record_extension(*wi, type);
|
|
|
}
|
|
|
- return _global_ptr;
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: LoaderFileTypeRegistry::get_num_types
|
|
|
+// Function: LoaderFileTypeRegistry::register_deferred_type
|
|
|
// Access: Public
|
|
|
+// Description: Records a type associated with a particular extension
|
|
|
+// to be loaded in the future. The named library will
|
|
|
+// be dynamically loaded the first time files of this
|
|
|
+// extension are loaded; presumably this library will
|
|
|
+// call register_type() when it initializes, thus making
|
|
|
+// the extension loadable.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void LoaderFileTypeRegistry::
|
|
|
+register_deferred_type(const string &extension, const string &library) {
|
|
|
+ string dcextension = downcase(extension);
|
|
|
+
|
|
|
+ Extensions::const_iterator ei;
|
|
|
+ ei = _extensions.find(dcextension);
|
|
|
+ if (ei != _extensions.end()) {
|
|
|
+ // We already have a loader for this type; no need to register
|
|
|
+ // another one.
|
|
|
+ loader_cat->debug()
|
|
|
+ << "Attempt to register loader library " << library
|
|
|
+ << " (" << dcextension << ") when extension is already known.\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DeferredTypes::const_iterator di;
|
|
|
+ di = _deferred_types.find(dcextension);
|
|
|
+ if (di != _deferred_types.end()) {
|
|
|
+ if ((*di).second == library) {
|
|
|
+ loader_cat->debug()
|
|
|
+ << "Attempt to register loader library " << library
|
|
|
+ << " (" << dcextension << ") more than once.\n";
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ loader_cat->debug()
|
|
|
+ << "Multiple libraries registered that use the extension "
|
|
|
+ << dcextension << "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _deferred_types[dcextension] = library;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: LoaderFileTypeRegistry::get_num_types
|
|
|
+// Access: Published
|
|
|
// Description: Returns the total number of types registered.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
int LoaderFileTypeRegistry::
|
|
|
@@ -72,7 +128,7 @@ get_num_types() const {
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: LoaderFileTypeRegistry::get_type
|
|
|
-// Access: Public
|
|
|
+// Access: Published
|
|
|
// Description: Returns the nth type registered.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
LoaderFileType *LoaderFileTypeRegistry::
|
|
|
@@ -83,7 +139,7 @@ get_type(int n) const {
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: LoaderFileTypeRegistry::get_type_from_extension
|
|
|
-// Access: Public
|
|
|
+// Access: Published
|
|
|
// Description: Determines the type of the file based on the indicated
|
|
|
// extension (without a leading dot). Returns NULL if
|
|
|
// the extension matches no known file types.
|
|
|
@@ -133,13 +189,13 @@ get_type_from_extension(const string &extension) {
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: LoaderFileTypeRegistry::write_types
|
|
|
-// Access: Public
|
|
|
+// Function: LoaderFileTypeRegistry::write
|
|
|
+// Access: Published
|
|
|
// Description: Writes a list of supported file types to the
|
|
|
// indicated output stream, one per line.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void LoaderFileTypeRegistry::
|
|
|
-write_types(ostream &out, int indent_level) const {
|
|
|
+write(ostream &out, int indent_level) const {
|
|
|
if (_types.empty()) {
|
|
|
indent(out, indent_level) << "(No file types are known).\n";
|
|
|
} else {
|
|
|
@@ -165,73 +221,17 @@ write_types(ostream &out, int indent_level) const {
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: LoaderFileTypeRegistry::register_type
|
|
|
-// Access: Public
|
|
|
-// Description: Defines a new LoaderFileType in the universe.
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-void LoaderFileTypeRegistry::
|
|
|
-register_type(LoaderFileType *type) {
|
|
|
- // Make sure we haven't already registered this type.
|
|
|
- if (find(_types.begin(), _types.end(), type) != _types.end()) {
|
|
|
- loader_cat->debug()
|
|
|
- << "Attempt to register LoaderFileType " << type->get_name()
|
|
|
- << " (" << type->get_type() << ") more than once.\n";
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _types.push_back(type);
|
|
|
-
|
|
|
- record_extension(type->get_extension(), type);
|
|
|
-
|
|
|
- vector_string words;
|
|
|
- extract_words(type->get_additional_extensions(), words);
|
|
|
- vector_string::const_iterator wi;
|
|
|
- for (wi = words.begin(); wi != words.end(); ++wi) {
|
|
|
- record_extension(*wi, type);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-// Function: LoaderFileTypeRegistry::register_deferred_type
|
|
|
-// Access: Public
|
|
|
-// Description: Records a type associated with a particular extension
|
|
|
-// to be loaded in the future. The named library will
|
|
|
-// be dynamically loaded the first time files of this
|
|
|
-// extension are loaded; presumably this library will
|
|
|
-// call register_type() when it initializes, thus making
|
|
|
-// the extension loadable.
|
|
|
+// Function: LoaderFileTypeRegistry::get_global_ptr
|
|
|
+// Access: Published, Static
|
|
|
+// Description: Returns a pointer to the global LoaderFileTypeRegistry
|
|
|
+// object.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-void LoaderFileTypeRegistry::
|
|
|
-register_deferred_type(const string &extension, const string &library) {
|
|
|
- string dcextension = downcase(extension);
|
|
|
-
|
|
|
- Extensions::const_iterator ei;
|
|
|
- ei = _extensions.find(dcextension);
|
|
|
- if (ei != _extensions.end()) {
|
|
|
- // We already have a loader for this type; no need to register
|
|
|
- // another one.
|
|
|
- loader_cat->debug()
|
|
|
- << "Attempt to register loader library " << library
|
|
|
- << " (" << dcextension << ") when extension is already known.\n";
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- DeferredTypes::const_iterator di;
|
|
|
- di = _deferred_types.find(dcextension);
|
|
|
- if (di != _deferred_types.end()) {
|
|
|
- if ((*di).second == library) {
|
|
|
- loader_cat->debug()
|
|
|
- << "Attempt to register loader library " << library
|
|
|
- << " (" << dcextension << ") more than once.\n";
|
|
|
- return;
|
|
|
- } else {
|
|
|
- loader_cat->debug()
|
|
|
- << "Multiple libraries registered that use the extension "
|
|
|
- << dcextension << "\n";
|
|
|
- }
|
|
|
+LoaderFileTypeRegistry *LoaderFileTypeRegistry::
|
|
|
+get_global_ptr() {
|
|
|
+ if (_global_ptr == (LoaderFileTypeRegistry *)NULL) {
|
|
|
+ _global_ptr = new LoaderFileTypeRegistry;
|
|
|
}
|
|
|
-
|
|
|
- _deferred_types[dcextension] = library;
|
|
|
+ return _global_ptr;
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|