diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fc1dcd4..18bed85f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,13 +250,24 @@ endif() # Check if PIP should be built with introspection +set(_PIP_DEFS "") if(INTROSPECTION) message(STATUS "Building PIP with introspection") message(STATUS "Warning: Introspection reduces the performance!") add_definitions(-DPIP_INTROSPECTION) + set(_PIP_DEFS "PIP_INTROSPECTION") else() message(STATUS "Building PIP without introspection") endif() +if ((NOT _PIP_SAVED_DEFS) OR (NOT "x${_PIP_SAVED_DEFS}" STREQUAL "x${_PIP_DEFS}")) + set(_PIP_SAVED_DEFS "${_PIP_DEFS}" CACHE STRING "pip_defs" FORCE) + file(WRITE "${PIP_SRC_MAIN}/pip_defs.h" "// This file was generated by PIP CMake, don`t edit it!\n") + if (NOT "x${_PIP_DEFS}" STREQUAL "x") + file(APPEND "${PIP_SRC_MAIN}/pip_defs.h" "#define ${_PIP_DEFS}\n") + endif() +endif() +list(APPEND HDRS "${PIP_SRC_MAIN}/pip_defs.h") +#message("${_PIP_DEFS_CHANGED}") # Check if RT timers exists diff --git a/doc/examples/pistring.cpp b/doc/examples/pistring.cpp index ab10fb9f..6ad2423f 100644 --- a/doc/examples/pistring.cpp +++ b/doc/examples/pistring.cpp @@ -179,6 +179,12 @@ PIString s("0123456789"); piCout << s.reversed(); // s = "9876543210" piCout << s; // s = "0123456789" //! [PIString::reversed] +//! [PIString::elided] +piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideLeft); // ..ABCDEF +piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideCenter); // 123..DEF +piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideRight); // 123456.. +piCout << PIString("123456789ABCDEF").elided(8, 0.25); // 12..CDEF +//! [PIString::elided] //! [PIString::lengthAscii] piCout << PIString("0123456789").lengthAscii(); // 10 piCout << PIString("№1").lengthAscii(); // 3 diff --git a/src_main/containers/pilist.h b/src_main/containers/pilist.h index f3a0a7c8..ffd8542c 100644 --- a/src_main/containers/pilist.h +++ b/src_main/containers/pilist.h @@ -33,13 +33,13 @@ class PIP_EXPORT PIList: public std::list { typedef PIList _CList; typedef std::list _stlc; public: - PIList() {piMonitor.containers++;} - PIList(const Type & value) {piMonitor.containers++; _stlc::resize(1, value);} - PIList(const Type & v0, const Type & v1) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1);} - PIList(const Type & v0, const Type & v1, const Type & v2) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);} - PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);} - PIList(uint size, const Type & value = Type()) {piMonitor.containers++; _stlc::resize(size, value);} - virtual ~PIList() {piMonitor.containers--;} + PIList() {} + PIList(const Type & value) {_stlc::resize(1, value);} + PIList(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);} + PIList(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);} + PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);} + PIList(uint size, const Type & value = Type()) {_stlc::resize(size, value);} + virtual ~PIList() {} Type & operator [](uint index) {return (*this)[index];} Type & operator [](uint index) const {return (*this)[index];} const Type * data(uint index = 0) const {return &(*this)[index];} diff --git a/src_main/containers/pivector.h b/src_main/containers/pivector.h index 85fad827..8e1b1ab4 100755 --- a/src_main/containers/pivector.h +++ b/src_main/containers/pivector.h @@ -437,9 +437,9 @@ class PIP_EXPORT PIVector: public vector { typedef vector _stlc; public: - PIVector() {piMonitor.containers++;} - PIVector(uint size, const T & value = T()) {piMonitor.containers++; _stlc::resize(size, value);} - ~PIVector() {piMonitor.containers--;} + PIVector() {} + PIVector(uint size, const T & value = T()) {_stlc::resize(size, value);} + ~PIVector() {} const T & at(uint index) const {return (*this)[index];} T & at(uint index) {return (*this)[index];} diff --git a/src_main/core/pibase.h b/src_main/core/pibase.h index 9380cd36..e0c2b5d8 100644 --- a/src_main/core/pibase.h +++ b/src_main/core/pibase.h @@ -29,6 +29,7 @@ #include "piversion.h" #include "piplatform.h" #include "pip_export.h" +#include "pip_defs.h" //! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision) #define PIP_VERSION ((PIP_VERSION_MAJOR << 16) | (PIP_VERSION_MINOR < 8) | PIP_VERSION_REVISION) diff --git a/src_main/core/piincludes.h b/src_main/core/piincludes.h index cc8ae33e..62c86086 100755 --- a/src_main/core/piincludes.h +++ b/src_main/core/piincludes.h @@ -22,14 +22,11 @@ #include "pibase.h" #include "piflags.h" -#include "pimonitor.h" #include #ifdef PIP_STD_IOSTREAM # include #endif -extern PIMonitor piMonitor; - class PIObject; class PIMutex; class PIString; diff --git a/src_main/core/piobject.cpp b/src_main/core/piobject.cpp index 25eaae16..bc27af37 100755 --- a/src_main/core/piobject.cpp +++ b/src_main/core/piobject.cpp @@ -77,7 +77,6 @@ PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__), setName(name); setDebug(true); mutexObjects().lock(); - piMonitor.objects++; objects() << this; mutexObjects().unlock(); //piCout << "new" << this; @@ -87,7 +86,6 @@ PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__), PIObject::~PIObject() { //piCout << "delete" << this; mutexObjects().lock(); - piMonitor.objects--; objects().removeAll(this); mutexObjects().unlock(); piDisconnect(this); diff --git a/src_main/core/pistring.cpp b/src_main/core/pistring.cpp index c4c845c8..e587a8b1 100755 --- a/src_main/core/pistring.cpp +++ b/src_main/core/pistring.cpp @@ -86,6 +86,10 @@ const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; +const float PIString::ElideLeft = 0.f; +const float PIString::ElideCenter = .5f; +const float PIString::ElideRight = 1.f; + #ifndef CC_VC # define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v); @@ -629,6 +633,21 @@ PIString & PIString::insert(int index, const PIString & str) { } +PIString & PIString::elide(int size, float pos) { + if (length() <= size) return *this; + if (length() <= 2) { + fill("."); + return *this; + } + pos = piClampf(pos, 0.f, 1.f); + int ns = size - 2; + int ls = piRoundf(ns * pos); + remove(ls, length() - ns); + insert(ls, ".."); + return *this; +} + + PIStringList PIString::split(const PIString & delim) const { PIStringList sl; if (isEmpty() || delim.isEmpty()) return sl; diff --git a/src_main/core/pistring.h b/src_main/core/pistring.h index f0adf1a1..7e1c2a0b 100755 --- a/src_main/core/pistring.h +++ b/src_main/core/pistring.h @@ -39,6 +39,10 @@ public: //! Contructs an empty string PIString(): PIDeque() {} + static const float ElideLeft ; + static const float ElideCenter; + static const float ElideRight ; + //inline PIString & operator +=(const char c) {push_back(c); return *this;} PIString & operator +=(const PIChar & c) {push_back(c); return *this;} PIString & operator +=(const char * str); @@ -354,7 +358,7 @@ public: PIString quoted(PIChar c = PIChar('"')) {return PIString(*this).quote(c);} /*! \brief Reverse string and return this string - * \details Example: \snippet pistring.cpp PIString::reverse + * \details Example: \snippet pistring.cpp PIString::reverse * \sa \a reversed() */ PIString & reverse() {PIString str(*this); clear(); piForeachR (const PIChar & c, str) push_back(c); return *this;} @@ -362,6 +366,15 @@ public: * \details Example: \snippet pistring.cpp PIString::reversed * \sa \a reverse() */ PIString reversed() const {PIString str(*this); str.reverse(); return str;} + + /*! \brief Elide string to maximum size \"size\" and return this string + * \sa \a elided() */ + PIString & elide(int size, float pos = ElideCenter); + + /*! \brief Elide copy of this string to maximum size \"size\" and return it + * \details Example: \snippet pistring.cpp PIString::elided + * \sa \a elide() */ + PIString elided(int size, float pos = ElideCenter) const {PIString str(*this); str.elide(size, pos); return str;} /*! \brief Take a part of string from symbol at index "start" and maximum length "len" and return it diff --git a/src_main/io_devices/piethernet.cpp b/src_main/io_devices/piethernet.cpp index eb230331..3526a720 100755 --- a/src_main/io_devices/piethernet.cpp +++ b/src_main/io_devices/piethernet.cpp @@ -246,7 +246,6 @@ PIEthernet::~PIEthernet() { //piCout << "~PIEthernet" << uint(this); stop(); closeDevice(); - piMonitor.ethernets--; //piCoutObj << "~PIEthernet done"; } @@ -254,7 +253,6 @@ PIEthernet::~PIEthernet() { void PIEthernet::construct() { //piCout << " PIEthernet" << uint(this); setOption(BlockingWrite); - piMonitor.ethernets++; connected_ = connecting_ = listen_threaded = server_bounded = false; sock = sock_s = -1; setReadTimeout(10000.); diff --git a/src_main/io_devices/piserial.cpp b/src_main/io_devices/piserial.cpp index 6197d650..d480e57d 100755 --- a/src_main/io_devices/piserial.cpp +++ b/src_main/io_devices/piserial.cpp @@ -164,7 +164,6 @@ PISerial::PISerial(const PIString & device_, PISerial::Speed speed_, PIFlagshCom = 0; #endif fd = -1; - piMonitor.serials++; setPriority(piHigh); vtime = 10; sending = false; diff --git a/src_main/system/pimonitor.cpp b/src_main/system/pimonitor.cpp deleted file mode 100755 index 7ab9d387..00000000 --- a/src_main/system/pimonitor.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - PIP - Platform Independent Primitives - Counter of some PIP types - Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "pimonitor.h" - -PIMonitor piMonitor; - -PIMonitor::PIMonitor() { - containers = strings = threads = timers = serials = ethernets = files = objects = 0; -} diff --git a/src_main/system/pimonitor.h b/src_main/system/pimonitor.h deleted file mode 100755 index 4e7d06b1..00000000 --- a/src_main/system/pimonitor.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - PIP - Platform Independent Primitives - Counter of some PIP types - Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef PIMONITOR_H -#define PIMONITOR_H - -#include "pip_export.h" - -#if defined(DOXYGEN) || defined(__GNUC__) -# undef PIP_EXPORT -# define PIP_EXPORT -#endif - -class PIP_EXPORT PIMonitor -{ -public: - PIMonitor(); - - int containers, strings, threads, timers, serials, ethernets, files, objects; - -}; - -#endif // PIMONITOR_H diff --git a/src_main/system/pisystemmodule.h b/src_main/system/pisystemmodule.h index 52b092bf..f316af06 100644 --- a/src_main/system/pisystemmodule.h +++ b/src_main/system/pisystemmodule.h @@ -20,7 +20,6 @@ #ifndef PISYSTEMMODULE_H #define PISYSTEMMODULE_H -#include "pimonitor.h" #include "picodec.h" #include "pisignals.h" #include "pilibrary.h" diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index 24b25289..650afbff 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -161,7 +161,6 @@ PRIVATE_DEFINITION_END(PIThread) PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay): PIObject() { PIINTROSPECTION_THREAD_NEW(this); - piMonitor.threads++; tid_ = -1; PRIVATE->thread = 0; data_ = data; @@ -175,7 +174,6 @@ PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay) PIThread::PIThread(bool startNow, int timer_delay): PIObject() { PIINTROSPECTION_THREAD_NEW(this); - piMonitor.threads++; tid_ = -1; PRIVATE->thread = 0; ret_func = 0; @@ -188,7 +186,6 @@ PIThread::PIThread(bool startNow, int timer_delay): PIObject() { PIThread::~PIThread() { PIINTROSPECTION_THREAD_DELETE(this); - piMonitor.threads--; if (!running_ || PRIVATE->thread == 0) return; #ifdef FREERTOS //void * ret(0); diff --git a/src_main/thread/pitimer.cpp b/src_main/thread/pitimer.cpp index 77edb3a2..9c94892d 100755 --- a/src_main/thread/pitimer.cpp +++ b/src_main/thread/pitimer.cpp @@ -458,7 +458,6 @@ bool _PITimerImp_Pool::stopTimer(bool wait) { PITimer::PITimer(): PIObject() { - piMonitor.timers++; #ifdef FREERTOS imp_mode = PITimer::Thread; #else @@ -469,14 +468,12 @@ PITimer::PITimer(): PIObject() { PITimer::PITimer(PITimer::TimerImplementation ti): PIObject() { - piMonitor.timers++; imp_mode = ti; initFirst(); } PITimer::PITimer(TimerEvent slot, void * data, PITimer::TimerImplementation ti): PIObject() { - piMonitor.timers++; imp_mode = ti; initFirst(); data_t = data; @@ -485,7 +482,6 @@ PITimer::PITimer(TimerEvent slot, void * data, PITimer::TimerImplementation ti): //PITimer::PITimer(const PITimer & other): PIObject() { -// piMonitor.timers++; // imp_mode = other.imp_mode; // initFirst(); // data_t = other.data_t; @@ -494,7 +490,6 @@ PITimer::PITimer(TimerEvent slot, void * data, PITimer::TimerImplementation ti): PITimer::~PITimer() { - piMonitor.timers--; destroy(); }