remove E2D_COUNTOF macro

This commit is contained in:
2019-05-25 23:27:19 +07:00
parent 9e5f32b041
commit 48a257f70d
12 changed files with 23 additions and 38 deletions

View File

@@ -45,12 +45,3 @@
template < typename... Ts >
constexpr void E2D_UNUSED(Ts&&...) noexcept {}
//
// E2D_COUNTOF
//
template < typename T, std::size_t N >
constexpr std::size_t E2D_COUNTOF(const T(&)[N]) noexcept {
return N;
}

View File

@@ -37,7 +37,7 @@ namespace
void on_keyboard_key(keyboard_key key, u32 scancode, keyboard_key_action act) noexcept final {
E2D_UNUSED(scancode);
auto key_i = utils::enum_to_underlying(key);
if ( key_i < E2D_COUNTOF(io_.KeysDown) ) {
if ( key_i < std::size(io_.KeysDown) ) {
switch ( act ) {
case keyboard_key_action::press:
case keyboard_key_action::repeat:

View File

@@ -105,8 +105,8 @@ namespace
}
{
char title_buf[128] = {0};
strings::format(title_buf, E2D_COUNTOF(title_buf), w.title());
if ( ImGui::InputText("title", title_buf, E2D_COUNTOF(title_buf)) ) {
strings::format(title_buf, std::size(title_buf), w.title());
if ( ImGui::InputText("title", title_buf, std::size(title_buf)) ) {
w.set_title(title_buf);
}
}

View File

@@ -48,7 +48,7 @@ namespace
const pixel_type_description& get_pixel_type_description(pixel_declaration::pixel_type type) noexcept {
const std::size_t index = math::numeric_cast<std::size_t>(utils::enum_to_underlying(type));
E2D_ASSERT(index < E2D_COUNTOF(pixel_type_descriptions));
E2D_ASSERT(index < std::size(pixel_type_descriptions));
const pixel_type_description& desc = pixel_type_descriptions[index];
E2D_ASSERT(desc.type == type);
return desc;

View File

@@ -76,7 +76,7 @@ namespace
{
const std::size_t uv_count = math::min(
mesh.uvs_channel_count(),
E2D_COUNTOF(uv_buffer_decls));
std::size(uv_buffer_decls));
for ( std::size_t i = 0; i < uv_count; ++i ) {
const vector<v2f>& uvs = mesh.uvs(i);
const vertex_buffer_ptr uv_buffer = render.create_vertex_buffer(
@@ -92,7 +92,7 @@ namespace
{
const std::size_t color_count = math::min(
mesh.colors_channel_count(),
E2D_COUNTOF(uv_buffer_decls));
std::size(uv_buffer_decls));
for ( std::size_t i = 0; i < color_count; ++i ) {
const vector<color32>& colors = mesh.colors(i);
const vertex_buffer_ptr color_buffer = render.create_vertex_buffer(

View File

@@ -202,8 +202,8 @@ namespace e2d { namespace render_system_impl
batcher_.batch(
mat_a,
property_cache_,
indices, E2D_COUNTOF(indices),
vertices, E2D_COUNTOF(vertices));
indices, std::size(indices),
vertices, std::size(vertices));
} catch (...) {
property_cache_.clear();
throw;

View File

@@ -52,7 +52,7 @@ namespace
bool extract_working_directory(str& dst) {
char buf[PATH_MAX + 1] = {0};
if ( ::getcwd(buf, E2D_COUNTOF(buf) - 1) ) {
if ( ::getcwd(buf, std::size(buf) - 1) ) {
dst.assign(buf);
return true;
}
@@ -61,7 +61,7 @@ namespace
bool extract_executable_path(str& dst) {
char buf[PATH_MAX + 1] = {0};
if ( ::readlink("/proc/self/exe", buf, E2D_COUNTOF(buf) - 1) != -1 ) {
if ( ::readlink("/proc/self/exe", buf, std::size(buf) - 1) != -1 ) {
dst.assign(buf);
return true;
}

View File

@@ -51,7 +51,7 @@ namespace
bool extract_working_directory(str& dst) {
WCHAR buf[MAX_PATH + 1] = {0};
const DWORD len = ::GetCurrentDirectoryW(
math::numeric_cast<DWORD>(E2D_COUNTOF(buf) - 1),
math::numeric_cast<DWORD>(std::size(buf) - 1),
buf);
if ( len > 0 && len <= MAX_PATH ) {
dst = make_utf8(buf);
@@ -74,7 +74,7 @@ namespace
const DWORD len = ::GetModuleFileNameW(
0,
buf,
math::numeric_cast<DWORD>(E2D_COUNTOF(buf) - 1));
math::numeric_cast<DWORD>(std::size(buf) - 1));
if ( len > 0 && len <= MAX_PATH ) {
dst = make_utf8(buf);
return true;

View File

@@ -38,7 +38,7 @@ namespace
const data_format_description& get_data_format_description(image_data_format format) noexcept {
const std::size_t findex = static_cast<std::underlying_type_t<image_data_format>>(format);
E2D_ASSERT(findex < E2D_COUNTOF(data_format_descriptions));
E2D_ASSERT(findex < std::size(data_format_descriptions));
const data_format_description& fdesc = data_format_descriptions[findex];
E2D_ASSERT(fdesc.format == format);
return fdesc;

View File

@@ -258,7 +258,7 @@ namespace
if ( root.IsObject() ) {
const char* const props[] = { "x", "y", "z", "w" };
for ( std::size_t i = 0; i < math::min(N, E2D_COUNTOF(props)); ++i ) {
for ( std::size_t i = 0; i < math::min(N, std::size(props)); ++i ) {
if ( root.HasMember(props[i]) ) {
const auto& jv = root[props[i]];
if ( !f(jv, v[i]) ) {
@@ -431,7 +431,7 @@ namespace
bool parse_b2(const rapidjson::Value& root, rect<V>& b, FV&& f) {
if ( root.IsObject() ) {
const char* const props[] = { "x", "y", "w", "h" };
for ( std::size_t i = 0; i < E2D_COUNTOF(props); ++i ) {
for ( std::size_t i = 0; i < std::size(props); ++i ) {
if ( root.HasMember(props[i]) ) {
const auto& jv = root[props[i]];
if ( !f(jv, b[i]) ) {
@@ -497,7 +497,7 @@ namespace
bool parse_b3(const rapidjson::Value& root, aabb<V>& b, FV&& f) {
if ( root.IsObject() ) {
const char* const props[] = { "x", "y", "z", "w", "h", "d" };
for ( std::size_t i = 0; i < E2D_COUNTOF(props); ++i ) {
for ( std::size_t i = 0; i < std::size(props); ++i ) {
if ( root.HasMember(props[i]) ) {
const auto& jv = root[props[i]];
if ( !f(jv, b[i]) ) {
@@ -568,7 +568,7 @@ namespace
if ( root.IsObject() ) {
const char* const props[] = { "r", "g", "b", "a" };
for ( std::size_t i = 0; i < E2D_COUNTOF(props); ++i ) {
for ( std::size_t i = 0; i < std::size(props); ++i ) {
if ( root.HasMember(props[i]) ) {
const auto& jv = root[props[i]];
if ( !jv.IsNumber() ) {
@@ -609,7 +609,7 @@ namespace
if ( root.IsObject() ) {
const char* const props[] = { "r", "g", "b", "a" };
for ( std::size_t i = 0; i < E2D_COUNTOF(props); ++i ) {
for ( std::size_t i = 0; i < std::size(props); ++i ) {
if ( root.HasMember(props[i]) ) {
const auto& jv = root[props[i]];
if ( !jv.IsUint() ) {

View File

@@ -14,10 +14,4 @@ TEST_CASE("macros") {
REQUIRE_FALSE(m[i]);
}
}
SECTION("E2D_COUNTOF") {
u32 arr[12];
u32 arr2[E2D_COUNTOF(arr)];
REQUIRE(E2D_COUNTOF(arr) == 12);
REQUIRE(E2D_COUNTOF(arr2) == 12);
}
}

View File

@@ -315,10 +315,10 @@ TEST_CASE("strings") {
REQUIRE_FALSE(strings::rformat_nothrow(s, "%"));
char buf[5] = {0};
std::size_t length = 0;
REQUIRE(strings::format_nothrow(buf, E2D_COUNTOF(buf), &length, "%0", "hell"));
REQUIRE(strings::format_nothrow(buf, std::size(buf), &length, "%0", "hell"));
REQUIRE(length == 4);
REQUIRE(str(buf) == str("hell"));
REQUIRE_FALSE(strings::format_nothrow(buf, E2D_COUNTOF(buf), &length, "%0", "hello"));
REQUIRE_FALSE(strings::format_nothrow(buf, std::size(buf), &length, "%0", "hello"));
}
{
REQUIRE(strings::rformat(str_view("%0"), 42) == "42");
@@ -506,14 +506,14 @@ TEST_CASE("strings") {
}
{
char buf[1];
strings::format(buf, E2D_COUNTOF(buf), "%0", "\0");
strings::format(buf, std::size(buf), "%0", "\0");
REQUIRE(str(buf) == str(""));
}
{
char buf[2];
REQUIRE_THROWS_AS(strings::format(buf, E2D_COUNTOF(buf), "%0%1", 1, 20), strings::bad_format_buffer);
REQUIRE_THROWS_AS(strings::format(buf, std::size(buf), "%0%1", 1, 20), strings::bad_format_buffer);
REQUIRE(str(buf) == str("1"));
REQUIRE_THROWS_AS(strings::format(buf, E2D_COUNTOF(buf), "%0%1", 20, 1), strings::bad_format_buffer);
REQUIRE_THROWS_AS(strings::format(buf, std::size(buf), "%0%1", 20, 1), strings::bad_format_buffer);
REQUIRE(str(buf) == str("2"));
}
}