mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: enum: Add helpers for converting virTristate* to a plain bool
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>
This commit is contained in:
parent
f17b9c57c5
commit
7489b5e37e
@ -2148,9 +2148,11 @@ ebtablesRemoveForwardAllowIn;
|
|||||||
virEnumFromString;
|
virEnumFromString;
|
||||||
virEnumToString;
|
virEnumToString;
|
||||||
virTristateBoolFromBool;
|
virTristateBoolFromBool;
|
||||||
|
virTristateBoolToBool;
|
||||||
virTristateBoolTypeFromString;
|
virTristateBoolTypeFromString;
|
||||||
virTristateBoolTypeToString;
|
virTristateBoolTypeToString;
|
||||||
virTristateSwitchFromBool;
|
virTristateSwitchFromBool;
|
||||||
|
virTristateSwitchToBool;
|
||||||
virTristateSwitchTypeFromString;
|
virTristateSwitchTypeFromString;
|
||||||
virTristateSwitchTypeToString;
|
virTristateSwitchTypeToString;
|
||||||
|
|
||||||
|
@ -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
|
virTristateSwitch
|
||||||
virTristateSwitchFromBool(bool val)
|
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
|
int
|
||||||
virEnumFromString(const char * const *types,
|
virEnumFromString(const char * const *types,
|
||||||
unsigned int ntypes,
|
unsigned int ntypes,
|
||||||
|
@ -68,7 +68,9 @@ VIR_ENUM_DECL(virTristateBool);
|
|||||||
VIR_ENUM_DECL(virTristateSwitch);
|
VIR_ENUM_DECL(virTristateSwitch);
|
||||||
|
|
||||||
virTristateBool virTristateBoolFromBool(bool val);
|
virTristateBool virTristateBoolFromBool(bool val);
|
||||||
|
void virTristateBoolToBool(virTristateBool t, bool *b);
|
||||||
virTristateSwitch virTristateSwitchFromBool(bool val);
|
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
|
/* the two enums must be in sync to be able to use helpers interchangeably in
|
||||||
* some special cases */
|
* some special cases */
|
||||||
|
Loading…
Reference in New Issue
Block a user