42 #ifndef __POL_DYNPROPS_H 43 #define __POL_DYNPROPS_H 46 #include <boost/any.hpp> 47 #include <boost/variant.hpp> 50 #include <type_traits> 53 #include "../clib/passert.h" 54 #include "../clib/rawtypes.h" 62 #define DYN_PROPERTY( name, type, id, defaultvalue ) \ 66 if ( getmember<type>( id, &val ) ) \ 68 return defaultvalue; \ 70 void name( const type& val ) { setmember( id, val, static_cast<type>( defaultvalue ) ); }; \ 71 bool has_##name() const { return hasmember( id ); } 73 #define DYN_PROPERTY_POINTER( name, type, id ) \ 77 if ( getmember<type>( id, &val ) ) \ 81 void name( type val ) { setmemberPointer( id, val ); }; \ 82 bool has_##name() const { return hasmember( id ); } 167 static_assert(
sizeof(
ValueModPack ) ==
sizeof(
u32 ),
"size missmatch" );
180 static_assert(
sizeof(
SkillStatCap ) ==
sizeof(
u32 ),
"size missmatch" );
203 MovementCostMod(
double walk_,
double run_,
double walk_mounted_,
double run_mounted_ );
209 template <
typename Storage>
216 template <
typename T>
220 std::is_same<T, u8>::value || std::is_same<T, u16>::value || std::is_same<T, u32>::value ||
221 std::is_same<T, s8>::value || std::is_same<T, s16>::value || std::is_same<T, s32>::value ||
222 std::is_same<T, ValueModPack>::value || std::is_same<T, SkillStatCap>::value ||
223 std::is_same<T, ExtStatBarFollowers>::value || std::is_same<T, gameclock_t>::value;
228 template <
typename Storage>
232 template <
typename S>
236 template <
typename V>
246 template <
typename Storage>
251 template <
typename V>
253 template <
typename V>
255 template <
typename V>
257 template <
typename V>
259 template <
typename V>
262 size_t estimateSize()
const;
279 template <
typename V>
282 template <
typename V>
284 template <
typename V>
287 template <
typename V>
289 size_t estimateSize()
const;
306 template <
typename V>
308 template <
typename V>
309 void setmember(
DynPropTypes member,
const V& value,
const V& defaultvalue );
310 template <
typename V>
312 size_t estimateSizeDynProps()
const;
393 : walk( 1.0 ),
run( 1.0 ), walk_mounted( 1.0 ), run_mounted( 1.0 )
397 double run_mounted_ )
409 template <
class Storage>
413 template <
class Storage>
420 template <
typename V>
423 return boost::any_cast<V>(
_value );
426 template <
typename V>
429 return boost::get<V>(
_value );
434 template <
class Storage>
439 template <
class Storage>
440 template <
typename V>
445 if ( prop._type == type )
447 *value = prop.template getValue<V>();
454 template <
class Storage>
455 template <
typename V>
460 if ( prop._type == type )
469 template <
class Storage>
470 template <
typename V>
475 if ( prop._type == type )
484 template <
class Storage>
485 template <
typename V>
488 _props.emplace_back( type, value );
491 template <
class Storage>
492 template <
typename V>
495 _props.emplace_back( type, value );
498 template <
class Storage>
507 template <
class Storage>
518 template <
typename V>
519 static typename std::enable_if<can_be_used_in_variant<V>::value,
bool>::type getPropertyHelper(
524 return variant_props.
getValue( type, value );
526 template <
typename V>
527 static typename std::enable_if<!can_be_used_in_variant<V>::value,
bool>::type getPropertyHelper(
533 return any_props->getValue( type, value );
536 template <
typename V>
537 static typename std::enable_if<can_be_used_in_variant<V>::value,
bool>::type updatePropertyHelper(
544 template <
typename V>
545 static typename std::enable_if<!can_be_used_in_variant<V>::value,
bool>::type updatePropertyHelper(
551 return any_props->updateValue( type, value );
553 template <
typename V>
554 static typename std::enable_if<can_be_used_in_variant<V>::value,
void>::type addPropertyHelper(
559 variant_props.
addValue( type, value );
561 template <
typename V>
562 static typename std::enable_if<!can_be_used_in_variant<V>::value,
void>::type addPropertyHelper(
572 template <
typename V>
573 static typename std::enable_if<can_be_used_in_variant<V>::value,
void>::type removePropertyHelper(
580 template <
typename V>
581 static typename std::enable_if<!can_be_used_in_variant<V>::value,
void>::type removePropertyHelper(
587 any_props->removeValue( type );
599 template <
typename V>
607 template <
typename V>
620 template <
typename V>
626 bool res =
_any_props->updateValue( type, value );
636 template <
typename V>
647 size_t size =
sizeof( std::bitset<PROP_FLAG_SIZE> ) +
sizeof( std::unique_ptr<void> ) +
666 template <
typename V>
671 return _dynprops->getProperty( member, value );
681 template <
typename V>
683 const V& defaultvalue )
685 if ( value == defaultvalue )
695 template <
typename V>
698 if ( value ==
nullptr )
std::unique_ptr< PropHolderContainer< boost::any > > _any_props
void setPropertyPointer(DynPropTypes type, V value)
void setmember(DynPropTypes member, const V &value, const V &defaultvalue)
size_t estimateSize() const
bool operator==(const ExtStatBarFollowers &other) const
void addValuePointer(DynPropTypes type, V value)
size_t estimateSizeDynProps() const
ValueModPack & addToValue(const ValueModPack &other)
static const SkillStatCap DEFAULT
bool hasProperty(DynPropTypes type) const
size_t estimateSize() const
static const ExtStatBarFollowers DEFAULT
bool operator==(const ValueModPack &other) const
void setmemberPointer(DynPropTypes member, V value)
bool getProperty(DynPropTypes type, V *value) const
PropHolderContainer< variant_storage > _props
bool getmember(DynPropTypes member, V *value) const
bool operator==(const MovementCostMod &other) const
void removeProperty(DynPropTypes type)
bool hasmember(DynPropTypes member) const
std::unique_ptr< DynProps > _dynprops
bool operator==(const SkillStatCap &other) const
std::bitset< PROP_FLAG_SIZE > _prop_bits
std::vector< PropHolder< Storage > > _props
ValueModPack & setAsMod(s16 other)
static const MovementCostMod DEFAULT
PropHolder(DynPropTypes type)
boost::variant< u8, u16, u32, s8, s16, s32, ValueModPack, SkillStatCap, ExtStatBarFollowers, gameclock_t > variant_storage
void removeValue(DynPropTypes type)
bool updateValue(DynPropTypes type, const V &value)
void addValue(DynPropTypes type, const V &value)
static const ValueModPack DEFAULT
bool getValue(DynPropTypes type, V *value) const
bool run(int argc, char **argv)
bool updateValuePointer(DynPropTypes type, V value)
ValueModPack & resetModAsValue()
#define passert_always(exp)
void setProperty(DynPropTypes type, const V &value)
ValueModPack & addToMod(s16 other)