1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
// os_path header.
// Copyright (c) 1994,1995,1996 by ObjectSpace, Inc. All rights reserved.
// Email: sales@objectspace.com, ccs.support@objectspace.com
// Last Modified: $Date: 9/10/01 5:06p $
#ifndef OS_FILE_PATH_H
#define OS_FILE_PATH_H
#include <ospace/config.h>
// SYNOPSIS:
// A file system path.
// DESCRIPTION:
// The class `os_path` allows file system paths to be manipulated.
// Conversions allow `os_paths` and `const char*`s to be used interchangeably.
#include <ospace/std/iosfwd>
#include <ospace/std/string>
class os_bstream;
class OS_PUBLIC os_path
{
private:
// This member is first to work-around a bug in the Sun 4.0.1 compiler.
os_string data_;
char path_separator_;
char drive_separator_;
char extension_separator_;
friend void os_write( os_bstream&, const os_path& );
friend void os_read( os_bstream&, os_path& );
public:
// Destructor
virtual ~os_path () {};
// Constructors.
inline os_path();
os_path( const os_string& filepath );
os_path( const os_string& dirpath, const os_string& filename );
os_path
(
const os_string& dirpath,
const os_string& base,
const os_string& extension
);
os_path
(
char drive,
const os_string& dirpath,
const os_string& filename
);
os_path
(
char drive,
const os_string& dirpath,
const os_string& base,
const os_string& extension
);
os_path
(
const os_string& servername,
const os_string& sharename,
const os_string& dirpath,
const os_string& filename
);
os_path
(
const os_string& servername,
const os_string& sharename,
const os_string& dirpath,
const os_string& base,
const os_string& extension
);
os_path( const os_path& path );
// Comparison
bool operator==( const os_path& path ) const;
bool operator==( const os_string& string ) const;
bool operator!=( const os_path& path ) const;
bool operator!=( const os_string& string ) const;
bool operator<( const os_path& path ) const;
bool operator<( const os_string& string ) const;
// Assignment.
os_path& operator=( const os_string& filepath );
os_path& operator=( const os_path& path );
// Conversion.
operator const char*() const;
operator const os_string&() const;
// Testing.
bool absolute() const;
bool relative() const;
bool file_path() const;
bool directory_path() const;
bool has_directory() const;
bool has_extension() const;
bool has_drive() const;
bool has_unc() const;
// Components.
int levels() const;
bool legal( int index ) const;
os_string operator[]( int index ) const;
// Accessors.
os_string directory() const;
os_string filename() const;
os_string head() const;
os_string tail() const;
os_string base() const;
os_string extension() const;
os_string drive() const;
os_string unc() const;
os_string server() const;
os_string share() const;
char path_separator() const;
char drive_separator() const;
char extension_separator() const;
// Modifiers.
os_path& directory( os_string string );
os_path& head( const os_string& string );
os_path& tail( const os_string& string );
os_path& section( int index, const os_string& string );
os_path& filename( const os_string& string );
os_path& base( const os_string& string );
os_path& extension( const os_string& string );
os_path& unc( const os_string& server, const os_string& share );
os_path& server( const os_string& string );
os_path& share( const os_string& string );
os_path& drive( char drive );
os_path& no_extension();
os_path& no_drive();
os_path& no_unc();
os_path& cd( os_string dirpath );
os_path& path_separator( char separator );
os_path& drive_separator( char separator );
os_path& extension_separator( char separator );
// cd.
os_path cd( os_string dirpath ) const;
// Simplifying.
os_path simplified() const;
void become_simplified();
// Relative conversion.
os_path relative_to( const os_string& dirpath ) const;
void become_relative_to( const os_string& dirpath );
// Special name testing.
static bool is_dot_directory( const os_string& name );
// Printing.
void print( os_ostream& stream ) const;
// Static accessors.
static char default_path_separator();
protected:
// Helpers.
static void validate_drive_letter( char drive );
os_string make_unc
(
const os_string& server,
const os_string& share
) const;
void proper_path_form(
os_string&,
bool ensure_leading_separator = false
) const;
size_t locate_dir_sep() const;
// Directory section access.
os_string section( int index, bool absolute = false ) const;
int absolute_levels() const;
size_t find_directory( size_t& length ) const;
size_t find_section( int index, size_t& length ) const;
void init_separators();
// Common finds.
size_t last_extension_separator() const;
};
#include <ospace/file/path.ipp>
#endif
|