version 2.98.0
remove PIFile::readLine() partially migrate PIConfig to text stream add more "override"
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 97)
|
set(pip_MINOR 98)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
|
|||||||
@@ -394,10 +394,10 @@
|
|||||||
public: \
|
public: \
|
||||||
static const char * __classNameCC() {return #name;} \
|
static const char * __classNameCC() {return #name;} \
|
||||||
static uint __classNameIDS() {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
static uint __classNameIDS() {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
||||||
virtual const char * className() const {return #name;} \
|
const char * className() const override {return #name;} \
|
||||||
virtual uint classNameID() const {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
uint classNameID() const override {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
||||||
private: \
|
private: \
|
||||||
virtual int ptrOffset() const {name * o = (name*)100; return int(llong((PIObject*)o) - llong(o));} \
|
int ptrOffset() const override {name * o = (name*)100; return int(llong((PIObject*)o) - llong(o));} \
|
||||||
class __BaseInitializer__ { \
|
class __BaseInitializer__ { \
|
||||||
public: \
|
public: \
|
||||||
__BaseInitializer__() { \
|
__BaseInitializer__() { \
|
||||||
@@ -437,7 +437,7 @@
|
|||||||
}; \
|
}; \
|
||||||
__ParentInitializer__ __parent_init__; \
|
__ParentInitializer__ __parent_init__; \
|
||||||
public: \
|
public: \
|
||||||
virtual const char * parentClassName() const {return #name;} \
|
const char * parentClassName() const override {return #name;} \
|
||||||
typedef name __Parent__; \
|
typedef name __Parent__; \
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Read character
|
//! \~english Read character
|
||||||
//! \~russian Читает символ
|
//! \~russian Читает символ
|
||||||
char takeChar(bool * rok) {
|
char readChar(bool * rok) {
|
||||||
char ret;
|
char ret;
|
||||||
bool ok = s->binaryStreamTake(&ret, sizeof(ret));
|
bool ok = s->binaryStreamTake(&ret, sizeof(ret));
|
||||||
if (!ok) is_end = true;
|
if (!ok) is_end = true;
|
||||||
@@ -156,11 +156,11 @@ public:
|
|||||||
|
|
||||||
//! \~english Read line
|
//! \~english Read line
|
||||||
//! \~russian Читает строку
|
//! \~russian Читает строку
|
||||||
PIString takeLine() {
|
PIString readLine() {
|
||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char b = takeChar(&ok);
|
char b = readChar(&ok);
|
||||||
if (!ok || b == '\n') break;
|
if (!ok || b == '\n') break;
|
||||||
if (b != '\r')
|
if (b != '\r')
|
||||||
ret.append((uchar)b);
|
ret.append((uchar)b);
|
||||||
@@ -170,16 +170,16 @@ public:
|
|||||||
|
|
||||||
//! \~english Read word, skip leading whitespaces, until next whitespace
|
//! \~english Read word, skip leading whitespaces, until next whitespace
|
||||||
//! \~russian Читает слово, пропуская начальные пробельные символы, до следующего пробельного символа
|
//! \~russian Читает слово, пропуская начальные пробельные символы, до следующего пробельного символа
|
||||||
PIString takeWord() {
|
PIString readWord() {
|
||||||
static PIConstChars spaces(" \t\n\r");
|
static PIConstChars spaces(" \t\n\r");
|
||||||
return takeUntil(spaces);
|
return readUntil(spaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~english
|
//! \~english
|
||||||
//! \~russian
|
//! \~russian
|
||||||
PIString takeCWord() {
|
PIString readCWord() {
|
||||||
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
|
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
|
||||||
return takeUntil(chars);
|
return readUntil(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -190,7 +190,7 @@ private:
|
|||||||
}
|
}
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
PIString takeUntil(const PIConstChars & chars) {
|
PIString readUntil(const PIConstChars & chars) {
|
||||||
//static PIConstChars spaces(" \t\n\r");
|
//static PIConstChars spaces(" \t\n\r");
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
char c = skipWhile(chars, &ok);
|
char c = skipWhile(chars, &ok);
|
||||||
@@ -198,7 +198,7 @@ private:
|
|||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
ret.append((uchar)c);
|
ret.append((uchar)c);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = takeChar(&ok);
|
c = readChar(&ok);
|
||||||
if (!ok || chars.contains(c)) break;
|
if (!ok || chars.contains(c)) break;
|
||||||
ret.append((uchar)c);
|
ret.append((uchar)c);
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ private:
|
|||||||
bool ok = true;
|
bool ok = true;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = takeChar(&ok);
|
c = readChar(&ok);
|
||||||
if (!ok || !chars.contains(c)) break;
|
if (!ok || !chars.contains(c)) break;
|
||||||
}
|
}
|
||||||
if (rok) *rok = ok;
|
if (rok) *rok = ok;
|
||||||
@@ -291,51 +291,51 @@ template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, c
|
|||||||
|
|
||||||
//! \~english Read word as bool
|
//! \~english Read word as bool
|
||||||
//! \~russian Читает слово как логическое
|
//! \~russian Читает слово как логическое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, bool & v) {v = s.takeWord().toBool(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, bool & v) {v = s.readWord().toBool(); return s;}
|
||||||
|
|
||||||
//! \~english Read character
|
//! \~english Read character
|
||||||
//! \~russian Читает символ
|
//! \~russian Читает символ
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, char & v) {v = s.takeChar(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, char & v) {v = s.readChar(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uchar & v) {v = s.takeWord().toUInt(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uchar & v) {v = s.readWord().toUInt(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, short & v) {v = s.takeWord().toInt(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, short & v) {v = s.readWord().toInt(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ushort & v) {v = s.takeWord().toUInt(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ushort & v) {v = s.readWord().toUInt(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, int & v) {v = s.takeWord().toInt(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, int & v) {v = s.readWord().toInt(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uint & v) {v = s.takeWord().toUInt(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uint & v) {v = s.readWord().toUInt(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, llong & v) {v = s.takeWord().toLLong(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, llong & v) {v = s.readWord().toLLong(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as integer
|
//! \~english Read word as integer
|
||||||
//! \~russian Читает слово как целое
|
//! \~russian Читает слово как целое
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ullong & v) {v = s.takeWord().toULLong(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ullong & v) {v = s.readWord().toULLong(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as floating-point number
|
//! \~english Read word as floating-point number
|
||||||
//! \~russian Читает слово как число с плавающей точкой
|
//! \~russian Читает слово как число с плавающей точкой
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, float & v) {v = s.takeWord().toFloat(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, float & v) {v = s.readWord().toFloat(); return s;}
|
||||||
|
|
||||||
//! \~english Read word as floating-point number
|
//! \~english Read word as floating-point number
|
||||||
//! \~russian Читает слово как число с плавающей точкой
|
//! \~russian Читает слово как число с плавающей точкой
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, double & v) {v = s.takeWord().toDouble(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, double & v) {v = s.readWord().toDouble(); return s;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Read word
|
//! \~english Read word
|
||||||
//! \~russian Читает слово
|
//! \~russian Читает слово
|
||||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, PIString & v) {v = s.takeWord(); return s;}
|
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, PIString & v) {v = s.readWord(); return s;}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -267,33 +267,19 @@ void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
|||||||
|
|
||||||
PIConfig::PIConfig(const PIString & path, PIIODevice::DeviceMode mode) {
|
PIConfig::PIConfig(const PIString & path, PIIODevice::DeviceMode mode) {
|
||||||
_init();
|
_init();
|
||||||
own_dev = true;
|
open(path, mode);
|
||||||
dev = new PIFile(path, mode);
|
|
||||||
if (!dev->isOpened())
|
|
||||||
dev->open(path, mode);
|
|
||||||
incdirs << PIFile::fileInfo(path).dir();
|
|
||||||
parse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIConfig::PIConfig(PIString * string, PIIODevice::DeviceMode mode) {
|
PIConfig::PIConfig(PIString * string, PIIODevice::DeviceMode mode) {
|
||||||
_init();
|
_init();
|
||||||
own_dev = true;
|
open(string, mode);
|
||||||
dev = new PIIOString(string, mode);
|
|
||||||
parse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) {
|
PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) {
|
||||||
_init();
|
_init();
|
||||||
own_dev = false;
|
open(device, mode);
|
||||||
dev = device;
|
|
||||||
if (dev) {
|
|
||||||
dev->open(mode);
|
|
||||||
if (PIString(dev->className()) == "PIFile")
|
|
||||||
incdirs << PIFile::fileInfo(((PIFile*)dev)->path()).dir();
|
|
||||||
}
|
|
||||||
parse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -317,43 +303,57 @@ PIConfig::PIConfig(const PIString & path, PIStringList dirs) {
|
|||||||
dev = 0;
|
dev = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_setupDev();
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIConfig::~PIConfig() {
|
PIConfig::~PIConfig() {
|
||||||
root.deleteBranch();
|
root.deleteBranch();
|
||||||
if (own_dev && dev) delete dev;
|
_destroy();
|
||||||
dev = 0;
|
|
||||||
piForeach (PIConfig * c, inc_devs)
|
|
||||||
delete c;
|
|
||||||
inc_devs.clear();
|
|
||||||
includes.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIConfig::open(const PIString & path, PIIODevice::DeviceMode mode) {
|
bool PIConfig::open(const PIString & path, PIIODevice::DeviceMode mode) {
|
||||||
if (own_dev && dev) delete dev;
|
_destroy();
|
||||||
|
incdirs << PIFile::fileInfo(path).dir();
|
||||||
own_dev = true;
|
own_dev = true;
|
||||||
dev = new PIFile(path, mode);
|
dev = new PIFile(path, mode);
|
||||||
if (!dev->isOpened())
|
if (!dev->isOpened())
|
||||||
dev->open(path, mode);
|
dev->open(path, mode);
|
||||||
|
_setupDev();
|
||||||
parse();
|
parse();
|
||||||
return dev->isOpened();
|
return dev->isOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIConfig::open(PIString * string, PIIODevice::DeviceMode mode) {
|
bool PIConfig::open(PIString * string, PIIODevice::DeviceMode mode) {
|
||||||
if (own_dev && dev) delete dev;
|
_destroy();
|
||||||
own_dev = true;
|
own_dev = true;
|
||||||
dev = new PIIOString(string, mode);
|
dev = new PIIOString(string, mode);
|
||||||
|
_setupDev();
|
||||||
parse();
|
parse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIConfig::open(PIIODevice * device, PIIODevice::DeviceMode mode) {
|
||||||
|
_destroy();
|
||||||
|
own_dev = false;
|
||||||
|
dev = device;
|
||||||
|
if (dev) {
|
||||||
|
dev->open(mode);
|
||||||
|
if (dev->isTypeOf<PIFile>())
|
||||||
|
incdirs << PIFile::fileInfo(((PIFile*)dev)->path()).dir();
|
||||||
|
}
|
||||||
|
_setupDev();
|
||||||
|
parse();
|
||||||
|
if (device) return device->isOpened();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIConfig::_init() {
|
void PIConfig::_init() {
|
||||||
internal = false;
|
|
||||||
delim = PIStringAscii(".");
|
delim = PIStringAscii(".");
|
||||||
root.delim = delim;
|
root.delim = delim;
|
||||||
empty.delim = delim;
|
empty.delim = delim;
|
||||||
@@ -361,6 +361,26 @@ void PIConfig::_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIConfig::_destroy() {
|
||||||
|
if (stream) {
|
||||||
|
delete stream;
|
||||||
|
stream = nullptr;
|
||||||
|
}
|
||||||
|
if (own_dev && dev) delete dev;
|
||||||
|
dev = nullptr;
|
||||||
|
piForeach (PIConfig * c, inc_devs)
|
||||||
|
delete c;
|
||||||
|
inc_devs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIConfig::_setupDev() {
|
||||||
|
if (!dev) return;
|
||||||
|
stream = new PIIOTextStream(dev);
|
||||||
|
stream->setEncoding(PIIOTextStream::UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIConfig::_clearDev() {
|
void PIConfig::_clearDev() {
|
||||||
if (!dev) return;
|
if (!dev) return;
|
||||||
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->clear(); return;}
|
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->clear(); return;}
|
||||||
@@ -375,10 +395,8 @@ void PIConfig::_flushDev() {
|
|||||||
|
|
||||||
|
|
||||||
bool PIConfig::_isEndDev() {
|
bool PIConfig::_isEndDev() {
|
||||||
if (!dev) return true;
|
if (!stream) return true;
|
||||||
if (PIString(dev->className()) == "PIFile") {return ((PIFile*)dev)->isEnd();}
|
return stream->isEnd();
|
||||||
if (PIString(dev->className()) == "PIIOString") {return ((PIIOString*)dev)->isEnd();}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -390,19 +408,15 @@ void PIConfig::_seekToBeginDev() {
|
|||||||
|
|
||||||
|
|
||||||
PIString PIConfig::_readLineDev() {
|
PIString PIConfig::_readLineDev() {
|
||||||
if (!dev) return PIString();
|
if (!stream) return PIString();
|
||||||
if (PIString(dev->className()) == "PIFile") {return ((PIFile*)dev)->readLine();}
|
return stream->readLine();
|
||||||
if (PIString(dev->className()) == "PIIOString") {return ((PIIOString*)dev)->readLine();}
|
|
||||||
return PIString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIConfig::_writeDev(const PIString & l) {
|
void PIConfig::_writeDev(const PIString & l) {
|
||||||
//piCout << "write \"" << l << "\"";
|
//piCout << "write \"" << l << "\"";
|
||||||
if (!dev) return;
|
if (!stream) return;
|
||||||
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->write(l.toUTF8()); return;}
|
stream->append(l);
|
||||||
if (PIString(dev->className()) == "PIIOString") {((PIIOString*)dev)->writeString(l); return;}
|
|
||||||
dev->write(l.toByteArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -799,7 +813,6 @@ void PIConfig::parse() {
|
|||||||
includes << iconf << iconf->includes;
|
includes << iconf << iconf->includes;
|
||||||
updateIncludes();
|
updateIncludes();
|
||||||
}
|
}
|
||||||
//piCout << "includes" << includes;
|
|
||||||
other.back() = src;
|
other.back() = src;
|
||||||
} else {
|
} else {
|
||||||
name = tree.back();
|
name = tree.back();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define PICONFIG_H
|
#define PICONFIG_H
|
||||||
|
|
||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
#include "piiostream.h"
|
||||||
|
|
||||||
#define PICONFIG_GET_VALUE \
|
#define PICONFIG_GET_VALUE \
|
||||||
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) {return getValue(vname, PIString(def), exists);} \
|
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) {return getValue(vname, PIString(def), exists);} \
|
||||||
@@ -68,7 +69,7 @@ public:
|
|||||||
PIConfig(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
PIConfig(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Contructs and read configuration from custom device "device" in mode "mode"
|
//! Contructs and read configuration from custom device "device" in mode "mode"
|
||||||
PIConfig(PIIODevice * device = 0, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
PIConfig(PIIODevice * device = nullptr, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
~PIConfig();
|
~PIConfig();
|
||||||
|
|
||||||
@@ -328,12 +329,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! Read configuration file at path "path" in mode "mode"
|
//! Read configuration from file at path "path" in mode "mode"
|
||||||
bool open(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
bool open(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Read configuration string "string" in mode "mode"
|
//! Read configuration from string "string" in mode "mode"
|
||||||
bool open(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
bool open(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
|
//! Read configuration from custom device "device" in mode "mode"
|
||||||
|
bool open(PIIODevice * device, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
bool isOpened() const;
|
bool isOpened() const;
|
||||||
|
|
||||||
//! Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false
|
//! Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false
|
||||||
@@ -474,6 +478,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
PIConfig(const PIString & path, PIStringList dirs);
|
PIConfig(const PIString & path, PIStringList dirs);
|
||||||
void _init();
|
void _init();
|
||||||
|
void _destroy();
|
||||||
|
void _setupDev();
|
||||||
void _clearDev();
|
void _clearDev();
|
||||||
void _flushDev();
|
void _flushDev();
|
||||||
bool _isEndDev();
|
bool _isEndDev();
|
||||||
@@ -493,14 +499,15 @@ private:
|
|||||||
PIString parseLine(PIString v);
|
PIString parseLine(PIString v);
|
||||||
void parse();
|
void parse();
|
||||||
|
|
||||||
bool own_dev, internal;
|
bool own_dev = false, internal = false;
|
||||||
PIVector<PIConfig * > includes, inc_devs;
|
PIVector<PIConfig * > includes, inc_devs;
|
||||||
Branch all_includes;
|
Branch all_includes;
|
||||||
PIIODevice * dev;
|
PIIODevice * dev = nullptr;
|
||||||
|
PIIOTextStream * stream = nullptr;
|
||||||
PIString delim;
|
PIString delim;
|
||||||
PIStringList incdirs;
|
PIStringList incdirs;
|
||||||
Entry root, empty;
|
Entry root, empty;
|
||||||
uint lines;
|
uint lines = 0;
|
||||||
PIStringList other;
|
PIStringList other;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
#include "pidir.h"
|
#include "pidir.h"
|
||||||
|
#include "piiostream.h"
|
||||||
#include "pitime_win.h"
|
#include "pitime_win.h"
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# undef S_IFDIR
|
# undef S_IFDIR
|
||||||
@@ -229,24 +230,6 @@ bool PIFile::closeDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString PIFile::readLine() {
|
|
||||||
PIByteArray str;
|
|
||||||
if (isClosed()) return str;
|
|
||||||
int cc;
|
|
||||||
while (!isEnd()) {
|
|
||||||
cc = fgetc(PRIVATE->fd);
|
|
||||||
if (char(cc) == '\n' || cc == EOF) break;
|
|
||||||
str.push_back(char(cc));
|
|
||||||
}
|
|
||||||
str.push_back('\0');
|
|
||||||
if (defaultCharset()) {
|
|
||||||
return PIString::fromCodepage((const char *)str.data(), defaultCharset());
|
|
||||||
}
|
|
||||||
//cout << "readline: " << str << endl;
|
|
||||||
return PIString::fromUTF8(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
llong PIFile::readAll(void * data) {
|
llong PIFile::readAll(void * data) {
|
||||||
llong cp = pos(), s = size(), i = -1;
|
llong cp = pos(), s = size(), i = -1;
|
||||||
seekToBegin();
|
seekToBegin();
|
||||||
@@ -371,7 +354,6 @@ void PIFile::_init() {
|
|||||||
PRIVATE->fd = 0;
|
PRIVATE->fd = 0;
|
||||||
fdi = -1;
|
fdi = -1;
|
||||||
_size = -1;
|
_size = -1;
|
||||||
setPrecision(5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -405,7 +387,8 @@ void PIFile::seekToEnd() {
|
|||||||
void PIFile::seekToLine(llong line) {
|
void PIFile::seekToLine(llong line) {
|
||||||
if (isClosed()) return;
|
if (isClosed()) return;
|
||||||
seekToBegin();
|
seekToBegin();
|
||||||
piForTimes(line) readLine();
|
PIIOTextStream ts(this);
|
||||||
|
piForTimes (line) ts.readLine();
|
||||||
clearerr(PRIVATE->fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,13 +427,6 @@ bool PIFile::isEnd() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIFile::setPrecision(int prec) {
|
|
||||||
prec_ = prec;
|
|
||||||
if (prec_ >= 0) prec_str = "." + PIString::fromNumber(prec_);
|
|
||||||
else prec_str = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PIFile & PIFile::put(const PIByteArray & v) {
|
PIFile & PIFile::put(const PIByteArray & v) {
|
||||||
int sz = (int)v.size_s();
|
int sz = (int)v.size_s();
|
||||||
write(createMemoryBlock(&sz));
|
write(createMemoryBlock(&sz));
|
||||||
@@ -500,16 +476,6 @@ void PIFile::remove() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char * PIFile::defaultCharset() {
|
|
||||||
return PIInit::instance()->file_charset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PIFile::setDefaultCharset(const char * c) {
|
|
||||||
PIInit::instance()->setFileCharset(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||||
FileInfo ret;
|
FileInfo ret;
|
||||||
|
|||||||
@@ -206,9 +206,6 @@ public:
|
|||||||
//! \~russian Читает один байт и возвращает его
|
//! \~russian Читает один байт и возвращает его
|
||||||
char readChar();
|
char readChar();
|
||||||
|
|
||||||
//! \~english Read one text line and return it
|
|
||||||
//! \~russian Читает одну текстовую строку и возвращает её
|
|
||||||
PIString readLine();
|
|
||||||
|
|
||||||
//! \~english Read all file content to "data" and return readed bytes count. Position leaved unchanged
|
//! \~english Read all file content to "data" and return readed bytes count. Position leaved unchanged
|
||||||
//! \~russian Читает всё содержимое файла в "data" и возвращает количество прочитанных байт. Позиция остаётся неизменной
|
//! \~russian Читает всё содержимое файла в "data" и возвращает количество прочитанных байт. Позиция остаётся неизменной
|
||||||
@@ -246,14 +243,6 @@ public:
|
|||||||
FileInfo fileInfo() const {return fileInfo(path());}
|
FileInfo fileInfo() const {return fileInfo(path());}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns float numbers write precision
|
|
||||||
//! \~russian Возвращает точность записи чисел с плавающей точкой
|
|
||||||
int precision() const {return prec_;}
|
|
||||||
|
|
||||||
//! \~english Set float numbers write precision to "prec_" digits
|
|
||||||
//! \~russian Устанавливает точность записи чисел с плавающей точкой
|
|
||||||
void setPrecision(int prec);
|
|
||||||
|
|
||||||
//! \~english Write size and content of "v" (serialize)
|
//! \~english Write size and content of "v" (serialize)
|
||||||
//! \~russian Пишет в файл размер и содержимое "v" (сериализация)
|
//! \~russian Пишет в файл размер и содержимое "v" (сериализация)
|
||||||
PIFile & put(const PIByteArray & v);
|
PIFile & put(const PIByteArray & v);
|
||||||
@@ -267,13 +256,6 @@ public:
|
|||||||
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
||||||
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
|
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
|
||||||
|
|
||||||
//! \~english
|
|
||||||
//! \~russian
|
|
||||||
static const char * defaultCharset();
|
|
||||||
|
|
||||||
//! \~english
|
|
||||||
//! \~russian
|
|
||||||
static void setDefaultCharset(const char * c);
|
|
||||||
|
|
||||||
//! \~english Returns if file with path "path" exists
|
//! \~english Returns if file with path "path" exists
|
||||||
//! \~russian Возвращает существует ли файл с путём "path"
|
//! \~russian Возвращает существует ли файл с путём "path"
|
||||||
@@ -341,7 +323,7 @@ private:
|
|||||||
void _init();
|
void _init();
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
int ret, prec_, fdi;
|
int ret, fdi;
|
||||||
llong _size;
|
llong _size;
|
||||||
PIString prec_str;
|
PIString prec_str;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
|
#include "piiostream.h"
|
||||||
|
|
||||||
|
|
||||||
PIVector<ParserSection> parse(const PIString & path) {
|
PIVector<ParserSection> parse(const PIString & path) {
|
||||||
@@ -32,9 +33,10 @@ ParserEntry makeEntry(PIString filename, const PIString & dir) {
|
|||||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
||||||
PIVector<ParserSection> ret;
|
PIVector<ParserSection> ret;
|
||||||
if (!file.isOpened()) return ret;
|
if (!file.isOpened()) return ret;
|
||||||
|
PIIOTextStream ts(&file);
|
||||||
ParserSection ps;
|
ParserSection ps;
|
||||||
while (!file.isEnd()) {
|
while (!ts.isEnd()) {
|
||||||
PIString line = file.readLine().trim();
|
PIString line = ts.readLine().trim();
|
||||||
if (line.isEmpty()) continue;
|
if (line.isEmpty()) continue;
|
||||||
if (line.startsWith("[") && line.endsWith("]")) {
|
if (line.startsWith("[") && line.endsWith("]")) {
|
||||||
if (!ps.files.isEmpty()) ret << ps;
|
if (!ps.files.isEmpty()) ret << ps;
|
||||||
@@ -61,10 +63,11 @@ PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
|||||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir) {
|
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir) {
|
||||||
PIVector<ParserSection> ret;
|
PIVector<ParserSection> ret;
|
||||||
if (!file.isOpened()) return ret;
|
if (!file.isOpened()) return ret;
|
||||||
|
PIIOTextStream ts(&file);
|
||||||
ParserSection ps;
|
ParserSection ps;
|
||||||
bool is_files = false;
|
bool is_files = false;
|
||||||
while (!file.isEnd()) {
|
while (!ts.isEnd()) {
|
||||||
PIString line = file.readLine().trim();
|
PIString line = ts.readLine().trim();
|
||||||
if (line.isEmpty()) continue;
|
if (line.isEmpty()) continue;
|
||||||
if (line.startsWith("<qresource")) {
|
if (line.startsWith("<qresource")) {
|
||||||
if (!ps.files.isEmpty()) ret << ps;
|
if (!ps.files.isEmpty()) ret << ps;
|
||||||
|
|||||||
Reference in New Issue
Block a user