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.
61 lines
1.4 KiB
61 lines
1.4 KiB
#include "webserv.hpp"
|
|
|
|
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() {
|
|
if (type == OBJECT) return *values.object;
|
|
throw std::logic_error("Improper return");
|
|
}
|
|
JSONList JSONNode::lst() {
|
|
if (type == LIST) return *values.list;
|
|
throw std::logic_error("Improper return");
|
|
}
|
|
string JSONNode::str() {
|
|
if (type == STRING) return *values.str;
|
|
throw std::logic_error("Improper return");
|
|
}
|
|
int JSONNode::nbr() {
|
|
if (type == NUMBER) return values.nbr;
|
|
throw std::logic_error("Improper return");
|
|
}
|
|
bool JSONNode::boo() {
|
|
if (type == BOOLEAN) return values.bValue;
|
|
throw std::logic_error("Improper return");
|
|
}
|
|
|
|
void JSONNode::setObj(JSONObject *object) {
|
|
this->values.object = object;
|
|
type = OBJECT;
|
|
}
|
|
void JSONNode::setLst(JSONList *list) {
|
|
this->values.list = list;
|
|
type = LIST;
|
|
}
|
|
void JSONNode::setStr(string *str) {
|
|
this->values.str = str;
|
|
type = STRING;
|
|
}
|
|
void JSONNode::setNbr(int nbr) {
|
|
this->values.nbr = nbr;
|
|
type = NUMBER;
|
|
}
|
|
void JSONNode::setBoo(bool v) {
|
|
this->values.bValue = v;
|
|
type = BOOLEAN;
|
|
}
|
|
void JSONNode::setNull() { type = NULL_TYPE; }
|
|
|