Mercurial > malikania
changeset 170:a3af3b793da4
Misc: new conventions (size.hpp)
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 17 Mar 2018 14:51:00 +0100 |
parents | 450d884456c4 |
children | ae34e5aec876 |
files | libcommon/malikania/size.hpp libcommon/malikania/tileset.hpp libcommon/malikania/util.cpp tests/libcommon/size/main.cpp tests/libcommon/util/main.cpp tests/tools/tileset/main.cpp |
diffstat | 6 files changed, 51 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/libcommon/malikania/size.hpp Fri Aug 17 15:44:12 2018 +0200 +++ b/libcommon/malikania/size.hpp Sat Mar 17 14:51:00 2018 +0100 @@ -26,52 +26,25 @@ /** * \brief size description. */ -class size { -private: - unsigned width_; - unsigned height_; - -public: +struct size { /** - * Constructor. - * - * \param width the size width - * \param height the size height + * \brief Width. */ - inline size(unsigned width = 0, unsigned height = 0) noexcept - : width_(width) - , height_(height) - { - } + unsigned width{0}; /** - * Get the width. - * - * \return the width + * \brief Height. */ - inline unsigned width() const noexcept - { - return width_; - } - - /** - * Get the height. - * - * \return the height - */ - inline unsigned height() const noexcept - { - return height_; - } + unsigned height{0}; /** * Check if the size is 0, 0. * * \return true if height and width are 0 */ - inline bool is_null() const noexcept + inline auto is_null() const noexcept -> bool { - return height_ == 0 && width_ == 0; + return height == 0 && width == 0; } }; @@ -82,9 +55,9 @@ * \param s2 the second size * \return true if they equal */ -inline bool operator==(const size& s1, const size& s2) noexcept +inline auto operator==(const size& s1, const size& s2) noexcept -> bool { - return s1.width() == s2.width() && s1.height() == s2.height(); + return s1.width == s2.width && s1.height == s2.height; } /** @@ -94,7 +67,7 @@ * \param s2 the second size * \return false if they equal */ -inline bool operator!=(const size& s1, const size& s2) noexcept +inline auto operator!=(const size& s1, const size& s2) noexcept -> bool { return !(s1 == s2); } @@ -106,9 +79,9 @@ * \param size the size object * \return out */ -inline std::ostream& operator<<(std::ostream& out, const size& size) +inline auto operator<<(std::ostream& out, const size& size) -> std::ostream& { - out << "{" << size.width() << ", " << size.height() << "}"; + out << "{" << size.width << ", " << size.height << "}"; return out; }
--- a/libcommon/malikania/tileset.hpp Fri Aug 17 15:44:12 2018 +0200 +++ b/libcommon/malikania/tileset.hpp Sat Mar 17 14:51:00 2018 +0100 @@ -69,7 +69,7 @@ * * \return the image identifier */ - inline const std::string& image() const noexcept + inline const std::string& get_image() const noexcept { return image_; } @@ -79,7 +79,7 @@ * * \return the cell size */ - inline const size& cell() const noexcept + inline const size& get_cell() const noexcept { return cell_; } @@ -89,7 +89,7 @@ * * \return the properties */ - inline properties_map& properties() noexcept + inline properties_map& get_properties() noexcept { return properties_; } @@ -99,7 +99,7 @@ * * \return the properties */ - inline const properties_map& properties() const noexcept + inline const properties_map& get_properties() const noexcept { return properties_; } @@ -119,7 +119,7 @@ * * \return the properties for each tile */ - inline tile_properties_map& tile_properties() noexcept + inline tile_properties_map& get_tile_properties() noexcept { return tile_properties_; } @@ -129,7 +129,7 @@ * * \return the properties for each tile */ - inline const tile_properties_map& tile_properties() const noexcept + inline const tile_properties_map& get_tile_properties() const noexcept { return tile_properties_; }
--- a/libcommon/malikania/util.cpp Fri Aug 17 15:44:12 2018 +0200 +++ b/libcommon/malikania/util.cpp Sat Mar 17 14:51:00 2018 +0100 @@ -431,8 +431,8 @@ using json_pointer = nlohmann::json::json_pointer; return { - get_uint(object, json_pointer(pointer.to_string() + "/width"), def.width()), - get_uint(object, json_pointer(pointer.to_string() + "/height"), def.height()) + get_uint(object, json_pointer(pointer.to_string() + "/width"), def.width), + get_uint(object, json_pointer(pointer.to_string() + "/height"), def.height) }; }
--- a/tests/libcommon/size/main.cpp Fri Aug 17 15:44:12 2018 +0200 +++ b/tests/libcommon/size/main.cpp Sat Mar 17 14:51:00 2018 +0100 @@ -23,44 +23,44 @@ BOOST_AUTO_TEST_CASE(none) { - mlk::size size; + const mlk::size size; - BOOST_REQUIRE_EQUAL(0U, size.width()); - BOOST_REQUIRE_EQUAL(0U, size.height()); + BOOST_TEST(size.width == 0U); + BOOST_TEST(size.height == 0U); } BOOST_AUTO_TEST_CASE(null) { BOOST_REQUIRE(mlk::size().is_null()); - BOOST_REQUIRE(!mlk::size(0, 10).is_null()); - BOOST_REQUIRE(!mlk::size(10, 0).is_null()); + BOOST_REQUIRE((!mlk::size{0, 10}.is_null())); + BOOST_REQUIRE((!mlk::size{10, 0}.is_null())); } BOOST_AUTO_TEST_CASE(standard) { - mlk::size size(10, 20); + const mlk::size size{10, 20}; - BOOST_REQUIRE_EQUAL(10U, size.width()); - BOOST_REQUIRE_EQUAL(20U, size.height()); + BOOST_TEST(size.width == 10U); + BOOST_TEST(size.height == 20U); } BOOST_AUTO_TEST_CASE(operator_eq) { - mlk::size size1, size2; + const mlk::size size1, size2; - BOOST_REQUIRE_EQUAL(size1, size2); + BOOST_TEST(size1 == size2); } BOOST_AUTO_TEST_CASE(operator_eq_1) { - mlk::size size1(10, 20); - mlk::size size2(10, 20); + const mlk::size size1{10, 20}; + const mlk::size size2{10, 20}; - BOOST_REQUIRE_EQUAL(size1, size2); + BOOST_TEST(size1 == size2); } BOOST_AUTO_TEST_CASE(operator_neq) { - BOOST_REQUIRE_NE(mlk::size(10), mlk::size(20)); - BOOST_REQUIRE_NE(mlk::size(10, 10), mlk::size(10, 20)); + BOOST_TEST((mlk::size{10} != mlk::size{20})); + BOOST_TEST((mlk::size{10, 10} != mlk::size{10, 20})); }
--- a/tests/libcommon/util/main.cpp Fri Aug 17 15:44:12 2018 +0200 +++ b/tests/libcommon/util/main.cpp Sat Mar 17 14:51:00 2018 +0100 @@ -354,7 +354,7 @@ } }; - BOOST_REQUIRE_EQUAL(util::json::require_size(object, "/size"_json_pointer), mlk::size(10, 20)); + BOOST_TEST((util::json::require_size(object, "/size"_json_pointer) == mlk::size{10, 20})); } BOOST_AUTO_TEST_CASE(not_object) @@ -424,23 +424,20 @@ } }; - BOOST_REQUIRE_EQUAL(util::json::get_size(object, "/size"_json_pointer), mlk::size(10, 20)); + BOOST_TEST((util::json::get_size(object, "/size"_json_pointer) == mlk::size{10, 20})); } BOOST_AUTO_TEST_CASE(not_object) { - json object{ - { "size", false } - }; + const json object{{ "size", false }}; + const mlk::size def{10, 20}; - mlk::size def(10, 20); - - BOOST_REQUIRE_EQUAL(util::json::get_size(object, "/size"_json_pointer, def), def); + BOOST_TEST(util::json::get_size(object, "/size"_json_pointer, def) == def); } BOOST_AUTO_TEST_CASE(not_int_width) { - json object{ + const json object{ { "size", { { "width", "10" }, { "height", 20 } @@ -448,14 +445,14 @@ } }; - mlk::size def(10, 20); + const mlk::size def{10, 20}; - BOOST_REQUIRE_EQUAL(util::json::get_size(object, "/size"_json_pointer, def), def); + BOOST_TEST(util::json::get_size(object, "/size"_json_pointer, def) == def); } BOOST_AUTO_TEST_CASE(not_int_height) { - json object{ + const json object{ { "size", { { "width", 10 }, { "height", "20" } @@ -463,9 +460,9 @@ } }; - mlk::size def(10, 20); + const mlk::size def{10, 20}; - BOOST_REQUIRE_EQUAL(util::json::get_size(object, "/size"_json_pointer, def), def); + BOOST_TEST(util::json::get_size(object, "/size"_json_pointer, def) == def); } BOOST_AUTO_TEST_SUITE_END()
--- a/tests/tools/tileset/main.cpp Fri Aug 17 15:44:12 2018 +0200 +++ b/tests/tools/tileset/main.cpp Sat Mar 17 14:51:00 2018 +0100 @@ -45,12 +45,12 @@ for (const auto& t : list) { auto tileset = loader_.load_tileset(t); - BOOST_REQUIRE_EQUAL("worldmapchip5fo.png", tileset.image()); - BOOST_REQUIRE_EQUAL(32U, tileset.cell().width()); - BOOST_REQUIRE_EQUAL(32U, tileset.cell().height()); - BOOST_REQUIRE_EQUAL(3U, tileset.tile_properties().size()); + BOOST_REQUIRE_EQUAL("worldmapchip5fo.png", tileset.get_image()); + BOOST_REQUIRE_EQUAL(32U, tileset.get_cell().width); + BOOST_REQUIRE_EQUAL(32U, tileset.get_cell().height); + BOOST_REQUIRE_EQUAL(3U, tileset.get_tile_properties().size()); - auto tp = tileset.tile_properties(); + auto tp = tileset.get_tile_properties(); // Index 8. BOOST_REQUIRE_EQUAL("value", tp[8]["test"]);