提交 d868366f 编写于 作者: P Peter Krempa

util: Add functions to simplify bool->virTristate(Bool|Switch) assignment

virTristateBoolFromBool and virTristateSwitchFromBool convert a boolean
to the correct enum value.
上级 8ffbc1f7
......@@ -2950,8 +2950,10 @@ virSetNonBlock;
virSetSockReuseAddr;
virSetUIDGID;
virSetUIDGIDWithCaps;
virTristateBoolFromBool;
virTristateBoolTypeFromString;
virTristateBoolTypeToString;
virTristateSwitchFromBool;
virTristateSwitchTypeFromString;
virTristateSwitchTypeToString;
virUpdateSelfLastChanged;
......
......@@ -100,6 +100,26 @@ VIR_ENUM_IMPL(virTristateSwitch, VIR_TRISTATE_SWITCH_LAST,
"off")
virTristateBool
virTristateBoolFromBool(bool val)
{
if (val)
return VIR_TRISTATE_BOOL_YES;
else
return VIR_TRISTATE_BOOL_NO;
}
virTristateSwitch
virTristateSwitchFromBool(bool val)
{
if (val)
return VIR_TRISTATE_SWITCH_ON;
else
return VIR_TRISTATE_SWITCH_OFF;
}
#ifndef WIN32
int virSetInherit(int fd, bool inherit)
......
......@@ -193,6 +193,9 @@ typedef enum {
VIR_ENUM_DECL(virTristateBool)
VIR_ENUM_DECL(virTristateSwitch)
virTristateBool virTristateBoolFromBool(bool val);
virTristateSwitch virTristateSwitchFromBool(bool val);
/* the two enums must be in sync to be able to use helpers interchangeably in
* some special cases */
verify((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册