Skip to content
Snippets Groups Projects
Commit 90610831 authored by Bhuvan Bezawada's avatar Bhuvan Bezawada
Browse files

Created and implemented iterator files

re #23145
parent 5c0135d1
No related branches found
No related tags found
No related merge requests found
......@@ -219,6 +219,8 @@ set ( INC_FILES
inc/MantidGeometry/Instrument/StructuredDetector.h
inc/MantidGeometry/Instrument/XMLInstrumentParameter.h
inc/MantidGeometry/Instrument_fwd.h
inc/MantidGeometry/Instrument/DetectorInfoIterator.h
inc/MantidGeometry/Instrument/DetectorInfoItem.h
inc/MantidGeometry/MDGeometry/CompositeImplicitFunction.h
inc/MantidGeometry/MDGeometry/GeneralFrame.h
inc/MantidGeometry/MDGeometry/HKL.h
......
#ifndef MANTID_GEOMETRY_DETECTORINFOITEM_H_
#define MANTID_GEOMETRY_DETECTORINFOITEM_H_
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include <utility>
namespace Mantid {
namespace Geometry {
namespace Iterators {
class DetectorInfoItem {
private:
friend class DetectorInfoIterator;
// Variables to hold data
const DetectorInfo &m_detectorInfo;
size_t m_index;
// Private constructor, can only be created by DetectorInfoIterator
DetectorInfoItem(const DetectorInfo &detectorInfo, const size_t index)
: m_detectorInfo(detectorInfo), m_index(index) {}
public:
void advance(int64_t delta) {
if (delta < 0) {
std::max(static_cast<uint64_t>(0),
static_cast<uint64_t>(m_index) + delta);
} else {
std::min(m_detectorInfo.size(), m_index + static_cast<size_t>(delta));
}
}
void incrementIndex() {
if (m_index < m_detectorInfo.size()) {
++m_index;
}
}
void decrementIndex() {
if (m_index > 0) {
--m_index;
}
}
size_t getIndex() const { return m_index; }
void setIndex(const size_t index) { m_index = index; }
};
} // namespace Iterators
} // namespace Geometry
} // namespace Mantid
#endif
#ifndef MANTID_GEOMETRY_DETECTORINFOITERATOR_H_
#define MANTID_GEOMETRY_DETECTORINFOITERATOR_H_
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include <boost/iterator/iterator_facade.hpp>
#include <memory>
using DetectorInfo;
namespace Mantid {
namespace Geometry {
namespace Iterators {
class DetectorInfoIterator
: public boost::iterator_facade<DetectorInfoIterator,
const DetectorInfoItem &,
boost::bidirectional_traversal_tag> {
private:
friend class boost::iterator_core_access;
DetectorInfoItem m_item;
void increment() { m_item.incrementIndex(); }
bool equal(const DetectorInfoIterator &other) const {
return m_item.getIndex() == other.m_item.getIndex();
}
const DetectorInfoItem &dereference() const { return m_item; }
void decrement() { m_item.decrementIndex(); }
void advance(int64_t delta) { m_item.advance(delta); }
uint64_t distance_to(const DetectorInfoIterator &other) const {
return static_cast<uint64_t>(other.m_item.getIndex()) -
static_cast<uint64_t>(m_item.getIndex());
}
public:
DetectorInfoIterator(const DetectorInfo &detectorInfo, const size_t index)
: m_item(detectorInfo, index){};
};
} // namespace Iterators
} // namespace Geometry
} // namespace Mantid
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment