#ifndef TRSL_PARTICLECOLLECTION_HPP
#define TRSL_PARTICLECOLLECTION_HPP
#include <vector>
#include <examples/Particle.hpp>
namespace example {
class ParticleCollection
{
public:
Particle> is_picked;
is_picked, std::vector<Particle>::iterator
> sample_iterator;
is_picked, std::vector<Particle>::const_iterator
> const_sample_iterator;
ParticleCollection(): totalWeight_(0) {}
void add(const Particle& p)
{
totalWeight_ += p.getWeight();
particles_.push_back(p);
}
size_t size() const { return particles_.size(); }
sample_iterator sample_begin(size_t sampleSize)
{
is_picked predicate(sampleSize, totalWeight_, &Particle::getWeight);
return sample_iterator(predicate, particles_.begin(), particles_.end());
}
sample_iterator sample_end()
{
is_picked predicate(1, 1, 0, &Particle::getWeight);
return sample_iterator(predicate, particles_.end(), particles_.end());
}
const_sample_iterator sample_begin(size_t sampleSize) const
{
is_picked predicate(sampleSize, totalWeight_, &Particle::getWeight);
return const_sample_iterator(predicate, particles_.begin(), particles_.end());
}
const_sample_iterator sample_end() const
{
is_picked predicate(1, 1, 0, &Particle::getWeight);
return const_sample_iterator(predicate, particles_.end(), particles_.end());
}
private:
std::vector<Particle> particles_;
double totalWeight_;
};
}
}
#endif // include guard