#ifndef PB_DS_RC_HPP
#define PB_DS_RC_HPP
namespace pb_ds
{
namespace detail
{
#define PB_DS_CLASS_T_DEC \
template<typename Node, class Allocator>
#define PB_DS_CLASS_C_DEC \
rc<Node, Allocator>
template<typename Node, class Allocator>
class rc
{
private:
typedef Allocator allocator;
typedef typename allocator::size_type size_type;
typedef Node node;
typedef
typename allocator::template rebind<
node>::other::pointer
node_pointer;
typedef
typename allocator::template rebind<
node_pointer>::other::pointer
entry_pointer;
typedef
typename allocator::template rebind<
node_pointer>::other::const_pointer
const_entry_pointer;
enum
{
max_entries = sizeof(size_type) << 3
};
public:
typedef node_pointer entry;
typedef const_entry_pointer const_iterator;
public:
rc();
rc(const PB_DS_CLASS_C_DEC& other);
inline void
swap(PB_DS_CLASS_C_DEC& other);
inline void
push(entry p_nd);
inline node_pointer
top() const;
inline void
pop();
inline bool
empty() const;
inline size_type
size() const;
void
clear();
const const_iterator
begin() const;
const const_iterator
end() const;
#ifdef _GLIBCXX_DEBUG
void
assert_valid() const;
#endif
#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
void
trace() const;
#endif
private:
node_pointer m_a_entries[max_entries];
size_type m_over_top;
};
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
rc() : m_over_top(0)
{ _GLIBCXX_DEBUG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
rc(const PB_DS_CLASS_C_DEC& other) : m_over_top(0)
{ _GLIBCXX_DEBUG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
swap(PB_DS_CLASS_C_DEC& other)
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ONLY(other.assert_valid();)
const size_type over_top = std::max(m_over_top, other.m_over_top);
for (size_type i = 0; i < over_top; ++i)
std::swap(m_a_entries[i], other.m_a_entries[i]);
std::swap(m_over_top, other.m_over_top);
_GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ONLY(other.assert_valid();)
}
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
push(entry p_nd)
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ASSERT(m_over_top < max_entries);
m_a_entries[m_over_top++] = p_nd;
_GLIBCXX_DEBUG_ONLY(assert_valid();)
}
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
pop()
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ASSERT(!empty());
--m_over_top;
_GLIBCXX_DEBUG_ONLY(assert_valid();)
}
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::node_pointer
PB_DS_CLASS_C_DEC::
top() const
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ASSERT(!empty());
return *(m_a_entries + m_over_top - 1);
}
PB_DS_CLASS_T_DEC
inline bool
PB_DS_CLASS_C_DEC::
empty() const
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
return m_over_top == 0;
}
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::size_type
PB_DS_CLASS_C_DEC::
size() const
{ return m_over_top; }
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
clear()
{
_GLIBCXX_DEBUG_ONLY(assert_valid();)
m_over_top = 0;
_GLIBCXX_DEBUG_ONLY(assert_valid();)
}
PB_DS_CLASS_T_DEC
const typename PB_DS_CLASS_C_DEC::const_iterator
PB_DS_CLASS_C_DEC::
begin() const
{ return& m_a_entries[0]; }
PB_DS_CLASS_T_DEC
const typename PB_DS_CLASS_C_DEC::const_iterator
PB_DS_CLASS_C_DEC::
end() const
{ return& m_a_entries[m_over_top]; }
#ifdef _GLIBCXX_DEBUG
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
assert_valid() const
{ _GLIBCXX_DEBUG_ASSERT(m_over_top < max_entries); }
#endif
#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
trace() const
{
std::cout << "rc" << std::endl;
for (size_type i = 0; i < m_over_top; ++i)
std::cerr << m_a_entries[i] << std::endl;
std::cout << std::endl;
}
#endif
#undef PB_DS_CLASS_T_DEC
#undef PB_DS_CLASS_C_DEC
} }
#endif