conversion.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <string>
  3. #include "define.h"
  4. #include "base/buffer.h"
  5. namespace ylib
  6. {
  7. int32 stoi(const std::string& value);
  8. int32 stoi(char value);
  9. uint64 stoull(const std::string& value);
  10. int64 stoll(const std::string& value);
  11. double stod(const std::string& value);
  12. float stof(const std::string& value);
  13. //保留小数点
  14. std::string to_fixed(double num, uint32 x);
  15. namespace bytes{
  16. /*流转*/
  17. void to_int(int32& dest, const char* src, bool reverse = false);
  18. void to_uint(uint32& dest, const char* src, bool reverse = false);
  19. void to_short(short& dest, const char* src, bool reverse = false);
  20. void to_ushort(ushort& dest, const char* src, bool reverse = false);
  21. void to_char(char* dest, short src, bool reverse = false);
  22. void to_char(char* dest, int32 src, bool reverse = false);
  23. void to_char(char* dest, int64 src, bool reverse = false);
  24. ylib::buffer to_buffer(short src, bool reverse = false);
  25. ylib::buffer to_buffer(int32 src, bool reverse = false);
  26. ylib::buffer to_buffer(int64 src, bool reverse = false);
  27. ylib::buffer to_buffer(uchar src);
  28. // 反转
  29. void reverse(void* dest, size_t length);
  30. void to_uint64(uint64& dest, const char* src, bool reverse = false);
  31. void to_int64(int64& dest, const char* src, bool reverse = false);
  32. }
  33. }