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
bool is_valid() const
Returns true if this FilePath represents a valid file, or false if it represents an error return.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_file(const std::string &basename, CVSSourceDirectory *dir)
Adds a new file to the set of known files.
Filename get_root_dirname() const
Returns the local directory name of the root of the tree.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename get_path() const
Returns the relative path to this file from the root of the source tree.
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:42
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:39
CVSSourceDirectory * find_dirname(const std::string &dirname)
Returns the source directory that corresponds to the given local directory name, or NULL if there is ...
This represents the root of the tree of source directory files.
Definition: cvsSourceTree.h:34
static bool temp_chdir(const Filename &path)
Temporarily changes the current directory to the named path.
CVSSourceDirectory * find_relpath(const std::string &relpath)
Returns the source directory that corresponds to the given relative path from the root,...
bool scan(const Filename &key_filename)
Scans the complete source directory starting at the indicated pathname.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename get_fullpath() const
Returns the full path to this file.
Filename get_rel_from(const CVSSourceDirectory *other) const
Returns the relative path to this file as seen from the indicated source directory.
static void restore_cwd()
Restores the current directory after changing it from temp_chdir().
FilePath()
Creates an invalid FilePath specification.
CVSSourceDirectory * get_root() const
Returns the root directory of the hierarchy.