Panda3D
 All Classes Functions Variables Enumerations
cvsSourceTree.h
1 // Filename: cvsSourceTree.h
2 // Created by: drose (31Oct00)
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 
15 #ifndef CVSSOURCETREE_H
16 #define CVSSOURCETREE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "pvector.h"
21 #include "pmap.h"
22 #include "filename.h"
23 
24 class CVSSourceDirectory;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : CVSSourceTree
28 // Description : This represents the root of the tree of source
29 // directory files.
30 //
31 // The tree is maintained in a case-insensitive manner,
32 // even on a non-Windows system, since you might want to
33 // eventually check out the CVS tree onto a Windows
34 // system--and if you do, you'll be sad if there are
35 // case conflicts within the tree. So we make an effort
36 // to ensure this doesn't happen by treating two files
37 // with a different case as the same file.
38 ////////////////////////////////////////////////////////////////////
40 public:
41  CVSSourceTree();
42  ~CVSSourceTree();
43 
44  void set_root(const Filename &root_path);
45  bool scan(const Filename &key_filename);
46 
49  CVSSourceDirectory *find_relpath(const string &relpath);
50  CVSSourceDirectory *find_dirname(const string &dirname);
51 
52  // This nested class represents the selection of a particular
53  // directory in which to place a given file, given its basename.
54  // The basename of the file is returned as part of the answer,
55  // because it might have changed in case from the original basename
56  // (in order to match the case of an existing file in the selected
57  // directory).
58  class FilePath {
59  public:
60  FilePath();
61  FilePath(CVSSourceDirectory *dir, const string &basename);
62  bool is_valid() const;
63  Filename get_path() const;
64  Filename get_fullpath() const;
65  Filename get_rel_from(const CVSSourceDirectory *other) const;
66 
67  CVSSourceDirectory *_dir;
68  string _basename;
69  };
70 
71  FilePath choose_directory(const string &basename,
72  CVSSourceDirectory *suggested_dir,
73  bool force, bool interactive);
74 
76  Filename get_root_dirname() const;
77 
78  static bool temp_chdir(const Filename &path);
79  static void restore_cwd();
80 
81 public:
82  void add_file(const string &basename, CVSSourceDirectory *dir);
83 
84 private:
86 
87  FilePath
88  prompt_user(const string &basename, CVSSourceDirectory *suggested_dir,
89  const FilePaths &paths, bool force, bool interactive);
90 
91  FilePath ask_existing(const string &filename, const FilePath &path);
92  FilePath ask_existing(const string &filename, const FilePaths &paths,
93  CVSSourceDirectory *suggested_dir);
94  FilePath ask_new(const string &filename, CVSSourceDirectory *dir);
95  FilePath ask_any(const string &filename, const FilePaths &paths);
96 
97  string prompt(const string &message);
98 
99  static Filename get_actual_fullpath(const Filename &path);
100  static Filename get_start_fullpath();
101 
102 private:
103  Filename _path;
104  CVSSourceDirectory *_root;
105 
107  Basenames _basenames;
108 
109  static bool _got_start_fullpath;
110  static Filename _start_fullpath;
111  bool _got_root_fullpath;
112  Filename _root_fullpath;
113 };
114 
115 #endif
Filename get_fullpath() const
Returns the full path to this file.
FilePath choose_directory(const string &basename, CVSSourceDirectory *suggested_dir, bool force, bool interactive)
Determines where an externally referenced model file of the indicated name should go...
void set_root(const Filename &root_path)
Sets the root of the source directory.
Filename get_root_fullpath()
Returns the full path from the root to the top of the source hierarchy.
Filename get_rel_from(const CVSSourceDirectory *other) const
Returns the relative path to this file as seen from the indicated source directory.
CVSSourceDirectory * find_directory(const Filename &path)
Returns the source directory that corresponds to the given path, or NULL if there is no such director...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
CVSSourceDirectory * find_dirname(const string &dirname)
Returns the source directory that corresponds to the given local directory name, or NULL if there is ...
CVSSourceDirectory * get_root() const
Returns the root directory of the hierarchy.
CVSSourceDirectory * find_relpath(const string &relpath)
Returns the source directory that corresponds to the given relative path from the root...
This represents one particular directory in the hierarchy of source directory files.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This represents the root of the tree of source directory files.
Definition: cvsSourceTree.h:39
Filename get_path() const
Returns the relative path to this file from the root of the source tree.
void add_file(const string &basename, CVSSourceDirectory *dir)
Adds a new file to the set of known files.
static bool temp_chdir(const Filename &path)
Temporarily changes the current directory to the named path.
Filename get_root_dirname() const
Returns the local directory name of the root of the tree.
bool scan(const Filename &key_filename)
Scans the complete source directory starting at the indicated pathname.
bool is_valid() const
Returns true if this FilePath represents a valid file, or false if it represents an error return...
static void restore_cwd()
Restores the current directory after changing it from temp_chdir().
FilePath()
Creates an invalid FilePath specification.