git-svn-id: svn://db.shs.com.ru/pip@470 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -13,7 +13,7 @@ PICout operator <<(PICout s, const PIBitArray & ba) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
std::ostream &operator <<(std::ostream & s, const PIBitArray & ba) {
|
std::ostream &operator <<(std::ostream & s, const PIBitArray & ba) {
|
||||||
for (uint i = 0; i < ba.bitSize(); ++i) {
|
for (uint i = 0; i < ba.bitSize(); ++i) {
|
||||||
s << ba[i];
|
s << ba[i];
|
||||||
@@ -21,4 +21,5 @@ std::ostream &operator <<(std::ostream & s, const PIBitArray & ba) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,9 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream & operator <<(std::ostream & s, const PIBitArray & ba);
|
#ifdef PIP_STD_IOSTREAM
|
||||||
|
//std::ostream & operator <<(std::ostream & s, const PIBitArray & ba);
|
||||||
|
#endif
|
||||||
|
|
||||||
inline PICout operator <<(PICout s, const PIBitArray & ba);
|
inline PICout operator <<(PICout s, const PIBitArray & ba);
|
||||||
|
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ PICout operator <<(PICout s, const PIByteArray & ba) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) {
|
std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) {
|
||||||
s << "{";
|
s << "{";
|
||||||
for (uint i = 0; i < ba.size(); ++i) {
|
for (uint i = 0; i < ba.size(); ++i) {
|
||||||
@@ -370,3 +371,4 @@ std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) {
|
|||||||
s << "}";
|
s << "}";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -125,8 +125,10 @@ public:
|
|||||||
|
|
||||||
inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {if (v0.size() == v1.size()) {for (uint i = 0; i < v0.size(); ++i) if (v0[i] != v1[i]) return v0[i] < v1[i]; return false;} return v0.size() < v1.size();}
|
inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {if (v0.size() == v1.size()) {for (uint i = 0; i < v0.size(); ++i) if (v0[i] != v1[i]) return v0[i] < v1[i]; return false;} return v0.size() < v1.size();}
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
//! \relatesalso PIByteArray \brief Output to std::ostream operator
|
//! \relatesalso PIByteArray \brief Output to std::ostream operator
|
||||||
inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba);
|
inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba);
|
||||||
|
#endif
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Output to PICout operator
|
//! \relatesalso PIByteArray \brief Output to PICout operator
|
||||||
PICout operator <<(PICout s, const PIByteArray & ba);
|
PICout operator <<(PICout s, const PIByteArray & ba);
|
||||||
|
|||||||
@@ -266,13 +266,12 @@ PIChar PIChar::toLower() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
|
|
||||||
std::ostream & operator <<(std::ostream & s, const PIChar & v) {
|
std::ostream & operator <<(std::ostream & s, const PIChar & v) {
|
||||||
s << v.toCharPtr();
|
s << v.toCharPtr();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
PICout operator <<(PICout s, const PIChar & v) {
|
PICout operator <<(PICout s, const PIChar & v) {
|
||||||
s.space();
|
s.space();
|
||||||
|
|||||||
@@ -157,8 +157,10 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
//! Output operator to \c std::ostream
|
//! Output operator to \c std::ostream
|
||||||
std::ostream & operator <<(std::ostream & s, const PIChar & v);
|
std::ostream & operator <<(std::ostream & s, const PIChar & v);
|
||||||
|
#endif
|
||||||
|
|
||||||
//! Output operator to \a PICout
|
//! Output operator to \a PICout
|
||||||
PICout operator <<(PICout s, const PIChar & v);
|
PICout operator <<(PICout s, const PIChar & v);
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ PICout PICout::operator <<(const PICoutAction v) {
|
|||||||
|
|
||||||
PICout PICout::operator <<(const char * v) {if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
PICout PICout::operator <<(const char * v) {if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const std::string & v) {space(); quote(); if (PICout::buffer_) __PICout_string__ << StdString2PIString(v); else std::cout << (v); quote(); return *this;}
|
//PICout PICout::operator <<(const std::string & v) {space(); quote(); if (PICout::buffer_) __PICout_string__ << StdString2PIString(v); else std::cout << (v); quote(); return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const bool v) {space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
|
PICout PICout::operator <<(const bool v) {space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public:
|
|||||||
PICout operator <<(const char * v);
|
PICout operator <<(const char * v);
|
||||||
|
|
||||||
//! Output operator for strings with <tt>"std::string"</tt> type
|
//! Output operator for strings with <tt>"std::string"</tt> type
|
||||||
PICout operator <<(const std::string & v);
|
//PICout operator <<(const std::string & v);
|
||||||
|
|
||||||
//! Output operator for boolean values
|
//! Output operator for boolean values
|
||||||
PICout operator <<(const bool v);
|
PICout operator <<(const bool v);
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
#include "pimonitor.h"
|
#include "pimonitor.h"
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
#else
|
|
||||||
# include <iosfwd>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern PIMonitor piMonitor;
|
extern PIMonitor piMonitor;
|
||||||
|
|||||||
@@ -237,12 +237,14 @@ bool PIConfig::Entry::entryExists(const Entry * e, const PIString & name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
||||||
PIString nl = p + " ";
|
PIString nl = p + " ";
|
||||||
if (!_value.isEmpty()) s << p << _name << " = " << _value << std::endl;
|
if (!_value.isEmpty()) s << p << _name << " = " << _value << std::endl;
|
||||||
else std::cout << p << _name << std::endl;
|
else std::cout << p << _name << std::endl;
|
||||||
piForeachC (Entry * i, _children) i->coutt(s, nl);
|
piForeachC (Entry * i, _children) i->coutt(s, nl);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
||||||
@@ -815,6 +817,7 @@ void PIConfig::parse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
std::ostream &operator <<(std::ostream & s, const PIConfig::Entry & v) {
|
std::ostream &operator <<(std::ostream & s, const PIConfig::Entry & v) {
|
||||||
s << v.value();
|
s << v.value();
|
||||||
return s;
|
return s;
|
||||||
@@ -825,3 +828,4 @@ std::ostream &operator <<(std::ostream & s, const PIConfig::Branch & v) {
|
|||||||
v.coutt(s, "");
|
v.coutt(s, "");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ public:
|
|||||||
class PIP_EXPORT Branch: public PIVector<Entry * > {
|
class PIP_EXPORT Branch: public PIVector<Entry * > {
|
||||||
friend class PIConfig;
|
friend class PIConfig;
|
||||||
friend class Entry;
|
friend class Entry;
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
friend std::ostream & operator <<(std::ostream & s, const Branch & v);
|
friend std::ostream & operator <<(std::ostream & s, const Branch & v);
|
||||||
|
#endif
|
||||||
friend PICout operator <<(PICout s, const Branch & v);
|
friend PICout operator <<(PICout s, const Branch & v);
|
||||||
public:
|
public:
|
||||||
Branch() {;}
|
Branch() {;}
|
||||||
@@ -97,7 +99,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool entryExists(const Entry * e, const PIString & name) const;
|
bool entryExists(const Entry * e, const PIString & name) const;
|
||||||
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
|
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
void coutt(std::ostream & s, const PIString & p) const {piForeachC (Entry * i, *this) i->coutt(s, p);}
|
void coutt(std::ostream & s, const PIString & p) const {piForeachC (Entry * i, *this) i->coutt(s, p);}
|
||||||
|
#endif
|
||||||
void piCoutt(PICout s, const PIString & p) const {piForeachC (Entry * i, *this) i->piCoutt(s, p);}
|
void piCoutt(PICout s, const PIString & p) const {piForeachC (Entry * i, *this) i->piCoutt(s, p);}
|
||||||
|
|
||||||
static Entry _empty;
|
static Entry _empty;
|
||||||
@@ -303,7 +307,9 @@ public:
|
|||||||
bool entryExists(const Entry * e, const PIString & name) const;
|
bool entryExists(const Entry * e, const PIString & name) const;
|
||||||
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
|
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
|
||||||
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
|
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
void coutt(std::ostream & s, const PIString & p) const;
|
void coutt(std::ostream & s, const PIString & p) const;
|
||||||
|
#endif
|
||||||
void piCoutt(PICout s, const PIString & p) const;
|
void piCoutt(PICout s, const PIString & p) const;
|
||||||
void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}}
|
void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}}
|
||||||
|
|
||||||
@@ -500,8 +506,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PIP_STD_IOSTREAM
|
||||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
||||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
||||||
|
#endif
|
||||||
|
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}
|
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,10 @@
|
|||||||
|
|
||||||
REGISTER_DEVICE(PIFile)
|
REGISTER_DEVICE(PIFile)
|
||||||
|
|
||||||
|
PRIVATE_DEFINITION_START(PIFile)
|
||||||
|
FILE * fd;
|
||||||
|
PRIVATE_DEFINITION_END(PIFile)
|
||||||
|
|
||||||
|
|
||||||
PIString PIFile::FileInfo::name() const {
|
PIString PIFile::FileInfo::name() const {
|
||||||
if (path.isEmpty()) return PIString();
|
if (path.isEmpty()) return PIString();
|
||||||
@@ -123,14 +127,14 @@ PIString PIFile::FileInfo::dir() const {
|
|||||||
|
|
||||||
|
|
||||||
PIFile::PIFile(): PIIODevice() {
|
PIFile::PIFile(): PIIODevice() {
|
||||||
fd = 0;
|
PRIVATE->fd = 0;
|
||||||
fdi = -1;
|
fdi = -1;
|
||||||
setPrecision(5);
|
setPrecision(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
|
PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
|
||||||
fd = 0;
|
PRIVATE->fd = 0;
|
||||||
fdi = -1;
|
fdi = -1;
|
||||||
setPrecision(5);
|
setPrecision(5);
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
@@ -144,7 +148,7 @@ bool PIFile::openTemporary(PIIODevice::DeviceMode mode) {
|
|||||||
|
|
||||||
|
|
||||||
//PIFile::PIFile(const PIFile & other) {
|
//PIFile::PIFile(const PIFile & other) {
|
||||||
// fd = 0;
|
// PRIVATE->fd = 0;
|
||||||
// fdi = -1;
|
// fdi = -1;
|
||||||
// setPrecision(other.prec_);
|
// setPrecision(other.prec_);
|
||||||
// setPath(other.path());
|
// setPath(other.path());
|
||||||
@@ -162,29 +166,29 @@ bool PIFile::openDevice() {
|
|||||||
if (fd != 0) fclose(fd);
|
if (fd != 0) fclose(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fd = _fopen_call_(p.data(), strType(mode_).data());
|
PRIVATE->fd = _fopen_call_(p.data(), strType(mode_).data());
|
||||||
//piCout << "fopen " << path() << ": " << strType(mode_).data() << fd;
|
//piCout << "fopen " << path() << ": " << strType(mode_).data() << PRIVATE->fd;
|
||||||
bool opened = (fd != 0);
|
bool opened = (PRIVATE->fd != 0);
|
||||||
if (opened) {
|
if (opened) {
|
||||||
fdi = fileno(fd);
|
fdi = fileno(PRIVATE->fd);
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
fcntl(fdi, F_SETFL, O_NONBLOCK);
|
fcntl(fdi, F_SETFL, O_NONBLOCK);
|
||||||
#endif
|
#endif
|
||||||
_fseek_call_(fd, 0, SEEK_SET);
|
_fseek_call_(PRIVATE->fd, 0, SEEK_SET);
|
||||||
clearerr(fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
//piCout << "open file" << fd << opened_;
|
//piCout << "open file" << PRIVATE->fd << opened_;
|
||||||
return opened;
|
return opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIFile::closeDevice() {
|
bool PIFile::closeDevice() {
|
||||||
//piCout << "close file" << fd << opened_;
|
//piCout << "close file" << PRIVATE->fd << opened_;
|
||||||
if (isClosed() || fd == 0) return true;
|
if (isClosed() || PRIVATE->fd == 0) return true;
|
||||||
bool cs = (fclose(fd) == 0);
|
bool cs = (fclose(PRIVATE->fd) == 0);
|
||||||
if (cs) fd = 0;
|
if (cs) PRIVATE->fd = 0;
|
||||||
fdi = -1;
|
fdi = -1;
|
||||||
//piCout << "closed file" << fd << opened_;
|
//piCout << "closed file" << PRIVATE->fd << opened_;
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +198,7 @@ PIString PIFile::readLine() {
|
|||||||
if (isClosed()) return str;
|
if (isClosed()) return str;
|
||||||
int cc;
|
int cc;
|
||||||
while (!isEnd()) {
|
while (!isEnd()) {
|
||||||
cc = fgetc(fd);
|
cc = fgetc(PRIVATE->fd);
|
||||||
if (char(cc) == '\n' || cc == EOF) break;
|
if (char(cc) == '\n' || cc == EOF) break;
|
||||||
str.push_back(char(cc));
|
str.push_back(char(cc));
|
||||||
}
|
}
|
||||||
@@ -243,9 +247,9 @@ PIByteArray PIFile::readAll(bool forceRead) {
|
|||||||
llong PIFile::size() const {
|
llong PIFile::size() const {
|
||||||
if (isClosed()) return -1;
|
if (isClosed()) return -1;
|
||||||
llong s, cp = pos();
|
llong s, cp = pos();
|
||||||
_fseek_call_(fd, 0, SEEK_END); clearerr(fd);
|
_fseek_call_(PRIVATE->fd, 0, SEEK_END); clearerr(PRIVATE->fd);
|
||||||
s = pos();
|
s = pos();
|
||||||
_fseek_call_(fd, cp, SEEK_SET); clearerr(fd);
|
_fseek_call_(PRIVATE->fd, cp, SEEK_SET); clearerr(PRIVATE->fd);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,29 +317,29 @@ PIString PIFile::strType(const PIIODevice::DeviceMode type) {
|
|||||||
|
|
||||||
|
|
||||||
void PIFile::flush() {
|
void PIFile::flush() {
|
||||||
if (isOpened()) fflush(fd);
|
if (isOpened()) fflush(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIFile::seek(llong position) {
|
void PIFile::seek(llong position) {
|
||||||
if (isClosed()) return;
|
if (isClosed()) return;
|
||||||
if (position == pos()) return;
|
if (position == pos()) return;
|
||||||
_fseek_call_(fd, position, SEEK_SET);
|
_fseek_call_(PRIVATE->fd, position, SEEK_SET);
|
||||||
clearerr(fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIFile::seekToBegin() {
|
void PIFile::seekToBegin() {
|
||||||
if (isClosed()) return;
|
if (isClosed()) return;
|
||||||
_fseek_call_(fd, 0, SEEK_SET);
|
_fseek_call_(PRIVATE->fd, 0, SEEK_SET);
|
||||||
clearerr(fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIFile::seekToEnd() {
|
void PIFile::seekToEnd() {
|
||||||
if (isClosed()) return;
|
if (isClosed()) return;
|
||||||
_fseek_call_(fd, 0, SEEK_END);
|
_fseek_call_(PRIVATE->fd, 0, SEEK_END);
|
||||||
clearerr(fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -343,12 +347,12 @@ void PIFile::seekToLine(llong line) {
|
|||||||
if (isClosed()) return;
|
if (isClosed()) return;
|
||||||
seekToBegin();
|
seekToBegin();
|
||||||
piForTimes(line) readLine();
|
piForTimes(line) readLine();
|
||||||
clearerr(fd);
|
clearerr(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char PIFile::readChar() {
|
char PIFile::readChar() {
|
||||||
return (char)fgetc(fd);
|
return (char)fgetc(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -360,13 +364,13 @@ void PIFile::setPath(const PIString & path) {
|
|||||||
|
|
||||||
llong PIFile::pos() const {
|
llong PIFile::pos() const {
|
||||||
if (isClosed()) return -1;
|
if (isClosed()) return -1;
|
||||||
return _ftell_call_(fd);
|
return _ftell_call_(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIFile::isEnd() const {
|
bool PIFile::isEnd() const {
|
||||||
if (isClosed()) return true;
|
if (isClosed()) return true;
|
||||||
return (feof(fd) || ferror(fd));
|
return (feof(PRIVATE->fd) || ferror(PRIVATE->fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -378,169 +382,169 @@ void PIFile::setPrecision(int prec) {
|
|||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(double v) {
|
PIFile &PIFile::operator <<(double v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "lf").data(), v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(double & v) {
|
PIFile &PIFile::operator >>(double & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%lf", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lf", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(float & v) {
|
PIFile &PIFile::operator >>(float & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%f", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%f", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(ullong & v) {
|
PIFile &PIFile::operator >>(ullong & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%lln", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(ulong & v) {
|
PIFile &PIFile::operator >>(ulong & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%ln", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(uint & v) {
|
PIFile &PIFile::operator >>(uint & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%n", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(ushort & v) {
|
PIFile &PIFile::operator >>(ushort & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%hn", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(uchar & v) {
|
PIFile &PIFile::operator >>(uchar & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%hhn", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(llong & v) {
|
PIFile &PIFile::operator >>(llong & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%lln", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(long & v) {
|
PIFile &PIFile::operator >>(long & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%ln", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(int & v) {
|
PIFile &PIFile::operator >>(int & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%n", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(short & v) {
|
PIFile &PIFile::operator >>(short & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%hn", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator >>(char & v) {
|
PIFile &PIFile::operator >>(char & v) {
|
||||||
if (canRead() && fd != 0) ret = fscanf(fd, "%hhn", &v);
|
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(float v) {
|
PIFile &PIFile::operator <<(float v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, ("%" + prec_str + "f").data(), v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "f").data(), v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(ullong v) {
|
PIFile &PIFile::operator <<(ullong v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%llu", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%llu", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(ulong v) {
|
PIFile &PIFile::operator <<(ulong v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%lu", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lu", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(uint v) {
|
PIFile &PIFile::operator <<(uint v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%u", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(ushort v) {
|
PIFile &PIFile::operator <<(ushort v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%hu", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hu", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(uchar v) {
|
PIFile &PIFile::operator <<(uchar v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%u", int(v));
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", int(v));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(llong v) {
|
PIFile &PIFile::operator <<(llong v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%lld", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lld", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(long v) {
|
PIFile &PIFile::operator <<(long v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%ld", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%ld", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(int v) {
|
PIFile &PIFile::operator <<(int v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%d", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%d", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(short v) {
|
PIFile &PIFile::operator <<(short v) {
|
||||||
if (canWrite() && fd != 0) ret = fprintf(fd, "%hd", v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hd", v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(const PIByteArray & v) {
|
PIFile &PIFile::operator <<(const PIByteArray & v) {
|
||||||
if (canWrite() && fd != 0) write(v.data(), v.size());
|
if (canWrite() && PRIVATE->fd != 0) write(v.data(), v.size());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(const char v) {
|
PIFile &PIFile::operator <<(const char v) {
|
||||||
if (canWrite() && fd != 0) write(&v, 1);
|
if (canWrite() && PRIVATE->fd != 0) write(&v, 1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PIFile::readDevice(void * read_to, int max_size) {
|
int PIFile::readDevice(void * read_to, int max_size) {
|
||||||
if (!canRead() || fd == 0) return -1;
|
if (!canRead() || PRIVATE->fd == 0) return -1;
|
||||||
return fread(read_to, 1, max_size, fd);
|
return fread(read_to, 1, max_size, PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PIFile::writeDevice(const void * data, int max_size) {
|
int PIFile::writeDevice(const void * data, int max_size) {
|
||||||
if (!canWrite() || fd == 0) return -1;
|
if (!canWrite() || PRIVATE->fd == 0) return -1;
|
||||||
return fwrite(data, 1, max_size, fd);
|
return fwrite(data, 1, max_size, PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(const PIString & v) {
|
PIFile &PIFile::operator <<(const PIString & v) {
|
||||||
if (canWrite() && fd != 0)
|
if (canWrite() && PRIVATE->fd != 0)
|
||||||
*this << v.toCharset(defaultCharset());
|
*this << v.toCharset(defaultCharset());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -548,9 +552,9 @@ PIFile &PIFile::operator <<(const PIString & v) {
|
|||||||
|
|
||||||
void PIFile::clear() {
|
void PIFile::clear() {
|
||||||
close();
|
close();
|
||||||
fd = fopen(path().data(), "w");
|
PRIVATE->fd = fopen(path().data(), "w");
|
||||||
if (fd != 0) fclose(fd);
|
if (PRIVATE->fd != 0) fclose(PRIVATE->fd);
|
||||||
fd = 0;
|
PRIVATE->fd = 0;
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
PIString strType(const PIIODevice::DeviceMode type);
|
PIString strType(const PIIODevice::DeviceMode type);
|
||||||
|
|
||||||
FILE * fd;
|
PRIVATE_DECLARATION
|
||||||
int ret, prec_, fdi;
|
int ret, prec_, fdi;
|
||||||
PIString prec_str;
|
PIString prec_str;
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
#else
|
#else
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
#endif
|
#endif
|
||||||
|
FILE * tf_in, * tf_out, * tf_err;
|
||||||
PRIVATE_DEFINITION_END(PIProcess)
|
PRIVATE_DEFINITION_END(PIProcess)
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ PIProcess::PIProcess(): PIThread() {
|
|||||||
is_exec = false;
|
is_exec = false;
|
||||||
g_in = g_out = g_err = false;
|
g_in = g_out = g_err = false;
|
||||||
t_in = t_out = t_err = false;
|
t_in = t_out = t_err = false;
|
||||||
tf_in = tf_out = tf_err = 0;
|
PRIVATE->tf_in = PRIVATE->tf_out = PRIVATE->tf_err = 0;
|
||||||
env = PIProcess::currentEnvironment();
|
env = PIProcess::currentEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +140,12 @@ void PIProcess::startProc(bool detached) {
|
|||||||
if (!detached) PRIVATE->pid = pid_;
|
if (!detached) PRIVATE->pid = pid_;
|
||||||
if (pid_ == 0) {
|
if (pid_ == 0) {
|
||||||
#endif
|
#endif
|
||||||
tf_in = tf_out = tf_err = 0;
|
PRIVATE->tf_in = PRIVATE->tf_out = PRIVATE->tf_err = 0;
|
||||||
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||||
//cout << f_out.path() << endl;
|
//cout << f_out.path() << endl;
|
||||||
if (g_in) tf_in = freopen(f_in.path().data(), "r", stdin);
|
if (g_in) PRIVATE->tf_in = freopen(f_in.path().data(), "r", stdin);
|
||||||
if (g_out) tf_out = freopen(f_out.path().data(), "w", stdout);
|
if (g_out) PRIVATE->tf_out = freopen(f_out.path().data(), "w", stdout);
|
||||||
if (g_err) tf_err = freopen(f_err.path().data(), "w", stderr);
|
if (g_err) PRIVATE->tf_err = freopen(f_err.path().data(), "w", stderr);
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
if (!wd.isEmpty())
|
if (!wd.isEmpty())
|
||||||
if (!chdir(wd.data()))
|
if (!chdir(wd.data()))
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ private:
|
|||||||
PIFile f_in, f_out, f_err;
|
PIFile f_in, f_out, f_err;
|
||||||
bool g_in, g_out, g_err, t_in, t_out, t_err;
|
bool g_in, g_out, g_err, t_in, t_out, t_err;
|
||||||
PRIVATE_DECLARATION
|
PRIVATE_DECLARATION
|
||||||
FILE * tf_in, * tf_out, * tf_err;
|
|
||||||
int exit_code, sz;
|
int exit_code, sz;
|
||||||
bool is_exec;
|
bool is_exec;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user