From 159b9e6f47a637592516590cc5d690381da00a68 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Tue, 23 Aug 2022 08:55:46 +0800 Subject: [PATCH] Goodbye genLinkedList - welcome std::stack it decrease ESP32 binary size of few bytes (-256) - when it increase esp8266 binary of few bytes (+56) , but make code more standard so it is fine IMHO --- esp3d/src/core/genLinkedList.h | 223 ------------------ esp3d/src/include/version.h | 2 +- esp3d/src/modules/filesystem/esp_globalFS.cpp | 1 - esp3d/src/modules/filesystem/esp_sd.cpp | 1 - .../filesystem/flash/fat_esp32_filesystem.cpp | 14 +- .../flash/littlefs_esp32_filesystem.cpp | 14 +- .../flash/littlefs_esp8266_filesystem .cpp | 12 +- .../flash/spiffs_esp32_filesystem.cpp | 2 +- .../flash/spiffs_esp8266_filesystem.cpp | 1 - .../modules/filesystem/sd/sd_native_esp32.cpp | 14 +- .../filesystem/sd/sd_native_esp8266.cpp | 14 +- .../modules/filesystem/sd/sd_sdfat2_esp32.cpp | 14 +- .../filesystem/sd/sd_sdfat2_esp8266.cpp | 14 +- .../modules/filesystem/sd/sd_sdfat_esp32.cpp | 14 +- .../filesystem/sd/sd_sdfat_esp8266.cpp | 14 +- .../src/modules/filesystem/sd/sdio_esp32.cpp | 14 +- 16 files changed, 71 insertions(+), 297 deletions(-) delete mode 100644 esp3d/src/core/genLinkedList.h diff --git a/esp3d/src/core/genLinkedList.h b/esp3d/src/core/genLinkedList.h deleted file mode 100644 index 6a1ec760..00000000 --- a/esp3d/src/core/genLinkedList.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - genlinkedlist.h - ESP3D simple generic linked list class - * inspired by great https://github.com/ivanseidel/LinkedList - - Copyright (c) 2018 Luc Lebosse. All rights reserved. - - This code 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 2.1 of the License, or (at your option) any later version. - - This code 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 code; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef _GENLINKEDLIST_H -#define _GENLINKEDLIST_H - -template struct GenNode { - T data; - GenNode *next; - GenNode *prev; -}; - -template class GenLinkedList -{ -public: - GenLinkedList(); - ~GenLinkedList(); - //Clear list - void clear(); - //number of GenNodes - size_t count(); - //add data at the end of list - bool push(T data); - //get data at end of list and remove from list - T pop(); - //add data at the begining of list - bool shift(T data); - //get data from begining of list and remove from list - T unshift(); - //get data from index position - T get(size_t index); - //get head data - T getFirst(); - //get tail data - T getLast(); - -private: - //number of GenNode - size_t _nb; - //First GenNode - GenNode *_head; - //Last GenNode - GenNode *_tail; -}; - -//Constructor -template GenLinkedList::GenLinkedList() -{ - _nb = 0; - _head = nullptr; - _tail = nullptr; -} - -//Destructor -template GenLinkedList::~GenLinkedList() -{ - clear(); -} - -//clear list of all GenNodes -templatevoid GenLinkedList::clear() -{ - GenNode *current; - //delete from first to last - while (_head != nullptr) { - current = _head; - _head = _head->next; - current->data = T(); - delete current; - } - _tail = _head; - _nb = 0; -} - -//Number of GenNodes -templatesize_t GenLinkedList::count() -{ - return _nb; -} - -//add to end of list -template bool GenLinkedList::push (T data) -{ - GenNode *ptr = new GenNode(); - if (!ptr) { - return false; - } - ptr->data = data; - ptr->next = nullptr; - ptr->prev = nullptr; - _nb++; - //Check if already have element in list - if (_head) { - _tail->next = ptr; - ptr->prev = _tail; - _tail = ptr; - } else { // no element _head = _tail - _head = ptr; - _tail = _head; - } - return true; -} -//take out from end of list -templateT GenLinkedList::pop() -{ - if (_head == nullptr) { - return T(); - } - T data = _tail->data; - - _nb--; - if (_head == _tail) { - _head->data = T(); - delete (_head); - _head = nullptr; - _tail = _head; - } else { - GenNode *ptr = _tail; - _tail = _tail->prev; - _tail->next = nullptr; - ptr->data = T(); - delete (ptr); - } - return data; -} - -//add to head of list -template bool GenLinkedList::shift (T data) -{ - - GenNode *ptr = new GenNode(); - if (!ptr) { - return false; - } - ptr->data = data; - ptr->next = nullptr; - ptr->prev = nullptr; - _nb++; - //Check if already have element in list - if (_head) { - ptr->next = _head; - _head->prev = ptr; - _head = ptr; - } else { // no element _head = _tail - _head = ptr; - _tail = _head; - } - return true; -} - -//take out from Head -templateT GenLinkedList::unshift() -{ - if (_head == nullptr) { - return T(); - } - T data = _head->data; - _nb--; - if (_head == _tail) { - _head->data = T(); - delete (_head); - _head = nullptr; - _tail = _head; - } else { - GenNode *ptr = _head; - _head = _head->next; - _head->prev = nullptr; - ptr->data = T(); - delete (ptr); - } - return data; -} - -//get data from position (do not remove from list) -templateT GenLinkedList::get(size_t index) -{ - if ((_head == nullptr) || (index > _nb)) { - return T(); - } - GenNode *ptr = _head; - for (size_t pos = 0; pos < index; pos++) { - ptr = ptr->next; - } - return ptr->data; -} - - -//get head data (do not remove from list) -templateT GenLinkedList::getFirst() -{ - if (_head == nullptr) { - return T(); - } - return _head->data; -} - -//get tail data (do not remove from list) -templateT GenLinkedList::getLast() -{ - if (_head == nullptr) { - return T(); - } - return _tail->data; -} - -#endif //_GENLINKEDLIST_H diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 8f97206d..a7323dbe 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a207" +#define FW_VERSION "3.0.0.a208" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/esp_globalFS.cpp b/esp3d/src/modules/filesystem/esp_globalFS.cpp index 407f9f18..1cdeea1a 100644 --- a/esp3d/src/modules/filesystem/esp_globalFS.cpp +++ b/esp3d/src/modules/filesystem/esp_globalFS.cpp @@ -21,7 +21,6 @@ #include "../../include/esp3d_config.h" #if defined(GLOBAL_FILESYSTEM_FEATURE) #include "esp_globalFS.h" -//#include "../../core/genLinkedList.h" //to verify FS is accessible bool ESP_GBFS::isavailable(uint8_t FS) diff --git a/esp3d/src/modules/filesystem/esp_sd.cpp b/esp3d/src/modules/filesystem/esp_sd.cpp index e1108eb8..78ba8131 100644 --- a/esp3d/src/modules/filesystem/esp_sd.cpp +++ b/esp3d/src/modules/filesystem/esp_sd.cpp @@ -21,7 +21,6 @@ #include "../../include/esp3d_config.h" #ifdef SD_DEVICE #include "esp_sd.h" -#include "../../core/genLinkedList.h" #include #define ESP_MAX_SD_OPENHANDLE 4 diff --git a/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp index 03ecbe91..6816cd4d 100644 --- a/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp @@ -21,7 +21,7 @@ fat_esp32_filesystem.cpp - ESP3D fat filesystem configuration class #include "../../../include/esp3d_config.h" #if (FILESYSTEM_FEATURE == ESP_FAT_FILESYSTEM) #include "../esp_filesystem.h" -#include "../../../core/genLinkedList.h" +#include #include #include "FFat.h" @@ -156,10 +156,10 @@ bool ESP_FileSystem::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; pathlist.push(p); - while (pathlist.count() > 0) { - File dir = FFat.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = FFat.open(pathlist.top().c_str()); File f = dir.openNextFile(); bool candelete = true; while (f) { @@ -176,15 +176,15 @@ bool ESP_FileSystem::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = FFat.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = FFat.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/flash/littlefs_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/littlefs_esp32_filesystem.cpp index d0a81dae..c81ac580 100644 --- a/esp3d/src/modules/filesystem/flash/littlefs_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/littlefs_esp32_filesystem.cpp @@ -21,7 +21,7 @@ littlefs_esp32_filesystem.cpp - ESP3D littlefs filesystem configuration class #include "../../../include/esp3d_config.h" #if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32) #include "../esp_filesystem.h" -#include "../../../core/genLinkedList.h" +#include #include #include @@ -163,10 +163,10 @@ bool ESP_FileSystem::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; pathlist.push(p); - while (pathlist.count() > 0) { - File dir = LittleFS.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = LittleFS.open(pathlist.top().c_str()); File f = dir.openNextFile(); bool candelete = true; while (f) { @@ -183,15 +183,15 @@ bool ESP_FileSystem::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = LittleFS.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = LittleFS.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp b/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp index f5e6ea21..02c0319c 100644 --- a/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp +++ b/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp @@ -20,7 +20,7 @@ littlefs_esp8266_filesystem.cpp - ESP3D littlefs filesystem configuration class #include "../../../include/esp3d_config.h" #if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP8266) #include "../esp_filesystem.h" -#include "../../../core/genLinkedList.h" +#include #include #include @@ -157,7 +157,7 @@ bool ESP_FileSystem::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String spath = path; spath.trim(); if (spath[spath.length()-1] != '/') { @@ -167,15 +167,15 @@ bool ESP_FileSystem::rmdir(const char *path) spath ="/" + spath; } pathlist.push(spath); - while (pathlist.count() > 0) { - spath=pathlist.getLast(); + while (pathlist.size() > 0) { + spath=pathlist.top(); bool candelete = true; if (LittleFS.exists(spath.c_str())) { - Dir dir = LittleFS.openDir(pathlist.getLast().c_str()); + Dir dir = LittleFS.openDir(pathlist.top().c_str()); while (dir.next()) { if (dir.isDirectory()) { candelete = false; - String newdir = pathlist.getLast() + dir.fileName() + "/"; + String newdir = pathlist.top() + dir.fileName() + "/"; pathlist.push(newdir); } else { log_esp3d("remove %s", dir.fileName().c_str()); diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp index 71fac21e..d459f183 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp @@ -21,7 +21,7 @@ #include "../../../include/esp3d_config.h" #if (FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32) #include "../esp_filesystem.h" -#include "../../../core/genLinkedList.h" +#include #include #include extern File tFile_handle[ESP_MAX_OPENHANDLE]; diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp index c7f93fc6..32594aa8 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp @@ -20,7 +20,6 @@ #include "../../../include/esp3d_config.h" #if (FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM) && defined (ARDUINO_ARCH_ESP8266) #include "../esp_filesystem.h" -#include "../../../core/genLinkedList.h" #include Dir tDir_handle[ESP_MAX_OPENHANDLE]; extern File tFile_handle[ESP_MAX_OPENHANDLE]; diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index 9b81e223..101cb2c0 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -21,7 +21,7 @@ sd_native_esp32.cpp - ESP3D sd support class #if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SD_NATIVE) #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #include "FS.h" #include "SD.h" @@ -213,14 +213,14 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; if (p.endsWith("/")) { p.remove( p.length() - 1,1); } pathlist.push(p); - while (pathlist.count() > 0) { - File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = SD.open(pathlist.top().c_str()); File f = dir.openNextFile(); bool candelete = true; while (f) { @@ -237,15 +237,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp index 0c1cb9ab..68ee8bc2 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp @@ -22,7 +22,7 @@ sd_native_esp8266.cpp - ESP3D sd support class #if (SD_DEVICE == ESP_SD_NATIVE) #define FS_NO_GLOBALS #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #include #include @@ -256,11 +256,11 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; pathlist.push(p); - while (pathlist.count() > 0) { - File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = SD.open(pathlist.top().c_str()); dir.rewindDirectory(); File f = dir.openNextFile(); bool candelete = true; @@ -279,15 +279,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp index 444419bc..24f2c5e1 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp @@ -21,7 +21,7 @@ sd_sdfat2_esp32.cpp - ESP3D sd support class #if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SDFAT2) #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #include #include @@ -366,11 +366,11 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; pathlist.push(p); - while (pathlist.count() > 0) { - File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = SD.open(pathlist.top().c_str()); dir.rewindDirectory(); File f = dir.openNextFile(); bool candelete = true; @@ -394,15 +394,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp index b2acafb6..9a4a4c49 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp @@ -23,7 +23,7 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class #if (SD_DEVICE == ESP_SDFAT2) #define FS_NO_GLOBALS #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #define NO_GLOBAL_SD #include @@ -351,11 +351,11 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; pathlist.push(p); - while (pathlist.count() > 0) { - sdfat::File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + sdfat::File dir = SD.open(pathlist.top().c_str()); dir.rewindDirectory(); sdfat::File f = dir.openNextFile(); bool candelete = true; @@ -379,15 +379,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp index cb125258..ea95db69 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp @@ -21,7 +21,7 @@ sd_sdfat_esp32.cpp - ESP3D sd support class #if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SDFAT) #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #include extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; @@ -677,11 +677,11 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; pathlist.push(p); - while (pathlist.count() > 0) { - File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = SD.open(pathlist.top().c_str()); dir.rewindDirectory(); File f = dir.openNextFile(); bool candelete = true; @@ -705,15 +705,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp8266.cpp index e1b0d907..ddc82801 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp8266.cpp @@ -22,7 +22,7 @@ sd_sdfat_esp8266.cpp - ESP3D sd support class #if (SD_DEVICE == ESP_SDFAT) #define FS_NO_GLOBALS #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #define NO_GLOBAL_SD #include @@ -684,11 +684,11 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; pathlist.push(p); - while (pathlist.count() > 0) { - sdfat::File dir = SD.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + sdfat::File dir = SD.open(pathlist.top().c_str()); dir.rewindDirectory(); sdfat::File f = dir.openNextFile(); bool candelete = true; @@ -712,15 +712,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; } diff --git a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp index 791436c6..442bfb8a 100644 --- a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp @@ -21,7 +21,7 @@ sdio_esp32.cpp - ESP3D sd support class #if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SDIO) #include "../esp_sd.h" -#include "../../../core/genLinkedList.h" +#include #include "../../../core/settings_esp3d.h" #include "FS.h" #include "SD_MMC.h" @@ -237,14 +237,14 @@ bool ESP_SD::rmdir(const char *path) return false; } bool res = true; - GenLinkedList pathlist; + std::stack pathlist; String p = path; if (p.endsWith("/")) { p.remove( p.length() - 1,1); } pathlist.push(p); - while (pathlist.count() > 0) { - File dir = SD_MMC.open(pathlist.getLast().c_str()); + while (pathlist.size() > 0) { + File dir = SD_MMC.open(pathlist.top().c_str()); File f = dir.openNextFile(); bool candelete = true; while (f) { @@ -261,15 +261,15 @@ bool ESP_SD::rmdir(const char *path) } } if (candelete) { - if (pathlist.getLast() !="/") { - res = SD_MMC.rmdir(pathlist.getLast().c_str()); + if (pathlist.top() !="/") { + res = SD_MMC.rmdir(pathlist.top().c_str()); } pathlist.pop(); } dir.close(); } p = String(); - log_esp3d("count %d", pathlist.count()); + log_esp3d("count %d", pathlist.size()); return res; }