-//$$CDS-header$$
-
-#ifndef __CDS_OPT_BUFFER_H
-#define __CDS_OPT_BUFFER_H
-
+/*
+ This file is a part of libcds - Concurrent Data Structures library
+
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+ Source code repo: http://github.com/khizmax/libcds/
+ Download: http://sourceforge.net/projects/libcds/files/
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef CDSLIB_OPT_BUFFER_H
+#define CDSLIB_OPT_BUFFER_H
+
+#include <memory.h>
#include <cds/details/defs.h>
#include <cds/user_setup/allocator.h>
#include <cds/details/allocator.h>
The template parameter \p Type should be rebindable.
Implementations:
- - opt::v::static_buffer
- - opt::v::dynamic_buffer
+ - \p opt::v::static_buffer
+ - \p opt::v::dynamic_buffer
*/
template <typename Type>
struct buffer {
namespace v {
- /// Static buffer (see \p cds::opt::buffer option)
+ /// Static buffer
/**
- One of available type for opt::buffer type-option.
+ One of available type for \p opt::buffer option.
This buffer maintains static array. No dynamic memory allocation performed.
{
public:
typedef T value_type ; ///< value type
- static const size_t c_nCapacity = Capacity ; ///< Capacity
- static const bool c_bExp2 = Exp2; ///< \p Exp2 flag
+ static CDS_CONSTEXPR const size_t c_nCapacity = Capacity ; ///< Capacity
+ static CDS_CONSTEXPR const bool c_bExp2 = Exp2; ///< \p Exp2 flag
/// Rebind buffer for other template parameters
template <typename Q, size_t Capacity2 = c_nCapacity, bool Exp22 = c_bExp2>
struct rebind {
typedef static_buffer<Q, Capacity2, Exp22> other ; ///< Rebind result type
};
+
+ // Capacity must be power of 2
+ static_assert(!c_bExp2 || (c_nCapacity & (c_nCapacity - 1)) == 0, "Capacity must be power of two");
+
private:
//@cond
value_type m_buffer[c_nCapacity];
//@endcond
public:
/// Construct static buffer
- static_buffer()
- {
- // Capacity must be power of 2
- static_assert( !c_bExp2 || (c_nCapacity & (c_nCapacity - 1)) == 0, "Capacity must be power of two" );
- }
+ static_buffer() CDS_NOEXCEPT
+ {}
/// Construct buffer of given capacity
/**
This ctor ignores \p nCapacity argument. The capacity of static buffer
is defined by template argument \p Capacity
*/
- static_buffer( size_t nCapacity )
+ static_buffer( size_t nCapacity ) CDS_NOEXCEPT
{
- // Capacity must be power of 2
- static_assert( !c_bExp2 || (c_nCapacity & (c_nCapacity - 1)) == 0, "Capacity must be power of two");
- //assert( c_nCapacity == nCapacity );
+ CDS_UNUSED( nCapacity );
}
+ static_buffer( const static_buffer& ) = delete;
+ static_buffer& operator =( const static_buffer& ) = delete;
+
/// Get item \p i
value_type& operator []( size_t i )
{
}
/// Returns pointer to buffer array
- value_type * buffer()
+ value_type * buffer() CDS_NOEXCEPT
{
return m_buffer;
}
- /// Returns pointer to buffer array (const version)
- value_type * buffer() const
+ /// Returns pointer to buffer array
+ value_type * buffer() const CDS_NOEXCEPT
{
return m_buffer;
}
-
- private:
- //@cond
- // non-copyable
- static_buffer(const static_buffer&);
- void operator =(const static_buffer&);
- //@endcond
};
/// Dynamically allocated buffer
/**
- One of available \p cds::opt::buffer type-option.
+ One of available type for \p opt::buffer option.
This buffer maintains dynamically allocated array.
Allocation is performed at construction time.
a.Delete( m_buffer, m_nCapacity );
}
+ dynamic_buffer( const dynamic_buffer& ) = delete;
+ dynamic_buffer& operator =( const dynamic_buffer& ) = delete;
+
/// Get item \p i
value_type& operator []( size_t i )
{
}
/// Returns pointer to buffer array
- value_type * buffer()
+ value_type * buffer() CDS_NOEXCEPT
{
return m_buffer;
}
- /// Returns pointer to buffer array (const version)
- value_type * buffer() const
+ /// Returns pointer to buffer array
+ value_type * buffer() const CDS_NOEXCEPT
{
return m_buffer;
}
-
- private:
- //@cond
- // non-copyable
- dynamic_buffer(const dynamic_buffer&);
- void operator =(const dynamic_buffer&);
- //@endcond
};
} // namespace v
}} // namespace cds::opt
-#endif // #ifndef __CDS_OPT_BUFFER_H
+#endif // #ifndef CDSLIB_OPT_BUFFER_H