From a791c8f4b8ec0dfc5afdee041aab9e3d075c78e4 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 21 Jul 2022 23:55:33 +0200 Subject: [PATCH] HTTPSession's get_int now has a default parameter. --- modules/web/http/http_session.cpp | 10 ++++++++-- modules/web/http/http_session.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/web/http/http_session.cpp b/modules/web/http/http_session.cpp index 8f8739531..40cf38486 100644 --- a/modules/web/http/http_session.cpp +++ b/modules/web/http/http_session.cpp @@ -52,10 +52,16 @@ Ref HTTPSession::get_reference(const String &key) { return Ref(_data[key]); } -int HTTPSession::get_int(const String &key) { +int HTTPSession::get_int(const String &key, const int def) { // don't lock here - return _data[key]; + Variant *v = _data.getptr(key); + + if (!v) { + return def; + } + + return *v; } void HTTPSession::clear() { diff --git a/modules/web/http/http_session.h b/modules/web/http/http_session.h index e44186fbd..3b507d11c 100644 --- a/modules/web/http/http_session.h +++ b/modules/web/http/http_session.h @@ -16,6 +16,8 @@ //Add an api for variants, similar to get set_meta, but rw locked. //Make sure it's obvious that it's not saved. Maybe set_temp_data ... +//Also add an RWLock + class HTTPSession : public Reference { GDCLASS(HTTPSession, Reference); @@ -34,7 +36,7 @@ public: const Variant &get_const(const String &key); Object *get_object(const String &key); Ref get_reference(const String &key); - int get_int(const String &key); + int get_int(const String &key, const int def = 0); void clear(); void reset();