dSearchPath.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Filename: dSearchPath.h
  2. // Created by: drose (01Jul00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef PANDASEARCHPATH_H
  19. #define PANDASEARCHPATH_H
  20. #include "ppremake.h"
  21. #include "filename.h"
  22. #include <vector>
  23. ///////////////////////////////////////////////////////////////////
  24. // Class : DSearchPath
  25. // Description : This class stores a list of directories that can be
  26. // searched, in order, to locate a particular file. It
  27. // is normally constructed by passing it a traditional
  28. // searchpath-style string, e.g. a list of directory
  29. // names delimited by spaces or colons, but it can also
  30. // be built up explicitly.
  31. ////////////////////////////////////////////////////////////////////
  32. class EXPCL_DTOOL DSearchPath {
  33. public:
  34. class EXPCL_DTOOL Results {
  35. PUBLISHED:
  36. Results();
  37. Results(const Results &copy);
  38. void operator = (const Results &copy);
  39. ~Results();
  40. void clear();
  41. int get_num_files() const;
  42. Filename get_file(int n) const;
  43. private:
  44. typedef vector<Filename> Files;
  45. Files _files;
  46. friend class DSearchPath;
  47. };
  48. PUBLISHED:
  49. DSearchPath();
  50. DSearchPath(const string &path, const string &delimiters = ": \n\t");
  51. DSearchPath(const DSearchPath &copy);
  52. void operator = (const DSearchPath &copy);
  53. ~DSearchPath();
  54. void clear();
  55. void append_directory(const Filename &directory);
  56. void prepend_directory(const Filename &directory);
  57. void append_path(const string &path,
  58. const string &delimiters = ": \n\t");
  59. void append_path(const DSearchPath &path);
  60. void prepend_path(const DSearchPath &path);
  61. bool is_empty() const;
  62. int get_num_directories() const;
  63. Filename get_directory(int n) const;
  64. Filename find_file(const Filename &filename) const;
  65. int find_all_files(const Filename &filename, Results &results) const;
  66. INLINE static Filename
  67. search_path(const Filename &filename, const string &path,
  68. const string &delimiters = ": \n\t");
  69. void output(ostream &out, const string &separator = ":") const;
  70. void write(ostream &out, int indent_level = 0) const;
  71. private:
  72. typedef vector<Filename> Directories;
  73. Directories _directories;
  74. };
  75. INLINE ostream &operator << (ostream &out, const DSearchPath &sp) {
  76. sp.output(out);
  77. return out;
  78. }
  79. #include "dSearchPath.I"
  80. #endif