diff --git a/Engine/source/console/arrayObject.cpp b/Engine/source/console/arrayObject.cpp index bc3235485..d5eaffe98 100644 --- a/Engine/source/console/arrayObject.cpp +++ b/Engine/source/console/arrayObject.cpp @@ -29,7 +29,7 @@ IMPLEMENT_CONOBJECT(ArrayObject); -ConsoleDocClass(ArrayObject, +ConsoleDocClass( ArrayObject, "@brief Data structure for storing indexed sequences of key/value pairs.\n\n" "This is a powerful array class providing PHP style arrays in TorqueScript.\n\n" @@ -60,72 +60,72 @@ bool ArrayObject::smCaseSensitive = false; const char* ArrayObject::smCompareFunction; -S32 QSORT_CALLBACK ArrayObject::_valueCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_valueCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); + ArrayObject::Element *ea = (ArrayObject::Element *) (a); + ArrayObject::Element *eb = (ArrayObject::Element *) (b); S32 result = smCaseSensitive ? dStrnatcmp(ea->value, eb->value) : dStrnatcasecmp(ea->value, eb->value); - return (smDecreasing ? -result : result); + return ( smDecreasing ? -result : result ); } -S32 QSORT_CALLBACK ArrayObject::_valueNumCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_valueNumCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); + ArrayObject::Element *ea = (ArrayObject::Element *) (a); + ArrayObject::Element *eb = (ArrayObject::Element *) (b); F32 aCol = dAtof(ea->value); F32 bCol = dAtof(eb->value); F32 result = aCol - bCol; S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0); - return (smDecreasing ? -res : res); + return ( smDecreasing ? -res : res ); } -S32 QSORT_CALLBACK ArrayObject::_keyCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_keyCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); + ArrayObject::Element *ea = (ArrayObject::Element *) (a); + ArrayObject::Element *eb = (ArrayObject::Element *) (b); S32 result = smCaseSensitive ? dStrnatcmp(ea->key, eb->key) : dStrnatcasecmp(ea->key, eb->key); - return (smDecreasing ? -result : result); + return ( smDecreasing ? -result : result ); } -S32 QSORT_CALLBACK ArrayObject::_keyNumCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_keyNumCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); + ArrayObject::Element *ea = (ArrayObject::Element *) (a); + ArrayObject::Element *eb = (ArrayObject::Element *) (b); const char* aCol = ea->key; const char* bCol = eb->key; F32 result = dAtof(aCol) - dAtof(bCol); S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0); - return (smDecreasing ? -res : res); + return ( smDecreasing ? -res : res ); } -S32 QSORT_CALLBACK ArrayObject::_keyFunctionCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_keyFunctionCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); - + ArrayObject::Element* ea = ( ArrayObject::Element* )( a ); + ArrayObject::Element* eb = ( ArrayObject::Element* )( b ); + ConsoleValue cValue = Con::executef((const char*)smCompareFunction, ea->key, eb->key); S32 result = cValue.getInt(); - S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0); - return (smDecreasing ? -res : res); + S32 res = result < 0 ? -1 : ( result > 0 ? 1 : 0 ); + return ( smDecreasing ? -res : res ); } -S32 QSORT_CALLBACK ArrayObject::_valueFunctionCompare(const void* a, const void* b) +S32 QSORT_CALLBACK ArrayObject::_valueFunctionCompare( const void* a, const void* b ) { - ArrayObject::Element* ea = (ArrayObject::Element*)(a); - ArrayObject::Element* eb = (ArrayObject::Element*)(b); - - ConsoleValue cValue = Con::executef((const char*)smCompareFunction, ea->value, eb->value); + ArrayObject::Element* ea = ( ArrayObject::Element* )( a ); + ArrayObject::Element* eb = ( ArrayObject::Element* )( b ); + + ConsoleValue cValue = Con::executef( (const char*)smCompareFunction, ea->value, eb->value ); S32 result = cValue.getInt(); - S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0); - return (smDecreasing ? -res : res); + S32 res = result < 0 ? -1 : ( result > 0 ? 1 : 0 ); + return ( smDecreasing ? -res : res ); } //----------------------------------------------------------------------------- ArrayObject::ArrayObject() - : mCaseSensitive(false), - mCurrentIndex(0) + : mCaseSensitive( false ), + mCurrentIndex( 0 ) { } @@ -134,44 +134,44 @@ ArrayObject::ArrayObject() void ArrayObject::initPersistFields() { docsURL; - addField("caseSensitive", TypeBool, Offset(mCaseSensitive, ArrayObject), + addField( "caseSensitive", TypeBool, Offset( mCaseSensitive, ArrayObject ), "Makes the keys and values case-sensitive.\n" - "By default, comparison of key and value strings will be case-insensitive."); + "By default, comparison of key and value strings will be case-insensitive." ); - addProtectedField("key", TypeCaseString, 0, &_addKeyFromField, &emptyStringProtectedGetFn, - "Helper field which allows you to add new key['keyname'] = value pairs."); + addProtectedField( "key", TypeCaseString, 0, &_addKeyFromField, &emptyStringProtectedGetFn, + "Helper field which allows you to add new key['keyname'] = value pairs." ); Parent::initPersistFields(); } //----------------------------------------------------------------------------- -bool ArrayObject::_addKeyFromField(void* object, const char* index, const char* data) +bool ArrayObject::_addKeyFromField( void *object, const char *index, const char *data ) { - static_cast(object)->push_back(index, data); + static_cast( object )->push_back( index, data ); return false; } //----------------------------------------------------------------------------- -S32 ArrayObject::getIndexFromValue(const String& value) const +S32 ArrayObject::getIndexFromValue( const String &value ) const { S32 currentIndex = mMax(mCurrentIndex, 0); S32 foundIndex = -1; - for (S32 i = currentIndex; i < mArray.size(); i++) + for ( S32 i = currentIndex; i < mArray.size(); i++ ) { - if (isEqual(mArray[i].value, value)) + if ( isEqual( mArray[i].value, value ) ) { foundIndex = i; break; } } - if (foundIndex < 0) + if( foundIndex < 0 ) { - for (S32 i = 0; i < currentIndex; i++) + for ( S32 i = 0; i < currentIndex; i++ ) { - if (isEqual(mArray[i].value, value)) + if ( isEqual( mArray[i].value, value ) ) { foundIndex = i; break; @@ -184,24 +184,24 @@ S32 ArrayObject::getIndexFromValue(const String& value) const //----------------------------------------------------------------------------- -S32 ArrayObject::getIndexFromKey(const String& key) const +S32 ArrayObject::getIndexFromKey( const String &key ) const { S32 currentIndex = mMax(mCurrentIndex, 0); S32 foundIndex = -1; - for (S32 i = currentIndex; i < mArray.size(); i++) + for ( S32 i = currentIndex; i < mArray.size(); i++ ) { - if (isEqual(mArray[i].key, key)) + if ( isEqual( mArray[i].key, key ) ) { foundIndex = i; break; } } - if (foundIndex < 0) + if( foundIndex < 0 ) { - for (S32 i = 0; i < currentIndex; i++) + for ( S32 i = 0; i < currentIndex; i++ ) { - if (isEqual(mArray[i].key, key)) + if ( isEqual( mArray[i].key, key ) ) { foundIndex = i; break; @@ -214,24 +214,24 @@ S32 ArrayObject::getIndexFromKey(const String& key) const //----------------------------------------------------------------------------- -S32 ArrayObject::getIndexFromKeyValue(const String& key, const String& value) const +S32 ArrayObject::getIndexFromKeyValue( const String &key, const String &value ) const { S32 currentIndex = mMax(mCurrentIndex, 0); S32 foundIndex = -1; - for (S32 i = currentIndex; i < mArray.size(); i++) + for ( S32 i = currentIndex; i < mArray.size(); i++ ) { - if (isEqual(mArray[i].key, key) && isEqual(mArray[i].value, value)) + if ( isEqual( mArray[i].key, key ) && isEqual( mArray[i].value, value ) ) { foundIndex = i; break; } } - if (foundIndex < 0) + if ( foundIndex < 0 ) { - for (S32 i = 0; i < currentIndex; i++) + for ( S32 i = 0; i < currentIndex; i++ ) { - if (isEqual(mArray[i].key, key) && isEqual(mArray[i].value, value)) + if ( isEqual( mArray[i].key, key ) && isEqual( mArray[i].value, value ) ) { foundIndex = i; break; @@ -244,9 +244,9 @@ S32 ArrayObject::getIndexFromKeyValue(const String& key, const String& value) co //----------------------------------------------------------------------------- -const String& ArrayObject::getKeyFromIndex(S32 index) const +const String& ArrayObject::getKeyFromIndex( S32 index ) const { - if (index >= mArray.size() || index < 0) + if ( index >= mArray.size() || index < 0 ) return String::EmptyString; return mArray[index].key; @@ -254,9 +254,9 @@ const String& ArrayObject::getKeyFromIndex(S32 index) const //----------------------------------------------------------------------------- -const String& ArrayObject::getValueFromIndex(S32 index) const +const String& ArrayObject::getValueFromIndex( S32 index ) const { - if (index >= mArray.size() || index < 0) + if( index >= mArray.size() || index < 0 ) return String::EmptyString; return mArray[index].value; @@ -264,12 +264,12 @@ const String& ArrayObject::getValueFromIndex(S32 index) const //----------------------------------------------------------------------------- -S32 ArrayObject::countValue(const String& value) const +S32 ArrayObject::countValue( const String &value ) const { S32 count = 0; - for (S32 i = 0; i < mArray.size(); i++) + for ( S32 i = 0; i < mArray.size(); i++ ) { - if (isEqual(mArray[i].value, value)) + if ( isEqual( mArray[i].value, value ) ) count++; } @@ -278,12 +278,12 @@ S32 ArrayObject::countValue(const String& value) const //----------------------------------------------------------------------------- -S32 ArrayObject::countKey(const String& key) const +S32 ArrayObject::countKey( const String &key) const { S32 count = 0; - for (S32 i = 0; i < mArray.size(); i++) + for ( S32 i = 0; i < mArray.size(); i++ ) { - if (isEqual(mArray[i].key, key)) + if ( isEqual( mArray[i].key, key ) ) count++; } @@ -292,36 +292,36 @@ S32 ArrayObject::countKey(const String& key) const //----------------------------------------------------------------------------- -void ArrayObject::push_back(const String& key, const String& value) +void ArrayObject::push_back( const String &key, const String &value ) { - mArray.push_back(Element(key, value)); + mArray.push_back( Element( key, value ) ); } //----------------------------------------------------------------------------- -void ArrayObject::push_front(const String& key, const String& value) +void ArrayObject::push_front( const String &key, const String &value ) { - mArray.push_front(Element(key, value)); + mArray.push_front( Element( key, value ) ); } //----------------------------------------------------------------------------- -void ArrayObject::insert(const String& key, const String& value, S32 index) +void ArrayObject::insert( const String &key, const String &value, S32 index ) { - index = mClamp(index, 0, mArray.size()); - mArray.insert(index, Element(key, value)); + index = mClamp( index, 0, mArray.size() ); + mArray.insert( index, Element( key, value ) ); } //----------------------------------------------------------------------------- void ArrayObject::pop_back() { - if (mArray.size() <= 0) + if(mArray.size() <= 0) return; mArray.pop_back(); - if (mCurrentIndex >= mArray.size()) + if( mCurrentIndex >= mArray.size() ) mCurrentIndex = mArray.size() - 1; } @@ -329,23 +329,23 @@ void ArrayObject::pop_back() void ArrayObject::pop_front() { - if (mArray.size() <= 0) + if( mArray.size() <= 0 ) return; mArray.pop_front(); - - if (mCurrentIndex >= mArray.size()) + + if( mCurrentIndex >= mArray.size() ) mCurrentIndex = mArray.size() - 1; } //----------------------------------------------------------------------------- -void ArrayObject::erase(S32 index) +void ArrayObject::erase( S32 index ) { - if (index < 0 || index >= mArray.size()) + if(index < 0 || index >= mArray.size()) return; - mArray.erase(index); + mArray.erase( index ); } //----------------------------------------------------------------------------- @@ -360,7 +360,7 @@ void ArrayObject::empty() void ArrayObject::moveIndex(S32 prev, S32 index) { - if (index >= mArray.size()) + if(index >= mArray.size()) push_back(mArray[prev].key, mArray[prev].value); else mArray[index] = mArray[prev]; @@ -372,11 +372,11 @@ void ArrayObject::moveIndex(S32 prev, S32 index) void ArrayObject::uniqueValue() { - for (S32 i = 0; i < mArray.size(); i++) + for(S32 i=0; icount(); i++) + for(S32 i=0; icount(); i++) { const String& tempval = obj->getValueFromIndex(i); const String& tempkey = obj->getKeyFromIndex(i); @@ -434,16 +434,16 @@ void ArrayObject::duplicate(ArrayObject* obj) //----------------------------------------------------------------------------- -void ArrayObject::crop(ArrayObject* obj) +void ArrayObject::crop( ArrayObject *obj ) { - for (S32 i = 0; i < obj->count(); i++) + for( S32 i = 0; i < obj->count(); i++ ) { - const String& tempkey = obj->getKeyFromIndex(i); - for (S32 j = 0; j < mArray.size(); j++) + const String &tempkey = obj->getKeyFromIndex( i ); + for( S32 j = 0; j < mArray.size(); j++ ) { - if (isEqual(mArray[j].key, tempkey)) + if( isEqual( mArray[j].key, tempkey ) ) { - mArray.erase(j); + mArray.erase( j ); j--; } } @@ -454,7 +454,7 @@ void ArrayObject::crop(ArrayObject* obj) void ArrayObject::append(ArrayObject* obj) { - for (S32 i = 0; i < obj->count(); i++) + for(S32 i=0; icount(); i++) { const String& tempval = obj->getValueFromIndex(i); const String& tempkey = obj->getKeyFromIndex(i); @@ -464,7 +464,7 @@ void ArrayObject::append(ArrayObject* obj) //----------------------------------------------------------------------------- -void ArrayObject::setKey(const String& key, S32 index) +void ArrayObject::setKey( const String &key, S32 index ) { if (index >= mArray.size() || index < 0) return; @@ -474,54 +474,54 @@ void ArrayObject::setKey(const String& key, S32 index) //----------------------------------------------------------------------------- -void ArrayObject::setValue(const String& value, S32 index) +void ArrayObject::setValue( const String &value, S32 index ) { if (index >= mArray.size() || index < 0) return; - + mArray[index].value = value; } //----------------------------------------------------------------------------- -void ArrayObject::sort(bool valsort, bool asc, bool numeric) +void ArrayObject::sort( bool valsort, bool asc, bool numeric ) { - if (mArray.size() <= 1) + if ( mArray.size() <= 1 ) return; smDecreasing = asc ? false : true; smCaseSensitive = isCaseSensitive(); - if (numeric) + if ( numeric ) { - if (valsort) - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _valueNumCompare); + if ( valsort ) + dQsort( (void *)&(mArray[0]), mArray.size(), sizeof(Element), _valueNumCompare) ; else - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _keyNumCompare); + dQsort( (void *)&(mArray[0]), mArray.size(), sizeof(Element), _keyNumCompare ); } else { - if (valsort) - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _valueCompare); + if( valsort ) + dQsort( (void *)&(mArray[0]), mArray.size(), sizeof(Element), _valueCompare ); else - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _keyCompare); + dQsort( (void *)&(mArray[0]), mArray.size(), sizeof(Element), _keyCompare ); } } //----------------------------------------------------------------------------- -void ArrayObject::sort(bool valsort, bool asc, const char* callbackFunctionName) +void ArrayObject::sort( bool valsort, bool asc, const char* callbackFunctionName ) { - if (mArray.size() <= 1) + if( mArray.size() <= 1 ) return; smDecreasing = asc ? false : true; smCompareFunction = callbackFunctionName; - if (valsort) - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _valueFunctionCompare); + if( valsort ) + dQsort( ( void* ) &( mArray[ 0 ] ), mArray.size(), sizeof( Element ), _valueFunctionCompare ) ; else - dQsort((void*)&(mArray[0]), mArray.size(), sizeof(Element), _keyFunctionCompare); + dQsort( ( void* ) &( mArray[ 0 ] ), mArray.size(), sizeof( Element ), _keyFunctionCompare ); smCompareFunction = NULL; } @@ -538,7 +538,7 @@ S32 ArrayObject::moveFirst() S32 ArrayObject::moveLast() { - if (mArray.empty()) + if ( mArray.empty() ) mCurrentIndex = 0; else mCurrentIndex = mArray.size() - 1; @@ -549,11 +549,11 @@ S32 ArrayObject::moveLast() S32 ArrayObject::moveNext() { - if (mCurrentIndex >= mArray.size() - 1) + if ( mCurrentIndex >= mArray.size() - 1 ) return -1; - + mCurrentIndex++; - + return mCurrentIndex; } @@ -561,21 +561,21 @@ S32 ArrayObject::moveNext() S32 ArrayObject::movePrev() { - if (mCurrentIndex <= 0) + if ( mCurrentIndex <= 0 ) return -1; mCurrentIndex--; - + return mCurrentIndex; } //----------------------------------------------------------------------------- -void ArrayObject::setCurrent(S32 idx) +void ArrayObject::setCurrent( S32 idx ) { - if (idx < 0 || idx >= mArray.size()) + if ( idx < 0 || idx >= mArray.size() ) { - Con::errorf("ArrayObject::setCurrent( %d ) is out of the array bounds!", idx); + Con::errorf( "ArrayObject::setCurrent( %d ) is out of the array bounds!", idx ); return; } @@ -586,13 +586,13 @@ void ArrayObject::setCurrent(S32 idx) void ArrayObject::echo() { - Con::printf("ArrayObject Listing:"); - Con::printf("Index Key Value"); - for (U32 i = 0; i < mArray.size(); i++) + Con::printf( "ArrayObject Listing:" ); + Con::printf( "Index Key Value" ); + for ( U32 i = 0; i < mArray.size(); i++ ) { const String& key = mArray[i].key; const String& val = mArray[i].value; - Con::printf("%d [%s] => %s", i, key.c_str(), val.c_str()); + Con::printf( "%d [%s] => %s", i, key.c_str(), val.c_str() ); } } @@ -600,20 +600,20 @@ void ArrayObject::echo() // Console Methods. //============================================================================= -DefineEngineMethod(ArrayObject, getIndexFromValue, S32, (const char* value), , +DefineEngineMethod( ArrayObject, getIndexFromValue, S32, ( const char* value ),, "Search the array from the current position for the element " "@param value Array value to search for\n" - "@return Index of the first element found, or -1 if none\n") + "@return Index of the first element found, or -1 if none\n" ) { - return object->getIndexFromValue(value); + return object->getIndexFromValue( value ); } -DefineEngineMethod(ArrayObject, getIndexFromKey, S32, (const char* key), , +DefineEngineMethod( ArrayObject, getIndexFromKey, S32, ( const char* key ),, "Search the array from the current position for the key " "@param value Array key to search for\n" - "@return Index of the first element found, or -1 if none\n") + "@return Index of the first element found, or -1 if none\n" ) { - return object->getIndexFromKey(key); + return object->getIndexFromKey( key ); } DefineEngineMethod(ArrayObject, getValueFromKey, const char*, (const char* key), , @@ -632,126 +632,126 @@ DefineEngineMethod(ArrayObject, getKeyFromValue, const char*, (const char* key), return object->getKeyFromIndex(object->getIndexFromValue(key)).c_str(); } -DefineEngineMethod(ArrayObject, getValue, const char*, (S32 index), , +DefineEngineMethod( ArrayObject, getValue, const char*, ( S32 index ),, "Get the value of the array element at the submitted index.\n" "@param index 0-based index of the array element to get\n" "@return The value of the array element at the specified index, " - "or \"\" if the index is out of range\n") + "or \"\" if the index is out of range\n" ) { - return object->getValueFromIndex(index).c_str(); + return object->getValueFromIndex( index ).c_str(); } -DefineEngineMethod(ArrayObject, getKey, const char*, (S32 index), , +DefineEngineMethod( ArrayObject, getKey, const char*, ( S32 index ),, "Get the key of the array element at the submitted index.\n" "@param index 0-based index of the array element to get\n" "@return The key associated with the array element at the " - "specified index, or \"\" if the index is out of range\n") + "specified index, or \"\" if the index is out of range\n" ) { - return object->getKeyFromIndex(index).c_str(); + return object->getKeyFromIndex( index ).c_str(); } -DefineEngineMethod(ArrayObject, setKey, void, (const char* key, S32 index), , +DefineEngineMethod( ArrayObject, setKey, void, ( const char* key, S32 index ),, "Set the key at the given index.\n" "@param key New key value\n" - "@param index 0-based index of the array element to update\n") + "@param index 0-based index of the array element to update\n" ) { - object->setKey(key, index); + object->setKey( key, index ); } -DefineEngineMethod(ArrayObject, setValue, void, (const char* value, S32 index), , +DefineEngineMethod( ArrayObject, setValue, void, ( const char* value, S32 index ),, "Set the value at the given index.\n" "@param value New array element value\n" - "@param index 0-based index of the array element to update\n") + "@param index 0-based index of the array element to update\n" ) { - object->setValue(value, index); + object->setValue( value, index ); } -DefineEngineMethod(ArrayObject, count, S32, (), , - "Get the number of elements in the array.") +DefineEngineMethod( ArrayObject, count, S32, (),, + "Get the number of elements in the array." ) { return (S32)object->count(); } -DefineEngineMethod(ArrayObject, countValue, S32, (const char* value), , +DefineEngineMethod( ArrayObject, countValue, S32, ( const char* value ),, "Get the number of times a particular value is found in the array.\n" - "@param value Array element value to count\n") + "@param value Array element value to count\n" ) { - return (S32)object->countValue(value); + return (S32)object->countValue( value ); } -DefineEngineMethod(ArrayObject, countKey, S32, (const char* key), , +DefineEngineMethod( ArrayObject, countKey, S32, ( const char* key ),, "Get the number of times a particular key is found in the array.\n" - "@param key Key value to count\n") + "@param key Key value to count\n" ) { - return (S32)object->countKey(key); + return (S32)object->countKey( key ); } -DefineEngineMethod(ArrayObject, add, void, (const char* key, const char* value), (""), +DefineEngineMethod( ArrayObject, add, void, ( const char* key, const char* value ), ( "" ), "Adds a new element to the end of an array (same as push_back()).\n" "@param key Key for the new element\n" - "@param value Value for the new element\n") + "@param value Value for the new element\n" ) { - object->push_back(key, value); + object->push_back( key, value ); } -DefineEngineMethod(ArrayObject, push_back, void, (const char* key, const char* value), (""), +DefineEngineMethod( ArrayObject, push_back, void, ( const char* key, const char* value ), ( "" ), "Adds a new element to the end of an array.\n" "@param key Key for the new element\n" - "@param value Value for the new element\n") + "@param value Value for the new element\n" ) { - object->push_back(key, value); + object->push_back( key, value ); } -DefineEngineMethod(ArrayObject, push_front, void, (const char* key, const char* value), (""), - "Adds a new element to the front of an array") +DefineEngineMethod( ArrayObject, push_front, void, ( const char* key, const char* value ), ( "" ), + "Adds a new element to the front of an array" ) { - object->push_front(key, value); + object->push_front( key, value ); } -DefineEngineMethod(ArrayObject, insert, void, (const char* key, const char* value, S32 index), , +DefineEngineMethod( ArrayObject, insert, void, ( const char* key, const char* value, S32 index ),, "Adds a new element to a specified position in the array.\n" "- @a index = 0 will insert an element at the start of the array (same as push_front())\n" "- @a index = %array.count() will insert an element at the end of the array (same as push_back())\n\n" "@param key Key for the new element\n" "@param value Value for the new element\n" - "@param index 0-based index at which to insert the new element") + "@param index 0-based index at which to insert the new element" ) { - object->insert(key, value, index); + object->insert( key, value, index ); } -DefineEngineMethod(ArrayObject, pop_back, void, (), , - "Removes the last element from the array") +DefineEngineMethod( ArrayObject, pop_back, void, (),, + "Removes the last element from the array" ) { object->pop_back(); } -DefineEngineMethod(ArrayObject, pop_front, void, (), , - "Removes the first element from the array") +DefineEngineMethod( ArrayObject, pop_front, void, (),, + "Removes the first element from the array" ) { object->pop_front(); } -DefineEngineMethod(ArrayObject, erase, void, (S32 index), , +DefineEngineMethod( ArrayObject, erase, void, ( S32 index ),, "Removes an element at a specific position from the array.\n" - "@param index 0-based index of the element to remove\n") + "@param index 0-based index of the element to remove\n" ) { - object->erase(index); + object->erase( index ); } -DefineEngineMethod(ArrayObject, empty, void, (), , - "Emptys all elements from an array") +DefineEngineMethod( ArrayObject, empty, void, (),, + "Emptys all elements from an array" ) { object->empty(); } -DefineEngineMethod(ArrayObject, uniqueValue, void, (), , - "Removes any elements that have duplicated values (leaving the first instance)") +DefineEngineMethod( ArrayObject, uniqueValue, void, (),, + "Removes any elements that have duplicated values (leaving the first instance)" ) { object->uniqueValue(); } -DefineEngineMethod(ArrayObject, uniqueKey, void, (), , - "Removes any elements that have duplicated keys (leaving the first instance)") +DefineEngineMethod( ArrayObject, uniqueKey, void, (),, + "Removes any elements that have duplicated keys (leaving the first instance)" ) { object->uniqueKey(); } @@ -762,122 +762,122 @@ DefineEngineMethod(ArrayObject, uniquePair, void, (), , object->uniquePair(); } -DefineEngineMethod(ArrayObject, duplicate, bool, (ArrayObject* target), , +DefineEngineMethod( ArrayObject, duplicate, bool, ( ArrayObject* target ),, "Alters array into an exact duplicate of the target array.\n" - "@param target ArrayObject to duplicate\n") + "@param target ArrayObject to duplicate\n" ) { - if (target) + if ( target ) { - object->duplicate(target); + object->duplicate( target ); return true; } return false; } -DefineEngineMethod(ArrayObject, crop, bool, (ArrayObject* target), , +DefineEngineMethod( ArrayObject, crop, bool, ( ArrayObject* target ),, "Removes elements with matching keys from array.\n" - "@param target ArrayObject containing keys to remove from this array\n") + "@param target ArrayObject containing keys to remove from this array\n" ) { - if (target) + if ( target ) { - object->crop(target); + object->crop( target ); return true; } return false; } -DefineEngineMethod(ArrayObject, append, bool, (ArrayObject* target), , +DefineEngineMethod( ArrayObject, append, bool, ( ArrayObject* target ),, "Appends the target array to the array object.\n" - "@param target ArrayObject to append to the end of this array\n") + "@param target ArrayObject to append to the end of this array\n" ) { - if (target) + if ( target ) { - object->append(target); + object->append( target ); return true; } return false; } -DefineEngineMethod(ArrayObject, sort, void, (bool ascending), (false), +DefineEngineMethod( ArrayObject, sort, void, ( bool ascending ), ( false ), "Alpha sorts the array by value\n\n" - "@param ascending [optional] True for ascending sort, false for descending sort\n") + "@param ascending [optional] True for ascending sort, false for descending sort\n" ) { - object->sort(true, ascending, false); + object->sort( true, ascending, false ); } -DefineEngineMethod(ArrayObject, sorta, void, (), , - "Alpha sorts the array by value in ascending order") +DefineEngineMethod( ArrayObject, sorta, void, (),, + "Alpha sorts the array by value in ascending order" ) { - object->sort(true, true, false); + object->sort( true, true, false ); } -DefineEngineMethod(ArrayObject, sortd, void, (), , - "Alpha sorts the array by value in descending order") +DefineEngineMethod( ArrayObject, sortd, void, (),, + "Alpha sorts the array by value in descending order" ) { - object->sort(true, false, false); + object->sort( true, false, false ); } -DefineEngineMethod(ArrayObject, sortk, void, (bool ascending), (false), +DefineEngineMethod( ArrayObject, sortk, void, ( bool ascending ), ( false ), "Alpha sorts the array by key\n\n" - "@param ascending [optional] True for ascending sort, false for descending sort\n") + "@param ascending [optional] True for ascending sort, false for descending sort\n" ) { - object->sort(false, ascending, false); + object->sort( false, ascending, false ); } -DefineEngineMethod(ArrayObject, sortka, void, (), , - "Alpha sorts the array by key in ascending order") +DefineEngineMethod( ArrayObject, sortka, void, (),, + "Alpha sorts the array by key in ascending order" ) { - object->sort(false, true, false); + object->sort( false, true, false ); } -DefineEngineMethod(ArrayObject, sortkd, void, (), , - "Alpha sorts the array by key in descending order") +DefineEngineMethod( ArrayObject, sortkd, void, (),, + "Alpha sorts the array by key in descending order" ) { - object->sort(false, false, false); + object->sort( false, false, false ); } -DefineEngineMethod(ArrayObject, sortn, void, (bool ascending), (false), +DefineEngineMethod( ArrayObject, sortn, void, ( bool ascending ), ( false ), "Numerically sorts the array by value\n\n" - "@param ascending [optional] True for ascending sort, false for descending sort\n") + "@param ascending [optional] True for ascending sort, false for descending sort\n" ) { - object->sort(true, ascending, true); + object->sort( true, ascending, true ); } -DefineEngineMethod(ArrayObject, sortna, void, (), , - "Numerically sorts the array by value in ascending order") +DefineEngineMethod( ArrayObject, sortna, void, (),, + "Numerically sorts the array by value in ascending order" ) { - object->sort(true, true, true); + object->sort( true, true, true ); } -DefineEngineMethod(ArrayObject, sortnd, void, (), , - "Numerically sorts the array by value in descending order") +DefineEngineMethod( ArrayObject, sortnd, void, (),, + "Numerically sorts the array by value in descending order" ) { - object->sort(true, false, true); + object->sort( true, false, true ); } -DefineEngineMethod(ArrayObject, sortnk, void, (bool ascending), (false), +DefineEngineMethod( ArrayObject, sortnk, void, ( bool ascending ), ( false ), "Numerically sorts the array by key\n\n" - "@param ascending [optional] True for ascending sort, false for descending sort\n") + "@param ascending [optional] True for ascending sort, false for descending sort\n" ) { - object->sort(false, ascending, true); + object->sort( false, ascending, true ); } -DefineEngineMethod(ArrayObject, sortnka, void, (), , - "Numerical sorts the array by key in ascending order") +DefineEngineMethod( ArrayObject, sortnka, void, (),, + "Numerical sorts the array by key in ascending order" ) { - object->sort(false, true, true); + object->sort( false, true, true ); } -DefineEngineMethod(ArrayObject, sortnkd, void, (), , - "Numerical sorts the array by key in descending order") +DefineEngineMethod( ArrayObject, sortnkd, void, (),, + "Numerical sorts the array by key in descending order" ) { - object->sort(false, false, true); + object->sort( false, false, true ); } -DefineEngineMethod(ArrayObject, sortf, void, (const char* functionName), , +DefineEngineMethod( ArrayObject, sortf, void, ( const char* functionName ),, "Sorts the array by value in ascending order using the given callback function.\n" "@param functionName Name of a function that takes two arguments A and B and returns -1 if A is less, 1 if B is less, and 0 if both are equal.\n\n" "@tsexample\n" @@ -886,78 +886,78 @@ DefineEngineMethod(ArrayObject, sortf, void, (const char* functionName), , " return strcmp( %a.name, %b.name );\n" "}\n\n" "%array.sortf( \"mySortCallback\" );\n" - "@endtsexample\n") + "@endtsexample\n" ) { - object->sort(true, true, functionName); + object->sort( true, true, functionName ); } -DefineEngineMethod(ArrayObject, sortfk, void, (const char* functionName), , +DefineEngineMethod( ArrayObject, sortfk, void, ( const char* functionName ),, "Sorts the array by key in ascending order using the given callback function.\n" "@param functionName Name of a function that takes two arguments A and B and returns -1 if A is less, 1 if B is less, and 0 if both are equal." - "@see sortf\n") + "@see sortf\n" ) { - object->sort(false, true, functionName); + object->sort( false, true, functionName ); } -DefineEngineMethod(ArrayObject, sortfd, void, (const char* functionName), , +DefineEngineMethod( ArrayObject, sortfd, void, ( const char* functionName ),, "Sorts the array by value in descending order using the given callback function.\n" "@param functionName Name of a function that takes two arguments A and B and returns -1 if A is less, 1 if B is less, and 0 if both are equal." - "@see sortf\n") + "@see sortf\n" ) { - object->sort(true, false, functionName); + object->sort( true, false, functionName ); } -DefineEngineMethod(ArrayObject, sortfkd, void, (const char* functionName), , +DefineEngineMethod( ArrayObject, sortfkd, void, ( const char* functionName ),, "Sorts the array by key in descending order using the given callback function.\n" "@param functionName Name of a function that takes two arguments A and B and returns -1 if A is less, 1 if B is less, and 0 if both are equal." - "@see sortf\n") + "@see sortf\n" ) { - object->sort(false, false, functionName); + object->sort( false, false, functionName ); } -DefineEngineMethod(ArrayObject, moveFirst, S32, (), , +DefineEngineMethod( ArrayObject, moveFirst, S32, (),, "Moves array pointer to start of array\n\n" - "@return Returns the new array pointer") + "@return Returns the new array pointer" ) { return object->moveFirst(); } -DefineEngineMethod(ArrayObject, moveLast, S32, (), , +DefineEngineMethod( ArrayObject, moveLast, S32, (),, "Moves array pointer to end of array\n\n" - "@return Returns the new array pointer") + "@return Returns the new array pointer" ) { return object->moveLast(); } -DefineEngineMethod(ArrayObject, moveNext, S32, (), , +DefineEngineMethod( ArrayObject, moveNext, S32, (),, "Moves array pointer to next position\n\n" - "@return Returns the new array pointer, or -1 if already at the end") + "@return Returns the new array pointer, or -1 if already at the end" ) { return object->moveNext(); } -DefineEngineMethod(ArrayObject, movePrev, S32, (), , +DefineEngineMethod( ArrayObject, movePrev, S32, (),, "Moves array pointer to prev position\n\n" - "@return Returns the new array pointer, or -1 if already at the start") + "@return Returns the new array pointer, or -1 if already at the start" ) { return object->movePrev(); } -DefineEngineMethod(ArrayObject, getCurrent, S32, (), , - "Gets the current pointer index") +DefineEngineMethod( ArrayObject, getCurrent, S32, (),, + "Gets the current pointer index" ) { return object->getCurrent(); } -DefineEngineMethod(ArrayObject, setCurrent, void, (S32 index), , +DefineEngineMethod( ArrayObject, setCurrent, void, ( S32 index ),, "Sets the current pointer index.\n" - "@param index New 0-based pointer index\n") + "@param index New 0-based pointer index\n" ) { - object->setCurrent(index); + object->setCurrent( index ); } -DefineEngineMethod(ArrayObject, echo, void, (), , - "Echos the array contents to the console") +DefineEngineMethod( ArrayObject, echo, void, (),, + "Echos the array contents to the console" ) { object->echo(); } diff --git a/Engine/source/console/arrayObject.h b/Engine/source/console/arrayObject.h index 0abdd6648..cde4f92b6 100644 --- a/Engine/source/console/arrayObject.h +++ b/Engine/source/console/arrayObject.h @@ -45,15 +45,15 @@ protected: String key; String value; Element() { } - Element(const String& _key, const String& _value) : key(_key), value(_value) { } + Element( const String& _key, const String& _value ) : key(_key), value(_value) { } }; bool mCaseSensitive; S32 mCurrentIndex; - + /// The array of key/value pairs. Vector< Element > mArray; - + /// @name Sorting /// @{ @@ -61,60 +61,60 @@ protected: static bool smCaseSensitive; static const char* smCompareFunction; - static S32 QSORT_CALLBACK _valueCompare(const void* a, const void* b); - static S32 QSORT_CALLBACK _valueNumCompare(const void* a, const void* b); - static S32 QSORT_CALLBACK _keyCompare(const void* a, const void* b); - static S32 QSORT_CALLBACK _keyNumCompare(const void* a, const void* b); - static S32 QSORT_CALLBACK _keyFunctionCompare(const void* a, const void* b); - static S32 QSORT_CALLBACK _valueFunctionCompare(const void* a, const void* b); - + static S32 QSORT_CALLBACK _valueCompare( const void *a, const void *b ); + static S32 QSORT_CALLBACK _valueNumCompare( const void *a, const void *b ); + static S32 QSORT_CALLBACK _keyCompare( const void *a, const void *b ); + static S32 QSORT_CALLBACK _keyNumCompare( const void *a, const void *b ); + static S32 QSORT_CALLBACK _keyFunctionCompare( const void* a, const void* b ); + static S32 QSORT_CALLBACK _valueFunctionCompare( const void* a, const void* b ); + /// @} - static bool _addKeyFromField(void* object, const char* index, const char* data); + static bool _addKeyFromField( void *object, const char *index, const char *data ); public: - + ArrayObject(); - /// @name Data Query + /// @name Data Query /// @{ - + /// Returns true if string handling by the array is case-sensitive. bool isCaseSensitive() const { return mCaseSensitive; } - bool isEqual(const String& valA, const String& valB) const + bool isEqual( const String &valA, const String &valB ) const { - return valA.equal(valB, isCaseSensitive() ? String::Case : String::NoCase); + return valA.equal( valB, isCaseSensitive() ? String::Case : String::NoCase ); } - /// Searches the array for the first matching value from the + /// Searches the array for the first matching value from the /// current array position. It will return -1 if no matching /// index is found. - S32 getIndexFromValue(const String& value) const; + S32 getIndexFromValue( const String &value ) const; /// Searches the array for the first matching key from the current /// array position. It will return -1 if no matching index found. - S32 getIndexFromKey(const String& key) const; - + S32 getIndexFromKey( const String &key ) const; + /// Returns the key for a given index. /// Will return a null value for an invalid index - const String& getKeyFromIndex(S32 index) const; + const String& getKeyFromIndex( S32 index ) const; /// Returns the value for a given index. /// Will return a null value for an invalid index - const String& getValueFromIndex(S32 index) const; - + const String& getValueFromIndex( S32 index ) const; + /// - S32 getIndexFromKeyValue(const String& key, const String& value) const; + S32 getIndexFromKeyValue( const String &key, const String &value ) const; /// Counts the number of elements in the array S32 count() const { return mArray.size(); } /// Counts the number of instances of a particular value in the array - S32 countValue(const String& value) const; + S32 countValue( const String &value ) const; /// Counts the number of instances of a particular key in the array - S32 countKey(const String& key) const; + S32 countKey( const String &key ) const; /// @} @@ -122,13 +122,13 @@ public: /// @{ /// Adds a new array item to the end of the array - void push_back(const String& key, const String& value); + void push_back( const String &key, const String &value ); /// Adds a new array item to the front of the array - void push_front(const String& key, const String& value); + void push_front( const String &key, const String &value ); /// Adds a new array item to a particular index of the array - void insert(const String& key, const String& value, S32 index); + void insert( const String &key, const String &value, S32 index ); /// Removes an array item from the end of the array void pop_back(); @@ -137,13 +137,13 @@ public: void pop_front(); /// Removes an array item from a particular index of the array - void erase(S32 index); + void erase( S32 index ); /// Clears an array void empty(); /// Moves a key and value from one index location to another. - void moveIndex(S32 prev, S32 index); + void moveIndex( S32 prev, S32 index ); /// @} @@ -163,31 +163,31 @@ public: void uniquePair(); /// Makes this array an exact duplicate of another array - void duplicate(ArrayObject* obj); + void duplicate( ArrayObject *obj ); /// Crops the keys that exists in the target array from our current array - void crop(ArrayObject* obj); + void crop( ArrayObject *obj ); /// Appends the target array to our current array - void append(ArrayObject* obj); + void append( ArrayObject *obj ); /// Sets the key at the given index - void setKey(const String& key, S32 index); + void setKey( const String &key, S32 index ); /// Sets the key at the given index - void setValue(const String& value, S32 index); + void setValue( const String &value, S32 index ); /// This sorts the array. /// @param valtest Determines whether sorting by value or key. /// @param asc Determines if sorting ascending or descending. /// @param numeric Determines if sorting alpha or numeric search. - void sort(bool valtest, bool asc, bool numeric); - + void sort( bool valtest, bool asc, bool numeric ); + /// This sorts the array using a script callback. /// @param valtest Determines whether sorting by value or key. /// @param asc Determines if sorting ascending or descending. /// @param callbackFunctionName Name of the script function. - void sort(bool valtest, bool asc, const char* callbackFunctionName); + void sort( bool valtest, bool asc, const char* callbackFunctionName ); /// @} @@ -212,7 +212,7 @@ public: S32 getCurrent() const { return mCurrentIndex; } /// - void setCurrent(S32 idx); + void setCurrent( S32 idx ); /// @} @@ -226,10 +226,10 @@ public: /// @} // SimObject - DECLARE_CONOBJECT(ArrayObject); - DECLARE_CATEGORY("Core"); - DECLARE_DESCRIPTION("An object storing an indexed sequence of key/value pairs."); - + DECLARE_CONOBJECT( ArrayObject ); + DECLARE_CATEGORY( "Core" ); + DECLARE_DESCRIPTION( "An object storing an indexed sequence of key/value pairs." ); + static void initPersistFields(); };