From d8481c4dd4616d4444d0e48c8bf8966b3495bd68 Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Mon, 28 Apr 2014 11:37:58 +0100 Subject: [PATCH] Refs #8913 Add a couple of additional methods for convenience. These are consistent with the functionality that is available in WorkspaceHistory. --- .../API/inc/MantidAPI/AlgorithmHistory.h | 4 +++ .../Framework/API/src/AlgorithmHistory.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h index dadc14c331cb..49367687a100 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h @@ -87,6 +87,10 @@ class MANTID_API_DLL AlgorithmHistory const std::vector& getProperties() const {return m_properties;} /// get the child histories of this history object AlgorithmHistories getChildHistories() const { return m_childHistories; } + /// Retrieve a child algorithm history by index + const AlgorithmHistory & getChildAlgorithmHistory(const size_t index) const; + /// Retrieve the number of child algorithms + size_t childHistorySize() const; /// print contents of object void printSelf(std::ostream&,const int indent = 0) const; /// Less than operator diff --git a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp index 9df327517885..76df6f1f88c3 100644 --- a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp +++ b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp @@ -91,6 +91,31 @@ void AlgorithmHistory::addChildHistory(const AlgorithmHistory& childHist) m_childHistories.insert(childHist); } +/* + Return the child history length + */ +size_t AlgorithmHistory::childHistorySize() const +{ + return m_childHistories.size(); +} + +/** + * Retrieve a child algorithm history by index + * @param index :: An index within the child algorithm history set + * @returns A reference to a const AlgorithmHistory object + * @throws std::out_of_range error if the index is invalid + */ +const AlgorithmHistory & AlgorithmHistory::getChildAlgorithmHistory(const size_t index) const +{ + if( index >= this->getChildHistories().size() ) + { + throw std::out_of_range("AlgorithmHistory::getAlgorithmHistory() - Index out of range"); + } + AlgorithmHistories::const_iterator start = m_childHistories.begin(); + std::advance(start, index); + return *start; +} + /** Set the duration time of the algorithm in the history * @param duration :: The time the algorithm took to execute */