Swap std::any for std::variant

This commit is contained in:
Essem 2022-11-27 17:23:57 -06:00
parent 7ee571dd2b
commit 9ddc32193f
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
26 changed files with 44 additions and 68 deletions

View file

@ -8,7 +8,7 @@ using namespace std;
using namespace vips;
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);
VOption *options = VImage::option()->set("access", "sequential");

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -8,7 +8,7 @@ using namespace std;
using namespace vips;
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 font = MAP_GET(Arguments, "font", string);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -8,7 +8,7 @@ using namespace std;
using namespace vips;
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);
string caption = MAP_GET(Arguments, "caption", string);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -11,7 +11,7 @@ using namespace std;
using namespace Magick;
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;

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -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);
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);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -1,12 +1,14 @@
#pragma once
#include <any>
#include <variant>
#include <string>
#include <unordered_map>
#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_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? any_cast<TYPE>(ARRAY.at(KEY)) : FALLBACK)
#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) ? get<TYPE>(ARRAY.at(KEY)) : FALLBACK)
#define ARG_TYPES std::variant<string, bool, int, float>
const std::unordered_map<std::string, std::string> fontPaths {
{"futura", "assets/fonts/caption.otf"},

View file

@ -7,7 +7,7 @@ using namespace std;
using namespace vips;
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");

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -6,7 +6,7 @@ using namespace std;
using namespace vips;
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");

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -12,7 +12,7 @@ using namespace std;
using namespace Magick;
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 delay = MAP_GET_FALLBACK(Arguments, "delay", int, 0);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -8,7 +8,7 @@ using namespace std;
using namespace vips;
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 basePath = MAP_GET(Arguments, "basePath", string);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -8,7 +8,7 @@ using namespace std;
using namespace vips;
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);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -4,7 +4,6 @@
#include <map>
#include <string>
#include <iostream>
#include <any>
#include "blur.h"
#include "colors.h"
@ -52,7 +51,7 @@
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},
{"caption", &Caption},
{"captionTwo", &CaptionTwo},
@ -118,7 +117,7 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) {
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++) {
string property = properties.Get(uint32_t(i)).As<Napi::String>().Utf8Value();
@ -139,8 +138,6 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) {
} else {
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);
} else {
Napi::Error::New(env, "Invalid command").ThrowAsJavaScriptException();
return env.Null();
}
}

View file

@ -7,7 +7,7 @@ using namespace std;
using namespace vips;
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);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);

View file

@ -7,7 +7,7 @@ using namespace std;
using namespace vips;
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);
int gravity = MAP_GET(Arguments, "gravity", int);

View file

@ -1,11 +1,9 @@
#pragma once
#include <any>
#include "common.h"
#include <map>
#include <string>
using std::any;
using std::map;
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);