1 module uim.oop.mixins.properties.functional; 2 3 import std..string; 4 5 /// mixin for boolean properties 6 template OBool(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 7 const char[] OBool = ` 8 protected bool _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 9 `~(get ? `@safe @property auto `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 10 `~(set ? `@safe @property O `~propertyName~`(this O)(bool newValue) { _`~propertyName~` = newValue; return cast(O)this; }`: ``)~` 11 `; 12 } 13 14 template OBoolArray(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 15 const char[] OBoolArray = ` 16 protected bool[] _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 17 `~(get ? `@safe @property auto `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 18 `~(set ? `@safe @property O `~propertyName~`(this O)(bool[] newValue) { _`~propertyName~` = newValue; return cast(O)this; }`: ``)~` 19 `; 20 } 21 22 /// mixin for string properties 23 template OString(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 24 const char[] OString = ` 25 protected string _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 26 `~(get ? `@safe @property auto `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 27 `~(set ? `@safe @property O `~propertyName~`(this O)(string newValue) { _`~propertyName~`=newValue; return cast(O)this; }`: ``)~` 28 `; 29 } 30 31 template OStringAA(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 32 const char[] OStringAA = ` 33 protected string[string] _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 34 `~(get ? `@safe @property auto `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 35 `~(set ? ` 36 @safe @property O `~name~`(this O)(string key, string newValue) { _`~name~`[key] = newValue; return cast(O)this; }; 37 @safe @property O `~propertyName~`(this O)(string[string] newValue) { _`~propertyName~`=newValue; return cast(O)this; }`: ``)~` 38 `; 39 } 40 41 /// mixin for uuid properties 42 template OUuid(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 43 const char[] OUuid = ` 44 protected UUID _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 45 `~(get ? `@safe @property UUID `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 46 `~(set ? `@safe @property O `~propertyName~`(this O)(UUID newValue) { _`~propertyName~` = newValue; return cast(O)this; }`: ``)~` 47 `; 48 } 49 /// mixin for uuid properties 50 template OUuidArray(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 51 const char[] OUuidArray = ` 52 protected UUID[] _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 53 `~(get ? `@safe @property UUID[] `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 54 `~(set ? ` 55 @safe @property O `~name~`(this O)(UUID addValue) { _`~name~` ~= addValue; return cast(O)this; }; 56 @safe @property O `~propertyName~`(this O)(UUID[] newValue) { _`~propertyName~` = newValue; return cast(O)this; } 57 `: ``)~` 58 `; 59 } 60 /// mixin for uuid properties 61 template OUuidString(string propertyName, string defaultValue = null, bool get = true, bool set = true) { 62 const char[] OUuidString = ` 63 protected UUID[string] _`~propertyName~(defaultValue ? `=`~defaultValue:``)~`; 64 `~(get ? `@safe @property UUID[string] `~propertyName~`() { return _`~propertyName~`; }`: ``)~` 65 `~(set ? ` 66 @safe @property O `~name~`(this O)(string key, UUID newValue) { _`~name~`[key] = newValue; return cast(O)this; }; 67 @safe @property O `~propertyName~`(this O)(UUID[string] newValue) { _`~propertyName~` = newValue; return cast(O)this; } 68 `: ``)~` 69 `; 70 } 71 72 /// mixin for language string properties 73 template OLanguageString(string name, string defaultValue = null, bool get = true, bool set = true) { 74 const char[] OLanguageString = ` 75 protected string[string] _`~name~`; 76 `~(get ? `@safe @property string[string] `~name~`() { return _`~name~`; }`: ``)~` 77 `~(set ? ` 78 @safe @property O `~name~`(this O)(string defValue) { _`~name~`["default"] = defValue; return cast(O)this; } 79 @safe @property O `~name~`(this O)(string language, string langValue) { _`~name~`[language] = langValue; return cast(O)this; } 80 @safe @property O `~name~`(this O)(string[string] newValue) { _`~name~` = newValue; return cast(O)this; }`: ``)~` 81 `; 82 } 83 84 /// mixin for object id properties 85 template OObjectId(string name, string defaultValue = null, bool get = true, bool set = true) { 86 const char[] OObjectId = ` 87 protected string[UUID] _`~name~`; 88 `~(get ? `@safe @property string[UUID] `~name~`() { return _`~name~`; }`: ``)~` 89 `~(set ? `@safe @property O `~name~`(this O)(string[UUID] newValue) { _`~name~` = newValue; return cast(O)this; }`: ``)~` 90 `; 91 } 92 93 /// mixin for object Ids properties - etag[UUID] 94 template OObjectIds(string name, string defaultValue = null, bool get = true, bool set = true) { 95 const char[] OObjectIds = ` 96 protected string[UUID] _`~name~`; 97 `~(get ? `@safe @property string[UUID] `~name~`() { return _`~name~`; }`: ``)~` 98 `~(set ? `@safe @property O `~name~`(this O)(string[UUID] newValue) { _`~name~` = newValue; return cast(O)this; }`: ``)~` 99 `; 100 } 101 102 /// mixin for uuid properties 103 template OTimestamp(string name, string defaultValue = null, bool get = true, bool set = true) { 104 const char[] OTimestamp = ` 105 protected size_t _`~name~`; 106 `~(get ? `@safe @property size_t `~name~`() { return _`~name~`; }`: ``)~` 107 `~(set ? `@safe @property O `~name~`(this O)(size_t newValue) { _`~name~` = newValue; return cast(O)this; }`: ``)~` 108 `; 109 } 110 111 /// mixin for uuid properties 112 template OCounter(string name, string defaultValue = null, bool get = true, bool set = true) { 113 const char[] OCounter = ` 114 protected size_t _`~name~`; 115 `~(get ? `@safe @property size_t `~name~`() { return _`~name~`; }`: ``)~` 116 `~(set ? ` 117 @safe @property O dec`~name.capitalize~`(this O)() { _`~name~`--; return cast(O)this; } 118 @safe @property O inc`~name.capitalize~`(this O)() { _`~name~`++; return cast(O)this; } 119 @safe @property O `~name~`(this O)(size_t newValue) { _`~name~` = newValue; return cast(O)this; } 120 `: ``)~` 121 `; 122 }