You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

#include "webserv.hpp"
2 years ago
JSONNode::~JSONNode(void) {
switch (type) {
case OBJECT:
for (JSONObject::iterator it = values.object->begin(); it != values.object->end(); it++) { delete it->second; }
delete values.object;
break;
case LIST:
for (JSONList::iterator it = values.list->begin(); it != values.list->end(); it++) { delete *it; }
delete values.list;
break;
case STRING:
delete values.str;
break;
default:
break;
}
}
JSONObject JSONNode::obj() {
2 years ago
if (type == OBJECT) return *values.object;
2 years ago
throw std::logic_error("Improper return");
}
JSONList JSONNode::lst() {
2 years ago
if (type == LIST) return *values.list;
2 years ago
throw std::logic_error("Improper return");
}
string JSONNode::str() {
2 years ago
if (type == STRING) return *values.str;
2 years ago
throw std::logic_error("Improper return");
}
int JSONNode::nbr() {
2 years ago
if (type == NUMBER) return values.nbr;
2 years ago
throw std::logic_error("Improper return");
}
bool JSONNode::boo() {
2 years ago
if (type == BOOLEAN) return values.bValue;
2 years ago
throw std::logic_error("Improper return");
}
2 years ago
void JSONNode::setObj(JSONObject *object) {
2 years ago
this->values.object = object;
type = OBJECT;
}
2 years ago
void JSONNode::setLst(JSONList *list) {
2 years ago
this->values.list = list;
type = LIST;
}
2 years ago
void JSONNode::setStr(string *str) {
2 years ago
this->values.str = str;
type = STRING;
}
2 years ago
void JSONNode::setNbr(int nbr) {
2 years ago
this->values.nbr = nbr;
type = NUMBER;
}
2 years ago
void JSONNode::setBoo(bool v) {
2 years ago
this->values.bValue = v;
type = BOOLEAN;
}
void JSONNode::setNull() { type = NULL_TYPE; }