Swap std::any for std::variant
This commit is contained in:
parent
7ee571dd2b
commit
9ddc32193f
26 changed files with 44 additions and 68 deletions
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Blur(string type, char *BufferData, size_t BufferLength,
|
char *Blur(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
bool sharp = MAP_GET(Arguments, "sharp", bool);
|
bool sharp = MAP_GET(Arguments, "sharp", bool);
|
||||||
VOption *options = VImage::option()->set("access", "sequential");
|
VOption *options = VImage::option()->set("access", "sequential");
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Blur(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Blur(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Caption(string type, char *BufferData, size_t BufferLength,
|
char *Caption(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
string caption = MAP_GET(Arguments, "caption", string);
|
string caption = MAP_GET(Arguments, "caption", string);
|
||||||
string font = MAP_GET(Arguments, "font", string);
|
string font = MAP_GET(Arguments, "font", string);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Caption(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Caption(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *CaptionTwo(string type, char *BufferData, size_t BufferLength,
|
char *CaptionTwo(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
bool top = MAP_GET(Arguments, "top", bool);
|
bool top = MAP_GET(Arguments, "top", bool);
|
||||||
string caption = MAP_GET(Arguments, "caption", string);
|
string caption = MAP_GET(Arguments, "caption", string);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* CaptionTwo(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* CaptionTwo(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -11,7 +11,7 @@ using namespace std;
|
||||||
using namespace Magick;
|
using namespace Magick;
|
||||||
|
|
||||||
char *Circle(string type, char *BufferData, size_t BufferLength,
|
char *Circle(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
Blob blob;
|
Blob blob;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Circle(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Circle(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -11,7 +11,7 @@ VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870,
|
||||||
0.1140, 0.2392, 0.4696, 0.0912);
|
0.1140, 0.2392, 0.4696, 0.0912);
|
||||||
|
|
||||||
char *Colors(string type, char *BufferData, size_t BufferLength,
|
char *Colors(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
string color = MAP_GET(Arguments, "color", string);
|
string color = MAP_GET(Arguments, "color", string);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Colors(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Colors(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -1,12 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include <variant>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#define MAP_HAS(ARRAY, KEY) (ARRAY.count(KEY) > 0)
|
#define MAP_HAS(ARRAY, KEY) (ARRAY.count(KEY) > 0)
|
||||||
#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? any_cast<TYPE>(ARRAY.at(KEY)) : NULL) // C++ has forced my hand
|
#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) : NULL) // C++ has forced my hand
|
||||||
#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? any_cast<TYPE>(ARRAY.at(KEY)) : FALLBACK)
|
#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) : FALLBACK)
|
||||||
|
|
||||||
|
#define ARG_TYPES std::variant<string, bool, int, float>
|
||||||
|
|
||||||
const std::unordered_map<std::string, std::string> fontPaths {
|
const std::unordered_map<std::string, std::string> fontPaths {
|
||||||
{"futura", "assets/fonts/caption.otf"},
|
{"futura", "assets/fonts/caption.otf"},
|
||||||
|
|
|
@ -7,7 +7,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Crop(string type, char *BufferData, size_t BufferLength,
|
char *Crop(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
VOption *options = VImage::option()->set("access", "sequential");
|
VOption *options = VImage::option()->set("access", "sequential");
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Crop(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Crop(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Deepfry(string type, char *BufferData, size_t BufferLength,
|
char *Deepfry(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
VOption *options = VImage::option()->set("access", "sequential");
|
VOption *options = VImage::option()->set("access", "sequential");
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Deepfry(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Deepfry(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -12,7 +12,7 @@ using namespace std;
|
||||||
using namespace Magick;
|
using namespace Magick;
|
||||||
|
|
||||||
char *Explode(string type, char *BufferData, size_t BufferLength,
|
char *Explode(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
int amount = MAP_GET(Arguments, "amount", int);
|
int amount = MAP_GET(Arguments, "amount", int);
|
||||||
int delay = MAP_GET_FALLBACK(Arguments, "delay", int, 0);
|
int delay = MAP_GET_FALLBACK(Arguments, "delay", int, 0);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Explode(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Explode(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Flag(string type, char *BufferData, size_t BufferLength,
|
char *Flag(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
string overlay = MAP_GET(Arguments, "overlay", string);
|
string overlay = MAP_GET(Arguments, "overlay", string);
|
||||||
string basePath = MAP_GET(Arguments, "basePath", string);
|
string basePath = MAP_GET(Arguments, "basePath", string);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Flag(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Flag(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Flip(string type, char *BufferData, size_t BufferLength,
|
char *Flip(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
bool flop = MAP_GET(Arguments, "flop", bool);
|
bool flop = MAP_GET(Arguments, "flop", bool);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Flip(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Flip(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -4,7 +4,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <any>
|
|
||||||
|
|
||||||
#include "blur.h"
|
#include "blur.h"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
@ -52,7 +51,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
std::map<std::string, char* (*)(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize)> FunctionMap = {
|
std::map<std::string, char* (*)(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize)> FunctionMap = {
|
||||||
{"blur", &Blur},
|
{"blur", &Blur},
|
||||||
{"caption", &Caption},
|
{"caption", &Caption},
|
||||||
{"captionTwo", &CaptionTwo},
|
{"captionTwo", &CaptionTwo},
|
||||||
|
@ -118,7 +117,7 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) {
|
||||||
|
|
||||||
Napi::Array properties = obj.GetPropertyNames();
|
Napi::Array properties = obj.GetPropertyNames();
|
||||||
|
|
||||||
std::map<string, any> Arguments;
|
std::map<string, ARG_TYPES> Arguments;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < properties.Length(); i++) {
|
for (unsigned int i = 0; i < properties.Length(); i++) {
|
||||||
string property = properties.Get(uint32_t(i)).As<Napi::String>().Utf8Value();
|
string property = properties.Get(uint32_t(i)).As<Napi::String>().Utf8Value();
|
||||||
|
@ -139,8 +138,6 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) {
|
||||||
} else {
|
} else {
|
||||||
Arguments[property] = num.FloatValue();
|
Arguments[property] = num.FloatValue();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Arguments[property] = val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +171,7 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) { // janky solution for
|
||||||
return OldProcessImage(command, info);
|
return OldProcessImage(command, info);
|
||||||
} else {
|
} else {
|
||||||
Napi::Error::New(env, "Invalid command").ThrowAsJavaScriptException();
|
Napi::Error::New(env, "Invalid command").ThrowAsJavaScriptException();
|
||||||
|
return env.Null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Uncaption(string type, char *BufferData, size_t BufferLength,
|
char *Uncaption(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
float tolerance = MAP_GET_FALLBACK(Arguments, "tolerance", float, 0.5);
|
float tolerance = MAP_GET_FALLBACK(Arguments, "tolerance", float, 0.5);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Uncaption(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Uncaption(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
|
@ -7,7 +7,7 @@ using namespace std;
|
||||||
using namespace vips;
|
using namespace vips;
|
||||||
|
|
||||||
char *Watermark(string type, char *BufferData, size_t BufferLength,
|
char *Watermark(string type, char *BufferData, size_t BufferLength,
|
||||||
map<string, any> Arguments, size_t *DataSize) {
|
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
|
||||||
|
|
||||||
string water = MAP_GET(Arguments, "water", string);
|
string water = MAP_GET(Arguments, "water", string);
|
||||||
int gravity = MAP_GET(Arguments, "gravity", int);
|
int gravity = MAP_GET(Arguments, "gravity", int);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <any>
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::any;
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
char* Watermark(string type, char* BufferData, size_t BufferLength, map<string, any> Arguments, size_t* DataSize);
|
char* Watermark(string type, char* BufferData, size_t BufferLength, map<string, ARG_TYPES> Arguments, size_t* DataSize);
|
Loading…
Reference in a new issue