31 LoaderFileTypeRegistry::
32 LoaderFileTypeRegistry() {
38 LoaderFileTypeRegistry::
39 ~LoaderFileTypeRegistry() {
48 if (find(_types.begin(), _types.end(), type) != _types.end()) {
49 if (loader_cat->is_debug()) {
51 <<
"Attempt to register LoaderFileType " << type->get_name()
52 <<
" (" << type->get_type() <<
") more than once.\n";
57 _types.push_back(type);
59 if (!type->get_extension().empty()) {
60 record_extension(type->get_extension(), type);
65 vector_string::const_iterator wi;
66 for (wi = words.begin(); wi != words.end(); ++wi) {
67 record_extension(*wi, type);
79 string dcextension =
downcase(extension);
81 Extensions::const_iterator ei;
82 ei = _extensions.find(dcextension);
83 if (ei != _extensions.end()) {
86 if (loader_cat->is_debug()) {
88 <<
"Attempt to register loader library " << library
89 <<
" (" << dcextension <<
") when extension is already known.\n";
94 DeferredTypes::const_iterator di;
95 di = _deferred_types.find(dcextension);
96 if (di != _deferred_types.end()) {
97 if ((*di).second == library) {
98 if (loader_cat->is_debug()) {
100 <<
"Attempt to register loader library " << library
101 <<
" (" << dcextension <<
") more than once.\n";
105 if (loader_cat->is_debug()) {
107 <<
"Multiple libraries registered that use the extension " 108 << dcextension <<
"\n";
113 _deferred_types[dcextension] = library;
119 int LoaderFileTypeRegistry::
120 get_num_types()
const {
121 return _types.size();
129 nassertr(n >= 0 && n < (
int)_types.size(),
nullptr);
139 string dcextension =
downcase(extension);
141 Extensions::const_iterator ei;
142 ei = _extensions.find(dcextension);
143 if (ei == _extensions.end()) {
146 DeferredTypes::iterator di;
147 di = _deferred_types.find(dcextension);
148 if (di != _deferred_types.end()) {
152 string name = (*di).second;
153 Filename dlname = Filename::dso_filename(
"lib" + name +
".so");
154 _deferred_types.erase(di);
157 <<
"loading file type module: " << name << std::endl;
158 void *tmp = load_dso(get_plugin_path().get_value(), dlname);
159 if (tmp ==
nullptr) {
160 loader_cat->warning()
162 << load_dso_error() << std::endl;
164 }
else if (loader_cat.is_debug()) {
166 <<
"done loading file type module: " << name << std::endl;
170 ei = _extensions.find(dcextension);
174 if (ei == _extensions.end()) {
188 write(std::ostream &out,
int indent_level)
const {
189 if (_types.empty()) {
190 indent(out, indent_level) <<
"(No file types are known).\n";
192 Types::const_iterator ti;
193 for (ti = _types.begin(); ti != _types.end(); ++ti) {
195 string name = type->get_name();
196 indent(out, indent_level) << name;
197 indent(out, std::max(30 - (
int)name.length(), 0)) <<
" ";
200 if (!type->get_extension().empty()) {
201 out <<
" ." << type->get_extension();
207 vector_string::const_iterator wi;
208 for (wi = words.begin(); wi != words.end(); ++wi) {
220 if (!_deferred_types.empty()) {
221 indent(out, indent_level) <<
"Also available:";
222 DeferredTypes::const_iterator di;
223 for (di = _deferred_types.begin(); di != _deferred_types.end(); ++di) {
224 const string &extension = (*di).first;
225 out <<
" ." << extension;
236 if (_global_ptr ==
nullptr) {
245 void LoaderFileTypeRegistry::
247 string dcextension =
downcase(extension);
248 Extensions::const_iterator ei;
249 ei = _extensions.find(dcextension);
250 if (ei != _extensions.end()) {
251 if (loader_cat->is_debug()) {
253 <<
"Multiple LoaderFileTypes registered that use the extension " 254 << dcextension <<
"\n";
257 _extensions.insert(Extensions::value_type(dcextension, type));
260 _deferred_types.erase(dcextension);
void register_deferred_type(const std::string &extension, const std::string &library)
Records a type associated with a particular extension to be loaded in the future.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(),...
static LoaderFileTypeRegistry * get_global_ptr()
Returns a pointer to the global LoaderFileTypeRegistry object.
void write(std::ostream &out, int indent_level=0) const
Writes a list of supported file types to the indicated output stream, one per line.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(LoaderFileType *type)
Defines a new LoaderFileType in the universe.
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
The name of a file, such as a texture file or an Egg file.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
get_type
Returns the nth type registered.
This class maintains the set of all known LoaderFileTypes in the universe.
LoaderFileType * get_type_from_extension(const std::string &extension)
Determines the type of the file based on the indicated extension (without a leading dot).
This is the base class for a family of scene-graph file types that the Loader supports.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.