-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathccfile.h
More file actions
157 lines (152 loc) · 5.41 KB
/
ccfile.h
File metadata and controls
157 lines (152 loc) · 5.41 KB
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
#ifndef _CC_FILE_H_
#define _CC_FILE_H_
#include "ccfilestrategy.h"
#include "common.h"
#include <vector>
class CC_File
{
public:
CC_File();
~CC_File();
//************************************
// @Method: Create
// @Returns: void
// @Parameter: path
// @Brief: 在指定目录下创建指定名字文件,如该文件已存在则会覆盖。
//************************************
void Create(std::string path) ;
//************************************
// @Method: Copy
// @Returns: intptr_t
// @Parameter: sourcePath
// @Parameter: destPath
// @Brief: 拷贝指定目录文件到目标路径下
//************************************
intptr_t Copy(std::string sourcePath, std::string destPath);
//************************************
// @Method: Delete
// @Returns: void
// @Parameter: path
// @Brief: 删除指定文件
//************************************
void Delete(std::string path) ;
//************************************
// @Method: Exists
// @Returns: bool
// @Parameter: path
// @Brief: 判断指定文件是否存在
//************************************
bool Exists(std::string path) ;
//************************************
// @Method: CanRead
// @Returns: bool
// @Parameter: path
// @Brief: 判断指定文件是否可读
//************************************
bool CanRead(std::string path);
//************************************
// @Method: CanWrite
// @Returns: bool
// @Parameter: path
// @Brief: 判断指定文件是否可写
//************************************
bool CanWrite(std::string path) ;
//************************************
// @Method: CanExecute
// @Returns: bool
// @Parameter: path
// @Brief: 判断指定文件是否可执行
//************************************
bool CanExecute(std::string path) ;
//************************************
// @Method: Move
// @Returns: void
// @Parameter: sourcePath
// @Parameter: destPath
// @Brief: 移动指定文件到目标文件夹下
//************************************
void Move(std::string sourcePath, std::string destPath);
//************************************
// @Method: Open
// @Returns: FileStream*
// @Parameter: path
// @Parameter: mode
// @Brief: 以相应的模式打开指定的文件,返回文件流
//************************************
FileStream* Open(std::string path, FileMode mode) ;
//************************************
// @Method: OpenRead
// @Returns: FileStream*
// @Parameter: path
// @Brief: 以只读模式打开指定文件,返回文件流
//************************************
FileStream* OpenRead(std::string path);
//************************************
// @Method: OpenWrite
// @Returns: FileStream*
// @Parameter: path
// @Brief: 以只写模式打开文件,返回文件流
//************************************
FileStream* OpenWrite(std::string path) ;
//************************************
// @Method: ReadAllBytes
// @Returns: intptr_t
// @Parameter: path
// @Parameter: destBuffer
// @Parameter: length
// @Brief: 打开指定文件,读取长度为length的内容到缓冲区,若缓冲区长度小于文件长度,则出错。
//************************************
intptr_t ReadAllBytes(std::string path, char destBuffer[], size_t length) ;
//************************************
// @Method: ReadAllLines
// @Returns: long
// @Parameter: path
// @Parameter: destContainer 用户缓冲
// @Brief: 打开文件,以行为单位读取文件内容到用户缓冲
//************************************
long ReadAllLines(std::string path, std::vector<std::string>& destContainer) ;
//************************************
// @Method: ReadAllText
// @Returns: std::string
// @Parameter: path
// @Brief: 打开指定文件,读取全部文件内容到字符串,返回该字符串
//************************************
std::string ReadAllText(std::string path);
//************************************
// @Method: Replace
// @Returns: bool
// @Parameter: sourcePath
// @Parameter: replaceFilePath
// @Parameter: backPath
// @Brief: 用目标路径文件内容替换源路径目标文件内容,并将源文件备份至backpath
//************************************
bool Replace(std::string sourcePath, std::string replaceFilePath, std::string backPath) ;
//************************************
// @Method: WriteAllBytes
// @Returns: intptr_t
// @Parameter: path
// @Parameter: sourceData
// @Parameter: len
// @Brief: 打开文件,将目标缓冲区的内容全部写入文件。 返回写入字节数。
//************************************
intptr_t WriteAllBytes(std::string path, const char sourceData[], size_t len);
//************************************
// @Method: WriteAllLines
// @Returns: long
// @Parameter: path
// @Parameter: sourceData
// @Brief: 打开指定文件,将指定缓冲区数据全部写入文件,返回写入数据行数。
//************************************
long WriteAllLines(std::string path, const std::vector<std::string>& sourceData);
//************************************
// @Method: WriteAllText
// @Returns: intptr_t
// @Parameter: path
// @Parameter: content
// @Brief: 打开指定文件,将字符串内容全部写入该文件,返回写入的字节数。
//************************************
intptr_t WriteAllText(std::string path, std::string& content);
private:
static CC_file_strategy* instance;
};
#endif