8.12.2010 - bug fixes
This commit is contained in:
@@ -125,7 +125,8 @@ void PIConsole::key_event(void * t, char key) {
|
||||
PIString PIConsole::fstr(Flags<PIConsole::Format> f) {
|
||||
if (f[PIConsole::Dec]) num_format = 0;
|
||||
if (f[PIConsole::Hex]) num_format = 1;
|
||||
if (f[PIConsole::Oct]) num_format = 2;
|
||||
|
||||
if (f[PIConsole::Oct]) num_format = 2;
|
||||
if (f[PIConsole::Scientific]) num_format = 3;
|
||||
|
||||
#ifdef WINDOWS
|
||||
@@ -152,9 +153,9 @@ PIString PIConsole::fstr(Flags<PIConsole::Format> f) {
|
||||
if (f[PIConsole::Bold]) attr |= FOREGROUND_INTENSITY;
|
||||
|
||||
SetConsoleTextAttribute(hOut, attr);
|
||||
return "";
|
||||
return PIString();
|
||||
#else
|
||||
PIString ts = "\e[0";
|
||||
PIString ts("\e[0");
|
||||
|
||||
if (f[PIConsole::Bold]) ts += ";1";
|
||||
if (f[PIConsole::Faint]) ts += ";2";
|
||||
@@ -187,21 +188,21 @@ PIString PIConsole::fstr(Flags<PIConsole::Format> f) {
|
||||
#define fprint(x) switch (num_format) {case (3): return printf("%e", x); break; default: return printf("%.5g", x); break;}
|
||||
#define dprint(x) switch (num_format) {case (3): return printf("%le", x); break; default: return printf("%.5lg", x); break;}
|
||||
|
||||
inline int PIConsole::couts(PIString v) {return printf("%s", v.data());}
|
||||
inline int PIConsole::couts(char * v) {return printf("%s", v);}
|
||||
inline int PIConsole::couts(bool v) {return (v ? printf("true") : printf("false"));}
|
||||
inline int PIConsole::couts(char v) {return printf("%c", v);}
|
||||
inline int PIConsole::couts(short v) {siprint(v);}
|
||||
inline int PIConsole::couts(int v) {iprint(v);}
|
||||
inline int PIConsole::couts(long v) {liprint(v);}
|
||||
inline int PIConsole::couts(llong v) {lliprint(v);}
|
||||
inline int PIConsole::couts(uchar v) {uprint(v);}
|
||||
inline int PIConsole::couts(ushort v) {suprint(v);}
|
||||
inline int PIConsole::couts(uint v) {uprint(v);}
|
||||
inline int PIConsole::couts(ulong v) {luprint(v);}
|
||||
inline int PIConsole::couts(ullong v) {lluprint(v);}
|
||||
inline int PIConsole::couts(float v) {fprint(v);}
|
||||
inline int PIConsole::couts(double v) {dprint(v);}
|
||||
inline int PIConsole::couts(const string v) {return printf("%s", v.c_str());}
|
||||
inline int PIConsole::couts(const char * v) {return printf("%s", v);}
|
||||
inline int PIConsole::couts(const bool v) {return (v ? printf("true") : printf("false"));}
|
||||
inline int PIConsole::couts(const char v) {return printf("%c", v);}
|
||||
inline int PIConsole::couts(const short v) {siprint(v);}
|
||||
inline int PIConsole::couts(const int v) {iprint(v);}
|
||||
inline int PIConsole::couts(const long v) {liprint(v);}
|
||||
inline int PIConsole::couts(const llong v) {lliprint(v);}
|
||||
inline int PIConsole::couts(const uchar v) {uprint(v);}
|
||||
inline int PIConsole::couts(const ushort v) {suprint(v);}
|
||||
inline int PIConsole::couts(const uint v) {uprint(v);}
|
||||
inline int PIConsole::couts(const ulong v) {luprint(v);}
|
||||
inline int PIConsole::couts(const ullong v) {lluprint(v);}
|
||||
inline int PIConsole::couts(const float v) {fprint(v);}
|
||||
inline int PIConsole::couts(const double v) {dprint(v);}
|
||||
|
||||
|
||||
void PIConsole::begin() {
|
||||
@@ -383,30 +384,35 @@ void PIConsole::addEmptyLine(int column) {
|
||||
tv.name = ""; tv.type = 0; tv.d = 0; tv.format = Normal;
|
||||
checkColumn(column); vars()[column - 1].push_back(tv);}
|
||||
|
||||
#define PRINT_VAR_BODY couts(fstr(format)); int ret = couts(value); fstr(PIConsole::Dec); return ret;
|
||||
#define PRINT_VAR_BODY couts(fstr(format).stdString()); int ret = couts(value); fstr(PIConsole::Dec); return ret;
|
||||
|
||||
void PIConsole::printLine(PIString value, int dx, Flags<PIConsole::Format> format) {
|
||||
inline void PIConsole::printLine(const PIString & value, int dx, Flags<PIConsole::Format> format) {
|
||||
int i = width - value.length() - dx;
|
||||
#ifdef QNX
|
||||
--i;
|
||||
#endif
|
||||
couts(fstr(format));
|
||||
if (i >= 0) couts(value + PIString(i, ' '));
|
||||
else couts(value.left(value.length() + i));
|
||||
couts(fstr(Dec));
|
||||
couts(fstr(format).stdString());
|
||||
if (i >= 0) couts((value + PIString(i, ' ')).stdString());
|
||||
else couts(value.left(value.size() + i).stdString());
|
||||
couts(fstr(Dec).stdString());
|
||||
}
|
||||
int PIConsole::printValue(PIString value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(char * value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(bool value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(int value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(long value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(llong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(float value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(double value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(char value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(short value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(uchar value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(ushort value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(uint value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(ulong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
int PIConsole::printValue(ullong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const PIString & value, Flags<PIConsole::Format> format) {
|
||||
couts(fstr(format).stdString());
|
||||
int ret = couts(value.stdString());
|
||||
fstr(PIConsole::Dec);
|
||||
return ret;
|
||||
}
|
||||
inline int PIConsole::printValue(const char * value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const bool value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const int value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const long value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const llong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const float value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const double value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const char value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const short value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const uchar value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const ushort value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const uint value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const ulong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
inline int PIConsole::printValue(const ullong value, Flags<PIConsole::Format> format) {PRINT_VAR_BODY}
|
||||
|
||||
62
piconsole.h
62
piconsole.h
@@ -104,22 +104,22 @@ private:
|
||||
void status();
|
||||
void checkColumn(uint col) {if (vars().size() < col) {vars().resize(col);}}
|
||||
int bitsValue(unsigned char * src, int offset, int count);
|
||||
void printLine(PIString str, int dx = 0, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(PIString str, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(char * str, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(bool value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(int value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(long value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(llong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(float value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(double value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(char value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(short value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(uchar value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(ushort value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(uint value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(ulong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
int printValue(ullong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline void printLine(const PIString & str, int dx = 0, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const PIString & str, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const char * str, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const bool value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const int value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const long value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const llong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const float value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const double value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const char value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const short value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const uchar value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const ushort value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const uint value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const ulong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const ullong value, Flags<PIConsole::Format> format = PIConsole::Normal);
|
||||
static void key_event(void * t, char key);
|
||||
|
||||
struct Variable {
|
||||
@@ -159,21 +159,21 @@ private:
|
||||
};
|
||||
|
||||
inline vector<vector<Variable> > & vars() {return tabs[cur_tab].variables;}
|
||||
inline int couts(PIString v);
|
||||
inline int couts(char * v);
|
||||
inline int couts(bool v);
|
||||
inline int couts(char v);
|
||||
inline int couts(short v);
|
||||
inline int couts(int v);
|
||||
inline int couts(long v);
|
||||
inline int couts(llong v);
|
||||
inline int couts(uchar v);
|
||||
inline int couts(ushort v);
|
||||
inline int couts(uint v);
|
||||
inline int couts(ulong v);
|
||||
inline int couts(ullong v);
|
||||
inline int couts(float v);
|
||||
inline int couts(double v);
|
||||
inline int couts(const string v);
|
||||
inline int couts(const char * v);
|
||||
inline int couts(const bool v);
|
||||
inline int couts(const char v);
|
||||
inline int couts(const short v);
|
||||
inline int couts(const int v);
|
||||
inline int couts(const long v);
|
||||
inline int couts(const llong v);
|
||||
inline int couts(const uchar v);
|
||||
inline int couts(const ushort v);
|
||||
inline int couts(const uint v);
|
||||
inline int couts(const ulong v);
|
||||
inline int couts(const ullong v);
|
||||
inline int couts(const float v);
|
||||
inline int couts(const double v);
|
||||
|
||||
#ifdef WINDOWS
|
||||
void * hOut;
|
||||
|
||||
30
pistring.h
30
pistring.h
@@ -12,27 +12,27 @@ public:
|
||||
PIString(const string & str) {*this += str;}
|
||||
PIString(const PIString & str) {*this += str;}
|
||||
PIString(const int len, const char c = ' ') {for (uint i = 0; i < len; ++i) push_back(c);}
|
||||
|
||||
operator const char*() {return (size() == 0) ? "" : string(&at(0), size()).c_str();}
|
||||
|
||||
operator const char*() {return data();}
|
||||
operator const string() {return (size() == 0) ? string() : string(&at(0), size());}
|
||||
inline char & operator [](const int pos) {return at(pos);}
|
||||
inline const char operator [](const int pos) const {return at(pos);}
|
||||
|
||||
|
||||
PIString & operator +=(const PIString & str);
|
||||
inline PIString & operator +=(const char & c) {push_back(c); return *this;}
|
||||
PIString & operator +=(const char * str);
|
||||
PIString & operator +=(const string & str);
|
||||
|
||||
|
||||
bool operator ==(const PIString & str) const;
|
||||
inline bool operator ==(const char & c) const {return *this == PIString(c);}
|
||||
inline bool operator ==(const char * str) const {return *this == PIString(str);}
|
||||
inline bool operator ==(const string & str) const {return *this == PIString(str);}
|
||||
|
||||
|
||||
bool operator !=(const PIString & str) const;
|
||||
inline bool operator !=(const char & c) const {return *this != PIString(c);}
|
||||
inline bool operator !=(const char * str) const {return *this != PIString(str);}
|
||||
inline bool operator !=(const string & str) const {return *this != PIString(str);}
|
||||
|
||||
|
||||
PIString & operator <<(const PIString & str) {*this += str; return *this;}
|
||||
inline PIString & operator <<(const char & c) {*this += c; return *this;}
|
||||
inline PIString & operator <<(const char * str) {*this += str; return *this;}
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
inline PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
inline PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
inline PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
|
||||
|
||||
PIString mid(const int start, const int len = -1) const;
|
||||
inline PIString left(const int len) const {return len <= 0 ? PIString() : mid(0, len);}
|
||||
inline PIString right(const int len) const {return len <= 0 ? PIString() : mid(size() - len, len);}
|
||||
@@ -51,12 +51,12 @@ public:
|
||||
inline PIString & cutRight(const int len) {return len <= 0 ? *this : cutMid(size() - len, len);}
|
||||
PIString trimmed() const;
|
||||
PIString & trim();
|
||||
const char * data() const {return ((size() == 0) ? string() : string(&at(0), size())).c_str();}
|
||||
const char * data() const {return stdString().c_str();}
|
||||
string stdString() const {return (size() == 0) ? string() : string(&at(0), size());}
|
||||
|
||||
|
||||
PIString toUpperCase() const;
|
||||
PIString toLowerCase() const;
|
||||
|
||||
|
||||
int find(const char str, const int start = 0);
|
||||
int find(const PIString str, const int start = 0);
|
||||
inline int find(const char * str, const int start = 0) {return find(PIString(str), start);}
|
||||
@@ -65,28 +65,28 @@ public:
|
||||
int findLast(const PIString str, const int start = 0);
|
||||
inline int findLast(const char * str, const int start = 0) {return findLast(PIString(str), start);}
|
||||
inline int findLast(const string str, const int start = 0) {return findLast(PIString(str), start);}
|
||||
|
||||
|
||||
inline int length() const {return size();}
|
||||
inline bool isEmpty() const {return size() == 0;}
|
||||
|
||||
|
||||
int toInt() const {return atoi(data());}
|
||||
short toShort() const {return (short)atoi(data());}
|
||||
long toLong() const {return atol(data());}
|
||||
float toFloat() const {return (float)atof(data());}
|
||||
double toDouble() const {return atof(data());}
|
||||
|
||||
|
||||
inline PIString & setNumber(const int value) {clear(); *this += itos(value); return *this;}
|
||||
inline PIString & setNumber(const short value) {clear(); *this += itos(value); return *this;}
|
||||
inline PIString & setNumber(const long value) {clear(); *this += ltos(value); return *this;}
|
||||
inline PIString & setNumber(const float value) {clear(); *this += ftos(value); return *this;}
|
||||
inline PIString & setNumber(const double value) {clear(); *this += dtos(value); return *this;}
|
||||
|
||||
|
||||
inline static PIString fromNumber(const int value) {return PIString(itos(value));}
|
||||
inline static PIString fromNumber(const short value) {return PIString(itos(value));}
|
||||
inline static PIString fromNumber(const long value) {return PIString(ltos(value));}
|
||||
inline static PIString fromNumber(const float value) {return PIString(ftos(value));}
|
||||
inline static PIString fromNumber(const double value) {return PIString(dtos(value));}
|
||||
|
||||
|
||||
};
|
||||
|
||||
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
|
||||
|
||||
Reference in New Issue
Block a user