|
@ -4,7 +4,11 @@ |
|
|
#include <cassert> |
|
|
#include <cassert> |
|
|
#include <vector> |
|
|
#include <vector> |
|
|
#include <string> |
|
|
#include <string> |
|
|
|
|
|
|
|
|
|
|
|
#pragma warning(push) |
|
|
|
|
|
#pragma warning(disable: 4267) |
|
|
#include <leveldb/db.h> |
|
|
#include <leveldb/db.h> |
|
|
|
|
|
#pragma warning(pop) |
|
|
|
|
|
|
|
|
namespace eth |
|
|
namespace eth |
|
|
{ |
|
|
{ |
|
@ -17,7 +21,7 @@ public: |
|
|
typedef _T element_type; |
|
|
typedef _T element_type; |
|
|
|
|
|
|
|
|
vector_ref(): m_data(nullptr), m_count(0) {} |
|
|
vector_ref(): m_data(nullptr), m_count(0) {} |
|
|
vector_ref(_T* _data, unsigned _count): m_data(_data), m_count(_count) {} |
|
|
vector_ref(_T* _data, size_t _count): m_data(_data), m_count(_count) {} |
|
|
vector_ref(std::string* _data): m_data((_T*)_data->data()), m_count(_data->size() / sizeof(_T)) {} |
|
|
vector_ref(std::string* _data): m_data((_T*)_data->data()), m_count(_data->size() / sizeof(_T)) {} |
|
|
vector_ref(typename std::conditional<std::is_const<_T>::value, std::vector<typename std::remove_const<_T>::type> const*, std::vector<_T>*>::type _data): m_data(_data->data()), m_count(_data->size()) {} |
|
|
vector_ref(typename std::conditional<std::is_const<_T>::value, std::vector<typename std::remove_const<_T>::type> const*, std::vector<_T>*>::type _data): m_data(_data->data()), m_count(_data->size()) {} |
|
|
vector_ref(typename std::conditional<std::is_const<_T>::value, std::string const&, std::string&>::type _data): m_data((_T*)_data.data()), m_count(_data.size() / sizeof(_T)) {} |
|
|
vector_ref(typename std::conditional<std::is_const<_T>::value, std::string const&, std::string&>::type _data): m_data((_T*)_data.data()), m_count(_data.size() / sizeof(_T)) {} |
|
@ -31,11 +35,11 @@ public: |
|
|
template <class _T2> operator vector_ref<_T2>() const { assert(m_count * sizeof(_T) / sizeof(_T2) * sizeof(_T2) / sizeof(_T) == m_count); return vector_ref<_T2>((_T2*)m_data, m_count * sizeof(_T) / sizeof(_T2)); } |
|
|
template <class _T2> operator vector_ref<_T2>() const { assert(m_count * sizeof(_T) / sizeof(_T2) * sizeof(_T2) / sizeof(_T) == m_count); return vector_ref<_T2>((_T2*)m_data, m_count * sizeof(_T) / sizeof(_T2)); } |
|
|
|
|
|
|
|
|
_T* data() const { return m_data; } |
|
|
_T* data() const { return m_data; } |
|
|
unsigned count() const { return m_count; } |
|
|
size_t count() const { return m_count; } |
|
|
unsigned size() const { return m_count; } |
|
|
size_t size() const { return m_count; } |
|
|
unsigned empty() const { return !m_count; } |
|
|
bool empty() const { return !m_count; } |
|
|
vector_ref<_T> next() const { return vector_ref<_T>(m_data + m_count, m_count); } |
|
|
vector_ref<_T> next() const { return vector_ref<_T>(m_data + m_count, m_count); } |
|
|
vector_ref<_T> cropped(unsigned _begin, int _count = -1) const { if (m_data && _begin + std::max(0, _count) <= m_count) return vector_ref<_T>(m_data + _begin, _count < 0 ? m_count - _begin : _count); else return vector_ref<_T>(); } |
|
|
vector_ref<_T> cropped(size_t _begin, int _count = -1) const { if (m_data && _begin + std::max(0, _count) <= m_count) return vector_ref<_T>(m_data + _begin, _count < 0 ? m_count - _begin : _count); else return vector_ref<_T>(); } |
|
|
void retarget(_T const* _d, size_t _s) { m_data = _d; m_count = _s; } |
|
|
void retarget(_T const* _d, size_t _s) { m_data = _d; m_count = _s; } |
|
|
void retarget(std::vector<_T> const& _t) { m_data = _t.data(); m_count = _t.size(); } |
|
|
void retarget(std::vector<_T> const& _t) { m_data = _t.data(); m_count = _t.size(); } |
|
|
|
|
|
|
|
@ -44,8 +48,8 @@ public: |
|
|
_T const* begin() const { return m_data; } |
|
|
_T const* begin() const { return m_data; } |
|
|
_T const* end() const { return m_data + m_count; } |
|
|
_T const* end() const { return m_data + m_count; } |
|
|
|
|
|
|
|
|
_T& operator[](unsigned _i) { assert(m_data); assert(_i < m_count); return m_data[_i]; } |
|
|
_T& operator[](size_t _i) { assert(m_data); assert(_i < m_count); return m_data[_i]; } |
|
|
_T const& operator[](unsigned _i) const { assert(m_data); assert(_i < m_count); return m_data[_i]; } |
|
|
_T const& operator[](size_t _i) const { assert(m_data); assert(_i < m_count); return m_data[_i]; } |
|
|
|
|
|
|
|
|
bool operator==(vector_ref<_T> const& _cmp) const { return m_data == _cmp.m_data && m_count == _cmp.m_count; } |
|
|
bool operator==(vector_ref<_T> const& _cmp) const { return m_data == _cmp.m_data && m_count == _cmp.m_count; } |
|
|
bool operator!=(vector_ref<_T> const& _cmp) const { return !operator==(); } |
|
|
bool operator!=(vector_ref<_T> const& _cmp) const { return !operator==(); } |
|
@ -56,7 +60,7 @@ public: |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
_T* m_data; |
|
|
_T* m_data; |
|
|
unsigned m_count; |
|
|
size_t m_count; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
template<class _T> vector_ref<_T const> ref(_T const& _t) { return vector_ref<_T const>(&_t, 1); } |
|
|
template<class _T> vector_ref<_T const> ref(_T const& _t) { return vector_ref<_T const>(&_t, 1); } |
|
|