From 7dc4bdca925a1999f7fcd2b052677ab1e2e43a4a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 25 Jan 2018 01:07:00 +0100 Subject: -Add API to know if dice is already inside the result. --- result/diceresult.cpp | 13 ++++++++++--- result/diceresult.h | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/result/diceresult.cpp b/result/diceresult.cpp index ddedd1c..f9f8253 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -78,10 +78,17 @@ QVariant DiceResult::getResult(RESULT_TYPE type) return QVariant(); } -/*bool DiceResult::hasResultOfType(RESULT_TYPE type) const +bool DiceResult::contains(Die* die, const std::function equal) { - return (m_resultTypes & type); -}*/ + for(auto value : m_diceValues) + { + if(equal(value,die)) + { + return true; + } + } + return false; +} qreal DiceResult::getScalarResult() { if(m_diceValues.size()==1) diff --git a/result/diceresult.h b/result/diceresult.h index 7eded95..ae16daf 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -76,8 +76,8 @@ public: void setHomogeneous(bool); Die::ArithmeticOperator getOperator() const; - void setOperator(const Die::ArithmeticOperator & dieOperator); - + void setOperator(const Die::ArithmeticOperator & dieOperator); + bool contains(Die *die, const std::function equal); private: qreal getScalarResult(); private: -- cgit v1.2.3-70-g09d2