Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:46:36

0001 // Copyright 2018 Hans Dembinski
0002 //
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_HISTOGRAM_UNSAFE_ACCESS_HPP
0008 #define BOOST_HISTOGRAM_UNSAFE_ACCESS_HPP
0009 
0010 #include <boost/histogram/detail/axes.hpp>
0011 #include <type_traits>
0012 
0013 namespace boost {
0014 namespace histogram {
0015 
0016 /** Unsafe read/write access to private data that potentially breaks consistency.
0017 
0018   This struct enables access to private data of some classes. It is intended for library
0019   developers who need this to implement algorithms efficiently, for example,
0020   serialization. Users should not use this. If you are a user who absolutely needs this to
0021   get a specific effect, please submit an issue on Github. Perhaps the public
0022   interface is insufficient and should be extended for your use case.
0023 
0024   Unlike the normal interface, the unsafe_access interface may change between versions.
0025   If your code relies on unsafe_access, it may or may not break when you update Boost.
0026   This is another reason to not use it unless you are ok with these conditions.
0027 */
0028 struct unsafe_access {
0029   /**
0030     Get axes.
0031     @param hist histogram.
0032   */
0033   template <class Histogram>
0034   static auto& axes(Histogram& hist) {
0035     return hist.axes_;
0036   }
0037 
0038   /// @copydoc axes()
0039   template <class Histogram>
0040   static const auto& axes(const Histogram& hist) {
0041     return hist.axes_;
0042   }
0043 
0044   /**
0045     Get mutable axis reference with compile-time number.
0046     @param hist histogram.
0047     @tparam I axis index (optional, default: 0).
0048   */
0049   template <class Histogram, unsigned I = 0>
0050   static decltype(auto) axis(Histogram& hist, std::integral_constant<unsigned, I> = {}) {
0051     assert(I < hist.rank());
0052     return detail::axis_get<I>(hist.axes_);
0053   }
0054 
0055   /**
0056     Get mutable axis reference with run-time number.
0057     @param hist histogram.
0058     @param i axis index.
0059   */
0060   template <class Histogram>
0061   static decltype(auto) axis(Histogram& hist, unsigned i) {
0062     assert(i < hist.rank());
0063     return detail::axis_get(hist.axes_, i);
0064   }
0065 
0066   /**
0067     Get storage.
0068     @param hist histogram.
0069   */
0070   template <class Histogram>
0071   static auto& storage(Histogram& hist) {
0072     return hist.storage_;
0073   }
0074 
0075   /// @copydoc storage()
0076   template <class Histogram>
0077   static const auto& storage(const Histogram& hist) {
0078     return hist.storage_;
0079   }
0080 
0081   /**
0082     Get index offset.
0083     @param hist histogram
0084     */
0085   template <class Histogram>
0086   static auto& offset(Histogram& hist) {
0087     return hist.offset_;
0088   }
0089 
0090   /// @copydoc offset()
0091   template <class Histogram>
0092   static const auto& offset(const Histogram& hist) {
0093     return hist.offset_;
0094   }
0095 
0096   /**
0097     Get buffer of unlimited_storage.
0098     @param storage instance of unlimited_storage.
0099   */
0100   template <class Allocator>
0101   static constexpr auto& unlimited_storage_buffer(unlimited_storage<Allocator>& storage) {
0102     return storage.buffer_;
0103   }
0104 
0105   /**
0106     Get implementation of storage_adaptor.
0107     @param storage instance of storage_adaptor.
0108   */
0109   template <class T>
0110   static constexpr auto& storage_adaptor_impl(storage_adaptor<T>& storage) {
0111     return static_cast<typename storage_adaptor<T>::impl_type&>(storage);
0112   }
0113 };
0114 
0115 } // namespace histogram
0116 } // namespace boost
0117 
0118 #endif