1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // SampleMap implements HistogramSamples interface. It is used by the
6 // SparseHistogram class to store samples.
8 #ifndef BASE_METRICS_SAMPLE_MAP_H_
9 #define BASE_METRICS_SAMPLE_MAP_H_
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/histogram_base.h"
16 #include "base/metrics/histogram_samples.h"
20 class BASE_EXPORT_PRIVATE SampleMap
: public HistogramSamples
{
25 // HistogramSamples implementation:
26 virtual void Accumulate(HistogramBase::Sample value
,
27 HistogramBase::Count count
) OVERRIDE
;
28 virtual HistogramBase::Count
GetCount(
29 HistogramBase::Sample value
) const OVERRIDE
;
30 virtual HistogramBase::Count
TotalCount() const OVERRIDE
;
31 virtual scoped_ptr
<SampleCountIterator
> Iterator() const OVERRIDE
;
34 virtual bool AddSubtractImpl(
35 SampleCountIterator
* iter
,
36 HistogramSamples::Operator op
) OVERRIDE
; // |op| is ADD or SUBTRACT.
39 std::map
<HistogramBase::Sample
, HistogramBase::Count
> sample_counts_
;
41 DISALLOW_COPY_AND_ASSIGN(SampleMap
);
44 class BASE_EXPORT_PRIVATE SampleMapIterator
: public SampleCountIterator
{
46 typedef std::map
<HistogramBase::Sample
, HistogramBase::Count
>
49 explicit SampleMapIterator(const SampleToCountMap
& sample_counts
);
50 virtual ~SampleMapIterator();
52 // SampleCountIterator implementation:
53 virtual bool Done() const OVERRIDE
;
54 virtual void Next() OVERRIDE
;
55 virtual void Get(HistogramBase::Sample
* min
,
56 HistogramBase::Sample
* max
,
57 HistogramBase::Count
* count
) const OVERRIDE
;
59 SampleToCountMap::const_iterator iter_
;
60 const SampleToCountMap::const_iterator end_
;
65 #endif // BASE_METRICS_SAMPLE_MAP_H_