]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: enum: Add helpers for converting virTristate* to a plain bool
authorPeter Krempa <pkrempa@redhat.com>
Wed, 24 Nov 2021 13:48:12 +0000 (14:48 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 1 Dec 2021 12:39:47 +0000 (13:39 +0100)
The helpers will update the passed boolean if the tristate's value is
not _ABSENT.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virenum.c
src/util/virenum.h

index 76fed136cd223efde4bcaeea25e2509554a83525..cdf9ca49b8d7f4408fdea7afaa3b5cb2fc0c85cb 100644 (file)
@@ -2148,9 +2148,11 @@ ebtablesRemoveForwardAllowIn;
 virEnumFromString;
 virEnumToString;
 virTristateBoolFromBool;
+virTristateBoolToBool;
 virTristateBoolTypeFromString;
 virTristateBoolTypeToString;
 virTristateSwitchFromBool;
+virTristateSwitchToBool;
 virTristateSwitchTypeFromString;
 virTristateSwitchTypeToString;
 
index 26093bd795b4c9a62630a02ae1a03162e25be12b..103f00b524130d89cfbdc80253a71caf3af74cbe 100644 (file)
@@ -47,6 +47,33 @@ virTristateBoolFromBool(bool val)
 }
 
 
+/**
+ * virTristateBoolToBool:
+ * @t: a virTristateBool value
+ * @b: pointer to a boolean to be updated according to the value of @t
+ *
+ * The value pointed to by @b is updated if the tristate value @t is not absent.
+ */
+void
+virTristateBoolToBool(virTristateBool t,
+                      bool *b)
+{
+    switch (t) {
+    case VIR_TRISTATE_BOOL_YES:
+        *b = true;
+        break;
+
+    case VIR_TRISTATE_BOOL_NO:
+        *b = false;
+        break;
+
+    case VIR_TRISTATE_BOOL_ABSENT:
+    case VIR_TRISTATE_BOOL_LAST:
+        break;
+    }
+}
+
+
 virTristateSwitch
 virTristateSwitchFromBool(bool val)
 {
@@ -57,6 +84,33 @@ virTristateSwitchFromBool(bool val)
 }
 
 
+/**
+ * virTristateSwitchToBool:
+ * @t: a virTristateSwitch value
+ * @b: pointer to a boolean to be updated according to the value of @t
+ *
+ * The value pointed to by @b is updated if the tristate value @t is not absent.
+ */
+void
+virTristateSwitchToBool(virTristateSwitch t,
+                        bool *b)
+{
+    switch (t) {
+    case VIR_TRISTATE_SWITCH_ON:
+        *b = true;
+        break;
+
+    case VIR_TRISTATE_SWITCH_OFF:
+        *b = false;
+        break;
+
+    case VIR_TRISTATE_SWITCH_ABSENT:
+    case VIR_TRISTATE_SWITCH_LAST:
+        break;
+    }
+}
+
+
 int
 virEnumFromString(const char * const *types,
                   unsigned int ntypes,
index d74af355308cb74db3d874547929502a13b68226..98f01d574d794f3a30ab7400d74bf3d746b7e31c 100644 (file)
@@ -68,7 +68,9 @@ VIR_ENUM_DECL(virTristateBool);
 VIR_ENUM_DECL(virTristateSwitch);
 
 virTristateBool virTristateBoolFromBool(bool val);
+void virTristateBoolToBool(virTristateBool t, bool *b);
 virTristateSwitch virTristateSwitchFromBool(bool val);
+void virTristateSwitchToBool(virTristateSwitch t, bool *b);
 
 /* the two enums must be in sync to be able to use helpers interchangeably in
  * some special cases */