diff --git a/dtool/src/dtoolutil/dSearchPath.I b/dtool/src/dtoolutil/dSearchPath.I index f5982b17bd..15bc87241b 100644 --- a/dtool/src/dtoolutil/dSearchPath.I +++ b/dtool/src/dtoolutil/dSearchPath.I @@ -13,9 +13,48 @@ //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::Results::operator [] +// Access: Published +// Description: Returns the nth filename in the set. This method is +// defined to make the Results object appear to be a +// list in Python. +//////////////////////////////////////////////////////////////////// +INLINE Filename DSearchPath::Results:: +operator [] (int n) const { + return get_file(n); +} + +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::Results::size +// Access: Published +// Description: Returns the num of filenames in the set. This method +// is defined to make the Results object appear to be a +// list in Python. +//////////////////////////////////////////////////////////////////// +INLINE int DSearchPath::Results:: +size() const { + return get_num_files(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::find_all_files +// Access: Published +// Description: This variant of find_all_files() returns the new +// Results object, instead of filling on in on the +// parameter list. This is a little more convenient to +// call from Python. +//////////////////////////////////////////////////////////////////// +INLINE DSearchPath::Results DSearchPath:: +find_all_files(const Filename &filename) const { + Results results; + find_all_files(filename, results); + return results; +} + //////////////////////////////////////////////////////////////////// // Function: DSearchPath::search_path -// Access: Public, Static +// Access: Published, Static // Description: A quick-and-easy way to search a searchpath for a // file when you don't feel like building or keeping // around a DSearchPath object. This simply diff --git a/dtool/src/dtoolutil/dSearchPath.cxx b/dtool/src/dtoolutil/dSearchPath.cxx index 894dcb4a82..1c04b4407d 100644 --- a/dtool/src/dtoolutil/dSearchPath.cxx +++ b/dtool/src/dtoolutil/dSearchPath.cxx @@ -19,7 +19,7 @@ //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath::Results:: @@ -28,7 +28,7 @@ Results() { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::Copy Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath::Results:: @@ -39,7 +39,7 @@ Results(const DSearchPath::Results ©) : //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::Copy Assignment Operator -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void DSearchPath::Results:: @@ -49,7 +49,7 @@ operator = (const DSearchPath::Results ©) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::Destructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath::Results:: @@ -58,7 +58,7 @@ DSearchPath::Results:: //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::clear -// Access: Public +// Access: Published // Description: Removes all the files from the list. //////////////////////////////////////////////////////////////////// void DSearchPath::Results:: @@ -68,7 +68,7 @@ clear() { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::get_num_files -// Access: Public +// Access: Published // Description: Returns the number of files on the result list. //////////////////////////////////////////////////////////////////// int DSearchPath::Results:: @@ -78,7 +78,7 @@ get_num_files() const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::get_file -// Access: Public +// Access: Published // Description: Returns the nth file on the result list. //////////////////////////////////////////////////////////////////// const Filename &DSearchPath::Results:: @@ -89,7 +89,7 @@ get_file(int n) const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Results::add_file -// Access: Public +// Access: Published // Description: Adds a new file to the result list. //////////////////////////////////////////////////////////////////// void DSearchPath::Results:: @@ -97,9 +97,45 @@ add_file(const Filename &file) { _files.push_back(file); } +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::Results::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void DSearchPath::Results:: +output(ostream &out) const { + out << "[ "; + if (!_files.empty()) { + Files::const_iterator fi = _files.begin(); + out << (*fi); + ++fi; + while (fi != _files.end()) { + out << ", " << (*fi); + ++fi; + } + } + out << " ]"; +} + +//////////////////////////////////////////////////////////////////// +// Function: DSearchPath::Results::write +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void DSearchPath::Results:: +write(ostream &out, int indent_level) const { + Files::const_iterator fi; + for (fi = _files.begin(); fi != _files.end(); ++fi) { + for (int i = 0; i < indent_level; ++i) { + out << ' '; + } + out << (*fi) << "\n"; + } +} + //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Default Constructor -// Access: Public +// Access: Published // Description: Creates an empty search path. //////////////////////////////////////////////////////////////////// DSearchPath:: @@ -108,7 +144,7 @@ DSearchPath() { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath:: @@ -118,7 +154,7 @@ DSearchPath(const string &path, const string &separator) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath:: @@ -128,7 +164,7 @@ DSearchPath(const Filename &directory) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Copy Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath:: @@ -139,7 +175,7 @@ DSearchPath(const DSearchPath ©) : //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Copy Assignment Operator -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void DSearchPath:: @@ -149,7 +185,7 @@ operator = (const DSearchPath ©) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::Destructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// DSearchPath:: @@ -158,7 +194,7 @@ DSearchPath:: //////////////////////////////////////////////////////////////////// // Function: DSearchPath::clear -// Access: Public +// Access: Published // Description: Removes all the directories from the search list. //////////////////////////////////////////////////////////////////// void DSearchPath:: @@ -168,7 +204,7 @@ clear() { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::append_directory -// Access: Public +// Access: Published // Description: Adds a new directory to the end of the search list. //////////////////////////////////////////////////////////////////// void DSearchPath:: @@ -178,7 +214,7 @@ append_directory(const Filename &directory) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::prepend_directory -// Access: Public +// Access: Published // Description: Adds a new directory to the front of the search list. //////////////////////////////////////////////////////////////////// void DSearchPath:: @@ -188,7 +224,7 @@ prepend_directory(const Filename &directory) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::append_path -// Access: Public +// Access: Published // Description: Adds all of the directories listed in the search path // to the end of the search list. //////////////////////////////////////////////////////////////////// @@ -220,7 +256,7 @@ append_path(const string &path, const string &separator) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::append_path -// Access: Public +// Access: Published // Description: Adds all of the directories listed in the search path // to the end of the search list. //////////////////////////////////////////////////////////////////// @@ -232,7 +268,7 @@ append_path(const DSearchPath &path) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::prepend_path -// Access: Public +// Access: Published // Description: Adds all of the directories listed in the search path // to the beginning of the search list. //////////////////////////////////////////////////////////////////// @@ -248,7 +284,7 @@ prepend_path(const DSearchPath &path) { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::is_empty -// Access: Public +// Access: Published // Description: Returns true if the search list is empty, false // otherwise. //////////////////////////////////////////////////////////////////// @@ -259,7 +295,7 @@ is_empty() const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::get_num_directories -// Access: Public +// Access: Published // Description: Returns the number of directories on the search list. //////////////////////////////////////////////////////////////////// int DSearchPath:: @@ -269,7 +305,7 @@ get_num_directories() const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::get_directory -// Access: Public +// Access: Published // Description: Returns the nth directory on the search list. //////////////////////////////////////////////////////////////////// const Filename &DSearchPath:: @@ -280,7 +316,7 @@ get_directory(int n) const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::find_file -// Access: Public +// Access: Published // Description: Searches all the directories in the search list for // the indicated file, in order. Returns the full // matching pathname of the first match if found, or the @@ -321,7 +357,7 @@ find_file(const Filename &filename) const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::find_all_files -// Access: Public +// Access: Published // Description: Searches all the directories in the search list for // the indicated file, in order. Fills up the results // list with *all* of the matching filenames found, if @@ -370,7 +406,7 @@ find_all_files(const Filename &filename, //////////////////////////////////////////////////////////////////// // Function: DSearchPath::output -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void DSearchPath:: @@ -396,7 +432,7 @@ output(ostream &out, const string &separator) const { //////////////////////////////////////////////////////////////////// // Function: DSearchPath::write -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void DSearchPath:: diff --git a/dtool/src/dtoolutil/dSearchPath.h b/dtool/src/dtoolutil/dSearchPath.h index 92b00c4a8d..e61e4c5f41 100644 --- a/dtool/src/dtoolutil/dSearchPath.h +++ b/dtool/src/dtoolutil/dSearchPath.h @@ -30,7 +30,7 @@ // be built up explicitly. //////////////////////////////////////////////////////////////////// class EXPCL_DTOOL DSearchPath { -public: +PUBLISHED: class EXPCL_DTOOL Results { PUBLISHED: Results(); @@ -42,6 +42,12 @@ public: int get_num_files() const; const Filename &get_file(int n) const; + INLINE Filename operator [] (int n) const; + INLINE int size() const; + + void output(ostream &out) const; + void write(ostream &out, int indent_level = 0) const; + public: void add_file(const Filename &file); @@ -50,7 +56,6 @@ public: Files _files; }; -PUBLISHED: DSearchPath(); DSearchPath(const string &path, const string &separator = string()); DSearchPath(const Filename &directory); @@ -73,6 +78,7 @@ PUBLISHED: Filename find_file(const Filename &filename) const; int find_all_files(const Filename &filename, Results &results) const; + INLINE Results find_all_files(const Filename &filename) const; INLINE static Filename search_path(const Filename &filename, const string &path, diff --git a/dtool/src/prc/configVariableSearchPath.I b/dtool/src/prc/configVariableSearchPath.I index 10c7401cc0..395e23a9f9 100644 --- a/dtool/src/prc/configVariableSearchPath.I +++ b/dtool/src/prc/configVariableSearchPath.I @@ -286,6 +286,19 @@ find_all_files(const Filename &filename, return get_value().find_all_files(filename, results); } +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableSearchPath::find_all_files +// Access: Published +// Description: This variant of find_all_files() returns the new +// Results object, instead of filling on in on the +// parameter list. This is a little more convenient to +// call from Python. +//////////////////////////////////////////////////////////////////// +INLINE DSearchPath::Results ConfigVariableSearchPath:: +find_all_files(const Filename &filename) const { + return get_value().find_all_files(filename); +} + //////////////////////////////////////////////////////////////////// // Function: ConfigVariableSearchPath::output // Access: Published diff --git a/dtool/src/prc/configVariableSearchPath.h b/dtool/src/prc/configVariableSearchPath.h index d599770d2a..8dca25ad7d 100644 --- a/dtool/src/prc/configVariableSearchPath.h +++ b/dtool/src/prc/configVariableSearchPath.h @@ -76,6 +76,7 @@ PUBLISHED: INLINE Filename find_file(const Filename &filename) const; INLINE int find_all_files(const Filename &filename, DSearchPath::Results &results) const; + INLINE DSearchPath::Results find_all_files(const Filename &filename) const; INLINE void output(ostream &out) const; INLINE void write(ostream &out) const;