fastdo  0.5.12
archives.hpp
浏览该文件的文档.
1 #ifndef __ARCHIVES_HPP__
2 #define __ARCHIVES_HPP__
3 //************************************************************************
4 // winux提供一些文档的读写功能
5 //************************************************************************
6 
7 namespace winux
8 {
9 
12 {
13 private:
14  String _configFile;
15  StringStringMap _rawParams;
16 
17  static int _FindConfigRef( String const & str, int offset, int * length, String * name );
18  String _expandVarNoStripSlashes( String const & name, StringArray * chains ) const;
19 
20  //返回加载的配置变量个数
21  int _load( String const & configFile, StringStringMap * rawParams, StringArray * loadFileChains );
22 public:
23  Configure();
24  Configure( String const & configFile );
25 
27  int load( String const & configFile );
28 
30  bool has( String const & name ) const { return _rawParams.find(name) != _rawParams.end(); }
31 
33  String get( String const & name, bool stripslashes = false, bool expand = false ) const;
34 
36  String operator [] ( String const & name ) const;
37 
39  String operator () ( String const & name ) const;
40 
44  void setRaw( String const & name, String const & value );
45 
50  void set( String const & name, String const & value );
51 
53  bool del( String const & name );
54 
56  void clear();
57 
59  StringStringMap const & getAll() const { return _rawParams; }
60 };
61 
64 {
65 public:
66  CsvWriter( IFile * outputFile );
67 
69  void write( Mixed const & records, Mixed const & columnHeaders = Mixed() );
71  void writeRecord( Mixed const & record );
72 
73 private:
74  IFile * _outputFile;
75 };
76 
77 
80 {
81 public:
82  CsvReader( IFile * inputFile, bool hasColumnHeaders = false );
83  CsvReader( String const & content, bool hasColumnHeaders = false );
84 
86  Mixed const & operator [] ( int iRow ) const { return _records[iRow]; }
88  Mixed const & operator () ( int iRow, String const & name ) const { return _records[iRow][ _columns[name] ]; }
90  int getCount() const { return _records.getCount(); }
91 
93  Mixed & getRecords() { return _records; }
95  Mixed & getColumnHeaders() { return _columns; }
97  void read( String const & content, bool hasColumnHeaders = false );
98 
99 private:
100  Mixed _columns; // 第一行列名代表的索引
101  Mixed _records;
102 
103  void _readRecord( String const & str, int & i, Mixed & record );
104 
105  void _readString( String const & str, int & i, String & valStr );
106 
107 };
108 
110 // These are the zresult codes:
111 #define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
112 #define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
113 // The following come from general system stuff (e.g. files not openable)
114 #define ZR_GENMASK 0x0000FF00
115 #define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
116 #define ZR_NOFILE 0x00000200 // couldn't create/open the file
117 #define ZR_NOALLOC 0x00000300 // failed to allocate some resource
118 #define ZR_WRITE 0x00000400 // a general error writing to the file
119 #define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
120 #define ZR_MORE 0x00000600 // there's still more data to be unzipped
121 #define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
122 #define ZR_READ 0x00000800 // a general error reading the file
123 #define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file
124 // The following come from mistakes on the part of the caller
125 #define ZR_CALLERMASK 0x00FF0000
126 #define ZR_ARGS 0x00010000 // general mistake with the arguments
127 #define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
128 #define ZR_MEMSIZE 0x00030000 // the memory size is too small
129 #define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
130 #define ZR_ENDED 0x00050000 // the zip creation has already been closed
131 #define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
132 #define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
133 #define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
134 // The following come from bugs within the zip library itself
135 #define ZR_BUGMASK 0xFF000000
136 #define ZR_NOTINITED 0x01000000 // initialisation didn't work
137 #define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
138 #define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
139 #define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
140 
143 {
144 public:
145  static String Message( ZRESULT code = ZR_RECENT );
146 
147  Zip();
148  Zip( String const & filename, char const * password = NULL );
149  Zip( void * buf, uint32 size, char const * password = NULL );
150  ~Zip();
151 
152  bool create( String const & filename, char const * password = NULL );
153  bool create( void * buf, uint32 size, char const * password = NULL );
154  ZRESULT close();
155 
156  ZRESULT addFile( String const & dstPathInZip, String const & srcFilename );
157  ZRESULT addFile( String const & dstPathInZip, void * src, uint32 size );
158  ZRESULT addFolder( String const & dstPathInZip );
159 
160  void zipAll( String const & dirPath );
161 
162  ZRESULT getMemory( void * * buf, unsigned long * size );
163 
164 private:
166 
168 };
169 
172 {
173 public:
174  typedef struct ZipEntry
175  {
176  int index; // index of this file within the zip
177  String name; // filename within the zip
178  winux::ulong attr; // attributes, as in GetFileAttributes.
179 #if defined(__linux__) || ( defined(__GNUC__) && !defined(_WIN32) )
180  time_t atime,ctime,mtime; // access, create, modify filetimes
181 #else
182  FILETIME atime,ctime,mtime;// access, create, modify filetimes
183 #endif
184  long comp_size; // sizes of item, compressed and uncompressed. These
185  long unc_size; // may be -1 if not yet known (e.g. being streamed in)
186  } ZipEntry;
187 
188 public:
189  static String Message( ZRESULT code = ZR_RECENT );
190 
191  Unzip();
192  Unzip( String const & filename, char const * password = NULL );
193  Unzip( void * zipbuf, uint32 size, char const * password = NULL );
194  ~Unzip();
195 
196  bool open( String const & filename, char const * password = NULL );
197  bool open( void * zipbuf, uint32 size, char const * password = NULL );
198  ZRESULT close();
199 
200  int getEntriesCount() const;
201 
202  ZRESULT getEntry( int index, ZipEntry * entry );
203 
204  ZRESULT findEntry( String const & name, bool caseInsensitive, int * index, ZipEntry * entry );
205 
206  ZRESULT unzipEntry( int index, String const & outFilename );
207  ZRESULT unzipEntry( int index, void * buf, uint32 size );
208  void unzipAll( String const & dirPath = "" );
209 
210  ZRESULT setUnzipBaseDir( String const & dirPath );
211 
212 private:
214 
216 };
217 
218 }
219 
220 #endif // __ARCHIVES_HPP__
long comp_size
Definition: archives.hpp:184
#define WINUX_DLL
Definition: utilities.hpp:57
String name
Definition: archives.hpp:177
配置文件类
Definition: archives.hpp:11
Mixed & getColumnHeaders()
获取所有列标头
Definition: archives.hpp:95
std::map< String, String > StringStringMap
Definition: utilities.hpp:172
winux::ulong attr
Definition: archives.hpp:178
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:78
std::vector< String > StringArray
Definition: utilities.hpp:171
int getCount() const
获取读取到的记录数
Definition: archives.hpp:90
CSV文件写入器
Definition: archives.hpp:63
int index
Definition: archives.hpp:176
long unc_size
Definition: archives.hpp:185
#define ZR_RECENT
Definition: archives.hpp:112
winux::ulong ZRESULT
Definition: archives.hpp:109
Mixed & getRecords()
获取所有记录的引用,可直接操作
Definition: archives.hpp:93
FILETIME mtime
Definition: archives.hpp:182
Definition: archives.hpp:174
混合体,能表示多种类型的值
Definition: utilities.hpp:586
文件接口
Definition: filesys.hpp:194
unsigned long ulong
Definition: utilities.hpp:129
unsigned int uint32
Definition: utilities.hpp:128
CSV文件读取器
Definition: archives.hpp:79
StringStringMap const & getAll() const
取得内部StringStringMap引用
Definition: archives.hpp:59
ZIP压缩
Definition: archives.hpp:142
std::basic_string< tchar > String
Definition: utilities.hpp:162
ZIP解压缩
Definition: archives.hpp:171
跨平台基础功能库
Definition: archives.hpp:7
bool has(String const &name) const
判断是否含有该变量
Definition: archives.hpp:30