Umasoft
Main Page
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Groups
Pages
TerrainSDK
vtdata
FilePath.h
Go to the documentation of this file.
1
//
2
// FilePath.h
3
//
4
// Copyright (c) 2002-2008 Virtual Terrain Project
5
// Free for all uses, see license.txt for details.
6
//
9
#ifndef FILEPATHH
10
#define FILEPATHH
11
12
#include "vtString.h"
13
14
#include "zlib.h"
15
16
#if SUPPORT_BZIP2
17
#ifndef _BZLIB_H
18
typedef
void
BZFILE;
19
#endif
20
#endif
21
22
#include <fstream>
23
24
#ifdef WIN32
25
#include <io.h>
26
#else
27
#include <sys/stat.h>
28
#include <dirent.h>
29
#include <unistd.h>
30
#include <pwd.h>
31
#include <grp.h>
32
#endif
33
50
class
dir_iter
51
{
52
public
:
53
dir_iter
();
54
dir_iter
(std::string
const
&dirname);
55
~
dir_iter
();
56
58
bool
is_directory
();
59
61
bool
is_hidden
();
62
64
std::string
filename
();
65
66
// Iterate the object to the next file/directory.
67
void
operator++();
68
69
// Test for inequality useful to test when iteration is finished.
70
bool
operator!=(
const
dir_iter
&it);
71
72
private
:
73
#ifdef WIN32
74
#if SUPPORT_WSTRING
75
struct
_wfinddata_t m_data;
76
#else
77
struct
_finddata_t m_data;
78
#endif
79
long
m_handle;
80
#else
81
DIR *m_handle;
82
std::string m_dirname;
83
std::string m_current;
84
struct
stat m_stat;
85
bool
m_stat_p;
86
struct
stat &get_stat();
87
#endif
88
};
89
90
vtString
FindFileOnPaths(
const
vtStringArray &paths,
const
char
*filename);
91
bool
vtCreateDir(
const
char
*dirname);
92
void
vtDestroyDir(
const
char
*dirname);
93
void
vtDeleteFile(
const
char
*filename);
94
const
char
*StartOfFilename(
const
char
*szFullPath);
95
vtString
ExtractPath(
const
char
*szFullPath,
bool
bTrailingSlash);
96
bool
PathIsAbsolute(
const
char
*szPath);
97
vtString
PathLevelUp(
const
char
*src);
98
vtString
get_line_from_stream(std::ifstream &input);
99
void
RemoveFileExtensions(
vtString
&fname,
bool
bAll =
true
);
100
vtString
GetExtension(
const
vtString
&fname,
bool
bFull =
true
);
101
vtString
ChangeFileExtension(
const
char
*input,
const
char
*extension);
102
bool
vtFileExists(
const
char
*fname);
103
int
GetFileSize(
const
char
*fname);
104
105
void
SetEnvironmentVar(
const
vtString
&var,
const
vtString
&value);
106
107
108
// Encapsulation for Zlib's gzip output functions.
109
class
GZOutput
110
{
111
public
:
112
GZOutput
(
bool
bCompressed);
113
bool
bGZip;
114
FILE *fp;
115
gzFile gfp;
116
};
117
bool
gfopen(
GZOutput
&out,
const
char
*fname);
118
int
gfprintf(
GZOutput
&out,
const
char
*pFormat, ...);
119
void
gfclose(
GZOutput
&out);
120
121
// Excapsulation of Zlib's gzip input functions
122
// adds support for utf-8 filenames
123
124
gzFile vtGZOpen(
const
char
*path,
const
char
*mode);
125
126
127
// These functions encapsulate reading from a file which may be compressed
128
// with gzip, compressed with bzip2, or not compressed. They automatically
129
// recognize the compression so the caller doesn't have to check.
130
class
VTCompress
131
{
132
public
:
133
VTCompress
();
134
~
VTCompress
();
135
136
bool
open(
const
char
*fname);
137
size_t
read(
void
*buf,
size_t
size);
138
void
close();
139
140
protected
:
141
FILE *fp;
142
gzFile gfp;
143
#if SUPPORT_BZIP2
144
BZFILE *bfp;
145
#endif
146
};
147
148
150
// Open a file using a UTF-8 or wide character filename.
151
152
FILE *vtFileOpen(
const
char
*fname_utf8,
const
char
*mode);
153
FILE *vtFileOpen(
wchar_t
*fname_wide,
const
char
*mode);
154
155
#if SUPPORT_WSTRING
156
FILE *vtFileOpen(
const
std::wstring &fname_ws,
const
char
*mode);
157
#endif
158
159
#endif // FILEPATHH
160
Generated on Fri Jun 7 2013 16:07:51 for Umasoft by
1.8.4