diff options
-rw-r--r-- | src/CAN/CanInterface.cpp | 2 | ||||
-rw-r--r-- | src/CAN/CanInterface.h | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes.cpp | 2 | ||||
-rw-r--r-- | src/Heating/Heat.cpp | 4 | ||||
-rw-r--r-- | src/Platform.cpp | 12 | ||||
-rw-r--r-- | src/Platform.h | 13 | ||||
-rw-r--r-- | src/RepRap.cpp | 6 | ||||
-rw-r--r-- | src/RepRap.h | 9 | ||||
-rw-r--r-- | src/RepRapFirmware.cpp | 2 | ||||
-rw-r--r-- | src/Tools/Tool.cpp | 4 | ||||
-rw-r--r-- | src/Tools/Tool.h | 9 |
11 files changed, 30 insertions, 35 deletions
diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp index 69a98b98..329374da 100644 --- a/src/CAN/CanInterface.cpp +++ b/src/CAN/CanInterface.cpp @@ -586,7 +586,7 @@ GCodeResult CanInterface::SendRequestAndGetStandardReply(CanMessageBuffer *buf, } // Send a request to an expansion board and append the response to 'reply'. The response may either be a standard reply or 'replyType'. -GCodeResult CanInterface::SendRequestAndGetCustomReply(CanMessageBuffer *buf, CanRequestId rid, const StringRef& reply, uint8_t *extra, CanMessageType replyType, std::function<void(const CanMessageBuffer*) /*noexcept*/> callback) noexcept +GCodeResult CanInterface::SendRequestAndGetCustomReply(CanMessageBuffer *buf, CanRequestId rid, const StringRef& reply, uint8_t *extra, CanMessageType replyType, stdext::inplace_function<void(const CanMessageBuffer*) /*noexcept*/> callback) noexcept { if (can0dev == nullptr) { diff --git a/src/CAN/CanInterface.h b/src/CAN/CanInterface.h index 4789e84d..68dd1993 100644 --- a/src/CAN/CanInterface.h +++ b/src/CAN/CanInterface.h @@ -76,7 +76,7 @@ namespace CanInterface CanRequestId AllocateRequestId(CanAddress destination) noexcept; GCodeResult SendRequestAndGetStandardReply(CanMessageBuffer *buf, CanRequestId rid, const StringRef& reply, uint8_t *extra = nullptr) noexcept; - GCodeResult SendRequestAndGetCustomReply(CanMessageBuffer *buf, CanRequestId rid, const StringRef& reply, uint8_t *extra, CanMessageType replyType, std::function<void(const CanMessageBuffer*) /*noexcept*/> callback) noexcept; + GCodeResult SendRequestAndGetCustomReply(CanMessageBuffer *buf, CanRequestId rid, const StringRef& reply, uint8_t *extra, CanMessageType replyType, stdext::inplace_function<void(const CanMessageBuffer*) /*noexcept*/> callback) noexcept; void SendResponseNoFree(CanMessageBuffer *buf) noexcept; void SendBroadcastNoFree(CanMessageBuffer *buf) noexcept; void SendMessageNoReplyNoFree(CanMessageBuffer *buf) noexcept; diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index 291938b4..209fee40 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -4666,7 +4666,7 @@ void GCodes::UnlockAll(const GCodeBuffer& gb) noexcept // Append a list of axes to a string void GCodes::AppendAxes(const StringRef& reply, AxesBitmap axes) const noexcept { - axes.Iterate([reply, this](unsigned int axis, unsigned int) noexcept { reply.cat(this->axisLetters[axis]); }); + axes.Iterate([&reply, this](unsigned int axis, unsigned int) noexcept { reply.cat(this->axisLetters[axis]); }); } // Get the name of the current machine mode diff --git a/src/Heating/Heat.cpp b/src/Heating/Heat.cpp index 37662c44..19e9acc2 100644 --- a/src/Heating/Heat.cpp +++ b/src/Heating/Heat.cpp @@ -1188,7 +1188,7 @@ bool Heat::WriteBedAndChamberTempSettings(FileStore *f) const noexcept void Heat::ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg) noexcept { Bitmap<uint64_t> sensorsReported(msg.whichSensors); - sensorsReported.Iterate([this, src, msg](unsigned int sensor, unsigned int index) + sensorsReported.Iterate([this, src, &msg](unsigned int sensor, unsigned int index) { if (index < ARRAY_SIZE(msg.temperatureReports)) { @@ -1212,7 +1212,7 @@ void Heat::ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemp void Heat::ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg) noexcept { Bitmap<uint64_t> heatersReported(msg.whichHeaters); - heatersReported.Iterate([this, src, msg](unsigned int heaterNum, unsigned int index) + heatersReported.Iterate([this, src, &msg](unsigned int heaterNum, unsigned int index) { if (index < ARRAY_SIZE(msg.reports)) { diff --git a/src/Platform.cpp b/src/Platform.cpp index 1aefcf06..8410d548 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -2505,7 +2505,7 @@ bool Platform::WriteAxisLimits(FileStore *f, AxesBitmap axesProbed, const float #if SUPPORT_CAN_EXPANSION // Function to identify and iterate through all drivers attached to an axis or extruder -void Platform::IterateDrivers(size_t axisOrExtruder, std::function<void(uint8_t)> localFunc, std::function<void(DriverId)> remoteFunc) noexcept +void Platform::IterateDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t)> localFunc, stdext::inplace_function<void(DriverId)> remoteFunc) noexcept { if (axisOrExtruder < reprap.GetGCodes().GetTotalAxes()) { @@ -2539,7 +2539,7 @@ void Platform::IterateDrivers(size_t axisOrExtruder, std::function<void(uint8_t) #else // Function to identify and iterate through all drivers attached to an axis or extruder -void Platform::IterateDrivers(size_t axisOrExtruder, std::function<void(uint8_t)> localFunc) noexcept +void Platform::IterateDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t)> localFunc) noexcept { if (axisOrExtruder < reprap.GetGCodes().GetTotalAxes()) { @@ -4726,7 +4726,7 @@ GCodeResult Platform::EutSetMotorCurrents(const CanMessageMultipleDrivesRequest< } GCodeResult rslt = GCodeResult::ok; - drivers.Iterate([this, msg, reply, &rslt](unsigned int driver, unsigned int count) -> void + drivers.Iterate([this, &msg, &reply, &rslt](unsigned int driver, unsigned int count) -> void { if (driver >= NumDirectDrivers) { @@ -4756,7 +4756,7 @@ GCodeResult Platform::EutSetStepsPerMmAndMicrostepping(const CanMessageMultipleD } GCodeResult rslt = GCodeResult::ok; - drivers.Iterate([this, msg, reply, &rslt](unsigned int driver, unsigned int count) -> void + drivers.Iterate([this, &msg, &reply, &rslt](unsigned int driver, unsigned int count) -> void { if (driver >= NumDirectDrivers) { @@ -4790,7 +4790,7 @@ GCodeResult Platform::EutHandleSetDriverStates(const CanMessageMultipleDrivesReq { //TODO check message is long enough for the number of drivers specified const auto drivers = Bitmap<uint16_t>::MakeFromRaw(msg.driversToUpdate); - drivers.Iterate([this, msg](unsigned int driver, unsigned int count) -> void + drivers.Iterate([this, &msg](unsigned int driver, unsigned int count) -> void { switch (msg.values[count].mode) { @@ -4829,7 +4829,7 @@ GCodeResult Platform::EutSetRemotePressureAdvance(const CanMessageMultipleDrives } GCodeResult rslt = GCodeResult::ok; - drivers.Iterate([this, msg, reply, &rslt](unsigned int driver, unsigned int count) -> void + drivers.Iterate([this, &msg, &reply, &rslt](unsigned int driver, unsigned int count) -> void { if (driver >= NumDirectDrivers) { diff --git a/src/Platform.h b/src/Platform.h index 48db8bbb..89c41f45 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -41,6 +41,7 @@ Licence: GPL #include <Comms/AuxDevice.h> #include <Comms/PanelDueUpdater.h> #include <General/IPAddress.h> +#include <General/inplace_function.h> #if defined(DUET_NG) # include "DueXn.h" @@ -58,8 +59,6 @@ Licence: GPL # include <RemoteInputHandle.h> #endif -#include <functional> - constexpr bool FORWARDS = true; constexpr bool BACKWARDS = !FORWARDS; @@ -661,12 +660,12 @@ private: float GetCpuTemperature() const noexcept; #if SUPPORT_CAN_EXPANSION - void IterateDrivers(size_t axisOrExtruder, std::function<void(uint8_t) /*noexcept*/ > localFunc, std::function<void(DriverId) /*noexcept*/ > remoteFunc) noexcept; - void IterateLocalDrivers(size_t axisOrExtruder, std::function<void(uint8_t) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, func, [](DriverId) noexcept {}); } - void IterateRemoteDrivers(size_t axisOrExtruder, std::function<void(DriverId) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, [](uint8_t) noexcept {}, func); } + void IterateDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t) /*noexcept*/ > localFunc, stdext::inplace_function<void(DriverId) /*noexcept*/ > remoteFunc) noexcept; + void IterateLocalDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, func, [](DriverId) noexcept {}); } + void IterateRemoteDrivers(size_t axisOrExtruder, stdext::inplace_function<void(DriverId) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, [](uint8_t) noexcept {}, func); } #else - void IterateDrivers(size_t axisOrExtruder, std::function<void(uint8_t) /*noexcept*/ > localFunc) noexcept; - void IterateLocalDrivers(size_t axisOrExtruder, std::function<void(uint8_t) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, func); } + void IterateDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t) /*noexcept*/ > localFunc) noexcept; + void IterateLocalDrivers(size_t axisOrExtruder, stdext::inplace_function<void(uint8_t) /*noexcept*/ > func) noexcept { IterateDrivers(axisOrExtruder, func); } #endif #if SUPPORT_REMOTE_COMMANDS diff --git a/src/RepRap.cpp b/src/RepRap.cpp index 2b27f7e7..b234939e 100644 --- a/src/RepRap.cpp +++ b/src/RepRap.cpp @@ -2286,7 +2286,7 @@ GCodeResult RepRap::GetFileInfoResponse(const char *filename, OutputBuffer *&res // Helper functions to write JSON arrays // Append float array using 1 decimal place -void RepRap::AppendFloatArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<float(size_t)> func, unsigned int numDecimalDigits) noexcept +void RepRap::AppendFloatArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<float(size_t)> func, unsigned int numDecimalDigits) noexcept { if (name != nullptr) { @@ -2304,7 +2304,7 @@ void RepRap::AppendFloatArray(OutputBuffer *buf, const char *name, size_t numVal buf->cat(']'); } -void RepRap::AppendIntArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<int(size_t)> func) noexcept +void RepRap::AppendIntArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<int(size_t)> func) noexcept { if (name != nullptr) { @@ -2322,7 +2322,7 @@ void RepRap::AppendIntArray(OutputBuffer *buf, const char *name, size_t numValue buf->cat(']'); } -void RepRap::AppendStringArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<const char *(size_t)> func) noexcept +void RepRap::AppendStringArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<const char *(size_t)> func) noexcept { if (name != nullptr) { diff --git a/src/RepRap.h b/src/RepRap.h index 7d46c3c8..85541d49 100644 --- a/src/RepRap.h +++ b/src/RepRap.h @@ -26,13 +26,12 @@ Licence: GPL #include "MessageType.h" #include "RTOSIface/RTOSIface.h" #include "GCodes/GCodeResult.h" +#include <General/inplace_function.h> #if SUPPORT_CAN_EXPANSION # include <CAN/ExpansionManager.h> #endif -#include <functional> - enum class ResponseSource { HTTP, @@ -209,9 +208,9 @@ protected: private: static void EncodeString(StringRef& response, const char* src, size_t spaceToLeave, bool allowControlChars = false, char prefix = 0) noexcept; - static void AppendFloatArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<float(size_t)> func, unsigned int numDecimalDigits) noexcept; - static void AppendIntArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<int(size_t)> func) noexcept; - static void AppendStringArray(OutputBuffer *buf, const char *name, size_t numValues, std::function<const char *(size_t)> func) noexcept; + static void AppendFloatArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<float(size_t)> func, unsigned int numDecimalDigits) noexcept; + static void AppendIntArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<int(size_t)> func) noexcept; + static void AppendStringArray(OutputBuffer *buf, const char *name, size_t numValues, stdext::inplace_function<const char *(size_t)> func) noexcept; size_t GetStatusIndex() const noexcept; char GetStatusCharacter() const noexcept; diff --git a/src/RepRapFirmware.cpp b/src/RepRapFirmware.cpp index 1e3b756a..c97e6079 100644 --- a/src/RepRapFirmware.cpp +++ b/src/RepRapFirmware.cpp @@ -263,7 +263,7 @@ double HideNan(float val) noexcept // Append a list of driver numbers to a string, with a space before each one void ListDrivers(const StringRef& str, DriversBitmap drivers) noexcept { - drivers.Iterate([str](unsigned int d, unsigned int) noexcept { str.catf(" %u", d); }); + drivers.Iterate([&str](unsigned int d, unsigned int) noexcept { str.catf(" %u", d); }); } // End diff --git a/src/Tools/Tool.cpp b/src/Tools/Tool.cpp index 3c247b97..640e22ed 100644 --- a/src/Tools/Tool.cpp +++ b/src/Tools/Tool.cpp @@ -666,7 +666,7 @@ void Tool::SetSpindleRpm(uint32_t rpm) THROWS(GCodeException) } } -void Tool::IterateExtruders(std::function<void(unsigned int)> f) const noexcept +void Tool::IterateExtruders(stdext::inplace_function<void(unsigned int)> f) const noexcept { for (size_t i = 0; i < driveCount; ++i) { @@ -674,7 +674,7 @@ void Tool::IterateExtruders(std::function<void(unsigned int)> f) const noexcept } } -void Tool::IterateHeaters(std::function<void(int)> f) const noexcept +void Tool::IterateHeaters(stdext::inplace_function<void(int)> f) const noexcept { for (size_t i = 0; i < heaterCount; ++i) { diff --git a/src/Tools/Tool.h b/src/Tools/Tool.h index c46b39d6..4d2934c4 100644 --- a/src/Tools/Tool.h +++ b/src/Tools/Tool.h @@ -31,10 +31,7 @@ Licence: GPL #include <ObjectModel/ObjectModel.h> #include <General/FreelistManager.h> #include <General/NamedEnum.h> - -#undef array -#include <functional> -#define array _ecv_array +#include <General/inplace_function.h> constexpr size_t ToolNameLength = 32; // maximum allowed length for tool names @@ -112,8 +109,8 @@ public: bool HasTemperatureFault() const noexcept { return heaterFault; } - void IterateExtruders(std::function<void(unsigned int)> f) const noexcept; - void IterateHeaters(std::function<void(int)> f) const noexcept; + void IterateExtruders(stdext::inplace_function<void(unsigned int)> f) const noexcept; + void IterateHeaters(stdext::inplace_function<void(int)> f) const noexcept; bool UsesHeater(int8_t heater) const noexcept; void SetFansPwm(float f) const noexcept; |