Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/dtoolutil/dSearchPath.h

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

Generated on Thu May 1 22:12:58 2003 for DTool by doxygen1.3