Browse Source

add load_prc_file_data

David Rose 21 years ago
parent
commit
6ac53b826a

+ 7 - 0
panda/src/doc/howto.use_config.txt

@@ -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
 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).
 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
 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
 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
 via load_prc_file(), as well as files found in the standard prc file

+ 32 - 0
panda/src/putil/load_prc_file.cxx

@@ -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
 //     Function: unload_prc_file
 //  Description: Unloads (and deletes) a ConfigPage that represents a
 //  Description: Unloads (and deletes) a ConfigPage that represents a

+ 15 - 0
panda/src/putil/load_prc_file.h

@@ -45,6 +45,21 @@ BEGIN_PUBLISH
 EXPCL_PANDA ConfigPage *
 EXPCL_PANDA ConfigPage *
 load_prc_file(const string &filename);
 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
 //     Function: unload_prc_file
 //  Description: Unloads (and deletes) a ConfigPage that represents a
 //  Description: Unloads (and deletes) a ConfigPage that represents a