<commit_before>#ifndef CXX_SIXTRACKLIB_COMMON_BUFFER_HPP__
#define CXX_SIXTRACKLIB_COMMON_BUFFER_HPP__

#if !defined( SIXTRL_NO_SYSTEM_INCLUDES )
    #if defined( __cplusplus )
        #include <algorithm>
        #include <cstddef>
        #include <cstdint>
        #include <cstdlib>
        #include <cstdio>
        #include <limits>
        #include <memory>
        #include <stdexcept>
        #include <string>
        #include <utility>
    #endif /* defined( __cplusplus ) */
#endif /* !defined( SIXTRL_NO_SYSTEM_INCLUDES ) */

#if !defined( SIXTRL_NO_INCLUDES )
    #include "sixtracklib/common/definitions.h"
    #include "sixtracklib/common/buffer.h"
#endif /* !defined( SIXTRL_NO_INCLUDES ) */

#if defined( __cplusplus )

namespace SIXTRL_CXX_NAMESPACE
{
    class Buffer : public ::NS(Buffer)
    {
        public:

        using size_type     = ::NS(buffer_size_t);
        using flags_t       = ::NS(buffer_flags_t);
        using address_t     = ::NS(buffer_addr_t);
        using addr_diff_t   = ::NS(buffer_addr_diff_t);
        using object_t      = ::NS(Object);
        using c_api_t       = ::NS(Buffer);
        using type_id_t     = ::NS(object_type_id_t);

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST size_type
            DEFAULT_BUFFER_CAPACITY = size_type{ 256 };

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST size_type
            DEFAULT_SLOT_SIZE = ::NS(BUFFER_DEFAULT_SLOT_SIZE);

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST flags_t
            DEFAULT_DATASTORE_FLAGS = ::NS(BUFFER_DATASTORE_MEMPOOL);

        #if !defined( _GPUCODE )

        SIXTRL_STATIC std::unique_ptr< Buffer >
        MAKE_FROM_CBUFFER_AND_TAKE_OWNERSHIP(
            ::NS(Buffer)* SIXTRL_RESTRICT ptr_to_take_ownership,
            bool const delete_ptr_after_move = true );

        #endif /* !defined( _GPUCODE ) */

        SIXTRL_FN SIXTRL_STATIC size_type CalculateBufferSize(
            size_type max_num_objects, size_type max_num_slots,
            size_type max_num_dataptrs, size_type max_num_garbage_ranges,
            size_type slot_size = ::NS(BUFFER_DEFAULT_SLOT_SIZE)
        ) SIXTRL_NOEXCEPT;

        SIXTRL_FN explicit Buffer(
            ::NS(Buffer) const& SIXTRL_RESTRICT_REF c_buffer ) SIXTRL_NOEXCEPT;

        SIXTRL_FN explicit Buffer(
            size_type const buffer_capacity = DEFAULT_BUFFER_CAPACITY,
            flags_t const buffer_flags = DEFAULT_DATASTORE_FLAGS );

        SIXTRL_FN Buffer(
            size_type max_num_objects,
            size_type max_num_slots,
            size_type max_num_dataptrs,
            size_type max_num_garbage_ranges,
            flags_t buffer_flags = DEFAULT_DATASTORE_FLAGS );

        template< typename Ptr >
        SIXTRL_FN Buffer( Ptr SIXTRL_RESTRICT data_buffer_begin,
                          size_type max_buffer_size ) SIXTRL_NOEXCEPT;

        template< typename Ptr >
        SIXTRL_FN Buffer(
            Ptr SIXTRL_RESTRICT begin,
            size_type max_num_objects,
            size_type max_num_slots,
            size_type max_num_dataptrs,
            size_type max_num_garbage_ranges,
            size_type buffer_capacity ) SIXTRL_NOEXCEPT;

        #if !defined( _GPUCODE )

        SIXTRL_HOST_FN Buffer( char const* path_to_file );
        SIXTRL_HOST_FN Buffer( std::string const& path_to_file );

        SIXTRL_FN Buffer( Buffer const& SIXTRL_RESTRICT_REF other );
        SIXTRL_FN Buffer( Buffer&& other ) SIXTRL_NOEXCEPT;

        SIXTRL_FN Buffer& operator=( Buffer const& SIXTRL_RESTRICT_REF rhs );
        SIXTRL_FN Buffer& operator=( Buffer&& rhs );

        SIXTRL_FN Buffer& operator=( ::NS(Buffer) const& rhs ) SIXTRL_NOEXCEPT;

        #else

        SIXTRL_FN Buffer( Buffer const& other) = delete;
        SIXTRL_FN Buffer( Buffer&& other) = delete;

        SIXTRL_FN Buffer& operator=( Buffer const& rhs ) = delete;
        SIXTRL_FN Buffer& operator=( Buffer&& rhs ) = delete;

        #endif /* !defined( _GPUCODE ) */

        SIXTRL_FN virtual ~Buffer();

        /* ----------------------------------------------------------------- */

        #if !defined( _GPUCODE )

        SIXTRL_FN bool deepCopyFrom(
            Buffer const& SIXTRL_RESTRICT_REF other );

        SIXTRL_FN bool deepCopyFrom(
            const ::NS(Buffer) *const SIXTRL_RESTRICT ptr_other );

        #endif /* !defined( _GPUCODE ) */

        /* ----------------------------------------------------------------- */

        SIXTRL_FN c_api_t const* getCApiPtr() const SIXTRL_NOEXCEPT;
        SIXTRL_FN c_api_t*       getCApiPtr() SIXTRL_NOEXCEPT;
<commit_msg>common: adds ADL enabled swap function to C++ Buffer API<commit_after>#ifndef CXX_SIXTRACKLIB_COMMON_BUFFER_HPP__
#define CXX_SIXTRACKLIB_COMMON_BUFFER_HPP__

#if !defined( SIXTRL_NO_SYSTEM_INCLUDES )
    #if defined( __cplusplus )
        #include <algorithm>
        #include <cstddef>
        #include <cstdint>
        #include <cstdlib>
        #include <cstdio>
        #include <limits>
        #include <memory>
        #include <stdexcept>
        #include <string>
        #include <utility>
    #endif /* defined( __cplusplus ) */
#endif /* !defined( SIXTRL_NO_SYSTEM_INCLUDES ) */

#if !defined( SIXTRL_NO_INCLUDES )
    #include "sixtracklib/common/definitions.h"
    #include "sixtracklib/common/buffer.h"
#endif /* !defined( SIXTRL_NO_INCLUDES ) */

#if defined( __cplusplus )

namespace SIXTRL_CXX_NAMESPACE
{
    class Buffer : public ::NS(Buffer)
    {
        public:

        using size_type     = ::NS(buffer_size_t);
        using flags_t       = ::NS(buffer_flags_t);
        using address_t     = ::NS(buffer_addr_t);
        using addr_diff_t   = ::NS(buffer_addr_diff_t);
        using object_t      = ::NS(Object);
        using c_api_t       = ::NS(Buffer);
        using type_id_t     = ::NS(object_type_id_t);

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST size_type
            DEFAULT_BUFFER_CAPACITY = size_type{ 256 };

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST size_type
            DEFAULT_SLOT_SIZE = ::NS(BUFFER_DEFAULT_SLOT_SIZE);

        SIXTRL_STATIC_VAR SIXTRL_CONSTEXPR_OR_CONST flags_t
            DEFAULT_DATASTORE_FLAGS = ::NS(BUFFER_DATASTORE_MEMPOOL);

        #if !defined( _GPUCODE )

        SIXTRL_STATIC std::unique_ptr< Buffer >
        MAKE_FROM_CBUFFER_AND_TAKE_OWNERSHIP(
            ::NS(Buffer)* SIXTRL_RESTRICT ptr_to_take_ownership,
            bool const delete_ptr_after_move = true );

        #endif /* !defined( _GPUCODE ) */

        SIXTRL_FN SIXTRL_STATIC size_type CalculateBufferSize(
            size_type max_num_objects, size_type max_num_slots,
            size_type max_num_dataptrs, size_type max_num_garbage_ranges,
            size_type slot_size = ::NS(BUFFER_DEFAULT_SLOT_SIZE)
        ) SIXTRL_NOEXCEPT;

        SIXTRL_FN explicit Buffer(
            ::NS(Buffer) const& SIXTRL_RESTRICT_REF c_buffer ) SIXTRL_NOEXCEPT;

        SIXTRL_FN explicit Buffer(
            size_type const buffer_capacity = DEFAULT_BUFFER_CAPACITY,
            flags_t const buffer_flags = DEFAULT_DATASTORE_FLAGS );

        SIXTRL_FN Buffer(
            size_type max_num_objects,
            size_type max_num_slots,
            size_type max_num_dataptrs,
            size_type max_num_garbage_ranges,
            flags_t buffer_flags = DEFAULT_DATASTORE_FLAGS );

        template< typename Ptr >
        SIXTRL_FN Buffer( Ptr SIXTRL_RESTRICT data_buffer_begin,
                          size_type max_buffer_size ) SIXTRL_NOEXCEPT;

        template< typename Ptr >
        SIXTRL_FN Buffer(
            Ptr SIXTRL_RESTRICT begin,
            size_type max_num_objects,
            size_type max_num_slots,
            size_type max_num_dataptrs,
            size_type max_num_garbage_ranges,
            size_type buffer_capacity ) SIXTRL_NOEXCEPT;

        #if !defined( _GPUCODE )

        SIXTRL_HOST_FN Buffer( char const* path_to_file );
        SIXTRL_HOST_FN Buffer( std::string const& path_to_file );

        SIXTRL_FN Buffer( Buffer const& SIXTRL_RESTRICT_REF other );
        SIXTRL_FN Buffer( Buffer&& other ) SIXTRL_NOEXCEPT;

        SIXTRL_FN Buffer& operator=( Buffer const& SIXTRL_RESTRICT_REF rhs );
        SIXTRL_FN Buffer& operator=( Buffer&& rhs );

        SIXTRL_FN Buffer& operator=( ::NS(Buffer) const& rhs ) SIXTRL_NOEXCEPT;

        #else

        SIXTRL_FN Buffer( Buffer const& other) = delete;
        SIXTRL_FN Buffer( Buffer&& other) = delete;

        SIXTRL_FN Buffer& operator=( Buffer const& rhs ) = delete;
        SIXTRL_FN Buffer& operator=( Buffer&& rhs ) = delete;

        #endif /* !defined( _GPUCODE ) */

        SIXTRL_FN virtual ~Buffer();

        friend void swap( Buffer& SIXTRL_RESTRICT_REF lhs,
                          Buffer& SIXTRL_RESTRICT_REF rhs ) SIXTRL_NOEXCEPT
        {
            using std::swap;

            swap( lhs.data_addr,       rhs.data_addr       );
            swap( lhs.data_size,       rhs.data_size       );
            swap( lhs.header_size,     rhs.header_size     );
            swap( lhs.data_capacity,   rhs.data_capacity   );
            swap( lhs.slot_length,     rhs.slot_length     );
            swap( lhs.object_addr,     rhs.object_addr     );
            swap( lhs.num_objects,     rhs.num_objects     );
            swap( lhs.datastore_flags, rhs.datastore_flags );
            swap( lhs.datastore_addr,  rhs.datastore_addr  );
        }

        /* ----------------------------------------------------------------- */

        #if !defined( _GPUCODE )

        SIXTRL_FN bool deepCopyFrom(
            Buffer const& SIXTRL_RESTRICT_REF other );

        SIXTRL_FN bool deepCopyFrom(
            const ::NS(Buffer) *const SIXTRL_RESTRICT ptr_other );

        #endif /* !defined( _GPUCODE ) */

        /* ----------------------------------------------------------------- */

        SIXTRL_FN c_api_t const* getCApiPtr() const SIXTRL_NOEXCEPT;
        SIXTRL_FN c_api_t*       getCApiPtr() SIXTRL_NOEXCEPT;

{'fraction_non_alphanumeric': 0.10305458187280922, 'fraction_numerical': 0.0006009013520280421, 'mean_word_length': 2.239052870580603, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1183328', 'n_tokens_mistral': 3395, 'n_tokens_neox': 3257, 'n_words': 634}