Panda3D
|
00001 // Filename: dSearchPath.h 00002 // Created by: drose (01Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PANDASEARCHPATH_H 00016 #define PANDASEARCHPATH_H 00017 00018 #include "dtoolbase.h" 00019 00020 #include "filename.h" 00021 #include "pvector.h" 00022 00023 /////////////////////////////////////////////////////////////////// 00024 // Class : DSearchPath 00025 // Description : This class stores a list of directories that can be 00026 // searched, in order, to locate a particular file. It 00027 // is normally constructed by passing it a traditional 00028 // searchpath-style string, e.g. a list of directory 00029 // names delimited by spaces or colons, but it can also 00030 // be built up explicitly. 00031 //////////////////////////////////////////////////////////////////// 00032 class EXPCL_DTOOL DSearchPath { 00033 PUBLISHED: 00034 class EXPCL_DTOOL Results { 00035 PUBLISHED: 00036 Results(); 00037 Results(const Results ©); 00038 void operator = (const Results ©); 00039 ~Results(); 00040 00041 void clear(); 00042 int get_num_files() const; 00043 const Filename &get_file(int n) const; 00044 00045 INLINE Filename operator [] (int n) const; 00046 INLINE int size() const; 00047 00048 void output(ostream &out) const; 00049 void write(ostream &out, int indent_level = 0) const; 00050 00051 public: 00052 void add_file(const Filename &file); 00053 00054 private: 00055 typedef pvector<Filename> Files; 00056 Files _files; 00057 }; 00058 00059 DSearchPath(); 00060 DSearchPath(const string &path, const string &separator = string()); 00061 DSearchPath(const Filename &directory); 00062 DSearchPath(const DSearchPath ©); 00063 void operator = (const DSearchPath ©); 00064 ~DSearchPath(); 00065 00066 void clear(); 00067 void append_directory(const Filename &directory); 00068 void prepend_directory(const Filename &directory); 00069 void append_path(const string &path, 00070 const string &separator = string()); 00071 void append_path(const DSearchPath &path); 00072 void prepend_path(const DSearchPath &path); 00073 00074 bool is_empty() const; 00075 int get_num_directories() const; 00076 const Filename &get_directory(int n) const; 00077 MAKE_SEQ(get_directories, get_num_directories, get_directory); 00078 00079 Filename find_file(const Filename &filename) const; 00080 int find_all_files(const Filename &filename, Results &results) const; 00081 INLINE Results find_all_files(const Filename &filename) const; 00082 00083 INLINE static Filename 00084 search_path(const Filename &filename, const string &path, 00085 const string &separator = string()); 00086 00087 void output(ostream &out, const string &separator = string()) const; 00088 void write(ostream &out, int indent_level = 0) const; 00089 00090 private: 00091 typedef pvector<Filename> Directories; 00092 Directories _directories; 00093 }; 00094 00095 INLINE ostream &operator << (ostream &out, const DSearchPath &sp) { 00096 sp.output(out); 00097 return out; 00098 } 00099 00100 #include "dSearchPath.I" 00101 00102 #endif