Browse Source

Compile and warning fixes for Visual Studio 2013 and x64

cl-refactor
Tim Hughes 11 years ago
parent
commit
3c4635c81d
  1. 5
      libethereum/Common.h
  2. 6
      libethereum/Dagger.cpp
  3. 20
      libethereum/vector_ref.h

5
libethereum/Common.h

@ -190,9 +190,8 @@ bytes toHex(std::string const& _s);
template <class _T, class _Out> template <class _T, class _Out>
inline void toBigEndian(_T _val, _Out& o_out) inline void toBigEndian(_T _val, _Out& o_out)
{ {
auto s = o_out.size(); for (auto i = o_out.size(); i-- != 0; _val >>= 8)
for (uint i = 0; i < s; ++i, _val >>= 8) o_out[i] = (typename _Out::value_type)(uint8_t)_val;
o_out[s - 1 - i] = (typename _Out::value_type)(uint8_t)_val;
} }
/// Converts a big-endian byte-stream represented on a templated collection to a templated integer value. /// Converts a big-endian byte-stream represented on a templated collection to a templated integer value.

6
libethereum/Dagger.cpp

@ -7,7 +7,9 @@
#include "Dagger.h" #include "Dagger.h"
using namespace std; using namespace std;
using namespace std::chrono; using namespace std::chrono;
using namespace eth;
namespace eth
{
Dagger::Dagger(h256 _hash): m_hash(_hash) Dagger::Dagger(h256 _hash): m_hash(_hash)
{ {
@ -93,3 +95,5 @@ u256 Dagger::eval(u256 _N)
} }
return get(bsha); return get(bsha);
} }
}

20
libethereum/vector_ref.h

@ -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); }

Loading…
Cancel
Save