Skip to content

Commit

Permalink
Replace STATIC_CHECK macro with static_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 4, 2017
1 parent 13c2eab commit 392ee43
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Common/object_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CLoader
template <bool a>
IC static void load_data(T& data, M& stream, const P& p)
{
STATIC_CHECK(!std::is_polymorphic<T>::value, Cannot_load_polymorphic_classes_as_binary_data);
static_assert(!std::is_polymorphic<T>::value, "Cannot load polymorphic classes as binary data.");
stream.r(&data, sizeof(T));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Common/object_saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CSaver
template <bool a>
IC static void save_data(const T& data, M& stream, const P& p)
{
STATIC_CHECK(!std::is_polymorphic<T>::value, Cannot_save_polymorphic_classes_as_binary_data);
static_assert(!std::is_polymorphic<T>::value, "Cannot save polymorphic classes as binary data.");
stream.w(&data, sizeof(T));
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/xrAI/guid_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ xrGUID generate_guid()
{
xrGUID result;
#ifdef WINVER
STATIC_CHECK(sizeof(xrGUID) == sizeof(GUID), Different_GUID_types);
static_assert(sizeof(xrGUID) == sizeof(GUID), "Different GUID types.");
GUID _result;
RPC_STATUS gen_result = UuidCreate(&_result);
memcpy(&result, &_result, sizeof(_result));
Expand All @@ -32,7 +32,7 @@ xrGUID generate_guid()
default: break;
}
#endif
STATIC_CHECK(sizeof(result) >= sizeof(u64), GUID_must_have_size_greater_or_equal_to_the_long_long);
static_assert(sizeof(result) >= sizeof(u64), "GUID must have size greater or equal to the long long.");
ZeroMemory(&result, sizeof(result));
u64 temp = CPU::GetCLK();
memcpy(&result, &temp, sizeof(temp));
Expand All @@ -42,7 +42,7 @@ xrGUID generate_guid()
LPCSTR generate_guid(const xrGUID& guid, LPSTR buffer, const u32& buffer_size)
{
#ifdef WINVER
STATIC_CHECK(sizeof(xrGUID) == sizeof(GUID), Different_GUID_types);
static_assert(sizeof(xrGUID) == sizeof(GUID), "Different GUID types.");
GUID temp;
memcpy(&temp, &guid, sizeof(guid));
RPC_CSTR temp2;
Expand Down
8 changes: 4 additions & 4 deletions src/xrAICore/Components/problem_solver_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ IC bool CProblemSolverAbstract::is_goal_reached(const _index_type& vertex_index)
TEMPLATE_SPECIALIZATION
IC bool CProblemSolverAbstract::is_goal_reached_impl(const _index_type& vertex_index) const
{
STATIC_CHECK(!reverse_search, This_function_cannot_be_used_in_the_REVERSE_search);
static_assert(!reverse_search, "This function cannot be used in the REVERSE search.");
xr_vector<COperatorCondition>::const_iterator I = vertex_index.conditions().begin();
xr_vector<COperatorCondition>::const_iterator E = vertex_index.conditions().end();
xr_vector<COperatorCondition>::const_iterator i = target_state().conditions().begin();
Expand Down Expand Up @@ -309,7 +309,7 @@ IC bool CProblemSolverAbstract::is_goal_reached_impl(const _index_type& vertex_i
TEMPLATE_SPECIALIZATION
IC bool CProblemSolverAbstract::is_goal_reached_impl(const _index_type& vertex_index, bool) const
{
STATIC_CHECK(reverse_search, This_function_cannot_be_used_in_the_STRAIGHT_search);
static_assert(reverse_search, "This function cannot be used in the STRAIGHT search.");
xr_vector<COperatorCondition>::const_iterator I = m_current_state.conditions().begin();
xr_vector<COperatorCondition>::const_iterator E = m_current_state.conditions().end();
xr_vector<COperatorCondition>::const_iterator i = vertex_index.conditions().begin();
Expand Down Expand Up @@ -377,7 +377,7 @@ TEMPLATE_SPECIALIZATION
IC typename CProblemSolverAbstract::_edge_value_type CProblemSolverAbstract::estimate_edge_weight_impl(
const _index_type& condition) const
{
STATIC_CHECK(!reverse_search, This_function_cannot_be_used_in_the_REVERSE_search);
static_assert(!reverse_search, "This function cannot be used in the REVERSE search.");
_edge_value_type result = 0;
xr_vector<COperatorCondition>::const_iterator I = target_state().conditions().begin();
xr_vector<COperatorCondition>::const_iterator E = target_state().conditions().end();
Expand Down Expand Up @@ -405,7 +405,7 @@ TEMPLATE_SPECIALIZATION
IC typename CProblemSolverAbstract::_edge_value_type CProblemSolverAbstract::estimate_edge_weight_impl(
const _index_type& condition, bool) const
{
STATIC_CHECK(reverse_search, This_function_cannot_be_used_in_the_STRAIGHT_search);
static_assert(reverse_search, "This function cannot be used in the STRAIGHT search.");
_edge_value_type result = 0;
xr_vector<COperatorCondition>::const_iterator I = current_state().conditions().begin();
xr_vector<COperatorCondition>::const_iterator E = current_state().conditions().end();
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/Crypto/xr_dsa_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ xr_dsa_signer::xr_dsa_signer(u8 const p_number[crypto::xr_dsa::public_key_length
u8 const q_number[crypto::xr_dsa::private_key_length], u8 const g_number[crypto::xr_dsa::public_key_length])
: m_dsa(p_number, q_number, g_number)
{
STATIC_CHECK(crypto::xr_dsa::private_key_length == crypto::xr_sha256::digest_length,
private_key_size_must_be_equal_to_digest_value_size);
static_assert(crypto::xr_dsa::private_key_length == crypto::xr_sha256::digest_length,
"Private key size must be equal to digest value size.");
}

xr_dsa_signer::~xr_dsa_signer() {}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Crypto/xr_dsa_verifyer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ xr_dsa_verifyer::xr_dsa_verifyer(u8 const p_number[crypto::xr_dsa::public_key_le
u8 const public_key[crypto::xr_dsa::public_key_length])
: m_dsa(p_number, q_number, g_number)
{
STATIC_CHECK(sizeof(m_public_key.m_value) == crypto::xr_dsa::public_key_length, public_key_sizes_not_equal);
static_assert(sizeof(m_public_key.m_value) == crypto::xr_dsa::public_key_length, "Public key sizes not equal.");
CopyMemory(m_public_key.m_value, public_key, sizeof(m_public_key.m_value));
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Crypto/xr_sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool xr_sha256::continue_calculate()

if (!m_data_size)
{
STATIC_CHECK(digest_length == CryptoPP::SHA1::DIGESTSIZE, digest_length_must_be_equal_to_digest_size);
static_assert(digest_length == CryptoPP::SHA1::DIGESTSIZE, "Digest length must be equal to digest size.");
m_sha_ctx.Final(m_result);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/intrusive_ptr_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ IC intrusive_ptr<object_type, base_type>::intrusive_ptr(self_type const& rhs)
template <typename object_type, typename base_type>
IC intrusive_ptr<object_type, base_type>::~intrusive_ptr()
{
STATIC_CHECK(result, Class_MUST_Be_Derived_From_The_Base);
static_assert(result, "Class MUST be derived from the base.");
dec();
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/string_concatenations_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class XRCORE_API string_tupples
template <typename T>
static inline void add_string(string_tupples& self, T p)
{
STATIC_CHECK(index < max_item_count, Error_invalid_string_index_specified);
static_assert(index < max_item_count, "Error invalid string index specified.");

LPCSTR cstr = string(p);
VERIFY(cstr);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/aimers_base_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ template <u32 bone_count0, u32 bone_count1>
inline void aimers::base::fill_bones(u32 const (&bones)[bone_count0], u16 const (&bones_ids)[bone_count1],
Fmatrix (&local_bones)[bone_count1], Fmatrix (&global_bones)[bone_count1])
{
STATIC_CHECK(bone_count0 <= bone_count1, invalid_arrays_passed);
static_assert(bone_count0 <= bone_count1, "Invalid arrays passed.");

u16 const root_bone_id = m_kinematics.LL_GetBoneRoot();
CBoneInstance& root_bone = m_kinematics.LL_GetBoneInstance(root_bone_id);
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/alife_registry_container_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ template <typename T>
IC T& CALifeRegistryContainer::operator()(const T*)
{
const int value = Loki::TL::IndexOf<TYPE_LIST, T>::value;
STATIC_CHECK(value != -1, There_is_no_specified_registry_in_the_registry_container);
static_assert(value != -1, "There is no specified registry in the registry container.");
return (*static_cast<T*>(this));
}

template <typename T>
IC const T& CALifeRegistryContainer::operator()(const T*) const
{
const int value = Loki::TL::IndexOf<TYPE_LIST, T>::value;
STATIC_CHECK(value != -1, There_is_no_specified_registry_in_the_registry_container);
static_assert(value != -1, "There is no specified registry in the registry container.");
return (*static_cast<T*>(this));
}
5 changes: 2 additions & 3 deletions src/xrGame/game_state_accumulator_inline.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
template <typename TypeListElement>
void game_state_accumulator::init_acpv_list()
{
STATIC_CHECK(Loki::TL::is_Typelist<TypeListElement>::value,
Type_Must_Have_a_Loki_Type_List_type_use__ADD_ACCUMULATIVE_STATE__macro_define);

static_assert(Loki::TL::is_Typelist<TypeListElement>::value,
"Type must have a Loki Type List type use ADD_ACCUMULATIVE_STATE macro define.");
init_acpv_list<TypeListElement::Tail>();

player_state_param* tmp_obj_inst = new typename TypeListElement::Head::value_type(this);
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/game_state_accumulator_state_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ char* player_values_strtable[] = {

void game_state_accumulator::init_accumulative_values()
{
STATIC_CHECK(Loki::TL::Length<ACCUMULATIVE_STATE_LIST>::value == acpv_count,
Not_all_accumulative_values_has_been_added_to_a__ACCUMULATIVE_STATE_LIST__type_list);
static_assert(Loki::TL::Length<ACCUMULATIVE_STATE_LIST>::value == acpv_count,
"Not all accumulative values has been added to a ACCUMULATIVE_STATE_LIST type list.");

init_acpv_list<ACCUMULATIVE_STATE_LIST>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/inventory_quickswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static char const* teamdata_section = "deathmatch_team0";

void CInventory::InitPriorityGroupsForQSwitch()
{
STATIC_CHECK(epg_groups_count == CInventory::qs_priorities_count, groups_count_problem);
static_assert(epg_groups_count == CInventory::qs_priorities_count, "Groups count problem.");
for (int i = epg_pistols; i < epg_groups_count; ++i)
{
m_groups[i].init_group(teamdata_section, groups_names[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/xrServer_updates_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ last_updates_cache::last_update_t* last_updates_cache::search_entity(u16 const e
last_updates_cache::last_update_t* last_updates_cache::search_most_expired(
u32 const current_time, u32 const update_size)
{
STATIC_CHECK(cache_entities_size > 1, cache_entities_size__must_be_greater_than_one);
static_assert(cache_entities_size > 1, "Cache entities size must be greater than one.");
last_update_t* min_time = &m_cache[0];
for (u32 i = 1; i < cache_entities_size; ++i)
{
Expand Down
22 changes: 11 additions & 11 deletions src/xrServerEntities/smart_cast_impl1.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct conversion_sequence
template <int length>
struct selector
{
STATIC_CHECK(length > 1, Internal_error_please_report);
static_assert(length > 1, "Internal error, please report.");

typedef typename selector<1>::result nearest;

Expand Down Expand Up @@ -515,8 +515,8 @@ struct CHelper2
template <typename T1>
IC static T1* smart_cast(T2* p)
{
STATIC_CHECK(!object_type_traits::is_const<T2>::value || object_type_traits::is_const<T1>::value,
Cannot_use_smart_cast_to_convert_const_to_non_const);
static_assert(!object_type_traits::is_const<T2>::value || object_type_traits::is_const<T1>::value,
"Cannot use smart_cast to convert const to non-const.");
typedef object_type_traits::remove_const<T1>::type _T1;
typedef object_type_traits::remove_const<T2>::type _T2;
#ifdef DEBUG
Expand Down Expand Up @@ -551,11 +551,11 @@ template <typename T1, typename T2>
IC T1 smart_cast(T2* p)
{
#ifdef PURE_DYNAMIC_CAST_COMPATIBILITY_CHECK
STATIC_CHECK(object_type_traits::is_pointer<T1>::value, Invalid_target_type_for_Dynamic_Cast);
STATIC_CHECK(object_type_traits::is_void<object_type_traits::remove_pointer<T1>::type>::value ||
static_assert(object_type_traits::is_pointer<T1>::value, "Invalid target type for Dynamic Cast.");
static_assert(object_type_traits::is_void<object_type_traits::remove_pointer<T1>::type>::value ||
std::is_polymorphic<object_type_traits::remove_pointer<T1>::type>::value,
Invalid_target_type_for_Dynamic_Cast);
STATIC_CHECK(std::is_polymorphic<T2>::value, Invalid_source_type_for_Dynamic_Cast);
"Invalid target type for Dynamic Cast");
static_assert(std::is_polymorphic<T2>::value, "Invalid source type for Dynamic Cast.");
#endif
#ifdef SMART_CAST_STATS_ALL
add_smart_cast_stats_all(typeid(T2*).name(), typeid(T1).name());
Expand All @@ -569,10 +569,10 @@ template <typename T1, typename T2>
IC T1 smart_cast(T2& p)
{
#ifdef PURE_DYNAMIC_CAST_COMPATIBILITY_CHECK
STATIC_CHECK(object_type_traits::is_reference<T1>::value, Invalid_target_type_for_Dynamic_Cast);
STATIC_CHECK(std::is_polymorphic<object_type_traits::remove_reference<T1>::type>::value,
Invalid_target_type_for_Dynamic_Cast);
STATIC_CHECK(std::is_polymorphic<T2>::value, Invalid_source_type_for_Dynamic_Cast);
static_assert(object_type_traits::is_reference<T1>::value, "Invalid target type for Dynamic Cast.");
static_assert(std::is_polymorphic<object_type_traits::remove_reference<T1>::type>::value,
"Invalid target type for Dynamic Cast.");
static_assert(std::is_polymorphic<T2>::value, "Invalid source type for Dynamic Cast.");
#endif
#ifdef SMART_CAST_STATS_ALL
add_smart_cast_stats_all(typeid(T2*).name(), typeid(object_type_traits::remove_reference<T1>::type*).name());
Expand Down

0 comments on commit 392ee43

Please sign in to comment.