1 #ifndef __ARCHIVES_HPP__ 2 #define __ARCHIVES_HPP__ 17 static int _FindConfigRef(
String const & str,
int offset,
int * length,
String * name );
34 int load(
String const & configFile );
37 bool has(
String const & name )
const {
return _rawParams.find(name) != _rawParams.end(); }
40 String get(
String const & name,
bool stripslashes =
false,
bool expand = false )
const;
51 void setRaw(
String const & name,
String const & value );
60 bool del(
String const & name );
87 size_t load(
String const & settingsFile );
101 Mixed const & operator [] (
String const & name )
const;
106 bool has(
String const & name )
const;
115 Mixed const & val()
const;
120 Mixed const & expr()
const;
138 void write(
Mixed const & records,
Mixed const & columnHeaders =
Mixed() );
140 void writeRecord(
Mixed const & record );
155 Mixed const & operator [] (
int iRow )
const {
return _records[iRow]; }
157 Mixed const & operator () (
int iRow,
String const & name )
const {
return _records[iRow][ _columns[name] ]; }
159 size_t getCount()
const {
return _records.getCount(); }
166 void read(
String const & content,
bool hasColumnHeaders =
false );
172 void _readRecord(
String const & str,
int & i,
Mixed & record );
174 void _readString(
String const & str,
int & i,
String & valStr );
220 this->_fileEncoding = fileEncoding;
226 return this->_fileEncoding;
232 this->_contentEncoding = contentEncoding;
238 return this->_contentEncoding;
244 this->_mbsEncoding = mbsEncoding;
250 return this->_mbsEncoding;
273 void * buf = f->
buffer(&n);
274 this->load(
winux::Buffer( buf, n,
true ), isConvert, targetEncoding, mbsEncoding );
285 this->setMultiByteEncoding(mbsEncoding);
288 this->_recognizeEncode( content, &i );
293 template <
typename _ChTy >
296 this->write(
winux::Buffer( (
void *)content.c_str(), content.length() *
sizeof(_ChTy),
true ) );
303 template <
typename _ChTy >
306 this->write(
winux::Buffer( (
void *)content.c_str(), content.length() *
sizeof(_ChTy),
true ), encoding );
312 this->_pureContent.append(content);
321 this->setContentEncoding(encoding);
322 this->_pureContent.append(content);
328 this->save( output, this->_fileEncoding );
334 this->save( f, this->_fileEncoding );
340 this->save( filePath, this->_fileEncoding );
349 this->saveEx( this->_pureContent, this->_contentEncoding, output, fileEncoding );
358 this->saveEx( this->_pureContent, this->_contentEncoding, f, fileEncoding );
367 this->saveEx( this->_pureContent, this->_contentEncoding, filePath, fileEncoding );
387 this->saveEx( content, encoding, &buf, fileEncoding );
400 this->saveEx( content, encoding, &file, fileEncoding );
404 template <
typename _ChTy >
407 return this->_pureContent.toString<_ChTy>();
413 this->_pureContent.free();
420 void _recognizeEncode(
winux::Buffer const & content,
size_t * pI );
430 #endif // __ARCHIVES_HPP__ XString< char > AnsiString
void * getBuf() const
暴露缓冲区指针
winux::AnsiString const & getMultiByteEncoding() const
获取多字节编码
Mixed & getColumnHeaders()
获取所有列标头
void save(winux::GrowBuffer *output)
保存本对象的内容到缓冲区
size_t getCount() const
获取读取到的记录数
void saveEx(winux::Buffer const &content, winux::AnsiString const &encoding, winux::IFile *f, FileEncoding fileEncoding)
保存内容到文件对象
std::map< String, String > StringStringMap
winux::XString< _ChTy > toString() const
转成指定字符的字符串
void load(winux::Buffer const &content, bool isConvert, winux::AnsiString const &targetEncoding="", winux::AnsiString const &mbsEncoding="")
载入指定内容
size_t getSize() const
获取数据大小
virtual size_t write(void const *data, size_t size)
写数据,返回写入字节数
void save(winux::String const &filePath)
保存本对象的内容到文件
void saveEx(winux::Buffer const &content, winux::AnsiString const &encoding, winux::String const &filePath, FileEncoding fileEncoding)
保存内容到文件
void save(winux::String const &filePath, FileEncoding fileEncoding)
保存本对象的内容到文件
void write(winux::XString< _ChTy > const &content, winux::AnsiString const &encoding)
写入字符串内容
void save(winux::GrowBuffer *output, FileEncoding fileEncoding)
保存本对象的内容到缓冲区
void setContentEncoding(winux::AnsiString const &contentEncoding)
设置内容编码。当给文本文档写入内容时,内容默认是什么编码,用这个函数指定。
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
void write(winux::Buffer const &content, winux::AnsiString const &encoding)
写入内容
void setMultiByteEncoding(winux::AnsiString const &mbsEncoding)
设置多字节编码。当文件编码为多字节时,这个参数指示是哪一个多字节编码。
void load(winux::IFile *f, bool isConvert, winux::AnsiString const &targetEncoding="", winux::AnsiString const &mbsEncoding="")
载入文本文件
void write(winux::Buffer const &content)
写入内容
Mixed & getRecords()
获取所有记录的引用,可直接操作
void save(winux::IFile *f, FileEncoding fileEncoding)
保存本对象的内容到文件
文本文档类。可载入文本文件自动识别BOM文件编码,转换为指定编码。
winux::AnsiString const & getContentEncoding() const
获取内容编码
void setFileEncoding(FileEncoding fileEncoding)
设置文件编码。文件编码当载入文本文件时会自动设置。但如果一开始就只是写文本文档,还是需要手动设置文件...
FileEncoding const & getFileEncoding() const
获取文件编码
std::basic_string< _ChTy > XString
TextArchive(FileEncoding fileEncoding=MultiByte, winux::AnsiString const &contentEncoding="", winux::AnsiString const &mbsEncoding="")
构造函数1
void write(winux::XString< _ChTy > const &content)
写入字符串内容
void save(winux::IFile *f)
保存本对象的内容到文件
XStringArray< tchar > StringArray
void load(winux::String const &filePath, bool isConvert, winux::AnsiString const &targetEncoding="", winux::AnsiString const &mbsEncoding="")
载入文本文件
virtual void * buffer(size_t *size)
取得缓冲区
Buffer FileGetContentsEx(String const &filename, bool textMode)
载入文件内容为一个Buffer,textMode表示是否为文本模式