Strted implmenting the iterators and frame class

This commit is contained in:
Antony Polukhin
2016-10-25 21:51:27 +03:00
parent 0edc5bc968
commit bd59ec8bef
2 changed files with 150 additions and 2 deletions

View File

@@ -14,6 +14,10 @@
#include <boost/aligned_storage.hpp>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/assert.hpp>
#include <iosfwd>
#include <string>
@@ -78,6 +82,71 @@
namespace boost { namespace stacktrace {
class stacktrace;
class frame {
void* frame_no_;
public:
};
//typedef std::string frame;
/// @cond
namespace detail {
class iterator : public boost::iterator_facade<
iterator,
const frame,
boost::random_access_traversal_tag>
{
typedef boost::iterator_facade<
iterator,
const frame,
boost::random_access_traversal_tag
> base_t;
const stacktrace* impl_;
std::size_t frame_no_;
iterator(const stacktrace* impl, std::size_t frame_no) BOOST_NOEXCEPT
: impl_(impl)
, frame_no_(frame_no)
{}
friend class ::boost::stacktrace::stacktrace;
friend class ::boost::iterators::iterator_core_access;
const frame& dereference() const; /* {
return (*impl_)[frame_no_];
}*/
bool equal(const iterator& it) const BOOST_NOEXCEPT {
return impl_ == it.impl_ && frame_no_ == it.frame_no_;
}
void increment() BOOST_NOEXCEPT {
++frame_no_;
}
void decrement() BOOST_NOEXCEPT {
--frame_no_;
}
void advance(std::size_t n) BOOST_NOEXCEPT {
frame_no_ += n;
}
base_t::difference_type distance_to(const iterator& it) const {
BOOST_ASSERT(impl_ == it.impl_);
return it.frame_no_ - frame_no_;
}
public:
};
} // namespace detail
/// @endcond
class stacktrace {
#ifdef BOOST_STACKTRACE_LINK
BOOST_STATIC_CONSTEXPR std::size_t max_implementation_size = sizeof(void*) * 110u;
@@ -89,6 +158,22 @@ class stacktrace {
std::size_t hash_code_;
public:
typedef frame value_type;
typedef boost::stacktrace::detail::iterator iterator;
typedef iterator const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_iterator begin() const BOOST_NOEXCEPT { return const_iterator(this, 0); }
const_iterator cbegin() const BOOST_NOEXCEPT { return const_iterator(this, 0); }
const_iterator end() const BOOST_NOEXCEPT { return const_iterator(this, size()); }
const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(this, size()); }
const_reverse_iterator rbegin() const BOOST_NOEXCEPT { return const_reverse_iterator( const_iterator(this, 0) ); }
const_reverse_iterator crbegin() const BOOST_NOEXCEPT { return const_reverse_iterator( const_iterator(this, 0) ); }
const_reverse_iterator rend() const BOOST_NOEXCEPT { return const_reverse_iterator( const_iterator(this, size()) ); }
const_reverse_iterator crend() const BOOST_NOEXCEPT { return const_reverse_iterator( const_iterator(this, size()) ); }
/// @brief Stores the current function call sequence inside the class.
///
/// @b Complexity: O(N) where N is call seaquence length, O(1) for noop backend.
@@ -108,14 +193,14 @@ public:
/// @b Complexity: O(1)
BOOST_STACKTRACE_FUNCTION std::size_t size() const BOOST_NOEXCEPT;
/// @param frame Zero based index of function to return. 0
/// @param frame_no Zero based index of function to return. 0
/// is the function index where stacktrace was constructed and
/// index close to this->size() contains function `main()`.
/// @returns Function name in a human readable form.
/// @throws std::bad_alloc if not enough memory to construct resulting string.
///
/// @b Complexity: Amortized O(1), O(1) for noop backend.
BOOST_STACKTRACE_FUNCTION std::string operator[](std::size_t frame) const;
BOOST_STACKTRACE_FUNCTION std::string operator[](std::size_t frame_no) const;
/// @cond
bool operator!() const BOOST_NOEXCEPT {