mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
59 lines
2.7 KiB
Plaintext
59 lines
2.7 KiB
Plaintext
[section Concepts]
|
|
|
|
Users can extend the library with new axis and storage types.
|
|
|
|
[section:axis Axis type]
|
|
|
|
An `axis_type` converts input values into bin indices.
|
|
|
|
An `axis_type` is required to:
|
|
|
|
* derive publically from [classref boost::histogram::axis::labeled_base] and [classref boost::histogram::axis::iterator_mixin]
|
|
* be default/copy/move constructable
|
|
* be copy/move assignable
|
|
* be equal comparable
|
|
* have a nested type `value_type` reflecting the type of the input values (may be a const reference if the input value is expensive to copy)
|
|
* have a nested type `bin_type`, which is a type that represents the bin, typically a semi-open interval (may be a const reference if the bin type is expensive to copy)
|
|
* have the following methods:
|
|
* `int index(value_type x) const`: takes an input value and returns the bin index
|
|
* `bin_type operator[](int index) const`: takes an index and returns the corresponding bin instance
|
|
* optionally, be streamable by implementation a free function
|
|
* `std::ostream operator<<(std::ostream&, const axis_type&)`
|
|
* optionally, be serializable, by implementing a member function template
|
|
* `template <class Archive> void serialize(Archive& ar, unsigned /* version */)`
|
|
|
|
The latter two are not needed, if the histogram that uses the custom axis type is never serialized or streamed.
|
|
|
|
It is recommended to take a look at the existing axis types, like [classref boost::histogram::axis::integer], which serve as templates to create new ones.
|
|
|
|
[endsect]
|
|
|
|
[section:storage 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 `allocator_type`
|
|
* have a nested type `element_type`, which represent the bin count
|
|
* have a nested type `const_reference`, its const reference version
|
|
* have a constructor `storage_type(std::size_t n)`, which prepares the storage of `n` bins.
|
|
* have the following methods and operators:
|
|
* `std::size_t size() const`
|
|
* `void increase(std::size_t index)`
|
|
* `template <typename T> void add(std::size_t index, const T& x)`
|
|
* `const_reference operator[](std::size_t index) const`
|
|
* `storage_type& operator+=(const storage_type& other)`
|
|
* `storage_type& operator*=(const value_type x)`
|
|
* optionally, it can have the following method to support weighted increments:
|
|
* `template <typename T> void add(std::size_t index, const boost::histogram::detail::weight_t<T>& w)`
|
|
|
|
[classref boost::histogram::array_storage] is a simple storage type which may serve as a template for creating a new storage type.
|
|
|
|
[endsect]
|
|
|
|
[endsect]
|