add load_prc_file_data

This commit is contained in:
David Rose 2004-11-21 00:14:43 +00:00
parent a6ba243428
commit 6ac53b826a
3 changed files with 54 additions and 0 deletions

View File

@ -353,6 +353,13 @@ on the standard prc file search path (e.g. $PRC_DIR), as well as on
the model-path. It may be a physical file on disk, or a subfile of a
multifile (and mounted via Panda's virtual file system).
If your prc file is stored as an in-memory string instead of as a disk
file (for instance, maybe you just built it up), you can use the
load_prc_file_data() method to load the prc file from the string data.
The first parameter is an arbitrary name to assign to your in-memory
prc file; supply a filename if you have one, or use some other name
that is meaningful to you.
You can see the complete list of prc files that have been loaded into
the config system at any given time, including files loaded explicitly
via load_prc_file(), as well as files found in the standard prc file

View File

@ -76,6 +76,38 @@ load_prc_file(const string &filename) {
}
}
////////////////////////////////////////////////////////////////////
// Function: load_prc_file_data
// Description: Another convenience function to load a prc file from
// an explicit string, which represents the contents of
// the prc file.
//
// The first parameter is an arbitrary name to assign to
// this in-memory prc file. Supply a filename if the
// data was read from a file, or use any other name that
// is meaningful to you. The name is only used when the
// set of loaded prc files is listed.
////////////////////////////////////////////////////////////////////
EXPCL_PANDA ConfigPage *
load_prc_file_data(const string &name, const string &data) {
istringstream strm(data);
ConfigPageManager *cp_mgr = ConfigPageManager::get_global_ptr();
ConfigPage *page = cp_mgr->make_explicit_page(name);
bool read_ok = page->read_prc(strm);
if (read_ok) {
return page;
} else {
util_cat.info()
<< "Unable to read explicit prc data " << name << "\n";
cp_mgr->delete_explicit_page(page);
return NULL;
}
}
////////////////////////////////////////////////////////////////////
// Function: unload_prc_file
// Description: Unloads (and deletes) a ConfigPage that represents a

View File

@ -45,6 +45,21 @@ BEGIN_PUBLISH
EXPCL_PANDA ConfigPage *
load_prc_file(const string &filename);
////////////////////////////////////////////////////////////////////
// Function: load_prc_file_data
// Description: Another convenience function to load a prc file from
// an explicit string, which represents the contents of
// the prc file.
//
// The first parameter is an arbitrary name to assign to
// this in-memory prc file. Supply a filename if the
// data was read from a file, or use any other name that
// is meaningful to you. The name is only used when the
// set of loaded prc files is listed.
////////////////////////////////////////////////////////////////////
EXPCL_PANDA ConfigPage *
load_prc_file_data(const string &name, const string &data);
////////////////////////////////////////////////////////////////////
// Function: unload_prc_file
// Description: Unloads (and deletes) a ConfigPage that represents a