X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.cpp;h=2075828e19b707b28e0afac8e77ca811da588a47;hb=40e697f7265b98dd99918d9c3f5541d9878d80b0;hp=b019fe76bc4f5fb6c09ebae980c86a1319936481;hpb=5d6b785e122093fe05e2ed14f688a8bce6bad6a9;p=l2e.git diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index b019fe7..2075828 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -17,6 +17,12 @@ using std::vector; namespace loader { +ParsedSource::~ParsedSource() { + for (map::const_iterator i(declarations.begin()), end(declarations.end()); i != end; ++i) { + delete i->second; + } +} + void ParsedSource::AddDeclaration(Declaration *d) { map::iterator i(declarations.find(d->Identifier())); if (i != declarations.end()) { @@ -96,6 +102,14 @@ const Definition &ParsedSource::GetDefinition(const std::string &name) const { } +Definition::~Definition() { + if (isLiteral) { + delete reinterpret_cast(value); + } else { + delete reinterpret_cast(value); + } +} + void Definition::SetValue(Literal *v) { value = v; isLiteral = true; @@ -108,7 +122,7 @@ void Definition::SetValue(PropertyList *v) { Literal *Definition::GetLiteral() { if (isLiteral) { - return (Literal *)value; + return reinterpret_cast(value); } else { throw runtime_error("tried to access properties as literal"); } @@ -116,7 +130,7 @@ Literal *Definition::GetLiteral() { const Literal *Definition::GetLiteral() const { if (isLiteral) { - return (Literal *)value; + return reinterpret_cast(value); } else { throw runtime_error("tried to access properties as literal"); } @@ -124,7 +138,7 @@ const Literal *Definition::GetLiteral() const { PropertyList *Definition::GetProperties() { if (!isLiteral) { - return (PropertyList *)value; + return reinterpret_cast(value); } else { throw runtime_error("tried to access literal value as property list"); } @@ -132,7 +146,7 @@ PropertyList *Definition::GetProperties() { const PropertyList *Definition::GetProperties() const { if (!isLiteral) { - return (PropertyList *)value; + return reinterpret_cast(value); } else { throw runtime_error("tried to access literal value as property list"); } @@ -222,6 +236,26 @@ Literal::Literal(const string &typeName, PropertyList *properties) } +Literal::~Literal() { + switch (type) { + case ARRAY_VALUES: + for (vector::const_iterator i(values.begin()), end(values.end()); i != end; ++i) { + delete *i; + } + break; + case ARRAY_PROPS: + for (vector::const_iterator i(propertyLists.begin()), end(propertyLists.end()); i != end; ++i) { + delete *i; + } + break; + case OBJECT: + delete props; + break; + default: + break; + } +} + const vector &Literal::GetValues() const { if (type == ARRAY_VALUES) { @@ -327,6 +361,29 @@ const PropertyList *Literal::GetProperties() const { } } + +Value::~Value() { + if (isLiteral) { + delete literal; + } +} + +const Literal &Value::GetLiteral() const { + if (isLiteral) { + return *literal; + } else { + throw runtime_error("tried to access literal of identifier value"); + } +} + +const std::string &Value::GetIdentifier() const { + if (!isLiteral) { + return identifier; + } else { + throw runtime_error("tried to access identifier of literal value"); + } +} + }