summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-bitutil/flag.tpl
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-08 19:49:45 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-08 18:49:45 +0100
commit5004e0a9da665ccc0e18cd4075ee636641b71f0a (patch)
treeb7c8269b954ced61afa9fffd7305bd88acca6f8e /vendor/codeberg.org/gruf/go-bitutil/flag.tpl
parent[bugfix] Fix existing bio text showing as HTML (#531) (diff)
downloadgotosocial-5004e0a9da665ccc0e18cd4075ee636641b71f0a.tar.xz
[bugfix] Fix remote media pruning failing if media already gone (#548)
* fix error check of prune to allow missing files * update go-store library, add test for pruning item with db entry but no file Signed-off-by: kim <grufwub@gmail.com> * remove now-unneccessary error check Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-bitutil/flag.tpl')
-rw-r--r--vendor/codeberg.org/gruf/go-bitutil/flag.tpl94
1 files changed, 94 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-bitutil/flag.tpl b/vendor/codeberg.org/gruf/go-bitutil/flag.tpl
new file mode 100644
index 000000000..80912e24d
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-bitutil/flag.tpl
@@ -0,0 +1,94 @@
+package bitutil
+
+import (
+ "strings"
+
+ "codeberg.org/gruf/go-bytes"
+)
+
+{{ range $idx, $size := . }}
+
+// Flags{{ $size.Size }} is a type-casted unsigned integer with helper
+// methods for easily managing up to {{ $size.Size }} bit flags.
+type Flags{{ $size.Size }} uint{{ $size.Size }}
+
+// Get will fetch the flag bit value at index 'bit'.
+func (f Flags{{ $size.Size }}) Get(bit uint8) bool {
+ mask := Flags{{ $size.Size }}(1) << bit
+ return (f & mask != 0)
+}
+
+// Set will set the flag bit value at index 'bit'.
+func (f Flags{{ $size.Size }}) Set(bit uint8) Flags{{ $size.Size }} {
+ mask := Flags{{ $size.Size }}(1) << bit
+ return f | mask
+}
+
+// Unset will unset the flag bit value at index 'bit'.
+func (f Flags{{ $size.Size }}) Unset(bit uint8) Flags{{ $size.Size }} {
+ mask := Flags{{ $size.Size }}(1) << bit
+ return f & ^mask
+}
+
+{{ range $idx := $size.Bits }}
+
+// Get{{ $idx }} will fetch the flag bit value at index {{ $idx }}.
+func (f Flags{{ $size.Size }}) Get{{ $idx }}() bool {
+ const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
+ return (f & mask != 0)
+}
+
+// Set{{ $idx }} will set the flag bit value at index {{ $idx }}.
+func (f Flags{{ $size.Size }}) Set{{ $idx }}() Flags{{ $size.Size }} {
+ const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
+ return f | mask
+}
+
+// Unset{{ $idx }} will unset the flag bit value at index {{ $idx }}.
+func (f Flags{{ $size.Size }}) Unset{{ $idx }}() Flags{{ $size.Size }} {
+ const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
+ return f & ^mask
+}
+
+{{ end }}
+
+// String returns a human readable representation of Flags{{ $size.Size }}.
+func (f Flags{{ $size.Size }}) String() string {
+ var val bool
+ var buf bytes.Buffer
+
+ buf.WriteByte('{')
+ {{ range $idx := .Bits }}
+ val = f.Get{{ $idx }}()
+ buf.WriteString(bool2str(val) + " ")
+ {{ end }}
+ buf.Truncate(1)
+ buf.WriteByte('}')
+
+ return buf.String()
+}
+
+// GoString returns a more verbose human readable representation of Flags{{ $size.Size }}.
+func (f Flags{{ $size.Size }})GoString() string {
+ var val bool
+ var buf bytes.Buffer
+
+ buf.WriteString("bitutil.Flags{{ $size.Size }}{")
+ {{ range $idx := .Bits }}
+ val = f.Get{{ $idx }}()
+ buf.WriteString("{{ $idx }}="+bool2str(val)+" ")
+ {{ end }}
+ buf.Truncate(1)
+ buf.WriteByte('}')
+
+ return buf.String()
+}
+
+{{ end }}
+
+func bool2str(b bool) string {
+ if b {
+ return "true"
+ }
+ return "false"
+} \ No newline at end of file