object.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef OBJECT_H
  2. #define OBJECT_H
  3. #include "../utils/types.h"
  4. #include "../utils/var_mem_mngr.h"
  5. #include "variable.h"
  6. namespace binom {
  7. class Object : VarMemoryManager<Object> {
  8. friend class VarMemoryManager<Object>;
  9. friend class Variable;
  10. union types {
  11. void* ptr;
  12. VarType* type;
  13. byte* bytes;
  14. types(void* ptr) : ptr(ptr) {}
  15. } data;
  16. inline ui64& length() const {return *reinterpret_cast<ui64*>(data.bytes + 1);}
  17. inline byte*& ptrImpl() {return data.bytes;}
  18. ui64 msizeImpl() const;
  19. void* cloneImpl() const;
  20. void destroyImpl();
  21. public:
  22. Object();
  23. Object(vobj object);
  24. Object(const Object& other) : data(other.clone()) {}
  25. Object(Object&& other) : data(other.data.ptr) {other.data.ptr = nullptr;}
  26. ~Object() {destroy ();}
  27. ByteArray serialize() const;
  28. static Object deserialize(ByteArray::iterator& it);
  29. inline bool isEmpty() const {return !length();}
  30. inline ui64 getMemberCount() const {return *reinterpret_cast<ui64*>(data.bytes + 1);}
  31. bool contains(BufferArray name) const;
  32. Variable& insert(BufferArray name, Variable var);
  33. void remove(BufferArray name);
  34. BufferArray& rename(BufferArray old_name, BufferArray new_name);
  35. Object& operator=(Object other);
  36. Object& operator+=(NamedVariable named_variable);
  37. Object& operator+=(Object other);
  38. bool operator==(Object other) const;
  39. bool operator!=(Object other) const;
  40. bool operator<(Object other) const;
  41. bool operator<=(Object other) const;
  42. bool operator>(Object other) const;
  43. bool operator>=(Object other) const;
  44. i8 getCompare(Object other) const;
  45. NamedVariable& getNamedVariable(BufferArray name) const;
  46. Variable& getVariable(BufferArray name) const;
  47. inline Variable& operator[](BufferArray name) const {return getVariable(std::move(name));}
  48. ObjectIterator begin() const {return reinterpret_cast<ObjectIterator>(data.bytes + 9);}
  49. ObjectIterator end() const {return reinterpret_cast<ObjectIterator>(data.bytes + msize());}
  50. Array getNameArray();
  51. Array getMemberArray();
  52. Variable& asVar() {return *reinterpret_cast<Variable*>(this);}
  53. };
  54. }
  55. #endif