diff options
-rw-r--r-- | audio/decoders/vorbis.cpp | 2 | ||||
-rw-r--r-- | audio/mods/maxtrax.cpp | 2 | ||||
-rw-r--r-- | common/util.h | 5 | ||||
-rw-r--r-- | devtools/create_kyradat/create_kyradat.cpp | 8 | ||||
-rw-r--r-- | devtools/create_kyradat/extract.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/kyra_hof.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/scene_hof.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/scene_mr.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/staticres.cpp | 6 | ||||
-rw-r--r-- | test/common/algorithm.h | 24 |
10 files changed, 32 insertions, 27 deletions
diff --git a/audio/decoders/vorbis.cpp b/audio/decoders/vorbis.cpp index 455803dc05..64cacb4d58 100644 --- a/audio/decoders/vorbis.cpp +++ b/audio/decoders/vorbis.cpp @@ -123,7 +123,7 @@ protected: VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) : _inStream(inStream, dispose), _length(0, 1000), - _bufferEnd(_buffer + ARRAYSIZE(_buffer)) { + _bufferEnd(ARRAYEND(_buffer)) { int res = ov_open_callbacks(inStream, &_ovFile, NULL, 0, g_stream_wrap); if (res < 0) { diff --git a/audio/mods/maxtrax.cpp b/audio/mods/maxtrax.cpp index 953bb8f8d2..252c0e3b06 100644 --- a/audio/mods/maxtrax.cpp +++ b/audio/mods/maxtrax.cpp @@ -707,7 +707,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui if ((channel.flags & ChannelContext::kFlagMono) == 0) { voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri); } else { - VoiceContext *voice = _voiceCtx + ARRAYSIZE(_voiceCtx) - 1; + VoiceContext *voice = ARRAYEND(_voiceCtx) - 1; for (voiceNum = ARRAYSIZE(_voiceCtx) - 1; voiceNum >= 0 && voice->channel != &channel; --voiceNum, --voice) ; if (voiceNum < 0) diff --git a/common/util.h b/common/util.h index 6e14188f04..a96c7a60c6 100644 --- a/common/util.h +++ b/common/util.h @@ -58,6 +58,11 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } */ #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) +/** + * Compute a pointer to one past the last element of an array. + */ +#define ARRAYEND(x) ((x) + ARRAYSIZE((x))) + /** * @def SCUMMVM_CURRENT_FUNCTION diff --git a/devtools/create_kyradat/create_kyradat.cpp b/devtools/create_kyradat/create_kyradat.cpp index ddcc8ad6d1..627b517c62 100644 --- a/devtools/create_kyradat/create_kyradat.cpp +++ b/devtools/create_kyradat/create_kyradat.cpp @@ -331,7 +331,7 @@ const TypeTable gameTable[] = { }; byte getGameID(int game) { - return std::find(gameTable, gameTable + ARRAYSIZE(gameTable) - 1, game)->value; + return std::find(gameTable, ARRAYEND(gameTable) - 1, game)->value; } const TypeTable languageTable[] = { @@ -347,7 +347,7 @@ const TypeTable languageTable[] = { }; byte getLanguageID(int lang) { - return std::find(languageTable, languageTable + ARRAYSIZE(languageTable) - 1, lang)->value; + return std::find(languageTable, ARRAYEND(languageTable) - 1, lang)->value; } const TypeTable platformTable[] = { @@ -360,7 +360,7 @@ const TypeTable platformTable[] = { }; byte getPlatformID(int platform) { - return std::find(platformTable, platformTable + ARRAYSIZE(platformTable) - 1, platform)->value; + return std::find(platformTable, ARRAYEND(platformTable) - 1, platform)->value; } const TypeTable specialTable[] = { @@ -373,7 +373,7 @@ const TypeTable specialTable[] = { }; byte getSpecialID(int special) { - return std::find(specialTable, specialTable + ARRAYSIZE(specialTable) - 1, special)->value; + return std::find(specialTable, ARRAYEND(specialTable) - 1, special)->value; } // filename processing diff --git a/devtools/create_kyradat/extract.cpp b/devtools/create_kyradat/extract.cpp index 2aa9fc0d39..371f2f4e2b 100644 --- a/devtools/create_kyradat/extract.cpp +++ b/devtools/create_kyradat/extract.cpp @@ -127,7 +127,7 @@ const ExtractType *findExtractType(const int type) { } byte getTypeID(int type) { - return std::find(typeTable, typeTable + ARRAYSIZE(typeTable) - 1, type)->value; + return std::find(typeTable, ARRAYEND(typeTable) - 1, type)->value; } // Extractor implementation diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp index d38868a919..432cf1a250 100644 --- a/engines/kyra/kyra_hof.cpp +++ b/engines/kyra/kyra_hof.cpp @@ -1084,7 +1084,7 @@ void KyraEngine_HoF::loadNPCScript() { #pragma mark - void KyraEngine_HoF::resetScaleTable() { - Common::set_to(_scaleTable, _scaleTable + ARRAYSIZE(_scaleTable), 0x100); + Common::set_to(_scaleTable, ARRAYEND(_scaleTable), 0x100); } void KyraEngine_HoF::setScaleTableItem(int item, int data) { @@ -1674,7 +1674,7 @@ void KyraEngine_HoF::setCauldronState(uint8 state, bool paletteFade) { } void KyraEngine_HoF::clearCauldronTable() { - Common::set_to(_cauldronTable, _cauldronTable+ARRAYSIZE(_cauldronTable), -1); + Common::set_to(_cauldronTable, ARRAYEND(_cauldronTable), -1); } void KyraEngine_HoF::addFrontCauldronTable(int item) { diff --git a/engines/kyra/scene_hof.cpp b/engines/kyra/scene_hof.cpp index e85e691364..f6cd77ca89 100644 --- a/engines/kyra/scene_hof.cpp +++ b/engines/kyra/scene_hof.cpp @@ -95,7 +95,7 @@ void KyraEngine_HoF::enterNewScene(uint16 newScene, int facing, int unk1, int un _emc->run(&_sceneScriptState); } - Common::for_each(_wsaSlots, _wsaSlots+ARRAYSIZE(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close)); + Common::for_each(_wsaSlots, ARRAYEND(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close)); _specialExitCount = 0; memset(_specialExitTable, -1, sizeof(_specialExitTable)); diff --git a/engines/kyra/scene_mr.cpp b/engines/kyra/scene_mr.cpp index 6b234d9a73..74d2e89e6e 100644 --- a/engines/kyra/scene_mr.cpp +++ b/engines/kyra/scene_mr.cpp @@ -83,7 +83,7 @@ void KyraEngine_MR::enterNewScene(uint16 sceneId, int facing, int unk1, int unk2 } _specialExitCount = 0; - Common::set_to(_specialExitTable, _specialExitTable+ARRAYSIZE(_specialExitTable), 0xFFFF); + Common::set_to(_specialExitTable, ARRAYEND(_specialExitTable), 0xFFFF); _mainCharacter.sceneId = sceneId; _sceneList[sceneId].flags &= ~1; @@ -388,7 +388,7 @@ void KyraEngine_MR::initSceneScript(int unk1) { strcat(filename, ".CPS"); _screen->loadBitmap(filename, 3, 3, 0); - Common::set_to(_specialSceneScriptState, _specialSceneScriptState+ARRAYSIZE(_specialSceneScriptState), false); + Common::set_to(_specialSceneScriptState, ARRAYEND(_specialSceneScriptState), false); _sceneEnterX1 = 160; _sceneEnterY1 = 0; _sceneEnterX2 = 296; diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index dc1a4fd2f2..f6d59922b1 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -80,7 +80,7 @@ const IndexTable iGameTable[] = { }; byte getGameID(const GameFlags &flags) { - return Common::find(iGameTable, iGameTable + ARRAYSIZE(iGameTable) - 1, flags.gameID)->value; + return Common::find(iGameTable, ARRAYEND(iGameTable) - 1, flags.gameID)->value; } const IndexTable iLanguageTable[] = { @@ -95,7 +95,7 @@ const IndexTable iLanguageTable[] = { }; byte getLanguageID(const GameFlags &flags) { - return Common::find(iLanguageTable, iLanguageTable + ARRAYSIZE(iLanguageTable) - 1, flags.lang)->value; + return Common::find(iLanguageTable, ARRAYEND(iLanguageTable) - 1, flags.lang)->value; } const IndexTable iPlatformTable[] = { @@ -108,7 +108,7 @@ const IndexTable iPlatformTable[] = { }; byte getPlatformID(const GameFlags &flags) { - return Common::find(iPlatformTable, iPlatformTable + ARRAYSIZE(iPlatformTable) - 1, flags.platform)->value; + return Common::find(iPlatformTable, ARRAYEND(iPlatformTable) - 1, flags.platform)->value; } byte getSpecialID(const GameFlags &flags) { diff --git a/test/common/algorithm.h b/test/common/algorithm.h index beba495e40..6eecae3635 100644 --- a/test/common/algorithm.h +++ b/test/common/algorithm.h @@ -38,30 +38,30 @@ public: const int arraySorted[] = { 1, 2, 3, 3, 4, 5 }; const int arrayUnsorted[] = { 5, 3, 1, 2, 4, 3 }; - TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Less<int>()), true); - TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Greater<int>()), false); + TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Less<int>()), true); + TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Greater<int>()), false); - TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Less<int>()), false); - TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Greater<int>()), false); + TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Less<int>()), false); + TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Greater<int>()), false); } void test_pod_sort() { { int array[] = { 63, 11, 31, 72, 1, 48, 32, 69, 38, 31 }; - Common::sort(array, array + ARRAYSIZE(array)); - TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true); + Common::sort(array, ARRAYEND(array)); + TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true); // already sorted - Common::sort(array, array + ARRAYSIZE(array)); - TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true); + Common::sort(array, ARRAYEND(array)); + TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true); } { int array[] = { 90, 80, 70, 60, 50, 40, 30, 20, 10 }; - Common::sort(array, array + ARRAYSIZE(array)); - TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true); + Common::sort(array, ARRAYEND(array)); + TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true); - Common::sort(array, array + ARRAYSIZE(array), Common::Greater<int>()); - TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Greater<int>()), true); + Common::sort(array, ARRAYEND(array), Common::Greater<int>()); + TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Greater<int>()), true); } } |