Mercurial > malikania
changeset 30:a1e80d991968
Misc: convert to spaces, #519
line wrap: on
line diff
--- a/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -20,10 +20,10 @@ project(malikania) set( - CMAKE_MODULE_PATH - "${malikania_SOURCE_DIR}/cmake" - "${malikania_SOURCE_DIR}/cmake/internal" - "${malikania_SOURCE_DIR}/cmake/packages" + CMAKE_MODULE_PATH + "${malikania_SOURCE_DIR}/cmake" + "${malikania_SOURCE_DIR}/cmake/internal" + "${malikania_SOURCE_DIR}/cmake/packages" ) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) @@ -34,8 +34,8 @@ include(cmake/MalikaniaSystem.cmake) configure_file( - ${malikania_SOURCE_DIR}/cmake/internal/Config.h.in - ${malikania_BINARY_DIR}/Config.h + ${malikania_SOURCE_DIR}/cmake/internal/Config.h.in + ${malikania_BINARY_DIR}/Config.h ) include_directories(${CMAKE_BINARY_DIR})
--- a/client/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/client/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -19,8 +19,8 @@ project(client) set( - FILES - main.cpp + FILES + main.cpp ) add_executable(mlk-client ${FILES})
--- a/client/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/client/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -43,142 +43,142 @@ int usage() { - std::cerr << "usage: mlk-client directory\n"; + std::cerr << "usage: mlk-client directory\n"; - return 1; + return 1; } duk::Context init() { - duk::Context ctx; + duk::Context ctx; - /* TODO: Put Malikania global somewhere else */ - duk::putGlobal(ctx, "Malikania", duk::Object()); + /* TODO: Put Malikania global somewhere else */ + duk::putGlobal(ctx, "Malikania", duk::Object()); - loadMalikaniaAnimation(ctx); - loadMalikaniaAnimator(ctx); - loadMalikaniaColor(ctx); - loadMalikaniaFont(ctx); - loadMalikaniaImage(ctx); - loadMalikaniaLine(ctx); - loadMalikaniaPoint(ctx); - loadMalikaniaRectangle(ctx); - loadMalikaniaSize(ctx); - loadMalikaniaSprite(ctx); - loadMalikaniaWindow(ctx); - loadMalikaniaClient(ctx); - loadMalikaniaClientTarget(ctx); + loadMalikaniaAnimation(ctx); + loadMalikaniaAnimator(ctx); + loadMalikaniaColor(ctx); + loadMalikaniaFont(ctx); + loadMalikaniaImage(ctx); + loadMalikaniaLine(ctx); + loadMalikaniaPoint(ctx); + loadMalikaniaRectangle(ctx); + loadMalikaniaSize(ctx); + loadMalikaniaSprite(ctx); + loadMalikaniaWindow(ctx); + loadMalikaniaClient(ctx); + loadMalikaniaClientTarget(ctx); - return ctx; + return ctx; } void start(duk::Context &ctx, std::shared_ptr<Client> client) { - duk::getGlobal<void>(ctx, "start"); + duk::getGlobal<void>(ctx, "start"); - if (duk::is<duk::Function>(ctx, -1)) { - duk::push(ctx, std::move(client)); - duk::pcall(ctx, 1); - duk::pop(ctx); - } else { - duk::pop(ctx); - } + if (duk::is<duk::Function>(ctx, -1)) { + duk::push(ctx, std::move(client)); + duk::pcall(ctx, 1); + duk::pop(ctx); + } else { + duk::pop(ctx); + } } void update(duk::Context &ctx, std::shared_ptr<Client> client) { - duk::getGlobal<void>(ctx, "update"); + duk::getGlobal<void>(ctx, "update"); - if (duk::is<duk::Function>(ctx, -1)) { - duk::push(ctx, std::move(client)); - duk::pcall(ctx, 1); - duk::pop(ctx); - } else { - duk::pop(ctx); - client->update(); - } + if (duk::is<duk::Function>(ctx, -1)) { + duk::push(ctx, std::move(client)); + duk::pcall(ctx, 1); + duk::pop(ctx); + } else { + duk::pop(ctx); + client->update(); + } } void draw(duk::Context &ctx, std::shared_ptr<Client> client) { - duk::getGlobal<void>(ctx, "draw"); + duk::getGlobal<void>(ctx, "draw"); - if (duk::is<duk::Function>(ctx, -1)) { - duk::push(ctx, std::move(client)); - duk::pcall(ctx, 1); - duk::pop(ctx); - } else { - duk::pop(ctx); - client->draw(); - } + if (duk::is<duk::Function>(ctx, -1)) { + duk::push(ctx, std::move(client)); + duk::pcall(ctx, 1); + duk::pop(ctx); + } else { + duk::pop(ctx); + client->draw(); + } } int run(duk::Context &ctx) { - auto running = true; - auto client = std::make_shared<Client>(); + auto running = true; + auto client = std::make_shared<Client>(); - client->setOnQuit([&] () { - running = false; - }); - client->setOnKeyDown([&] (unsigned key) { - duk::getGlobal<void>(ctx, "keyDown"); + client->setOnQuit([&] () { + running = false; + }); + client->setOnKeyDown([&] (unsigned key) { + duk::getGlobal<void>(ctx, "keyDown"); - if (duk::is<duk::Function>(ctx, -1)) { - duk::push(ctx, static_cast<int>(key)); - duk::pcall(ctx, 1); - duk::pop(ctx); - } else { - duk::pop(ctx); - } - }); - client->setOnKeyDown([&] (unsigned key) { - duk::getGlobal<void>(ctx, "keyUp"); + if (duk::is<duk::Function>(ctx, -1)) { + duk::push(ctx, static_cast<int>(key)); + duk::pcall(ctx, 1); + duk::pop(ctx); + } else { + duk::pop(ctx); + } + }); + client->setOnKeyDown([&] (unsigned key) { + duk::getGlobal<void>(ctx, "keyUp"); - if (duk::is<duk::Function>(ctx, -1)) { - duk::push(ctx, static_cast<int>(key)); - duk::pcall(ctx, 1); - duk::pop(ctx); - } else { - duk::pop(ctx); - } - }); + if (duk::is<duk::Function>(ctx, -1)) { + duk::push(ctx, static_cast<int>(key)); + duk::pcall(ctx, 1); + duk::pop(ctx); + } else { + duk::pop(ctx); + } + }); - start(ctx, client); + start(ctx, client); - while (running) { - client->poll(); + while (running) { + client->poll(); - update(ctx, client); - draw(ctx, client); + update(ctx, client); + draw(ctx, client); - // TODO: remove this with an appropriate FPS calculation. - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } + // TODO: remove this with an appropriate FPS calculation. + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } - return 0; + return 0; } int boot(const std::string &directory) { - std::string path = directory + "/client.js"; - duk::Context ctx = init(); + std::string path = directory + "/client.js"; + duk::Context ctx = init(); - /* Store the loader */ - ResourcesLocatorDirectory locator(directory); - ClientResourcesLoader loader(locator); + /* Store the loader */ + ResourcesLocatorDirectory locator(directory); + ClientResourcesLoader loader(locator); - duk::putGlobal(ctx, "\xff""\xff""loader", &loader); + duk::putGlobal(ctx, "\xff""\xff""loader", &loader); - if (duk::pevalFile(ctx, path) != 0) { - duk::Exception info = duk::exception(ctx, -1); + if (duk::pevalFile(ctx, path) != 0) { + duk::Exception info = duk::exception(ctx, -1); - std::cerr << info.fileName << ":" << info.lineNumber << ": " << info.stack << std::endl; + std::cerr << info.fileName << ":" << info.lineNumber << ": " << info.stack << std::endl; - return 1; - } + return 1; + } - return run(ctx); + return run(ctx); } } // !namespace @@ -186,25 +186,25 @@ int main(int argc, char **argv) { #if 0 - -- argc; - ++ argv; + -- argc; + ++ argv; - if (argc < 1) { - return usage(); - } + if (argc < 1) { + return usage(); + } - return boot(argv[0]); + return boot(argv[0]); #endif - Client client; - ElapsedTimer timer; + Client client; + ElapsedTimer timer; - while (timer.elapsed() < 5000) { - client.poll(); - client.update(); - client.draw(); + while (timer.elapsed() < 5000) { + client.poll(); + client.update(); + client.draw(); - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } - return 0; + return 0; }
--- a/cmake/CMake.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/CMake.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -21,37 +21,37 @@ # # The following files will be installed: # -# MalikaniaConfig - Include all Malikania CMake files -# MalikaniaVersion - The version of the engine -# MalikaniaSystem - Platform specific definitions -# MalikaniaMacros - Malikania public macros +# MalikaniaConfig - Include all Malikania CMake files +# MalikaniaVersion - The version of the engine +# MalikaniaSystem - Platform specific definitions +# MalikaniaMacros - Malikania public macros # set( - FILES - MalikaniaConfig.cmake - Macros.cmake - System.cmake - Version.cmake + FILES + MalikaniaConfig.cmake + Macros.cmake + System.cmake + Version.cmake ) if (WIN32) - set(DIRECTORY "Malikania") + set(DIRECTORY "Malikania") elseif (UNIX) - set(DIRECTORY "share/malikania/cmake") + set(DIRECTORY "share/malikania/cmake") elseif (APPLE) - set(DIRECTORY "malikania.framework/Resources/CMake") + set(DIRECTORY "malikania.framework/Resources/CMake") endif () install( - FILES ${FILES} - DESTINATION ${DIRECTORY} + FILES ${FILES} + DESTINATION ${DIRECTORY} ) set( - CMAKE_SOURCES - ${CMAKE_CURRENT_LIST_DIR}/CMake.cmake - ${CMAKE_CURRENT_LIST_DIR}/MalikaniaConfig.cmake - ${CMAKE_CURRENT_LIST_DIR}/MalikaniaFunctions.cmake - ${CMAKE_CURRENT_LIST_DIR}/MalikaniaSystem.cmake - ${CMAKE_CURRENT_LIST_DIR}/MalikaniaVersion.cmake + CMAKE_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/CMake.cmake + ${CMAKE_CURRENT_LIST_DIR}/MalikaniaConfig.cmake + ${CMAKE_CURRENT_LIST_DIR}/MalikaniaFunctions.cmake + ${CMAKE_CURRENT_LIST_DIR}/MalikaniaSystem.cmake + ${CMAKE_CURRENT_LIST_DIR}/MalikaniaVersion.cmake )
--- a/cmake/MalikaniaFunctions.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/MalikaniaFunctions.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -25,11 +25,11 @@ # --------------------------- # # malikania_define_executable( -# TARGET The target name -# SOURCES The list of sources -# FLAGS (Optional) List of flags -# INCLUDES (Optional) List of include directories -# LIBRARIES (Optional) List of libraries +# TARGET The target name +# SOURCES The list of sources +# FLAGS (Optional) List of flags +# INCLUDES (Optional) List of include directories +# LIBRARIES (Optional) List of libraries # ) # # Create an executable. Be sure to quote SOURCES, if not only the first file will be passed. @@ -39,12 +39,12 @@ # ------------------------ # # malikania_create_library( -# TARGET The target name -# SOURCES The sources -# FLAGS (Optional) List of flags -# PRIVATE_INCLUDES (Optional) List of includes only for building the library -# PUBLIC_INCLUDES (Optional) List of public includes to share with the library users -# LIBRARIES (Optional) List of libraries to link against +# TARGET The target name +# SOURCES The sources +# FLAGS (Optional) List of flags +# PRIVATE_INCLUDES (Optional) List of includes only for building the library +# PUBLIC_INCLUDES (Optional) List of public includes to share with the library users +# LIBRARIES (Optional) List of libraries to link against # ) # # Create a shared library. Follow the same specification as malikania_define_executable. @@ -54,10 +54,10 @@ # --------------------- # # malikania_create_test( -# NAME Test name (must be lowercase) -# SOURCES Test sources files -# LIBRARIES (Optional) Libraries to link to -# RESOURCES (Optional) Resources files to copy verbatim +# NAME Test name (must be lowercase) +# SOURCES Test sources files +# LIBRARIES (Optional) Libraries to link to +# RESOURCES (Optional) Resources files to copy verbatim # ) # # This will generate a target named test-<name> where name is the parameter NAME. The test is created @@ -73,152 +73,152 @@ # --------------------------------------------------------- function(apply_flags target flags) - # Add MALIKANIA_BUILD to enable declspec(dllexport) on Windows - if (${flags}) - target_compile_definitions( - ${target} - PRIVATE ${flags} - PRIVATE "MALIKANIA_BUILD" - ) - endif () + # Add MALIKANIA_BUILD to enable declspec(dllexport) on Windows + if (${flags}) + target_compile_definitions( + ${target} + PRIVATE ${flags} + PRIVATE "MALIKANIA_BUILD" + ) + endif () endfunction() function(apply_public_includes target var) - if (${var}) - target_include_directories(${target} PUBLIC ${${var}}) - endif () + if (${var}) + target_include_directories(${target} PUBLIC ${${var}}) + endif () - target_include_directories( - ${target} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ) + target_include_directories( + ${target} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + ) endfunction() function(apply_private_includes target var) - if (${var}) - target_include_directories(${target} PRIVATE ${${var}}) - endif () + if (${var}) + target_include_directories(${target} PRIVATE ${${var}}) + endif () endfunction() function(apply_includes target var) - if (${var}) - target_include_directories(${target} PRIVATE ${${var}}) - endif () + if (${var}) + target_include_directories(${target} PRIVATE ${${var}}) + endif () endfunction() function(apply_libraries target libs) - if (${libs}) - target_link_libraries(${target} ${${libs}}) - endif () + if (${libs}) + target_link_libraries(${target} ${${libs}}) + endif () endfunction() function(check_args prefix list) - foreach (e ${list}) - if (NOT ${prefix}_${e}) - message(FATAL_ERROR "Please set `${e}' parameter") - endif () - endforeach () + foreach (e ${list}) + if (NOT ${prefix}_${e}) + message(FATAL_ERROR "Please set `${e}' parameter") + endif () + endforeach () endfunction() function(malikania_define_executable) - set(singleArgs TARGET) - set(multiArgs SOURCES FLAGS INCLUDES LIBRARIES) - set(mandatory TARGET SOURCES) + set(singleArgs TARGET) + set(multiArgs SOURCES FLAGS INCLUDES LIBRARIES) + set(mandatory TARGET SOURCES) - cmake_parse_arguments(EXE "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(EXE ${mandatory}) + cmake_parse_arguments(EXE "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(EXE ${mandatory}) - add_executable(${EXE_TARGET} ${EXE_SOURCES}) + add_executable(${EXE_TARGET} ${EXE_SOURCES}) - apply_libraries(${EXE_TARGET} EXE_LIBRARIES) - apply_includes(${EXE_TARGET} EXE_INCLUDES) - apply_flags(${EXE_TARGET} EXE_FLAGS) + apply_libraries(${EXE_TARGET} EXE_LIBRARIES) + apply_includes(${EXE_TARGET} EXE_INCLUDES) + apply_flags(${EXE_TARGET} EXE_FLAGS) endfunction() function(malikania_create_library) - set(singleArgs TARGET) - set(multiArgs SOURCES FLAGS PRIVATE_INCLUDES PUBLIC_INCLUDES LIBRARIES) - set(mandatory TARGET SOURCES) + set(singleArgs TARGET) + set(multiArgs SOURCES FLAGS PRIVATE_INCLUDES PUBLIC_INCLUDES LIBRARIES) + set(mandatory TARGET SOURCES) - cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(LIB ${mandatory}) + cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(LIB ${mandatory}) - add_library(${LIB_TARGET} SHARED ${LIB_SOURCES}) + add_library(${LIB_TARGET} SHARED ${LIB_SOURCES}) - # Remove lib suffix to avoid conflict with client and libclient targets - set_target_properties( - ${LIB_TARGET} - PROPERTIES - PREFIX "" - ) + # Remove lib suffix to avoid conflict with client and libclient targets + set_target_properties( + ${LIB_TARGET} + PROPERTIES + PREFIX "" + ) - list(APPEND LIB_LIBRARIES duktape) + list(APPEND LIB_LIBRARIES duktape) - apply_libraries(${LIB_TARGET} LIB_LIBRARIES) - apply_private_includes(${LIB_TARGET} LIB_PRIVATE_INCLUDES) - apply_public_includes(${LIB_TARGET} LIB_PUBLIC_INCLUDES) - apply_flags(${LIB_TARGET} LIB_FLAGS) + apply_libraries(${LIB_TARGET} LIB_LIBRARIES) + apply_private_includes(${LIB_TARGET} LIB_PRIVATE_INCLUDES) + apply_public_includes(${LIB_TARGET} LIB_PUBLIC_INCLUDES) + apply_flags(${LIB_TARGET} LIB_FLAGS) endfunction() function(malikania_create_test) - set(singleArgs NAME) - set(multiArgs LIBRARIES SOURCES RESOURCES) + set(singleArgs NAME) + set(multiArgs LIBRARIES SOURCES RESOURCES) - set(mandatory NAME SOURCES) + set(mandatory NAME SOURCES) - cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(TEST ${mandatory}) + cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(TEST ${mandatory}) - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) - if (UNIX) - list(APPEND TEST_LIBRARIES pthread) - endif () + if (UNIX) + list(APPEND TEST_LIBRARIES pthread) + endif () - # Resources files added before as custom output - foreach (f ${TEST_RESOURCES}) - get_filename_component(absolute ${f} ABSOLUTE) - file(RELATIVE_PATH basename ${CMAKE_CURRENT_SOURCE_DIR} ${absolute}) - set(output ${CMAKE_BINARY_DIR}/test/${TEST_NAME}/${basename}) + # Resources files added before as custom output + foreach (f ${TEST_RESOURCES}) + get_filename_component(absolute ${f} ABSOLUTE) + file(RELATIVE_PATH basename ${CMAKE_CURRENT_SOURCE_DIR} ${absolute}) + set(output ${CMAKE_BINARY_DIR}/test/${TEST_NAME}/${basename}) - add_custom_command( - OUTPUT ${output} - COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} - DEPENDS ${absolute} - ) + add_custom_command( + OUTPUT ${output} + COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} + DEPENDS ${absolute} + ) - list(APPEND TEST_SOURCES ${absolute}) - list(APPEND outputs ${output}) - endforeach () + list(APPEND TEST_SOURCES ${absolute}) + list(APPEND outputs ${output}) + endforeach () - add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs}) - source_group(private\\Resources FILES ${outputs}) - target_compile_definitions(test-${TEST_NAME} PRIVATE SOURCE_DIRECTORY=\"${CMAKE_BINARY_DIR}/test/${TEST_NAME}\") - set_target_properties( - test-${TEST_NAME} - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - ) - add_test( - NAME ${TEST_NAME} - COMMAND $<TARGET_FILE:test-${TEST_NAME}> - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} - ) + add_executable(test-${TEST_NAME} ${TEST_SOURCES} ${outputs}) + source_group(private\\Resources FILES ${outputs}) + target_compile_definitions(test-${TEST_NAME} PRIVATE SOURCE_DIRECTORY=\"${CMAKE_BINARY_DIR}/test/${TEST_NAME}\") + set_target_properties( + test-${TEST_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + ) + add_test( + NAME ${TEST_NAME} + COMMAND $<TARGET_FILE:test-${TEST_NAME}> + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME} + ) - target_link_libraries( - test-${TEST_NAME} - ${TEST_LIBRARIES} - gtest - ) + target_link_libraries( + test-${TEST_NAME} + ${TEST_LIBRARIES} + gtest + ) - add_dependencies(tests test-${TEST_NAME}) + add_dependencies(tests test-${TEST_NAME}) endfunction() macro(setg var value) - set(${var} ${value} CACHE INTERNAL "" FORCE) + set(${var} ${value} CACHE INTERNAL "" FORCE) endmacro()
--- a/cmake/MalikaniaOptions.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/MalikaniaOptions.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -21,37 +21,37 @@ # ------------------------------------------------------------------- # # The following options are available: -# WITH_BACKEND - Type of backend to use. (Default: SDL) +# WITH_BACKEND - Type of backend to use. (Default: SDL) # set(WITH_BACKEND "SDL" - CACHE STRING "Which backend to use") + CACHE STRING "Which backend to use") # # Documentation and technical references # ------------------------------------------------------------------- # # The following options are available: -# WITH_DOCS - Disable or enable all docs, if set to Off, disable all documentation. -# WITH_DOXYGEN - Enable doxygen +# WITH_DOCS - Disable or enable all docs, if set to Off, disable all documentation. +# WITH_DOXYGEN - Enable doxygen # option(WITH_DOCS "Build all documentation" On) option(WITH_DOXYGEN "Enable doxygen generation" On) if (NOT WITH_DOCS) - set(WITH_DOXYGEN Off) + set(WITH_DOXYGEN Off) endif () set(WITH_DRIVERDIR "lib/malikania/${MALIKANIA_VERSION}" - CACHE STRING "Database driver directory") + CACHE STRING "Database driver directory") set(WITH_BINDIR "libexec/malikania/${MALIKANIA_VERSION}" - CACHE STRING "Front end directory") + CACHE STRING "Front end directory") if (IS_ABSOLUTE ${WITH_DRIVERDIR}) - message(FATAL_ERROR "WITH_DRIVERDIR must not be absolute") + message(FATAL_ERROR "WITH_DRIVERDIR must not be absolute") elseif (IS_ABSOLUTE ${WITH_BINDIR}) - message(FATAL_ERROR "WITH_BINDIR must not be absolute") + message(FATAL_ERROR "WITH_BINDIR must not be absolute") endif () # @@ -60,34 +60,34 @@ # set(WITH_TEST_PGSQL_HOST "localhost" - CACHE STRING "Hostname for PostgreSQL driver") + CACHE STRING "Hostname for PostgreSQL driver") set(WITH_TEST_PGSQL_PORT "5432" - CACHE STRING "Port for PostgreSQL driver") + CACHE STRING "Port for PostgreSQL driver") set(WITH_TEST_PGSQL_DATABASE "malikaniadb" - CACHE STRING "Database for PostgreSQL driver") + CACHE STRING "Database for PostgreSQL driver") set(WITH_TEST_PGSQL_USER "malikania" - CACHE STRING "Username for PostgreSQL driver") + CACHE STRING "Username for PostgreSQL driver") # # Targets to build # ------------------------------------------------------------------- # # The following options are available: -# WITH_LIBCLIENT - Build the client library. -# WITH_LIBSERVER - Build the server library. +# WITH_LIBCLIENT - Build the client library. +# WITH_LIBSERVER - Build the server library. # option(WITH_LIBCLIENT "Build libclient" On) option(WITH_LIBSERVER "Build libserver" On) if (WITH_BACKEND MATCHES "SDL") - set(WITH_BACKEND_SDL TRUE) - set(WITH_BACKEND_DIRECTORY "backend/sdl") + set(WITH_BACKEND_SDL TRUE) + set(WITH_BACKEND_DIRECTORY "backend/sdl") else () - message(FATAL_ERROR "Unknown backend selected: ${WITH_BACKEND}") + message(FATAL_ERROR "Unknown backend selected: ${WITH_BACKEND}") endif () configure_file( - ${malikania_SOURCE_DIR}/cmake/internal/sysconfig-tests.h - ${malikania_BINARY_DIR}/sysconfig-tests.h + ${malikania_SOURCE_DIR}/cmake/internal/sysconfig-tests.h + ${malikania_BINARY_DIR}/sysconfig-tests.h )
--- a/cmake/MalikaniaSystem.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/MalikaniaSystem.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -22,32 +22,32 @@ # instead. # if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # - # For GCC, we require at least GCC 5.1 - # - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1") - message(FATAL_ERROR "You need at least GCC 5.1") - endif () + # + # For GCC, we require at least GCC 5.1 + # + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1") + message(FATAL_ERROR "You need at least GCC 5.1") + endif () - set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 ${CMAKE_CXX_FLAGS}") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # - # LLVM/clang implemented C++14 starting from version 3.4 but the - # switch -std=c++14 was not available. - # - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4") - message(FATAL_ERROR "You need at least Clang 3.4") - endif () + # + # LLVM/clang implemented C++14 starting from version 3.4 but the + # switch -std=c++14 was not available. + # + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4") + message(FATAL_ERROR "You need at least Clang 3.4") + endif () - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5") - set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++1y ${CMAKE_CXX_FLAGS}") - else () - set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 ${CMAKE_CXX_FLAGS}") - endif () + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5") + set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++1y ${CMAKE_CXX_FLAGS}") + else () + set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 ${CMAKE_CXX_FLAGS}") + endif () else () - message(WARNING "Unsupported ${CMAKE_CXX_COMPILER_ID}, may not build correctly.") + message(WARNING "Unsupported ${CMAKE_CXX_COMPILER_ID}, may not build correctly.") endif () if (MINGW) - set(CMAKE_CXX_FLAGS "-D_WIN32_WINNT=0x0600 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-D_WIN32_WINNT=0x0600 ${CMAKE_CXX_FLAGS}") endif ()
--- a/cmake/packages/FindPandoc.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/packages/FindPandoc.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -10,25 +10,25 @@ # This module also defines the following macros: # # pandoc( -# SOURCES file1 [file2 ...] -# OUTPUT output -# [FROM format] -# [TO format] -# [TARGET target] -# [DEPENDS dependency ...] -# [ALL] -# [TOC] -# [STANDALONE] -# [MAKE_DIRECTORY] -# [TEMPLATE file] -# [FILTER filter] -# [HEADER header ...] -# [FOOTER footer ...] -# [BODY body ...] -# [VARIABLE var ...] -# [METADATA meta ...] -# [ARGS argument ...] -# [WORKING_DIRECTORY directory] +# SOURCES file1 [file2 ...] +# OUTPUT output +# [FROM format] +# [TO format] +# [TARGET target] +# [DEPENDS dependency ...] +# [ALL] +# [TOC] +# [STANDALONE] +# [MAKE_DIRECTORY] +# [TEMPLATE file] +# [FILTER filter] +# [HEADER header ...] +# [FOOTER footer ...] +# [BODY body ...] +# [VARIABLE var ...] +# [METADATA meta ...] +# [ARGS argument ...] +# [WORKING_DIRECTORY directory] # ) # # The sources files are listed in the parameter SOURCES, all files are passed @@ -75,9 +75,9 @@ # find_program( - Pandoc_EXECUTABLE - NAMES pandoc - DOC "Pandoc executable" + Pandoc_EXECUTABLE + NAMES pandoc + DOC "Pandoc executable" ) include(FindPackageHandleStandardArgs) @@ -85,147 +85,147 @@ # Extract the version if (Pandoc_EXECUTABLE) - execute_process( - COMMAND ${Pandoc_EXECUTABLE} --version - OUTPUT_VARIABLE _pandoc_version_tmp - ) + execute_process( + COMMAND ${Pandoc_EXECUTABLE} --version + OUTPUT_VARIABLE _pandoc_version_tmp + ) - if (_pandoc_version_tmp MATCHES "^pandoc[^ ]* ([0-9]+\\.[0-9]+\\.[0-9]+)") - set(Pandoc_VERSION "${CMAKE_MATCH_1}") - endif () + if (_pandoc_version_tmp MATCHES "^pandoc[^ ]* ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(Pandoc_VERSION "${CMAKE_MATCH_1}") + endif () endif () find_package_handle_standard_args( - Pandoc - FOUND_VAR Pandoc_FOUND - VERSION_VAR Pandoc_VERSION - REQUIRED_VARS Pandoc_EXECUTABLE + Pandoc + FOUND_VAR Pandoc_FOUND + VERSION_VAR Pandoc_VERSION + REQUIRED_VARS Pandoc_EXECUTABLE ) if (Pandoc_FOUND) - function(pandoc) - set(options MAKE_DIRECTORY STANDALONE TOC) - set(oneValueArgs FILTER FROM TARGET TEMPLATE TO OUTPUT WORKING_DIRECTORY) - set(multiValueArgs ARGS FOOTER HEADER METADATA SOURCES VARIABLE) + function(pandoc) + set(options MAKE_DIRECTORY STANDALONE TOC) + set(oneValueArgs FILTER FROM TARGET TEMPLATE TO OUTPUT WORKING_DIRECTORY) + set(multiValueArgs ARGS FOOTER HEADER METADATA SOURCES VARIABLE) - # - # The following variables will be set in that scope: - # _pandoc_arguments - List of all arguments that will passed to pandoc invocation. - # _pandoc_depends - List of all dependencies attached to the add_custom_command. - # _pandoc_mkdir - The mkdir command if MAKE_DIRECTORY is set - # _pandoc_output_base - The base output directory - # - cmake_parse_arguments(PANDOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + # + # The following variables will be set in that scope: + # _pandoc_arguments - List of all arguments that will passed to pandoc invocation. + # _pandoc_depends - List of all dependencies attached to the add_custom_command. + # _pandoc_mkdir - The mkdir command if MAKE_DIRECTORY is set + # _pandoc_output_base - The base output directory + # + cmake_parse_arguments(PANDOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - # - # Output and sources are mandatory - # - if (NOT PANDOC_OUTPUT) - message(FATAL_ERROR "Please define OUTPUT") - elseif (NOT PANDOC_SOURCES) - message(FATAL_ERROR "Please defines SOURCES") - endif () + # + # Output and sources are mandatory + # + if (NOT PANDOC_OUTPUT) + message(FATAL_ERROR "Please define OUTPUT") + elseif (NOT PANDOC_SOURCES) + message(FATAL_ERROR "Please defines SOURCES") + endif () - # - # Handle the filter with care. - # - # 1. If it is a target, depend on it and use a generator - # expression to get its full path on the disk. - # 2. If it is not a target, just use the user provided path. - # - if (PANDOC_FILTER) - # If it is a target, add a dependency so that it is built - if (TARGET ${PANDOC_FILTER}) - list(APPEND _pandoc_arguments --filter "$<TARGET_FILE:${PANDOC_FILTER}>") - list(APPEND _pandoc_depends ${PANDOC_FILTER}) - else () - list(APPEND _pandoc_arguments --filter ${PANDOC_FILTER}) - endif () - endif () + # + # Handle the filter with care. + # + # 1. If it is a target, depend on it and use a generator + # expression to get its full path on the disk. + # 2. If it is not a target, just use the user provided path. + # + if (PANDOC_FILTER) + # If it is a target, add a dependency so that it is built + if (TARGET ${PANDOC_FILTER}) + list(APPEND _pandoc_arguments --filter "$<TARGET_FILE:${PANDOC_FILTER}>") + list(APPEND _pandoc_depends ${PANDOC_FILTER}) + else () + list(APPEND _pandoc_arguments --filter ${PANDOC_FILTER}) + endif () + endif () - if (PANDOC_TOC) - list(APPEND _pandoc_arguments --toc) - endif () - if (PANDOC_STANDALONE) - list(APPEND _pandoc_arguments -s) - endif () - if (PANDOC_FROM) - list(APPEND _pandoc_arguments -f ${PANDOC_FROM}) - endif () - if (PANDOC_TO) - list(APPEND _pandoc_arguments -t ${PANDOC_TO}) - endif () - if (PANDOC_TEMPLATE) - list(APPEND _pandoc_arguments --template ${PANDOC_TEMPLATE}) - list(APPEND _pandoc_depends ${PANDOC_TEMPLATE}) - endif () + if (PANDOC_TOC) + list(APPEND _pandoc_arguments --toc) + endif () + if (PANDOC_STANDALONE) + list(APPEND _pandoc_arguments -s) + endif () + if (PANDOC_FROM) + list(APPEND _pandoc_arguments -f ${PANDOC_FROM}) + endif () + if (PANDOC_TO) + list(APPEND _pandoc_arguments -t ${PANDOC_TO}) + endif () + if (PANDOC_TEMPLATE) + list(APPEND _pandoc_arguments --template ${PANDOC_TEMPLATE}) + list(APPEND _pandoc_depends ${PANDOC_TEMPLATE}) + endif () - # Header, footers and body - foreach (h ${PANDOC_HEADER}) - list(APPEND _pandoc_arguments -H ${h}) - list(APPEND _pandoc_depends ${h}) - endforeach () - foreach (b ${PANDOC_BODY}) - list(APPEND _pandoc_arguments -B ${b}) - list(APPEND _pandoc_depends ${b}) - endforeach () - foreach (f ${PANDOC_FOOTER}) - list(APPEND _pandoc_arguments -A ${f}) - list(APPEND _pandoc_depends ${f}) - endforeach () + # Header, footers and body + foreach (h ${PANDOC_HEADER}) + list(APPEND _pandoc_arguments -H ${h}) + list(APPEND _pandoc_depends ${h}) + endforeach () + foreach (b ${PANDOC_BODY}) + list(APPEND _pandoc_arguments -B ${b}) + list(APPEND _pandoc_depends ${b}) + endforeach () + foreach (f ${PANDOC_FOOTER}) + list(APPEND _pandoc_arguments -A ${f}) + list(APPEND _pandoc_depends ${f}) + endforeach () - # Variables and metadata - foreach (var ${PANDOC_VARIABLE}) - list(APPEND _pandoc_arguments -V ${var}) - endforeach () - foreach (meta ${PANDOC_METADATA}) - list(APPEND _pandoc_arguments -M ${meta}) - endforeach () + # Variables and metadata + foreach (var ${PANDOC_VARIABLE}) + list(APPEND _pandoc_arguments -V ${var}) + endforeach () + foreach (meta ${PANDOC_METADATA}) + list(APPEND _pandoc_arguments -M ${meta}) + endforeach () - # Optional list of arguments - foreach (arg ${PANDOC_ARGS}) - list(APPEND _pandoc_arguments ${arg}) - endforeach () + # Optional list of arguments + foreach (arg ${PANDOC_ARGS}) + list(APPEND _pandoc_arguments ${arg}) + endforeach () - # Output and sources - list(APPEND _pandoc_arguments -o ${PANDOC_OUTPUT}) + # Output and sources + list(APPEND _pandoc_arguments -o ${PANDOC_OUTPUT}) - # - # The following variables are set within the loop: - # - # _pandoc_input - The absolute path to the input file. - # _pandoc_output_base - The base output directory. - # - foreach (s ${PANDOC_SOURCES}) - get_filename_component(_pandoc_input ${s} ABSOLUTE) - get_filename_component(_pandoc_output_base ${PANDOC_OUTPUT} DIRECTORY) - list(APPEND _pandoc_depends ${_pandoc_input}) - list(APPEND _pandoc_arguments ${_pandoc_input}) - endforeach () + # + # The following variables are set within the loop: + # + # _pandoc_input - The absolute path to the input file. + # _pandoc_output_base - The base output directory. + # + foreach (s ${PANDOC_SOURCES}) + get_filename_component(_pandoc_input ${s} ABSOLUTE) + get_filename_component(_pandoc_output_base ${PANDOC_OUTPUT} DIRECTORY) + list(APPEND _pandoc_depends ${_pandoc_input}) + list(APPEND _pandoc_arguments ${_pandoc_input}) + endforeach () - # Create the output directory if requested - if (PANDOC_MAKE_DIRECTORY) - set(_pandoc_mkdir ${CMAKE_COMMAND} -E make_directory ${_pandoc_output_base}) - endif () + # Create the output directory if requested + if (PANDOC_MAKE_DIRECTORY) + set(_pandoc_mkdir ${CMAKE_COMMAND} -E make_directory ${_pandoc_output_base}) + endif () - add_custom_command( - OUTPUT ${PANDOC_OUTPUT} - COMMAND ${_pandoc_mkdir} - COMMAND ${Pandoc_EXECUTABLE} ${_pandoc_arguments} - DEPENDS ${_pandoc_depends} ${PANDOC_DEPENDS} - WORKING_DIRECTORY ${PANDOC_WORKING_DIRECTORY} - VERBATIM - ) + add_custom_command( + OUTPUT ${PANDOC_OUTPUT} + COMMAND ${_pandoc_mkdir} + COMMAND ${Pandoc_EXECUTABLE} ${_pandoc_arguments} + DEPENDS ${_pandoc_depends} ${PANDOC_DEPENDS} + WORKING_DIRECTORY ${PANDOC_WORKING_DIRECTORY} + VERBATIM + ) - if (PANDOC_TARGET) - add_custom_target( - ${PANDOC_TARGET} ${PANDOC_ALL} - SOURCES ${_pandoc_depends} - DEPENDS ${PANDOC_OUTPUT} - WORKING_DIRECTORY ${PANDOC_WORKING_DIRECTORY} - ) - endif () - endfunction() + if (PANDOC_TARGET) + add_custom_target( + ${PANDOC_TARGET} ${PANDOC_ALL} + SOURCES ${_pandoc_depends} + DEPENDS ${PANDOC_OUTPUT} + WORKING_DIRECTORY ${PANDOC_WORKING_DIRECTORY} + ) + endif () + endfunction() endif () mark_as_advanced(Pandoc_EXECUTABLE)
--- a/cmake/packages/FindSDL2.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/packages/FindSDL2.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -13,9 +13,9 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - SDL2 - FOUND_VAR SDL2_FOUND - REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR + SDL2 + FOUND_VAR SDL2_FOUND + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR ) set(SDL2_LIBRARIES ${SDL2_LIBRARY})
--- a/cmake/packages/FindZIP.cmake Thu May 26 07:32:05 2016 +0200 +++ b/cmake/packages/FindZIP.cmake Thu Jun 16 13:35:31 2016 +0200 @@ -10,42 +10,42 @@ find_package(ZLIB QUIET) find_path( - ZIP_INCLUDE_DIR - NAMES zip.h + ZIP_INCLUDE_DIR + NAMES zip.h ) find_library( - ZIP_LIBRARY - NAMES zip libzip + ZIP_LIBRARY + NAMES zip libzip ) find_path( - ZIPCONF_INCLUDE_DIR - NAMES zipconf.h + ZIPCONF_INCLUDE_DIR + NAMES zipconf.h ) if (NOT ZIPCONF_INCLUDE_DIR) - # zipconf.h is sometimes directly in the include/ folder but on some systems - # like Windows, it is installed in the lib/ directory. - get_filename_component(_ZIP_PRIVATE_LIBRARY "${ZIP_LIBRARY}" DIRECTORY) + # zipconf.h is sometimes directly in the include/ folder but on some systems + # like Windows, it is installed in the lib/ directory. + get_filename_component(_ZIP_PRIVATE_LIBRARY "${ZIP_LIBRARY}" DIRECTORY) - find_path( - ZIPCONF_INCLUDE_DIR - NAMES zipconf.h - PATHS "${_ZIP_PRIVATE_LIBRARY}/libzip/include" - ) + find_path( + ZIPCONF_INCLUDE_DIR + NAMES zipconf.h + PATHS "${_ZIP_PRIVATE_LIBRARY}/libzip/include" + ) endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - ZIP - REQUIRED_VARS ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS ZIP_LIBRARY ZIP_INCLUDE_DIR ZIPCONF_INCLUDE_DIR + ZIP + REQUIRED_VARS ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS ZIP_LIBRARY ZIP_INCLUDE_DIR ZIPCONF_INCLUDE_DIR ) if (ZIP_FOUND) - set(ZIP_LIBRARIES ${ZIP_LIBRARY} ${ZLIB_LIBRARIES}) - set(ZIP_INCLUDE_DIRS ${ZIP_INCLUDE_DIR} ${ZIPCONF_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) + set(ZIP_LIBRARIES ${ZIP_LIBRARY} ${ZLIB_LIBRARIES}) + set(ZIP_INCLUDE_DIRS ${ZIP_INCLUDE_DIR} ${ZIPCONF_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) endif () mark_as_advanced(ZIP_LIBRARY ZIP_INCLUDE_DIR ZIPCONF_INCLUDE_DIR)
--- a/database/postgresql/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/database/postgresql/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -19,21 +19,21 @@ find_package(PostgreSQL REQUIRED) add_library( - mlk-driver-postgresql - MODULE - script/init.sql - src/account.cpp - src/driver.cpp - src/driver.h + mlk-driver-postgresql + MODULE + script/init.sql + src/account.cpp + src/driver.cpp + src/driver.h ) target_link_libraries(mlk-driver-postgresql libmlk-server ${PostgreSQL_LIBRARIES}) target_include_directories(mlk-driver-postgresql PRIVATE ${PostgreSQL_INCLUDE_DIRS}) target_compile_options(mlk-driver-postgresql PRIVATE -Wno-return-type-c-linkage) set_target_properties( - mlk-driver-postgresql - PROPERTIES - PREFIX "" - OUTPUT_NAME pgsql - LIBRARY_OUTPUT_DIRECTORY ${malikania_BINARY_DIR}/fakeroot/${WITH_DRIVERDIR} + mlk-driver-postgresql + PROPERTIES + PREFIX "" + OUTPUT_NAME pgsql + LIBRARY_OUTPUT_DIRECTORY ${malikania_BINARY_DIR}/fakeroot/${WITH_DRIVERDIR} )
--- a/database/postgresql/script/init.sql Thu May 26 07:32:05 2016 +0200 +++ b/database/postgresql/script/init.sql Thu Jun 16 13:35:31 2016 +0200 @@ -17,123 +17,123 @@ -- create table if not exists mk_info( - if_id varchar(32), - if_value varchar(256), - CONSTRAINT pk_if_id PRIMARY KEY(if_id) + if_id varchar(32), + if_value varchar(256), + CONSTRAINT pk_if_id PRIMARY KEY(if_id) ); create table if not exists mk_account( - ac_id serial, - ac_name varchar(32), - ac_email varchar(128), - ac_firstname varchar(32), - ac_lastname varchar(32), - ac_salt varchar(8), - ac_password varchar(256), - ac_joindate date, - CONSTRAINT pk_ac_id PRIMARY KEY(ac_id) + ac_id serial, + ac_name varchar(32), + ac_email varchar(128), + ac_firstname varchar(32), + ac_lastname varchar(32), + ac_salt varchar(8), + ac_password varchar(256), + ac_joindate date, + CONSTRAINT pk_ac_id PRIMARY KEY(ac_id) ); create table if not exists mk_log_history( - log_id serial, - log_ac_id serial, - CONSTRAINT pk_log_id PRIMARY KEY(log_id), - CONSTRAINT fk_log_ac_id FOREIGN KEY(log_ac_id) REFERENCES mk_account(ac_id) + log_id serial, + log_ac_id serial, + CONSTRAINT pk_log_id PRIMARY KEY(log_id), + CONSTRAINT fk_log_ac_id FOREIGN KEY(log_ac_id) REFERENCES mk_account(ac_id) ); create table if not exists mk_character( - ch_id serial, - ch_ac_id serial, - ch_class varchar(32), - ch_createdate date, - CONSTRAINT pk_ch_id PRIMARY KEY(ch_id), - CONSTRAINT fk_ch_ac_id FOREIGN KEY(ch_ac_id) REFERENCES mk_account(ac_id) + ch_id serial, + ch_ac_id serial, + ch_class varchar(32), + ch_createdate date, + CONSTRAINT pk_ch_id PRIMARY KEY(ch_id), + CONSTRAINT fk_ch_ac_id FOREIGN KEY(ch_ac_id) REFERENCES mk_account(ac_id) ); create table if not exists mk_log_history_item( - lhi_id serial, - lhi_log_id serial, - lhi_date time, - CONSTRAINT pk_lhi_id PRIMARY KEY(lhi_id), - CONSTRAINT fk_lhi_log_id FOREIGN KEY(lhi_log_id) REFERENCES mk_log_history(log_id) + lhi_id serial, + lhi_log_id serial, + lhi_date time, + CONSTRAINT pk_lhi_id PRIMARY KEY(lhi_id), + CONSTRAINT fk_lhi_log_id FOREIGN KEY(lhi_log_id) REFERENCES mk_log_history(log_id) ); create table if not exists mk_status( - st_id serial, - st_ch_id serial, - st_hp int, - st_mp int, - CONSTRAINT pk_st_id PRIMARY KEY(st_id), - CONSTRAINT fk_st_ch_id FOREIGN KEY(st_ch_id) REFERENCES mk_character(ch_id) + st_id serial, + st_ch_id serial, + st_hp int, + st_mp int, + CONSTRAINT pk_st_id PRIMARY KEY(st_id), + CONSTRAINT fk_st_ch_id FOREIGN KEY(st_ch_id) REFERENCES mk_character(ch_id) ); create table if not exists mk_points( - pt_id serial, - pt_st_id serial, - pt_avail smallint, - pt_force smallint, - pt_defense smallint, - pt_agility smallint, - CONSTRAINT pk_pt_id PRIMARY KEY(pt_id), - CONSTRAINT fk_st_id FOREIGN KEY(pt_st_id) REFERENCES mk_status(st_id) + pt_id serial, + pt_st_id serial, + pt_avail smallint, + pt_force smallint, + pt_defense smallint, + pt_agility smallint, + CONSTRAINT pk_pt_id PRIMARY KEY(pt_id), + CONSTRAINT fk_st_id FOREIGN KEY(pt_st_id) REFERENCES mk_status(st_id) ); create table if not exists mk_build( - bd_id serial, - bd_ac_id serial, - bd_position int, - bd_title varchar(32), - bd_password varchar(25), - bd_kind varchar(32), - CONSTRAINT pk_bd_id PRIMARY KEY(bd_id), - CONSTRAINT fk_bd_ac_id FOREIGN KEY(bd_ac_id) REFERENCES mk_account(ac_id) + bd_id serial, + bd_ac_id serial, + bd_position int, + bd_title varchar(32), + bd_password varchar(25), + bd_kind varchar(32), + CONSTRAINT pk_bd_id PRIMARY KEY(bd_id), + CONSTRAINT fk_bd_ac_id FOREIGN KEY(bd_ac_id) REFERENCES mk_account(ac_id) ); create table if not exists mk_chest( - cht_id serial, - cht_bd_id serial, - cht_name varchar(32), - CONSTRAINT pk_cht_id PRIMARY KEY(cht_id), - CONSTRAINT fk_cht_bd_id FOREIGN KEY(cht_bd_id) REFERENCES mk_build(bd_id) + cht_id serial, + cht_bd_id serial, + cht_name varchar(32), + CONSTRAINT pk_cht_id PRIMARY KEY(cht_id), + CONSTRAINT fk_cht_bd_id FOREIGN KEY(cht_bd_id) REFERENCES mk_build(bd_id) ); create table if not exists mk_inventory( - inv_id serial, - inv_ch_id serial, - CONSTRAINT pk_inv_id PRIMARY KEY(inv_id), - CONSTRAINT fk_inv_ch_id FOREIGN KEY(inv_ch_id) REFERENCES mk_character(ch_id) + inv_id serial, + inv_ch_id serial, + CONSTRAINT pk_inv_id PRIMARY KEY(inv_id), + CONSTRAINT fk_inv_ch_id FOREIGN KEY(inv_ch_id) REFERENCES mk_character(ch_id) ); create table if not exists mk_artefact( - atf_id serial, - atf_ch_id serial, - atf_name varchar(32), - CONSTRAINT pk_atf_id PRIMARY KEY(atf_id), - CONSTRAINT fk_atf_ch_id FOREIGN KEY(atf_ch_id) REFERENCES mk_character(ch_id) + atf_id serial, + atf_ch_id serial, + atf_name varchar(32), + CONSTRAINT pk_atf_id PRIMARY KEY(atf_id), + CONSTRAINT fk_atf_ch_id FOREIGN KEY(atf_ch_id) REFERENCES mk_character(ch_id) ); create table if not exists mk_quest( - qs_id serial, - qs_ch_id serial, - qs_name varchar(32), - CONSTRAINT pk_qs_id PRIMARY KEY(qs_id), - CONSTRAINT fk_qs_ch_id FOREIGN KEY(qs_ch_id) REFERENCES mk_character(ch_id) + qs_id serial, + qs_ch_id serial, + qs_name varchar(32), + CONSTRAINT pk_qs_id PRIMARY KEY(qs_id), + CONSTRAINT fk_qs_ch_id FOREIGN KEY(qs_ch_id) REFERENCES mk_character(ch_id) ); create table if not exists mk_inventory_object( - invo_id serial, - invo_inv_id serial, - invo_name varchar(32), - invo_count smallint, - CONSTRAINT pk_invo_id PRIMARY KEY(invo_id), - CONSTRAINT fk_invo_inv_id FOREIGN KEY(invo_inv_id) REFERENCES mk_inventory(inv_id) + invo_id serial, + invo_inv_id serial, + invo_name varchar(32), + invo_count smallint, + CONSTRAINT pk_invo_id PRIMARY KEY(invo_id), + CONSTRAINT fk_invo_inv_id FOREIGN KEY(invo_inv_id) REFERENCES mk_inventory(inv_id) ); create table if not exists mk_quest_property( - qp_id serial, - qp_qs_id serial, - qp_name varchar(32), - qp_value text, - CONSTRAINT pk_qp_id PRIMARY KEY(qp_id), - CONSTRAINT fk_qp_qs_id FOREIGN KEY(qp_qs_id) REFERENCES mk_quest(qs_id) + qp_id serial, + qp_qs_id serial, + qp_name varchar(32), + qp_value text, + CONSTRAINT pk_qp_id PRIMARY KEY(qp_id), + CONSTRAINT fk_qp_qs_id FOREIGN KEY(qp_qs_id) REFERENCES mk_quest(qs_id) );
--- a/database/postgresql/src/account.cpp Thu May 26 07:32:05 2016 +0200 +++ b/database/postgresql/src/account.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -34,97 +34,97 @@ Account toAccount(PGresult *result, int i) { - assert(i < PQntuples(result)); + assert(i < PQntuples(result)); - Account account; + Account account; - account.setId(static_cast<std::uint64_t>(std::stoll(PQgetvalue(result, i, 0)))); - account.setName(PQgetvalue(result, i, 1)); - account.setEmail(PQgetvalue(result, i, 2)); - account.setFirstName(PQgetvalue(result, i, 3)); - account.setLastName(PQgetvalue(result, i, 4)); - account.setPassword(PQgetvalue(result, i, 6)); + account.setId(static_cast<std::uint64_t>(std::stoll(PQgetvalue(result, i, 0)))); + account.setName(PQgetvalue(result, i, 1)); + account.setEmail(PQgetvalue(result, i, 2)); + account.setFirstName(PQgetvalue(result, i, 3)); + account.setLastName(PQgetvalue(result, i, 4)); + account.setPassword(PQgetvalue(result, i, 6)); - return account; + return account; } } // !namespace DYNLIB_EXPORT void malikania_account_create(Account &account) { - std::ostringstream oss; + std::ostringstream oss; - oss << "insert into mk_account(ac_name, ac_email, ac_firstname, ac_lastname, ac_password) values ("; - oss << pgsql::escape(account.name()) << ", "; - oss << pgsql::escape(account.email()) << ", "; - oss << pgsql::escape(account.firstName()) << ", "; - oss << pgsql::escape(account.lastName()) << ", "; - oss << pgsql::escape(account.password()) << ") returning ac_id"; + oss << "insert into mk_account(ac_name, ac_email, ac_firstname, ac_lastname, ac_password) values ("; + oss << pgsql::escape(account.name()) << ", "; + oss << pgsql::escape(account.email()) << ", "; + oss << pgsql::escape(account.firstName()) << ", "; + oss << pgsql::escape(account.lastName()) << ", "; + oss << pgsql::escape(account.password()) << ") returning ac_id"; - std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); + std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); - account.setId(static_cast<std::uint64_t>(std::stoll(PQgetvalue(result.get(), 0, 0)))); + account.setId(static_cast<std::uint64_t>(std::stoll(PQgetvalue(result.get(), 0, 0)))); } DYNLIB_EXPORT void malikania_account_update(Account &account) { - std::ostringstream oss; + std::ostringstream oss; - oss << "update mk_account set "; - oss << "ac_name = " << pgsql::escape(account.name()) << ", "; - oss << "ac_email = " << pgsql::escape(account.email()) << ", "; - oss << "ac_firstname = " << pgsql::escape(account.firstName()) << ", "; - oss << "ac_lastname = " << pgsql::escape(account.lastName()) << ", "; - oss << "ac_password = " << pgsql::escape(account.password()) << " "; - oss << "where ac_id = " << account.id(); + oss << "update mk_account set "; + oss << "ac_name = " << pgsql::escape(account.name()) << ", "; + oss << "ac_email = " << pgsql::escape(account.email()) << ", "; + oss << "ac_firstname = " << pgsql::escape(account.firstName()) << ", "; + oss << "ac_lastname = " << pgsql::escape(account.lastName()) << ", "; + oss << "ac_password = " << pgsql::escape(account.password()) << " "; + oss << "where ac_id = " << account.id(); - pgsql::exec(oss.str()); + pgsql::exec(oss.str()); } DYNLIB_EXPORT void malikania_account_remove(const Account &account) { - std::ostringstream oss; + std::ostringstream oss; - oss << "delete from mk_account where ac_id = " << account.id(); + oss << "delete from mk_account where ac_id = " << account.id(); - pgsql::exec(oss.str()); + pgsql::exec(oss.str()); } DYNLIB_EXPORT Account malikania_account_get(std::uint64_t id) { - std::ostringstream oss; + std::ostringstream oss; - oss << "select * from mk_account where ac_id = " << id; + oss << "select * from mk_account where ac_id = " << id; - std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); + std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); - if (PQntuples(result.get()) != 1) - throw std::out_of_range("account not found"); + if (PQntuples(result.get()) != 1) + throw std::out_of_range("account not found"); - return toAccount(result.get(), 0); + return toAccount(result.get(), 0); } DYNLIB_EXPORT std::vector<malikania::Account> malikania_account_list() { - std::vector<Account> accounts; - std::shared_ptr<PGresult> result = pgsql::exec("select * from mk_account"); + std::vector<Account> accounts; + std::shared_ptr<PGresult> result = pgsql::exec("select * from mk_account"); - for (int i = 0; i < PQntuples(result.get()); ++i) - accounts.push_back(toAccount(result.get(), i)); + for (int i = 0; i < PQntuples(result.get()); ++i) + accounts.push_back(toAccount(result.get(), i)); - return accounts; + return accounts; } DYNLIB_EXPORT std::uint64_t malikania_account_count() { - std::shared_ptr<PGresult> result = pgsql::exec("select count(*) from mk_account"); + std::shared_ptr<PGresult> result = pgsql::exec("select count(*) from mk_account"); - return static_cast<std::uint64_t>(std::stoll(PQgetvalue(result.get(), 0, 0))); + return static_cast<std::uint64_t>(std::stoll(PQgetvalue(result.get(), 0, 0))); } DYNLIB_EXPORT void malikania_account_clear() { - pgsql::exec("delete from mk_account"); + pgsql::exec("delete from mk_account"); } }
--- a/database/postgresql/src/driver.cpp Thu May 26 07:32:05 2016 +0200 +++ b/database/postgresql/src/driver.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -30,26 +30,26 @@ std::shared_ptr<PGresult> exec(const std::string &sql) { - std::shared_ptr<PGresult> ptr(PQexec(connection, sql.c_str()), PQclear); + std::shared_ptr<PGresult> ptr(PQexec(connection, sql.c_str()), PQclear); - if (PQresultStatus(ptr.get()) != PGRES_TUPLES_OK && PQresultStatus(ptr.get()) != PGRES_COMMAND_OK) - throw std::runtime_error(PQresultErrorMessage(ptr.get())); + if (PQresultStatus(ptr.get()) != PGRES_TUPLES_OK && PQresultStatus(ptr.get()) != PGRES_COMMAND_OK) + throw std::runtime_error(PQresultErrorMessage(ptr.get())); - return ptr; + return ptr; } std::string escape(const std::string &input) { - auto text = PQescapeLiteral(connection, input.c_str(), input.length()); + auto text = PQescapeLiteral(connection, input.c_str(), input.length()); - if (!text) - throw std::runtime_error(PQerrorMessage(connection)); + if (!text) + throw std::runtime_error(PQerrorMessage(connection)); - std::string result(text); + std::string result(text); - PQfreemem(text); + PQfreemem(text); - return result; + return result; } } // !pgsql @@ -58,36 +58,36 @@ std::string parameters(const std::unordered_map<std::string, std::string> ¶ms) { - std::ostringstream oss; - std::unordered_map<std::string, std::string>::const_iterator it; + std::ostringstream oss; + std::unordered_map<std::string, std::string>::const_iterator it; - // Host. - if ((it = params.find("host")) == params.end()) - throw std::runtime_error("missing 'host' parameter"); + // Host. + if ((it = params.find("host")) == params.end()) + throw std::runtime_error("missing 'host' parameter"); - oss << "host = " << it->second << " "; + oss << "host = " << it->second << " "; - // Database. - if ((it = params.find("database")) == params.end()) - throw std::runtime_error("missing 'database' parameter"); + // Database. + if ((it = params.find("database")) == params.end()) + throw std::runtime_error("missing 'database' parameter"); - oss << "dbname = " << it->second << " "; + oss << "dbname = " << it->second << " "; - // User. - if ((it = params.find("user")) == params.end()) - throw std::runtime_error("missing 'user' parameter"); + // User. + if ((it = params.find("user")) == params.end()) + throw std::runtime_error("missing 'user' parameter"); - oss << "user = " << it->second << " "; + oss << "user = " << it->second << " "; - // Port (optional). - if ((it = params.find("port")) != params.end()) - oss << "port = " << it->second << " "; + // Port (optional). + if ((it = params.find("port")) != params.end()) + oss << "port = " << it->second << " "; - // Password (optional). - if ((it = params.find("password")) != params.end()) - oss << "password = " << it->second << " "; + // Password (optional). + if ((it = params.find("password")) != params.end()) + oss << "password = " << it->second << " "; - return oss.str(); + return oss.str(); } } // !namespace @@ -96,18 +96,18 @@ DYNLIB_EXPORT void malikania_driver_load(const std::unordered_map<std::string, std::string> ¶ms) { - pgsql::connection = PQconnectdb(parameters(params).c_str()); + pgsql::connection = PQconnectdb(parameters(params).c_str()); - if (!pgsql::connection) - throw std::runtime_error(PQerrorMessage(pgsql::connection)); + if (!pgsql::connection) + throw std::runtime_error(PQerrorMessage(pgsql::connection)); } DYNLIB_EXPORT void malikania_driver_unload() { - if (pgsql::connection) { - PQfinish(pgsql::connection); - pgsql::connection = nullptr; - } + if (pgsql::connection) { + PQfinish(pgsql::connection); + pgsql::connection = nullptr; + } } } // !C
--- a/docs/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/docs/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -19,9 +19,9 @@ project(docs) add_custom_target( - docs - ALL - COMMENT "Generating documentation" + docs + ALL + COMMENT "Generating documentation" ) # @@ -32,16 +32,16 @@ find_package(Doxygen) if (DOXYGEN_FOUND) - if (WITH_DOXYGEN) - setg(WITH_DOXYGEN_MSG "Yes") - else () - setg(WITH_DOXYGEN_MSG "No (disabled by user)") - endif () + if (WITH_DOXYGEN) + setg(WITH_DOXYGEN_MSG "Yes") + else () + setg(WITH_DOXYGEN_MSG "No (disabled by user)") + endif () else () - setg(WITH_DOXYGEN_MSG "No (doxygen not found)") - setg(WITH_DOXYGEN Off) + setg(WITH_DOXYGEN_MSG "No (doxygen not found)") + setg(WITH_DOXYGEN Off) endif () if (WITH_DOXYGEN) - add_subdirectory(doxygen) + add_subdirectory(doxygen) endif ()
--- a/docs/doxygen/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/docs/doxygen/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -22,22 +22,22 @@ set(DOXYGEN_OUTPUT ${docs_BINARY_DIR}/doxygen) if (DOXYGEN_DOT_FOUND) - set(DOXYGEN_HAVE_DOT YES) - set(DOXYGEN_DOT_PATH \"${DOXYGEN_DOT_EXECUTABLE}\") + set(DOXYGEN_HAVE_DOT YES) + set(DOXYGEN_DOT_PATH \"${DOXYGEN_DOT_EXECUTABLE}\") else () - set(DOXYGEN_HAVE_DOT NO) - set(DOXYGEN_DOT_PATH) + set(DOXYGEN_HAVE_DOT NO) + set(DOXYGEN_DOT_PATH) endif () configure_file( - ${doxygen_SOURCE_DIR}/Doxyfile.in - ${docs_BINARY_DIR}/doxygen/Doxyfile + ${doxygen_SOURCE_DIR}/Doxyfile.in + ${docs_BINARY_DIR}/doxygen/Doxyfile ) add_custom_target( - docs-doxygen - COMMAND ${DOXYGEN_EXECUTABLE} ${docs_BINARY_DIR}/doxygen/Doxyfile - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + docs-doxygen + COMMAND ${DOXYGEN_EXECUTABLE} ${docs_BINARY_DIR}/doxygen/Doxyfile + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) add_dependencies(docs docs-doxygen)
--- a/docs/doxygen/Doxyfile.in Thu May 26 07:32:05 2016 +0200 +++ b/docs/doxygen/Doxyfile.in Thu Jun 16 13:35:31 2016 +0200 @@ -5,10 +5,10 @@ # # The following variables will be set by CMake: # -# DOXYGEN_SOURCE Path to the source files -# DOXYGEN_OUTPUT Path to the output directory -# DOXYGEN_HAVE_DOT Set to YES or NO depending if dot was found -# DOXYGEN_DOT_PATH Path to the the dot tool +# DOXYGEN_SOURCE Path to the source files +# DOXYGEN_OUTPUT Path to the output directory +# DOXYGEN_HAVE_DOT Set to YES or NO depending if dot was found +# DOXYGEN_DOT_PATH Path to the the dot tool # # This file describes the settings to be used by the documentation system @@ -771,9 +771,9 @@ # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = @DOXYGEN_SOURCE@/libcommon \ - @DOXYGEN_SOURCE@/libclient \ - @DOXYGEN_SOURCE@/libserver +INPUT = @DOXYGEN_SOURCE@/libcommon \ + @DOXYGEN_SOURCE@/libclient \ + @DOXYGEN_SOURCE@/libserver # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
--- a/examples/01-bouncing/client.js Thu May 26 07:32:05 2016 +0200 +++ b/examples/01-bouncing/client.js Thu Jun 16 13:35:31 2016 +0200 @@ -9,33 +9,33 @@ function start(window) { - font = new Malikania.Font("fonts/DejaVuSans.ttf", 10); - clip = font.clip("Malikania"); + font = new Malikania.Font("fonts/DejaVuSans.ttf", 10); + clip = font.clip("Malikania"); - x = (640 / 2) - (clip.width / 2); - y = (480 / 2) - (clip.height / 2); + x = (640 / 2) - (clip.width / 2); + y = (480 / 2) - (clip.height / 2); } function update() { - x += dx; - y += dy; + x += dx; + y += dy; - if (x >= 640 - clip.width) - dx = -1; - else if (x <= 0) - dx = 1; - if (y >= 480 - clip.height) - dy = -1; - else if (y <= 0) - dy = 1; + if (x >= 640 - clip.width) + dx = -1; + else if (x <= 0) + dx = 1; + if (y >= 480 - clip.height) + dy = -1; + else if (y <= 0) + dy = 1; } function draw(window) { - window.setDrawingColor('lightskyblue'); - window.clear(); - window.setDrawingColor('white'); - window.drawText('Malikania', font, { x: x, y: y }); - window.present(); + window.setDrawingColor('lightskyblue'); + window.clear(); + window.setDrawingColor('white'); + window.drawText('Malikania', font, { x: x, y: y }); + window.present(); }
--- a/libclient/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/libclient/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,70 +17,70 @@ # set( - HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animation.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animator.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-resources-loader.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-loading.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-map.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/color.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/font.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/image.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animation.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animator.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client-target.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-color.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-font.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-image.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-line.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-point.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-rectangle.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-sprite.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-window.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/label.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/line.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/point.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/rectangle.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/size.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/sprite.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/font-backend.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/image-backend.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/window-backend.h + HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animation.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animator.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-resources-loader.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-loading.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-map.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/color.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/font.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/image.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animation.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animator.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client-target.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-color.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-font.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-image.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-line.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-point.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-rectangle.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-sprite.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-window.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/label.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/line.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/point.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/rectangle.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/size.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/sprite.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/window.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/font-backend.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/image-backend.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/window-backend.h ) set( - SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-resources-loader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-loading.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-map.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/color.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/font.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/image.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animation.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client-target.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-color.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-font.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-image.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-line.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-point.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-rectangle.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-sprite.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-size.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-window.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/label.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/sprite.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/window.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/font-backend.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/image-backend.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/window-backend.cpp + SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-resources-loader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-loading.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-map.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/color.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/font.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/image.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client-target.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-color.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-font.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-image.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-line.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-point.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-rectangle.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-sprite.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-size.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-window.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/label.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/sprite.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/window.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/font-backend.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/image-backend.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/window-backend.cpp ) find_package(SDL2 REQUIRED) @@ -88,18 +88,18 @@ find_package(SDL2_ttf REQUIRED) malikania_create_library( - PROJECT libclient - TARGET libclient - SOURCES ${HEADERS} ${SOURCES} - PUBLIC_INCLUDES - ${SDL2_INCLUDE_DIRS} - ${SDL2_IMAGE_INCLUDE_DIRS} - ${SDL2_TTF_INCLUDE_DIRS} - LIBRARIES - libcommon - ${SDL2_LIBRARIES} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_TTF_LIBRARIES} + PROJECT libclient + TARGET libclient + SOURCES ${HEADERS} ${SOURCES} + PUBLIC_INCLUDES + ${SDL2_INCLUDE_DIRS} + ${SDL2_IMAGE_INCLUDE_DIRS} + ${SDL2_TTF_INCLUDE_DIRS} + LIBRARIES + libcommon + ${SDL2_LIBRARIES} + ${SDL2_IMAGE_LIBRARIES} + ${SDL2_TTF_LIBRARIES} ) target_compile_definitions(libclient PUBLIC ${DEFINITIONS})
--- a/libclient/malikania/animation.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/animation.h Thu Jun 16 13:35:31 2016 +0200 @@ -45,28 +45,28 @@ */ class AnimationFrame { private: - std::uint16_t m_delay; + std::uint16_t m_delay; public: - /** - * Construct a frame. - * - * @param delay the optional delay - */ - inline AnimationFrame(std::uint16_t delay = 100) noexcept - : m_delay(delay) - { - } + /** + * Construct a frame. + * + * @param delay the optional delay + */ + inline AnimationFrame(std::uint16_t delay = 100) noexcept + : m_delay(delay) + { + } - /** - * Get the the delay. - * - * @return the delay - */ - inline std::uint16_t delay() const noexcept - { - return m_delay; - } + /** + * Get the the delay. + * + * @return the delay + */ + inline std::uint16_t delay() const noexcept + { + return m_delay; + } }; /** @@ -89,65 +89,65 @@ */ class Animation : public duk::Bindable { private: - Sprite m_sprite; - AnimationFrames m_frames; + Sprite m_sprite; + AnimationFrames m_frames; public: - /** - * Create an animation. - * - * @param sprite the sprite image - * @param frames the frames to show - */ - inline Animation(Sprite sprite, AnimationFrames frames) noexcept - : m_sprite(std::move(sprite)) - , m_frames(std::move(frames)) - { - } + /** + * Create an animation. + * + * @param sprite the sprite image + * @param frames the frames to show + */ + inline Animation(Sprite sprite, AnimationFrames frames) noexcept + : m_sprite(std::move(sprite)) + , m_frames(std::move(frames)) + { + } - /** - * Get the underlying sprite. - * - * @return the sprite - */ - inline const Sprite &sprite() const noexcept - { - return m_sprite; - } + /** + * Get the underlying sprite. + * + * @return the sprite + */ + inline const Sprite &sprite() const noexcept + { + return m_sprite; + } - /** - * Overloaded function. - * - * @return the sprite - */ - inline Sprite &sprite() noexcept - { - return m_sprite; - } + /** + * Overloaded function. + * + * @return the sprite + */ + inline Sprite &sprite() noexcept + { + return m_sprite; + } - /** - * Get the frames. - * - * @return the frames - */ - inline const AnimationFrames &frames() const noexcept - { - return m_frames; - } + /** + * Get the frames. + * + * @return the frames + */ + inline const AnimationFrames &frames() const noexcept + { + return m_frames; + } - /** - * Access a frame. - * - * @pre index < number of frames - * @param index the index - * @return the frame - */ - inline const AnimationFrame &operator[](unsigned index) const noexcept - { - assert(index < m_frames.size()); + /** + * Access a frame. + * + * @pre index < number of frames + * @param index the index + * @return the frame + */ + inline const AnimationFrame &operator[](unsigned index) const noexcept + { + assert(index < m_frames.size()); - return m_frames[index]; - } + return m_frames[index]; + } }; } // !malikania
--- a/libclient/malikania/animator.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/animator.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -22,32 +22,32 @@ namespace malikania { Animator::Animator(Animation &animation) noexcept - : m_animation(animation) + : m_animation(animation) { } void Animator::update() noexcept { - unsigned total = m_animation.sprite().rows() * m_animation.sprite().columns(); + unsigned total = m_animation.sprite().rows() * m_animation.sprite().columns(); - if (m_current >= total) { - return; - } + if (m_current >= total) { + return; + } - if (m_timer.elapsed() >= m_animation[m_current].delay()) { - m_current ++; - m_timer.reset(); - } + if (m_timer.elapsed() >= m_animation[m_current].delay()) { + m_current ++; + m_timer.reset(); + } } void Animator::draw(Window &window, const Point &point) { - // TODO: assert ? - if (m_current >= m_animation.sprite().rows() * m_animation.sprite().columns()) { - return; - } + // TODO: assert ? + if (m_current >= m_animation.sprite().rows() * m_animation.sprite().columns()) { + return; + } - m_animation.sprite().draw(window, m_current, point); + m_animation.sprite().draw(window, m_current, point); } } // !malikania
--- a/libclient/malikania/animator.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/animator.h Thu Jun 16 13:35:31 2016 +0200 @@ -41,33 +41,33 @@ */ class Animator : public duk::Bindable { private: - Animation &m_animation; - ElapsedTimer m_timer; - unsigned m_current{0}; + Animation &m_animation; + ElapsedTimer m_timer; + unsigned m_current{0}; public: - /** - * Construct an animator. - * - * @pre animation must not be null - * @param animation the animation - */ - Animator(Animation &animation) noexcept; + /** + * Construct an animator. + * + * @pre animation must not be null + * @param animation the animation + */ + Animator(Animation &animation) noexcept; - /** - * Update the animator state. - * - * This function should be called in the main loop to update the cell to draw before calling draw(). - */ - void update() noexcept; + /** + * Update the animator state. + * + * This function should be called in the main loop to update the cell to draw before calling draw(). + */ + void update() noexcept; - /** - * Draw the animation. - * - * @param window the window - * @param position the position in the window - */ - void draw(Window &window, const Point &position); + /** + * Draw the animation. + * + * @param window the window + * @param position the position in the window + */ + void draw(Window &window, const Point &position); }; } // !malikania
--- a/libclient/malikania/backend/sdl/font-backend.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/font-backend.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -28,30 +28,30 @@ namespace malikania { Font::Backend::Backend(std::string data, unsigned size) - : m_font(nullptr, nullptr) + : m_font(nullptr, nullptr) { - auto rw = sdl::RWFromBinary(std::move(data)); + auto rw = sdl::RWFromBinary(std::move(data)); - if (rw == nullptr) { - throw std::runtime_error(SDL_GetError()); - } + if (rw == nullptr) { + throw std::runtime_error(SDL_GetError()); + } - m_font = Handle(TTF_OpenFontRW(rw, true, size), TTF_CloseFont); + m_font = Handle(TTF_OpenFontRW(rw, true, size), TTF_CloseFont); - if (m_font == NULL) { - throw std::runtime_error(TTF_GetError()); - } + if (m_font == NULL) { + throw std::runtime_error(TTF_GetError()); + } } Size Font::Backend::clip(const Font &, const std::string &text) const { - int width, height; + int width, height; - if (TTF_SizeUTF8(m_font.get(), text.c_str(), &width, &height) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (TTF_SizeUTF8(m_font.get(), text.c_str(), &width, &height) != 0) { + throw std::runtime_error(SDL_GetError()); + } - return Size((unsigned)width, (unsigned)height); + return Size((unsigned)width, (unsigned)height); } } // !malikania
--- a/libclient/malikania/backend/sdl/font-backend.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/font-backend.h Thu Jun 16 13:35:31 2016 +0200 @@ -33,19 +33,19 @@ class Font::Backend { private: - using Handle = std::unique_ptr<TTF_Font, void (*)(TTF_Font*)>; + using Handle = std::unique_ptr<TTF_Font, void (*)(TTF_Font*)>; - Handle m_font; + Handle m_font; public: - Backend(std::string data, unsigned size); + Backend(std::string data, unsigned size); - inline TTF_Font *font() noexcept - { - return m_font.get(); - } + inline TTF_Font *font() noexcept + { + return m_font.get(); + } - Size clip(const Font &self, const std::string &text) const; + Size clip(const Font &self, const std::string &text) const; }; } // !malikania
--- a/libclient/malikania/backend/sdl/image-backend.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/image-backend.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,82 +29,82 @@ void Image::Backend::createTexture(Window &window) { - m_texture = Texture(SDL_CreateTextureFromSurface(window.backend().renderer(), m_surface.get()), SDL_DestroyTexture); + m_texture = Texture(SDL_CreateTextureFromSurface(window.backend().renderer(), m_surface.get()), SDL_DestroyTexture); - if (m_texture == nullptr) { - throw std::runtime_error(SDL_GetError()); - } + if (m_texture == nullptr) { + throw std::runtime_error(SDL_GetError()); + } } Image::Backend::Backend(Image &, std::string data) - : m_surface(nullptr, nullptr) - , m_texture(nullptr, nullptr) + : m_surface(nullptr, nullptr) + , m_texture(nullptr, nullptr) { - /* Initialize the texture */ - auto rw = sdl::RWFromBinary(std::move(data)); + /* Initialize the texture */ + auto rw = sdl::RWFromBinary(std::move(data)); - if (rw == nullptr) { - throw std::runtime_error(SDL_GetError()); - } + if (rw == nullptr) { + throw std::runtime_error(SDL_GetError()); + } - m_surface = Surface(IMG_Load_RW(rw, true), SDL_FreeSurface); + m_surface = Surface(IMG_Load_RW(rw, true), SDL_FreeSurface); - if (!m_surface) { - throw std::runtime_error(SDL_GetError()); - } + if (!m_surface) { + throw std::runtime_error(SDL_GetError()); + } - m_size = Size((unsigned)m_surface->w, (unsigned)m_surface->h); + m_size = Size((unsigned)m_surface->w, (unsigned)m_surface->h); } void Image::Backend::draw(Window &window, const Point &point) { - if (!m_texture) { - createTexture(window); - } + if (!m_texture) { + createTexture(window); + } - SDL_Rect target; + SDL_Rect target; - target.x = (int)point.x(); - target.y = (int)point.y(); - target.w = (int)m_size.width(); - target.h = (int)m_size.height(); + target.x = (int)point.x(); + target.y = (int)point.y(); + target.w = (int)m_size.width(); + target.h = (int)m_size.height(); - if (SDL_RenderCopy(window.backend().renderer(), m_texture.get(), nullptr, &target) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderCopy(window.backend().renderer(), m_texture.get(), nullptr, &target) < 0) { + throw std::runtime_error(SDL_GetError()); + } } void Image::Backend::draw(Window &window, const Rectangle &source, const Rectangle &target) { - if (!m_texture) { - createTexture(window); - } + if (!m_texture) { + createTexture(window); + } - SDL_Rect sr, st; + SDL_Rect sr, st; - sr.x = source.x(); - sr.y = source.y(); - sr.w = (int)source.width(); - sr.h = (int)source.height(); + sr.x = source.x(); + sr.y = source.y(); + sr.w = (int)source.width(); + sr.h = (int)source.height(); - st.x = target.x(); - st.y = target.y(); - st.w = (int)target.width(); - st.h = (int)target.height(); + st.x = target.x(); + st.y = target.y(); + st.w = (int)target.width(); + st.h = (int)target.height(); - /* Readjust .w, .h if null */ - if (source.isNull()) { - sr.w = (int)m_size.width(); - sr.h = (int)m_size.height(); - } - if (target.isNull()) { - st.w = (int)m_size.width(); - st.h = (int)m_size.height(); - } + /* Readjust .w, .h if null */ + if (source.isNull()) { + sr.w = (int)m_size.width(); + sr.h = (int)m_size.height(); + } + if (target.isNull()) { + st.w = (int)m_size.width(); + st.h = (int)m_size.height(); + } - if (SDL_RenderCopy(window.backend().renderer(), m_texture.get(), &sr, &st) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderCopy(window.backend().renderer(), m_texture.get(), &sr, &st) < 0) { + throw std::runtime_error(SDL_GetError()); + } } } // !malikania
--- a/libclient/malikania/backend/sdl/image-backend.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/image-backend.h Thu Jun 16 13:35:31 2016 +0200 @@ -35,31 +35,31 @@ class Image::Backend { private: - using Surface = std::unique_ptr<SDL_Surface, void (*)(SDL_Surface *)>; - using Texture = std::unique_ptr<SDL_Texture, void (*)(SDL_Texture *)>; + using Surface = std::unique_ptr<SDL_Surface, void (*)(SDL_Surface *)>; + using Texture = std::unique_ptr<SDL_Texture, void (*)(SDL_Texture *)>; - Surface m_surface; - Texture m_texture; - Size m_size; + Surface m_surface; + Texture m_texture; + Size m_size; - void createTexture(Window &window); + void createTexture(Window &window); public: - Backend(Image &self, std::string data); + Backend(Image &self, std::string data); - inline SDL_Texture *texture() noexcept - { - return m_texture.get(); - } + inline SDL_Texture *texture() noexcept + { + return m_texture.get(); + } - inline const Size &size() const noexcept - { - return m_size; - } + inline const Size &size() const noexcept + { + return m_size; + } - void draw(Window &window, const Point &position); + void draw(Window &window, const Point &position); - void draw(Window &window, const Rectangle &source, const Rectangle &target); + void draw(Window &window, const Rectangle &source, const Rectangle &target); }; } // !malikania
--- a/libclient/malikania/backend/sdl/window-backend.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/window-backend.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -32,65 +32,65 @@ namespace malikania { Window::Backend::Backend(Window &, unsigned width, unsigned height, const std::string &title) - : m_window(nullptr, nullptr) - , m_renderer(nullptr, nullptr) + : m_window(nullptr, nullptr) + , m_renderer(nullptr, nullptr) { - SDL_SetMainReady(); - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); + SDL_SetMainReady(); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); - m_window = WindowHandle( - SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL), - SDL_DestroyWindow - ); + m_window = WindowHandle( + SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL), + SDL_DestroyWindow + ); - if (m_window == nullptr) { - throw std::runtime_error(SDL_GetError()); - } + if (m_window == nullptr) { + throw std::runtime_error(SDL_GetError()); + } - // Create renderer - m_renderer = RendererHandle( - SDL_CreateRenderer(m_window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), - SDL_DestroyRenderer - ); + // Create renderer + m_renderer = RendererHandle( + SDL_CreateRenderer(m_window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), + SDL_DestroyRenderer + ); - if (m_renderer == nullptr) { - throw std::runtime_error(SDL_GetError()); - } + if (m_renderer == nullptr) { + throw std::runtime_error(SDL_GetError()); + } - if (TTF_Init() == -1) { - throw std::runtime_error(TTF_GetError()); - } + if (TTF_Init() == -1) { + throw std::runtime_error(TTF_GetError()); + } } void Window::Backend::poll(Window &self) { - SDL_Event event; + SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_KEYUP: - self.onKeyUp(event.key.keysym.sym); - break; - case SDL_KEYDOWN: - self.onKeyDown(event.key.keysym.sym); - break; - case SDL_QUIT: - self.onQuit(); - break; - default: - break; - } - } + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_KEYUP: + self.onKeyUp(event.key.keysym.sym); + break; + case SDL_KEYDOWN: + self.onKeyDown(event.key.keysym.sym); + break; + case SDL_QUIT: + self.onQuit(); + break; + default: + break; + } + } } void Window::Backend::clear() { - SDL_RenderClear(m_renderer.get()); + SDL_RenderClear(m_renderer.get()); } void Window::Backend::present() { - SDL_RenderPresent(m_renderer.get()); + SDL_RenderPresent(m_renderer.get()); } #if 0 @@ -99,149 +99,149 @@ Size Window::Backend::resolution() { - SDL_DisplayMode current; - int width = 0; - int height = 0; - for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { - int error = SDL_GetCurrentDisplayMode(i, ¤t); - if (error == 0) { - // Get the last one - // TODO test with only one display mode, but we have to test with more than that - width = current.w; - height = current.h; - } else { - throw std::runtime_error("Could not get display mode for video display" + std::string(SDL_GetError())); - } - } + SDL_DisplayMode current; + int width = 0; + int height = 0; + for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { + int error = SDL_GetCurrentDisplayMode(i, ¤t); + if (error == 0) { + // Get the last one + // TODO test with only one display mode, but we have to test with more than that + width = current.w; + height = current.h; + } else { + throw std::runtime_error("Could not get display mode for video display" + std::string(SDL_GetError())); + } + } - return Size((unsigned)width, (unsigned)height); + return Size((unsigned)width, (unsigned)height); } #endif Color Window::Backend::drawingColor() const { - SDL_Color color; + SDL_Color color; - if (SDL_GetRenderDrawColor(m_renderer.get(), &color.r, &color.g, &color.b, &color.a) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_GetRenderDrawColor(m_renderer.get(), &color.r, &color.g, &color.b, &color.a) < 0) { + throw std::runtime_error(SDL_GetError()); + } - return Color(color.r, color.g, color.b, color.a); + return Color(color.r, color.g, color.b, color.a); } void Window::Backend::setDrawingColor(const Color &color) { - if (SDL_SetRenderDrawColor(m_renderer.get(), color.red(), color.green(), color.blue(), color.alpha()) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_SetRenderDrawColor(m_renderer.get(), color.red(), color.green(), color.blue(), color.alpha()) < 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawLine(const Line &line) { - if (SDL_RenderDrawLine(m_renderer.get(), line.x1(), line.y1(), line.x2(), line.y2()) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawLine(m_renderer.get(), line.x1(), line.y1(), line.x2(), line.y2()) != 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawLines(const std::vector<Point> &points) { - std::vector<SDL_Point> sdlPoints(points.size()); + std::vector<SDL_Point> sdlPoints(points.size()); - for (unsigned i = 0; i < points.size(); ++i) { - sdlPoints[i] = SDL_Point{points[i].x(), points[i].y()}; - } + for (unsigned i = 0; i < points.size(); ++i) { + sdlPoints[i] = SDL_Point{points[i].x(), points[i].y()}; + } - if (SDL_RenderDrawLines(m_renderer.get(), sdlPoints.data(), sdlPoints.size()) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawLines(m_renderer.get(), sdlPoints.data(), sdlPoints.size()) < 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawPoint(const Point &point) { - if (SDL_RenderDrawPoint(m_renderer.get(), point.x(), point.y()) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawPoint(m_renderer.get(), point.x(), point.y()) != 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawPoints(const std::vector<Point> &points) { - std::vector<SDL_Point> sdlPoints(points.size()); + std::vector<SDL_Point> sdlPoints(points.size()); - for (unsigned i = 0; i < points.size(); ++i) { - sdlPoints[i] = SDL_Point{points[i].x(), points[i].y()}; - } + for (unsigned i = 0; i < points.size(); ++i) { + sdlPoints[i] = SDL_Point{points[i].x(), points[i].y()}; + } - if (SDL_RenderDrawPoints(m_renderer.get(), sdlPoints.data(), sdlPoints.size()) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawPoints(m_renderer.get(), sdlPoints.data(), sdlPoints.size()) != 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawRectangle(const Rectangle &rectangle) { - SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; + SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; - if (SDL_RenderDrawRect(m_renderer.get(), &rect) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawRect(m_renderer.get(), &rect) < 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawRectangles(const std::vector<Rectangle> &rectangles) { - std::vector<SDL_Rect> sdlRects(rectangles.size()); + std::vector<SDL_Rect> sdlRects(rectangles.size()); - for (unsigned i = 0; i < rectangles.size(); ++i) { - sdlRects[i] = SDL_Rect{rectangles[i].x(), rectangles[i].y(), (int)rectangles[i].width(), (int)rectangles[i].height()}; - } + for (unsigned i = 0; i < rectangles.size(); ++i) { + sdlRects[i] = SDL_Rect{rectangles[i].x(), rectangles[i].y(), (int)rectangles[i].width(), (int)rectangles[i].height()}; + } - if (SDL_RenderDrawRects(m_renderer.get(), sdlRects.data(), sdlRects.size()) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderDrawRects(m_renderer.get(), sdlRects.data(), sdlRects.size()) != 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::fillRectangle(const Rectangle &rectangle) { - SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; + SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; - if (SDL_RenderFillRect(m_renderer.get(), &rect) < 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderFillRect(m_renderer.get(), &rect) < 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::fillRectangles(const std::vector<Rectangle> &rectangles) { - std::vector<SDL_Rect> sdlRects(rectangles.size()); + std::vector<SDL_Rect> sdlRects(rectangles.size()); - for (unsigned i = 0; i < rectangles.size(); ++i) { - sdlRects[i] = SDL_Rect{rectangles[i].x(), rectangles[i].y(), (int)rectangles[i].width(), (int)rectangles[i].height()}; - } + for (unsigned i = 0; i < rectangles.size(); ++i) { + sdlRects[i] = SDL_Rect{rectangles[i].x(), rectangles[i].y(), (int)rectangles[i].width(), (int)rectangles[i].height()}; + } - if (SDL_RenderFillRects(m_renderer.get(), sdlRects.data(), sdlRects.size()) != 0) { - throw std::runtime_error(SDL_GetError()); - } + if (SDL_RenderFillRects(m_renderer.get(), sdlRects.data(), sdlRects.size()) != 0) { + throw std::runtime_error(SDL_GetError()); + } } void Window::Backend::drawText(const std::string &text, Font &font, const Rectangle &rectangle) { - SDL_Color color = {0, 0, 0, 255}; - SDL_Surface *message = TTF_RenderUTF8_Blended(font.backend().font(), text.c_str(), color); - SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer.get(), message); - SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; - SDL_RenderCopy(m_renderer.get(), texture, nullptr, &rect); - SDL_FreeSurface(message); - SDL_DestroyTexture(texture); + SDL_Color color = {0, 0, 0, 255}; + SDL_Surface *message = TTF_RenderUTF8_Blended(font.backend().font(), text.c_str(), color); + SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer.get(), message); + SDL_Rect rect{rectangle.x(), rectangle.y(), (int)rectangle.width(), (int)rectangle.height()}; + SDL_RenderCopy(m_renderer.get(), texture, nullptr, &rect); + SDL_FreeSurface(message); + SDL_DestroyTexture(texture); } void Window::Backend::drawText(const std::string &text, Font &font, const Point &point) { - SDL_Color color = {0, 0, 0, 0}; - SDL_GetRenderDrawColor(m_renderer.get(), &color.r, &color.g, &color.b, &color.a); - SDL_Surface *message = TTF_RenderUTF8_Blended(font.backend().font(), text.c_str(), color); - SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer.get(), message); - SDL_Rect rect{point.x(), point.y(), message->w, message->h}; - SDL_RenderCopy(m_renderer.get(), texture, nullptr, &rect); - SDL_FreeSurface(message); - SDL_DestroyTexture(texture); + SDL_Color color = {0, 0, 0, 0}; + SDL_GetRenderDrawColor(m_renderer.get(), &color.r, &color.g, &color.b, &color.a); + SDL_Surface *message = TTF_RenderUTF8_Blended(font.backend().font(), text.c_str(), color); + SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer.get(), message); + SDL_Rect rect{point.x(), point.y(), message->w, message->h}; + SDL_RenderCopy(m_renderer.get(), texture, nullptr, &rect); + SDL_FreeSurface(message); + SDL_DestroyTexture(texture); } void Window::Backend::close()
--- a/libclient/malikania/backend/sdl/window-backend.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/window-backend.h Thu Jun 16 13:35:31 2016 +0200 @@ -30,51 +30,51 @@ class Window::Backend { private: - using WindowHandle = std::unique_ptr<SDL_Window, void (*)(SDL_Window *)>; - using RendererHandle = std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer *)>; + using WindowHandle = std::unique_ptr<SDL_Window, void (*)(SDL_Window *)>; + using RendererHandle = std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer *)>; - WindowHandle m_window; - RendererHandle m_renderer; + WindowHandle m_window; + RendererHandle m_renderer; public: - Backend(Window &self, unsigned width, unsigned height, const std::string &title); + Backend(Window &self, unsigned width, unsigned height, const std::string &title); - inline SDL_Renderer *renderer() noexcept - { - return m_renderer.get(); - } + inline SDL_Renderer *renderer() noexcept + { + return m_renderer.get(); + } - void poll(Window &self); + void poll(Window &self); - void close(); + void close(); - void clear(); + void clear(); - void present(); + void present(); - Color drawingColor() const; + Color drawingColor() const; - void setDrawingColor(const Color &color); + void setDrawingColor(const Color &color); - void drawLine(const Line &line); + void drawLine(const Line &line); - void drawLines(const std::vector<Point> &points); + void drawLines(const std::vector<Point> &points); - void drawPoint(const Point &point); + void drawPoint(const Point &point); - void drawPoints(const std::vector<Point> &points); + void drawPoints(const std::vector<Point> &points); - void drawRectangle(const Rectangle &rect); + void drawRectangle(const Rectangle &rect); - void drawRectangles(const std::vector<Rectangle> &rects); + void drawRectangles(const std::vector<Rectangle> &rects); - void fillRectangle(const Rectangle &rect); + void fillRectangle(const Rectangle &rect); - void fillRectangles(const std::vector<Rectangle> &rects); + void fillRectangles(const std::vector<Rectangle> &rects); - void drawText(const std::string &text, Font &font, const Rectangle &rectangle); + void drawText(const std::string &text, Font &font, const Rectangle &rectangle); - void drawText(const std::string &text, Font &font, const Point &point); + void drawText(const std::string &text, Font &font, const Point &point); }; } // !malikania
--- a/libclient/malikania/client-resources-loader.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client-resources-loader.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -27,98 +27,98 @@ Size ClientResourcesLoader::requireSize(const std::string &id, const json::Value &object, const std::string &property) const { - assert(object.isObject()); + assert(object.isObject()); - auto it = object.find(property); + auto it = object.find(property); - if (it == object.end() || !it->isArray()) { - throw std::runtime_error(id + ": missing '" + property + "' property (array expected)"); - } - if (it->size() != 2) { - throw std::runtime_error(id + ": property '" + property + "' must have two values"); - } - if (!(*it)[0].isInt() || !(*it)[1].isInt()) { - throw std::runtime_error(id + ": property '" + property + "' must have to integer values"); - } + if (it == object.end() || !it->isArray()) { + throw std::runtime_error(id + ": missing '" + property + "' property (array expected)"); + } + if (it->size() != 2) { + throw std::runtime_error(id + ": property '" + property + "' must have two values"); + } + if (!(*it)[0].isInt() || !(*it)[1].isInt()) { + throw std::runtime_error(id + ": property '" + property + "' must have to integer values"); + } - return Size((*it)[0].toInt(), (*it)[1].toInt()); + return Size((*it)[0].toInt(), (*it)[1].toInt()); } Size ClientResourcesLoader::getSize(const std::string &, const json::Value &object, const std::string &key) const noexcept { - assert(object.isObject()); + assert(object.isObject()); - auto it = object.find(key); + auto it = object.find(key); - if (it == object.end() || !it->isArray() || it->size() != 2 || !(*it)[0].isInt() || !(*it)[1].isInt()) { - return Size(); - } + if (it == object.end() || !it->isArray() || it->size() != 2 || !(*it)[0].isInt() || !(*it)[1].isInt()) { + return Size(); + } - return Size((*it)[0].toInt(), (*it)[1].toInt()); + return Size((*it)[0].toInt(), (*it)[1].toInt()); } Font ClientResourcesLoader::loadFont(const std::string &id, unsigned size) { - return Font(locator().read(id), size); + return Font(locator().read(id), size); } Image ClientResourcesLoader::loadImage(const std::string &id) { - return Image(locator().read(id)); + return Image(locator().read(id)); } Sprite ClientResourcesLoader::loadSprite(const std::string &id) { - json::Value value = json::fromString(locator().read(id)); + json::Value value = json::fromString(locator().read(id)); - if (!value.isObject()) { - throw std::runtime_error(id + ": not a JSON object"); - } + if (!value.isObject()) { + throw std::runtime_error(id + ": not a JSON object"); + } - return Sprite( - loadImage(requireString(id, value, "image")), - requireSize(id, value, "cell"), - getSize(id, value, "size"), - getSize(id, value, "space"), - getSize(id, value, "margin") - ); + return Sprite( + loadImage(requireString(id, value, "image")), + requireSize(id, value, "cell"), + getSize(id, value, "size"), + getSize(id, value, "space"), + getSize(id, value, "margin") + ); } Animation ClientResourcesLoader::loadAnimation(const std::string &id) { - json::Value value = json::fromString(locator().read(id)); + json::Value value = json::fromString(locator().read(id)); - if (!value.isObject()) { - throw std::runtime_error(id + ": not a JSON object"); - } + if (!value.isObject()) { + throw std::runtime_error(id + ": not a JSON object"); + } - Sprite sprite = loadSprite(requireString(id, value, "sprite")); + Sprite sprite = loadSprite(requireString(id, value, "sprite")); - /* Load all frames */ - json::Value property = value["frames"]; + /* Load all frames */ + json::Value property = value["frames"]; - if (!property.isArray()) { - throw std::runtime_error(id + ": missing 'frames' property (array expected)"); - } + if (!property.isArray()) { + throw std::runtime_error(id + ": missing 'frames' property (array expected)"); + } - AnimationFrames frames; + AnimationFrames frames; - for (auto it = property.begin(); it != property.end(); ++it) { - if (!it->isObject()) { - throw std::runtime_error(id + ": frame " + std::to_string(it.index()) + ": not a JSON object"); - } + for (auto it = property.begin(); it != property.end(); ++it) { + if (!it->isObject()) { + throw std::runtime_error(id + ": frame " + std::to_string(it.index()) + ": not a JSON object"); + } - auto delay = it->find("delay"); + auto delay = it->find("delay"); - if (delay == it->end() || !delay->isInt()) { - throw std::runtime_error(id + ": frame " + std::to_string(it.index()) + - ": missing 'delay' property (int expected)"); - } + if (delay == it->end() || !delay->isInt()) { + throw std::runtime_error(id + ": frame " + std::to_string(it.index()) + + ": missing 'delay' property (int expected)"); + } - frames.emplace_back(delay->toInt()); - } + frames.emplace_back(delay->toInt()); + } - return Animation(std::move(sprite), std::move(frames)); + return Animation(std::move(sprite), std::move(frames)); } } // !malikania
--- a/libclient/malikania/client-resources-loader.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client-resources-loader.h Thu Jun 16 13:35:31 2016 +0200 @@ -35,81 +35,81 @@ */ class ClientResourcesLoader : public ResourcesLoader { protected: - /** - * Require a size object from an object property. - * - * The size is an array of two integers (e.g. [ 1, 2 ]). - * - * @pre object.isObject() - * @param id the resource id - * @param object the object - * @param property the property - * @return the size - * @throw std::runtime_error if the property is not a size - */ - Size requireSize(const std::string &id, const json::Value &object, const std::string &property) const; + /** + * Require a size object from an object property. + * + * The size is an array of two integers (e.g. [ 1, 2 ]). + * + * @pre object.isObject() + * @param id the resource id + * @param object the object + * @param property the property + * @return the size + * @throw std::runtime_error if the property is not a size + */ + Size requireSize(const std::string &id, const json::Value &object, const std::string &property) const; - /** - * Get a size object or a default one if not present or invalid. - * - * @pre object.isObject() - * @param id the resource id - * @param object the object - * @param property the property - * @return the size or default one - */ - Size getSize(const std::string &id, const json::Value &object, const std::string &property) const noexcept; + /** + * Get a size object or a default one if not present or invalid. + * + * @pre object.isObject() + * @param id the resource id + * @param object the object + * @param property the property + * @return the size or default one + */ + Size getSize(const std::string &id, const json::Value &object, const std::string &property) const noexcept; public: - /** - * Client resources loader constructor. - * - * The window is required because some of the resources require it. - * - * @param window the window - * @param locator the resources locator - */ - inline ClientResourcesLoader(ResourcesLocator &locator) - : ResourcesLoader(locator) - { - } + /** + * Client resources loader constructor. + * + * The window is required because some of the resources require it. + * + * @param window the window + * @param locator the resources locator + */ + inline ClientResourcesLoader(ResourcesLocator &locator) + : ResourcesLoader(locator) + { + } - /** - * Load a font. - * - * @param id the resource id - * @param size the desired size - * @return the font - * @throw std::runtime_error on errors - */ - virtual Font loadFont(const std::string &id, unsigned size); + /** + * Load a font. + * + * @param id the resource id + * @param size the desired size + * @return the font + * @throw std::runtime_error on errors + */ + virtual Font loadFont(const std::string &id, unsigned size); - /** - * Load an image. - * - * @param id the resource id - * @return the image - * @throw std::runtime_error on errors - */ - virtual Image loadImage(const std::string &id); + /** + * Load an image. + * + * @param id the resource id + * @return the image + * @throw std::runtime_error on errors + */ + virtual Image loadImage(const std::string &id); - /** - * Load a sprite. - * - * @param id the resource id - * @return the sprite - * @throw std::runtime_error on errors - */ - virtual Sprite loadSprite(const std::string &id); + /** + * Load a sprite. + * + * @param id the resource id + * @return the sprite + * @throw std::runtime_error on errors + */ + virtual Sprite loadSprite(const std::string &id); - /** - * Load an animation. - * - * @param id the resource id - * @return the animation - * @throw std::runtime_error on errors - */ - virtual Animation loadAnimation(const std::string &id); + /** + * Load an animation. + * + * @param id the resource id + * @return the animation + * @throw std::runtime_error on errors + */ + virtual Animation loadAnimation(const std::string &id); }; } // !malikania
--- a/libclient/malikania/client-target-loading.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client-target-loading.h Thu Jun 16 13:35:31 2016 +0200 @@ -25,9 +25,9 @@ class Client::LoadingTarget : public Client::Target { public: - virtual void update(Client &client); + virtual void update(Client &client); - virtual void draw(Client &client); + virtual void draw(Client &client); }; } // !malikania
--- a/libclient/malikania/client-target-map.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client-target-map.h Thu Jun 16 13:35:31 2016 +0200 @@ -25,9 +25,9 @@ class Client::MapTarget : public Client::Target { public: - virtual void update(Client &client); + virtual void update(Client &client); - virtual void draw(Client &client); + virtual void draw(Client &client); }; } // !malikania
--- a/libclient/malikania/client-target.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client-target.h Thu Jun 16 13:35:31 2016 +0200 @@ -25,29 +25,29 @@ class Client::Target : public duk::Bindable { public: - Target() = default; + Target() = default; - virtual ~Target() = default; + virtual ~Target() = default; - virtual void load(Client &client) - { - (void)client; - } + virtual void load(Client &client) + { + (void)client; + } - virtual void update(Client &client) - { - (void)client; - } + virtual void update(Client &client) + { + (void)client; + } - virtual void draw(Client &client) - { - (void)client; - } + virtual void draw(Client &client) + { + (void)client; + } - virtual void unload(Client &client) - { - (void)client; - } + virtual void unload(Client &client) + { + (void)client; + } }; } // !malikania
--- a/libclient/malikania/client.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -23,32 +23,32 @@ namespace malikania { Client::Client() - : m_loadingTarget(std::make_shared<LoadingTarget>()) - , m_mapTarget(std::make_shared<MapTarget>()) - , m_target(m_loadingTarget) + : m_loadingTarget(std::make_shared<LoadingTarget>()) + , m_mapTarget(std::make_shared<MapTarget>()) + , m_target(m_loadingTarget) { - m_target->load(*this); + m_target->load(*this); } void Client::setTarget(std::shared_ptr<Target> target) { - m_targetNext = std::move(target); + m_targetNext = std::move(target); } void Client::update() { - if (m_targetNext) { - m_target->unload(*this); - m_target = std::move(m_targetNext); - m_target->load(*this); - } + if (m_targetNext) { + m_target->unload(*this); + m_target = std::move(m_targetNext); + m_target->load(*this); + } - m_target->update(*this); + m_target->update(*this); } void Client::draw() { - m_target->draw(*this); + m_target->draw(*this); } } // !malikania
--- a/libclient/malikania/client.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/client.h Thu Jun 16 13:35:31 2016 +0200 @@ -27,45 +27,45 @@ class Client : public Window { public: - class Target; - class LoadingTarget; - class MapTarget; + class Target; + class LoadingTarget; + class MapTarget; private: - std::shared_ptr<LoadingTarget> m_loadingTarget; - std::shared_ptr<MapTarget> m_mapTarget; + std::shared_ptr<LoadingTarget> m_loadingTarget; + std::shared_ptr<MapTarget> m_mapTarget; - std::shared_ptr<Target> m_target; - std::shared_ptr<Target> m_targetNext; + std::shared_ptr<Target> m_target; + std::shared_ptr<Target> m_targetNext; public: - Client(); + Client(); - inline const std::shared_ptr<LoadingTarget> &loadingTarget() noexcept - { - return m_loadingTarget; - } + inline const std::shared_ptr<LoadingTarget> &loadingTarget() noexcept + { + return m_loadingTarget; + } - inline void setLoadingTarget(std::shared_ptr<LoadingTarget> loadingTarget) noexcept - { - m_loadingTarget = std::move(loadingTarget); - } + inline void setLoadingTarget(std::shared_ptr<LoadingTarget> loadingTarget) noexcept + { + m_loadingTarget = std::move(loadingTarget); + } - inline const std::shared_ptr<MapTarget> &mapTarget() noexcept - { - return m_mapTarget; - } + inline const std::shared_ptr<MapTarget> &mapTarget() noexcept + { + return m_mapTarget; + } - inline void setMapTarget(std::shared_ptr<MapTarget> mapTarget) noexcept - { - m_mapTarget = std::move(mapTarget); - } + inline void setMapTarget(std::shared_ptr<MapTarget> mapTarget) noexcept + { + m_mapTarget = std::move(mapTarget); + } - void setTarget(std::shared_ptr<Target> target); + void setTarget(std::shared_ptr<Target> target); - void update(); + void update(); - void draw(); + void draw(); }; } // !malikania
--- a/libclient/malikania/color.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/color.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -27,7 +27,7 @@ constexpr unsigned rgb(std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept { - return (0xff000000 | (r << 16) | (g << 8) | b); + return (0xff000000 | (r << 16) | (g << 8) | b); } /* @@ -35,202 +35,202 @@ */ std::uint8_t value(char digit) { - if (std::isdigit(digit)) { - return digit - '0'; - } - if ((digit = std::toupper(digit)) < 'A' || digit > 'F') { - throw std::invalid_argument("invalid hexadecimal value: " + std::to_string(digit)); - } + if (std::isdigit(digit)) { + return digit - '0'; + } + if ((digit = std::toupper(digit)) < 'A' || digit > 'F') { + throw std::invalid_argument("invalid hexadecimal value: " + std::to_string(digit)); + } - return digit - 55; + return digit - 55; } inline std::uint8_t value(char digit1, char digit2) { - return ((value(digit1) << 4) & 0xf0) | value(digit2); + return ((value(digit1) << 4) & 0xf0) | value(digit2); } const std::unordered_map<std::string, std::uint32_t> colors{ - { "aliceblue", rgb(240, 248, 255) }, - { "antiquewhite", rgb(250, 235, 215) }, - { "aqua", rgb( 0, 255, 255) }, - { "aquamarine", rgb(127, 255, 212) }, - { "azure", rgb(240, 255, 255) }, - { "beige", rgb(245, 245, 220) }, - { "bisque", rgb(255, 228, 196) }, - { "black", rgb( 0, 0, 0) }, - { "blanchedalmond", rgb(255, 235, 205) }, - { "blue", rgb( 0, 0, 255) }, - { "blueviolet", rgb(138, 43, 226) }, - { "brown", rgb(165, 42, 42) }, - { "burlywood", rgb(222, 184, 135) }, - { "cadetblue", rgb( 95, 158, 160) }, - { "chartreuse", rgb(127, 255, 0) }, - { "chocolate", rgb(210, 105, 30) }, - { "coral", rgb(255, 127, 80) }, - { "cornflowerblue", rgb(100, 149, 237) }, - { "cornsilk", rgb(255, 248, 220) }, - { "crimson", rgb(220, 20, 60) }, - { "cyan", rgb( 0, 255, 255) }, - { "darkblue", rgb( 0, 0, 139) }, - { "darkcyan", rgb( 0, 139, 139) }, - { "darkgoldenrod", rgb(184, 134, 11) }, - { "darkgray", rgb(169, 169, 169) }, - { "darkgreen", rgb( 0, 100, 0) }, - { "darkgrey", rgb(169, 169, 169) }, - { "darkkhaki", rgb(189, 183, 107) }, - { "darkmagenta", rgb(139, 0, 139) }, - { "darkolivegreen", rgb( 85, 107, 47) }, - { "darkorange", rgb(255, 140, 0) }, - { "darkorchid", rgb(153, 50, 204) }, - { "darkred", rgb(139, 0, 0) }, - { "darksalmon", rgb(233, 150, 122) }, - { "darkseagreen", rgb(143, 188, 143) }, - { "darkslateblue", rgb( 72, 61, 139) }, - { "darkslategray", rgb( 47, 79, 79) }, - { "darkslategrey", rgb( 47, 79, 79) }, - { "darkturquoise", rgb( 0, 206, 209) }, - { "darkviolet", rgb(148, 0, 211) }, - { "deeppink", rgb(255, 20, 147) }, - { "deepskyblue", rgb( 0, 191, 255) }, - { "dimgray", rgb(105, 105, 105) }, - { "dimgrey", rgb(105, 105, 105) }, - { "dodgerblue", rgb( 30, 144, 255) }, - { "firebrick", rgb(178, 34, 34) }, - { "floralwhite", rgb(255, 250, 240) }, - { "forestgreen", rgb( 34, 139, 34) }, - { "fuchsia", rgb(255, 0, 255) }, - { "gainsboro", rgb(220, 220, 220) }, - { "ghostwhite", rgb(248, 248, 255) }, - { "gold", rgb(255, 215, 0) }, - { "goldenrod", rgb(218, 165, 32) }, - { "gray", rgb(128, 128, 128) }, - { "green", rgb( 0, 128, 0) }, - { "greenyellow", rgb(173, 255, 47) }, - { "grey", rgb(128, 128, 128) }, - { "honeydew", rgb(240, 255, 240) }, - { "hotpink", rgb(255, 105, 180) }, - { "indianred", rgb(205, 92, 92) }, - { "indigo", rgb( 75, 0, 130) }, - { "ivory", rgb(255, 255, 240) }, - { "khaki", rgb(240, 230, 140) }, - { "lavender", rgb(230, 230, 250) }, - { "lavenderblush", rgb(255, 240, 245) }, - { "lawngreen", rgb(124, 252, 0) }, - { "lemonchiffon", rgb(255, 250, 205) }, - { "lightblue", rgb(173, 216, 230) }, - { "lightcoral", rgb(240, 128, 128) }, - { "lightcyan", rgb(224, 255, 255) }, - { "lightgoldenrodyellow", rgb(250, 250, 210) }, - { "lightgray", rgb(211, 211, 211) }, - { "lightgreen", rgb(144, 238, 144) }, - { "lightgrey", rgb(211, 211, 211) }, - { "lightpink", rgb(255, 182, 193) }, - { "lightsalmon", rgb(255, 160, 122) }, - { "lightseagreen", rgb( 32, 178, 170) }, - { "lightskyblue", rgb(135, 206, 250) }, - { "lightslategray", rgb(119, 136, 153) }, - { "lightslategrey", rgb(119, 136, 153) }, - { "lightsteelblue", rgb(176, 196, 222) }, - { "lightyellow", rgb(255, 255, 224) }, - { "lime", rgb( 0, 255, 0) }, - { "limegreen", rgb( 50, 205, 50) }, - { "linen", rgb(250, 240, 230) }, - { "magenta", rgb(255, 0, 255) }, - { "maroon", rgb(128, 0, 0) }, - { "mediumaquamarine", rgb(102, 205, 170) }, - { "mediumblue", rgb( 0, 0, 205) }, - { "mediumorchid", rgb(186, 85, 211) }, - { "mediumpurple", rgb(147, 112, 219) }, - { "mediumseagreen", rgb( 60, 179, 113) }, - { "mediumslateblue", rgb(123, 104, 238) }, - { "mediumspringgreen", rgb( 0, 250, 154) }, - { "mediumturquoise", rgb( 72, 209, 204) }, - { "mediumvioletred", rgb(199, 21, 133) }, - { "midnightblue", rgb( 25, 25, 112) }, - { "mintcream", rgb(245, 255, 250) }, - { "mistyrose", rgb(255, 228, 225) }, - { "moccasin", rgb(255, 228, 181) }, - { "navajowhite", rgb(255, 222, 173) }, - { "navy", rgb( 0, 0, 128) }, - { "oldlace", rgb(253, 245, 230) }, - { "olive", rgb(128, 128, 0) }, - { "olivedrab", rgb(107, 142, 35) }, - { "orange", rgb(255, 165, 0) }, - { "orangered", rgb(255, 69, 0) }, - { "orchid", rgb(218, 112, 214) }, - { "palegoldenrod", rgb(238, 232, 170) }, - { "palegreen", rgb(152, 251, 152) }, - { "paleturquoise", rgb(175, 238, 238) }, - { "palevioletred", rgb(219, 112, 147) }, - { "papayawhip", rgb(255, 239, 213) }, - { "peachpuff", rgb(255, 218, 185) }, - { "peru", rgb(205, 133, 63) }, - { "pink", rgb(255, 192, 203) }, - { "plum", rgb(221, 160, 221) }, - { "powderblue", rgb(176, 224, 230) }, - { "purple", rgb(128, 0, 128) }, - { "red", rgb(255, 0, 0) }, - { "rosybrown", rgb(188, 143, 143) }, - { "royalblue", rgb( 65, 105, 225) }, - { "saddlebrown", rgb(139, 69, 19) }, - { "salmon", rgb(250, 128, 114) }, - { "sandybrown", rgb(244, 164, 96) }, - { "seagreen", rgb( 46, 139, 87) }, - { "seashell", rgb(255, 245, 238) }, - { "sienna", rgb(160, 82, 45) }, - { "silver", rgb(192, 192, 192) }, - { "skyblue", rgb(135, 206, 235) }, - { "slateblue", rgb(106, 90, 205) }, - { "slategray", rgb(112, 128, 144) }, - { "slategrey", rgb(112, 128, 144) }, - { "snow", rgb(255, 250, 250) }, - { "springgreen", rgb( 0, 255, 127) }, - { "steelblue", rgb( 70, 130, 180) }, - { "tan", rgb(210, 180, 140) }, - { "teal", rgb( 0, 128, 128) }, - { "thistle", rgb(216, 191, 216) }, - { "tomato", rgb(255, 99, 71) }, - { "transparent", 0 }, - { "turquoise", rgb( 64, 224, 208) }, - { "violet", rgb(238, 130, 238) }, - { "wheat", rgb(245, 222, 179) }, - { "white", rgb(255, 255, 255) }, - { "whitesmoke", rgb(245, 245, 245) }, - { "yellow", rgb(255, 255, 0) }, - { "yellowgreen", rgb(154, 205, 50) } + { "aliceblue", rgb(240, 248, 255) }, + { "antiquewhite", rgb(250, 235, 215) }, + { "aqua", rgb( 0, 255, 255) }, + { "aquamarine", rgb(127, 255, 212) }, + { "azure", rgb(240, 255, 255) }, + { "beige", rgb(245, 245, 220) }, + { "bisque", rgb(255, 228, 196) }, + { "black", rgb( 0, 0, 0) }, + { "blanchedalmond", rgb(255, 235, 205) }, + { "blue", rgb( 0, 0, 255) }, + { "blueviolet", rgb(138, 43, 226) }, + { "brown", rgb(165, 42, 42) }, + { "burlywood", rgb(222, 184, 135) }, + { "cadetblue", rgb( 95, 158, 160) }, + { "chartreuse", rgb(127, 255, 0) }, + { "chocolate", rgb(210, 105, 30) }, + { "coral", rgb(255, 127, 80) }, + { "cornflowerblue", rgb(100, 149, 237) }, + { "cornsilk", rgb(255, 248, 220) }, + { "crimson", rgb(220, 20, 60) }, + { "cyan", rgb( 0, 255, 255) }, + { "darkblue", rgb( 0, 0, 139) }, + { "darkcyan", rgb( 0, 139, 139) }, + { "darkgoldenrod", rgb(184, 134, 11) }, + { "darkgray", rgb(169, 169, 169) }, + { "darkgreen", rgb( 0, 100, 0) }, + { "darkgrey", rgb(169, 169, 169) }, + { "darkkhaki", rgb(189, 183, 107) }, + { "darkmagenta", rgb(139, 0, 139) }, + { "darkolivegreen", rgb( 85, 107, 47) }, + { "darkorange", rgb(255, 140, 0) }, + { "darkorchid", rgb(153, 50, 204) }, + { "darkred", rgb(139, 0, 0) }, + { "darksalmon", rgb(233, 150, 122) }, + { "darkseagreen", rgb(143, 188, 143) }, + { "darkslateblue", rgb( 72, 61, 139) }, + { "darkslategray", rgb( 47, 79, 79) }, + { "darkslategrey", rgb( 47, 79, 79) }, + { "darkturquoise", rgb( 0, 206, 209) }, + { "darkviolet", rgb(148, 0, 211) }, + { "deeppink", rgb(255, 20, 147) }, + { "deepskyblue", rgb( 0, 191, 255) }, + { "dimgray", rgb(105, 105, 105) }, + { "dimgrey", rgb(105, 105, 105) }, + { "dodgerblue", rgb( 30, 144, 255) }, + { "firebrick", rgb(178, 34, 34) }, + { "floralwhite", rgb(255, 250, 240) }, + { "forestgreen", rgb( 34, 139, 34) }, + { "fuchsia", rgb(255, 0, 255) }, + { "gainsboro", rgb(220, 220, 220) }, + { "ghostwhite", rgb(248, 248, 255) }, + { "gold", rgb(255, 215, 0) }, + { "goldenrod", rgb(218, 165, 32) }, + { "gray", rgb(128, 128, 128) }, + { "green", rgb( 0, 128, 0) }, + { "greenyellow", rgb(173, 255, 47) }, + { "grey", rgb(128, 128, 128) }, + { "honeydew", rgb(240, 255, 240) }, + { "hotpink", rgb(255, 105, 180) }, + { "indianred", rgb(205, 92, 92) }, + { "indigo", rgb( 75, 0, 130) }, + { "ivory", rgb(255, 255, 240) }, + { "khaki", rgb(240, 230, 140) }, + { "lavender", rgb(230, 230, 250) }, + { "lavenderblush", rgb(255, 240, 245) }, + { "lawngreen", rgb(124, 252, 0) }, + { "lemonchiffon", rgb(255, 250, 205) }, + { "lightblue", rgb(173, 216, 230) }, + { "lightcoral", rgb(240, 128, 128) }, + { "lightcyan", rgb(224, 255, 255) }, + { "lightgoldenrodyellow", rgb(250, 250, 210) }, + { "lightgray", rgb(211, 211, 211) }, + { "lightgreen", rgb(144, 238, 144) }, + { "lightgrey", rgb(211, 211, 211) }, + { "lightpink", rgb(255, 182, 193) }, + { "lightsalmon", rgb(255, 160, 122) }, + { "lightseagreen", rgb( 32, 178, 170) }, + { "lightskyblue", rgb(135, 206, 250) }, + { "lightslategray", rgb(119, 136, 153) }, + { "lightslategrey", rgb(119, 136, 153) }, + { "lightsteelblue", rgb(176, 196, 222) }, + { "lightyellow", rgb(255, 255, 224) }, + { "lime", rgb( 0, 255, 0) }, + { "limegreen", rgb( 50, 205, 50) }, + { "linen", rgb(250, 240, 230) }, + { "magenta", rgb(255, 0, 255) }, + { "maroon", rgb(128, 0, 0) }, + { "mediumaquamarine", rgb(102, 205, 170) }, + { "mediumblue", rgb( 0, 0, 205) }, + { "mediumorchid", rgb(186, 85, 211) }, + { "mediumpurple", rgb(147, 112, 219) }, + { "mediumseagreen", rgb( 60, 179, 113) }, + { "mediumslateblue", rgb(123, 104, 238) }, + { "mediumspringgreen", rgb( 0, 250, 154) }, + { "mediumturquoise", rgb( 72, 209, 204) }, + { "mediumvioletred", rgb(199, 21, 133) }, + { "midnightblue", rgb( 25, 25, 112) }, + { "mintcream", rgb(245, 255, 250) }, + { "mistyrose", rgb(255, 228, 225) }, + { "moccasin", rgb(255, 228, 181) }, + { "navajowhite", rgb(255, 222, 173) }, + { "navy", rgb( 0, 0, 128) }, + { "oldlace", rgb(253, 245, 230) }, + { "olive", rgb(128, 128, 0) }, + { "olivedrab", rgb(107, 142, 35) }, + { "orange", rgb(255, 165, 0) }, + { "orangered", rgb(255, 69, 0) }, + { "orchid", rgb(218, 112, 214) }, + { "palegoldenrod", rgb(238, 232, 170) }, + { "palegreen", rgb(152, 251, 152) }, + { "paleturquoise", rgb(175, 238, 238) }, + { "palevioletred", rgb(219, 112, 147) }, + { "papayawhip", rgb(255, 239, 213) }, + { "peachpuff", rgb(255, 218, 185) }, + { "peru", rgb(205, 133, 63) }, + { "pink", rgb(255, 192, 203) }, + { "plum", rgb(221, 160, 221) }, + { "powderblue", rgb(176, 224, 230) }, + { "purple", rgb(128, 0, 128) }, + { "red", rgb(255, 0, 0) }, + { "rosybrown", rgb(188, 143, 143) }, + { "royalblue", rgb( 65, 105, 225) }, + { "saddlebrown", rgb(139, 69, 19) }, + { "salmon", rgb(250, 128, 114) }, + { "sandybrown", rgb(244, 164, 96) }, + { "seagreen", rgb( 46, 139, 87) }, + { "seashell", rgb(255, 245, 238) }, + { "sienna", rgb(160, 82, 45) }, + { "silver", rgb(192, 192, 192) }, + { "skyblue", rgb(135, 206, 235) }, + { "slateblue", rgb(106, 90, 205) }, + { "slategray", rgb(112, 128, 144) }, + { "slategrey", rgb(112, 128, 144) }, + { "snow", rgb(255, 250, 250) }, + { "springgreen", rgb( 0, 255, 127) }, + { "steelblue", rgb( 70, 130, 180) }, + { "tan", rgb(210, 180, 140) }, + { "teal", rgb( 0, 128, 128) }, + { "thistle", rgb(216, 191, 216) }, + { "tomato", rgb(255, 99, 71) }, + { "transparent", 0 }, + { "turquoise", rgb( 64, 224, 208) }, + { "violet", rgb(238, 130, 238) }, + { "wheat", rgb(245, 222, 179) }, + { "white", rgb(255, 255, 255) }, + { "whitesmoke", rgb(245, 245, 245) }, + { "yellow", rgb(255, 255, 0) }, + { "yellowgreen", rgb(154, 205, 50) } }; } // !namespace Color::Color(const std::string &name) { - if (!name.empty()) { - /* Parse #rrggbb or #rgb */ - if (name[0] == '#') { - if (name.length() == 7) { - m_red = value(name[1], name[2]); - m_green = value(name[3], name[4]); - m_blue = value(name[5], name[6]); - } else if (name.length() == 4) { - m_red = value(name[1], name[1]); - m_green = value(name[2], name[2]); - m_blue = value(name[3], name[3]); - } else { - throw std::invalid_argument{"invalid format"}; - } - } else { - /* Name lookup */ - auto it = colors.find(name); + if (!name.empty()) { + /* Parse #rrggbb or #rgb */ + if (name[0] == '#') { + if (name.length() == 7) { + m_red = value(name[1], name[2]); + m_green = value(name[3], name[4]); + m_blue = value(name[5], name[6]); + } else if (name.length() == 4) { + m_red = value(name[1], name[1]); + m_green = value(name[2], name[2]); + m_blue = value(name[3], name[3]); + } else { + throw std::invalid_argument{"invalid format"}; + } + } else { + /* Name lookup */ + auto it = colors.find(name); - if (it == colors.end()) { - throw std::invalid_argument{name + " is not a valid color"}; - } + if (it == colors.end()) { + throw std::invalid_argument{name + " is not a valid color"}; + } - /* Assign the color to *this */ - *this = it->second; - } - } + /* Assign the color to *this */ + *this = it->second; + } + } } } // !malikania
--- a/libclient/malikania/color.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/color.h Thu Jun 16 13:35:31 2016 +0200 @@ -30,95 +30,95 @@ */ class Color { private: - std::uint8_t m_red{0}; - std::uint8_t m_green{0}; - std::uint8_t m_blue{0}; - std::uint8_t m_alpha{255}; + std::uint8_t m_red{0}; + std::uint8_t m_green{0}; + std::uint8_t m_blue{0}; + std::uint8_t m_alpha{255}; public: - /** - * Default color to black. - */ - inline Color() noexcept = default; + /** + * Default color to black. + */ + inline Color() noexcept = default; - /** - * Constructor with all fields. - * - * @param red the red value - * @param green the green value - * @param blue the blue value - * @param alpha the alpha value - */ - inline Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha) noexcept - : m_red(red) - , m_green(green) - , m_blue(blue) - , m_alpha(alpha) - { - } + /** + * Constructor with all fields. + * + * @param red the red value + * @param green the green value + * @param blue the blue value + * @param alpha the alpha value + */ + inline Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha) noexcept + : m_red(red) + , m_green(green) + , m_blue(blue) + , m_alpha(alpha) + { + } - /** - * Constructor with an hexadecimal value. - * - * @param hex the color - */ - inline Color(std::uint32_t hex) noexcept - : m_red((hex >> 16) & 0xff) - , m_green((hex >> 8) & 0xff) - , m_blue(hex & 0xff) - , m_alpha((hex >> 24) & 0xff) - { - } + /** + * Constructor with an hexadecimal value. + * + * @param hex the color + */ + inline Color(std::uint32_t hex) noexcept + : m_red((hex >> 16) & 0xff) + , m_green((hex >> 8) & 0xff) + , m_blue(hex & 0xff) + , m_alpha((hex >> 24) & 0xff) + { + } - /** - * Construct a color from #rrggbb or name. - * - * See the SVG this [list](http://www.december.com/html/spec/colorsvg.html) for supported names. - * - * @param name the color name - * @throw std::invalid_argument if the color does not exist or is invalid - */ - Color(const std::string &name); + /** + * Construct a color from #rrggbb or name. + * + * See the SVG this [list](http://www.december.com/html/spec/colorsvg.html) for supported names. + * + * @param name the color name + * @throw std::invalid_argument if the color does not exist or is invalid + */ + Color(const std::string &name); - /** - * Get the red value. - * - * @return the value - */ - inline std::uint8_t red() const noexcept - { - return m_red; - } + /** + * Get the red value. + * + * @return the value + */ + inline std::uint8_t red() const noexcept + { + return m_red; + } - /** - * Get the green value. - * - * @return the value - */ - inline std::uint8_t green() const noexcept - { - return m_green; - } + /** + * Get the green value. + * + * @return the value + */ + inline std::uint8_t green() const noexcept + { + return m_green; + } - /** - * Get the blue value. - * - * @return the value - */ - inline std::uint8_t blue() const noexcept - { - return m_blue; - } + /** + * Get the blue value. + * + * @return the value + */ + inline std::uint8_t blue() const noexcept + { + return m_blue; + } - /** - * Get the alpha value. - * - * @return the value - */ - inline std::uint8_t alpha() const noexcept - { - return m_alpha; - } + /** + * Get the alpha value. + * + * @return the value + */ + inline std::uint8_t alpha() const noexcept + { + return m_alpha; + } }; } // !malikania
--- a/libclient/malikania/font.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/font.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -21,8 +21,8 @@ namespace malikania { Font::Font(std::string data, unsigned size) - : m_backend(std::make_unique<Backend>(std::move(data), size)) - , m_size(size) + : m_backend(std::make_unique<Backend>(std::move(data), size)) + , m_size(size) { } @@ -32,7 +32,7 @@ Size Font::clip(const std::string &text) const { - return m_backend->clip(*this, text); + return m_backend->clip(*this, text); } Font &Font::operator=(Font &&other) noexcept = default;
--- a/libclient/malikania/font.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/font.h Thu Jun 16 13:35:31 2016 +0200 @@ -38,77 +38,77 @@ */ class Font : public duk::Bindable { private: - class Backend; + class Backend; - std::unique_ptr<Backend> m_backend; - unsigned m_size; + std::unique_ptr<Backend> m_backend; + unsigned m_size; public: - /** - * Construct a font from binary data. - * - * @param data the raw data - * @param size the size - */ - Font(std::string data, unsigned size); + /** + * Construct a font from binary data. + * + * @param data the raw data + * @param size the size + */ + Font(std::string data, unsigned size); - /** - * Default move constructor. - * - * @param other the other font - */ - Font(Font &&other) noexcept; + /** + * Default move constructor. + * + * @param other the other font + */ + Font(Font &&other) noexcept; - /** - * Default destructor. - */ - virtual ~Font() noexcept; + /** + * Default destructor. + */ + virtual ~Font() noexcept; - /** - * Get the font size. - * - * @return the font size - */ - inline unsigned size() const noexcept - { - return m_size; - } + /** + * Get the font size. + * + * @return the font size + */ + inline unsigned size() const noexcept + { + return m_size; + } - /** - * Get the underlying backend. - * - * @return the backend - */ - inline const Backend &backend() const noexcept - { - return *m_backend; - } + /** + * Get the underlying backend. + * + * @return the backend + */ + inline const Backend &backend() const noexcept + { + return *m_backend; + } - /** - * Overloaded function. - * - * @return the backend - */ - inline Backend &backend() noexcept - { - return *m_backend; - } + /** + * Overloaded function. + * + * @return the backend + */ + inline Backend &backend() noexcept + { + return *m_backend; + } - /** - * Get the clipping size required to draw the given text. - * - * @param text the text to clip - * @return the required size - */ - Size clip(const std::string &text) const; + /** + * Get the clipping size required to draw the given text. + * + * @param text the text to clip + * @return the required size + */ + Size clip(const std::string &text) const; - /** - * Default move assignment operator. - * - * @param other the other font - * @return this - */ - Font &operator=(Font &&other) noexcept; + /** + * Default move assignment operator. + * + * @param other the other font + * @return this + */ + Font &operator=(Font &&other) noexcept; }; } // !malikania
--- a/libclient/malikania/image.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/image.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -21,7 +21,7 @@ namespace malikania { Image::Image(std::string data) - : m_backend(std::make_unique<Backend>(*this, std::move(data))) + : m_backend(std::make_unique<Backend>(*this, std::move(data))) { } @@ -31,17 +31,17 @@ const Size &Image::size() const noexcept { - return m_backend->size(); + return m_backend->size(); } void Image::draw(Window &window, const Point &position) { - m_backend->draw(window, position); + m_backend->draw(window, position); } void Image::draw(Window &window, const Rectangle &source, const Rectangle &target) { - m_backend->draw(window, source, target); + m_backend->draw(window, source, target); } Image &Image::operator=(Image &&) noexcept = default;
--- a/libclient/malikania/image.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/image.h Thu Jun 16 13:35:31 2016 +0200 @@ -42,82 +42,82 @@ */ class Image : public duk::Bindable { private: - class Backend; + class Backend; - std::unique_ptr<Backend> m_backend; + std::unique_ptr<Backend> m_backend; public: - /** - * Construct an image from the binary data. - * - * @param window the window - * @param data the data - */ - Image(std::string data); + /** + * Construct an image from the binary data. + * + * @param window the window + * @param data the data + */ + Image(std::string data); - /** - * Default move constructor. - * - * @param other the other image - */ - Image(Image &&other) noexcept; + /** + * Default move constructor. + * + * @param other the other image + */ + Image(Image &&other) noexcept; - /** - * Default destructor. - */ - ~Image() noexcept; + /** + * Default destructor. + */ + ~Image() noexcept; - /** - * Overloaded function. - * - * @return the backend - */ - inline Backend &backend() noexcept - { - return *m_backend; - } + /** + * Overloaded function. + * + * @return the backend + */ + inline Backend &backend() noexcept + { + return *m_backend; + } - /** - * Get the underlying backend. - * - * @return the backend - */ - inline const Backend &backend() const noexcept - { - return *m_backend; - } + /** + * Get the underlying backend. + * + * @return the backend + */ + inline const Backend &backend() const noexcept + { + return *m_backend; + } - /** - * Get the image size. - * - * @return the size - */ - const Size &size() const noexcept; + /** + * Get the image size. + * + * @return the size + */ + const Size &size() const noexcept; - /** - * Draw the image to the window. - * - * @param window the window - * @param position the position - */ - void draw(Window &window, const Point &position = {0, 0}); + /** + * Draw the image to the window. + * + * @param window the window + * @param position the position + */ + void draw(Window &window, const Point &position = {0, 0}); - /** - * Overloaded function. - * - * @param window the window - * @param source the source to clip - * @param target the target destination - */ - void draw(Window &window, const Rectangle &source, const Rectangle &target); + /** + * Overloaded function. + * + * @param window the window + * @param source the source to clip + * @param target the target destination + */ + void draw(Window &window, const Rectangle &source, const Rectangle &target); - /** - * Default move assignment operator. - * - * @param other the other image - * @return this - */ - Image &operator=(Image &&image) noexcept; + /** + * Default move assignment operator. + * + * @param other the other image + * @return this + */ + Image &operator=(Image &&image) noexcept; }; } // !malikania
--- a/libclient/malikania/js-animation.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-animation.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -25,34 +25,34 @@ duk::Ret constructor(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "animation must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "animation must be new-constructed"); + } - try { - auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); - auto animation = loader->loadAnimation(duk::require<std::string>(ctx, 0)); + try { + auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); + auto animation = loader->loadAnimation(duk::require<std::string>(ctx, 0)); - duk::construct(ctx, std::make_shared<Animation>(std::move(animation))); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + duk::construct(ctx, std::make_shared<Animation>(std::move(animation))); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } } // !namespace void loadMalikaniaAnimation(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 1}); - duk::putProperty(ctx, -2, "Animation"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 1}); + duk::putProperty(ctx, -2, "Animation"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-animator.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-animator.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -27,60 +27,60 @@ duk::Ret constructor(duk::ContextPtr ctx) { - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "animator must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "animator must be new-constructed"); + } - duk::construct(ctx, std::make_shared<Animator>(*duk::require<std::shared_ptr<Animation>>(ctx, 0))); + duk::construct(ctx, std::make_shared<Animator>(*duk::require<std::shared_ptr<Animation>>(ctx, 0))); - /* Be sure animation get not collected before */ - duk::push(ctx, duk::This()); - duk::dup(ctx, 0); - duk::putProperty(ctx, -2, "\xff""\xff""animation-ref"); + /* Be sure animation get not collected before */ + duk::push(ctx, duk::This()); + duk::dup(ctx, 0); + duk::putProperty(ctx, -2, "\xff""\xff""animation-ref"); - return 0; + return 0; } duk::Ret draw(duk::ContextPtr ctx) { - try { - auto self = duk::self<std::shared_ptr<Animator>>(ctx); - auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); - auto point = duk::get<Point>(ctx, 1); + try { + auto self = duk::self<std::shared_ptr<Animator>>(ctx); + auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); + auto point = duk::get<Point>(ctx, 1); - self->draw(*window, point); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + self->draw(*window, point); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret update(duk::ContextPtr ctx) { - duk::self<std::shared_ptr<Animator>>(ctx)->update(); + duk::self<std::shared_ptr<Animator>>(ctx)->update(); - return 0; + return 0; } const duk::FunctionMap methods{ - { "draw", { draw, 2 } }, - { "update", { update, 0 } } + { "draw", { draw, 2 } }, + { "update", { update, 0 } } }; } // !namespace void loadMalikaniaAnimator(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 1}); - duk::push(ctx, duk::Object()); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Animator"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 1}); + duk::push(ctx, duk::Object()); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Animator"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-client-target.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-client-target.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -13,28 +13,28 @@ { - return 0; + return 0; } duk::Ret draw(duk::ContextPtr ctx) { - //duk::self<std::shared_ptr<Client::Target>>(ctx)->draw(); + //duk::self<std::shared_ptr<Client::Target>>(ctx)->draw(); - return 0; + return 0; } } // !namespace void loadMalikaniaClientTarget(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::getProperty<void>(ctx, -1, "Client"); - duk::push(ctx, duk::Function{constructor}); - duk::putProperty(ctx, -1, "prototype", duk::Object()); - duk::putProperty(ctx, -2, "Target"); - duk::pop(ctx, 2); + duk::getGlobal<void>(ctx, "Malikania"); + duk::getProperty<void>(ctx, -1, "Client"); + duk::push(ctx, duk::Function{constructor}); + duk::putProperty(ctx, -1, "prototype", duk::Object()); + duk::putProperty(ctx, -2, "Target"); + duk::pop(ctx, 2); } } // !malikania
--- a/libclient/malikania/js-client.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-client.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -8,57 +8,57 @@ duk::Ret draw(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Client>>(ctx)->draw(); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Client>>(ctx)->draw(); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret setTarget(duk::ContextPtr ctx) { - auto self = duk::self<std::shared_ptr<Client>>(ctx); - auto target = duk::get<std::shared_ptr<Client::Target>>(ctx, 0); + auto self = duk::self<std::shared_ptr<Client>>(ctx); + auto target = duk::get<std::shared_ptr<Client::Target>>(ctx, 0); - self->setTarget(std::move(target)); + self->setTarget(std::move(target)); - return 0; + return 0; } duk::Ret update(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Client>>(ctx)->update(); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Client>>(ctx)->update(); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } const duk::FunctionMap methods{ - { "draw", { draw, 0 } }, - { "setTarget", { setTarget, 1 } }, - { "update", { update, 0 } } + { "draw", { draw, 0 } }, + { "setTarget", { setTarget, 1 } }, + { "update", { update, 0 } } }; } // !namespace void loadMalikaniaClient(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Object()); - duk::push(ctx, duk::Object()); - duk::TypeTraits<Window>::prototype(ctx); - duk::setPrototype(ctx, -2); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Client"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Object()); + duk::push(ctx, duk::Object()); + duk::TypeTraits<Window>::prototype(ctx); + duk::setPrototype(ctx, -2); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Client"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-client.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-client.h Thu Jun 16 13:35:31 2016 +0200 @@ -11,16 +11,16 @@ template <> class TypeTraits<Client> { public: - static inline void prototype(ContextPtr ctx) - { - StackAssert sa(ctx, 1); + static inline void prototype(ContextPtr ctx) + { + StackAssert sa(ctx, 1); - getGlobal<void>(ctx, "Malikania"); - getProperty<void>(ctx, -1, "Client"); - getProperty<void>(ctx, -1, "prototype"); - remove(ctx, -2); - remove(ctx, -2); - } + getGlobal<void>(ctx, "Malikania"); + getProperty<void>(ctx, -1, "Client"); + getProperty<void>(ctx, -1, "prototype"); + remove(ctx, -2); + remove(ctx, -2); + } }; } // !duk
--- a/libclient/malikania/js-color.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-color.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -27,108 +27,108 @@ std::uint8_t clampComponent(duk::ContextPtr ctx, int value, bool required) { - if (value < 0 || value > 255) { - if (required) { - duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d is out of range (0, 255)", value); - } else { - value = util::clamp(value, 0, 255); - } - } + if (value < 0 || value > 255) { + if (required) { + duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d is out of range (0, 255)", value); + } else { + value = util::clamp(value, 0, 255); + } + } - return static_cast<std::uint8_t>(value); + return static_cast<std::uint8_t>(value); } Color parseString(duk::ContextPtr ctx, duk::Index index, bool required) { - assert(duk::type(ctx, index) == DUK_TYPE_STRING); + assert(duk::type(ctx, index) == DUK_TYPE_STRING); - Color color; + Color color; - try { - color = Color(duk::get<std::string>(ctx, index)); - } catch (const std::exception &ex) { - if (required) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } - } + try { + color = Color(duk::get<std::string>(ctx, index)); + } catch (const std::exception &ex) { + if (required) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } + } - return color; + return color; } Color parseObject(duk::ContextPtr ctx, duk::Index index, bool required) { - assert(duk::type(ctx, index) == DUK_TYPE_OBJECT); + assert(duk::type(ctx, index) == DUK_TYPE_OBJECT); - auto require = [&] (const std::string &property) -> std::uint8_t { - if (required && !duk::hasProperty(ctx, index, property)) { - duk::raise(ctx, DUK_ERR_ERROR, "missing %s property in color description", property.c_str()); - } + auto require = [&] (const std::string &property) -> std::uint8_t { + if (required && !duk::hasProperty(ctx, index, property)) { + duk::raise(ctx, DUK_ERR_ERROR, "missing %s property in color description", property.c_str()); + } - return clampComponent(ctx, duk::getProperty<int>(ctx, index, property), required); - }; + return clampComponent(ctx, duk::getProperty<int>(ctx, index, property), required); + }; - return Color( - require("red"), - require("green"), - require("blue"), - clampComponent(ctx, duk::optionalProperty<int>(ctx, index, "alpha", 255), required) - ); + return Color( + require("red"), + require("green"), + require("blue"), + clampComponent(ctx, duk::optionalProperty<int>(ctx, index, "alpha", 255), required) + ); } Color parse(duk::ContextPtr ctx, duk::Index index, bool required, Color color = {}) { - switch (duk::type(ctx, index)) { - case DUK_TYPE_STRING: - color = parseString(ctx, index, required); - break; - case DUK_TYPE_OBJECT: - color = parseObject(ctx, index, required); - break; - default: - if (required) { - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "color (string, object) expected"); - } + switch (duk::type(ctx, index)) { + case DUK_TYPE_STRING: + color = parseString(ctx, index, required); + break; + case DUK_TYPE_OBJECT: + color = parseObject(ctx, index, required); + break; + default: + if (required) { + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "color (string, object) expected"); + } - break; - } + break; + } - return color; + return color; } duk::Ret constructor(duk::ContextPtr ctx) { - Color color; + Color color; - /* - * The constructor allows an additional signature that takes 4 number arguments, otherwise use the literal - * parsing functions. - */ - if (duk::top(ctx) >= 3) { - color = Color( - clampComponent(ctx, duk::require<int>(ctx, 0), true), - clampComponent(ctx, duk::require<int>(ctx, 1), true), - clampComponent(ctx, duk::require<int>(ctx, 2), true), - clampComponent(ctx, duk::optional<int>(ctx, 3, 255), true) - ); - } else if (duk::top(ctx) == 1) { - color = parse(ctx, 0, true); - } + /* + * The constructor allows an additional signature that takes 4 number arguments, otherwise use the literal + * parsing functions. + */ + if (duk::top(ctx) >= 3) { + color = Color( + clampComponent(ctx, duk::require<int>(ctx, 0), true), + clampComponent(ctx, duk::require<int>(ctx, 1), true), + clampComponent(ctx, duk::require<int>(ctx, 2), true), + clampComponent(ctx, duk::optional<int>(ctx, 3, 255), true) + ); + } else if (duk::top(ctx) == 1) { + color = parse(ctx, 0, true); + } - duk::Ret ret; + duk::Ret ret; - /* Allow both constructor and non constructor calls */ - if (duk_is_constructor_call(ctx)) { - duk::push(ctx, duk::This()); - /* TODO: use duk::put when available */ - duk::TypeTraits<Color>::put(ctx, color); - duk::pop(ctx); - ret = 0; - } else { - duk::push(ctx, color); - ret = 1; - } + /* Allow both constructor and non constructor calls */ + if (duk_is_constructor_call(ctx)) { + duk::push(ctx, duk::This()); + /* TODO: use duk::put when available */ + duk::TypeTraits<Color>::put(ctx, color); + duk::pop(ctx); + ret = 0; + } else { + duk::push(ctx, color); + ret = 1; + } - return ret; + return ret; } } //! namespace @@ -137,50 +137,50 @@ Color TypeTraits<Color>::get(ContextPtr ctx, Index index) { - return parse(ctx, index, false); + return parse(ctx, index, false); } Color TypeTraits<Color>::require(ContextPtr ctx, Index index) { - return parse(ctx, index, true); + return parse(ctx, index, true); } Color TypeTraits<Color>::optional(ContextPtr ctx, Index index, Color def) { - return parse(ctx, index, false, std::move(def)); + return parse(ctx, index, false, std::move(def)); } void TypeTraits<Color>::push(ContextPtr ctx, const Color &color) { - duk::StackAssert sa(ctx, 1); + duk::StackAssert sa(ctx, 1); - duk::push(ctx, Object()); - /* TODO: use duk::put when available */ - duk::TypeTraits<Color>::put(ctx, color); + duk::push(ctx, Object()); + /* TODO: use duk::put when available */ + duk::TypeTraits<Color>::put(ctx, color); } void TypeTraits<Color>::put(ContextPtr ctx, const Color &color) { - assert(type(ctx, -1) == DUK_TYPE_OBJECT); + assert(type(ctx, -1) == DUK_TYPE_OBJECT); - StackAssert sa(ctx, 0); + StackAssert sa(ctx, 0); - putProperty(ctx, -1, "red", static_cast<int>(color.red())); - putProperty(ctx, -1, "green", static_cast<int>(color.green())); - putProperty(ctx, -1, "blue", static_cast<int>(color.blue())); - putProperty(ctx, -1, "alpha", static_cast<int>(color.alpha())); + putProperty(ctx, -1, "red", static_cast<int>(color.red())); + putProperty(ctx, -1, "green", static_cast<int>(color.green())); + putProperty(ctx, -1, "blue", static_cast<int>(color.blue())); + putProperty(ctx, -1, "alpha", static_cast<int>(color.alpha())); } } // !duk void loadMalikaniaColor(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx, 0); + duk::StackAssert sa(ctx, 0); - duk::getGlobal<void>(ctx, "Malikania"); - duk::putProperty(ctx, -1, "Color", duk::Function{constructor, DUK_VARARGS}); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::putProperty(ctx, -1, "Color", duk::Function{constructor, DUK_VARARGS}); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-color.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-color.h Thu Jun 16 13:35:31 2016 +0200 @@ -45,52 +45,52 @@ template <> class TypeTraits<Color> { public: - /** - * Get a color. - * - * May return a default value or a color with adjusted components. - * - * @param ctx the context - * @param index the index - */ - static Color get(ContextPtr ctx, Index index); + /** + * Get a color. + * + * May return a default value or a color with adjusted components. + * + * @param ctx the context + * @param index the index + */ + static Color get(ContextPtr ctx, Index index); - /** - * Require a color. - * - * If the color has any invalid component, raise a JavaScript error. - * - * @param ctx the context - * @param index the index - */ - static Color require(ContextPtr ctx, Index index); + /** + * Require a color. + * + * If the color has any invalid component, raise a JavaScript error. + * + * @param ctx the context + * @param index the index + */ + static Color require(ContextPtr ctx, Index index); - /** - * Like get, but return the default value only if the value at the given index is not an object or not a string, - * otherwise, adjust invalid values. - * - * @param ctx the context - * @param index the index - * @param def the default value - */ - static Color optional(ContextPtr ctx, Index index, Color def); + /** + * Like get, but return the default value only if the value at the given index is not an object or not a string, + * otherwise, adjust invalid values. + * + * @param ctx the context + * @param index the index + * @param def the default value + */ + static Color optional(ContextPtr ctx, Index index, Color def); - /** - * Push the color as object. - * - * @param ctx the context - * @param color the color - */ - static void push(ContextPtr ctx, const Color &color); + /** + * Push the color as object. + * + * @param ctx the context + * @param color the color + */ + static void push(ContextPtr ctx, const Color &color); - /** - * Put the color properties into the object at the top of the stack. - * - * @pre the top value must be an object - * @param ctx the context - * @param color the color - */ - static void put(ContextPtr ctx, const Color &color); + /** + * Put the color properties into the object at the top of the stack. + * + * @pre the top value must be an object + * @param ctx the context + * @param color the color + */ + static void put(ContextPtr ctx, const Color &color); }; } // !duk
--- a/libclient/malikania/js-font.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-font.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -26,57 +26,57 @@ duk::Ret constructor(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "font must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "font must be new-constructed"); + } - try { - auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); - auto id = duk::require<std::string>(ctx, 0); - auto size = duk::require<int>(ctx, 1); + try { + auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); + auto id = duk::require<std::string>(ctx, 0); + auto size = duk::require<int>(ctx, 1); - if (size < 0) { - duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d must not be negative", size); - } + if (size < 0) { + duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d must not be negative", size); + } - duk::construct(ctx, std::make_shared<Font>(loader->loadFont(id, static_cast<unsigned>(size)))); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + duk::construct(ctx, std::make_shared<Font>(loader->loadFont(id, static_cast<unsigned>(size)))); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret clip(duk::ContextPtr ctx) { - try { - duk::push(ctx, duk::self<std::shared_ptr<Font>>(ctx)->clip(duk::require<std::string>(ctx, 0))); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::push(ctx, duk::self<std::shared_ptr<Font>>(ctx)->clip(duk::require<std::string>(ctx, 0))); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 1; + return 1; } const duk::FunctionMap methods{ - { "clip", { clip, 1 } } + { "clip", { clip, 1 } } }; } // !namespace void loadMalikaniaFont(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 2}); - duk::push(ctx, duk::Object()); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Font"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 2}); + duk::push(ctx, duk::Object()); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Font"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-image.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-image.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,75 +29,75 @@ duk::Ret size(duk::ContextPtr ctx) { - try { - duk::push(ctx, duk::self<std::shared_ptr<Image>>(ctx)->size()); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::push(ctx, duk::self<std::shared_ptr<Image>>(ctx)->size()); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 1; + return 1; } duk::Ret draw(duk::ContextPtr ctx) { - try { - auto self = duk::self<std::shared_ptr<Image>>(ctx); - auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); + try { + auto self = duk::self<std::shared_ptr<Image>>(ctx); + auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); - if (duk::top(ctx) == 2) { - self->draw(*window, duk::get<Point>(ctx, 1)); - } else if (duk::top(ctx) == 3) { - self->draw(*window, duk::get<Rectangle>(ctx, 1), duk::get<Rectangle>(ctx, 2)); - } else { - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid number of arguments: #%d", duk::top(ctx)); - } - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + if (duk::top(ctx) == 2) { + self->draw(*window, duk::get<Point>(ctx, 1)); + } else if (duk::top(ctx) == 3) { + self->draw(*window, duk::get<Rectangle>(ctx, 1), duk::get<Rectangle>(ctx, 2)); + } else { + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid number of arguments: #%d", duk::top(ctx)); + } + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret constructor(duk::ContextPtr ctx) { - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "image must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "image must be new-constructed"); + } - try { - auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); - auto image = loader->loadImage(duk::require<std::string>(ctx, 0)); + try { + auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); + auto image = loader->loadImage(duk::require<std::string>(ctx, 0)); - duk::construct(ctx, std::make_shared<Image>(std::move(image))); - duk::push(ctx, duk::This()); - duk::push(ctx, "size"); - duk::push(ctx, duk::Function{size, 0}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - duk::pop(ctx); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + duk::construct(ctx, std::make_shared<Image>(std::move(image))); + duk::push(ctx, duk::This()); + duk::push(ctx, "size"); + duk::push(ctx, duk::Function{size, 0}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + duk::pop(ctx); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } const duk::FunctionMap methods{ - { "draw", { draw, DUK_VARARGS } } + { "draw", { draw, DUK_VARARGS } } }; } // !namespace void loadMalikaniaImage(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 1}); - duk::push(ctx, duk::Object()); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Image"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 1}); + duk::push(ctx, duk::Object()); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Image"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-line.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-line.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,34 +24,34 @@ duk::Ret constructor(duk::ContextPtr ctx) { - Line line; + Line line; - if (duk::top(ctx) == 4) { - line = Line( - duk::get<int>(ctx, 0), - duk::get<int>(ctx, 1), - duk::get<int>(ctx, 2), - duk::get<int>(ctx, 3) - ); - } else if (duk::top(ctx) == 1) { - line = duk::require<Line>(ctx, 0); - } + if (duk::top(ctx) == 4) { + line = Line( + duk::get<int>(ctx, 0), + duk::get<int>(ctx, 1), + duk::get<int>(ctx, 2), + duk::get<int>(ctx, 3) + ); + } else if (duk::top(ctx) == 1) { + line = duk::require<Line>(ctx, 0); + } - duk::Ret ret; + duk::Ret ret; - /* Allow both constructor and non constructor calls */ - if (duk_is_constructor_call(ctx)) { - duk::push(ctx, duk::This()); - /* TODO: use duk::put when available */ - duk::TypeTraits<Line>::put(ctx, line); - duk::pop(ctx); - ret = 0; - } else { - duk::push(ctx, line); - ret = 1; - } + /* Allow both constructor and non constructor calls */ + if (duk_is_constructor_call(ctx)) { + duk::push(ctx, duk::This()); + /* TODO: use duk::put when available */ + duk::TypeTraits<Line>::put(ctx, line); + duk::pop(ctx); + ret = 0; + } else { + duk::push(ctx, line); + ret = 1; + } - return ret; + return ret; } } // !namespace @@ -60,76 +60,76 @@ Line TypeTraits<Line>::get(ContextPtr ctx, Index index) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - return Line( - duk::getProperty<int>(ctx, index, "x1"), - duk::getProperty<int>(ctx, index, "y1"), - duk::getProperty<int>(ctx, index, "x2"), - duk::getProperty<int>(ctx, index, "y2") - ); + return Line( + duk::getProperty<int>(ctx, index, "x1"), + duk::getProperty<int>(ctx, index, "y1"), + duk::getProperty<int>(ctx, index, "x2"), + duk::getProperty<int>(ctx, index, "y2") + ); } Line TypeTraits<Line>::require(ContextPtr ctx, Index index) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - auto get = [&] (const std::string &property) -> int { - if (!duk::hasProperty(ctx, index, property)) { - duk::raise(ctx, DUK_ERR_ERROR, "missing %s property in line description", property.c_str()); - } + auto get = [&] (const std::string &property) -> int { + if (!duk::hasProperty(ctx, index, property)) { + duk::raise(ctx, DUK_ERR_ERROR, "missing %s property in line description", property.c_str()); + } - duk::getProperty<void>(ctx, index, property); + duk::getProperty<void>(ctx, index, property); - if (!duk::is<int>(ctx, -1)) { - duk::pop(ctx); - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "property %s is not an int", property.c_str()); - } + if (!duk::is<int>(ctx, -1)) { + duk::pop(ctx); + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "property %s is not an int", property.c_str()); + } - int value = duk::get<int>(ctx, -1); + int value = duk::get<int>(ctx, -1); - duk::pop(ctx); + duk::pop(ctx); - return value; - }; + return value; + }; - return Line(get("x1"), get("y1"), get("x2"), get("y2")); + return Line(get("x1"), get("y1"), get("x2"), get("y2")); } Line TypeTraits<Line>::optional(ContextPtr ctx, Index index, Line def) { - return duk::is<duk::Object>(ctx, index) ? get(ctx, index) : def; + return duk::is<duk::Object>(ctx, index) ? get(ctx, index) : def; } void TypeTraits<Line>::push(ContextPtr ctx, const Line &line) { - duk::StackAssert sa(ctx, 1); + duk::StackAssert sa(ctx, 1); - duk::push(ctx, duk::Object()); - duk::TypeTraits<Line>::put(ctx, line); + duk::push(ctx, duk::Object()); + duk::TypeTraits<Line>::put(ctx, line); } void TypeTraits<Line>::put(ContextPtr ctx, const Line &line) { - assert(duk::is<duk::Object>(ctx, -1)); + assert(duk::is<duk::Object>(ctx, -1)); - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::putProperty(ctx, -1, "x1", line.x1()); - duk::putProperty(ctx, -1, "y1", line.y1()); - duk::putProperty(ctx, -1, "x2", line.x2()); - duk::putProperty(ctx, -1, "y2", line.y2()); + duk::putProperty(ctx, -1, "x1", line.x1()); + duk::putProperty(ctx, -1, "y1", line.y1()); + duk::putProperty(ctx, -1, "x2", line.x2()); + duk::putProperty(ctx, -1, "y2", line.y2()); } } // !duk void loadMalikaniaLine(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx, 0); + duk::StackAssert sa(ctx, 0); - duk::getGlobal<void>(ctx, "Malikania"); - duk::putProperty(ctx, -1, "Line", duk::Function{constructor, DUK_VARARGS}); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::putProperty(ctx, -1, "Line", duk::Function{constructor, DUK_VARARGS}); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-line.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-line.h Thu Jun 16 13:35:31 2016 +0200 @@ -43,51 +43,51 @@ template <> class TypeTraits<Line> { public: - /** - * Get a line. - * - * @param ctx the context - * @param index the index - * @return the line - */ - static Line get(ContextPtr ctx, Index index); + /** + * Get a line. + * + * @param ctx the context + * @param index the index + * @return the line + */ + static Line get(ContextPtr ctx, Index index); - /** - * Require a line. - * - * If value is not an object or any property is invalid, raise a JavaScript error. - * - * @param ctx the context - * @param index the index - * @return the line - */ - static Line require(ContextPtr ctx, Index index); + /** + * Require a line. + * + * If value is not an object or any property is invalid, raise a JavaScript error. + * + * @param ctx the context + * @param index the index + * @return the line + */ + static Line require(ContextPtr ctx, Index index); - /** - * Like get but return def if the value at the given index is not an object. - * - * @param ctx the context - * @param index the index - * @param def the default value - * @return the line - */ - static Line optional(ContextPtr ctx, Index index, Line def); + /** + * Like get but return def if the value at the given index is not an object. + * + * @param ctx the context + * @param index the index + * @param def the default value + * @return the line + */ + static Line optional(ContextPtr ctx, Index index, Line def); - /** - * Push the line as object. - * - * @param ctx the context - * @param line the line - */ - static void push(ContextPtr ctx, const Line &line); + /** + * Push the line as object. + * + * @param ctx the context + * @param line the line + */ + static void push(ContextPtr ctx, const Line &line); - /** - * Put the line properties into the object at the top of the stack. - * - * @param ctx the context - * @param line the line - */ - static void put(ContextPtr ctx, const Line &line); + /** + * Put the line properties into the object at the top of the stack. + * + * @param ctx the context + * @param line the line + */ + static void put(ContextPtr ctx, const Line &line); }; } // !duk
--- a/libclient/malikania/js-point.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-point.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,48 +24,48 @@ Point parse(duk::ContextPtr ctx, duk::Index index, bool required, Point point = {}) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (duk::type(ctx, index) == DUK_TYPE_OBJECT){ - if (required && !duk::hasProperty(ctx, index, "x")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing x property in point description"); - } else if (required && !duk::hasProperty(ctx, index, "y")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing y property in point description"); - } + if (duk::type(ctx, index) == DUK_TYPE_OBJECT){ + if (required && !duk::hasProperty(ctx, index, "x")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing x property in point description"); + } else if (required && !duk::hasProperty(ctx, index, "y")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing y property in point description"); + } - point = Point(duk::getProperty<int>(ctx, index, "x"), duk::getProperty<int>(ctx, index, "y")); - } else if (required) { - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "point object expected"); - } + point = Point(duk::getProperty<int>(ctx, index, "x"), duk::getProperty<int>(ctx, index, "y")); + } else if (required) { + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "point object expected"); + } - return point; + return point; } duk::Ret constructor(duk::ContextPtr ctx) { - Point point; + Point point; - if (duk::top(ctx) == 2) { - point = Point(duk::require<int>(ctx, 0), duk::require<int>(ctx, 1)); - } else if (duk::top(ctx) == 1) { - point = parse(ctx, 0, true); - } + if (duk::top(ctx) == 2) { + point = Point(duk::require<int>(ctx, 0), duk::require<int>(ctx, 1)); + } else if (duk::top(ctx) == 1) { + point = parse(ctx, 0, true); + } - duk::Ret ret; + duk::Ret ret; - /* Allow both constructor and non constructor calls */ - if (duk_is_constructor_call(ctx)) { - duk::push(ctx, duk::This()); - /* TODO: use duk::put when available */ - duk::TypeTraits<Point>::put(ctx, point); - duk::pop(ctx); - ret = 0; - } else { - duk::push(ctx, point); - ret = 1; - } + /* Allow both constructor and non constructor calls */ + if (duk_is_constructor_call(ctx)) { + duk::push(ctx, duk::This()); + /* TODO: use duk::put when available */ + duk::TypeTraits<Point>::put(ctx, point); + duk::pop(ctx); + ret = 0; + } else { + duk::push(ctx, point); + ret = 1; + } - return ret; + return ret; } } // !namespace @@ -74,46 +74,46 @@ Point TypeTraits<Point>::get(ContextPtr ctx, Index index) { - return parse(ctx, index, false); + return parse(ctx, index, false); } Point TypeTraits<Point>::require(ContextPtr ctx, Index index) { - return parse(ctx, index, true); + return parse(ctx, index, true); } Point TypeTraits<Point>::optional(ContextPtr ctx, Index index, Point def) { - return parse(ctx, index, false, std::move(def)); + return parse(ctx, index, false, std::move(def)); } void TypeTraits<Point>::push(ContextPtr ctx, const Point &point) { - duk::StackAssert sa(ctx, 1); + duk::StackAssert sa(ctx, 1); - duk::push(ctx, duk::Object()); - duk::TypeTraits<Point>::put(ctx, point); + duk::push(ctx, duk::Object()); + duk::TypeTraits<Point>::put(ctx, point); } void TypeTraits<Point>::put(ContextPtr ctx, const Point &point) { - assert(duk::type(ctx, -1) == DUK_TYPE_OBJECT); + assert(duk::type(ctx, -1) == DUK_TYPE_OBJECT); - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::putProperty(ctx, -1, "x", point.x()); - duk::putProperty(ctx, -1, "y", point.y()); + duk::putProperty(ctx, -1, "x", point.x()); + duk::putProperty(ctx, -1, "y", point.y()); } } // !duk void loadMalikaniaPoint(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx, 0); + duk::StackAssert sa(ctx, 0); - duk::getGlobal<void>(ctx, "Malikania"); - duk::putProperty(ctx, -1, "Point", duk::Function{constructor, DUK_VARARGS}); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::putProperty(ctx, -1, "Point", duk::Function{constructor, DUK_VARARGS}); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-point.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-point.h Thu Jun 16 13:35:31 2016 +0200 @@ -29,15 +29,15 @@ template <> class TypeTraits<Point> { public: - static Point get(ContextPtr ctx, Index index); + static Point get(ContextPtr ctx, Index index); - static Point require(ContextPtr ctx, Index index); + static Point require(ContextPtr ctx, Index index); - static Point optional(ContextPtr ctx, Index index, Point def); + static Point optional(ContextPtr ctx, Index index, Point def); - static void push(ContextPtr ctx, const Point &point); + static void push(ContextPtr ctx, const Point &point); - static void put(ContextPtr ctx, const Point &point); + static void put(ContextPtr ctx, const Point &point); }; } // !duk
--- a/libclient/malikania/js-rectangle.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-rectangle.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,75 +24,75 @@ unsigned clamp(duk::ContextPtr ctx, int value, bool required) { - if (value < 0) { - if (required) { - duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d can not be negative", value); - } else { - value = 0; - } - } + if (value < 0) { + if (required) { + duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d can not be negative", value); + } else { + value = 0; + } + } - return static_cast<unsigned>(value); + return static_cast<unsigned>(value); } Rectangle parse(duk::ContextPtr ctx, duk::Index index, bool required, Rectangle rect = {}) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (duk::type(ctx, index) == DUK_TYPE_OBJECT) { - if (required && !duk::hasProperty(ctx, index, "x")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing x property in rectangle description"); - } else if (required && !duk::hasProperty(ctx, index, "y")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing y property in rectangle description"); - } else if (required && !duk::hasProperty(ctx, index, "width")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing width property in rectangle description"); - } else if (required && !duk::hasProperty(ctx, index, "height")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing height property in rectangle description"); - } + if (duk::type(ctx, index) == DUK_TYPE_OBJECT) { + if (required && !duk::hasProperty(ctx, index, "x")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing x property in rectangle description"); + } else if (required && !duk::hasProperty(ctx, index, "y")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing y property in rectangle description"); + } else if (required && !duk::hasProperty(ctx, index, "width")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing width property in rectangle description"); + } else if (required && !duk::hasProperty(ctx, index, "height")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing height property in rectangle description"); + } - rect = Rectangle( - duk::getProperty<int>(ctx, index, "x"), - duk::getProperty<int>(ctx, index, "y"), - clamp(ctx, duk::getProperty<int>(ctx, index, "width"), required), - clamp(ctx, duk::getProperty<int>(ctx, index, "height"), required) - ); - } else if (required) { - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "size object expected"); - } + rect = Rectangle( + duk::getProperty<int>(ctx, index, "x"), + duk::getProperty<int>(ctx, index, "y"), + clamp(ctx, duk::getProperty<int>(ctx, index, "width"), required), + clamp(ctx, duk::getProperty<int>(ctx, index, "height"), required) + ); + } else if (required) { + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "size object expected"); + } - return rect; + return rect; } duk::Ret constructor(duk::ContextPtr ctx) { - Rectangle rect; + Rectangle rect; - if (duk::top(ctx) == 4) { - rect = Rectangle( - duk::require<int>(ctx, 0), - duk::require<int>(ctx, 1), - clamp(ctx, duk::require<int>(ctx, 2), true), - clamp(ctx, duk::require<int>(ctx, 3), true) - ); - } else if (duk::top(ctx) == 1) { - rect = parse(ctx, 0, true); - } + if (duk::top(ctx) == 4) { + rect = Rectangle( + duk::require<int>(ctx, 0), + duk::require<int>(ctx, 1), + clamp(ctx, duk::require<int>(ctx, 2), true), + clamp(ctx, duk::require<int>(ctx, 3), true) + ); + } else if (duk::top(ctx) == 1) { + rect = parse(ctx, 0, true); + } - duk::Ret ret; + duk::Ret ret; - /* Allow both constructor and non constructor calls */ - if (duk_is_constructor_call(ctx)) { - duk::push(ctx, duk::This()); - /* TODO: use duk::put when available */ - duk::TypeTraits<Rectangle>::put(ctx, rect); - duk::pop(ctx); - ret = 0; - } else { - duk::push(ctx, rect); - ret = 1; - } + /* Allow both constructor and non constructor calls */ + if (duk_is_constructor_call(ctx)) { + duk::push(ctx, duk::This()); + /* TODO: use duk::put when available */ + duk::TypeTraits<Rectangle>::put(ctx, rect); + duk::pop(ctx); + ret = 0; + } else { + duk::push(ctx, rect); + ret = 1; + } - return ret; + return ret; } } // !namespace @@ -101,48 +101,48 @@ Rectangle TypeTraits<Rectangle>::get(ContextPtr ctx, Index index) { - return parse(ctx, index, false); + return parse(ctx, index, false); } Rectangle TypeTraits<Rectangle>::require(ContextPtr ctx, Index index) { - return parse(ctx, index, true); + return parse(ctx, index, true); } Rectangle TypeTraits<Rectangle>::optional(ContextPtr ctx, Index index, Rectangle def) { - return parse(ctx, index, false, std::move(def)); + return parse(ctx, index, false, std::move(def)); } void TypeTraits<Rectangle>::push(ContextPtr ctx, const Rectangle &rect) { - duk::StackAssert sa(ctx, 1); + duk::StackAssert sa(ctx, 1); - duk::push(ctx, duk::Object()); - duk::TypeTraits<Rectangle>::put(ctx, rect); + duk::push(ctx, duk::Object()); + duk::TypeTraits<Rectangle>::put(ctx, rect); } void TypeTraits<Rectangle>::put(ContextPtr ctx, const Rectangle &rect) { - assert(duk::type(ctx, -1) == DUK_TYPE_OBJECT); + assert(duk::type(ctx, -1) == DUK_TYPE_OBJECT); - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::putProperty(ctx, -1, "x", rect.x()); - duk::putProperty(ctx, -1, "y", rect.y()); - duk::putProperty(ctx, -1, "width", static_cast<int>(rect.width())); - duk::putProperty(ctx, -1, "height", static_cast<int>(rect.height())); + duk::putProperty(ctx, -1, "x", rect.x()); + duk::putProperty(ctx, -1, "y", rect.y()); + duk::putProperty(ctx, -1, "width", static_cast<int>(rect.width())); + duk::putProperty(ctx, -1, "height", static_cast<int>(rect.height())); } } // !duk void loadMalikaniaRectangle(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx, 0); + duk::StackAssert sa(ctx, 0); - duk::getGlobal<void>(ctx, "Malikania"); - duk::putProperty(ctx, -1, "Rectangle", duk::Function{constructor, DUK_VARARGS}); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::putProperty(ctx, -1, "Rectangle", duk::Function{constructor, DUK_VARARGS}); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-rectangle.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-rectangle.h Thu Jun 16 13:35:31 2016 +0200 @@ -43,54 +43,54 @@ template <> class TypeTraits<Rectangle> { public: - /** - * Get a rectangle. - * - * The rectangle may be adjusted if any values are incorrect. - * - * @param ctx the context - * @param index the value index - * @return the rectangle - */ - static Rectangle get(ContextPtr ctx, Index index); + /** + * Get a rectangle. + * + * The rectangle may be adjusted if any values are incorrect. + * + * @param ctx the context + * @param index the value index + * @return the rectangle + */ + static Rectangle get(ContextPtr ctx, Index index); - /** - * Require a rectangle. - * - * If the object is not a rectangle or if width, height are invalid, raise a JavaScript error. - * - * @param ctx the context - * @param index the index - * @return the rectangle - */ - static Rectangle require(ContextPtr ctx, Index index); + /** + * Require a rectangle. + * + * If the object is not a rectangle or if width, height are invalid, raise a JavaScript error. + * + * @param ctx the context + * @param index the index + * @return the rectangle + */ + static Rectangle require(ContextPtr ctx, Index index); - /** - * Like get but return the default value if the value at the given index is not an object or invalid - * - * @param ctx the context - * @param index the idnex - * @param def the default value - * @return the rectangle - */ - static Rectangle optional(ContextPtr ctx, Index index, Rectangle def); + /** + * Like get but return the default value if the value at the given index is not an object or invalid + * + * @param ctx the context + * @param index the idnex + * @param def the default value + * @return the rectangle + */ + static Rectangle optional(ContextPtr ctx, Index index, Rectangle def); - /** - * Push the rectangle as object. - * - * @param ctx the context - * @param rect the rectangle - */ - static void push(ContextPtr ctx, const Rectangle &rect); + /** + * Push the rectangle as object. + * + * @param ctx the context + * @param rect the rectangle + */ + static void push(ContextPtr ctx, const Rectangle &rect); - /** - * Put the rectangle properties into the object at the top of the stack. - * - * @param ctx the context - * @param rect the rectangle - */ - static void put(ContextPtr ctx, const Rectangle &rect); + /** + * Put the rectangle properties into the object at the top of the stack. + * + * @param ctx the context + * @param rect the rectangle + */ + static void put(ContextPtr ctx, const Rectangle &rect); }; } // !duk
--- a/libclient/malikania/js-size.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-size.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,67 +24,67 @@ unsigned clamp(duk::ContextPtr ctx, int value, bool required) { - if (value < 0) { - if (required) { - duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d can not be negative", value); - } else { - value = 0; - } - } + if (value < 0) { + if (required) { + duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d can not be negative", value); + } else { + value = 0; + } + } - return static_cast<unsigned>(value); + return static_cast<unsigned>(value); } Size parse(duk::ContextPtr ctx, duk::Index index, bool required, Size size = {}) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (duk::type(ctx, index) == DUK_TYPE_OBJECT) { - if (required && !duk::hasProperty(ctx, index, "width")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing width property in size description"); - } else if (required && !duk::hasProperty(ctx, index, "height")) { - duk::raise(ctx, DUK_ERR_ERROR, "missing height property in size description"); - } + if (duk::type(ctx, index) == DUK_TYPE_OBJECT) { + if (required && !duk::hasProperty(ctx, index, "width")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing width property in size description"); + } else if (required && !duk::hasProperty(ctx, index, "height")) { + duk::raise(ctx, DUK_ERR_ERROR, "missing height property in size description"); + } - size = Size( - clamp(ctx, duk::getProperty<int>(ctx, index, "width"), required), - clamp(ctx, duk::getProperty<int>(ctx, index, "height"), required) - ); - } else if (required) { - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "size object expected"); - } + size = Size( + clamp(ctx, duk::getProperty<int>(ctx, index, "width"), required), + clamp(ctx, duk::getProperty<int>(ctx, index, "height"), required) + ); + } else if (required) { + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "size object expected"); + } - return size; + return size; } duk::Ret constructor(duk::ContextPtr ctx) { - malikania::Size size; + malikania::Size size; - if (duk::top(ctx) == 2) { - size = malikania::Size( - clamp(ctx, duk::require<int>(ctx, 0), true), - clamp(ctx, duk::require<int>(ctx, 1), true) - ); - } else if (duk::top(ctx) == 1) { - size = parse(ctx, 0, true); - } + if (duk::top(ctx) == 2) { + size = malikania::Size( + clamp(ctx, duk::require<int>(ctx, 0), true), + clamp(ctx, duk::require<int>(ctx, 1), true) + ); + } else if (duk::top(ctx) == 1) { + size = parse(ctx, 0, true); + } - duk::Ret ret; + duk::Ret ret; - /* Allow both constructor and non constructor calls */ - if (duk_is_constructor_call(ctx)) { - duk::push(ctx, duk::This()); - /* TODO: use duk::put when available */ - duk::TypeTraits<malikania::Size>::put(ctx, size); - duk::pop(ctx); - ret = 0; - } else { - duk::push(ctx, size); - ret = 1; - } + /* Allow both constructor and non constructor calls */ + if (duk_is_constructor_call(ctx)) { + duk::push(ctx, duk::This()); + /* TODO: use duk::put when available */ + duk::TypeTraits<malikania::Size>::put(ctx, size); + duk::pop(ctx); + ret = 0; + } else { + duk::push(ctx, size); + ret = 1; + } - return ret; + return ret; } } // !namespace @@ -93,46 +93,46 @@ malikania::Size TypeTraits<malikania::Size>::get(ContextPtr ctx, Index index) { - return parse(ctx, index, false); + return parse(ctx, index, false); } malikania::Size TypeTraits<malikania::Size>::require(ContextPtr ctx, Index index) { - return parse(ctx, index, true); + return parse(ctx, index, true); } malikania::Size TypeTraits<malikania::Size>::optional(ContextPtr ctx, Index index, malikania::Size def) { - return parse(ctx, index, false, std::move(def)); + return parse(ctx, index, false, std::move(def)); } void TypeTraits<malikania::Size>::push(ContextPtr ctx, const malikania::Size &size) { - StackAssert sa(ctx, 1); + StackAssert sa(ctx, 1); - duk::push(ctx, duk::Object()); - duk::TypeTraits<malikania::Size>::put(ctx, size); + duk::push(ctx, duk::Object()); + duk::TypeTraits<malikania::Size>::put(ctx, size); } void TypeTraits<malikania::Size>::put(ContextPtr ctx, const malikania::Size &size) { - assert(type(ctx, -1) == DUK_TYPE_OBJECT); + assert(type(ctx, -1) == DUK_TYPE_OBJECT); - StackAssert sa(ctx, 0); + StackAssert sa(ctx, 0); - duk::putProperty(ctx, -1, "width", static_cast<int>(size.width())); - duk::putProperty(ctx, -1, "height", static_cast<int>(size.height())); + duk::putProperty(ctx, -1, "width", static_cast<int>(size.width())); + duk::putProperty(ctx, -1, "height", static_cast<int>(size.height())); } } // !duk void loadMalikaniaSize(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx, 0); + duk::StackAssert sa(ctx, 0); - duk::getGlobal<void>(ctx, "Malikania"); - duk::putProperty(ctx, -1, "Size", duk::Function{constructor, DUK_VARARGS}); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::putProperty(ctx, -1, "Size", duk::Function{constructor, DUK_VARARGS}); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-size.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-size.h Thu Jun 16 13:35:31 2016 +0200 @@ -41,53 +41,53 @@ template <> class TypeTraits<malikania::Size> { public: - /** - * Get a size. - * - * The size may be adjusted if any values are incorrect. - * - * @param ctx the context - * @param index the value index - * @return the size - */ - static malikania::Size get(ContextPtr ctx, Index index); + /** + * Get a size. + * + * The size may be adjusted if any values are incorrect. + * + * @param ctx the context + * @param index the value index + * @return the size + */ + static malikania::Size get(ContextPtr ctx, Index index); - /** - * Require a size - * - * If the object is not a size, raise a JavaScript error. - * - * @param ctx the context - * @param index the index - * @return the size - */ - static malikania::Size require(ContextPtr ctx, Index index); + /** + * Require a size + * + * If the object is not a size, raise a JavaScript error. + * + * @param ctx the context + * @param index the index + * @return the size + */ + static malikania::Size require(ContextPtr ctx, Index index); - /** - * Like get but return the default value if the value at the given index is not an object. - * - * @param ctx the context - * @param index the idnex - * @param def the default value - * @return the size - */ - static malikania::Size optional(ContextPtr ctx, Index index, malikania::Size def); + /** + * Like get but return the default value if the value at the given index is not an object. + * + * @param ctx the context + * @param index the idnex + * @param def the default value + * @return the size + */ + static malikania::Size optional(ContextPtr ctx, Index index, malikania::Size def); - /** - * Push the size as object. - * - * @param ctx the context - * @param size the size - */ - static void push(ContextPtr ctx, const malikania::Size &size); + /** + * Push the size as object. + * + * @param ctx the context + * @param size the size + */ + static void push(ContextPtr ctx, const malikania::Size &size); - /** - * Put the size properties into the object at the top of the stack. - * - * @param ctx the context - * @param size the size - */ - static void put(ContextPtr ctx, const malikania::Size &size); + /** + * Put the size properties into the object at the top of the stack. + * + * @param ctx the context + * @param size the size + */ + static void put(ContextPtr ctx, const malikania::Size &size); }; } // !duk
--- a/libclient/malikania/js-sprite.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-sprite.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -28,122 +28,122 @@ duk::Ret cell(duk::ContextPtr ctx) { - duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->cell()); + duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->cell()); - return 1; + return 1; } duk::Ret columns(duk::ContextPtr ctx) { - duk::push(ctx, static_cast<int>(duk::self<std::shared_ptr<Sprite>>(ctx)->columns())); + duk::push(ctx, static_cast<int>(duk::self<std::shared_ptr<Sprite>>(ctx)->columns())); - return 1; + return 1; } duk::Ret margins(duk::ContextPtr ctx) { - duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->margin()); + duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->margin()); - return 1; + return 1; } duk::Ret rows(duk::ContextPtr ctx) { - duk::push(ctx, static_cast<int>(duk::self<std::shared_ptr<Sprite>>(ctx)->rows())); + duk::push(ctx, static_cast<int>(duk::self<std::shared_ptr<Sprite>>(ctx)->rows())); - return 1; + return 1; } duk::Ret space(duk::ContextPtr ctx) { - duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->space()); + duk::push(ctx, duk::self<std::shared_ptr<Sprite>>(ctx)->space()); - return 1; + return 1; } duk::Ret constructor(duk::ContextPtr ctx) { - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "sprite must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "sprite must be new-constructed"); + } - try { - auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); - auto sprite = loader->loadSprite(duk::require<std::string>(ctx, 0)); + try { + auto loader = duk::getGlobal<ClientResourcesLoader *>(ctx, "\xff""\xff""loader"); + auto sprite = loader->loadSprite(duk::require<std::string>(ctx, 0)); - duk::construct(ctx, std::make_shared<Sprite>(std::move(sprite))); - duk::push(ctx, duk::This()); + duk::construct(ctx, std::make_shared<Sprite>(std::move(sprite))); + duk::push(ctx, duk::This()); - /* Cell */ - duk::push(ctx, "cell"); - duk::push(ctx, duk::Function{cell}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + /* Cell */ + duk::push(ctx, "cell"); + duk::push(ctx, duk::Function{cell}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - /* Columns */ - duk::push(ctx, "columns"); - duk::push(ctx, duk::Function{columns}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + /* Columns */ + duk::push(ctx, "columns"); + duk::push(ctx, duk::Function{columns}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - /* Margins */ - duk::push(ctx, "margins"); - duk::push(ctx, duk::Function{margins}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + /* Margins */ + duk::push(ctx, "margins"); + duk::push(ctx, duk::Function{margins}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - /* Rows */ - duk::push(ctx, "rows"); - duk::push(ctx, duk::Function{rows}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + /* Rows */ + duk::push(ctx, "rows"); + duk::push(ctx, duk::Function{rows}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - /* Space */ - duk::push(ctx, "space"); - duk::push(ctx, duk::Function{space}); - duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); + /* Space */ + duk::push(ctx, "space"); + duk::push(ctx, duk::Function{space}); + duk::defineProperty(ctx, -3, DUK_DEFPROP_HAVE_GETTER); - duk::pop(ctx); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + duk::pop(ctx); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret draw(duk::ContextPtr ctx) { - try { - auto self = duk::self<std::shared_ptr<Sprite>>(ctx); - auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); - auto cell = duk::require<int>(ctx, 1); - auto point = duk::get<Point>(ctx, 2); + try { + auto self = duk::self<std::shared_ptr<Sprite>>(ctx); + auto window = duk::get<std::shared_ptr<Window>>(ctx, 0); + auto cell = duk::require<int>(ctx, 1); + auto point = duk::get<Point>(ctx, 2); - if (cell < 0 || cell >= static_cast<int>(self->rows() * self->columns())) { - duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d is out of range", cell); - } + if (cell < 0 || cell >= static_cast<int>(self->rows() * self->columns())) { + duk::raise(ctx, DUK_ERR_RANGE_ERROR, "%d is out of range", cell); + } - self->draw(*window, static_cast<unsigned>(cell), point); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + self->draw(*window, static_cast<unsigned>(cell), point); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } const duk::FunctionMap methods{ - { "draw", { draw, 3 } } + { "draw", { draw, 3 } } }; } // !namespace void loadMalikaniaSprite(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 1}); - duk::push(ctx, duk::Object()); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Sprite"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 1}); + duk::push(ctx, duk::Object()); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Sprite"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-sprite.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-sprite.h Thu Jun 16 13:35:31 2016 +0200 @@ -32,41 +32,41 @@ template <> class TypeTraits<Sprite> { public: - /** - * Put the Sprite prototype to the top of the stack. - * - * @param ctx the context - */ - static void prototype(ContextPtr ctx) - { - duk::StackAssert sa(ctx, 1); + /** + * Put the Sprite prototype to the top of the stack. + * + * @param ctx the context + */ + static void prototype(ContextPtr ctx) + { + duk::StackAssert sa(ctx, 1); - duk::getGlobal<void>(ctx, "Malikania"); - duk::getGlobal<void>(ctx, "Sprite"); - duk::getProperty<void>(ctx, -1, "prototype"); - duk::remove(ctx, -2); - duk::remove(ctx, -2); - } + duk::getGlobal<void>(ctx, "Malikania"); + duk::getGlobal<void>(ctx, "Sprite"); + duk::getProperty<void>(ctx, -1, "prototype"); + duk::remove(ctx, -2); + duk::remove(ctx, -2); + } - /** - * Get the object signature. - * - * @return Sprite signature - */ - static inline std::string name() - { - return "\xff""\xff""Sprite"; - } + /** + * Get the object signature. + * + * @return Sprite signature + */ + static inline std::string name() + { + return "\xff""\xff""Sprite"; + } - /** - * Get inheritance list. - * - * @return empty - */ - static inline std::vector<std::string> inherits() - { - return {}; - } + /** + * Get inheritance list. + * + * @return empty + */ + static inline std::vector<std::string> inherits() + { + return {}; + } }; } // !duk
--- a/libclient/malikania/js-window.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-window.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,203 +29,203 @@ duk::Ret constructor(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - if (!duk_is_constructor_call(ctx)) { - duk::raise(ctx, DUK_ERR_ERROR, "window must be new-constructed"); - } + if (!duk_is_constructor_call(ctx)) { + duk::raise(ctx, DUK_ERR_ERROR, "window must be new-constructed"); + } - /* TODO: add parameters */ - try { - duk::construct(ctx, std::make_shared<Window>()); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + /* TODO: add parameters */ + try { + duk::construct(ctx, std::make_shared<Window>()); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret clear(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->clear(); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->clear(); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret present(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->present(); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->present(); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawingColor(duk::ContextPtr ctx) { - try { - duk::push(ctx, duk::self<std::shared_ptr<Window>>(ctx)->drawingColor()); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::push(ctx, duk::self<std::shared_ptr<Window>>(ctx)->drawingColor()); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 1; + return 1; } duk::Ret drawLine(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawLine(duk::require<Line>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawLine(duk::require<Line>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawLines(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawLines(duk::get<std::vector<Point>>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawLines(duk::get<std::vector<Point>>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawPoint(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawPoint(duk::require<Point>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawPoint(duk::require<Point>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawPoints(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawPoints(duk::get<std::vector<Point>>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawPoints(duk::get<std::vector<Point>>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawRectangle(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawRectangle(duk::require<Rectangle>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawRectangle(duk::require<Rectangle>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawRectangles(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->drawRectangles(duk::get<std::vector<Rectangle>>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->drawRectangles(duk::get<std::vector<Rectangle>>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret drawText(duk::ContextPtr ctx) { - try { - auto self = duk::self<std::shared_ptr<Window>>(ctx); - auto text = duk::require<std::string>(ctx, 0); - auto font = duk::get<std::shared_ptr<Font>>(ctx, 1); - auto rect = duk::get<Rectangle>(ctx, 2); + try { + auto self = duk::self<std::shared_ptr<Window>>(ctx); + auto text = duk::require<std::string>(ctx, 0); + auto font = duk::get<std::shared_ptr<Font>>(ctx, 1); + auto rect = duk::get<Rectangle>(ctx, 2); - if (!rect.isNull()) { - self->drawText(text, *font, rect); - } else { - self->drawText(text, *font, Point(rect.x(), rect.y())); - } - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + if (!rect.isNull()) { + self->drawText(text, *font, rect); + } else { + self->drawText(text, *font, Point(rect.x(), rect.y())); + } + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret fillRectangle(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->fillRectangle(duk::require<Rectangle>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->fillRectangle(duk::require<Rectangle>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret fillRectangles(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->fillRectangles(duk::get<std::vector<Rectangle>>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->fillRectangles(duk::get<std::vector<Rectangle>>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } duk::Ret setDrawingColor(duk::ContextPtr ctx) { - try { - duk::self<std::shared_ptr<Window>>(ctx)->setDrawingColor(duk::require<Color>(ctx, 0)); - } catch (const std::exception &ex) { - duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); - } + try { + duk::self<std::shared_ptr<Window>>(ctx)->setDrawingColor(duk::require<Color>(ctx, 0)); + } catch (const std::exception &ex) { + duk::raise(ctx, DUK_ERR_ERROR, "%s", ex.what()); + } - return 0; + return 0; } const duk::FunctionMap methods{ - { "clear", { clear, 0 } }, - { "drawingColor", { drawingColor, 0 } }, - { "drawLine", { drawLine, 1 } }, - { "drawLines", { drawLines, 1 } }, - { "drawPoint", { drawPoint, 1 } }, - { "drawPoints", { drawPoints, 1 } }, - { "drawRectangle", { drawRectangle, 1 } }, - { "drawRectangles", { drawRectangles, 1 } }, - { "drawText", { drawText, 3 } }, - { "fillRectangle", { fillRectangle, 1 } }, - { "fillRectangles", { fillRectangles, 1 } }, - { "present", { present, 0 } }, - { "setDrawingColor", { setDrawingColor, 1 } } + { "clear", { clear, 0 } }, + { "drawingColor", { drawingColor, 0 } }, + { "drawLine", { drawLine, 1 } }, + { "drawLines", { drawLines, 1 } }, + { "drawPoint", { drawPoint, 1 } }, + { "drawPoints", { drawPoints, 1 } }, + { "drawRectangle", { drawRectangle, 1 } }, + { "drawRectangles", { drawRectangles, 1 } }, + { "drawText", { drawText, 3 } }, + { "fillRectangle", { fillRectangle, 1 } }, + { "fillRectangles", { fillRectangles, 1 } }, + { "present", { present, 0 } }, + { "setDrawingColor", { setDrawingColor, 1 } } }; } // !namespace void loadMalikaniaWindow(duk::ContextPtr ctx) { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor}); - duk::push(ctx, duk::Object()); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "Window"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor}); + duk::push(ctx, duk::Object()); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "Window"); + duk::pop(ctx); } } // !malikania
--- a/libclient/malikania/js-window.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/js-window.h Thu Jun 16 13:35:31 2016 +0200 @@ -32,21 +32,21 @@ template <> class TypeTraits<Window> { public: - /** - * Put the Window prototype to the top of the stack. - * - * @param ctx the context - */ - static void prototype(duk::ContextPtr ctx) - { - duk::StackAssert sa(ctx, 1); + /** + * Put the Window prototype to the top of the stack. + * + * @param ctx the context + */ + static void prototype(duk::ContextPtr ctx) + { + duk::StackAssert sa(ctx, 1); - duk::getGlobal<void>(ctx, "Malikania"); - duk::getProperty<void>(ctx, -1, "Window"); - duk::getProperty<void>(ctx, -1, "prototype"); - duk::remove(ctx, -2); - duk::remove(ctx, -2); - } + duk::getGlobal<void>(ctx, "Malikania"); + duk::getProperty<void>(ctx, -1, "Window"); + duk::getProperty<void>(ctx, -1, "prototype"); + duk::remove(ctx, -2); + duk::remove(ctx, -2); + } }; } // !duk
--- a/libclient/malikania/label.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/label.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -21,18 +21,18 @@ namespace malikania { Label::Label(std::string text, std::shared_ptr<Font> font, Rectangle frame, Color textColor, Color backgroundColor) - : m_text(std::move(text)) - , m_font(std::move(font)) - , m_frame(std::move(frame)) - , m_textColor(std::move(textColor)) - , m_backgroundColor(std::move(backgroundColor)) + : m_text(std::move(text)) + , m_font(std::move(font)) + , m_frame(std::move(frame)) + , m_textColor(std::move(textColor)) + , m_backgroundColor(std::move(backgroundColor)) { } int Label::fontSize() const noexcept { - // TODO - return 12; + // TODO + return 12; } void Label::draw(Window &, const Rectangle &)
--- a/libclient/malikania/label.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/label.h Thu Jun 16 13:35:31 2016 +0200 @@ -30,38 +30,38 @@ class Label { private: - std::string m_text; - std::shared_ptr<Font> m_font; - Rectangle m_frame; - Color m_textColor; - Color m_backgroundColor; + std::string m_text; + std::shared_ptr<Font> m_font; + Rectangle m_frame; + Color m_textColor; + Color m_backgroundColor; public: - Label(std::string text, std::shared_ptr<Font> font, Rectangle frame, Color textColor = {0, 0, 0, 255}, Color backgroundColor = {255, 255, 255, 0}); + Label(std::string text, std::shared_ptr<Font> font, Rectangle frame, Color textColor = {0, 0, 0, 255}, Color backgroundColor = {255, 255, 255, 0}); - inline const std::string text() const noexcept - { - return m_text; - } + inline const std::string text() const noexcept + { + return m_text; + } - inline std::string text() noexcept - { - return m_text; - } + inline std::string text() noexcept + { + return m_text; + } - inline const std::shared_ptr<Font> &font() const noexcept - { - return m_font; - } + inline const std::shared_ptr<Font> &font() const noexcept + { + return m_font; + } - inline std::shared_ptr<Font> &font() noexcept - { - return m_font; - } + inline std::shared_ptr<Font> &font() noexcept + { + return m_font; + } - int fontSize() const noexcept; + int fontSize() const noexcept; - void draw(Window &window, const Rectangle &rectangle); + void draw(Window &window, const Rectangle &rectangle); }; }// !malikania
--- a/libclient/malikania/line.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/line.h Thu Jun 16 13:35:31 2016 +0200 @@ -34,67 +34,67 @@ */ class Line { private: - int m_x1; - int m_y1; - int m_x2; - int m_y2; + int m_x1; + int m_y1; + int m_x2; + int m_y2; public: - /** - * Construct a line. - * - * @param x1 the first x - * @param y1 the first y - * @param x2 the second x - * @param y2 the second y - */ - inline Line(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0) noexcept - : m_x1(x1) - , m_y1(y1) - , m_x2(x2) - , m_y2(y2) - { - } + /** + * Construct a line. + * + * @param x1 the first x + * @param y1 the first y + * @param x2 the second x + * @param y2 the second y + */ + inline Line(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0) noexcept + : m_x1(x1) + , m_y1(y1) + , m_x2(x2) + , m_y2(y2) + { + } - /** - * Get the first x. - * - * @return the x1 - */ - inline int x1() const noexcept - { - return m_x1; - } + /** + * Get the first x. + * + * @return the x1 + */ + inline int x1() const noexcept + { + return m_x1; + } - /** - * Get the first y. - * - * @return the y1 - */ - inline int y1() const noexcept - { - return m_y1; - } + /** + * Get the first y. + * + * @return the y1 + */ + inline int y1() const noexcept + { + return m_y1; + } - /** - * Get the second x. - * - * @return the x2 - */ - inline int x2() const noexcept - { - return m_x2; - } + /** + * Get the second x. + * + * @return the x2 + */ + inline int x2() const noexcept + { + return m_x2; + } - /** - * Get the second y. - * - * @return the y2 - */ - inline int y2() const noexcept - { - return m_y2; - } + /** + * Get the second y. + * + * @return the y2 + */ + inline int y2() const noexcept + { + return m_y2; + } }; /** @@ -106,7 +106,7 @@ */ inline bool operator==(const Line &l1, const Line &l2) noexcept { - return l1.x1() == l2.x1() && l1.x2() == l2.x2() && l1.y1() == l2.y1() && l1.y2() == l2.y2(); + return l1.x1() == l2.x1() && l1.x2() == l2.x2() && l1.y1() == l2.y1() && l1.y2() == l2.y2(); } /** @@ -118,7 +118,7 @@ */ inline bool operator!=(const Line &l1, const Line &l2) noexcept { - return !(l1 == l2); + return !(l1 == l2); } } // !malikania
--- a/libclient/malikania/point.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/point.h Thu Jun 16 13:35:31 2016 +0200 @@ -32,41 +32,41 @@ */ class Point { private: - int m_x; - int m_y; + int m_x; + int m_y; public: - /** - * Construct a point. - * - * @param x the x - * @param y the y - */ - inline Point(int x = 0, int y = 0) noexcept - : m_x(x) - , m_y(y) - { - } + /** + * Construct a point. + * + * @param x the x + * @param y the y + */ + inline Point(int x = 0, int y = 0) noexcept + : m_x(x) + , m_y(y) + { + } - /** - * Get the x position. - * - * @return the x - */ - inline int x() const noexcept - { - return m_x; - } + /** + * Get the x position. + * + * @return the x + */ + inline int x() const noexcept + { + return m_x; + } - /** - * Get the y position. - * - * @return the y - */ - inline int y() const noexcept - { - return m_y; - } + /** + * Get the y position. + * + * @return the y + */ + inline int y() const noexcept + { + return m_y; + } }; /** @@ -78,7 +78,7 @@ */ inline bool operator==(const Point &p1, const Point &p2) noexcept { - return p1.x() == p2.x() && p1.y() == p2.y(); + return p1.x() == p2.x() && p1.y() == p2.y(); } /** @@ -90,7 +90,7 @@ */ inline bool operator!=(const Point &p1, const Point &p2) noexcept { - return !(p1 == p2); + return !(p1 == p2); } } // !malikania
--- a/libclient/malikania/rectangle.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/rectangle.h Thu Jun 16 13:35:31 2016 +0200 @@ -36,77 +36,77 @@ */ class Rectangle { private: - int m_x; - int m_y; - unsigned m_width; - unsigned m_height; + int m_x; + int m_y; + unsigned m_width; + unsigned m_height; public: - /** - * Construct a rectangle. - * - * @param x the x position - * @param y the y position - * @param width the width - * @param height the height - */ - inline Rectangle(int x = 0, int y = 0, unsigned width = 0, unsigned height = 0) noexcept - : m_x(x) - , m_y(y) - , m_width(width) - , m_height(height) - { - } + /** + * Construct a rectangle. + * + * @param x the x position + * @param y the y position + * @param width the width + * @param height the height + */ + inline Rectangle(int x = 0, int y = 0, unsigned width = 0, unsigned height = 0) noexcept + : m_x(x) + , m_y(y) + , m_width(width) + , m_height(height) + { + } - /** - * Get the x position. - * - * @return the x position - */ - inline int x() const noexcept - { - return m_x; - } + /** + * Get the x position. + * + * @return the x position + */ + inline int x() const noexcept + { + return m_x; + } - /** - * Get the y position. - * - * @return the y position - */ - inline int y() const noexcept - { - return m_y; - } + /** + * Get the y position. + * + * @return the y position + */ + inline int y() const noexcept + { + return m_y; + } - /** - * Get the rectangle width. - * - * @return the width - */ - inline unsigned width() const noexcept - { - return m_width; - } + /** + * Get the rectangle width. + * + * @return the width + */ + inline unsigned width() const noexcept + { + return m_width; + } - /** - * Get the rectangle height. - * - * @return the height - */ - inline unsigned height() const noexcept - { - return m_height; - } + /** + * Get the rectangle height. + * + * @return the height + */ + inline unsigned height() const noexcept + { + return m_height; + } - /** - * Check if the rectangle has null dimensions. - * - * @return true if weight and height are 0 - */ - inline bool isNull() const noexcept - { - return m_width == 0 && m_height == 0; - } + /** + * Check if the rectangle has null dimensions. + * + * @return true if weight and height are 0 + */ + inline bool isNull() const noexcept + { + return m_width == 0 && m_height == 0; + } }; /** @@ -118,7 +118,7 @@ */ inline bool operator==(const Rectangle &r1, const Rectangle &r2) noexcept { - return r1.x() == r2.x() && r1.y() == r2.y() && r1.width() == r2.width() && r1.height() == r2.height(); + return r1.x() == r2.x() && r1.y() == r2.y() && r1.width() == r2.width() && r1.height() == r2.height(); } /** @@ -130,7 +130,7 @@ */ inline bool operator!=(const Rectangle &r1, const Rectangle &r2) noexcept { - return !(r1 == r2); + return !(r1 == r2); } } // !malikania
--- a/libclient/malikania/size.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/size.h Thu Jun 16 13:35:31 2016 +0200 @@ -27,51 +27,51 @@ */ class Size { private: - unsigned m_width; - unsigned m_height; + unsigned m_width; + unsigned m_height; public: - /** - * Constructor. - * - * @param width the size width - * @param height the size height - */ - inline Size(unsigned width = 0, unsigned height = 0) noexcept - : m_width(width) - , m_height(height) - { - } + /** + * Constructor. + * + * @param width the size width + * @param height the size height + */ + inline Size(unsigned width = 0, unsigned height = 0) noexcept + : m_width(width) + , m_height(height) + { + } - /** - * Get the width. - * - * @return the width - */ - inline unsigned width() const noexcept - { - return m_width; - } + /** + * Get the width. + * + * @return the width + */ + inline unsigned width() const noexcept + { + return m_width; + } - /** - * Get the height. - * - * @return the height - */ - inline unsigned height() const noexcept - { - return m_height; - } + /** + * Get the height. + * + * @return the height + */ + inline unsigned height() const noexcept + { + return m_height; + } - /** - * Check if the size is 0, 0. - * - * @return true if height and width are 0 - */ - inline bool isNull() const noexcept - { - return m_height == 0 && m_width == 0; - } + /** + * Check if the size is 0, 0. + * + * @return true if height and width are 0 + */ + inline bool isNull() const noexcept + { + return m_height == 0 && m_width == 0; + } }; /** @@ -83,7 +83,7 @@ */ inline bool operator==(const Size &s1, const Size &s2) noexcept { - return s1.width() == s2.width() && s1.height() == s2.height(); + return s1.width() == s2.width() && s1.height() == s2.height(); } /** @@ -95,7 +95,7 @@ */ inline bool operator!=(const Size &s1, const Size &s2) noexcept { - return !(s1 == s2); + return !(s1 == s2); } } // !malikania
--- a/libclient/malikania/sprite.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/sprite.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -21,41 +21,41 @@ namespace malikania { Sprite::Sprite(Image image, Size cell, Size size, Size space, Size margin) noexcept - : m_image(std::move(image)) - , m_cell(std::move(cell)) - , m_margin(std::move(margin)) - , m_space(std::move(space)) - , m_size(std::move(size)) + : m_image(std::move(image)) + , m_cell(std::move(cell)) + , m_margin(std::move(margin)) + , m_space(std::move(space)) + , m_size(std::move(size)) { - assert(m_cell.width() > 0); - assert(m_cell.height() > 0); + assert(m_cell.width() > 0); + assert(m_cell.height() > 0); - /* If size is not specified, take from image */ - if (m_size.isNull()) { - m_size = m_image.size(); - } + /* If size is not specified, take from image */ + if (m_size.isNull()) { + m_size = m_image.size(); + } - /* Compute number of cells */ - m_rows = (m_size.height() - (margin.height() * 2) + m_space.height()) / (m_cell.height() + m_space.height()); - m_columns = (m_size.width() - (m_margin.width() * 2) + m_space.width()) / (m_cell.width() + m_space.width()); + /* Compute number of cells */ + m_rows = (m_size.height() - (margin.height() * 2) + m_space.height()) / (m_cell.height() + m_space.height()); + m_columns = (m_size.width() - (m_margin.width() * 2) + m_space.width()) / (m_cell.width() + m_space.width()); } void Sprite::draw(Window &window, unsigned cell, const Point &point) { - assert(cell < m_rows * m_columns); + assert(cell < m_rows * m_columns); - /* Compute index in the grid */ - unsigned hindex = (cell % m_columns); - unsigned vindex = (cell / m_columns); + /* Compute index in the grid */ + unsigned hindex = (cell % m_columns); + unsigned vindex = (cell / m_columns); - /* Compute the pixel boundaries */ - int x = m_margin.width() + (hindex * m_space.width()) + (hindex * m_cell.width()); - int y = m_margin.height() + (vindex * m_space.height()) + (vindex * m_cell.height()); + /* Compute the pixel boundaries */ + int x = m_margin.width() + (hindex * m_space.width()) + (hindex * m_cell.width()); + int y = m_margin.height() + (vindex * m_space.height()) + (vindex * m_cell.height()); - Rectangle source(x, y, m_cell.width(), m_cell.height()); - Rectangle target(point.x(), point.y(), m_cell.width(), m_cell.height()); + Rectangle source(x, y, m_cell.width(), m_cell.height()); + Rectangle target(point.x(), point.y(), m_cell.width(), m_cell.height()); - m_image.draw(window, source, target); + m_image.draw(window, source, target); } } // !malikania
--- a/libclient/malikania/sprite.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/sprite.h Thu Jun 16 13:35:31 2016 +0200 @@ -40,106 +40,106 @@ */ class Sprite : public duk::Bindable { private: - Image m_image; - Size m_cell; - Size m_margin; - Size m_space; - Size m_size; - unsigned m_rows; - unsigned m_columns; + Image m_image; + Size m_cell; + Size m_margin; + Size m_space; + Size m_size; + unsigned m_rows; + unsigned m_columns; public: - /** - * Construct a sprite. - * - * @pre cell must not have height or width null - * @param image the image to use - * @param cell size of cell in the image - * @param margin the optional space from borders - * @param space the optional space between cells - * @param size the sprite size (if 0, taken from the image) - */ - Sprite(Image image, Size cell, Size margin = { 0, 0 }, Size space = { 0, 0 }, Size size = { 0, 0 }) noexcept; + /** + * Construct a sprite. + * + * @pre cell must not have height or width null + * @param image the image to use + * @param cell size of cell in the image + * @param margin the optional space from borders + * @param space the optional space between cells + * @param size the sprite size (if 0, taken from the image) + */ + Sprite(Image image, Size cell, Size margin = { 0, 0 }, Size space = { 0, 0 }, Size size = { 0, 0 }) noexcept; - /** - * Get the underlying image. - * - * @return the image - */ - inline const Image &image() const noexcept - { - return m_image; - } + /** + * Get the underlying image. + * + * @return the image + */ + inline const Image &image() const noexcept + { + return m_image; + } - /** - * Overloaded function. - * - * @return the image - */ - inline Image &image() noexcept - { - return m_image; - } + /** + * Overloaded function. + * + * @return the image + */ + inline Image &image() noexcept + { + return m_image; + } - /** - * Get the cell size. - * - * @return the cell size - */ - inline const Size &cell() const noexcept - { - return m_cell; - } + /** + * Get the cell size. + * + * @return the cell size + */ + inline const Size &cell() const noexcept + { + return m_cell; + } - /** - * Get the margin size. - * - * @return the margin size - */ - inline const Size &margin() noexcept - { - return m_margin; - } + /** + * Get the margin size. + * + * @return the margin size + */ + inline const Size &margin() noexcept + { + return m_margin; + } - /** - * Get the space size. - * - * @return the space size - */ - inline const Size &space() const noexcept - { - return m_space; - } + /** + * Get the space size. + * + * @return the space size + */ + inline const Size &space() const noexcept + { + return m_space; + } - /** - * Get the number of rows in the grid. - * - * @return the number of rows - */ - inline unsigned rows() const noexcept - { - return m_rows; - } + /** + * Get the number of rows in the grid. + * + * @return the number of rows + */ + inline unsigned rows() const noexcept + { + return m_rows; + } - /** - * Get the number of columns in the grid. - * - * @return the number of columns - */ - inline unsigned columns() const noexcept - { - return m_columns; - } + /** + * Get the number of columns in the grid. + * + * @return the number of columns + */ + inline unsigned columns() const noexcept + { + return m_columns; + } - /** - * Draw the sprite into the window at the specified position. - * - * @pre cell < rows() * columns() - * @param window the window - * @param cell the cell index - * @param position the position in the window - */ - void draw(Window &window, unsigned cell, const Point &position); + /** + * Draw the sprite into the window at the specified position. + * + * @pre cell < rows() * columns() + * @param window the window + * @param cell the cell index + * @param position the position in the window + */ + void draw(Window &window, unsigned cell, const Point &position); }; } // !malikania
--- a/libclient/malikania/window.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/window.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,7 +24,7 @@ namespace malikania { Window::Window(unsigned width, unsigned height, const std::string &title) - : m_backend(std::make_unique<Backend>(*this, width, height, title)) + : m_backend(std::make_unique<Backend>(*this, width, height, title)) { } @@ -34,83 +34,83 @@ void Window::poll() { - m_backend->poll(*this); + m_backend->poll(*this); } void Window::clear() { - m_backend->clear(); + m_backend->clear(); } void Window::present() { - m_backend->present(); + m_backend->present(); } void Window::close() noexcept { - m_isOpen = false; - m_backend->close(); + m_isOpen = false; + m_backend->close(); } Color Window::drawingColor() const { - return m_backend->drawingColor(); + return m_backend->drawingColor(); } void Window::setDrawingColor(const Color &color) { - m_backend->setDrawingColor(color); + m_backend->setDrawingColor(color); } void Window::drawLine(const Line &line) { - m_backend->drawLine(line); + m_backend->drawLine(line); } void Window::drawLines(const std::vector<Point> &points) { - m_backend->drawLines(points); + m_backend->drawLines(points); } void Window::drawPoint(const Point &point) { - m_backend->drawPoint(point); + m_backend->drawPoint(point); } void Window::drawPoints(const std::vector<Point> &points) { - m_backend->drawPoints(points); + m_backend->drawPoints(points); } void Window::drawRectangle(const Rectangle &rectangle) { - m_backend->drawRectangle(rectangle); + m_backend->drawRectangle(rectangle); } void Window::drawRectangles(const std::vector<Rectangle> &rectangles) { - m_backend->drawRectangles(rectangles); + m_backend->drawRectangles(rectangles); } void Window::fillRectangle(const Rectangle &rectangle) { - m_backend->fillRectangle(rectangle); + m_backend->fillRectangle(rectangle); } void Window::fillRectangles(const std::vector<Rectangle> &rectangles) { - m_backend->fillRectangles(rectangles); + m_backend->fillRectangles(rectangles); } void Window::drawText(const std::string &text, Font &font, const Rectangle &rectangle) { - m_backend->drawText(text, font, rectangle); + m_backend->drawText(text, font, rectangle); } void Window::drawText(const std::string &text, Font &font, const Point &point) { - m_backend->drawText(text, font, point); + m_backend->drawText(text, font, point); } Window &Window::operator=(Window &&) = default;
--- a/libclient/malikania/window.h Thu May 26 07:32:05 2016 +0200 +++ b/libclient/malikania/window.h Thu Jun 16 13:35:31 2016 +0200 @@ -44,225 +44,225 @@ */ class Window : public duk::Bindable { private: - class Backend; + class Backend; - std::function<void ()> m_onQuit; - std::function<void (unsigned)> m_onKeyDown; - std::function<void (unsigned)> m_onKeyUp; + std::function<void ()> m_onQuit; + std::function<void (unsigned)> m_onKeyDown; + std::function<void (unsigned)> m_onKeyUp; - std::unique_ptr<Backend> m_backend; + std::unique_ptr<Backend> m_backend; - bool m_isOpen{true}; + bool m_isOpen{true}; public: - inline void onQuit() - { - if (m_onQuit) { - m_onQuit(); - } - } + inline void onQuit() + { + if (m_onQuit) { + m_onQuit(); + } + } - inline void onKeyDown(unsigned key) - { - if (m_onKeyDown) { - m_onKeyDown(key); - } - } + inline void onKeyDown(unsigned key) + { + if (m_onKeyDown) { + m_onKeyDown(key); + } + } - inline void onKeyUp(unsigned key) - { - if (m_onKeyUp) { - m_onKeyUp(key); - } - } + inline void onKeyUp(unsigned key) + { + if (m_onKeyUp) { + m_onKeyUp(key); + } + } - inline void setOnQuit(std::function<void ()> fn) noexcept - { - m_onQuit = std::move(fn); - } + inline void setOnQuit(std::function<void ()> fn) noexcept + { + m_onQuit = std::move(fn); + } - inline void setOnKeyDown(std::function<void (unsigned)> fn) noexcept - { - m_onKeyDown = std::move(fn); - } + inline void setOnKeyDown(std::function<void (unsigned)> fn) noexcept + { + m_onKeyDown = std::move(fn); + } - inline void setOnKeyUp(std::function<void (unsigned)> fn) noexcept - { - m_onKeyUp = std::move(fn); - } + inline void setOnKeyUp(std::function<void (unsigned)> fn) noexcept + { + m_onKeyUp = std::move(fn); + } - /** - * Create a window. - * - * @param width the initial width - * @param height the initial height - * @param title the optional title - * @throw std::runtime_error on errors - */ - Window(unsigned width = 640, unsigned height = 480, const std::string &title = "Malikania"); + /** + * Create a window. + * + * @param width the initial width + * @param height the initial height + * @param title the optional title + * @throw std::runtime_error on errors + */ + Window(unsigned width = 640, unsigned height = 480, const std::string &title = "Malikania"); - /** - * Move constructor defaulted. - */ - Window(Window &&); + /** + * Move constructor defaulted. + */ + Window(Window &&); - /** - * Virtual destructor defaulted. - */ - virtual ~Window(); + /** + * Virtual destructor defaulted. + */ + virtual ~Window(); - /** - * Tells if the window is open. - * - * @return true if open - */ - inline bool isOpen() const noexcept - { - return m_isOpen; - } + /** + * Tells if the window is open. + * + * @return true if open + */ + inline bool isOpen() const noexcept + { + return m_isOpen; + } - /** - * Get the underlying backend. - * - * @return the backend - */ - inline const Backend &backend() const noexcept - { - return *m_backend; - } + /** + * Get the underlying backend. + * + * @return the backend + */ + inline const Backend &backend() const noexcept + { + return *m_backend; + } - /** - * Overloaded function. - * - * @return the backend - */ - inline Backend &backend() noexcept - { - return *m_backend; - } + /** + * Overloaded function. + * + * @return the backend + */ + inline Backend &backend() noexcept + { + return *m_backend; + } - /** - * Poll pending events. - */ - void poll(); + /** + * Poll pending events. + */ + void poll(); - /** - * Clear the window content with the current drawing color. - */ - void clear(); + /** + * Clear the window content with the current drawing color. + */ + void clear(); - /** - * Render the content of the window to the screen. - */ - void present(); + /** + * Render the content of the window to the screen. + */ + void present(); - /** - * Close the window. - */ - void close() noexcept; + /** + * Close the window. + */ + void close() noexcept; - /** - * Get the current drawing color. - * - * @return the color - */ - Color drawingColor() const; + /** + * Get the current drawing color. + * + * @return the color + */ + Color drawingColor() const; - /** - * Set the drawing color. - * - * @param color the color - */ - void setDrawingColor(const Color &color); + /** + * Set the drawing color. + * + * @param color the color + */ + void setDrawingColor(const Color &color); - /** - * Draw a line. - * - * @param line the line - */ - void drawLine(const Line &line); + /** + * Draw a line. + * + * @param line the line + */ + void drawLine(const Line &line); - /** - * Draw a several lines. - * - * @param the lines vertices - */ - void drawLines(const std::vector<Point> &points); + /** + * Draw a several lines. + * + * @param the lines vertices + */ + void drawLines(const std::vector<Point> &points); - /** - * Draw a point. - * - * @param point the point - */ - void drawPoint(const Point &point); + /** + * Draw a point. + * + * @param point the point + */ + void drawPoint(const Point &point); - /** - * Draw a list of points. - * - * @param points the points - */ - void drawPoints(const std::vector<Point> &points); + /** + * Draw a list of points. + * + * @param points the points + */ + void drawPoints(const std::vector<Point> &points); - /** - * Draw a rectangle (only borders). - * - * @param rect the rectangle - * @see fillRectangle - */ - void drawRectangle(const Rectangle &rect); + /** + * Draw a rectangle (only borders). + * + * @param rect the rectangle + * @see fillRectangle + */ + void drawRectangle(const Rectangle &rect); - /** - * Draw a list of rectangles. - * - * @param rects the rectangles - * @see fillRectangles - */ - void drawRectangles(const std::vector<Rectangle> &rects); + /** + * Draw a list of rectangles. + * + * @param rects the rectangles + * @see fillRectangles + */ + void drawRectangles(const std::vector<Rectangle> &rects); - /** - * Fill the given rectangle with the current color. - * - * @param rect the rectangle - * @see drawRectangle - */ - void fillRectangle(const Rectangle &rect); + /** + * Fill the given rectangle with the current color. + * + * @param rect the rectangle + * @see drawRectangle + */ + void fillRectangle(const Rectangle &rect); - /** - * Fill the list of rectangles with the current color. - * - * @param rects the list of rectangles - * @see drawRectangles - */ - void fillRectangles(const std::vector<Rectangle> &rects); + /** + * Fill the list of rectangles with the current color. + * + * @param rects the list of rectangles + * @see drawRectangles + */ + void fillRectangles(const std::vector<Rectangle> &rects); - /** - * Draw some text. - * - * This function may stretch the text texture. - * - * @param text the text (UTF-8) - * @param font the font - * @param rectangle the rectangle target - */ - void drawText(const std::string &text, Font &font, const Rectangle &rectangle); + /** + * Draw some text. + * + * This function may stretch the text texture. + * + * @param text the text (UTF-8) + * @param font the font + * @param rectangle the rectangle target + */ + void drawText(const std::string &text, Font &font, const Rectangle &rectangle); - /** - * Overloaded function. - * - * Draw the text at the given position. - * - * @param text the text (UTF-8) - * @param font the font - * @param point the text position - */ - void drawText(const std::string &text, Font &font, const Point &point); + /** + * Overloaded function. + * + * Draw the text at the given position. + * + * @param text the text (UTF-8) + * @param font the font + * @param point the text position + */ + void drawText(const std::string &text, Font &font, const Point &point); - /** - * Move assigment operator defaulted. - * - * @return this - */ - Window &operator=(Window &&); + /** + * Move assigment operator defaulted. + * + * @return this + */ + Window &operator=(Window &&); }; } // !malikania
--- a/libcommon/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,54 +17,54 @@ # set( - HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/application.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/elapsed-timer.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/id.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-elapsed-timer.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/json.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-loader.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-locator.h - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/util.h + HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/application.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/elapsed-timer.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/id.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-elapsed-timer.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/json.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-loader.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-locator.h + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/util.h ) set( - SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/application.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/elapsed-timer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-elapsed-timer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/json.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-loader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-locator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/malikania/util.cpp + SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/application.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/elapsed-timer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-elapsed-timer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/json.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-loader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-locator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/util.cpp ) if (WITH_BACKEND_SDL) - find_package(SDL2 REQUIRED) + find_package(SDL2 REQUIRED) - list(APPEND HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/malikania/backend/sdl/common-sdl.h) - list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/malikania/backend/sdl/common-sdl.cpp) - list(APPEND INCLUDES ${SDL2_INCLUDE_DIRS}) - list(APPEND LIBRARIES ${SDL2_LIBRARIES}) + list(APPEND HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/malikania/backend/sdl/common-sdl.h) + list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/malikania/backend/sdl/common-sdl.cpp) + list(APPEND INCLUDES ${SDL2_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${SDL2_LIBRARIES}) endif () if (WIN32) - list(APPEND LIBRARIES ws2_32) + list(APPEND LIBRARIES ws2_32) endif () malikania_create_library( - PROJECT libcommon - TARGET libcommon - SOURCES ${HEADERS} ${SOURCES} - FLAGS "MALIKANIA_COMMON_BUILD" - PUBLIC_INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR} - ${INCLUDES} - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/malikania> - LIBRARIES extern-jansson ${LIBRARIES} + PROJECT libcommon + TARGET libcommon + SOURCES ${HEADERS} ${SOURCES} + FLAGS "MALIKANIA_COMMON_BUILD" + PUBLIC_INCLUDES + ${CMAKE_CURRENT_SOURCE_DIR} + ${INCLUDES} + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/malikania> + LIBRARIES extern-jansson ${LIBRARIES} ) set_target_properties(libcommon PROPERTIES PREFIX "")
--- a/libcommon/malikania/application.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/application.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -22,7 +22,7 @@ Application::Application(int, char **) { - // TODO: find the executable path + // TODO: find the executable path } } // !malikania
--- a/libcommon/malikania/application.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/application.h Thu Jun 16 13:35:31 2016 +0200 @@ -32,18 +32,18 @@ */ class Application { public: - /** - * Construct the application. - * - * @param argc the argument count - * @param argv the arguments - */ - Application(int argc, char **argv); + /** + * Construct the application. + * + * @param argc the argument count + * @param argv the arguments + */ + Application(int argc, char **argv); - /** - * Virtual destructor defaulted. - */ - virtual ~Application() = default; + /** + * Virtual destructor defaulted. + */ + virtual ~Application() = default; }; } // !malikania
--- a/libcommon/malikania/backend/sdl/common-sdl.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/backend/sdl/common-sdl.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -39,113 +39,113 @@ class Buffer { public: - std::string m_data; - std::uint64_t m_position; - std::uint64_t m_length; + std::string m_data; + std::uint64_t m_position; + std::uint64_t m_length; - inline Buffer(std::string data) noexcept - : m_data(std::move(data)) - , m_position(0U) - , m_length(m_data.length()) - { - } + inline Buffer(std::string data) noexcept + : m_data(std::move(data)) + , m_position(0U) + , m_length(m_data.length()) + { + } }; Sint64 size(SDL_RWops *ops) { - return reinterpret_cast<Buffer *>(ops->hidden.unknown.data1)->m_length; + return reinterpret_cast<Buffer *>(ops->hidden.unknown.data1)->m_length; } Sint64 seek(SDL_RWops *ops, Sint64 offset, int whence) { - Buffer *data = reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); - Sint64 position = data->m_position; + Buffer *data = reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); + Sint64 position = data->m_position; - switch (whence) { - case RW_SEEK_SET: - position = offset; - break; - case RW_SEEK_CUR: - position = data->m_position + offset; - break; - case RW_SEEK_END: - position = data->m_length + offset; - break; - default: - break; - } + switch (whence) { + case RW_SEEK_SET: + position = offset; + break; + case RW_SEEK_CUR: + position = data->m_position + offset; + break; + case RW_SEEK_END: + position = data->m_length + offset; + break; + default: + break; + } - if (position < 0) - position = 0; - else if ((std::uint64_t)position > data->m_length) - position = data->m_length; + if (position < 0) + position = 0; + else if ((std::uint64_t)position > data->m_length) + position = data->m_length; - return (data->m_position = position); + return (data->m_position = position); } size_t read(SDL_RWops *ops, void *dst, size_t size, size_t number) { - Buffer *data = reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); - size_t total = number * size; - size_t avail = data->m_length - data->m_position; + Buffer *data = reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); + size_t total = number * size; + size_t avail = data->m_length - data->m_position; - if (number <= 0 || size <= 0 || ((total / number) != (size_t)size)) { - return 0; - } - if (total > avail) { - total = avail; - } + if (number <= 0 || size <= 0 || ((total / number) != (size_t)size)) { + return 0; + } + if (total > avail) { + total = avail; + } - SDL_memcpy(dst, &data->m_data[data->m_position], total); + SDL_memcpy(dst, &data->m_data[data->m_position], total); - data->m_position += total; + data->m_position += total; - return (total / size); + return (total / size); } size_t write(SDL_RWops *, const void *, size_t, size_t) { - SDL_SetError("write not supported"); + SDL_SetError("write not supported"); - return -1; + return -1; } int close(SDL_RWops *ops) { - if (ops != nullptr) { - delete reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); - SDL_FreeRW(ops); - } + if (ops != nullptr) { + delete reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); + SDL_FreeRW(ops); + } - return 0; + return 0; } } // !namespace SDL_RWops *RWFromBinary(std::string data) noexcept { - SDL_RWops *ops = SDL_AllocRW(); + SDL_RWops *ops = SDL_AllocRW(); - if (ops == nullptr) { - return nullptr; - } + if (ops == nullptr) { + return nullptr; + } - ops->hidden.unknown.data1 = new (std::nothrow) Buffer(std::move(data)); + ops->hidden.unknown.data1 = new (std::nothrow) Buffer(std::move(data)); - if (ops->hidden.unknown.data1 == nullptr) { - SDL_SetError("%s", std::strerror(errno)); - SDL_FreeRW(ops); - return nullptr; - } + if (ops->hidden.unknown.data1 == nullptr) { + SDL_SetError("%s", std::strerror(errno)); + SDL_FreeRW(ops); + return nullptr; + } - ops->type = SDL_RWOPS_UNKNOWN; - ops->seek = seek; - ops->size = size; - ops->read = read; - ops->write = write; - ops->close = close; + ops->type = SDL_RWOPS_UNKNOWN; + ops->seek = seek; + ops->size = size; + ops->read = read; + ops->write = write; + ops->close = close; - return ops; + return ops; } } // !sdl
--- a/libcommon/malikania/elapsed-timer.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/elapsed-timer.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -26,39 +26,39 @@ ElapsedTimer::ElapsedTimer() noexcept { - m_last = high_resolution_clock::now(); + m_last = high_resolution_clock::now(); } void ElapsedTimer::pause() noexcept { - /* - * When we put the timer on pause, do not forget to set the already - * elapsed time. - */ - (void)elapsed(); - m_paused = true; + /* + * When we put the timer on pause, do not forget to set the already + * elapsed time. + */ + (void)elapsed(); + m_paused = true; } void ElapsedTimer::restart() noexcept { - m_paused = false; - m_last = high_resolution_clock::now(); + m_paused = false; + m_last = high_resolution_clock::now(); } void ElapsedTimer::reset() noexcept { - m_elapsed = 0; - m_last = high_resolution_clock::now(); + m_elapsed = 0; + m_last = high_resolution_clock::now(); } unsigned ElapsedTimer::elapsed() noexcept { - if (!m_paused) { - m_elapsed += duration_cast<milliseconds>(high_resolution_clock::now() - m_last).count(); - m_last = high_resolution_clock::now(); - } + if (!m_paused) { + m_elapsed += duration_cast<milliseconds>(high_resolution_clock::now() - m_last).count(); + m_last = high_resolution_clock::now(); + } - return m_elapsed; + return m_elapsed; } } // !malikania
--- a/libcommon/malikania/elapsed-timer.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/elapsed-timer.h Thu Jun 16 13:35:31 2016 +0200 @@ -42,40 +42,40 @@ */ class ElapsedTimer : public duk::Bindable { public: - using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; + using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; private: - TimePoint m_last; - bool m_paused{false}; - unsigned m_elapsed{0}; + TimePoint m_last; + bool m_paused{false}; + unsigned m_elapsed{0}; public: - /** - * Construct the elapsed timer, start counting. - */ - ElapsedTimer() noexcept; + /** + * Construct the elapsed timer, start counting. + */ + ElapsedTimer() noexcept; - /** - * Put the timer on pause, the already elapsed time is stored. - */ - void pause() noexcept; + /** + * Put the timer on pause, the already elapsed time is stored. + */ + void pause() noexcept; - /** - * Restart the timer, does not reset it. - */ - void restart() noexcept; + /** + * Restart the timer, does not reset it. + */ + void restart() noexcept; - /** - * Reset the timer to 0. - */ - void reset() noexcept; + /** + * Reset the timer to 0. + */ + void reset() noexcept; - /** - * Get the number of elapsed milliseconds. - * - * @return the milliseconds - */ - unsigned elapsed() noexcept; + /** + * Get the number of elapsed milliseconds. + * + * @return the milliseconds + */ + unsigned elapsed() noexcept; }; } // !malikania
--- a/libcommon/malikania/game.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/game.h Thu Jun 16 13:35:31 2016 +0200 @@ -37,86 +37,86 @@ */ class Game { private: - std::string m_name; - std::string m_version; - std::string m_requires; - std::string m_license; - std::string m_author; + std::string m_name; + std::string m_version; + std::string m_requires; + std::string m_license; + std::string m_author; public: - /** - * Construct a game. - * - * @pre name must not be empty - * @pre version must not be empty - * @pre requires must not be empty - * @param name the game name - * @param version the version - * @param requires the engine version required - * @param license the license (Optional) - * @param authors the authors (Optional) - */ - inline Game(std::string name, std::string version, std::string requires, std::string license, std::string author) - : m_name(std::move(name)) - , m_version(std::move(version)) - , m_requires(std::move(requires)) - , m_license(std::move(license)) - , m_author(std::move(author)) - { - assert(!m_name.empty()); - assert(!m_version.empty()); - assert(!m_requires.empty()); - } + /** + * Construct a game. + * + * @pre name must not be empty + * @pre version must not be empty + * @pre requires must not be empty + * @param name the game name + * @param version the version + * @param requires the engine version required + * @param license the license (Optional) + * @param authors the authors (Optional) + */ + inline Game(std::string name, std::string version, std::string requires, std::string license, std::string author) + : m_name(std::move(name)) + , m_version(std::move(version)) + , m_requires(std::move(requires)) + , m_license(std::move(license)) + , m_author(std::move(author)) + { + assert(!m_name.empty()); + assert(!m_version.empty()); + assert(!m_requires.empty()); + } - /** - * Get the game name. - * - * @return the name - */ - inline const std::string &name() const noexcept - { - return m_name; - } + /** + * Get the game name. + * + * @return the name + */ + inline const std::string &name() const noexcept + { + return m_name; + } - /** - * Get the author. - * - * @return the author - */ - inline const std::string &author() const noexcept - { - return m_author; - } + /** + * Get the author. + * + * @return the author + */ + inline const std::string &author() const noexcept + { + return m_author; + } - /** - * Get the license. - * - * @return the license - */ - inline const std::string &license() const noexcept - { - return m_license; - } + /** + * Get the license. + * + * @return the license + */ + inline const std::string &license() const noexcept + { + return m_license; + } - /** - * Get the license. - * - * @return the license - */ - inline const std::string &version() const noexcept - { - return m_version; - } + /** + * Get the license. + * + * @return the license + */ + inline const std::string &version() const noexcept + { + return m_version; + } - /** - * Get the engine version required to run the game. - * - * @return the version required - */ - inline const std::string &requires() const noexcept - { - return m_requires; - } + /** + * Get the engine version required to run the game. + * + * @return the version required + */ + inline const std::string &requires() const noexcept + { + return m_requires; + } }; } // !malikania
--- a/libcommon/malikania/id.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/id.h Thu Jun 16 13:35:31 2016 +0200 @@ -44,63 +44,63 @@ template <typename T> class IdGen { private: - static_assert(std::numeric_limits<T>::is_integer, "IdGen requires integral types"); + static_assert(std::numeric_limits<T>::is_integer, "IdGen requires integral types"); - T m_current{0}; - std::priority_queue<T> m_reusable; + T m_current{0}; + std::priority_queue<T> m_reusable; public: - /** - * Get the next id for that player. - * - * @return the id - * @throw std::out_of_range if no number is available - */ - T next(); + /** + * Get the next id for that player. + * + * @return the id + * @throw std::out_of_range if no number is available + */ + T next(); - /** - * Release the player id. - * - * @param id the id not needed anymore - */ - inline void release(T id) noexcept - { - m_reusable.push(id); - } + /** + * Release the player id. + * + * @param id the id not needed anymore + */ + inline void release(T id) noexcept + { + m_reusable.push(id); + } - /** - * Reset the ids to 0 and remove the queue. - */ - void reset() noexcept; + /** + * Reset the ids to 0 and remove the queue. + */ + void reset() noexcept; }; template <typename T> T IdGen<T>::next() { - T id; + T id; - if (m_reusable.size() > 0) { - id = m_reusable.top(); - m_reusable.pop(); - } else { - if (m_current == std::numeric_limits<T>::max()) { - throw std::out_of_range("no id available"); - } + if (m_reusable.size() > 0) { + id = m_reusable.top(); + m_reusable.pop(); + } else { + if (m_current == std::numeric_limits<T>::max()) { + throw std::out_of_range("no id available"); + } - id = m_current++; - } + id = m_current++; + } - return id; + return id; } template <typename T> void IdGen<T>::reset() noexcept { - m_current = 0; + m_current = 0; - while (!m_reusable.empty()) { - m_reusable.pop(); - } + while (!m_reusable.empty()) { + m_reusable.pop(); + } } /** @@ -115,60 +115,60 @@ template <typename T> class Id { private: - IdGen<T> &m_gen; - T m_id; + IdGen<T> &m_gen; + T m_id; public: - /** - * Construct a new Id and take the next number. - * - * @param gen the generator - * @throw any exception if IdGen fails to give an id. - */ - inline Id(IdGen<T> &gen) - : m_gen(gen) - , m_id(m_gen.next()) - { - } + /** + * Construct a new Id and take the next number. + * + * @param gen the generator + * @throw any exception if IdGen fails to give an id. + */ + inline Id(IdGen<T> &gen) + : m_gen(gen) + , m_id(m_gen.next()) + { + } - /** - * Construct an Id with an already taken number. - * - * @param gen the generator - * @param id the id - * @warning be sure that the id was taken from this generator - */ - Id(IdGen<T> &gen, T id) - : m_gen(gen) - , m_id(id) - { - } + /** + * Construct an Id with an already taken number. + * + * @param gen the generator + * @param id the id + * @warning be sure that the id was taken from this generator + */ + Id(IdGen<T> &gen, T id) + : m_gen(gen) + , m_id(id) + { + } - /** - * Destroy the id and release the number. - */ - ~Id() noexcept - { - m_gen.release(m_id); - } + /** + * Destroy the id and release the number. + */ + ~Id() noexcept + { + m_gen.release(m_id); + } - /** - * Get the number id. - * - * @return the id - */ - inline T value() const noexcept - { - return m_id; - } + /** + * Get the number id. + * + * @return the id + */ + inline T value() const noexcept + { + return m_id; + } - /** - * Convert the id to the number. - */ - inline operator T() const noexcept - { - return m_id; - } + /** + * Convert the id to the number. + */ + inline operator T() const noexcept + { + return m_id; + } }; } // !malikania
--- a/libcommon/malikania/js-elapsed-timer.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/js-elapsed-timer.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -31,9 +31,9 @@ */ duk::Ret pause(duk::ContextPtr ctx) { - duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->pause(); + duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->pause(); - return 0; + return 0; } /* @@ -44,9 +44,9 @@ */ duk::Ret reset(duk::ContextPtr ctx) { - duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->reset(); + duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->reset(); - return 0; + return 0; } /* @@ -57,9 +57,9 @@ */ duk::Ret restart(duk::ContextPtr ctx) { - duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->restart(); + duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->restart(); - return 0; + return 0; } /* @@ -73,9 +73,9 @@ */ duk::Ret elapsed(duk::ContextPtr ctx) { - duk::push(ctx, (int)duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->elapsed()); + duk::push(ctx, (int)duk::self<std::shared_ptr<ElapsedTimer>>(ctx)->elapsed()); - return 1; + return 1; } /* @@ -86,31 +86,31 @@ */ duk::Ret constructor(duk::ContextPtr ctx) { - duk::construct(ctx, std::make_shared<ElapsedTimer>()); + duk::construct(ctx, std::make_shared<ElapsedTimer>()); - return 0; + return 0; } const duk::FunctionMap methods{ - { "elapsed", { elapsed, 0 } }, - { "pause", { pause, 0 } }, - { "reset", { reset, 0 } }, - { "restart", { restart, 0 } } + { "elapsed", { elapsed, 0 } }, + { "pause", { pause, 0 } }, + { "reset", { reset, 0 } }, + { "restart", { restart, 0 } } }; } // !namespace void loadJsElapsedTimer(duk::ContextPtr ctx) noexcept { - duk::StackAssert sa(ctx); + duk::StackAssert sa(ctx); - duk::getGlobal<void>(ctx, "Malikania"); - duk::push(ctx, duk::Function{constructor, 0}); - duk::push(ctx, duk::Object{}); - duk::put(ctx, methods); - duk::putProperty(ctx, -2, "prototype"); - duk::putProperty(ctx, -2, "ElapsedTimer"); - duk::pop(ctx); + duk::getGlobal<void>(ctx, "Malikania"); + duk::push(ctx, duk::Function{constructor, 0}); + duk::push(ctx, duk::Object{}); + duk::put(ctx, methods); + duk::putProperty(ctx, -2, "prototype"); + duk::putProperty(ctx, -2, "ElapsedTimer"); + duk::pop(ctx); } } // !malikania
--- a/libcommon/malikania/js.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/js.h Thu Jun 16 13:35:31 2016 +0200 @@ -714,44 +714,44 @@ class StackAssert { #if !defined(NDEBUG) private: - ContextPtr m_context; - unsigned m_expected; - unsigned m_begin; + ContextPtr m_context; + unsigned m_expected; + unsigned m_begin; #endif public: - /** - * Create the stack checker. - * - * No-op if NDEBUG is set. - * - * @param ctx the context - * @param expected the size expected relative to the already existing values - */ - inline StackAssert(ContextPtr ctx, unsigned expected = 0) noexcept + /** + * Create the stack checker. + * + * No-op if NDEBUG is set. + * + * @param ctx the context + * @param expected the size expected relative to the already existing values + */ + inline StackAssert(ContextPtr ctx, unsigned expected = 0) noexcept #if !defined(NDEBUG) - : m_context(ctx) - , m_expected(expected) - , m_begin(static_cast<unsigned>(duk_get_top(ctx))) + : m_context(ctx) + , m_expected(expected) + , m_begin(static_cast<unsigned>(duk_get_top(ctx))) #endif - { + { #if defined(NDEBUG) - (void)ctx; - (void)expected; + (void)ctx; + (void)expected; #endif - } + } - /** - * Verify the expected size. - * - * No-op if NDEBUG is set. - */ - inline ~StackAssert() noexcept - { + /** + * Verify the expected size. + * + * No-op if NDEBUG is set. + */ + inline ~StackAssert() noexcept + { #if !defined(NDEBUG) - assert((unsigned)duk_get_top(m_context) - m_begin == m_expected); + assert((unsigned)duk_get_top(m_context) - m_begin == m_expected); #endif - } + } }; /** @@ -759,15 +759,15 @@ */ class Bindable { public: - /** - * Default constructor - */ - Bindable() = default; + /** + * Default constructor + */ + Bindable() = default; - /** - * Default destructor. - */ - virtual ~Bindable() = default; + /** + * Default destructor. + */ + virtual ~Bindable() = default; }; /** @@ -887,15 +887,15 @@ */ class Function { public: - /** - * The function pointer, must not be null. - */ - duk_c_function function; + /** + * The function pointer, must not be null. + */ + duk_c_function function; - /** - * Number of args that the function takes - */ - duk_idx_t nargs{0}; + /** + * Number of args that the function takes + */ + duk_idx_t nargs{0}; }; /** @@ -917,21 +917,21 @@ */ class Exception : public std::exception { public: - std::string name; //!< name of error - std::string message; //!< error message - std::string stack; //!< stack if available - std::string fileName; //!< filename if applicable - int lineNumber{0}; //!< line number if applicable + std::string name; //!< name of error + std::string message; //!< error message + std::string stack; //!< stack if available + std::string fileName; //!< filename if applicable + int lineNumber{0}; //!< line number if applicable - /** - * Get the error message. This effectively returns message field. - * - * @return the message - */ - const char *what() const noexcept override - { - return message.c_str(); - } + /** + * Get the error message. This effectively returns message field. + * + * @return the message + */ + const char *what() const noexcept override + { + return message.c_str(); + } }; /** @@ -942,52 +942,52 @@ */ class Context { private: - using Deleter = void (*)(duk_context *); - using Handle = std::unique_ptr<duk_context, Deleter>; + using Deleter = void (*)(duk_context *); + using Handle = std::unique_ptr<duk_context, Deleter>; - Handle m_handle; + Handle m_handle; - Context(const Context &) = delete; - Context &operator=(const Context &) = delete; + Context(const Context &) = delete; + Context &operator=(const Context &) = delete; public: - /** - * Create default context. - */ - inline Context() - : m_handle(duk_create_heap_default(), duk_destroy_heap) - { - } + /** + * Create default context. + */ + inline Context() + : m_handle(duk_create_heap_default(), duk_destroy_heap) + { + } - /** - * Default move constructor. - */ - Context(Context &&) noexcept = default; + /** + * Default move constructor. + */ + Context(Context &&) noexcept = default; - /** - * Convert the context to the native Duktape/C type. - * - * @return the duk_context - */ - inline operator duk_context *() noexcept - { - return m_handle.get(); - } + /** + * Convert the context to the native Duktape/C type. + * + * @return the duk_context + */ + inline operator duk_context *() noexcept + { + return m_handle.get(); + } - /** - * Convert the context to the native Duktape/C type. - * - * @return the duk_context - */ - inline operator duk_context *() const noexcept - { - return m_handle.get(); - } + /** + * Convert the context to the native Duktape/C type. + * + * @return the duk_context + */ + inline operator duk_context *() const noexcept + { + return m_handle.get(); + } - /** - * Default move assignment operator. - */ - Context &operator=(Context &&) noexcept = delete; + /** + * Default move assignment operator. + */ + Context &operator=(Context &&) noexcept = delete; }; /** @@ -1009,7 +1009,7 @@ */ inline void base64Decode(ContextPtr ctx, Index index) { - duk_base64_decode(ctx, index); + duk_base64_decode(ctx, index); } /** @@ -1021,7 +1021,7 @@ */ inline std::string base64Encode(ContextPtr ctx, Index index) { - return duk_base64_encode(ctx, index); + return duk_base64_encode(ctx, index); } /** @@ -1032,7 +1032,7 @@ */ inline void call(ContextPtr ctx, Index nargs = 0) { - duk_call(ctx, nargs); + duk_call(ctx, nargs); } /** @@ -1043,7 +1043,7 @@ */ inline void callMethod(ContextPtr ctx, Index nargs = 0) { - duk_call_method(ctx, nargs); + duk_call_method(ctx, nargs); } /** @@ -1055,7 +1055,7 @@ */ inline void callProperty(ContextPtr ctx, Index index, Index nargs = 0) { - duk_call_prop(ctx, index, nargs); + duk_call_prop(ctx, index, nargs); } /** @@ -1067,7 +1067,7 @@ */ inline duk_codepoint_t charCodeAt(ContextPtr ctx, Index index, duk_size_t charOffset) { - return duk_char_code_at(ctx, index, charOffset); + return duk_char_code_at(ctx, index, charOffset); } /** @@ -1079,7 +1079,7 @@ */ inline bool checkStack(ContextPtr ctx, Index extra) { - return duk_check_stack(ctx, extra); + return duk_check_stack(ctx, extra); } /** @@ -1091,7 +1091,7 @@ */ inline bool checkStackTop(ContextPtr ctx, Index top) { - return duk_check_stack_top(ctx, top); + return duk_check_stack_top(ctx, top); } /** @@ -1104,7 +1104,7 @@ */ inline bool checkType(ContextPtr ctx, Index index, int type) { - return duk_check_type(ctx, index, type); + return duk_check_type(ctx, index, type); } /** @@ -1117,7 +1117,7 @@ */ inline bool checkTypeMask(ContextPtr ctx, Index index, unsigned mask) { - return duk_check_type_mask(ctx, index, mask); + return duk_check_type_mask(ctx, index, mask); } /** @@ -1128,7 +1128,7 @@ */ inline void compact(ContextPtr ctx, Index objIndex) { - duk_compact(ctx, objIndex); + duk_compact(ctx, objIndex); } /** @@ -1139,7 +1139,7 @@ */ inline void concat(ContextPtr ctx, Index count) { - duk_concat(ctx, count); + duk_concat(ctx, count); } /** @@ -1151,7 +1151,7 @@ */ inline void copy(ContextPtr ctx, Index from, Index to) { - duk_copy(ctx, from, to); + duk_copy(ctx, from, to); } /** @@ -1162,7 +1162,7 @@ */ inline void create(ContextPtr ctx, int nargs = 0) { - duk_new(ctx, nargs); + duk_new(ctx, nargs); } /** @@ -1174,7 +1174,7 @@ */ inline void defineProperty(ContextPtr ctx, Index index, unsigned flags) { - duk_def_prop(ctx, index, flags); + duk_def_prop(ctx, index, flags); } /** @@ -1186,7 +1186,7 @@ */ inline bool deleteProperty(ContextPtr ctx, Index index) { - return duk_del_prop(ctx, index); + return duk_del_prop(ctx, index); } /** @@ -1199,7 +1199,7 @@ */ inline bool deleteProperty(ContextPtr ctx, Index index, unsigned position) { - return duk_del_prop_index(ctx, index, position); + return duk_del_prop_index(ctx, index, position); } /** @@ -1212,7 +1212,7 @@ */ inline bool deleteProperty(ContextPtr ctx, Index index, const std::string &name) { - return duk_del_prop_string(ctx, index, name.c_str()); + return duk_del_prop_string(ctx, index, name.c_str()); } /** @@ -1223,7 +1223,7 @@ */ inline void dup(ContextPtr ctx, int index = -1) { - duk_dup(ctx, index); + duk_dup(ctx, index); } /** @@ -1236,7 +1236,7 @@ */ inline bool equals(ContextPtr ctx, Index index1, Index index2) { - return duk_equals(ctx, index1, index2); + return duk_equals(ctx, index1, index2); } /** @@ -1246,7 +1246,7 @@ */ inline void eval(ContextPtr ctx) { - duk_eval(ctx); + duk_eval(ctx); } /** @@ -1258,10 +1258,10 @@ */ inline void evalFile(ContextPtr ctx, const std::string &path, bool result = true) { - if (result) - duk_eval_file(ctx, path.c_str()); - else - duk_eval_file_noresult(ctx, path.c_str()); + if (result) + duk_eval_file(ctx, path.c_str()); + else + duk_eval_file_noresult(ctx, path.c_str()); } /** @@ -1273,10 +1273,10 @@ */ inline void evalString(ContextPtr ctx, const std::string &src, bool result = true) { - if (result) - duk_eval_string(ctx, src.c_str()); - else - duk_eval_string_noresult(ctx, src.c_str()); + if (result) + duk_eval_string(ctx, src.c_str()); + else + duk_eval_string_noresult(ctx, src.c_str()); } /** * Wrapper for [duk_gc](http://duktape.org/api.html#duk_gc). @@ -1286,7 +1286,7 @@ */ inline void gc(ContextPtr ctx, unsigned flags = 0) { - duk_gc(ctx, flags); + duk_gc(ctx, flags); } /** @@ -1298,7 +1298,7 @@ */ inline bool hasProperty(ContextPtr ctx, Index index) { - return duk_has_prop(ctx, index); + return duk_has_prop(ctx, index); } /** @@ -1311,7 +1311,7 @@ */ inline bool hasProperty(ContextPtr ctx, Index index, unsigned position) { - return duk_has_prop_index(ctx, index, position); + return duk_has_prop_index(ctx, index, position); } /** @@ -1324,7 +1324,7 @@ */ inline bool hasProperty(ContextPtr ctx, int index, const std::string &name) { - return duk_has_prop_string(ctx, index, name.c_str()); + return duk_has_prop_string(ctx, index, name.c_str()); } /** @@ -1336,7 +1336,7 @@ */ inline void insert(ContextPtr ctx, Index to) { - duk_insert(ctx, to); + duk_insert(ctx, to); } /** @@ -1349,7 +1349,7 @@ */ inline bool instanceof(ContextPtr ctx, Index idx1, Index idx2) { - return duk_instanceof(ctx, idx1, idx2); + return duk_instanceof(ctx, idx1, idx2); } /** @@ -1360,7 +1360,7 @@ */ inline void join(ContextPtr ctx, Index count) { - duk_join(ctx, count); + duk_join(ctx, count); } /** @@ -1371,7 +1371,7 @@ */ inline void jsonDecode(ContextPtr ctx, Index index) { - duk_json_decode(ctx, index); + duk_json_decode(ctx, index); } /** @@ -1383,7 +1383,7 @@ */ inline std::string jsonEncode(ContextPtr ctx, Index index) { - return duk_json_encode(ctx, index); + return duk_json_encode(ctx, index); } /** @@ -1394,7 +1394,7 @@ */ inline Index normalizeIndex(ContextPtr ctx, Index index) { - return duk_normalize_index(ctx, index); + return duk_normalize_index(ctx, index); } /** @@ -1405,7 +1405,7 @@ */ inline int pcall(ContextPtr ctx, Index nargs = 0) { - return duk_pcall(ctx, nargs); + return duk_pcall(ctx, nargs); } /** @@ -1416,7 +1416,7 @@ */ inline int pcallMethod(ContextPtr ctx, Index nargs = 0) { - return duk_pcall_method(ctx, nargs); + return duk_pcall_method(ctx, nargs); } /** @@ -1428,7 +1428,7 @@ */ inline int pcallProperty(ContextPtr ctx, Index index, Index nargs = 0) { - return duk_pcall_prop(ctx, index, nargs); + return duk_pcall_prop(ctx, index, nargs); } /** @@ -1438,7 +1438,7 @@ */ inline int peval(ContextPtr ctx) { - return duk_peval(ctx); + return duk_peval(ctx); } /** @@ -1450,7 +1450,7 @@ */ inline int pevalFile(ContextPtr ctx, const std::string &path, bool result = true) { - return result ? duk_peval_file(ctx, path.c_str()) : duk_peval_file_noresult(ctx, path.c_str()); + return result ? duk_peval_file(ctx, path.c_str()) : duk_peval_file_noresult(ctx, path.c_str()); } /** @@ -1462,7 +1462,7 @@ */ inline int pevalString(ContextPtr ctx, const std::string &src, bool result = true) { - return result ? duk_peval_string(ctx, src.c_str()) : duk_peval_string_noresult(ctx, src.c_str()); + return result ? duk_peval_string(ctx, src.c_str()) : duk_peval_string_noresult(ctx, src.c_str()); } /** @@ -1473,7 +1473,7 @@ */ inline void pop(ContextPtr ctx, Index count = 1) { - duk_pop_n(ctx, count); + duk_pop_n(ctx, count); } /** @@ -1484,7 +1484,7 @@ */ inline void putProperty(ContextPtr ctx, Index index) { - duk_put_prop(ctx, index); + duk_put_prop(ctx, index); } /** @@ -1496,7 +1496,7 @@ */ inline void putProperty(ContextPtr ctx, Index index, const std::string &name) { - duk_put_prop_string(ctx, index, name.c_str()); + duk_put_prop_string(ctx, index, name.c_str()); } /** @@ -1508,7 +1508,7 @@ */ inline void putProperty(ContextPtr ctx, Index index, unsigned position) { - duk_put_prop_index(ctx, index, position); + duk_put_prop_index(ctx, index, position); } /** @@ -1519,7 +1519,7 @@ */ inline void remove(ContextPtr ctx, Index index) { - duk_remove(ctx, index); + duk_remove(ctx, index); } /** @@ -1530,7 +1530,7 @@ */ inline void replace(ContextPtr ctx, Index index) { - duk_replace(ctx, index); + duk_replace(ctx, index); } /** @@ -1541,7 +1541,7 @@ */ inline void setPrototype(ContextPtr ctx, Index index) { - duk_set_prototype(ctx, index); + duk_set_prototype(ctx, index); } /** @@ -1553,7 +1553,7 @@ */ inline void swap(ContextPtr ctx, Index index1, Index index2) { - duk_swap(ctx, index1, index2); + duk_swap(ctx, index1, index2); } /** @@ -1564,7 +1564,7 @@ */ inline void swapTop(ContextPtr ctx, Index index) { - duk_swap_top(ctx, index); + duk_swap_top(ctx, index); } /** @@ -1575,7 +1575,7 @@ */ inline int top(ContextPtr ctx) { - return duk_get_top(ctx); + return duk_get_top(ctx); } /** @@ -1585,7 +1585,7 @@ */ inline void raise(ContextPtr ctx) { - duk_throw(ctx); + duk_throw(ctx); } /** @@ -1599,7 +1599,7 @@ template <typename... Args> inline void raise(ContextPtr ctx, int type, const char *fmt, Args&&... args) { - duk_error(ctx, type, fmt, std::forward<Args>(args)...); + duk_error(ctx, type, fmt, std::forward<Args>(args)...); } /** @@ -1611,7 +1611,7 @@ */ inline int type(ContextPtr ctx, Index index) { - return duk_get_type(ctx, index); + return duk_get_type(ctx, index); } /** @@ -1638,24 +1638,24 @@ */ inline Exception exception(ContextPtr ctx, int index) { - Exception ex; - StackAssert sa(ctx); + Exception ex; + StackAssert sa(ctx); - index = duk_normalize_index(ctx, index); + index = duk_normalize_index(ctx, index); - duk_get_prop_string(ctx, index, "name"); - ex.name = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "message"); - ex.message = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "fileName"); - ex.fileName = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "lineNumber"); - ex.lineNumber = duk_to_int(ctx, -1); - duk_get_prop_string(ctx, index, "stack"); - ex.stack = duk_to_string(ctx, -1); - duk_pop_n(ctx, 5); + duk_get_prop_string(ctx, index, "name"); + ex.name = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "message"); + ex.message = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "fileName"); + ex.fileName = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "lineNumber"); + ex.lineNumber = duk_to_int(ctx, -1); + duk_get_prop_string(ctx, index, "stack"); + ex.stack = duk_to_string(ctx, -1); + duk_pop_n(ctx, 5); - return ex; + return ex; } /** @@ -1667,7 +1667,7 @@ template <typename Type> inline void push(ContextPtr ctx, Type &&value) { - TypeTraits<std::decay_t<Type>>::push(ctx, std::forward<Type>(value)); + TypeTraits<std::decay_t<Type>>::push(ctx, std::forward<Type>(value)); } /** @@ -1679,7 +1679,7 @@ template <typename Type> inline void put(ContextPtr ctx, Type &&value) { - TypeTraits<std::decay_t<Type>>::put(ctx, std::forward<Type>(value)); + TypeTraits<std::decay_t<Type>>::put(ctx, std::forward<Type>(value)); } /** @@ -1692,7 +1692,7 @@ template <typename Type> inline auto get(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::get(ctx, 0)) { - return TypeTraits<Type>::get(ctx, index); + return TypeTraits<Type>::get(ctx, index); } /** @@ -1705,7 +1705,7 @@ template <typename Type> inline auto require(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::require(ctx, 0)) { - return TypeTraits<Type>::require(ctx, index); + return TypeTraits<Type>::require(ctx, index); } /** @@ -1720,7 +1720,7 @@ template <typename T> inline bool is(ContextPtr ctx, int index) { - return TypeTraits<T>::is(ctx, index); + return TypeTraits<T>::is(ctx, index); } /** @@ -1737,7 +1737,7 @@ template <typename Type> inline auto optional(ContextPtr ctx, int index, Type &&defaultValue) { - return TypeTraits<std::decay_t<Type>>::optional(ctx, index, std::forward<Type>(defaultValue)); + return TypeTraits<std::decay_t<Type>>::optional(ctx, index, std::forward<Type>(defaultValue)); } /** @@ -1752,11 +1752,11 @@ template <typename Type, typename std::enable_if_t<!std::is_void<Type>::value> * = nullptr> inline auto getProperty(ContextPtr ctx, int index, const std::string &name) -> decltype(get<Type>(ctx, 0)) { - duk_get_prop_string(ctx, index, name.c_str()); - decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); - duk_pop(ctx); + duk_get_prop_string(ctx, index, name.c_str()); + decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); + duk_pop(ctx); - return value; + return value; } /** @@ -1771,11 +1771,11 @@ template <typename Type, typename std::enable_if_t<!std::is_void<Type>::value> * = nullptr> inline auto getProperty(ContextPtr ctx, int index, int position) -> decltype(get<Type>(ctx, 0)) { - duk_get_prop_index(ctx, index, position); - decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); - duk_pop(ctx); + duk_get_prop_index(ctx, index, position); + decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); + duk_pop(ctx); - return value; + return value; } /** @@ -1789,7 +1789,7 @@ template <typename Type, typename std::enable_if_t<std::is_void<Type>::value> * = nullptr> inline void getProperty(ContextPtr ctx, int index, const std::string &name) { - duk_get_prop_string(ctx, index, name.c_str()); + duk_get_prop_string(ctx, index, name.c_str()); } /** @@ -1803,7 +1803,7 @@ template <typename Type, typename std::enable_if_t<std::is_void<Type>::value> * = nullptr> inline void getProperty(ContextPtr ctx, int index, int position) { - duk_get_prop_index(ctx, index, position); + duk_get_prop_index(ctx, index, position); } /** @@ -1819,11 +1819,11 @@ template <typename Type, typename DefaultValue> inline auto optionalProperty(ContextPtr ctx, int index, const std::string &name, DefaultValue &&def) -> decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) { - duk_get_prop_string(ctx, index, name.c_str()); - decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) value = optional(ctx, -1, std::forward<DefaultValue>(def)); - duk_pop(ctx); + duk_get_prop_string(ctx, index, name.c_str()); + decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) value = optional(ctx, -1, std::forward<DefaultValue>(def)); + duk_pop(ctx); - return value; + return value; } /** @@ -1839,11 +1839,11 @@ template <typename Type, typename DefaultValue> inline auto optionalProperty(ContextPtr ctx, int index, int position, DefaultValue &&def) -> decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) { - duk_get_prop_index(ctx, index, position); - decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) value = optional(ctx, -1, std::forward<DefaultValue>(def)); - duk_pop(ctx); + duk_get_prop_index(ctx, index, position); + decltype(optional(ctx, 0, std::forward<DefaultValue>(def))) value = optional(ctx, -1, std::forward<DefaultValue>(def)); + duk_pop(ctx); - return value; + return value; } /** @@ -1858,10 +1858,10 @@ template <typename Type> void putProperty(ContextPtr ctx, int index, const std::string &name, Type &&value) { - index = duk_normalize_index(ctx, index); + index = duk_normalize_index(ctx, index); - push(ctx, std::forward<Type>(value)); - duk_put_prop_string(ctx, index, name.c_str()); + push(ctx, std::forward<Type>(value)); + duk_put_prop_string(ctx, index, name.c_str()); } /** @@ -1876,10 +1876,10 @@ template <typename Type> void putProperty(ContextPtr ctx, int index, int position, Type &&value) { - index = duk_normalize_index(ctx, index); + index = duk_normalize_index(ctx, index); - push(ctx, std::forward<Type>(value)); - duk_put_prop_index(ctx, index, position); + push(ctx, std::forward<Type>(value)); + duk_put_prop_index(ctx, index, position); } /** @@ -1892,11 +1892,11 @@ template <typename Type> inline auto getGlobal(ContextPtr ctx, const std::string &name, std::enable_if_t<!std::is_void<Type>::value> * = nullptr) -> decltype(get<Type>(ctx, 0)) { - duk_get_global_string(ctx, name.c_str()); - decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); - duk_pop(ctx); + duk_get_global_string(ctx, name.c_str()); + decltype(get<Type>(ctx, 0)) value = get<Type>(ctx, -1); + duk_pop(ctx); - return value; + return value; } /** @@ -1905,7 +1905,7 @@ template <typename Type> inline void getGlobal(ContextPtr ctx, const std::string &name, std::enable_if_t<std::is_void<Type>::value> * = nullptr) { - duk_get_global_string(ctx, name.c_str()); + duk_get_global_string(ctx, name.c_str()); } /** @@ -1918,8 +1918,8 @@ template <typename Type> inline void putGlobal(ContextPtr ctx, const std::string &name, Type&& type) { - push(ctx, std::forward<Type>(type)); - duk_put_global_string(ctx, name.c_str()); + push(ctx, std::forward<Type>(type)); + duk_put_global_string(ctx, name.c_str()); } /** @@ -1930,7 +1930,7 @@ */ inline void putGlobal(ContextPtr ctx, const std::string &name) { - duk_put_global_string(ctx, name.c_str()); + duk_put_global_string(ctx, name.c_str()); } /** @@ -1945,14 +1945,14 @@ template <typename Func> void enumerate(ContextPtr ctx, int index, duk_uint_t flags, duk_bool_t getvalue, Func &&func) { - duk_enum(ctx, index, flags); + duk_enum(ctx, index, flags); - while (duk_next(ctx, -1, getvalue)) { - func(ctx); - duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); - } + while (duk_next(ctx, -1, getvalue)) { + func(ctx); + duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); + } - duk_pop(ctx); + duk_pop(ctx); } /** @@ -1964,11 +1964,11 @@ template <typename T> inline auto self(ContextPtr ctx) -> decltype(TypeTraits<T>::require(ctx, 0)) { - duk_push_this(ctx); - decltype(TypeTraits<T>::require(ctx, 0)) value = TypeTraits<T>::require(ctx, -1); - duk_pop(ctx); + duk_push_this(ctx); + decltype(TypeTraits<T>::require(ctx, 0)) value = TypeTraits<T>::require(ctx, -1); + duk_pop(ctx); - return value; + return value; } /** @@ -1980,7 +1980,7 @@ template <typename Exception> void raise(ContextPtr ctx, const Exception &ex) { - ex.raise(ctx); + ex.raise(ctx); } /** @@ -1997,7 +1997,7 @@ template <typename T> inline void construct(ContextPtr ctx, T &&value) { - TypeTraits<std::decay_t<T>>::construct(ctx, std::forward<T>(value)); + TypeTraits<std::decay_t<T>>::construct(ctx, std::forward<T>(value)); } /** @@ -2011,43 +2011,43 @@ */ class Error { private: - int m_type{DUK_ERR_ERROR}; - std::string m_message; + int m_type{DUK_ERR_ERROR}; + std::string m_message; protected: - /** - * Constructor with a type of error specified, specially designed for derived errors. - * - * @param type of error (e.g. DUK_ERR_ERROR) - * @param message the message - */ - inline Error(int type, std::string message) noexcept - : m_type(type) - , m_message(std::move(message)) - { - } + /** + * Constructor with a type of error specified, specially designed for derived errors. + * + * @param type of error (e.g. DUK_ERR_ERROR) + * @param message the message + */ + inline Error(int type, std::string message) noexcept + : m_type(type) + , m_message(std::move(message)) + { + } public: - /** - * Constructor with a message. - * - * @param message the message - */ - inline Error(std::string message) noexcept - : m_message(std::move(message)) - { - } + /** + * Constructor with a message. + * + * @param message the message + */ + inline Error(std::string message) noexcept + : m_message(std::move(message)) + { + } - /** - * Create the exception on the stack. - * - * @note the default implementation search for the global variables - * @param ctx the context - */ - virtual void raise(ContextPtr ctx) const - { - duk_error(ctx, m_type, "%s", m_message.c_str()); - } + /** + * Create the exception on the stack. + * + * @note the default implementation search for the global variables + * @param ctx the context + */ + virtual void raise(ContextPtr ctx) const + { + duk_error(ctx, m_type, "%s", m_message.c_str()); + } }; /** @@ -2056,15 +2056,15 @@ */ class EvalError : public Error { public: - /** - * Construct an EvalError. - * - * @param message the message - */ - inline EvalError(std::string message) noexcept - : Error(DUK_ERR_EVAL_ERROR, std::move(message)) - { - } + /** + * Construct an EvalError. + * + * @param message the message + */ + inline EvalError(std::string message) noexcept + : Error(DUK_ERR_EVAL_ERROR, std::move(message)) + { + } }; /** @@ -2073,15 +2073,15 @@ */ class RangeError : public Error { public: - /** - * Construct an RangeError. - * - * @param message the message - */ - inline RangeError(std::string message) noexcept - : Error(DUK_ERR_RANGE_ERROR, std::move(message)) - { - } + /** + * Construct an RangeError. + * + * @param message the message + */ + inline RangeError(std::string message) noexcept + : Error(DUK_ERR_RANGE_ERROR, std::move(message)) + { + } }; /** @@ -2090,15 +2090,15 @@ */ class ReferenceError : public Error { public: - /** - * Construct an ReferenceError. - * - * @param message the message - */ - inline ReferenceError(std::string message) noexcept - : Error(DUK_ERR_REFERENCE_ERROR, std::move(message)) - { - } + /** + * Construct an ReferenceError. + * + * @param message the message + */ + inline ReferenceError(std::string message) noexcept + : Error(DUK_ERR_REFERENCE_ERROR, std::move(message)) + { + } }; /** @@ -2107,15 +2107,15 @@ */ class SyntaxError : public Error { public: - /** - * Construct an SyntaxError. - * - * @param message the message - */ - inline SyntaxError(std::string message) noexcept - : Error(DUK_ERR_SYNTAX_ERROR, std::move(message)) - { - } + /** + * Construct an SyntaxError. + * + * @param message the message + */ + inline SyntaxError(std::string message) noexcept + : Error(DUK_ERR_SYNTAX_ERROR, std::move(message)) + { + } }; /** @@ -2124,15 +2124,15 @@ */ class TypeError : public Error { public: - /** - * Construct an TypeError. - * - * @param message the message - */ - inline TypeError(std::string message) noexcept - : Error(DUK_ERR_TYPE_ERROR, std::move(message)) - { - } + /** + * Construct an TypeError. + * + * @param message the message + */ + inline TypeError(std::string message) noexcept + : Error(DUK_ERR_TYPE_ERROR, std::move(message)) + { + } }; /** @@ -2141,15 +2141,15 @@ */ class URIError : public Error { public: - /** - * Construct an URIError. - * - * @param message the message - */ - inline URIError(std::string message) noexcept - : Error(DUK_ERR_URI_ERROR, std::move(message)) - { - } + /** + * Construct an URIError. + * + * @param message the message + */ + inline URIError(std::string message) noexcept + : Error(DUK_ERR_URI_ERROR, std::move(message)) + { + } }; /* ------------------------------------------------------------------ @@ -2165,65 +2165,65 @@ template <> class TypeTraits<int> { public: - /** - * Get an integer, return 0 if not an integer. - * - * @param ctx the context - * @param index the index - * @return the integer - */ - static inline int get(ContextPtr ctx, int index) - { - return duk_get_int(ctx, index); - } + /** + * Get an integer, return 0 if not an integer. + * + * @param ctx the context + * @param index the index + * @return the integer + */ + static inline int get(ContextPtr ctx, int index) + { + return duk_get_int(ctx, index); + } - /** - * Check if value is an integer. - * - * @param ctx the context - * @param index the index - * @return true if integer - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_number(ctx, index); - } + /** + * Check if value is an integer. + * + * @param ctx the context + * @param index the index + * @return true if integer + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_number(ctx, index); + } - /** - * Get an integer, return defaultValue if the value is not an integer. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the integer or defaultValue - */ - static inline int optional(ContextPtr ctx, int index, int defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get an integer, return defaultValue if the value is not an integer. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the integer or defaultValue + */ + static inline int optional(ContextPtr ctx, int index, int defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push an integer. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, int value) - { - duk_push_int(ctx, value); - } + /** + * Push an integer. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, int value) + { + duk_push_int(ctx, value); + } - /** - * Require an integer, throws a JavaScript exception if not an integer. - * - * @param ctx the context - * @param index the index - * @return the integer - */ - static inline int require(ContextPtr ctx, int index) - { - return duk_require_int(ctx, index); - } + /** + * Require an integer, throws a JavaScript exception if not an integer. + * + * @param ctx the context + * @param index the index + * @return the integer + */ + static inline int require(ContextPtr ctx, int index) + { + return duk_require_int(ctx, index); + } }; /** @@ -2235,65 +2235,65 @@ template <> class TypeTraits<bool> { public: - /** - * Get a boolean, return 0 if not a boolean. - * - * @param ctx the context - * @param index the index - * @return the boolean - */ - static inline bool get(ContextPtr ctx, int index) - { - return duk_get_boolean(ctx, index); - } + /** + * Get a boolean, return 0 if not a boolean. + * + * @param ctx the context + * @param index the index + * @return the boolean + */ + static inline bool get(ContextPtr ctx, int index) + { + return duk_get_boolean(ctx, index); + } - /** - * Check if value is a boolean. - * - * @param ctx the context - * @param index the index - * @return true if boolean - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_boolean(ctx, index); - } + /** + * Check if value is a boolean. + * + * @param ctx the context + * @param index the index + * @return true if boolean + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_boolean(ctx, index); + } - /** - * Get a bool, return defaultValue if the value is not a boolean. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the boolean or defaultValue - */ - static inline bool optional(ContextPtr ctx, int index, bool defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get a bool, return defaultValue if the value is not a boolean. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the boolean or defaultValue + */ + static inline bool optional(ContextPtr ctx, int index, bool defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push a boolean. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, bool value) - { - duk_push_boolean(ctx, value); - } + /** + * Push a boolean. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, bool value) + { + duk_push_boolean(ctx, value); + } - /** - * Require a boolean, throws a JavaScript exception if not a boolean. - * - * @param ctx the context - * @param index the index - * @return the boolean - */ - static inline bool require(ContextPtr ctx, int index) - { - return duk_require_boolean(ctx, index); - } + /** + * Require a boolean, throws a JavaScript exception if not a boolean. + * + * @param ctx the context + * @param index the index + * @return the boolean + */ + static inline bool require(ContextPtr ctx, int index) + { + return duk_require_boolean(ctx, index); + } }; /** @@ -2305,65 +2305,65 @@ template <> class TypeTraits<double> { public: - /** - * Get a double, return 0 if not a double. - * - * @param ctx the context - * @param index the index - * @return the double - */ - static inline double get(ContextPtr ctx, int index) - { - return duk_get_number(ctx, index); - } + /** + * Get a double, return 0 if not a double. + * + * @param ctx the context + * @param index the index + * @return the double + */ + static inline double get(ContextPtr ctx, int index) + { + return duk_get_number(ctx, index); + } - /** - * Check if value is a double. - * - * @param ctx the context - * @param index the index - * @return true if double - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_number(ctx, index); - } + /** + * Check if value is a double. + * + * @param ctx the context + * @param index the index + * @return true if double + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_number(ctx, index); + } - /** - * Get a double, return defaultValue if the value is not a double. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the double or defaultValue - */ - static inline double optional(ContextPtr ctx, int index, double defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get a double, return defaultValue if the value is not a double. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the double or defaultValue + */ + static inline double optional(ContextPtr ctx, int index, double defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push a double. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, double value) - { - duk_push_number(ctx, value); - } + /** + * Push a double. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, double value) + { + duk_push_number(ctx, value); + } - /** - * Require a double, throws a JavaScript exception if not a double. - * - * @param ctx the context - * @param index the index - * @return the double - */ - static inline double require(ContextPtr ctx, int index) - { - return duk_require_number(ctx, index); - } + /** + * Require a double, throws a JavaScript exception if not a double. + * + * @param ctx the context + * @param index the index + * @return the double + */ + static inline double require(ContextPtr ctx, int index) + { + return duk_require_number(ctx, index); + } }; /** @@ -2377,71 +2377,71 @@ template <> class TypeTraits<std::string> { public: - /** - * Get a string, return 0 if not a string. - * - * @param ctx the context - * @param index the index - * @return the string - */ - static inline std::string get(ContextPtr ctx, int index) - { - duk_size_t size; - const char *text = duk_get_lstring(ctx, index, &size); + /** + * Get a string, return 0 if not a string. + * + * @param ctx the context + * @param index the index + * @return the string + */ + static inline std::string get(ContextPtr ctx, int index) + { + duk_size_t size; + const char *text = duk_get_lstring(ctx, index, &size); - return std::string{text, size}; - } + return std::string{text, size}; + } - /** - * Check if value is a string. - * - * @param ctx the context - * @param index the index - * @return true if string - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_string(ctx, index); - } + /** + * Check if value is a string. + * + * @param ctx the context + * @param index the index + * @return true if string + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_string(ctx, index); + } - /** - * Get a string, return defaultValue if the value is not an string. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the string or defaultValue - */ - static inline std::string optional(ContextPtr ctx, int index, std::string defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get a string, return defaultValue if the value is not an string. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the string or defaultValue + */ + static inline std::string optional(ContextPtr ctx, int index, std::string defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push a string. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, const std::string &value) - { - duk_push_lstring(ctx, value.c_str(), value.length()); - } + /** + * Push a string. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, const std::string &value) + { + duk_push_lstring(ctx, value.c_str(), value.length()); + } - /** - * Require a string, throws a JavaScript exception if not a string. - * - * @param ctx the context - * @param index the index - * @return the string - */ - static inline std::string require(ContextPtr ctx, int index) - { - duk_size_t size; - const char *text = duk_require_lstring(ctx, index, &size); + /** + * Require a string, throws a JavaScript exception if not a string. + * + * @param ctx the context + * @param index the index + * @return the string + */ + static inline std::string require(ContextPtr ctx, int index) + { + duk_size_t size; + const char *text = duk_require_lstring(ctx, index, &size); - return std::string{text, size}; - } + return std::string{text, size}; + } }; /** @@ -2453,65 +2453,65 @@ template <> class TypeTraits<const char *> { public: - /** - * Get a string, return 0 if not a string. - * - * @param ctx the context - * @param index the index - * @return the string - */ - static inline const char *get(ContextPtr ctx, int index) - { - return duk_get_string(ctx, index); - } + /** + * Get a string, return 0 if not a string. + * + * @param ctx the context + * @param index the index + * @return the string + */ + static inline const char *get(ContextPtr ctx, int index) + { + return duk_get_string(ctx, index); + } - /** - * Check if value is a string. - * - * @param ctx the context - * @param index the index - * @return true if string - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_string(ctx, index); - } + /** + * Check if value is a string. + * + * @param ctx the context + * @param index the index + * @return true if string + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_string(ctx, index); + } - /** - * Get an integer, return defaultValue if the value is not an integer. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the integer or defaultValue - */ - static inline const char *optional(ContextPtr ctx, int index, const char *defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get an integer, return defaultValue if the value is not an integer. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the integer or defaultValue + */ + static inline const char *optional(ContextPtr ctx, int index, const char *defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push a string. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, const char *value) - { - duk_push_string(ctx, value); - } + /** + * Push a string. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, const char *value) + { + duk_push_string(ctx, value); + } - /** - * Require a string, throws a JavaScript exception if not a string. - * - * @param ctx the context - * @param index the index - * @return the string - */ - static inline const char *require(ContextPtr ctx, int index) - { - return duk_require_string(ctx, index); - } + /** + * Require a string, throws a JavaScript exception if not a string. + * + * @param ctx the context + * @param index the index + * @return the string + */ + static inline const char *require(ContextPtr ctx, int index) + { + return duk_require_string(ctx, index); + } }; /** @@ -2523,65 +2523,65 @@ template <> class TypeTraits<unsigned> { public: - /** - * Get an integer, return 0 if not an integer. - * - * @param ctx the context - * @param index the index - * @return the integer - */ - static inline unsigned get(ContextPtr ctx, int index) - { - return duk_get_uint(ctx, index); - } + /** + * Get an integer, return 0 if not an integer. + * + * @param ctx the context + * @param index the index + * @return the integer + */ + static inline unsigned get(ContextPtr ctx, int index) + { + return duk_get_uint(ctx, index); + } - /** - * Check if value is an integer. - * - * @param ctx the context - * @param index the index - * @return true if integer - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_number(ctx, index); - } + /** + * Check if value is an integer. + * + * @param ctx the context + * @param index the index + * @return true if integer + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_number(ctx, index); + } - /** - * Get an integer, return defaultValue if the value is not an integer. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the integer or defaultValue - */ - static inline unsigned optional(ContextPtr ctx, int index, unsigned defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get an integer, return defaultValue if the value is not an integer. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the integer or defaultValue + */ + static inline unsigned optional(ContextPtr ctx, int index, unsigned defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push an integer. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, unsigned value) - { - duk_push_uint(ctx, value); - } + /** + * Push an integer. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, unsigned value) + { + duk_push_uint(ctx, value); + } - /** - * Require an integer, throws a JavaScript exception if not an integer. - * - * @param ctx the context - * @param index the index - * @return the integer - */ - static inline unsigned require(ContextPtr ctx, int index) - { - return duk_require_uint(ctx, index); - } + /** + * Require an integer, throws a JavaScript exception if not an integer. + * + * @param ctx the context + * @param index the index + * @return the integer + */ + static inline unsigned require(ContextPtr ctx, int index) + { + return duk_require_uint(ctx, index); + } }; /** @@ -2592,65 +2592,65 @@ template <typename T> class TypeTraits<T *> { public: - /** - * Get a pointer, return nullptr if not a pointer. - * - * @param ctx the context - * @param index the index - * @return the pointer - */ - static inline T *get(ContextPtr ctx, int index) - { - return static_cast<T *>(duk_to_pointer(ctx, index)); - } + /** + * Get a pointer, return nullptr if not a pointer. + * + * @param ctx the context + * @param index the index + * @return the pointer + */ + static inline T *get(ContextPtr ctx, int index) + { + return static_cast<T *>(duk_to_pointer(ctx, index)); + } - /** - * Check if value is a pointer. - * - * @param ctx the context - * @param index the index - * @return true if pointer - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_pointer(ctx, index); - } + /** + * Check if value is a pointer. + * + * @param ctx the context + * @param index the index + * @return true if pointer + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_pointer(ctx, index); + } - /** - * Get a pointer, return defaultValue if the value is not a pointer. - * - * @param ctx the context - * @param index the index - * @param defaultValue the defaultValue - * @return the pointer or defaultValue - */ - static inline T *optional(ContextPtr ctx, int index, T *defaultValue) - { - return is(ctx, index) ? get(ctx, index) : defaultValue; - } + /** + * Get a pointer, return defaultValue if the value is not a pointer. + * + * @param ctx the context + * @param index the index + * @param defaultValue the defaultValue + * @return the pointer or defaultValue + */ + static inline T *optional(ContextPtr ctx, int index, T *defaultValue) + { + return is(ctx, index) ? get(ctx, index) : defaultValue; + } - /** - * Push a pointer. - * - * @param ctx the context - * @param value the value - */ - static inline void push(ContextPtr ctx, T *value) - { - duk_push_pointer(ctx, value); - } + /** + * Push a pointer. + * + * @param ctx the context + * @param value the value + */ + static inline void push(ContextPtr ctx, T *value) + { + duk_push_pointer(ctx, value); + } - /** - * Require a pointer, throws a JavaScript exception if not a pointer. - * - * @param ctx the context - * @param index the index - * @return the pointer - */ - static inline T *require(ContextPtr ctx, int index) - { - return static_cast<T *>(duk_require_pointer(ctx, index)); - } + /** + * Require a pointer, throws a JavaScript exception if not a pointer. + * + * @param ctx the context + * @param index the index + * @return the pointer + */ + static inline T *require(ContextPtr ctx, int index) + { + return static_cast<T *>(duk_require_pointer(ctx, index)); + } }; /** @@ -2664,29 +2664,29 @@ template <> class TypeTraits<Function> { public: - /** - * Check if the value at the given index is callable. - * - * @param ctx the context - * @param index the value index - * @return true if the value is callable - */ - static bool is(ContextPtr ctx, Index index) - { - return duk_is_callable(ctx, index); - } + /** + * Check if the value at the given index is callable. + * + * @param ctx the context + * @param index the value index + * @return true if the value is callable + */ + static bool is(ContextPtr ctx, Index index) + { + return duk_is_callable(ctx, index); + } - /** - * Push the C++ function, it is wrapped as Duktape/C function and allocated on the heap by moving the - * std::function. - * - * @param ctx the context - * @param fn the function - */ - static void push(ContextPtr ctx, Function fn) - { - duk_push_c_function(ctx, fn.function, fn.nargs); - } + /** + * Push the C++ function, it is wrapped as Duktape/C function and allocated on the heap by moving the + * std::function. + * + * @param ctx the context + * @param fn the function + */ + static void push(ContextPtr ctx, Function fn) + { + duk_push_c_function(ctx, fn.function, fn.nargs); + } }; /** @@ -2698,21 +2698,21 @@ template <> class TypeTraits<FunctionMap> { public: - /** - * Push all functions to the object at the top of the stack. - * - * @param ctx the context - * @param map the map of function - */ - static void put(ContextPtr ctx, const FunctionMap &map) - { - StackAssert sa(ctx, 0); + /** + * Push all functions to the object at the top of the stack. + * + * @param ctx the context + * @param map the map of function + */ + static void put(ContextPtr ctx, const FunctionMap &map) + { + StackAssert sa(ctx, 0); - for (const auto &entry : map) { - duk_push_c_function(ctx, entry.second.function, entry.second.nargs); - duk_put_prop_string(ctx, -2, entry.first.c_str()); - } - } + for (const auto &entry : map) { + duk_push_c_function(ctx, entry.second.function, entry.second.nargs); + duk_put_prop_string(ctx, -2, entry.first.c_str()); + } + } }; /** @@ -2724,27 +2724,27 @@ template <> class TypeTraits<Object> { public: - /** - * Check if value is an object. - * - * @param ctx the context - * @param index the index - * @return true if object - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_object(ctx, index); - } + /** + * Check if value is an object. + * + * @param ctx the context + * @param index the index + * @return true if object + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_object(ctx, index); + } - /** - * Create an empty object on the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const Object &) - { - duk_push_object(ctx); - } + /** + * Create an empty object on the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const Object &) + { + duk_push_object(ctx); + } }; /** @@ -2756,27 +2756,27 @@ template <> class TypeTraits<Array> { public: - /** - * Check if value is a array. - * - * @param ctx the context - * @param index the index - * @return true if array - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_array(ctx, index); - } + /** + * Check if value is a array. + * + * @param ctx the context + * @param index the index + * @return true if array + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_array(ctx, index); + } - /** - * Create an empty array on the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const Array &) - { - duk_push_array(ctx); - } + /** + * Create an empty array on the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const Array &) + { + duk_push_array(ctx); + } }; /** @@ -2788,27 +2788,27 @@ template <> class TypeTraits<Undefined> { public: - /** - * Check if value is undefined. - * - * @param ctx the context - * @param index the index - * @return true if undefined - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_undefined(ctx, index); - } + /** + * Check if value is undefined. + * + * @param ctx the context + * @param index the index + * @return true if undefined + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_undefined(ctx, index); + } - /** - * Push undefined value on the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const Undefined &) - { - duk_push_undefined(ctx); - } + /** + * Push undefined value on the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const Undefined &) + { + duk_push_undefined(ctx); + } }; /** @@ -2820,27 +2820,27 @@ template <> class TypeTraits<Null> { public: - /** - * Check if value is null. - * - * @param ctx the context - * @param index the index - * @return true if null - */ - static inline bool is(ContextPtr ctx, int index) - { - return duk_is_null(ctx, index); - } + /** + * Check if value is null. + * + * @param ctx the context + * @param index the index + * @return true if null + */ + static inline bool is(ContextPtr ctx, int index) + { + return duk_is_null(ctx, index); + } - /** - * Push null value on the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const Null &) - { - duk_push_null(ctx); - } + /** + * Push null value on the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const Null &) + { + duk_push_null(ctx); + } }; /** @@ -2851,15 +2851,15 @@ template <> class TypeTraits<This> { public: - /** - * Push this function into the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const This &) - { - duk_push_this(ctx); - } + /** + * Push this function into the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const This &) + { + duk_push_this(ctx); + } }; /** @@ -2871,15 +2871,15 @@ template <> class TypeTraits<Global> { public: - /** - * Push the global object into the stack. - * - * @param ctx the context - */ - static inline void push(ContextPtr ctx, const Global &) - { - duk_push_global_object(ctx); - } + /** + * Push the global object into the stack. + * + * @param ctx the context + */ + static inline void push(ContextPtr ctx, const Global &) + { + duk_push_global_object(ctx); + } }; /** @@ -2892,39 +2892,39 @@ template <typename T> class TypeTraits<std::unordered_map<std::string, T>> { public: - /** - * Put all values from the map as properties to the object at the top of the stack. - * - * @param ctx the context - * @param map the values - * @note You need an object at the top of the stack before calling this function - */ - static void push(ContextPtr ctx, const std::unordered_map<std::string, T> &map) - { - StackAssert sa(ctx, 1); + /** + * Put all values from the map as properties to the object at the top of the stack. + * + * @param ctx the context + * @param map the values + * @note You need an object at the top of the stack before calling this function + */ + static void push(ContextPtr ctx, const std::unordered_map<std::string, T> &map) + { + StackAssert sa(ctx, 1); - duk_push_object(ctx); - put(ctx, map); - } + duk_push_object(ctx); + put(ctx, map); + } - /** - * Apply the map to the object at the top of the stack. - * - * @pre top value must be an object - * @param ctx the context - * @param map the map - */ - static void put(ContextPtr ctx, const std::unordered_map<std::string, T> &map) - { - assert(type(ctx, -1) == DUK_TYPE_OBJECT); + /** + * Apply the map to the object at the top of the stack. + * + * @pre top value must be an object + * @param ctx the context + * @param map the map + */ + static void put(ContextPtr ctx, const std::unordered_map<std::string, T> &map) + { + assert(type(ctx, -1) == DUK_TYPE_OBJECT); - StackAssert sa(ctx); + StackAssert sa(ctx); - for (const auto &pair : map) { - TypeTraits<T>::push(ctx, pair.second); - duk_put_prop_string(ctx, -2, pair.first.c_str()); - } - } + for (const auto &pair : map) { + TypeTraits<T>::push(ctx, pair.second); + duk_put_prop_string(ctx, -2, pair.first.c_str()); + } + } }; /** @@ -2935,63 +2935,63 @@ template <typename T> class TypeTraits<std::vector<T>> { public: - /** - * Get an array from the stack. - * - * @param ctx the context - * @param index the array index - * @return the array or empty array if the value is not an array - */ - static std::vector<T> get(ContextPtr ctx, int index) - { - StackAssert sa(ctx, 0); + /** + * Get an array from the stack. + * + * @param ctx the context + * @param index the array index + * @return the array or empty array if the value is not an array + */ + static std::vector<T> get(ContextPtr ctx, int index) + { + StackAssert sa(ctx, 0); - std::vector<T> result; + std::vector<T> result; - if (!duk_is_array(ctx, -1)) - return result; + if (!duk_is_array(ctx, -1)) + return result; - int total = duk_get_length(ctx, index); + int total = duk_get_length(ctx, index); - for (int i = 0; i < total; ++i) - result.push_back(getProperty<T>(ctx, index, i)); + for (int i = 0; i < total; ++i) + result.push_back(getProperty<T>(ctx, index, i)); - return result; - } + return result; + } - /** - * Create an array with the specified values. - * - * @param ctx the context - * @param array the values - */ - static void push(ContextPtr ctx, const std::vector<T> &array) - { - StackAssert sa(ctx, 1); + /** + * Create an array with the specified values. + * + * @param ctx the context + * @param array the values + */ + static void push(ContextPtr ctx, const std::vector<T> &array) + { + StackAssert sa(ctx, 1); - duk_push_array(ctx); - put(ctx, array); - } + duk_push_array(ctx); + put(ctx, array); + } - /** - * Apply the array to the object at the top of the stack. - * - * @pre top value must be an object - * @param ctx the context - * @param array the array - */ - static void put(ContextPtr ctx, const std::vector<T> &array) - { - assert(type(ctx, -1) == DUK_TYPE_OBJECT); + /** + * Apply the array to the object at the top of the stack. + * + * @pre top value must be an object + * @param ctx the context + * @param array the array + */ + static void put(ContextPtr ctx, const std::vector<T> &array) + { + assert(type(ctx, -1) == DUK_TYPE_OBJECT); - StackAssert sa(ctx); + StackAssert sa(ctx); - unsigned i = 0; - for (const auto &v : array) { - TypeTraits<T>::push(ctx, v); - duk_put_prop_index(ctx, -2, i++); - } - } + unsigned i = 0; + for (const auto &v : array) { + TypeTraits<T>::push(ctx, v); + duk_put_prop_index(ctx, -2, i++); + } + } }; /** @@ -3002,98 +3002,98 @@ template <typename T> class TypeTraits<std::shared_ptr<T>> { private: - static void apply(ContextPtr ctx, std::shared_ptr<T> value) - { - StackAssert sa(ctx, 0); + static void apply(ContextPtr ctx, std::shared_ptr<T> value) + { + StackAssert sa(ctx, 0); - duk_push_pointer(ctx, new std::shared_ptr<Bindable>(std::move(value))); - duk_put_prop_string(ctx, -2, "\xff""\xff""js-shared-ptr"); - duk_push_c_function(ctx, [] (duk_context *ctx) -> Ret { - duk_get_prop_string(ctx, 0, "\xff""\xff""js-shared-ptr"); - delete static_cast<std::shared_ptr<Bindable> *>(duk_to_pointer(ctx, -1)); - duk_pop(ctx); - duk_push_null(ctx); - duk_put_prop_string(ctx, 0, "\xff""\xff""js-shared-ptr"); + duk_push_pointer(ctx, new std::shared_ptr<Bindable>(std::move(value))); + duk_put_prop_string(ctx, -2, "\xff""\xff""js-shared-ptr"); + duk_push_c_function(ctx, [] (duk_context *ctx) -> Ret { + duk_get_prop_string(ctx, 0, "\xff""\xff""js-shared-ptr"); + delete static_cast<std::shared_ptr<Bindable> *>(duk_to_pointer(ctx, -1)); + duk_pop(ctx); + duk_push_null(ctx); + duk_put_prop_string(ctx, 0, "\xff""\xff""js-shared-ptr"); - return 0; - }, 1); - duk_set_finalizer(ctx, -2); - } + return 0; + }, 1); + duk_set_finalizer(ctx, -2); + } public: - /** - * Construct the shared_ptr as this. - * - * @param ctx the context - * @param value the value - */ - static void construct(ContextPtr ctx, std::shared_ptr<T> value) - { - static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); + /** + * Construct the shared_ptr as this. + * + * @param ctx the context + * @param value the value + */ + static void construct(ContextPtr ctx, std::shared_ptr<T> value) + { + static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); - StackAssert sa(ctx, 0); + StackAssert sa(ctx, 0); - duk_push_this(ctx); - apply(ctx, std::move(value)); - duk_pop(ctx); - } + duk_push_this(ctx); + apply(ctx, std::move(value)); + duk_pop(ctx); + } - /** - * Push a managed shared_ptr as object. - * - * @param ctx the context - * @param value the value - */ - static void push(ContextPtr ctx, std::shared_ptr<T> value) - { - static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); + /** + * Push a managed shared_ptr as object. + * + * @param ctx the context + * @param value the value + */ + static void push(ContextPtr ctx, std::shared_ptr<T> value) + { + static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); - StackAssert sa(ctx, 1); + StackAssert sa(ctx, 1); - duk_push_object(ctx); - apply(ctx, std::move(value)); - TypeTraits<T>::prototype(ctx); - duk_set_prototype(ctx, -2); - } + duk_push_object(ctx); + apply(ctx, std::move(value)); + TypeTraits<T>::prototype(ctx); + duk_set_prototype(ctx, -2); + } - /** - * Get a managed std::shared_ptr from the stack. - * - * @param ctx the context - * @param index the object index - * @return the pointer or a null if invalid - */ - static std::shared_ptr<T> get(ContextPtr ctx, Index index) - { - static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); + /** + * Get a managed std::shared_ptr from the stack. + * + * @param ctx the context + * @param index the object index + * @return the pointer or a null if invalid + */ + static std::shared_ptr<T> get(ContextPtr ctx, Index index) + { + static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); - StackAssert sa(ctx); + StackAssert sa(ctx); - auto ptr = getProperty<std::shared_ptr<Bindable> *>(ctx, index, "\xff""\xff""js-shared-ptr"); + auto ptr = getProperty<std::shared_ptr<Bindable> *>(ctx, index, "\xff""\xff""js-shared-ptr"); - return (ptr == nullptr) ? nullptr : std::dynamic_pointer_cast<T>(*ptr); - } + return (ptr == nullptr) ? nullptr : std::dynamic_pointer_cast<T>(*ptr); + } - /** - * Require a managed shared_ptr from the stack. - * - * Raise a JavaScript error if the object is not valid. - * - * @param ctx the context - * @param index the index - * @return the pointer - */ - static std::shared_ptr<T> require(ContextPtr ctx, Index index) - { - static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); + /** + * Require a managed shared_ptr from the stack. + * + * Raise a JavaScript error if the object is not valid. + * + * @param ctx the context + * @param index the index + * @return the pointer + */ + static std::shared_ptr<T> require(ContextPtr ctx, Index index) + { + static_assert(std::is_base_of<Bindable, T>::value, "T must be base of Bindable"); - auto ptr = get(ctx, index); + auto ptr = get(ctx, index); - if (!ptr) - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid this binding"); + if (!ptr) + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid this binding"); - return ptr; - } + return ptr; + } }; } // !duk
--- a/libcommon/malikania/json.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/json.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -33,311 +33,311 @@ Value readValue(json_t *v) { - if (json_is_null(v)) - return Value(nullptr); - if (json_is_string(v)) - return Value(json_string_value(v)); - if (json_is_real(v)) - return Value(json_number_value(v)); - if (json_is_integer(v)) - return Value(static_cast<int>(json_integer_value(v))); - if (json_is_boolean(v)) - return Value(json_boolean_value(v)); - if (json_is_object(v)) { - Value object(Type::Object); + if (json_is_null(v)) + return Value(nullptr); + if (json_is_string(v)) + return Value(json_string_value(v)); + if (json_is_real(v)) + return Value(json_number_value(v)); + if (json_is_integer(v)) + return Value(static_cast<int>(json_integer_value(v))); + if (json_is_boolean(v)) + return Value(json_boolean_value(v)); + if (json_is_object(v)) { + Value object(Type::Object); - readObject(object, v); + readObject(object, v); - return object; - } - if (json_is_array(v)) { - Value array(Type::Array); + return object; + } + if (json_is_array(v)) { + Value array(Type::Array); - readArray(array, v); + readArray(array, v); - return array; - } + return array; + } - return Value(); + return Value(); } void readObject(Value &parent, json_t *object) { - const char *key; - json_t *value; + const char *key; + json_t *value; - json_object_foreach(object, key, value) - parent.insert(key, readValue(value)); + json_object_foreach(object, key, value) + parent.insert(key, readValue(value)); } void readArray(Value &parent, json_t *array) { - size_t index; - json_t *value; + size_t index; + json_t *value; - json_array_foreach(array, index, value) - parent.append(readValue(value)); + json_array_foreach(array, index, value) + parent.append(readValue(value)); } template <typename Func, typename... Args> Value convert(Func fn, Args&&... args) { - json_error_t error; - json_t *json = fn(std::forward<Args>(args)..., &error); + json_error_t error; + json_t *json = fn(std::forward<Args>(args)..., &error); - if (json == nullptr) - throw Error(error.text, error.source, error.line, error.column, error.position); + if (json == nullptr) + throw Error(error.text, error.source, error.line, error.column, error.position); - Value value; + Value value; - if (json_is_object(json)) { - value = Value(Type::Object); - readObject(value, json); - } else { - value = Value(Type::Array); - readArray(value, json); - } + if (json_is_object(json)) { + value = Value(Type::Object); + readObject(value, json); + } else { + value = Value(Type::Array); + readArray(value, json); + } - json_decref(json); + json_decref(json); - return value; + return value; } std::string indent(int param, int level) { - std::string str; + std::string str; - if (param < 0) - str = std::string(level, '\t'); - else if (param > 0) - str = std::string(param * level, ' '); + if (param < 0) + str = std::string(level, '\t'); + else if (param > 0) + str = std::string(param * level, ' '); - return str; + return str; } } // !namespace void Value::copy(const Value &other) { - switch (other.m_type) { - case Type::Array: - new (&m_array) std::vector<Value>(other.m_array); - break; - case Type::Boolean: - m_boolean = other.m_boolean; - break; - case Type::Int: - m_integer = other.m_integer; - break; - case Type::Object: - new (&m_object) std::map<std::string, Value>(other.m_object); - break; - case Type::Real: - m_number = other.m_number; - break; - case Type::String: - new (&m_string) std::string(other.m_string); - break; - default: - break; - } + switch (other.m_type) { + case Type::Array: + new (&m_array) std::vector<Value>(other.m_array); + break; + case Type::Boolean: + m_boolean = other.m_boolean; + break; + case Type::Int: + m_integer = other.m_integer; + break; + case Type::Object: + new (&m_object) std::map<std::string, Value>(other.m_object); + break; + case Type::Real: + m_number = other.m_number; + break; + case Type::String: + new (&m_string) std::string(other.m_string); + break; + default: + break; + } - m_type = other.m_type; + m_type = other.m_type; } void Value::move(Value &&other) { - switch (other.m_type) { - case Type::Array: - new (&m_array) std::vector<Value>(std::move(other.m_array)); - break; - case Type::Boolean: - m_boolean = other.m_boolean; - break; - case Type::Int: - m_integer = other.m_integer; - break; - case Type::Object: - new (&m_object) std::map<std::string, Value>(std::move(other.m_object)); - break; - case Type::Real: - m_number = other.m_number; - break; - case Type::String: - new (&m_string) std::string(std::move(other.m_string)); - break; - default: - break; - } + switch (other.m_type) { + case Type::Array: + new (&m_array) std::vector<Value>(std::move(other.m_array)); + break; + case Type::Boolean: + m_boolean = other.m_boolean; + break; + case Type::Int: + m_integer = other.m_integer; + break; + case Type::Object: + new (&m_object) std::map<std::string, Value>(std::move(other.m_object)); + break; + case Type::Real: + m_number = other.m_number; + break; + case Type::String: + new (&m_string) std::string(std::move(other.m_string)); + break; + default: + break; + } - m_type = other.m_type; + m_type = other.m_type; } Value::Value(Type type) - : m_type(type) + : m_type(type) { - switch (m_type) { - case Type::Array: - new (&m_array) std::vector<Value>(); - break; - case Type::Boolean: - m_boolean = false; - break; - case Type::Int: - m_integer = 0; - break; - case Type::Object: - new (&m_object) std::map<std::string, Value>(); - break; - case Type::Real: - m_number = 0; - break; - case Type::String: - new (&m_string) std::string(); - break; - default: - break; - } + switch (m_type) { + case Type::Array: + new (&m_array) std::vector<Value>(); + break; + case Type::Boolean: + m_boolean = false; + break; + case Type::Int: + m_integer = 0; + break; + case Type::Object: + new (&m_object) std::map<std::string, Value>(); + break; + case Type::Real: + m_number = 0; + break; + case Type::String: + new (&m_string) std::string(); + break; + default: + break; + } } Value::~Value() { - switch (m_type) { - case Type::Array: - m_array.~vector<Value>(); - break; - case Type::Object: - m_object.~map<std::string, Value>(); - break; - case Type::String: - m_string.~basic_string(); - break; - default: - break; - } + switch (m_type) { + case Type::Array: + m_array.~vector<Value>(); + break; + case Type::Object: + m_object.~map<std::string, Value>(); + break; + case Type::String: + m_string.~basic_string(); + break; + default: + break; + } } std::string Value::toString(bool coerce) const { - std::string result; + std::string result; - if (m_type == Type::String) - result = m_string; - else if (coerce) - result = toJson(); + if (m_type == Type::String) + result = m_string; + else if (coerce) + result = toJson(); - return result; + return result; } std::string Value::toJson(int level, int current) const { - std::ostringstream oss; + std::ostringstream oss; - switch (m_type) { - case Type::Array: { - oss << '[' << (level != 0 ? "\n" : ""); + switch (m_type) { + case Type::Array: { + oss << '[' << (level != 0 ? "\n" : ""); - unsigned total = m_array.size(); - unsigned i = 0; - for (const auto &v : m_array) { - oss << indent(level, current + 1) << v.toJson(level, current + 1); - oss << (++i < total ? "," : ""); - oss << (level != 0 ? "\n" : ""); - } + unsigned total = m_array.size(); + unsigned i = 0; + for (const auto &v : m_array) { + oss << indent(level, current + 1) << v.toJson(level, current + 1); + oss << (++i < total ? "," : ""); + oss << (level != 0 ? "\n" : ""); + } - oss << (level != 0 ? indent(level, current) : "") << ']'; - break; - } - case Type::Boolean: - oss << (m_boolean ? "true" : "false"); - break; - case Type::Int: - oss << m_integer; - break; - case Type::Null: - oss << "null"; - break; - case Type::Object: { - oss << '{' << (level != 0 ? "\n" : ""); + oss << (level != 0 ? indent(level, current) : "") << ']'; + break; + } + case Type::Boolean: + oss << (m_boolean ? "true" : "false"); + break; + case Type::Int: + oss << m_integer; + break; + case Type::Null: + oss << "null"; + break; + case Type::Object: { + oss << '{' << (level != 0 ? "\n" : ""); - unsigned total = m_object.size(); - unsigned i = 0; - for (const auto &pair : m_object) { - oss << indent(level, current + 1); + unsigned total = m_object.size(); + unsigned i = 0; + for (const auto &pair : m_object) { + oss << indent(level, current + 1); - /* Key and : */ - oss << "\"" << pair.first << "\":" << (level != 0 ? " " : ""); + /* Key and : */ + oss << "\"" << pair.first << "\":" << (level != 0 ? " " : ""); - /* Value */ - oss << pair.second.toJson(level, current + 1); + /* Value */ + oss << pair.second.toJson(level, current + 1); - /* Comma, new line if needed */ - oss << (++i < total ? "," : "") << (level != 0 ? "\n" : ""); - } + /* Comma, new line if needed */ + oss << (++i < total ? "," : "") << (level != 0 ? "\n" : ""); + } - oss << (level != 0 ? indent(level, current) : "") << '}'; - break; - } - case Type::Real: - oss << m_number; - break; - case Type::String: - oss << "\"" << escape(m_string) << "\""; - break; - default: - break; - } + oss << (level != 0 ? indent(level, current) : "") << '}'; + break; + } + case Type::Real: + oss << m_number; + break; + case Type::String: + oss << "\"" << escape(m_string) << "\""; + break; + default: + break; + } - return oss.str(); + return oss.str(); } std::string escape(const std::string &value) { - std::string result; + std::string result; - for (auto it = value.begin(); it != value.end(); ++it) { - switch (*it) { - case '\\': - result += "\\\\"; - break; - case '/': - result += "\\/"; - break; - case '"': - result += "\\\""; - break; - case '\b': - result += "\\b"; - break; - case '\f': - result += "\\f"; - break; - case '\n': - result += "\\n"; - break; - case '\r': - result += "\\r"; - break; - case '\t': - result += "\\t"; - break; - default: - result += *it; - break; - } - } + for (auto it = value.begin(); it != value.end(); ++it) { + switch (*it) { + case '\\': + result += "\\\\"; + break; + case '/': + result += "\\/"; + break; + case '"': + result += "\\\""; + break; + case '\b': + result += "\\b"; + break; + case '\f': + result += "\\f"; + break; + case '\n': + result += "\\n"; + break; + case '\r': + result += "\\r"; + break; + case '\t': + result += "\\t"; + break; + default: + result += *it; + break; + } + } - return result; + return result; } Value fromString(const std::string &buffer) { - return convert(json_loads, buffer.c_str(), 0); + return convert(json_loads, buffer.c_str(), 0); } Value fromFile(const std::string &path) { - return convert(json_load_file, path.c_str(), 0); + return convert(json_load_file, path.c_str(), 0); } } // !json
--- a/libcommon/malikania/json.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/json.h Thu Jun 16 13:35:31 2016 +0200 @@ -44,13 +44,13 @@ * @brief Type of Value. */ enum class Type { - Array, //!< Value is an array [] - Boolean, //!< Value is boolean - Int, //!< Value is integer - Null, //!< Value is defined to null - Object, //!< Value is object {} - Real, //!< Value is float - String //!< Value is unicode string + Array, //!< Value is an array [] + Boolean, //!< Value is boolean + Int, //!< Value is integer + Null, //!< Value is defined to null + Object, //!< Value is object {} + Real, //!< Value is float + String //!< Value is unicode string }; /** @@ -59,90 +59,90 @@ */ class Error : public std::exception { private: - std::string m_text; - std::string m_source; - int m_line; - int m_column; - int m_position; + std::string m_text; + std::string m_source; + int m_line; + int m_column; + int m_position; public: - /** - * Create the error. - * - * @param text the text message - * @param source the source (e.g. file name) - * @param line the line number - * @param column the column number - * @param position the position - */ - inline Error(std::string text, std::string source, int line, int column, int position) noexcept - : m_text(std::move(text)) - , m_source(std::move(source)) - , m_line(line) - , m_column(column) - , m_position(position) - { - } + /** + * Create the error. + * + * @param text the text message + * @param source the source (e.g. file name) + * @param line the line number + * @param column the column number + * @param position the position + */ + inline Error(std::string text, std::string source, int line, int column, int position) noexcept + : m_text(std::move(text)) + , m_source(std::move(source)) + , m_line(line) + , m_column(column) + , m_position(position) + { + } - /** - * Get the error message. - * - * @return the text - */ - inline const std::string &text() const noexcept - { - return m_text; - } + /** + * Get the error message. + * + * @return the text + */ + inline const std::string &text() const noexcept + { + return m_text; + } - /** - * Get the source (e.g. a file name). - * - * @return the source - */ - inline const std::string &source() const noexcept - { - return m_source; - } + /** + * Get the source (e.g. a file name). + * + * @return the source + */ + inline const std::string &source() const noexcept + { + return m_source; + } - /** - * Get the line. - * - * @return the line - */ - inline int line() const noexcept - { - return m_line; - } + /** + * Get the line. + * + * @return the line + */ + inline int line() const noexcept + { + return m_line; + } - /** - * Get the column. - * - * @return the column - */ - inline int column() const noexcept - { - return m_column; - } + /** + * Get the column. + * + * @return the column + */ + inline int column() const noexcept + { + return m_column; + } - /** - * Get the position. - * - * @return the position - */ - inline int position() const noexcept - { - return m_position; - } + /** + * Get the position. + * + * @return the position + */ + inline int position() const noexcept + { + return m_position; + } - /** - * Get the error message. - * - * @return the message - */ - const char *what() const noexcept override - { - return m_text.c_str(); - } + /** + * Get the error message. + * + * @return the message + */ + const char *what() const noexcept override + { + return m_text.c_str(); + } }; /** @@ -157,156 +157,156 @@ template <typename ValueType, typename ArrayIteratorType, typename ObjectIteratorType> class Iterator : public std::iterator<std::forward_iterator_tag, ValueType> { private: - friend class Value; + friend class Value; - ValueType *m_parent{nullptr}; - ArrayIteratorType m_ita; - ObjectIteratorType m_itm; + ValueType *m_parent{nullptr}; + ArrayIteratorType m_ita; + ObjectIteratorType m_itm; - inline void increment() - { - if (m_parent->isObject()) - m_itm++; - else - m_ita++; - } + inline void increment() + { + if (m_parent->isObject()) + m_itm++; + else + m_ita++; + } - inline Iterator(ValueType *parent, ObjectIteratorType it) - : m_parent(parent) - , m_itm(it) - { - assert(parent); - } + inline Iterator(ValueType *parent, ObjectIteratorType it) + : m_parent(parent) + , m_itm(it) + { + assert(parent); + } - inline Iterator(ValueType *parent, ArrayIteratorType it) - : m_parent(parent) - , m_ita(it) - { - assert(parent); - } + inline Iterator(ValueType *parent, ArrayIteratorType it) + : m_parent(parent) + , m_ita(it) + { + assert(parent); + } public: - /** - * Default constructor. - */ - Iterator() = default; + /** + * Default constructor. + */ + Iterator() = default; - /** - * Get the iterator key (for objects). - * - * @pre iterator must be dereferenceable - * @pre iterator must come from object - * @return the key - */ - inline const std::string &key() const noexcept - { - assert(m_parent && m_parent->isObject()); - assert(m_itm != m_parent->m_object.end()); + /** + * Get the iterator key (for objects). + * + * @pre iterator must be dereferenceable + * @pre iterator must come from object + * @return the key + */ + inline const std::string &key() const noexcept + { + assert(m_parent && m_parent->isObject()); + assert(m_itm != m_parent->m_object.end()); - return m_itm->first; - } + return m_itm->first; + } - /** - * Get the iterator position (for arrays). - * - * @pre iterator must be dereferenceable - * @pre iterator must come from arrays - * @return the index - */ - inline unsigned index() const noexcept - { - assert(m_parent && m_parent->isArray()); - assert(m_ita != m_parent->m_array.end()); + /** + * Get the iterator position (for arrays). + * + * @pre iterator must be dereferenceable + * @pre iterator must come from arrays + * @return the index + */ + inline unsigned index() const noexcept + { + assert(m_parent && m_parent->isArray()); + assert(m_ita != m_parent->m_array.end()); - return std::distance(m_parent->m_array.begin(), m_ita); - } + return std::distance(m_parent->m_array.begin(), m_ita); + } - /** - * Dereference the iterator. - * - * @pre iterator be dereferenceable - * @return the value - */ - inline ValueType &operator*() noexcept - { - assert(m_parent); - assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || - (m_parent->isObject() && m_itm != m_parent->m_object.end())); + /** + * Dereference the iterator. + * + * @pre iterator be dereferenceable + * @return the value + */ + inline ValueType &operator*() noexcept + { + assert(m_parent); + assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || + (m_parent->isObject() && m_itm != m_parent->m_object.end())); - return (m_parent->m_type == Type::Object) ? m_itm->second : *m_ita; - } + return (m_parent->m_type == Type::Object) ? m_itm->second : *m_ita; + } - /** - * Dereference the iterator as a pointer. - * - * @pre iterator must be dereferenceable - * @return the value - */ - inline ValueType *operator->() noexcept - { - assert(m_parent); - assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || - (m_parent->isObject() && m_itm != m_parent->m_object.end())); + /** + * Dereference the iterator as a pointer. + * + * @pre iterator must be dereferenceable + * @return the value + */ + inline ValueType *operator->() noexcept + { + assert(m_parent); + assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || + (m_parent->isObject() && m_itm != m_parent->m_object.end())); - return (m_parent->m_type == Type::Object) ? &m_itm->second : &(*m_ita); - } + return (m_parent->m_type == Type::Object) ? &m_itm->second : &(*m_ita); + } - /** - * Increment the iterator. (Prefix version). - * - * @pre iterator must be dereferenceable - * @return *this; - */ - inline Iterator &operator++() noexcept - { - assert(m_parent); - assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || - (m_parent->isObject() && m_itm != m_parent->m_object.end())); + /** + * Increment the iterator. (Prefix version). + * + * @pre iterator must be dereferenceable + * @return *this; + */ + inline Iterator &operator++() noexcept + { + assert(m_parent); + assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || + (m_parent->isObject() && m_itm != m_parent->m_object.end())); - increment(); + increment(); - return *this; - } + return *this; + } - /** - * Increment the iterator. (Postfix version). - * - * @pre iterator must be dereferenceable - * @return *this; - */ - inline Iterator &operator++(int) noexcept - { - assert(m_parent); - assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || - (m_parent->isObject() && m_itm != m_parent->m_object.end())); + /** + * Increment the iterator. (Postfix version). + * + * @pre iterator must be dereferenceable + * @return *this; + */ + inline Iterator &operator++(int) noexcept + { + assert(m_parent); + assert((m_parent->isArray() && m_ita != m_parent->m_array.end()) || + (m_parent->isObject() && m_itm != m_parent->m_object.end())); - increment(); + increment(); - return *this; - } + return *this; + } - /** - * Compare two iterators. - * - * @param it1 the first iterator - * @param it2 the second iterator - * @return true if they are same - */ - bool operator==(const Iterator &it) const noexcept - { - return m_parent == it.m_parent && m_itm == it.m_itm && m_ita == it.m_ita; - } + /** + * Compare two iterators. + * + * @param it1 the first iterator + * @param it2 the second iterator + * @return true if they are same + */ + bool operator==(const Iterator &it) const noexcept + { + return m_parent == it.m_parent && m_itm == it.m_itm && m_ita == it.m_ita; + } - /** - * Test if the iterator is different. - * - * @param it the iterator - * @return true if they are different - */ - inline bool operator!=(const Iterator &it) const noexcept - { - return !(*this == it); - } + /** + * Test if the iterator is different. + * + * @param it the iterator + * @return true if they are different + */ + inline bool operator!=(const Iterator &it) const noexcept + { + return !(*this == it); + } }; /** @@ -315,814 +315,814 @@ */ class Value { private: - Type m_type{Type::Null}; + Type m_type{Type::Null}; - union { - double m_number; - bool m_boolean; - int m_integer; - std::string m_string; - std::vector<Value> m_array; - std::map<std::string, Value> m_object; - }; + union { + double m_number; + bool m_boolean; + int m_integer; + std::string m_string; + std::vector<Value> m_array; + std::map<std::string, Value> m_object; + }; - void copy(const Value &); - void move(Value &&); - std::string toJson(int indent, int current) const; + void copy(const Value &); + void move(Value &&); + std::string toJson(int indent, int current) const; - friend class Iterator<Value, typename std::vector<Value>::iterator, typename std::map<std::string, Value>::iterator>; - friend class Iterator<const Value, typename std::vector<Value>::const_iterator, typename std::map<std::string, Value>::const_iterator>; + friend class Iterator<Value, typename std::vector<Value>::iterator, typename std::map<std::string, Value>::iterator>; + friend class Iterator<const Value, typename std::vector<Value>::const_iterator, typename std::map<std::string, Value>::const_iterator>; public: - /** - * Forward iterator. - */ - using iterator = Iterator<Value, typename std::vector<Value>::iterator, typename std::map<std::string, Value>::iterator>; + /** + * Forward iterator. + */ + using iterator = Iterator<Value, typename std::vector<Value>::iterator, typename std::map<std::string, Value>::iterator>; - /** - * Const forward iterator. - */ - using const_iterator = Iterator<const Value, typename std::vector<Value>::const_iterator, typename std::map<std::string, Value>::const_iterator>; + /** + * Const forward iterator. + */ + using const_iterator = Iterator<const Value, typename std::vector<Value>::const_iterator, typename std::map<std::string, Value>::const_iterator>; - /** - * Construct a null value. - */ - inline Value() noexcept - { - } + /** + * Construct a null value. + */ + inline Value() noexcept + { + } - /** - * Create a value with a specified type, this is usually only needed when you want to create an object or - * an array. - * - * For any other types, initialize with sane default value. - * - * @param type the type - */ - Value(Type type); + /** + * Create a value with a specified type, this is usually only needed when you want to create an object or + * an array. + * + * For any other types, initialize with sane default value. + * + * @param type the type + */ + Value(Type type); - /** - * Construct a null value. - */ - inline Value(std::nullptr_t) noexcept - : m_type(Type::Null) - { - } + /** + * Construct a null value. + */ + inline Value(std::nullptr_t) noexcept + : m_type(Type::Null) + { + } - /** - * Construct a boolean value. - * - * @param value the boolean value - */ - inline Value(bool value) noexcept - : m_type(Type::Boolean) - , m_boolean(value) - { - } + /** + * Construct a boolean value. + * + * @param value the boolean value + */ + inline Value(bool value) noexcept + : m_type(Type::Boolean) + , m_boolean(value) + { + } - /** - * Create value from integer. - * - * @param value the value - */ - inline Value(int value) noexcept - : m_type(Type::Int) - , m_integer(value) - { - } + /** + * Create value from integer. + * + * @param value the value + */ + inline Value(int value) noexcept + : m_type(Type::Int) + , m_integer(value) + { + } - /** - * Construct a value from a C-string. - * - * @param value the C-string - */ - inline Value(const char *value) - : m_type(Type::String) - { - new (&m_string) std::string{value ? value : ""}; - } + /** + * Construct a value from a C-string. + * + * @param value the C-string + */ + inline Value(const char *value) + : m_type(Type::String) + { + new (&m_string) std::string{value ? value : ""}; + } - /** - * Construct a number value. - * - * @param value the real value - */ - inline Value(double value) noexcept - : m_type(Type::Real) - , m_number(value) - { - } + /** + * Construct a number value. + * + * @param value the real value + */ + inline Value(double value) noexcept + : m_type(Type::Real) + , m_number(value) + { + } - /** - * Construct a string value. - * - * @param value the string - */ - inline Value(std::string value) noexcept - : m_type(Type::String) - { - new (&m_string) std::string(std::move(value)); - } + /** + * Construct a string value. + * + * @param value the string + */ + inline Value(std::string value) noexcept + : m_type(Type::String) + { + new (&m_string) std::string(std::move(value)); + } - /** - * Create an object from a map. - * - * @param values the values - * @see fromObject - */ - inline Value(std::map<std::string, Value> values) - : Value(Type::Object) - { - for (const auto &pair : values) - insert(pair.first, pair.second); - } + /** + * Create an object from a map. + * + * @param values the values + * @see fromObject + */ + inline Value(std::map<std::string, Value> values) + : Value(Type::Object) + { + for (const auto &pair : values) + insert(pair.first, pair.second); + } - /** - * Create an array from a vector. - * - * @param values the values - * @see fromArray - */ - inline Value(std::vector<Value> values) - : Value(Type::Array) - { - for (Value value : values) - append(std::move(value)); - } + /** + * Create an array from a vector. + * + * @param values the values + * @see fromArray + */ + inline Value(std::vector<Value> values) + : Value(Type::Array) + { + for (Value value : values) + append(std::move(value)); + } - /** - * Move constructor. - * - * @param other the value to move from - */ - inline Value(Value &&other) - { - move(std::move(other)); - } + /** + * Move constructor. + * + * @param other the value to move from + */ + inline Value(Value &&other) + { + move(std::move(other)); + } - /** - * Copy constructor. - * - * @param other the value to copy from - */ - inline Value(const Value &other) - { - copy(other); - } + /** + * Copy constructor. + * + * @param other the value to copy from + */ + inline Value(const Value &other) + { + copy(other); + } - /** - * Copy operator. - * - * @param other the value to copy from - * @return *this - */ - inline Value &operator=(const Value &other) - { - copy(other); + /** + * Copy operator. + * + * @param other the value to copy from + * @return *this + */ + inline Value &operator=(const Value &other) + { + copy(other); - return *this; - } + return *this; + } - /** - * Move operator. - * - * @param other the value to move from - */ - inline Value &operator=(Value &&other) - { - move(std::move(other)); + /** + * Move operator. + * + * @param other the value to move from + */ + inline Value &operator=(Value &&other) + { + move(std::move(other)); - return *this; - } + return *this; + } - /** - * Destructor. - */ - ~Value(); + /** + * Destructor. + */ + ~Value(); - /** - * Get an iterator to the beginning. - * - * @pre must be an array or object - * @return the iterator - */ - inline iterator begin() noexcept - { - assert(isArray() || isObject()); + /** + * Get an iterator to the beginning. + * + * @pre must be an array or object + * @return the iterator + */ + inline iterator begin() noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? iterator(this, m_object.begin()) : iterator(this, m_array.begin()); - } + return m_type == Type::Object ? iterator(this, m_object.begin()) : iterator(this, m_array.begin()); + } - /** - * Overloaded function. - * - * @pre must be an array or object - * @return the iterator - */ - inline const_iterator begin() const noexcept - { - assert(isArray() || isObject()); + /** + * Overloaded function. + * + * @pre must be an array or object + * @return the iterator + */ + inline const_iterator begin() const noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? const_iterator(this, m_object.begin()) : const_iterator(this, m_array.begin()); - } + return m_type == Type::Object ? const_iterator(this, m_object.begin()) : const_iterator(this, m_array.begin()); + } - /** - * Overloaded function. - * - * @pre must be an array or object - * @return the iterator - */ - inline const_iterator cbegin() const noexcept - { - assert(isArray() || isObject()); + /** + * Overloaded function. + * + * @pre must be an array or object + * @return the iterator + */ + inline const_iterator cbegin() const noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? const_iterator(this, m_object.cbegin()) : const_iterator(this, m_array.cbegin()); - } + return m_type == Type::Object ? const_iterator(this, m_object.cbegin()) : const_iterator(this, m_array.cbegin()); + } - /** - * Get an iterator to the end. - * - * @pre must be an array or object - * @return the iterator - */ - inline iterator end() noexcept - { - assert(isArray() || isObject()); + /** + * Get an iterator to the end. + * + * @pre must be an array or object + * @return the iterator + */ + inline iterator end() noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? iterator(this, m_object.end()) : iterator(this, m_array.end()); - } + return m_type == Type::Object ? iterator(this, m_object.end()) : iterator(this, m_array.end()); + } - /** - * Get an iterator to the end. - * - * @pre must be an array or object - * @return the iterator - */ - inline const_iterator end() const noexcept - { - assert(isArray() || isObject()); + /** + * Get an iterator to the end. + * + * @pre must be an array or object + * @return the iterator + */ + inline const_iterator end() const noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? const_iterator(this, m_object.end()) : const_iterator(this, m_array.end()); - } + return m_type == Type::Object ? const_iterator(this, m_object.end()) : const_iterator(this, m_array.end()); + } - /** - * Get an iterator to the end. - * - * @pre must be an array or object - * @return the iterator - */ - inline const_iterator cend() const noexcept - { - assert(isArray() || isObject()); + /** + * Get an iterator to the end. + * + * @pre must be an array or object + * @return the iterator + */ + inline const_iterator cend() const noexcept + { + assert(isArray() || isObject()); - return m_type == Type::Object ? const_iterator(this, m_object.cend()) : const_iterator(this, m_array.cend()); - } + return m_type == Type::Object ? const_iterator(this, m_object.cend()) : const_iterator(this, m_array.cend()); + } - /** - * Get the value type. - * - * @return the type - */ - inline Type typeOf() const noexcept - { - return m_type; - } + /** + * Get the value type. + * + * @return the type + */ + inline Type typeOf() const noexcept + { + return m_type; + } - /** - * Get the value as boolean. - * - * @return the value or false if not a boolean - */ - inline bool toBool() const noexcept - { - return m_type != Type::Boolean ? false : m_boolean; - } + /** + * Get the value as boolean. + * + * @return the value or false if not a boolean + */ + inline bool toBool() const noexcept + { + return m_type != Type::Boolean ? false : m_boolean; + } - /** - * Get the value as integer. - * - * @return the value or 0 if not a integer - */ - inline int toInt() const noexcept - { - return m_type != Type::Int ? 0 : m_integer; - } + /** + * Get the value as integer. + * + * @return the value or 0 if not a integer + */ + inline int toInt() const noexcept + { + return m_type != Type::Int ? 0 : m_integer; + } - /** - * Get the value as real. - * - * @return the value or 0 if not a real - */ - inline double toReal() const noexcept - { - return m_type != Type::Real ? 0 : m_number; - } + /** + * Get the value as real. + * + * @return the value or 0 if not a real + */ + inline double toReal() const noexcept + { + return m_type != Type::Real ? 0 : m_number; + } - /** - * Get the value as string. - * - * @param coerce set to true to coerce the value if not a string - * @return the value or empty string if not a string - */ - std::string toString(bool coerce = false) const; + /** + * Get the value as string. + * + * @param coerce set to true to coerce the value if not a string + * @return the value or empty string if not a string + */ + std::string toString(bool coerce = false) const; - /** - * Check if the value is boolean type. - * - * @return true if boolean - */ - inline bool isBool() const noexcept - { - return m_type == Type::Boolean; - } + /** + * Check if the value is boolean type. + * + * @return true if boolean + */ + inline bool isBool() const noexcept + { + return m_type == Type::Boolean; + } - /** - * Check if the value is integer type. - * - * @return true if integer - */ - inline bool isInt() const noexcept - { - return m_type == Type::Int; - } + /** + * Check if the value is integer type. + * + * @return true if integer + */ + inline bool isInt() const noexcept + { + return m_type == Type::Int; + } - /** - * Check if the value is object type. - * - * @return true if object - */ - inline bool isObject() const noexcept - { - return m_type == Type::Object; - } + /** + * Check if the value is object type. + * + * @return true if object + */ + inline bool isObject() const noexcept + { + return m_type == Type::Object; + } - /** - * Check if the value is array type. - * - * @return true if array - */ - inline bool isArray() const noexcept - { - return m_type == Type::Array; - } + /** + * Check if the value is array type. + * + * @return true if array + */ + inline bool isArray() const noexcept + { + return m_type == Type::Array; + } - /** - * Check if the value is integer or real type. - * - * @return true if integer or real - * @see toInt - * @see toReal - */ - inline bool isNumber() const noexcept - { - return m_type == Type::Real || m_type == Type::Int; - } + /** + * Check if the value is integer or real type. + * + * @return true if integer or real + * @see toInt + * @see toReal + */ + inline bool isNumber() const noexcept + { + return m_type == Type::Real || m_type == Type::Int; + } - /** - * Check if the value is real type. - * - * @return true if real - */ - inline bool isReal() const noexcept - { - return m_type == Type::Real; - } + /** + * Check if the value is real type. + * + * @return true if real + */ + inline bool isReal() const noexcept + { + return m_type == Type::Real; + } - /** - * Check if the value is null type. - * - * @return true if null - */ - inline bool isNull() const noexcept - { - return m_type == Type::Null; - } + /** + * Check if the value is null type. + * + * @return true if null + */ + inline bool isNull() const noexcept + { + return m_type == Type::Null; + } - /** - * Check if the value is string type. - * - * @return true if string - */ - inline bool isString() const noexcept - { - return m_type == Type::String; - } + /** + * Check if the value is string type. + * + * @return true if string + */ + inline bool isString() const noexcept + { + return m_type == Type::String; + } - /** - * Get the array or object size. - * - * @pre must be an array or object - * @return the size - */ - inline unsigned size() const noexcept - { - assert(isArray() || isObject()); + /** + * Get the array or object size. + * + * @pre must be an array or object + * @return the size + */ + inline unsigned size() const noexcept + { + assert(isArray() || isObject()); - if (m_type == Type::Object) - return m_object.size(); + if (m_type == Type::Object) + return m_object.size(); - return m_array.size(); - } + return m_array.size(); + } - /** - * Remove all the values. - * - * @pre must be an array or an object - */ - inline void clear() noexcept - { - assert(isArray() || isObject()); + /** + * Remove all the values. + * + * @pre must be an array or an object + */ + inline void clear() noexcept + { + assert(isArray() || isObject()); - if (m_type == Type::Array) - m_array.clear(); - else - m_object.clear(); - } + if (m_type == Type::Array) + m_array.clear(); + else + m_object.clear(); + } - /* - * Array functions - * ---------------------------------------------------------- - */ + /* + * Array functions + * ---------------------------------------------------------- + */ - /** - * Get the value at the specified position or the defaultValue if position is out of bounds. - * - * @param position the position - * @param defaultValue the value replacement - * @return the value or defaultValue - */ - template <typename DefaultValue> - inline Value valueOr(unsigned position, DefaultValue &&defaultValue) const - { - if (m_type != Type::Array || position >= m_array.size()) - return defaultValue; + /** + * Get the value at the specified position or the defaultValue if position is out of bounds. + * + * @param position the position + * @param defaultValue the value replacement + * @return the value or defaultValue + */ + template <typename DefaultValue> + inline Value valueOr(unsigned position, DefaultValue &&defaultValue) const + { + if (m_type != Type::Array || position >= m_array.size()) + return defaultValue; - return m_array[position]; - } + return m_array[position]; + } - /** - * Overloaded function with type check. - * - * @param position the position - * @param type the requested type - * @param defaultValue the value replacement - * @return the value or defaultValue - */ - template <typename DefaultValue> - inline Value valueOr(unsigned position, Type type, DefaultValue &&defaultValue) const - { - if (m_type != Type::Array || position >= m_array.size() || m_array[position].typeOf() != type) - return defaultValue; + /** + * Overloaded function with type check. + * + * @param position the position + * @param type the requested type + * @param defaultValue the value replacement + * @return the value or defaultValue + */ + template <typename DefaultValue> + inline Value valueOr(unsigned position, Type type, DefaultValue &&defaultValue) const + { + if (m_type != Type::Array || position >= m_array.size() || m_array[position].typeOf() != type) + return defaultValue; - return m_array[position]; - } + return m_array[position]; + } - /** - * Get a value at the specified index. - * - * @pre must be an array - * @param position the position - * @return the value - * @throw std::out_of_range if out of bounds - */ - inline const Value &at(unsigned position) const - { - assert(isArray()); + /** + * Get a value at the specified index. + * + * @pre must be an array + * @param position the position + * @return the value + * @throw std::out_of_range if out of bounds + */ + inline const Value &at(unsigned position) const + { + assert(isArray()); - return m_array.at(position); - } + return m_array.at(position); + } - /** - * Overloaded function. - * - * @pre must be an array - * @param position the position - * @return the value - * @throw std::out_of_range if out of bounds - */ - inline Value &at(unsigned position) - { - assert(isArray()); + /** + * Overloaded function. + * + * @pre must be an array + * @param position the position + * @return the value + * @throw std::out_of_range if out of bounds + */ + inline Value &at(unsigned position) + { + assert(isArray()); - return m_array.at(position); - } + return m_array.at(position); + } - /** - * Get a value at the specified index. - * - * @pre must be an array - * @pre position must be valid - * @param position the position - * @return the value - */ - inline const Value &operator[](unsigned position) const - { - assert(isArray()); - assert(position < m_array.size()); + /** + * Get a value at the specified index. + * + * @pre must be an array + * @pre position must be valid + * @param position the position + * @return the value + */ + inline const Value &operator[](unsigned position) const + { + assert(isArray()); + assert(position < m_array.size()); - return m_array[position]; - } + return m_array[position]; + } - /** - * Overloaded function. - * - * @pre must be an array - * @pre position must be valid - * @param position the position - * @return the value - */ - inline Value &operator[](unsigned position) - { - assert(isArray()); - assert(position < m_array.size()); + /** + * Overloaded function. + * + * @pre must be an array + * @pre position must be valid + * @param position the position + * @return the value + */ + inline Value &operator[](unsigned position) + { + assert(isArray()); + assert(position < m_array.size()); - return m_array[position]; - } + return m_array[position]; + } - /** - * Push a value to the beginning of the array. - * - * @pre must be an array - * @param value the value to push - */ - inline void push(const Value &value) - { - assert(isArray()); + /** + * Push a value to the beginning of the array. + * + * @pre must be an array + * @param value the value to push + */ + inline void push(const Value &value) + { + assert(isArray()); - m_array.insert(m_array.begin(), value); - } + m_array.insert(m_array.begin(), value); + } - /** - * Overloaded function. - * - * @pre must be an array - * @param value the value to push - */ - inline void push(Value &&value) - { - assert(isArray()); + /** + * Overloaded function. + * + * @pre must be an array + * @param value the value to push + */ + inline void push(Value &&value) + { + assert(isArray()); - m_array.insert(m_array.begin(), std::move(value)); - } + m_array.insert(m_array.begin(), std::move(value)); + } - /** - * Insert a value at the specified position. - * - * @pre must be an array - * @pre position must be valid - * @param position the position - * @param value the value to push - */ - inline void insert(unsigned position, const Value &value) - { - assert(isArray()); - assert(position <= m_array.size()); + /** + * Insert a value at the specified position. + * + * @pre must be an array + * @pre position must be valid + * @param position the position + * @param value the value to push + */ + inline void insert(unsigned position, const Value &value) + { + assert(isArray()); + assert(position <= m_array.size()); - m_array.insert(m_array.begin() + position, value); - } + m_array.insert(m_array.begin() + position, value); + } - /** - * Overloaded function. - * - * @pre must be an array - * @pre position must be valid - * @param position the position - * @param value the value to push - */ - inline void insert(unsigned position, Value &&value) - { - assert(isArray()); - assert(position <= m_array.size()); + /** + * Overloaded function. + * + * @pre must be an array + * @pre position must be valid + * @param position the position + * @param value the value to push + */ + inline void insert(unsigned position, Value &&value) + { + assert(isArray()); + assert(position <= m_array.size()); - m_array.insert(m_array.begin() + position, std::move(value)); - } + m_array.insert(m_array.begin() + position, std::move(value)); + } - /** - * Add a new value to the end. - * - * @pre must be an array - * @param value the value to append - */ - inline void append(const Value &value) - { - assert(isArray()); + /** + * Add a new value to the end. + * + * @pre must be an array + * @param value the value to append + */ + inline void append(const Value &value) + { + assert(isArray()); - m_array.push_back(value); - } + m_array.push_back(value); + } - /** - * Overloaded function. - * - * @pre must be an array - * @param value the value to append - */ - inline void append(Value &&value) - { - assert(isArray()); + /** + * Overloaded function. + * + * @pre must be an array + * @param value the value to append + */ + inline void append(Value &&value) + { + assert(isArray()); - m_array.push_back(std::move(value)); - } + m_array.push_back(std::move(value)); + } - /** - * Remove a value at the specified position. - * - * @pre must be an array - * @pre position must be valid - * @param position the position - */ - inline void erase(unsigned position) - { - assert(isArray()); - assert(position < m_array.size()); + /** + * Remove a value at the specified position. + * + * @pre must be an array + * @pre position must be valid + * @param position the position + */ + inline void erase(unsigned position) + { + assert(isArray()); + assert(position < m_array.size()); - m_array.erase(m_array.begin() + position); - } + m_array.erase(m_array.begin() + position); + } - /* - * Object functions - * ---------------------------------------------------------- - */ + /* + * Object functions + * ---------------------------------------------------------- + */ - /** - * Get the value at the specified key or the defaultValue if key is absent. - * - * @param name the name - * @param defaultValue the value replacement - * @return the value or defaultValue - */ - template <typename DefaultValue> - Value valueOr(const std::string &name, DefaultValue &&defaultValue) const - { - if (m_type != Type::Object) - return defaultValue; + /** + * Get the value at the specified key or the defaultValue if key is absent. + * + * @param name the name + * @param defaultValue the value replacement + * @return the value or defaultValue + */ + template <typename DefaultValue> + Value valueOr(const std::string &name, DefaultValue &&defaultValue) const + { + if (m_type != Type::Object) + return defaultValue; - auto it = m_object.find(name); + auto it = m_object.find(name); - if (it == m_object.end()) - return defaultValue; + if (it == m_object.end()) + return defaultValue; - return it->second; - } + return it->second; + } - /** - * Overloaded function with type check. - * - * @param name the name - * @param type the requested type - * @param defaultValue the value replacement - * @return the value or defaultValue - */ - template <typename DefaultValue> - Value valueOr(const std::string &name, Type type, DefaultValue &&defaultValue) const - { - if (m_type != Type::Object) - return defaultValue; + /** + * Overloaded function with type check. + * + * @param name the name + * @param type the requested type + * @param defaultValue the value replacement + * @return the value or defaultValue + */ + template <typename DefaultValue> + Value valueOr(const std::string &name, Type type, DefaultValue &&defaultValue) const + { + if (m_type != Type::Object) + return defaultValue; - auto it = m_object.find(name); + auto it = m_object.find(name); - if (it == m_object.end() || it->second.typeOf() != type) - return defaultValue; + if (it == m_object.end() || it->second.typeOf() != type) + return defaultValue; - return it->second; - } + return it->second; + } - /** - * Get a value from the object. - * - * @pre must be an object - * @param name the value key - * @return the value - * @throw std::out_of_range if not found - */ - inline const Value &at(const std::string &name) const - { - assert(isObject()); + /** + * Get a value from the object. + * + * @pre must be an object + * @param name the value key + * @return the value + * @throw std::out_of_range if not found + */ + inline const Value &at(const std::string &name) const + { + assert(isObject()); - return m_object.at(name); - } + return m_object.at(name); + } - /** - * Overloaded function. - * - * @pre must be an object - * @param name the value key - * @return the value - * @throw std::out_of_range if not found - */ - inline Value &at(const std::string &name) - { - assert(isObject()); + /** + * Overloaded function. + * + * @pre must be an object + * @param name the value key + * @return the value + * @throw std::out_of_range if not found + */ + inline Value &at(const std::string &name) + { + assert(isObject()); - return m_object.at(name); - } + return m_object.at(name); + } - /** - * Get a value from the object. - * - * @pre must be an object - * @param name the value key - * @return the value - */ - inline Value &operator[](const std::string &name) - { - assert(isObject()); + /** + * Get a value from the object. + * + * @pre must be an object + * @param name the value key + * @return the value + */ + inline Value &operator[](const std::string &name) + { + assert(isObject()); - return m_object[name]; - } + return m_object[name]; + } - /** - * Find a value by key. - * - * @pre must be an object - * @param key the property key - * @return the iterator or past the end if not found - */ - inline iterator find(const std::string &key) - { - assert(isObject()); + /** + * Find a value by key. + * + * @pre must be an object + * @param key the property key + * @return the iterator or past the end if not found + */ + inline iterator find(const std::string &key) + { + assert(isObject()); - return iterator(this, m_object.find(key)); - } + return iterator(this, m_object.find(key)); + } - /** - * Overloaded function. - * - * @pre must be an object - * @param key the property key - * @return the iterator or past the end if not found - */ - inline const_iterator find(const std::string &key) const - { - assert(isObject()); + /** + * Overloaded function. + * + * @pre must be an object + * @param key the property key + * @return the iterator or past the end if not found + */ + inline const_iterator find(const std::string &key) const + { + assert(isObject()); - return const_iterator(this, m_object.find(key)); - } + return const_iterator(this, m_object.find(key)); + } - /** - * Insert a new value. - * - * @pre must be an object - * @param name the key - * @param value the value - */ - inline void insert(std::string name, const Value &value) - { - assert(isObject()); + /** + * Insert a new value. + * + * @pre must be an object + * @param name the key + * @param value the value + */ + inline void insert(std::string name, const Value &value) + { + assert(isObject()); - m_object.insert({std::move(name), value}); - } + m_object.insert({std::move(name), value}); + } - /** - * Overloaded function. - * - * @pre must be an object - * @param name the key - * @param value the value - */ - inline void insert(std::string name, Value &&value) - { - assert(isObject()); + /** + * Overloaded function. + * + * @pre must be an object + * @param name the key + * @param value the value + */ + inline void insert(std::string name, Value &&value) + { + assert(isObject()); - m_object.insert({std::move(name), std::move(value)}); - } + m_object.insert({std::move(name), std::move(value)}); + } - /** - * Check if a value exists. - * - * @pre must be an object - * @param key the key value - * @return true if exists - */ - inline bool contains(const std::string &key) const noexcept - { - assert(isObject()); + /** + * Check if a value exists. + * + * @pre must be an object + * @param key the key value + * @return true if exists + */ + inline bool contains(const std::string &key) const noexcept + { + assert(isObject()); - return m_object.find(key) != m_object.end(); - } + return m_object.find(key) != m_object.end(); + } - /** - * Remove a value of the specified key. - * - * @pre must be an object - * @param key the value key - */ - inline void erase(const std::string &key) - { - assert(isObject()); + /** + * Remove a value of the specified key. + * + * @pre must be an object + * @param key the value key + */ + inline void erase(const std::string &key) + { + assert(isObject()); - m_object.erase(key); - } + m_object.erase(key); + } - /** - * Return this value as JSon representation. - * - * @param indent the indentation to use (0 == compact, < 0 == tabs, > 0 == number of spaces) - * @return the string - */ - inline std::string toJson(int indent = 2) const - { - return toJson(indent, 0); - } + /** + * Return this value as JSon representation. + * + * @param indent the indentation to use (0 == compact, < 0 == tabs, > 0 == number of spaces) + * @return the string + */ + inline std::string toJson(int indent = 2) const + { + return toJson(indent, 0); + } }; /** @@ -1140,7 +1140,7 @@ */ inline Value array() { - return Value(Type::Array); + return Value(Type::Array); } /** @@ -1151,7 +1151,7 @@ */ inline Value array(std::initializer_list<Value> values) { - return Value(std::vector<Value>(values.begin(), values.end())); + return Value(std::vector<Value>(values.begin(), values.end())); } /** @@ -1161,7 +1161,7 @@ */ inline Value object() { - return Value(Type::Object); + return Value(Type::Object); } /** @@ -1172,7 +1172,7 @@ */ inline Value object(std::initializer_list<std::pair<std::string, Value>> values) { - return Value(std::map<std::string, Value>(values.begin(), values.end())); + return Value(std::map<std::string, Value>(values.begin(), values.end())); } /**
--- a/libcommon/malikania/resources-loader.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/resources-loader.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -25,85 +25,85 @@ namespace malikania { void ResourcesLoader::requires(const std::string &id, - const json::Value &object, - const std::unordered_map<std::string, json::Type> props) const + const json::Value &object, + const std::unordered_map<std::string, json::Type> props) const { - assert(object.isObject()); + assert(object.isObject()); - for (const auto &pair : props) { - auto it = object.find(pair.first); + for (const auto &pair : props) { + auto it = object.find(pair.first); - if (it == object.end() || it->typeOf() != pair.second) { - std::string msg = id + ": missing '" + pair.first + "' property ("; + if (it == object.end() || it->typeOf() != pair.second) { + std::string msg = id + ": missing '" + pair.first + "' property ("; - switch (pair.second) { - case json::Type::Array: - msg += "array"; - break; - case json::Type::Boolean: - msg += "boolean"; - break; - case json::Type::Int: - msg += "int"; - break; - case json::Type::Object: - msg += "object"; - break; - case json::Type::Real: - msg += "real"; - break; - case json::Type::String: - msg += "string"; - break; - default: - break; - } + switch (pair.second) { + case json::Type::Array: + msg += "array"; + break; + case json::Type::Boolean: + msg += "boolean"; + break; + case json::Type::Int: + msg += "int"; + break; + case json::Type::Object: + msg += "object"; + break; + case json::Type::Real: + msg += "real"; + break; + case json::Type::String: + msg += "string"; + break; + default: + break; + } - msg += " expected)"; + msg += " expected)"; - throw std::runtime_error(std::move(msg)); - } - } + throw std::runtime_error(std::move(msg)); + } + } } std::string ResourcesLoader::requireString(const std::string &id, - const json::Value &object, - const std::string &property) const + const json::Value &object, + const std::string &property) const { - assert(object.isObject()); + assert(object.isObject()); - auto it = object.find(property); + auto it = object.find(property); - if (it == object.end() || !it->isString()) { - throw std::runtime_error(id + ": missing '" + property + "' property (string expected)"); - } + if (it == object.end() || !it->isString()) { + throw std::runtime_error(id + ": missing '" + property + "' property (string expected)"); + } - return it->toString(); + return it->toString(); } ResourcesLoader::ResourcesLoader(ResourcesLocator &locator) - : m_locator(locator) + : m_locator(locator) { } Game ResourcesLoader::loadGame() const { - json::Value value = json::fromString(m_locator.read("game.json")); + json::Value value = json::fromString(m_locator.read("game.json")); - if (!value.isObject()) - throw std::runtime_error("game.json: not a JSON object"); + if (!value.isObject()) + throw std::runtime_error("game.json: not a JSON object"); - requires("game.json", value, { - { "name", json::Type::String }, - { "version", json::Type::String }, - { "requires", json::Type::String } - }); + requires("game.json", value, { + { "name", json::Type::String }, + { "version", json::Type::String }, + { "requires", json::Type::String } + }); - return Game(value["name"].toString(), - value["version"].toString(), - value["requires"].toString(), - value.valueOr("license", json::Type::String, "").toString(), - value.valueOr("author", json::Type::String, "").toString()); + return Game(value["name"].toString(), + value["version"].toString(), + value["requires"].toString(), + value.valueOr("license", json::Type::String, "").toString(), + value.valueOr("author", json::Type::String, "").toString()); } } // !malikania
--- a/libcommon/malikania/resources-loader.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/resources-loader.h Thu Jun 16 13:35:31 2016 +0200 @@ -40,69 +40,69 @@ */ class ResourcesLoader { private: - ResourcesLocator &m_locator; + ResourcesLocator &m_locator; protected: - /** - * Check that an object has the specified properties of the given type. - * - * Throws an error when any of the property is missing or not the correct type. - * - * You can use this function when you have lot of properties to extract, otherwise, you can use one of the - * require* or get* functions to avoid performances overhead. - * - * @pre object.isObject() - * @param id the resource id - * @param object the object - * @param props the properties - * @throw std::runtime_error when a property is missing / invalid - */ - void requires(const std::string &id, - const json::Value &object, - const std::unordered_map<std::string, json::Type> props) const; + /** + * Check that an object has the specified properties of the given type. + * + * Throws an error when any of the property is missing or not the correct type. + * + * You can use this function when you have lot of properties to extract, otherwise, you can use one of the + * require* or get* functions to avoid performances overhead. + * + * @pre object.isObject() + * @param id the resource id + * @param object the object + * @param props the properties + * @throw std::runtime_error when a property is missing / invalid + */ + void requires(const std::string &id, + const json::Value &object, + const std::unordered_map<std::string, json::Type> props) const; - /** - * Require a string. - * - * @pre object.isObject() - * @param id the resource id - * @param object the object - * @param property the property - * @return the string - * @throw std::runtime_error if the property is not a string or missing - */ - std::string requireString(const std::string &id, const json::Value &object, const std::string &property) const; + /** + * Require a string. + * + * @pre object.isObject() + * @param id the resource id + * @param object the object + * @param property the property + * @return the string + * @throw std::runtime_error if the property is not a string or missing + */ + std::string requireString(const std::string &id, const json::Value &object, const std::string &property) const; public: - /** - * Construct the ResourcesLoader. - * - * @param locator the locator - */ - ResourcesLoader(ResourcesLocator &locator); + /** + * Construct the ResourcesLoader. + * + * @param locator the locator + */ + ResourcesLoader(ResourcesLocator &locator); - /** - * Virtual destructor defaulted. - */ - virtual ~ResourcesLoader() = default; + /** + * Virtual destructor defaulted. + */ + virtual ~ResourcesLoader() = default; - /** - * Get the underlying locator. - * - * @return the locator - */ - inline ResourcesLocator &locator() noexcept - { - return m_locator; - } + /** + * Get the underlying locator. + * + * @return the locator + */ + inline ResourcesLocator &locator() noexcept + { + return m_locator; + } - /** - * Load a game. - * - * @return the game - * @throw std::runtime_error on errors - */ - virtual Game loadGame() const; + /** + * Load a game. + * + * @return the game + * @throw std::runtime_error on errors + */ + virtual Game loadGame() const; }; } // !malikania
--- a/libcommon/malikania/resources-locator.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/resources-locator.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -27,30 +27,30 @@ namespace malikania { ResourcesLocatorDirectory::ResourcesLocatorDirectory(std::string path) noexcept - : m_path(std::move(path)) + : m_path(std::move(path)) { } std::string ResourcesLocatorDirectory::read(const std::string &id) { - std::ifstream in(m_path + "/" + id, std::ifstream::in | std::ifstream::binary); + std::ifstream in(m_path + "/" + id, std::ifstream::in | std::ifstream::binary); - if (!in) { - throw std::runtime_error(std::strerror(errno)); - } + if (!in) { + throw std::runtime_error(std::strerror(errno)); + } - return std::string(std::istreambuf_iterator<char>(in.rdbuf()), std::istreambuf_iterator<char>()); + return std::string(std::istreambuf_iterator<char>(in.rdbuf()), std::istreambuf_iterator<char>()); } std::unique_ptr<std::istream> ResourcesLocatorDirectory::open(const std::string &id) { - std::unique_ptr<std::istream> ptr = std::make_unique<std::ifstream>(m_path + "/" + id); + std::unique_ptr<std::istream> ptr = std::make_unique<std::ifstream>(m_path + "/" + id); - if (!(*ptr)) { - throw std::runtime_error(std::strerror(errno)); - } + if (!(*ptr)) { + throw std::runtime_error(std::strerror(errno)); + } - return ptr; + return ptr; } } // !malikania
--- a/libcommon/malikania/resources-locator.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/resources-locator.h Thu Jun 16 13:35:31 2016 +0200 @@ -31,23 +31,23 @@ */ class ResourcesLocator { public: - /** - * Read a whole resource as a string. - * - * @param id the resource id - * @return the string - * @throw std::runtime_error on any errors - */ - virtual std::string read(const std::string &id) = 0; + /** + * Read a whole resource as a string. + * + * @param id the resource id + * @return the string + * @throw std::runtime_error on any errors + */ + virtual std::string read(const std::string &id) = 0; - /** - * Open a resource as a stream. - * - * @param id the resource id - * @return the stream - * @throw std::runtime_error on any errors - */ - virtual std::unique_ptr<std::istream> open(const std::string &id) = 0; + /** + * Open a resource as a stream. + * + * @param id the resource id + * @return the stream + * @throw std::runtime_error on any errors + */ + virtual std::unique_ptr<std::istream> open(const std::string &id) = 0; }; /** @@ -56,25 +56,25 @@ */ class ResourcesLocatorDirectory : public ResourcesLocator { private: - std::string m_path; + std::string m_path; public: - /** - * Load the game from the directory. - * - * @param path the base directory - */ - ResourcesLocatorDirectory(std::string path) noexcept; + /** + * Load the game from the directory. + * + * @param path the base directory + */ + ResourcesLocatorDirectory(std::string path) noexcept; - /** - * @copydoc ResourcesLocator::read - */ - std::string read(const std::string &id) override; + /** + * @copydoc ResourcesLocator::read + */ + std::string read(const std::string &id) override; - /** - * @copydoc ResourcesLocator::open - */ - std::unique_ptr<std::istream> open(const std::string &id) override; + /** + * @copydoc ResourcesLocator::open + */ + std::unique_ptr<std::istream> open(const std::string &id) override; }; } // !malikania
--- a/libcommon/malikania/util.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/util.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ std::vector<std::string> netsplit(std::string &input) { - std::vector<std::string> ret; - std::string::size_type pos; + std::vector<std::string> ret; + std::string::size_type pos; - while ((pos = input.find("\r\n\r\n")) != std::string::npos) { - ret.push_back(input.substr(0U, pos)); - input.erase(0U, pos + 4); - } + while ((pos = input.find("\r\n\r\n")) != std::string::npos) { + ret.push_back(input.substr(0U, pos)); + input.erase(0U, pos + 4); + } - return ret; + return ret; } } // !util
--- a/libcommon/malikania/util.h Thu May 26 07:32:05 2016 +0200 +++ b/libcommon/malikania/util.h Thu Jun 16 13:35:31 2016 +0200 @@ -52,7 +52,7 @@ template <typename T> constexpr T clamp(T value, T low, T high) noexcept { - return (value < high) ? std::max(value, low) : std::min(value, high); + return (value < high) ? std::max(value, low) : std::min(value, high); } } // !util
--- a/libserver/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/libserver/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -19,23 +19,23 @@ project(libmlk-server) set( - HEADERS - ${libmlk-server_SOURCE_DIR}/malikania/account.h - ${libmlk-server_SOURCE_DIR}/malikania/dao-account.h - ${libmlk-server_SOURCE_DIR}/malikania/database.h - ${libmlk-server_SOURCE_DIR}/malikania/dynlib.h + HEADERS + ${libmlk-server_SOURCE_DIR}/malikania/account.h + ${libmlk-server_SOURCE_DIR}/malikania/dao-account.h + ${libmlk-server_SOURCE_DIR}/malikania/database.h + ${libmlk-server_SOURCE_DIR}/malikania/dynlib.h ) set( - SOURCES - ${libmlk-server_SOURCE_DIR}/malikania/dao-account.cpp - ${libmlk-server_SOURCE_DIR}/malikania/database.cpp + SOURCES + ${libmlk-server_SOURCE_DIR}/malikania/dao-account.cpp + ${libmlk-server_SOURCE_DIR}/malikania/database.cpp ) malikania_create_library( - TARGET libmlk-server - SOURCES ${HEADERS} ${SOURCES} - LIBRARIES libcommon + TARGET libmlk-server + SOURCES ${HEADERS} ${SOURCES} + LIBRARIES libcommon ) target_include_directories(libmlk-server PUBLIC ${libmlk-server_SOURCE_DIR})
--- a/libserver/malikania/account.h Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/account.h Thu Jun 16 13:35:31 2016 +0200 @@ -34,145 +34,145 @@ */ class Account { private: - std::uint64_t m_id{0}; - std::string m_name; - std::string m_email; - std::string m_firstName; - std::string m_lastName; - std::string m_password; + std::uint64_t m_id{0}; + std::string m_name; + std::string m_email; + std::string m_firstName; + std::string m_lastName; + std::string m_password; public: - /** - * Get the id. - * - * \return the id - */ - inline std::uint64_t id() const noexcept - { - return m_id; - } + /** + * Get the id. + * + * \return the id + */ + inline std::uint64_t id() const noexcept + { + return m_id; + } - /** - * Set the id. - * - * \param id the id - */ - inline void setId(std::uint64_t id) noexcept - { - m_id = id; - } + /** + * Set the id. + * + * \param id the id + */ + inline void setId(std::uint64_t id) noexcept + { + m_id = id; + } - /** - * Get the account name. - * - * \return the name - */ - inline const std::string &name() const noexcept - { - return m_name; - } + /** + * Get the account name. + * + * \return the name + */ + inline const std::string &name() const noexcept + { + return m_name; + } - /** - * Set the account name. - * - * \param name the name - */ - inline void setName(std::string name) noexcept - { - m_name = std::move(name); - } + /** + * Set the account name. + * + * \param name the name + */ + inline void setName(std::string name) noexcept + { + m_name = std::move(name); + } - /** - * Get the email. - * - * \return the email address - */ - inline const std::string &email() const noexcept - { - return m_email; - } + /** + * Get the email. + * + * \return the email address + */ + inline const std::string &email() const noexcept + { + return m_email; + } - /** - * Set the email. - * - * \param email the email address - */ - inline void setEmail(std::string email) noexcept - { - m_email = std::move(email); - } + /** + * Set the email. + * + * \param email the email address + */ + inline void setEmail(std::string email) noexcept + { + m_email = std::move(email); + } - /** - * Get the first name. - * - * \return the first name - */ - inline const std::string &firstName() const noexcept - { - return m_firstName; - } + /** + * Get the first name. + * + * \return the first name + */ + inline const std::string &firstName() const noexcept + { + return m_firstName; + } - /** - * Set the first name. - * - * \param firstName the first name - */ - inline void setFirstName(std::string firstName) noexcept - { - m_firstName = std::move(firstName); - } + /** + * Set the first name. + * + * \param firstName the first name + */ + inline void setFirstName(std::string firstName) noexcept + { + m_firstName = std::move(firstName); + } - /** - * Get the last name. - * - * \return the last name - */ - inline const std::string &lastName() const noexcept - { - return m_lastName; - } + /** + * Get the last name. + * + * \return the last name + */ + inline const std::string &lastName() const noexcept + { + return m_lastName; + } - /** - * Set the last name. - * - * \param lastName the last name - */ - inline void setLastName(std::string lastName) noexcept - { - m_lastName = std::move(lastName); - } + /** + * Set the last name. + * + * \param lastName the last name + */ + inline void setLastName(std::string lastName) noexcept + { + m_lastName = std::move(lastName); + } - /** - * Get the password. - * - * \return the password - */ - inline const std::string &password() const noexcept - { - return m_password; - } + /** + * Get the password. + * + * \return the password + */ + inline const std::string &password() const noexcept + { + return m_password; + } - /** - * Set the password. - * - * \param password the password - */ - inline void setPassword(std::string password) noexcept - { - m_password = std::move(password); - } + /** + * Set the password. + * + * \param password the password + */ + inline void setPassword(std::string password) noexcept + { + m_password = std::move(password); + } }; inline bool operator==(const Account &ac1, const Account &ac2) noexcept { - return ac1.id() == ac2.id() && ac1.name() == ac2.name() && ac1.email() == ac2.email() && - ac1.firstName() == ac2.firstName() && ac1.lastName() == ac2.lastName() && - ac1.password() == ac2.password(); + return ac1.id() == ac2.id() && ac1.name() == ac2.name() && ac1.email() == ac2.email() && + ac1.firstName() == ac2.firstName() && ac1.lastName() == ac2.lastName() && + ac1.password() == ac2.password(); } inline bool operator!=(const Account &ac1, const Account &ac2) noexcept { - return !(ac1 == ac2); + return !(ac1 == ac2); } } // !malikania
--- a/libserver/malikania/dao-account.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/dao-account.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -32,37 +32,37 @@ void AccountDao::create(Account &account) { - m_database.handle().sym<Create>("malikania_account_create")(account); + m_database.handle().sym<Create>("malikania_account_create")(account); } void AccountDao::remove(const Account &account) { - m_database.handle().sym<Remove>("malikania_account_remove")(account); + m_database.handle().sym<Remove>("malikania_account_remove")(account); } void AccountDao::update(Account &account) { - m_database.handle().sym<Update>("malikania_account_update")(account); + m_database.handle().sym<Update>("malikania_account_update")(account); } Account AccountDao::get(uint64_t id) { - return m_database.handle().sym<Get>("malikania_account_get")(id); + return m_database.handle().sym<Get>("malikania_account_get")(id); } std::vector<Account> AccountDao::list() { - return m_database.handle().sym<List>("malikania_account_list")(); + return m_database.handle().sym<List>("malikania_account_list")(); } std::uint64_t AccountDao::count() { - return m_database.handle().sym<Count>("malikania_account_count")(); + return m_database.handle().sym<Count>("malikania_account_count")(); } void AccountDao::clear() { - m_database.handle().sym<Clear>("malikania_account_clear")(); + m_database.handle().sym<Clear>("malikania_account_clear")(); } } // !malikania
--- a/libserver/malikania/dao-account.h Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/dao-account.h Thu Jun 16 13:35:31 2016 +0200 @@ -37,75 +37,75 @@ */ class AccountDao { private: - Database &m_database; + Database &m_database; public: - /** - * Constructor. - * - * \param database the database - */ - inline AccountDao(Database &database) noexcept - : m_database(database) - { - } + /** + * Constructor. + * + * \param database the database + */ + inline AccountDao(Database &database) noexcept + : m_database(database) + { + } - /** - * Create the given account. - * - * The object will be modified in place. - * - * \param account the account to add - * \throw std::exception on errors - */ - void create(Account &account); + /** + * Create the given account. + * + * The object will be modified in place. + * + * \param account the account to add + * \throw std::exception on errors + */ + void create(Account &account); - /** - * Remove the given account, all data that references this account is deleted too. - * - * \param account the account - * \throw std::exception on errors - */ - void remove(const Account &account); + /** + * Remove the given account, all data that references this account is deleted too. + * + * \param account the account + * \throw std::exception on errors + */ + void remove(const Account &account); - /** - * Update account only, does not recurse into objects that references the account. - * - * \param account the account - * \throw std::exception on errors - */ - void update(Account &account); + /** + * Update account only, does not recurse into objects that references the account. + * + * \param account the account + * \throw std::exception on errors + */ + void update(Account &account); - /** - * Get an account. - * - * \param id the account id - * \return the account - * \throw std::exception if not found - */ - Account get(std::uint64_t id); + /** + * Get an account. + * + * \param id the account id + * \return the account + * \throw std::exception if not found + */ + Account get(std::uint64_t id); - /** - * Get the list of account. - * - * \throw std::exception on errors - */ - std::vector<Account> list(); + /** + * Get the list of account. + * + * \throw std::exception on errors + */ + std::vector<Account> list(); - /** - * Get the number of accounts. - * - * \return the number of account. - */ - std::uint64_t count(); + /** + * Get the number of accounts. + * + * \return the number of account. + */ + std::uint64_t count(); - /** - * Remove all accounts recursively. - * - * \throw std::exception on errors - * \warning use with care - */ - void clear(); + /** + * Remove all accounts recursively. + * + * \throw std::exception on errors + * \warning use with care + */ + void clear(); }; } // !malikania
--- a/libserver/malikania/database.cpp Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/database.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -26,14 +26,14 @@ // TODO: is path is relative, search for it Database::Database(const std::string &path, const std::unordered_map<std::string, std::string> ¶ms) - : m_dso(path) + : m_dso(path) { - m_dso.sym<Load>("malikania_driver_load")(params); + m_dso.sym<Load>("malikania_driver_load")(params); } Database::~Database() { - m_dso.sym<Unload>("malikania_driver_unload")(); + m_dso.sym<Unload>("malikania_driver_unload")(); } } // !malikania
--- a/libserver/malikania/database.h Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/database.h Thu Jun 16 13:35:31 2016 +0200 @@ -36,32 +36,32 @@ */ class Database { private: - Dynlib m_dso; + Dynlib m_dso; public: - /** - * Load the database driver dynamically. - * - * The type is the canonical file name (e.g. "pgsql"). - * - * \param type the database name - * \param params the parameters to pass to the driver - * \throw std::exception on errors - */ - Database(const std::string &type, const std::unordered_map<std::string, std::string> ¶ms); + /** + * Load the database driver dynamically. + * + * The type is the canonical file name (e.g. "pgsql"). + * + * \param type the database name + * \param params the parameters to pass to the driver + * \throw std::exception on errors + */ + Database(const std::string &type, const std::unordered_map<std::string, std::string> ¶ms); - /** - * Close the database. - */ - ~Database(); + /** + * Close the database. + */ + ~Database(); - /** - * Get the associated dynlib handle. - */ - inline Dynlib &handle() noexcept - { - return m_dso; - } + /** + * Get the associated dynlib handle. + */ + inline Dynlib &handle() noexcept + { + return m_dso; + } }; } // !malikania
--- a/libserver/malikania/dynlib.h Thu May 26 07:32:05 2016 +0200 +++ b/libserver/malikania/dynlib.h Thu Jun 16 13:35:31 2016 +0200 @@ -115,16 +115,16 @@ * * int main() * { - * try { - * Dynlib dso("./plugin" DYNLIB_SUFFIX); + * try { + * Dynlib dso("./plugin" DYNLIB_SUFFIX); * - * dso.sym<PluginLoad>("plugin_load")(); - * dso.sym<PluginUnload>("plugin_unload")(); - * } catch (const std::exception &ex) { - * std::cerr << ex.what() << std::endl; - * } + * dso.sym<PluginLoad>("plugin_load")(); + * dso.sym<PluginUnload>("plugin_unload")(); + * } catch (const std::exception &ex) { + * std::cerr << ex.what() << std::endl; + * } * - * return 0; + * return 0; * } * ```` * @@ -156,7 +156,7 @@ * \endcode */ #if defined(_WIN32) -# define DYNLIB_EXPORT __declspec(dllexport) +# define DYNLIB_EXPORT __declspec(dllexport) #else # define DYNLIB_EXPORT #endif @@ -191,80 +191,80 @@ class Dynlib { private: #if defined(_WIN32) - using Handle = HMODULE; - using Sym = FARPROC; + using Handle = HMODULE; + using Sym = FARPROC; #else - using Handle = void *; - using Sym = void *; + using Handle = void *; + using Sym = void *; #endif public: - /** - * \brief Policy for symbol resolution. - */ - enum Policy { - Immediately, //!< load symbols immediately - Lazy //!< load symbols when needed - }; + /** + * \brief Policy for symbol resolution. + */ + enum Policy { + Immediately, //!< load symbols immediately + Lazy //!< load symbols when needed + }; private: - Handle m_handle; + Handle m_handle; - Dynlib(const Dynlib &) = delete; - Dynlib &operator=(const Dynlib &) = delete; + Dynlib(const Dynlib &) = delete; + Dynlib &operator=(const Dynlib &) = delete; - Dynlib(Dynlib &&) = delete; - Dynlib &operator=(Dynlib &&) = delete; + Dynlib(Dynlib &&) = delete; + Dynlib &operator=(Dynlib &&) = delete; #if defined(_WIN32) - std::string error() - { - LPSTR error = nullptr; - std::string errmsg; + std::string error() + { + LPSTR error = nullptr; + std::string errmsg; - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&error, 0, NULL); + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&error, 0, NULL); - if (error) { - errmsg = std::string(error); - LocalFree(error); - } + if (error) { + errmsg = std::string(error); + LocalFree(error); + } - return errmsg; - } + return errmsg; + } #endif public: - /** - * Constructor to load a shared module. - * - * \param path the absolute path - * \param policy the policy to load - * \throw std::runtime_error on error - */ - Dynlib(const std::string &path, Policy policy = Immediately); + /** + * Constructor to load a shared module. + * + * \param path the absolute path + * \param policy the policy to load + * \throw std::runtime_error on error + */ + Dynlib(const std::string &path, Policy policy = Immediately); - /** - * Close the library automatically. - */ - ~Dynlib(); + /** + * Close the library automatically. + */ + ~Dynlib(); - /** - * Get a symbol from the library. - * - * On some platforms the symbol must be manually exported. - * - * \param name the symbol - * \return the symbol - * \throw std::runtime_error on error - * \see DYNLIB_EXPORT - */ - template <typename T> - T sym(const std::string &name); + /** + * Get a symbol from the library. + * + * On some platforms the symbol must be manually exported. + * + * \param name the symbol + * \return the symbol + * \throw std::runtime_error on error + * \see DYNLIB_EXPORT + */ + template <typename T> + T sym(const std::string &name); }; #if defined(_WIN32) @@ -276,27 +276,27 @@ inline Dynlib::Dynlib(const std::string &path, Policy) { - m_handle = LoadLibraryA(path.c_str()); + m_handle = LoadLibraryA(path.c_str()); - if (m_handle == nullptr) - throw std::runtime_error(error()); + if (m_handle == nullptr) + throw std::runtime_error(error()); } inline Dynlib::~Dynlib() { - FreeLibrary(m_handle); - m_handle = nullptr; + FreeLibrary(m_handle); + m_handle = nullptr; } template <typename T> T Dynlib::sym(const std::string &name) { - Sym sym = GetProcAddress(m_handle, name.c_str()); + Sym sym = GetProcAddress(m_handle, name.c_str()); - if (sym == nullptr) - throw std::runtime_error(error()); + if (sym == nullptr) + throw std::runtime_error(error()); - return reinterpret_cast<T>(sym); + return reinterpret_cast<T>(sym); } #else @@ -308,27 +308,27 @@ inline Dynlib::Dynlib(const std::string &path, Policy policy) { - m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); + m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); - if (m_handle == nullptr) - throw std::runtime_error(dlerror()); + if (m_handle == nullptr) + throw std::runtime_error(dlerror()); } inline Dynlib::~Dynlib() { - dlclose(m_handle); - m_handle = nullptr; + dlclose(m_handle); + m_handle = nullptr; } template <typename T> T Dynlib::sym(const std::string &name) { - Sym sym = dlsym(m_handle, name.c_str()); + Sym sym = dlsym(m_handle, name.c_str()); - if (sym == nullptr) - throw std::runtime_error(dlerror()); + if (sym == nullptr) + throw std::runtime_error(dlerror()); - return reinterpret_cast<T>(sym); + return reinterpret_cast<T>(sym); } #endif
--- a/server/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/server/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -26,30 +26,30 @@ int main(int, char **) { - try { - Database database("./pgsql", { - { "user", "kingdom" }, - { "host", "localhost" }, - { "database", "kingdomdb" } - }); + try { + Database database("./pgsql", { + { "user", "kingdom" }, + { "host", "localhost" }, + { "database", "kingdomdb" } + }); - AccountDao act(database); - Account account; + AccountDao act(database); + Account account; - account.setId(2); + account.setId(2); - act.remove(account); + act.remove(account); - for (const Account &ac : act.list()) { - std::cout << "id : " << ac.id() << std::endl; - std::cout << "name : " << ac.name() << std::endl; - std::cout << "email : " << ac.email() << std::endl; - std::cout << "firstname : " << ac.firstName() << std::endl; - std::cout << "lastname : " << ac.lastName() << std::endl; - } - } catch (const std::exception &ex) { - std::cerr << ex.what() << std::endl; - } + for (const Account &ac : act.list()) { + std::cout << "id : " << ac.id() << std::endl; + std::cout << "name : " << ac.name() << std::endl; + std::cout << "email : " << ac.email() << std::endl; + std::cout << "firstname : " << ac.firstName() << std::endl; + std::cout << "lastname : " << ac.lastName() << std::endl; + } + } catch (const std::exception &ex) { + std::cerr << ex.what() << std::endl; + } - return 0; + return 0; }
--- a/tests/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -22,8 +22,8 @@ # Meta target to build all tests. # add_custom_target( - tests - COMMENT "Building tests" + tests + COMMENT "Building tests" ) add_subdirectory(libclient)
--- a/tests/libclient/animation/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/animation/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,11 +17,11 @@ # malikania_create_test( - NAME animation - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/animations/margins.json - resources/images/margins.png - resources/sprites/margins.json + NAME animation + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/animations/margins.json + resources/images/margins.png + resources/sprites/margins.json )
--- a/tests/libclient/animation/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/animation/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -40,65 +40,65 @@ class TestAnimation : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; public: - TestAnimation() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } + TestAnimation() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } }; TEST_F(TestAnimation, standard) { - try { - Animation animation = m_loader.loadAnimation("animations/margins.json"); + try { + Animation animation = m_loader.loadAnimation("animations/margins.json"); - ASSERT_EQ(12U, animation.frames().size()); - ASSERT_EQ(500U, animation[0].delay()); - ASSERT_EQ(501U, animation[1].delay()); - ASSERT_EQ(502U, animation[2].delay()); - ASSERT_EQ(503U, animation[3].delay()); - ASSERT_EQ(504U, animation[4].delay()); - ASSERT_EQ(505U, animation[5].delay()); - ASSERT_EQ(506U, animation[6].delay()); - ASSERT_EQ(507U, animation[7].delay()); - ASSERT_EQ(508U, animation[8].delay()); - ASSERT_EQ(509U, animation[9].delay()); - ASSERT_EQ(510U, animation[10].delay()); - ASSERT_EQ(511U, animation[11].delay()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(12U, animation.frames().size()); + ASSERT_EQ(500U, animation[0].delay()); + ASSERT_EQ(501U, animation[1].delay()); + ASSERT_EQ(502U, animation[2].delay()); + ASSERT_EQ(503U, animation[3].delay()); + ASSERT_EQ(504U, animation[4].delay()); + ASSERT_EQ(505U, animation[5].delay()); + ASSERT_EQ(506U, animation[6].delay()); + ASSERT_EQ(507U, animation[7].delay()); + ASSERT_EQ(508U, animation[8].delay()); + ASSERT_EQ(509U, animation[9].delay()); + ASSERT_EQ(510U, animation[10].delay()); + ASSERT_EQ(511U, animation[11].delay()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestAnimation, draw) { - ElapsedTimer timer; + ElapsedTimer timer; - try { - Animation animation = m_loader.loadAnimation("animations/margins.json"); - Animator animator(animation); + try { + Animation animation = m_loader.loadAnimation("animations/margins.json"); + Animator animator(animation); - auto x = (400 / 2) - (animation.sprite().cell().width() / 2); - auto y = (400 / 2) - (animation.sprite().cell().height() / 2); + auto x = (400 / 2) - (animation.sprite().cell().width() / 2); + auto y = (400 / 2) - (animation.sprite().cell().height() / 2); - while (timer.elapsed() < 8000) { - window.clear(); - animator.draw(window, Point(x, y)); - animator.update(); - window.present(); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + while (timer.elapsed() < 8000) { + window.clear(); + animator.draw(window, Point(x, y)); + animator.update(); + window.present(); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/color/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/color/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME color - LIBRARIES libclient - SOURCES main.cpp + NAME color + LIBRARIES libclient + SOURCES main.cpp ) \ No newline at end of file
--- a/tests/libclient/color/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/color/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,52 +29,52 @@ TEST(Basic, black) { - Color c; + Color c; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Basic, white) { - Color c{255, 255, 255, 255}; + Color c{255, 255, 255, 255}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Basic, red) { - Color c{255, 0, 0, 255}; + Color c{255, 0, 0, 255}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Basic, green) { - Color c{0, 255, 0, 255}; + Color c{0, 255, 0, 255}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Basic, blue) { - Color c{0, 0, 255, 255}; + Color c{0, 0, 255, 255}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } /* @@ -84,52 +84,52 @@ TEST(Hex, black) { - Color c{0xff000000}; + Color c{0xff000000}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Hex, white) { - Color c{0xffffffff}; + Color c{0xffffffff}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Hex, red) { - Color c{0xffff0000}; + Color c{0xffff0000}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Hex, green) { - Color c{0xff00ff00}; + Color c{0xff00ff00}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Hex, blue) { - Color c{0xff0000ff}; + Color c{0xff0000ff}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } /* @@ -141,62 +141,62 @@ TEST(Named, black) { - Color c{"black"}; + Color c{"black"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Named, white) { - Color c{"white"}; + Color c{"white"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Named, red) { - Color c{"red"}; + Color c{"red"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Named, green) { - Color c{"green"}; + Color c{"green"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(128, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(128, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Named, blue) { - Color c{"blue"}; + Color c{"blue"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(Named, wrong) { - try { - Color c{"does not exist"}; + try { + Color c{"does not exist"}; - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -208,62 +208,62 @@ TEST(FullRgb, black) { - Color c{"#000000"}; + Color c{"#000000"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(FullRgb, white) { - Color c{"#ffffff"}; + Color c{"#ffffff"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(FullRgb, red) { - Color c{"#ff0000"}; + Color c{"#ff0000"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(FullRgb, green) { - Color c{"#00ff00"}; + Color c{"#00ff00"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(FullRgb, blue) { - Color c{"#0000ff"}; + Color c{"#0000ff"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(FullRgb, wrong) { - try { - Color c{"#ghijkl"}; + try { + Color c{"#ghijkl"}; - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -275,77 +275,77 @@ TEST(ShortRgb, black) { - Color c{"#000"}; + Color c{"#000"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, white) { - Color c{"#fff"}; + Color c{"#fff"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, red) { - Color c{"#f00"}; + Color c{"#f00"}; - ASSERT_EQ(255, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(255, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, green) { - Color c{"#0f0"}; + Color c{"#0f0"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(255, c.green()); - ASSERT_EQ(0, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(255, c.green()); + ASSERT_EQ(0, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, blue) { - Color c{"#00f"}; + Color c{"#00f"}; - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, combination) { - Color c{"#123"}; + Color c{"#123"}; - ASSERT_EQ(17, c.red()); - ASSERT_EQ(34, c.green()); - ASSERT_EQ(51, c.blue()); - ASSERT_EQ(255, c.alpha()); + ASSERT_EQ(17, c.red()); + ASSERT_EQ(34, c.green()); + ASSERT_EQ(51, c.blue()); + ASSERT_EQ(255, c.alpha()); } TEST(ShortRgb, wrong) { - try { - Color c{"#ghi"}; + try { + Color c{"#ghi"}; - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/font/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/font/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,9 +17,9 @@ # malikania_create_test( - NAME font - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/DejaVuSans.ttf + NAME font + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/DejaVuSans.ttf )
--- a/tests/libclient/font/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/font/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -40,89 +40,89 @@ class TestFont : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; - Font m_font; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; + Font m_font; public: - TestFont() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - , m_font(m_loader.loadFont("DejaVuSans.ttf", 10)) - { - window.setDrawingColor(Color("black")); - window.clear(); - } + TestFont() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + , m_font(m_loader.loadFont("DejaVuSans.ttf", 10)) + { + window.setDrawingColor(Color("black")); + window.clear(); + } }; TEST_F(TestFont, topleft) { - window.setDrawingColor(Color("white")); - window.drawText("top left", m_font, Point(10, 10)); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("top left", m_font, Point(10, 10)); + window.present(); - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(1s); } TEST_F(TestFont, topright) { - Size dim = m_font.clip("top right"); + Size dim = m_font.clip("top right"); - window.setDrawingColor(Color("white")); - window.drawText("top right", m_font, Point(400 - dim.width() - 10, 10)); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("top right", m_font, Point(400 - dim.width() - 10, 10)); + window.present(); - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(1s); } TEST_F(TestFont, bottomleft) { - Size dim = m_font.clip("bottom left"); + Size dim = m_font.clip("bottom left"); - window.setDrawingColor(Color("white")); - window.drawText("bottom left", m_font, Point(10, 400 - dim.height() - 10)); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("bottom left", m_font, Point(10, 400 - dim.height() - 10)); + window.present(); - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(1s); } TEST_F(TestFont, bottomright) { - Size dim = m_font.clip("bottom right"); + Size dim = m_font.clip("bottom right"); - window.setDrawingColor(Color("white")); - window.drawText("bottom right", m_font, Point(400 - dim.width() - 10, 400 - dim.height() - 10)); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("bottom right", m_font, Point(400 - dim.width() - 10, 400 - dim.height() - 10)); + window.present(); - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(1s); } TEST_F(TestFont, center) { - Size dim = m_font.clip("center"); + Size dim = m_font.clip("center"); - window.setDrawingColor(Color("white")); - window.drawText("center", m_font, Point(200 - (dim.width() / 2), 200 - (dim.height() -2))); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("center", m_font, Point(200 - (dim.width() / 2), 200 - (dim.height() -2))); + window.present(); - std::this_thread::sleep_for(1s); + std::this_thread::sleep_for(1s); } TEST_F(TestFont, center2) { - Size dim = m_font.clip("The world is Malikania."); + Size dim = m_font.clip("The world is Malikania."); - window.setDrawingColor(Color("white")); - window.drawText("The world is Malikania.", m_font, Point(200 - (dim.width() / 2), 200 - (dim.height() -2))); - window.present(); + window.setDrawingColor(Color("white")); + window.drawText("The world is Malikania.", m_font, Point(200 - (dim.width() / 2), 200 - (dim.height() -2))); + window.present(); - std::this_thread::sleep_for(3s); + std::this_thread::sleep_for(3s); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/image/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/image/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,12 +17,12 @@ # malikania_create_test( - NAME image - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/images/100x10.png - resources/images/10x100.png - resources/images/16x16.png - resources/images/smiley.png + NAME image + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/images/100x10.png + resources/images/10x100.png + resources/images/16x16.png + resources/images/smiley.png )
--- a/tests/libclient/image/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/image/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -38,61 +38,61 @@ class TestImage : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; public: - TestImage() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } + TestImage() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } }; TEST_F(TestImage, image100x10) { - try { - Image image = m_loader.loadImage("images/100x10.png"); + try { + Image image = m_loader.loadImage("images/100x10.png"); - ASSERT_EQ(100U, image.size().width()); - ASSERT_EQ(10U, image.size().height()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100U, image.size().width()); + ASSERT_EQ(10U, image.size().height()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestImage, image16x16) { - try { - Image image = m_loader.loadImage("images/16x16.png"); + try { + Image image = m_loader.loadImage("images/16x16.png"); - ASSERT_EQ(16U, image.size().width()); - ASSERT_EQ(16U, image.size().height()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(16U, image.size().width()); + ASSERT_EQ(16U, image.size().height()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestImage, image10x100) { - try { - Image image = m_loader.loadImage("images/10x100.png"); + try { + Image image = m_loader.loadImage("images/10x100.png"); - ASSERT_EQ(10U, image.size().width()); - ASSERT_EQ(100U, image.size().height()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10U, image.size().width()); + ASSERT_EQ(100U, image.size().height()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestImage, notfound) { - try { - m_loader.loadImage("image-not-found"); + try { + m_loader.loadImage("image-not-found"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -102,24 +102,24 @@ TEST_F(TestImage, draw) { - try { - auto image = m_loader.loadImage("images/smiley.png"); - auto x = (400 / 2) - (image.size().width() / 2); - auto y = (400 / 2) - (image.size().height() / 2); + try { + auto image = m_loader.loadImage("images/smiley.png"); + auto x = (400 / 2) - (image.size().width() / 2); + auto y = (400 / 2) - (image.size().height() / 2); - window.clear(); - image.draw(window, Point(x, y)); - window.present(); + window.clear(); + image.draw(window, Point(x, y)); + window.present(); - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-animation/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-animation/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,11 +17,11 @@ # malikania_create_test( - NAME js-animation - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/animations/margins.json - resources/images/margins.png - resources/sprites/margins.json + NAME js-animation + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/animations/margins.json + resources/images/margins.png + resources/sprites/margins.json )
--- a/tests/libclient/js-animation/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-animation/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -34,65 +34,65 @@ class TestAnimation : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; - duk::Context m_ctx; + duk::Context m_ctx; public: - TestAnimation() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestAnimation() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaAnimation(m_ctx); - loadMalikaniaAnimator(m_ctx); - loadMalikaniaWindow(m_ctx); + loadMalikaniaAnimation(m_ctx); + loadMalikaniaAnimator(m_ctx); + loadMalikaniaWindow(m_ctx); - /* Store the loader */ - duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); - } + /* Store the loader */ + duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); + } }; TEST_F(TestAnimation, basic) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "a = new Malikania.Animation('animations/margins.json');" - "d = new Malikania.Animator(a);" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "a = new Malikania.Animation('animations/margins.json');" + "d = new Malikania.Animator(a);" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ElapsedTimer timer; + ElapsedTimer timer; - while (timer.elapsed() < 8000) { - auto ret = duk::pevalString(m_ctx, - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "d.draw(w, { x: 320 - 16, y: 240 - 16 });" - "d.update();" - "w.present();" - ); + while (timer.elapsed() < 8000) { + auto ret = duk::pevalString(m_ctx, + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "d.draw(w, { x: 320 - 16, y: 240 - 16 });" + "d.update();" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-color/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-color/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-color - LIBRARIES libclient - SOURCES main.cpp + NAME js-color + LIBRARIES libclient + SOURCES main.cpp ) \ No newline at end of file
--- a/tests/libclient/js-color/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-color/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ class TestColor : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestColor() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestColor() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaColor(m_ctx); - } + loadMalikaniaColor(m_ctx); + } }; /* @@ -42,197 +42,197 @@ TEST_F(TestColor, ConstructorNoArgs) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color();" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color();" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, ConstructorString) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color('white');" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color('white');" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, ConstructorStringRgb) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color('#0000ff');" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color('#0000ff');" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, Constructor3Args) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color(10, 20, 30);" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color(10, 20, 30);" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, Constructor4Args) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color(10, 20, 30, 40);" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color(10, 20, 30, 40);" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, ConstructorObjectNoAlpha) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color({ red: 10, green: 20, blue: 30 });" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color({ red: 10, green: 20, blue: 30 });" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, ConstructorObjectAlpha) { - try { - auto ret = duk::pevalString(m_ctx, - "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, ConstructorNew) { - /* - * Just one test, function parse the same way, only 'this' or a new object is returned. - */ - try { - auto ret = duk::pevalString(m_ctx, - "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" - "r = c.red;" - "g = c.green;" - "b = c.blue;" - "a = c.alpha;" - ); + /* + * Just one test, function parse the same way, only 'this' or a new object is returned. + */ + try { + auto ret = duk::pevalString(m_ctx, + "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" + "r = c.red;" + "g = c.green;" + "b = c.blue;" + "a = c.alpha;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -242,209 +242,209 @@ TEST_F(TestColor, InvalidConstructorArg1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color(null);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color(null);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorArg2) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color(10, null, 30);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color(10, null, 30);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorRange1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color(-1, 20, 30);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color(-1, 20, 30);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorRange2) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color(10, 20, 256);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color(10, 20, 256);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorRange3) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color(10, 20, 30, 800);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color(10, 20, 30, 800);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorRange4) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color({ red: -1, green: 20, blue: 30 });" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color({ red: -1, green: 20, blue: 30 });" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorRange5) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorStringUnknown) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color('does not exist');" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color('does not exist');" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, InvalidConstructorStringRgb) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Color('#ghijkl');" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Color('#ghijkl');" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -457,89 +457,89 @@ TEST_F(TestColor, requireSuccess) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Color color = duk::require<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Color color = duk::require<Color>(ctx, 0); - duk::putGlobal(ctx, "r", static_cast<int>(color.red())); - duk::putGlobal(ctx, "g", static_cast<int>(color.green())); - duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); - duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); + duk::putGlobal(ctx, "r", static_cast<int>(color.red())); + duk::putGlobal(ctx, "g", static_cast<int>(color.green())); + duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); + duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); + auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, requireFail) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Color>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " draw('#ghijkl');" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " draw('#ghijkl');" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, requireFailAlpha) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Color>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " draw({ red: 10, green: 20, blue: 30, alpha: 800 });" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " draw({ red: 10, green: 20, blue: 30, alpha: 800 });" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -551,123 +551,123 @@ TEST_F(TestColor, getNormal) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Color color = duk::get<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Color color = duk::get<Color>(ctx, 0); - duk::putGlobal(ctx, "r", static_cast<int>(color.red())); - duk::putGlobal(ctx, "g", static_cast<int>(color.green())); - duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); - duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); + duk::putGlobal(ctx, "r", static_cast<int>(color.red())); + duk::putGlobal(ctx, "g", static_cast<int>(color.green())); + duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); + duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); + auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, getAdjustRgb) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Color color = duk::get<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Color color = duk::get<Color>(ctx, 0); - duk::putGlobal(ctx, "r", static_cast<int>(color.red())); - duk::putGlobal(ctx, "g", static_cast<int>(color.green())); - duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); - duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); + duk::putGlobal(ctx, "r", static_cast<int>(color.red())); + duk::putGlobal(ctx, "g", static_cast<int>(color.green())); + duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); + duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "draw('#ghijkl');"); + auto ret = duk::pevalString(m_ctx, "draw('#ghijkl');"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, getAdjustAll) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Color color = duk::get<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Color color = duk::get<Color>(ctx, 0); - duk::putGlobal(ctx, "r", static_cast<int>(color.red())); - duk::putGlobal(ctx, "g", static_cast<int>(color.green())); - duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); - duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); + duk::putGlobal(ctx, "r", static_cast<int>(color.red())); + duk::putGlobal(ctx, "g", static_cast<int>(color.green())); + duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); + duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });"); + auto ret = duk::pevalString(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestColor, getSomethingElse) { - try { - duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Color color = duk::get<Color>(ctx, 0); + try { + duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Color color = duk::get<Color>(ctx, 0); - duk::putGlobal(ctx, "r", static_cast<int>(color.red())); - duk::putGlobal(ctx, "g", static_cast<int>(color.green())); - duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); - duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); + duk::putGlobal(ctx, "r", static_cast<int>(color.red())); + duk::putGlobal(ctx, "g", static_cast<int>(color.green())); + duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); + duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "draw(null);"); + auto ret = duk::pevalString(m_ctx, "draw(null);"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); - ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); + ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-font/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-font/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,9 +17,9 @@ # malikania_create_test( - NAME js-font - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/DejaVuSans.ttf + NAME js-font + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/DejaVuSans.ttf )
--- a/tests/libclient/js-font/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-font/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -32,54 +32,54 @@ class TestFont : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; - duk::Context m_ctx; + duk::Context m_ctx; public: - TestFont() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestFont() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaFont(m_ctx); - loadMalikaniaWindow(m_ctx); + loadMalikaniaFont(m_ctx); + loadMalikaniaWindow(m_ctx); - /* Store the loader */ - duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); - } + /* Store the loader */ + duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); + } }; TEST_F(TestFont, basic) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "f = new Malikania.Font('DejaVuSans.ttf', 10);" - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "s = 'The world is Malikania.';" - "c = f.clip(s);" - "w.setDrawingColor('white');" - "w.drawText(s, f, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });" - "w.present();" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "f = new Malikania.Font('DejaVuSans.ttf', 10);" + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "s = 'The world is Malikania.';" + "c = f.clip(s);" + "w.setDrawingColor('white');" + "w.drawText(s, f, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-image/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-image/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,9 +17,9 @@ # malikania_create_test( - NAME js-image - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/images/smiley.png + NAME js-image + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/images/smiley.png )
--- a/tests/libclient/js-image/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-image/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -32,93 +32,93 @@ class TestImage : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; - duk::Context m_ctx; + duk::Context m_ctx; public: - TestImage() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestImage() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaImage(m_ctx); - loadMalikaniaWindow(m_ctx); + loadMalikaniaImage(m_ctx); + loadMalikaniaWindow(m_ctx); - /* Store the loader */ - duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); - } + /* Store the loader */ + duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); + } }; TEST_F(TestImage, size) { - try { - auto ret = duk::pevalString(m_ctx, - "i = new Malikania.Image('images/smiley.png');" - "w = i.size.width;" - "h = i.size.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "i = new Malikania.Image('images/smiley.png');" + "w = i.size.width;" + "h = i.size.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestImage, basic) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "i = new Malikania.Image('images/smiley.png');" - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "i.draw(w, { x: 320 - 16, y: 240 - 16 });" - "w.present();" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "i = new Malikania.Image('images/smiley.png');" + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "i.draw(w, { x: 320 - 16, y: 240 - 16 });" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestImage, stretch) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "i = new Malikania.Image('images/smiley.png');" - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });" - "w.present();" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "i = new Malikania.Image('images/smiley.png');" + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-line/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-line/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-line - LIBRARIES libclient - SOURCES main.cpp + NAME js-line + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/js-line/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-line/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ class TestLine : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestLine() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestLine() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaLine(m_ctx); - } + loadMalikaniaLine(m_ctx); + } }; /* @@ -42,98 +42,98 @@ TEST_F(TestLine, ConstructorNoArgs) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Line();" - "x1 = r.x1;" - "y1 = r.y1;" - "x2 = r.x2;" - "y2 = r.y2;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Line();" + "x1 = r.x1;" + "y1 = r.y1;" + "x2 = r.x2;" + "y2 = r.y2;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestLine, Constructor4Args) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Line(10, 20, 30, 40);" - "x1 = r.x1;" - "y1 = r.y1;" - "x2 = r.x2;" - "y2 = r.y2;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Line(10, 20, 30, 40);" + "x1 = r.x1;" + "y1 = r.y1;" + "x2 = r.x2;" + "y2 = r.y2;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestLine, ConstructorObject) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Line({ x1: 10, y1: 20, x2: 30, y2: 40 });" - "x1 = r.x1;" - "y1 = r.y1;" - "x2 = r.x2;" - "y2 = r.y2;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Line({ x1: 10, y1: 20, x2: 30, y2: 40 });" + "x1 = r.x1;" + "y1 = r.y1;" + "x2 = r.x2;" + "y2 = r.y2;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestLine, ConstructorNew) { - try { - auto ret = duk::pevalString(m_ctx, - "r = new Malikania.Line({ x1: 10, y1: 20, x2: 30, y2: 40 });" - "x1 = r.x1;" - "y1 = r.y1;" - "x2 = r.x2;" - "y2 = r.y2;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = new Malikania.Line({ x1: 10, y1: 20, x2: 30, y2: 40 });" + "x1 = r.x1;" + "y1 = r.y1;" + "x2 = r.x2;" + "y2 = r.y2;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -143,25 +143,25 @@ TEST_F(TestLine, InvalidConstructorArg1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Line(null);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Line(null);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -171,60 +171,60 @@ TEST_F(TestLine, requireSuccess) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Line line = duk::require<Line>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Line line = duk::require<Line>(ctx, 0); - duk::putGlobal(ctx, "x1", line.x1()); - duk::putGlobal(ctx, "y1", line.y1()); - duk::putGlobal(ctx, "x2", line.x2()); - duk::putGlobal(ctx, "y2", line.y2()); + duk::putGlobal(ctx, "x1", line.x1()); + duk::putGlobal(ctx, "y1", line.y1()); + duk::putGlobal(ctx, "x2", line.x2()); + duk::putGlobal(ctx, "y2", line.y2()); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({ x1: 50, y1: 80, x2: 100, y2: 200 });"); + auto ret = duk::pevalString(m_ctx, "build({ x1: 50, y1: 80, x2: 100, y2: 200 });"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(50, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(80, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(50, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(80, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestLine, requireFail) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Line>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Line>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " build({});" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " build({});" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -234,36 +234,36 @@ TEST_F(TestLine, getAdjustAll) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Line line = duk::get<Line>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Line line = duk::get<Line>(ctx, 0); - duk::putGlobal(ctx, "x1", line.x1()); - duk::putGlobal(ctx, "y1", line.y1()); - duk::putGlobal(ctx, "x2", line.x2()); - duk::putGlobal(ctx, "y2", line.y2()); + duk::putGlobal(ctx, "x1", line.x1()); + duk::putGlobal(ctx, "y1", line.y1()); + duk::putGlobal(ctx, "x2", line.x2()); + duk::putGlobal(ctx, "y2", line.y2()); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({});"); + auto ret = duk::pevalString(m_ctx, "build({});"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x1")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y1")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x2")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y2")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x1")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y1")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x2")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y2")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-point/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-point/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-point - LIBRARIES libclient - SOURCES main.cpp + NAME js-point + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/js-point/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-point/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ class TestPoint : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestPoint() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestPoint() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaPoint(m_ctx); - } + loadMalikaniaPoint(m_ctx); + } }; /* @@ -42,82 +42,82 @@ TEST_F(TestPoint, ConstructorNoArgs) { - try { - auto ret = duk::pevalString(m_ctx, - "p = Malikania.Point();" - "x = p.x;" - "y = p.y;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "p = Malikania.Point();" + "x = p.x;" + "y = p.y;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestPoint, Constructor2Args) { - try { - auto ret = duk::pevalString(m_ctx, - "p = Malikania.Point(-10, -20);" - "x = p.x;" - "y = p.y;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "p = Malikania.Point(-10, -20);" + "x = p.x;" + "y = p.y;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(-10, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(-20, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(-10, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(-20, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestPoint, ConstructorObject) { - try { - auto ret = duk::pevalString(m_ctx, - "p = Malikania.Point({ x: 100, y: 200 });" - "x = p.x;" - "y = p.y;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "p = Malikania.Point({ x: 100, y: 200 });" + "x = p.x;" + "y = p.y;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestPoint, ConstructorNew) { - try { - auto ret = duk::pevalString(m_ctx, - "p = new Malikania.Point({ x: 100, y: 200 });" - "x = p.x;" - "y = p.y;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "p = new Malikania.Point({ x: 100, y: 200 });" + "x = p.x;" + "y = p.y;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -127,25 +127,25 @@ TEST_F(TestPoint, InvalidConstructorArg1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Point(null);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Point(null);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -155,56 +155,56 @@ TEST_F(TestPoint, requireSuccess) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Point point = duk::require<Point>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Point point = duk::require<Point>(ctx, 0); - duk::putGlobal(ctx, "x", point.x()); - duk::putGlobal(ctx, "y", point.y()); + duk::putGlobal(ctx, "x", point.x()); + duk::putGlobal(ctx, "y", point.y()); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({ x: 100, y: 200 });"); + auto ret = duk::pevalString(m_ctx, "build({ x: 100, y: 200 });"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestPoint, requireFail) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Point>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Point>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " build({});" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " build({});" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -214,32 +214,32 @@ TEST_F(TestPoint, getAdjustAll) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Point point = duk::get<Point>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Point point = duk::get<Point>(ctx, 0); - duk::putGlobal(ctx, "x", point.x()); - duk::putGlobal(ctx, "y", point.y()); + duk::putGlobal(ctx, "x", point.x()); + duk::putGlobal(ctx, "y", point.y()); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({});"); + auto ret = duk::pevalString(m_ctx, "build({});"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-rectangle/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-rectangle/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-rectangle - LIBRARIES libclient - SOURCES main.cpp + NAME js-rectangle + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/js-rectangle/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-rectangle/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ class TestRectangle : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestRectangle() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestRectangle() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaRectangle(m_ctx); - } + loadMalikaniaRectangle(m_ctx); + } }; /* @@ -42,98 +42,98 @@ TEST_F(TestRectangle, ConstructorNoArgs) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Rectangle();" - "x = r.x;" - "y = r.y;" - "w = r.width;" - "h = r.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Rectangle();" + "x = r.x;" + "y = r.y;" + "w = r.width;" + "h = r.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestRectangle, Constructor4Args) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Rectangle(10, 20, 30, 40);" - "x = r.x;" - "y = r.y;" - "w = r.width;" - "h = r.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Rectangle(10, 20, 30, 40);" + "x = r.x;" + "y = r.y;" + "w = r.width;" + "h = r.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestRectangle, ConstructorObject) { - try { - auto ret = duk::pevalString(m_ctx, - "r = Malikania.Rectangle({ x: 10, y: 20, width: 30, height: 40 });" - "x = r.x;" - "y = r.y;" - "w = r.width;" - "h = r.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = Malikania.Rectangle({ x: 10, y: 20, width: 30, height: 40 });" + "x = r.x;" + "y = r.y;" + "w = r.width;" + "h = r.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestRectangle, ConstructorNew) { - try { - auto ret = duk::pevalString(m_ctx, - "r = new Malikania.Rectangle({ x: 10, y: 20, width: 30, height: 40 });" - "x = r.x;" - "y = r.y;" - "w = r.width;" - "h = r.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "r = new Malikania.Rectangle({ x: 10, y: 20, width: 30, height: 40 });" + "x = r.x;" + "y = r.y;" + "w = r.width;" + "h = r.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -143,48 +143,48 @@ TEST_F(TestRectangle, InvalidConstructorArg1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Rectangle(null);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Rectangle(null);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestRectangle, InvalidConstructorRange1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Rectangle(0, 0, -10, -10);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Rectangle(0, 0, -10, -10);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -194,60 +194,60 @@ TEST_F(TestRectangle, requireSuccess) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Rectangle rect = duk::require<Rectangle>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Rectangle rect = duk::require<Rectangle>(ctx, 0); - duk::putGlobal(ctx, "x", rect.x()); - duk::putGlobal(ctx, "y", rect.y()); - duk::putGlobal(ctx, "w", static_cast<int>(rect.width())); - duk::putGlobal(ctx, "h", static_cast<int>(rect.height())); + duk::putGlobal(ctx, "x", rect.x()); + duk::putGlobal(ctx, "y", rect.y()); + duk::putGlobal(ctx, "w", static_cast<int>(rect.width())); + duk::putGlobal(ctx, "h", static_cast<int>(rect.height())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({ x: 50, y: 80, width: 100, height: 200 });"); + auto ret = duk::pevalString(m_ctx, "build({ x: 50, y: 80, width: 100, height: 200 });"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(50, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(80, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(50, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(80, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestRectangle, requireFail) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Rectangle>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Rectangle>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " build({});" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " build({});" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -257,36 +257,36 @@ TEST_F(TestRectangle, getAdjustAll) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Rectangle rect = duk::get<Rectangle>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Rectangle rect = duk::get<Rectangle>(ctx, 0); - duk::putGlobal(ctx, "x", rect.x()); - duk::putGlobal(ctx, "y", rect.y()); - duk::putGlobal(ctx, "w", static_cast<int>(rect.width())); - duk::putGlobal(ctx, "h", static_cast<int>(rect.height())); + duk::putGlobal(ctx, "x", rect.x()); + duk::putGlobal(ctx, "y", rect.y()); + duk::putGlobal(ctx, "w", static_cast<int>(rect.width())); + duk::putGlobal(ctx, "h", static_cast<int>(rect.height())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({});"); + auto ret = duk::pevalString(m_ctx, "build({});"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "x")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "y")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-size/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-size/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-size - LIBRARIES libclient - SOURCES main.cpp + NAME js-size + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/js-size/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-size/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,15 +24,15 @@ class TestSize : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestSize() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestSize() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaSize(m_ctx); - } + loadMalikaniaSize(m_ctx); + } }; /* @@ -42,82 +42,82 @@ TEST_F(TestSize, ConstructorNoArgs) { - try { - auto ret = duk::pevalString(m_ctx, - "s = Malikania.Size();" - "w = s.width;" - "h = s.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = Malikania.Size();" + "w = s.width;" + "h = s.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, Constructor2Args) { - try { - auto ret = duk::pevalString(m_ctx, - "s = Malikania.Size(100, 200);" - "w = s.width;" - "h = s.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = Malikania.Size(100, 200);" + "w = s.width;" + "h = s.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, ConstructorObject) { - try { - auto ret = duk::pevalString(m_ctx, - "s = Malikania.Size({ width: 100, height: 200 });" - "w = s.width;" - "h = s.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = Malikania.Size({ width: 100, height: 200 });" + "w = s.width;" + "h = s.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, ConstructorNew) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Size({ width: 100, height: 200 });" - "w = s.width;" - "h = s.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Size({ width: 100, height: 200 });" + "w = s.width;" + "h = s.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -127,117 +127,117 @@ TEST_F(TestSize, InvalidConstructorArg1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Size(null);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof TypeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Size(null);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof TypeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, InvalidConstructorRange1) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Size(-1, 200);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Size(-1, 200);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, InvalidConstructorRange2) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Size(100, -1);" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Size(100, -1);" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, InvalidConstructorRange3) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Size({ width: -1, height: 200 });" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Size({ width: -1, height: 200 });" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, InvalidConstructorRange4) { - try { - auto ret = duk::pevalString(m_ctx, - "try {" - " Malikania.Size({ width: 100, height: -1 });" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof RangeError);" - "}" - ); + try { + auto ret = duk::pevalString(m_ctx, + "try {" + " Malikania.Size({ width: 100, height: -1 });" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof RangeError);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -247,56 +247,56 @@ TEST_F(TestSize, requireSuccess) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Size size = duk::require<Size>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Size size = duk::require<Size>(ctx, 0); - duk::putGlobal(ctx, "w", static_cast<int>(size.width())); - duk::putGlobal(ctx, "h", static_cast<int>(size.height())); + duk::putGlobal(ctx, "w", static_cast<int>(size.width())); + duk::putGlobal(ctx, "h", static_cast<int>(size.height())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({ width: 100, height: 200 });"); + auto ret = duk::pevalString(m_ctx, "build({ width: 100, height: 200 });"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(200, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSize, requireFail) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - duk::require<Size>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + duk::require<Size>(ctx, 0); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, - "try {" - " build({});" - "} catch (e) {" - " name = e.name;" - " correct = (e instanceof Error);" - "}" - ); + auto ret = duk::pevalString(m_ctx, + "try {" + " build({});" + "} catch (e) {" + " name = e.name;" + " correct = (e instanceof Error);" + "}" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); - ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); + ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -306,32 +306,32 @@ TEST_F(TestSize, getAdjustAll) { - try { - duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - Size size = duk::get<Size>(ctx, 0); + try { + duk::putGlobal(m_ctx, "build", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + Size size = duk::get<Size>(ctx, 0); - duk::putGlobal(ctx, "w", static_cast<int>(size.width())); - duk::putGlobal(ctx, "h", static_cast<int>(size.height())); + duk::putGlobal(ctx, "w", static_cast<int>(size.width())); + duk::putGlobal(ctx, "h", static_cast<int>(size.height())); - return 0; - }, 1}); + return 0; + }, 1}); - auto ret = duk::pevalString(m_ctx, "build({});"); + auto ret = duk::pevalString(m_ctx, "build({});"); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); - ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); + ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-sprite/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-sprite/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,10 +17,10 @@ # malikania_create_test( - NAME js-sprite - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/images/margins.png - resources/sprites/margins.json + NAME js-sprite + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/images/margins.png + resources/sprites/margins.json )
--- a/tests/libclient/js-sprite/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-sprite/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -33,158 +33,158 @@ class TestSprite : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; - duk::Context m_ctx; + duk::Context m_ctx; public: - TestSprite() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestSprite() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaImage(m_ctx); - loadMalikaniaSprite(m_ctx); - loadMalikaniaWindow(m_ctx); + loadMalikaniaImage(m_ctx); + loadMalikaniaSprite(m_ctx); + loadMalikaniaWindow(m_ctx); - /* Store the loader */ - duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); - } + /* Store the loader */ + duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); + } }; TEST_F(TestSprite, cell) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.cell.width;" - "h = s.cell.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.cell.width;" + "h = s.cell.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, columns) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "n = s.columns;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "n = s.columns;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(4, duk::getGlobal<int>(m_ctx, "n")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(4, duk::getGlobal<int>(m_ctx, "n")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, margins) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.margins.width;" - "h = s.margins.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.margins.width;" + "h = s.margins.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(4, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(6, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(4, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(6, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, rows) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "n = s.rows;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "n = s.rows;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(3, duk::getGlobal<int>(m_ctx, "n")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(3, duk::getGlobal<int>(m_ctx, "n")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, space) { - try { - auto ret = duk::pevalString(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.space.width;" - "h = s.space.height;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.space.width;" + "h = s.space.height;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - ASSERT_EQ(2, duk::getGlobal<int>(m_ctx, "w")); - ASSERT_EQ(3, duk::getGlobal<int>(m_ctx, "h")); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(2, duk::getGlobal<int>(m_ctx, "w")); + ASSERT_EQ(3, duk::getGlobal<int>(m_ctx, "h")); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, basic) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "s = new Malikania.Sprite('sprites/margins.json');" - "c = 0;" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "s = new Malikania.Sprite('sprites/margins.json');" + "c = 0;" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - for (unsigned c = 0; c < 12; ++c) { - auto ret = duk::pevalString(m_ctx, - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "s.draw(w, c++, { x: 320 - 16, y: 240 - 16 });" - "w.present();" - ); + for (unsigned c = 0; c < 12; ++c) { + auto ret = duk::pevalString(m_ctx, + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "s.draw(w, c++, { x: 320 - 16, y: 240 - 16 });" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(1s); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(1s); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/js-window/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-window/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME js-window - LIBRARIES libclient - SOURCES main.cpp + NAME js-window + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/js-window/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/js-window/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,62 +29,62 @@ class TestWindow : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; public: - TestWindow() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestWindow() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadMalikaniaWindow(m_ctx); - } + loadMalikaniaWindow(m_ctx); + } }; TEST_F(TestWindow, basic) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "w.present();" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestWindow, rect) { - try { - auto ret = duk::pevalString(m_ctx, - "w = new Malikania.Window();" - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "w.setDrawingColor('white');" - "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" - "w.present();" - ); + try { + auto ret = duk::pevalString(m_ctx, + "w = new Malikania.Window();" + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "w.setDrawingColor('white');" + "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" + "w.present();" + ); - if (ret != 0) { - throw duk::exception(m_ctx, -1); - } + if (ret != 0) { + throw duk::exception(m_ctx, -1); + } - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/line/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/line/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME line - LIBRARIES libclient - SOURCES main.cpp + NAME line + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/line/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/line/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,50 +24,50 @@ TEST(Basics, none) { - Line line; + Line line; - ASSERT_EQ(0, line.x1()); - ASSERT_EQ(0, line.y1()); - ASSERT_EQ(0, line.x2()); - ASSERT_EQ(0, line.y2()); + ASSERT_EQ(0, line.x1()); + ASSERT_EQ(0, line.y1()); + ASSERT_EQ(0, line.x2()); + ASSERT_EQ(0, line.y2()); } TEST(Basics, standard) { - Line line(10, 20, 30, 40); + Line line(10, 20, 30, 40); - ASSERT_EQ(10, line.x1()); - ASSERT_EQ(20, line.y1()); - ASSERT_EQ(30, line.x2()); - ASSERT_EQ(40, line.y2()); + ASSERT_EQ(10, line.x1()); + ASSERT_EQ(20, line.y1()); + ASSERT_EQ(30, line.x2()); + ASSERT_EQ(40, line.y2()); } TEST(Basics, operatorEq) { - Line line1, line2; + Line line1, line2; - ASSERT_EQ(line1, line2); + ASSERT_EQ(line1, line2); } TEST(Basics, operatorEq1) { - Line line1(10, 20, 30, 40); - Line line2(10, 20, 30, 40); + Line line1(10, 20, 30, 40); + Line line2(10, 20, 30, 40); - ASSERT_EQ(line1, line2); + ASSERT_EQ(line1, line2); } TEST(Basics, operatorNeq) { - ASSERT_NE(Line(10), Line(20)); - ASSERT_NE(Line(10, 10), Line(10, 20)); - ASSERT_NE(Line(10, 10, 10), Line(10, 10, 20)); - ASSERT_NE(Line(10, 10, 10, 10), Line(10, 10, 10, 20)); + ASSERT_NE(Line(10), Line(20)); + ASSERT_NE(Line(10, 10), Line(10, 20)); + ASSERT_NE(Line(10, 10, 10), Line(10, 10, 20)); + ASSERT_NE(Line(10, 10, 10, 10), Line(10, 10, 10, 20)); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/point/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/point/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME point - LIBRARIES libclient - SOURCES main.cpp + NAME point + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/point/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/point/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,44 +24,44 @@ TEST(Basics, none) { - Point point; + Point point; - ASSERT_EQ(0, point.x()); - ASSERT_EQ(0, point.y()); + ASSERT_EQ(0, point.x()); + ASSERT_EQ(0, point.y()); } TEST(Basics, standard) { - Point point(10, 20); + Point point(10, 20); - ASSERT_EQ(10, point.x()); - ASSERT_EQ(20, point.y()); + ASSERT_EQ(10, point.x()); + ASSERT_EQ(20, point.y()); } TEST(Basics, operatorEq) { - Point point1, point2; + Point point1, point2; - ASSERT_EQ(point1, point2); + ASSERT_EQ(point1, point2); } TEST(Basics, operatorEq1) { - Point point1(10, 20); - Point point2(10, 20); + Point point1(10, 20); + Point point2(10, 20); - ASSERT_EQ(point1, point2); + ASSERT_EQ(point1, point2); } TEST(Basics, operatorNeq) { - ASSERT_NE(Point(10), Point(20)); - ASSERT_NE(Point(10, 10), Point(10, 20)); + ASSERT_NE(Point(10), Point(20)); + ASSERT_NE(Point(10, 10), Point(10, 20)); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/rectangle/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/rectangle/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME rectangle - LIBRARIES libclient - SOURCES main.cpp + NAME rectangle + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/rectangle/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/rectangle/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,58 +24,58 @@ TEST(Basics, none) { - Rectangle rectangle; + Rectangle rectangle; - ASSERT_EQ(0, rectangle.x()); - ASSERT_EQ(0, rectangle.y()); - ASSERT_EQ(0U, rectangle.width()); - ASSERT_EQ(0U, rectangle.height()); + ASSERT_EQ(0, rectangle.x()); + ASSERT_EQ(0, rectangle.y()); + ASSERT_EQ(0U, rectangle.width()); + ASSERT_EQ(0U, rectangle.height()); } TEST(Basics, null) { - ASSERT_TRUE(Rectangle().isNull()); - ASSERT_FALSE(Rectangle(0, 0, 10, 0).isNull()); - ASSERT_FALSE(Rectangle(0, 0, 0, 10).isNull()); - ASSERT_FALSE(Rectangle(0, 0, 10, 10).isNull()); + ASSERT_TRUE(Rectangle().isNull()); + ASSERT_FALSE(Rectangle(0, 0, 10, 0).isNull()); + ASSERT_FALSE(Rectangle(0, 0, 0, 10).isNull()); + ASSERT_FALSE(Rectangle(0, 0, 10, 10).isNull()); } TEST(Basics, standard) { - Rectangle rectangle(10, 20, 30, 40); + Rectangle rectangle(10, 20, 30, 40); - ASSERT_EQ(10, rectangle.x()); - ASSERT_EQ(20, rectangle.y()); - ASSERT_EQ(30U, rectangle.width()); - ASSERT_EQ(40U, rectangle.height()); + ASSERT_EQ(10, rectangle.x()); + ASSERT_EQ(20, rectangle.y()); + ASSERT_EQ(30U, rectangle.width()); + ASSERT_EQ(40U, rectangle.height()); } TEST(Basics, operatorEq) { - Rectangle rectangle1, rectangle2; + Rectangle rectangle1, rectangle2; - ASSERT_EQ(rectangle1, rectangle2); + ASSERT_EQ(rectangle1, rectangle2); } TEST(Basics, operatorEq1) { - Rectangle rectangle1(10, 20, 30, 40); - Rectangle rectangle2(10, 20, 30, 40); + Rectangle rectangle1(10, 20, 30, 40); + Rectangle rectangle2(10, 20, 30, 40); - ASSERT_EQ(rectangle1, rectangle2); + ASSERT_EQ(rectangle1, rectangle2); } TEST(Basics, operatorNeq) { - ASSERT_NE(Rectangle(10), Rectangle(20)); - ASSERT_NE(Rectangle(10, 10), Rectangle(10, 20)); - ASSERT_NE(Rectangle(10, 10, 10), Rectangle(10, 10, 20)); - ASSERT_NE(Rectangle(10, 10, 10, 10), Rectangle(10, 10, 10, 20)); + ASSERT_NE(Rectangle(10), Rectangle(20)); + ASSERT_NE(Rectangle(10, 10), Rectangle(10, 20)); + ASSERT_NE(Rectangle(10, 10, 10), Rectangle(10, 10, 20)); + ASSERT_NE(Rectangle(10, 10, 10, 10), Rectangle(10, 10, 10, 20)); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/size/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/size/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME size - LIBRARIES libclient - SOURCES main.cpp + NAME size + LIBRARIES libclient + SOURCES main.cpp )
--- a/tests/libclient/size/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/size/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -24,51 +24,51 @@ TEST(Basics, none) { - Size size; + Size size; - ASSERT_EQ(0U, size.width()); - ASSERT_EQ(0U, size.height()); + ASSERT_EQ(0U, size.width()); + ASSERT_EQ(0U, size.height()); } TEST(Basics, null) { - ASSERT_TRUE(Size().isNull()); - ASSERT_FALSE(Size(0, 10).isNull()); - ASSERT_FALSE(Size(10, 0).isNull()); + ASSERT_TRUE(Size().isNull()); + ASSERT_FALSE(Size(0, 10).isNull()); + ASSERT_FALSE(Size(10, 0).isNull()); } TEST(Basics, standard) { - Size size(10, 20); + Size size(10, 20); - ASSERT_EQ(10U, size.width()); - ASSERT_EQ(20U, size.height()); + ASSERT_EQ(10U, size.width()); + ASSERT_EQ(20U, size.height()); } TEST(Basics, operatorEq) { - Size size1, size2; + Size size1, size2; - ASSERT_EQ(size1, size2); + ASSERT_EQ(size1, size2); } TEST(Basics, operatorEq1) { - Size size1(10, 20); - Size size2(10, 20); + Size size1(10, 20); + Size size2(10, 20); - ASSERT_EQ(size1, size2); + ASSERT_EQ(size1, size2); } TEST(Basics, operatorNeq) { - ASSERT_NE(Size(10), Size(20)); - ASSERT_NE(Size(10, 10), Size(10, 20)); + ASSERT_NE(Size(10), Size(20)); + ASSERT_NE(Size(10, 10), Size(10, 20)); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libclient/sprite/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/sprite/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,20 +17,20 @@ # malikania_create_test( - NAME sprite - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/images/mokodemo.png - resources/images/margins.png - resources/sprites/no-property-cell.json - resources/sprites/no-property-image.json - resources/sprites/image-not-found.json - resources/sprites/not-object.json - resources/sprites/property-image-not-string.json - resources/sprites/property-cell-not-array.json - resources/sprites/property-cell-not-array2.json - resources/sprites/simple.json - resources/sprites/margins.json + NAME sprite + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/images/mokodemo.png + resources/images/margins.png + resources/sprites/no-property-cell.json + resources/sprites/no-property-image.json + resources/sprites/image-not-found.json + resources/sprites/not-object.json + resources/sprites/property-image-not-string.json + resources/sprites/property-cell-not-array.json + resources/sprites/property-cell-not-array2.json + resources/sprites/simple.json + resources/sprites/margins.json )
--- a/tests/libclient/sprite/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libclient/sprite/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -39,15 +39,15 @@ class TestSprite : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; public: - TestSprite() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } + TestSprite() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } }; /* @@ -57,22 +57,22 @@ TEST_F(TestSprite, missingPropertyImage) { - try { - m_loader.loadSprite("sprites/no-property-image.json"); + try { + m_loader.loadSprite("sprites/no-property-image.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } TEST_F(TestSprite, missingPropertyCell) { - try { - m_loader.loadSprite("sprites/no-property-cell.json"); + try { + m_loader.loadSprite("sprites/no-property-cell.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -82,32 +82,32 @@ TEST_F(TestSprite, imageNotString) { - try { - m_loader.loadSprite("sprites/property-image-not-string.json"); + try { + m_loader.loadSprite("sprites/property-image-not-string.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } TEST_F(TestSprite, cellNotArray) { - try { - m_loader.loadSprite("sprites/property-cell-not-array.json"); + try { + m_loader.loadSprite("sprites/property-cell-not-array.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } TEST_F(TestSprite, cellNotArray2) { - try { - m_loader.loadSprite("sprites/property-cell-not-array2.json"); + try { + m_loader.loadSprite("sprites/property-cell-not-array2.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -117,22 +117,22 @@ TEST_F(TestSprite, imageNotFound) { - try { - m_loader.loadSprite("sprites/image-not-found.json"); + try { + m_loader.loadSprite("sprites/image-not-found.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } TEST_F(TestSprite, notObject) { - try { - m_loader.loadSprite("sprites/not-object.json"); + try { + m_loader.loadSprite("sprites/not-object.json"); - FAIL() << "exception expected"; - } catch (const std::exception &) { - } + FAIL() << "exception expected"; + } catch (const std::exception &) { + } } /* @@ -142,53 +142,53 @@ TEST_F(TestSprite, standard) { - try { - Sprite sprite = m_loader.loadSprite("sprites/simple.json"); + try { + Sprite sprite = m_loader.loadSprite("sprites/simple.json"); - ASSERT_EQ(300U, sprite.cell().width()); - ASSERT_EQ(300U, sprite.cell().height()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(300U, sprite.cell().width()); + ASSERT_EQ(300U, sprite.cell().height()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, margins) { - try { - Sprite sprite = m_loader.loadSprite("sprites/margins.json"); + try { + Sprite sprite = m_loader.loadSprite("sprites/margins.json"); - ASSERT_EQ(3U, sprite.rows()); - ASSERT_EQ(4U, sprite.columns()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(3U, sprite.rows()); + ASSERT_EQ(4U, sprite.columns()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, draw) { - try { - Sprite sprite = m_loader.loadSprite("sprites/margins.json"); + try { + Sprite sprite = m_loader.loadSprite("sprites/margins.json"); - unsigned total = sprite.rows() * sprite.columns(); + unsigned total = sprite.rows() * sprite.columns(); - auto x = (400 / 2) - (sprite.cell().width() / 2); - auto y = (400 / 2) - (sprite.cell().height() / 2); + auto x = (400 / 2) - (sprite.cell().width() / 2); + auto y = (400 / 2) - (sprite.cell().height() / 2); - for (unsigned c = 0; c < total; ++c) { - window.clear(); - sprite.draw(window, c, Point(x, y)); - window.present(); + for (unsigned c = 0; c < total; ++c) { + window.clear(); + sprite.draw(window, c, Point(x, y)); + window.present(); - std::this_thread::sleep_for(1s); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(1s); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libcommon/elapsed-timer/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/elapsed-timer/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME elapsedtimer - LIBRARIES libcommon - SOURCES main.cpp + NAME elapsedtimer + LIBRARIES libcommon + SOURCES main.cpp )
--- a/tests/libcommon/elapsed-timer/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/elapsed-timer/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -32,69 +32,69 @@ class TestElapsedTimer : public testing::Test { protected: - ElapsedTimer m_timer; + ElapsedTimer m_timer; - inline void assertRange(int value, int expected) const noexcept - { - if (value < (expected - margin) || value > (expected + margin)) { - FAIL() << value << " is bigger than [" << (expected - margin) << ", " << (expected + margin) << "]"; - } - } + inline void assertRange(int value, int expected) const noexcept + { + if (value < (expected - margin) || value > (expected + margin)) { + FAIL() << value << " is bigger than [" << (expected - margin) << ", " << (expected + margin) << "]"; + } + } }; TEST_F(TestElapsedTimer, standard) { - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - assertRange(m_timer.elapsed(), 300); + assertRange(m_timer.elapsed(), 300); } TEST_F(TestElapsedTimer, reset) { - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - m_timer.reset(); + m_timer.reset(); - assertRange(m_timer.elapsed(), 0); + assertRange(m_timer.elapsed(), 0); } TEST_F(TestElapsedTimer, pause) { - /* - * Simulate a pause in the game like this: - * - * start pause restart elapsed - * | 10ms |.5ms.| 6ms | - * - * Since the game was paused, the 5ms must not be totalized. - */ - std::this_thread::sleep_for(10ms); + /* + * Simulate a pause in the game like this: + * + * start pause restart elapsed + * | 10ms |.5ms.| 6ms | + * + * Since the game was paused, the 5ms must not be totalized. + */ + std::this_thread::sleep_for(10ms); - m_timer.pause(); + m_timer.pause(); - std::this_thread::sleep_for(5ms); + std::this_thread::sleep_for(5ms); - m_timer.restart(); + m_timer.restart(); - std::this_thread::sleep_for(6ms); + std::this_thread::sleep_for(6ms); - assertRange(m_timer.elapsed(), 16); + assertRange(m_timer.elapsed(), 16); } TEST_F(TestElapsedTimer, doublecheck) { - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(50ms); - (void)m_timer.elapsed(); + (void)m_timer.elapsed(); - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(50ms); - assertRange(m_timer.elapsed(), 100); + assertRange(m_timer.elapsed(), 100); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libcommon/js-elapsed-timer/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/js-elapsed-timer/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,8 +17,8 @@ # malikania_create_test( - NAME js-elapsed-timer - LIBRARIES libcommon - SOURCES main.cpp + NAME js-elapsed-timer + LIBRARIES libcommon + SOURCES main.cpp )
--- a/tests/libcommon/js-elapsed-timer/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/js-elapsed-timer/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -33,116 +33,116 @@ class TestElapsedTimer : public testing::Test { protected: - duk::Context m_ctx; + duk::Context m_ctx; - TestElapsedTimer() - { - duk::putGlobal(m_ctx, "Malikania", duk::Object()); + TestElapsedTimer() + { + duk::putGlobal(m_ctx, "Malikania", duk::Object()); - loadJsElapsedTimer(m_ctx); - } + loadJsElapsedTimer(m_ctx); + } - inline void assertRange(int value, int expected) const noexcept - { - if (value < (expected - margin) || value > (expected + margin)) - FAIL() << value << " is bigger than [" << (expected - margin) << ", " << (expected + margin) << "]"; - } + inline void assertRange(int value, int expected) const noexcept + { + if (value < (expected - margin) || value > (expected + margin)) + FAIL() << value << " is bigger than [" << (expected - margin) << ", " << (expected + margin) << "]"; + } }; TEST_F(TestElapsedTimer, standard) { - try { - if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) - throw duk::exception(m_ctx, -1); + try { + if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - if (duk::pevalString(m_ctx, "result = timer.elapsed();") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "result = timer.elapsed();") != 0) + throw duk::exception(m_ctx, -1); - assertRange(duk::getGlobal<int>(m_ctx, "result"), 300); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + assertRange(duk::getGlobal<int>(m_ctx, "result"), 300); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestElapsedTimer, reset) { - try { - if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) - throw duk::exception(m_ctx, -1); + try { + if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - if (duk::pevalString(m_ctx, "timer.reset(); result = timer.elapsed();") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "timer.reset(); result = timer.elapsed();") != 0) + throw duk::exception(m_ctx, -1); - assertRange(duk::getGlobal<int>(m_ctx, "result"), 0); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + assertRange(duk::getGlobal<int>(m_ctx, "result"), 0); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestElapsedTimer, pause) { - try { - if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) - throw duk::exception(m_ctx, -1); + try { + if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) + throw duk::exception(m_ctx, -1); - /* - * Simulate a pause in the game like this: - * - * start pause restart elapsed - * | 10ms |.5ms.| 6ms | - * - * Since the game was paused, the 5ms must not be totalized. - */ - std::this_thread::sleep_for(10ms); + /* + * Simulate a pause in the game like this: + * + * start pause restart elapsed + * | 10ms |.5ms.| 6ms | + * + * Since the game was paused, the 5ms must not be totalized. + */ + std::this_thread::sleep_for(10ms); - if (duk::pevalString(m_ctx, "timer.pause();") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "timer.pause();") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(5ms); + std::this_thread::sleep_for(5ms); - if (duk::pevalString(m_ctx, "timer.restart();") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "timer.restart();") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(6ms); + std::this_thread::sleep_for(6ms); - if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) + throw duk::exception(m_ctx, -1); - assertRange(duk::getGlobal<int>(m_ctx, "result"), 16); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + assertRange(duk::getGlobal<int>(m_ctx, "result"), 16); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestElapsedTimer, doublecheck) { - try { - if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) - throw duk::exception(m_ctx, -1); + try { + if (duk::pevalString(m_ctx, "timer = new Malikania.ElapsedTimer();") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(50ms); - if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) + throw duk::exception(m_ctx, -1); - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(50ms); - if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) - throw duk::exception(m_ctx, -1); + if (duk::pevalString(m_ctx, "result = timer.elapsed()") != 0) + throw duk::exception(m_ctx, -1); - assertRange(duk::getGlobal<int>(m_ctx, "result"), 100); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + assertRange(duk::getGlobal<int>(m_ctx, "result"), 100); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libcommon/util/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/util/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME util - LIBRARIES libcommon - SOURCES main.cpp + NAME util + LIBRARIES libcommon + SOURCES main.cpp )
--- a/tests/libcommon/util/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libcommon/util/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -29,27 +29,27 @@ TEST(Clamp, normal) { - ASSERT_EQ(5, util::clamp(5, 0, 10)); + ASSERT_EQ(5, util::clamp(5, 0, 10)); } TEST(Clamp, minimum) { - ASSERT_EQ(0, util::clamp(0, 0, 10)); + ASSERT_EQ(0, util::clamp(0, 0, 10)); } TEST(Clamp, maximum) { - ASSERT_EQ(10, util::clamp(10, 0, 10)); + ASSERT_EQ(10, util::clamp(10, 0, 10)); } TEST(Clamp, less) { - ASSERT_EQ(0, util::clamp(-10, 0, 10)); + ASSERT_EQ(0, util::clamp(-10, 0, 10)); } TEST(Clamp, higher) { - ASSERT_EQ(10, util::clamp(20, 0, 10)); + ASSERT_EQ(10, util::clamp(20, 0, 10)); } /* @@ -59,49 +59,49 @@ TEST(Netsplit, simple) { - std::string input = "hello world\r\n\r\n"; - std::vector<std::string> messages = util::netsplit(input); + std::string input = "hello world\r\n\r\n"; + std::vector<std::string> messages = util::netsplit(input); - ASSERT_EQ(1U, messages.size()); - ASSERT_EQ("hello world", messages[0]); - ASSERT_TRUE(input.empty()); + ASSERT_EQ(1U, messages.size()); + ASSERT_EQ("hello world", messages[0]); + ASSERT_TRUE(input.empty()); } TEST(Netsplit, two) { - std::string input = "hello world\r\n\r\nhow are you?\r\n\r\n"; - std::vector<std::string> messages = util::netsplit(input); + std::string input = "hello world\r\n\r\nhow are you?\r\n\r\n"; + std::vector<std::string> messages = util::netsplit(input); - ASSERT_EQ(2U, messages.size()); - ASSERT_EQ("hello world", messages[0]); - ASSERT_EQ("how are you?", messages[1]); - ASSERT_TRUE(input.empty()); + ASSERT_EQ(2U, messages.size()); + ASSERT_EQ("hello world", messages[0]); + ASSERT_EQ("how are you?", messages[1]); + ASSERT_TRUE(input.empty()); } TEST(Netsplit, imcomplete) { - std::string input = "hello world\r\n"; - std::vector<std::string> messages = util::netsplit(input); + std::string input = "hello world\r\n"; + std::vector<std::string> messages = util::netsplit(input); - ASSERT_EQ(0U, messages.size()); - ASSERT_EQ("hello world\r\n", input); + ASSERT_EQ(0U, messages.size()); + ASSERT_EQ("hello world\r\n", input); } TEST(Netsplit, empty) { - std::string input = "hello world\r\n\r\n\r\n\r\nhow are you?\r\n\r\n"; - std::vector<std::string> messages = util::netsplit(input); + std::string input = "hello world\r\n\r\n\r\n\r\nhow are you?\r\n\r\n"; + std::vector<std::string> messages = util::netsplit(input); - ASSERT_EQ(3U, messages.size()); - ASSERT_EQ("hello world", messages[0]); - ASSERT_TRUE(messages[1].empty()); - ASSERT_EQ("how are you?", messages[2]); - ASSERT_TRUE(input.empty()); + ASSERT_EQ(3U, messages.size()); + ASSERT_EQ("hello world", messages[0]); + ASSERT_TRUE(messages[1].empty()); + ASSERT_EQ("how are you?", messages[2]); + ASSERT_TRUE(input.empty()); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libserver/dao-account/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libserver/dao-account/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,9 +17,9 @@ # malikania_create_test( - NAME dao-account - LIBRARIES libmlk-server - SOURCES main.cpp + NAME dao-account + LIBRARIES libmlk-server + SOURCES main.cpp ) target_compile_definitions(test-dao-account PRIVATE DRIVERDIR=\"${CMAKE_BINARY_DIR}/fakeroot/${WITH_DRIVERDIR}/\")
--- a/tests/libserver/dao-account/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libserver/dao-account/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -30,76 +30,76 @@ class TestAccountDao : public testing::Test { protected: - Database m_database; - AccountDao m_dao; + Database m_database; + AccountDao m_dao; public: - TestAccountDao() - : m_database(DRIVERDIR "pgsql.so", { - { "host", WITH_TEST_PGSQL_HOST }, - { "port", WITH_TEST_PGSQL_PORT }, - { "user", WITH_TEST_PGSQL_USER }, - { "database", WITH_TEST_PGSQL_DATABASE } - }) - , m_dao(m_database) - { - m_dao.clear(); + TestAccountDao() + : m_database(DRIVERDIR "pgsql.so", { + { "host", WITH_TEST_PGSQL_HOST }, + { "port", WITH_TEST_PGSQL_PORT }, + { "user", WITH_TEST_PGSQL_USER }, + { "database", WITH_TEST_PGSQL_DATABASE } + }) + , m_dao(m_database) + { + m_dao.clear(); - assert(m_dao.count() == 0U); - } + assert(m_dao.count() == 0U); + } }; TEST_F(TestAccountDao, create) { - try { - Account ac; + try { + Account ac; - ac.setName("jean"); - ac.setEmail("jean@christophe.fr"); - ac.setFirstName("Jean"); - ac.setLastName("Christophe"); - ac.setPassword("raw"); + ac.setName("jean"); + ac.setEmail("jean@christophe.fr"); + ac.setFirstName("Jean"); + ac.setLastName("Christophe"); + ac.setPassword("raw"); - m_dao.create(ac); + m_dao.create(ac); - ASSERT_EQ(1U, m_dao.count()); - ASSERT_EQ(ac, m_dao.list()[0]); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(1U, m_dao.count()); + ASSERT_EQ(ac, m_dao.list()[0]); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestAccountDao, update) { - try { - Account ac; + try { + Account ac; - ac.setName("jean"); - ac.setEmail("jean@christophe.fr"); - ac.setFirstName("Jean"); - ac.setLastName("Christophe"); - ac.setPassword("raw"); + ac.setName("jean"); + ac.setEmail("jean@christophe.fr"); + ac.setFirstName("Jean"); + ac.setLastName("Christophe"); + ac.setPassword("raw"); - m_dao.create(ac); + m_dao.create(ac); - ac.setEmail("benoit@christophe.fr"); - ac.setFirstName("Benoit"); + ac.setEmail("benoit@christophe.fr"); + ac.setFirstName("Benoit"); - m_dao.update(ac); + m_dao.update(ac); - Account ac2 = m_dao.get(ac.id()); + Account ac2 = m_dao.get(ac.id()); - ASSERT_EQ("jean", ac2.name()); - ASSERT_EQ("benoit@christophe.fr", ac2.email()); - ASSERT_EQ("Benoit", ac2.firstName()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("jean", ac2.name()); + ASSERT_EQ("benoit@christophe.fr", ac2.email()); + ASSERT_EQ("Benoit", ac2.firstName()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/tests/libserver/id/CMakeLists.txt Thu May 26 07:32:05 2016 +0200 +++ b/tests/libserver/id/CMakeLists.txt Thu Jun 16 13:35:31 2016 +0200 @@ -17,7 +17,7 @@ # malikania_create_test( - NAME id - LIBRARIES libcommon - SOURCES main.cpp + NAME id + LIBRARIES libcommon + SOURCES main.cpp )
--- a/tests/libserver/id/main.cpp Thu May 26 07:32:05 2016 +0200 +++ b/tests/libserver/id/main.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -31,69 +31,69 @@ class TestId : public testing::Test { protected: - IdGen<unsigned> m_idgen; + IdGen<unsigned> m_idgen; public: - ~TestId() - { - m_idgen.reset(); - } + ~TestId() + { + m_idgen.reset(); + } }; TEST_F(TestId, simple) { - ASSERT_EQ(0U, m_idgen.next()); - ASSERT_EQ(1U, m_idgen.next()); - ASSERT_EQ(2U, m_idgen.next()); - ASSERT_EQ(3U, m_idgen.next()); - ASSERT_EQ(4U, m_idgen.next()); + ASSERT_EQ(0U, m_idgen.next()); + ASSERT_EQ(1U, m_idgen.next()); + ASSERT_EQ(2U, m_idgen.next()); + ASSERT_EQ(3U, m_idgen.next()); + ASSERT_EQ(4U, m_idgen.next()); } TEST_F(TestId, reset) { - m_idgen.next(); - m_idgen.next(); - m_idgen.next(); + m_idgen.next(); + m_idgen.next(); + m_idgen.next(); - m_idgen.reset(); + m_idgen.reset(); - ASSERT_EQ(0U, m_idgen.next()); + ASSERT_EQ(0U, m_idgen.next()); } TEST_F(TestId, release1) { - m_idgen.next(); // 0 - m_idgen.next(); // 1 - m_idgen.next(); // 2 - m_idgen.release(1); + m_idgen.next(); // 0 + m_idgen.next(); // 1 + m_idgen.next(); // 2 + m_idgen.release(1); - /* - * 0 and 2 are currently in use. - * - * The next id must be 1 and then 3. - */ - ASSERT_EQ(1U, m_idgen.next()); - ASSERT_EQ(3U, m_idgen.next()); + /* + * 0 and 2 are currently in use. + * + * The next id must be 1 and then 3. + */ + ASSERT_EQ(1U, m_idgen.next()); + ASSERT_EQ(3U, m_idgen.next()); } TEST_F(TestId, release2) { - m_idgen.next(); // 0 - m_idgen.next(); // 1 - m_idgen.next(); // 2 - m_idgen.release(1); - m_idgen.release(0); + m_idgen.next(); // 0 + m_idgen.next(); // 1 + m_idgen.next(); // 2 + m_idgen.release(1); + m_idgen.release(0); - /* - * Only 2 is in use, next id must be: - * - * - 1 - * - 0 - * - 3 - */ - ASSERT_EQ(1U, m_idgen.next()); - ASSERT_EQ(0U, m_idgen.next()); - ASSERT_EQ(3U, m_idgen.next()); + /* + * Only 2 is in use, next id must be: + * + * - 1 + * - 0 + * - 3 + */ + ASSERT_EQ(1U, m_idgen.next()); + ASSERT_EQ(0U, m_idgen.next()); + ASSERT_EQ(3U, m_idgen.next()); } /* -------------------------------------------------------- @@ -102,28 +102,28 @@ TEST(IdLocker, basic) { - IdGen<int8_t> gen; - Id<int8_t> id(gen); + IdGen<int8_t> gen; + Id<int8_t> id(gen); - ASSERT_EQ(0, id); + ASSERT_EQ(0, id); } TEST(IdLocker, two) { - IdGen<int8_t> gen; - Id<int8_t> id(gen); - Id<int8_t> id2(gen); + IdGen<int8_t> gen; + Id<int8_t> id(gen); + Id<int8_t> id2(gen); - ASSERT_EQ(0, id); - ASSERT_EQ(1, id2); + ASSERT_EQ(0, id); + ASSERT_EQ(1, id2); } TEST(IdLocker, already) { - IdGen<int8_t> gen; - Id<int8_t> id(gen, gen.next()); + IdGen<int8_t> gen; + Id<int8_t> id(gen, gen.next()); - ASSERT_EQ(0, id); + ASSERT_EQ(0, id); } /* -------------------------------------------------------- @@ -132,40 +132,40 @@ TEST(Limits, max) { - IdGen<int8_t> idgen; - int8_t last; + IdGen<int8_t> idgen; + int8_t last; - try { - for (int i = 0; i < 127; ++i) { - last = idgen.next(); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + try { + for (int i = 0; i < 127; ++i) { + last = idgen.next(); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } - ASSERT_EQ(126, last); + ASSERT_EQ(126, last); } TEST(Limits, fail) { - IdGen<int8_t> idgen; - int8_t last; + IdGen<int8_t> idgen; + int8_t last; - try { - for (int i = 0; i < 200; ++i) { - last = idgen.next(); - } + try { + for (int i = 0; i < 200; ++i) { + last = idgen.next(); + } - FAIL() << "Exception expected"; - } catch (const std::exception &ex) { - } + FAIL() << "Exception expected"; + } catch (const std::exception &ex) { + } - ASSERT_EQ(126, last); + ASSERT_EQ(126, last); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }