1 /** 2 * Copyright © Yurai Web Framework 2021 3 * License: MIT (https://github.com/YuraiWeb/yurai/blob/main/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module yurai.json.jsonobjectmember; 7 8 import yurai.json.jsonobject; 9 10 final class JsonObjectMember(S) 11 { 12 private: 13 alias JsonObject = Json!S; 14 15 size_t _index; 16 JsonObject _object; 17 S _key; 18 19 public: 20 this(S key, size_t index, JsonObject obj) 21 { 22 _key = key; 23 _index = index; 24 _object = obj; 25 } 26 27 @property 28 { 29 S key() { return _key; } 30 31 size_t index() { return _index; } 32 33 JsonObject obj() { return _object; } 34 } 35 36 override int opCmp(Object o) 37 { 38 auto obj = cast(JsonObjectMember!S)o; 39 40 if (!obj) 41 { 42 return -1; 43 } 44 45 if (obj._index == _index) 46 { 47 return 0; 48 } 49 50 if (obj._index > _index) 51 { 52 return -1; 53 } 54 55 return 1; 56 } 57 58 /// Operator overload. 59 override bool opEquals(Object o) 60 { 61 return opCmp(o) == 0; 62 } 63 }