version 0.5.0_alpha
git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Bit array
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Byte array
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -133,7 +133,7 @@ void PIHuffman::calcFrequencies(const PIDeque<uchar> & src) {
|
||||
if (nodes[i].freq > 0 && i < 255)
|
||||
{nodes.remove(i + 1, 255 - i); break;}
|
||||
for (int i = 0; i < nodes.size_s(); ++i)
|
||||
cout << string((char*)nodes[i].word.data(), 1) << ": " << nodes[i].freq << endl;
|
||||
std::cout << std::string((char*)nodes[i].word.data(), 1) << ": " << nodes[i].freq << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Byte array
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Unicode char
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Command-Line Parser
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Command-Line Parser
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node, forming self-organized peering network
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Universal output to console class
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
#include "picout.h"
|
||||
#include "piconsole.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
# define COMMON_LVB_UNDERSCORE 0x8000
|
||||
#endif
|
||||
|
||||
/*! \class PICout
|
||||
* \brief Class for formatted output similar std::cout
|
||||
@@ -44,29 +49,43 @@
|
||||
PIMutex __PICout_mutex__;
|
||||
PIString __PICout_string__;
|
||||
|
||||
#ifdef WINDOWS
|
||||
void * PICout::hOut = 0;
|
||||
WORD PICout::dattr = 0;
|
||||
DWORD PICout::smode = 0;
|
||||
#endif
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
bool PICout::buffer_ = false;
|
||||
|
||||
PRIVATE_DEFINITION_START(PICout)
|
||||
PIStack<PICoutControls> cos_;
|
||||
#ifdef WINDOWS
|
||||
static void * hOut;
|
||||
static WORD dattr;
|
||||
static DWORD smode;
|
||||
#endif
|
||||
PRIVATE_DEFINITION_END(PICout)
|
||||
|
||||
#ifdef WINDOWS
|
||||
void * PICout::__Private__::hOut = 0;
|
||||
WORD PICout::__Private__::dattr = 0;
|
||||
DWORD PICout::__Private__::smode = 0;
|
||||
#endif
|
||||
|
||||
PICout::PICout(PIFlags<PICoutControl> controls): fo_(true), cc_(false), fc_(false), cnb_(10), co_(controls) {
|
||||
#ifdef WINDOWS
|
||||
if (hOut == 0) {
|
||||
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (__Private__::hOut == 0) {
|
||||
__Private__::hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
GetConsoleScreenBufferInfo(hOut, &sbi);
|
||||
dattr = sbi.wAttributes;
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
__Private__::dattr = sbi.wAttributes;
|
||||
}
|
||||
attr_ = dattr;
|
||||
attr_ = __Private__::dattr;
|
||||
#endif
|
||||
__PICout_mutex__.lock();
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_), co_(other.co_) {
|
||||
}
|
||||
|
||||
|
||||
PICout::~PICout() {
|
||||
if (fc_) applyFormat(PICoutManipulators::Default);
|
||||
if (cc_) return;
|
||||
@@ -89,12 +108,12 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
case PICoutManipulators::Backspace:
|
||||
if (!PICout::buffer_) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleScreenBufferInfo(hOut, &sbi);
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
coord = sbi.dwCursorPosition;
|
||||
coord.X = piMax<int>(0, int(coord.X) - 1);
|
||||
SetConsoleCursorPosition(hOut, coord);
|
||||
SetConsoleCursorPosition(__Private__::hOut, coord);
|
||||
printf(" ");
|
||||
SetConsoleCursorPosition(hOut, coord);
|
||||
SetConsoleCursorPosition(__Private__::hOut, coord);
|
||||
#else
|
||||
printf("\e[1D \e[1D");
|
||||
#endif
|
||||
@@ -103,9 +122,9 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
case PICoutManipulators::ShowCursor:
|
||||
if (!PICout::buffer_) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleCursorInfo(hOut, &curinfo);
|
||||
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
curinfo.bVisible = true;
|
||||
SetConsoleCursorInfo(hOut, &curinfo);
|
||||
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
#else
|
||||
printf("\e[?25h");
|
||||
#endif
|
||||
@@ -114,9 +133,9 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
case PICoutManipulators::HideCursor:
|
||||
if (!PICout::buffer_) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleCursorInfo(hOut, &curinfo);
|
||||
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
curinfo.bVisible = false;
|
||||
SetConsoleCursorInfo(hOut, &curinfo);
|
||||
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
#else
|
||||
printf("\e[?25l");
|
||||
#endif
|
||||
@@ -126,13 +145,13 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
if (!PICout::buffer_) {
|
||||
#ifdef WINDOWS
|
||||
/// TODO !!!
|
||||
/*GetConsoleCursorInfo(hOut, &curinfo);
|
||||
/*GetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
curinfo.bVisible = false;
|
||||
SetConsoleCursorInfo(hOut, &curinfo);
|
||||
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
|
||||
SetConsoleCursorPosition(hOut, ulcoord);
|
||||
FillConsoleOutputAttribute(hOut, dattr, width * (height + 1), ulcoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width * (height + 1), ulcoord, &written);*/
|
||||
SetConsoleCursorPosition(__Private__::hOut, ulcoord);
|
||||
FillConsoleOutputAttribute(__Private__::hOut, __Private__::dattr, width * (height + 1), ulcoord, &written);
|
||||
FillConsoleOutputCharacter(__Private__::hOut, ' ', width * (height + 1), ulcoord, &written);*/
|
||||
#else
|
||||
printf("\e[H\e[J");
|
||||
#endif
|
||||
@@ -152,7 +171,7 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
|
||||
PICout PICout::operator <<(const char * v) {if (v == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
||||
|
||||
PICout PICout::operator <<(const string & v) {space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
||||
PICout PICout::operator <<(const std::string & v) {space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
||||
|
||||
PICout PICout::operator <<(const bool v) {space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
|
||||
|
||||
@@ -228,6 +247,22 @@ PICout PICout::operator <<(const PICoutSpecialChar v) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::saveControl() {
|
||||
PRIVATE->cos_.push(co_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::restoreControl() {
|
||||
if (!PRIVATE->cos_.isEmpty()) {
|
||||
co_ = PRIVATE->cos_.top();
|
||||
PRIVATE->cos_.pop();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#undef PICOUTTOTARGET
|
||||
#undef PINUMERICCOUT
|
||||
|
||||
@@ -285,10 +320,10 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
case PICoutManipulators::BackMagenta: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackCyan: attr_ = (attr_ & mask_back) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackWhite: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::Default: attr_ = dattr; break;
|
||||
case PICoutManipulators::Default: attr_ = __Private__::dattr; break;
|
||||
default: break;
|
||||
}
|
||||
SetConsoleTextAttribute(hOut, attr_);
|
||||
SetConsoleTextAttribute(__Private__::hOut, attr_);
|
||||
#else
|
||||
switch (f) {
|
||||
case Bin: case Oct: case Dec: case Hex: break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Universal output to console class
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -102,25 +102,28 @@ namespace PICoutManipulators {
|
||||
BackWhite /*! White background */ = 0x2000000,
|
||||
Default /*! Default format */ = 0x4000000
|
||||
};
|
||||
|
||||
typedef PIFlags<PICoutControl> PICoutControls;
|
||||
};
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
//using namespace PICoutManipulators;
|
||||
|
||||
typedef PIFlags<PICoutControl> PICoutControls;
|
||||
|
||||
class PIP_EXPORT PICout {
|
||||
public:
|
||||
//! Default constructor with default features (AddSpaces and AddNewLine)
|
||||
PICout(PIFlags<PICoutControl> controls = AddSpaces | AddNewLine);
|
||||
explicit PICout(PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::AddSpaces | PICoutManipulators::AddNewLine);
|
||||
|
||||
PICout(const PICout & other);
|
||||
|
||||
PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_), co_(other.co_) {;}
|
||||
~PICout();
|
||||
|
||||
|
||||
//! Output operator for strings with <tt>"const char * "</tt> type
|
||||
PICout operator <<(const char * v);
|
||||
|
||||
//! Output operator for strings with <tt>"std::string"</tt> type
|
||||
PICout operator <<(const string & v);
|
||||
PICout operator <<(const std::string & v);
|
||||
|
||||
//! Output operator for boolean values
|
||||
PICout operator <<(const bool v);
|
||||
@@ -168,65 +171,65 @@ public:
|
||||
PICout operator <<(const PIObject * v);
|
||||
|
||||
//! Output operator for \a PICoutSpecialChar values
|
||||
PICout operator <<(const PICoutSpecialChar v);
|
||||
PICout operator <<(const PICoutManipulators::PICoutSpecialChar v);
|
||||
|
||||
//! Output operator for \a PIFlags<PICoutFormat> values
|
||||
PICout operator <<(const PIFlags<PICoutFormat> v) {
|
||||
if (v[Bin]) cnb_ = 2;
|
||||
if (v[Oct]) cnb_ = 8;
|
||||
if (v[Dec]) cnb_ = 10;
|
||||
if (v[Hex]) cnb_ = 16;
|
||||
if (v[Bold]) applyFormat(Bold);
|
||||
if (v[Faint]) applyFormat(Faint);
|
||||
if (v[Italic]) applyFormat(Italic);
|
||||
if (v[Underline]) applyFormat(Underline);
|
||||
if (v[Blink]) applyFormat(Blink);
|
||||
if (v[Black]) applyFormat(Black);
|
||||
if (v[Red]) applyFormat(Red);
|
||||
if (v[Green]) applyFormat(Green);
|
||||
if (v[Blue]) applyFormat(Blue);
|
||||
if (v[Yellow]) applyFormat(Yellow);
|
||||
if (v[Magenta]) applyFormat(Magenta);
|
||||
if (v[Cyan]) applyFormat(Cyan);
|
||||
if (v[White]) applyFormat(White);
|
||||
if (v[BackBlack]) applyFormat(BackBlack);
|
||||
if (v[BackRed]) applyFormat(BackRed);
|
||||
if (v[BackGreen]) applyFormat(BackGreen);
|
||||
if (v[BackBlue]) applyFormat(BackBlue);
|
||||
if (v[BackYellow]) applyFormat(BackYellow);
|
||||
if (v[BackMagenta]) applyFormat(BackMagenta);
|
||||
if (v[BackCyan]) applyFormat(BackCyan);
|
||||
if (v[BackWhite]) applyFormat(BackWhite);
|
||||
if (v[Default]) applyFormat(Default);
|
||||
PICout operator <<(const PIFlags<PICoutManipulators::PICoutFormat> v) {
|
||||
if (v[PICoutManipulators::Bin]) cnb_ = 2;
|
||||
if (v[PICoutManipulators::Oct]) cnb_ = 8;
|
||||
if (v[PICoutManipulators::Dec]) cnb_ = 10;
|
||||
if (v[PICoutManipulators::Hex]) cnb_ = 16;
|
||||
if (v[PICoutManipulators::Bold]) applyFormat(PICoutManipulators::Bold);
|
||||
if (v[PICoutManipulators::Faint]) applyFormat(PICoutManipulators::Faint);
|
||||
if (v[PICoutManipulators::Italic]) applyFormat(PICoutManipulators::Italic);
|
||||
if (v[PICoutManipulators::Underline]) applyFormat(PICoutManipulators::Underline);
|
||||
if (v[PICoutManipulators::Blink]) applyFormat(PICoutManipulators::Blink);
|
||||
if (v[PICoutManipulators::Black]) applyFormat(PICoutManipulators::Black);
|
||||
if (v[PICoutManipulators::Red]) applyFormat(PICoutManipulators::Red);
|
||||
if (v[PICoutManipulators::Green]) applyFormat(PICoutManipulators::Green);
|
||||
if (v[PICoutManipulators::Blue]) applyFormat(PICoutManipulators::Blue);
|
||||
if (v[PICoutManipulators::Yellow]) applyFormat(PICoutManipulators::Yellow);
|
||||
if (v[PICoutManipulators::Magenta]) applyFormat(PICoutManipulators::Magenta);
|
||||
if (v[PICoutManipulators::Cyan]) applyFormat(PICoutManipulators::Cyan);
|
||||
if (v[PICoutManipulators::White]) applyFormat(PICoutManipulators::White);
|
||||
if (v[PICoutManipulators::BackBlack]) applyFormat(PICoutManipulators::BackBlack);
|
||||
if (v[PICoutManipulators::BackRed]) applyFormat(PICoutManipulators::BackRed);
|
||||
if (v[PICoutManipulators::BackGreen]) applyFormat(PICoutManipulators::BackGreen);
|
||||
if (v[PICoutManipulators::BackBlue]) applyFormat(PICoutManipulators::BackBlue);
|
||||
if (v[PICoutManipulators::BackYellow]) applyFormat(PICoutManipulators::BackYellow);
|
||||
if (v[PICoutManipulators::BackMagenta]) applyFormat(PICoutManipulators::BackMagenta);
|
||||
if (v[PICoutManipulators::BackCyan]) applyFormat(PICoutManipulators::BackCyan);
|
||||
if (v[PICoutManipulators::BackWhite]) applyFormat(PICoutManipulators::BackWhite);
|
||||
if (v[PICoutManipulators::Default]) applyFormat(PICoutManipulators::Default);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Output operator for \a PICoutFormat values
|
||||
PICout operator <<(const PICoutFormat v) {
|
||||
PICout operator <<(const PICoutManipulators::PICoutFormat v) {
|
||||
switch (v) {
|
||||
case Bin: cnb_ = 2; break;
|
||||
case Oct: cnb_ = 8; break;
|
||||
case Dec: cnb_ = 10; break;
|
||||
case Hex: cnb_ = 16; break;
|
||||
case PICoutManipulators::Bin: cnb_ = 2; break;
|
||||
case PICoutManipulators::Oct: cnb_ = 8; break;
|
||||
case PICoutManipulators::Dec: cnb_ = 10; break;
|
||||
case PICoutManipulators::Hex: cnb_ = 16; break;
|
||||
default: applyFormat(v);
|
||||
};
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Do some action
|
||||
PICout operator <<(const PICoutAction v);
|
||||
PICout operator <<(const PICoutManipulators::PICoutAction v);
|
||||
|
||||
//! Set control flag "c" is "on" state
|
||||
PICout & setControl(PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
|
||||
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
|
||||
|
||||
//! Set control flags "c" and if "save" exec \a saveControl()
|
||||
PICout & setControl(PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
|
||||
PICout & setControl(PICoutManipulators::PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
|
||||
|
||||
//! Save control flags to internal stack \sa \a restoreControl()
|
||||
PICout & saveControl() {cos_.push(co_); return *this;}
|
||||
PICout & saveControl();
|
||||
|
||||
//! Restore control flags from internal stack \sa \a saveControl()
|
||||
PICout & restoreControl() {if (!cos_.empty()) {co_ = cos_.top(); cos_.pop();} return *this;}
|
||||
PICout & restoreControl();
|
||||
|
||||
/*! \brief Conditional put space character to output
|
||||
* \details If it is not a first output and control \a AddSpaces is set
|
||||
@@ -249,18 +252,13 @@ public:
|
||||
static void clearBuffer();
|
||||
|
||||
private:
|
||||
void applyFormat(PICoutFormat f);
|
||||
void applyFormat(PICoutManipulators::PICoutFormat f);
|
||||
|
||||
static bool buffer_;
|
||||
PRIVATE_DECLARATION
|
||||
bool fo_, cc_, fc_;
|
||||
int cnb_, attr_;
|
||||
PICoutControls co_;
|
||||
std::stack<PICoutControls> cos_;
|
||||
#ifdef WINDOWS
|
||||
static void * hOut;
|
||||
static WORD dattr;
|
||||
static DWORD smode;
|
||||
#endif
|
||||
PICoutManipulators::PICoutControls co_;
|
||||
};
|
||||
|
||||
#endif // PICOUT_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
General flags class
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Global includes
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,6 +19,18 @@
|
||||
|
||||
#include "piincludes.h"
|
||||
#include "piconsole.h"
|
||||
#ifndef QNX
|
||||
# include <clocale>
|
||||
#else
|
||||
# include <locale.h>
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
//# include <mach/mach_traps.h>
|
||||
//# include <mach/mach.h>
|
||||
# include <mach/clock.h>
|
||||
//# include <crt_externs.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
bool piDebug = true;
|
||||
double piMountInfoRefreshIntervalMs = 10000.;
|
||||
@@ -53,7 +65,7 @@ PIString errorString() {
|
||||
char * msg;
|
||||
int err = GetLastError();
|
||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, NULL);
|
||||
return "code " + itos(err) + " - " + string(msg);
|
||||
return "code " + PIString::fromNumber(err) + " - " + PIString(msg);
|
||||
#else
|
||||
int e = errno;
|
||||
return PIString("code ") + PIString::fromNumber(e) + " - " + PIString(strerror(e));
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
/*! \file piincludes.h
|
||||
* \brief Global includes of PIP
|
||||
*
|
||||
* This file include all needed system headers, STL
|
||||
* and declare many useful macros and functions
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Global includes
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Minimal PIP includes
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -26,105 +20,36 @@
|
||||
#ifndef PIINCLUDES_H
|
||||
#define PIINCLUDES_H
|
||||
|
||||
#include "piversion.h"
|
||||
#include "pibase.h"
|
||||
#include "piflags.h"
|
||||
|
||||
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
|
||||
#define PIP_VERSION ((PIP_VERSION_MAJOR << 16) | (PIP_VERSION_MINOR < 8) | PIP_VERSION_REVISION)
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
//! Major value of PIP version
|
||||
# define PIP_VERSION_MAJOR
|
||||
|
||||
//! Minor value of PIP version
|
||||
# define PIP_VERSION_MINOR
|
||||
|
||||
//! Revision value of PIP version
|
||||
# define PIP_VERSION_REVISION
|
||||
|
||||
//! Suffix of PIP version
|
||||
# define PIP_VERSION_SUFFIX
|
||||
|
||||
//! Macro is defined when compile-time debug is enabled
|
||||
# define PIP_DEBUG
|
||||
|
||||
//! Macro is defined when host is any Windows
|
||||
# define WINDOWS
|
||||
|
||||
//! Macro is defined when host is QNX
|
||||
# define QNX
|
||||
|
||||
//! Macro is defined when host is FreeBSD
|
||||
# define FREE_BSD
|
||||
|
||||
//! Macro is defined when host is Mac OS
|
||||
# define MAC_OS
|
||||
|
||||
//! Macro is defined when host is Android
|
||||
# define ANDROID
|
||||
|
||||
//! Macro is defined when host is any Linux
|
||||
# define LINUX
|
||||
|
||||
//! Macro is defined when compiler is GCC or MinGW
|
||||
# define CC_GCC
|
||||
|
||||
//! Macro is defined when PIP is decided that host is support language
|
||||
# define HAS_LOCALE
|
||||
|
||||
//! Macro is defined when compiler is Visual Studio
|
||||
# define CC_VC
|
||||
|
||||
//! Macro is defined when compiler is unknown
|
||||
# define CC_OTHER
|
||||
|
||||
//! Macro is defined when PIP use "rt" library for timers implementation
|
||||
# define PIP_TIMER_RT
|
||||
|
||||
//! Define this macro to use STL implementation of containers, else PIP implementation will be used
|
||||
# define PIP_CONTAINERS_STL
|
||||
|
||||
#endif
|
||||
|
||||
#include "piplatform.h"
|
||||
|
||||
#include "pip_export.h"
|
||||
#if defined(DOXYGEN) || defined(CC_GCC) || defined(PICODE)
|
||||
# undef PIP_EXPORT
|
||||
# define PIP_EXPORT
|
||||
#endif
|
||||
#include <iostream>
|
||||
#ifdef CC_GCC
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <cassert>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#ifndef QNX
|
||||
# include <cstdio>
|
||||
# include <cstdlib>
|
||||
# include <clocale>
|
||||
# include <complex>
|
||||
# include <cmath>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <locale.h>
|
||||
# include <complex.h>
|
||||
# include <math.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
/*#ifdef WINDOWS
|
||||
# include <io.h>
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
#endif*/
|
||||
#ifdef CC_GCC
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
/*
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <cctype>
|
||||
#include <ctime>
|
||||
#include <csignal>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
//#include <signal.h>
|
||||
#include <typeinfo>
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
@@ -135,397 +60,36 @@
|
||||
#ifdef WINDOWS
|
||||
# include <conio.h>
|
||||
# include <io.h>
|
||||
# include <winsock2.h>
|
||||
# ifdef CC_VC
|
||||
# define SHUT_RDWR 2
|
||||
# pragma comment(lib, "Ws2_32.lib")
|
||||
# pragma comment(lib, "Iphlpapi.lib")
|
||||
# pragma comment(lib, "Psapi.lib")
|
||||
# else
|
||||
# define SHUT_RDWR SD_BOTH
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
# include <iphlpapi.h>
|
||||
# include <psapi.h>
|
||||
typedef int socklen_t;
|
||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
extern long long __pi_perf_freq;
|
||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
||||
inline long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
|
||||
inline void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
|
||||
#else
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <net/if.h>
|
||||
# include <sys/utsname.h>
|
||||
# include <pthread.h>
|
||||
# ifndef ANDROID
|
||||
# include <ifaddrs.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
||||
inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
|
||||
inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;}
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
# include <mach/mach_traps.h>
|
||||
# include <mach/mach.h>
|
||||
# include <mach/clock.h>
|
||||
# include <crt_externs.h>
|
||||
# define environ (*_NSGetEnviron())
|
||||
typedef long time_t;
|
||||
extern clock_serv_t __pi_mac_clock;
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
# define environ __environ
|
||||
#endif
|
||||
#if !defined(WINDOWS) && !defined(MAC_OS)
|
||||
//# define PIP_TIMER_RT
|
||||
#endif
|
||||
#ifdef FREE_BSD
|
||||
extern char ** environ;
|
||||
#endif
|
||||
#if defined(DOXYGEN) || defined(PICODE)
|
||||
# undef PIP_EXPORT
|
||||
# define PIP_EXPORT
|
||||
# undef DEPRECATED
|
||||
# define DEPRECATED
|
||||
#endif
|
||||
|
||||
#include "pimonitor.h"
|
||||
#include "piflags.h"
|
||||
#endif*/
|
||||
|
||||
extern PIMonitor piMonitor;
|
||||
|
||||
//! Macro used for infinite loop
|
||||
#define FOREVER for (;;)
|
||||
|
||||
//! Macro used for infinite wait
|
||||
#define FOREVER_WAIT FOREVER msleep(1);
|
||||
|
||||
//! Macro used for infinite wait
|
||||
#define WAIT_FOREVER FOREVER msleep(1);
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
using std::flush;
|
||||
using std::vector;
|
||||
using std::list;
|
||||
using std::queue;
|
||||
using std::deque;
|
||||
using std::stack;
|
||||
using std::set;
|
||||
using std::map;
|
||||
using std::multimap;
|
||||
using std::string;
|
||||
using std::complex;
|
||||
#ifndef QNX
|
||||
using std::wstring;
|
||||
#else
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
|
||||
typedef long long llong;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef long double ldouble;
|
||||
typedef complex<int> complexi;
|
||||
typedef complex<float> complexf;
|
||||
typedef complex<double> complexd;
|
||||
typedef complex<ldouble> complexld;
|
||||
|
||||
const complexld complexld_i(0., 1.);
|
||||
const complexld complexld_0(0.);
|
||||
const complexld complexld_1(1.);
|
||||
const complexd complexd_i(0., 1.);
|
||||
const complexd complexd_0(0.);
|
||||
const complexd complexd_1(1.);
|
||||
|
||||
/*! \brief Templated function for swap two values
|
||||
* \details Example:\n \snippet piincludes.cpp swap */
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
|
||||
|
||||
/*! \brief Templated function for swap two values without "="
|
||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||
template<typename T> inline void piSwapBinary(T & f, T & s) {
|
||||
static size_t j = (sizeof(T) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(T);
|
||||
size_t i = 0;
|
||||
for (i = 0; i < j; ++i) {
|
||||
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
||||
((size_t*)(&s))[i] ^= ((size_t*)(&f))[i];
|
||||
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
||||
}
|
||||
for (i = bs; i < bf; ++i) {
|
||||
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
|
||||
((uchar*)(&s))[i] ^= ((uchar*)(&f))[i];
|
||||
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Templated function return round of float falue
|
||||
* \details Round is the nearest integer value \n
|
||||
* There are some macros:
|
||||
* - \c piRoundf for "float"
|
||||
* - \c piRoundd for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp round */
|
||||
template<typename T> inline int piRound(const T & v) {return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));}
|
||||
|
||||
/*! \brief Templated function return floor of float falue
|
||||
* \details Floor is the largest integer that is not greater than value \n
|
||||
* There are some macros:
|
||||
* - \c piFloorf for "float"
|
||||
* - \c piFloord for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp floor */
|
||||
template<typename T> inline int piFloor(const T & v) {return v < T(0) ? int(v) - 1 : int(v);}
|
||||
|
||||
/*! \brief Templated function return ceil of float falue
|
||||
* \details Ceil is the smallest integer that is not less than value \n
|
||||
* There are some macros:
|
||||
* - \c piCeilf for "float"
|
||||
* - \c piCeild for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp ceil */
|
||||
template<typename T> inline int piCeil(const T & v) {return v < T(0) ? int(v) : int(v) + 1;}
|
||||
|
||||
/*! \brief Templated function return absolute of numeric falue
|
||||
* \details Absolute is the positive or equal 0 value \n
|
||||
* There are some macros:
|
||||
* - \c piAbss for "short"
|
||||
* - \c piAbsi for "int"
|
||||
* - \c piAbsl for "long"
|
||||
* - \c piAbsll for "llong"
|
||||
* - \c piAbsf for "float"
|
||||
* - \c piAbsd for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp abs */
|
||||
template<typename T> inline T piAbs(const T & v) {return (v >= T(0) ? v : -v);}
|
||||
|
||||
/*! \brief Templated function return minimum of two values
|
||||
* \details There are some macros:
|
||||
* - \c piMins for "short"
|
||||
* - \c piMini for "int"
|
||||
* - \c piMinl for "long"
|
||||
* - \c piMinll for "llong"
|
||||
* - \c piMinf for "float"
|
||||
* - \c piMind for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp min2 */
|
||||
template<typename T> inline T piMin(const T & f, const T & s) {return ((f > s) ? s : f);}
|
||||
|
||||
/*! \brief Templated function return minimum of tree values
|
||||
* \details There are some macros:
|
||||
* - \c piMins for "short"
|
||||
* - \c piMini for "int"
|
||||
* - \c piMinl for "long"
|
||||
* - \c piMinll for "llong"
|
||||
* - \c piMinf for "float"
|
||||
* - \c piMind for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp min3 */
|
||||
template<typename T> inline T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));}
|
||||
|
||||
/*! \brief Templated function return maximum of two values
|
||||
* \details There are some macros:
|
||||
* - \c piMaxs for "short"
|
||||
* - \c piMaxi for "int"
|
||||
* - \c piMaxl for "long"
|
||||
* - \c piMaxll for "llong"
|
||||
* - \c piMaxf for "float"
|
||||
* - \c piMaxd for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp max2 */
|
||||
template<typename T> inline T piMax(const T & f, const T & s) {return ((f < s) ? s : f);}
|
||||
|
||||
/*! \brief Templated function return maximum of tree values
|
||||
* \details There are some macros:
|
||||
* - \c piMaxs for "short"
|
||||
* - \c piMaxi for "int"
|
||||
* - \c piMaxl for "long"
|
||||
* - \c piMaxll for "llong"
|
||||
* - \c piMaxf for "float"
|
||||
* - \c piMaxd for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp max3 */
|
||||
template<typename T> inline T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));}
|
||||
|
||||
/*! \brief Templated function return clamped value
|
||||
* \details Clamped is the not greater than "max" and not lesser than "min" value \n
|
||||
* There are some macros:
|
||||
* - \c piClamps for "short"
|
||||
* - \c piClampi for "int"
|
||||
* - \c piClampl for "long"
|
||||
* - \c piClampll for "llong"
|
||||
* - \c piClampf for "float"
|
||||
* - \c piClampd for "double"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp clamp */
|
||||
template<typename T> inline T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
|
||||
/// Function inverse byte order in memory block
|
||||
inline void piLetobe(void * data, int size) {
|
||||
for (int i = 0; i < size / 2; i++)
|
||||
piSwap<uchar>(((uchar*)data)[size - i - 1], ((uchar*)data)[i]);
|
||||
}
|
||||
|
||||
/// \brief Templated function that inverse byte order of value "v"
|
||||
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
||||
|
||||
/*! \brief Templated function that returns "v" with inversed byte order
|
||||
* \details This function used to convert values between little and big endian \n
|
||||
* There are some macros:
|
||||
* - \c piLetobes for "ushort"
|
||||
* - \c piLetobei for "uint"
|
||||
* - \c piLetobel for "ulong"
|
||||
* - \c piLetobell for "ullong"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp letobe */
|
||||
template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;}
|
||||
|
||||
// specialization
|
||||
template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
DEPRECATED inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
/// \deprecated \brief Use \a piLetobe() instead of this function
|
||||
ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
|
||||
/// \deprecated \brief Use \a piLetobe() instead of this function
|
||||
uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
#endif
|
||||
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piFloorf piFloor<float>
|
||||
#define piFloord piFloor<double>
|
||||
#define piCeilf piCeil<float>
|
||||
#define piCeild piCeil<double>
|
||||
#define piAbss piAbs<short>
|
||||
#define piAbsi piAbs<int>
|
||||
#define piAbsl piAbs<long>
|
||||
#define piAbsll piAbs<llong>
|
||||
#define piAbsf piAbs<float>
|
||||
#define piAbsd piAbs<double>
|
||||
#define piMins piMin<short>
|
||||
#define piMini piMin<int>
|
||||
#define piMinl piMin<long>
|
||||
#define piMinll piMin<llong>
|
||||
#define piMinf piMin<float>
|
||||
#define piMind piMin<double>
|
||||
#define piMaxs piMax<short>
|
||||
#define piMaxi piMax<int>
|
||||
#define piMaxl piMax<long>
|
||||
#define piMaxll piMax<llong>
|
||||
#define piMaxf piMax<float>
|
||||
#define piMaxd piMax<double>
|
||||
#define piClamps piClamp<short>
|
||||
#define piClampi piClamp<int>
|
||||
#define piClampl piClamp<long>
|
||||
#define piClampll piClamp<llong>
|
||||
#define piClampf piClamp<float>
|
||||
#define piClampd piClamp<double>
|
||||
#define piLetobes piLetobe<ushort>
|
||||
#define piLetobei piLetobe<uint>
|
||||
#define piLetobel piLetobe<ulong>
|
||||
#define piLetobell piLetobe<ullong>
|
||||
|
||||
class PIObject;
|
||||
class PIMutex;
|
||||
class PIString;
|
||||
class PIInit;
|
||||
|
||||
//! global variable enabling output to piCout, default is true
|
||||
extern PIP_EXPORT bool piDebug;
|
||||
|
||||
//! global variable that set minimum real update interval
|
||||
//! for function PIInit::mountInfo(), default is 10000 ms
|
||||
extern PIP_EXPORT double piMountInfoRefreshIntervalMs;
|
||||
struct lconv;
|
||||
|
||||
extern lconv * currentLocale;
|
||||
|
||||
#ifdef WINDOWS
|
||||
inline int random() {return rand();}
|
||||
# ifdef CC_VC
|
||||
inline double round(const double & v) {return floor(v + 0.5);}
|
||||
# endif
|
||||
#endif
|
||||
inline bool atob(const string & str) {return str == "1" ? true : false;}
|
||||
inline string btos(const bool num) {return num ? "0" : "1";}
|
||||
inline string itos(const int num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%d", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%d", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
inline string ltos(const long num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%ld", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%ld", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
inline string uitos(const uint num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%u", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%u", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
inline string ultos(const ulong num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%lu", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%lu", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
inline string ftos(const float num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%.8f", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%.8f", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
inline string dtos(const double num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%.8f", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%.8f", num);
|
||||
#endif
|
||||
return string(ch);}
|
||||
|
||||
/*! \fn errorString()
|
||||
* \brief Return readable error description in format "code <number> - <description>" */
|
||||
PIString errorString();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Initialization
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -25,9 +25,32 @@
|
||||
#include "pidir.h"
|
||||
#include "piprocess.h"
|
||||
#ifdef WINDOWS
|
||||
# include <winsock2.h>
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
#else
|
||||
# include <pwd.h>
|
||||
# include <sys/utsname.h>
|
||||
# include <pthread.h>
|
||||
# include <csignal>
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
# include <mach/mach_traps.h>
|
||||
# include <mach/mach.h>
|
||||
# include <mach/clock.h>
|
||||
//# include <crt_externs.h>
|
||||
extern clock_serv_t __pi_mac_clock;
|
||||
#endif
|
||||
/*
|
||||
#ifdef WINDOWS
|
||||
# include <conio.h>
|
||||
# include <io.h>
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
#else
|
||||
# include <fcntl.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <pthread.h>
|
||||
#endif*/
|
||||
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Initialization
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -339,26 +339,26 @@ bool PIObject::execute(const PIString & method) {
|
||||
|
||||
void PIObject::dump(const PIString & line_prefix) const {
|
||||
//printf("dump %s \"%s\"\n", className(), name().data());
|
||||
PICout(AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
|
||||
PICout(AddNewLine) << line_prefix << " properties {";
|
||||
PICout(AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
||||
//printf("dump %d properties\n", properties_.size());
|
||||
piForeachC (Property p, properties_)
|
||||
if (p.first != "name")
|
||||
PICout(AddNewLine) << line_prefix << " " << p.first << ": " << p.second;
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.first << ": " << p.second;
|
||||
//printf("dump %d properties ok\n", properties_.size());
|
||||
PICout(AddNewLine) << line_prefix << " }";
|
||||
PICout(AddNewLine) << line_prefix << " methodsEH {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methodsEH {";
|
||||
__EHData & ehd(__eh_data[className()]);
|
||||
PICout(AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
|
||||
//printf("dump %d methods\n", ehd.eh_func.size());
|
||||
piForeachC (__EHPair & eh, ehd.eh_func) {
|
||||
PICout(AddNewLine) << line_prefix << " " << eh.second.fullFormat();
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.second.fullFormat();
|
||||
}
|
||||
//printf("dump %d methods ok\n", ehd.eh_func.size());
|
||||
PICout(AddNewLine) << line_prefix << " }";
|
||||
PICout(AddNewLine) << line_prefix << " connections {";
|
||||
PICout(AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||
//printf("dump %d connections\n",connections.size());
|
||||
piForeachC (Connection & c, connections) {
|
||||
PIObject * dst = c.dest_o;
|
||||
@@ -369,11 +369,11 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
PIString src(c.event);
|
||||
if (!ef.func_name.isEmpty())
|
||||
src = ef.func_name + "(" + ef.arguments() + ")";
|
||||
PICout(AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf.func_name;
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf.func_name;
|
||||
}
|
||||
//printf("dump %d connections ok\n",connections.size());
|
||||
PICout(AddNewLine) << line_prefix << " }";
|
||||
PICout(AddNewLine) << line_prefix << "}";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << "}";
|
||||
}
|
||||
|
||||
|
||||
@@ -383,20 +383,20 @@ void dumpApplication() {
|
||||
//printf("dump application ...\n");
|
||||
PIDateTime cd = PIDateTime::current();
|
||||
PISystemInfo * pi = PISystemInfo::instance();
|
||||
PICout(AddNewLine) << "application {";
|
||||
PICout(AddNewLine) << " PIP version: " << PIPVersion();
|
||||
PICout(AddNewLine) << " processors: " << pi->processorsCount;
|
||||
PICout(AddNewLine) << " hostname: \"" << pi->hostname << "\"";
|
||||
PICout(AddNewLine) << " user: \"" << pi->user << "\"";
|
||||
PICout(AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
|
||||
PICout(AddNewLine) << " started: " << pi->execDateTime.toString();
|
||||
PICout(AddNewLine) << " uptime, s: " << (cd.toSystemTime() - pi->execDateTime.toSystemTime()).toSeconds();
|
||||
PICout(AddNewLine) << " PIObjects {";
|
||||
PICout(AddNewLine) << " count: " << PIObject::objects.size_s();
|
||||
PICout(PICoutManipulators::AddNewLine) << "application {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIP version: " << PIPVersion();
|
||||
PICout(PICoutManipulators::AddNewLine) << " processors: " << pi->processorsCount;
|
||||
PICout(PICoutManipulators::AddNewLine) << " hostname: \"" << pi->hostname << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " user: \"" << pi->user << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " started: " << pi->execDateTime.toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " uptime, s: " << (cd.toSystemTime() - pi->execDateTime.toSystemTime()).toSeconds();
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects.size_s();
|
||||
piForeachC (PIObject * o, PIObject::objects)
|
||||
o->dump(" ");
|
||||
PICout(AddNewLine) << " }";
|
||||
PICout(AddNewLine) << "}";
|
||||
PICout(PICoutManipulators::AddNewLine) << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << "}";
|
||||
//printf("dump application done\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
String
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -76,6 +76,21 @@ const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||
|
||||
#ifndef CC_VC
|
||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v);
|
||||
#else
|
||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v);
|
||||
#endif
|
||||
|
||||
PIString PIString::itos(const int num) {pisprintf("%d", num); return PIString(ch);}
|
||||
PIString PIString::ltos(const long num) {pisprintf("%ld", num); return PIString(ch);}
|
||||
PIString PIString::uitos(const uint num) {pisprintf("%u", num); return PIString(ch);}
|
||||
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num); return PIString(ch);}
|
||||
PIString PIString::ftos(const float num) {pisprintf("%.8f", num); return PIString(ch);}
|
||||
PIString PIString::dtos(const double num) {pisprintf("%.8f", num); return PIString(ch);}
|
||||
|
||||
#undef pisprintf
|
||||
|
||||
|
||||
void PIString::appendFromChars(const char * c, int s) {
|
||||
int sz;
|
||||
@@ -640,8 +655,8 @@ const char * PIString::data() const {
|
||||
}
|
||||
|
||||
|
||||
string PIString::convertToStd() const {
|
||||
string s;
|
||||
std::string PIString::convertToStd() const {
|
||||
std::string s;
|
||||
uint wc;
|
||||
uchar tc;
|
||||
if (size() > 0) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
String
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "pibytearray.h"
|
||||
#include "pichar.h"
|
||||
#include "math.h"
|
||||
|
||||
class PIStringList;
|
||||
|
||||
@@ -41,7 +40,7 @@ public:
|
||||
PIString & operator +=(const PIChar & c) {push_back(c); return *this;}
|
||||
PIString & operator +=(const char * str);
|
||||
PIString & operator +=(const wchar_t * str);
|
||||
PIString & operator +=(const string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
|
||||
PIString & operator +=(const std::string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
|
||||
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s()); return *this;}
|
||||
PIString & operator +=(const PIString & str);
|
||||
#ifdef HAS_LOCALE
|
||||
@@ -67,7 +66,7 @@ public:
|
||||
PIString(const wchar_t * str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
|
||||
//! Contructs string from std::string "str"
|
||||
PIString(const string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
PIString(const std::string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
PIString(const wstring & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
|
||||
@@ -81,7 +80,7 @@ public:
|
||||
|
||||
/*! \brief Contructs string from "len" characters of buffer "str"
|
||||
* \details Example: \snippet pistring.cpp PIString(char * , int) */
|
||||
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += string(str, len);}
|
||||
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += std::string(str, len);}
|
||||
|
||||
/*! \brief Contructs string as sequence of characters "c" of buffer with length "len"
|
||||
* \details Example: \snippet pistring.cpp PIString(int, char) */
|
||||
@@ -123,7 +122,7 @@ public:
|
||||
operator const char*() {return data();}
|
||||
|
||||
//! Return std::string representation of string
|
||||
operator const string() {if (size() == 0) return string(); string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
|
||||
operator const std::string() {if (size() == 0) return std::string(); std::string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
|
||||
|
||||
//! Return symbol at index "pos"
|
||||
PIChar operator [](const int pos) const {return at(pos);}
|
||||
@@ -142,7 +141,7 @@ public:
|
||||
bool operator ==(const char * str) const {return *this == PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator ==(const string & str) const {return *this == PIString(str);}
|
||||
bool operator ==(const std::string & str) const {return *this == PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
@@ -156,7 +155,7 @@ public:
|
||||
bool operator !=(const char * str) const {return *this != PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator !=(const string & str) const {return *this != PIString(str);}
|
||||
bool operator !=(const std::string & str) const {return *this != PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
@@ -170,7 +169,7 @@ public:
|
||||
bool operator <(const char * str) const {return *this < PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <(const string & str) const {return *this < PIString(str);}
|
||||
bool operator <(const std::string & str) const {return *this < PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
@@ -184,7 +183,7 @@ public:
|
||||
bool operator >(const char * str) const {return *this > PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >(const string & str) const {return *this > PIString(str);}
|
||||
bool operator >(const std::string & str) const {return *this > PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
@@ -198,7 +197,7 @@ public:
|
||||
bool operator <=(const char * str) const {return *this <= PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <=(const string & str) const {return *this <= PIString(str);}
|
||||
bool operator <=(const std::string & str) const {return *this <= PIString(str);}
|
||||
|
||||
|
||||
//! Compare operator
|
||||
@@ -212,7 +211,7 @@ public:
|
||||
bool operator >=(const char * str) const {return *this >= PIString(str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >=(const string & str) const {return *this >= PIString(str);}
|
||||
bool operator >=(const std::string & str) const {return *this >= PIString(str);}
|
||||
|
||||
|
||||
operator bool() const {return toBool();}
|
||||
@@ -246,7 +245,7 @@ public:
|
||||
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
||||
|
||||
//! Append std::string "str" at the end of string
|
||||
PIString & operator <<(const string & str) {*this += str; return *this;}
|
||||
PIString & operator <<(const std::string & str) {*this += str; return *this;}
|
||||
|
||||
/*! \brief Append string representation of "num" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(int) */
|
||||
@@ -469,6 +468,7 @@ public:
|
||||
|
||||
//! \brief Return \c std::string representation of this string
|
||||
std::string stdString() const {return convertToStd();}
|
||||
|
||||
#ifdef HAS_LOCALE
|
||||
wstring stdWString() const {return convertToWString();}
|
||||
#endif
|
||||
@@ -486,11 +486,15 @@ public:
|
||||
|
||||
//! \brief Convert each symbol in copyed string to lower case and return it
|
||||
PIString toLowerCase() const;
|
||||
|
||||
|
||||
PIString toNativeDecimalPoints() const {
|
||||
#ifdef HAS_LOCALE
|
||||
PIString toNativeDecimalPoints() const {PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);}
|
||||
PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);
|
||||
#else
|
||||
PIString toNativeDecimalPoints() const {return PIString(*this).replaceAll(",", ".");}
|
||||
return PIString(*this).replaceAll(",", ".");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return first occur position
|
||||
@@ -505,10 +509,6 @@ public:
|
||||
//! \details Example: \snippet pistring.cpp PIString::find
|
||||
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return first occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::find
|
||||
int find(const string str, const int start = 0) const {return find(PIString(str), start);}
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return last occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::findLast
|
||||
int findLast(const char str, const int start = 0) const;
|
||||
@@ -521,10 +521,6 @@ public:
|
||||
//! \details Example: \snippet pistring.cpp PIString::findLast
|
||||
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return last occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::findLast
|
||||
int findLast(const string str, const int start = 0) const {return findLast(PIString(str), start);}
|
||||
|
||||
//! \brief Search word "word" from symbol at index "start" and return first occur position.
|
||||
//! \details Example: \snippet pistring.cpp PIString::findWord
|
||||
int findWord(const PIString & word, const int start = 0) const;
|
||||
@@ -632,15 +628,15 @@ public:
|
||||
|
||||
//! \brief Set string content to numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::setFloat
|
||||
PIString & setNumber(const float value) {clear(); *this += ftos(value); return *this;}
|
||||
PIString & setNumber(const float value) {clear(); *this += PIString::fromNumber(value); return *this;}
|
||||
|
||||
//! \brief Set string content to numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::setFloat
|
||||
PIString & setNumber(const double & value) {clear(); *this += dtos(value); return *this;}
|
||||
PIString & setNumber(const double & value) {clear(); *this += PIString::fromNumber(value); return *this;}
|
||||
|
||||
//! \brief Set string content to numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::setFloat
|
||||
PIString & setNumber(const ldouble & value) {clear(); *this += dtos(value); return *this;}
|
||||
PIString & setNumber(const ldouble & value) {clear(); *this += PIString::fromNumber(value); return *this;}
|
||||
|
||||
//! \brief Set string content to human readable size in B/kB/MB/GB/TB
|
||||
//! \details Example: \snippet pistring.cpp PIString::setReadableSize
|
||||
@@ -682,15 +678,15 @@ public:
|
||||
|
||||
//! \brief Return string contains numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::fromFloat
|
||||
static PIString fromNumber(const float value) {return PIString(ftos(value));}
|
||||
static PIString fromNumber(const float value) {return ftos(value);}
|
||||
|
||||
//! \brief Return string contains numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::fromFloat
|
||||
static PIString fromNumber(const double & value) {return PIString(dtos(value));}
|
||||
static PIString fromNumber(const double & value) {return ftos(value);}
|
||||
|
||||
//! \brief Return string contains numeric representation of "value"
|
||||
//! \details Example: \snippet pistring.cpp PIString::fromFloat
|
||||
static PIString fromNumber(const ldouble & value) {return PIString(dtos(value));}
|
||||
static PIString fromNumber(const ldouble & value) {return ftos(value);}
|
||||
|
||||
//! \brief Return "true" or "false"
|
||||
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
|
||||
@@ -706,6 +702,12 @@ private:
|
||||
static const char toBaseN[];
|
||||
static const int fromBaseN[];
|
||||
|
||||
static PIString itos(const int num);
|
||||
static PIString ltos(const long num);
|
||||
static PIString uitos(const uint num);
|
||||
static PIString ultos(const ulong num);
|
||||
static PIString ftos(const float num);
|
||||
static PIString dtos(const double num);
|
||||
static PIString fromNumberBaseS(const llong value, int base = 10, bool * ok = 0) {
|
||||
if (value == 0) return PIString("0");
|
||||
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
|
||||
@@ -777,7 +779,7 @@ private:
|
||||
return ret;
|
||||
}
|
||||
void appendFromChars(const char * c, int s);
|
||||
string convertToStd() const;
|
||||
std::string convertToStd() const;
|
||||
#ifdef HAS_LOCALE
|
||||
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
|
||||
#endif
|
||||
@@ -793,7 +795,7 @@ private:
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {for (int i = 0; i < v.length(); ++i) s << v[i]; return s;}
|
||||
|
||||
//! \relatesalso PIString \brief Input operator from std::istream (cin)
|
||||
inline std::istream & operator >>(std::istream & s, PIString & v) {string ss; s >> ss; v << PIString(ss); return s;}
|
||||
inline std::istream & operator >>(std::istream & s, PIString & v) {std::string ss; s >> ss; v << PIString(ss); return s;}
|
||||
|
||||
//! \relatesalso PIString \relatesalso PICout \brief Output operator to PICout
|
||||
inline PICout operator <<(PICout s, const PIString & v) {s.space(); s.quote(); s.setControl(0, true); for (int i = 0; i < v.length(); ++i) s << v[i]; s.restoreControl(); s.quote(); return s;}
|
||||
@@ -815,7 +817,7 @@ inline PIString operator +(const PIString & str, const PIString & f) {PIString s
|
||||
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const PIString & f, const string & str) {PIString s(f); s += str; return s;}
|
||||
inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += str; return s;}
|
||||
|
||||
//inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;}
|
||||
|
||||
@@ -823,7 +825,7 @@ inline PIString operator +(const PIString & f, const string & str) {PIString s(f
|
||||
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const string & str, const PIString & f) {return PIString(str) + f;}
|
||||
inline PIString operator +(const std::string & str, const PIString & f) {return PIString(str) + f;}
|
||||
|
||||
inline char chrUpr(char c);
|
||||
inline char chrLwr(char c);
|
||||
@@ -890,7 +892,7 @@ public:
|
||||
PIStringList & operator <<(const PIStringList & sl) {piForeachC (PIString & i, sl) push_back(i); return *this;}
|
||||
//inline PIStringList & operator <<(const char c) {push_back(PIString(c)); return *this;}
|
||||
PIStringList & operator <<(const char * str) {push_back(PIString(str)); return *this;}
|
||||
PIStringList & operator <<(const string & str) {push_back(str); return *this;}
|
||||
PIStringList & operator <<(const std::string & str) {push_back(str); return *this;}
|
||||
PIStringList & operator <<(const int & num) {push_back(PIString::fromNumber(num)); return *this;}
|
||||
PIStringList & operator <<(const short & num) {push_back(PIString::fromNumber(num)); return *this;}
|
||||
PIStringList & operator <<(const long & num) {push_back(PIString::fromNumber(num)); return *this;}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Timer
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,6 +19,17 @@
|
||||
|
||||
#include "pitime.h"
|
||||
#include "pisystemtests.h"
|
||||
#ifdef WINDOWS
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
//# include <mach/mach_traps.h>
|
||||
//# include <mach/mach.h>
|
||||
# include <mach/clock.h>
|
||||
//# include <crt_externs.h>
|
||||
extern clock_serv_t __pi_mac_clock;
|
||||
#endif
|
||||
|
||||
|
||||
/*! \class PISystemTime
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Time structs
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -24,7 +24,6 @@
|
||||
#define PITIME_H
|
||||
|
||||
#include <ctime>
|
||||
#include <csignal>
|
||||
#include "pistring.h"
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Variant type
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Variant type
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "pistring.h"
|
||||
#include "pibitarray.h"
|
||||
#include "pitime.h"
|
||||
#include "pimath.h"
|
||||
#include "pimathbase.h"
|
||||
|
||||
#define __PIVARIANT_UNION_SIZE__ 32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user