Skip to content

Commit 3733030

Browse files
committed
Made a Callback alias for std::function that can be used until a custom implementation is completed.
1 parent c5feb78 commit 3733030

File tree

16 files changed

+78
-42
lines changed

16 files changed

+78
-42
lines changed

Source/DFPSR/api/bufferAPI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <cstdint>
2828
#include <memory>
29-
#include <functional>
3029
#include "../base/SafePointer.h"
3130
#include "../settings.h"
3231
#include "../base/Handle.h"

Source/DFPSR/api/configAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#define DFPSR_API_CONFIG
2626

2727
#include "stringAPI.h"
28-
#include <functional>
28+
#include "../base/Callback.h"
2929

3030
namespace dsr {
3131
// A type of function sending (block, key, value) to the caller.
3232
// One can have hard-coded options, lookup-tables, dictionaries, et cetera for looking up the given key names.
33-
using ConfigIniCallback = std::function<void(const ReadableString& block, const ReadableString& key, const ReadableString& value)>;
33+
using ConfigIniCallback = Callback<void(const ReadableString& block, const ReadableString& key, const ReadableString& value)>;
3434
/*
3535
Parsing the given content of a *.ini configuration file.
3636
Sending callbacks to receiverLambda for each key being assigned a value.

Source/DFPSR/api/fileAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ EntryType file_getEntryType(const ReadableString &path) {
586586
return result;
587587
}
588588

589-
bool file_getFolderContent(const ReadableString& folderPath, std::function<void(const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType)> action) {
589+
bool file_getFolderContent(const ReadableString& folderPath, Callback<void(const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType)> action) {
590590
String optimizedPath = file_optimizePath(folderPath, LOCAL_PATH_SYNTAX);
591591
#ifdef USE_MICROSOFT_WINDOWS
592592
String pattern = file_combinePaths(optimizedPath, U"*.*", LOCAL_PATH_SYNTAX);
@@ -639,7 +639,7 @@ bool file_getFolderContent(const ReadableString& folderPath, std::function<void(
639639
return true;
640640
}
641641

642-
void file_getPathEntries(const ReadableString& path, std::function<void(ReadableString, int64_t, int64_t)> action) {
642+
void file_getPathEntries(const ReadableString& path, Callback<void(ReadableString, int64_t, int64_t)> action) {
643643
int64_t sectionStart = 0;
644644
int64_t length = string_length(path);
645645
for (int64_t i = 0; i < string_length(path); i++) {

Source/DFPSR/api/fileAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace dsr {
9898
// The first entry must be something selectable to be included. Otherwise it is ignored.
9999
// C: would be returned as an entry, because other drives can be selected.
100100
// The implicit Windows drive \ and Posix system root / will not be returned, because they are implicit and can't be replaced in the path.
101-
void file_getPathEntries(const ReadableString& path, std::function<void(ReadableString, int64_t, int64_t)> action);
101+
void file_getPathEntries(const ReadableString& path, Callback<void(ReadableString, int64_t, int64_t)> action);
102102

103103
// Path-syntax: Depends on pathSyntax argument.
104104
// Turns / and \ into the path convention specified by pathSyntax, which is the local system's by default.
@@ -258,7 +258,7 @@ namespace dsr {
258258
// entryName equals file_getPathlessName(entryPath).
259259
// entryType equals file_getEntryType(entryPath).
260260
// Post-condition: Returns true iff the folder could be found.
261-
bool file_getFolderContent(const ReadableString& folderPath, std::function<void(const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType)> action);
261+
bool file_getFolderContent(const ReadableString& folderPath, Callback<void(const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType)> action);
262262

263263
// Path-syntax: According to the local computer.
264264
// Access permissions: Default settings according to the local operating system, either inherited from the parent folder or no specific restrictions.

Source/DFPSR/api/filterAPI.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define DFPSR_API_FILTER
2727

2828
#include "../implementation/image/Image.h"
29-
#include <functional>
29+
#include "../base/Callback.h"
3030

3131
namespace dsr {
3232

@@ -51,9 +51,9 @@ namespace dsr {
5151
// Create images from Lambda expressions when speed is not critical.
5252
// Capture images within [] and sample pixels from them using image_readPixel_border, image_readPixel_clamp and image_readPixel_tile.
5353
// Lambda expressions for generating integer images.
54-
using ImageGenRgbaU8 = std::function<ColorRgbaI32(int32_t x, int32_t y)>;
55-
using ImageGenI32 = std::function<int32_t(int32_t x, int32_t y)>; // Used for U8 and U16 images using different saturations.
56-
using ImageGenF32 = std::function<float(int32_t x, int32_t y)>;
54+
using ImageGenRgbaU8 = Callback<ColorRgbaI32(int32_t x, int32_t y)>;
55+
using ImageGenI32 = Callback<int32_t(int32_t x, int32_t y)>; // Used for U8 and U16 images using different saturations.
56+
using ImageGenF32 = Callback<float(int32_t x, int32_t y)>;
5757
// In-place image generation to an existing image.
5858
// The pixel at the upper left corner gets (startX, startY) as x and y arguments to the function.
5959
void filter_mapRgbaU8(const ImageRgbaU8 &target, const ImageGenRgbaU8& lambda, int32_t startX = 0, int32_t startY = 0);

Source/DFPSR/api/guiAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Component dsr::component_getChild(const Component& parent, int32_t childIndex) {
146146
}
147147
}
148148

149-
static void findAllComponentsByName(const Component& component, const ReadableString& name, std::function<void(Component, int32_t)> callback) {
149+
static void findAllComponentsByName(const Component& component, const ReadableString& name, Callback<void(Component, int32_t)> callback) {
150150
if (component_exists(component)) {
151151
// Check if the current component matches
152152
if (string_match(component->getName(), name)) {
@@ -159,7 +159,7 @@ static void findAllComponentsByName(const Component& component, const ReadableSt
159159
}
160160
}
161161
}
162-
void dsr::window_findAllComponentsByName(const Window& window, const ReadableString& name, std::function<void(Component, int32_t)> callback) {
162+
void dsr::window_findAllComponentsByName(const Window& window, const ReadableString& name, Callback<void(Component, int32_t)> callback) {
163163
MUST_EXIST(window, window_findAllComponentsByName);
164164
findAllComponentsByName(window->getRootComponent(), name, callback);
165165
}

Source/DFPSR/api/guiAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace dsr {
127127
// To allow detaching components while iterating over the list of children, order is reversed for child components.
128128
// Raises an exception if window doesn't exist.
129129
// Component names are case sensitive to reduce the risk of accidental naming conflicts among many components.
130-
void window_findAllComponentsByName(const Window& window, const ReadableString& name, std::function<void(Component component, int32_t index)> callback);
130+
void window_findAllComponentsByName(const Window& window, const ReadableString& name, Callback<void(Component component, int32_t index)> callback);
131131

132132
// The three main events to run in a loop at the end of the main function
133133
// If the window's event queue contained any resize of the window, the canvas and the depth buffer will be replaced during this call.

Source/DFPSR/api/mediaMachineAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ String machine_getOutputName(const MediaMachine& machine, int32_t methodIndex, i
11971197
return method->locals[method->inputCount + outputIndex].name;
11981198
}
11991199

1200-
MediaResult MediaMethod::callUsingKeywords(std::function<void(MediaMachine &machine, int32_t methodIndex, int32_t inputIndex, const ReadableString &argumentName)> setInputAction) {
1200+
MediaResult MediaMethod::callUsingKeywords(Callback<void(MediaMachine &machine, int32_t methodIndex, int32_t inputIndex, const ReadableString &argumentName)> setInputAction) {
12011201
if (this->methodIndex < 0 || this->methodIndex >= this->machine->methods.length()) {
12021202
throwError(U"Method index ", this->methodIndex, U" is out of bound 0..", this->machine->methods.length() - 1, U"\n");
12031203
}

Source/DFPSR/api/mediaMachineAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class MediaMethod {
239239
// The function setInputAction should simply make a call to machine_setInputByIndex with the provided machine, methodIndex, inputIndex and the value corresponding to argumentName in setInputAction.
240240
// If you don't recognize argumentName, then throw an exception because default input arguments are currently not implemented.
241241
// Useful when the called function can be extended or reduced with only the arguments needed.
242-
MediaResult callUsingKeywords(std::function<void(MediaMachine &machine, int32_t methodIndex, int32_t inputIndex, const ReadableString &argumentName)> setInputAction);
242+
MediaResult callUsingKeywords(Callback<void(MediaMachine &machine, int32_t methodIndex, int32_t inputIndex, const ReadableString &argumentName)> setInputAction);
243243
};
244244

245245
// Post-condition: Returns a MediaMethod structure, which can be stored as a reference counting function pointer that keeps the virtual machine alive.

Source/DFPSR/api/soundAPI.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace dsr {
99

1010
// See the Source/soundManagers folder for implementations of sound_streamToSpeakers for different operating systems.
1111

12-
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, std::function<bool(SafePointer<float> fixedTarget)> soundOutput) {
12+
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, Callback<bool(SafePointer<float> fixedTarget)> soundOutput) {
1313
int32_t bufferSamplesPerChannel = 0;
1414
int32_t blockBytes = channels * sizeof(float);
1515
Buffer fixedBuffer;
@@ -251,7 +251,7 @@ static String readChar4(SafePointer<const uint8_t> nameStart) {
251251
return name;
252252
}
253253

254-
static void getRiffChunks(const Chunk &parentChunk, std::function<void(const ReadableString &name, const Chunk &chunk)> returnChunk) {
254+
static void getRiffChunks(const Chunk &parentChunk, Callback<void(const ReadableString &name, const Chunk &chunk)> returnChunk) {
255255
SafePointer<const uint8_t> chunkStart = parentChunk.chunkStart;
256256
SafePointer<const uint8_t> chunkEnd = chunkStart + parentChunk.chunkSize;
257257
while (chunkStart.getUnchecked() + 8 <= chunkEnd.getUnchecked()) {
@@ -267,7 +267,7 @@ static void getRiffChunks(const Chunk &parentChunk, std::function<void(const Rea
267267
}
268268
}
269269

270-
static void getRiffChunks(const Buffer &fileBuffer, std::function<void(const ReadableString &name, const Chunk &chunk)> returnChunk) {
270+
static void getRiffChunks(const Buffer &fileBuffer, Callback<void(const ReadableString &name, const Chunk &chunk)> returnChunk) {
271271
Chunk rootChunk = Chunk(U"RIFF", fileBuffer);
272272
getRiffChunks(rootChunk, [&returnChunk](const ReadableString &name, const Chunk &chunk) {
273273
if (string_match(name, U"RIFF")) {
@@ -440,7 +440,7 @@ bool sound_save_RiffWave(const ReadableString& filename, const SoundBuffer &soun
440440
}
441441
}
442442

443-
SoundBuffer sound_generate_function(uint32_t samplesPerChannel, uint32_t channelCount, uint32_t sampleRate, std::function<float(double time, uint32_t channelIndex)> generator) {
443+
SoundBuffer sound_generate_function(uint32_t samplesPerChannel, uint32_t channelCount, uint32_t sampleRate, Callback<float(double time, uint32_t channelIndex)> generator) {
444444
SoundBuffer result = sound_create(samplesPerChannel, channelCount, sampleRate);
445445
SafePointer<float> target = sound_getSafePointer(result);
446446
double time = 0.0;

0 commit comments

Comments
 (0)