2021-08-28 12:16:03 +02:00
# pragma once
# include <variant>
# include <functional>
# include <cstddef>
2021-08-29 10:38:03 +02:00
# include "upv_info.h"
# include "skidoo_info.h"
2021-09-16 05:06:03 +03:00
# include "itemdata/door_data.h"
2021-08-29 10:38:03 +02:00
# include "kayak_info.h"
# include "lara_struct.h"
# include "jeep_info.h"
# include "motorbike_info.h"
2021-08-29 16:11:03 +02:00
# include "minecart_info.h"
2021-08-29 10:38:03 +02:00
# include "biggun_info.h"
# include "quad_info.h"
# include "tr5_laserhead_info.h"
2021-09-16 05:06:03 +03:00
# include "itemdata/creature_info.h"
2021-08-29 16:11:03 +02:00
# include "boat_info.h"
# include "rubberboat_info.h"
2021-08-29 10:38:03 +02:00
# include <stdexcept>
2021-08-29 16:11:03 +02:00
# include "phd_global.h"
# include "tr4_wraith_info.h"
# include "tr5_pushableblock_info.h"
2021-08-30 17:50:11 +02:00
template < class . . . Ts > struct visitor : Ts . . . { using Ts : : operator ( ) . . . ; } ;
template < class . . . Ts > visitor ( Ts . . . ) - > visitor < Ts . . . > ; // line not needed in C++20...
2021-08-29 16:11:03 +02:00
2021-08-28 12:16:03 +02:00
struct ITEM_INFO ;
2021-08-29 10:04:49 +02:00
2021-08-28 12:16:03 +02:00
class ITEM_DATA {
2021-08-29 10:38:03 +02:00
std : : variant < std : : nullptr_t ,
2021-08-29 16:11:03 +02:00
char ,
short ,
int ,
long ,
2021-08-29 10:38:03 +02:00
long long ,
2021-08-29 16:11:03 +02:00
unsigned char ,
unsigned short ,
unsigned int ,
unsigned long ,
2021-08-29 10:38:03 +02:00
unsigned long long ,
2021-08-29 16:11:03 +02:00
float ,
double ,
2021-08-29 10:38:03 +02:00
long double ,
2021-08-29 16:35:19 +02:00
std : : array < short , 4 > ,
2021-08-29 16:11:03 +02:00
ITEM_INFO * ,
2021-08-29 10:38:03 +02:00
CREATURE_INFO ,
LASER_HEAD_INFO ,
QUAD_INFO ,
BIGGUNINFO ,
MOTORBIKE_INFO ,
JEEP_INFO ,
LaraInfo ,
KAYAK_INFO ,
DOOR_DATA ,
SKIDOO_INFO ,
2021-08-29 16:11:03 +02:00
SUB_INFO ,
BOAT_INFO ,
GAME_VECTOR ,
WRAITH_INFO ,
RUBBER_BOAT_INFO ,
PUSHABLE_INFO ,
CART_INFO
2021-08-29 10:38:03 +02:00
> data ;
2021-08-29 16:11:03 +02:00
public :
ITEM_DATA ( ) ;
template < typename D >
2021-08-30 17:28:26 +02:00
ITEM_DATA ( D & & type ) : data ( std : : move ( type ) ) { }
2021-08-29 10:38:03 +02:00
// conversion operators to keep original syntax!
// TODO: should be removed later and
template < typename T >
operator T * ( ) {
if ( std : : holds_alternative < T > ( data ) ) {
auto & ref = std : : get < T > ( data ) ;
return & ref ;
}
throw std : : runtime_error ( " ITEM_DATA does not hold the requested type! \n The code set the ITEM_DATA to a different type than the type that was attempted to read " ) ;
}
template < typename T >
operator T & ( ) {
if ( std : : holds_alternative < T > ( data ) ) {
auto & ref = std : : get < T > ( data ) ;
return ref ;
}
throw std : : runtime_error ( " ITEM_DATA does not hold the requested type! \n The code set the ITEM_DATA to a different type than the type that was attempted to read " ) ;
}
template < typename T >
2021-08-29 16:11:03 +02:00
ITEM_DATA & operator = ( T * newData ) {
2021-08-29 10:38:03 +02:00
data = * newData ;
return * this ;
}
2021-08-29 16:11:03 +02:00
ITEM_DATA & operator = ( std : : nullptr_t null ) {
data = nullptr ;
return * this ;
}
template < typename T >
ITEM_DATA & operator = ( T & newData ) {
data = newData ;
return * this ;
}
2021-08-30 17:50:11 +02:00
2021-08-29 16:11:03 +02:00
template < typename T >
ITEM_DATA & operator = ( T & & newData ) {
2021-08-30 17:28:26 +02:00
data = std : : move ( newData ) ;
2021-08-29 16:11:03 +02:00
return * this ;
}
2021-08-30 17:50:11 +02:00
2021-09-03 09:37:42 +02:00
operator bool ( ) const {
2021-08-29 16:11:03 +02:00
return ! std : : holds_alternative < std : : nullptr_t > ( data ) ;
}
2021-08-30 17:50:11 +02:00
template < typename . . . Funcs >
void apply ( Funcs & & . . . funcs ) {
std : : visit (
visitor {
[ ] ( auto const & ) { } ,
std : : forward < Funcs > ( funcs ) . . .
} ,
data ) ;
2021-08-29 16:11:03 +02:00
}
2021-09-03 09:37:42 +02:00
template < typename T >
bool is ( ) const {
return std : : holds_alternative < T > ( data ) ;
}
2021-08-28 12:16:03 +02:00
} ;