X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.cpp;h=13b1262f93410de52ce0f522bfb538f66531fa6a;hb=774c652e18456863dc1ae03e3a5bb4a75f40a956;hp=1f7fc983053e68ab32047bdbba7abdc2f466d796;hpb=2bd2e92a227af66386af1dfca2f52df6941f0f94;p=l2e.git diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index 1f7fc98..13b1262 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,9 @@ PropertyList *Definition::GetProperties() { const PropertyList *Definition::GetProperties() const { if (!isLiteral) { - return (PropertyList *)value; + return reinterpret_cast(value); + } else if (GetLiteral()->GetType() == Literal::OBJECT) { + return GetLiteral()->GetProperties(); } else { throw runtime_error("tried to access literal value as property list"); } @@ -222,6 +238,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) { @@ -328,6 +364,12 @@ const PropertyList *Literal::GetProperties() const { } +Value::~Value() { + if (isLiteral) { + delete literal; + } +} + const Literal &Value::GetLiteral() const { if (isLiteral) { return *literal;