~pbms-core/pbms/5.11-beta

« back to all changes in this revision

Viewing changes to mybs/src/cslib/CSPath.h

  • Committer: paul-mccullagh
  • Date: 2008-03-26 11:35:17 UTC
  • Revision ID: paul-mccullagh-afb1610c21464a577ae428d72fc725eb986c05a5
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007 SNAP Innovation GmbH
 
2
 *
 
3
 * BLOB Streaming for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Author: Paul McCullagh
 
20
 *
 
21
 * 2007-06-07
 
22
 *
 
23
 * CORE SYSTEM:
 
24
 * Basic file system path.
 
25
 *
 
26
 */
 
27
 
 
28
#ifndef __CSPATH_H__
 
29
#define __CSPATH_H__
 
30
 
 
31
#ifdef OS_UNIX
 
32
#include <limits.h>
 
33
#endif
 
34
 
 
35
#include "CSDefs.h"
 
36
#include "CSTime.h"
 
37
#include "CSDefs.h"
 
38
#include "CSString.h"
 
39
 
 
40
using namespace std;
 
41
 
 
42
class UXPath;
 
43
class CSFile;
 
44
class CSDirectory;
 
45
 
 
46
class CSPath : public CSRefObject {
 
47
public:
 
48
        virtual CSFile *createFile(int mode);
 
49
 
 
50
        virtual void copyFile(CSPath *to_file, bool overwrite);
 
51
 
 
52
        /*
 
53
         * Recursively creates as many directories as required.
 
54
         */
 
55
        virtual void makePath();
 
56
 
 
57
        virtual void copyDir(CSPath *to_dir, bool overwrite);
 
58
 
 
59
        /* Return true of the directory is empty. */
 
60
        virtual bool isEmpty();
 
61
 
 
62
        /* Delete the contents of a directory */
 
63
        virtual void emptyDir();
 
64
        
 
65
        /* Copy a file or directory to the specified location. */
 
66
        virtual void copyTo(CSPath *to_path, bool overwrite);
 
67
 
 
68
        virtual void moveTo(CSPath *to_path);
 
69
 
 
70
        virtual void remove();
 
71
 
 
72
        /* Create an empty file. */
 
73
        virtual void touch(bool create_path);
 
74
 
 
75
        virtual CSString *getString();
 
76
 
 
77
        virtual const char *getCString();
 
78
 
 
79
        virtual const char *getNameCString();
 
80
 
 
81
        //virtual CSPath *clone() const = 0;
 
82
 
 
83
        friend class UXPath;
 
84
 
 
85
        friend class TDPath;
 
86
        
 
87
        virtual bool exists(bool *is_dir) = 0;
 
88
 
 
89
        virtual bool exists() { return exists(NULL); }
 
90
 
 
91
        virtual void info(bool *is_dir, off_t *size, CSTime *mod_time) = 0;
 
92
 
 
93
        virtual off_t getSize();
 
94
 
 
95
        virtual bool isDir();
 
96
 
 
97
        virtual CSFile *openFile(int mode) = 0;
 
98
 
 
99
        /*
 
100
         * Remove a file or directory (even if not empty).
 
101
         */
 
102
        virtual void removeFile() = 0;
 
103
 
 
104
        /*
 
105
         * Creates a directory assuming the directory path exists.
 
106
         */
 
107
        virtual void makeDir() = 0;
 
108
 
 
109
        virtual CSDirectory *openDirectory() = 0;
 
110
 
 
111
        virtual void removeDir() = 0;
 
112
 
 
113
        virtual void rename(const char *name) = 0;
 
114
 
 
115
        /*
 
116
         * Renames one path to another.
 
117
         * The destination path may not exist.
 
118
         */
 
119
        virtual void move(CSPath *to_path) = 0;
 
120
 
 
121
        static CSPath *getSystemCWD();
 
122
 
 
123
        /* Create a new path given an absolute and a relative path: */
 
124
        static CSPath *newPath(const char *path);
 
125
        static CSPath *newPath(CSString *path);
 
126
 
 
127
        /* Create a path relative to the given 'cwd' */
 
128
        static CSPath *newPath(CSPath *cwd, const char *path);
 
129
        static CSPath *newPath(CSString *cwd, const char *path);
 
130
 
 
131
private:
 
132
        CSPath():iPath(NULL) { }
 
133
 
 
134
        virtual ~CSPath();
 
135
 
 
136
        CSString *iPath;
 
137
 
 
138
        static CSPath *iCWD;
 
139
};
 
140
 
 
141
class UXPath : public CSPath {
 
142
public:
 
143
        UXPath(): CSPath() { }
 
144
 
 
145
        virtual ~UXPath() { }
 
146
        
 
147
        virtual bool exists(bool *is_dir);
 
148
 
 
149
        virtual void info(bool *is_dir, off_t *size, CSTime *mod_time);
 
150
 
 
151
        virtual CSFile *openFile(int mode);
 
152
 
 
153
        virtual void removeFile();
 
154
 
 
155
        virtual void makeDir();
 
156
 
 
157
        virtual CSDirectory *openDirectory();
 
158
 
 
159
        virtual void removeDir();
 
160
 
 
161
        virtual void rename(const char *path);
 
162
 
 
163
        virtual void move(CSPath *to_path);
 
164
 
 
165
        static CSPath *getCWD();
 
166
 
 
167
        static CSPath *newPath(const char *path);
 
168
 
 
169
        static CSPath *newPath(CSString *path);
 
170
 
 
171
        static CSPath *newPath(CSPath *cwd, const char *path);
 
172
 
 
173
        static CSPath *newPath(CSString *cwd, const char *path);
 
174
};
 
175
 
 
176
#endif