Panda3D
cvsSourceTree.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file cvsSourceTree.h
10  * @author drose
11  * @date 2000-10-31
12  */
13 
14 #ifndef CVSSOURCETREE_H
15 #define CVSSOURCETREE_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "pvector.h"
20 #include "pmap.h"
21 #include "filename.h"
22 
23 class CVSSourceDirectory;
24 
25 /**
26  * This represents the root of the tree of source directory files.
27  *
28  * The tree is maintained in a case-insensitive manner, even on a non-Windows
29  * system, since you might want to eventually check out the CVS tree onto a
30  * Windows system--and if you do, you'll be sad if there are case conflicts
31  * within the tree. So we make an effort to ensure this doesn't happen by
32  * treating two files with a different case as the same file.
33  */
35 public:
36  CVSSourceTree();
37  ~CVSSourceTree();
38 
39  void set_root(const Filename &root_path);
40  bool scan(const Filename &key_filename);
41 
44  CVSSourceDirectory *find_relpath(const std::string &relpath);
45  CVSSourceDirectory *find_dirname(const std::string &dirname);
46 
47  // This nested class represents the selection of a particular directory in
48  // which to place a given file, given its basename. The basename of the
49  // file is returned as part of the answer, because it might have changed in
50  // case from the original basename (in order to match the case of an
51  // existing file in the selected directory).
52  class FilePath {
53  public:
54  FilePath();
55  FilePath(CVSSourceDirectory *dir, const std::string &basename);
56  bool is_valid() const;
57  Filename get_path() const;
58  Filename get_fullpath() const;
59  Filename get_rel_from(const CVSSourceDirectory *other) const;
60 
61  CVSSourceDirectory *_dir;
62  std::string _basename;
63  };
64 
65  FilePath choose_directory(const std::string &basename,
66  CVSSourceDirectory *suggested_dir,
67  bool force, bool interactive);
68 
70  Filename get_root_dirname() const;
71 
72  static bool temp_chdir(const Filename &path);
73  static void restore_cwd();
74 
75 public:
76  void add_file(const std::string &basename, CVSSourceDirectory *dir);
77 
78 private:
80 
81  FilePath
82  prompt_user(const std::string &basename, CVSSourceDirectory *suggested_dir,
83  const FilePaths &paths, bool force, bool interactive);
84 
85  FilePath ask_existing(const std::string &filename, const FilePath &path);
86  FilePath ask_existing(const std::string &filename, const FilePaths &paths,
87  CVSSourceDirectory *suggested_dir);
88  FilePath ask_new(const std::string &filename, CVSSourceDirectory *dir);
89  FilePath ask_any(const std::string &filename, const FilePaths &paths);
90 
91  std::string prompt(const std::string &message);
92 
93  static Filename get_actual_fullpath(const Filename &path);
94  static Filename get_start_fullpath();
95 
96 private:
97  Filename _path;
98  CVSSourceDirectory *_root;
99 
101  Basenames _basenames;
102 
103  static bool _got_start_fullpath;
104  static Filename _start_fullpath;
105  bool _got_root_fullpath;
106  Filename _root_fullpath;
107 };
108 
109 #endif
CVSSourceTree::FilePath::get_fullpath
Filename get_fullpath() const
Returns the full path to this file.
Definition: cvsSourceTree.cxx:533
CVSSourceTree::temp_chdir
static bool temp_chdir(const Filename &path)
Temporarily changes the current directory to the named path.
Definition: cvsSourceTree.cxx:210
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap< std::string, FilePaths >
CVSSourceTree::find_dirname
CVSSourceDirectory * find_dirname(const std::string &dirname)
Returns the source directory that corresponds to the given local directory name, or NULL if there is ...
Definition: cvsSourceTree.cxx:142
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CVSSourceTree::get_root_dirname
Filename get_root_dirname() const
Returns the local directory name of the root of the tree.
Definition: cvsSourceTree.cxx:189
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CVSSourceDirectory
This represents one particular directory in the hierarchy of source directory files.
Definition: cvsSourceDirectory.h:35
CVSSourceTree::set_root
void set_root(const Filename &root_path)
Sets the root of the source directory.
Definition: cvsSourceTree.cxx:60
CVSSourceTree::get_root_fullpath
Filename get_root_fullpath()
Returns the full path from the root to the top of the source hierarchy.
Definition: cvsSourceTree.cxx:176
CVSSourceTree::find_relpath
CVSSourceDirectory * find_relpath(const std::string &relpath)
Returns the source directory that corresponds to the given relative path from the root,...
Definition: cvsSourceTree.cxx:115
CVSSourceTree::find_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...
Definition: cvsSourceTree.cxx:91
CVSSourceTree
This represents the root of the tree of source directory files.
Definition: cvsSourceTree.h:34
CVSSourceTree::FilePath
Definition: cvsSourceTree.h:52
CVSSourceTree::FilePath::get_path
Filename get_path() const
Returns the relative path to this file from the root of the source tree.
Definition: cvsSourceTree.cxx:524
CVSSourceTree::restore_cwd
static void restore_cwd()
Restores the current directory after changing it from temp_chdir().
Definition: cvsSourceTree.cxx:226
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CVSSourceTree::add_file
void add_file(const std::string &basename, CVSSourceDirectory *dir)
Adds a new file to the set of known files.
Definition: cvsSourceTree.cxx:199
CVSSourceTree::FilePath::FilePath
FilePath()
Creates an invalid FilePath specification.
Definition: cvsSourceTree.cxx:495
CVSSourceTree::get_root
CVSSourceDirectory * get_root() const
Returns the root directory of the hierarchy.
Definition: cvsSourceTree.cxx:82
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
CVSSourceTree::choose_directory
FilePath choose_directory(const std::string &basename, CVSSourceDirectory *suggested_dir, bool force, bool interactive)
Determines where an externally referenced model file of the indicated name should go.
Definition: cvsSourceTree.cxx:153
CVSSourceTree::FilePath::is_valid
bool is_valid() const
Returns true if this FilePath represents a valid file, or false if it represents an error return.
Definition: cvsSourceTree.cxx:516
CVSSourceTree::FilePath::get_rel_from
Filename get_rel_from(const CVSSourceDirectory *other) const
Returns the relative path to this file as seen from the indicated source directory.
Definition: cvsSourceTree.cxx:543
CVSSourceTree::scan
bool scan(const Filename &key_filename)
Scans the complete source directory starting at the indicated pathname.
Definition: cvsSourceTree.cxx:71