Added reference support to the session.

This commit is contained in:
Relintai 2021-08-22 22:03:10 +02:00
parent ed434b7f68
commit 8318e0257a
2 changed files with 24 additions and 1 deletions

View File

@ -17,6 +17,22 @@ Object *HTTPSession::get_object(const std::string &key) {
return _data[key];
}
void HTTPSession::add_reference(const std::string &key, const Ref<Reference> &ref) {
std::lock_guard<std::mutex> lock(_mutex);
_reference_data[key] = ref;
}
void HTTPSession::remove_reference(const std::string &key) {
std::lock_guard<std::mutex> lock(_mutex);
_reference_data.erase(key);
}
Ref<Reference> HTTPSession::get_reference(const std::string &key) {
//don't lock here
return _reference_data[key];
}
void HTTPSession::add_int(const std::string &key, const int val) {
std::lock_guard<std::mutex> lock(_mutex);
@ -36,6 +52,7 @@ int HTTPSession::get_int(const std::string &key) {
void HTTPSession::clear() {
_data.clear();
_int_data.clear();
_reference_data.clear();
}
void HTTPSession::reset() {

View File

@ -2,16 +2,21 @@
#define HTTP_SESSION_H
#include "core/object.h"
#include "core/reference.h"
#include <map>
#include <mutex>
#include <string>
class HTTPSession : public Object {
public:
void add_object(const std::string &key,Object *obj);
void add_object(const std::string &key, Object *obj);
void remove_object(const std::string &key);
Object *get_object(const std::string &key);
void add_reference(const std::string &key, const Ref<Reference> &ref);
void remove_reference(const std::string &key);
Ref<Reference> get_reference(const std::string &key);
void add_int(const std::string &key, const int val);
void remove_int(const std::string &key);
int get_int(const std::string &key);
@ -29,6 +34,7 @@ protected:
//todo make something similar to godot's variant. (Or get godot's variant lol)
std::map<std::string, Object *> _data;
std::map<std::string, Ref<Reference> > _reference_data;
std::map<std::string, int> _int_data;
};