dSearchPath.h 2.7 KB

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