path.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef PATH_H
  2. #define PATH_H
  3. #include "../variables/variable.h"
  4. namespace binom {
  5. enum class PathNodeType : ui8 {
  6. index,
  7. name
  8. };
  9. class Path {
  10. public:
  11. class PathLiteral;
  12. class PathNode;
  13. class iterator;
  14. private:
  15. ByteArray data;
  16. bool isValid();
  17. Path(ByteArray data);
  18. public:
  19. Path(std::initializer_list<PathLiteral> path);
  20. Path();
  21. Path(const Path& other);
  22. Path(Path&& other);
  23. inline Path& operator=(const Path& other) {this->~Path(); return *new(this) Path(other);}
  24. inline Path& operator=(Path&& other) {this->~Path(); return *new(this) Path(std::move(other));}
  25. bool isEmpty() const;
  26. bool operator==(const Path& other) const;
  27. inline bool operator!=(const Path& other) const {return !(*this == other);}
  28. Path& pushBack(BufferArray name);
  29. Path& pushBack(ui64 index);
  30. inline Path& operator+=(BufferArray name) {return pushBack(std::move(name));}
  31. inline Path& operator+=(ui64 index) {return pushBack(index);}
  32. inline Path operator+(BufferArray name) {return Path(*this).pushBack(std::move(name));}
  33. inline Path operator+(ui64 index) {return Path(*this).pushBack(index);}
  34. iterator begin() const;
  35. iterator end() const;
  36. ByteArray toByteArray() const;
  37. std::string toString() const;
  38. static Path fromByteArray(ByteArray path);
  39. static Path fromString(std::string str);
  40. };
  41. class Path::PathLiteral{
  42. PathNodeType type;
  43. union PathLiteralValue {
  44. ui64 index;
  45. BufferArray string;
  46. PathLiteralValue(ui64 index) : index(index) {}
  47. PathLiteralValue(const BufferArray& string) : string(std::move(string)) {}
  48. PathLiteralValue(BufferArray&& string) : string(std::move(string)) {}
  49. ~PathLiteralValue() {}
  50. } value;
  51. friend class Path;
  52. public:
  53. PathLiteral(ui64 index);
  54. PathLiteral(int index);
  55. PathLiteral(ui8arr byte_array);
  56. PathLiteral(i8arr byte_array);
  57. PathLiteral(ui16arr word_array);
  58. PathLiteral(i16arr word_array);
  59. PathLiteral(ui32arr dword_array);
  60. PathLiteral(i32arr dword_array);
  61. PathLiteral(ui64arr qword_array);
  62. PathLiteral(i64arr qword_array);
  63. PathLiteral(BufferArray string);
  64. PathLiteral(const char* string);
  65. PathLiteral(const PathLiteral& other) = delete;
  66. PathLiteral(PathLiteral&& other) = delete;
  67. ~PathLiteral();
  68. };
  69. class Path::PathNode {
  70. PathNodeType* ptr;
  71. public:
  72. PathNode(void* ptr);
  73. PathNodeType type() const;
  74. ui64 index() const;
  75. BufferArray name() const;
  76. };
  77. class Path::iterator {
  78. friend class Path;
  79. PathNodeType* ptr;
  80. public:
  81. iterator(void* ptr);
  82. iterator(iterator& other);
  83. iterator(iterator&& other);
  84. PathNode& operator*();
  85. PathNode* operator->();
  86. iterator& operator++();
  87. iterator operator++(int);
  88. bool operator==(iterator other);
  89. bool operator!=(iterator other);
  90. bool operator>(iterator other);
  91. bool operator>=(iterator other);
  92. bool operator<(iterator other);
  93. bool operator<=(iterator other);
  94. };
  95. //Path operator""_pth(const char* str, size_t);
  96. }
  97. #endif // PATH_H