From 695e2bedb3e1e3d8ae93b9efa12067193d144434 Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Sat, 23 Nov 2024 13:34:23 -0600 Subject: [PATCH] Add overloads to JSON::Value to allow assignment of size_t types (#214) --- lib/json.cpp | 10 ++++++++++ lib/json.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/lib/json.cpp b/lib/json.cpp index d98c3e8f1..696d0b606 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -497,6 +497,11 @@ JSON::Value::Value(int64_t val){ myType = INTEGER; intVal = val; } +/// Sets this JSON::Value to the given integer. +JSON::Value::Value(size_t val){ + myType = INTEGER; + intVal = val; +} /// Sets this JSON::Value to the given double. JSON::Value::Value(double val){ @@ -692,6 +697,11 @@ JSON::Value &JSON::Value::operator=(const uint64_t &rhs){ return ((*this) = (int64_t)rhs); } +/// Sets this JSON::Value to the given integer. +JSON::Value &JSON::Value::operator=(const size_t &rhs){ + return ((*this) = (int64_t)rhs); +} + /// Sets this JSON::Value to the given double. JSON::Value &JSON::Value::operator=(const double &rhs){ null(); diff --git a/lib/json.h b/lib/json.h index 20799b9bc..6d1dd2537 100644 --- a/lib/json.h +++ b/lib/json.h @@ -46,6 +46,7 @@ namespace JSON{ Value(int64_t val); Value(uint32_t val); Value(uint64_t val); + Value(size_t val); Value(double val); Value(bool val); // comparison operators @@ -63,6 +64,7 @@ namespace JSON{ Value &operator=(const int32_t &rhs); Value &operator=(const uint64_t &rhs); Value &operator=(const uint32_t &rhs); + Value &operator=(const size_t &rhs); Value &operator=(const double &rhs); Value &operator=(const bool &rhs); // converts to basic types