Try using type_traits for detection of valid save types.

This commit is contained in:
Aaron Giles 2010-01-11 09:53:25 +00:00
parent 51e6cbf6cd
commit 317da101d8
3 changed files with 45 additions and 11 deletions

View File

@ -163,8 +163,42 @@ INLINE void flip_data(state_entry *entry)
all registrations
-------------------------------------------------*/
enum test_enum_type { test_val };
class test_class_type { public: int dummy; };
void state_init(running_machine *machine)
{
bool test_bool;
INT8 test_INT8;
UINT8 test_UINT8;
INT16 test_INT16;
UINT16 test_UINT16;
INT32 test_INT32;
UINT32 test_UINT32;
INT64 test_INT64;
UINT64 test_UINT64;
float test_float;
double test_double;
test_enum_type test_enum;
test_class_type test_class;
assert_always(IS_VALID_SAVE_TYPE(test_bool), "bool is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_INT8), "INT8 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_UINT8), "UINT8 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_INT16), "INT16 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_UINT16), "UINT16 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_INT32), "INT32 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_UINT32), "UINT32 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_INT64), "INT64 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_UINT64), "UINT64 is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_float), "float is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_double), "double is not a valid type for save");
assert_always(IS_VALID_SAVE_TYPE(test_enum), "enums are not a valid type for save");
#ifdef __GNUC__
assert_always(!IS_VALID_SAVE_TYPE(test_class), "classes are a valid type for save");
#endif
machine->state_data = auto_alloc_clear(machine, state_private);
}

View File

@ -18,6 +18,9 @@
#ifndef __STATE_H__
#define __STATE_H__
#ifdef __GNUC__
#include <tr1/type_traits>
#endif
/***************************************************************************
@ -53,16 +56,13 @@ typedef enum _state_save_error state_save_error;
#define STATE_POSTLOAD(name) void name(running_machine *machine, void *param)
#define IS_COMPATIBLE_TYPE(_valtype, _checktype) \
(sizeof(_valtype) == sizeof(_checktype) && TYPES_COMPATIBLE(_valtype, _checktype))
#define IS_VALID_SAVE_TYPE(_valtype) \
(IS_COMPATIBLE_TYPE(_valtype, double) || IS_COMPATIBLE_TYPE(_valtype, float) || \
IS_COMPATIBLE_TYPE(_valtype, INT64) || IS_COMPATIBLE_TYPE(_valtype, UINT64) || \
IS_COMPATIBLE_TYPE(_valtype, INT32) || IS_COMPATIBLE_TYPE(_valtype, UINT32) || \
IS_COMPATIBLE_TYPE(_valtype, INT16) || IS_COMPATIBLE_TYPE(_valtype, UINT16) || \
IS_COMPATIBLE_TYPE(_valtype, INT8) || IS_COMPATIBLE_TYPE(_valtype, UINT8) || \
IS_COMPATIBLE_TYPE(_valtype, PAIR) || IS_COMPATIBLE_TYPE(_valtype, PAIR64))
#ifdef __GNUC__
#define IS_VALID_SAVE_TYPE(_var) \
(std::tr1::is_arithmetic<typeof(_var)>::value || std::tr1::is_enum<typeof(_var)>::value)
#else
#define IS_VALID_SAVE_TYPE(_var) \
(sizeof(_var) == 1 || sizeof(_var) == 2 || sizeof(_var) == 4 || sizeof(_var) == 8)
#endif
/* generic registration; all further registrations are based on this */

View File

@ -470,7 +470,7 @@ static int validate_roms(int drivnum, const machine_config *config, region_info
for (rgnnum = 0; rgnnum < ARRAY_LENGTH(rgninfo->entries); rgnnum++)
{
/* stop when we hit an empty */
if (rgninfo->entries[rgnnum].tag.len() == NULL)
if (rgninfo->entries[rgnnum].tag.len() == 0)
{
currgn = &rgninfo->entries[rgnnum];
currgn->tag.cpy(fulltag);