From 8cc678e2eeda0df0b80fd19b03712a626b0b7bd2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 14:45:51 -0500 Subject: ZVISION: Convert 'Object' implicit conversion operators to accessors Implicit conversion, while simple can cause problems and doesn't show exactly how to get the value. --- engines/zvision/object.cpp | 67 +++++++++++++++++++++++++++------------------- engines/zvision/object.h | 18 ++++++------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp index 6bc8c0f648..322d7f2ea6 100644 --- a/engines/zvision/object.cpp +++ b/engines/zvision/object.cpp @@ -305,67 +305,78 @@ Object &Object::operator=(const Object &rhs) { } -Object::operator bool() { - if (_objectType != BOOL) - warning("'Object' not of type bool. Bad cast"); +bool Object::getBoolValue(bool *returnValue) const { + if (_objectType != BOOL) { + warning("'Object' not of type bool."); + return false; + } - return *_value.boolVal; + *returnValue = *_value.boolVal; + return true; } -Object::operator byte() { +bool Object::getByteValue(byte *returnValue) const { if (_objectType != BYTE) - warning("'Object' not of type byte. Bad cast"); + warning("'Object' not of type byte."); - return *_value.byteVal; + *returnValue = *_value.byteVal; + return true; } -Object::operator int16() { +bool Object::getInt16Value(int16 *returnValue) const { if (_objectType != INT16) - warning("'Object' not of type int16. Bad cast"); + warning("'Object' not of type int16."); - return *_value.int16Val; + *returnValue = *_value.int16Val; + return true; } -Object::operator uint16() { +bool Object::getUInt16Value(uint16 *returnValue) const { if (_objectType != UINT16) - warning("'Object' not of type uint16. Bad cast"); + warning("'Object' not of type uint16."); - return *_value.uint16Val; + *returnValue = *_value.uint16Val; + return true; } -Object::operator int32() { +bool Object::getInt32Value(int32 *returnValue) const { if (_objectType != INT32) - warning("'Object' not of type int32. Bad cast"); + warning("'Object' not of type int32."); - return *_value.int32Val; + *returnValue = *_value.int32Val; + return true; } -Object::operator uint32() { +bool Object::getUInt32Value(uint32 *returnValue) const { if (_objectType != UINT32) - warning("'Object' not of type uint32. Bad cast"); + warning("'Object' not of type uint32."); - return *_value.uint32Val; + *returnValue = *_value.uint32Val; + return true; } -Object::operator float() { +bool Object::getFloatValue(float *returnValue) const { if (_objectType != FLOAT) - warning("'Object' not of type float. Bad cast"); + warning("'Object' not of type float."); - return *_value.floatVal; + *returnValue = *_value.floatVal; + return true; } -Object::operator double() { +bool Object::getDoubleValue(double *returnValue) const { if (_objectType != DOUBLE) - warning("'Object' not of type double. Bad cast"); + warning("'Object' not of type double."); - return *_value.doubleVal; + *returnValue = *_value.doubleVal; + return true; } -Object::operator Common::String() { +bool Object::getStringValue(Common::String *returnValue) const { if (_objectType != STRING) - warning("'Object' not of type Common::String. Bad cast"); + warning("'Object' not of type Common::String."); - return *_value.stringVal; + *returnValue = *_value.stringVal; + return true; } } // End of namespace ZVision diff --git a/engines/zvision/object.h b/engines/zvision/object.h index b98b3812cd..4df572c2b1 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -97,15 +97,15 @@ public: Object& operator=(const Object &rhs); - operator bool(); - operator byte(); - operator int16(); - operator uint16(); - operator int32(); - operator uint32(); - operator float(); - operator double(); - operator Common::String(); + bool getBoolValue(bool *returnValue) const; + bool getByteValue(byte *returnValue) const; + bool getInt16Value(int16 *returnValue) const; + bool getUInt16Value(uint16 *returnValue) const; + bool getInt32Value(int32 *returnValue) const; + bool getUInt32Value(uint32 *returnValue) const; + bool getFloatValue(float *returnValue) const; + bool getDoubleValue(double *returnValue) const; + bool getStringValue(Common::String *returnValue) const; private: /** -- cgit v1.2.3