json_cast.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "json_cast.hpp"
  2. #include <iostream>
  3. #include <string>
  4. namespace mature {
  5. template<typename T>
  6. void print_type() {
  7. std::cout << "unkown" << std::endl;
  8. }
  9. template<>
  10. void print_type<char>() {
  11. std::cout << "char" << std::endl;
  12. }
  13. template<>
  14. void print_type<wchar_t>() {
  15. std::cout << "wchar_t" << std::endl;
  16. }
  17. template<>
  18. void print_type<unsigned char>() {
  19. std::cout << "UTF8CHAR" << std::endl;
  20. }
  21. template<>
  22. void print_type<unsigned short int>() {
  23. std::cout << "uint16_t" << std::endl;
  24. }
  25. template<>
  26. void print_type<unsigned int>() {
  27. std::cout << "uint32_t" << std::endl;
  28. }
  29. FString GetString(const Value& ValueRef) {
  30. switch (ValueRef.GetType())
  31. {
  32. case mature::Type::kFalseType: return TEXT("false");
  33. case mature::Type::kTrueType: return TEXT("true");
  34. case mature::Type::kNumberType: return FString::SanitizeFloat(mature::GetNumber<float>(ValueRef), 0);
  35. case mature::Type::kStringType: return FString(ValueRef.GetString());
  36. }
  37. return FString();
  38. }
  39. bool GetStringBool(const Value& ValueRef, FString& value) {
  40. switch (ValueRef.GetType())
  41. {
  42. case mature::Type::kFalseType: value = TEXT("false"); break;
  43. case mature::Type::kTrueType: value = TEXT("true"); break;
  44. case mature::Type::kNumberType: value = FString::SanitizeFloat(mature::GetNumber<float>(ValueRef), 0); break;
  45. case mature::Type::kStringType: value = FString(ValueRef.GetString()); break;
  46. default: return false;
  47. }
  48. return true;
  49. }
  50. FString GetStringArray(const unsigned int idx, const Array& ArrayRef) {
  51. if (ArrayRef.Size() < idx)return FString();
  52. return GetString(ArrayRef[idx]);
  53. }
  54. }