Commit 3cc9962a authored by Matthieu Dorier's avatar Matthieu Dorier

added Prefetchable object and related test

parent 59135965
#ifndef __HEPNOS_PREFETCHABLE_HPP
#define __HEPNOS_PREFETCHABLE_HPP
#include <memory>
namespace hepnos {
class Prefetcher;
template<typename Container>
class Prefetchable {
friend class Prefetcher;
public:
Prefetchable(const Prefetchable& other) = delete;
Prefetchable(Prefetchable&& other) = default;
Prefetchable& operator=(const Prefetchable& other) = delete;
Prefetchable& operator=(Prefetchable&& other) = delete;
~Prefetchable() = default;
typename Container::iterator begin() {
return m_container.begin(m_prefetcher);
}
typename Container::iterator end() {
return m_container.end();
}
typename Container::const_iterator begin() const {
return m_container.begin(m_prefetcher);
}
typename Container::const_iterator end() const {
return m_container.end();
}
private:
Container m_container;
const Prefetcher& m_prefetcher;
Prefetchable(const Container& c, const Prefetcher& p)
: m_container(c)
, m_prefetcher(p) {}
};
}
#endif
......@@ -2,6 +2,7 @@
#define __HEPNOS_PREFETCHER_HPP
#include <memory>
#include <hepnos/Prefetchable.hpp>
namespace hepnos {
......@@ -42,6 +43,11 @@ class Prefetcher {
void setCacheSize(unsigned int size);
unsigned int getBatchSize() const;
void setBatchSize(unsigned int size);
template<typename Container>
Prefetchable<Container> operator()(const Container& c) const {
return Prefetchable<Container>(c, *this);
}
};
}
......
......@@ -206,6 +206,16 @@ void RunSetTest::testPrefetcher() {
i += 1;
}
}
// test begin/end using a Prefetchable object
{
Prefetcher prefetch(*datastore);
unsigned i=0;
for(auto& r : prefetch(mds.runs())) {
CPPUNIT_ASSERT(r.valid());
CPPUNIT_ASSERT(r.number() == i);
i += 1;
}
}
// test lower_bound
{
Prefetcher prefetcher(*datastore);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment