#include <map>
#include <vector>
#include <string>
+#include <chrono>
+#include <thread>
#ifndef Q_MOC_RUN
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
-#include <boost/date_time/gregorian/gregorian_types.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
#endif
#include <stdarg.h>
static const int32_t nOneHour = 60 * 60;
static const int32_t nOneDay = 24 * 60 * 60;
+static const int64_t nOneWeek = 7 * 24 * 60 * 60;
static const int64_t COIN = 1000000;
static const int64_t CENT = 10000;
#define END(a) ((char*)&((&(a))[1]))
#define UBEGIN(a) ((unsigned char*)&(a))
#define UEND(a) ((unsigned char*)&((&(a))[1]))
-#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
-
-#define UVOIDBEGIN(a) ((void*)&(a))
-#define CVOIDBEGIN(a) ((const void*)&(a))
-#define UINTBEGIN(a) ((uint32_t*)&(a))
-#define CUINTBEGIN(a) ((const uint32_t*)&(a))
#ifndef THROW_WITH_STACKTRACE
#define THROW_WITH_STACKTRACE(exception) \
#define PRIpdd "td"
#endif
-// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
-#define PAIRTYPE(t1, t2) std::pair<t1, t2>
-
// Align by increasing pointer, must have extra space at end of buffer
template <size_t nBytes, typename T>
T* alignup(T* p)
#define MAX_PATH 1024
inline void Sleep(int64_t n)
{
- /*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
- So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
- boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
+ this_thread::sleep_for(std::chrono::milliseconds(n));
}
#endif
std::string FormatMoney(int64_t n, bool fPlus=false);
bool ParseMoney(const std::string& str, int64_t& nRet);
bool ParseMoney(const char* pszIn, int64_t& nRet);
-std::vector<unsigned char> ParseHex(const char* psz);
-std::vector<unsigned char> ParseHex(const std::string& str);
+std::vector<uint8_t> ParseHex(const char *str);
+inline std::vector<uint8_t> ParseHex(const std::string& str) { return ParseHex(str.c_str()); }
bool IsHex(const std::string& str);
std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL);
std::string DecodeBase64(const std::string& str);
int GetRandInt(int nMax);
uint64_t GetRand(uint64_t nMax);
uint256 GetRandHash();
+void FillRand(uint8_t *buffer, size_t nCount);
int64_t GetTime();
-void SetMockTime(int64_t nMockTimeIn);
+int64_t GetTimeMillis();
+int64_t GetTimeMicros();
+
int64_t GetAdjustedTime();
int64_t GetTimeOffset();
int64_t GetNodesOffset();
-
-
-
-
inline std::string i64tostr(int64_t n)
{
return strprintf("%" PRId64, n);
}
-inline std::string itostr(int n)
-{
- return strprintf("%d", n);
-}
-
-inline int64_t atoi64(const char* psz)
+inline int64_t strtoll(const char* psz)
{
-#ifdef _MSC_VER
- return _atoi64(psz);
-#else
return strtoll(psz, NULL, 10);
-#endif
}
-inline int64_t atoi64(const std::string& str)
+inline int64_t strtoll(const std::string& str)
{
-#ifdef _MSC_VER
- return _atoi64(str.c_str());
-#else
return strtoll(str.c_str(), NULL, 10);
-#endif
}
inline int32_t strtol(const char* psz)
return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
}
-inline int64_t abs64(int64_t n)
-{
- return (n >= 0 ? n : -n);
-}
-
inline std::string leftTrim(std::string src, char chr)
{
std::string::size_type pos = src.find_first_not_of(chr, 0);
inline int64_t GetTimeMillis()
{
- return (boost::posix_time::microsec_clock::universal_time() -
- boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
+ return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
+}
+
+inline int64_t GetTimeMicros()
+{
+ return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);
T median() const
{
- int size = vSorted.size();
+ size_t size = vSorted.size();
assert(size>0);
if(size & 1) // Odd number of elements
{