github.com/Aoi-hosizora/ahlib@v1.5.1-0.20230404072829-241b93cf91c7/xpointer/xpointer.go (about) 1 package xpointer 2 3 // =========== 4 // ptr related 5 // =========== 6 7 // BoolPtr returns a pointer pointed to given bool value. 8 func BoolPtr(v bool) *bool { 9 return &v 10 } 11 12 // StringPtr returns a pointer pointed to given string value. 13 func StringPtr(v string) *string { 14 return &v 15 } 16 17 // IntPtr returns a pointer pointed to given int value. 18 func IntPtr(v int) *int { 19 return &v 20 } 21 22 // Int8Ptr returns a pointer pointed to given int8 value. 23 func Int8Ptr(v int8) *int8 { 24 return &v 25 } 26 27 // Int16Ptr returns a pointer pointed to given int16 value. 28 func Int16Ptr(v int16) *int16 { 29 return &v 30 } 31 32 // Int32Ptr returns a pointer pointed to given int32 value. 33 func Int32Ptr(v int32) *int32 { 34 return &v 35 } 36 37 // Int64Ptr returns a pointer pointed to given int64 value. 38 func Int64Ptr(v int64) *int64 { 39 return &v 40 } 41 42 // UintPtr returns a pointer pointed to given uint value. 43 func UintPtr(v uint) *uint { 44 return &v 45 } 46 47 // Uint8Ptr returns a pointer pointed to given uint8 value. 48 func Uint8Ptr(v uint8) *uint8 { 49 return &v 50 } 51 52 // Uint16Ptr returns a pointer pointed to given uint16 value. 53 func Uint16Ptr(v uint16) *uint16 { 54 return &v 55 } 56 57 // Uint32Ptr returns a pointer pointed to given uint32 value. 58 func Uint32Ptr(v uint32) *uint32 { 59 return &v 60 } 61 62 // Uint64Ptr returns a pointer pointed to given uint64 value. 63 func Uint64Ptr(v uint64) *uint64 { 64 return &v 65 } 66 67 // Float32Ptr returns a pointer pointed to given float32 value. 68 func Float32Ptr(v float32) *float32 { 69 return &v 70 } 71 72 // Float64Ptr returns a pointer pointed to given float64 value. 73 func Float64Ptr(v float64) *float64 { 74 return &v 75 } 76 77 // Complex64Ptr returns a pointer pointed to given complex64 value. 78 func Complex64Ptr(v complex64) *complex64 { 79 return &v 80 } 81 82 // Complex128Ptr returns a pointer pointed to given complex128 value. 83 func Complex128Ptr(v complex128) *complex128 { 84 return &v 85 } 86 87 // BytePtr returns a pointer pointed to given byte value. 88 func BytePtr(v byte) *byte { 89 return &v 90 } 91 92 // RunePtr returns a pointer pointed to given rune value. 93 func RunePtr(v rune) *rune { 94 return &v 95 } 96 97 // =========== 98 // val related 99 // =========== 100 101 // BoolVal returns a bool value from given pointer, returns the fallback value when nil. 102 func BoolVal(p *bool, o bool) bool { 103 if p == nil { 104 return o 105 } 106 return *p 107 } 108 109 // StringVal returns a string value from given pointer, returns the fallback value when nil. 110 func StringVal(p *string, o string) string { 111 if p == nil { 112 return o 113 } 114 return *p 115 } 116 117 // IntVal returns an int value from given pointer, returns the fallback value when nil. 118 func IntVal(p *int, o int) int { 119 if p == nil { 120 return o 121 } 122 return *p 123 } 124 125 // Int8Val returns an int8 value from given pointer, returns the fallback value when nil. 126 func Int8Val(p *int8, o int8) int8 { 127 if p == nil { 128 return o 129 } 130 return *p 131 } 132 133 // Int16Val returns an int16 value from given pointer, returns the fallback value when nil. 134 func Int16Val(p *int16, o int16) int16 { 135 if p == nil { 136 return o 137 } 138 return *p 139 } 140 141 // Int32Val returns an int32 value from given pointer, returns the fallback value when nil. 142 func Int32Val(p *int32, o int32) int32 { 143 if p == nil { 144 return o 145 } 146 return *p 147 } 148 149 // Int64Val returns an int64 value from given pointer, returns the fallback value when nil. 150 func Int64Val(p *int64, o int64) int64 { 151 if p == nil { 152 return o 153 } 154 return *p 155 } 156 157 // UintVal returns an uint value from given pointer, returns the fallback value when nil. 158 func UintVal(p *uint, o uint) uint { 159 if p == nil { 160 return o 161 } 162 return *p 163 } 164 165 // Uint8Val returns an uint8 value from given pointer, returns the fallback value when nil. 166 func Uint8Val(p *uint8, o uint8) uint8 { 167 if p == nil { 168 return o 169 } 170 return *p 171 } 172 173 // Uint16Val returns an uint16 value from given pointer, returns the fallback value when nil. 174 func Uint16Val(p *uint16, o uint16) uint16 { 175 if p == nil { 176 return o 177 } 178 return *p 179 } 180 181 // Uint32Val returns an uint32 value from given pointer, returns the fallback value when nil. 182 func Uint32Val(p *uint32, o uint32) uint32 { 183 if p == nil { 184 return o 185 } 186 return *p 187 } 188 189 // Uint64Val returns an uint64 value from given pointer, returns the fallback value when nil. 190 func Uint64Val(p *uint64, o uint64) uint64 { 191 if p == nil { 192 return o 193 } 194 return *p 195 } 196 197 // Float32Val returns a float32 value from given pointer, returns the fallback value when nil. 198 func Float32Val(p *float32, o float32) float32 { 199 if p == nil { 200 return o 201 } 202 return *p 203 } 204 205 // Float64Val returns a float64 value from given pointer, returns the fallback value when nil. 206 func Float64Val(p *float64, o float64) float64 { 207 if p == nil { 208 return o 209 } 210 return *p 211 } 212 213 // Complex64Val returns a complex64 value from given pointer, returns the fallback value when nil. 214 func Complex64Val(p *complex64, o complex64) complex64 { 215 if p == nil { 216 return o 217 } 218 return *p 219 } 220 221 // Complex128Val returns a complex128 value from given pointer, returns the fallback value when nil. 222 func Complex128Val(p *complex128, o complex128) complex128 { 223 if p == nil { 224 return o 225 } 226 return *p 227 } 228 229 // ByteVal returns a byte value from given pointer, returns the fallback value when nil. 230 func ByteVal(p *byte, o byte) byte { 231 if p == nil { 232 return o 233 } 234 return *p 235 } 236 237 // RuneVal returns a rune value from given pointer, returns the fallback value when nil. 238 func RuneVal(p *rune, o rune) rune { 239 if p == nil { 240 return o 241 } 242 return *p 243 }