dSearchPath.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Filename: dSearchPath.h
  2. // Created by: drose (01Jul00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ .
  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. const Filename &get_file(int n) const;
  43. public:
  44. void add_file(const Filename &file);
  45. private:
  46. typedef vector<Filename> Files;
  47. Files _files;
  48. };
  49. PUBLISHED:
  50. DSearchPath();
  51. DSearchPath(const string &path, const string &delimiters = ": \n\t");
  52. DSearchPath(const DSearchPath &copy);
  53. void operator = (const DSearchPath &copy);
  54. ~DSearchPath();
  55. void clear();
  56. void append_directory(const Filename &directory);
  57. void prepend_directory(const Filename &directory);
  58. void append_path(const string &path,
  59. const string &delimiters = ": \n\t");
  60. void append_path(const DSearchPath &path);
  61. void prepend_path(const DSearchPath &path);
  62. bool is_empty() const;
  63. int get_num_directories() const;
  64. const Filename &get_directory(int n) const;
  65. Filename find_file(const Filename &filename) const;
  66. int find_all_files(const Filename &filename, Results &results) const;
  67. INLINE static Filename
  68. search_path(const Filename &filename, const string &path,
  69. const string &delimiters = ": \n\t");
  70. void output(ostream &out, const string &separator = ":") const;
  71. void write(ostream &out, int indent_level = 0) const;
  72. private:
  73. typedef vector<Filename> Directories;
  74. Directories _directories;
  75. };
  76. INLINE ostream &operator << (ostream &out, const DSearchPath &sp) {
  77. sp.output(out);
  78. return out;
  79. }
  80. #include "dSearchPath.I"
  81. #endif