Compare commits
77 Commits
90afc369f0
...
pimap
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e85b11a233 | ||
|
|
831adf3fc9 | ||
|
|
a18f461ce3 | ||
| 12c032392c | |||
| ffa25c18f0 | |||
| a502182eba | |||
| d219baee27 | |||
| 0ea1e2c856 | |||
| 3107949e6f | |||
| 460519c075 | |||
| 9347ed2e55 | |||
| 5770adfd34 | |||
| 9714d8ea42 | |||
| 0b3ee4bb6a | |||
| d1f7065c8a | |||
| 6995c25613 | |||
| 28ce6e8f3f | |||
| 8d5730f715 | |||
| 2bbdbc3ac9 | |||
| 19e4eee222 | |||
| 4139d88103 | |||
| 6881fd13b7 | |||
|
|
8c8553a6af | ||
| 97dd19f0c7 | |||
|
|
784c949b1a | ||
|
|
7325e12e30 | ||
| 019ddbb80b | |||
|
|
6322b248a8 | ||
| c1c47b4869 | |||
| 2f4e73ef13 | |||
| 5ae1cfae87 | |||
| 5d82caf889 | |||
| d3028a3ce8 | |||
| eef4573a68 | |||
| 48f3b62540 | |||
|
|
f7d6302572 | ||
|
|
7ad520a1c3 | ||
|
|
4bc12989ca | ||
|
|
186c71d973 | ||
|
|
06c8e6af10 | ||
|
|
69b9589e84 | ||
|
|
5c767c5e3e | ||
|
|
9cd0389a0b | ||
|
|
a7ffc85404 | ||
|
|
2e9c3a1dbf | ||
| 9f581335d3 | |||
| e70e1c0203 | |||
| cb179de856 | |||
| 0aaa5ba890 | |||
| 0cf7fb9f25 | |||
| a304997177 | |||
| d6ba51e4bc | |||
| 892edb7d5b | |||
| c3cf0f3586 | |||
| 2dec17e871 | |||
| 88ffd602d6 | |||
| a57e51bdf8 | |||
| 44c52c40f1 | |||
| 6ecd04b0d8 | |||
| 964823b332 | |||
| ca8839f097 | |||
| 546ad6a744 | |||
| bd9ad16074 | |||
| 23907c7043 | |||
| a6cea11911 | |||
| cea7a7c121 | |||
| 095ecd254f | |||
| 2246b8b5fd | |||
| 914ff5355d | |||
| 858269a46b | |||
| 5072d8c915 | |||
| 5f8c04a78e | |||
| 41fb7cc40d | |||
| 6a399c7d39 | |||
| 03384d02a0 | |||
| dd3d42944e | |||
| c2e44dc3ba |
@@ -2,15 +2,52 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 36)
|
set(pip_MINOR 39)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
set(pip_DOMAIN org.SHS)
|
set(pip_DOMAIN org.SHS)
|
||||||
|
|
||||||
|
set(GIT_CMAKE_DIR)
|
||||||
|
if (NOT DEFINED SHSTKPROJECT)
|
||||||
|
set(ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmake-download/CMakeLists.txt"
|
||||||
|
"# This file was generated by PIP CMake, don`t edit it!
|
||||||
|
cmake_minimum_required(VERSION 2.8.2)
|
||||||
|
project(cmake-download NONE)
|
||||||
|
include(ExternalProject)
|
||||||
|
ExternalProject_Add(cmake
|
||||||
|
GIT_REPOSITORY https://git.shs.tools/SHS/cmake.git
|
||||||
|
GIT_TAG \"origin/master\"
|
||||||
|
GIT_CONFIG \"advice.detachedHead=false\"
|
||||||
|
SOURCE_DIR \"${CMAKE_CURRENT_BINARY_DIR}/cmake-src\"
|
||||||
|
BINARY_DIR \"${CMAKE_CURRENT_BINARY_DIR}/cmake-build\"
|
||||||
|
INSTALL_COMMAND \"\"
|
||||||
|
TEST_COMMAND \"\"
|
||||||
|
)
|
||||||
|
")
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake-download)
|
||||||
|
if(result)
|
||||||
|
message(FATAL_ERROR "CMake step for cmake failed: ${result}")
|
||||||
|
endif()
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake-download)
|
||||||
|
if(result)
|
||||||
|
message(FATAL_ERROR "Build step for cmake failed: ${result}")
|
||||||
|
endif()
|
||||||
|
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_CURRENT_BINARY_DIR}/cmake-build\" --target install)")
|
||||||
|
set(GIT_CMAKE_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake-src")
|
||||||
|
endif()
|
||||||
|
|
||||||
if ("x${CMAKE_MODULE_PATH}" STREQUAL "x")
|
if ("x${CMAKE_MODULE_PATH}" STREQUAL "x")
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
endif()
|
endif()
|
||||||
|
if (NOT "x${GIT_CMAKE_DIR}" STREQUAL "x")
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${GIT_CMAKE_DIR}")
|
||||||
|
endif()
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
include(CheckFunctionExists)
|
include(CheckFunctionExists)
|
||||||
include(PIPMacros)
|
include(PIPMacros)
|
||||||
@@ -579,7 +616,7 @@ if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
|
|||||||
foreach(F ${PIP_MAIN_FOLDERS})
|
foreach(F ${PIP_MAIN_FOLDERS})
|
||||||
list(APPEND DOXY_INPUT "\"${F}\"")
|
list(APPEND DOXY_INPUT "\"${F}\"")
|
||||||
endforeach(F)
|
endforeach(F)
|
||||||
string(REPLACE ";" " " DOXY_INPUT "\"${CMAKE_CURRENT_SOURCE_DIR}/libs\"")
|
string(REPLACE ";" " " DOXY_INPUT "\"${CMAKE_CURRENT_SOURCE_DIR}/libs\";\"${CMAKE_CURRENT_SOURCE_DIR}/doc/pages\"")
|
||||||
string(REPLACE ";" " " DOXY_INCLUDE_PATH "${PIP_INCLUDES}")
|
string(REPLACE ";" " " DOXY_INCLUDE_PATH "${PIP_INCLUDES}")
|
||||||
string(REPLACE ";" " " DOXY_DEFINES "${DOXY_DEFINES}")
|
string(REPLACE ";" " " DOXY_DEFINES "${DOXY_DEFINES}")
|
||||||
add_documentation(doc doc/Doxyfile.in)
|
add_documentation(doc doc/Doxyfile.in)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ void _() {
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class SomeIO: public PIIODevice {
|
class SomeIO: public PIIODevice {
|
||||||
PIIODEVICE(SomeIO)
|
PIIODEVICE(SomeIO, "myio")
|
||||||
public:
|
public:
|
||||||
SomeIO(): PIIODevice() {}
|
SomeIO(): PIIODevice() {}
|
||||||
protected:
|
protected:
|
||||||
@@ -19,9 +19,8 @@ protected:
|
|||||||
// write to your device here
|
// write to your device here
|
||||||
return written_bytes;
|
return written_bytes;
|
||||||
}
|
}
|
||||||
PIString fullPathPrefix() const {return "myio";}
|
|
||||||
void configureFromFullPath(const PIString & full_path) {
|
void configureFromFullPath(const PIString & full_path) {
|
||||||
// parse full_path and configure device there
|
// parse full_path and configure device here
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
REGISTER_DEVICE(SomeIO)
|
REGISTER_DEVICE(SomeIO)
|
||||||
|
|||||||
44
doc/pages/main.md
Normal file
44
doc/pages/main.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
\~english \mainpage What is PIP
|
||||||
|
\~russian \mainpage Что такое PIP
|
||||||
|
|
||||||
|
|
||||||
|
\~english
|
||||||
|
|
||||||
|
PIP - Platform-Independent Primitives - is crossplatform library for C++ developers.
|
||||||
|
This library can help developers write non-GUI projects much more quickly, efficiently
|
||||||
|
and customizable than on pure C++.
|
||||||
|
|
||||||
|
Application written on PIP works the same on any system. One can read and write
|
||||||
|
any data types, serialize any types to device channels between any systems.
|
||||||
|
|
||||||
|
Many common data types, system primitives and devices implemented in this library.
|
||||||
|
|
||||||
|
PIP also tightly integrates with [CMake](https://cmake.org/) build system, providing handly search
|
||||||
|
main library, additional modules of PIP and several utilites. With
|
||||||
|
CMake with PIP one can easily generate and use code metainformation or
|
||||||
|
serialize custom types with it versions back-compatability.
|
||||||
|
|
||||||
|
Summary one can find at \ref summary page.
|
||||||
|
|
||||||
|
Basic using of PIP described at \ref using_basic page.
|
||||||
|
|
||||||
|
|
||||||
|
\~russian
|
||||||
|
|
||||||
|
PIP - Platform-Independent Primitives - кроссплатформенная библиотека для разработчиков на C++.
|
||||||
|
Эта библиотека поможет разработчику написать неграфическое приложение быстрее, эффективнее
|
||||||
|
и более гибко, чем на чистом C++.
|
||||||
|
|
||||||
|
Приложения, написанные на PIP, работают одинаково на многих системах. Можно читать и писать
|
||||||
|
любые типы данных, сериализовать любые типы в каналы устройств между любыми системами.
|
||||||
|
|
||||||
|
Многие типы данных, системные сущности и устройства реализованы в библиотеке.
|
||||||
|
|
||||||
|
PIP также тесно интегрируется с системой сборки [CMake](https://cmake.org/), предоставляя удобный поиск
|
||||||
|
главной библиотеки, модулей PIP и некоторых утилит. Используя CMake вместе с PIP
|
||||||
|
можно генерировать и использовать метаинформация о коде или сериализовать
|
||||||
|
свои типы данных с обратной совместимостью их версий.
|
||||||
|
|
||||||
|
Сводку можно найти на странице \ref summary.
|
||||||
|
|
||||||
|
Базовое использование PIP описано на странице \ref using_basic.
|
||||||
104
doc/pages/summary.md
Normal file
104
doc/pages/summary.md
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
\~english \page summary Functionality summary
|
||||||
|
\~russian \page summary Сводка функциональности
|
||||||
|
|
||||||
|
\~english
|
||||||
|
|
||||||
|
* direct output to console (\a PICout)
|
||||||
|
* containers (\a PIVector, \a PIDeque, \a PIVector2D, \a PIStack, \a PIQueue, \a PIMap, \a PISet)
|
||||||
|
* byte array (\a PIByteArray)
|
||||||
|
* serialization (\a PIChunkStream)
|
||||||
|
* string (\a PIConstChars, \a PIString, \a PIStringList)
|
||||||
|
* base object (events and handlers) (\a PIObject)
|
||||||
|
* multithreading
|
||||||
|
* thread (\a PIThread)
|
||||||
|
* blocking (\a PIMutex, \a PISpinlock)
|
||||||
|
* executor (\a PIThreadPoolExecutor)
|
||||||
|
* blocking dequeue (\a PIBlockingDequeue)
|
||||||
|
* timer (\a PITimer)
|
||||||
|
* tiling console (with widgets) (\a PIScreen)
|
||||||
|
* simple text rows
|
||||||
|
* scroll bar
|
||||||
|
* list
|
||||||
|
* button
|
||||||
|
* buttons group
|
||||||
|
* check box
|
||||||
|
* progress bar
|
||||||
|
* PICout output
|
||||||
|
* text input
|
||||||
|
* I/O devices
|
||||||
|
* base class (\a PIIODevice)
|
||||||
|
* file (\a PIFile)
|
||||||
|
* serial port (\a PISerial)
|
||||||
|
* ethernet (\a PIEthernet)
|
||||||
|
* USB (\a PIUSB)
|
||||||
|
* packets extractor (\a PIPacketExtractor)
|
||||||
|
* binary log (\a PIBinaryLog)
|
||||||
|
* complex I/O point (\a PIConnection)
|
||||||
|
* peering net node (\a PIPeer)
|
||||||
|
* connection quality diagnotic (\a PIDiagnostics)
|
||||||
|
* Run-time libraries
|
||||||
|
* abstract (\a PILibrary)
|
||||||
|
* plugin (\a PIPluginLoader)
|
||||||
|
* Mathematics
|
||||||
|
* complex numbers
|
||||||
|
* vectors (\a PIMathVector, \a PIMathVectorT)
|
||||||
|
* matrices (\a PIMathMatrix, \a PIMathMatrixT)
|
||||||
|
* quaternion (\a PIQuaternion)
|
||||||
|
* 2D geometry (\a PIPoint, \a PILine, \a PIRect)
|
||||||
|
* statistic (\a PIStatistic)
|
||||||
|
* CRC checksum (\a PICRC)
|
||||||
|
* Fourier transform (\a PIFFTW, \a PIFFT)
|
||||||
|
* expression evaluator (\a PIEvaluator)
|
||||||
|
* command-line arguments parser (\a PICLI)
|
||||||
|
* process (\a PIProcess)
|
||||||
|
|
||||||
|
\~russian
|
||||||
|
|
||||||
|
* общение с консолью (\a PICout)
|
||||||
|
* контейнеры (\a PIVector, \a PIDeque, \a PIVector2D, \a PIStack, \a PIQueue, \a PIMap, \a PISet)
|
||||||
|
* байтовый массив (\a PIByteArray)
|
||||||
|
* сериализация (\a PIChunkStream)
|
||||||
|
* строка (\a PIConstChars, \a PIString, \a PIStringList)
|
||||||
|
* базовый объект (события и обработчики) (\a PIObject)
|
||||||
|
* многопоточность
|
||||||
|
* поток (\a PIThread)
|
||||||
|
* блокировки (\a PIMutex, \a PISpinlock)
|
||||||
|
* исполнитель (\a PIThreadPoolExecutor)
|
||||||
|
* блокирующая очередь (\a PIBlockingDequeue)
|
||||||
|
* таймер (\a PITimer)
|
||||||
|
* тайлинговая консоль (с виджетами) (\a PIScreen)
|
||||||
|
* простой вывод строк
|
||||||
|
* скроллбар
|
||||||
|
* лист
|
||||||
|
* кнопка
|
||||||
|
* группа кнопок
|
||||||
|
* галочка
|
||||||
|
* прогрессбар
|
||||||
|
* вывод PICout
|
||||||
|
* текстовый ввод
|
||||||
|
* устройства ввода/вывода
|
||||||
|
* базовый класс (\a PIIODevice)
|
||||||
|
* файл (\a PIFile)
|
||||||
|
* последовательный порт (\a PISerial)
|
||||||
|
* ethernet (\a PIEthernet)
|
||||||
|
* USB (\a PIUSB)
|
||||||
|
* packets extractor (\a PIPacketExtractor)
|
||||||
|
* бинарный логфайл (\a PIBinaryLog)
|
||||||
|
* сложное составное устройство (\a PIConnection)
|
||||||
|
* пиринговая сеть (\a PIPeer)
|
||||||
|
* диагностика качества связи (\a PIDiagnostics)
|
||||||
|
* поддержка библиотек времени выполнения
|
||||||
|
* базовая функциональность (\a PILibrary)
|
||||||
|
* плагин (\a PIPluginLoader)
|
||||||
|
* Математика
|
||||||
|
* комплексные числа
|
||||||
|
* вектора (\a PIMathVector, \a PIMathVectorT)
|
||||||
|
* матрицы (\a PIMathMatrix, \a PIMathMatrixT)
|
||||||
|
* кватернион (\a PIQuaternion)
|
||||||
|
* 2D геометрия (\a PIPoint, \a PILine, \a PIRect)
|
||||||
|
* статистика (\a PIStatistic)
|
||||||
|
* CRC контрольная сумма (\a PICRC)
|
||||||
|
* преобразования Фурье (\a PIFFTW, \a PIFFT)
|
||||||
|
* вычислитель выражений (\a PIEvaluator)
|
||||||
|
* парсер аргументов командной строки (\a PICLI)
|
||||||
|
* процесс (\a PIProcess)
|
||||||
128
doc/pages/using_basic.md
Normal file
128
doc/pages/using_basic.md
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
\~english \page using_basic Getting started
|
||||||
|
\~russian \page using_basic Простые начала
|
||||||
|
|
||||||
|
\~english
|
||||||
|
|
||||||
|
Many novice programmers are solved many common task with system integrity: output to console,
|
||||||
|
keyboard buttons press detecting, working with serial ports, ethernet or files, and many other.
|
||||||
|
These tasks can solve this library, and code, based only on PIP will be compile and work
|
||||||
|
similar on many systems: Windows, any Linux, Red Hat, FreeBSD, MacOS X and QNX.
|
||||||
|
Typical application on PIP looks like this: \n
|
||||||
|
|
||||||
|
\~russian
|
||||||
|
|
||||||
|
Многие начинающие программисты решают общие задачи взаимодействия с операционной системой:
|
||||||
|
вывод в консоль, определение нажатия клавиш, работа с последовательными портами, сетью или файлами,
|
||||||
|
и многое другое. Эти задачи решены в библиотеке, и код, основанный на PIP будет компилироваться
|
||||||
|
и работать одинаково на многих системах: Windows, любой Linux, Red Hat, FreeBSD, MacOS X и QNX.
|
||||||
|
Типовое приложение на PIP выглядит примерно так: \n
|
||||||
|
|
||||||
|
\code{.cpp}
|
||||||
|
#include <pip.h>
|
||||||
|
|
||||||
|
|
||||||
|
// declare key press handler
|
||||||
|
void key_event(char key, void * );
|
||||||
|
|
||||||
|
|
||||||
|
PIConsole console(false, key_event); // don`t start now, key handler is "key_event"
|
||||||
|
|
||||||
|
|
||||||
|
// some vars
|
||||||
|
int i = 2, j = 3;
|
||||||
|
|
||||||
|
|
||||||
|
// implicit key press handler
|
||||||
|
void key_event(char key, void * ) {
|
||||||
|
switch (key) {
|
||||||
|
case '-':
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
j--;
|
||||||
|
break;
|
||||||
|
case ')':
|
||||||
|
j++;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class MainClass: public PITimer {
|
||||||
|
PIOBJECT(MainClass)
|
||||||
|
public:
|
||||||
|
MainClass() {}
|
||||||
|
protected:
|
||||||
|
void tick(void * data, int delimiter) {
|
||||||
|
piCout << "timer tick";
|
||||||
|
// timer tick
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
MainClass main_class;
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char * argv[]) {
|
||||||
|
// enabling auto-detection of exit button press, by default 'Q' (shift+q)
|
||||||
|
console.enableExitCapture();
|
||||||
|
|
||||||
|
// if we want to parse command-line arguments
|
||||||
|
PICLI cli(argc, argv);
|
||||||
|
cli.addArgument("console"); // "-c" or "--console"
|
||||||
|
cli.addArgument("debug"); // "-d" or "--debug"
|
||||||
|
|
||||||
|
// enabling or disabling global debug flag
|
||||||
|
piDebug = cli.hasArgument("debug");
|
||||||
|
|
||||||
|
// configure console
|
||||||
|
console.addTab("first tab", '1');
|
||||||
|
console.addString("PIP console", 1, PIConsole::Bold);
|
||||||
|
console.addVariable("int var (i)", &i, 1);
|
||||||
|
console.addVariable("int green var (j)", &j, 1, PIConsole::Green);
|
||||||
|
console.addString("'-' - i--", 2);
|
||||||
|
console.addString("'+' - i++", 2);
|
||||||
|
console.addString("'(' - j--", 2);
|
||||||
|
console.addString("')' - j++", 2);
|
||||||
|
console.addTab("second tab", '2');
|
||||||
|
console.addString("col 1", 1);
|
||||||
|
console.addString("col 2", 2);
|
||||||
|
console.addString("col 3", 3);
|
||||||
|
console.setTab("first tab");
|
||||||
|
|
||||||
|
// start output to console if "console" argument exists
|
||||||
|
if (cli.hasArgument("console"))
|
||||||
|
console.start();
|
||||||
|
|
||||||
|
// start main class, e.g. 40 Hz
|
||||||
|
main_class.start(25.);
|
||||||
|
|
||||||
|
// wait for 'Q' press, independently if console is started or not
|
||||||
|
console.waitForFinish();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
\~english
|
||||||
|
|
||||||
|
This code demonstrates simple interactive configurable program, which can be started with console
|
||||||
|
display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
||||||
|
\a PIThread and reimplement \a run() function.
|
||||||
|
\n Many PIP classes has events and event handlers, which can be connected one to another.
|
||||||
|
Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
||||||
|
\n To configure your program from file use \a PIConfig.
|
||||||
|
\n If you want more information see \ref using_advanced
|
||||||
|
|
||||||
|
\~russian
|
||||||
|
|
||||||
|
Этот код демонстрирует простую конфигурируемую программу, которая может быть запущена с
|
||||||
|
This code demonstrates simple interactive configurable program, which can be started with console
|
||||||
|
display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
||||||
|
\a PIThread and reimplement \a run() function.
|
||||||
|
\n Many PIP classes has events and event handlers, which can be connected one to another.
|
||||||
|
Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
||||||
|
\n To configure your program from file use \a PIConfig.
|
||||||
@@ -219,14 +219,15 @@ void PIScreen::SystemConsole::print() {
|
|||||||
} else {
|
} else {
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
moveTo(si, sj);
|
moveTo(si, sj);
|
||||||
printf("%s", s.data());
|
PICout::stdoutPIString(s);
|
||||||
s.clear();
|
s.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
moveTo(si, sj);
|
moveTo(si, sj);
|
||||||
printf("%s", s.data());
|
PICout::stdoutPIString(s);
|
||||||
|
//printf("%s", s.data());
|
||||||
s.clear();
|
s.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,32 +296,32 @@ void PIScreen::SystemConsole::newLine() {
|
|||||||
}
|
}
|
||||||
#else // WINDOWS
|
#else // WINDOWS
|
||||||
PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) {
|
PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) {
|
||||||
PIString ts("\e[0");
|
PIString ts = PIStringAscii("\e[0");
|
||||||
switch (c.format.color_char) {
|
switch (c.format.color_char) {
|
||||||
case Black: ts += ";30"; break;
|
case Black: ts += PIStringAscii(";30"); break;
|
||||||
case Red: ts += ";31"; break;
|
case Red: ts += PIStringAscii(";31"); break;
|
||||||
case Green: ts += ";32"; break;
|
case Green: ts += PIStringAscii(";32"); break;
|
||||||
case Blue: ts += ";34"; break;
|
case Blue: ts += PIStringAscii(";34"); break;
|
||||||
case Cyan: ts += ";36"; break;
|
case Cyan: ts += PIStringAscii(";36"); break;
|
||||||
case Magenta: ts += ";35"; break;
|
case Magenta: ts += PIStringAscii(";35"); break;
|
||||||
case Yellow: ts += ";33"; break;
|
case Yellow: ts += PIStringAscii(";33"); break;
|
||||||
case White: ts += ";37"; break;
|
case White: ts += PIStringAscii(";37"); break;
|
||||||
}
|
}
|
||||||
switch (c.format.color_back) {
|
switch (c.format.color_back) {
|
||||||
case Black: ts += ";40"; break;
|
case Black: ts += PIStringAscii(";40"); break;
|
||||||
case Red: ts += ";41"; break;
|
case Red: ts += PIStringAscii(";41"); break;
|
||||||
case Green: ts += ";42"; break;
|
case Green: ts += PIStringAscii(";42"); break;
|
||||||
case Blue: ts += ";44"; break;
|
case Blue: ts += PIStringAscii(";44"); break;
|
||||||
case Cyan: ts += ";46"; break;
|
case Cyan: ts += PIStringAscii(";46"); break;
|
||||||
case Magenta: ts += ";45"; break;
|
case Magenta: ts += PIStringAscii(";45"); break;
|
||||||
case Yellow: ts += ";43"; break;
|
case Yellow: ts += PIStringAscii(";43"); break;
|
||||||
case White: ts += ";47"; break;
|
case White: ts += PIStringAscii(";47"); break;
|
||||||
}
|
}
|
||||||
if ((c.format.flags & Bold) == Bold) ts += ";1";
|
if ((c.format.flags & Bold ) == Bold ) ts += PIStringAscii(";1");
|
||||||
if ((c.format.flags & Underline) == Underline) ts += ";4";
|
if ((c.format.flags & Underline) == Underline) ts += PIStringAscii(";4");
|
||||||
if ((c.format.flags & Blink) == Blink) ts += ";5";
|
if ((c.format.flags & Blink ) == Blink ) ts += PIStringAscii(";5");
|
||||||
if ((c.format.flags & Inverse) == Inverse) ts += ";7";
|
if ((c.format.flags & Inverse ) == Inverse ) ts += PIStringAscii(";7");
|
||||||
return ts + "m";
|
return ts + 'm';
|
||||||
}
|
}
|
||||||
#endif // WINDOWS
|
#endif // WINDOWS
|
||||||
|
|
||||||
|
|||||||
@@ -689,13 +689,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
case PIKbdListener::F12:
|
case PIKbdListener::F12:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PIChar tc
|
text.insert(cur, PIChar((ushort)key.key));
|
||||||
#ifdef WINDOWS
|
|
||||||
= PIChar((ushort)key.key);
|
|
||||||
#else
|
|
||||||
= PIChar::fromUTF8((char *)&(key.key));
|
|
||||||
#endif
|
|
||||||
text.insert(cur, tc);
|
|
||||||
cur++;
|
cur++;
|
||||||
oo++;
|
oo++;
|
||||||
if (cur - offset >= lwid - osp) offset += oo;
|
if (cur - offset >= lwid - osp) offset += oo;
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ bool PITerminal::initialize() {
|
|||||||
memcpy(argv[0], shell.data(), shell.size());
|
memcpy(argv[0], shell.data(), shell.size());
|
||||||
argv[0][shell.size()] = 0;
|
argv[0][shell.size()] = 0;
|
||||||
argv[1] = 0;
|
argv[1] = 0;
|
||||||
execvp(shell.data(), argv);
|
execvp(argv[0], argv);
|
||||||
delete[] argv[0];
|
delete[] argv[0];
|
||||||
delete[] argv;
|
delete[] argv;
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
class PIP_CLOUD_EXPORT PICloudClient: public PIIODevice, public PICloudBase
|
class PIP_CLOUD_EXPORT PICloudClient: public PIIODevice, public PICloudBase
|
||||||
{
|
{
|
||||||
PIIODEVICE(PICloudClient)
|
PIIODEVICE(PICloudClient, "")
|
||||||
public:
|
public:
|
||||||
explicit PICloudClient(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PICloudClient(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PICloudClient();
|
virtual ~PICloudClient();
|
||||||
|
|||||||
@@ -32,14 +32,14 @@
|
|||||||
|
|
||||||
class PIP_CLOUD_EXPORT PICloudServer: public PIIODevice, public PICloudBase
|
class PIP_CLOUD_EXPORT PICloudServer: public PIIODevice, public PICloudBase
|
||||||
{
|
{
|
||||||
PIIODEVICE(PICloudServer)
|
PIIODEVICE(PICloudServer, "")
|
||||||
public:
|
public:
|
||||||
//! PICloudServer
|
//! PICloudServer
|
||||||
explicit PICloudServer(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PICloudServer(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PICloudServer();
|
virtual ~PICloudServer();
|
||||||
|
|
||||||
class Client : public PIIODevice {
|
class Client : public PIIODevice {
|
||||||
PIIODEVICE(PICloudServer::Client)
|
PIIODEVICE(PICloudServer::Client, "")
|
||||||
friend class PICloudServer;
|
friend class PICloudServer;
|
||||||
public:
|
public:
|
||||||
Client(PICloudServer * srv = nullptr, uint id = 0);
|
Client(PICloudServer * srv = nullptr, uint id = 0);
|
||||||
|
|||||||
@@ -24,39 +24,39 @@
|
|||||||
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
||||||
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
||||||
if (e.value == value_)
|
if (e.value == value_)
|
||||||
return e.name;
|
return e.name.toString();
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
||||||
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
||||||
if (e.name == name_)
|
if (e.name.toString() == name_)
|
||||||
return e.value;
|
return e.value;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
||||||
PIVariantTypes::Enum en(name);
|
PIVariantTypes::Enum en(name.toString());
|
||||||
for (auto m: members) en << m.toPIVariantEnumerator();
|
for (auto m: members) en << m.toPIVariantEnumerator();
|
||||||
if (!en.isEmpty()) en.selectValue(members.front().value);
|
if (!en.isEmpty()) en.selectValue(members.front().value);
|
||||||
return en;
|
return en;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIMap<PIString, PICodeInfo::ClassInfo * > * PICodeInfo::classesInfo;
|
PIMap<PIConstChars, PICodeInfo::ClassInfo * > * PICodeInfo::classesInfo;
|
||||||
PIMap<PIString, PICodeInfo::EnumInfo * > * PICodeInfo::enumsInfo;
|
PIMap<PIConstChars, PICodeInfo::EnumInfo * > * PICodeInfo::enumsInfo;
|
||||||
PIMap<PIString, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
||||||
PIMap<PIString, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
||||||
|
|
||||||
bool __PICodeInfoInitializer__::_inited_ = false;
|
bool __PICodeInfoInitializer__::_inited_ = false;
|
||||||
|
|
||||||
|
|
||||||
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
||||||
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
||||||
AccessTypeFunction atf = accessTypeFunctions->value(PIStringAscii(class_name), (AccessTypeFunction)0);
|
AccessTypeFunction atf = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||||
AccessValueFunction avf = accessValueFunctions->value(PIStringAscii(class_name), (AccessValueFunction)0);
|
AccessValueFunction avf = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||||
if (!atf || !avf) return PIVariant();
|
if (!atf || !avf) return PIVariant();
|
||||||
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#ifndef PICODEINFO_H
|
#ifndef PICODEINFO_H
|
||||||
#define PICODEINFO_H
|
#define PICODEINFO_H
|
||||||
|
|
||||||
|
#include "piconstchars.h"
|
||||||
#include "pistringlist.h"
|
#include "pistringlist.h"
|
||||||
#include "pivarianttypes.h"
|
#include "pivarianttypes.h"
|
||||||
|
|
||||||
@@ -52,18 +53,18 @@ typedef PIByteArray(*AccessValueFunction)(const void *, const char *);
|
|||||||
typedef const char*(*AccessTypeFunction)(const char *);
|
typedef const char*(*AccessTypeFunction)(const char *);
|
||||||
|
|
||||||
struct PIP_EXPORT TypeInfo {
|
struct PIP_EXPORT TypeInfo {
|
||||||
TypeInfo(const PIString & n = PIString(), const PIString & t = PIString(), PICodeInfo::TypeFlags f = 0, int b = -1) {name = n; type = t; flags = f; bits = b;}
|
TypeInfo(const PIConstChars & n = PIConstChars(), const PIConstChars & t = PIConstChars(), PICodeInfo::TypeFlags f = 0, int b = -1) {name = n; type = t; flags = f; bits = b;}
|
||||||
bool isBitfield() const {return bits > 0;}
|
bool isBitfield() const {return bits > 0;}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIString type;
|
PIConstChars type;
|
||||||
PICodeInfo::TypeFlags flags;
|
PICodeInfo::TypeFlags flags;
|
||||||
int bits;
|
int bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT FunctionInfo {
|
struct PIP_EXPORT FunctionInfo {
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
TypeInfo return_type;
|
TypeInfo return_type;
|
||||||
PIVector<PICodeInfo::TypeInfo> arguments;
|
PIVector<PICodeInfo::TypeInfo> arguments;
|
||||||
};
|
};
|
||||||
@@ -72,19 +73,19 @@ struct PIP_EXPORT ClassInfo {
|
|||||||
ClassInfo() {has_name = true;}
|
ClassInfo() {has_name = true;}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
bool has_name;
|
bool has_name;
|
||||||
PIString type;
|
PIConstChars type;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIStringList parents;
|
PIVector<PIConstChars> parents;
|
||||||
PIVector<PICodeInfo::TypeInfo> variables;
|
PIVector<PICodeInfo::TypeInfo> variables;
|
||||||
PIVector<PICodeInfo::FunctionInfo> functions;
|
PIVector<PICodeInfo::FunctionInfo> functions;
|
||||||
PIVector<PICodeInfo::ClassInfo * > children_info;
|
PIVector<PICodeInfo::ClassInfo * > children_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT EnumeratorInfo {
|
struct PIP_EXPORT EnumeratorInfo {
|
||||||
EnumeratorInfo(const PIString & n = PIString(), int v = 0) {name = n; value = v;}
|
EnumeratorInfo(const PIConstChars & n = PIConstChars(), int v = 0) {name = n; value = v;}
|
||||||
PIVariantTypes::Enumerator toPIVariantEnumerator() {return PIVariantTypes::Enumerator(value, name);}
|
PIVariantTypes::Enumerator toPIVariantEnumerator() {return PIVariantTypes::Enumerator(value, name.toString());}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
int value;
|
int value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ struct PIP_EXPORT EnumInfo {
|
|||||||
int memberValue(const PIString & name) const;
|
int memberValue(const PIString & name) const;
|
||||||
PIVariantTypes::Enum toPIVariantEnum();
|
PIVariantTypes::Enum toPIVariantEnum();
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIVector<PICodeInfo::EnumeratorInfo> members;
|
PIVector<PICodeInfo::EnumeratorInfo> members;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,17 +120,17 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
if (!v.parents.isEmpty()) {
|
if (!v.parents.isEmpty()) {
|
||||||
s << ": ";
|
s << ": ";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
piForeachC (PIString & i, v.parents) {
|
for (const auto & i: v.parents) {
|
||||||
if (first) first = false;
|
if (first) first = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
s << i;
|
s << i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s << " Meta" << v.meta << " {\n";
|
s << " Meta" << v.meta << " {\n";
|
||||||
piForeachC (FunctionInfo & i, v.functions) {
|
for (const auto & i: v.functions) {
|
||||||
s << PICoutManipulators::Tab << i.return_type << " " << i.name << "(";
|
s << PICoutManipulators::Tab << i.return_type << " " << i.name << "(";
|
||||||
bool fa = true;
|
bool fa = true;
|
||||||
piForeachC (TypeInfo & a, i.arguments) {
|
for (const auto & a: i.arguments) {
|
||||||
if (fa) fa = false;
|
if (fa) fa = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
s << a;
|
s << a;
|
||||||
@@ -138,7 +139,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
}
|
}
|
||||||
if (!v.functions.isEmpty() && !v.variables.isEmpty())
|
if (!v.functions.isEmpty() && !v.variables.isEmpty())
|
||||||
s << "\n";
|
s << "\n";
|
||||||
piForeachC (TypeInfo & i, v.variables) {
|
for (const auto & i: v.variables) {
|
||||||
s << PICoutManipulators::Tab << i << " Meta" << i.meta << ";\n";
|
s << PICoutManipulators::Tab << i << " Meta" << i.meta << ";\n";
|
||||||
}
|
}
|
||||||
s << "}\n";
|
s << "}\n";
|
||||||
@@ -149,7 +150,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
s << "enum " << v.name << " Meta" << v.meta << " {\n";
|
s << "enum " << v.name << " Meta" << v.meta << " {\n";
|
||||||
piForeachC (EnumeratorInfo & i, v.members) {
|
for (const auto & i: v.members) {
|
||||||
bool f = true;
|
bool f = true;
|
||||||
if (f) f = false;
|
if (f) f = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
@@ -160,21 +161,21 @@ inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::ClassInfo * > * classesInfo;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::ClassInfo * > * classesInfo;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::EnumInfo * > * enumsInfo;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::EnumInfo * > * enumsInfo;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||||
|
|
||||||
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
||||||
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
||||||
AccessValueFunction af = accessValueFunctions->value(PIStringAscii(class_name), (AccessValueFunction)0);
|
AccessValueFunction af = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||||
if (!af) return PIByteArray();
|
if (!af) return PIByteArray();
|
||||||
return af(p, member_name);
|
return af(p, member_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
||||||
if (!class_name || !member_name || !accessTypeFunctions) return "";
|
if (!class_name || !member_name || !accessTypeFunctions) return "";
|
||||||
AccessTypeFunction af = accessTypeFunctions->value(PIStringAscii(class_name), (AccessTypeFunction)0);
|
AccessTypeFunction af = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||||
if (!af) return "";
|
if (!af) return "";
|
||||||
return af(member_name);
|
return af(member_name);
|
||||||
}
|
}
|
||||||
@@ -195,10 +196,10 @@ public:
|
|||||||
__PICodeInfoInitializer__() {
|
__PICodeInfoInitializer__() {
|
||||||
if (_inited_) return;
|
if (_inited_) return;
|
||||||
_inited_ = true;
|
_inited_ = true;
|
||||||
PICodeInfo::classesInfo = new PIMap<PIString, PICodeInfo::ClassInfo * >;
|
PICodeInfo::classesInfo = new PIMap<PIConstChars, PICodeInfo::ClassInfo * >;
|
||||||
PICodeInfo::enumsInfo = new PIMap<PIString, PICodeInfo::EnumInfo * >;
|
PICodeInfo::enumsInfo = new PIMap<PIConstChars, PICodeInfo::EnumInfo * >;
|
||||||
PICodeInfo::accessValueFunctions = new PIMap<PIString, PICodeInfo::AccessValueFunction>;
|
PICodeInfo::accessValueFunctions = new PIMap<PIConstChars, PICodeInfo::AccessValueFunction>;
|
||||||
PICodeInfo::accessTypeFunctions = new PIMap<PIString, PICodeInfo::AccessTypeFunction>;
|
PICodeInfo::accessTypeFunctions = new PIMap<PIConstChars, PICodeInfo::AccessTypeFunction>;
|
||||||
}
|
}
|
||||||
static bool _inited_;
|
static bool _inited_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
PIString prev_namespace = cur_namespace, ccmn;
|
PIString prev_namespace = cur_namespace, ccmn;
|
||||||
cur_namespace += pfc.takeCWord() + s_ns;
|
cur_namespace += pfc.takeCWord() + s_ns;
|
||||||
ccmn = pfc.takeRange('{', '}');
|
ccmn = pfc.takeRange('{', '}');
|
||||||
parseClass(0, ccmn);
|
parseClass(0, ccmn, true);
|
||||||
cur_namespace = prev_namespace;
|
cur_namespace = prev_namespace;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;}
|
if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;}
|
||||||
ccmn = pfc.left(dind) + s_bo + pfc.mid(dind).takeRange('{', '}') + s_bc;
|
ccmn = pfc.left(dind) + s_bo + pfc.mid(dind).takeRange('{', '}') + s_bc;
|
||||||
pfc.remove(0, ccmn.size());
|
pfc.remove(0, ccmn.size());
|
||||||
parseClass(0, ccmn);
|
parseClass(0, ccmn, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (pfc.left(4) == s_enum) {
|
if (pfc.left(4) == s_enum) {
|
||||||
@@ -425,7 +425,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) {
|
||||||
static const PIString s_ns = PIStringAscii("::");
|
static const PIString s_ns = PIStringAscii("::");
|
||||||
static const PIString s_public = PIStringAscii("public");
|
static const PIString s_public = PIStringAscii("public");
|
||||||
static const PIString s_protected = PIStringAscii("protected");
|
static const PIString s_protected = PIStringAscii("protected");
|
||||||
@@ -436,22 +436,31 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
static const PIString s_enum = PIStringAscii("enum");
|
static const PIString s_enum = PIStringAscii("enum");
|
||||||
static const PIString s_friend = PIStringAscii("friend");
|
static const PIString s_friend = PIStringAscii("friend");
|
||||||
static const PIString s_typedef = PIStringAscii("typedef");
|
static const PIString s_typedef = PIStringAscii("typedef");
|
||||||
|
static const PIString s_namespace = PIStringAscii("namespace");
|
||||||
static const PIString s_template = PIStringAscii("template");
|
static const PIString s_template = PIStringAscii("template");
|
||||||
Visibility prev_vis = cur_def_vis;
|
Visibility prev_vis = cur_def_vis;
|
||||||
int dind = fc.find('{'), find = fc.find(';'), end = 0;
|
int dind = fc.find('{'), find = fc.find(';'), end = 0;
|
||||||
if (dind < 0 && find < 0) return PIString();
|
if (dind < 0 && find < 0) return;
|
||||||
if (dind < 0 || find < dind) return fc.left(find);
|
if (dind < 0 || find < dind) {
|
||||||
//piCout << "parse class <****\n" << fc.left(20) << "\n****>";
|
fc.left(find);
|
||||||
Entity * ce = parseClassDeclaration(fc.takeLeft(dind));
|
return;
|
||||||
|
}
|
||||||
|
//piCout << "parse class <****\n" << fc << "\n****>";
|
||||||
|
Entity * ce = parent;
|
||||||
|
if (!is_namespace) {
|
||||||
|
ce = parseClassDeclaration(fc.takeLeft(dind));
|
||||||
fc.trim().cutLeft(1).cutRight(1).trim();
|
fc.trim().cutLeft(1).cutRight(1).trim();
|
||||||
|
}
|
||||||
//piCout << "found class <****\n" << fc << "\n****>";
|
//piCout << "found class <****\n" << fc << "\n****>";
|
||||||
if (!ce) return PIString();
|
///if (!ce) return PIString();
|
||||||
|
if (ce) {
|
||||||
if (parent) parent->children << ce;
|
if (parent) parent->children << ce;
|
||||||
ce->parent_scope = parent;
|
ce->parent_scope = parent;
|
||||||
|
}
|
||||||
int ps = -1;
|
int ps = -1;
|
||||||
bool def = false;
|
bool def = false;
|
||||||
PIString prev_namespace = cur_namespace, stmp;
|
PIString prev_namespace = cur_namespace, stmp;
|
||||||
cur_namespace += ce->name + s_ns;
|
if (ce) cur_namespace += ce->name + s_ns;
|
||||||
//piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
//piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
||||||
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
||||||
while (!fc.isEmpty()) {
|
while (!fc.isEmpty()) {
|
||||||
@@ -460,6 +469,14 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
if (cw == s_public ) {cur_def_vis = Public; fc.cutLeft(1); continue;}
|
if (cw == s_public ) {cur_def_vis = Public; fc.cutLeft(1); continue;}
|
||||||
if (cw == s_protected) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
|
if (cw == s_protected) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
|
||||||
if (cw == s_private ) {cur_def_vis = Private; fc.cutLeft(1); continue;}
|
if (cw == s_private ) {cur_def_vis = Private; fc.cutLeft(1); continue;}
|
||||||
|
if (cw == s_namespace) {
|
||||||
|
PIString prev_namespace = cur_namespace, ccmn;
|
||||||
|
cur_namespace += fc.takeCWord() + s_ns;
|
||||||
|
ccmn = fc.takeRange('{', '}');
|
||||||
|
parseClass(ce, ccmn, true);
|
||||||
|
cur_namespace = prev_namespace;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (cw == s_class || cw == s_struct || cw == s_union) {
|
if (cw == s_class || cw == s_struct || cw == s_union) {
|
||||||
if (isDeclaration(fc, 0, &end)) {
|
if (isDeclaration(fc, 0, &end)) {
|
||||||
fc.cutLeft(end);
|
fc.cutLeft(end);
|
||||||
@@ -470,7 +487,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
stmp = fc.takeRange('{', '}');
|
stmp = fc.takeRange('{', '}');
|
||||||
fc.takeSymbol();
|
fc.takeSymbol();
|
||||||
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
||||||
parseClass(ce, stmp);
|
parseClass(ce, stmp, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cw == s_enum) {
|
if (cw == s_enum) {
|
||||||
@@ -483,11 +500,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
}
|
}
|
||||||
if (cw == s_friend) {fc.cutLeft(fc.find(';') + 1); continue;}
|
if (cw == s_friend) {fc.cutLeft(fc.find(';') + 1); continue;}
|
||||||
if (cw == s_typedef) {
|
if (cw == s_typedef) {
|
||||||
|
if (ce) {
|
||||||
ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';')));
|
ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';')));
|
||||||
typedefs << ce->typedefs.back();
|
typedefs << ce->typedefs.back();
|
||||||
typedefs.back().first.insert(0, cur_namespace);
|
typedefs.back().first.insert(0, cur_namespace);
|
||||||
if (ce->typedefs.back().first.isEmpty())
|
if (ce->typedefs.back().first.isEmpty())
|
||||||
ce->typedefs.pop_back();
|
ce->typedefs.pop_back();
|
||||||
|
}
|
||||||
fc.takeSymbol();
|
fc.takeSymbol();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -501,7 +520,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
}
|
}
|
||||||
def = !isDeclaration(fc, 0, &end);
|
def = !isDeclaration(fc, 0, &end);
|
||||||
tmp = (cw + fc.takeLeft(end)).trim();
|
tmp = (cw + fc.takeLeft(end)).trim();
|
||||||
if (!tmp.isEmpty())
|
if (!tmp.isEmpty() && ce)
|
||||||
parseMember(ce, tmp);
|
parseMember(ce, tmp);
|
||||||
if (def) fc.takeRange('{', '}');
|
if (def) fc.takeRange('{', '}');
|
||||||
else fc.takeSymbol();
|
else fc.takeSymbol();
|
||||||
@@ -510,7 +529,6 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
|||||||
}
|
}
|
||||||
cur_def_vis = prev_vis;
|
cur_def_vis = prev_vis;
|
||||||
cur_namespace = prev_namespace;
|
cur_namespace = prev_namespace;
|
||||||
return ce->name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ private:
|
|||||||
bool parseFileContent(PIString & fc, bool main);
|
bool parseFileContent(PIString & fc, bool main);
|
||||||
bool parseDirective(PIString d);
|
bool parseDirective(PIString d);
|
||||||
Entity * parseClassDeclaration(const PIString & fc);
|
Entity * parseClassDeclaration(const PIString & fc);
|
||||||
PIString parseClass(Entity * parent, PIString & fc);
|
void parseClass(Entity * parent, PIString & fc, bool is_namespace);
|
||||||
MetaMap parseMeta(PIString & fc);
|
MetaMap parseMeta(PIString & fc);
|
||||||
bool parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta);
|
bool parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta);
|
||||||
Typedef parseTypedef(PIString fc);
|
Typedef parseTypedef(PIString fc);
|
||||||
|
|||||||
@@ -323,12 +323,18 @@ void PIKbdListener::readKeyboard() {
|
|||||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||||
PICout(0) << PICoutManipulators::Hex << int(((uchar * )&rc)[i]) << ' ';
|
PICout(0) << PICoutManipulators::Hex << int(((uchar * )&rc)[i]) << ' ';
|
||||||
PICout(0) << "\n";
|
PICout(0) << "\n";
|
||||||
|
std::cout << PRIVATE->ret << " chars ";
|
||||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||||
cout << "'" << (char)(rc[i]) << "' ";
|
std::cout << "'" << (char)(rc[i]) << "' " << (int)(uchar)(rc[i]);
|
||||||
cout << endl;*/
|
std::cout << std::endl;*/
|
||||||
if (rc[0] == 0) {piMSleep(10); return;}
|
if (rc[0] == 0) {piMSleep(10); return;}
|
||||||
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
||||||
if (PRIVATE->ret == 1) ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
if (PRIVATE->ret == 1) {
|
||||||
|
if (rc[0] == 8)
|
||||||
|
ke.key = Backspace;
|
||||||
|
else
|
||||||
|
ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
||||||
|
}
|
||||||
int mod(0);
|
int mod(0);
|
||||||
// 2 - shift 1
|
// 2 - shift 1
|
||||||
// 3 - alt 2
|
// 3 - alt 2
|
||||||
|
|||||||
34
libs/main/containers/picontainers.cpp
Normal file
34
libs/main/containers/picontainers.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Base macros for generic containers
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "picontainers.h"
|
||||||
|
|
||||||
|
|
||||||
|
const ssize_t minAlloc = 64;
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t _PIContainerConstantsBase::calcMinCountPoT(ssize_t szof) {
|
||||||
|
ssize_t ret = 0, elc = 1;
|
||||||
|
while (elc * szof < minAlloc) {
|
||||||
|
elc *= 2;
|
||||||
|
++ret;
|
||||||
|
}
|
||||||
|
//printf("calcMinCount sizeof = %d, min_count = %d, pot = %d\n", szof, elc, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -63,6 +63,18 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class PIP_EXPORT _PIContainerConstantsBase {
|
||||||
|
public:
|
||||||
|
static ssize_t calcMinCountPoT(ssize_t szof);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class _PIContainerConstants {
|
||||||
|
public:
|
||||||
|
static ssize_t minCountPoT() {static ssize_t ret = _PIContainerConstantsBase::calcMinCountPoT(sizeof(T)); return ret;}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Template reverse wrapper over any container
|
//! \~english Template reverse wrapper over any container
|
||||||
//! \~russian Шаблонная функция обертки любого контейнера для обратного доступа через итераторы
|
//! \~russian Шаблонная функция обертки любого контейнера для обратного доступа через итераторы
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
//! первый элемент массива имеет индекс, равный `0`,
|
//! первый элемент массива имеет индекс, равный `0`,
|
||||||
//! а индекс последнего элемента равен `size() - 1`.
|
//! а индекс последнего элемента равен `size() - 1`.
|
||||||
//! Также для массива доступен набор различных удобных функций,
|
//! Также для массива доступен набор различных удобных функций,
|
||||||
//! например: \a indexOf, \a contains(), \a entries(), \a isEmpty(), \a isNotEmpty(),
|
//! например: \a indexOf(), \a contains(), \a entries(), \a isEmpty(), \a isNotEmpty(),
|
||||||
//! \a every(), \a any(), \a forEach(), \a indexWhere(), \a getRange(), \a sort(),
|
//! \a every(), \a any(), \a forEach(), \a indexWhere(), \a getRange(), \a sort(),
|
||||||
//! \a map(), \a reduce(), \a filter(), \a flatten(), \a reshape() и другие.
|
//! \a map(), \a reduce(), \a filter(), \a flatten(), \a reshape() и другие.
|
||||||
//!
|
//!
|
||||||
@@ -611,7 +611,7 @@ public:
|
|||||||
//! \~\sa \a rend(), \a begin(), \a end()
|
//! \~\sa \a rend(), \a begin(), \a end()
|
||||||
inline reverse_iterator rbegin() {return reverse_iterator(this, pid_size - 1);}
|
inline reverse_iterator rbegin() {return reverse_iterator(this, pid_size - 1);}
|
||||||
|
|
||||||
//! \~english Returns a reverse iterator to the element
|
//! \~english Returns a reverse iterator to the element.
|
||||||
//! following the last element of the reversed array.
|
//! following the last element of the reversed array.
|
||||||
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
||||||
//! \~\details 
|
//! \~\details 
|
||||||
@@ -2280,10 +2280,9 @@ private:
|
|||||||
if (pid_rsize + pid_rsize >= size_t(s) && pid_rsize < size_t(s)) {
|
if (pid_rsize + pid_rsize >= size_t(s) && pid_rsize < size_t(s)) {
|
||||||
return pid_rsize + pid_rsize;
|
return pid_rsize + pid_rsize;
|
||||||
}
|
}
|
||||||
ssize_t t = 0, s_ = s - 1;
|
ssize_t t = _PIContainerConstants<T>::minCountPoT(), s_ = s - 1;
|
||||||
while (s_ >> t) {
|
while (s_ >> t)
|
||||||
++t;
|
++t;
|
||||||
}
|
|
||||||
return (1 << t);
|
return (1 << t);
|
||||||
}
|
}
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
|
|||||||
@@ -30,41 +30,6 @@
|
|||||||
#include "pipair.h"
|
#include "pipair.h"
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void piQuickSort(T * a, ssize_t N) {
|
|
||||||
if (N < 1) return;
|
|
||||||
if (N < 46) {
|
|
||||||
T tmp;
|
|
||||||
ssize_t i,j;
|
|
||||||
for(i=1; i<=N; i++) {
|
|
||||||
tmp = a[i];
|
|
||||||
j = i-1;
|
|
||||||
while(tmp<a[j] && j>=0) {
|
|
||||||
a[j+1] = a[j];
|
|
||||||
j = j-1;
|
|
||||||
}
|
|
||||||
a[j+1] = tmp;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ssize_t i = 0, j = N;
|
|
||||||
T & p(a[N >> 1]);
|
|
||||||
do {
|
|
||||||
while (a[i] < p) i++;
|
|
||||||
while (a[j] > p) j--;
|
|
||||||
if (i <= j) {
|
|
||||||
if (i != j) {
|
|
||||||
//piCout << "swap" << i << j << a[i] << a[j];
|
|
||||||
piSwap<T>(a[i], a[j]);
|
|
||||||
}
|
|
||||||
i++; j--;
|
|
||||||
}
|
|
||||||
} while (i <= j);
|
|
||||||
if (j > 0) piQuickSort(a, j);
|
|
||||||
if (N > i) piQuickSort(a + i, N - i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Key, typename T>
|
template <typename Key, typename T>
|
||||||
class PIMapIterator;
|
class PIMapIterator;
|
||||||
|
|
||||||
@@ -75,16 +40,19 @@ class PIMap {
|
|||||||
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIMap<Key1, T1> & v);
|
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIMap<Key1, T1> & v);
|
||||||
template <typename Key1, typename T1> friend class PIMapIterator;
|
template <typename Key1, typename T1> friend class PIMapIterator;
|
||||||
public:
|
public:
|
||||||
PIMap() {;}
|
PIMap() {}
|
||||||
PIMap(const PIMap<Key, T> & other) {*this = other;}
|
PIMap(const PIMap<Key, T> & other) {*this = other;}
|
||||||
PIMap(PIMap<Key, T> && other) : pim_content(std::move(other.pim_content)), pim_index(std::move(other.pim_index)) {}
|
PIMap(PIMap<Key, T> && other) : pim_content(std::move(other.pim_content)) {}
|
||||||
|
PIMap(std::initializer_list<std::pair<Key, T>> init_list) {
|
||||||
|
for (auto i: init_list)
|
||||||
|
insert(std::get<0>(i), std::get<1>(i));
|
||||||
|
}
|
||||||
virtual ~PIMap() {;}
|
virtual ~PIMap() {;}
|
||||||
|
|
||||||
PIMap<Key, T> & operator =(const PIMap<Key, T> & other) {
|
PIMap<Key, T> & operator =(const PIMap<Key, T> & other) {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
clear();
|
clear();
|
||||||
pim_content = other.pim_content;
|
pim_content = other.pim_content;
|
||||||
pim_index = other.pim_index;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,12 +167,15 @@ public:
|
|||||||
T & operator [](const Key & key) {
|
T & operator [](const Key & key) {
|
||||||
bool f(false);
|
bool f(false);
|
||||||
ssize_t i = _find(key, f);
|
ssize_t i = _find(key, f);
|
||||||
if (f) return pim_content[pim_index[i].index];
|
if (!f) pim_content.insert(i, PIPair<Key, T>(key, T()));
|
||||||
pim_content.push_back(T());
|
return pim_content[i].second;
|
||||||
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
}
|
||||||
return pim_content.back();
|
const T operator [](const Key & key) const {
|
||||||
|
bool f(false);
|
||||||
|
ssize_t i = _find(key, f);
|
||||||
|
if (f) return pim_content[i].second;
|
||||||
|
return T();
|
||||||
}
|
}
|
||||||
const T operator [](const Key & key) const {bool f(false); ssize_t i = _find(key, f); if (f) return pim_content[pim_index[i].index]; return T();}
|
|
||||||
const T at(const Key & key) const {return (*this)[key];}
|
const T at(const Key & key) const {return (*this)[key];}
|
||||||
|
|
||||||
PIMap<Key, T> & operator <<(const PIMap<Key, T> & other) {
|
PIMap<Key, T> & operator <<(const PIMap<Key, T> & other) {
|
||||||
@@ -215,27 +186,26 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
assert(&other != this);
|
assert(&other != this);
|
||||||
if (other.isEmpty()) return *this;
|
if (other.isEmpty()) return *this;
|
||||||
if (other.size() == 1) {insert(other.pim_index[0].key, other.pim_content[0]); return *this;}
|
// if (other.size() == 1) {insert(other.pim_index[0].key, other.pim_content[0]); return *this;}
|
||||||
if (other.size() == 2) {insert(other.pim_index[0].key, other.pim_content[0]); insert(other.pim_index[1].key, other.pim_content[1]); return *this;}
|
// if (other.size() == 2) {insert(other.pim_index[0].key, other.pim_content[0]); insert(other.pim_index[1].key, other.pim_content[1]); return *this;}
|
||||||
for (int i = 0; i < other.pim_index.size_s(); ++i)
|
for (int i = 0; i < other.pim_content.size_s(); ++i)
|
||||||
insert(other.pim_index[i].key, other.pim_content[other.pim_index[i].index]);
|
insert(other.pim_content[i].first, other.pim_content[i].second);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(const PIMap<Key, T> & t) const {return (pim_content == t.pim_content && pim_index == t.pim_index);}
|
bool operator ==(const PIMap<Key, T> & t) const {return (pim_content == t.pim_content);}
|
||||||
bool operator !=(const PIMap<Key, T> & t) const {return (pim_content != t.pim_content || pim_index != t.pim_index);}
|
bool operator !=(const PIMap<Key, T> & t) const {return (pim_content != t.pim_content);}
|
||||||
bool contains(const Key & key) const {bool f(false); _find(key, f); return f;}
|
bool contains(const Key & key) const {bool f(false); _find(key, f); return f;}
|
||||||
|
|
||||||
PIMap<Key, T> & reserve(size_t new_size) {pim_content.reserve(new_size); pim_index.reserve(new_size); return *this;}
|
PIMap<Key, T> & reserve(size_t new_size) {pim_content.reserve(new_size);return *this;}
|
||||||
|
|
||||||
PIMap<Key, T> & removeOne(const Key & key) {bool f(false); ssize_t i = _find(key, f); if (f) _remove(i); return *this;}
|
PIMap<Key, T> & removeOne(const Key & key) {bool f(false); ssize_t i = _find(key, f); if (f) _remove(i); return *this;}
|
||||||
PIMap<Key, T> & remove(const Key & key) {return removeOne(key);}
|
PIMap<Key, T> & remove(const Key & key) {return removeOne(key);}
|
||||||
PIMap<Key, T> & erase(const Key & key) {return removeOne(key);}
|
PIMap<Key, T> & erase(const Key & key) {return removeOne(key);}
|
||||||
PIMap<Key, T> & clear() {pim_content.clear(); pim_index.clear(); return *this;}
|
PIMap<Key, T> & clear() {pim_content.clear(); return *this;}
|
||||||
|
|
||||||
void swap(PIMap<Key, T> & other) {
|
void swap(PIMap<Key, T> & other) {
|
||||||
pim_content.swap(other.pim_content);
|
pim_content.swap(other.pim_content);
|
||||||
pim_index.swap(other.pim_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PIMap<Key, T> & insert(const Key & key, const T & value) {
|
PIMap<Key, T> & insert(const Key & key, const T & value) {
|
||||||
@@ -243,10 +213,9 @@ public:
|
|||||||
ssize_t i = _find(key, f);
|
ssize_t i = _find(key, f);
|
||||||
//piCout << "insert key=" << key << "found=" << f << "index=" << i << "value=" << value;
|
//piCout << "insert key=" << key << "found=" << f << "index=" << i << "value=" << value;
|
||||||
if (f) {
|
if (f) {
|
||||||
pim_content[pim_index[i].index] = value;
|
pim_content[i].second = value;
|
||||||
} else {
|
} else {
|
||||||
pim_content.push_back(value);
|
pim_content.insert(i, PIPair<Key, T>(key, value));
|
||||||
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -255,20 +224,34 @@ public:
|
|||||||
ssize_t i = _find(key, f);
|
ssize_t i = _find(key, f);
|
||||||
//piCout << "insert key=" << key << "found=" << f << "index=" << i << "value=" << value;
|
//piCout << "insert key=" << key << "found=" << f << "index=" << i << "value=" << value;
|
||||||
if (f) {
|
if (f) {
|
||||||
pim_content[pim_index[i].index] = std::move(value);
|
pim_content[i].second = std::move(value);
|
||||||
} else {
|
} else {
|
||||||
pim_content.push_back(std::move(value));
|
// pim_content.push_back(std::move(value));
|
||||||
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
// pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
||||||
|
pim_content.insert(i, PIPair<Key, T>(key, std::move(value)));
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
const T value(const Key & key, const T & default_ = T()) const {bool f(false); ssize_t i = _find(key, f); if (!f) return default_; return pim_content[pim_index[i].index];}
|
const T value(const Key & key, const T & default_ = T()) const {
|
||||||
PIVector<T> values() const {return pim_content;}
|
bool f(false);
|
||||||
Key key(const T & value_, const Key & default_ = Key()) const {for (int i = 0; i < pim_index.size_s(); ++i) if (pim_content[pim_index[i].index] == value_) return pim_index[i].key; return default_;}
|
ssize_t i = _find(key, f);
|
||||||
|
if (!f) return default_;
|
||||||
|
return pim_content[i].second;
|
||||||
|
}
|
||||||
|
PIVector<T> values() const {
|
||||||
|
PIVector<T> ret;
|
||||||
|
for (size_t i = 0; i < pim_content.size(); ++i) ret << pim_content[i].second;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Key key(const T & value_, const Key & default_ = Key()) const {
|
||||||
|
for (int i = 0; i < pim_content.size_s(); ++i)
|
||||||
|
if (pim_content[i].second == value_)
|
||||||
|
return pim_content[i].first;
|
||||||
|
return default_;
|
||||||
|
}
|
||||||
PIVector<Key> keys() const {
|
PIVector<Key> keys() const {
|
||||||
PIVector<Key> ret;
|
PIVector<Key> ret;
|
||||||
for (int i = 0; i < pim_index.size_s(); ++i)
|
for (size_t i = 0; i < pim_content.size(); ++i) ret << pim_content[i].first;
|
||||||
ret << pim_index[i].key;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,66 +259,53 @@ public:
|
|||||||
piCout << "PIMap" << size() << "entries" << PICoutManipulators::NewLine << "content:";
|
piCout << "PIMap" << size() << "entries" << PICoutManipulators::NewLine << "content:";
|
||||||
for (size_t i = 0; i < pim_content.size(); ++i)
|
for (size_t i = 0; i < pim_content.size(); ++i)
|
||||||
piCout << PICoutManipulators::Tab << i << ":" << pim_content[i];
|
piCout << PICoutManipulators::Tab << i << ":" << pim_content[i];
|
||||||
piCout << "index:";
|
// piCout << "index:";
|
||||||
for (size_t i = 0; i < pim_index.size(); ++i)
|
// for (size_t i = 0; i < pim_index.size(); ++i)
|
||||||
piCout << PICoutManipulators::Tab << i << ":" << pim_index[i].key << "->" << pim_index[i].index;
|
// piCout << PICoutManipulators::Tab << i << ":" << pim_index[i].key << "->" << pim_index[i].index;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct MapIndex {
|
// struct MapIndex {
|
||||||
MapIndex(Key k = Key(), size_t i = 0): key(k), index(i) {;}
|
// MapIndex(Key k = Key(), size_t i = 0): key(k), index(i) {;}
|
||||||
Key key;
|
// Key key;
|
||||||
size_t index;
|
// size_t index;
|
||||||
bool operator ==(const MapIndex & s) const {return key == s.key;}
|
// bool operator ==(const MapIndex & s) const {return key == s.key;}
|
||||||
bool operator !=(const MapIndex & s) const {return key != s.key;}
|
// bool operator !=(const MapIndex & s) const {return key != s.key;}
|
||||||
bool operator <(const MapIndex & s) const {return key < s.key;}
|
// bool operator <(const MapIndex & s) const {return key < s.key;}
|
||||||
bool operator >(const MapIndex & s) const {return key > s.key;}
|
// bool operator >(const MapIndex & s) const {return key > s.key;}
|
||||||
};
|
// };
|
||||||
template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
// template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
||||||
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
// template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
||||||
|
|
||||||
ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
|
ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
|
||||||
ssize_t mid;
|
ssize_t mid;
|
||||||
while (first <= last) {
|
while (first <= last) {
|
||||||
mid = (first + last) / 2;
|
mid = (first + last) / 2;
|
||||||
if (key > pim_index[mid].key) first = mid + 1;
|
if (key > pim_content[mid].first) first = mid + 1;
|
||||||
else if (key < pim_index[mid].key) last = mid - 1;
|
else if (key < pim_content[mid].first) last = mid - 1;
|
||||||
else {found = true; return mid;}
|
else {found = true; return mid;}
|
||||||
}
|
}
|
||||||
found = false;
|
found = false;
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
void _sort() {piQuickSort<MapIndex>(pim_index.data(), pim_index.size_s() - 1);}
|
|
||||||
ssize_t _find(const Key & k, bool & found) const {
|
ssize_t _find(const Key & k, bool & found) const {
|
||||||
if (pim_index.isEmpty()) {
|
if (pim_content.isEmpty()) {
|
||||||
found = false;
|
found = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return binarySearch(0, pim_index.size_s() - 1, k, found);
|
return binarySearch(0, pim_content.size_s() - 1, k, found);
|
||||||
}
|
}
|
||||||
void _remove(ssize_t index) {
|
void _remove(ssize_t index) {
|
||||||
//if (index >= pim_index.size()) return;
|
pim_content.remove(index);
|
||||||
size_t ci = pim_index[index].index, bi = pim_index.size() - 1;
|
|
||||||
pim_index.remove(index);
|
|
||||||
for (size_t i = 0; i < pim_index.size(); ++i)
|
|
||||||
if (pim_index[i].index == bi) {
|
|
||||||
pim_index[i].index = ci;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
piSwap<T>(pim_content[ci], pim_content.back());
|
|
||||||
pim_content.resize(pim_index.size());
|
|
||||||
}
|
}
|
||||||
const value_type _pair(ssize_t index) const {
|
const value_type _pair(ssize_t index) const {
|
||||||
if (index < 0 || index >= pim_index.size_s())
|
if (index < 0 || index >= pim_content.size_s()) return value_type();
|
||||||
return value_type();
|
return pim_content[index];
|
||||||
//piCout << "_pair" << index << pim_index[index].index;
|
|
||||||
return value_type(pim_index[index].key, pim_content[pim_index[index].index]);
|
|
||||||
}
|
}
|
||||||
Key & _key(ssize_t index) {return pim_index[index].key;}
|
Key & _key(ssize_t index) {return pim_content[index].first;}
|
||||||
T & _value(ssize_t index) {return pim_content[pim_index[index].index];}
|
T & _value(ssize_t index) {return pim_content[index].second;}
|
||||||
|
|
||||||
PIVector<T> pim_content;
|
PIDeque<PIPair<Key, T>> pim_content;
|
||||||
PIDeque<MapIndex> pim_index;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,13 @@ public:
|
|||||||
second = std::move(value1);
|
second = std::move(value1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type0 first /*! \~english First element \~russian Первый элемент */;
|
//! \~english First element.
|
||||||
Type1 second /*! \~english Second element \~russian Второй элемент */;
|
//! \~russian Первый элемент.
|
||||||
|
Type0 first;
|
||||||
|
|
||||||
|
//! \~english Second element.
|
||||||
|
//! \~russian Второй элемент.
|
||||||
|
Type1 second;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \~english Compare operator with PIPair.
|
//! \~english Compare operator with PIPair.
|
||||||
|
|||||||
@@ -90,7 +90,7 @@
|
|||||||
//! первый элемент массива имеет индекс, равный `0`,
|
//! первый элемент массива имеет индекс, равный `0`,
|
||||||
//! а индекс последнего элемента равен `size() - 1`.
|
//! а индекс последнего элемента равен `size() - 1`.
|
||||||
//! Также для массива доступен набор различных удобных функций,
|
//! Также для массива доступен набор различных удобных функций,
|
||||||
//! например: \a indexOf, \a contains(), \a entries(), \a isEmpty(), \a isNotEmpty(),
|
//! например: \a indexOf(), \a contains(), \a entries(), \a isEmpty(), \a isNotEmpty(),
|
||||||
//! \a every(), \a any(), \a forEach(), \a indexWhere(), \a getRange(), \a sort(),
|
//! \a every(), \a any(), \a forEach(), \a indexWhere(), \a getRange(), \a sort(),
|
||||||
//! \a map(), \a reduce(), \a filter(), \a flatten(), \a reshape() и другие.
|
//! \a map(), \a reduce(), \a filter(), \a flatten(), \a reshape() и другие.
|
||||||
//!
|
//!
|
||||||
@@ -2205,8 +2205,9 @@ private:
|
|||||||
if (piv_rsize + piv_rsize >= s && piv_rsize < s) {
|
if (piv_rsize + piv_rsize >= s && piv_rsize < s) {
|
||||||
return piv_rsize + piv_rsize;
|
return piv_rsize + piv_rsize;
|
||||||
}
|
}
|
||||||
ssize_t t = 0, s_ = s - 1;
|
ssize_t t = _PIContainerConstants<T>::minCountPoT(), s_ = s - 1;
|
||||||
while (s_ >> t) ++t;
|
while (s_ >> t)
|
||||||
|
++t;
|
||||||
return (1 << t);
|
return (1 << t);
|
||||||
}
|
}
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
|
|||||||
@@ -246,6 +246,10 @@
|
|||||||
extern char ** environ;
|
extern char ** environ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_UNUSED
|
||||||
|
# define NO_UNUSED(x) (void)x
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef assert
|
#ifndef assert
|
||||||
# define assert(x)
|
# define assert(x)
|
||||||
# define assertm(exp, msg)
|
# define assertm(exp, msg)
|
||||||
@@ -387,12 +391,12 @@
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Macro used for infinite wait
|
//! \~english Macro used for infinite wait
|
||||||
//! \~russian Макрос для бесконечного ожидания
|
//! \~russian Макрос для бесконечного ожидания
|
||||||
#define FOREVER_WAIT FOREVER piMinSleep;
|
#define FOREVER_WAIT FOREVER piMinSleep();
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Macro used for infinite wait
|
//! \~english Macro used for infinite wait
|
||||||
//! \~russian Макрос для бесконечного ожидания
|
//! \~russian Макрос для бесконечного ожидания
|
||||||
#define WAIT_FOREVER FOREVER piMinSleep;
|
#define WAIT_FOREVER FOREVER piMinSleep();
|
||||||
|
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
|
|||||||
@@ -21,14 +21,7 @@
|
|||||||
#include "pistringlist.h"
|
#include "pistringlist.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PIByteArray pibytearray.h
|
//! \class PIByteArray pibytearray.h
|
||||||
//!
|
|
||||||
//! \~\brief
|
|
||||||
//! \~english The %PIByteArray class provides an array of bytes
|
|
||||||
//! \~russian Класс %PIByteArray представляет собой массив байтов
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! %PIByteArray used to store raw bytes.
|
//! %PIByteArray used to store raw bytes.
|
||||||
@@ -98,7 +91,6 @@
|
|||||||
//! метов \a append().
|
//! метов \a append().
|
||||||
//! \~\snippet pibytearray.cpp 3
|
//! \~\snippet pibytearray.cpp 3
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
static const uchar base64Table[64] = {
|
static const uchar base64Table[64] = {
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ class PIString;
|
|||||||
class PIByteArray;
|
class PIByteArray;
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english The %PIByteArray class provides an array of bytes.
|
||||||
|
//! \~russian Класс %PIByteArray представляет собой массив байтов.
|
||||||
class PIP_EXPORT PIByteArray: public PIDeque<uchar>
|
class PIP_EXPORT PIByteArray: public PIDeque<uchar>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -268,8 +272,8 @@ inline PIByteArray::StreamRef operator <<(PIByteArray & s, const T & v) {
|
|||||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v);
|
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v);
|
||||||
|
|
||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Store operator, see \ref PIByteArray_sec1 for details
|
//! \~english Store operator
|
||||||
//! \~russian Оператор сохранения, подробнее в \ref PIByteArray_sec1
|
//! \~russian Оператор сохранения
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {
|
||||||
int os = s.size_s();
|
int os = s.size_s();
|
||||||
if (v.s > 0) {
|
if (v.s > 0) {
|
||||||
@@ -402,8 +406,8 @@ inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) {
|
|||||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
|
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
|
||||||
|
|
||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Restore operator, see \ref PIByteArray_sec1 for details
|
//! \~english Restore operator
|
||||||
//! \~russian Оператор извлечения, подробнее в \ref PIByteArray_sec1
|
//! \~russian Оператор извлечения
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {
|
||||||
if (s.size_s() < v.s) {
|
if (s.size_s() < v.s) {
|
||||||
printf("error with RawData %d < %d\n", (int)s.size_s(), v.s);
|
printf("error with RawData %d < %d\n", (int)s.size_s(), v.s);
|
||||||
@@ -626,9 +630,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
|||||||
//! \~russian Оператор сохранения
|
//! \~russian Оператор сохранения
|
||||||
template <typename Key, typename T>
|
template <typename Key, typename T>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
|
||||||
s << int(v.pim_index.size_s());
|
// s << int(v.pim_index.size_s());
|
||||||
for (uint i = 0; i < v.size(); ++i)
|
// for (uint i = 0; i < v.size(); ++i)
|
||||||
s << int(v.pim_index[i].index) << v.pim_index[i].key;
|
// s << int(v.pim_index[i].index) << v.pim_index[i].key;
|
||||||
s << v.pim_content;
|
s << v.pim_content;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -643,17 +647,17 @@ inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v) {
|
|||||||
printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||||
assert(s.size_s() >= 4);
|
assert(s.size_s() >= 4);
|
||||||
}
|
}
|
||||||
int sz; s >> sz; v.pim_index.resize(sz);
|
// int sz; s >> sz; v.pim_index.resize(sz);
|
||||||
int ind = 0;
|
// int ind = 0;
|
||||||
for (int i = 0; i < sz; ++i) {
|
// for (int i = 0; i < sz; ++i) {
|
||||||
s >> ind >> v.pim_index[i].key;
|
// s >> ind >> v.pim_index[i].key;
|
||||||
v.pim_index[i].index = ind;
|
// v.pim_index[i].index = ind;
|
||||||
}
|
// }
|
||||||
s >> v.pim_content;
|
s >> v.pim_content;
|
||||||
if (v.pim_content.size_s() != v.pim_index.size_s()) {
|
// if (v.pim_content.size_s() != v.pim_index.size_s()) {
|
||||||
piCout << "Warning: loaded invalid PIMap, clear";
|
// piCout << "Warning: loaded invalid PIMap, clear";
|
||||||
v.clear();
|
// v.clear();
|
||||||
}
|
// }
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
#include "pibytearray.h"
|
#include "pistring.h"
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
# define U_NOEXCEPT
|
# define U_NOEXCEPT
|
||||||
# include "unicode/ucnv.h"
|
# include "unicode/ucnv.h"
|
||||||
@@ -35,21 +35,8 @@ char * __utf8name__ = 0;
|
|||||||
# include <ctype.h>
|
# include <ctype.h>
|
||||||
#endif
|
#endif
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#ifdef ANDROID
|
|
||||||
# if __ANDROID_API__ < 21
|
|
||||||
# define wctomb(s, wc) wcrtomb(s, wc, NULL)
|
|
||||||
# define mbtowc(pwc, s, n) mbrtowc(pwc, s, n, NULL)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PIChar pichar.h
|
//! \class PIChar pichar.h
|
||||||
//!
|
|
||||||
//! \~\brief
|
|
||||||
//! \~english %PIChar represents a single character
|
|
||||||
//! \~russian %PIChar представляет собой один символ строки
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This class is wrapper around UTF16.
|
//! This class is wrapper around UTF16.
|
||||||
@@ -59,7 +46,6 @@ char * __utf8name__ = 0;
|
|||||||
//! %PIChar хранит один сивол в UTF16. Имеет много контрукторов, геттеров в различные
|
//! %PIChar хранит один сивол в UTF16. Имеет много контрукторов, геттеров в различные
|
||||||
//! кодировки (системную, консольную, UTF8) и информационных функций.
|
//! кодировки (системную, консольную, UTF8) и информационных функций.
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
ushort charFromCodepage(const char * c, int size, const char * codepage, int * taken = 0) {
|
ushort charFromCodepage(const char * c, int size, const char * codepage, int * taken = 0) {
|
||||||
@@ -86,10 +72,12 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
|
|||||||
if (taken) *taken = ret;
|
if (taken) *taken = ret;
|
||||||
return buffer;
|
return buffer;
|
||||||
# else
|
# else
|
||||||
wchar_t wc(0);
|
mbstate_t state;
|
||||||
mbtowc(0, 0, 0); // reset mbtowc
|
memset(&state, 0, sizeof(state));
|
||||||
ret = mbtowc(&wc, c, size);
|
wchar_t wc;
|
||||||
|
ret = mbrtowc(&wc, c, size, &state);
|
||||||
//printf("mbtowc = %d\n", ret);
|
//printf("mbtowc = %d\n", ret);
|
||||||
|
//piCout << errorString();
|
||||||
if (ret < 1) return 0;
|
if (ret < 1) return 0;
|
||||||
return ushort(wc);
|
return ushort(wc);
|
||||||
# endif
|
# endif
|
||||||
@@ -389,13 +377,7 @@ PICout operator <<(PICout s, const PIChar & v) {
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
s << v.toSystem();
|
s << v.toSystem();
|
||||||
#else
|
#else
|
||||||
{
|
s << PIString(v);
|
||||||
char tc[8];
|
|
||||||
wctomb(0, 0);
|
|
||||||
int sz = wctomb(tc, v.ch);
|
|
||||||
for (int b = 0; b < sz; ++b)
|
|
||||||
s << tc[b];
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
s.restoreControl();
|
s.restoreControl();
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ extern PIP_EXPORT char * __syslocname__;
|
|||||||
extern PIP_EXPORT char * __sysoemname__;
|
extern PIP_EXPORT char * __sysoemname__;
|
||||||
extern PIP_EXPORT char * __utf8name__;
|
extern PIP_EXPORT char * __utf8name__;
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english %PIChar represents a single character.
|
||||||
|
//! \~russian %PIChar представляет собой один символ строки.
|
||||||
class PIP_EXPORT PIChar
|
class PIP_EXPORT PIChar
|
||||||
{
|
{
|
||||||
friend class PIString;
|
friend class PIString;
|
||||||
@@ -61,6 +65,10 @@ public:
|
|||||||
//! \~russian Оператор присваивания
|
//! \~russian Оператор присваивания
|
||||||
PIChar & operator =(const char v) {ch = v; return *this;}
|
PIChar & operator =(const char v) {ch = v; return *this;}
|
||||||
|
|
||||||
|
//! \~english Copy operator
|
||||||
|
//! \~russian Оператор присваивания
|
||||||
|
PIChar & operator =(const wchar_t v) {ch = v; return *this;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator ==(const PIChar & o) const;
|
bool operator ==(const PIChar & o) const;
|
||||||
|
|||||||
@@ -19,13 +19,8 @@
|
|||||||
|
|
||||||
#include "pichunkstream.h"
|
#include "pichunkstream.h"
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PIChunkStream pichunkstream.h
|
//! \class PIChunkStream pichunkstream.h
|
||||||
//! \brief
|
//! \details
|
||||||
//! \~english Class for binary de/serialization
|
|
||||||
//! \~russian Класс для бинарной де/сериализации
|
|
||||||
//!
|
|
||||||
//! \~english \section PIChunkStream_sec0 Synopsis
|
//! \~english \section PIChunkStream_sec0 Synopsis
|
||||||
//! \~russian \section PIChunkStream_sec0 Краткий обзор
|
//! \~russian \section PIChunkStream_sec0 Краткий обзор
|
||||||
//! \~english
|
//! \~english
|
||||||
@@ -89,7 +84,6 @@
|
|||||||
//! \~russian ... и десериализовать:
|
//! \~russian ... и десериализовать:
|
||||||
//! \~\snippet pichunkstream.cpp read_new
|
//! \~\snippet pichunkstream.cpp read_new
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
void PIChunkStream::setSource(const PIByteArray & data) {
|
void PIChunkStream::setSource(const PIByteArray & data) {
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
#include "pibytearray.h"
|
#include "pibytearray.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Class for binary de/serialization.
|
||||||
|
//! \~russian Класс для бинарной де/сериализации.
|
||||||
class PIP_EXPORT PIChunkStream
|
class PIP_EXPORT PIChunkStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -21,13 +21,8 @@
|
|||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PICLI picli.h
|
//! \class PICLI picli.h
|
||||||
//! \~\brief
|
//! \details
|
||||||
//! \~english Command-Line parser
|
|
||||||
//! \~russian Парсер командной строки
|
|
||||||
//!
|
|
||||||
//! \~english \section PICLI_sec0 Synopsis
|
//! \~english \section PICLI_sec0 Synopsis
|
||||||
//! \~russian \section PICLI_sec0 Краткий обзор
|
//! \~russian \section PICLI_sec0 Краткий обзор
|
||||||
//! \~english
|
//! \~english
|
||||||
@@ -43,7 +38,7 @@
|
|||||||
//! а также получить их значения при помощи \a argumentValue().
|
//! а также получить их значения при помощи \a argumentValue().
|
||||||
//!
|
//!
|
||||||
//! \~english \section PICLI_sec1 Example
|
//! \~english \section PICLI_sec1 Example
|
||||||
//! \~russian \section PICLI_sec0 Пример
|
//! \~russian \section PICLI_sec1 Пример
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! int main(int argc, char ** argv) {
|
//! int main(int argc, char ** argv) {
|
||||||
//! PICLI cli(argc, argv);
|
//! PICLI cli(argc, argv);
|
||||||
@@ -66,12 +61,10 @@
|
|||||||
//! a.out --debug -c --value 10
|
//! a.out --debug -c --value 10
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PICLI::PICLI(int argc, char * argv[]) {
|
PICLI::PICLI(int argc, char * argv[]) {
|
||||||
setName("CLI");
|
needParse = debug_ = true;
|
||||||
needParse = true;
|
|
||||||
_prefix_short = "-";
|
_prefix_short = "-";
|
||||||
_prefix_full = "--";
|
_prefix_full = "--";
|
||||||
_count_opt = 0;
|
_count_opt = 0;
|
||||||
|
|||||||
@@ -26,11 +26,15 @@
|
|||||||
#ifndef PICLI_H
|
#ifndef PICLI_H
|
||||||
#define PICLI_H
|
#define PICLI_H
|
||||||
|
|
||||||
#include "piobject.h"
|
#include "pistringlist.h"
|
||||||
|
#include "piset.h"
|
||||||
|
|
||||||
class PIP_EXPORT PICLI: public PIObject
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Command-Line parser.
|
||||||
|
//! \~russian Парсер командной строки.
|
||||||
|
class PIP_EXPORT PICLI
|
||||||
{
|
{
|
||||||
PIOBJECT_SUBCLASS(PICLI, PIObject)
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! \~english Constructor
|
//! \~english Constructor
|
||||||
@@ -94,6 +98,11 @@ public:
|
|||||||
void setMandatoryArgumentsCount(const int count) {_count_mand = count; needParse = true;}
|
void setMandatoryArgumentsCount(const int count) {_count_mand = count; needParse = true;}
|
||||||
void setOptionalArgumentsCount(const int count) {_count_opt = count; needParse = true;}
|
void setOptionalArgumentsCount(const int count) {_count_opt = count; needParse = true;}
|
||||||
|
|
||||||
|
bool debug() const {return debug_;}
|
||||||
|
void setDebug(bool debug) {debug_ = debug;}
|
||||||
|
PIConstChars className() const {return "PICLI";}
|
||||||
|
PIString name() const {return PIStringAscii("CLI");}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Argument {
|
struct Argument {
|
||||||
Argument() {has_value = found = false;}
|
Argument() {has_value = found = false;}
|
||||||
@@ -112,7 +121,7 @@ private:
|
|||||||
PISet<PIString> keys_full, keys_short;
|
PISet<PIString> keys_full, keys_short;
|
||||||
PIVector<Argument> _args;
|
PIVector<Argument> _args;
|
||||||
int _count_mand, _count_opt;
|
int _count_mand, _count_opt;
|
||||||
bool needParse;
|
bool needParse, debug_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,7 @@
|
|||||||
#include "picollection.h"
|
#include "picollection.h"
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PICollection picollection.h
|
//! \~\class PICollection picollection.h
|
||||||
//! \~\brief
|
|
||||||
//! \~english Helper to collect and retrieve classes to groups
|
|
||||||
//! \~russian Помощник для создания и получения классов в группы
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PICollection_sec0 Synopsis
|
//! \~english \section PICollection_sec0 Synopsis
|
||||||
//! \~russian \section PICollection_sec0 Краткий обзор
|
//! \~russian \section PICollection_sec0 Краткий обзор
|
||||||
@@ -41,7 +35,6 @@
|
|||||||
//! объектов в глобальные группы. Затем можно получить их список в любом месте программы.
|
//! объектов в глобальные группы. Затем можно получить их список в любом месте программы.
|
||||||
//! \~\snippet picollection.cpp main
|
//! \~\snippet picollection.cpp main
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PIStringList PICollection::groups() {
|
PIStringList PICollection::groups() {
|
||||||
|
|||||||
@@ -100,6 +100,10 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Helper to collect and retrieve classes to groups.
|
||||||
|
//! \~russian Помощник для создания и получения классов в группы.
|
||||||
class PIP_EXPORT PICollection
|
class PIP_EXPORT PICollection
|
||||||
{
|
{
|
||||||
friend class __PICollectionInitializer;
|
friend class __PICollectionInitializer;
|
||||||
|
|||||||
164
libs/main/core/piconstchars.cpp
Normal file
164
libs/main/core/piconstchars.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
C-String class
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "piconstchars.h"
|
||||||
|
#include "pistring.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\class PIConstChars piconstchars.h
|
||||||
|
//! \~\details
|
||||||
|
//! \~english \section PIConstChars_sec0 Synopsis
|
||||||
|
//! \~russian \section PIConstChars_sec0 Краткий обзор
|
||||||
|
//! \~english
|
||||||
|
//! This is wrapper around \c const char * string. %PIConstChars doesn`t
|
||||||
|
//! copy string, just save pointer and size.
|
||||||
|
//!
|
||||||
|
//! Provides API similar to string, with information and compare methods.
|
||||||
|
//!
|
||||||
|
//! Used to more handly works with ordinary C-strings.
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Это обертка вокруг \c const char * строки. %PIConstChars не скопирует
|
||||||
|
//! строку, а хранит только указатель и размер.
|
||||||
|
//!
|
||||||
|
//! Предоставляет API схожий с обычной строкой, с методами сравнения и информационными.
|
||||||
|
//!
|
||||||
|
//! Используется для более удобной работы с обычными C-строками.
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
|
bool PIConstChars::startsWith(const PIConstChars & str) const {
|
||||||
|
if (size() < str.size()) return false;
|
||||||
|
return str == left(str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIConstChars::startsWith(const char c) const {
|
||||||
|
if (size() < 1) return false;
|
||||||
|
return str[0] == c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIConstChars::endsWith(const PIConstChars & str) const {
|
||||||
|
if (size() < str.size()) return false;
|
||||||
|
return str == right(str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIConstChars::endsWith(const char c) const {
|
||||||
|
if (size() < 1) return false;
|
||||||
|
return str[len - 1] == c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars PIConstChars::mid(const int start, const int len) const {
|
||||||
|
int s = start, l = len;
|
||||||
|
if (l == 0 || s >= (int)size() || isEmpty()) return PIConstChars("");
|
||||||
|
if (s < 0) {
|
||||||
|
l += s;
|
||||||
|
s = 0;
|
||||||
|
}
|
||||||
|
if (l < 0) {
|
||||||
|
return PIConstChars(str + s, (int)size() - s);
|
||||||
|
} else {
|
||||||
|
if (l > (int)size() - s)
|
||||||
|
l = (int)size() - s;
|
||||||
|
return PIConstChars(str + s, l);
|
||||||
|
}
|
||||||
|
return PIConstChars("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars PIConstChars::left(const int l) const {
|
||||||
|
if (l <= 0) return PIConstChars("");
|
||||||
|
return mid(0, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars PIConstChars::right(const int l) const {
|
||||||
|
if (l <= 0) return PIConstChars("");
|
||||||
|
return mid((int)size() - l, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars & PIConstChars::cutLeft(const int l) {
|
||||||
|
if (l <= 0) return *this;
|
||||||
|
if (l >= (int)size())
|
||||||
|
*this = PIConstChars("");
|
||||||
|
else {
|
||||||
|
str += l;
|
||||||
|
len -= l;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars & PIConstChars::cutRight(const int l) {
|
||||||
|
if (l <= 0) return *this;
|
||||||
|
if (l >= (int)size())
|
||||||
|
*this = PIConstChars("");
|
||||||
|
else {
|
||||||
|
len -= l;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars PIConstChars::takeLeft(const int len) {
|
||||||
|
PIConstChars ret(left(len));
|
||||||
|
cutLeft(len);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars PIConstChars::takeRight(const int len) {
|
||||||
|
PIConstChars ret(right(len));
|
||||||
|
cutRight(len);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIConstChars & PIConstChars::trim() {
|
||||||
|
if (isEmpty()) return *this;
|
||||||
|
int st = -1, fn = 0;
|
||||||
|
for (int i = 0; i < (int)len; ++i) {
|
||||||
|
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
||||||
|
st = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (st < 0) {
|
||||||
|
*this = PIConstChars("");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
for (int i = (int)len - 1; i >= 0; --i) {
|
||||||
|
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
||||||
|
fn = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fn < (int)len - 1) cutRight((int)len - fn - 1);
|
||||||
|
if (st > 0) cutLeft(st);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIConstChars::toString() const {
|
||||||
|
if (isEmpty()) return PIString();
|
||||||
|
return PIString::fromAscii(str, len);
|
||||||
|
}
|
||||||
262
libs/main/core/piconstchars.h
Normal file
262
libs/main/core/piconstchars.h
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
/*! \file piconstchars.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \brief
|
||||||
|
* \~english C-String class
|
||||||
|
* \~russian Класс C-строки
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
C-String class
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PICONSTCHARS_H
|
||||||
|
#define PICONSTCHARS_H
|
||||||
|
|
||||||
|
#include "picout.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english C-String class.
|
||||||
|
//! \~russian Класс C-строки.
|
||||||
|
class PIP_EXPORT PIConstChars {
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! \~english Contructs an null string.
|
||||||
|
//! \~russian Создает нулевую строку.
|
||||||
|
PIConstChars() {}
|
||||||
|
|
||||||
|
//! \~english Contructs string from C-string "string".
|
||||||
|
//! \~russian Создает строку из C-строки "string".
|
||||||
|
PIConstChars(const char * string) {
|
||||||
|
str = string;
|
||||||
|
len = strlen(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Contructs string from "size" characters of buffer "data".
|
||||||
|
//! \~russian Создает строку из "size" символов массива "data".
|
||||||
|
PIConstChars(const char * data, size_t size) {
|
||||||
|
str = data;
|
||||||
|
len = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Contructs a copy of string.
|
||||||
|
//! \~russian Создает копию строки.
|
||||||
|
PIConstChars(const PIConstChars & o) {
|
||||||
|
str = o.str;
|
||||||
|
len = o.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Read-only access to character by `index`.
|
||||||
|
//! \~russian Доступ на чтение к символу по индексу `index`.
|
||||||
|
inline char operator [](size_t index) const {return str[index];}
|
||||||
|
|
||||||
|
//! \~english Read-only access to character by `index`.
|
||||||
|
//! \~russian Доступ на чтение к символу по индексу `index`.
|
||||||
|
inline char at(size_t index) const {return str[index];}
|
||||||
|
|
||||||
|
//! \~english Returns \c char * string pointer.
|
||||||
|
//! \~russian Возвращает \c char * указатель строки.
|
||||||
|
inline const char * data() const {return str;}
|
||||||
|
|
||||||
|
//! \~english Returns \c true if string doesn`t have any data.
|
||||||
|
//! \~russian Возвращает \c true если строка не имеет данных.
|
||||||
|
inline bool isNull() const {return !str;}
|
||||||
|
|
||||||
|
//! \~english Returns \c true if string is empty, i.e. length = 0, or null.
|
||||||
|
//! \~russian Возвращает \c true если строка пустая, т.е. длина = 0, или нулевая.
|
||||||
|
inline bool isEmpty() const {return len == 0;}
|
||||||
|
|
||||||
|
//! \~english Returns \c true if string is not empty, i.e. length > 0.
|
||||||
|
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0.
|
||||||
|
inline bool isNotEmpty() const {return len > 0;}
|
||||||
|
|
||||||
|
//! \~english Returns characters length of string.
|
||||||
|
//! \~russian Возвращает длину строки в символах.
|
||||||
|
inline size_t length() const {return len;}
|
||||||
|
|
||||||
|
//! \~english Returns characters length of string.
|
||||||
|
//! \~russian Возвращает длину строки в символах.
|
||||||
|
inline size_t size() const {return len;}
|
||||||
|
|
||||||
|
//! \~english Returns characters length of string.
|
||||||
|
//! \~russian Возвращает длину строки в символах.
|
||||||
|
inline ssize_t size_s() const {return len;}
|
||||||
|
|
||||||
|
//! \~english Returns if string starts with "str".
|
||||||
|
//! \~russian Возвращает начинается ли строка со "str".
|
||||||
|
bool startsWith(const PIConstChars & str) const;
|
||||||
|
|
||||||
|
//! \~english Returns if string starts with "c".
|
||||||
|
//! \~russian Возвращает начинается ли строка с "c".
|
||||||
|
bool startsWith(const char c) const;
|
||||||
|
|
||||||
|
//! \~english Returns if string ends with "str".
|
||||||
|
//! \~russian Возвращает оканчивается ли строка на "str".
|
||||||
|
bool endsWith(const PIConstChars & str) const;
|
||||||
|
|
||||||
|
//! \~english Returns if string ends with "c".
|
||||||
|
//! \~russian Возвращает оканчивается ли строка "c".
|
||||||
|
bool endsWith(const char c) const;
|
||||||
|
|
||||||
|
//! \~english Returns part of string from character at index "start" and maximum length "len".
|
||||||
|
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len".
|
||||||
|
//! \~\sa \a left(), \a right()
|
||||||
|
PIConstChars mid(const int start, const int len = -1) const;
|
||||||
|
|
||||||
|
//! \~english Returns part of string from start and maximum length "len".
|
||||||
|
//! \~russian Возвращает подстроку от начала и максимальной длиной "len".
|
||||||
|
//! \~\sa \a mid(), \a right()
|
||||||
|
PIConstChars left(const int len) const;
|
||||||
|
|
||||||
|
//! \~english Returns part of string at end and maximum length "len".
|
||||||
|
//! \~russian Возвращает подстроку максимальной длиной "len" и до конца.
|
||||||
|
//! \~\sa \a mid(), \a left()
|
||||||
|
PIConstChars right(const int len) const;
|
||||||
|
|
||||||
|
//! \~english Remove part of string from start and maximum length "len" and return this string.
|
||||||
|
//! \~russian Удаляет часть строки от начала и максимальной длины "len", возвращает эту строку.
|
||||||
|
//! \~\sa \a cutRight()
|
||||||
|
PIConstChars & cutLeft(const int len);
|
||||||
|
|
||||||
|
//! \~english Remove part of string at end and maximum length "len" and return this string.
|
||||||
|
//! \~russian Удаляет часть строки максимальной длины "len" от конца, возвращает эту строку.
|
||||||
|
//! \~\sa \a cutLeft()
|
||||||
|
PIConstChars & cutRight(const int len);
|
||||||
|
|
||||||
|
//! \~english Take a part from the begin of string with maximum length "len" and return it.
|
||||||
|
//! \~russian Извлекает часть строки от начала максимальной длины "len" и возвращает её.
|
||||||
|
//! \~\sa \a takeRight()
|
||||||
|
PIConstChars takeLeft(const int len);
|
||||||
|
|
||||||
|
//! \~english Take a part from the end of string with maximum length "len" and return it.
|
||||||
|
//! \~russian Извлекает часть строки с конца максимальной длины "len" и возвращает её.
|
||||||
|
//! \~\sa \a takeLeft()
|
||||||
|
PIConstChars takeRight(const int len);
|
||||||
|
|
||||||
|
//! \~english Remove spaces at the start and at the end of string and return this string.
|
||||||
|
//! \~russian Удаляет пробельные символы с начала и конца строки и возвращает эту строку.
|
||||||
|
//! \~\sa \a trimmed()
|
||||||
|
PIConstChars & trim();
|
||||||
|
|
||||||
|
//! \~english Returns copy of this string without spaces at the start and at the end.
|
||||||
|
//! \~russian Возвращает копию этой строки без пробельных символов с начала и конца.
|
||||||
|
//! \~\sa \a trim()
|
||||||
|
PIConstChars trimmed() const {return PIConstChars(*this).trim();}
|
||||||
|
|
||||||
|
//! \~english Returns as PIString.
|
||||||
|
//! \~russian Возвращает как PIString.
|
||||||
|
PIString toString() const;
|
||||||
|
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
inline PIConstChars & operator =(const PIConstChars & s) {
|
||||||
|
if (this == &s) return *this;
|
||||||
|
len = s.len;
|
||||||
|
str = s.str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Assign move operator.
|
||||||
|
//! \~russian Оператор перемещающего присваивания.
|
||||||
|
inline PIConstChars & operator =(PIConstChars && s) {
|
||||||
|
swap(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
inline PIConstChars & operator =(const char * s) {
|
||||||
|
str = s;
|
||||||
|
len = strlen(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Compare operator.
|
||||||
|
//! \~russian Оператор сравнения.
|
||||||
|
inline bool operator ==(const PIConstChars & s) const {
|
||||||
|
if (isNull() && s.isNull()) return true;
|
||||||
|
if (isNull() xor s.isNull()) return false;
|
||||||
|
if (size() != s.size()) return false;
|
||||||
|
return strcmp(str, s.str) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Compare operator.
|
||||||
|
//! \~russian Оператор сравнения.
|
||||||
|
inline bool operator !=(const PIConstChars & s) const {return !(*this == s);}
|
||||||
|
|
||||||
|
//! \~english Compare operator.
|
||||||
|
//! \~russian Оператор сравнения.
|
||||||
|
inline bool operator <(const PIConstChars & s) const {
|
||||||
|
if ( isNull() && s.isNull()) return false;
|
||||||
|
if ( isNull() && !s.isNull()) return true ;
|
||||||
|
if (!isNull() && s.isNull()) return false;
|
||||||
|
if (size() == s.size())
|
||||||
|
return strcmp(str, s.str) < 0;
|
||||||
|
return size() < s.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Compare operator.
|
||||||
|
//! \~russian Оператор сравнения.
|
||||||
|
inline bool operator >(const PIConstChars & s) const {
|
||||||
|
if ( isNull() && s.isNull()) return false;
|
||||||
|
if ( isNull() && !s.isNull()) return false;
|
||||||
|
if (!isNull() && s.isNull()) return true ;
|
||||||
|
if (size() == s.size())
|
||||||
|
return strcmp(str, s.str) > 0;
|
||||||
|
return size() > s.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~english Returns hash of string content.
|
||||||
|
//! \~russian Возвращает хэш содержимого строки.
|
||||||
|
inline uint hash() const {
|
||||||
|
if (isEmpty()) return 0;
|
||||||
|
return piHashData((const uchar *)str, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void swap(PIConstChars& v) {
|
||||||
|
piSwap<const char *>(str, v.str);
|
||||||
|
piSwap<size_t>(len, v.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char * str = nullptr;
|
||||||
|
size_t len = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout.
|
||||||
|
//! \~russian Оператор вывода в \a PICout.
|
||||||
|
inline PICout operator <<(PICout s, const PIConstChars & v) {
|
||||||
|
s.space();
|
||||||
|
if (v.isNull())
|
||||||
|
s.write("(null)");
|
||||||
|
else {
|
||||||
|
s.quote();
|
||||||
|
s.write(v.data(), v.size());
|
||||||
|
s.quote();
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<> inline uint piHash(const PIConstChars & s) {return s.hash();}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PICONSTCHARS_H
|
||||||
@@ -22,6 +22,10 @@
|
|||||||
#include "pistack.h"
|
#include "pistack.h"
|
||||||
#include "piobject.h"
|
#include "piobject.h"
|
||||||
#include "pistring_std.h"
|
#include "pistring_std.h"
|
||||||
|
#ifdef HAS_LOCALE
|
||||||
|
# include <locale>
|
||||||
|
# include <codecvt>
|
||||||
|
#endif
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <wingdi.h>
|
# include <wingdi.h>
|
||||||
@@ -30,13 +34,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PICout picout.h
|
//! \~\class PICout picout.h
|
||||||
//! \~\brief
|
//! \~\details
|
||||||
//! \~english Universal output to console class
|
|
||||||
//! \~russian Универсальный вывод в консоль
|
|
||||||
//!
|
|
||||||
//! \~english \section PICout_sec0 Synopsis
|
//! \~english \section PICout_sec0 Synopsis
|
||||||
//! \~russian \section PICout_sec0 Краткий обзор
|
//! \~russian \section PICout_sec0 Краткий обзор
|
||||||
//! \~english
|
//! \~english
|
||||||
@@ -75,7 +74,6 @@
|
|||||||
//! \~russian \section PICout_ex1 Создание своего оператора вывода
|
//! \~russian \section PICout_ex1 Создание своего оператора вывода
|
||||||
//! \~\snippet picout.cpp own
|
//! \~\snippet picout.cpp own
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
//! \addtogroup Core
|
||||||
@@ -333,7 +331,7 @@ PICout PICout::operator <<(const PIFlags<PICoutManipulators::PICoutFormat> & v)
|
|||||||
if (!act_) return *this; \
|
if (!act_) return *this; \
|
||||||
space(); \
|
space(); \
|
||||||
if (cnb_ == 10) PICOUTTOTARGET(v) \
|
if (cnb_ == 10) PICOUTTOTARGET(v) \
|
||||||
else writePIString(PIString::fromNumber(v, cnb_)); \
|
else write(PIString::fromNumber(v, cnb_)); \
|
||||||
return *this; \
|
return *this; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +364,7 @@ PICout PICout::operator <<(const float v) {if (!act_) return *this; space(); PIC
|
|||||||
|
|
||||||
PICout PICout::operator <<(const double v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
PICout PICout::operator <<(const double v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const void * v) {if (!act_) return *this; space(); PICOUTTOTARGET("0x") writePIString(PIString::fromNumber(ullong(v), 16)); return *this;}
|
PICout PICout::operator <<(const void * v) {if (!act_) return *this; space(); PICOUTTOTARGET("0x") write(PIString::fromNumber(ullong(v), 16)); return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const PIObject * v) {
|
PICout PICout::operator <<(const PIObject * v) {
|
||||||
if (!act_) return *this;
|
if (!act_) return *this;
|
||||||
@@ -375,9 +373,9 @@ PICout PICout::operator <<(const PIObject * v) {
|
|||||||
else {
|
else {
|
||||||
PICOUTTOTARGET(v->className())
|
PICOUTTOTARGET(v->className())
|
||||||
PICOUTTOTARGET("*(0x")
|
PICOUTTOTARGET("*(0x")
|
||||||
writePIString(PIString::fromNumber(ullong(v), 16));
|
write(PIString::fromNumber(ullong(v), 16));
|
||||||
PICOUTTOTARGET(", \"")
|
PICOUTTOTARGET(", \"")
|
||||||
writePIString(v->name());
|
write(v->name());
|
||||||
PICOUTTOTARGET("\")")
|
PICOUTTOTARGET("\")")
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -522,8 +520,14 @@ PICout & PICout::newLine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PICout & PICout::write(const char * str) {
|
||||||
|
if (!act_ || !str) return *this;
|
||||||
|
return write(str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PICout & PICout::write(const char * str, int len) {
|
PICout & PICout::write(const char * str, int len) {
|
||||||
if (!act_) return *this;
|
if (!act_ || !str) return *this;
|
||||||
if (buffer_) {
|
if (buffer_) {
|
||||||
buffer_->append(PIString(str, len));
|
buffer_->append(PIString(str, len));
|
||||||
} else {
|
} else {
|
||||||
@@ -534,20 +538,29 @@ PICout & PICout::write(const char * str, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PICout & PICout::writePIString(const PIString & s) {
|
PICout & PICout::write(const PIString & s) {
|
||||||
if (!act_) return *this;
|
if (!act_) return *this;
|
||||||
if (buffer_) {
|
if (buffer_) {
|
||||||
buffer_->append(s);
|
buffer_->append(s);
|
||||||
} else {
|
} else {
|
||||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) {
|
if (PICout::isOutputDeviceActive(PICout::StdOut))
|
||||||
for (PIChar c: s) std::wcout.put(c.toWChar());
|
stdoutPIString(s);
|
||||||
}
|
|
||||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
|
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PICout::stdoutPIString(const PIString & s) {
|
||||||
|
#ifdef HAS_LOCALE
|
||||||
|
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
|
||||||
|
std::cout << utf8conv.to_bytes((char16_t*)&(const_cast<PIString&>(s).front()), (char16_t*)&(const_cast<PIString&>(s).front()) + s.size());
|
||||||
|
#else
|
||||||
|
for (PIChar c: s) std::wcout.put(c.toWChar());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PICout::init() {
|
void PICout::init() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (__Private__::hOut == 0) {
|
if (__Private__::hOut == 0) {
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ namespace PICoutManipulators {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Universal output to console class.
|
||||||
|
//! \~russian Универсальный вывод в консоль.
|
||||||
class PIP_EXPORT PICout {
|
class PIP_EXPORT PICout {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -283,13 +287,21 @@ public:
|
|||||||
//! \~russian Условно добавляет новую строку
|
//! \~russian Условно добавляет новую строку
|
||||||
PICout & newLine();
|
PICout & newLine();
|
||||||
|
|
||||||
|
//! \~english Write raw data
|
||||||
|
//! \~russian Пишет сырые символы
|
||||||
|
PICout & write(const char * str);
|
||||||
|
|
||||||
//! \~english Write raw data
|
//! \~english Write raw data
|
||||||
//! \~russian Пишет сырые символы
|
//! \~russian Пишет сырые символы
|
||||||
PICout & write(const char * str, int len);
|
PICout & write(const char * str, int len);
|
||||||
|
|
||||||
//! \~english Write raw \a PIString
|
//! \~english Write raw \a PIString
|
||||||
//! \~russian Пишет сырой \a PIString
|
//! \~russian Пишет сырой \a PIString
|
||||||
PICout & writePIString(const PIString & s);
|
PICout & write(const PIString & s);
|
||||||
|
|
||||||
|
//! \~english Output \a PIString to stdout
|
||||||
|
//! \~russian Вывод \a PIString в stdout
|
||||||
|
static void stdoutPIString(const PIString & s);
|
||||||
|
|
||||||
//! \~english Set output device to \a PICout::Buffer and if "clear" clear it
|
//! \~english Set output device to \a PICout::Buffer and if "clear" clear it
|
||||||
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
|
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
|
||||||
|
|||||||
@@ -35,20 +35,12 @@
|
|||||||
|
|
||||||
//! \addtogroup Core
|
//! \addtogroup Core
|
||||||
//! \{
|
//! \{
|
||||||
|
//!
|
||||||
//! \~\class PITime pidatetime.h
|
//! \~\class PITime pidatetime.h
|
||||||
//! \brief
|
|
||||||
//! \~english Calendar time
|
|
||||||
//! \~russian Календарное время
|
|
||||||
//!
|
//!
|
||||||
//! \~\class PIDate pidatetime.h
|
//! \~\class PIDate pidatetime.h
|
||||||
//! \brief
|
|
||||||
//! \~english Calendar date
|
|
||||||
//! \~russian Календарная дата
|
|
||||||
//!
|
//!
|
||||||
//! \~\class PIDateTime pidatetime.h
|
//! \~\class PIDateTime pidatetime.h
|
||||||
//! \brief
|
|
||||||
//! \~english Calendar date and time
|
|
||||||
//! \~russian Календарное дата и время
|
|
||||||
//!
|
//!
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
#include "pisystemtime.h"
|
#include "pisystemtime.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Calendar time.
|
||||||
|
//! \~russian Календарное время.
|
||||||
class PIP_EXPORT PITime {
|
class PIP_EXPORT PITime {
|
||||||
public:
|
public:
|
||||||
//! \~english Construct %PITime from hours, minutes, seconds and milliseconds
|
//! \~english Construct %PITime from hours, minutes, seconds and milliseconds
|
||||||
@@ -102,6 +106,10 @@ PIP_EXPORT PICout operator <<(PICout s, const PITime & v);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Calendar date.
|
||||||
|
//! \~russian Календарная дата.
|
||||||
class PIP_EXPORT PIDate {
|
class PIP_EXPORT PIDate {
|
||||||
public:
|
public:
|
||||||
//! \~english Construct %PIDate from year, month and day
|
//! \~english Construct %PIDate from year, month and day
|
||||||
@@ -162,6 +170,10 @@ PIP_EXPORT PICout operator <<(PICout s, const PIDate & v);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Calendar date and time.
|
||||||
|
//! \~russian Календарное дата и время.
|
||||||
class PIP_EXPORT PIDateTime {
|
class PIP_EXPORT PIDateTime {
|
||||||
public:
|
public:
|
||||||
//! \~english Construct null %PIDateTime
|
//! \~english Construct null %PIDateTime
|
||||||
|
|||||||
@@ -64,10 +64,16 @@ void errorClear() {
|
|||||||
|
|
||||||
PIString errorString() {
|
PIString errorString() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
char * msg;
|
char * msg = nullptr;
|
||||||
int err = GetLastError();
|
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);
|
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 " + PIString::fromNumber(err) + " - " + PIString(msg);
|
PIString ret = PIStringAscii("code ") + PIString::fromNumber(err) + PIStringAscii(" - ");
|
||||||
|
if (msg) {
|
||||||
|
ret += PIString::fromSystem(msg).trim();
|
||||||
|
LocalFree(msg);
|
||||||
|
} else
|
||||||
|
ret += '?';
|
||||||
|
return ret;
|
||||||
#else
|
#else
|
||||||
int e = errno;
|
int e = errno;
|
||||||
return PIString("code ") + PIString::fromNumber(e) + " - " + PIString(strerror(e));
|
return PIString("code ") + PIString::fromNumber(e) + " - " + PIString(strerror(e));
|
||||||
@@ -88,237 +94,3 @@ void randomize() {
|
|||||||
int randomi() {
|
int randomi() {
|
||||||
return rand();
|
return rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \~english \mainpage What is PIP
|
|
||||||
* \~russian \mainpage Что такое PIP
|
|
||||||
*
|
|
||||||
* \~english
|
|
||||||
* PIP - Platform-Independent Primitives - is crossplatform library for C++ developers.
|
|
||||||
* It is wrap around STL and pure C++. This library can help developers write non-GUI
|
|
||||||
* projects much more quickly, efficiently and customizable than on pure C++.
|
|
||||||
* Library contains many classes, some of them are pure abstract, some classes
|
|
||||||
* can be used as they are, some classes should be inherited to new classes.
|
|
||||||
* PIP provide classes:
|
|
||||||
* * direct output to console (\a PICout)
|
|
||||||
* * containers (\a PIVector, \a PIList, \a PIMap, \a PIStack)
|
|
||||||
* * byte array (\a PIByteArray)
|
|
||||||
* * string (\a PIString, \a PIStringList)
|
|
||||||
* * base object (events and handlers) (\a PIObject)
|
|
||||||
* * multithreading
|
|
||||||
* * thread (\a PIThread)
|
|
||||||
* * executor (\a PIThreadPoolExecutor)
|
|
||||||
* * blocking dequeue (\a PIBlockingDequeue)
|
|
||||||
* * timer (\a PITimer)
|
|
||||||
* * tiling console (with widgets) (\a PIScreen)
|
|
||||||
* * simple text rows
|
|
||||||
* * scroll bar
|
|
||||||
* * list
|
|
||||||
* * button
|
|
||||||
* * buttons group
|
|
||||||
* * check box
|
|
||||||
* * progress bar
|
|
||||||
* * PICout output
|
|
||||||
* * text input
|
|
||||||
* * I/O devices
|
|
||||||
* * base class (\a PIIODevice)
|
|
||||||
* * file (\a PIFile)
|
|
||||||
* * serial port (\a PISerial)
|
|
||||||
* * ethernet (\a PIEthernet)
|
|
||||||
* * USB (\a PIUSB)
|
|
||||||
* * packets extractor (\a PIPacketExtractor)
|
|
||||||
* * binary log (\a PIBinaryLog)
|
|
||||||
* * complex I/O point (\a PIConnection)
|
|
||||||
* * Run-time libraries
|
|
||||||
* * abstract (\a PILibrary)
|
|
||||||
* * plugin (\a PIPluginLoader)
|
|
||||||
* * connection quality diagnotic (\a PIDiagnostics)
|
|
||||||
* * command-line arguments parser (\a PICLI)
|
|
||||||
* * math evaluator (\a PIEvaluator)
|
|
||||||
* * peering net node (\a PIPeer)
|
|
||||||
* * process (\a PIProcess)
|
|
||||||
* * state machine (\a PIStateMachine)
|
|
||||||
* \n \n Basic using of PIP described at page \ref using_basic
|
|
||||||
*
|
|
||||||
* \~russian
|
|
||||||
* PIP - Platform-Independent Primitives - кроссплатформенная библиотека для разработчиков на C++.
|
|
||||||
* It is wrap around STL and pure C++. This library can help developers write non-GUI
|
|
||||||
* projects much more quickly, efficiently and customizable than on pure C++.
|
|
||||||
* PIP предоставляет следующие классы:
|
|
||||||
* * общение с консолью (\a PICout)
|
|
||||||
* * контейнеры (\a PIVector, \a PIList, \a PIMap, \a PIStack)
|
|
||||||
* * байтовый массив (\a PIByteArray)
|
|
||||||
* * строка (\a PIString, \a PIStringList)
|
|
||||||
* * базовый объект (события и обработчики) (\a PIObject)
|
|
||||||
* * многопоточность
|
|
||||||
* * поток (\a PIThread)
|
|
||||||
* * исполнитель (\a PIThreadPoolExecutor)
|
|
||||||
* * блокирующая очередь (\a PIBlockingDequeue)
|
|
||||||
* * таймер (\a PITimer)
|
|
||||||
* * тайлинговая консоль (с виджетами) (\a PIScreen)
|
|
||||||
* * простой вывод строк
|
|
||||||
* * скроллбар
|
|
||||||
* * лист
|
|
||||||
* * кнопка
|
|
||||||
* * группа кнопок
|
|
||||||
* * галочка
|
|
||||||
* * прогрессбар
|
|
||||||
* * вывод PICout
|
|
||||||
* * текстовый ввод
|
|
||||||
* * устройства ввода/вывода
|
|
||||||
* * базовый класс (\a PIIODevice)
|
|
||||||
* * файл (\a PIFile)
|
|
||||||
* * последовательный порт (\a PISerial)
|
|
||||||
* * ethernet (\a PIEthernet)
|
|
||||||
* * USB (\a PIUSB)
|
|
||||||
* * packets extractor (\a PIPacketExtractor)
|
|
||||||
* * бинарный логфайл (\a PIBinaryLog)
|
|
||||||
* * сложное составное устройство (\a PIConnection)
|
|
||||||
* * поддержка библиотек времени выполнения
|
|
||||||
* * базовая функциональность (\a PILibrary)
|
|
||||||
* * плагин (\a PIPluginLoader)
|
|
||||||
* * диагностика качества связи (\a PIDiagnostics)
|
|
||||||
* * парсер аргументов командной строки (\a PICLI)
|
|
||||||
* * вычислитель (\a PIEvaluator)
|
|
||||||
* * пиринговая сеть (\a PIPeer)
|
|
||||||
* * процесс (\a PIProcess)
|
|
||||||
* * машина состояний (\a PIStateMachine)
|
|
||||||
* \n \n Базовое использование PIP описано на странице \ref using_basic
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*! \~english \page using_basic Getting started
|
|
||||||
* \~russian \page using_basic Простые начала
|
|
||||||
*
|
|
||||||
* \~english
|
|
||||||
* Many novice programmers are solved many common task with system integrity: output to console,
|
|
||||||
* keyboard buttons press detecting, working with serial ports, ethernet or files, and many other.
|
|
||||||
* These tasks can solve this library, and code, based only on PIP will be compile and work
|
|
||||||
* similar on many systems: Windows, any Linux, Red Hat, FreeBSD, MacOS X and QNX.
|
|
||||||
* Typical application on PIP looks like this: \n
|
|
||||||
*
|
|
||||||
* \~russian
|
|
||||||
* Многие начинающие программисты решают общие задачи взаимодействия с операционной системой:
|
|
||||||
* вывод в консоль, определение нажатия клавиш, работа с последовательными портами, сетью или файлами,
|
|
||||||
* и многое другое. Эти задачи решены в библиотеке, и код, основанный на PIP будет компилироваться
|
|
||||||
* и работать одинаково на многих системах: Windows, любой Linux, Red Hat, FreeBSD, MacOS X и QNX.
|
|
||||||
* Типовое приложение на PIP выглядит примерно так: \n
|
|
||||||
*
|
|
||||||
\code{.cpp}
|
|
||||||
#include <pip.h>
|
|
||||||
|
|
||||||
|
|
||||||
// declare key press handler
|
|
||||||
void key_event(char key, void * );
|
|
||||||
|
|
||||||
|
|
||||||
PIConsole console(false, key_event); // don`t start now, key handler is "key_event"
|
|
||||||
|
|
||||||
|
|
||||||
// some vars
|
|
||||||
int i = 2, j = 3;
|
|
||||||
|
|
||||||
|
|
||||||
// implicit key press handler
|
|
||||||
void key_event(char key, void * ) {
|
|
||||||
switch (key) {
|
|
||||||
case '-':
|
|
||||||
i--;
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
i++;
|
|
||||||
break;
|
|
||||||
case '(':
|
|
||||||
j--;
|
|
||||||
break;
|
|
||||||
case ')':
|
|
||||||
j++;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class MainClass: public PITimer {
|
|
||||||
PIOBJECT(MainClass)
|
|
||||||
public:
|
|
||||||
MainClass() {}
|
|
||||||
protected:
|
|
||||||
void tick(void * data, int delimiter) {
|
|
||||||
piCout << "timer tick";
|
|
||||||
// timer tick
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MainClass main_class;
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
|
||||||
// enabling auto-detection of exit button press, by default 'Q' (shift+q)
|
|
||||||
console.enableExitCapture();
|
|
||||||
|
|
||||||
// if we want to parse command-line arguments
|
|
||||||
PICLI cli(argc, argv);
|
|
||||||
cli.addArgument("console"); // "-c" or "--console"
|
|
||||||
cli.addArgument("debug"); // "-d" or "--debug"
|
|
||||||
|
|
||||||
// enabling or disabling global debug flag
|
|
||||||
piDebug = cli.hasArgument("debug");
|
|
||||||
|
|
||||||
// configure console
|
|
||||||
console.addTab("first tab", '1');
|
|
||||||
console.addString("PIP console", 1, PIConsole::Bold);
|
|
||||||
console.addVariable("int var (i)", &i, 1);
|
|
||||||
console.addVariable("int green var (j)", &j, 1, PIConsole::Green);
|
|
||||||
console.addString("'-' - i--", 2);
|
|
||||||
console.addString("'+' - i++", 2);
|
|
||||||
console.addString("'(' - j--", 2);
|
|
||||||
console.addString("')' - j++", 2);
|
|
||||||
console.addTab("second tab", '2');
|
|
||||||
console.addString("col 1", 1);
|
|
||||||
console.addString("col 2", 2);
|
|
||||||
console.addString("col 3", 3);
|
|
||||||
console.setTab("first tab");
|
|
||||||
|
|
||||||
// start output to console if "console" argument exists
|
|
||||||
if (cli.hasArgument("console"))
|
|
||||||
console.start();
|
|
||||||
|
|
||||||
// start main class, e.g. 40 Hz
|
|
||||||
main_class.start(25.);
|
|
||||||
|
|
||||||
// wait for 'Q' press, independently if console is started or not
|
|
||||||
console.waitForFinish();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
\endcode
|
|
||||||
*
|
|
||||||
* \~english
|
|
||||||
* This code demonstrates simple interactive configurable program, which can be started with console
|
|
||||||
* display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
|
||||||
* \a PIThread and reimplement \a run() function.
|
|
||||||
* \n Many PIP classes has events and event handlers, which can be connected one to another.
|
|
||||||
* Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
|
||||||
* \n To configure your program from file use \a PIConfig.
|
|
||||||
* \n If you want more information see \ref using_advanced
|
|
||||||
*
|
|
||||||
* \~russian
|
|
||||||
* Этот код демонстрирует простую конфигурируемую программу, которая может быть запущена с
|
|
||||||
* This code demonstrates simple interactive configurable program, which can be started with console
|
|
||||||
* display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
|
||||||
* \a PIThread and reimplement \a run() function.
|
|
||||||
* \n Many PIP classes has events and event handlers, which can be connected one to another.
|
|
||||||
* Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
|
||||||
* \n To configure your program from file use \a PIConfig.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*! \page using_advanced Advanced using
|
|
||||||
* Sorry, creativity crysis xD
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* \~english
|
|
||||||
* \~russian
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -152,12 +152,16 @@ PIInit::PIInit() {
|
|||||||
}
|
}
|
||||||
# endif //WINDOWS
|
# endif //WINDOWS
|
||||||
# ifdef HAS_LOCALE
|
# ifdef HAS_LOCALE
|
||||||
//cout << "has locale" << endl;
|
//std::cout << "has locale" << std::endl;
|
||||||
if (currentLocale_t != 0) {
|
if (currentLocale_t != 0) {
|
||||||
freelocale(currentLocale_t);
|
freelocale(currentLocale_t);
|
||||||
currentLocale_t = 0;
|
currentLocale_t = 0;
|
||||||
}
|
}
|
||||||
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
|
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, "C"), 0);
|
||||||
|
setlocale(LC_CTYPE, "en_US.UTF-8");
|
||||||
|
//std::ios_base::sync_with_stdio(false);
|
||||||
|
//std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
||||||
|
//std::wcout.imbue(utf8);
|
||||||
# else //HAS_LOCALE
|
# else //HAS_LOCALE
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
@@ -212,9 +216,6 @@ PIInit::PIInit() {
|
|||||||
if (gethostname(cbuff, 1023) == 0) {
|
if (gethostname(cbuff, 1023) == 0) {
|
||||||
sinfo->hostname = cbuff;
|
sinfo->hostname = cbuff;
|
||||||
}
|
}
|
||||||
// std::ios_base::sync_with_stdio(false);
|
|
||||||
// std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
|
||||||
// std::wcout.imbue(utf8);
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
|
|||||||
@@ -26,13 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PIObject piobject.h
|
//! \~\class PIObject piobject.h
|
||||||
//! \~\brief
|
|
||||||
//! \~english This is base class for any classes which use events -> handlers mechanism
|
|
||||||
//! \~russian Этот класс является базовым для использования механизма события -> обработчики
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PIObject_sec0 Events and Event handlers
|
//! \~english \section PIObject_sec0 Events and Event handlers
|
||||||
//! \~russian \section PIObject_sec0 События и Обработчики событий
|
//! \~russian \section PIObject_sec0 События и Обработчики событий
|
||||||
@@ -98,16 +92,12 @@
|
|||||||
//! handler A: event to event
|
//! handler A: event to event
|
||||||
//! event to lambda
|
//! event to lambda
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \}
|
//!
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PIObject::Connection piobject.h
|
//! \~\class PIObject::Connection piobject.h
|
||||||
//! \~\brief
|
//! \~\details
|
||||||
//! \~english Helper class for obtain info about if connection successful and disconnect single connection
|
//!
|
||||||
//! \~russian Вспомогательный класс для получения информации об успешности соединения и возможности его разрыва
|
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PIObject::__MetaFunc::__MetaFunc() {
|
PIObject::__MetaFunc::__MetaFunc() {
|
||||||
@@ -206,15 +196,6 @@ PIObject::~PIObject() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIMap<PIString, PIVariant> PIObject::properties() const {
|
|
||||||
PIMap<PIString, PIVariant> ret;
|
|
||||||
piForeachC (PropertyHash p, properties_)
|
|
||||||
ret[p.second.first] = p.second.second;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple> & vl) {
|
bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple> & vl) {
|
||||||
@@ -259,7 +240,7 @@ PIStringList PIObject::scopeList() const {
|
|||||||
PIMutexLocker ml(__meta_mutex());
|
PIMutexLocker ml(__meta_mutex());
|
||||||
const PIVector<const char *> & scope(__meta_data()[classNameID()].scope_list);
|
const PIVector<const char *> & scope(__meta_data()[classNameID()].scope_list);
|
||||||
for (const char * c: scope)
|
for (const char * c: scope)
|
||||||
ret = PIStringAscii(c);
|
ret << PIStringAscii(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -693,9 +674,12 @@ void PIObject::dump(const PIString & line_prefix) const {
|
|||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
||||||
//printf("dump %d properties\n", properties_.size());
|
//printf("dump %d properties\n", properties_.size());
|
||||||
piForeachC (PropertyHash p, properties_)
|
const char * o_name = "name";
|
||||||
if (p.first != PIString("name").hash())
|
auto it = properties_.makeIterator();
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.second.first << ": " << p.second.second;
|
while (it.next()) {
|
||||||
|
if (it.key() != piHashData((const uchar *)o_name, strlen(o_name)))
|
||||||
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << it.key() << ": " << it.value();
|
||||||
|
}
|
||||||
//printf("dump %d properties ok\n", properties_.size());
|
//printf("dump %d properties ok\n", properties_.size());
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
||||||
@@ -710,7 +694,7 @@ void PIObject::dump(const PIString & line_prefix) const {
|
|||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||||
//printf("dump %d connections\n",connections.size());
|
//printf("dump %d connections\n",connections.size());
|
||||||
piForeachC (Connection & c, connections) {
|
for (const Connection & c : connections) {
|
||||||
PIObject * dst = c.dest_o;
|
PIObject * dst = c.dest_o;
|
||||||
__MetaFunc ef = methodEH(c.signal);
|
__MetaFunc ef = methodEH(c.signal);
|
||||||
PIString src(c.event);
|
PIString src(c.event);
|
||||||
@@ -733,7 +717,7 @@ void PIObject::dump(const PIString & line_prefix) const {
|
|||||||
|
|
||||||
|
|
||||||
#ifndef MICRO_PIP
|
#ifndef MICRO_PIP
|
||||||
void dumpApplication() {
|
void dumpApplication(bool with_objects) {
|
||||||
PIMutexLocker _ml(PIObject::mutexObjects());
|
PIMutexLocker _ml(PIObject::mutexObjects());
|
||||||
//printf("dump application ...\n");
|
//printf("dump application ...\n");
|
||||||
PIDateTime cd = PIDateTime::current();
|
PIDateTime cd = PIDateTime::current();
|
||||||
@@ -751,22 +735,24 @@ void dumpApplication() {
|
|||||||
PICout(PICoutManipulators::AddNewLine) << " uptime: " << PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
|
PICout(PICoutManipulators::AddNewLine) << " uptime: " << PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
|
||||||
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
|
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
|
||||||
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects().size_s();
|
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects().size_s();
|
||||||
piForeachC (PIObject * o, PIObject::objects())
|
if (with_objects) {
|
||||||
|
for (const PIObject * o: PIObject::objects())
|
||||||
o->dump(" ");
|
o->dump(" ");
|
||||||
|
}
|
||||||
PICout(PICoutManipulators::AddNewLine) << " }";
|
PICout(PICoutManipulators::AddNewLine) << " }";
|
||||||
PICout(PICoutManipulators::AddNewLine) << "}";
|
PICout(PICoutManipulators::AddNewLine) << "}";
|
||||||
//printf("dump application done\n");
|
//printf("dump application done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool dumpApplicationToFile(const PIString & path) {
|
bool dumpApplicationToFile(const PIString & path, bool with_objects) {
|
||||||
PIFile f(path + "_tmp");
|
PIFile f(path + "_tmp");
|
||||||
f.setName("__S__DumpFile");
|
f.setName("__S__DumpFile");
|
||||||
f.clear();
|
f.clear();
|
||||||
if (!f.open(PIIODevice::WriteOnly)) return false;
|
if (!f.open(PIIODevice::WriteOnly)) return false;
|
||||||
bool ba = PICout::isBufferActive();
|
bool ba = PICout::isBufferActive();
|
||||||
PICout::setBufferActive(true, true);
|
PICout::setBufferActive(true, true);
|
||||||
dumpApplication();
|
dumpApplication(with_objects);
|
||||||
f << PICout::buffer();
|
f << PICout::buffer();
|
||||||
f.close();
|
f.close();
|
||||||
PICout::setBufferActive(ba, true);
|
PICout::setBufferActive(ba, true);
|
||||||
|
|||||||
@@ -36,10 +36,14 @@
|
|||||||
|
|
||||||
typedef void (*Handler)(void * );
|
typedef void (*Handler)(void * );
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english This is base class for any classes which use events -> handlers mechanism.
|
||||||
|
//! \~russian Этот класс является базовым для использования механизма события -> обработчики.
|
||||||
class PIP_EXPORT PIObject {
|
class PIP_EXPORT PIObject {
|
||||||
#ifndef MICRO_PIP
|
#ifndef MICRO_PIP
|
||||||
friend class PIObjectManager;
|
friend class PIObjectManager;
|
||||||
friend void dumpApplication();
|
friend void dumpApplication(bool);
|
||||||
friend class PIIntrospection;
|
friend class PIIntrospection;
|
||||||
#endif
|
#endif
|
||||||
typedef PIObject __PIObject__;
|
typedef PIObject __PIObject__;
|
||||||
@@ -53,6 +57,10 @@ public:
|
|||||||
|
|
||||||
virtual ~PIObject();
|
virtual ~PIObject();
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Helper class for obtain info about if connection successful and disconnect single connection.
|
||||||
|
//! \~russian Вспомогательный класс для получения информации об успешности соединения и возможности его разрыва.
|
||||||
class PIP_EXPORT Connection {
|
class PIP_EXPORT Connection {
|
||||||
friend class PIObject;
|
friend class PIObject;
|
||||||
Connection(void * sl, void * si, const PIString & e = PIString(),
|
Connection(void * sl, void * si, const PIString & e = PIString(),
|
||||||
@@ -113,7 +121,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Returns object name
|
//! \~english Returns object name
|
||||||
//! \~russian Возвращает имя объекта
|
//! \~russian Возвращает имя объекта
|
||||||
PIString name() const {return property(PIStringAscii("name")).toString();}
|
PIString name() const {return property("name").toString();}
|
||||||
|
|
||||||
//! \~english Returns object class name
|
//! \~english Returns object class name
|
||||||
//! \~russian Возвращает имя класса объекта
|
//! \~russian Возвращает имя класса объекта
|
||||||
@@ -131,40 +139,28 @@ public:
|
|||||||
|
|
||||||
//! \~english Return if \a piCoutObj of this object is active
|
//! \~english Return if \a piCoutObj of this object is active
|
||||||
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
|
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
|
||||||
bool debug() const {return property(PIStringAscii("debug")).toBool();}
|
bool debug() const {return property("debug").toBool();}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set object name
|
//! \~english Set object name
|
||||||
//! \~russian Устанавливает имя объекта
|
//! \~russian Устанавливает имя объекта
|
||||||
void setName(const PIString & name) {setProperty(PIStringAscii("name"), name);}
|
void setName(const PIString & name) {setProperty("name", name);}
|
||||||
void setName(const char * name) {setName(PIStringAscii(name));}
|
|
||||||
|
|
||||||
//! \~english Set object \a piCoutObj active
|
//! \~english Set object \a piCoutObj active
|
||||||
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
|
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
|
||||||
void setDebug(bool debug) {setProperty(PIStringAscii("debug"), debug);}
|
void setDebug(bool debug) {setProperty("debug", debug);}
|
||||||
|
|
||||||
//! \~english Returns properties of the object
|
|
||||||
//! \~russian Возвращает словарь свойств объекта
|
|
||||||
PIMap<PIString, PIVariant> properties() const;
|
|
||||||
|
|
||||||
//! \~english Returns properties count of the object
|
|
||||||
//! \~russian Возвращает количество свойств объекта
|
|
||||||
int propertiesCount() const {return properties_.size_s();}
|
|
||||||
|
|
||||||
//! \~english Returns property with name "name"
|
//! \~english Returns property with name "name"
|
||||||
//! \~russian Возвращает свойство объекта по имени "name"
|
//! \~russian Возвращает свойство объекта по имени "name"
|
||||||
PIVariant property(const PIString & name) const {return properties_.value(name.hash(), Property(PIString(), PIVariant())).second;}
|
PIVariant property(const char * name) const {return properties_.value(piHashData((const uchar *)name, strlen(name)));}
|
||||||
PIVariant property(const char * name) const {return property(PIStringAscii(name));}
|
|
||||||
|
|
||||||
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
|
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
|
||||||
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
|
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
|
||||||
void setProperty(const PIString & name, const PIVariant & value) {properties_[name.hash()] = Property(name, value); propertyChanged(name);}
|
void setProperty(const char * name, const PIVariant & value) {properties_[piHashData((const uchar *)name, strlen(name))] = value; propertyChanged(name);}
|
||||||
void setProperty(const char * name, const PIVariant & value) {setProperty(PIStringAscii(name), value);}
|
|
||||||
|
|
||||||
//! \~english Returns if property with name "name" exists
|
//! \~english Returns if property with name "name" exists
|
||||||
//! \~russian Возвращает присутствует ли свойство по имени "name"
|
//! \~russian Возвращает присутствует ли свойство по имени "name"
|
||||||
bool isPropertyExists(const PIString & name) const {return properties_.contains(name.hash());}
|
bool isPropertyExists(const char * name) const {return properties_.contains(piHashData((const uchar *)name, strlen(name)));}
|
||||||
bool isPropertyExists(const char * name) const {return isPropertyExists(PIStringAscii(name));}
|
|
||||||
|
|
||||||
void setThreadSafe(bool yes) {thread_safe_ = yes;}
|
void setThreadSafe(bool yes) {thread_safe_ = yes;}
|
||||||
bool isThreadSafe() const {return thread_safe_;}
|
bool isThreadSafe() const {return thread_safe_;}
|
||||||
@@ -520,7 +516,7 @@ protected:
|
|||||||
|
|
||||||
//! \~english Virtual function executes after property with name "name" has been changed
|
//! \~english Virtual function executes after property with name "name" has been changed
|
||||||
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
|
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
|
||||||
virtual void propertyChanged(const PIString & name) {}
|
virtual void propertyChanged(const char * name) {}
|
||||||
|
|
||||||
EVENT1(deleted, PIObject *, o)
|
EVENT1(deleted, PIObject *, o)
|
||||||
|
|
||||||
@@ -569,9 +565,6 @@ private:
|
|||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef PIPair<PIString, PIVariant> Property;
|
|
||||||
typedef PIPair<uint, PIPair<PIString, PIVariant> > PropertyHash;
|
|
||||||
|
|
||||||
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
|
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
|
||||||
PIVector<__MetaFunc> findEH(const PIString & name) const;
|
PIVector<__MetaFunc> findEH(const PIString & name) const;
|
||||||
__MetaFunc methodEH(const void * addr) const;
|
__MetaFunc methodEH(const void * addr) const;
|
||||||
@@ -591,7 +584,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
PIVector<Connection> connections;
|
PIVector<Connection> connections;
|
||||||
PIMap<uint, PIPair<PIString, PIVariant> > properties_;
|
PIMap<uint, PIVariant> properties_;
|
||||||
PISet<PIObject * > connectors;
|
PISet<PIObject * > connectors;
|
||||||
PIVector<__QueuedEvent> events_queue;
|
PIVector<__QueuedEvent> events_queue;
|
||||||
PIMutex mutex_, mutex_connect, mutex_queue;
|
PIMutex mutex_, mutex_connect, mutex_queue;
|
||||||
@@ -602,8 +595,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifndef MICRO_PIP
|
#ifndef MICRO_PIP
|
||||||
PIP_EXPORT void dumpApplication();
|
PIP_EXPORT void dumpApplication(bool with_objects = true);
|
||||||
PIP_EXPORT bool dumpApplicationToFile(const PIString & path);
|
PIP_EXPORT bool dumpApplicationToFile(const PIString & path, bool with_objects = true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // PIOBJECT_H
|
#endif // PIOBJECT_H
|
||||||
|
|||||||
@@ -20,13 +20,7 @@
|
|||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PIPropertyStorage pipropertystorage.h
|
//! \~\class PIPropertyStorage pipropertystorage.h
|
||||||
//! \~\brief
|
|
||||||
//! \~english This class provides key-value properties storage
|
|
||||||
//! \~russian Этот класс предоставляет ключ-значение хранение свойств
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PIPropertyStorage_sec0 Synopsis
|
//! \~english \section PIPropertyStorage_sec0 Synopsis
|
||||||
//! \~russian \section PIPropertyStorage_sec0 Краткий обзор
|
//! \~russian \section PIPropertyStorage_sec0 Краткий обзор
|
||||||
@@ -45,35 +39,12 @@
|
|||||||
//! \~russian Пример:
|
//! \~russian Пример:
|
||||||
//! \~\code{.cpp}
|
//! \~\code{.cpp}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \}
|
//!
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PIPropertyStorage::Property pipropertystorage.h
|
//! \~\class PIPropertyStorage::Property pipropertystorage.h
|
||||||
//! \~\brief
|
|
||||||
//! \~english PIPropertyStorage element
|
|
||||||
//! \~russian Элемент PIPropertyStorage
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PIPropertyStorage_sec1 Synopsis
|
|
||||||
//! \~russian \section PIPropertyStorage_sec1 Краткий обзор
|
|
||||||
//!
|
//!
|
||||||
//! \~english
|
|
||||||
//! Key-value storage, based on PIVector with PIPropertyStorage::Property elements. Each element in vector
|
|
||||||
//! contains unique name. You can access property by name with \a propertyValueByName() or \a propertyByName().
|
|
||||||
//! You can add or replace property by \a addProperty(const Property&) or \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
|
|
||||||
//!
|
|
||||||
//! \~russian
|
|
||||||
//! Хранилище свойств ключ-значние, основанный на PIVector с элементами PIPropertyStorage::Property.
|
|
||||||
//! Каждый элемент имеет уникальное имя. Доступ к свойствам через \a propertyValueByName() или \a propertyByName().
|
|
||||||
//! Добавление и перезапись свойств через \a addProperty(const Property&) или \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
|
|
||||||
//!
|
|
||||||
//! \~english Example:
|
|
||||||
//! \~russian Пример:
|
|
||||||
//! \~\code{.cpp}
|
|
||||||
//! \endcode
|
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
#include "pivariant.h"
|
#include "pivariant.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english This class provides key-value properties storage.
|
||||||
|
//! \~russian Этот класс предоставляет ключ-значение хранение свойств.
|
||||||
class PIP_EXPORT PIPropertyStorage {
|
class PIP_EXPORT PIPropertyStorage {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -36,6 +40,10 @@ public:
|
|||||||
//! \~russian Создает пустой %PIPropertyStorage
|
//! \~russian Создает пустой %PIPropertyStorage
|
||||||
PIPropertyStorage() {}
|
PIPropertyStorage() {}
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIPropertyStorage element.
|
||||||
|
//! \~russian Элемент PIPropertyStorage.
|
||||||
struct PIP_EXPORT Property {
|
struct PIP_EXPORT Property {
|
||||||
|
|
||||||
//! \~english Contructs %PIPropertyStorage::Property with name "n", comment "c", value "v" and flags "f"
|
//! \~english Contructs %PIPropertyStorage::Property with name "n", comment "c", value "v" and flags "f"
|
||||||
@@ -257,8 +265,6 @@ public:
|
|||||||
//! \~russian Возвращает свойство с именем "name" как константу
|
//! \~russian Возвращает свойство с именем "name" как константу
|
||||||
const Property operator[](const PIString & name) const;
|
const Property operator[](const PIString & name) const;
|
||||||
|
|
||||||
static Property parsePropertyLine(PIString l);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIVector<Property> props;
|
PIVector<Property> props;
|
||||||
|
|
||||||
|
|||||||
@@ -27,15 +27,11 @@
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <stringapiset.h>
|
# include <stringapiset.h>
|
||||||
#endif
|
#endif
|
||||||
#include <wchar.h>
|
#include <string>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PIString pistring.h
|
//! \class PIString pistring.h
|
||||||
//! \brief
|
|
||||||
//! \~english String class
|
|
||||||
//! \~russian Класс строки
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PIString_sec0 Synopsis
|
//! \~english \section PIString_sec0 Synopsis
|
||||||
//! \~russian \section PIString_sec0 Краткий обзор
|
//! \~russian \section PIString_sec0 Краткий обзор
|
||||||
@@ -52,7 +48,6 @@
|
|||||||
//! создана из множества типов и преобразована в несколько типов.
|
//! создана из множества типов и преобразована в несколько типов.
|
||||||
//! Имеет множество методов для манипуляций.
|
//! Имеет множество методов для манипуляций.
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +56,7 @@ const char PIString::toBaseN[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '
|
|||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||||
'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^'};
|
'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^'};
|
||||||
const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
const char 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, -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,
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
||||||
@@ -83,11 +78,7 @@ const float PIString::ElideCenter = .5f;
|
|||||||
const float PIString::ElideRight = 1.f;
|
const float PIString::ElideRight = 1.f;
|
||||||
|
|
||||||
|
|
||||||
#ifndef CC_VC
|
#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIStringAscii(ch);
|
||||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v); return PIString(ch);
|
|
||||||
#else
|
|
||||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v); return PIString(ch);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PIString PIString::itos(const int num) {pisprintf("%d", num);}
|
PIString PIString::itos(const int num) {pisprintf("%d", num);}
|
||||||
PIString PIString::ltos(const long num) {pisprintf("%ld", num);}
|
PIString PIString::ltos(const long num) {pisprintf("%ld", num);}
|
||||||
@@ -95,16 +86,10 @@ PIString PIString::lltos(const llong num) {pisprintf("%lld", num);}
|
|||||||
PIString PIString::uitos(const uint num) {pisprintf("%u", num);}
|
PIString PIString::uitos(const uint num) {pisprintf("%u", num);}
|
||||||
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num);}
|
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num);}
|
||||||
PIString PIString::ulltos(const ullong num) {pisprintf("%llu", num);}
|
PIString PIString::ulltos(const ullong num) {pisprintf("%llu", num);}
|
||||||
PIString PIString::ftos(const float num, char format, int precision) {
|
|
||||||
char f[8] = "%.";
|
|
||||||
int wr = sprintf(&(f[2]), "%d", precision);
|
|
||||||
f[2 + wr] = format;
|
|
||||||
f[3 + wr] = 0;
|
|
||||||
pisprintf(f, num);
|
|
||||||
}
|
|
||||||
PIString PIString::dtos(const double num, char format, int precision) {
|
PIString PIString::dtos(const double num, char format, int precision) {
|
||||||
char f[8] = "%.";
|
char f[8] = "%.";
|
||||||
int wr = sprintf(&(f[2]), "%d", precision);
|
int wr = snprintf(&(f[2]), 4, "%d", precision);
|
||||||
|
if (wr > 4) wr = 4;
|
||||||
f[2 + wr] = format;
|
f[2 + wr] = format;
|
||||||
f[3 + wr] = 0;
|
f[3 + wr] = 0;
|
||||||
pisprintf(f, num);
|
pisprintf(f, num);
|
||||||
@@ -115,7 +100,7 @@ PIString PIString::dtos(const double num, char format, int precision) {
|
|||||||
|
|
||||||
PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
|
PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
|
||||||
if (value == 0LL) return PIString('0');
|
if (value == 0LL) return PIString('0');
|
||||||
if (base < 2 || base > 40) {
|
if ((base < 2) || (base > 40)) {
|
||||||
if (ok != 0) *ok = false;
|
if (ok != 0) *ok = false;
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
@@ -137,7 +122,7 @@ PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
|
|||||||
|
|
||||||
PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
|
PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
|
||||||
if (value == 0ULL) return PIString('0');
|
if (value == 0ULL) return PIString('0');
|
||||||
if (base < 2 || base > 40) {
|
if ((base < 2) || (base > 40)) {
|
||||||
if (ok != 0) *ok = false;
|
if (ok != 0) *ok = false;
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
@@ -168,7 +153,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
|||||||
} else {
|
} else {
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
} else if (base < 2 || base > 40) {
|
} else if ((base < 2) || (base > 40)) {
|
||||||
if (ok != 0) *ok = false;
|
if (ok != 0) *ok = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -176,7 +161,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
|||||||
PIVector<int> digits;
|
PIVector<int> digits;
|
||||||
llong ret = 0, m = 1;
|
llong ret = 0, m = 1;
|
||||||
bool neg = false;
|
bool neg = false;
|
||||||
int cs;
|
char cs;
|
||||||
for (int i = 0; i < v.size_s(); ++i) {
|
for (int i = 0; i < v.size_s(); ++i) {
|
||||||
if (v[i] == PIChar('-')) {
|
if (v[i] == PIChar('-')) {
|
||||||
neg = !neg;
|
neg = !neg;
|
||||||
@@ -199,50 +184,32 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
|||||||
|
|
||||||
|
|
||||||
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||||
if (s <= 0) return;
|
// piCout << "appendFromChars";
|
||||||
int sz;
|
if (s == 0) return;
|
||||||
|
int old_sz = size_s();
|
||||||
|
if (s == -1) s = strlen(c);
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
UErrorCode e((UErrorCode)0);
|
UErrorCode e((UErrorCode)0);
|
||||||
UConverter * cc = ucnv_open(codepage, &e);
|
UConverter * cc = ucnv_open(codepage, &e);
|
||||||
if (cc) {
|
if (cc) {
|
||||||
UChar * ucs = new UChar[s];
|
d.enlarge(s);
|
||||||
memset(ucs, 0, s * sizeof(UChar));
|
|
||||||
e = (UErrorCode)0;
|
e = (UErrorCode)0;
|
||||||
sz = ucnv_toUChars(cc, ucs, s, c, s, &e);
|
int sz = ucnv_toUChars(cc, (UChar*)(d.data(old_sz)), s, c, s, &e);
|
||||||
//printf("appendFromChars %d -> %d\n", s, sz);
|
d.resize(old_sz+sz);
|
||||||
//printf("PIString %d -> %d\n", c[0], ucs[0]);
|
|
||||||
reserve(size_s() + sz);
|
|
||||||
for (int i = 0; i < sz; ++i) {
|
|
||||||
push_back(PIChar((ushort)ucs[i]));
|
|
||||||
}
|
|
||||||
delete[] ucs;
|
|
||||||
ucnv_close(cc);
|
ucnv_close(cc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
int sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
||||||
if (sz <= 0) return;
|
if (sz <= 0) return;
|
||||||
int old_sz = size_s();
|
d.enlarge(sz);
|
||||||
enlarge(sz);
|
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)d.data(old_sz), sz);
|
||||||
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque<PIChar>::data(old_sz), sz);
|
|
||||||
return;
|
|
||||||
//printf("request %d\n", sz);
|
|
||||||
# else
|
# else
|
||||||
mbstate_t state;
|
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
|
||||||
memset(&state, 0, sizeof(state));
|
std::u16string ucs2 = ucs2conv.from_bytes(c, c+s);
|
||||||
wchar_t wc;
|
d.enlarge(ucs2.size());
|
||||||
//qDebug() << "FromChars ...";
|
ucs2.copy((char16_t *)d.data(old_sz), ucs2.size());
|
||||||
while (sz = mbrtowc(&wc, c, s, &state) > 0) {
|
|
||||||
//qDebug() << "0" << s;
|
|
||||||
// sz = mbrtowc(&wc, c, s, &state);
|
|
||||||
//qDebug() << "1" << sz;
|
|
||||||
// if (sz < 1) break;
|
|
||||||
push_back(PIChar(wc));
|
|
||||||
c += sz; s -= sz;
|
|
||||||
//qDebug() << "2" << c;
|
|
||||||
}
|
|
||||||
//qDebug() << "FromChars done" << size();
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -251,7 +218,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
PIString PIString::fromConsole(const char * s) {
|
PIString PIString::fromConsole(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __sysoemname__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __sysoemname__);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -260,7 +227,7 @@ PIString PIString::fromConsole(const char * s) {
|
|||||||
PIString PIString::fromSystem(const char * s) {
|
PIString PIString::fromSystem(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __syslocname__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __syslocname__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +235,7 @@ PIString PIString::fromSystem(const char * s) {
|
|||||||
PIString PIString::fromUTF8(const char * s) {
|
PIString PIString::fromUTF8(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __utf8name__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __utf8name__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +264,7 @@ PIString PIString::fromAscii(const char * s, int len) {
|
|||||||
|
|
||||||
PIString PIString::fromCodepage(const char * s, const char * c) {
|
PIString PIString::fromCodepage(const char * s, const char * c) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (s[0] > '\0') ret.appendFromChars(s, strlen(s)
|
if (s[0] > '\0') ret.appendFromChars(s, -1
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
, c
|
, c
|
||||||
#else
|
#else
|
||||||
@@ -331,63 +298,35 @@ PIString PIString::readableSize(llong bytes) {
|
|||||||
|
|
||||||
|
|
||||||
void PIString::buildData(const char * cp) const {
|
void PIString::buildData(const char * cp) const {
|
||||||
//data_.clear();
|
|
||||||
deleteData();
|
deleteData();
|
||||||
int sz = 0;
|
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
UErrorCode e((UErrorCode)0);
|
UErrorCode e((UErrorCode)0);
|
||||||
UConverter * cc = ucnv_open(cp, &e);
|
UConverter * cc = ucnv_open(cp, &e);
|
||||||
if (cc) {
|
if (cc) {
|
||||||
char uc[8];
|
const size_t len = MB_CUR_MAX*size()+1;
|
||||||
data_.reserve(size_s());
|
data_ = (char *)malloc(len);
|
||||||
for (int i = 0; i < size_s(); ++i) {
|
int sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e);
|
||||||
if (at(i).isAscii()) {
|
|
||||||
data_.push_back(uchar(at(i).unicode16Code()));
|
|
||||||
} else {
|
|
||||||
e = (UErrorCode)0;
|
|
||||||
sz = ucnv_fromUChars(cc, uc, 8, (const UChar*)(PIDeque<PIChar>::data(i)), 1, &e);
|
|
||||||
for (int j = 0; j < sz; ++j) {
|
|
||||||
data_.push_back(uc[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ucnv_close(cc);
|
ucnv_close(cc);
|
||||||
data_.push_back('\0');
|
data_[sz] = '\0';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)PIDeque<PIChar>::data(), PIDeque<PIChar>::size_s(), 0, 0, NULL, NULL);
|
int sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL);
|
||||||
//printf("WideCharToMultiByte %d %d\n", (uint)(uintptr_t)cp, sz);
|
|
||||||
if (sz <= 0) {
|
if (sz <= 0) {
|
||||||
//printf("WideCharToMultiByte erro %d\n", GetLastError());
|
|
||||||
data_ = (char *)malloc(1);
|
data_ = (char *)malloc(1);
|
||||||
data_[0] = '\0';
|
data_[0] = '\0';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data_ = (char *)malloc(sz+1);
|
data_ = (char *)malloc(sz+1);
|
||||||
//data_.resize(sz);
|
WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), (LPSTR)data_, sz, NULL, NULL);
|
||||||
WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)PIDeque<PIChar>::data(), PIDeque<PIChar>::size_s(), (LPSTR)data_, sz, NULL, NULL);
|
|
||||||
data_[sz] = '\0';
|
data_[sz] = '\0';
|
||||||
return;
|
return;
|
||||||
# else
|
# else
|
||||||
wchar_t wc;
|
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
|
||||||
//char tc[MB_CUR_MAX];
|
std::string u8str = ucs2conv.to_bytes((char16_t*)d.data(), (char16_t*)d.data() + d.size());
|
||||||
mbstate_t state;
|
data_ = (char *)malloc(u8str.size()+1);
|
||||||
memset(&state, 0, sizeof(state));
|
strcpy(data_, u8str.c_str());
|
||||||
data_ = (char *)malloc(MB_CUR_MAX*size()+1);
|
|
||||||
char *p = data_;
|
|
||||||
for (int i = 0; i < size_s(); ++i) {
|
|
||||||
// if (at(i).isAscii()) {
|
|
||||||
// data_.push_back(uchar(at(i).toAscii()));
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
wc = at(i).toWChar();
|
|
||||||
sz = wcrtomb(p, wc, &state);
|
|
||||||
if (sz < 0) break;
|
|
||||||
p += sz;
|
|
||||||
}
|
|
||||||
p[0] = '\0';
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -401,14 +340,14 @@ void PIString::deleteData() const {
|
|||||||
|
|
||||||
|
|
||||||
void PIString::trimsubstr(int &st, int &fn) const {
|
void PIString::trimsubstr(int &st, int &fn) const {
|
||||||
for (int i = 0; i < length(); ++i) {
|
for (int i = 0; i < d.size_s(); ++i) {
|
||||||
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
||||||
st = i;
|
st = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (st < 0) return;
|
if (st < 0) return;
|
||||||
for (int i = length() - 1; i >= 0; --i) {
|
for (int i = d.size_s() - 1; i >= 0; --i) {
|
||||||
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
|
||||||
fn = i;
|
fn = i;
|
||||||
break;
|
break;
|
||||||
@@ -418,19 +357,19 @@ void PIString::trimsubstr(int &st, int &fn) const {
|
|||||||
|
|
||||||
|
|
||||||
uint PIString::hash() const {
|
uint PIString::hash() const {
|
||||||
return piHashData((const uchar*)PIDeque<PIChar>::data(), size() * sizeof(PIChar));
|
return piHashData((const uchar*)d.data(), d.size() * sizeof(PIChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIString::toUTF8() const {
|
PIByteArray PIString::toUTF8() const {
|
||||||
if (isEmpty()) return PIByteArray(1,'\0');
|
if (isEmpty()) return PIByteArray();
|
||||||
buildData(__utf8name__);
|
buildData(__utf8name__);
|
||||||
return PIByteArray(data_, strlen(data_));
|
return PIByteArray(data_, strlen(data_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIString::toCharset(const char * c) const {
|
PIByteArray PIString::toCharset(const char * c) const {
|
||||||
if (isEmpty()) return PIByteArray(1,'\0');
|
if (isEmpty()) return PIByteArray();
|
||||||
buildData(
|
buildData(
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
c
|
c
|
||||||
@@ -446,7 +385,7 @@ PIByteArray PIString::toCharset(const char * c) const {
|
|||||||
|
|
||||||
PIString & PIString::operator +=(const char * str) {
|
PIString & PIString::operator +=(const char * str) {
|
||||||
if (!str) return *this;
|
if (!str) return *this;
|
||||||
appendFromChars(str, strlen(str), __syslocname__);
|
appendFromChars(str, -1, __syslocname__);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,45 +399,47 @@ PIString & PIString::operator +=(const wchar_t * str) {
|
|||||||
if (!str) return *this;
|
if (!str) return *this;
|
||||||
int i = -1;
|
int i = -1;
|
||||||
while (str[++i]) {
|
while (str[++i]) {
|
||||||
push_back(PIChar(str[i]));
|
d.push_back(PIChar(str[i]));
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString & PIString::operator +=(const PIString & str) {
|
PIString & PIString::operator +=(const PIString & str) {
|
||||||
PIDeque<PIChar>::append(*(const PIDeque<PIChar>*)&str);
|
d.append(str.d);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString & PIString::operator +=(const PIConstChars & str) {
|
||||||
|
if (!str.isEmpty()) {
|
||||||
|
size_t os = d.size();
|
||||||
|
d.enlarge(str.size());
|
||||||
|
for (size_t l = 0; l < d.size(); ++l) {
|
||||||
|
d[os + l] = str[l];
|
||||||
|
}
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIString::operator ==(const PIString & str) const {
|
bool PIString::operator ==(const PIString & str) const {
|
||||||
uint l = str.size();
|
return d == str.d;
|
||||||
if (size() != l) return false;
|
|
||||||
for (uint i = 0; i < l; ++i) {
|
|
||||||
if (str[i] != at(i)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIString::operator !=(const PIString & str) const {
|
bool PIString::operator !=(const PIString & str) const {
|
||||||
uint l = str.size();
|
return d != str.d;
|
||||||
if (size() != l) return true;
|
|
||||||
for (uint i = 0; i < l; ++i) {
|
|
||||||
if (str[i] != at(i)) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIString::operator <(const PIString & str) const {
|
bool PIString::operator <(const PIString & str) const {
|
||||||
uint l = str.size();
|
size_t l = str.size();
|
||||||
if (size() < l) return true;
|
if (size() < l) return true;
|
||||||
if (size() > l) return false;
|
if (size() > l) return false;
|
||||||
for (uint i = 0; i < l; ++i) {
|
for (size_t i = 0; i < l; ++i) {
|
||||||
if (at(i) == str[i]) continue;
|
if (at(i) == str.at(i)) continue;
|
||||||
if (at(i) < str[i]) return true;
|
if (at(i) < str.at(i)) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -506,12 +447,12 @@ bool PIString::operator <(const PIString & str) const {
|
|||||||
|
|
||||||
|
|
||||||
bool PIString::operator >(const PIString & str) const {
|
bool PIString::operator >(const PIString & str) const {
|
||||||
uint l = str.size();
|
size_t l = str.size();
|
||||||
if (size() < l) return false;
|
if (size() < l) return false;
|
||||||
if (size() > l) return true;
|
if (size() > l) return true;
|
||||||
for (uint i = 0; i < l; ++i) {
|
for (size_t i = 0; i < l; ++i) {
|
||||||
if (at(i) == str[i]) continue;
|
if (at(i) == str.at(i)) continue;
|
||||||
if (at(i) < str[i]) return false;
|
if (at(i) < str.at(i)) return false;
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -542,10 +483,10 @@ PIString PIString::mid(const int start, const int len) const {
|
|||||||
s = 0;
|
s = 0;
|
||||||
}
|
}
|
||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
return PIString(&(at(s)), size_s() - s);
|
return PIString(d.data(s), size_s() - s);
|
||||||
} else {
|
} else {
|
||||||
if (l > length() - s) l = length() - s;
|
if (l > length() - s) l = length() - s;
|
||||||
return PIString(&(at(s)), l);
|
return PIString(d.data(s), l);
|
||||||
}
|
}
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
@@ -570,10 +511,10 @@ PIString & PIString::cutMid(const int start, const int len) {
|
|||||||
s = 0;
|
s = 0;
|
||||||
}
|
}
|
||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
remove(s, size() - s);
|
d.remove(s, size() - s);
|
||||||
} else {
|
} else {
|
||||||
if (l > length() - s) l = length() - s;
|
if (l > length() - s) l = length() - s;
|
||||||
remove(s, l);
|
d.remove(s, l);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -622,10 +563,10 @@ PIString PIString::trimmed() const {
|
|||||||
PIString & PIString::replace(int from, int count, const PIString & with) {
|
PIString & PIString::replace(int from, int count, const PIString & with) {
|
||||||
count = piMini(count, length() - from);
|
count = piMini(count, length() - from);
|
||||||
if (count == with.size_s()) {
|
if (count == with.size_s()) {
|
||||||
memcpy(PIDeque<PIChar>::data(from), static_cast<PIDeque<PIChar>>(with).data(), count * sizeof(PIChar));
|
memcpy(d.data(from), with.d.data(), count * sizeof(PIChar));
|
||||||
} else {
|
} else {
|
||||||
remove(from, count);
|
d.remove(from, count);
|
||||||
PIDeque<PIChar>::insert(from, with);
|
d.insert(from, with.d);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -677,9 +618,9 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!match) continue;
|
if (!match) continue;
|
||||||
if (dl > 0) PIDeque<PIChar>::insert(i, PIDeque<PIChar>((size_t)dl));
|
if (dl > 0) d.insert(i, PIDeque<PIChar>((size_t)dl));
|
||||||
if (dl < 0) PIDeque<PIChar>::remove(i, -dl);
|
if (dl < 0) d.remove(i, -dl);
|
||||||
memcpy(PIDeque<PIChar>::data(i), &(with.at(0)), with.length() * sizeof(PIChar));
|
memcpy(d.data(i), with.d.data(), with.size() * sizeof(PIChar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -705,8 +646,8 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!match) continue;
|
if (!match) continue;
|
||||||
if (dl > 0) PIDeque<PIChar>::remove(i, dl);
|
if (dl > 0) d.remove(i, dl);
|
||||||
(*this)[i] = PIChar(with);
|
d[i] = PIChar(with);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -722,7 +663,7 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
|
|||||||
PIString & PIString::replaceAll(const char what, const char with) {
|
PIString & PIString::replaceAll(const char what, const char with) {
|
||||||
int l = length();
|
int l = length();
|
||||||
for (int i = 0; i < l; ++i) {
|
for (int i = 0; i < l; ++i) {
|
||||||
if (at(i) == what) (*this)[i] = with;
|
if (at(i) == what) d[i] = with;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -734,13 +675,13 @@ PIString & PIString::removeAll(const PIString & str) {
|
|||||||
for (int i = 0; i < length() - l + 1; ++i) {
|
for (int i = 0; i < length() - l + 1; ++i) {
|
||||||
bool match = true;
|
bool match = true;
|
||||||
for (int j = 0; j < l; ++j) {
|
for (int j = 0; j < l; ++j) {
|
||||||
if (at(j + i) != str[j]) {
|
if (d.at(j + i) != str.at(j)) {
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!match) continue;
|
if (!match) continue;
|
||||||
PIDeque<PIChar>::remove(i, l);
|
d.remove(i, l);
|
||||||
i -= l;
|
i -= l;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -748,7 +689,7 @@ PIString & PIString::removeAll(const PIString & str) {
|
|||||||
|
|
||||||
|
|
||||||
PIString & PIString::insert(int index, const PIString & str) {
|
PIString & PIString::insert(int index, const PIString & str) {
|
||||||
PIDeque<PIChar>::insert(index, *((const PIDeque<PIChar>*)&str));
|
d.insert(index, str.d);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,8 +704,8 @@ PIString & PIString::elide(int size, float pos) {
|
|||||||
pos = piClampf(pos, 0.f, 1.f);
|
pos = piClampf(pos, 0.f, 1.f);
|
||||||
int ns = size - 2;
|
int ns = size - 2;
|
||||||
int ls = piRoundf(ns * pos);
|
int ls = piRoundf(ns * pos);
|
||||||
remove(ls, length() - ns);
|
d.remove(ls, length() - ns);
|
||||||
insert(ls, s_dotdot);
|
d.insert(ls, s_dotdot.d);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,6 +791,14 @@ int PIString::findLast(const char c, const int start) const {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PIString::findLast(PIChar c, const int start) const
|
||||||
|
{
|
||||||
|
for (int i = length() - 1; i >= start; --i) {
|
||||||
|
if (at(i) == c) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
@@ -899,14 +848,14 @@ int PIString::findWord(const PIString & word, const int start) const {
|
|||||||
bool ok = true;
|
bool ok = true;
|
||||||
PIChar c;
|
PIChar c;
|
||||||
if (f > 0) {
|
if (f > 0) {
|
||||||
c = (*this)[f - 1];
|
c = at(f - 1);
|
||||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
|
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f + wl < tl) {
|
if (f + wl < tl) {
|
||||||
c = (*this)[f + wl];
|
c = at(f + wl);
|
||||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
|
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
@@ -933,14 +882,14 @@ int PIString::findCWord(const PIString & word, const int start) const {
|
|||||||
bool ok = true;
|
bool ok = true;
|
||||||
PIChar c;
|
PIChar c;
|
||||||
if (f > 0) {
|
if (f > 0) {
|
||||||
c = (*this)[f - 1];
|
c = at(f - 1);
|
||||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
|
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f + wl < tl) {
|
if (f + wl < tl) {
|
||||||
c = (*this)[f + wl];
|
c = at(f + wl);
|
||||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
|
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
@@ -1355,14 +1304,13 @@ PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
|
|||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This function fill internal buffer by sequence
|
//! This function fill internal buffer by sequence of chars.
|
||||||
//! of chars. Minimum length of this buffer is count
|
//! Length of this buffer is count of symbols + end byte '\0'.
|
||||||
//! of symbols. Returned pointer is valid until next
|
//! Returned pointer is valid until next execution of this function.
|
||||||
//! execution of this function
|
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
|
//! Этот метод заполняет внутренный байтовый буфер. Размер
|
||||||
//! этого буфера равен количеству символов строки. Возвращаемый указатель
|
//! этого буфера равен количеству символов строки + завершающий байт '\0'.
|
||||||
//! действителен до следующего вызова этого метода
|
//! Возвращаемый указатель действителен до следующего вызова этого метода.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("0123456789").data(); // 0123456789
|
//! piCout << PIString("0123456789").data(); // 0123456789
|
||||||
//! piCout << PIString("№1").data(); // №1
|
//! piCout << PIString("№1").data(); // №1
|
||||||
@@ -1377,14 +1325,13 @@ const char * PIString::data() const {
|
|||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This function fill internal buffer by sequence
|
//! This function fill internal buffer by sequence of chars.
|
||||||
//! of chars. Minimum length of this buffer is count
|
//! Length of this buffer is count of symbols + end byte '\0'.
|
||||||
//! of symbols. Returned pointer is valid until next
|
//! Returned pointer is valid until next execution of this function.
|
||||||
//! execution of this function
|
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
|
//! Этот метод заполняет внутренный байтовый буфер. Размер
|
||||||
//! этого буфера равен количеству символов строки. Возвращаемый указатель
|
//! этого буфера равен количеству символов строки + завершающий байт '\0'.
|
||||||
//! действителен до следующего вызова этого метода
|
//! Возвращаемый указатель действителен до следующего вызова этого метода.
|
||||||
//! \~\sa \a data(), \a dataUTF8()
|
//! \~\sa \a data(), \a dataUTF8()
|
||||||
const char * PIString::dataConsole() const {
|
const char * PIString::dataConsole() const {
|
||||||
if (isEmpty()) return "";
|
if (isEmpty()) return "";
|
||||||
@@ -1395,14 +1342,13 @@ const char * PIString::dataConsole() const {
|
|||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This function fill internal buffer by sequence
|
//! This function fill internal buffer by sequence of chars.
|
||||||
//! of chars. Minimum length of this buffer is count
|
//! Length of this buffer is count of symbols + end byte '\0'.
|
||||||
//! of symbols. Returned pointer is valid until next
|
//! Returned pointer is valid until next execution of this function.
|
||||||
//! execution of this function
|
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
|
//! Этот метод заполняет внутренный байтовый буфер. Размер
|
||||||
//! этого буфера равен количеству символов строки. Возвращаемый указатель
|
//! этого буфера равен количеству символов строки + завершающий байт '\0'.
|
||||||
//! действителен до следующего вызова этого метода
|
//! Возвращаемый указатель действителен до следующего вызова этого метода.
|
||||||
//! \~\sa \a data(), \a dataConsole()
|
//! \~\sa \a data(), \a dataConsole()
|
||||||
const char * PIString::dataUTF8() const {
|
const char * PIString::dataUTF8() const {
|
||||||
if (isEmpty()) return "";
|
if (isEmpty()) return "";
|
||||||
@@ -1413,14 +1359,13 @@ const char * PIString::dataUTF8() const {
|
|||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This function fill internal buffer by sequence
|
//! This function fill internal buffer by sequence of chars.
|
||||||
//! of chars. Length of this buffer is count
|
//! Length of this buffer is count of symbols + end byte '\0'.
|
||||||
//! of symbols. Returned pointer is valid until next
|
//! Returned pointer is valid until next execution of this function.
|
||||||
//! execution of this function
|
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод заполняет внутренный байтовый буфер. Размер
|
//! Этот метод заполняет внутренный байтовый буфер. Размер
|
||||||
//! этого буфера равен количеству символов строки. Возвращаемый указатель
|
//! этого буфера равен количеству символов строки + завершающий байт '\0'.
|
||||||
//! действителен до следующего вызова этого метода
|
//! Возвращаемый указатель действителен до следующего вызова этого метода.
|
||||||
//! \~\sa \a dataConsole(), \a dataUTF8()
|
//! \~\sa \a dataConsole(), \a dataUTF8()
|
||||||
const char * PIString::dataAscii() const {
|
const char * PIString::dataAscii() const {
|
||||||
if (isEmpty()) return "";
|
if (isEmpty()) return "";
|
||||||
@@ -1438,7 +1383,7 @@ PIString PIString::toUpperCase() const {
|
|||||||
PIString str(*this);
|
PIString str(*this);
|
||||||
int l = str.size();
|
int l = str.size();
|
||||||
for (int i = 0; i < l; ++i) {
|
for (int i = 0; i < l; ++i) {
|
||||||
str[i] = str[i].toUpper();
|
str.d[i] = str.d[i].toUpper();
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -1448,7 +1393,7 @@ PIString PIString::toLowerCase() const {
|
|||||||
PIString str(*this);
|
PIString str(*this);
|
||||||
int l = str.size();
|
int l = str.size();
|
||||||
for (int i = 0; i < l; ++i) {
|
for (int i = 0; i < l; ++i) {
|
||||||
str[i] = str[i].toLower();
|
str.d[i] = str.d[i].toLower();
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -1717,7 +1662,7 @@ PIString versionNormalize(const PIString & v) {
|
|||||||
PICout operator <<(PICout s, const PIString & v) {
|
PICout operator <<(PICout s, const PIString & v) {
|
||||||
s.space();
|
s.space();
|
||||||
s.quote();
|
s.quote();
|
||||||
s.writePIString(v);
|
s.write(v);
|
||||||
s.quote();
|
s.quote();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,56 +27,75 @@
|
|||||||
#define PISTRING_H
|
#define PISTRING_H
|
||||||
|
|
||||||
#include "pibytearray.h"
|
#include "pibytearray.h"
|
||||||
|
#include "piconstchars.h"
|
||||||
|
|
||||||
#define PIStringAscii PIString::fromAscii
|
#define PIStringAscii PIString::fromAscii
|
||||||
|
|
||||||
|
|
||||||
class PIStringList;
|
class PIStringList;
|
||||||
|
|
||||||
class PIP_EXPORT PIString: public PIDeque<PIChar>
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english String class.
|
||||||
|
//! \~russian Класс строки.
|
||||||
|
class PIP_EXPORT PIString
|
||||||
{
|
{
|
||||||
friend PIByteArray & operator >>(PIByteArray & s, PIString & v);
|
friend PIByteArray & operator >>(PIByteArray & s, PIString & v);
|
||||||
|
friend PIByteArray & operator <<(PIByteArray & s, const PIString & v);
|
||||||
public:
|
public:
|
||||||
//! \~english Contructs an empty string
|
typedef PIDeque<PIChar>::iterator iterator;
|
||||||
//! \~russian Создает пустую строку
|
typedef PIDeque<PIChar>::const_iterator const_iterator;
|
||||||
PIString(): PIDeque<PIChar>() {}
|
typedef PIDeque<PIChar>::reverse_iterator reverse_iterator;
|
||||||
|
typedef PIDeque<PIChar>::const_reverse_iterator const_reverse_iterator;
|
||||||
|
typedef PIChar value_type;
|
||||||
|
typedef PIChar* pointer;
|
||||||
|
typedef const PIChar* const_pointer;
|
||||||
|
typedef PIChar& reference;
|
||||||
|
typedef const PIChar& const_reference;
|
||||||
|
typedef size_t size_type;
|
||||||
|
|
||||||
//! \~english Value for elide at left
|
//! \~english Contructs an empty string.
|
||||||
//! \~russian Значение для пропуска слева
|
//! \~russian Создает пустую строку.
|
||||||
|
PIString() {}
|
||||||
|
|
||||||
|
//! \~english Value for elide at left.
|
||||||
|
//! \~russian Значение для пропуска слева.
|
||||||
static const float ElideLeft ;
|
static const float ElideLeft ;
|
||||||
|
|
||||||
//! \~english Value for elide at center
|
//! \~english Value for elide at center.
|
||||||
//! \~russian Значение для пропуска в середине
|
//! \~russian Значение для пропуска в середине.
|
||||||
static const float ElideCenter;
|
static const float ElideCenter;
|
||||||
|
|
||||||
//! \~english Value for elide at right
|
//! \~english Value for elide at right.
|
||||||
//! \~russian Значение для пропуска справа
|
//! \~russian Значение для пропуска справа.
|
||||||
static const float ElideRight ;
|
static const float ElideRight ;
|
||||||
|
|
||||||
PIString & operator +=(const PIChar & c) {PIDeque<PIChar>::push_back(c); return *this;}
|
PIString & operator +=(const PIChar & c) {d.push_back(c); return *this;}
|
||||||
PIString & operator +=(const char c) {PIDeque<PIChar>::push_back(PIChar(c)); return *this;}
|
PIString & operator +=(const char c) {d.push_back(PIChar(c)); return *this;}
|
||||||
PIString & operator +=(const char * str);
|
PIString & operator +=(const char * str);
|
||||||
PIString & operator +=(const wchar_t * str);
|
PIString & operator +=(const wchar_t * str);
|
||||||
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
||||||
PIString & operator +=(const PIString & str);
|
PIString & operator +=(const PIString & str);
|
||||||
|
PIString & operator +=(const PIConstChars & str);
|
||||||
|
|
||||||
//! \~english Contructs a copy of string
|
//! \~english Contructs a copy of string.
|
||||||
//! \~russian Создает копию строки
|
//! \~russian Создает копию строки.
|
||||||
PIString(const PIString & o): PIDeque<PIChar>(o) {}
|
PIString(const PIString & o) {d = o.d;}
|
||||||
|
|
||||||
PIString(PIString && o): PIDeque<PIChar>(std::move(o)) {}
|
//! \~english Move constructor.
|
||||||
|
//! \~russian Перемещающий конструктор.
|
||||||
|
PIString(PIString && o): d(std::move(o.d)) {piSwap(data_, o.data_);}
|
||||||
|
|
||||||
|
//! \~english Contructs string with single character "c".
|
||||||
|
//! \~russian Создает строку из одного символа "c".
|
||||||
|
PIString(const PIChar c) {*this += c;}
|
||||||
|
|
||||||
//! \~english Contructs string with single symbol "c"
|
//! \~english Contructs string with single character "c".
|
||||||
//! \~russian Создает строку из одного символа "c"
|
//! \~russian Создает строку из одного символа "c".
|
||||||
PIString(const PIChar c): PIDeque<PIChar>() {*this += c;}
|
PIString(const char c) {*this += PIChar(c);}
|
||||||
|
|
||||||
//! \~english Contructs string with single symbol "c"
|
//! \~english Contructs string from C-string "str" (system codepage).
|
||||||
//! \~russian Создает строку из одного символа "c"
|
//! \~russian Создает строку из C-строки "str" (кодировка системы).
|
||||||
PIString(const char c): PIDeque<PIChar>() {*this += PIChar(c);}
|
|
||||||
|
|
||||||
//! \~english Contructs string from C-string "str" (system codepage)
|
|
||||||
//! \~russian Создает строку из C-строки "str" (кодировка системы)
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! "str" should be null-terminated\n
|
//! "str" should be null-terminated\n
|
||||||
@@ -85,10 +104,10 @@ public:
|
|||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("string");
|
//! PIString s("string");
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const char * str): PIDeque<PIChar>() {*this += str;}
|
PIString(const char * str) {*this += str;}
|
||||||
|
|
||||||
//! \~english Contructs string from \c wchar_t C-string "str"
|
//! \~english Contructs string from \c wchar_t C-string "str".
|
||||||
//! \~russian Создает строку из \c wchar_t C-строки "str"
|
//! \~russian Создает строку из \c wchar_t C-строки "str".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! "str" should be null-terminated
|
//! "str" should be null-terminated
|
||||||
@@ -97,123 +116,134 @@ public:
|
|||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(L"string");
|
//! PIString s(L"string");
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const wchar_t * str): PIDeque<PIChar>() {*this += str;}
|
PIString(const wchar_t * str) {*this += str;}
|
||||||
|
|
||||||
//! \~english Contructs string from byte array "ba" (as UTF-8)
|
//! \~english Contructs string from byte array "ba" (as UTF-8).
|
||||||
//! \~russian Создает строку из байтового массива "ba" (как UTF-8)
|
//! \~russian Создает строку из байтового массива "ba" (как UTF-8).
|
||||||
PIString(const PIByteArray & ba): PIDeque<PIChar>() {*this += ba;}
|
PIString(const PIByteArray & ba) {*this += ba;}
|
||||||
|
|
||||||
//! \~english Contructs string from "len" characters of buffer "str"
|
//! \~english Contructs string from "len" characters of buffer "str".
|
||||||
//! \~russian Создает строку из "len" символов массива "str"
|
//! \~russian Создает строку из "len" символов массива "str".
|
||||||
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {}
|
PIString(const PIChar * str, const int len): d(str, size_t(len)) {}
|
||||||
|
|
||||||
//! \~english Contructs string from "len" characters of buffer "str" (system codepage)
|
//! \~english Contructs string from "len" characters of buffer "str" (system codepage).
|
||||||
//! \~russian Создает строку из "len" символов массива "str" (кодировка системы)
|
//! \~russian Создает строку из "len" символов массива "str" (кодировка системы).
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("string", 3); // s = "str"
|
//! PIString s("string", 3); // s = "str"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const char * str, const int len): PIDeque<PIChar>() {appendFromChars(str, len);}
|
PIString(const char * str, const int len) {appendFromChars(str, len);}
|
||||||
|
|
||||||
//! \~english Contructs string as sequence of characters "c" of buffer with length "len"
|
//! \~english Contructs string as sequence of characters "c" of buffer with length "len".
|
||||||
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
//! \~russian Создает строку как последовательность длиной "len" символа "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(5, 'p'); // s = "ppppp"
|
//! PIString s(5, 'p'); // s = "ppppp"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(PIChar(c));}
|
PIString(const int len, const char c) {for (int i = 0; i < len; ++i) d.push_back(PIChar(c));}
|
||||||
|
|
||||||
//! \~english Contructs string as sequence of symbols "c" of buffer with length "len"
|
//! \~english Contructs string as sequence of characters "c" of buffer with length "len".
|
||||||
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
//! \~russian Создает строку как последовательность длиной "len" символа "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(5, "№"); // s = "№№№№№"
|
//! PIString s(5, "№"); // s = "№№№№№"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(c);}
|
PIString(const int len, const PIChar c) {for (int i = 0; i < len; ++i) d.push_back(c);}
|
||||||
|
|
||||||
|
PIString(const PIConstChars & c) {*this += c;}
|
||||||
|
|
||||||
~PIString();
|
~PIString();
|
||||||
|
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
PIString & operator =(const PIString & o) {if (this == &o) return *this; d = o.d; return *this;}
|
||||||
|
|
||||||
//! \~english Assign operator
|
//! \~english Assign move operator.
|
||||||
//! \~russian Оператор присваивания
|
//! \~russian Оператор перемещающего присваивания.
|
||||||
PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;}
|
PIString & operator =(PIString && o) {d.swap(o.d); piSwap(data_, o.data_); return *this;}
|
||||||
|
|
||||||
PIString & operator =(PIString && o) {swap(o); return *this;}
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
PIString & operator =(const PIConstChars & o) {d.clear(); *this += o; return *this;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Assign operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор присваивания.
|
||||||
|
PIString & operator =(const char * o) {d.clear(); *this += o; return *this;}
|
||||||
|
|
||||||
|
//! \~english Compare operator.
|
||||||
|
//! \~russian Оператор сравнения.
|
||||||
bool operator ==(const PIString & str) const;
|
bool operator ==(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator ==(const PIChar c) const {if (size_s() != 1) return false; return at(0) == c;}
|
bool operator ==(const PIChar c) const {if (d.size() != 1) return false; return d.at(0) == c;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator ==(const char * str) const {return *this == PIString(str);}
|
bool operator ==(const char * str) const {return *this == PIString(str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator !=(const PIString & str) const;
|
bool operator !=(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator !=(const PIChar c) const {if (size_s() != 1) return true; return at(0) != c;}
|
bool operator !=(const PIChar c) const {if (d.size() != 1) return true; return d.at(0) != c;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator !=(const char * str) const {return *this != PIString(str);}
|
bool operator !=(const char * str) const {return *this != PIString(str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <(const PIString & str) const;
|
bool operator <(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <(const PIChar c) const {if (size_s() != 1) return size_s() < 1; return at(0) < c;}
|
bool operator <(const PIChar c) const {if (d.size() != 1) return d.size() < 1; return d.at(0) < c;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <(const char * str) const {return *this < PIString(str);}
|
bool operator <(const char * str) const {return *this < PIString(str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >(const PIString & str) const;
|
bool operator >(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >(const PIChar c) const {if (size_s() != 1) return size_s() > 1; return at(0) > c;}
|
bool operator >(const PIChar c) const {if (d.size() != 1) return d.size() > 1; return d.at(0) > c;}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >(const char * str) const {return *this > PIString(str);}
|
bool operator >(const char * str) const {return *this > PIString(str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <=(const PIString & str) const {return !(*this > str);}
|
bool operator <=(const PIString & str) const {return !(*this > str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <=(const PIChar c) const {return !(*this > c);}
|
bool operator <=(const PIChar c) const {return !(*this > c);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator <=(const char * str) const {return *this <= PIString(str);}
|
bool operator <=(const char * str) const {return *this <= PIString(str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >=(const PIString & str) const {return !(*this < str);}
|
bool operator >=(const PIString & str) const {return !(*this < str);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >=(const PIChar c) const {return !(*this < c);}
|
bool operator >=(const PIChar c) const {return !(*this < c);}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения.
|
||||||
bool operator >=(const char * str) const {return *this >= PIString(str);}
|
bool operator >=(const char * str) const {return *this >= PIString(str);}
|
||||||
|
|
||||||
//! \~english Append string "str" at the end of string
|
//! \~english Append string "str" at the end of string.
|
||||||
//! \~russian Добавляет в конец строку "str"
|
//! \~russian Добавляет в конец строку "str".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("this"), s1(" is"), s2(" string");
|
//! PIString s("this"), s1(" is"), s2(" string");
|
||||||
@@ -221,26 +251,26 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const PIString & str) {*this += str; return *this;}
|
PIString & operator <<(const PIString & str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Append symbol "c" at the end of string
|
//! \~english Append character "c" at the end of string.
|
||||||
//! \~russian Добавляет в конец символ "c"
|
//! \~russian Добавляет в конец символ "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("stri");
|
//! PIString s("stri");
|
||||||
//! s << PIChar('n') << PIChar('g'); // s = "string"
|
//! s << PIChar('n') << PIChar('g'); // s = "string"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const PIChar c) {*this += c; return *this;}
|
PIString & operator <<(const PIChar c) {d.append(c); return *this;}
|
||||||
|
|
||||||
//! \~english Append symbol `c` at the end of string
|
//! \~english Append character `c` at the end of string.
|
||||||
//! \~russian Добавляет в конец символ `c`
|
//! \~russian Добавляет в конец символ `c`.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("stri");
|
//! PIString s("stri");
|
||||||
//! s << 'n' << 'g'; // s = "string"
|
//! s << 'n' << 'g'; // s = "string"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const char c) {*this += PIChar(c); return *this;}
|
PIString & operator <<(const char c) {d.append(PIChar(c)); return *this;}
|
||||||
|
|
||||||
//! \~english Append С-string "str" at the end of string
|
//! \~english Append С-string "str" at the end of string.
|
||||||
//! \~russian Добавляет в конец C-строку "str"
|
//! \~russian Добавляет в конец C-строку "str".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("this");
|
//! PIString s("this");
|
||||||
@@ -248,8 +278,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const char * str) {*this += str; return *this;}
|
PIString & operator <<(const char * str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Append \c wchar_t C-string "str" at the end of string
|
//! \~english Append \c wchar_t C-string "str" at the end of string.
|
||||||
//! \~russian Добавляет в конец \c wchar_t C-строку "str"
|
//! \~russian Добавляет в конец \c wchar_t C-строку "str".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -257,8 +287,10 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Append string representation of "num" at the end of string
|
PIString & operator <<(const PIConstChars & str) {*this += str; return *this;}
|
||||||
//! \~russian Добавляет в конец строковое представление "num"
|
|
||||||
|
//! \~english Append string representation of "num" at the end of string.
|
||||||
|
//! \~russian Добавляет в конец строковое представление "num".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("ten - ");
|
//! PIString s("ten - ");
|
||||||
@@ -267,8 +299,8 @@ public:
|
|||||||
PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
|
|
||||||
//! \~english Append string representation of "num" at the end of string
|
//! \~english Append string representation of "num" at the end of string.
|
||||||
//! \~russian Добавляет в конец строковое представление "num"
|
//! \~russian Добавляет в конец строковое представление "num".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("ten - ");
|
//! PIString s("ten - ");
|
||||||
@@ -280,8 +312,8 @@ public:
|
|||||||
PIString & operator <<(const llong & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const llong & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
PIString & operator <<(const ullong & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const ullong & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
|
|
||||||
//! \~english Append string representation of "num" at the end of string
|
//! \~english Append string representation of "num" at the end of string.
|
||||||
//! \~russian Добавляет в конец строковое представление "num"
|
//! \~russian Добавляет в конец строковое представление "num".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("1/10 - ");
|
//! PIString s("1/10 - ");
|
||||||
@@ -289,8 +321,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
|
|
||||||
//! \~english Append string representation of "num" at the end of string
|
//! \~english Append string representation of "num" at the end of string.
|
||||||
//! \~russian Добавляет в конец строковое представление "num"
|
//! \~russian Добавляет в конец строковое представление "num".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("1/10 - ");
|
//! PIString s("1/10 - ");
|
||||||
@@ -298,82 +330,186 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
|
|
||||||
|
//! \~english Iterator to the first element.
|
||||||
|
//! \~russian Итератор на первый элемент.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a end(), \a rbegin(), \a rend()
|
||||||
|
inline iterator begin() {return d.begin();}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the begin of string
|
//! \~english Iterator to the element following the last element.
|
||||||
//! \~russian Вставляет "str" в начало строки
|
//! \~russian Итератор на элемент, следующий за последним элементом.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a begin(), \a rbegin(), \a rend()
|
||||||
|
inline iterator end() {return d.end();}
|
||||||
|
|
||||||
|
inline const_iterator begin() const {return d.begin();}
|
||||||
|
inline const_iterator end() const {return d.end();}
|
||||||
|
|
||||||
|
//! \~english Returns a reverse iterator to the first element of the reversed array.
|
||||||
|
//! \~russian Обратный итератор на первый элемент.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english It corresponds to the last element of the non-reversed array.
|
||||||
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
|
//! Указывает на последний элемент.
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a rend(), \a begin(), \a end()
|
||||||
|
inline reverse_iterator rbegin() {return d.rbegin();}
|
||||||
|
|
||||||
|
//! \~english Returns a reverse iterator to the element.
|
||||||
|
//! following the last element of the reversed array.
|
||||||
|
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english It corresponds to the element preceding the first element of the non-reversed array.
|
||||||
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
|
//! Указывает на элемент, предшествующий первому элементу.
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a rbegin(), \a begin(), \a end()
|
||||||
|
inline reverse_iterator rend() {return d.rend();}
|
||||||
|
|
||||||
|
inline const_reverse_iterator rbegin() const {return d.rbegin();}
|
||||||
|
inline const_reverse_iterator rend() const {return d.rend();}
|
||||||
|
|
||||||
|
//! \~english Full access to character by `index`.
|
||||||
|
//! \~russian Полный доступ к символу по индексу `index`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Сharacter index starts from `0`.
|
||||||
|
//! Сharacter index must be in range from `0` to `size()-1`.
|
||||||
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Индекс элемента считается от `0`.
|
||||||
|
//! Индекс символа должен лежать в пределах от `0` до `size()-1`.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
inline PIChar & operator [](size_t index) {return d[index];}
|
||||||
|
inline PIChar operator [](size_t index) const {return d[index];}
|
||||||
|
|
||||||
|
//! \~english Read only access to character by `index`.
|
||||||
|
//! \~russian Доступ исключительно на чтение к символу по индексу `index`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Сharacter index starts from `0`.
|
||||||
|
//! Сharacter index must be in range from `0` to `size()-1`.
|
||||||
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Индекс символа считается от `0`.
|
||||||
|
//! Индекс символа должен лежать в пределах от `0` до `size()-1`.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
inline const PIChar at(size_t index) const {return d.at(index);}
|
||||||
|
|
||||||
|
//! \~english Returns the last character of the string.
|
||||||
|
//! \~russian Возвращает последний символ строки.
|
||||||
|
inline PIChar & back() {return d.back();}
|
||||||
|
inline PIChar back() const {return d.back();}
|
||||||
|
|
||||||
|
inline PIChar & front() {return d.front();}
|
||||||
|
inline PIChar front() const {return d.front();}
|
||||||
|
|
||||||
|
//! \~english Sets size of the string, new characters are copied from `c`.
|
||||||
|
//! \~russian Устанавливает размер строки, новые символы копируются из `c`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If `new_size` is greater than the current \a size(),
|
||||||
|
//! characters are added to the end; the new characters are initialized from `c`.
|
||||||
|
//! If `new_size` is less than the current \a size(), characters are removed from the end.
|
||||||
|
//! \~russian Если `new_size` больше чем текущий размер строки \a size(),
|
||||||
|
//! новые символы добавляются в конец строки и создаются из `с`.
|
||||||
|
//! Если `new_size` меньше чем текущий размер строки \a size(),
|
||||||
|
//! лишние символы удаляются с конца строки.
|
||||||
|
//! \~\sa \a size(), \a clear()
|
||||||
|
inline PIString & resize(size_t new_size, PIChar c = PIChar()) {d.resize(new_size, c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Delete one character at the end of string.
|
||||||
|
//! \~russian Удаляет один символ с конца строки.
|
||||||
|
inline PIString & pop_back() {d.pop_back(); return *this;}
|
||||||
|
|
||||||
|
//! \~english Delete one character at the benig of string.
|
||||||
|
//! \~russian Удаляет один символ с начала строки.
|
||||||
|
inline PIString & pop_front() {d.pop_front(); return *this;}
|
||||||
|
|
||||||
|
//! \~english Removes `count` characters from the string, starting at `index` position.
|
||||||
|
//! \~russian Удаляет символы из строки, начиная с позиции `index` в количестве `count`.
|
||||||
|
inline PIString & remove(size_t index, size_t count = 1) {d.remove(index, count); return *this;}
|
||||||
|
|
||||||
|
//! \~english Assigns character 'c' to all string characters.
|
||||||
|
//! \~russian Заполняет всю строку символами `c`.
|
||||||
|
inline PIString & fill(PIChar c = PIChar()) {d.fill(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the begin of string.
|
||||||
|
//! \~russian Вставляет "str" в начало строки.
|
||||||
PIString & prepend(const char * str) {insert(0, str); return *this;}
|
PIString & prepend(const char * str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the begin of string
|
//! \~english Insert string "str" at the begin of string.
|
||||||
//! \~russian Вставляет "str" в начало строки
|
//! \~russian Вставляет "str" в начало строки.
|
||||||
PIString & prepend(const PIString & str) {insert(0, str); return *this;}
|
PIString & prepend(const PIString & str) {d.prepend(str.d); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the begin of string
|
//! \~english Insert character `c` at the begin of string.
|
||||||
//! \~russian Вставляет символ `c` в начало строки
|
//! \~russian Вставляет символ `c` в начало строки.
|
||||||
PIString & prepend(const PIChar c) {PIDeque<PIChar>::prepend(c); return *this;}
|
PIString & prepend(const PIChar c) {d.prepend(c); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the begin of string
|
//! \~english Insert character `c` at the begin of string.
|
||||||
//! \~russian Вставляет символ `c` в начало строки
|
//! \~russian Вставляет символ `c` в начало строки.
|
||||||
PIString & prepend(const char c) {PIDeque<PIChar>::prepend(PIChar(c)); return *this;}
|
PIString & prepend(const char c) {d.prepend(PIChar(c)); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the begin of string
|
//! \~english Insert string "str" at the begin of string.
|
||||||
//! \~russian Вставляет "str" в начало строки
|
//! \~russian Вставляет "str" в начало строки.
|
||||||
PIString & push_front(const char * str) {insert(0, str); return *this;}
|
PIString & push_front(const char * str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the begin of string
|
//! \~english Insert string "str" at the begin of string.
|
||||||
//! \~russian Вставляет "str" в начало строки
|
//! \~russian Вставляет "str" в начало строки.
|
||||||
PIString & push_front(const PIString & str) {insert(0, str); return *this;}
|
PIString & push_front(const PIString & str) {d.push_front(str.d); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the begin of string
|
//! \~english Insert character `c` at the begin of string.
|
||||||
//! \~russian Вставляет символ `c` в начало строки
|
//! \~russian Вставляет символ `c` в начало строки.
|
||||||
PIString & push_front(const PIChar c) {PIDeque<PIChar>::push_front(c); return *this;}
|
PIString & push_front(const PIChar c) {d.push_front(c); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the begin of string
|
//! \~english Insert character `c` at the begin of string.
|
||||||
//! \~russian Вставляет символ `c` в начало строки
|
//! \~russian Вставляет символ `c` в начало строки.
|
||||||
PIString & push_front(const char c) {PIDeque<PIChar>::push_front(PIChar(c)); return *this;}
|
PIString & push_front(const char c) {d.push_front(PIChar(c)); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the end of string
|
//! \~english Insert string "str" at the end of string.
|
||||||
//! \~russian Вставляет "str" в конец строки
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & append(const char * str) {*this += str; return *this;}
|
PIString & append(const char * str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the end of string
|
//! \~english Insert string "str" at the end of string.
|
||||||
//! \~russian Вставляет "str" в конец строки
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & append(const PIString & str) {*this += str; return *this;}
|
PIString & append(const PIString & str) {d.append(str.d); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the end of string
|
PIString & append(const PIConstChars & str) {*this += str; return *this;}
|
||||||
//! \~russian Вставляет символ `c` в конец строки
|
|
||||||
PIString & append(const PIChar c) {PIDeque<PIChar>::append(c); return *this;}
|
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the end of string
|
//! \~english Insert character `c` at the end of string.
|
||||||
//! \~russian Вставляет символ `c` в конец строки
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
PIString & append(const char c) {PIDeque<PIChar>::append(PIChar(c)); return *this;}
|
PIString & append(const PIChar c) {d.append(c); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the end of string
|
//! \~english Insert character `c` at the end of string.
|
||||||
//! \~russian Вставляет "str" в конец строки
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
|
PIString & append(const char c) {d.append(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the end of string.
|
||||||
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & push_back(const char * str) {*this += str; return *this;}
|
PIString & push_back(const char * str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the end of string
|
//! \~english Insert string "str" at the end of string.
|
||||||
//! \~russian Вставляет "str" в конец строки
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & push_back(const PIString & str) {*this += str; return *this;}
|
PIString & push_back(const PIString & str) {d.push_back(str.d); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the end of string
|
PIString & push_back(const PIConstChars & str) {*this += str; return *this;}
|
||||||
//! \~russian Вставляет символ `c` в конец строки
|
|
||||||
PIString & push_back(const PIChar c) {PIDeque<PIChar>::push_back(c); return *this;}
|
|
||||||
|
|
||||||
//! \~english Insert symbol `c` at the end of string
|
//! \~english Insert character `c` at the end of string.
|
||||||
//! \~russian Вставляет символ `c` в конец строки
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
PIString & push_back(const char c) {PIDeque<PIChar>::push_back(PIChar(c)); return *this;}
|
PIString & push_back(const PIChar c) {d.push_back(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert character `c` at the end of string.
|
||||||
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
|
PIString & push_back(const char c) {d.push_back(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns part of string from symbol at index "start" and maximum length "len"
|
//! \~english Returns part of string from character at index "start" and maximum length "len".
|
||||||
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len"
|
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len".
|
||||||
PIString mid(const int start, const int len = -1) const;
|
PIString mid(const int start, const int len = -1) const;
|
||||||
|
|
||||||
//! \~english Synonym of \a mid()
|
//! \~english Synonym of \a mid().
|
||||||
//! \~russian Аналог \a mid()
|
//! \~russian Аналог \a mid().
|
||||||
PIString subString(const int start, const int len = -1) const {return mid(start, len);}
|
PIString subString(const int start, const int len = -1) const {return mid(start, len);}
|
||||||
|
|
||||||
//! \~english Returns part of string from start and maximum length "len"
|
//! \~english Returns part of string from start and maximum length "len".
|
||||||
//! \~russian Возвращает подстроку от начала и максимальной длиной "len"
|
//! \~russian Возвращает подстроку от начала и максимальной длиной "len".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -385,8 +521,8 @@ public:
|
|||||||
//! \~\sa \a mid(), \a right()
|
//! \~\sa \a mid(), \a right()
|
||||||
PIString left(const int len) const {return len <= 0 ? PIString() : mid(0, len);}
|
PIString left(const int len) const {return len <= 0 ? PIString() : mid(0, len);}
|
||||||
|
|
||||||
//! \~english Returns part of string at end and maximum length "len"
|
//! \~english Returns part of string at end and maximum length "len".
|
||||||
//! \~russian Возвращает подстроку максимальной длиной "len" и до конца
|
//! \~russian Возвращает подстроку максимальной длиной "len" и до конца.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -398,12 +534,12 @@ public:
|
|||||||
//! \~\sa \a mid(), \a left()
|
//! \~\sa \a mid(), \a left()
|
||||||
PIString right(const int len) const {return len <= 0 ? PIString() : mid(size() - len, len);}
|
PIString right(const int len) const {return len <= 0 ? PIString() : mid(size() - len, len);}
|
||||||
|
|
||||||
//! \~english Remove part of string from symbol as index "start" and maximum length "len" and return this string
|
//! \~english Remove part of string from character as index "start" and maximum length "len" and return this string.
|
||||||
//! \~russian Удаляет часть строки от символа "start" и максимальной длины "len", возвращает эту строку
|
//! \~russian Удаляет часть строки от символа "start" и максимальной длины "len", возвращает эту строку.
|
||||||
PIString & cutMid(const int start, const int len);
|
PIString & cutMid(const int start, const int len);
|
||||||
|
|
||||||
//! \~english Remove part of string from start and maximum length "len" and return this string
|
//! \~english Remove part of string from start and maximum length "len" and return this string.
|
||||||
//! \~russian Удаляет часть строки от начала и максимальной длины "len", возвращает эту строку
|
//! \~russian Удаляет часть строки от начала и максимальной длины "len", возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -417,8 +553,8 @@ public:
|
|||||||
//! \~\sa \a cutMid(), \a cutRight()
|
//! \~\sa \a cutMid(), \a cutRight()
|
||||||
PIString & cutLeft(const int len) {return len <= 0 ? *this : cutMid(0, len);}
|
PIString & cutLeft(const int len) {return len <= 0 ? *this : cutMid(0, len);}
|
||||||
|
|
||||||
//! \~english Remove part of string at end and maximum length "len" and return this string
|
//! \~english Remove part of string at end and maximum length "len" and return this string.
|
||||||
//! \~russian Удаляет часть строки максимальной длины "len" от конца, возвращает эту строку
|
//! \~russian Удаляет часть строки максимальной длины "len" от конца, возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -432,12 +568,12 @@ public:
|
|||||||
//! \~\sa \a cutMid(), \a cutLeft()
|
//! \~\sa \a cutMid(), \a cutLeft()
|
||||||
PIString & cutRight(const int len) {return len <= 0 ? *this : cutMid(size() - len, len);}
|
PIString & cutRight(const int len) {return len <= 0 ? *this : cutMid(size() - len, len);}
|
||||||
|
|
||||||
//! \~english Remove spaces at the start and at the end of string and return this string
|
//! \~english Remove spaces at the start and at the end of string and return this string.
|
||||||
//! \~russian Удаляет пробельные символы с начала и конца строки и возвращает эту строку
|
//! \~russian Удаляет пробельные символы с начала и конца строки и возвращает эту строку.
|
||||||
PIString & trim();
|
PIString & trim();
|
||||||
|
|
||||||
//! \~english Returns copy of this string without spaces at the start and at the end
|
//! \~english Returns copy of this string without spaces at the start and at the end.
|
||||||
//! \~russian Возвращает копию этой строки без пробельных символов с начала и конца
|
//! \~russian Возвращает копию этой строки без пробельных символов с начала и конца.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(" \t string \n");
|
//! PIString s(" \t string \n");
|
||||||
@@ -447,12 +583,12 @@ public:
|
|||||||
//! \~\sa \a trim()
|
//! \~\sa \a trim()
|
||||||
PIString trimmed() const;
|
PIString trimmed() const;
|
||||||
|
|
||||||
//! \~english Replace part of string from index "from" and maximum length "len" with string "with" and return this string
|
//! \~english Replace part of string from index "from" and maximum length "len" with string "with" and return this string.
|
||||||
//! \~russian Заменяет часть строки от символа "from" и максимальной длины "len" строкой "with", возвращает эту строку
|
//! \~russian Заменяет часть строки от символа "from" и максимальной длины "len" строкой "with", возвращает эту строку.
|
||||||
PIString & replace(const int from, const int count, const PIString & with);
|
PIString & replace(const int from, const int count, const PIString & with);
|
||||||
|
|
||||||
//! \~english Replace part copy of this string from index "from" and maximum length "len" with string "with"
|
//! \~english Replace part copy of this string from index "from" and maximum length "len" with string "with".
|
||||||
//! \~russian Заменяет часть копии этой строки от символа "from" и максимальной длины "len" строкой "with"
|
//! \~russian Заменяет часть копии этой строки от символа "from" и максимальной длины "len" строкой "with".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -462,15 +598,15 @@ public:
|
|||||||
//! \~\sa \a replace(), \a replaceAll()
|
//! \~\sa \a replace(), \a replaceAll()
|
||||||
PIString replaced(const int from, const int count, const PIString & with) const {PIString str(*this); str.replace(from, count, with); return str;}
|
PIString replaced(const int from, const int count, const PIString & with) const {PIString str(*this); str.replace(from, count, with); return str;}
|
||||||
|
|
||||||
//! \~english Replace first founded substring "what" with string "with" and return this string
|
//! \~english Replace first founded substring "what" with string "with" and return this string.
|
||||||
//! \~russian Заменяет первую найденную подстроку "what" строкой "with", возвращает эту строку
|
//! \~russian Заменяет первую найденную подстроку "what" строкой "with", возвращает эту строку.
|
||||||
PIString & replace(const PIString & what, const PIString & with, bool * ok = 0);
|
PIString & replace(const PIString & what, const PIString & with, bool * ok = 0);
|
||||||
|
|
||||||
//! \~english Replace in string copy first founded substring "what" with string "with"
|
//! \~english Replace in string copy first founded substring "what" with string "with".
|
||||||
//! \~russian Заменяет в копии строки первую найденную подстроку "what" строкой "with"
|
//! \~russian Заменяет в копии строки первую найденную подстроку "what" строкой "with".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "ok" is not null, it set to "true" if something was replaced
|
//! \~english If "ok" is not null, it set to "true" if something was replaced.
|
||||||
//! \~russian Если "ok" не null, то устанавливает в "true" если замена произведена
|
//! \~russian Если "ok" не null, то устанавливает в "true" если замена произведена.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("pip string");
|
//! PIString s("pip string");
|
||||||
//! bool ok;
|
//! bool ok;
|
||||||
@@ -480,43 +616,43 @@ public:
|
|||||||
//! \~\sa \a replaced(), \a replaceAll()
|
//! \~\sa \a replaced(), \a replaceAll()
|
||||||
PIString replaced(const PIString & what, const PIString & with, bool * ok = 0) const {PIString str(*this); str.replace(what, with, ok); return str;}
|
PIString replaced(const PIString & what, const PIString & with, bool * ok = 0) const {PIString str(*this); str.replace(what, with, ok); return str;}
|
||||||
|
|
||||||
//! \~english Replace all founded substrings "what" with strings "with" and return this string
|
//! \~english Replace all founded substrings "what" with strings "with" and return this string.
|
||||||
//! \~russian Заменяет все найденные подстроки "what" строками "with", возвращает эту строку
|
//! \~russian Заменяет все найденные подстроки "what" строками "with", возвращает эту строку.
|
||||||
PIString & replaceAll(const PIString & what, const PIString & with);
|
PIString & replaceAll(const PIString & what, const PIString & with);
|
||||||
|
|
||||||
//! \~english Replace all founded substrings "what" with symbols "with" and return this string
|
//! \~english Replace all founded substrings "what" with characters "with" and return this string.
|
||||||
//! \~russian Заменяет все найденные подстроки "what" символами "with", возвращает эту строку
|
//! \~russian Заменяет все найденные подстроки "what" символами "with", возвращает эту строку.
|
||||||
PIString & replaceAll(const PIString & what, const char with);
|
PIString & replaceAll(const PIString & what, const char with);
|
||||||
|
|
||||||
//! \~english Replace all founded symbols "what" with symbols "with" and return this string
|
//! \~english Replace all founded characters "what" with characters "with" and return this string.
|
||||||
//! \~russian Заменяет все найденные символы "what" символами "with", возвращает эту строку
|
//! \~russian Заменяет все найденные символы "what" символами "with", возвращает эту строку.
|
||||||
PIString & replaceAll(const char what, const char with);
|
PIString & replaceAll(const char what, const char with);
|
||||||
|
|
||||||
//! \~english Replace all founded substrings "what" with strings "with" in string copy
|
//! \~english Replace all founded substrings "what" with strings "with" in string copy.
|
||||||
//! \~russian Заменяет в копии строки все найденные подстроки "what" строками "with"
|
//! \~russian Заменяет в копии строки все найденные подстроки "what" строками "with".
|
||||||
//! \~\sa \a replaceAll()
|
//! \~\sa \a replaceAll()
|
||||||
PIString replacedAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
PIString replacedAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||||
|
|
||||||
//! \~english Replace all founded substrings "what" with symbols "with" in string copy
|
//! \~english Replace all founded substrings "what" with characters "with" in string copy.
|
||||||
//! \~russian Заменяет в копии строки все найденные подстроки "what" символами "with"
|
//! \~russian Заменяет в копии строки все найденные подстроки "what" символами "with".
|
||||||
//! \~\sa \a replaceAll()
|
//! \~\sa \a replaceAll()
|
||||||
PIString replacedAll(const PIString & what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
PIString replacedAll(const PIString & what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||||
|
|
||||||
//! \~english Replace all founded symbols "what" with symbols "with" in string copy
|
//! \~english Replace all founded characters "what" with characters "with" in string copy.
|
||||||
//! \~russian Заменяет в копии строки все найденные символы "what" символами "with"
|
//! \~russian Заменяет в копии строки все найденные символы "what" символами "with".
|
||||||
//! \~\sa \a replaceAll()
|
//! \~\sa \a replaceAll()
|
||||||
PIString replacedAll(const char what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
PIString replacedAll(const char what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||||
|
|
||||||
//! \~english Remove all founded substrings "what" and return this string
|
//! \~english Remove all founded substrings "what" and return this string.
|
||||||
//! \~russian Удаляет все найденные подстроки "what", возвращает эту строку
|
//! \~russian Удаляет все найденные подстроки "what", возвращает эту строку.
|
||||||
PIString & removeAll(const PIString & str);
|
PIString & removeAll(const PIString & str);
|
||||||
|
|
||||||
//! \~english Remove all founded symbols "what" and return this string
|
//! \~english Remove all founded characters "what" and return this string.
|
||||||
//! \~russian Удаляет все найденные символы "what", возвращает эту строку
|
//! \~russian Удаляет все найденные символы "what", возвращает эту строку.
|
||||||
PIString & removeAll(char c) {PIDeque<PIChar>::removeAll(PIChar(c)); return *this;}
|
PIString & removeAll(char c) {d.removeAll(PIChar(c)); return *this;}
|
||||||
|
|
||||||
//! \~english Repeat content of string "times" times and return this string
|
//! \~english Repeat content of string "times" times and return this string.
|
||||||
//! \~russian Повторяет содержимое строки "times" раз и возвращает эту строку
|
//! \~russian Повторяет содержимое строки "times" раз и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(" :-) ");
|
//! PIString s(" :-) ");
|
||||||
@@ -526,8 +662,8 @@ public:
|
|||||||
//! \~\sa \a repeated()
|
//! \~\sa \a repeated()
|
||||||
PIString & repeat(int times) {PIString ss(*this); times--; piForTimes (times) *this += ss; return *this;}
|
PIString & repeat(int times) {PIString ss(*this); times--; piForTimes (times) *this += ss; return *this;}
|
||||||
|
|
||||||
//! \~english Returns repeated "times" times string
|
//! \~english Returns repeated "times" times string.
|
||||||
//! \~russian Возвращает повторённую "times" раз строку
|
//! \~russian Возвращает повторённую "times" раз строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(" :-) ");
|
//! PIString s(" :-) ");
|
||||||
@@ -537,18 +673,18 @@ public:
|
|||||||
//! \~\sa \a repeat()
|
//! \~\sa \a repeat()
|
||||||
PIString repeated(int times) const {PIString ss(*this); return ss.repeat(times);}
|
PIString repeated(int times) const {PIString ss(*this); return ss.repeat(times);}
|
||||||
|
|
||||||
//! \~english Insert symbol "c" after index "index" and return this string
|
//! \~english Insert character "c" after index "index" and return this string.
|
||||||
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку
|
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("pp");
|
//! PIString s("pp");
|
||||||
//! s.insert(1, "i");
|
//! s.insert(1, "i");
|
||||||
//! piCout << s; // s = "pip"
|
//! piCout << s; // s = "pip"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & insert(const int index, const PIChar c) {PIDeque<PIChar>::insert(index, c); return *this;}
|
PIString & insert(const int index, const PIChar c) {d.insert(index, c); return *this;}
|
||||||
|
|
||||||
//! \~english Insert symbol "c" after index "index" and return this string
|
//! \~english Insert character "c" after index "index" and return this string.
|
||||||
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку
|
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("pp");
|
//! PIString s("pp");
|
||||||
@@ -557,8 +693,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & insert(const int index, const char c) {return insert(index, PIChar(c));}
|
PIString & insert(const int index, const char c) {return insert(index, PIChar(c));}
|
||||||
|
|
||||||
//! \~english Insert string "str" after index "index" and return this string
|
//! \~english Insert string "str" after index "index" and return this string.
|
||||||
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку
|
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("stg");
|
//! PIString s("stg");
|
||||||
@@ -567,8 +703,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & insert(const int index, const PIString & str);
|
PIString & insert(const int index, const PIString & str);
|
||||||
|
|
||||||
//! \~english Insert string "str" after index "index" and return this string
|
//! \~english Insert string "str" after index "index" and return this string.
|
||||||
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку
|
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("stg");
|
//! PIString s("stg");
|
||||||
@@ -577,8 +713,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & insert(const int index, const char * c) {return insert(index, PIString(c));}
|
PIString & insert(const int index, const char * c) {return insert(index, PIString(c));}
|
||||||
|
|
||||||
//! \~english Enlarge string to length "len" by addition symbols "c" at the end, and return this string
|
//! \~english Enlarge string to length "len" by addition characters "c" at the end, and return this string.
|
||||||
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в конец и возвращает эту строку
|
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в конец и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -588,10 +724,10 @@ public:
|
|||||||
//! piCout << s; // s = "str___"
|
//! piCout << s; // s = "str___"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a expandLeftTo(), \a expandedRightTo(), \a expandedLeftTo()
|
//! \~\sa \a expandLeftTo(), \a expandedRightTo(), \a expandedLeftTo()
|
||||||
PIString & expandRightTo(const int len, const PIChar c) {if (len > length()) resize(len, c); return *this;}
|
PIString & expandRightTo(const int len, const PIChar c) {if (len > d.size_s()) d.resize(len, c); return *this;}
|
||||||
|
|
||||||
//! \~english Enlarge string to length "len" by addition symbols "c" at the begin, and return this string
|
//! \~english Enlarge string to length "len" by addition characters "c" at the begin, and return this string.
|
||||||
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в начало и возвращает эту строку
|
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в начало и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -601,10 +737,10 @@ public:
|
|||||||
//! piCout << s; // s = "___str"
|
//! piCout << s; // s = "___str"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a expandRightTo(), \a expandedRightTo(), \a expandedLeftTo()
|
//! \~\sa \a expandRightTo(), \a expandedRightTo(), \a expandedLeftTo()
|
||||||
PIString & expandLeftTo(const int len, const PIChar c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;}
|
PIString & expandLeftTo(const int len, const PIChar c) {if (len > d.size_s()) insert(0, PIString(len - d.size_s(), c)); return *this;}
|
||||||
|
|
||||||
//! \~english Enlarge copy of this string to length "len" by addition symbols "c" at the end
|
//! \~english Enlarge copy of this string to length "len" by addition characters "c" at the end.
|
||||||
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в конец
|
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в конец.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -614,8 +750,8 @@ public:
|
|||||||
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedLeftTo()
|
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedLeftTo()
|
||||||
PIString expandedRightTo(const int len, const PIChar c) const {return PIString(*this).expandRightTo(len, c);}
|
PIString expandedRightTo(const int len, const PIChar c) const {return PIString(*this).expandRightTo(len, c);}
|
||||||
|
|
||||||
//! \~english Enlarge copy of this string to length "len" by addition symbols "c" at the begin
|
//! \~english Enlarge copy of this string to length "len" by addition characters "c" at the begin.
|
||||||
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в начало
|
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в начало.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -625,8 +761,8 @@ public:
|
|||||||
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedRightTo()
|
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedRightTo()
|
||||||
PIString expandedLeftTo(const int len, const PIChar c) const {return PIString(*this).expandLeftTo(len, c);}
|
PIString expandedLeftTo(const int len, const PIChar c) const {return PIString(*this).expandLeftTo(len, c);}
|
||||||
|
|
||||||
//! \~english Add "c" symbols at the beginning and end, and return this string
|
//! \~english Add "c" characters at the beginning and end, and return this string.
|
||||||
//! \~russian Добавляет символ "c" в начало и конец и возвращает эту строку
|
//! \~russian Добавляет символ "c" в начало и конец и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -634,10 +770,10 @@ public:
|
|||||||
//! piCout << s; // s = ""str""
|
//! piCout << s; // s = ""str""
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a quoted()
|
//! \~\sa \a quoted()
|
||||||
PIString & quote(PIChar c = PIChar('"')) {insert(0, c); *this += c; return *this;}
|
PIString & quote(PIChar c = PIChar('"')) {d.prepend(c); d.append(c); return *this;}
|
||||||
|
|
||||||
//! \~english Returns quoted copy of this string
|
//! \~english Returns quoted copy of this string.
|
||||||
//! \~russian Возвращает копию строки с добавленным в начало и конец символом "c"
|
//! \~russian Возвращает копию строки с добавленным в начало и конец символом "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("str");
|
//! PIString s("str");
|
||||||
@@ -647,8 +783,8 @@ public:
|
|||||||
//! \~\sa \a quote()
|
//! \~\sa \a quote()
|
||||||
PIString quoted(PIChar c = PIChar('"')) {return PIString(*this).quote(c);}
|
PIString quoted(PIChar c = PIChar('"')) {return PIString(*this).quote(c);}
|
||||||
|
|
||||||
//! \~english Reverse string and return this string
|
//! \~english Reverse string and return this string.
|
||||||
//! \~russian Разворачивает и возвращает эту строку
|
//! \~russian Разворачивает и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -656,10 +792,10 @@ public:
|
|||||||
//! piCout << s; // s = "9876543210"
|
//! piCout << s; // s = "9876543210"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a reversed()
|
//! \~\sa \a reversed()
|
||||||
PIString & reverse() {PIDeque<PIChar>::reverse(); return *this;}
|
PIString & reverse() {d.reverse(); return *this;}
|
||||||
|
|
||||||
//! \~english Reverse copy of this string
|
//! \~english Reverse copy of this string.
|
||||||
//! \~russian Разворачивает копию этой строки
|
//! \~russian Разворачивает копию этой строки.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -669,13 +805,13 @@ public:
|
|||||||
//! \~\sa \a reverse()
|
//! \~\sa \a reverse()
|
||||||
PIString reversed() const {PIString ret(*this); return ret.reverse();}
|
PIString reversed() const {PIString ret(*this); return ret.reverse();}
|
||||||
|
|
||||||
//! \~english Fit string to maximum size "size" by inserting ".." at position "pos" and return this string
|
//! \~english Fit string to maximum size "size" by inserting ".." at position "pos" and return this string.
|
||||||
//! \~russian Уменьшает строку до размера "size", вставляя ".." в положение "pos" и возвращает эту строку
|
//! \~russian Уменьшает строку до размера "size", вставляя ".." в положение "pos" и возвращает эту строку.
|
||||||
//! \~\sa \a elided()
|
//! \~\sa \a elided()
|
||||||
PIString & elide(int size, float pos = ElideCenter);
|
PIString & elide(int size, float pos = ElideCenter);
|
||||||
|
|
||||||
//! \~english Fit copy of this string to maximum size "size" by inserting ".." at position "pos"
|
//! \~english Fit copy of this string to maximum size "size" by inserting ".." at position "pos".
|
||||||
//! \~russian Уменьшает копию этой строки до размера "size", вставляя ".." в положение "pos"
|
//! \~russian Уменьшает копию этой строки до размера "size", вставляя ".." в положение "pos".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideLeft); // ..ABCDEF
|
//! piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideLeft); // ..ABCDEF
|
||||||
@@ -687,8 +823,8 @@ public:
|
|||||||
PIString elided(int size, float pos = ElideCenter) const {PIString str(*this); str.elide(size, pos); return str;}
|
PIString elided(int size, float pos = ElideCenter) const {PIString str(*this); str.elide(size, pos); return str;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Take a part of string from symbol at index "start" and maximum length "len" and return it
|
//! \~english Take a part of string from character at index "start" and maximum length "len" and return it.
|
||||||
//! \~russian Извлекает часть строки от символа "start" максимальной длины "len" и возвращает её
|
//! \~russian Извлекает часть строки от символа "start" максимальной длины "len" и возвращает её.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -698,8 +834,8 @@ public:
|
|||||||
//! \~\sa \a takeLeft, \a takeRight()
|
//! \~\sa \a takeLeft, \a takeRight()
|
||||||
PIString takeMid(const int start, const int len = -1) {PIString ret(mid(start, len)); cutMid(start, len); return ret;}
|
PIString takeMid(const int start, const int len = -1) {PIString ret(mid(start, len)); cutMid(start, len); return ret;}
|
||||||
|
|
||||||
//! \~english Take a part from the begin of string with maximum length "len" and return it
|
//! \~english Take a part from the begin of string with maximum length "len" and return it.
|
||||||
//! \~russian Извлекает часть строки от начала максимальной длины "len" и возвращает её
|
//! \~russian Извлекает часть строки от начала максимальной длины "len" и возвращает её.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -709,8 +845,8 @@ public:
|
|||||||
//! \~\sa \a takeMid(), \a takeRight()
|
//! \~\sa \a takeMid(), \a takeRight()
|
||||||
PIString takeLeft(const int len) {PIString ret(left(len)); cutLeft(len); return ret;}
|
PIString takeLeft(const int len) {PIString ret(left(len)); cutLeft(len); return ret;}
|
||||||
|
|
||||||
//! \~english Take a part from the end of string with maximum length "len" and return it
|
//! \~english Take a part from the end of string with maximum length "len" and return it.
|
||||||
//! \~russian Извлекает часть строки с конца максимальной длины "len" и возвращает её
|
//! \~russian Извлекает часть строки с конца максимальной длины "len" и возвращает её.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("0123456789");
|
//! PIString s("0123456789");
|
||||||
@@ -720,69 +856,69 @@ public:
|
|||||||
//! \~\sa \a takeMid(), \a takeLeft()
|
//! \~\sa \a takeMid(), \a takeLeft()
|
||||||
PIString takeRight(const int len) {PIString ret(right(len)); cutRight(len); return ret;}
|
PIString takeRight(const int len) {PIString ret(right(len)); cutRight(len); return ret;}
|
||||||
|
|
||||||
//! \~english Take a symbol from the begin of this string and return it
|
//! \~english Take a character from the begin of this string and return it.
|
||||||
//! \~russian Извлекает символ с начала строки и возвращает его как строку
|
//! \~russian Извлекает символ с начала строки и возвращает его как строку.
|
||||||
PIString takeSymbol();
|
PIString takeSymbol();
|
||||||
|
|
||||||
//! \~english Take a word from the begin of this string and return it
|
//! \~english Take a word from the begin of this string and return it.
|
||||||
//! \~russian Извлекает слово с начала строки и возвращает его
|
//! \~russian Извлекает слово с начала строки и возвращает его.
|
||||||
PIString takeWord();
|
PIString takeWord();
|
||||||
|
|
||||||
//! \~english Take a word with letters, numbers and '_' symbols from the begin of this string and return it
|
//! \~english Take a word with letters, numbers and '_' characters from the begin of this string and return it.
|
||||||
//! \~russian Извлекает слово из букв, цифр и симолов '_' с начала строки и возвращает его
|
//! \~russian Извлекает слово из букв, цифр и симолов '_' с начала строки и возвращает его.
|
||||||
PIString takeCWord();
|
PIString takeCWord();
|
||||||
|
|
||||||
//! \~english Take a line from the begin of this string and return it
|
//! \~english Take a line from the begin of this string and return it.
|
||||||
//! \~russian Извлекает строку текста (до новой строки) с начала строки и возвращает её
|
//! \~russian Извлекает строку текста (до новой строки) с начала строки и возвращает её.
|
||||||
PIString takeLine();
|
PIString takeLine();
|
||||||
|
|
||||||
//! \~english Take a number with C-format from the begin of this string and return it
|
//! \~english Take a number with C-format from the begin of this string and return it.
|
||||||
//! \~russian Извлекает число в C-формате с начала строки и возвращает его как строку
|
//! \~russian Извлекает число в C-формате с начала строки и возвращает его как строку.
|
||||||
PIString takeNumber();
|
PIString takeNumber();
|
||||||
|
|
||||||
//! \~english Take a range between "start" and "end" symbols from the begin of this string and return it
|
//! \~english Take a range between "start" and "end" characters from the begin of this string and return it.
|
||||||
//! \~russian Извлекает диапазон между символами "start" и "end" с начала строки и возвращает его
|
//! \~russian Извлекает диапазон между символами "start" и "end" с начала строки и возвращает его.
|
||||||
PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\');
|
PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\');
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns string in brackets "start" and "end" symbols from the beginning
|
//! \~english Returns string in brackets "start" and "end" characters from the beginning.
|
||||||
//! \~russian Возвращает строку между символами "start" и "end" с начала строки
|
//! \~russian Возвращает строку между символами "start" и "end" с начала строки.
|
||||||
PIString inBrackets(const PIChar start, const PIChar end) const;
|
PIString inBrackets(const PIChar start, const PIChar end) const;
|
||||||
|
|
||||||
//! \~english Returns \c char * representation of this string in system codepage
|
//! \~english Returns \c char * representation of this string in system codepage.
|
||||||
//! \~russian Возвращает \c char * представление строки в системной кодировке
|
//! \~russian Возвращает \c char * представление строки в системной кодировке.
|
||||||
const char * data() const;
|
const char * data() const;
|
||||||
|
|
||||||
//! \~english Returns \c char * representation of this string in terminal codepage
|
//! \~english Returns \c char * representation of this string in terminal codepage.
|
||||||
//! \~russian Возвращает \c char * представление строки в кодировке консоли
|
//! \~russian Возвращает \c char * представление строки в кодировке консоли.
|
||||||
const char * dataConsole() const;
|
const char * dataConsole() const;
|
||||||
|
|
||||||
//! \~english Returns \c char * representation of this string in UTF-8
|
//! \~english Returns \c char * representation of this string in UTF-8.
|
||||||
//! \~russian Возвращает \c char * представление строки в кодировке UTF-8
|
//! \~russian Возвращает \c char * представление строки в кодировке UTF-8.
|
||||||
const char * dataUTF8() const;
|
const char * dataUTF8() const;
|
||||||
|
|
||||||
//! \~english Returns \c char * representation of this string in ASCII
|
//! \~english Returns \c char * representation of this string in ASCII.
|
||||||
//! \~russian Возвращает \c char * представление строки в кодировке ASCII
|
//! \~russian Возвращает \c char * представление строки в кодировке ASCII.
|
||||||
const char * dataAscii() const;
|
const char * dataAscii() const;
|
||||||
|
|
||||||
//! \~english Returns hash
|
//! \~english Returns hash of string
|
||||||
//! \~russian Возвращает хэш
|
//! \~russian Возвращает хэш строки
|
||||||
uint hash() const;
|
uint hash() const;
|
||||||
|
|
||||||
//! \~english Same as \a toUTF8().
|
//! \~english Same as \a toUTF8().
|
||||||
//! \~russian Тоже самое, что \a toUTF8().
|
//! \~russian Тоже самое, что \a toUTF8().
|
||||||
PIByteArray toByteArray() const {return toUTF8();}
|
PIByteArray toByteArray() const {return toUTF8();}
|
||||||
|
|
||||||
//! \~english Returns \a PIByteArray contains \a dataUTF8() of this string without terminating null-char
|
//! \~english Returns \a PIByteArray contains \a dataUTF8() of this string without terminating null-char.
|
||||||
//! \~russian Возвращает \a PIByteArray содержащий \a dataUTF8() строки без завершающего нулевого байта
|
//! \~russian Возвращает \a PIByteArray содержащий \a dataUTF8() строки без завершающего нулевого байта.
|
||||||
PIByteArray toUTF8() const;
|
PIByteArray toUTF8() const;
|
||||||
|
|
||||||
//! \~english Returns \a PIByteArray contains custom charset representation of this string without terminating null-char
|
//! \~english Returns \a PIByteArray contains custom charset representation of this string without terminating null-char.
|
||||||
//! \~russian Возвращает \a PIByteArray содержащий строку в указанной кодировке без завершающего нулевого байта
|
//! \~russian Возвращает \a PIByteArray содержащий строку в указанной кодировке без завершающего нулевого байта.
|
||||||
PIByteArray toCharset(const char * c) const;
|
PIByteArray toCharset(const char * c) const;
|
||||||
|
|
||||||
//! \~english Split string with delimiter "delim" to \a PIStringList
|
//! \~english Split string with delimiter "delim" to \a PIStringList.
|
||||||
//! \~russian Разделяет строку в \a PIStringList через разделитель "delim"
|
//! \~russian Разделяет строку в \a PIStringList через разделитель "delim".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("1 2 3");
|
//! PIString s("1 2 3");
|
||||||
@@ -791,40 +927,45 @@ public:
|
|||||||
PIStringList split(const PIString & delim) const;
|
PIStringList split(const PIString & delim) const;
|
||||||
|
|
||||||
|
|
||||||
//! \~english Convert each symbol in copied string to upper case
|
//! \~english Convert each character in copied string to upper case.
|
||||||
//! \~russian Преобразует каждый символ в скопированной строке в верхний регистр
|
//! \~russian Преобразует каждый символ в скопированной строке в верхний регистр.
|
||||||
PIString toUpperCase() const;
|
PIString toUpperCase() const;
|
||||||
|
|
||||||
//! \~english Convert each symbol in copied string to lower case
|
//! \~english Convert each character in copied string to lower case.
|
||||||
//! \~russian Преобразует каждый символ в скопированной строке в нижний регистр
|
//! \~russian Преобразует каждый символ в скопированной строке в нижний регистр.
|
||||||
PIString toLowerCase() const;
|
PIString toLowerCase() const;
|
||||||
|
|
||||||
|
// TODO: doxygen
|
||||||
PIString toNativeDecimalPoints() const;
|
PIString toNativeDecimalPoints() const;
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns if string contains symbol "c"
|
//! \~english Returns if string contains character "c".
|
||||||
//! \~russian Возвращает содержит ли строка символ "c"
|
//! \~russian Возвращает содержит ли строка символ "c".
|
||||||
bool contains(const char c) const {return PIDeque<PIChar>::contains(PIChar(c));}
|
bool contains(const char c) const {return d.contains(PIChar(c));}
|
||||||
|
|
||||||
//! \~english Returns if string contains substring "str"
|
//! \~english Returns if string contains substring "str".
|
||||||
//! \~russian Возвращает содержит ли строка подстроку "str"
|
//! \~russian Возвращает содержит ли строка подстроку "str".
|
||||||
bool contains(const char * str) const {return contains(PIString(str));}
|
bool contains(const char * str) const {return contains(PIString(str));}
|
||||||
|
|
||||||
//! \~english Returns if string contains substring "str"
|
//! \~english Returns if string contains substring "str".
|
||||||
//! \~russian Возвращает содержит ли строка подстроку "str"
|
//! \~russian Возвращает содержит ли строка подстроку "str".
|
||||||
bool contains(const PIString & str) const {return find(str) >= 0;}
|
bool contains(const PIString & str) const {return find(str) >= 0;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Search symbol "c" from symbol at index "start" and return first occur position
|
//! \~english Search character "c" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение
|
//! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение.
|
||||||
int find(const char c, const int start = 0) const;
|
int find(const char c, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search substring "str" from symbol at index "start" and return first occur position
|
//! \~english Search character "c" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение
|
//! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение.
|
||||||
|
int find(PIChar c, const int start = 0) const {return d.indexOf(c, start);}
|
||||||
|
|
||||||
|
//! \~english Search substring "str" from character at index "start" and return first occur position.
|
||||||
|
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение.
|
||||||
int find(const PIString & str, const int start = 0) const;
|
int find(const PIString & str, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search substring "str" from symbol at index "start" and return first occur position
|
//! \~english Search substring "str" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение
|
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("012345012345");
|
//! PIString s("012345012345");
|
||||||
@@ -836,12 +977,12 @@ public:
|
|||||||
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||||
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
|
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
|
||||||
|
|
||||||
//! \~english Search any symbol of "str" from symbol at index "start" and return first occur position
|
//! \~english Search any character of "str" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение
|
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение.
|
||||||
int findAny(const PIString & str, const int start = 0) const;
|
int findAny(const PIString & str, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search any symbol of "str" from symbol at index "start" and return first occur position
|
//! \~english Search any character of "str" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение
|
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("1.str").findAny(".,:"); // 1
|
//! piCout << PIString("1.str").findAny(".,:"); // 1
|
||||||
@@ -851,16 +992,20 @@ public:
|
|||||||
//! \~\sa \a find(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
//! \~\sa \a find(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||||
int findAny(const char * str, const int start = 0) const {return findAny(PIString(str), start);}
|
int findAny(const char * str, const int start = 0) const {return findAny(PIString(str), start);}
|
||||||
|
|
||||||
//! \~english Search symbol "c" from symbol at index "start" and return last occur position
|
//! \~english Search character "c" from character at index "start" and return last occur position.
|
||||||
//! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение
|
//! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение.
|
||||||
int findLast(const char c, const int start = 0) const;
|
int findLast(const char c, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search substring "str" from symbol at index "start" and return last occur position
|
//! \~english Search character "c" from character at index "start" and return last occur position.
|
||||||
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение
|
//! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение.
|
||||||
|
int findLast(PIChar c, const int start = 0) const;
|
||||||
|
|
||||||
|
//! \~english Search substring "str" from character at index "start" and return last occur position.
|
||||||
|
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение.
|
||||||
int findLast(const PIString & str, const int start = 0) const;
|
int findLast(const PIString & str, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search substring "str" from symbol at index "start" and return last occur position
|
//! \~english Search substring "str" from character at index "start" and return last occur position.
|
||||||
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение
|
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("012345012345");
|
//! PIString s("012345012345");
|
||||||
@@ -872,12 +1017,12 @@ public:
|
|||||||
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||||
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
|
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
|
||||||
|
|
||||||
//! \~english Search any symbol of "str" from symbol at index "start" and return last occur position
|
//! \~english Search any character of "str" from character at index "start" and return last occur position.
|
||||||
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение
|
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение.
|
||||||
int findAnyLast(const PIString & str, const int start = 0) const;
|
int findAnyLast(const PIString & str, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search any symbol of "str" from symbol at index "start" and return last occur position
|
//! \~english Search any character of "str" from character at index "start" and return last occur position.
|
||||||
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение
|
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString(".str.0").findAnyLast(".,:"); // 4
|
//! piCout << PIString(".str.0").findAnyLast(".,:"); // 4
|
||||||
@@ -887,20 +1032,20 @@ public:
|
|||||||
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findWord(), \a findCWord(), \a findRange()
|
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||||
int findAnyLast(const char * str, const int start = 0) const {return findAnyLast(PIString(str), start);}
|
int findAnyLast(const char * str, const int start = 0) const {return findAnyLast(PIString(str), start);}
|
||||||
|
|
||||||
//! \~english Search word "word" from symbol at index "start" and return first occur position
|
//! \~english Search word "word" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет слово "word" от симола "start" и возвращает первое вхождение
|
//! \~russian Ищет слово "word" от симола "start" и возвращает первое вхождение.
|
||||||
int findWord(const PIString & word, const int start = 0) const;
|
int findWord(const PIString & word, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search C-word "word" from symbol at index "start" and return first occur position
|
//! \~english Search C-word "word" from character at index "start" and return first occur position.
|
||||||
//! \~russian Ищет C-слово "word" от симола "start" и возвращает первое вхождение
|
//! \~russian Ищет C-слово "word" от симола "start" и возвращает первое вхождение.
|
||||||
int findCWord(const PIString & word, const int start = 0) const;
|
int findCWord(const PIString & word, const int start = 0) const;
|
||||||
|
|
||||||
//! \~english Search range start between "start" and "end" symbols at index "start_index" and return first occur position
|
//! \~english Search range start between "start" and "end" characters at index "start_index" and return first occur position.
|
||||||
//! \~russian Ищет начало диапазона между символами "start" и "end" от симола "start" и возвращает первое вхождение
|
//! \~russian Ищет начало диапазона между символами "start" и "end" от симола "start" и возвращает первое вхождение.
|
||||||
int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const;
|
int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const;
|
||||||
|
|
||||||
//! \~english Returns number of occurrences of symbol "c"
|
//! \~english Returns number of occurrences of character "c".
|
||||||
//! \~russian Возвращает число вхождений символа "c"
|
//! \~russian Возвращает число вхождений символа "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString(".str.0").entries("."); // 2
|
//! piCout << PIString(".str.0").entries("."); // 2
|
||||||
@@ -908,8 +1053,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
int entries(const PIChar c) const;
|
int entries(const PIChar c) const;
|
||||||
|
|
||||||
//! \~english Returns number of occurrences of symbol "c"
|
//! \~english Returns number of occurrences of character "c".
|
||||||
//! \~russian Возвращает число вхождений символа "c"
|
//! \~russian Возвращает число вхождений символа "c".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString(".str.0").entries('.'); // 2
|
//! piCout << PIString(".str.0").entries('.'); // 2
|
||||||
@@ -917,40 +1062,56 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
int entries(char c) const {return entries(PIChar(c));}
|
int entries(char c) const {return entries(PIChar(c));}
|
||||||
|
|
||||||
//! \~english Returns if string starts with "str"
|
//! \~english Returns if string starts with "str".
|
||||||
//! \~russian Возвращает начинается ли строка со "str"
|
//! \~russian Возвращает начинается ли строка со "str".
|
||||||
bool startsWith(const PIString & str) const;
|
bool startsWith(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Returns if string ends with "str"
|
//! \~english Returns if string ends with "str".
|
||||||
//! \~russian Возвращает оканчивается ли строка на "str"
|
//! \~russian Возвращает оканчивается ли строка на "str".
|
||||||
bool endsWith(const PIString & str) const;
|
bool endsWith(const PIString & str) const;
|
||||||
|
|
||||||
//! \~english Returns symbols length of string
|
//! \~english Returns characters length of string.
|
||||||
//! \~russian Возвращает длину строки в символах
|
//! \~russian Возвращает длину строки в символах.
|
||||||
int length() const {return size();}
|
int length() const {return d.size_s();}
|
||||||
|
|
||||||
//! \~english Returns \c true if string is empty, i.e. length = 0
|
//! \~english Returns characters length of string.
|
||||||
//! \~russian Возвращает \c true если строка пустая, т.е. длина = 0
|
//! \~russian Возвращает длину строки в символах.
|
||||||
bool isEmpty() const {return (size() == 0 || *this == "");}
|
size_t size() const {return d.size();}
|
||||||
|
|
||||||
//! \~english Returns \c true if string is not empty, i.e. length > 0
|
//! \~english Returns characters length of string.
|
||||||
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0
|
//! \~russian Возвращает длину строки в символах.
|
||||||
|
ssize_t size_s() const {return d.size_s();}
|
||||||
|
|
||||||
|
//! \~english Returns \c true if string is empty, i.e. length = 0.
|
||||||
|
//! \~russian Возвращает \c true если строка пустая, т.е. длина = 0.
|
||||||
|
bool isEmpty() const {if (d.isEmpty()) return true; if (d.at(0) == PIChar()) return true; return false;}
|
||||||
|
|
||||||
|
//! \~english Returns \c true if string is not empty, i.e. length > 0.
|
||||||
|
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0.
|
||||||
bool isNotEmpty() const {return !isEmpty();}
|
bool isNotEmpty() const {return !isEmpty();}
|
||||||
|
|
||||||
|
//! \~english Clear string, will be empty string.
|
||||||
|
//! \~russian Очищает строку, строка становится пустой.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\note
|
||||||
|
//! \~english Reserved memory will not be released.
|
||||||
|
//! \~russian Зарезервированная память не освободится.
|
||||||
|
//! \~\sa \a resize()
|
||||||
|
void clear() {d.clear();}
|
||||||
|
|
||||||
//! \~english Returns \c true if string equal "true", "yes", "on" or positive not null numeric value
|
//! \~english Returns \c true if string equal "true", "yes", "on" or positive not null numeric value.
|
||||||
//! \~russian Возвращает \c true если строка равна "true", "yes", "on" или числу > 0
|
//! \~russian Возвращает \c true если строка равна "true", "yes", "on" или числу > 0.
|
||||||
bool toBool() const;
|
bool toBool() const;
|
||||||
|
|
||||||
//! \~english Returns \c char numeric value of string
|
//! \~english Returns \c char numeric value of string.
|
||||||
//! \~russian Возвращает \c char числовое значение строки
|
//! \~russian Возвращает \c char числовое значение строки.
|
||||||
char toChar() const;
|
char toChar() const;
|
||||||
|
|
||||||
//! \~english Returns \c short numeric value of string in base "base"
|
//! \~english Returns \c short numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c short числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c short числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toShort(); // 123
|
//! piCout << PIString("123").toShort(); // 123
|
||||||
//! piCout << PIString("123").toShort(16); // 291
|
//! piCout << PIString("123").toShort(16); // 291
|
||||||
@@ -959,11 +1120,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
short toShort(int base = -1, bool * ok = 0) const {return short(toNumberBase(*this, base, ok));}
|
short toShort(int base = -1, bool * ok = 0) const {return short(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c ushort numeric value of string in base "base"
|
//! \~english Returns \c ushort numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c ushort числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c ushort числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toUShort(); // 123
|
//! piCout << PIString("123").toUShort(); // 123
|
||||||
//! piCout << PIString("123").toUShort(16); // 291
|
//! piCout << PIString("123").toUShort(16); // 291
|
||||||
@@ -972,11 +1133,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
ushort toUShort(int base = -1, bool * ok = 0) const {return ushort(toNumberBase(*this, base, ok));}
|
ushort toUShort(int base = -1, bool * ok = 0) const {return ushort(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c int numeric value of string in base "base"
|
//! \~english Returns \c int numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c int числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c int числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toInt(); // 123
|
//! piCout << PIString("123").toInt(); // 123
|
||||||
//! piCout << PIString("123").toInt(16); // 291
|
//! piCout << PIString("123").toInt(16); // 291
|
||||||
@@ -985,11 +1146,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
int toInt(int base = -1, bool * ok = 0) const {return int(toNumberBase(*this, base, ok));}
|
int toInt(int base = -1, bool * ok = 0) const {return int(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c uint numeric value of string in base "base"
|
//! \~english Returns \c uint numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c uint числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c uint числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toUInt(); // 123
|
//! piCout << PIString("123").toUInt(); // 123
|
||||||
//! piCout << PIString("123").toUInt(16); // 291
|
//! piCout << PIString("123").toUInt(16); // 291
|
||||||
@@ -998,11 +1159,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
uint toUInt(int base = -1, bool * ok = 0) const {return uint(toNumberBase(*this, base, ok));}
|
uint toUInt(int base = -1, bool * ok = 0) const {return uint(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c long numeric value of string in base "base"
|
//! \~english Returns \c long numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c long числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c long числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toLong(); // 123
|
//! piCout << PIString("123").toLong(); // 123
|
||||||
//! piCout << PIString("123").toLong(16); // 291
|
//! piCout << PIString("123").toLong(16); // 291
|
||||||
@@ -1011,11 +1172,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
long toLong(int base = -1, bool * ok = 0) const {return long(toNumberBase(*this, base, ok));}
|
long toLong(int base = -1, bool * ok = 0) const {return long(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c ulong numeric value of string in base "base"
|
//! \~english Returns \c ulong numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c ulong числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c ulong числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toULong(); // 123
|
//! piCout << PIString("123").toULong(); // 123
|
||||||
//! piCout << PIString("123").toULong(16); // 291
|
//! piCout << PIString("123").toULong(16); // 291
|
||||||
@@ -1024,11 +1185,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
ulong toULong(int base = -1, bool * ok = 0) const {return ulong(toNumberBase(*this, base, ok));}
|
ulong toULong(int base = -1, bool * ok = 0) const {return ulong(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c llong numeric value of string in base "base"
|
//! \~english Returns \c llong numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c llong числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c llong числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toLLong(); // 123
|
//! piCout << PIString("123").toLLong(); // 123
|
||||||
//! piCout << PIString("123").toLLong(16); // 291
|
//! piCout << PIString("123").toLLong(16); // 291
|
||||||
@@ -1037,11 +1198,11 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
llong toLLong(int base = -1, bool * ok = 0) const {return toNumberBase(*this, base, ok);}
|
llong toLLong(int base = -1, bool * ok = 0) const {return toNumberBase(*this, base, ok);}
|
||||||
|
|
||||||
//! \~english Returns \c ullong numeric value of string in base "base"
|
//! \~english Returns \c ullong numeric value of string in base "base".
|
||||||
//! \~russian Возвращает \c ullong числовое значение строки по основанию "base"
|
//! \~russian Возвращает \c ullong числовое значение строки по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
|
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.
|
||||||
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
|
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toULLong(); // 123
|
//! piCout << PIString("123").toULLong(); // 123
|
||||||
//! piCout << PIString("123").toULLong(16); // 291
|
//! piCout << PIString("123").toULLong(16); // 291
|
||||||
@@ -1050,8 +1211,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
ullong toULLong(int base = -1, bool * ok = 0) const {return ullong(toNumberBase(*this, base, ok));}
|
ullong toULLong(int base = -1, bool * ok = 0) const {return ullong(toNumberBase(*this, base, ok));}
|
||||||
|
|
||||||
//! \~english Returns \c float numeric value of string
|
//! \~english Returns \c float numeric value of string.
|
||||||
//! \~russian Возвращает \c float числовое значение строки
|
//! \~russian Возвращает \c float числовое значение строки.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toFloat(); // 123
|
//! piCout << PIString("123").toFloat(); // 123
|
||||||
@@ -1060,8 +1221,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
float toFloat() const;
|
float toFloat() const;
|
||||||
|
|
||||||
//! \~english Returns \c double numeric value of string
|
//! \~english Returns \c double numeric value of string.
|
||||||
//! \~russian Возвращает \c double числовое значение строки
|
//! \~russian Возвращает \c double числовое значение строки.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toDouble(); // 123
|
//! piCout << PIString("123").toDouble(); // 123
|
||||||
@@ -1070,8 +1231,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
double toDouble() const;
|
double toDouble() const;
|
||||||
|
|
||||||
//! \~english Returns \c ldouble numeric value of string
|
//! \~english Returns \c ldouble numeric value of string.
|
||||||
//! \~russian Возвращает \c ldouble числовое значение строки
|
//! \~russian Возвращает \c ldouble числовое значение строки.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString("123").toLDouble(); // 123
|
//! piCout << PIString("123").toLDouble(); // 123
|
||||||
@@ -1080,8 +1241,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
ldouble toLDouble() const;
|
ldouble toLDouble() const;
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1090,10 +1251,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const short value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const short value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1102,10 +1263,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const ushort value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const ushort value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1114,10 +1275,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const int value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const int value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1126,10 +1287,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const uint value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const uint value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1138,10 +1299,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const long value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const long value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1150,10 +1311,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const ulong value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const ulong value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1162,10 +1323,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const llong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const llong & value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" in base "base" and return this string
|
//! \~english Set string content to text representation of "value" in base "base" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1174,10 +1335,10 @@ public:
|
|||||||
//! s.setNumber(123, 16);
|
//! s.setNumber(123, 16);
|
||||||
//! piCout << s; // 7B
|
//! piCout << s; // 7B
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const ullong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
|
PIString & setNumber(const ullong & value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
|
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1192,10 +1353,10 @@ public:
|
|||||||
//! s.setNumber(123456789., 'f', 0);
|
//! s.setNumber(123456789., 'f', 0);
|
||||||
//! piCout << s; // 123456789
|
//! piCout << s; // 123456789
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const float value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
|
PIString & setNumber(const float value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
|
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1210,10 +1371,10 @@ public:
|
|||||||
//! s.setNumber(123456789., 'f', 0);
|
//! s.setNumber(123456789., 'f', 0);
|
||||||
//! piCout << s; // 123456789
|
//! piCout << s; // 123456789
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const double & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
|
PIString & setNumber(const double & value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
|
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string.
|
||||||
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
|
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s;
|
//! PIString s;
|
||||||
@@ -1228,15 +1389,15 @@ public:
|
|||||||
//! s.setNumber(123456789., 'f', 0);
|
//! s.setNumber(123456789., 'f', 0);
|
||||||
//! piCout << s; // 123456789
|
//! piCout << s; // 123456789
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & setNumber(const ldouble & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
|
PIString & setNumber(const ldouble & value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;}
|
||||||
|
|
||||||
//! \~english Set string content to human readable size in B/kB/MB/GB/TB/PB
|
//! \~english Set string content to human readable size in B/kB/MB/GB/TB/PB.
|
||||||
//! \~russian Устанавливает содержимое в строку с читаемым размером B/kB/MB/GB/TB/PB
|
//! \~russian Устанавливает содержимое в строку с читаемым размером B/kB/MB/GB/TB/PB.
|
||||||
//! \~\sa PIString::readableSize()
|
//! \~\sa PIString::readableSize()
|
||||||
PIString & setReadableSize(llong bytes);
|
PIString & setReadableSize(llong bytes);
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1244,8 +1405,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const short value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
static PIString fromNumber(const short value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1253,8 +1414,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const ushort value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
static PIString fromNumber(const ushort value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1262,8 +1423,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const int value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
static PIString fromNumber(const int value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1271,8 +1432,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const uint value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
static PIString fromNumber(const uint value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1280,8 +1441,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const long value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
static PIString fromNumber(const long value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1289,8 +1450,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const ulong value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
static PIString fromNumber(const ulong value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1298,8 +1459,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const llong & value, int base = 10, bool * ok = 0) {return fromNumberBaseS(value, base, ok);}
|
static PIString fromNumber(const llong & value, int base = 10, bool * ok = 0) {return fromNumberBaseS(value, base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" in base "base"
|
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
|
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(123); // 123
|
//! piCout << PIString::fromNumber(123); // 123
|
||||||
@@ -1307,8 +1468,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const ullong & value, int base = 10, bool * ok = 0) {return fromNumberBaseU(value, base, ok);}
|
static PIString fromNumber(const ullong & value, int base = 10, bool * ok = 0) {return fromNumberBaseU(value, base, ok);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
|
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision".
|
||||||
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
|
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
||||||
@@ -1317,10 +1478,10 @@ public:
|
|||||||
//! piCout << PIString::fromNumber(123456789., 'g', 2); // 1.2e+08
|
//! piCout << PIString::fromNumber(123456789., 'g', 2); // 1.2e+08
|
||||||
//! piCout << PIString::fromNumber(123456789., 'f', 0); // 123456789
|
//! piCout << PIString::fromNumber(123456789., 'f', 0); // 123456789
|
||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const float value, char format = 'f', int precision = 8) {return ftos(value, format, precision);}
|
static PIString fromNumber(const float value, char format = 'f', int precision = 8) {return dtos(value, format, precision);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
|
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision".
|
||||||
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
|
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
||||||
@@ -1331,8 +1492,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
static PIString fromNumber(const double & value, char format = 'f', int precision = 8) {return dtos(value, format, precision);}
|
static PIString fromNumber(const double & value, char format = 'f', int precision = 8) {return dtos(value, format, precision);}
|
||||||
|
|
||||||
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
|
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision".
|
||||||
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
|
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
//! piCout << PIString::fromNumber(12.3); // 12.30000000
|
||||||
@@ -1345,44 +1506,54 @@ public:
|
|||||||
|
|
||||||
//! \~english Returns "true" or "false"
|
//! \~english Returns "true" or "false"
|
||||||
//! \~russian Возвращает "true" или "false"
|
//! \~russian Возвращает "true" или "false"
|
||||||
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
|
static PIString fromBool(const bool value) {return PIString(value ? PIStringAscii("true") : PIStringAscii("false"));}
|
||||||
|
|
||||||
//! \~english Returns string constructed from terminal codepage
|
//! \~english Returns string constructed from terminal codepage.
|
||||||
//! \~russian Возвращает строку созданную из кодировки консоли
|
//! \~russian Возвращает строку созданную из кодировки консоли.
|
||||||
static PIString fromConsole(const char * s);
|
static PIString fromConsole(const char * s);
|
||||||
|
|
||||||
//! \~english Returns string constructed from system codepage
|
//! \~english Returns string constructed from system codepage.
|
||||||
//! \~russian Возвращает строку созданную из кодировки системы
|
//! \~russian Возвращает строку созданную из кодировки системы.
|
||||||
static PIString fromSystem(const char * s);
|
static PIString fromSystem(const char * s);
|
||||||
|
|
||||||
//! \~english Returns string constructed from UTF-8
|
//! \~english Returns string constructed from UTF-8.
|
||||||
//! \~russian Возвращает строку созданную из UTF-8
|
//! \~russian Возвращает строку созданную из UTF-8.
|
||||||
static PIString fromUTF8(const char * s);
|
static PIString fromUTF8(const char * s);
|
||||||
|
|
||||||
//! \~english Returns string constructed from UTF-8
|
//! \~english Returns string constructed from UTF-8.
|
||||||
//! \~russian Возвращает строку созданную из UTF-8
|
//! \~russian Возвращает строку созданную из UTF-8.
|
||||||
static PIString fromUTF8(const PIByteArray & utf);
|
static PIString fromUTF8(const PIByteArray & utf);
|
||||||
|
|
||||||
//! \~english Returns string constructed from ASCII
|
//! \~english Returns string constructed from ASCII.
|
||||||
//! \~russian Возвращает строку созданную из ASCII
|
//! \~russian Возвращает строку созданную из ASCII.
|
||||||
static PIString fromAscii(const char * s);
|
static PIString fromAscii(const char * s);
|
||||||
|
|
||||||
//! \~english Returns string constructed from "len" chars ASCII
|
//! \~english Returns string constructed from "len" chars ASCII.
|
||||||
//! \~russian Возвращает строку созданную из "len" символов ASCII
|
//! \~russian Возвращает строку созданную из "len" символов ASCII.
|
||||||
static PIString fromAscii(const char * s, int len);
|
static PIString fromAscii(const char * s, int len);
|
||||||
|
|
||||||
//! \~english Returns string constructed from "cp" codepage
|
//! \~english Returns string constructed from "cp" codepage.
|
||||||
//! \~russian Возвращает строку созданную из кодировки "cp"
|
//! \~russian Возвращает строку созданную из кодировки "cp".
|
||||||
static PIString fromCodepage(const char * s, const char * cp);
|
static PIString fromCodepage(const char * s, const char * cp);
|
||||||
|
|
||||||
//! \~english Returns string contains human readable size in B/kB/MB/GB/TB/PB
|
//! \~english Returns string contains human readable size in B/kB/MB/GB/TB/PB.
|
||||||
//! \~russian Возвращает строку с читаемым размером B/kB/MB/GB/TB/PB
|
//! \~russian Возвращает строку с читаемым размером B/kB/MB/GB/TB/PB.
|
||||||
//! \~\sa PIString::setReadableSize()
|
//! \~\sa PIString::setReadableSize()
|
||||||
static PIString readableSize(llong bytes);
|
static PIString readableSize(llong bytes);
|
||||||
|
|
||||||
|
//! \~english Swaps string `str` other with this string.
|
||||||
|
//! \~russian Меняет строку `str` с этой строкой.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english This operation is very fast and never fails.
|
||||||
|
//! \~russian Эта операция выполняется мгновенно без копирования памяти и никогда не дает сбоев.
|
||||||
|
void swap(PIString & str) {
|
||||||
|
d.swap(str.d);
|
||||||
|
piSwap(data_, str.data_);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char toBaseN[];
|
static const char toBaseN[];
|
||||||
static const int fromBaseN[];
|
static const char fromBaseN[];
|
||||||
|
|
||||||
static PIString itos(const int num);
|
static PIString itos(const int num);
|
||||||
static PIString ltos(const long num);
|
static PIString ltos(const long num);
|
||||||
@@ -1390,7 +1561,6 @@ private:
|
|||||||
static PIString uitos(const uint num);
|
static PIString uitos(const uint num);
|
||||||
static PIString ultos(const ulong num);
|
static PIString ultos(const ulong num);
|
||||||
static PIString ulltos(const ullong num);
|
static PIString ulltos(const ullong num);
|
||||||
static PIString ftos(const float num, char format = 'f', int precision = 8);
|
|
||||||
static PIString dtos(const double num, char format = 'f', int precision = 8);
|
static PIString dtos(const double num, char format = 'f', int precision = 8);
|
||||||
static PIString fromNumberBaseS(const llong value, int base = 10, bool * ok = 0);
|
static PIString fromNumberBaseS(const llong value, int base = 10, bool * ok = 0);
|
||||||
static PIString fromNumberBaseU(const ullong value, int base = 10, bool * ok = 0);
|
static PIString fromNumberBaseU(const ullong value, int base = 10, bool * ok = 0);
|
||||||
@@ -1400,63 +1570,63 @@ private:
|
|||||||
void deleteData() const;
|
void deleteData() const;
|
||||||
void trimsubstr(int &st, int &fn) const;
|
void trimsubstr(int &st, int &fn) const;
|
||||||
|
|
||||||
|
PIDeque<PIChar> d;
|
||||||
mutable char * data_ = nullptr;
|
mutable char * data_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PICout
|
//! \relatesalso PICout
|
||||||
//! \~english Output operator to \a PICout
|
//! \~english Output operator to \a PICout.
|
||||||
//! \~russian Оператор вывода в \a PICout
|
//! \~russian Оператор вывода в \a PICout.
|
||||||
PIP_EXPORT PICout operator <<(PICout s, const PIString & v);
|
PIP_EXPORT PICout operator <<(PICout s, const PIString & v);
|
||||||
|
|
||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Store operator
|
//! \~english Store operator.
|
||||||
//! \~russian Оператор сохранения
|
//! \~russian Оператор сохранения.
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << *(PIDeque<PIChar>*)&v; return s;}
|
inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << v.d; return s;}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Restore operator
|
//! \~english Restore operator.
|
||||||
//! \~russian Оператор извлечения
|
//! \~russian Оператор извлечения.
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.clear(); s >> *(PIDeque<PIChar>*)&v; return s;}
|
inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.d.clear(); s >> v.d; return s;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns concatenated string
|
//! \~english Returns concatenated string.
|
||||||
//! \~russian Возвращает соединение строк
|
//! \~russian Возвращает соединение строк.
|
||||||
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
|
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
|
||||||
|
|
||||||
//! \~english Returns concatenated string
|
//! \~english Returns concatenated string.
|
||||||
//! \~russian Возвращает соединение строк
|
//! \~russian Возвращает соединение строк.
|
||||||
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
|
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
|
||||||
|
|
||||||
//! \~english Returns concatenated string
|
//! \~english Returns concatenated string.
|
||||||
//! \~russian Возвращает соединение строк
|
//! \~russian Возвращает соединение строк.
|
||||||
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
|
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
|
||||||
|
|
||||||
//! \~english Returns concatenated string
|
//! \~english Returns concatenated string.
|
||||||
//! \~russian Возвращает соединение строк
|
//! \~russian Возвращает соединение строк.
|
||||||
inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;}
|
inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;}
|
||||||
|
|
||||||
//! \~english Returns concatenated string
|
//! \~english Returns concatenated string.
|
||||||
//! \~russian Возвращает соединение строк
|
//! \~russian Возвращает соединение строк.
|
||||||
inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);}
|
inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);}
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIString
|
//! \relatesalso PIString
|
||||||
//! \~english Compare two version strings in free notation and returns 0, -1 or 1
|
//! \~english Compare two version strings in free notation and returns 0, -1 or 1.
|
||||||
//! \~russian Сравнивает две строки с версиями в произвольной форме и возвращает 0, -1 или 1
|
//! \~russian Сравнивает две строки с версиями в произвольной форме и возвращает 0, -1 или 1.
|
||||||
int PIP_EXPORT versionCompare(const PIString & v0, const PIString & v1, int components = 6);
|
int PIP_EXPORT versionCompare(const PIString & v0, const PIString & v1, int components = 6);
|
||||||
|
|
||||||
//! \relatesalso PIString
|
//! \relatesalso PIString
|
||||||
//! \~english Converts version string in free notation to classic view
|
//! \~english Converts version string in free notation to classic view.
|
||||||
//! \~russian Преобразует строку с версией в произвольной форме к классическому виду
|
//! \~russian Преобразует строку с версией в произвольной форме к классическому виду.
|
||||||
PIString PIP_EXPORT versionNormalize(const PIString & v);
|
PIString PIP_EXPORT versionNormalize(const PIString & v);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns hash of string
|
|
||||||
//! \~russian Возвращает хэш строки
|
|
||||||
template<> inline uint piHash(const PIString & s) {return s.hash();}
|
template<> inline uint piHash(const PIString & s) {return s.hash();}
|
||||||
|
|
||||||
template<> inline void piSwap(PIString & f, PIString & s) {f.swap(s);}
|
template<> inline void piSwap(PIString & f, PIString & s) {
|
||||||
|
f.swap(s);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PISTRING_H
|
#endif // PISTRING_H
|
||||||
|
|||||||
@@ -20,16 +20,9 @@
|
|||||||
#include "pistringlist.h"
|
#include "pistringlist.h"
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \~\class PIStringList pistringlist.h
|
//! \~\class PIStringList pistringlist.h
|
||||||
//! \~\brief
|
|
||||||
//! \~english Based on \a PIDeque<PIString> strings list
|
|
||||||
//! \~russian Основанный на \a PIDeque<PIString> массив строк
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
//! \details
|
//! \details
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Based on \a PIDeque<PIString> strings list.
|
||||||
|
//! \~russian Основанный на \a PIDeque<PIString> массив строк.
|
||||||
class PIP_EXPORT PIStringList: public PIDeque<PIString>
|
class PIP_EXPORT PIStringList: public PIDeque<PIString>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -45,13 +45,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PISystemTime pisystemtime.h
|
//! \class PISystemTime pisystemtime.h
|
||||||
//! \brief
|
//! \details
|
||||||
//! \~english System time with nanosecond precision
|
|
||||||
//! \~russian Системное время с точностью до наносекунд
|
|
||||||
//!
|
|
||||||
//! \~english \section PISystemTime_sec0 Synopsis
|
//! \~english \section PISystemTime_sec0 Synopsis
|
||||||
//! \~russian \section PISystemTime_sec0 Краткий обзор
|
//! \~russian \section PISystemTime_sec0 Краткий обзор
|
||||||
//! \~english
|
//! \~english
|
||||||
@@ -72,16 +67,10 @@
|
|||||||
//! \~russian \section PISystemTime_sec1 Пример
|
//! \~russian \section PISystemTime_sec1 Пример
|
||||||
//! \~\snippet pitimer.cpp system_time
|
//! \~\snippet pitimer.cpp system_time
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup Core
|
|
||||||
//! \{
|
|
||||||
//! \class PITimeMeasurer pisystemtime.h
|
//! \class PITimeMeasurer pisystemtime.h
|
||||||
//! \brief
|
//! \details
|
||||||
//! \~english Time measurements
|
|
||||||
//! \~russian Измерение времени
|
|
||||||
//!
|
|
||||||
//! \~english \section PITimeMeasurer_sec0 Usage
|
//! \~english \section PITimeMeasurer_sec0 Usage
|
||||||
//! \~russian \section PITimeMeasurer_sec0 Использование
|
//! \~russian \section PITimeMeasurer_sec0 Использование
|
||||||
//! \~english
|
//! \~english
|
||||||
@@ -96,7 +85,6 @@
|
|||||||
//! Эти методы возвращают нано, микро, милли и секунды с приставками
|
//! Эти методы возвращают нано, микро, милли и секунды с приставками
|
||||||
//! "n", "u", "m" и "s".
|
//! "n", "u", "m" и "s".
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english System time with nanosecond precision.
|
||||||
|
//! \~russian Системное время с точностью до наносекунд.
|
||||||
class PIP_EXPORT PISystemTime {
|
class PIP_EXPORT PISystemTime {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -187,6 +191,10 @@ inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.setCon
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Time measurements.
|
||||||
|
//! \~russian Измерение времени.
|
||||||
class PIP_EXPORT PITimeMeasurer {
|
class PIP_EXPORT PITimeMeasurer {
|
||||||
public:
|
public:
|
||||||
PITimeMeasurer();
|
PITimeMeasurer();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
|
|
||||||
/** \class PIVariant
|
/** \class PIVariant
|
||||||
* \brief Variant type
|
|
||||||
* \details
|
* \details
|
||||||
* \section PIVariant_sec0 Synopsis
|
* \section PIVariant_sec0 Synopsis
|
||||||
* This class provides general type that can contains all standard types, some
|
* This class provides general type that can contains all standard types, some
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define PIVARIANT_H
|
#define PIVARIANT_H
|
||||||
|
|
||||||
#include "pivarianttypes.h"
|
#include "pivarianttypes.h"
|
||||||
|
#include "piconstchars.h"
|
||||||
#include "pitime.h"
|
#include "pitime.h"
|
||||||
#include "pigeometry.h"
|
#include "pigeometry.h"
|
||||||
#include "pimathmatrix.h"
|
#include "pimathmatrix.h"
|
||||||
@@ -200,6 +201,9 @@ classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(c
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//! \ingroup Core
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Variant type.
|
||||||
class PIP_EXPORT PIVariant {
|
class PIP_EXPORT PIVariant {
|
||||||
friend PICout operator <<(PICout s, const PIVariant & v);
|
friend PICout operator <<(PICout s, const PIVariant & v);
|
||||||
friend PIByteArray & operator <<(PIByteArray & s, const PIVariant & v);
|
friend PIByteArray & operator <<(PIByteArray & s, const PIVariant & v);
|
||||||
@@ -801,7 +805,10 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVariant & v) {
|
|||||||
|
|
||||||
inline PICout operator <<(PICout s, const PIVariant & v) {
|
inline PICout operator <<(PICout s, const PIVariant & v) {
|
||||||
s.space(); s.setControl(0, true);
|
s.space(); s.setControl(0, true);
|
||||||
s << "PIVariant(" << v.typeName() << ", " << v.toString() << ")";
|
s << "PIVariant(" << v.typeName();
|
||||||
|
if (v.isValid())
|
||||||
|
s << ", " << v.toString();
|
||||||
|
s << ")";
|
||||||
s.restoreControl(); return s;
|
s.restoreControl(); return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ PIVector<PIIntrospection::ObjectInfo> PIIntrospection::getObjects() {
|
|||||||
for (int i = 0; i < ao.size_s(); ++i) {
|
for (int i = 0; i < ao.size_s(); ++i) {
|
||||||
ret[i].classname = PIStringAscii(ao[i]->className());
|
ret[i].classname = PIStringAscii(ao[i]->className());
|
||||||
ret[i].name = ao[i]->name();
|
ret[i].name = ao[i]->name();
|
||||||
ret[i].properties = ao[i]->properties();
|
//ret[i].properties = ao[i]->properties();
|
||||||
ret[i].parents = ao[i]->scopeList();
|
ret[i].parents = ao[i]->scopeList();
|
||||||
ao[i]->mutex_queue.lock();
|
ao[i]->mutex_queue.lock();
|
||||||
ret[i].queued_events = ao[i]->events_queue.size_s();
|
ret[i].queued_events = ao[i]->events_queue.size_s();
|
||||||
|
|||||||
@@ -791,7 +791,7 @@ void PIBinaryLog::configureFromVariantDevice(const PIPropertyStorage & d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIBinaryLog::propertyChanged(const PIString &s) {
|
void PIBinaryLog::propertyChanged(const char * s) {
|
||||||
default_id = property("defaultID").toInt();
|
default_id = property("defaultID").toInt();
|
||||||
rapid_start = property("rapidStart").toBool();
|
rapid_start = property("rapidStart").toBool();
|
||||||
play_mode = (PlayMode)property("playMode").toInt();
|
play_mode = (PlayMode)property("playMode").toInt();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
class PIP_EXPORT PIBinaryLog: public PIIODevice
|
class PIP_EXPORT PIBinaryLog: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIBinaryLog)
|
PIIODEVICE(PIBinaryLog, "binlog")
|
||||||
public:
|
public:
|
||||||
explicit PIBinaryLog();
|
explicit PIBinaryLog();
|
||||||
virtual ~PIBinaryLog();
|
virtual ~PIBinaryLog();
|
||||||
@@ -288,7 +288,6 @@ public:
|
|||||||
static bool cutBinLog(const BinLogInfo & src, const PIString & dst, int from, int to);
|
static bool cutBinLog(const BinLogInfo & src, const PIString & dst, int from, int to);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("binlog");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
@@ -297,7 +296,7 @@ protected:
|
|||||||
int writeDevice(const void * data, int size) {return writeBinLog(default_id, data, size);}
|
int writeDevice(const void * data, int size) {return writeBinLog(default_id, data, size);}
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
void propertyChanged(const PIString &);
|
void propertyChanged(const char * s);
|
||||||
bool threadedRead(uchar *readed, int size);
|
bool threadedRead(uchar *readed, int size);
|
||||||
void threadedReadTerminated() {pausemutex.unlock();}
|
void threadedReadTerminated() {pausemutex.unlock();}
|
||||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
class PIP_EXPORT PICAN: public PIIODevice
|
class PIP_EXPORT PICAN: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PICAN)
|
PIIODEVICE(PICAN, "can")
|
||||||
public:
|
public:
|
||||||
explicit PICAN(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PICAN(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PICAN();
|
virtual ~PICAN();
|
||||||
@@ -45,7 +45,6 @@ protected:
|
|||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
int readDevice(void * read_to, int max_size);
|
int readDevice(void * read_to, int max_size);
|
||||||
int writeDevice(const void * data, int max_size);
|
int writeDevice(const void * data, int max_size);
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("can");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
|
|||||||
@@ -45,17 +45,16 @@ extern "C" {
|
|||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*! \class PIDir
|
|
||||||
* \brief Local directory
|
//! \class PIDir pidir.h
|
||||||
*
|
//! \details
|
||||||
* \section PIDir_sec0 Synopsis
|
//! \~english \section PIDir_sec0 Synopsis
|
||||||
* This class provide access to local file. You can manipulate
|
//! \~russian \section PIDir_sec0 Краткий обзор
|
||||||
* binary content or use this class as text stream. To binary
|
//! \~english
|
||||||
* access there are function \a read(), \a write(), and many
|
//! This class provide access to local directory.
|
||||||
* \a writeBinary() functions. For write variables to file in
|
//!
|
||||||
* their text representation threr are many "<<" operators.
|
//! \~russian
|
||||||
*
|
//!
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
PIDir::PIDir(const PIString & dir) {
|
PIDir::PIDir(const PIString & dir) {
|
||||||
@@ -115,6 +114,15 @@ PIString PIDir::absolutePath() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \details
|
||||||
|
//! \~english
|
||||||
|
//! This function remove repeatedly separators and
|
||||||
|
//! resolve ".." in path. E.g. "/home/.//user/src/../.." will
|
||||||
|
//! become "/home". \n Returns reference to this %PIDir
|
||||||
|
//! \~russian
|
||||||
|
//! Этот метод удаляет повторяющиеся разделители и разрешает
|
||||||
|
//! "..". Например, путь "/home/.//user/src/../.." станет "/home". \n
|
||||||
|
//! Возвращает ссылку на этот %PIDir
|
||||||
PIDir & PIDir::cleanPath() {
|
PIDir & PIDir::cleanPath() {
|
||||||
PIString p(path_);
|
PIString p(path_);
|
||||||
if (p.isEmpty()) {
|
if (p.isEmpty()) {
|
||||||
@@ -236,6 +244,14 @@ bool PIDir::make(bool withParents) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIDir::rename(const PIString & new_name) {
|
||||||
|
if (!PIDir::rename(path(), new_name))
|
||||||
|
return false;
|
||||||
|
setDir(new_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
bool sort_compare(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {
|
bool sort_compare(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {
|
||||||
return strcoll(v0.path.data(), v1.path.data()) < 0;
|
return strcoll(v0.path.data(), v1.path.data()) < 0;
|
||||||
@@ -243,6 +259,20 @@ bool sort_compare(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! Scan this directory and returns all directories
|
||||||
|
//! and files in one list, sorted alphabetically. This list
|
||||||
|
//! contains also "." and ".." members. There are absolute
|
||||||
|
//! pathes in returned list.
|
||||||
|
//! \attention This function doesn`t scan content of inner
|
||||||
|
//! directories!
|
||||||
|
//! \~russian
|
||||||
|
//! Читает директорию и возвращает все директории и файлы
|
||||||
|
//! одним списком, сортированным по алфавиту. Список содержит
|
||||||
|
//! также "." и "..". Возвращаются абсолютные пути.
|
||||||
|
//! \attention Этот метод не читает содержимое директорий
|
||||||
|
//! рекурсивно!
|
||||||
PIVector<PIFile::FileInfo> PIDir::entries() {
|
PIVector<PIFile::FileInfo> PIDir::entries() {
|
||||||
PIVector<PIFile::FileInfo> l;
|
PIVector<PIFile::FileInfo> l;
|
||||||
if (!isExists()) return l;
|
if (!isExists()) return l;
|
||||||
@@ -322,6 +352,18 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! Scan this directory recursively and returns all
|
||||||
|
//! directories and files in one list, sorted alphabetically.
|
||||||
|
//! This list doesn`t contains "." and ".." members. There
|
||||||
|
//! are absolute pathes in returned list, and
|
||||||
|
//! files placed after directories in this list.
|
||||||
|
//! \~russian
|
||||||
|
//! Читает директорию рекурсивно и возвращает все директории и файлы
|
||||||
|
//! одним списком, сортированным по алфавиту. Список не содержит
|
||||||
|
//! "." и "..". Возвращаются абсолютные пути, причём файлы
|
||||||
|
//! располагаются после директорий.
|
||||||
PIVector<PIFile::FileInfo> PIDir::allEntries() {
|
PIVector<PIFile::FileInfo> PIDir::allEntries() {
|
||||||
PIVector<PIFile::FileInfo> ret;
|
PIVector<PIFile::FileInfo> ret;
|
||||||
PIVector<PIFile::FileInfo> dirs;
|
PIVector<PIFile::FileInfo> dirs;
|
||||||
|
|||||||
@@ -29,93 +29,146 @@
|
|||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Local directory.
|
||||||
|
//! \~russian Локальная директория.
|
||||||
class PIP_EXPORT PIDir
|
class PIP_EXPORT PIDir
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructs directory with path "path"
|
//! \~english Constructs directory with path "dir"
|
||||||
|
//! \~russian Создает директорию с путём "dir"
|
||||||
PIDir(const PIString & dir = PIString());
|
PIDir(const PIString & dir = PIString());
|
||||||
|
|
||||||
//! Constructs directory with "file" directory path "path"
|
//! \~english Constructs directory with "file" directory path
|
||||||
|
//! \~russian Создает директорию с путём директории файла "file"
|
||||||
PIDir(const PIFile & file);
|
PIDir(const PIFile & file);
|
||||||
|
|
||||||
|
|
||||||
//! Returns if this directory is exists
|
//! \~english Returns if this directory exists
|
||||||
|
//! \~russian Возвращает существует ли эта директория
|
||||||
bool isExists() const {return PIDir::isExists(path());}
|
bool isExists() const {return PIDir::isExists(path());}
|
||||||
|
|
||||||
//! Returns if path of this directory is absolute
|
//! \~english Returns if path of this directory is absolute
|
||||||
|
//! \~russian Возвращает абсолютный ли путь у директории
|
||||||
bool isAbsolute() const;
|
bool isAbsolute() const;
|
||||||
|
|
||||||
//! Returns if path of this directory is relative
|
//! \~english Returns if path of this directory is relative
|
||||||
|
//! \~russian Возвращает относительный ли путь у директории
|
||||||
bool isRelative() const {return !isAbsolute();}
|
bool isRelative() const {return !isAbsolute();}
|
||||||
|
|
||||||
//! Returns path of current reading directory. This path
|
//! \~english Returns path of current reading directory. This path valid only while \a allEntries() functions
|
||||||
//! valid only while \a allEntries functions
|
//! \~russian Возвращает путь текущей директории чтения. Этот путь действителен только во время выполнения метода \a allEntries()
|
||||||
const PIString & scanDir() const {return scan_;}
|
const PIString & scanDir() const {return scan_;}
|
||||||
|
|
||||||
|
|
||||||
//! Returns path of this directory
|
//! \~english Returns path of this directory
|
||||||
|
//! \~russian Возвращает путь директории
|
||||||
PIString path() const;
|
PIString path() const;
|
||||||
|
|
||||||
//! Returns absolute path of this directory
|
//! \~english Returns absolute path of this directory
|
||||||
|
//! \~russian Возвращает абсолютный путь директории
|
||||||
PIString absolutePath() const;
|
PIString absolutePath() const;
|
||||||
|
|
||||||
/** \brief Simplify path of this directory
|
//! \~english Simplify path of this directory
|
||||||
* \details This function remove repeatedly separators and
|
//! \~russian Упрощает путь директории
|
||||||
* resolve ".." in path. E.g. "/home/.//peri4/src/../.." will
|
|
||||||
* become "/home" \n This function returns reference to this %PIDir */
|
|
||||||
PIDir & cleanPath();
|
PIDir & cleanPath();
|
||||||
|
|
||||||
//! Returns %PIDir with simplified path of this directory
|
//! \~english Returns %PIDir with simplified path of this directory
|
||||||
|
//! \~russian Возвращает %PIDir с упрощённым путём директории
|
||||||
PIDir cleanedPath() const {PIDir d(path()); d.cleanPath(); return d;}
|
PIDir cleanedPath() const {PIDir d(path()); d.cleanPath(); return d;}
|
||||||
|
|
||||||
//! Returns relative to this directory path "path"
|
//! \~english Returns relative to this directory path "path"
|
||||||
|
//! \~russian Возвращает путь "path" относительно этой директории
|
||||||
PIString relative(const PIString & path) const;
|
PIString relative(const PIString & path) const;
|
||||||
|
|
||||||
//! Set this directory path to simplified "path"
|
//! \~english Set this directory path to simplified "path"
|
||||||
|
//! \~russian Устанавливает путь директории упрощённым "path"
|
||||||
PIDir & setDir(const PIString & path);
|
PIDir & setDir(const PIString & path);
|
||||||
|
|
||||||
//! Set this directory path as current for application
|
//! \~english Set this directory path as current for application
|
||||||
|
//! \~russian Устанавливает путь директории текущим путём приложения
|
||||||
bool setCurrent() {return PIDir::setCurrent(path());}
|
bool setCurrent() {return PIDir::setCurrent(path());}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Returns this directory content
|
//! \~english Returns this directory content
|
||||||
* \details Scan this directory and returns all directories
|
//! \~russian Возвращает содержимое этой директории
|
||||||
* and files in one list, sorted alphabetically. This list
|
|
||||||
* contains also "." and ".." members. There are absolute
|
|
||||||
* pathes in returned list.
|
|
||||||
* \attention This function doesn`t scan content of inner
|
|
||||||
* directories! */
|
|
||||||
PIVector<PIFile::FileInfo> entries();
|
PIVector<PIFile::FileInfo> entries();
|
||||||
|
|
||||||
/** \brief Returns all this directory content
|
//! \~english Returns this directory content recursively
|
||||||
* \details Scan this directory recursively and returns all
|
//! \~russian Возвращает содержимое этой директории рекурсивно
|
||||||
* directories and files in one list, sorted alphabetically.
|
|
||||||
* This list doesn`t contains "." and ".." members. There
|
|
||||||
* are absolute pathes in returned list, and
|
|
||||||
* files placed after directories in this list */
|
|
||||||
PIVector<PIFile::FileInfo> allEntries();
|
PIVector<PIFile::FileInfo> allEntries();
|
||||||
|
|
||||||
|
//! \~english Make this directory, recursively if "withParents"
|
||||||
|
//! \~russian Создаёт эту директорию, рекурсивно если "withParents"
|
||||||
bool make(bool withParents = true);
|
bool make(bool withParents = true);
|
||||||
|
|
||||||
|
//! \~english Remove this directory
|
||||||
|
//! \~russian Удаляет эту директорию
|
||||||
bool remove() {return PIDir::remove(path());}
|
bool remove() {return PIDir::remove(path());}
|
||||||
bool rename(const PIString & new_name) {if (!PIDir::rename(path(), new_name)) return false; setDir(new_name); return true;}
|
|
||||||
|
//! \~english Rename this directory
|
||||||
|
//! \~russian Переименовывает эту директорию
|
||||||
|
bool rename(const PIString & new_name);
|
||||||
|
|
||||||
|
//! \~english Change this directory to relative path "path"
|
||||||
|
//! \~russian Изменяет директорию на относительный путь "path"
|
||||||
PIDir & cd(const PIString & path);
|
PIDir & cd(const PIString & path);
|
||||||
|
|
||||||
|
//! \~english Change this directory to parent
|
||||||
|
//! \~russian Изменяет директорию на родительскую
|
||||||
PIDir & up() {return cd("..");}
|
PIDir & up() {return cd("..");}
|
||||||
|
|
||||||
|
//! \~english Compare operator
|
||||||
|
//! \~russian Оператор сравнения
|
||||||
bool operator ==(const PIDir & d) const;
|
bool operator ==(const PIDir & d) const;
|
||||||
|
|
||||||
|
//! \~english Compare operator
|
||||||
|
//! \~russian Оператор сравнения
|
||||||
bool operator !=(const PIDir & d) const {return !((*this) == d);}
|
bool operator !=(const PIDir & d) const {return !((*this) == d);}
|
||||||
|
|
||||||
static const PIChar separator;
|
static const PIChar separator;
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns current directory for application
|
||||||
|
//! \~russian Возвращает текущую директорию приложения
|
||||||
static PIDir current();
|
static PIDir current();
|
||||||
|
|
||||||
|
//! \~english Returns user home directory
|
||||||
|
//! \~russian Возвращает домашнюю директорию пользователя
|
||||||
static PIDir home();
|
static PIDir home();
|
||||||
|
|
||||||
|
//! \~english Returns temporary directory
|
||||||
|
//! \~russian Возвращает временную директорию
|
||||||
static PIDir temporary();
|
static PIDir temporary();
|
||||||
|
|
||||||
|
//! \~english Returns directory "path" content recursively
|
||||||
|
//! \~russian Возвращает содержимое директории "path" рекурсивно
|
||||||
static PIVector<PIFile::FileInfo> allEntries(const PIString & path);
|
static PIVector<PIFile::FileInfo> allEntries(const PIString & path);
|
||||||
|
|
||||||
|
//! \~english Returns if directory "path" exists
|
||||||
|
//! \~russian Возвращает существует ли эта директория
|
||||||
static bool isExists(const PIString & path);
|
static bool isExists(const PIString & path);
|
||||||
|
|
||||||
|
//! \~english Make directory "path", recursively if "withParents"
|
||||||
|
//! \~russian Создаёт директорию "path", рекурсивно если "withParents"
|
||||||
static bool make(const PIString & path, bool withParents = true);
|
static bool make(const PIString & path, bool withParents = true);
|
||||||
|
|
||||||
|
//! \~english Remove directory "path"
|
||||||
|
//! \~russian Удаляет директорию "path"
|
||||||
static bool remove(const PIString & path) {return removeDir(path);}
|
static bool remove(const PIString & path) {return removeDir(path);}
|
||||||
|
|
||||||
|
//! \~english Rename directory "path"
|
||||||
|
//! \~russian Переименовывает директорию "path"
|
||||||
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
|
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
|
||||||
|
|
||||||
|
//! \~english Set path "path" as current for application
|
||||||
|
//! \~russian Устанавливает путь "path" текущим путём приложения
|
||||||
static bool setCurrent(const PIString & path);
|
static bool setCurrent(const PIString & path);
|
||||||
|
|
||||||
|
//! \~english Set directory "dir" path as current for application
|
||||||
|
//! \~russian Устанавливает путь директории "dir" текущим путём приложения
|
||||||
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path());}
|
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path());}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -133,6 +186,9 @@ inline bool operator >(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1
|
|||||||
inline bool operator ==(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {return (v0.path == v1.path);}
|
inline bool operator ==(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {return (v0.path == v1.path);}
|
||||||
inline bool operator !=(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {return (v0.path != v1.path);}
|
inline bool operator !=(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {return (v0.path != v1.path);}
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PIDir & v) {s.setControl(0, true); s << "PIDir(\"" << v.path() << "\")"; s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const PIDir & v) {s.setControl(0, true); s << "PIDir(\"" << v.path() << "\")"; s.restoreControl(); return s;}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
#include "piconstchars.h"
|
||||||
#ifdef QNX
|
#ifdef QNX
|
||||||
# include <net/if.h>
|
# include <net/if.h>
|
||||||
# include <net/if_dl.h>
|
# include <net/if_dl.h>
|
||||||
@@ -919,10 +920,11 @@ bool PIEthernet::configureDevice(const void * e_main, const void * e_parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIEthernet::propertyChanged(const PIString & name) {
|
void PIEthernet::propertyChanged(const char * name) {
|
||||||
if (name.endsWith("Timeout")) applyTimeouts();
|
PIConstChars pn(name);
|
||||||
if (name == "TTL") applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
if (pn.endsWith("Timeout")) applyTimeouts();
|
||||||
if (name == "MulticastTTL") applyOptInt(IPPROTO_IP, IP_MULTICAST_TTL, multicastTTL());
|
if (pn == "TTL") applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
||||||
|
if (pn == "MulticastTTL") applyOptInt(IPPROTO_IP, IP_MULTICAST_TTL, multicastTTL());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1001,24 +1003,23 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
|||||||
ci.index = -1;
|
ci.index = -1;
|
||||||
ci.mtu = 1500;
|
ci.mtu = 1500;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PIP_ADAPTER_INFO pAdapterInfo, pAdapter = 0;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||||
pAdapterInfo = (IP_ADAPTER_INFO * ) HeapAlloc(GetProcessHeap(), 0, (sizeof (IP_ADAPTER_INFO)));
|
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
|
||||||
if (pAdapterInfo == 0) {
|
if (!pAdapterInfo) {
|
||||||
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersinfo";
|
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersInfo";
|
||||||
return il;
|
return il;
|
||||||
}
|
}
|
||||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
||||||
HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
|
HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
||||||
pAdapterInfo = (IP_ADAPTER_INFO *) HeapAlloc(GetProcessHeap(), 0, (ulOutBufLen));
|
pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, ulOutBufLen);
|
||||||
if (pAdapterInfo == 0) {
|
if (!pAdapterInfo) {
|
||||||
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersinfo";
|
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersInfo";
|
||||||
return il;
|
return il;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
if ((ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
||||||
pAdapter = pAdapterInfo;
|
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||||
while (pAdapter) {
|
while (pAdapter) {
|
||||||
ci.name = PIString(pAdapter->AdapterName);
|
ci.name = PIString(pAdapter->AdapterName);
|
||||||
ci.index = pAdapter->Index;
|
ci.index = pAdapter->Index;
|
||||||
@@ -1031,8 +1032,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
|||||||
IP_ADDR_STRING * as = &(pAdapter->IpAddressList);
|
IP_ADDR_STRING * as = &(pAdapter->IpAddressList);
|
||||||
while (as) {
|
while (as) {
|
||||||
// piCout << "[pAdapter]" << ci.name << PIString(as->IpAddress.String);
|
// piCout << "[pAdapter]" << ci.name << PIString(as->IpAddress.String);
|
||||||
ci.address = PIString(as->IpAddress.String);
|
ci.address = PIStringAscii(as->IpAddress.String);
|
||||||
ci.netmask = PIString(as->IpMask.String);
|
ci.netmask = PIStringAscii(as->IpMask.String);
|
||||||
if (ci.address == "0.0.0.0") {
|
if (ci.address == "0.0.0.0") {
|
||||||
as = as->Next;
|
as = as->Next;
|
||||||
continue;
|
continue;
|
||||||
@@ -1053,7 +1054,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pAdapterInfo)
|
if (pAdapterInfo)
|
||||||
HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
|
HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
||||||
#else
|
#else
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
#else
|
#else
|
||||||
@@ -1213,10 +1214,16 @@ int PIEthernet::ethErrorCore() {
|
|||||||
|
|
||||||
PIString PIEthernet::ethErrorString() {
|
PIString PIEthernet::ethErrorString() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
char * msg;
|
char * msg = nullptr;
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, NULL);
|
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 " + PIString::fromNumber(err) + " - " + PIString(msg);
|
PIString ret = PIStringAscii("code ") + PIString::fromNumber(err) + PIStringAscii(" - ");
|
||||||
|
if (msg) {
|
||||||
|
ret += PIString::fromSystem(msg).trim();
|
||||||
|
LocalFree(msg);
|
||||||
|
} else
|
||||||
|
ret += '?';
|
||||||
|
return ret;
|
||||||
#else
|
#else
|
||||||
return errorString();
|
return errorString();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class
|
|||||||
|
|
||||||
class PIP_EXPORT PIEthernet: public PIIODevice
|
class PIP_EXPORT PIEthernet: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIEthernet)
|
PIIODEVICE(PIEthernet, "eth")
|
||||||
friend class PIPeer;
|
friend class PIPeer;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -201,44 +201,44 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! Set parameters to "parameters_". You should to reopen %PIEthernet to apply them
|
//! Set parameters to "parameters_". You should to reopen %PIEthernet to apply them
|
||||||
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty(PIStringAscii("parameters"), (int)parameters_);}
|
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty("parameters", (int)parameters_);}
|
||||||
|
|
||||||
//! Set parameter "parameter" to state "on". You should to reopen %PIEthernet to apply this
|
//! Set parameter "parameter" to state "on". You should to reopen %PIEthernet to apply this
|
||||||
void setParameter(PIEthernet::Parameters parameter, bool on = true);
|
void setParameter(PIEthernet::Parameters parameter, bool on = true);
|
||||||
|
|
||||||
//! Returns if parameter "parameter" is set
|
//! Returns if parameter "parameter" is set
|
||||||
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt()))[parameter];}
|
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property("parameters").toInt()))[parameter];}
|
||||||
|
|
||||||
//! Returns parameters
|
//! Returns parameters
|
||||||
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt());}
|
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property("parameters").toInt());}
|
||||||
|
|
||||||
//! Returns %PIEthernet type
|
//! Returns %PIEthernet type
|
||||||
Type type() const {return (Type)(property(PIStringAscii("type")).toInt());}
|
Type type() const {return (Type)(property("type").toInt());}
|
||||||
|
|
||||||
//! Returns read timeout
|
//! Returns read timeout
|
||||||
double readTimeout() const {return property(PIStringAscii("readTimeout")).toDouble();}
|
double readTimeout() const {return property("readTimeout").toDouble();}
|
||||||
|
|
||||||
//! Returns write timeout
|
//! Returns write timeout
|
||||||
double writeTimeout() const {return property(PIStringAscii("writeTimeout")).toDouble();}
|
double writeTimeout() const {return property("writeTimeout").toDouble();}
|
||||||
|
|
||||||
//! Set timeout for read
|
//! Set timeout for read
|
||||||
void setReadTimeout(double ms) {setProperty(PIStringAscii("readTimeout"), ms);}
|
void setReadTimeout(double ms) {setProperty("readTimeout", ms);}
|
||||||
|
|
||||||
//! Set timeout for write
|
//! Set timeout for write
|
||||||
void setWriteTimeout(double ms) {setProperty(PIStringAscii("writeTimeout"), ms);}
|
void setWriteTimeout(double ms) {setProperty("writeTimeout", ms);}
|
||||||
|
|
||||||
|
|
||||||
//! Returns TTL (Time To Live)
|
//! Returns TTL (Time To Live)
|
||||||
int TTL() const {return property(PIStringAscii("TTL")).toInt();}
|
int TTL() const {return property("TTL").toInt();}
|
||||||
|
|
||||||
//! Returns multicast TTL (Time To Live)
|
//! Returns multicast TTL (Time To Live)
|
||||||
int multicastTTL() const {return property(PIStringAscii("MulticastTTL")).toInt();}
|
int multicastTTL() const {return property("MulticastTTL").toInt();}
|
||||||
|
|
||||||
//! Set TTL (Time To Live), default is 64
|
//! Set TTL (Time To Live), default is 64
|
||||||
void setTTL(int ttl) {setProperty(PIStringAscii("TTL"), ttl);}
|
void setTTL(int ttl) {setProperty("TTL", ttl);}
|
||||||
|
|
||||||
//! Set multicast TTL (Time To Live), default is 1
|
//! Set multicast TTL (Time To Live), default is 1
|
||||||
void setMulticastTTL(int ttl) {setProperty(PIStringAscii("MulticastTTL"), ttl);}
|
void setMulticastTTL(int ttl) {setProperty("MulticastTTL", ttl);}
|
||||||
|
|
||||||
|
|
||||||
//! Join to multicast group with address "group". Use only for UDP
|
//! Join to multicast group with address "group". Use only for UDP
|
||||||
@@ -462,9 +462,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
explicit PIEthernet(int sock, PIString ip_port);
|
explicit PIEthernet(int sock, PIString ip_port);
|
||||||
|
|
||||||
void propertyChanged(const PIString & name);
|
void propertyChanged(const char * name);
|
||||||
|
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("eth");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
@@ -499,7 +498,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
EVENT_HANDLER1(void, clientDeleted, PIObject *, o);
|
EVENT_HANDLER1(void, clientDeleted, PIObject *, o);
|
||||||
static void server_func(void * eth);
|
static void server_func(void * eth);
|
||||||
void setType(Type t, bool reopen = true) {setProperty(PIStringAscii("type"), (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
|
void setType(Type t, bool reopen = true) {setProperty("type", (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
|
||||||
|
|
||||||
static int ethErrorCore();
|
static int ethErrorCore();
|
||||||
static PIString ethErrorString();
|
static PIString ethErrorString();
|
||||||
|
|||||||
@@ -69,25 +69,44 @@
|
|||||||
# define _stat_link_ lstat64
|
# define _stat_link_ lstat64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*! \class PIFile
|
|
||||||
* \brief Local file
|
//! \class PIFile pifile.h
|
||||||
*
|
//! \details
|
||||||
* \section PIFile_sec0 Synopsis
|
//! \~english \section PIFile_sec0 Synopsis
|
||||||
* This class provide access to local file. You can manipulate
|
//! \~russian \section PIFile_sec0 Краткий обзор
|
||||||
* binary content or use this class as text stream. To binary
|
//! \~english
|
||||||
* access there are function \a read(), \a write(), and many
|
//!
|
||||||
* \a writeBinary() functions. For write variables to file in
|
//! This class provide access to local file. You can manipulate
|
||||||
* their text representation threr are many "<<" operators.
|
//! binary content or use this class as text stream. To binary
|
||||||
*
|
//! access there are function \a read(), \a write(), and many
|
||||||
* \section PIFile_sec1 Position
|
//! \a writeBinary() functions. For write and read variables to file in
|
||||||
* Each opened file has a read/write position - logical position
|
//! their text representation there are many "<<" and ">>" operators.
|
||||||
* in the file content you read from or you write to. You can
|
//!
|
||||||
* find out current position with function \a pos(). Function
|
//! \~russian
|
||||||
* \a seek(llong position) move position to position "position",
|
//! Этот класс предоставляет доступ к локальному файлу. Можно
|
||||||
* \a seekToBegin() move position to the begin of file,
|
//! работать на байтовом уровне, либо использовать его как
|
||||||
* \a seekToEnd() move position to the end of file.
|
//! текстовый поток. Для байтового доступа используются методы
|
||||||
*
|
//! \a read(), \a write(), и много \a writeBinary() методов.
|
||||||
*/
|
//! Для записи и чтения переменных в текстовом представлении
|
||||||
|
//! используются операторы "<<" и ">>".
|
||||||
|
//!
|
||||||
|
//! \~english \section PIFile_sec1 Position
|
||||||
|
//! \~russian \section PIFile_sec1 Позиция
|
||||||
|
//! \~english
|
||||||
|
//! Each opened file has a read/write position - logical position
|
||||||
|
//! in the file content you read from or you write to. You can
|
||||||
|
//! find out current position with function \a pos(). Function
|
||||||
|
//! \a seek(llong position) move position to position "position",
|
||||||
|
//! \a seekToBegin() move position to the begin of file,
|
||||||
|
//! \a seekToEnd() move position to the end of file.
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Каждый файл имеет позицию чтения/записи - логическое положение
|
||||||
|
//! в содержимом файла, откуда производится чтение или запись.
|
||||||
|
//! Узнать текущую позицию можно с помощью метода \a pos().
|
||||||
|
//! Метод \a seek(llong position) перемещает позицию на указанную,
|
||||||
|
//! \a seekToBegin() перемещает её в начало файла, а \a seekToEnd() - в конец.
|
||||||
|
//!
|
||||||
|
|
||||||
REGISTER_DEVICE(PIFile)
|
REGISTER_DEVICE(PIFile)
|
||||||
|
|
||||||
@@ -614,7 +633,7 @@ int PIFile::writeDevice(const void * data, int max_size) {
|
|||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(const PIString & v) {
|
PIFile &PIFile::operator <<(const PIString & v) {
|
||||||
if (canWrite() && PRIVATE->fd != 0)
|
if (canWrite() && v.isNotEmpty() && PRIVATE->fd != 0)
|
||||||
*this << v.toCharset(defaultCharset());
|
*this << v.toCharset(defaultCharset());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,30 +30,62 @@
|
|||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Local file.
|
||||||
|
//! \~russian Локальный файл.
|
||||||
class PIP_EXPORT PIFile: public PIIODevice
|
class PIP_EXPORT PIFile: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIFile)
|
PIIODEVICE(PIFile, "file")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructs an empty file
|
//! \~english Constructs file with empty path
|
||||||
|
//! \~russian Создает файл с пустым путём
|
||||||
explicit PIFile();
|
explicit PIFile();
|
||||||
|
|
||||||
|
//! \~english Constructs a file with path "path" and open mode "mode". Open if "path" is not empty
|
||||||
|
//! \~russian Создает файл с путём "path" и режимом открытия "mode". Открывает если "path" не пустой
|
||||||
|
explicit PIFile(const PIString & path, DeviceMode mode = ReadWrite);
|
||||||
|
|
||||||
|
virtual ~PIFile();
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Local file or directory information.
|
||||||
|
//! \~russian Информация о локальном файле или директории.
|
||||||
struct PIP_EXPORT FileInfo {
|
struct PIP_EXPORT FileInfo {
|
||||||
|
|
||||||
|
//! \~english Constructs %FileInfo with path "path_". No information gathered
|
||||||
|
//! \~russian Создает %FileInfo с путём "path_". Информация не собирается
|
||||||
FileInfo(const PIString & path_ = PIString()) {path = path_; size = 0; id_group = id_user = 0;}
|
FileInfo(const PIString & path_ = PIString()) {path = path_; size = 0; id_group = id_user = 0;}
|
||||||
|
|
||||||
|
//! \~english Type flags
|
||||||
|
//! \~russian Флаги типа
|
||||||
enum Flag {
|
enum Flag {
|
||||||
File = 0x01,
|
File /*! \~english File \~russian Файл */ = 0x01,
|
||||||
Dir = 0x02,
|
Dir /*! \~english Directory \~russian Директория */ = 0x02,
|
||||||
Dot = 0x04,
|
Dot /*! \~english '.', current directory \~russian '.', текущая директория */ = 0x04,
|
||||||
DotDot = 0x08,
|
DotDot /*! \~english '..', parent directory \~russian '..', родительская директория */ = 0x08,
|
||||||
SymbolicLink = 0x10,
|
SymbolicLink /*! \~english Symbolic link \~russian Символическая ссылка */ = 0x10,
|
||||||
Hidden = 0x20
|
Hidden /*! \~english Hidden \~russian Скрытый */ = 0x20
|
||||||
};
|
};
|
||||||
typedef PIFlags<FileInfo::Flag> Flags;
|
typedef PIFlags<FileInfo::Flag> Flags;
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Local file or directory permissions.
|
||||||
|
//! \~russian Разрешения локального файла или директории.
|
||||||
struct PIP_EXPORT Permissions {
|
struct PIP_EXPORT Permissions {
|
||||||
Permissions(uchar r = 0): raw(r) {}
|
Permissions(uchar r = 0): raw(r) {}
|
||||||
Permissions(bool r, bool w, bool e): raw(0) {read = r; write = w; exec = e;}
|
Permissions(bool r, bool w, bool e): raw(0) {read = r; write = w; exec = e;}
|
||||||
|
|
||||||
|
//! \~english Returns as string (from "---" to "rwx")
|
||||||
|
//! \~russian Возвращает как строку (от "---" до "rwx")
|
||||||
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
||||||
|
|
||||||
|
//! \~english Convertion to \c int
|
||||||
|
//! \~russian Преобразование в \c int
|
||||||
operator int() const {return raw;}
|
operator int() const {return raw;}
|
||||||
Permissions & operator =(int v) {raw = v; return *this;}
|
Permissions & operator =(int v) {raw = v; return *this;}
|
||||||
union {
|
union {
|
||||||
@@ -66,175 +98,321 @@ public:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \~english Path
|
||||||
|
//! \~russian Путь
|
||||||
PIString path;
|
PIString path;
|
||||||
|
|
||||||
|
//! \~english File size
|
||||||
|
//! \~russian Размер файла
|
||||||
llong size;
|
llong size;
|
||||||
|
|
||||||
|
//! \~english Last access time
|
||||||
|
//! \~russian Время последнего доступа
|
||||||
PIDateTime time_access;
|
PIDateTime time_access;
|
||||||
|
|
||||||
|
//! \~english Last modification time
|
||||||
|
//! \~russian Время последнего изменения
|
||||||
PIDateTime time_modification;
|
PIDateTime time_modification;
|
||||||
|
|
||||||
|
//! \~english Flags
|
||||||
|
//! \~russian Флаги
|
||||||
Flags flags;
|
Flags flags;
|
||||||
|
|
||||||
|
//! \~english User ID
|
||||||
|
//! \~russian ID пользователя
|
||||||
uint id_user;
|
uint id_user;
|
||||||
|
|
||||||
|
//! \~english Group ID
|
||||||
|
//! \~russian ID группы
|
||||||
uint id_group;
|
uint id_group;
|
||||||
|
|
||||||
|
//! \~english Permissions for user
|
||||||
|
//! \~russian Разрешения для пользователя
|
||||||
Permissions perm_user;
|
Permissions perm_user;
|
||||||
|
|
||||||
|
//! \~english Permissions for group
|
||||||
|
//! \~russian Разрешения для группы
|
||||||
Permissions perm_group;
|
Permissions perm_group;
|
||||||
|
|
||||||
|
//! \~english Permissions for other
|
||||||
|
//! \~russian Разрешения для остальных
|
||||||
Permissions perm_other;
|
Permissions perm_other;
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns name, without directory
|
||||||
|
//! \~russian Возвращает имя, без директории
|
||||||
PIString name() const;
|
PIString name() const;
|
||||||
|
|
||||||
|
//! \~english Returns base name, without directory and extension
|
||||||
|
//! \~russian Возвращает базовое имя, без директории и расширения
|
||||||
PIString baseName() const;
|
PIString baseName() const;
|
||||||
|
|
||||||
|
//! \~english Returns extension
|
||||||
|
//! \~russian Возвращает расширение
|
||||||
PIString extension() const;
|
PIString extension() const;
|
||||||
|
|
||||||
|
//! \~english Returns directory
|
||||||
|
//! \~russian Возвращает директорию
|
||||||
PIString dir() const;
|
PIString dir() const;
|
||||||
|
|
||||||
|
//! \~english Returns if it`s directory
|
||||||
|
//! \~russian Возвращает директория ли это
|
||||||
bool isDir() const {return flags[Dir];}
|
bool isDir() const {return flags[Dir];}
|
||||||
|
|
||||||
|
//! \~english Returns if it`s file
|
||||||
|
//! \~russian Возвращает файл ли это
|
||||||
bool isFile() const {return flags[File];}
|
bool isFile() const {return flags[File];}
|
||||||
|
|
||||||
|
//! \~english Returns if it`s symbolic link
|
||||||
|
//! \~russian Возвращает символическая ссылка ли это
|
||||||
bool isSymbolicLink() const {return flags[SymbolicLink];}
|
bool isSymbolicLink() const {return flags[SymbolicLink];}
|
||||||
|
|
||||||
|
//! \~english Returns if Hidden flag set
|
||||||
|
//! \~russian Возвращает установлен ли флаг Hidden
|
||||||
bool isHidden() const {return flags[Hidden];}
|
bool isHidden() const {return flags[Hidden];}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Constructs a file with path "path" and open mode "mode"
|
|
||||||
//! If "path" is not empty then open file
|
|
||||||
explicit PIFile(const PIString & path, DeviceMode mode = ReadWrite);
|
|
||||||
|
|
||||||
|
//! \~english Open temporary file with open mode "mode"
|
||||||
//! Open temporary file with open mode "mode"
|
//! \~russian Открывает временный файл с режимом открытия "mode"
|
||||||
bool openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
bool openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
virtual ~PIFile();
|
//! \~english Immediate write all buffered data to disk
|
||||||
|
//! \~russian Немедленно записывает все буферизированные данные на диск
|
||||||
//! Immediate write all buffered data to disk
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
//! Move read/write position to "position"
|
//! \~english Move read/write position to "position"
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на "position"
|
||||||
void seek(llong position);
|
void seek(llong position);
|
||||||
|
|
||||||
//! Move read/write position to the begin of the file
|
//! \~english Move read/write position to the begin of the file
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на начало файла
|
||||||
void seekToBegin();
|
void seekToBegin();
|
||||||
|
|
||||||
//! Move read/write position to the end of the file
|
//! \~english Move read/write position to the end of the file
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на конец файла
|
||||||
void seekToEnd();
|
void seekToEnd();
|
||||||
|
|
||||||
//! Move read/write position to text line number "line"
|
//! \~english Move read/write position to text line number "line" beginning
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на начало текстовой строки номер "line"
|
||||||
void seekToLine(llong line);
|
void seekToLine(llong line);
|
||||||
|
|
||||||
//! Skip "bytes" bytes (move position next to "bytes" bytes)
|
//! \~english Skip "bytes" bytes (move position next to "bytes" bytes)
|
||||||
|
//! \~russian Пропускает "bytes" байт (перемещает позицию на "bytes" байт вперёд)
|
||||||
void skip(llong bytes);
|
void skip(llong bytes);
|
||||||
|
|
||||||
//! Read one char and return it
|
//! \~english Read one char and return it
|
||||||
|
//! \~russian Читает один байт и возвращает его
|
||||||
char readChar();
|
char readChar();
|
||||||
|
|
||||||
//! Read one text line and return it
|
//! \~english Read one text line and return it
|
||||||
|
//! \~russian Читает одну текстовую строку и возвращает её
|
||||||
PIString readLine();
|
PIString readLine();
|
||||||
|
|
||||||
//! Read all file content to "data" and return readed bytes count. Position leaved unchanged
|
//! \~english Read all file content to "data" and return readed bytes count. Position leaved unchanged
|
||||||
|
//! \~russian Читает всё содержимое файла в "data" и возвращает количество прочитанных байт. Позиция остаётся неизменной
|
||||||
llong readAll(void * data);
|
llong readAll(void * data);
|
||||||
|
|
||||||
//! Read all file content to byte array and return it. Position leaved unchanged
|
//! \~english Read all file content to byte array and return it. Position leaved unchanged
|
||||||
|
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
|
||||||
PIByteArray readAll(bool forceRead = false);
|
PIByteArray readAll(bool forceRead = false);
|
||||||
|
|
||||||
|
|
||||||
//! Set file path to "path" and reopen file if need
|
//! \~english Set file path to "path" and reopen file if need
|
||||||
|
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
|
||||||
void setPath(const PIString & path);
|
void setPath(const PIString & path);
|
||||||
|
|
||||||
//! Returns file size
|
//! \~english Returns file size in bytes
|
||||||
|
//! \~russian Возвращает размер файла в байтах
|
||||||
llong size() const;
|
llong size() const;
|
||||||
|
|
||||||
//! Returns read/write position
|
//! \~english Returns read/write position
|
||||||
|
//! \~russian Возвращает позицию чтения/записи
|
||||||
llong pos() const;
|
llong pos() const;
|
||||||
|
|
||||||
//! Returns if position is at the end of file
|
//! \~english Returns if position is at the end of file
|
||||||
|
//! \~russian Возвращает достигнут ли конец файла
|
||||||
bool isEnd() const;
|
bool isEnd() const;
|
||||||
|
|
||||||
//! Returns if file is empty
|
//! \~english Returns if file is empty
|
||||||
|
//! \~russian Возвращает пустой ли файл
|
||||||
bool isEmpty() const {return (size() <= 0);}
|
bool isEmpty() const {return (size() <= 0);}
|
||||||
|
|
||||||
//! Returns FileInfo of current file
|
//! \~english Returns \a PIFile::FileInfo of current file
|
||||||
|
//! \~russian Возвращает \a PIFile::FileInfo текущего файла
|
||||||
FileInfo fileInfo() const {return fileInfo(path());}
|
FileInfo fileInfo() const {return fileInfo(path());}
|
||||||
|
|
||||||
|
|
||||||
//! Returns float numbers write precision
|
//! \~english Returns float numbers write precision
|
||||||
|
//! \~russian Возвращает точность записи чисел с плавающей точкой
|
||||||
int precision() const {return prec_;}
|
int precision() const {return prec_;}
|
||||||
|
|
||||||
//! Set float numbers write precision to "prec_" digits
|
//! \~english Set float numbers write precision to "prec_" digits
|
||||||
|
//! \~russian Устанавливает точность записи чисел с плавающей точкой
|
||||||
void setPrecision(int prec);
|
void setPrecision(int prec);
|
||||||
|
|
||||||
|
//! \~english Write size and content of "v" (serialize)
|
||||||
|
//! \~russian Пишет в файл размер и содержимое "v" (сериализация)
|
||||||
PIFile & put(const PIByteArray & v);
|
PIFile & put(const PIByteArray & v);
|
||||||
|
|
||||||
|
//! \~english Read size of byte array and it content (deserialize)
|
||||||
|
//! \~russian Читает из файла размер байтового массива и его содержимое (десериализация)
|
||||||
PIByteArray get();
|
PIByteArray get();
|
||||||
|
|
||||||
|
|
||||||
//! Write to file binary content of "v"
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const short v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const short v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const int v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const int v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const long v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const long v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const llong v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const llong v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const uchar v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const uchar v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const ushort v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const ushort v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const uint v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const uint v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const ulong v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const ulong v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const ullong v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const ullong v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const float v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const float v) {write(&v, sizeof(v)); return *this;}
|
||||||
//! Write to file binary content of "v"
|
|
||||||
|
//! \~english Write to file binary content of "v"
|
||||||
|
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||||
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
|
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
|
||||||
|
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(const char v);
|
PIFile & operator <<(const char v);
|
||||||
//! Write to file string "v"
|
|
||||||
|
//! \~english Write to file string "v"
|
||||||
|
//! \~russian Пишет в файл строку "v"
|
||||||
PIFile & operator <<(const PIString & v);
|
PIFile & operator <<(const PIString & v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(const PIByteArray & v);
|
PIFile & operator <<(const PIByteArray & v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(short v);
|
PIFile & operator <<(short v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(int v);
|
PIFile & operator <<(int v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(long v);
|
PIFile & operator <<(long v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(llong v);
|
PIFile & operator <<(llong v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(uchar v);
|
PIFile & operator <<(uchar v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(ushort v);
|
PIFile & operator <<(ushort v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(uint v);
|
PIFile & operator <<(uint v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(ulong v);
|
PIFile & operator <<(ulong v);
|
||||||
//! Write to file text representation of "v"
|
|
||||||
|
//! \~english Write to file text representation of "v"
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v"
|
||||||
PIFile & operator <<(ullong v);
|
PIFile & operator <<(ullong v);
|
||||||
//! Write to file text representation of "v" with precision \a precision()
|
|
||||||
|
//! \~english Write to file text representation of "v" with precision \a precision()
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
|
||||||
PIFile & operator <<(float v);
|
PIFile & operator <<(float v);
|
||||||
//! Write to file text representation of "v" with precision \a precision()
|
|
||||||
|
//! \~english Write to file text representation of "v" with precision \a precision()
|
||||||
|
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
|
||||||
PIFile & operator <<(double v);
|
PIFile & operator <<(double v);
|
||||||
|
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(char & v);
|
PIFile & operator >>(char & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(short & v);
|
PIFile & operator >>(short & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(int & v);
|
PIFile & operator >>(int & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(long & v);
|
PIFile & operator >>(long & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(llong & v);
|
PIFile & operator >>(llong & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(uchar & v);
|
PIFile & operator >>(uchar & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(ushort & v);
|
PIFile & operator >>(ushort & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(uint & v);
|
PIFile & operator >>(uint & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(ulong & v);
|
PIFile & operator >>(ulong & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(ullong & v);
|
PIFile & operator >>(ullong & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(float & v);
|
PIFile & operator >>(float & v);
|
||||||
//! Read from file text representation of "v"
|
|
||||||
|
//! \~english Read from file text representation of "v"
|
||||||
|
//! \~russian Читает из файла текстовое представление "v"
|
||||||
PIFile & operator >>(double & v);
|
PIFile & operator >>(double & v);
|
||||||
|
|
||||||
EVENT_HANDLER(void, clear);
|
EVENT_HANDLER(void, clear);
|
||||||
@@ -242,44 +420,56 @@ public:
|
|||||||
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
||||||
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
|
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
|
||||||
|
|
||||||
//!
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
static const char * defaultCharset();
|
static const char * defaultCharset();
|
||||||
|
|
||||||
//!
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
static void setDefaultCharset(const char * c);
|
static void setDefaultCharset(const char * c);
|
||||||
|
|
||||||
//! Returns if file with path "path" does exists
|
//! \~english Returns if file with path "path" exists
|
||||||
|
//! \~russian Возвращает существует ли файл с путём "path"
|
||||||
static bool isExists(const PIString & path);
|
static bool isExists(const PIString & path);
|
||||||
|
|
||||||
//! Remove file with path "path" and returns if remove was successful
|
//! \~english Remove file with path "path" and returns if remove successful
|
||||||
|
//! \~russian Удаляет файл с путём "path" и возвращает успешность операции
|
||||||
static bool remove(const PIString & path);
|
static bool remove(const PIString & path);
|
||||||
|
|
||||||
//! Rename file with path "from" to path "to" and returns if rename was successful
|
//! \~english Rename file with path "from" to path "to" and returns if rename successful
|
||||||
|
//! \~russian Переименовывает файл с путём "path" на "to" и возвращает успешность операции
|
||||||
static bool rename(const PIString & from, const PIString & to);
|
static bool rename(const PIString & from, const PIString & to);
|
||||||
|
|
||||||
//! Returns FileInfo of file or dir with path "path"
|
//! \~english Returns \a PIFile::FileInfo of file or dir with path "path"
|
||||||
|
//! \~russian Возвращает \a PIFile::FileInfo файла или директории с путём "path"
|
||||||
static FileInfo fileInfo(const PIString & path);
|
static FileInfo fileInfo(const PIString & path);
|
||||||
|
|
||||||
//! Apply "info" parameters to file or dir with path "path"
|
//! \~english Apply "info" parameters to file or dir with path "path"
|
||||||
|
//! \~russian Применяет параметры "info" к файлу или директории с путём "path"
|
||||||
static bool applyFileInfo(const PIString & path, const FileInfo & info);
|
static bool applyFileInfo(const PIString & path, const FileInfo & info);
|
||||||
|
|
||||||
//! Apply "info" parameters to file or dir with path "info".path
|
//! \~english Apply "info" parameters to file or dir with path "info".path
|
||||||
|
//! \~russian Применяет параметры "info" к файлу или директории с путём "info".path
|
||||||
static bool applyFileInfo(const FileInfo & info) {return applyFileInfo(info.path, info);}
|
static bool applyFileInfo(const FileInfo & info) {return applyFileInfo(info.path, info);}
|
||||||
|
|
||||||
//! \handlers
|
//! \handlers
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn void clear()
|
//! \fn void clear()
|
||||||
//! \brief Clear content of file
|
//! \~english Clear content of file
|
||||||
|
//! \~russian Очищает содержимое файла
|
||||||
|
|
||||||
//! \fn void resize(llong new_size)
|
//! \fn void resize(llong new_size)
|
||||||
//! \brief Resize file to "new_size" with "fill" filling
|
//! \~english Resize file to "new_size" with null-byte fill
|
||||||
|
//! \~russian Изменяет размер файла на "new_size" с заполнением нулевыми байтами
|
||||||
|
|
||||||
//! \fn void resize(llong new_size, uchar fill)
|
//! \fn void resize(llong new_size, uchar fill)
|
||||||
//! \brief Resize file to "new_size" with "fill" filling
|
//! \~english Resize file to "new_size" with "fill" fill
|
||||||
|
//! \~russian Изменяет размер файла на "new_size" с заполнением байтами "fill"
|
||||||
|
|
||||||
//! \fn void remove()
|
//! \fn void remove()
|
||||||
//! \brief Remove file
|
//! \~english Remove file
|
||||||
|
//! \~russian Удаляет файл
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
//! \ioparams
|
//! \ioparams
|
||||||
@@ -289,7 +479,6 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("file");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
@@ -311,6 +500,10 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
|
inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
s << "FileInfo(\"" << v.path << "\", " << PIString::readableSize(v.size) << ", "
|
s << "FileInfo(\"" << v.path << "\", " << PIString::readableSize(v.size) << ", "
|
||||||
@@ -322,9 +515,17 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Store operator
|
||||||
|
//! \~russian Оператор сохранения
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification <<
|
inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification <<
|
||||||
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
|
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Restore operator
|
||||||
|
//! \~russian Оператор извлечения
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >>
|
inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >>
|
||||||
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
|
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
|
||||||
|
|
||||||
|
|
||||||
#endif // PIFILE_H
|
#endif // PIFILE_H
|
||||||
|
|||||||
@@ -28,25 +28,40 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*! \class PIGPIO
|
//! \class PIGPIO pigpio.h
|
||||||
* \brief GPIO support
|
//! \~english \section PIGPIO_sec0 Synopsis
|
||||||
*
|
//! \~russian \section PIGPIO_sec0 Краткий обзор
|
||||||
* \section PIGPIO_sec0 Synopsis
|
//! \~english
|
||||||
* This class provide initialize, get/set and watch functions for GPIO.
|
//! This class provide initialize, get/set and watch functions for GPIO.
|
||||||
*
|
//!
|
||||||
* Currently supported only \"/sys/class/gpio\" mechanism on Linux.
|
//! This class should be used with \a PIGPIO::instance() singleton.
|
||||||
*
|
//!
|
||||||
* This class should be used with \a PIGPIO::instance() singleton.
|
//! Currently supported only "/sys/class/gpio" mechanism on Linux.
|
||||||
*
|
//!
|
||||||
*
|
//!
|
||||||
*
|
//! \~russian
|
||||||
* \section PIGPIO_sec1 API
|
//! Этот класс предоставляет инициализацию, установку, чтение и наблюдение
|
||||||
* There are several function to directly read or write pin states.
|
//! за GPIO.
|
||||||
*
|
//!
|
||||||
* Also you can start %PIGPIO as thread to watch pin states and receive
|
//! Этот класс используется только через синглтон \a PIGPIO::instance().
|
||||||
* \a pinChanged() event.
|
//!
|
||||||
*
|
//! Сейчас поддерживается только "/sys/class/gpio" для Linux.
|
||||||
*/
|
//!
|
||||||
|
//!
|
||||||
|
//! \~\section PIGPIO_sec1 API
|
||||||
|
//! \~english
|
||||||
|
//! There are several function to directly read or write pin states.
|
||||||
|
//!
|
||||||
|
//! Also you can start %PIGPIO as thread to watch pin states and receive
|
||||||
|
//! \a pinChanged() event.
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Имеется несколько методов для прямой записи и чтения состояний пинов.
|
||||||
|
//!
|
||||||
|
//! Также можно запустить %PIGPIO как поток для наблюдения за пинами и
|
||||||
|
//! принимать события \a pinChanged().
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
PIGPIO::PIGPIO(): PIThread() {
|
PIGPIO::PIGPIO(): PIThread() {
|
||||||
@@ -155,20 +170,26 @@ void PIGPIO::begin() {
|
|||||||
|
|
||||||
|
|
||||||
void PIGPIO::run() {
|
void PIGPIO::run() {
|
||||||
PIMutexLocker ml(mutex);
|
mutex.lock();
|
||||||
if (watch_state.isEmpty()) return;
|
if (watch_state.isEmpty()) {
|
||||||
PIVector<int> ids = watch_state.keys();
|
mutex.unlock();
|
||||||
for(int i = 0; i < ids.size_s(); i++) {
|
return;
|
||||||
GPIOData & g(gpio_[ids[i]]);
|
}
|
||||||
if (g.num != -1 && !g.name.isEmpty()) {
|
PIVector<PIPair<int, bool>> changed;
|
||||||
|
auto it = watch_state.makeIterator();
|
||||||
|
while (it.next()) {
|
||||||
|
GPIOData & g(gpio_[it.key()]);
|
||||||
|
if (g.num == -1 || g.name.isEmpty()) continue;
|
||||||
bool v = getPinState(g.num);
|
bool v = getPinState(g.num);
|
||||||
//piCoutObj << "*** pin state ***" << ids[i] << "=" << v;
|
//piCoutObj << "*** pin state ***" << ids[i] << "=" << v;
|
||||||
if (watch_state[g.num] != v) {
|
if (watch_state[g.num] != v) {
|
||||||
watch_state[g.num] = v;
|
watch_state[g.num] = v;
|
||||||
pinChanged(g.num, v);
|
changed.push_back({g.num, v});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mutex.unlock();
|
||||||
|
for (const auto & i: changed)
|
||||||
|
pinChanged(i.first, i.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -199,6 +220,7 @@ void PIGPIO::initPin(int gpio_num, Direction dir) {
|
|||||||
}
|
}
|
||||||
g.dir = dir;
|
g.dir = dir;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
NO_UNUSED(ret);
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case In:
|
case In:
|
||||||
ret = system(("echo in >> /sys/class/gpio/" + g.name + "/direction").dataAscii());
|
ret = system(("echo in >> /sys/class/gpio/" + g.name + "/direction").dataAscii());
|
||||||
@@ -218,6 +240,7 @@ void PIGPIO::pinSet(int gpio_num, bool value) {
|
|||||||
PIMutexLocker ml(mutex);
|
PIMutexLocker ml(mutex);
|
||||||
GPIOData & g(gpio_[gpio_num]);
|
GPIOData & g(gpio_[gpio_num]);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
NO_UNUSED(ret);
|
||||||
if (g.fd != -1) {
|
if (g.fd != -1) {
|
||||||
if (value) ret = ::write(g.fd, "1", 1);
|
if (value) ret = ::write(g.fd, "1", 1);
|
||||||
else ret = ::write(g.fd, "0", 1);
|
else ret = ::write(g.fd, "0", 1);
|
||||||
@@ -233,6 +256,14 @@ bool PIGPIO::pinState(int gpio_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! This function doesn`t affect thread state!
|
||||||
|
//! Pins watching starts only with \a PIThread::start() function
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Этот метод не меняет состояние потока наблюдения!
|
||||||
|
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||||
void PIGPIO::pinBeginWatch(int gpio_num) {
|
void PIGPIO::pinBeginWatch(int gpio_num) {
|
||||||
PIMutexLocker ml(mutex);
|
PIMutexLocker ml(mutex);
|
||||||
GPIOData & g(gpio_[gpio_num]);
|
GPIOData & g(gpio_[gpio_num]);
|
||||||
@@ -246,12 +277,28 @@ void PIGPIO::pinBeginWatch(int gpio_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! This function doesn`t affect thread state!
|
||||||
|
//! Pins watching starts only with \a PIThread::start() function
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Этот метод не меняет состояние потока наблюдения!
|
||||||
|
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||||
void PIGPIO::pinEndWatch(int gpio_num) {
|
void PIGPIO::pinEndWatch(int gpio_num) {
|
||||||
PIMutexLocker ml(mutex);
|
PIMutexLocker ml(mutex);
|
||||||
watch_state.remove(gpio_num);
|
watch_state.remove(gpio_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! This function doesn`t affect thread state!
|
||||||
|
//! Pins watching starts only with \a PIThread::start() function
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Этот метод не меняет состояние потока наблюдения!
|
||||||
|
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||||
void PIGPIO::clearWatch() {
|
void PIGPIO::clearWatch() {
|
||||||
PIMutexLocker ml(mutex);
|
PIMutexLocker ml(mutex);
|
||||||
watch_state.clear();
|
watch_state.clear();
|
||||||
@@ -259,5 +306,5 @@ void PIGPIO::clearWatch() {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
# pragma GCC diagnostic pop
|
//# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -29,50 +29,57 @@
|
|||||||
#include "pithread.h"
|
#include "pithread.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english GPIO support.
|
||||||
|
//! \~russian Поддержка GPIO.
|
||||||
class PIP_EXPORT PIGPIO: public PIThread
|
class PIP_EXPORT PIGPIO: public PIThread
|
||||||
{
|
{
|
||||||
PIOBJECT_SUBCLASS(PIGPIO, PIThread)
|
PIOBJECT_SUBCLASS(PIGPIO, PIThread)
|
||||||
public:
|
public:
|
||||||
PIGPIO();
|
|
||||||
virtual ~PIGPIO();
|
|
||||||
|
|
||||||
//! \brief Work mode for pin
|
//! \~english Work mode for pin
|
||||||
|
//! \~russian Режим работы пина
|
||||||
enum Direction {
|
enum Direction {
|
||||||
In /** Input direction (read) */,
|
In /** \~english Input direction (read) \~russian Входной (чтение) */,
|
||||||
Out /** Output direction (write) */
|
Out /** \~english Output direction (write) \~russian Выходной (запись) */
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Returns singleton object of %PIGPIO
|
//! \~english Returns singleton object of %PIGPIO
|
||||||
|
//! \~russian Возвращает синглтон объекта %PIGPIO
|
||||||
static PIGPIO * instance();
|
static PIGPIO * instance();
|
||||||
|
|
||||||
//! \brief Initialize pin \"gpio_num\" for \"dir\" mode
|
//! \~english Initialize pin "gpio_num" for "dir" mode
|
||||||
|
//! \~russian Инициализирует пин "gpio_num" для режима работы "dir"
|
||||||
void initPin(int gpio_num, Direction dir = PIGPIO::In);
|
void initPin(int gpio_num, Direction dir = PIGPIO::In);
|
||||||
|
|
||||||
//! \brief Set pin \"gpio_num\" value to \"value\"
|
//! \~english Set pin "gpio_num" value to "value"
|
||||||
|
//! \~russian Устанавливает значение пина "gpio_num" в "value"
|
||||||
void pinSet (int gpio_num, bool value);
|
void pinSet (int gpio_num, bool value);
|
||||||
|
|
||||||
//! \brief Set pin \"gpio_num\" value to \b true
|
//! \~english Set pin "gpio_num" value to \b true
|
||||||
|
//! \~russian Устанавливает значение пина "gpio_num" в \b true
|
||||||
void pinHigh (int gpio_num) {pinSet(gpio_num, true );}
|
void pinHigh (int gpio_num) {pinSet(gpio_num, true );}
|
||||||
|
|
||||||
//! \brief Set pin \"gpio_num\" value to \b false
|
//! \~english Set pin "gpio_num" value to \b false
|
||||||
|
//! \~russian Устанавливает значение пина "gpio_num" в \b false
|
||||||
void pinLow (int gpio_num) {pinSet(gpio_num, false);}
|
void pinLow (int gpio_num) {pinSet(gpio_num, false);}
|
||||||
|
|
||||||
//! \brief Returns pin \"gpio_num\" state
|
//!
|
||||||
|
//! \~english Returns pin "gpio_num" state
|
||||||
|
//! \~russian Возвращает значение пина "gpio_num"
|
||||||
bool pinState(int gpio_num);
|
bool pinState(int gpio_num);
|
||||||
|
|
||||||
//! \brief Starts watch for pin \"gpio_num\".
|
//! \~english Starts watch for pin "gpio_num"
|
||||||
//! \details Pins watching starts only with \a PIThread::start() function!
|
//! \~russian Начинает наблюдение за пином "gpio_num"
|
||||||
//! This function doesn`t affect thread state
|
|
||||||
void pinBeginWatch(int gpio_num);
|
void pinBeginWatch(int gpio_num);
|
||||||
|
|
||||||
//! \brief End watch for pin \"gpio_num\".
|
//! \~english End watch for pin "gpio_num"
|
||||||
//! \details Pins watching starts only with \a PIThread::start() function!
|
//! \~russian Заканчивает наблюдение за пином "gpio_num"
|
||||||
//! This function doesn`t affect thread state
|
|
||||||
void pinEndWatch (int gpio_num);
|
void pinEndWatch (int gpio_num);
|
||||||
|
|
||||||
//! \brief End watch for all pins.
|
//! \~english End watch for all pins
|
||||||
//! \details Pins watching starts only with \a PIThread::start() function!
|
//! \~russian Заканчивает наблюдение за всеми пинами
|
||||||
//! This function doesn`t affect thread state
|
|
||||||
void clearWatch();
|
void clearWatch();
|
||||||
|
|
||||||
EVENT2(pinChanged, int, gpio_num, bool, new_value)
|
EVENT2(pinChanged, int, gpio_num, bool, new_value)
|
||||||
@@ -81,13 +88,20 @@ public:
|
|||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn void pinChanged(int gpio_num, bool new_value)
|
//! \fn void pinChanged(int gpio_num, bool new_value)
|
||||||
//! \brief Raise on pin \"gpio_num\" state changes to \"new_value\"
|
//! \~english Raise on pin "gpio_num" state changes to "new_value"
|
||||||
//! \details Important! This event will be raised only with started
|
//! \~russian Вызывается по смене состояния пина "gpio_num" на "new_value"
|
||||||
//! thread.
|
//! \~\details
|
||||||
|
//! \~\warning
|
||||||
|
//! \~english This event raised only when thread started.
|
||||||
|
//! \~russian Это событие вызывается только при запущенном потоке.
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PIGPIO();
|
||||||
|
virtual ~PIGPIO();
|
||||||
|
NO_COPY_CLASS(PIGPIO)
|
||||||
|
|
||||||
struct PIP_EXPORT GPIOData {
|
struct PIP_EXPORT GPIOData {
|
||||||
GPIOData() {dir = PIGPIO::In; num = fd = -1;}
|
GPIOData() {dir = PIGPIO::In; num = fd = -1;}
|
||||||
PIString name;
|
PIString name;
|
||||||
|
|||||||
@@ -20,12 +20,15 @@
|
|||||||
#include "piiobytearray.h"
|
#include "piiobytearray.h"
|
||||||
|
|
||||||
|
|
||||||
/*! \class PIIOByteArray
|
//! \class PIIOByteArray piiobytearray.h
|
||||||
* \brief PIIODevice wrapper around PIByteArray
|
//! \details
|
||||||
*
|
//! \~english
|
||||||
* \section PIIOByteArray_sec0 Synopsis
|
//! This class allow you to use PIByteArray as PIIODevice, e.g. to pass it to PIConfig.
|
||||||
* This class sllow you to use PIByteArray as PIIODevice and pass it to, e.g. PIConfig
|
//!
|
||||||
*/
|
//! \~russian
|
||||||
|
//! Этот класс позволяет использовать PIByteArray в качестве PIIODevice, например,
|
||||||
|
//! для передачи в PIConfig.
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
PIIOByteArray::PIIOByteArray(PIByteArray *buffer, PIIODevice::DeviceMode mode) {
|
PIIOByteArray::PIIOByteArray(PIByteArray *buffer, PIIODevice::DeviceMode mode) {
|
||||||
|
|||||||
@@ -29,44 +29,59 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIIODevice wrapper around PIByteArray
|
||||||
|
//! \~russian Обёртка PIIODevice вокруг PIByteArray
|
||||||
class PIP_EXPORT PIIOByteArray: public PIIODevice
|
class PIP_EXPORT PIIOByteArray: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIIOByteArray)
|
PIIODEVICE(PIIOByteArray, "")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Contructs %PIIOByteArray with \"buffer\" content and \"mode\" open mode
|
//! \~english Contructs %PIIOByteArray with "buffer" content and "mode" open mode
|
||||||
|
//! \~russian Создает %PIIOByteArray с содержимым "buffer" и режимом открытия "mode"
|
||||||
explicit PIIOByteArray(PIByteArray * buffer = 0, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PIIOByteArray(PIByteArray * buffer = 0, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Contructs %PIIOByteArray with \"buffer\" content only for read
|
//! \~english Contructs %PIIOByteArray with "buffer" content only for read
|
||||||
|
//! \~russian Создает %PIIOByteArray с содержимым "buffer" только для чтения
|
||||||
explicit PIIOByteArray(const PIByteArray & buffer);
|
explicit PIIOByteArray(const PIByteArray & buffer);
|
||||||
|
|
||||||
//! Returns content
|
//! \~english Returns content
|
||||||
|
//! \~russian Возвращает содержимое
|
||||||
PIByteArray * byteArray() const {return data_;}
|
PIByteArray * byteArray() const {return data_;}
|
||||||
|
|
||||||
//! Clear content buffer
|
//! \~english Clear content buffer
|
||||||
|
//! \~russian Очищает содержимое буфера
|
||||||
void clear() {if (data_) data_->clear(); pos = 0;}
|
void clear() {if (data_) data_->clear(); pos = 0;}
|
||||||
|
|
||||||
//! Open \"buffer\" content with \"mode\" open mode
|
//! \~english Open "buffer" content with "mode" open mode
|
||||||
|
//! \~russian Открывает содержимое "buffer" с режимом открытия "mode"
|
||||||
bool open(PIByteArray * buffer, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
bool open(PIByteArray * buffer, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Open \"buffer\" content only for read
|
//! \~english Open "buffer" content only for read
|
||||||
|
//! \~russian Открывает содержимое "buffer" только для чтения
|
||||||
bool open(const PIByteArray & buffer);
|
bool open(const PIByteArray & buffer);
|
||||||
|
|
||||||
//! Returns if position is at the end of content
|
//! \~english Returns if position is at the end of content
|
||||||
|
//! \~russian Возвращает в конце содержимого ли позиция
|
||||||
bool isEnd() const {if (!data_) return true; return pos >= data_->size_s();}
|
bool isEnd() const {if (!data_) return true; return pos >= data_->size_s();}
|
||||||
|
|
||||||
|
|
||||||
//! Move read/write position to \"position\"
|
//! \~english Move read/write position to "position"
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на "position"
|
||||||
void seek(llong position) {pos = position;}
|
void seek(llong position) {pos = position;}
|
||||||
|
|
||||||
//! Move read/write position to the begin of the string
|
//! \~english Move read/write position to the beginning of the buffer
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на начало буфера
|
||||||
void seekToBegin() {if (data_) pos = 0;}
|
void seekToBegin() {if (data_) pos = 0;}
|
||||||
|
|
||||||
//! Move read/write position to the end of the string
|
//! \~english Move read/write position to the end of the buffer
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на конец буфера
|
||||||
void seekToEnd() {if (data_) pos = data_->size_s();}
|
void seekToEnd() {if (data_) pos = data_->size_s();}
|
||||||
|
|
||||||
|
|
||||||
//! Insert data \"ba\" into content at current position
|
//! \~english Insert data "ba" into content at current position
|
||||||
|
//! \~russian Вставляет данные "ba" в содержимое буфера в текущую позицию
|
||||||
int writeByteArray(const PIByteArray & ba);
|
int writeByteArray(const PIByteArray & ba);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -23,13 +23,7 @@
|
|||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup IO
|
|
||||||
//! \{
|
|
||||||
//! \class PIIODevice piiodevice.h
|
//! \class PIIODevice piiodevice.h
|
||||||
//! \brief
|
|
||||||
//! \~english Base class for input/output classes
|
|
||||||
//! \~russian Базовый класс утройств ввода/вывода
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \section PIIODevice_sec0 Synopsis
|
//! \section PIIODevice_sec0 Synopsis
|
||||||
//! This class provide open/close logic, threaded read/write and virtual input/output
|
//! This class provide open/close logic, threaded read/write and virtual input/output
|
||||||
@@ -84,11 +78,10 @@
|
|||||||
//!
|
//!
|
||||||
//! \section PIIODevice_sec7 Creating devices by unambiguous string
|
//! \section PIIODevice_sec7 Creating devices by unambiguous string
|
||||||
//! There are some virtual functions to describe child class without its declaration.
|
//! There are some virtual functions to describe child class without its declaration.
|
||||||
//! \n \a fullPathPrefix() should returns unique prefix of device
|
|
||||||
//! \n \a constructFullPath() should returns full unambiguous string, contains prefix and all device parameters
|
//! \n \a constructFullPath() should returns full unambiguous string, contains prefix and all device parameters
|
||||||
//! \n \a configureFromFullPath() provide configuring device from full unambiguous string without prefix and "://"
|
//! \n \a configureFromFullPath() provide configuring device from full unambiguous string without prefix and "://"
|
||||||
//! \n Macro PIIODEVICE should be used instead of PIOBJECT
|
//! \n Macro PIIODEVICE should be used instead of PIOBJECT
|
||||||
//! \n Macro REGISTER_DEVICE should be used after definition of class, i.e. at the last line of *.cpp file
|
//! \n Macro REGISTER_DEVICE should be used after declaration of class, i.e. at the last line of *.h file
|
||||||
//! \n \n If custom I/O device corresponds there rules, it can be returned by function \a createFromFullPath().
|
//! \n \n If custom I/O device corresponds there rules, it can be returned by function \a createFromFullPath().
|
||||||
//! \n Each PIP I/O device has custom unambiguous string description:
|
//! \n Each PIP I/O device has custom unambiguous string description:
|
||||||
//! * PIFile: "file://<path>"
|
//! * PIFile: "file://<path>"
|
||||||
@@ -117,7 +110,6 @@
|
|||||||
//! \section PIIODevice_ex0 Example
|
//! \section PIIODevice_ex0 Example
|
||||||
//! \snippet piiodevice.cpp 0
|
//! \snippet piiodevice.cpp 0
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PIMutex PIIODevice::nfp_mutex;
|
PIMutex PIIODevice::nfp_mutex;
|
||||||
@@ -131,9 +123,6 @@ PIIODevice::PIIODevice(): PIThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Constructs a PIIODevice with path and mode
|
|
||||||
* \param path path to device
|
|
||||||
* \param type mode for open */
|
|
||||||
PIIODevice::PIIODevice(const PIString & path, PIIODevice::DeviceMode mode): PIThread() {
|
PIIODevice::PIIODevice(const PIString & path, PIIODevice::DeviceMode mode): PIThread() {
|
||||||
mode_ = mode;
|
mode_ = mode;
|
||||||
_init();
|
_init();
|
||||||
@@ -160,6 +149,34 @@ bool PIIODevice::setOption(PIIODevice::DeviceOption o, bool yes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! Set external static function of threaded read that will be executed
|
||||||
|
//! at every successful threaded read. Function should have format
|
||||||
|
//! "bool func(void * data, uchar * readed, int size)"
|
||||||
|
//! \~russian
|
||||||
|
//! Устанавливает внешний статический метод, который будет вызван
|
||||||
|
//! после каждого успешного потокового чтения. Метод должен быть
|
||||||
|
//! в формате "bool func(void * data, uchar * readed, int size)"
|
||||||
|
void PIIODevice::setThreadedReadSlot(ReadRetFunc func) {
|
||||||
|
ret_func_ = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! Default size is 4096 bytes. If your device can read at single read
|
||||||
|
//! more than 4096 bytes you should use this function to adjust buffer size
|
||||||
|
//! \~russian
|
||||||
|
//! По умолчанию 4096 байт. Если устройство за одно чтение может читать
|
||||||
|
//! более 4096 байт, необходимо использовать этот метод для установки
|
||||||
|
//! нужного размера буфера
|
||||||
|
void PIIODevice::setThreadedReadBufferSize(int new_size) {
|
||||||
|
threaded_read_buffer_size = new_size;
|
||||||
|
threadedReadBufferSizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool stopThread(PIThread * t, bool hard) {
|
bool stopThread(PIThread * t, bool hard) {
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
t->stop(true);
|
t->stop(true);
|
||||||
@@ -265,15 +282,12 @@ void PIIODevice::write_func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIIODevice * PIIODevice::newDeviceByPrefix(const PIString & prefix) {
|
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
||||||
if (prefix.isEmpty()) return 0;
|
if (!prefix) return nullptr;
|
||||||
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
|
auto fi = fabrics().value(prefix);
|
||||||
piForeachC (PIObject * d, rd) {
|
if (fi.fabricator)
|
||||||
if (prefix == ((const PIIODevice * )d)->fullPathPrefix()) {
|
return fi.fabricator();
|
||||||
return ((const PIIODevice * )d)->copy();
|
return nullptr;
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -427,7 +441,7 @@ bool PIIODevice::configure(const PIString & config_file, const PIString & sectio
|
|||||||
|
|
||||||
|
|
||||||
PIString PIIODevice::constructFullPath() const {
|
PIString PIIODevice::constructFullPath() const {
|
||||||
return fullPathPrefix() + "://" + constructFullPathDevice() + fullPathOptions();
|
return fullPathPrefix().toString() + PIStringAscii("://") + constructFullPathDevice() + fullPathOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -462,23 +476,23 @@ void PIIODevice::configureFromVariant(const PIVariantTypes::IODevice & d) {
|
|||||||
void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode, DeviceOptions * opts) {
|
void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode, DeviceOptions * opts) {
|
||||||
int dm = 0;
|
int dm = 0;
|
||||||
DeviceOptions op = 0;
|
DeviceOptions op = 0;
|
||||||
if (fpwm.find("(") > 0 && fpwm.find(")") > 0) {
|
if (fpwm.find('(') > 0 && fpwm.find(')') > 0) {
|
||||||
PIString dms(fpwm.right(fpwm.length() - fpwm.findLast("(")).takeRange("(", ")").trim().toLowerCase().removeAll(' '));
|
PIString dms(fpwm.right(fpwm.length() - fpwm.findLast('(')).takeRange('(', ')').trim().toLowerCase().removeAll(' '));
|
||||||
PIStringList opts(dms.split(","));
|
PIStringList opts(dms.split(","));
|
||||||
piForeachC (PIString & o, opts) {
|
piForeachC (PIString & o, opts) {
|
||||||
//piCout << dms;
|
//piCout << dms;
|
||||||
if (o == "r" || o == "ro" || o == "read" || o == "readonly")
|
if (o == PIStringAscii("r") || o == PIStringAscii("ro") || o == PIStringAscii("read") || o == PIStringAscii("readonly"))
|
||||||
dm |= ReadOnly;
|
dm |= ReadOnly;
|
||||||
if (o == "w" || o == "wo" || o == "write" || o == "writeonly")
|
if (o == PIStringAscii("w") || o == PIStringAscii("wo") || o == PIStringAscii("write") || o == PIStringAscii("writeonly"))
|
||||||
dm |= WriteOnly;
|
dm |= WriteOnly;
|
||||||
if (o == "br" || o == "blockr" || o == "blockread" || o == "blockingread")
|
if (o == PIStringAscii("br") || o == PIStringAscii("blockr") || o == PIStringAscii("blockread") || o == PIStringAscii("blockingread"))
|
||||||
op |= BlockingRead;
|
op |= BlockingRead;
|
||||||
if (o == "bw" || o == "blockw" || o == "blockwrite" || o == "blockingwrite")
|
if (o == PIStringAscii("bw") || o == PIStringAscii("blockw") || o == PIStringAscii("blockwrite") || o == PIStringAscii("blockingwrite"))
|
||||||
op |= BlockingWrite;
|
op |= BlockingWrite;
|
||||||
if (o == "brw" || o == "bwr" || o == "blockrw" || o == "blockwr" || o == "blockreadrite" || o == "blockingreadwrite")
|
if (o == PIStringAscii("brw") || o == PIStringAscii("bwr") || o == PIStringAscii("blockrw") || o == PIStringAscii("blockwr") || o == PIStringAscii("blockreadrite") || o == PIStringAscii("blockingreadwrite"))
|
||||||
op |= BlockingRead | BlockingWrite;
|
op |= BlockingRead | BlockingWrite;
|
||||||
}
|
}
|
||||||
fpwm.cutRight(fpwm.length() - fpwm.findLast("(")).trim();
|
fpwm.cutRight(fpwm.length() - fpwm.findLast('(')).trim();
|
||||||
}
|
}
|
||||||
if (dm == 0) dm = ReadWrite;
|
if (dm == 0) dm = ReadWrite;
|
||||||
if (full_path) *full_path = fpwm;
|
if (full_path) *full_path = fpwm;
|
||||||
@@ -489,14 +503,33 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
|
|||||||
|
|
||||||
PIStringList PIIODevice::availablePrefixes() {
|
PIStringList PIIODevice::availablePrefixes() {
|
||||||
PIStringList ret;
|
PIStringList ret;
|
||||||
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
|
for (const auto & i: fabrics())
|
||||||
piForeachC (PIObject * d, rd) {
|
ret << i.second.prefix.toString();
|
||||||
ret << ((const PIIODevice * )d)->fullPathPrefix();
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIStringList PIIODevice::availableClasses() {
|
||||||
|
PIStringList ret;
|
||||||
|
for (const auto & i: fabrics())
|
||||||
|
ret << i.second.classname.toString();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIIODevice::registerDevice(PIConstChars prefix, PIConstChars classname, PIIODevice * (*fabric)()) {
|
||||||
|
if (prefix.isEmpty()) return;
|
||||||
|
//printf("registerDevice %s %d %d\n", prefix, p.isEmpty(), fabrics().size());
|
||||||
|
if (!fabrics().contains(prefix)) {
|
||||||
|
FabricInfo fi;
|
||||||
|
fi.prefix = prefix;
|
||||||
|
fi.classname = classname;
|
||||||
|
fi.fabricator = fabric;
|
||||||
|
fabrics()[prefix] = fi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString PIIODevice::fullPathOptions() const {
|
PIString PIIODevice::fullPathOptions() const {
|
||||||
if (mode_ == ReadWrite && options_ == 0) return PIString();
|
if (mode_ == ReadWrite && options_ == 0) return PIString();
|
||||||
PIString ret(" (");
|
PIString ret(" (");
|
||||||
@@ -509,10 +542,17 @@ PIString PIIODevice::fullPathOptions() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() and "://".
|
||||||
|
//! See \ref PIIODevice_sec7
|
||||||
|
//! \~russian
|
||||||
|
//! В метод \a configureFromFullPath() "full_path" передается без \a fullPathPrefix() и "://".
|
||||||
|
//! См. \ref PIIODevice_sec7
|
||||||
PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
|
PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
|
||||||
PIString prefix = full_path.left(full_path.find(":"));
|
PIString prefix = full_path.left(full_path.find(":"));
|
||||||
PIIODevice * nd = newDeviceByPrefix(prefix);
|
PIIODevice * nd = newDeviceByPrefix(prefix.dataAscii());
|
||||||
if (!nd) return 0;
|
if (!nd) return nullptr;
|
||||||
nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
|
nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
|
||||||
cacheFullPath(full_path, nd);
|
cacheFullPath(full_path, nd);
|
||||||
return nd;
|
return nd;
|
||||||
@@ -520,8 +560,8 @@ PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
|
|||||||
|
|
||||||
|
|
||||||
PIIODevice * PIIODevice::createFromVariant(const PIVariantTypes::IODevice & d) {
|
PIIODevice * PIIODevice::createFromVariant(const PIVariantTypes::IODevice & d) {
|
||||||
PIIODevice * nd = newDeviceByPrefix(d.prefix);
|
PIIODevice * nd = newDeviceByPrefix(d.prefix.dataAscii());
|
||||||
if (!nd) return 0;
|
if (!nd) return nullptr;
|
||||||
nd->configureFromVariant(d);
|
nd->configureFromVariant(d);
|
||||||
return nd;
|
return nd;
|
||||||
}
|
}
|
||||||
@@ -550,6 +590,12 @@ void PIIODevice::cacheFullPath(const PIString & full_path, const PIIODevice * d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIMap<PIConstChars, PIIODevice::FabricInfo> & PIIODevice::fabrics() {
|
||||||
|
static PIMap<PIConstChars, FabricInfo> ret;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIIODevice::threadedRead(uchar *readed, int size) {
|
bool PIIODevice::threadedRead(uchar *readed, int size) {
|
||||||
// piCout << "iodevice threaded read";
|
// piCout << "iodevice threaded read";
|
||||||
if (ret_func_ != 0) return ret_func_(ret_data_, readed, size);
|
if (ret_func_ != 0) return ret_func_(ret_data_, readed, size);
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
#define PIIODEVICE_H
|
#define PIIODEVICE_H
|
||||||
|
|
||||||
#include "piinit.h"
|
#include "piinit.h"
|
||||||
#include "picollection.h"
|
|
||||||
#include "pitimer.h"
|
#include "pitimer.h"
|
||||||
#include "piqueue.h"
|
#include "piqueue.h"
|
||||||
|
|
||||||
@@ -38,20 +37,46 @@ typedef bool (*ReadRetFunc)(void * , uchar * , int );
|
|||||||
|
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
|
|
||||||
//! \relatesalso PIIODevice \brief Use this macro to enable automatic creation instances of your class with \a createFromFullPath() function
|
//! \relatesalso PIIODevice
|
||||||
|
//! \brief
|
||||||
|
//! \~english Enable device instances creation with \a PIIODevice::createFromFullPath() function.
|
||||||
|
//! \~russian Включить создание экземпляров устройства с помощью метода \a PIIODevice::createFromFullPath().
|
||||||
|
//! \~\details
|
||||||
|
//! \~english This macro may be placed in cpp or header file, but preferred place is header
|
||||||
|
//! \~russian Этот макрос может быть расположен в cpp или заголовочном файле, но предпочтительнее распологать в заголовочном
|
||||||
# define REGISTER_DEVICE(class)
|
# define REGISTER_DEVICE(class)
|
||||||
|
|
||||||
//! \relatesalso PIIODevice \brief Use this macro instead of PIOBJECT when describe your own PIIODevice
|
//! \relatesalso PIIODevice
|
||||||
# define PIIODEVICE(class)
|
//! \brief
|
||||||
|
//! \~english Use this macro instead of PIOBJECT when describe your own PIIODevice.
|
||||||
|
//! \~russian Используйте этот макрос вместо PIOBJECT при объявлении своего PIIODevice.
|
||||||
|
//! \~\param "prefix"
|
||||||
|
//! \~english Unique device prefix in quotes, may be ""
|
||||||
|
//! \~russian Уникальный префикс устройства в кавычках, может быть ""
|
||||||
|
# define PIIODEVICE(class, "prefix")
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# define REGISTER_DEVICE(name) ADD_NEW_TO_COLLECTION_WITH_NAME(__PIIODevices__, name, __S__collection_##name##__)
|
# define REGISTER_DEVICE(name) \
|
||||||
# define PIIODEVICE(name) PIOBJECT_SUBCLASS(name, PIIODevice) PIIODevice * copy() const {return new name();}
|
STATIC_INITIALIZER_BEGIN \
|
||||||
|
PIIODevice::registerDevice(name::fullPathPrefixS(), #name, []()->PIIODevice*{return new name();});\
|
||||||
|
STATIC_INITIALIZER_END
|
||||||
|
|
||||||
|
# define PIIODEVICE(name, prefix) \
|
||||||
|
PIOBJECT_SUBCLASS(name, PIIODevice) \
|
||||||
|
PIIODevice * copy() const {return new name();} \
|
||||||
|
public: \
|
||||||
|
virtual PIConstChars fullPathPrefix() const {return prefix;} \
|
||||||
|
static PIConstChars fullPathPrefixS() {return prefix;} \
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Base class for input/output devices.
|
||||||
|
//! \~russian Базовый класс утройств ввода/вывода.
|
||||||
class PIP_EXPORT PIIODevice: public PIThread
|
class PIP_EXPORT PIIODevice: public PIThread
|
||||||
{
|
{
|
||||||
PIOBJECT_SUBCLASS(PIIODevice, PIThread)
|
PIOBJECT_SUBCLASS(PIIODevice, PIThread)
|
||||||
@@ -59,207 +84,271 @@ class PIP_EXPORT PIIODevice: public PIThread
|
|||||||
public:
|
public:
|
||||||
NO_COPY_CLASS(PIIODevice)
|
NO_COPY_CLASS(PIIODevice)
|
||||||
|
|
||||||
//! Constructs a empty PIIODevice
|
//! \~english Constructs a empty %PIIODevice
|
||||||
|
//! \~russian Создает пустой %PIIODevice
|
||||||
explicit PIIODevice();
|
explicit PIIODevice();
|
||||||
|
|
||||||
//! \brief Open modes for PIIODevice
|
//! \~english Open modes for PIIODevice
|
||||||
|
//! \~russian Режимы открытия для PIIODevice
|
||||||
enum DeviceMode {
|
enum DeviceMode {
|
||||||
ReadOnly /*! Device can only read */ = 0x01,
|
ReadOnly /*! \~english Device can only read \~russian Устройство может только читать */ = 0x01,
|
||||||
WriteOnly /*! Device can only write */ = 0x02,
|
WriteOnly /*! \~english Device can only write \~russian Устройство может только писать */ = 0x02,
|
||||||
ReadWrite /*! Device can both read and write */ = 0x03
|
ReadWrite /*! \~english Device can both read and write \~russian Устройство может читать и писать */ = 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Options for PIIODevice, works with some devices
|
//! \~english Options for PIIODevice, works with some devices
|
||||||
|
//! \~russian Опции для PIIODevice, работает для некоторых устройств
|
||||||
enum DeviceOption {
|
enum DeviceOption {
|
||||||
BlockingRead /*! \a read block until data is received, default off */ = 0x01,
|
BlockingRead /*! \~english \a read() block until data is received, default off \~russian \a read() блокируется, пока данные не поступят, по умолчанию выключено */ = 0x01,
|
||||||
BlockingWrite /*! \a write block until data is sent, default off */ = 0x02
|
BlockingWrite /*! \~english \a write() block until data is sent, default off \~russian \a write() блокируется, пока данные не запишутся, по умолчанию выключено */ = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Characteristics of PIIODevice subclass
|
//! \~english Characteristics of PIIODevice channel
|
||||||
|
//! \~russian Характеристики канала PIIODevice
|
||||||
enum DeviceInfoFlag {
|
enum DeviceInfoFlag {
|
||||||
Sequential /*! Continuous bytestream without datagrams */ = 0x01,
|
Sequential /*! \~english Continuous bytestream without packets \~russian Непрерывный поток байт, без пакетирования */ = 0x01,
|
||||||
Reliable /*! Channel without data errors / corruptions */ = 0x02
|
Reliable /*! \~english Channel without data errors or corruptions \~russian Канал без ошибок или повреждений данных */ = 0x02
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FabricInfo {
|
||||||
|
PIConstChars prefix;
|
||||||
|
PIConstChars classname;
|
||||||
|
PIIODevice*(*fabricator)() = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef PIFlags<DeviceOption> DeviceOptions;
|
typedef PIFlags<DeviceOption> DeviceOptions;
|
||||||
typedef PIFlags<DeviceInfoFlag> DeviceInfoFlags;
|
typedef PIFlags<DeviceInfoFlag> DeviceInfoFlags;
|
||||||
|
|
||||||
|
//! \~english Constructs %PIIODevice with path "path" and open mode "mode"
|
||||||
|
//! \~russian Создает %PIIODevice с путём "path" и режимом открытия "mode"
|
||||||
explicit PIIODevice(const PIString & path, DeviceMode mode = ReadWrite);
|
explicit PIIODevice(const PIString & path, DeviceMode mode = ReadWrite);
|
||||||
|
|
||||||
virtual ~PIIODevice();
|
virtual ~PIIODevice();
|
||||||
|
|
||||||
//! Current open mode of device
|
//! \~english Returns current open mode of device
|
||||||
|
//! \~russian Возвращает текущий режим открытия устройства
|
||||||
DeviceMode mode() const {return mode_;}
|
DeviceMode mode() const {return mode_;}
|
||||||
|
|
||||||
//! Set open mode of device
|
//! \~english Set open mode of device. Don`t reopen device
|
||||||
|
//! \~russian Устанавливает режим открытия устройства. Не переоткрывает устройство
|
||||||
void setMode(DeviceMode m) {mode_ = m;}
|
void setMode(DeviceMode m) {mode_ = m;}
|
||||||
|
|
||||||
//! Current device options
|
//! \~english Returns current device options
|
||||||
|
//! \~russian Возвращает текущие опции устройства
|
||||||
DeviceOptions options() const {return options_;}
|
DeviceOptions options() const {return options_;}
|
||||||
|
|
||||||
//! Current device option "o" state
|
//! \~english Returns current device option "o" state
|
||||||
|
//! \~russian Возвращает текущее состояние опции "o"
|
||||||
bool isOptionSet(DeviceOption o) const {return options_[o];}
|
bool isOptionSet(DeviceOption o) const {return options_[o];}
|
||||||
|
|
||||||
//! Set device options
|
//! \~english Set device options
|
||||||
|
//! \~russian Устанавливает опции устройства
|
||||||
void setOptions(DeviceOptions o);
|
void setOptions(DeviceOptions o);
|
||||||
|
|
||||||
//! Set device option "o" to "yes" and return previous state
|
//! \~english Set device option "o" to "yes" and returns previous state
|
||||||
|
//! \~russian Устанавливает опцию "o" устройства в "yes" и возвращает предыдущее состояние опции
|
||||||
bool setOption(DeviceOption o, bool yes = true);
|
bool setOption(DeviceOption o, bool yes = true);
|
||||||
|
|
||||||
//! Returns device characteristic flags
|
//! \~english Returns device characteristic flags
|
||||||
|
//! \~russian Возвращает характеристики канала
|
||||||
DeviceInfoFlags infoFlags() const {return deviceInfoFlags();}
|
DeviceInfoFlags infoFlags() const {return deviceInfoFlags();}
|
||||||
|
|
||||||
//! Current path of device
|
//! \~english Returns current path of device
|
||||||
PIString path() const {return property(PIStringAscii("path")).toString();}
|
//! \~russian Возвращает текущий путь устройства
|
||||||
|
PIString path() const {return property("path").toString();}
|
||||||
|
|
||||||
//! Set path of device
|
//! \~english Set path of device. Don`t reopen device
|
||||||
void setPath(const PIString & path) {setProperty(PIStringAscii("path"), path);}
|
//! \~russian Устанавливает путь устройства. Не переоткрывает устройство
|
||||||
|
void setPath(const PIString & path) {setProperty("path", path);}
|
||||||
|
|
||||||
//! Return \b true if mode is ReadOnly or ReadWrite
|
//! \~english Returns if mode is ReadOnly or ReadWrite
|
||||||
|
//! \~russian Возвращает равен ли режим открытия ReadOnly или ReadWrite
|
||||||
bool isReadable() const {return (mode_ & ReadOnly);}
|
bool isReadable() const {return (mode_ & ReadOnly);}
|
||||||
|
|
||||||
//! Return \b true if mode is WriteOnly or ReadWrite
|
//! \~english Returns if mode is WriteOnly or ReadWrite
|
||||||
|
//! \~russian Возвращает равен ли режим открытия WriteOnly или ReadWrite
|
||||||
bool isWriteable() const {return (mode_ & WriteOnly);}
|
bool isWriteable() const {return (mode_ & WriteOnly);}
|
||||||
|
|
||||||
//! Return \b true if device is successfully opened
|
//! \~english Returns if device is successfully opened
|
||||||
|
//! \~russian Возвращает успешно ли открыто устройство
|
||||||
bool isOpened() const {return opened_;}
|
bool isOpened() const {return opened_;}
|
||||||
|
|
||||||
//! Return \b true if device is closed
|
//! \~english Returns if device is closed
|
||||||
|
//! \~russian Возвращает закрыто ли устройство
|
||||||
bool isClosed() const {return !opened_;}
|
bool isClosed() const {return !opened_;}
|
||||||
|
|
||||||
//! Return \b true if device can read \b now
|
//! \~english Returns if device can read \b now
|
||||||
|
//! \~russian Возвращает может ли устройство читать \b сейчас
|
||||||
virtual bool canRead() const {return opened_ && (mode_ & ReadOnly);}
|
virtual bool canRead() const {return opened_ && (mode_ & ReadOnly);}
|
||||||
|
|
||||||
//! Return \b true if device can write \b now
|
//! \~english Returns if device can write \b now
|
||||||
|
//! \~russian Возвращает может ли устройство писать \b сейчас
|
||||||
virtual bool canWrite() const {return opened_ && (mode_ & WriteOnly);}
|
virtual bool canWrite() const {return opened_ && (mode_ & WriteOnly);}
|
||||||
|
|
||||||
|
|
||||||
//! Set execution of \a open enabled while threaded read on closed device
|
//! \~english Set calling of \a open() enabled while threaded read on closed device
|
||||||
void setReopenEnabled(bool yes = true) {setProperty(PIStringAscii("reopenEnabled"), yes);}
|
//! \~russian Устанавливает возможность вызова \a open() при потоковом чтении на закрытом устройстве
|
||||||
|
void setReopenEnabled(bool yes = true) {setProperty("reopenEnabled", yes);}
|
||||||
|
|
||||||
//! Set timeout in milliseconds between \a open tryings if reopen is enabled
|
//!
|
||||||
void setReopenTimeout(int msecs) {setProperty(PIStringAscii("reopenTimeout"), msecs);}
|
//! \~english Set timeout in milliseconds between \a open() tryings if reopen is enabled
|
||||||
|
//! \~russian Устанавливает задержку в миллисекундах между вызовами \a open() если переоткрытие активно
|
||||||
|
void setReopenTimeout(int msecs) {setProperty("reopenTimeout", msecs);}
|
||||||
|
|
||||||
|
//! \~english Returns reopen enable
|
||||||
|
//! \~russian Возвращает активно ли переоткрытие
|
||||||
|
bool isReopenEnabled() const {return property("reopenEnabled").toBool();}
|
||||||
|
|
||||||
|
//! \~english Returns reopen timeout in milliseconds
|
||||||
|
//! \~russian Возвращает задержку переоткрытия в миллисекундах
|
||||||
|
int reopenTimeout() {return property("reopenTimeout").toInt();}
|
||||||
|
|
||||||
|
|
||||||
//! Return reopen enable
|
//! \~english Set threaded read callback
|
||||||
bool isReopenEnabled() const {return property(PIStringAscii("reopenEnabled")).toBool();}
|
//! \~russian Устанавливает callback потокового чтения
|
||||||
|
void setThreadedReadSlot(ReadRetFunc func);
|
||||||
|
|
||||||
//! Return reopen timeout
|
//! \~english Set custom data that will be passed to threaded read callback
|
||||||
int reopenTimeout() {return property(PIStringAscii("reopenTimeout")).toInt();}
|
//! \~russian Устанавливает произвольный указатель, который будет передан в callback потокового чтения
|
||||||
|
|
||||||
|
|
||||||
/** \brief Set "threaded read slot"
|
|
||||||
* \details Set external static function of threaded read that will be executed
|
|
||||||
* at every successful threaded read. Function should have format
|
|
||||||
* "bool func(void * data, uchar * readed, int size)" */
|
|
||||||
void setThreadedReadSlot(ReadRetFunc func) {ret_func_ = func;}
|
|
||||||
|
|
||||||
//! Set custom data that will be passed to "threaded read slot"
|
|
||||||
void setThreadedReadData(void * d) {ret_data_ = d;}
|
void setThreadedReadData(void * d) {ret_data_ = d;}
|
||||||
|
|
||||||
/** \brief Set size of threaded read buffer
|
//! \~english Set size of threaded read buffer
|
||||||
* \details Default size is 4096 bytes. If your device can read at single read
|
//! \~russian Устанавливает размер буфера потокового чтения
|
||||||
* more than 4096 bytes you should use this function to adjust buffer size */
|
void setThreadedReadBufferSize(int new_size);
|
||||||
void setThreadedReadBufferSize(int new_size) {threaded_read_buffer_size = new_size; threadedReadBufferSizeChanged();}
|
|
||||||
|
|
||||||
//! Return size of threaded read buffer
|
//! \~english Returns size of threaded read buffer
|
||||||
|
//! \~russian Возвращает размер буфера потокового чтения
|
||||||
int threadedReadBufferSize() const {return threaded_read_buffer_size;}
|
int threadedReadBufferSize() const {return threaded_read_buffer_size;}
|
||||||
|
|
||||||
//! Return content of threaded read buffer
|
//! \~english Returns content of threaded read buffer
|
||||||
|
//! \~russian Возвращает содержимое буфера потокового чтения
|
||||||
const uchar * threadedReadBuffer() const {return buffer_tr.data();}
|
const uchar * threadedReadBuffer() const {return buffer_tr.data();}
|
||||||
|
|
||||||
//! Return custom data that will be passed to "threaded read slot"
|
//! \~english Returns custom data that will be passed to threaded read callback
|
||||||
|
//! \~russian Возвращает произвольный указатель, который будет передан в callback потокового чтения
|
||||||
void * threadedReadData() const {return ret_data_;}
|
void * threadedReadData() const {return ret_data_;}
|
||||||
|
|
||||||
|
|
||||||
//! Return \b true if threaded read is started
|
//! \~english Returns if threaded read is started
|
||||||
|
//! \~russian Возвращает запущен ли поток чтения
|
||||||
bool isThreadedRead() const {return isRunning();}
|
bool isThreadedRead() const {return isRunning();}
|
||||||
|
|
||||||
//! Start threaded read
|
//! \~english Start threaded read
|
||||||
|
//! \~russian Запускает потоковое чтение
|
||||||
void startThreadedRead() {if (!isRunning()) PIThread::start();}
|
void startThreadedRead() {if (!isRunning()) PIThread::start();}
|
||||||
|
|
||||||
//! Start threaded read and assign "threaded read slot" to "func"
|
//! \~english Start threaded read and assign threaded read callback to "func"
|
||||||
|
//! \~russian Запускает потоковое чтение и устанавливает callback потокового чтения в "func"
|
||||||
void startThreadedRead(ReadRetFunc func) {ret_func_ = func; startThreadedRead();}
|
void startThreadedRead(ReadRetFunc func) {ret_func_ = func; startThreadedRead();}
|
||||||
|
|
||||||
//! Stop threaded read. Hard stop terminate thread, otherwise wait fo 10 seconds
|
//! \~english Stop threaded read. Hard stop terminate thread, otherwise wait fo 10 seconds
|
||||||
|
//! \~russian Останавливает потоковое чтение. Жесткая остановка убивает поток, иначе ожидает 10 секунд
|
||||||
void stopThreadedRead(bool hard = true);
|
void stopThreadedRead(bool hard = true);
|
||||||
|
|
||||||
|
|
||||||
//! Return \b true if threaded write is started
|
//! \~english Returns if threaded write is started
|
||||||
|
//! \~russian Возвращает запущен ли поток записи
|
||||||
bool isThreadedWrite() const {return write_thread.isRunning();}
|
bool isThreadedWrite() const {return write_thread.isRunning();}
|
||||||
|
|
||||||
//! Start threaded write
|
//! \~english Start threaded write
|
||||||
|
//! \~russian Запускает потоковую запись
|
||||||
void startThreadedWrite() {if (!write_thread.isRunning()) write_thread.startOnce();}
|
void startThreadedWrite() {if (!write_thread.isRunning()) write_thread.startOnce();}
|
||||||
|
|
||||||
//! Stop threaded write. Hard stop terminate thread, otherwise wait fo 10 seconds
|
//! \~english Stop threaded write. Hard stop terminate thread, otherwise wait fo 10 seconds
|
||||||
|
//! \~russian Останавливает потоковую запись. Жесткая остановка убивает поток, иначе ожидает 10 секунд
|
||||||
void stopThreadedWrite(bool hard = true);
|
void stopThreadedWrite(bool hard = true);
|
||||||
|
|
||||||
//! Clear threaded write task queue
|
//! \~english Clear threaded write task queue
|
||||||
|
//! \~russian Очищает очередь потоковой записи
|
||||||
void clearThreadedWriteQueue();
|
void clearThreadedWriteQueue();
|
||||||
|
|
||||||
|
|
||||||
//! Start both threaded read and threaded write
|
//! \~english Start both threaded read and threaded write
|
||||||
|
//! \~russian Запускает потоковое чтение и запись
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
//! Stop both threaded read and threaded write. Hard stop terminate threads, otherwise wait fo 10 seconds
|
//! \~english Stop both threaded read and threaded write. Hard stop terminate threads, otherwise wait fo 10 seconds
|
||||||
|
//! \~russian Останавливает потоковое чтение и запись. Жесткая остановка убивает потоки, иначе ожидает 10 секунд
|
||||||
void stop(bool hard = true);
|
void stop(bool hard = true);
|
||||||
|
|
||||||
|
|
||||||
//! Read from device maximum "max_size" bytes to "read_to"
|
//! \~english Read from device maximum "max_size" bytes to "read_to"
|
||||||
|
//! \~russian Читает из устройства не более "max_size" байт в "read_to"
|
||||||
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
||||||
|
|
||||||
//! Read from device maximum "max_size" bytes and return them as PIByteArray
|
//! \~english Read from device maximum "max_size" bytes and returns them as PIByteArray
|
||||||
|
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
|
||||||
PIByteArray read(int max_size);
|
PIByteArray read(int max_size);
|
||||||
|
|
||||||
//! Write maximum "max_size" bytes of "data" to device
|
//! \~english Write maximum "max_size" bytes of "data" to device
|
||||||
|
//! \~russian Пишет в устройство не более "max_size" байт из "data"
|
||||||
int write(const void * data, int max_size) {return writeDevice(data, max_size);}
|
int write(const void * data, int max_size) {return writeDevice(data, max_size);}
|
||||||
|
|
||||||
//! Read from device for "timeout_ms" milliseconds and return readed data as PIByteArray. Timeout should to be greater than 0
|
//! \~english Read from device for "timeout_ms" milliseconds and return readed data as PIByteArray.
|
||||||
|
//! Timeout should to be greater than 0
|
||||||
|
//! \~russian Читает из устройства в течении "timeout_ms" миллисекунд и возвращает данные как PIByteArray.
|
||||||
|
//! Таймаут должен быть больше 0
|
||||||
PIByteArray readForTime(double timeout_ms);
|
PIByteArray readForTime(double timeout_ms);
|
||||||
|
|
||||||
|
|
||||||
//! Add task to threaded write queue and return task ID
|
//! \~english Add task to threaded write queue and return task ID
|
||||||
|
//! \~russian Добавляет данные в очередь на потоковую запись и возвращает ID задания
|
||||||
ullong writeThreaded(const void * data, int max_size) {return writeThreaded(PIByteArray(data, uint(max_size)));}
|
ullong writeThreaded(const void * data, int max_size) {return writeThreaded(PIByteArray(data, uint(max_size)));}
|
||||||
|
|
||||||
//! Add task to threaded write queue and return task ID
|
//! \~english Add task to threaded write queue and return task ID
|
||||||
|
//! \~russian Добавляет данные в очередь на потоковую запись и возвращает ID задания
|
||||||
ullong writeThreaded(const PIByteArray & data);
|
ullong writeThreaded(const PIByteArray & data);
|
||||||
|
|
||||||
|
|
||||||
//! Configure device from section "section" of file "config_file", if "parent_section" parent section also will be read
|
//! \~english Configure device from section "section" of file "config_file", if "parent_section" parent section also will be read
|
||||||
|
//! \~russian
|
||||||
bool configure(const PIString & config_file, const PIString & section, bool parent_section = false);
|
bool configure(const PIString & config_file, const PIString & section, bool parent_section = false);
|
||||||
|
|
||||||
|
|
||||||
//! Reimplement to construct full unambiguous string prefix. \ref PIIODevice_sec7
|
//! \~english Returns full unambiguous string prefix. \ref PIIODevice_sec7
|
||||||
virtual PIString fullPathPrefix() const {return PIString();}
|
//! \~russian Возвращает префикс устройства. \ref PIIODevice_sec7
|
||||||
|
virtual PIConstChars fullPathPrefix() const {return "";}
|
||||||
|
|
||||||
//! Returns full unambiguous string, describes this device, \a fullPathPrefix() + "://"
|
static PIConstChars fullPathPrefixS() {return "";}
|
||||||
|
|
||||||
|
//! \~english Returns full unambiguous string, describes this device, \a fullPathPrefix() + "://" + ...
|
||||||
|
//! \~russian Возвращает строку полного описания для этого устройства, \a fullPathPrefix() + "://" + ...
|
||||||
PIString constructFullPath() const;
|
PIString constructFullPath() const;
|
||||||
|
|
||||||
//! Configure device with parameters of full unambiguous string
|
//! \~english Configure device with parameters of full unambiguous string
|
||||||
|
//! \~russian Настраивает устройство из параметров строки полного описания
|
||||||
void configureFromFullPath(const PIString & full_path);
|
void configureFromFullPath(const PIString & full_path);
|
||||||
|
|
||||||
//! Returns PIVariantTypes::IODevice, describes this device
|
//! \~english Returns PIVariantTypes::IODevice, describes this device
|
||||||
|
//! \~russian Возвращает PIVariantTypes::IODevice, описывающий это устройство
|
||||||
PIVariantTypes::IODevice constructVariant() const;
|
PIVariantTypes::IODevice constructVariant() const;
|
||||||
|
|
||||||
//! Configure device from PIVariantTypes::IODevice
|
//! \~english Configure device from PIVariantTypes::IODevice
|
||||||
|
//! \~russian Настраивает устройство из PIVariantTypes::IODevice
|
||||||
void configureFromVariant(const PIVariantTypes::IODevice & d);
|
void configureFromVariant(const PIVariantTypes::IODevice & d);
|
||||||
|
|
||||||
//! \brief Try to determine suitable device, create new one, configure it with \a configureFromFullPath() and returns it.
|
//! \~english Try to create new device by prefix, configure it with \a configureFromFullPath() and returns it.
|
||||||
//! \details To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() + "://".
|
//! \~russian Пытается создать новое устройство по префиксу, настраивает с помощью \a configureFromFullPath() и возвращает его
|
||||||
//! See \ref PIIODevice_sec7
|
|
||||||
static PIIODevice * createFromFullPath(const PIString & full_path);
|
static PIIODevice * createFromFullPath(const PIString & full_path);
|
||||||
|
|
||||||
//! \brief Try to determine suitable device, create new one, configure it with \a configureFromVariant() and returns it.
|
//! \~english Try to create new device by prefix, configure it with \a configureFromVariant() and returns it.
|
||||||
//! \details To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() + "://".
|
//! \~russian Пытается создать новое устройство по префиксу, настраивает с помощью \a configureFromVariant() и возвращает его
|
||||||
//! See \ref PIIODevice_sec7
|
|
||||||
static PIIODevice * createFromVariant(const PIVariantTypes::IODevice & d);
|
static PIIODevice * createFromVariant(const PIVariantTypes::IODevice & d);
|
||||||
|
|
||||||
static PIString normalizeFullPath(const PIString & full_path);
|
static PIString normalizeFullPath(const PIString & full_path);
|
||||||
|
|
||||||
static void splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode = 0, DeviceOptions * opts = 0);
|
static void splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode = 0, DeviceOptions * opts = 0);
|
||||||
|
|
||||||
//! Returns fullPath prefixes of all registered devices
|
//! \~english Returns fullPath prefixes of all registered devices
|
||||||
|
//! \~russian Возвращает префиксы всех зарегистрированных устройств
|
||||||
static PIStringList availablePrefixes();
|
static PIStringList availablePrefixes();
|
||||||
|
|
||||||
|
//! \~english Returns class names of all registered devices
|
||||||
|
//! \~russian Возвращает имена классов всех зарегистрированных устройств
|
||||||
|
static PIStringList availableClasses();
|
||||||
|
|
||||||
|
static void registerDevice(PIConstChars prefix, PIConstChars classname, PIIODevice*(*fabric)());
|
||||||
|
|
||||||
|
|
||||||
EVENT_HANDLER(bool, open);
|
EVENT_HANDLER(bool, open);
|
||||||
EVENT_HANDLER1(bool, open, const PIString &, _path);
|
EVENT_HANDLER1(bool, open, const PIString &, _path);
|
||||||
@@ -279,114 +368,152 @@ public:
|
|||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn bool open()
|
//! \fn bool open()
|
||||||
//! \brief Open device
|
//! \~english Open device
|
||||||
|
//! \~russian Открывает устройство
|
||||||
|
|
||||||
//! \fn bool open(const PIString & path)
|
//! \fn bool open(const PIString & path)
|
||||||
//! \brief Open device with path "path"
|
//! \~english Open device with path "path"
|
||||||
|
//! \~russian Открывает устройство с путём "path"
|
||||||
|
|
||||||
//! \fn bool open(const DeviceMode & mode)
|
//! \fn bool open(const DeviceMode & mode)
|
||||||
//! \brief Open device with mode "mode"
|
//! \~english Open device with mode "mode"
|
||||||
|
//! \~russian Открывает устройство с режимом открытия "mode"
|
||||||
|
|
||||||
//! \fn bool open(const PIString & path, const DeviceMode & mode)
|
//! \fn bool open(const PIString & path, const DeviceMode & mode)
|
||||||
//! \brief Open device with path "path" and mode "mode"
|
//! \~english Open device with path "path" and mode "mode"
|
||||||
|
//! \~russian Открывает устройство с путём "path" и режимом открытия "mode"
|
||||||
|
|
||||||
//! \fn bool close()
|
//! \fn bool close()
|
||||||
//! \brief Close device
|
//! \~english Close device
|
||||||
|
//! \~russian Закрывает устройство
|
||||||
|
|
||||||
//! \fn int write(PIByteArray data)
|
//! \fn int write(PIByteArray data)
|
||||||
//! \brief Write "data" to device
|
//! \~english Write "data" to device
|
||||||
|
//! \~russian Пишет "data" в устройство
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
//! \vhandlers
|
//! \vhandlers
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn void flush()
|
//! \fn void flush()
|
||||||
//! \brief Immediate write all buffers
|
//! \~english Immediate write all buffers
|
||||||
|
//! \~russian Немедленно записать все буферизированные данные
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
//! \events
|
//! \events
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn void opened()
|
//! \fn void opened()
|
||||||
//! \brief Raise if succesfull open
|
//! \~english Raise if succesfull open
|
||||||
|
//! \~russian Вызывается при успешном открытии
|
||||||
|
|
||||||
//! \fn void closed()
|
//! \fn void closed()
|
||||||
//! \brief Raise if succesfull close
|
//! \~english Raise if succesfull close
|
||||||
|
//! \~russian Вызывается при успешном закрытии
|
||||||
|
|
||||||
//! \fn void threadedReadEvent(uchar * readed, int size)
|
//! \fn void threadedReadEvent(uchar * readed, int size)
|
||||||
//! \brief Raise if read thread succesfull read some data
|
//! \~english Raise if read thread succesfull read some data
|
||||||
|
//! \~russian Вызывается при успешном потоковом чтении данных
|
||||||
|
|
||||||
//! \fn void threadedWriteEvent(ullong id, int written_size)
|
//! \fn void threadedWriteEvent(ullong id, int written_size)
|
||||||
//! \brief Raise if write thread successfull write some data of task with ID "id"
|
//! \~english Raise if write thread successfull write some data of task with ID "id"
|
||||||
|
//! \~russian Вызывается при успешной потоковой записи данных с ID задания "id"
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
//! \ioparams
|
//! \ioparams
|
||||||
//! \{
|
//! \{
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
//! \brief setReopenEnabled, default "true"
|
//! \~english setReopenEnabled, default "true"
|
||||||
|
//! \~russian setReopenEnabled, по умолчанию "true"
|
||||||
bool reopenEnabled;
|
bool reopenEnabled;
|
||||||
|
|
||||||
//! \brief setReopenTimeout in ms, default 1000
|
//! \~english setReopenTimeout in milliseconds, default 1000
|
||||||
|
//! \~russian setReopenTimeout в миллисекундах, по умолчанию 1000
|
||||||
int reopenTimeout;
|
int reopenTimeout;
|
||||||
|
|
||||||
//! \brief setThreadedReadBufferSize in bytes, default 4096
|
//! \~english setThreadedReadBufferSize in bytes, default 4096
|
||||||
|
//! \~russian setThreadedReadBufferSize в байтах, по умолчанию 4096
|
||||||
int threadedReadBufferSize;
|
int threadedReadBufferSize;
|
||||||
#endif
|
#endif
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! Function executed before first \a openDevice() or from constructor
|
//! \~english Function executed before first \a openDevice() or from constructor
|
||||||
|
//! \~russian Метод вызывается перед первым \a openDevice() или из конструктора
|
||||||
virtual bool init() {return true;}
|
virtual bool init() {return true;}
|
||||||
|
|
||||||
//! Reimplement to configure device from entries "e_main" and "e_parent", cast arguments to \a PIConfig::Entry*
|
//! \~english Reimplement to configure device from entries "e_main" and "e_parent", cast arguments to \a PIConfig::Entry*
|
||||||
|
//! \~russian
|
||||||
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) {return true;}
|
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) {return true;}
|
||||||
|
|
||||||
//! Reimplement to open device, return value will be set to "opened_" variable; don't call this function in subclass, use open()
|
//! \~english Reimplement to open device, return value will be set to "opened_" variable.
|
||||||
|
//! Don't call this function in subclass, use \a open()!
|
||||||
|
//! \~russian Переопределите для открытия устройства, возвращаемое значение будет установлено в
|
||||||
|
//! переменную "opened_". Не используйте напрямую, только через \a open()!
|
||||||
virtual bool openDevice() = 0; // use path_, type_, opened_, init_ variables
|
virtual bool openDevice() = 0; // use path_, type_, opened_, init_ variables
|
||||||
|
|
||||||
//! Reimplement to close device, inverse return value will be set to "opened_" variable
|
//! \~english Reimplement to close device, inverse return value will be set to "opened_" variable
|
||||||
|
//! \~russian Переопределите для закрытия устройства, обратное возвращаемое значение будет установлено в переменную "opened_"
|
||||||
virtual bool closeDevice() {return true;} // use path_, type_, opened_, init_ variables
|
virtual bool closeDevice() {return true;} // use path_, type_, opened_, init_ variables
|
||||||
|
|
||||||
//! Reimplement this function to read from your device
|
//! \~english Reimplement this function to read from your device
|
||||||
|
//! \~russian Переопределите для чтения данных из устройства
|
||||||
virtual int readDevice(void * read_to, int max_size) {piCoutObj << "\"read\" is not implemented!"; return -2;}
|
virtual int readDevice(void * read_to, int max_size) {piCoutObj << "\"read\" is not implemented!"; return -2;}
|
||||||
|
|
||||||
//! Reimplement this function to write to your device
|
//! \~english Reimplement this function to write to your device
|
||||||
|
//! \~russian Переопределите для записи данных в устройство
|
||||||
virtual int writeDevice(const void * data, int max_size) {piCoutObj << "\"write\" is not implemented!"; return -2;}
|
virtual int writeDevice(const void * data, int max_size) {piCoutObj << "\"write\" is not implemented!"; return -2;}
|
||||||
|
|
||||||
//! Function executed when thread read some data, default implementation execute external slot "ret_func_"
|
//! \~english Function executed when thread read some data, default implementation execute external callback "ret_func_"
|
||||||
|
//! \~russian Метод вызывается после каждого успешного потокового чтения, по умолчанию вызывает callback "ret_func_"
|
||||||
virtual bool threadedRead(uchar * readed, int size);
|
virtual bool threadedRead(uchar * readed, int size);
|
||||||
|
|
||||||
//! Reimplement to construct full unambiguous string, describes this device. Default implementation returns \a path()
|
//! \~english Reimplement to construct full unambiguous string, describes this device.
|
||||||
|
//! Default implementation returns \a path()
|
||||||
|
//! \~russian Переопределите для создания строки полного описания устройства.
|
||||||
|
//! По умолчанию возвращает \a path()
|
||||||
virtual PIString constructFullPathDevice() const {return path();}
|
virtual PIString constructFullPathDevice() const {return path();}
|
||||||
|
|
||||||
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
|
//! \~english Reimplement to configure your device with parameters of full unambiguous string.
|
||||||
|
//! Default implementation call \a setPath()
|
||||||
|
//! \~russian Переопределите для настройки устройства из строки полного описания.
|
||||||
|
//! По умолчанию вызывает \a setPath()
|
||||||
virtual void configureFromFullPathDevice(const PIString & full_path) {setPath(full_path);}
|
virtual void configureFromFullPathDevice(const PIString & full_path) {setPath(full_path);}
|
||||||
|
|
||||||
//! Reimplement to construct device properties.
|
//! \~english Reimplement to construct device properties.
|
||||||
//! Default implementation return PIPropertyStorage with \"path\" entry
|
//! Default implementation return PIPropertyStorage with \"path\" entry
|
||||||
|
//! \~russian Переопределите для создания свойств устройства.
|
||||||
|
//! По умолчанию возвращает PIPropertyStorage со свойством \"path\"
|
||||||
virtual PIPropertyStorage constructVariantDevice() const;
|
virtual PIPropertyStorage constructVariantDevice() const;
|
||||||
|
|
||||||
//! Reimplement to configure your device from PIPropertyStorage. Options and mode already applied.
|
//! \~english Reimplement to configure your device from PIPropertyStorage. Options and mode already applied.
|
||||||
//! Default implementation apply \"path\" entry
|
//! Default implementation apply \"path\" entry
|
||||||
|
//! \~russian Переопределите для настройки устройства из PIPropertyStorage. Опции и режим уже применены.
|
||||||
|
//! По умолчанию устанавливает свойство \"path\"
|
||||||
virtual void configureFromVariantDevice(const PIPropertyStorage & d);
|
virtual void configureFromVariantDevice(const PIPropertyStorage & d);
|
||||||
|
|
||||||
//! Reimplement to apply new device options
|
//! \~english Reimplement to apply new device options
|
||||||
|
//! \~russian Переопределите для применения новых опций устройства
|
||||||
virtual void optionsChanged() {;}
|
virtual void optionsChanged() {;}
|
||||||
|
|
||||||
//! Reimplement to return correct \a DeviceInfoFlags. Default implementation returns 0
|
//! \~english Reimplement to return correct \a DeviceInfoFlags. Default implementation returns 0
|
||||||
|
//! \~russian Переопределите для возврата правильных \a DeviceInfoFlags. По умолчанию возвращает 0
|
||||||
virtual DeviceInfoFlags deviceInfoFlags() const {return 0;}
|
virtual DeviceInfoFlags deviceInfoFlags() const {return 0;}
|
||||||
|
|
||||||
//! Reimplement to apply new \a threadedReadBufferSize()
|
//! \~english Reimplement to apply new \a threadedReadBufferSize()
|
||||||
|
//! \~russian Переопределите для применения нового \a threadedReadBufferSize()
|
||||||
virtual void threadedReadBufferSizeChanged() {;}
|
virtual void threadedReadBufferSizeChanged() {;}
|
||||||
|
|
||||||
//! Invoked after hard read thread stop
|
//! \~english Invoked after hard read thread stop
|
||||||
|
//! \~russian Вызывается после жесткой остановки потока чтения
|
||||||
virtual void threadedReadTerminated() {;}
|
virtual void threadedReadTerminated() {;}
|
||||||
|
|
||||||
//! Invoked after hard write thread stop
|
//! \~english Invoked after hard write thread stop
|
||||||
|
//! \~russian Вызывается после жесткой остановки потока записи
|
||||||
virtual void threadedWriteTerminated() {;}
|
virtual void threadedWriteTerminated() {;}
|
||||||
|
|
||||||
static PIIODevice * newDeviceByPrefix(const PIString & prefix);
|
static PIIODevice * newDeviceByPrefix(const char * prefix);
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
@@ -408,6 +535,7 @@ private:
|
|||||||
void run();
|
void run();
|
||||||
void end() {terminate();}
|
void end() {terminate();}
|
||||||
static void cacheFullPath(const PIString & full_path, const PIIODevice * d);
|
static void cacheFullPath(const PIString & full_path, const PIIODevice * d);
|
||||||
|
static PIMap<PIConstChars, FabricInfo> & fabrics();
|
||||||
|
|
||||||
PITimer timer;
|
PITimer timer;
|
||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
|
|||||||
@@ -20,12 +20,15 @@
|
|||||||
#include "piiostring.h"
|
#include "piiostring.h"
|
||||||
|
|
||||||
|
|
||||||
/*! \class PIIOString
|
//! \class PIIOString piiostring.h
|
||||||
* \brief PIIODevice wrapper around PIString
|
//! \details
|
||||||
*
|
//! \~english
|
||||||
* \section PIIOString_sec0 Synopsis
|
//! This class allow you to use PIString as PIIODevice, e.g. to pass it to PIConfig.
|
||||||
* This class allow you to use PIString as PIIODevice and pass it to, e.g. PIConfig
|
//!
|
||||||
*/
|
//! \~russian
|
||||||
|
//! Этот класс позволяет использовать PIString в качестве PIIODevice, например,
|
||||||
|
//! для передачи в PIConfig.
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
PIIOString::PIIOString(PIString * string, PIIODevice::DeviceMode mode) {
|
PIIOString::PIIOString(PIString * string, PIIODevice::DeviceMode mode) {
|
||||||
|
|||||||
@@ -29,47 +29,63 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIIODevice wrapper around PIString.
|
||||||
|
//! \~russian Обёртка PIIODevice вокруг PIString.
|
||||||
class PIP_EXPORT PIIOString: public PIIODevice
|
class PIP_EXPORT PIIOString: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIIOString)
|
PIIODEVICE(PIIOString, "")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Contructs %PIIOString with \"string\" content and \"mode\" open mode
|
//! \~english Contructs %PIIOString with "string" content and "mode" open mode
|
||||||
|
//! \~russian Создает %PIIOString с содержимым "string" и режимом открытия "mode"
|
||||||
explicit PIIOString(PIString * string = 0, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PIIOString(PIString * string = 0, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Contructs %PIIOString with \"string\" content only for read
|
//! \~english Contructs %PIIOString with "string" content only for read
|
||||||
|
//! \~russian Создает %PIIOString с содержимым "string" только для чтения
|
||||||
explicit PIIOString(const PIString & string);
|
explicit PIIOString(const PIString & string);
|
||||||
|
|
||||||
//! Returns content
|
//! \~english Returns content
|
||||||
|
//! \~russian Возвращает содержимое
|
||||||
PIString * string() const {return str;}
|
PIString * string() const {return str;}
|
||||||
|
|
||||||
//! Clear content string
|
//! \~english Clear content string
|
||||||
|
//! \~russian Очищает содержимое строки
|
||||||
void clear() {if (str) str->clear(); pos = 0;}
|
void clear() {if (str) str->clear(); pos = 0;}
|
||||||
|
|
||||||
//! Open \"string\" content with \"mode\" open mode
|
//! \~english Open "string" content with "mode" open mode
|
||||||
|
//! \~russian Открывает содержимое "string" с режимом открытия "mode"
|
||||||
bool open(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
bool open(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
//! Open \"string\" content only for read
|
//! \~english Open "string" content only for read
|
||||||
|
//! \~russian Открывает содержимое "string" только для чтения
|
||||||
bool open(const PIString & string);
|
bool open(const PIString & string);
|
||||||
|
|
||||||
//! Returns if position is at the end of content
|
//! \~english Returns if position is at the end of content
|
||||||
|
//! \~russian Возвращает в конце содержимого ли позиция
|
||||||
bool isEnd() const {if (!str) return true; return pos >= str->size_s();}
|
bool isEnd() const {if (!str) return true; return pos >= str->size_s();}
|
||||||
|
|
||||||
|
|
||||||
//! Move read/write position to \"position\"
|
//! \~english Move read/write position to "position"
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на "position"
|
||||||
void seek(llong position) {pos = position;}
|
void seek(llong position) {pos = position;}
|
||||||
|
|
||||||
//! Move read/write position to the begin of the string
|
//! \~english Move read/write position to the beginning of the string
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на начало строки
|
||||||
void seekToBegin() {if (str) pos = 0;}
|
void seekToBegin() {if (str) pos = 0;}
|
||||||
|
|
||||||
//! Move read/write position to the end of the string
|
//! \~english Move read/write position to the end of the string
|
||||||
|
//! \~russian Перемещает позицию чтения/записи на конец строки
|
||||||
void seekToEnd() {if (str) pos = str->size_s();}
|
void seekToEnd() {if (str) pos = str->size_s();}
|
||||||
|
|
||||||
|
|
||||||
//! Read one text line and return it
|
//! \~english Read one text line and return it
|
||||||
|
//! \~russian Читает одну строку и возвращает её
|
||||||
PIString readLine();
|
PIString readLine();
|
||||||
|
|
||||||
//! Insert string \"string\" into content at current position
|
//! \~english Insert string "string" into content at current position
|
||||||
|
//! \~russian Вставляет строку "string" в содержимое буфера в текущую позицию
|
||||||
int writeString(const PIString & string);
|
int writeString(const PIString & string);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
class PIP_EXPORT PIPeer: public PIIODevice
|
class PIP_EXPORT PIPeer: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIPeer)
|
PIIODEVICE(PIPeer, "peer")
|
||||||
private:
|
private:
|
||||||
class PeerData;
|
class PeerData;
|
||||||
|
|
||||||
@@ -168,7 +168,6 @@ private:
|
|||||||
|
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("peer");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString &full_path);
|
void configureFromFullPathDevice(const PIString &full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
|
|||||||
@@ -137,21 +137,33 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*! \class PISerial
|
//! \class PISerial piserial.h
|
||||||
* \brief Serial device
|
//! \details
|
||||||
*
|
//! \~english \section PISerial_sec0 Synopsis
|
||||||
* \section PISerial_sec0 Synopsis
|
//! \~russian \section PISerial_sec0 Краткий обзор
|
||||||
* This class provide access to serial device, e.g. COM port. It can read,
|
//! \~english
|
||||||
* write, wait for write. There are several read and write functions.
|
//! This class provide access to serial device, e.g. COM port. It can read,
|
||||||
*
|
//! write, wait for write. There are several read and write functions.
|
||||||
* \section PISerial_sec1 FullPath
|
//!
|
||||||
* Since version 1.16.0 you can use as \a path DeviceInfo::id() USB identifier.
|
//! \~russian
|
||||||
* \code
|
//! Этот класс предоставляет доступ к последовательному порту, например, COM-порт.
|
||||||
* PISerial * s = new PISerial("0403:6001");
|
//!
|
||||||
* PIIODevice * d = PIIODevice::createFromFullPath("ser://0403:6001:115200");
|
//! \~english \section PISerial_sec1 FullPath
|
||||||
* \endcode
|
//! \~russian \section PISerial_sec1 Строка полного описания
|
||||||
*
|
//! \~english
|
||||||
*/
|
//! Since version 1.16.0 you can use as \a path \a PISerial::DeviceInfo::id() USB identifier
|
||||||
|
//! for USB devices.
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Начиная с версии 1.16.0 можно в качестве \a path использовать \a PISerial::DeviceInfo::id()
|
||||||
|
//! USB идентификатор для USB устройств.
|
||||||
|
//!
|
||||||
|
//! \~\code
|
||||||
|
//! PISerial * s = new PISerial("0403:6001");
|
||||||
|
//! PIIODevice * d = PIIODevice::createFromFullPath("ser://0403:6001:115200");
|
||||||
|
//! \endcode
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
REGISTER_DEVICE(PISerial)
|
REGISTER_DEVICE(PISerial)
|
||||||
|
|
||||||
@@ -289,6 +301,16 @@ bool PISerial::isRNG() const {return isBit(TIOCM_RNG, "RNG");}
|
|||||||
bool PISerial::isDSR() const {return isBit(TIOCM_DSR, "DSR");}
|
bool PISerial::isDSR() const {return isBit(TIOCM_DSR, "DSR");}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! If enabled, sends a continuous stream of zero bits.
|
||||||
|
//! Returns if state changed successfully.
|
||||||
|
//! \note The serial port has to be open before using this method
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Если включено, отсылается непрерывный поток нулей.
|
||||||
|
//! Возвращает успешна ли смена состояния.
|
||||||
|
//! \note Порт должен быть открыт перед использованием этого метода
|
||||||
bool PISerial::setBreak(bool enabled) {
|
bool PISerial::setBreak(bool enabled) {
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!";
|
piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!";
|
||||||
@@ -416,14 +438,24 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Advanced read function
|
//! \details
|
||||||
* \details Read to pointer "read_to" no more than "max_size" and no longer
|
//! \~english
|
||||||
* than "timeout_ms" milliseconds. If "timeout_ms" < 0 function will be
|
//! Read to pointer "read_to" no more than "max_size" and no longer
|
||||||
* wait forever until "max_size" will be readed. If size <= 0 function
|
//! than "timeout_ms" milliseconds.\n
|
||||||
* immediate returns \b false. For read data with unknown size use function
|
//! If "timeout_ms" < 0 function will be wait forever until "max_size" will be readed.\n
|
||||||
* \a readData().
|
//! If "size" <= 0 function immediate returns \b false.\n
|
||||||
* \returns \b True if readed bytes count = "max_size", else \b false
|
//! For read data with unknown size use function \a readData().
|
||||||
* \sa \a readData() */
|
//! \returns If readed bytes count = "max_size"
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Читает в указатель "read_to" не более "max_size" байт и не дольше
|
||||||
|
//! чем "timeout_ms" миллисекунд.\n
|
||||||
|
//! Если "timeout_ms" < 0 метод ожидает бесконечно, пока не будет прочитано "max_size" байт.\n
|
||||||
|
//! Если "size" <= 0, то метод немедленно возвращает \b false.\n
|
||||||
|
//! Для чтения данных неизвестного размера используется метод \a readData().
|
||||||
|
//! \returns Если количество прочитанных байт = "max_size"
|
||||||
|
//!
|
||||||
|
//! \sa \a readString(), \a readData()
|
||||||
bool PISerial::read(void * data, int size, double timeout_ms) {
|
bool PISerial::read(void * data, int size, double timeout_ms) {
|
||||||
if (data == 0 || size <= 0) return false;
|
if (data == 0 || size <= 0) return false;
|
||||||
int ret, all = 0;
|
int ret, all = 0;
|
||||||
@@ -454,15 +486,25 @@ bool PISerial::read(void * data, int size, double timeout_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Advanced read function
|
//! \details
|
||||||
* \details Read all or no more than "size" and no longer than
|
//! \~english
|
||||||
* "timeout_ms" milliseconds. If "timeout_ms" < 0 function will be
|
//! Read all or no more than "size" bytes and no longer than "timeout_ms" milliseconds.\n
|
||||||
* wait forever until "size" will be readed. If "size" <= 0
|
//! If "timeout_ms" < 0 function will be wait forever until "max_size" will be readed.\n
|
||||||
* function will be read all until "timeout_ms" elaped. \n If size <= 0
|
//! If "size" <= 0 function will be read all until "timeout_ms" elaped.\n
|
||||||
* and "timeout_ms" <= 0 function immediate returns empty string.
|
//! If "size" <= 0 and "timeout_ms" <= 0 function immediate returns empty string.\n
|
||||||
* \n This function similar to \a readData() but returns data as string.
|
//! This function similar to \a readData() but returns data as string.
|
||||||
* \sa \a readData() */
|
//! \returns If readed bytes count = "max_size"
|
||||||
PIString PISerial::read(int size, double timeout_ms) {
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Читает всё или не более "size" байт и не дольше чем "timeout_ms" миллисекунд.\n
|
||||||
|
//! Если "timeout_ms" < 0 метод ожидает бесконечно, пока не будет прочитано "max_size" байт.\n
|
||||||
|
//! Если "size" <= 0, то читает всё в течении "timeout_ms" миллисекунд.\n
|
||||||
|
//! Если "size" <= 0 и "timeout_ms" <= 0, то метод немедленно возвращает пустую строку.\n
|
||||||
|
//! Этот метод аналогичен \a readData(), но возвращает строку.
|
||||||
|
//! \returns Если количество прочитанных байт = "max_size"
|
||||||
|
//!
|
||||||
|
//! \sa \a readData()
|
||||||
|
PIString PISerial::readString(int size, double timeout_ms) {
|
||||||
PIString str;
|
PIString str;
|
||||||
if (size <= 0 && timeout_ms <= 0.) return str;
|
if (size <= 0 && timeout_ms <= 0.) return str;
|
||||||
int ret, all = 0;
|
int ret, all = 0;
|
||||||
@@ -506,14 +548,24 @@ PIString PISerial::read(int size, double timeout_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Advanced read function
|
//! \details
|
||||||
* \details Read all or no more than "size" and no longer than
|
//! \~english
|
||||||
* "timeout_ms" milliseconds. If "timeout_ms" < 0 function will be
|
//! Read all or no more than "size" bytes and no longer than "timeout_ms" milliseconds.\n
|
||||||
* wait forever until "size" will be readed. If "size" <= 0
|
//! If "timeout_ms" < 0 function will be wait forever until "max_size" will be readed.\n
|
||||||
* function will be read all until "timeout_ms" elaped. \n If size <= 0
|
//! If "size" <= 0 function will be read all until "timeout_ms" elaped.\n
|
||||||
* and "timeout_ms" <= 0 function immediate returns empty byte array.
|
//! If "size" <= 0 and "timeout_ms" <= 0 function immediate returns empty string.\n
|
||||||
* \n This function similar to \a read() but returns data as byte array.
|
//! This function similar to \a readString() but returns data as byte array.
|
||||||
* \sa \a read() */
|
//! \returns If readed bytes count = "max_size"
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Читает всё или не более "size" байт и не дольше чем "timeout_ms" миллисекунд.\n
|
||||||
|
//! Если "timeout_ms" < 0 метод ожидает бесконечно, пока не будет прочитано "max_size" байт.\n
|
||||||
|
//! Если "size" <= 0, то читает всё в течении "timeout_ms" миллисекунд.\n
|
||||||
|
//! Если "size" <= 0 и "timeout_ms" <= 0, то метод немедленно возвращает пустую строку.\n
|
||||||
|
//! Этот метод аналогичен \a readString(), но возвращает массив байт.
|
||||||
|
//! \returns Если количество прочитанных байт = "max_size"
|
||||||
|
//!
|
||||||
|
//! \sa \a readString()
|
||||||
PIByteArray PISerial::readData(int size, double timeout_ms) {
|
PIByteArray PISerial::readData(int size, double timeout_ms) {
|
||||||
PIByteArray str;
|
PIByteArray str;
|
||||||
if (size <= 0 && timeout_ms <= 0.) return str;
|
if (size <= 0 && timeout_ms <= 0.) return str;
|
||||||
@@ -722,11 +774,20 @@ void PISerial::setTimeouts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Basic read function
|
//! \details
|
||||||
* \details Read to pointer "read_to" no more than "max_size". If read is
|
//! \~english
|
||||||
* set to blocking this function will be wait at least one byte.
|
//! Read to pointer "read_to" no more than "max_size".
|
||||||
* \returns Readed bytes count
|
//! If \a PIIODevice::BlockingRead option set this function
|
||||||
* \sa \a readData() */
|
//! will be wait at least one byte.
|
||||||
|
//! \returns Readed bytes count, -1 for error
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Читает в указатель "read_to" не более "max_size" байт.
|
||||||
|
//! Если установлена опция \a PIIODevice::BlockingRead,
|
||||||
|
//! то этот метод ожидает хотя бы одного байта.
|
||||||
|
//! \returns Количество прочитанных байт, -1 при ошибке
|
||||||
|
//!
|
||||||
|
//! \~\sa \a readData(), \a readString()
|
||||||
int PISerial::readDevice(void * read_to, int max_size) {
|
int PISerial::readDevice(void * read_to, int max_size) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (!canRead()) return -1;
|
if (!canRead()) return -1;
|
||||||
|
|||||||
@@ -29,22 +29,32 @@
|
|||||||
#include "pitimer.h"
|
#include "pitimer.h"
|
||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Serial device.
|
||||||
|
//! \~russian Последовательный порт.
|
||||||
class PIP_EXPORT PISerial: public PIIODevice
|
class PIP_EXPORT PISerial: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PISerial)
|
PIIODEVICE(PISerial, "ser")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Contructs an empty %PISerial
|
//! \~english Contructs an empty %PISerial
|
||||||
|
//! \~russian Создает пустой %PISerial
|
||||||
explicit PISerial();
|
explicit PISerial();
|
||||||
|
|
||||||
//! \brief Parameters of PISerial
|
virtual ~PISerial();
|
||||||
|
|
||||||
|
//! \~english Parameters of PISerial
|
||||||
|
//! \~russian Параметры PISerial
|
||||||
enum Parameters {
|
enum Parameters {
|
||||||
ParityControl /*! Enable parity check and generate */ = 0x1,
|
ParityControl /*! \~english Enable parity check and generate \~russian Включить генерацию и проверку контроля чётности */ = 0x1,
|
||||||
ParityOdd /*! Parity is odd instead of even */ = 0x2,
|
ParityOdd /*! \~english Parity is odd instead of even \~russian Нечётный контроль чётности вместо чётного */ = 0x2,
|
||||||
TwoStopBits /*! Two stop bits instead of one */ = 0x4
|
TwoStopBits /*! \~english Two stop bits instead of one \~russian Два стоповых бита вместо одного */ = 0x4
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Speed of PISerial
|
//! \~english Speed of PISerial
|
||||||
|
//! \~russian Скорость PISerial
|
||||||
enum Speed {
|
enum Speed {
|
||||||
S50 /*! 50 baud */ = 50,
|
S50 /*! 50 baud */ = 50,
|
||||||
S75 /*! 75 baud */ = 75,
|
S75 /*! 75 baud */ = 75,
|
||||||
@@ -75,72 +85,93 @@ public:
|
|||||||
S4000000 /*! 4000000 baud */ = 4000000
|
S4000000 /*! 4000000 baud */ = 4000000
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Information about serial device
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Information about serial device
|
||||||
|
//! \~russian Информация о последовательном устройстве
|
||||||
struct PIP_EXPORT DeviceInfo {
|
struct PIP_EXPORT DeviceInfo {
|
||||||
DeviceInfo();
|
DeviceInfo();
|
||||||
|
|
||||||
//! \brief String representation of USB ID in format \"xxxx:xxxx\"
|
//! \~english Returns string representation of USB ID in format "xxxx:xxxx" (vID:pID)
|
||||||
|
//! \~russian Возвращает строковое представление USB ID в формате "xxxx:xxxx" (vID:pID)
|
||||||
PIString id() const;
|
PIString id() const;
|
||||||
|
|
||||||
//! \brief USB Vendor ID
|
//! \~english USB Vendor ID
|
||||||
|
//! \~russian USB Vendor ID
|
||||||
uint vID;
|
uint vID;
|
||||||
|
|
||||||
//! \brief USB Product ID
|
//! \~english USB Product ID
|
||||||
|
//! \~russian USB Product ID
|
||||||
uint pID;
|
uint pID;
|
||||||
|
|
||||||
//! \brief Path to device, e.g. "COM2" or "/dev/ttyUSB0"
|
//! \~english Path to device, e.g. "COM2" or "/dev/ttyUSB0"
|
||||||
|
//! \~russian Путь к устройству, например "COM2" или "/dev/ttyUSB0"
|
||||||
PIString path;
|
PIString path;
|
||||||
|
|
||||||
//! \brief Device description
|
//! \~english Device description
|
||||||
|
//! \~russian Описание устройства
|
||||||
PIString description;
|
PIString description;
|
||||||
|
|
||||||
//! \brief Device manufacturer
|
//! \~english Device manufacturer
|
||||||
|
//! \~russian Описание производителя
|
||||||
PIString manufacturer;
|
PIString manufacturer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Contructs %PISerial with device name "device", speed "speed" and parameters "params"
|
//! \~english Contructs %PISerial with device name "device", speed "speed" and parameters "params"
|
||||||
|
//! \~russian Создает %PISerial с именем устройства "device", скоростью "speed" и параметрами "params"
|
||||||
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
|
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
|
||||||
|
|
||||||
virtual ~PISerial();
|
|
||||||
|
|
||||||
|
//! \~english Set both input and output speed to "speed"
|
||||||
//! Set both input and output speed to "speed"
|
//! \~russian Устанавливает скорости приема и передачи в "speed"
|
||||||
void setSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); setProperty("inSpeed", (int)speed); applySettings();}
|
void setSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); setProperty("inSpeed", (int)speed); applySettings();}
|
||||||
|
|
||||||
//! Set output speed to "speed"
|
//! \~english Set output speed to "speed"
|
||||||
|
//! \~russian Устанавливает скорость передачи в "speed"
|
||||||
void setOutSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); applySettings();}
|
void setOutSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); applySettings();}
|
||||||
|
|
||||||
//! Set input speed to "speed"
|
//! \~english Set input speed to "speed"
|
||||||
|
//! \~russian Устанавливает скорость приема в "speed"
|
||||||
void setInSpeed(PISerial::Speed speed) {setProperty("inSpeed", (int)speed); applySettings();}
|
void setInSpeed(PISerial::Speed speed) {setProperty("inSpeed", (int)speed); applySettings();}
|
||||||
|
|
||||||
//! Set device name to "dev"
|
//! \~english Set device name to "dev"
|
||||||
|
//! \~russian Устанавливает имя устройства в "dev"
|
||||||
void setDevice(const PIString & dev) {setPath(dev); if (isOpened()) {close(); open();};}
|
void setDevice(const PIString & dev) {setPath(dev); if (isOpened()) {close(); open();};}
|
||||||
|
|
||||||
|
|
||||||
//! Set parameters to "parameters_"
|
//! \~english Set parameters to "parameters_"
|
||||||
|
//! \~russian Устанавливает параметры в "parameters_"
|
||||||
void setParameters(PIFlags<PISerial::Parameters> parameters_) {setProperty("parameters", (int)parameters_); applySettings();}
|
void setParameters(PIFlags<PISerial::Parameters> parameters_) {setProperty("parameters", (int)parameters_); applySettings();}
|
||||||
|
|
||||||
//! Set parameter "parameter" to "on" state
|
//! \~english Set parameter "parameter" to "on" state
|
||||||
|
//! \~russian Устанавливает параметр "parameter" в "on"
|
||||||
void setParameter(PISerial::Parameters parameter, bool on = true);
|
void setParameter(PISerial::Parameters parameter, bool on = true);
|
||||||
|
|
||||||
//! Returns if parameter "parameter" is set
|
//! \~english Returns if parameter "parameter" is set
|
||||||
|
//! \~russian Возвращает установлен ли параметр "parameter"
|
||||||
bool isParameterSet(PISerial::Parameters parameter) const;
|
bool isParameterSet(PISerial::Parameters parameter) const;
|
||||||
|
|
||||||
//! Returns parameters
|
//! \~english Returns parameters
|
||||||
|
//! \~russian Возвращает параметры
|
||||||
PIFlags<PISerial::Parameters> parameters() const {return (PIFlags<Parameters>)(property("parameters").toInt());}
|
PIFlags<PISerial::Parameters> parameters() const {return (PIFlags<Parameters>)(property("parameters").toInt());}
|
||||||
|
|
||||||
|
|
||||||
//! Set data bits count. Valid range is from 5 to 8, befault is 8
|
//! \~english Set data bits count. Valid range is from 5 to 8, befault is 8
|
||||||
|
//! \~russian Устанавливает количество бит данных. Разрешены значения от 5 до 8, по умолчанию 8
|
||||||
void setDataBitsCount(int bits) {setProperty("dataBitsCount", bits); applySettings();}
|
void setDataBitsCount(int bits) {setProperty("dataBitsCount", bits); applySettings();}
|
||||||
|
|
||||||
//! Returns data bits count
|
//! \~english Returns data bits count
|
||||||
|
//! \~russian Возвращает количество бит данных
|
||||||
int dataBitsCount() const {return property("dataBitsCount").toInt();}
|
int dataBitsCount() const {return property("dataBitsCount").toInt();}
|
||||||
|
|
||||||
|
|
||||||
//! Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
|
//! \~english Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
|
||||||
|
//! \~russian Устанавливает пин с номером "number" в логический уровень "on". Разрешены номера 4 (DTR) и 7 (RTS)
|
||||||
bool setPin(int number, bool on);
|
bool setPin(int number, bool on);
|
||||||
|
|
||||||
//! Returns pin number "number" logic level. Valid numbers range is from 1 to 9
|
//! \~english Returns pin number "number" logic level. Valid numbers range is from 1 to 9
|
||||||
|
//! \~russian Возвращает логический уровень пина с номером "number". Разрешены номера от 1 до 9
|
||||||
bool isPin(int number) const;
|
bool isPin(int number) const;
|
||||||
|
|
||||||
bool setLE(bool on); // useless function, just formally
|
bool setLE(bool on); // useless function, just formally
|
||||||
@@ -163,75 +194,94 @@ public:
|
|||||||
bool isRNG() const;
|
bool isRNG() const;
|
||||||
bool isDSR() const;
|
bool isDSR() const;
|
||||||
|
|
||||||
//! Switch transmission line in break if enabled.
|
//! \~english Switch transmission line in break
|
||||||
//! i.e. sends a continuous stream of zero bits.
|
//! \~russian Переключает состояние передачи в break
|
||||||
//! If successful, returns true; otherwise returns false.
|
|
||||||
//! The serial port has to be open before trying to send a break duration; otherwise returns false
|
|
||||||
bool setBreak(bool enabled);
|
bool setBreak(bool enabled);
|
||||||
|
|
||||||
void setVTime(int t) {vtime = t; applySettings();}
|
void setVTime(int t) {vtime = t; applySettings();}
|
||||||
|
|
||||||
//! Returns device name
|
//! \~english Returns device name
|
||||||
|
//! \~russian Возвращает имя устройства
|
||||||
PIString device() const {return path();}
|
PIString device() const {return path();}
|
||||||
|
|
||||||
//! Returns output speed
|
//! \~english Returns output speed
|
||||||
|
//! \~russian Возвращает скорость передачи
|
||||||
PISerial::Speed outSpeed() const {return (PISerial::Speed)(property("outSpeed").toInt());}
|
PISerial::Speed outSpeed() const {return (PISerial::Speed)(property("outSpeed").toInt());}
|
||||||
|
|
||||||
//! Returns input speed
|
//! \~english Returns input speed
|
||||||
|
//! \~russian Возвращает скорость приема
|
||||||
PISerial::Speed inSpeed() const {return (PISerial::Speed)(property("inSpeed").toInt());}
|
PISerial::Speed inSpeed() const {return (PISerial::Speed)(property("inSpeed").toInt());}
|
||||||
|
|
||||||
int VTime() const {return vtime;}
|
int VTime() const {return vtime;}
|
||||||
|
|
||||||
//! Discard all buffered input and output data
|
//! \~english Discard all buffered input and output data
|
||||||
|
//! \~russian Откидывает все буферизированные данные для передачи и приема
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
||||||
|
|
||||||
|
//! \~english Read from device no more "max_size" bytes into "read_to" with "timeout_ms" timeout
|
||||||
|
//! \~russian Читает из устройства не более "max_size" байт в "read_to" с таймаутом "timeout_ms"
|
||||||
bool read(void * read_to, int max_size, double timeout_ms);
|
bool read(void * read_to, int max_size, double timeout_ms);
|
||||||
PIString read(int size = -1, double timeout_ms = 1000.);
|
|
||||||
|
//! \~english Read from device for "timeout_ms" timeout or for "size" bytes
|
||||||
|
//! \~russian Читает из устройства в течении таймаута "timeout_ms" или до "size" байт
|
||||||
|
PIString readString(int size = -1, double timeout_ms = 1000.);
|
||||||
|
|
||||||
|
//! \~english Read from device for "timeout_ms" timeout or for "size" bytes
|
||||||
|
//! \~russian Читает из устройства в течении таймаута "timeout_ms" или до "size" байт
|
||||||
PIByteArray readData(int size = -1, double timeout_ms = 1000.);
|
PIByteArray readData(int size = -1, double timeout_ms = 1000.);
|
||||||
|
|
||||||
//! \brief Write to device data "data" with maximum size "size" and wait for data written if "wait" is \b true.
|
//! \~english Write to device data "data" with maximum size "size". Returns if sended bytes count = "size"
|
||||||
//! \returns \b true if sended bytes count = "size"
|
//! \~russian Пишет в порт не более "size" байт данных "data". Возвращает если количество записанных байт = "size"
|
||||||
bool send(const void * data, int size);
|
bool send(const void * data, int size);
|
||||||
|
|
||||||
//! \brief Write to device byte array "data"
|
//! \~english Write to device byte array "data". Returns if sended bytes count = size of "data"
|
||||||
//! \returns \b true if sended bytes count = size of string
|
//! \~russian Пишет в порт байтовый массив "data". Возвращает если количество записанных байт = размер "data"
|
||||||
bool send(const PIByteArray & data) {return send(data.data(), data.size_s());}
|
bool send(const PIByteArray & data) {return send(data.data(), data.size_s());}
|
||||||
|
|
||||||
//! \brief Returns all available speeds for serial devices
|
//! \~english Returns all available speeds for serial devices
|
||||||
|
//! \~russian Возвращает все возможные скорости для устройств
|
||||||
static PIVector<int> availableSpeeds();
|
static PIVector<int> availableSpeeds();
|
||||||
|
|
||||||
//! \brief Returns all available system devices path. If "test" each device will be tried to open
|
//! \~english Returns all available system devices path. If "test" each device will be tried to open
|
||||||
|
//! \~russian Возвращает пути всех доступных устройств в системе. Если "test", то каждое устройство будет опробовано на открытие
|
||||||
static PIStringList availableDevices(bool test = false);
|
static PIStringList availableDevices(bool test = false);
|
||||||
|
|
||||||
//! \brief Returns all available system devices. If "test" each device will be tried to open
|
//! \~english Returns all available system devices. If "test" each device will be tried to open
|
||||||
|
//! \~russian Возвращает все доступные устройства в системе. Если "test", то каждое устройство будет опробовано на открытие
|
||||||
static PIVector<DeviceInfo> availableDevicesInfo(bool test = false);
|
static PIVector<DeviceInfo> availableDevicesInfo(bool test = false);
|
||||||
|
|
||||||
//! \ioparams
|
//! \ioparams
|
||||||
//! \{
|
//! \{
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
//! \brief device, default ""
|
//! \~english device, default ""
|
||||||
|
//! \~russian устройство, по умолчанию ""
|
||||||
string device;
|
string device;
|
||||||
|
|
||||||
//! \brief input/output speed, default 115200
|
//! \~english input/output speed, default 115200
|
||||||
|
//! \~russian скорость чтения/записи, по умолчанию 115200
|
||||||
int speed;
|
int speed;
|
||||||
|
|
||||||
//! \brief dataBitsCount, default 8
|
//! \~english dataBitsCount, default 8
|
||||||
|
//! \~russian количесво бит данных, по умолчанию 8
|
||||||
int dataBitsCount;
|
int dataBitsCount;
|
||||||
|
|
||||||
//! \brief parityControl, default false
|
//! \~english parityControl, default false
|
||||||
|
//! \~russian контроль четности, по умолчанию false
|
||||||
bool parityControl;
|
bool parityControl;
|
||||||
|
|
||||||
//! \brief parityOdd, default false
|
//! \~english parityOdd, default false
|
||||||
|
//! \~russian нечётный контроль четности, по умолчанию false
|
||||||
bool parityOdd;
|
bool parityOdd;
|
||||||
|
|
||||||
//! \brief twoStopBits, default false
|
//! \~english twoStopBits, default false
|
||||||
|
//! \~russian два стоповых бита, по умолчанию false
|
||||||
bool twoStopBits;
|
bool twoStopBits;
|
||||||
#endif
|
#endif
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("ser");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
@@ -239,6 +289,9 @@ protected:
|
|||||||
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
||||||
void optionsChanged();
|
void optionsChanged();
|
||||||
void threadedReadBufferSizeChanged();
|
void threadedReadBufferSizeChanged();
|
||||||
|
|
||||||
|
//! \~english Basic read function
|
||||||
|
//! \~russian Базовое чтение
|
||||||
int readDevice(void * read_to, int max_size);
|
int readDevice(void * read_to, int max_size);
|
||||||
int writeDevice(const void * data, int max_size);
|
int writeDevice(const void * data, int max_size);
|
||||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;}
|
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;}
|
||||||
@@ -264,14 +317,30 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PISerial::DeviceInfo & v) {
|
inline PICout operator <<(PICout s, const PISerial::DeviceInfo & v) {
|
||||||
s << v.path << " (" << v.id() << ", \"" << v.manufacturer << "\", \"" << v.description << "\")";
|
s << v.path << " (" << v.id() << ", \"" << v.manufacturer << "\", \"" << v.description << "\")";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~english Compare operator
|
||||||
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator ==(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path == v1.path;}
|
inline bool operator ==(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path == v1.path;}
|
||||||
|
|
||||||
|
//! \~english Compare operator
|
||||||
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path != v1.path;}
|
inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path != v1.path;}
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Store operator
|
||||||
|
//! \~russian Оператор сохранения
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
|
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Restore operator
|
||||||
|
//! \~russian Оператор извлечения
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
|
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,25 +40,24 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*! \class PISharedMemory
|
//! \class PISharedMemory pisharedmemory.h
|
||||||
* \brief Shared memory
|
//! \details
|
||||||
*
|
//! \~english
|
||||||
* \section PISharedMemory_sec0 Synopsis
|
//!
|
||||||
* This class provide access to local file. You can manipulate
|
//!
|
||||||
* binary content or use this class as text stream. To binary
|
//! \~russian
|
||||||
* access there are function \a read(), \a write(), and many
|
//! Разделяемая память используется как единое хранилище данных,
|
||||||
* \a writeBinary() functions. For write variables to file in
|
//! доступное различным процессам по имени. При первом открытии
|
||||||
* their text representation threr are many "<<" operators.
|
//! объекта разделяемой памяти выделяется \a size() байт, по умолчанию
|
||||||
*
|
//! 65 Кб. Все процессы должны использовать один и тот же \a size()
|
||||||
* \section PISharedMemory_sec1 Position
|
//! во избежании ошибок.
|
||||||
* Each opened file has a read/write position - logical position
|
//!
|
||||||
* in the file content you read from or you write to. You can
|
//! У объекта разделяемой памяти нету позиции чтения/записи,
|
||||||
* find out current position with function \a pos(). Function
|
//! каждый вызов \a read() или \a write() обращается
|
||||||
* \a seek(llong position) move position to position "position",
|
//! к началу памяти. Для работы с конкретным участком памяти
|
||||||
* \a seekToBegin() move position to the begin of file,
|
//! используются перегруженные методы с указанием "offset".
|
||||||
* \a seekToEnd() move position to the end of file.
|
//!
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
REGISTER_DEVICE(PISharedMemory)
|
REGISTER_DEVICE(PISharedMemory)
|
||||||
|
|
||||||
|
|||||||
@@ -29,54 +29,70 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Shared memory.
|
||||||
|
//! \~russian Разделяемая память.
|
||||||
class PIP_EXPORT PISharedMemory: public PIIODevice
|
class PIP_EXPORT PISharedMemory: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PISharedMemory)
|
PIIODEVICE(PISharedMemory, "shm")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//! \~english Constructs empty %PISharedMemory
|
||||||
|
//! \~russian Создает пустой %PISharedMemory
|
||||||
explicit PISharedMemory();
|
explicit PISharedMemory();
|
||||||
|
|
||||||
//! Constructs a shared memory object with name "shm_name", size "size" and open mode "mode"
|
//! \~english Constructs a shared memory object with name "shm_name", size "size" and open mode "mode"
|
||||||
|
//! \~russian Создает объект разделяемой памяти с именем "shm_name", размером "size" и режимом открытия "mode"
|
||||||
explicit PISharedMemory(const PIString & shm_name, int size, DeviceMode mode = ReadWrite);
|
explicit PISharedMemory(const PIString & shm_name, int size, DeviceMode mode = ReadWrite);
|
||||||
|
|
||||||
|
|
||||||
virtual ~PISharedMemory();
|
virtual ~PISharedMemory();
|
||||||
|
|
||||||
//! Read all shared memory object content to byte array and return it
|
|
||||||
|
//! \~english Read all shared memory content and return it as byte array
|
||||||
|
//! \~russian Читает всю разделяемую память и возвращает её как байтовый массив
|
||||||
PIByteArray readAll();
|
PIByteArray readAll();
|
||||||
|
|
||||||
//! Returns shared memory object size
|
//! \~english Returns shared memory size
|
||||||
|
//! \~russian Возвращает размер разделяемой памяти
|
||||||
llong size() const;
|
llong size() const;
|
||||||
|
|
||||||
//! Set shared memory object size
|
//! \~english Set shared memory size
|
||||||
|
//! \~russian Устанавливает размер разделяемой памяти
|
||||||
void setSize(llong s);
|
void setSize(llong s);
|
||||||
|
|
||||||
//! Returns if shared memory object is empty
|
//! \~english Returns if shared memory object is empty (by size)
|
||||||
|
//! \~russian Возвращает пустой ли объект разделяемой памяти (по размеру)
|
||||||
bool isEmpty() const {return (size() <= 0);}
|
bool isEmpty() const {return (size() <= 0);}
|
||||||
|
|
||||||
//! Read from shared memory object to "read_to" no more than "max_size" and return readed bytes count
|
//! \~english Read from shared memory to "read_to" no more than "max_size" and return readed bytes count
|
||||||
|
//! \~russian Читает из разделяемой памяти в "read_to" не более "max_size" и возвращает количество прочитанных байт
|
||||||
int read(void * read_to, int max_size);
|
int read(void * read_to, int max_size);
|
||||||
|
|
||||||
//! Read from shared memory object to "read_to" no more than "max_size" and return readed bytes count
|
//! \~english Read from shared memory started from "offset" to "read_to" no more than "max_size" and return readed bytes count
|
||||||
|
//! \~russian Читает из разделяемой памяти с начала "offset" в "read_to" не более "max_size" и возвращает количество прочитанных байт
|
||||||
int read(void * read_to, int max_size, int offset);
|
int read(void * read_to, int max_size, int offset);
|
||||||
|
|
||||||
//! Write to shared memory object "data" with size "max_size" and return written bytes count
|
//! \~english Write to shared memory "data" with size "max_size" and return written bytes count
|
||||||
|
//! \~russian Пишет в разделяемую память "data" размером "max_size" и возвращает количество записанных байт
|
||||||
int write(const void * data, int max_size);
|
int write(const void * data, int max_size);
|
||||||
|
|
||||||
//! Write to shared memory object "data" with size "max_size" and return written bytes count
|
//! \~english Write to shared memory started from "offset" "data" with size "max_size" and return written bytes count
|
||||||
|
//! \~russian Пишет в разделяемую память с начала "offset" "data" размером "max_size" и возвращает количество записанных
|
||||||
int write(const void * data, int max_size, int offset);
|
int write(const void * data, int max_size, int offset);
|
||||||
|
|
||||||
//! Write "data" to shared memory object
|
//! \~english Write "data" to shared memory
|
||||||
|
//! \~russian Пишет в разделяемую память "data"
|
||||||
int write(const PIByteArray & data) {return write(data.data(), data.size_s());}
|
int write(const PIByteArray & data) {return write(data.data(), data.size_s());}
|
||||||
|
|
||||||
//! Write "data" to shared memory object
|
//! \~english Write "data" to shared memory
|
||||||
|
//! \~russian Пишет в разделяемую память "data"
|
||||||
int write(const PIByteArray & data, int offset) {return write(data.data(), data.size_s(), offset);}
|
int write(const PIByteArray & data, int offset) {return write(data.data(), data.size_s(), offset);}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("shm");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
class PIP_EXPORT PISPI: public PIIODevice
|
class PIP_EXPORT PISPI: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PISPI)
|
PIIODEVICE(PISPI, "spi")
|
||||||
public:
|
public:
|
||||||
explicit PISPI(const PIString & path = PIString(), uint speed_hz = 1000000, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PISPI(const PIString & path = PIString(), uint speed_hz = 1000000, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PISPI();
|
virtual ~PISPI();
|
||||||
@@ -67,7 +67,6 @@ protected:
|
|||||||
int readDevice(void * read_to, int max_size);
|
int readDevice(void * read_to, int max_size);
|
||||||
int writeDevice(const void * data, int max_size);
|
int writeDevice(const void * data, int max_size);
|
||||||
|
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("spi");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
PIPropertyStorage constructVariantDevice() const;
|
PIPropertyStorage constructVariantDevice() const;
|
||||||
|
|||||||
@@ -20,15 +20,21 @@
|
|||||||
#include "pitransparentdevice.h"
|
#include "pitransparentdevice.h"
|
||||||
|
|
||||||
|
|
||||||
/*! \class PITransparentDevice
|
//! \class PITransparentDevice pitransparentdevice.h
|
||||||
* \brief PIIODevice that pass write to read
|
//! \details
|
||||||
*
|
//! \~english
|
||||||
* \section PITransparentDevice_sec0 Synopsis
|
//! This class pass all data from \a write() function to \a read().
|
||||||
* This class pass all data from \a write() function to \a read().
|
//! %PITransparentDevice contains internal queue and works in
|
||||||
* %PITransparentDevice contains internal queue and works in
|
//! packets mode. If you write 3 different packets into this device,
|
||||||
* packets mode. If you write 3 different packets into this device,
|
//! read will return this 3 packets.
|
||||||
* read will return this 3 packets.
|
//!
|
||||||
*/
|
//! \~russian
|
||||||
|
//! Этот класс транслирует все данные с метода \a write() на метод
|
||||||
|
//! \a read(). %PITransparentDevice содержит внутреннюю очередь и работает
|
||||||
|
//! в пакетном режиме. Если запишется 3 различных пакета в устройство,
|
||||||
|
//! то чтение вернет по очереди эти 3 пакета.
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
REGISTER_DEVICE(PITransparentDevice)
|
REGISTER_DEVICE(PITransparentDevice)
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,17 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup IO
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIIODevice that pass write to read.
|
||||||
|
//! \~russian PIIODevice который транслирует запись на чтение.
|
||||||
class PIP_EXPORT PITransparentDevice: public PIIODevice
|
class PIP_EXPORT PITransparentDevice: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PITransparentDevice)
|
PIIODEVICE(PITransparentDevice, "tr")
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Contructs empty %PITransparentDevice
|
//! \~english Contructs empty %PITransparentDevice
|
||||||
|
//! \~russian Создает пустой %PITransparentDevice
|
||||||
explicit PITransparentDevice();
|
explicit PITransparentDevice();
|
||||||
|
|
||||||
virtual ~PITransparentDevice();
|
virtual ~PITransparentDevice();
|
||||||
@@ -44,7 +49,6 @@ protected:
|
|||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
int readDevice(void * read_to, int max_size);
|
int readDevice(void * read_to, int max_size);
|
||||||
int writeDevice(const void * data, int max_size);
|
int writeDevice(const void * data, int max_size);
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("tr");}
|
|
||||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
PIMutex que_mutex;
|
PIMutex que_mutex;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ struct usb_dev_handle;
|
|||||||
|
|
||||||
class PIP_EXPORT PIUSB: public PIIODevice
|
class PIP_EXPORT PIUSB: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIUSB)
|
PIIODEVICE(PIUSB, "usb")
|
||||||
public:
|
public:
|
||||||
explicit PIUSB(ushort vid = 0, ushort pid = 0);
|
explicit PIUSB(ushort vid = 0, ushort pid = 0);
|
||||||
virtual ~PIUSB();
|
virtual ~PIUSB();
|
||||||
@@ -160,7 +160,6 @@ public:
|
|||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("usb");}
|
|
||||||
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
void configureFromFullPathDevice(const PIString & full_path);
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> & hist, int & cnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIDiagnostics::propertyChanged(const PIString &) {
|
void PIDiagnostics::propertyChanged(const char *) {
|
||||||
float disct = property("disconnectTimeout").toFloat();
|
float disct = property("disconnectTimeout").toFloat();
|
||||||
changeDisconnectTimeout(disct);
|
changeDisconnectTimeout(disct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ private:
|
|||||||
|
|
||||||
void tick(void *, int);
|
void tick(void *, int);
|
||||||
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
||||||
void propertyChanged(const PIString &);
|
void propertyChanged(const char *);
|
||||||
void changeDisconnectTimeout(float disct);
|
void changeDisconnectTimeout(float disct);
|
||||||
|
|
||||||
PIQueue<Entry> history_rec, history_send;
|
PIQueue<Entry> history_rec, history_send;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ void PIPacketExtractor::construct() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPacketExtractor::propertyChanged(const PIString &) {
|
void PIPacketExtractor::propertyChanged(const char *) {
|
||||||
packetSize_ = property("packetSize").toInt();
|
packetSize_ = property("packetSize").toInt();
|
||||||
mode_ = (SplitMode)(property("splitMode").toInt());
|
mode_ = (SplitMode)(property("splitMode").toInt());
|
||||||
dataSize = property("payloadSize").toInt();
|
dataSize = property("payloadSize").toInt();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ typedef bool (*PacketExtractorCheckFunc)(void * , uchar * , uchar * , int );
|
|||||||
|
|
||||||
class PIP_EXPORT PIPacketExtractor: public PIIODevice
|
class PIP_EXPORT PIPacketExtractor: public PIIODevice
|
||||||
{
|
{
|
||||||
PIIODEVICE(PIPacketExtractor)
|
PIIODEVICE(PIPacketExtractor, "pckext")
|
||||||
friend class PIConnection;
|
friend class PIConnection;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -161,11 +161,10 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void construct();
|
void construct();
|
||||||
void propertyChanged(const PIString & );
|
void propertyChanged(const char *);
|
||||||
int readDevice(void * read_to, int max_size) {if (dev == 0) return -1; return dev->read(read_to, max_size);}
|
int readDevice(void * read_to, int max_size) {if (dev == 0) return -1; return dev->read(read_to, max_size);}
|
||||||
int writeDevice(const void * data, int max_size) {if (dev == 0) return -1; return dev->write(data, max_size);}
|
int writeDevice(const void * data, int max_size) {if (dev == 0) return -1; return dev->write(data, max_size);}
|
||||||
bool threadedRead(uchar * readed, int size);
|
bool threadedRead(uchar * readed, int size);
|
||||||
PIString fullPathPrefix() const {return PIStringAscii("pckext");}
|
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
bool openDevice() {if (dev == 0) return false; return dev->open();}
|
bool openDevice() {if (dev == 0) return false; return dev->open();}
|
||||||
bool closeDevice() {if (dev == 0) return false; return dev->close();}
|
bool closeDevice() {if (dev == 0) return false; return dev->close();}
|
||||||
|
|||||||
@@ -26,14 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup System
|
|
||||||
//! \{
|
|
||||||
//! \class PILibrary pilibrary.h
|
//! \class PILibrary pilibrary.h
|
||||||
//!
|
|
||||||
//! \~\brief
|
|
||||||
//! \~english Run-time library
|
|
||||||
//! \~russian Run-time библиотека
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section _sec0 Synopsis
|
//! \~english \section _sec0 Synopsis
|
||||||
//! \~russian \section _sec0 Краткий обзор
|
//! \~russian \section _sec0 Краткий обзор
|
||||||
@@ -126,7 +119,6 @@
|
|||||||
//! // mul = 30
|
//! // mul = 30
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PRIVATE_DEFINITION_START(PILibrary)
|
PRIVATE_DEFINITION_START(PILibrary)
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
|
|
||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Run-time library.
|
||||||
|
//! \~russian Run-time библиотека.
|
||||||
class PIP_EXPORT PILibrary {
|
class PIP_EXPORT PILibrary {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,7 @@
|
|||||||
#include "pidir.h"
|
#include "pidir.h"
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
|
|
||||||
//! \addtogroup System
|
|
||||||
//! \{
|
|
||||||
//! \class PIPluginLoader piplugin.h
|
//! \class PIPluginLoader piplugin.h
|
||||||
//!
|
|
||||||
//! \brief
|
|
||||||
//! \~english Plugin loader
|
|
||||||
//! \~russian Загрузчик плагина
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english \section PIPluginLoader_sec0 Synopsis
|
//! \~english \section PIPluginLoader_sec0 Synopsis
|
||||||
//! \~russian \section PIPluginLoader_sec0 Краткий обзор
|
//! \~russian \section PIPluginLoader_sec0 Краткий обзор
|
||||||
@@ -238,7 +231,6 @@
|
|||||||
//! }
|
//! }
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
#define STR_WF(s) #s
|
#define STR_WF(s) #s
|
||||||
#define STR(s) STR_WF(s)
|
#define STR(s) STR_WF(s)
|
||||||
@@ -342,7 +334,14 @@ bool PIPluginLoader::load(const PIString & name) {
|
|||||||
unload();
|
unload();
|
||||||
PIPluginInfo * ai = PIPluginInfoStorage::instance()->applicationInfo();
|
PIPluginInfo * ai = PIPluginInfoStorage::instance()->applicationInfo();
|
||||||
PIPluginInfo * pi = PIPluginInfoStorage::instance()->enterPlugin(this);
|
PIPluginInfo * pi = PIPluginInfoStorage::instance()->enterPlugin(this);
|
||||||
if (!lib.load(findLibrary(name))) {
|
PIString fname = findLibrary(name);
|
||||||
|
if (fname.isEmpty()) {
|
||||||
|
error = NoSuchFile;
|
||||||
|
error_str = "Load plugin \"" + lib.path() + "\" error: can`t find lib for \"" + name + "\"";
|
||||||
|
if (messages) piCout << error_str;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!lib.load(fname)) {
|
||||||
unload();
|
unload();
|
||||||
error = LibraryLoadError;
|
error = LibraryLoadError;
|
||||||
error_str = "Load plugin \"" + lib.path() + "\" error: can`t load lib: " + lib.lastError();
|
error_str = "Load plugin \"" + lib.path() + "\" error: can`t load lib: " + lib.lastError();
|
||||||
|
|||||||
@@ -156,6 +156,10 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Plugin loader.
|
||||||
|
//! \~russian Загрузчик плагина.
|
||||||
class PIP_EXPORT PIPluginLoader {
|
class PIP_EXPORT PIPluginLoader {
|
||||||
public:
|
public:
|
||||||
typedef int(*FunctionLoaderVersion)();
|
typedef int(*FunctionLoaderVersion)();
|
||||||
@@ -166,6 +170,7 @@ public:
|
|||||||
enum Error {
|
enum Error {
|
||||||
Unknown /** \~english No \a load() call yet \~russian Не было вызова \a load() */ ,
|
Unknown /** \~english No \a load() call yet \~russian Не было вызова \a load() */ ,
|
||||||
NoError /** \~english No error \~russian Нет ошибки */ ,
|
NoError /** \~english No error \~russian Нет ошибки */ ,
|
||||||
|
NoSuchFile /** \~english Can`t find library file \~russian Не найден файл библиотеки */ ,
|
||||||
LibraryLoadError /** \~english System can`t load library \~russian Система не смогла загрузить библиотеку */ ,
|
LibraryLoadError /** \~english System can`t load library \~russian Система не смогла загрузить библиотеку */ ,
|
||||||
MissingSymbols /** \~english Can`t find necessary symbols \~russian Нет необходимых методов */ ,
|
MissingSymbols /** \~english Can`t find necessary symbols \~russian Нет необходимых методов */ ,
|
||||||
InvalidLoaderVersion /** \~english Internal version mismatch \~russian Неверная внутренняя версия */ ,
|
InvalidLoaderVersion /** \~english Internal version mismatch \~russian Неверная внутренняя версия */ ,
|
||||||
|
|||||||
@@ -30,14 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//! \addtogroup System
|
|
||||||
//! \{
|
|
||||||
//! \class PIProcess piprocess.h
|
//! \class PIProcess piprocess.h
|
||||||
//!
|
|
||||||
//! \~\brief
|
|
||||||
//! \~english External process
|
|
||||||
//! \~russian Внешний процесс
|
|
||||||
//!
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This class able to start external executables, watch for them,
|
//! This class able to start external executables, watch for them,
|
||||||
@@ -65,7 +58,6 @@
|
|||||||
//!
|
//!
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//!
|
//!
|
||||||
//! \}
|
|
||||||
|
|
||||||
|
|
||||||
PRIVATE_DEFINITION_START(PIProcess)
|
PRIVATE_DEFINITION_START(PIProcess)
|
||||||
@@ -202,10 +194,10 @@ void PIProcess::startProc(bool detached) {
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||||
if (execve(str.data(), argscc, envcc) < 0)
|
if (execve(str.data(), (char * const *)argscc, (char * const *)envcc) < 0)
|
||||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||||
} else {
|
} else {
|
||||||
piMinSleep;
|
piMinSleep();
|
||||||
//cout << "wait" << endl;
|
//cout << "wait" << endl;
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
wait(&exit_code);
|
wait(&exit_code);
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english External process.
|
||||||
|
//! \~russian Внешний процесс.
|
||||||
class PIP_EXPORT PIProcess: public PIThread
|
class PIP_EXPORT PIProcess: public PIThread
|
||||||
{
|
{
|
||||||
PIOBJECT_SUBCLASS(PIProcess, PIThread)
|
PIOBJECT_SUBCLASS(PIProcess, PIThread)
|
||||||
|
|||||||
@@ -20,6 +20,46 @@
|
|||||||
#include "pisingleapplication.h"
|
#include "pisingleapplication.h"
|
||||||
#include "pisharedmemory.h"
|
#include "pisharedmemory.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \class PISingleApplication pisingleapplication.h
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Этот класс позволяет отслеживать повторный запуск приложения
|
||||||
|
//! и передавать сообщение первому запущеному.
|
||||||
|
//!
|
||||||
|
//! Видят друг друга %PISingleApplication с одинаковыми "app_name",
|
||||||
|
//! задаваемым в конструкторе.
|
||||||
|
//!
|
||||||
|
//! Если проверка \a isFirst() успешна, значит этот экземпляр
|
||||||
|
//! запущен первым, и можно соединиться к событию \a messageReceived().
|
||||||
|
//!
|
||||||
|
//! Если проверка провалена, значит этот экземпляр не первый,
|
||||||
|
//! и можно послать ему сообщение с помощью \a sendMessage(),
|
||||||
|
//! а затем выйти.
|
||||||
|
//!
|
||||||
|
//! \~\code
|
||||||
|
//! int main(int argc, char * argv[]) {
|
||||||
|
//! PISingleApplication sapp("myapp");
|
||||||
|
//! if (sapp.isFirst()) {
|
||||||
|
//! piCout << "I`m first, wait for another";
|
||||||
|
//! CONNECTL(&sapp, messageReceived, [](PIByteArray msg){
|
||||||
|
//! piCout << "Msg from another:" << PIString(msg);
|
||||||
|
//! });
|
||||||
|
//! } else {
|
||||||
|
//! piCout << "I`m not first, send and exit";
|
||||||
|
//! sapp.sendMessage(PIString("Hello!").toByteArray());
|
||||||
|
//! return 0;
|
||||||
|
//! }
|
||||||
|
//! WAIT_FOREVER
|
||||||
|
//! return 0;
|
||||||
|
//! }
|
||||||
|
//! \endcode
|
||||||
|
//!
|
||||||
|
|
||||||
|
|
||||||
#define SHM_SIZE 1024*32
|
#define SHM_SIZE 1024*32
|
||||||
|
|
||||||
|
|
||||||
@@ -49,10 +89,10 @@ bool PISingleApplication::isFirst() const {
|
|||||||
void PISingleApplication::sendMessage(const PIByteArray & m) {
|
void PISingleApplication::sendMessage(const PIByteArray & m) {
|
||||||
waitFirst();
|
waitFirst();
|
||||||
PIByteArray ba;
|
PIByteArray ba;
|
||||||
int lm[2] = {0, 0};
|
int lm[3] = {0, 0, 0};
|
||||||
for (;;) {
|
for (;;) {
|
||||||
shm->read(lm, 8);
|
shm->read(lm, 12);
|
||||||
if (lm[1] == 0) break;
|
if (lm[2] == 0) break;
|
||||||
piMSleep(10);
|
piMSleep(10);
|
||||||
}
|
}
|
||||||
ba << sacnt << sacnt << int(1) << m;
|
ba << sacnt << sacnt << int(1) << m;
|
||||||
@@ -85,10 +125,12 @@ void PISingleApplication::run() {
|
|||||||
int st_[2] = {sacnt, sacnt};
|
int st_[2] = {sacnt, sacnt};
|
||||||
shm->write(st_, 8);
|
shm->write(st_, 8);
|
||||||
//piCoutObj << "write" << sacnt;
|
//piCoutObj << "write" << sacnt;
|
||||||
readed = shm->readAll();
|
int ri[3] = {0, 0, 0};
|
||||||
int t1(0), t2(0), nm(0);
|
const int hdr_sz = sizeof(int) * 3;
|
||||||
readed >> t1 >> t2 >> nm;
|
shm->read(ri, hdr_sz);
|
||||||
if (nm != 0 && t1 == t2) {
|
if (ri[2] != 0 && ri[0] == ri[1]) {
|
||||||
|
readed.resize(shm->size() - hdr_sz);
|
||||||
|
shm->read(readed.data(), readed.size(), hdr_sz);
|
||||||
PIByteArray msg;
|
PIByteArray msg;
|
||||||
readed >> msg;
|
readed >> msg;
|
||||||
if (!msg.isEmpty()) {
|
if (!msg.isEmpty()) {
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*! \file pisingleapplication.h
|
||||||
|
* \ingroup System
|
||||||
|
* \~\brief
|
||||||
|
* \~english Single-instance application control
|
||||||
|
* \~russian Контроль одного экземпляра приложения
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Single application
|
Single application
|
||||||
@@ -24,16 +30,46 @@
|
|||||||
|
|
||||||
class PISharedMemory;
|
class PISharedMemory;
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Single-instance application control.
|
||||||
|
//! \~russian Контроль одного экземпляра приложения.
|
||||||
class PIP_EXPORT PISingleApplication: public PIThread {
|
class PIP_EXPORT PISingleApplication: public PIThread {
|
||||||
PIOBJECT_SUBCLASS(PISingleApplication, PIThread)
|
PIOBJECT_SUBCLASS(PISingleApplication, PIThread)
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//! \~english Construct %PISingleApplication with name "app_name"
|
||||||
|
//! \~russian Создает %PISingleApplication с именем "app_name"
|
||||||
PISingleApplication(const PIString & app_name = PIString());
|
PISingleApplication(const PIString & app_name = PIString());
|
||||||
|
|
||||||
~PISingleApplication();
|
~PISingleApplication();
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns if this application instance is launched first
|
||||||
|
//! \~russian Возвращает первым ли был запущен этот экземпляр приложения
|
||||||
bool isFirst() const;
|
bool isFirst() const;
|
||||||
|
|
||||||
EVENT_HANDLER1(void, sendMessage, const PIByteArray &, m);
|
EVENT_HANDLER1(void, sendMessage, const PIByteArray &, m);
|
||||||
EVENT1(messageReceived, const PIByteArray &, m)
|
EVENT1(messageReceived, PIByteArray, m)
|
||||||
|
|
||||||
|
//! \handlers
|
||||||
|
//! \{
|
||||||
|
|
||||||
|
//! \fn void sendMessage(const PIByteArray & m)
|
||||||
|
//! \brief
|
||||||
|
//! \~english Send message "m" to first launched application
|
||||||
|
//! \~russian Посылает сообщение "m" первому запущеному приложению
|
||||||
|
|
||||||
|
//! \}
|
||||||
|
//! \events
|
||||||
|
//! \{
|
||||||
|
|
||||||
|
//! \fn void messageReceived(PIByteArray m)
|
||||||
|
//! \brief
|
||||||
|
//! \~english Raise on first launched application receive message from another
|
||||||
|
//! \~russian Вызывается первым запущеным приложением по приему сообщения от других
|
||||||
|
|
||||||
|
//! \}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin();
|
void begin();
|
||||||
|
|||||||
@@ -30,17 +30,6 @@
|
|||||||
#define SALT_SIZE 8
|
#define SALT_SIZE 8
|
||||||
|
|
||||||
|
|
||||||
PISystemInfo::MountInfo::MountInfo() {
|
|
||||||
space_all = space_used = space_free = 0;
|
|
||||||
removable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PISystemInfo::PISystemInfo() {
|
|
||||||
processorsCount = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PISystemInfo * PISystemInfo::instance() {
|
PISystemInfo * PISystemInfo::instance() {
|
||||||
|
|||||||
@@ -28,35 +28,121 @@
|
|||||||
|
|
||||||
#include "pitime.h"
|
#include "pitime.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Information about system.
|
||||||
|
//! \~russian Информация о системе.
|
||||||
class PIP_EXPORT PISystemInfo {
|
class PIP_EXPORT PISystemInfo {
|
||||||
public:
|
public:
|
||||||
PISystemInfo();
|
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Mount point information.
|
||||||
|
//! \~russian Информация о точке монтирования.
|
||||||
struct PIP_EXPORT MountInfo {
|
struct PIP_EXPORT MountInfo {
|
||||||
MountInfo();
|
|
||||||
|
//! \~english Absolute path to mount point
|
||||||
|
//! \~russian Абсолютный путь к точке монтирования
|
||||||
PIString mount_point;
|
PIString mount_point;
|
||||||
|
|
||||||
|
//! \~english Device description
|
||||||
|
//! \~russian Описание устройства
|
||||||
PIString device;
|
PIString device;
|
||||||
|
|
||||||
|
//! \~english Filesystem name
|
||||||
|
//! \~russian Имя файловой системы
|
||||||
PIString filesystem;
|
PIString filesystem;
|
||||||
|
|
||||||
|
//! \~english Mount point label
|
||||||
|
//! \~russian Метка точки монтирования
|
||||||
PIString label;
|
PIString label;
|
||||||
ullong space_all;
|
|
||||||
ullong space_used;
|
//! \~english Total space in bytes
|
||||||
ullong space_free;
|
//! \~russian Полный объем в байтах
|
||||||
bool removable;
|
ullong space_all = 0;
|
||||||
|
|
||||||
|
//! \~english Used space in bytes
|
||||||
|
//! \~russian Занятый объем в байтах
|
||||||
|
ullong space_used = 0;
|
||||||
|
|
||||||
|
//! \~english Free space in bytes
|
||||||
|
//! \~russian Свободный объем в байтах
|
||||||
|
ullong space_free = 0;
|
||||||
|
|
||||||
|
//! \~english Is this device is removable
|
||||||
|
//! \~russian Является ли устройство съёмным
|
||||||
|
bool removable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
PIString ifconfigPath, execCommand, hostname, user, OS_name, OS_version, architecture;
|
//! \~english Absolute path to "ifconfig" utility
|
||||||
PIDateTime execDateTime;
|
//! \~russian Абсолютный путь к утилите "ifconfig"
|
||||||
int processorsCount;
|
PIString ifconfigPath;
|
||||||
|
|
||||||
|
//! \~english Application execution path (\c argv[0])
|
||||||
|
//! \~russian Путь вызова приложения (\c argv[0])
|
||||||
|
PIString execCommand;
|
||||||
|
|
||||||
|
//! \~english System hostname
|
||||||
|
//! \~russian Hostname системы
|
||||||
|
PIString hostname;
|
||||||
|
|
||||||
|
//! \~english Username that starts application
|
||||||
|
//! \~russian Имя пользователя, запустившего приложение
|
||||||
|
PIString user;
|
||||||
|
|
||||||
|
//! \~english System name (Windows, MacOS, ...)
|
||||||
|
//! \~russian Имя системы (Windows, MacOS, ...)
|
||||||
|
PIString OS_name;
|
||||||
|
|
||||||
|
//! \~english System version
|
||||||
|
//! \~russian Версия системы
|
||||||
|
PIString OS_version;
|
||||||
|
|
||||||
|
//! \~english System architecture (x86, x86_64, ...)
|
||||||
|
//! \~russian Архитектура системы (x86, x86_64, ...)
|
||||||
|
PIString architecture;
|
||||||
|
|
||||||
|
//! \~english Application start date and time
|
||||||
|
//! \~russian Дата и время запуска приложения
|
||||||
|
PIDateTime execDateTime;
|
||||||
|
|
||||||
|
//! \~english System logical processors count
|
||||||
|
//! \~russian Количество логических процессоров системы
|
||||||
|
int processorsCount = 1;
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns all mount points absolute pathes
|
||||||
|
//! \~russian Возвращает абсолютные пути всех точек монтирования
|
||||||
static PIStringList mountRoots();
|
static PIStringList mountRoots();
|
||||||
|
|
||||||
|
//! \~english Returns information of all mount points
|
||||||
|
//! \~russian Возвращает информацию о всех точках монтирования
|
||||||
static PIVector<MountInfo> mountInfo(bool ignore_cache = false);
|
static PIVector<MountInfo> mountInfo(bool ignore_cache = false);
|
||||||
|
|
||||||
|
//! \~english Returns system unique key
|
||||||
|
//! \~russian Возвращает уникальный ключ системы
|
||||||
static PIString machineKey();
|
static PIString machineKey();
|
||||||
|
|
||||||
|
//! \~english Returns system unique key hash
|
||||||
|
//! \~russian Возвращает хэш уникального ключа системы
|
||||||
static uint machineID();
|
static uint machineID();
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns singleton of %PISystemInfo
|
||||||
|
//! \~russian Возвращает синглтон %PISystemInfo
|
||||||
static PISystemInfo * instance();
|
static PISystemInfo * instance();
|
||||||
|
|
||||||
|
private:
|
||||||
|
PISystemInfo() {}
|
||||||
|
NO_COPY_CLASS(PISystemInfo)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PISystemInfo::MountInfo & v) {
|
inline PICout operator <<(PICout s, const PISystemInfo::MountInfo & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
s << "MountInfo(" << v.device << " mounted on \"" << v.mount_point << "\", type " << v.filesystem
|
s << "MountInfo(" << v.device << " mounted on \"" << v.mount_point << "\", type " << v.filesystem
|
||||||
|
|||||||
@@ -37,13 +37,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
PISystemMonitor::ProcessStatsFixed::ProcessStatsFixed() {
|
|
||||||
ID = parent_ID = group_ID = session_ID = priority = threads = 0;
|
|
||||||
physical_memsize = resident_memsize = share_memsize = virtual_memsize = data_memsize = 0;
|
|
||||||
cpu_load_user = cpu_load_system = 0.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PISystemMonitor::ProcessStats::makeStrings() {
|
void PISystemMonitor::ProcessStats::makeStrings() {
|
||||||
physical_memsize_readable.setReadableSize(physical_memsize);
|
physical_memsize_readable.setReadableSize(physical_memsize);
|
||||||
resident_memsize_readable.setReadableSize(resident_memsize);
|
resident_memsize_readable.setReadableSize(resident_memsize);
|
||||||
@@ -53,12 +46,6 @@ void PISystemMonitor::ProcessStats::makeStrings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PISystemMonitor::ThreadStatsFixed::ThreadStatsFixed() {
|
|
||||||
id = 0;
|
|
||||||
cpu_load_kernel = cpu_load_user = -1.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MICRO_PIP
|
#ifndef MICRO_PIP
|
||||||
PRIVATE_DEFINITION_START(PISystemMonitor)
|
PRIVATE_DEFINITION_START(PISystemMonitor)
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
@@ -356,6 +343,7 @@ void PISystemMonitor::run() {
|
|||||||
|
|
||||||
void PISystemMonitor::gatherThread(llong id) {
|
void PISystemMonitor::gatherThread(llong id) {
|
||||||
PISystemMonitor::ThreadStats ts;
|
PISystemMonitor::ThreadStats ts;
|
||||||
|
if (id == 0) return;
|
||||||
ts.id = id;
|
ts.id = id;
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
ts.name = tbid.value(id, "<PIThread>");
|
ts.name = tbid.value(id, "<PIThread>");
|
||||||
@@ -386,11 +374,12 @@ void PISystemMonitor::gatherThread(llong id) {
|
|||||||
PISystemTime ct = PISystemTime::current();
|
PISystemTime ct = PISystemTime::current();
|
||||||
FILETIME times[4];
|
FILETIME times[4];
|
||||||
HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
|
HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
|
||||||
if (thdl == NULL) {
|
if (!thdl) {
|
||||||
piCout << "[PISystemMonitor] gatherThread(" << id << "):: OpenThread() error:" << errorString();
|
piCout << "[PISystemMonitor] gatherThread(" << id << "):: OpenThread() error:" << errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GetThreadTimes(thdl, &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) {
|
if (GetThreadTimes(thdl, &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) {
|
||||||
|
CloseHandle(thdl);
|
||||||
piCout << "[PISystemMonitor] gatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
|
piCout << "[PISystemMonitor] gatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,75 +29,220 @@
|
|||||||
#include "pithread.h"
|
#include "pithread.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
|
||||||
class PIP_EXPORT PISystemMonitor: public PIThread
|
|
||||||
{
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Process monitoring.
|
||||||
|
//! \~russian Мониторинг процесса.
|
||||||
|
class PIP_EXPORT PISystemMonitor: public PIThread {
|
||||||
PIOBJECT_SUBCLASS(PISystemMonitor, PIThread)
|
PIOBJECT_SUBCLASS(PISystemMonitor, PIThread)
|
||||||
friend class PIIntrospectionServer;
|
friend class PIIntrospectionServer;
|
||||||
public:
|
public:
|
||||||
|
//! \~english Constructs unassigned %PISystemMonitor
|
||||||
|
//! \~russian Создает непривязанный %PISystemMonitor
|
||||||
PISystemMonitor();
|
PISystemMonitor();
|
||||||
|
|
||||||
~PISystemMonitor();
|
~PISystemMonitor();
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Process statistics (fixed-size fields).
|
||||||
|
//! \~russian Статистика процесса (фиксированные поля).
|
||||||
struct PIP_EXPORT ProcessStatsFixed {
|
struct PIP_EXPORT ProcessStatsFixed {
|
||||||
ProcessStatsFixed();
|
|
||||||
int ID;
|
//! \~english PID
|
||||||
int parent_ID;
|
//! \~russian PID
|
||||||
int group_ID;
|
int ID = 0;
|
||||||
int session_ID;
|
|
||||||
int priority;
|
//! \~english Parent PID
|
||||||
int threads;
|
//! \~russian PID родителя
|
||||||
ullong physical_memsize;
|
int parent_ID = 0;
|
||||||
ullong resident_memsize;
|
|
||||||
ullong share_memsize;
|
//! \~english Group ID
|
||||||
ullong virtual_memsize;
|
//! \~russian ID группы
|
||||||
ullong data_memsize;
|
int group_ID = 0;
|
||||||
ullong ram_total;
|
|
||||||
ullong ram_free;
|
//! \~english Session ID
|
||||||
ullong ram_used;
|
//! \~russian ID сессии
|
||||||
float cpu_load_system;
|
int session_ID = 0;
|
||||||
float cpu_load_user;
|
|
||||||
|
//! \~english Priority
|
||||||
|
//! \~russian Приоритет
|
||||||
|
int priority = 0;
|
||||||
|
|
||||||
|
//! \~english Threads count
|
||||||
|
//! \~russian Количество потоков
|
||||||
|
int threads = 0;
|
||||||
|
|
||||||
|
//! \~english Physical memory in bytes
|
||||||
|
//! \~russian Физическая память в байтах
|
||||||
|
ullong physical_memsize = 0;
|
||||||
|
|
||||||
|
//! \~english Resident memory in bytes
|
||||||
|
//! \~russian Резидентная память в байтах
|
||||||
|
ullong resident_memsize = 0;
|
||||||
|
|
||||||
|
//! \~english Share memory in bytes
|
||||||
|
//! \~russian Разделяемая память в байтах
|
||||||
|
ullong share_memsize = 0;
|
||||||
|
|
||||||
|
//! \~english Virtual memory in bytes
|
||||||
|
//! \~russian Виртуальная память в байтах
|
||||||
|
ullong virtual_memsize = 0;
|
||||||
|
|
||||||
|
//! \~english Data memory in bytes
|
||||||
|
//! \~russian Память данных в байтах
|
||||||
|
ullong data_memsize = 0;
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
|
ullong ram_total = 0;
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
|
ullong ram_free = 0;
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
|
ullong ram_used = 0;
|
||||||
|
|
||||||
|
//! \~english CPU load in kernel space
|
||||||
|
//! \~russian Загрузка CPU в пространстве ядра
|
||||||
|
float cpu_load_system = 0.f;
|
||||||
|
|
||||||
|
//! \~english CPU load in user space
|
||||||
|
//! \~russian Загрузка CPU в пространстве пользователя
|
||||||
|
float cpu_load_user = 0.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Thread statistics (fixed-size fields).
|
||||||
|
//! \~russian Статистика потока (фиксированные поля).
|
||||||
struct PIP_EXPORT ThreadStatsFixed {
|
struct PIP_EXPORT ThreadStatsFixed {
|
||||||
ThreadStatsFixed();
|
|
||||||
llong id;
|
//! \~english TID
|
||||||
|
//! \~russian TID
|
||||||
|
llong id = 0;
|
||||||
|
|
||||||
|
//! \~english Overall live time
|
||||||
|
//! \~russian Полное время жизни
|
||||||
PISystemTime work_time;
|
PISystemTime work_time;
|
||||||
|
|
||||||
|
//! \~english Busy time in kernel space
|
||||||
|
//! \~russian Время работы в пространстве ядра
|
||||||
PISystemTime kernel_time;
|
PISystemTime kernel_time;
|
||||||
|
|
||||||
|
//! \~english Busy time in user space
|
||||||
|
//! \~russian Время работы в пространстве пользователя
|
||||||
PISystemTime user_time;
|
PISystemTime user_time;
|
||||||
float cpu_load_kernel;
|
|
||||||
float cpu_load_user;
|
//! \~english CPU load in kernel space
|
||||||
|
//! \~russian Загрузка CPU в пространстве ядра
|
||||||
|
float cpu_load_kernel = -1.f;
|
||||||
|
|
||||||
|
//! \~english CPU load in user space
|
||||||
|
//! \~russian Загрузка CPU в пространстве пользователя
|
||||||
|
float cpu_load_user = -1.f;
|
||||||
|
|
||||||
|
//! \~english Date and time of creation
|
||||||
|
//! \~russian Дата и время создания
|
||||||
PIDateTime created;
|
PIDateTime created;
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Process statistics.
|
||||||
|
//! \~russian Статистика процесса.
|
||||||
struct PIP_EXPORT ProcessStats: ProcessStatsFixed {
|
struct PIP_EXPORT ProcessStats: ProcessStatsFixed {
|
||||||
|
|
||||||
|
//! \~english Fill human-readable fields
|
||||||
|
//! \~russian Заполнить читаемые поля
|
||||||
void makeStrings();
|
void makeStrings();
|
||||||
|
|
||||||
|
//! \~english Execution command
|
||||||
|
//! \~russian Команда запуска
|
||||||
PIString exec_name;
|
PIString exec_name;
|
||||||
|
|
||||||
|
//! \~english State
|
||||||
|
//! \~russian Состояние
|
||||||
PIString state;
|
PIString state;
|
||||||
|
|
||||||
|
//! \~english Human-readable physical memory
|
||||||
|
//! \~russian Физическая память в читаемом виде
|
||||||
PIString physical_memsize_readable;
|
PIString physical_memsize_readable;
|
||||||
|
|
||||||
|
//! \~english Human-readable resident memory
|
||||||
|
//! \~russian Резидентная память в читаемом виде
|
||||||
PIString resident_memsize_readable;
|
PIString resident_memsize_readable;
|
||||||
|
|
||||||
|
//! \~english Human-readable share memory
|
||||||
|
//! \~russian Разделяемая память в читаемом виде
|
||||||
PIString share_memsize_readable;
|
PIString share_memsize_readable;
|
||||||
|
|
||||||
|
//! \~english Human-readable virtual memory
|
||||||
|
//! \~russian Виртуальная память в читаемом виде
|
||||||
PIString virtual_memsize_readable;
|
PIString virtual_memsize_readable;
|
||||||
|
|
||||||
|
//! \~english Human-readable data memory
|
||||||
|
//! \~russian Память данных в читаемом виде
|
||||||
PIString data_memsize_readable;
|
PIString data_memsize_readable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \ingroup System
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Thread statistics.
|
||||||
|
//! \~russian Статистика потока.
|
||||||
struct PIP_EXPORT ThreadStats: ThreadStatsFixed {
|
struct PIP_EXPORT ThreadStats: ThreadStatsFixed {
|
||||||
|
|
||||||
|
//! \~english Name
|
||||||
|
//! \~russian Имя
|
||||||
PIString name;
|
PIString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef MICRO_PIP
|
#ifndef MICRO_PIP
|
||||||
|
|
||||||
|
//! \~english Starts monitoring of process with PID "pID" and update interval "interval_ms" milliseconds
|
||||||
|
//! \~russian Начинает мониторинг процесса с PID "pID" и интервалом обновления "interval_ms" миллисекунд
|
||||||
bool startOnProcess(int pID, int interval_ms = 1000);
|
bool startOnProcess(int pID, int interval_ms = 1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//! \~english Starts monitoring of application process with update interval "interval_ms" milliseconds
|
||||||
|
//! \~russian Начинает мониторинг процесса приложения с интервалом обновления "interval_ms" миллисекунд
|
||||||
bool startOnSelf(int interval_ms = 1000);
|
bool startOnSelf(int interval_ms = 1000);
|
||||||
|
|
||||||
|
//! \~english Stop monitoring
|
||||||
|
//! \~russian Останавливает мониторинг
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Returns monitoring process PID
|
||||||
|
//! \~russian Возвращает PID наблюдаемого процесса
|
||||||
int pID() const {return pID_;}
|
int pID() const {return pID_;}
|
||||||
|
|
||||||
|
//! \~english Returns monitoring process statistics
|
||||||
|
//! \~russian Возвращает статистику наблюдаемого процесса
|
||||||
ProcessStats statistic() const;
|
ProcessStats statistic() const;
|
||||||
|
|
||||||
|
//! \~english Returns monitoring process threads statistics
|
||||||
|
//! \~russian Возвращает статистику потоков наблюдаемого процесса
|
||||||
PIVector<ThreadStats> threadsStatistic() const;
|
PIVector<ThreadStats> threadsStatistic() const;
|
||||||
|
|
||||||
void setStatistic(const ProcessStats & s);
|
void setStatistic(const ProcessStats & s);
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
static ullong totalRAM();
|
static ullong totalRAM();
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
static ullong freeRAM();
|
static ullong freeRAM();
|
||||||
|
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
static ullong usedRAM();
|
static ullong usedRAM();
|
||||||
|
|
||||||
|
|
||||||
@@ -131,6 +276,9 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
s << "ThreadInfo(\"" << v.name << "\", created " << v.created
|
s << "ThreadInfo(\"" << v.name << "\", created " << v.created
|
||||||
@@ -142,9 +290,25 @@ inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Store operator
|
||||||
|
//! \~russian Оператор сохранения
|
||||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ProcessStats & v);
|
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ProcessStats & v);
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Restore operator
|
||||||
|
//! \~russian Оператор извлечения
|
||||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v);
|
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v);
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Store operator
|
||||||
|
//! \~russian Оператор сохранения
|
||||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v);
|
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v);
|
||||||
|
|
||||||
|
//! \relatesalso PIByteArray
|
||||||
|
//! \~english Restore operator
|
||||||
|
//! \~russian Оператор извлечения
|
||||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v);
|
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v);
|
||||||
|
|
||||||
#endif // PISYSTEMMONITOR_H
|
#endif // PISYSTEMMONITOR_H
|
||||||
|
|||||||
312
main.cpp
312
main.cpp
@@ -1,89 +1,241 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
|
||||||
REGISTER_VARIANT_TYPEINFO(PIVector<double>)
|
|
||||||
|
|
||||||
PIEthernet eth;
|
|
||||||
|
|
||||||
class OH: public PIObject {
|
|
||||||
PIOBJECT(OH)
|
|
||||||
public:
|
|
||||||
EVENT_HANDLER0(void, eh0) {
|
|
||||||
piCout << "eh0";
|
|
||||||
}
|
|
||||||
EVENT_HANDLER1(void, eh1, PIStringList, sl) {
|
|
||||||
piCout << "eh1" << sl;
|
|
||||||
}
|
|
||||||
EVENT_HANDLER2(void, eh2, PIStringList, sl, const PIVector< double > &, vd) {
|
|
||||||
piCout << "eh2" << sl << vd;
|
|
||||||
}
|
|
||||||
EVENT_HANDLER3(void, eh3, PIStringList, sl, const PIVector<double> &, vd, PISystemTime, st) {
|
|
||||||
piCout << "eh3" << sl << vd << st;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
int cnt = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class OE: public PIThread {
|
|
||||||
PIOBJECT_SUBCLASS(OE, PIThread)
|
|
||||||
public:
|
|
||||||
EVENT0(e0);
|
|
||||||
EVENT1(e1, PIStringList, sl);
|
|
||||||
EVENT2(e2, PIStringList, sl, PIVector< double>, vd);
|
|
||||||
EVENT3(e3, PIStringList, sl, PIVector< double>, vd, PISystemTime, st);
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
PIThreadNotifier notifier;
|
|
||||||
PITimeMeasurer time;
|
|
||||||
|
|
||||||
class Worker: public PIThread {
|
|
||||||
PIOBJECT_SUBCLASS(Worker, PIThread)
|
|
||||||
public:
|
|
||||||
Worker(const PIString & n) {
|
|
||||||
setName(n);
|
|
||||||
}
|
|
||||||
void run() override {
|
|
||||||
piCoutObj << (int)time.elapsed_m() << "wait ...";
|
|
||||||
notifier.wait();
|
|
||||||
piCoutObj << (int)time.elapsed_m() << "done";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
typedef int(*MyFunc)(int,int);
|
const int repeat = 1000;
|
||||||
PILibrary * lib = new PILibrary();
|
const int no_repeat = 1;
|
||||||
if (lib->load("libpip_plugin.dll")) {
|
const int small_cnt = 1000;
|
||||||
MyFunc fadd = (MyFunc)lib->resolve("exportedSum");
|
const int big_cnt = 100000;
|
||||||
MyFunc fmul = (MyFunc)lib->resolve("exportedMul");
|
PITimeMeasurer tm;
|
||||||
if (fadd) {
|
|
||||||
int sum = fadd(1, 2);
|
|
||||||
piCout << "sum =" << sum;
|
PIStringList small_sl;
|
||||||
} else {
|
PIStringList big_sl;
|
||||||
piCout << "Can`t resolve" << "exportedSum";
|
// {
|
||||||
|
// for (int i=0; i<small_cnt; ++i) small_sl << PIString::fromNumber(randomi())+PIString::fromNumber(i);
|
||||||
|
// for (int i=0; i<big_cnt; ++i) big_sl << PIString::fromNumber(randomi())+PIString::fromNumber(i);
|
||||||
|
// PIFile f;
|
||||||
|
// f.open("test.bin", PIIODevice::WriteOnly);
|
||||||
|
// PIByteArray slba;
|
||||||
|
// slba << small_sl;
|
||||||
|
// slba << big_sl;
|
||||||
|
// f.write(slba);
|
||||||
|
// f.close();
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
{
|
||||||
|
PIFile f;
|
||||||
|
f.open("test.bin", PIIODevice::ReadOnly);
|
||||||
|
PIByteArray slba = f.readAll();
|
||||||
|
slba >> small_sl;
|
||||||
|
slba >> big_sl;
|
||||||
|
f.close();
|
||||||
}
|
}
|
||||||
if (fmul) {
|
|
||||||
int mul = fadd(10, 20);
|
piCout << "map<int, int> insert...";
|
||||||
piCout << "mul =" << mul;
|
tm.reset();
|
||||||
} else {
|
for (int c=0; c<repeat; ++c) {
|
||||||
piCout << "Can`t resolve" << "exportedMul";
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(i, i);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
piCout << lib->lastError();
|
|
||||||
}
|
}
|
||||||
delete lib;
|
piCout << "map<int, int> insert" << tm.elapsed_m();
|
||||||
/*OH oh;
|
piCout << "map<int, int> insert []...";
|
||||||
OE oe;
|
tm.reset();
|
||||||
CONNECTU(&oe, e3, &oh, eh0);
|
for (int c=0; c<repeat; ++c) {
|
||||||
CONNECTU(&oe, e3, &oh, eh1);
|
PIMap<int64_t, int64_t> m1;
|
||||||
CONNECTU(&oe, e3, &oh, eh2);
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
CONNECTU(&oe, e3, &oh, eh3);
|
m1[i] = i;
|
||||||
//oh.dump();
|
}
|
||||||
oe.dump();
|
}
|
||||||
oe.e0();
|
piCout << "map<int, int> insert []" << tm.elapsed_m();
|
||||||
oe.e1({"a", "b", "c"});
|
piCout << "map<int, int> insert rnd...";
|
||||||
oe.e2({"a", "b", "c"}, {1., 1.5, 2.});
|
tm.reset();
|
||||||
oe.e3({"a", "b", "c"}, {1., 1.5, 2.}, PISystemTime::current());
|
for (int c=0; c<repeat; ++c) {
|
||||||
//piCout << oe.methodsEH();*/
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(randomi(), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "map<int, int> insert rnd" << tm.elapsed_m();
|
||||||
|
piCout << "map<int, int> insert rnd []...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1[randomi()] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "map<int, int> insert rnd []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "bigmap<int, int> insert...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(i, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<int, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert []...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[i] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<int, int> insert []" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert rnd...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(randomi(), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<int, int> insert rnd" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert rnd []...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<int64_t, int64_t> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[randomi()] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<int, int> insert rnd []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<PIString, int> insert...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIMap<PIString, int> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(small_sl[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "map<PIString, int> insert []...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIMap<PIString, int> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1[small_sl[i]] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> insert []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "bigmap<PIString, int> insert...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<PIString, int> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(big_sl[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<PIString, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<PIString, int> insert []...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
|
PIMap<PIString, int> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[big_sl[i]] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
piCout << "bigmap<PIString, int> insert []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
|
||||||
|
PIMap<int, int> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) m1.insert(i,i);
|
||||||
|
piCout << "map<int, int> interate...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIVector<int> v;
|
||||||
|
v.reserve(m1.size());
|
||||||
|
auto it = m1.makeIterator();
|
||||||
|
while (it.next()) v << it.value();
|
||||||
|
}
|
||||||
|
piCout << "map<int, int> interate" << tm.elapsed_m();
|
||||||
|
|
||||||
|
PIMap<PIString, int> m2;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m2.insert(big_sl[i], i);
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> interate...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIVector<int> v;
|
||||||
|
v.reserve(m2.size());
|
||||||
|
auto it = m2.makeIterator();
|
||||||
|
while (it.next()) v << it.value();
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> interate" << tm.elapsed_m();
|
||||||
|
|
||||||
|
|
||||||
|
PIByteArray ba;
|
||||||
|
ba.resize(64*1024);
|
||||||
|
piCout << "map<int, PIByteArray> insert...";
|
||||||
|
PIMap<int, PIByteArray> m3;
|
||||||
|
m3.reserve(big_cnt);
|
||||||
|
tm.reset();
|
||||||
|
for (int i=0; i<big_cnt; ++i) m3.insert(i, ba);
|
||||||
|
piCout << "map<int, PIByteArray> insert" << tm.elapsed_m();
|
||||||
|
piCout << "map<int, PIByteArray> interate...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIVector<int> v;
|
||||||
|
v.reserve(m3.size());
|
||||||
|
auto it = m3.makeIterator();
|
||||||
|
while (it.next()) v << it.value().size();
|
||||||
|
}
|
||||||
|
piCout << "map<int, PIByteArray> interate" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<PIString, PIByteArray> insert...";
|
||||||
|
PIMap<PIString, PIByteArray> m4;
|
||||||
|
m4.reserve(big_cnt);
|
||||||
|
tm.reset();
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m4.insert(big_sl[i], ba);
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, PIByteArray> insert" << tm.elapsed_m();
|
||||||
|
piCout << "map<PIString, PIByteArray> interate...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIVector<int> v;
|
||||||
|
v.reserve(m4.size());
|
||||||
|
auto it = m4.makeIterator();
|
||||||
|
while (it.next()) v << it.value().size();
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, PIByteArray> interate" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<int, int> cointains...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<big_cnt; ++c) {
|
||||||
|
m1.contains(1023);
|
||||||
|
}
|
||||||
|
piCout << "map<int, int> contains" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<int, int> cointains miss...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<big_cnt; ++c) {
|
||||||
|
m1.contains(-1);
|
||||||
|
}
|
||||||
|
piCout << "map<int, int> contains miss" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<PIString, int> cointains...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<big_cnt; ++c) {
|
||||||
|
m2.contains(big_sl[1023]);
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> contains" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "map<PIString, int> cointains miss...";
|
||||||
|
PIString s = "dfcdsfas";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<big_cnt; ++c) {
|
||||||
|
m2.contains(s);
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> contains miss" << tm.elapsed_m();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ endif()
|
|||||||
if (NOT DEFINED ANDROID_PLATFORM)
|
if (NOT DEFINED ANDROID_PLATFORM)
|
||||||
deploy_target(${PROJECT_NAME}
|
deploy_target(${PROJECT_NAME}
|
||||||
DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
DESTINATION ${ROOT_DIR}/release
|
DESTINATION "${ROOT_DIR}/release"
|
||||||
DEB_ADD_SERVICE
|
DEB_ADD_SERVICE
|
||||||
ADD_MANIFEST
|
ADD_MANIFEST
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -419,18 +419,22 @@ void makeGetterValue(PIFile & f, const PICodeParser::Entity * e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, const PIStringList & files, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
||||||
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
||||||
PISet<PIString> inc_files;
|
PISet<PIString> inc_files;
|
||||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
piForeachC (PICodeParser::Entity * e, parser.entities)
|
||||||
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
|
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
|
||||||
inc_files << e->file;
|
inc_files << e->file;
|
||||||
PIString inc_string;
|
|
||||||
PIVector<PIString> incf = inc_files.toVector();
|
PIVector<PIString> incf = inc_files.toVector();
|
||||||
|
for (auto & f: files) incf << f;
|
||||||
|
PIString inc_string;
|
||||||
piForeachC (PIString & i, incf) {
|
piForeachC (PIString & i, incf) {
|
||||||
if (i != parser.mainFile())
|
if ((i != parser.mainFile()) && (streams || texts || getters))
|
||||||
inc_string << "\n#include \"" << i << "\"";
|
inc_string << "\n#include \"" << i << "\"";
|
||||||
}
|
}
|
||||||
|
//piCout << parser.mainFile() << streams << texts << getters;
|
||||||
|
//piCout << incf;
|
||||||
|
//piCout << inc_string;
|
||||||
|
|
||||||
PIFile f(out + ".cpp");
|
PIFile f(out + ".cpp");
|
||||||
f.clear();
|
f.clear();
|
||||||
@@ -562,7 +566,8 @@ int main(int argc, char * argv[]) {
|
|||||||
piCout << Cyan << Bold << "Parsing done";
|
piCout << Cyan << Bold << "Parsing done";
|
||||||
piCout << Cyan << Bold << "Writing code model ...";
|
piCout << Cyan << Bold << "Writing code model ...";
|
||||||
bool all = cli.hasArgument("All");
|
bool all = cli.hasArgument("All");
|
||||||
writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
writeModel(parser, cli, cli.argumentValue("output"), files,
|
||||||
|
cli.hasArgument("Metainfo") || all,
|
||||||
cli.hasArgument("Enum") || all,
|
cli.hasArgument("Enum") || all,
|
||||||
cli.hasArgument("Stream") || all,
|
cli.hasArgument("Stream") || all,
|
||||||
cli.hasArgument("Text") || all,
|
cli.hasArgument("Text") || all,
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ PIString frameworkName(const PIString & l) {
|
|||||||
|
|
||||||
|
|
||||||
PIString frameworkInternalPath(const PIString & l) {
|
PIString frameworkInternalPath(const PIString & l) {
|
||||||
return l.right(l.size_s() - l.lastIndexOf(".framework") - 11);
|
return l.right(l.size_s() - l.findLast('.') - 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -632,7 +632,7 @@ int main(int argc, char * argv[]) {
|
|||||||
if (styles.isEmpty()) styles << "";
|
if (styles.isEmpty()) styles << "";
|
||||||
PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM);
|
PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM);
|
||||||
piForeachC (PIString & qp, qpd) {
|
piForeachC (PIString & qp, qpd) {
|
||||||
int _i = qp.indexOf("=");
|
int _i = qp.find('=');
|
||||||
if (_i < 0) continue;
|
if (_i < 0) continue;
|
||||||
PIString pname = qp.left(_i).trim();
|
PIString pname = qp.left(_i).trim();
|
||||||
PIStringList pfilt = qp.mid(_i + 1).trim().split(",");
|
PIStringList pfilt = qp.mid(_i + 1).trim().split(",");
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ public:
|
|||||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||||
//piCout << "key" << e.key;
|
//piCout << "key" << e.key;
|
||||||
}
|
}
|
||||||
EVENT_HANDLER1(void, messageFromApp, const PIByteArray & , m) {
|
EVENT_HANDLER1(void, messageFromApp, PIByteArray, m) {
|
||||||
if (m[0] == 'k') PIKbdListener::exiting = true;
|
if (m[0] == 'k') PIKbdListener::exiting = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ void usage() {
|
|||||||
piCout << PICoutManipulators::Bold << "PIP System Daemon";
|
piCout << PICoutManipulators::Bold << "PIP System Daemon";
|
||||||
piCout << PICoutManipulators::Cyan << "Version" << PICoutManipulators::Bold << PIPVersion() << PICoutManipulators::NewLine;
|
piCout << PICoutManipulators::Cyan << "Version" << PICoutManipulators::Bold << PIPVersion() << PICoutManipulators::NewLine;
|
||||||
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Usage:" << PICoutManipulators::Default
|
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Usage:" << PICoutManipulators::Default
|
||||||
<< "\"pisd [-hdfk] [-n <name>] [-a <ip>]\"" << PICoutManipulators::NewLine;
|
<< "\"pisd [-1hdfk] [-n <name>] [-a <ip>]\"" << PICoutManipulators::NewLine;
|
||||||
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Details:";
|
piCout << PICoutManipulators::Green << PICoutManipulators::Bold << "Details:";
|
||||||
piCout << "-h --help " << PICoutManipulators::Green << "- display this message and exit";
|
piCout << "-h --help " << PICoutManipulators::Green << "- display this message and exit";
|
||||||
piCout << "-d --daemon " << PICoutManipulators::Green << "- start as daemon";
|
piCout << "-d --daemon " << PICoutManipulators::Green << "- start as daemon";
|
||||||
@@ -332,7 +332,6 @@ void usage() {
|
|||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
sys_mon.startOnSelf();
|
sys_mon.startOnSelf();
|
||||||
PIINTROSPECTION_START(pisd)
|
|
||||||
//piDebug = false;
|
//piDebug = false;
|
||||||
PICLI cli(argc, argv);
|
PICLI cli(argc, argv);
|
||||||
cli.addArgument("help");
|
cli.addArgument("help");
|
||||||
@@ -355,14 +354,17 @@ int main(int argc, char * argv[]) {
|
|||||||
if (cli.hasArgument("1")) {
|
if (cli.hasArgument("1")) {
|
||||||
if (!sapp->isFirst()) {
|
if (!sapp->isFirst()) {
|
||||||
piCout << "Another pisd is running, exit";
|
piCout << "Another pisd is running, exit";
|
||||||
|
delete sapp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cli.hasArgument("kill")) {
|
if (cli.hasArgument("kill")) {
|
||||||
sapp->sendMessage(PIByteArray("k", 1));
|
sapp->sendMessage(PIByteArray("k", 1));
|
||||||
|
delete sapp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PIINTROSPECTION_START(pisd)
|
||||||
if (cli.hasArgument("daemon")) {
|
if (cli.hasArgument("daemon")) {
|
||||||
PIStringList args;
|
PIStringList args;
|
||||||
args << "-1" << "-s";
|
args << "-1" << "-s";
|
||||||
|
|||||||
Reference in New Issue
Block a user