From 67bce173824e2ee99d858aa97145c6e1b3e81ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sat, 13 Jun 2020 13:46:02 +0200 Subject: [PATCH] Extract logic to NoteDataUtil::StringInterpretsAs --- src/NoteDataUtil.cpp | 11 +++++++++++ src/NoteDataUtil.h | 5 +++++ src/NotesLoaderSM.cpp | 46 +++++++------------------------------------ 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/NoteDataUtil.cpp b/src/NoteDataUtil.cpp index 330b3f0b58..ee5e321258 100644 --- a/src/NoteDataUtil.cpp +++ b/src/NoteDataUtil.cpp @@ -11,6 +11,17 @@ #include "TimingData.h" #include +bool NoteDataUtil::StringInterpretsAs( const std::string& str, int integer ) { + try + { + return std::stoi( str ) == integer; + } + catch ( const std::invalid_argument & ) + { + return false; + } +} + // TODO: Remove these constants that aren't time signature-aware static const int BEATS_PER_MEASURE = 4; static const int ROWS_PER_MEASURE = ROWS_PER_BEAT * BEATS_PER_MEASURE; diff --git a/src/NoteDataUtil.h b/src/NoteDataUtil.h index a855ddd2a6..8b9ea53432 100644 --- a/src/NoteDataUtil.h +++ b/src/NoteDataUtil.h @@ -23,6 +23,11 @@ void LightTransformHelper( const NoteData &in, NoteData &out, const vector * and makes it much easier to change NoteData internally in the future. */ namespace NoteDataUtil { + /** + * @brief Whether a string can be interpreted as the provided signed integer + */ + bool StringInterpretsAs( const std::string& str, int integer ); + NoteType GetSmallestNoteTypeForMeasure( const NoteData &nd, int iMeasureIndex ); NoteType GetSmallestNoteTypeInRange( const NoteData &nd, int iStartIndex, int iEndIndex ); void LoadFromSMNoteDataString( NoteData &out, const RString &sSMNoteData, bool bComposite ); diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index fa2a6c0279..b0b52148a2 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -3,6 +3,7 @@ #include "BackgroundUtil.h" #include "GameManager.h" #include "MsdFile.h" +#include "NoteDataUtil.h" #include "NoteTypes.h" #include "RageFileManager.h" #include "RageLog.h" @@ -974,58 +975,25 @@ bool SMLoader::LoadFromBGChangesVector( BackgroundChange &change, std::vector