histogram/doc/concepts.qbk
2017-05-05 00:13:44 +02:00

61 lines
2.3 KiB
Plaintext

[section Concepts]
Users can extend the library with new axis and storage types.
[section Axis type]
An `axis_type` converts input values into bin indices.
An `axis_type` is required to:
* be default/copy/move constructable
* be copy/move assignable
* be equal comparable
* have a nested type `value_type`, which is the type of the input values (may be a const reference if the input value is expensive to copy)
* have the following methods:
* `int index(value_type x) const`
* `value_type operator[](int index) const`
* `const std::string& label() const`
* `int bin() const`
* `int shape() const`
* `bool uoflow() const`
For full support of all library features, the `axis_type` should also be:
* streamable, by implementing a free function `std::ostream operator<<(std::ostream&, const axis_type&)`
* serializable, by implementing a free function `template <class Archive> inline void serialize(Archive& ar, axis_type & axis, unsigned /* version */)`
The latter two are not needed, if the histogram that uses the custom axis type is never serialized or ostreamed.
It is recommended to take a look at [classref boost::histogram::axis_base], which provides part of the aforementioned infrastructure for axis types.
[endsect]
[section Storage type]
A `storage_type` handles memory for the bin counters and provides a uniform interface for incrementing bin counters and reading their values.
A `storage_type` is required to:
* be default/copy/move constructable
* be copy/move assignable
* be equal comparable
* have a nested type `value_type`, the uniform external type of the bin count (internally it may be a different type)
* have a constructor `storage_type(std::size_t n)`, which prepares the storage for `n` bins.
* have the following methods:
* `std::size_t size() const`
* `void increase(std::size_t index)`
* `void increase(std::size_t index, value_type n)`
* `value_type value(std::size_t index) const`
To support weighted fills, two additional methods are required:
* `value_type variance(std::size_t index) const`
* `void weighted_increase(std::size_t index, value_type weight)`
[classref boost::histogram::container_storage] is a simple example of a storage type which does not support weighted fills.
[endsect]
[endsect]