From f26f04b5fec94f9c7a88c6aa99ead5d6e68d24cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 14 Mar 2022 09:49:52 +0100 Subject: [PATCH] Replace usage of wcj by C API --- src/common/IOModesController.cpp | 10 +++------- src/core/CutterCommon.h | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/common/IOModesController.cpp b/src/common/IOModesController.cpp index 4fa29502..88378c10 100644 --- a/src/common/IOModesController.cpp +++ b/src/common/IOModesController.cpp @@ -77,16 +77,12 @@ bool IOModesController::prepareForWriting() bool IOModesController::allChangesComitted() { - // Get a list of available write changes - CutterJson changes = Core()->cmdj("wcj"); - - // Check if there is a change which isn't written to the file - for (CutterJson changeObject : changes) { - if (!changeObject["written"].toBool()) { + RzCoreLocked core(Core()); + for (auto c : CutterPVector(&core->io->cache)) { + if (!c->written) { return false; } } - return true; } diff --git a/src/core/CutterCommon.h b/src/core/CutterCommon.h index 3cbc1941..6d6f7e7a 100644 --- a/src/core/CutterCommon.h +++ b/src/core/CutterCommon.h @@ -25,6 +25,32 @@ (char *)it != (char *)(vec)->a + ((vec)->len * (vec)->elem_size); \ it = (type *)((char *)it + (vec)->elem_size)) +template class CutterPVector +{ +private: + const RzPVector * const vec; + +public: + class iterator : public std::iterator + { + private: + T **p; + + public: + iterator(T **p) : p(p) {} + iterator(const iterator &o) : p(o.p) {} + iterator &operator++() { p++; return *this; } + iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } + bool operator==(const iterator &rhs) const {return p == rhs.p;} + bool operator!=(const iterator &rhs) const {return p != rhs.p;} + T *operator*() { return *p; } + }; + + CutterPVector(const RzPVector *vec) : vec(vec) {} + iterator begin() const { return iterator(reinterpret_cast(vec->v.a)); } + iterator end() const { return iterator(reinterpret_cast(vec->v.a) + vec->v.len); } +}; + // Global information for Cutter #define APPNAME "Cutter"