+Literal::~Literal() {
+ switch (type) {
+ case ARRAY_VALUES:
+ for (vector<Value *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case ARRAY_PROPS:
+ for (vector<PropertyList *>::const_iterator i(propertyLists.begin()), end(propertyLists.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case OBJECT:
+ delete props;
+ break;
+ default:
+ break;
+ }
+}
+
+
+const vector<Value *> &Literal::GetValues() const {
+ if (type == ARRAY_VALUES) {
+ return values;
+ } else {
+ throw runtime_error("tried to access values of non-array literal");
+ }
+}
+
+const vector<PropertyList *> &Literal::GetPropertyLists() const {
+ if (type == ARRAY_PROPS) {
+ return propertyLists;
+ } else {
+ throw runtime_error("tried to access property lists of non-array literal");
+ }
+}
+
+bool Literal::GetBoolean() const {
+ if (type == BOOLEAN) {
+ return b;
+ } else {
+ throw runtime_error("tried to access boolean value of non-boolean literal");
+ }
+}
+
+int Literal::GetRed() const {
+ if (type == COLOR) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access red component of non-color literal");
+ }
+}
+
+int Literal::GetGreen() const {
+ if (type == COLOR) {
+ return i2;
+ } else {
+ throw runtime_error("tried to access green component of non-color literal");
+ }
+}
+
+int Literal::GetBlue() const {
+ if (type == COLOR) {
+ return i3;
+ } else {
+ throw runtime_error("tried to access blue component of non-color literal");
+ }
+}
+
+int Literal::GetAlpha() const {
+ if (type == COLOR) {
+ return i4;
+ } else {
+ throw runtime_error("tried to access alpha component of non-color literal");
+ }
+}
+
+int Literal::GetNumber() const {
+ if (type == NUMBER) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access numerical value of non-number literal");
+ }
+}
+
+const string &Literal::GetString() const {
+ if (type == STRING) {
+ return str;
+ } else {
+ throw runtime_error("tried to access string value of non-color literal");
+ }
+}
+
+int Literal::GetX() const {
+ if (type == VECTOR) {
+ return i1;
+ } else {
+ throw runtime_error("tried to access x component of non-vector literal");
+ }
+}
+
+int Literal::GetY() const {
+ if (type == VECTOR) {
+ return i2;
+ } else {
+ throw runtime_error("tried to access y component of non-vector literal");
+ }
+}
+
+const string &Literal::GetTypeName() const {
+ if (type == OBJECT) {
+ return str;
+ } else {
+ throw runtime_error("tried to access type name of non-object literal");
+ }
+}
+
+const PropertyList *Literal::GetProperties() const {
+ if (type == OBJECT) {
+ return props;
+ } else {
+ throw runtime_error("tried to access properties of non-object literal");
+ }
+}
+
+
+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");
+ }
+}
+