#ifndef BASE_METRICS_SAMPLE_VECTOR_H_
#define BASE_METRICS_SAMPLE_VECTOR_H_
#include <vector>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
namespace base {
class BucketRanges;
class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples {
public:
explicit SampleVector(const BucketRanges* bucket_ranges);
virtual ~SampleVector();
virtual void Accumulate(HistogramBase::Sample value,
HistogramBase::Count count) OVERRIDE;
virtual HistogramBase::Count GetCount(
HistogramBase::Sample value) const OVERRIDE;
virtual HistogramBase::Count TotalCount() const OVERRIDE;
virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE;
HistogramBase::Count GetCountAtIndex(size_t bucket_index) const;
protected:
virtual bool AddSubtractImpl(
SampleCountIterator* iter,
HistogramSamples::Operator op) OVERRIDE;
virtual size_t GetBucketIndex(HistogramBase::Sample value) const;
private:
FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
std::vector<HistogramBase::AtomicCount> counts_;
const BucketRanges* const bucket_ranges_;
DISALLOW_COPY_AND_ASSIGN(SampleVector);
};
class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator {
public:
SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts,
const BucketRanges* bucket_ranges);
virtual ~SampleVectorIterator();
virtual bool Done() const OVERRIDE;
virtual void Next() OVERRIDE;
virtual void Get(HistogramBase::Sample* min,
HistogramBase::Sample* max,
HistogramBase::Count* count) const OVERRIDE;
virtual bool GetBucketIndex(size_t* index) const OVERRIDE;
private:
void SkipEmptyBuckets();
const std::vector<HistogramBase::AtomicCount>* counts_;
const BucketRanges* bucket_ranges_;
size_t index_;
};
}
#endif