[PATCH 1/6] util: enum: Add helpers for converting virTristate* to a plain bool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The helpers will update the passed boolean if the tristate's value is
not _ABSENT.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libvirt_private.syms |  2 ++
 src/util/virenum.c       | 54 ++++++++++++++++++++++++++++++++++++++++
 src/util/virenum.h       |  2 ++
 3 files changed, 58 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b98cb0f66d..49795e5b81 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2147,9 +2147,11 @@ ebtablesRemoveForwardAllowIn;
 virEnumFromString;
 virEnumToString;
 virTristateBoolFromBool;
+virTristateBoolToBool;
 virTristateBoolTypeFromString;
 virTristateBoolTypeToString;
 virTristateSwitchFromBool;
+virTristateSwitchToBool;
 virTristateSwitchTypeFromString;
 virTristateSwitchTypeToString;

diff --git a/src/util/virenum.c b/src/util/virenum.c
index 26093bd795..103f00b524 100644
--- a/src/util/virenum.c
+++ b/src/util/virenum.c
@@ -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,
diff --git a/src/util/virenum.h b/src/util/virenum.h
index d74af35530..98f01d574d 100644
--- a/src/util/virenum.h
+++ b/src/util/virenum.h
@@ -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 */
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux