2019-04-01 10:14:26 +00:00
|
|
|
/*
|
|
|
|
* virenum.h: enum value conversion helpers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#pragma once
|
2019-04-01 10:14:26 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#include "internal.h"
|
2019-04-01 10:14:26 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
virEnumFromString(const char * const *types,
|
|
|
|
unsigned int ntypes,
|
|
|
|
const char *type);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
virEnumToString(const char * const *types,
|
|
|
|
unsigned int ntypes,
|
|
|
|
int type);
|
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#define VIR_ENUM_IMPL(name, lastVal, ...) \
|
2019-04-01 10:14:26 +00:00
|
|
|
static const char *const name ## TypeList[] = { __VA_ARGS__ }; \
|
|
|
|
const char *name ## TypeToString(int type) { \
|
|
|
|
return virEnumToString(name ## TypeList, \
|
2019-10-15 11:55:26 +00:00
|
|
|
G_N_ELEMENTS(name ## TypeList), \
|
2019-04-01 10:14:26 +00:00
|
|
|
type); \
|
|
|
|
} \
|
|
|
|
int name ## TypeFromString(const char *type) { \
|
|
|
|
return virEnumFromString(name ## TypeList, \
|
2019-10-15 11:55:26 +00:00
|
|
|
G_N_ELEMENTS(name ## TypeList), \
|
2019-04-01 10:14:26 +00:00
|
|
|
type); \
|
|
|
|
} \
|
2020-01-09 10:39:55 +00:00
|
|
|
G_STATIC_ASSERT(G_N_ELEMENTS(name ## TypeList) == lastVal)
|
2019-04-01 10:14:26 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#define VIR_ENUM_DECL(name) \
|
2019-04-01 10:14:26 +00:00
|
|
|
const char *name ## TypeToString(int type); \
|
|
|
|
int name ## TypeFromString(const char*type)
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VIR_TRISTATE_BOOL_ABSENT = 0,
|
|
|
|
VIR_TRISTATE_BOOL_YES,
|
|
|
|
VIR_TRISTATE_BOOL_NO,
|
|
|
|
|
|
|
|
VIR_TRISTATE_BOOL_LAST
|
|
|
|
} virTristateBool;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VIR_TRISTATE_SWITCH_ABSENT = 0,
|
|
|
|
VIR_TRISTATE_SWITCH_ON,
|
|
|
|
VIR_TRISTATE_SWITCH_OFF,
|
|
|
|
|
|
|
|
VIR_TRISTATE_SWITCH_LAST
|
|
|
|
} virTristateSwitch;
|
|
|
|
|
|
|
|
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 */
|
2020-01-09 10:39:55 +00:00
|
|
|
G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON);
|
|
|
|
G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_NO == (int)VIR_TRISTATE_SWITCH_OFF);
|
|
|
|
G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT);
|