Panda3D
Loading...
Searching...
No Matches
filenameUnifier.cxx
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 filenameUnifier.cxx
10 * @author drose
11 * @date 2000-12-05
12 */
13
14#include "filenameUnifier.h"
15
17
18Filename FilenameUnifier::_txa_filename;
19Filename FilenameUnifier::_txa_dir;
20Filename FilenameUnifier::_rel_dirname;
21
22FilenameUnifier::CanonicalFilenames FilenameUnifier::_canonical_filenames;
23
24/**
25 * Notes the filename the .txa file was found in. This may have come from the
26 * command line, or it may have been implicitly located. This has other
27 * implications for the FilenameUnifier, particularly in locating the bam file
28 * that saves the filenameUnifier state from last session.
29 */
31set_txa_filename(const Filename &txa_filename) {
32 _txa_filename = txa_filename;
33 _txa_dir = txa_filename.get_dirname();
34 if (_txa_dir.empty()) {
35 _txa_dir = ".";
36 }
37 make_canonical(_txa_dir);
38}
39
40/**
41 * Sets the name of the directory that texture filenames will be written
42 * relative to, when generating egg files. This is not the directory the
43 * textures are actually written to (see set_map_dirname()), but rather is the
44 * name of some directory above that, which will be the starting point for the
45 * pathnames written to the egg files. If this is empty, the full pathnames
46 * will be written to the egg files.
47 */
49set_rel_dirname(const Filename &rel_dirname) {
50 _rel_dirname = rel_dirname;
51 if (!_rel_dirname.empty()) {
52 make_canonical(_rel_dirname);
53 }
54}
55
56/**
57 * Returns a new filename that's made relative to the bam file itself,
58 * suitable for writing to the bam file.
59 */
62 make_canonical(filename);
63 filename.make_relative_to(_txa_dir);
64 return filename;
65}
66
67/**
68 * Returns an absolute pathname based on the given relative pathname,
69 * presumably read from the bam file and relative to the bam file.
70 */
72get_bam_filename(Filename filename) {
73 if (!filename.empty()) {
74 filename.make_absolute(_txa_dir);
75 }
76 return filename;
77}
78
79/**
80 * Returns a new filename that's made relative to the rel_directory, suitable
81 * for writing out within egg files.
82 */
85 if (!filename.empty()) {
86 make_canonical(filename);
87 filename.make_relative_to(_rel_dirname);
88 }
89 return filename;
90}
91
92/**
93 * Returns a new filename that's made relative to the current directory,
94 * suitable for reporting to the user.
95 */
98 if (!filename.empty()) {
99 make_canonical(filename);
101 }
102 return filename;
103}
104
105/**
106 * Does the same thing as Filename::make_canonical()--it converts the filename
107 * to its canonical form--but caches the operation so that repeated calls to
108 * filenames in the same directory will tend to be faster.
109 */
111make_canonical(Filename &filename) {
112 if (filename.empty()) {
113 return;
114 }
115
116 Filename orig_dirname = filename.get_dirname();
117
118 CanonicalFilenames::iterator fi;
119 fi = _canonical_filenames.find(orig_dirname);
120 if (fi != _canonical_filenames.end()) {
121 filename.set_dirname((*fi).second);
122 return;
123 }
124
125 Filename new_dirname = orig_dirname;
126 if (new_dirname.empty()) {
127 new_dirname = ".";
128 }
129 new_dirname.make_canonical();
130 filename.set_dirname(new_dirname);
131
132 _canonical_filenames.insert(CanonicalFilenames::value_type(orig_dirname, new_dirname));
133}
get_cwd
Returns the name of the current working directory.
static void set_txa_filename(const Filename &txa_filename)
Notes the filename the .txa file was found in.
static Filename get_bam_filename(Filename filename)
Returns an absolute pathname based on the given relative pathname, presumably read from the bam file ...
static Filename make_bam_filename(Filename filename)
Returns a new filename that's made relative to the bam file itself, suitable for writing to the bam f...
static void set_rel_dirname(const Filename &rel_dirname)
Sets the name of the directory that texture filenames will be written relative to,...
static void make_canonical(Filename &filename)
Does the same thing as Filename::make_canonical()–it converts the filename to its canonical form–but ...
static Filename make_user_filename(Filename filename)
Returns a new filename that's made relative to the current directory, suitable for reporting to the u...
static Filename make_egg_filename(Filename filename)
Returns a new filename that's made relative to the rel_directory, suitable for writing out within egg...
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
void set_dirname(const std::string &s)
Replaces the directory part of the filename.
Definition filename.cxx:704
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
bool make_relative_to(Filename directory, bool allow_backups=true)
Adjusts this filename, which must be a fully-specified pathname beginning with a slash,...
std::string get_dirname() const
Returns the directory part of the filename.
Definition filename.I:358
void make_absolute()
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname),...
Definition filename.cxx:968
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.