28 #include <unordered_set>
38 #include <boost/filesystem.hpp>
44 std::string
getPassword(std::string
const& _prompt);
59 void writeFile(boost::filesystem::path
const& _file,
bytesConstRef _data,
bool _writeDeleteRename =
false);
65 void copyDirectory(boost::filesystem::path
const& _srcDir, boost::filesystem::path
const& _dstDir);
69 std::string
memDump(
bytes const& _bytes,
unsigned _width = 8,
bool _html =
false);
74 template <
class T>
struct StreamOut {
static std::ostream&
bypass(std::ostream& _out, T
const& _t) { _out << _t;
return _out; } };
75 template <>
struct StreamOut<uint8_t> {
static std::ostream&
bypass(std::ostream& _out, uint8_t
const& _t) { _out << (int)_t;
return _out; } };
78 template <
class T>
inline std::ostream&
operator<<(std::ostream& _out, std::vector<T>
const& _e);
79 template <
class T, std::
size_t Z>
inline std::ostream&
operator<<(std::ostream& _out, std::array<T, Z>
const& _e);
80 template <
class T,
class U>
inline std::ostream&
operator<<(std::ostream& _out, std::set<T, U>
const& _e);
81 template <
class T,
class U>
inline std::ostream&
operator<<(std::ostream& _out, std::unordered_set<T, U>
const& _e);
84 template <
class T>
inline std::string
toString(std::chrono::time_point<T>
const& _e, std::string
const& _format =
"%Y-%m-%d %H:%M:%S")
86 template <
class T>
inline std::string
toString(std::chrono::time_point<T>
const& _e, std::string
const& _format =
"%F %T")
89 unsigned long milliSecondsSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(_e.time_since_epoch()).count();
90 auto const durationSinceEpoch = std::chrono::milliseconds(milliSecondsSinceEpoch);
91 std::chrono::time_point<std::chrono::system_clock>
const tpAfterDuration(durationSinceEpoch);
94 auto time = std::chrono::system_clock::to_time_t(tpAfterDuration);
96 gmtime_s(&timeValue, &time);
98 gmtime_r(&time, &timeValue);
101 unsigned const millisRemainder = milliSecondsSinceEpoch % 1000;
103 if (strftime(buffer,
sizeof(buffer), _format.c_str(), &timeValue))
104 return std::string(buffer) +
"." + (millisRemainder < 1 ?
"000" : millisRemainder < 10 ?
"00" : millisRemainder < 100 ?
"0" :
"") + std::to_string(millisRemainder) +
"Z";
105 return std::string();
109 inline std::ostream&
streamout(std::ostream& _out, std::vector<T>
const& _e)
115 for (
auto i = ++_e.begin(); i != _e.end(); ++i)
122 template <
class T>
inline std::ostream&
operator<<(std::ostream& _out, std::vector<T>
const& _e) {
streamout(_out, _e);
return _out; }
124 template <
class T, std::
size_t Z>
125 inline std::ostream&
streamout(std::ostream& _out, std::array<T, Z>
const& _e)
132 for (++i; i != _e.end(); ++i)
138 template <
class T, std::
size_t Z>
inline std::ostream&
operator<<(std::ostream& _out, std::array<T, Z>
const& _e) {
streamout(_out, _e);
return _out; }
141 std::ostream&
streamout(std::ostream& _out, std::set<T>
const& _v)
147 _out << (!(i++) ?
"{ " :
", ") << p;
150 template <
class T>
inline std::ostream&
operator<<(std::ostream& _out, std::set<T>
const& _e) {
streamout(_out, _e);
return _out; }
153 std::ostream&
streamout(std::ostream& _out, std::unordered_set<T>
const& _v)
159 _out << (!(i++) ?
"{ " :
", ") << p;
162 template <
class T>
inline std::ostream&
operator<<(std::ostream& _out, std::unordered_set<T>
const& _e) {
streamout(_out, _e);
return _out; }
170 std::ostringstream o;
176 inline std::string toString<std::string>(std::string
const& _s)
184 std::ostringstream o;
185 o << static_cast<uint16_t>(_u);