Panda3D
|
00001 // Filename: cvsSourceTree.h 00002 // Created by: drose (31Oct00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CVSSOURCETREE_H 00016 #define CVSSOURCETREE_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "pvector.h" 00021 #include "pmap.h" 00022 #include "filename.h" 00023 00024 class CVSSourceDirectory; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : CVSSourceTree 00028 // Description : This represents the root of the tree of source 00029 // directory files. 00030 // 00031 // The tree is maintained in a case-insensitive manner, 00032 // even on a non-Windows system, since you might want to 00033 // eventually check out the CVS tree onto a Windows 00034 // system--and if you do, you'll be sad if there are 00035 // case conflicts within the tree. So we make an effort 00036 // to ensure this doesn't happen by treating two files 00037 // with a different case as the same file. 00038 //////////////////////////////////////////////////////////////////// 00039 class CVSSourceTree { 00040 public: 00041 CVSSourceTree(); 00042 ~CVSSourceTree(); 00043 00044 void set_root(const Filename &root_path); 00045 bool scan(const Filename &key_filename); 00046 00047 CVSSourceDirectory *get_root() const; 00048 CVSSourceDirectory *find_directory(const Filename &path); 00049 CVSSourceDirectory *find_relpath(const string &relpath); 00050 CVSSourceDirectory *find_dirname(const string &dirname); 00051 00052 // This nested class represents the selection of a particular 00053 // directory in which to place a given file, given its basename. 00054 // The basename of the file is returned as part of the answer, 00055 // because it might have changed in case from the original basename 00056 // (in order to match the case of an existing file in the selected 00057 // directory). 00058 class FilePath { 00059 public: 00060 FilePath(); 00061 FilePath(CVSSourceDirectory *dir, const string &basename); 00062 bool is_valid() const; 00063 Filename get_path() const; 00064 Filename get_fullpath() const; 00065 Filename get_rel_from(const CVSSourceDirectory *other) const; 00066 00067 CVSSourceDirectory *_dir; 00068 string _basename; 00069 }; 00070 00071 FilePath choose_directory(const string &basename, 00072 CVSSourceDirectory *suggested_dir, 00073 bool force, bool interactive); 00074 00075 Filename get_root_fullpath(); 00076 Filename get_root_dirname() const; 00077 00078 static bool temp_chdir(const Filename &path); 00079 static void restore_cwd(); 00080 00081 public: 00082 void add_file(const string &basename, CVSSourceDirectory *dir); 00083 00084 private: 00085 typedef pvector<FilePath> FilePaths; 00086 00087 FilePath 00088 prompt_user(const string &basename, CVSSourceDirectory *suggested_dir, 00089 const FilePaths &paths, bool force, bool interactive); 00090 00091 FilePath ask_existing(const string &filename, const FilePath &path); 00092 FilePath ask_existing(const string &filename, const FilePaths &paths, 00093 CVSSourceDirectory *suggested_dir); 00094 FilePath ask_new(const string &filename, CVSSourceDirectory *dir); 00095 FilePath ask_any(const string &filename, const FilePaths &paths); 00096 00097 string prompt(const string &message); 00098 00099 static Filename get_actual_fullpath(const Filename &path); 00100 static Filename get_start_fullpath(); 00101 00102 private: 00103 Filename _path; 00104 CVSSourceDirectory *_root; 00105 00106 typedef pmap<string, FilePaths> Basenames; 00107 Basenames _basenames; 00108 00109 static bool _got_start_fullpath; 00110 static Filename _start_fullpath; 00111 bool _got_root_fullpath; 00112 Filename _root_fullpath; 00113 }; 00114 00115 #endif