dSearchPath.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #define pvector std::vector
  24. ///////////////////////////////////////////////////////////////////
  25. // Class : DSearchPath
  26. // Description : This class stores a list of directories that can be
  27. // searched, in order, to locate a particular file. It
  28. // is normally constructed by passing it a traditional
  29. // searchpath-style string, e.g. a list of directory
  30. // names delimited by spaces or colons, but it can also
  31. // be built up explicitly.
  32. ////////////////////////////////////////////////////////////////////
  33. class EXPCL_DTOOL DSearchPath {
  34. public:
  35. class EXPCL_DTOOL Results {
  36. PUBLISHED:
  37. Results();
  38. Results(const Results &copy);
  39. void operator = (const Results &copy);
  40. ~Results();
  41. void clear();
  42. int get_num_files() const;
  43. const Filename &get_file(int n) const;
  44. public:
  45. void add_file(const Filename &file);
  46. private:
  47. typedef pvector<Filename> Files;
  48. Files _files;
  49. };
  50. PUBLISHED:
  51. DSearchPath();
  52. DSearchPath(const string &path, const string &delimiters = ": \n\t");
  53. DSearchPath(const DSearchPath &copy);
  54. void operator = (const DSearchPath &copy);
  55. ~DSearchPath();
  56. void clear();
  57. void append_directory(const Filename &directory);
  58. void prepend_directory(const Filename &directory);
  59. void append_path(const string &path,
  60. const string &delimiters = ": \n\t");
  61. void append_path(const DSearchPath &path);
  62. void prepend_path(const DSearchPath &path);
  63. bool is_empty() const;
  64. int get_num_directories() const;
  65. const Filename &get_directory(int n) const;
  66. Filename find_file(const Filename &filename) const;
  67. int find_all_files(const Filename &filename, Results &results) const;
  68. INLINE static Filename
  69. search_path(const Filename &filename, const string &path,
  70. const string &delimiters = ": \n\t");
  71. void output(ostream &out, const string &separator = ":") const;
  72. void write(ostream &out, int indent_level = 0) const;
  73. private:
  74. typedef pvector<Filename> Directories;
  75. Directories _directories;
  76. };
  77. INLINE ostream &operator << (ostream &out, const DSearchPath &sp) {
  78. sp.output(out);
  79. return out;
  80. }
  81. #include "dSearchPath.I"
  82. #endif