Mercurial > malikania
changeset 33:d4f5f7231b84
Misc: switch to .hpp, dos2unix everything while here, #478
line wrap: on
line diff
--- a/AUTHORS.md Fri Jun 17 13:07:05 2016 +0200 +++ b/AUTHORS.md Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -Malikania Engine AUTHORS -======================== - - - David Demelier <markand@malikania.fr> - - Alexis Dörr <nanahara@malikania.fr> - - Renaud Jenny <renox0@malikania.fr> +Malikania Engine AUTHORS +======================== + + - David Demelier <markand@malikania.fr> + - Alexis Dörr <nanahara@malikania.fr> + - Renaud Jenny <renox0@malikania.fr>
--- a/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,65 +1,65 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -cmake_minimum_required(VERSION 3.0) -project(malikania) - -set( - CMAKE_MODULE_PATH - "${malikania_SOURCE_DIR}/cmake" - "${malikania_SOURCE_DIR}/cmake/internal" - "${malikania_SOURCE_DIR}/cmake/packages" -) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - -include(cmake/MalikaniaVersion.cmake) -include(cmake/MalikaniaOptions.cmake) -include(cmake/MalikaniaFunctions.cmake) -include(cmake/MalikaniaSystem.cmake) - -configure_file( - ${malikania_SOURCE_DIR}/cmake/internal/Config.h.in - ${malikania_BINARY_DIR}/Config.h -) - -include_directories(${CMAKE_BINARY_DIR}) -enable_testing() - -find_package(ZIP REQUIRED) -find_package(OpenSSL REQUIRED) - -add_subdirectory(extern) -add_subdirectory(database) -add_subdirectory(docs) -add_subdirectory(libcommon) -add_subdirectory(libclient) -add_subdirectory(libserver) -add_subdirectory(client) -add_subdirectory(server) -add_subdirectory(tests) - -message("Building information:") -message(" General flags: ${CMAKE_CXX_FLAGS}") -message(" Debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") -message(" Release flags: ${CMAKE_CXX_FLAGS_RELEASE}") -message("") -message("Documentation:") -message(" Doxygen: ${WITH_DOCS_DOXYGEN_MSG}") +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +cmake_minimum_required(VERSION 3.0) +project(malikania) + +set( + CMAKE_MODULE_PATH + "${malikania_SOURCE_DIR}/cmake" + "${malikania_SOURCE_DIR}/cmake/internal" + "${malikania_SOURCE_DIR}/cmake/packages" +) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + +include(cmake/MalikaniaVersion.cmake) +include(cmake/MalikaniaOptions.cmake) +include(cmake/MalikaniaFunctions.cmake) +include(cmake/MalikaniaSystem.cmake) + +configure_file( + ${malikania_SOURCE_DIR}/cmake/internal/Config.h.in + ${malikania_BINARY_DIR}/Config.h +) + +include_directories(${CMAKE_BINARY_DIR}) +enable_testing() + +find_package(ZIP REQUIRED) +find_package(OpenSSL REQUIRED) + +add_subdirectory(extern) +add_subdirectory(database) +add_subdirectory(docs) +add_subdirectory(libcommon) +add_subdirectory(libclient) +add_subdirectory(libserver) +add_subdirectory(client) +add_subdirectory(server) +add_subdirectory(tests) + +message("Building information:") +message(" General flags: ${CMAKE_CXX_FLAGS}") +message(" Debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") +message(" Release flags: ${CMAKE_CXX_FLAGS_RELEASE}") +message("") +message("Documentation:") +message(" Doxygen: ${WITH_DOCS_DOXYGEN_MSG}")
--- a/LICENSE.md Fri Jun 17 13:07:05 2016 +0200 +++ b/LICENSE.md Fri Jun 17 13:12:35 2016 +0200 @@ -1,16 +1,16 @@ -Malikania Engine LICENSE -======================== - -Copyright (c) 2013-2016 Malikania Authors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +Malikania Engine LICENSE +======================== + +Copyright (c) 2013-2016 Malikania Authors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--- a/README.md Fri Jun 17 13:07:05 2016 +0200 +++ b/README.md Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -Malikania Engine README -======================= - -Malikania Engine is a free, opensource 2D MMORPG engine. +Malikania Engine README +======================= + +Malikania Engine is a free, opensource 2D MMORPG engine.
--- a/client/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/client/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,28 +1,28 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(client) - -set( - FILES - main.cpp -) - -add_executable(mlk-client ${FILES}) -target_include_directories(mlk-client PRIVATE ${client_SOURCE_DIR}) -target_link_libraries(mlk-client libcommon libclient) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(client) + +set( + FILES + main.cpp +) + +add_executable(mlk-client ${FILES}) +target_include_directories(mlk-client PRIVATE ${client_SOURCE_DIR}) +target_link_libraries(mlk-client libcommon libclient)
--- a/client/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/client/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,210 +1,210 @@ -/* - * main.cpp -- main client file - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <chrono> -#include <iostream> -#include <thread> - -#include <malikania/client-resources-loader.h> -#include <malikania/resources-locator.h> - -#include <malikania/js-animation.h> -#include <malikania/js-animator.h> -#include <malikania/js-client.h> -#include <malikania/js-client-target.h> -#include <malikania/js-color.h> -#include <malikania/js-font.h> -#include <malikania/js-image.h> -#include <malikania/js-line.h> -#include <malikania/js-point.h> -#include <malikania/js-rectangle.h> -#include <malikania/js-size.h> -#include <malikania/js-sprite.h> -#include <malikania/js-window.h> - -using namespace malikania; - -namespace { - -int usage() -{ - std::cerr << "usage: mlk-client directory\n"; - - return 1; -} - -duk::Context init() -{ - duk::Context ctx; - - /* 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); - - return ctx; -} - -void start(duk::Context &ctx, std::shared_ptr<Client> client) -{ - 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); - } -} - -void update(duk::Context &ctx, std::shared_ptr<Client> client) -{ - 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(); - } -} - -void draw(duk::Context &ctx, std::shared_ptr<Client> client) -{ - 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(); - } -} - -int run(duk::Context &ctx) -{ - auto running = true; - auto client = std::make_shared<Client>(); - - 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); - } - }); - - start(ctx, client); - - while (running) { - client->poll(); - - update(ctx, client); - draw(ctx, client); - - // TODO: remove this with an appropriate FPS calculation. - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } - - return 0; -} - -int boot(const std::string &directory) -{ - std::string path = directory + "/client.js"; - duk::Context ctx = init(); - - /* Store the loader */ - ResourcesLocatorDirectory locator(directory); - ClientResourcesLoader loader(locator); - - duk::putGlobal(ctx, "\xff""\xff""loader", &loader); - - if (duk::pevalFile(ctx, path) != 0) { - duk::Exception info = duk::exception(ctx, -1); - - std::cerr << info.fileName << ":" << info.lineNumber << ": " << info.stack << std::endl; - - return 1; - } - - return run(ctx); -} - -} // !namespace - -int main(int argc, char **argv) -{ -#if 0 - -- argc; - ++ argv; - - if (argc < 1) { - return usage(); - } - - return boot(argv[0]); -#endif - Client client; - ElapsedTimer timer; - - while (timer.elapsed() < 5000) { - client.poll(); - client.update(); - client.draw(); - - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } - - return 0; -} +/* + * main.cpp -- main client file + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <chrono> +#include <iostream> +#include <thread> + +#include <malikania/client-resources-loader.hpp> +#include <malikania/resources-locator.hpp> + +#include <malikania/js-animation.hpp> +#include <malikania/js-animator.hpp> +#include <malikania/js-client.hpp> +#include <malikania/js-client-target.hpp> +#include <malikania/js-color.hpp> +#include <malikania/js-font.hpp> +#include <malikania/js-image.hpp> +#include <malikania/js-line.hpp> +#include <malikania/js-point.hpp> +#include <malikania/js-rectangle.hpp> +#include <malikania/js-size.hpp> +#include <malikania/js-sprite.hpp> +#include <malikania/js-window.hpp> + +using namespace malikania; + +namespace { + +int usage() +{ + std::cerr << "usage: mlk-client directory\n"; + + return 1; +} + +duk::Context init() +{ + duk::Context ctx; + + /* 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); + + return ctx; +} + +void start(duk::Context &ctx, std::shared_ptr<Client> client) +{ + 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); + } +} + +void update(duk::Context &ctx, std::shared_ptr<Client> client) +{ + 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(); + } +} + +void draw(duk::Context &ctx, std::shared_ptr<Client> client) +{ + 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(); + } +} + +int run(duk::Context &ctx) +{ + auto running = true; + auto client = std::make_shared<Client>(); + + 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); + } + }); + + start(ctx, client); + + while (running) { + client->poll(); + + update(ctx, client); + draw(ctx, client); + + // TODO: remove this with an appropriate FPS calculation. + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + + return 0; +} + +int boot(const std::string &directory) +{ + std::string path = directory + "/client.js"; + duk::Context ctx = init(); + + /* Store the loader */ + ResourcesLocatorDirectory locator(directory); + ClientResourcesLoader loader(locator); + + duk::putGlobal(ctx, "\xff""\xff""loader", &loader); + + if (duk::pevalFile(ctx, path) != 0) { + duk::Exception info = duk::exception(ctx, -1); + + std::cerr << info.fileName << ":" << info.lineNumber << ": " << info.stack << std::endl; + + return 1; + } + + return run(ctx); +} + +} // !namespace + +int main(int argc, char **argv) +{ +#if 0 + -- argc; + ++ argv; + + if (argc < 1) { + return usage(); + } + + return boot(argv[0]); +#endif + Client client; + ElapsedTimer timer; + + while (timer.elapsed() < 5000) { + client.poll(); + client.update(); + client.draw(); + + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + + return 0; +}
--- a/cmake/CMake.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/CMake.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,57 +1,57 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013, 2014, 2015 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(cmake) - -# -# 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 -# -set( - FILES - MalikaniaConfig.cmake - Macros.cmake - System.cmake - Version.cmake -) - -if (WIN32) - set(DIRECTORY "Malikania") -elseif (UNIX) - set(DIRECTORY "share/malikania/cmake") -elseif (APPLE) - set(DIRECTORY "malikania.framework/Resources/CMake") -endif () - -install( - 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 -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013, 2014, 2015 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(cmake) + +# +# 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 +# +set( + FILES + MalikaniaConfig.cmake + Macros.cmake + System.cmake + Version.cmake +) + +if (WIN32) + set(DIRECTORY "Malikania") +elseif (UNIX) + set(DIRECTORY "share/malikania/cmake") +elseif (APPLE) + set(DIRECTORY "malikania.framework/Resources/CMake") +endif () + +install( + 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 +)
--- a/cmake/MalikaniaConfig.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/MalikaniaConfig.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,21 +1,21 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013, 2014, 2015 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -include(System) -include(Version) -include(Macros) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013, 2014, 2015 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +include(System) +include(Version) +include(Macros)
--- a/cmake/MalikaniaFunctions.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/MalikaniaFunctions.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,224 +1,224 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -include(CMakeParseArguments) - -# --------------------------------------------------------- -# The following macros are available: -# -# malikania_define_executable -# --------------------------- -# -# 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 -# ) -# -# Create an executable. Be sure to quote SOURCES, if not only the first file will be passed. -# If you need flags, just pass them without -D or /D, this is automatically done for you. -# -# malikania_create_library -# ------------------------ -# -# 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 -# ) -# -# Create a shared library. Follow the same specification as malikania_define_executable. -# However, additional PRIVATE_INCLUDES and PUBLIC_INCLUDES are available. -# -# malikania_create_test -# --------------------- -# -# 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 -# ) -# -# This will generate a target named test-<name> where name is the parameter NAME. The test is created -# under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy. -# -# setg -# ---- -# -# setg(var value) -# -# Set a cache variable internal with name var. -# -# --------------------------------------------------------- - -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 () -endfunction() - -function(apply_public_includes target var) - 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} - ) -endfunction() - -function(apply_private_includes target var) - if (${var}) - target_include_directories(${target} PRIVATE ${${var}}) - endif () -endfunction() - -function(apply_includes target var) - if (${var}) - target_include_directories(${target} PRIVATE ${${var}}) - endif () -endfunction() - -function(apply_libraries target libs) - 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 () -endfunction() - -function(malikania_define_executable) - set(singleArgs TARGET) - set(multiArgs SOURCES FLAGS INCLUDES LIBRARIES) - set(mandatory TARGET SOURCES) - - cmake_parse_arguments(EXE "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(EXE ${mandatory}) - - add_executable(${EXE_TARGET} ${EXE_SOURCES}) - - 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) - - cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(LIB ${mandatory}) - - 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 "" - ) - - 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) -endfunction() - -function(malikania_create_test) - set(singleArgs NAME) - set(multiArgs LIBRARIES SOURCES RESOURCES) - - set(mandatory NAME SOURCES) - - cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) - check_args(TEST ${mandatory}) - - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) - - 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}) - - add_custom_command( - OUTPUT ${output} - COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} - DEPENDS ${absolute} - ) - - 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} - ) - - target_link_libraries( - test-${TEST_NAME} - ${TEST_LIBRARIES} - gtest - ) - - add_dependencies(tests test-${TEST_NAME}) -endfunction() - -macro(setg var value) - set(${var} ${value} CACHE INTERNAL "" FORCE) -endmacro() +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +include(CMakeParseArguments) + +# --------------------------------------------------------- +# The following macros are available: +# +# malikania_define_executable +# --------------------------- +# +# 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 +# ) +# +# Create an executable. Be sure to quote SOURCES, if not only the first file will be passed. +# If you need flags, just pass them without -D or /D, this is automatically done for you. +# +# malikania_create_library +# ------------------------ +# +# 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 +# ) +# +# Create a shared library. Follow the same specification as malikania_define_executable. +# However, additional PRIVATE_INCLUDES and PUBLIC_INCLUDES are available. +# +# malikania_create_test +# --------------------- +# +# 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 +# ) +# +# This will generate a target named test-<name> where name is the parameter NAME. The test is created +# under CMAKE_BINARY_DIR/test/<NAME> and resources are copied there with the same hierarchy. +# +# setg +# ---- +# +# setg(var value) +# +# Set a cache variable internal with name var. +# +# --------------------------------------------------------- + +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 () +endfunction() + +function(apply_public_includes target var) + 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} + ) +endfunction() + +function(apply_private_includes target var) + if (${var}) + target_include_directories(${target} PRIVATE ${${var}}) + endif () +endfunction() + +function(apply_includes target var) + if (${var}) + target_include_directories(${target} PRIVATE ${${var}}) + endif () +endfunction() + +function(apply_libraries target libs) + 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 () +endfunction() + +function(malikania_define_executable) + set(singleArgs TARGET) + set(multiArgs SOURCES FLAGS INCLUDES LIBRARIES) + set(mandatory TARGET SOURCES) + + cmake_parse_arguments(EXE "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(EXE ${mandatory}) + + add_executable(${EXE_TARGET} ${EXE_SOURCES}) + + 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) + + cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(LIB ${mandatory}) + + 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 "" + ) + + 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) +endfunction() + +function(malikania_create_test) + set(singleArgs NAME) + set(multiArgs LIBRARIES SOURCES RESOURCES) + + set(mandatory NAME SOURCES) + + cmake_parse_arguments(TEST "" "${singleArgs}" "${multiArgs}" ${ARGN}) + check_args(TEST ${mandatory}) + + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/${TEST_NAME}) + + 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}) + + add_custom_command( + OUTPUT ${output} + COMMAND ${CMAKE_COMMAND} -E copy ${absolute} ${output} + DEPENDS ${absolute} + ) + + 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} + ) + + target_link_libraries( + test-${TEST_NAME} + ${TEST_LIBRARIES} + gtest + ) + + add_dependencies(tests test-${TEST_NAME}) +endfunction() + +macro(setg var value) + set(${var} ${value} CACHE INTERNAL "" FORCE) +endmacro()
--- a/cmake/MalikaniaOptions.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/MalikaniaOptions.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,93 +1,93 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -# -# Backend selection. -# ------------------------------------------------------------------- -# -# The following options are available: -# WITH_BACKEND - Type of backend to use. (Default: SDL) -# - -set(WITH_BACKEND "SDL" - 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 -# - -option(WITH_DOCS "Build all documentation" On) -option(WITH_DOXYGEN "Enable doxygen generation" On) - -if (NOT WITH_DOCS) - set(WITH_DOXYGEN Off) -endif () - -set(WITH_DRIVERDIR "lib/malikania/${MALIKANIA_VERSION}" - CACHE STRING "Database driver directory") -set(WITH_BINDIR "libexec/malikania/${MALIKANIA_VERSION}" - CACHE STRING "Front end directory") - -if (IS_ABSOLUTE ${WITH_DRIVERDIR}) - message(FATAL_ERROR "WITH_DRIVERDIR must not be absolute") -elseif (IS_ABSOLUTE ${WITH_BINDIR}) - message(FATAL_ERROR "WITH_BINDIR must not be absolute") -endif () - -# -# Options for unit tests -# ------------------------------------------------------------------- -# - -set(WITH_TEST_PGSQL_HOST "localhost" - CACHE STRING "Hostname for PostgreSQL driver") -set(WITH_TEST_PGSQL_PORT "5432" - CACHE STRING "Port for PostgreSQL driver") -set(WITH_TEST_PGSQL_DATABASE "malikaniadb" - CACHE STRING "Database for PostgreSQL driver") -set(WITH_TEST_PGSQL_USER "malikania" - 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. -# - -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") -else () - 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 -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +# +# Backend selection. +# ------------------------------------------------------------------- +# +# The following options are available: +# WITH_BACKEND - Type of backend to use. (Default: SDL) +# + +set(WITH_BACKEND "SDL" + 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 +# + +option(WITH_DOCS "Build all documentation" On) +option(WITH_DOXYGEN "Enable doxygen generation" On) + +if (NOT WITH_DOCS) + set(WITH_DOXYGEN Off) +endif () + +set(WITH_DRIVERDIR "lib/malikania/${MALIKANIA_VERSION}" + CACHE STRING "Database driver directory") +set(WITH_BINDIR "libexec/malikania/${MALIKANIA_VERSION}" + CACHE STRING "Front end directory") + +if (IS_ABSOLUTE ${WITH_DRIVERDIR}) + message(FATAL_ERROR "WITH_DRIVERDIR must not be absolute") +elseif (IS_ABSOLUTE ${WITH_BINDIR}) + message(FATAL_ERROR "WITH_BINDIR must not be absolute") +endif () + +# +# Options for unit tests +# ------------------------------------------------------------------- +# + +set(WITH_TEST_PGSQL_HOST "localhost" + CACHE STRING "Hostname for PostgreSQL driver") +set(WITH_TEST_PGSQL_PORT "5432" + CACHE STRING "Port for PostgreSQL driver") +set(WITH_TEST_PGSQL_DATABASE "malikaniadb" + CACHE STRING "Database for PostgreSQL driver") +set(WITH_TEST_PGSQL_USER "malikania" + 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. +# + +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") +else () + 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 +)
--- a/cmake/MalikaniaSystem.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/MalikaniaSystem.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,27 +1,27 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic ${CMAKE_CXX_FLAGS}") - - if (MINGW) - set(CMAKE_CXX_FLAGS "-D_WIN32_WINNT=0x0600 ${CMAKE_CXX_FLAGS}") - endif () -endif () - - +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic ${CMAKE_CXX_FLAGS}") + + if (MINGW) + set(CMAKE_CXX_FLAGS "-D_WIN32_WINNT=0x0600 ${CMAKE_CXX_FLAGS}") + endif () +endif () + +
--- a/cmake/MalikaniaVersion.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/MalikaniaVersion.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,22 +1,22 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -set(MALIKANIA_VERSION_MAJOR 0) -set(MALIKANIA_VERSION_MINOR 1) -set(MALIKANIA_VERSION_PATCH 0) -set(MALIKANIA_VERSION ${MALIKANIA_VERSION_MAJOR}.${MALIKANIA_VERSION_MINOR}.${MALIKANIA_VERSION_PATCH}) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +set(MALIKANIA_VERSION_MAJOR 0) +set(MALIKANIA_VERSION_MINOR 1) +set(MALIKANIA_VERSION_PATCH 0) +set(MALIKANIA_VERSION ${MALIKANIA_VERSION_MAJOR}.${MALIKANIA_VERSION_MINOR}.${MALIKANIA_VERSION_PATCH})
--- a/cmake/internal/Config.h.in Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/internal/Config.h.in Fri Jun 17 13:12:35 2016 +0200 @@ -1,37 +1,37 @@ -/* - * Config.h -- autogenerated configuration file - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _MALIKANIA_CONFIG_H_ -#define _MALIKANIA_CONFIG_H_ - -/* - * Export attributes. - */ -#if defined(_WIN32) -# if defined(MALIKANIA_BUILD) -# define MALIKANIA_EXPORT __declspec(dllexport) -# else -# define MALIKANIA_EXPORT __declspec(dllimport) -# endif -#else -# define MALIKANIA_EXPORT -#endif - -#cmakedefine WITH_BACKEND_SDL - -#endif // !_MALIKANIA_CONFIG_H_ +/* + * Config.h -- autogenerated configuration file + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MALIKANIA_CONFIG_H_ +#define _MALIKANIA_CONFIG_H_ + +/* + * Export attributes. + */ +#if defined(_WIN32) +# if defined(MALIKANIA_BUILD) +# define MALIKANIA_EXPORT __declspec(dllexport) +# else +# define MALIKANIA_EXPORT __declspec(dllimport) +# endif +#else +# define MALIKANIA_EXPORT +#endif + +#cmakedefine WITH_BACKEND_SDL + +#endif // !_MALIKANIA_CONFIG_H_
--- a/cmake/packages/FindPandoc.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/packages/FindPandoc.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,231 +1,231 @@ -# FindPandoc -# ---------- -# -# Find Pandoc executable, this modules defines: -# -# Pandoc_EXECUTABLE, where to find pandoc's executable -# Pandoc_FOUND, if it is found -# Pandoc_VERSION, the version -# -# 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] -# ) -# -# The sources files are listed in the parameter SOURCES, all files are passed -# in the same order they are passed to that variable. -# -# The OUTPUT file is set with OUTPUT. It is generated only if one of the file -# has changed. -# -# The FROM (-f) and TO (-t) arguments specify respectively the source and -# destinations formats. -# -# If the parameter TARGET is set, then a target named `target` will be added -# with the OUTPUT file as the dependency but not listed as sources files. -# But the SOURCES files will be added as the target sources in the IDE. -# -# Optional dependencies can be added to the output command (not the target) with -# the DEPENDS parameter. -# -# If ALL is set and TARGET is also set, the target will be added to the ALL_BUILD. -# -# If TOC (--toc) is specified, a table of content will be automatically created. -# -# If STANDALONE (-s) is set, the compilation will assume that it is standalone -# and adds the necessary of the output format. -# -# Optional MAKE_DIRECTORY can be set to create the output directory before -# pandoc processes the file (recommended). -# -# The TEMPLATE parameter can be used to specify the formate template file. -# -# You can set a filter with the parameter FILTER. The filter will be added to -# the output dependencies so you can safely use CMake's targets. -# -# The HEADER (-H), FOOTER (-A) and BODY (-B) are copied verbatim before, just -# after and after the body respectively. They can be set more than once. -# -# You can pass variables (-V) and metadata (-M) to the parameters VARIABLE -# and METADATA, be sure to pass the same syntax as pandoc. (e.g VARIABLE foo=1) -# -# ARGS is an optional list of additional arguments to pass to pandoc. -# -# The parameter WORKING_DIRECTORY can be set to change the directory when pandoc -# is invoked. -# - -find_program( - Pandoc_EXECUTABLE - NAMES pandoc - DOC "Pandoc executable" -) - -include(FindPackageHandleStandardArgs) -include(CMakeParseArguments) - -# Extract the version -if (Pandoc_EXECUTABLE) - 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 () -endif () - -find_package_handle_standard_args( - 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) - - # - # 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 () - - # - # 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 () - - # 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 () - - # Optional list of arguments - foreach (arg ${PANDOC_ARGS}) - list(APPEND _pandoc_arguments ${arg}) - endforeach () - - # 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 () - - # 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 - ) - - 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) +# FindPandoc +# ---------- +# +# Find Pandoc executable, this modules defines: +# +# Pandoc_EXECUTABLE, where to find pandoc's executable +# Pandoc_FOUND, if it is found +# Pandoc_VERSION, the version +# +# 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] +# ) +# +# The sources files are listed in the parameter SOURCES, all files are passed +# in the same order they are passed to that variable. +# +# The OUTPUT file is set with OUTPUT. It is generated only if one of the file +# has changed. +# +# The FROM (-f) and TO (-t) arguments specify respectively the source and +# destinations formats. +# +# If the parameter TARGET is set, then a target named `target` will be added +# with the OUTPUT file as the dependency but not listed as sources files. +# But the SOURCES files will be added as the target sources in the IDE. +# +# Optional dependencies can be added to the output command (not the target) with +# the DEPENDS parameter. +# +# If ALL is set and TARGET is also set, the target will be added to the ALL_BUILD. +# +# If TOC (--toc) is specified, a table of content will be automatically created. +# +# If STANDALONE (-s) is set, the compilation will assume that it is standalone +# and adds the necessary of the output format. +# +# Optional MAKE_DIRECTORY can be set to create the output directory before +# pandoc processes the file (recommended). +# +# The TEMPLATE parameter can be used to specify the formate template file. +# +# You can set a filter with the parameter FILTER. The filter will be added to +# the output dependencies so you can safely use CMake's targets. +# +# The HEADER (-H), FOOTER (-A) and BODY (-B) are copied verbatim before, just +# after and after the body respectively. They can be set more than once. +# +# You can pass variables (-V) and metadata (-M) to the parameters VARIABLE +# and METADATA, be sure to pass the same syntax as pandoc. (e.g VARIABLE foo=1) +# +# ARGS is an optional list of additional arguments to pass to pandoc. +# +# The parameter WORKING_DIRECTORY can be set to change the directory when pandoc +# is invoked. +# + +find_program( + Pandoc_EXECUTABLE + NAMES pandoc + DOC "Pandoc executable" +) + +include(FindPackageHandleStandardArgs) +include(CMakeParseArguments) + +# Extract the version +if (Pandoc_EXECUTABLE) + 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 () +endif () + +find_package_handle_standard_args( + 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) + + # + # 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 () + + # + # 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 () + + # 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 () + + # Optional list of arguments + foreach (arg ${PANDOC_ARGS}) + list(APPEND _pandoc_arguments ${arg}) + endforeach () + + # 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 () + + # 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 + ) + + 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 Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/packages/FindSDL2.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,24 +1,24 @@ -# FindSDL2 -# -------- -# -# Find SDL2 library, this modules defines: -# -# SDL2_INCLUDE_DIRS, where to find SDL.h -# SDL2_LIBRARIES, where to find library -# SDL2_FOUND, if it is found - -find_path(SDL2_INCLUDE_DIR NAMES SDL.h PATH_SUFFIXES SDL2) -find_library(SDL2_LIBRARY NAMES libSDL2 SDL2) - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args( - SDL2 - FOUND_VAR SDL2_FOUND - REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR -) - -set(SDL2_LIBRARIES ${SDL2_LIBRARY}) -set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) - -mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) +# FindSDL2 +# -------- +# +# Find SDL2 library, this modules defines: +# +# SDL2_INCLUDE_DIRS, where to find SDL.h +# SDL2_LIBRARIES, where to find library +# SDL2_FOUND, if it is found + +find_path(SDL2_INCLUDE_DIR NAMES SDL.h PATH_SUFFIXES SDL2) +find_library(SDL2_LIBRARY NAMES libSDL2 SDL2) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + SDL2 + FOUND_VAR SDL2_FOUND + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR +) + +set(SDL2_LIBRARIES ${SDL2_LIBRARY}) +set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) + +mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY)
--- a/cmake/packages/FindSDL2_image.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/packages/FindSDL2_image.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,70 +1,70 @@ -# - Locate SDL_image library -# This module defines: -# SDL2_IMAGE_LIBRARIES, the name of the library to link against -# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers -# SDL2_IMAGE_FOUND, if false, do not try to link against -# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image -# -# $SDLDIR is an environment variable that would -# correspond to the ./configure --prefix=$SDLDIR -# used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h - HINTS - ENV SDLIMAGEDIR - ENV SDLDIR - PATH_SUFFIXES include/SDL2 include/SDL2.0 include -) - -find_library(SDL2_IMAGE_LIBRARY - NAMES SDL2_image SDL2_image-2.0 - HINTS - ENV SDLIMAGEDIR - ENV SDLDIR - PATH_SUFFIXES lib -) - -if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") - set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) - unset(SDL2_IMAGE_VERSION_MAJOR_LINE) - unset(SDL2_IMAGE_VERSION_MINOR_LINE) - unset(SDL2_IMAGE_VERSION_PATCH_LINE) - unset(SDL2_IMAGE_VERSION_MAJOR) - unset(SDL2_IMAGE_VERSION_MINOR) - unset(SDL2_IMAGE_VERSION_PATCH) -endif() - -set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) -set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image - REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS - VERSION_VAR SDL2_IMAGE_VERSION_STRING) - -mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) +# - Locate SDL_image library +# This module defines: +# SDL2_IMAGE_LIBRARIES, the name of the library to link against +# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers +# SDL2_IMAGE_FOUND, if false, do not try to link against +# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# +# Created by Eric Wing. This was influenced by the FindSDL.cmake +# module, but with modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h + HINTS + ENV SDLIMAGEDIR + ENV SDLDIR + PATH_SUFFIXES include/SDL2 include/SDL2.0 include +) + +find_library(SDL2_IMAGE_LIBRARY + NAMES SDL2_image SDL2_image-2.0 + HINTS + ENV SDLIMAGEDIR + ENV SDLDIR + PATH_SUFFIXES lib +) + +if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") + file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") + set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) + unset(SDL2_IMAGE_VERSION_MAJOR_LINE) + unset(SDL2_IMAGE_VERSION_MINOR_LINE) + unset(SDL2_IMAGE_VERSION_PATCH_LINE) + unset(SDL2_IMAGE_VERSION_MAJOR) + unset(SDL2_IMAGE_VERSION_MINOR) + unset(SDL2_IMAGE_VERSION_PATCH) +endif() + +set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) +set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image + REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS + VERSION_VAR SDL2_IMAGE_VERSION_STRING) + +mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
--- a/cmake/packages/FindZIP.cmake Fri Jun 17 13:07:05 2016 +0200 +++ b/cmake/packages/FindZIP.cmake Fri Jun 17 13:12:35 2016 +0200 @@ -1,51 +1,51 @@ -# FindZIP -# ------- -# -# Find libzip library, this modules defines: -# -# ZIP_INCLUDE_DIRS, where to find zip.h -# ZIP_LIBRARIES, where to find library -# ZIP_FOUND, if it is found - -find_package(ZLIB QUIET) - -find_path( - ZIP_INCLUDE_DIR - NAMES zip.h -) - -find_library( - ZIP_LIBRARY - NAMES zip libzip -) - -find_path( - 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) - - 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 -) - -if (ZIP_FOUND) - 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) +# FindZIP +# ------- +# +# Find libzip library, this modules defines: +# +# ZIP_INCLUDE_DIRS, where to find zip.h +# ZIP_LIBRARIES, where to find library +# ZIP_FOUND, if it is found + +find_package(ZLIB QUIET) + +find_path( + ZIP_INCLUDE_DIR + NAMES zip.h +) + +find_library( + ZIP_LIBRARY + NAMES zip libzip +) + +find_path( + 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) + + 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 +) + +if (ZIP_FOUND) + 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/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/database/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,21 +1,21 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013, 2014, 2015 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(database) - -add_subdirectory(postgresql) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013, 2014, 2015 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(database) + +add_subdirectory(postgresql)
--- a/database/postgresql/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/database/postgresql/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,39 +1,39 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013, 2014, 2015 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -find_package(PostgreSQL REQUIRED) - -add_library( - 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} -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013, 2014, 2015 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +find_package(PostgreSQL REQUIRED) + +add_library( + 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} +)
--- a/database/postgresql/src/account.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/database/postgresql/src/account.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,130 +1,130 @@ -/* - * account.cpp -- account management - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cassert> -#include <sstream> -#include <stdexcept> -#include <vector> - -#include <malikania/dynlib.h> -#include <malikania/account.h> - -#include "driver.h" - -using namespace malikania; - -extern "C" { - -namespace { - -Account toAccount(PGresult *result, int i) -{ - assert(i < PQntuples(result)); - - 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)); - - return account; -} - -} // !namespace - -DYNLIB_EXPORT void malikania_account_create(Account &account) -{ - 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"; - - std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); - - 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; - - 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()); -} - -DYNLIB_EXPORT void malikania_account_remove(const Account &account) -{ - std::ostringstream oss; - - oss << "delete from mk_account where ac_id = " << account.id(); - - pgsql::exec(oss.str()); -} - -DYNLIB_EXPORT Account malikania_account_get(std::uint64_t id) -{ - std::ostringstream oss; - - oss << "select * from mk_account where ac_id = " << id; - - std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); - - if (PQntuples(result.get()) != 1) - throw std::out_of_range("account not found"); - - 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"); - - for (int i = 0; i < PQntuples(result.get()); ++i) - accounts.push_back(toAccount(result.get(), i)); - - return accounts; -} - -DYNLIB_EXPORT std::uint64_t malikania_account_count() -{ - 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))); -} - -DYNLIB_EXPORT void malikania_account_clear() -{ - pgsql::exec("delete from mk_account"); -} - -} +/* + * account.cpp -- account management + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cassert> +#include <sstream> +#include <stdexcept> +#include <vector> + +#include <malikania/dynlib.hpp> +#include <malikania/account.hpp> + +#include "driver.hpp" + +using namespace malikania; + +extern "C" { + +namespace { + +Account toAccount(PGresult *result, int i) +{ + assert(i < PQntuples(result)); + + 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)); + + return account; +} + +} // !namespace + +DYNLIB_EXPORT void malikania_account_create(Account &account) +{ + 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"; + + std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); + + 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; + + 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()); +} + +DYNLIB_EXPORT void malikania_account_remove(const Account &account) +{ + std::ostringstream oss; + + oss << "delete from mk_account where ac_id = " << account.id(); + + pgsql::exec(oss.str()); +} + +DYNLIB_EXPORT Account malikania_account_get(std::uint64_t id) +{ + std::ostringstream oss; + + oss << "select * from mk_account where ac_id = " << id; + + std::shared_ptr<PGresult> result = pgsql::exec(oss.str()); + + if (PQntuples(result.get()) != 1) + throw std::out_of_range("account not found"); + + 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"); + + for (int i = 0; i < PQntuples(result.get()); ++i) + accounts.push_back(toAccount(result.get(), i)); + + return accounts; +} + +DYNLIB_EXPORT std::uint64_t malikania_account_count() +{ + 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))); +} + +DYNLIB_EXPORT void malikania_account_clear() +{ + pgsql::exec("delete from mk_account"); +} + +}
--- a/database/postgresql/src/driver.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/database/postgresql/src/driver.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -20,9 +20,9 @@ #include <string> #include <unordered_map> -#include <malikania/dynlib.h> +#include <malikania/dynlib.hpp> -#include "driver.h" +#include "driver.hpp" namespace pgsql {
--- a/database/postgresql/src/driver.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * driver.h -- PostgreSQL database driver - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_POSTGRESQL_DRIVER_H -#define MALIKANIA_POSTGRESQL_DRIVER_H - -#include <memory> -#include <string> - -#include <libpq-fe.h> - -namespace pgsql { - -extern PGconn *connection; - -std::shared_ptr<PGresult> exec(const std::string &sql); - -std::string escape(const std::string &input); - -} // !pgsql - -#endif // !MALIKANIA_POSTGRESQL_DRIVER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/database/postgresql/src/driver.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,37 @@ +/* + * driver.hpp -- PostgreSQL database driver + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_POSTGRESQL_DRIVER_HPPPP +#define MALIKANIA_POSTGRESQL_DRIVER_HPPPP + +#include <memory> +#include <string> + +#include <libpq-fe.h> + +namespace pgsql { + +extern PGconn *connection; + +std::shared_ptr<PGresult> exec(const std::string &sql); + +std::string escape(const std::string &input); + +} // !pgsql + +#endif // !MALIKANIA_POSTGRESQL_DRIVER_HPPPP
--- a/docs/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/docs/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,47 +1,47 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(docs) - -add_custom_target( - docs - ALL - COMMENT "Generating documentation" -) - -# -# Doxygen generation. -# ------------------------------------------------------------------- -# - -find_package(Doxygen) - -if (DOXYGEN_FOUND) - 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) -endif () - -if (WITH_DOXYGEN) - add_subdirectory(doxygen) -endif () +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(docs) + +add_custom_target( + docs + ALL + COMMENT "Generating documentation" +) + +# +# Doxygen generation. +# ------------------------------------------------------------------- +# + +find_package(Doxygen) + +if (DOXYGEN_FOUND) + 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) +endif () + +if (WITH_DOXYGEN) + add_subdirectory(doxygen) +endif ()
--- a/docs/doxygen/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/docs/doxygen/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,43 +1,43 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013, 2014, 2015 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(doxygen) - -set(DOXYGEN_SOURCE ${CMAKE_SOURCE_DIR}) -set(DOXYGEN_OUTPUT ${docs_BINARY_DIR}/doxygen) - -if (DOXYGEN_DOT_FOUND) - set(DOXYGEN_HAVE_DOT YES) - set(DOXYGEN_DOT_PATH \"${DOXYGEN_DOT_EXECUTABLE}\") -else () - set(DOXYGEN_HAVE_DOT NO) - set(DOXYGEN_DOT_PATH) -endif () - -configure_file( - ${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} -) - -add_dependencies(docs docs-doxygen) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013, 2014, 2015 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(doxygen) + +set(DOXYGEN_SOURCE ${CMAKE_SOURCE_DIR}) +set(DOXYGEN_OUTPUT ${docs_BINARY_DIR}/doxygen) + +if (DOXYGEN_DOT_FOUND) + set(DOXYGEN_HAVE_DOT YES) + set(DOXYGEN_DOT_PATH \"${DOXYGEN_DOT_EXECUTABLE}\") +else () + set(DOXYGEN_HAVE_DOT NO) + set(DOXYGEN_DOT_PATH) +endif () + +configure_file( + ${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} +) + +add_dependencies(docs docs-doxygen)
--- a/docs/doxygen/Doxyfile.in Fri Jun 17 13:07:05 2016 +0200 +++ b/docs/doxygen/Doxyfile.in Fri Jun 17 13:12:35 2016 +0200 @@ -1,2378 +1,2378 @@ -# -# Doxyfile.in -- Doxygen file configured for Malikania Engine -# - -# -# 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 -# - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = "Malikania Engine" - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = - -# With the PROJECT_LOGO tag one can specify a logo or an icon that is included -# in the documentation. The maximum height of the logo should not exceed 55 -# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy -# the logo to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT@ - -# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII -# characters to appear in the names of generated files. If set to NO, non-ASCII -# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode -# U+3044. -# The default value is: NO. - -ALLOW_UNICODE_NAMES = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = libclient/malikania \ - libcommon/malikania \ - libserver/malikania - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = @CMAKE_SOURCE_DIR@/libclient - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new -# page for each member. If set to NO, the documentation of a member will be part -# of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: -# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: -# Fortran. In the later case the parser tries to guess whether the code is fixed -# or free formatted code, this is the default for Fortran type files), VHDL. For -# instance to make doxygen treat .inc files as Fortran files (default is PHP), -# and .f files as C (default is Fortran), use: inc=Fortran f=C. -# -# Note: For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by putting a % sign in front of the word or -# globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO, -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. If set to YES, local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO, only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO, these classes will be included in the various overviews. This option -# has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO, these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO, these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES, upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES, the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will -# append additional text to a page's title, such as Class Reference. If set to -# YES the compound reference will be hidden. -# The default value is: NO. - -HIDE_COMPOUND_REFERENCE= NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo -# list. This list is created by putting \todo commands in the documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test -# list. This list is created by putting \test commands in the documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if <section_label> ... \endif and \cond <section_label> -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES, the -# list will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. See also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = YES - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO, doxygen will only warn about wrong or incomplete -# parameter documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. -# Note: If this tag is empty the current directory is searched. - -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 -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. - -FILE_PATTERNS = - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = libclient/malikania/backend \ - libcommon/malikania/backend - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# <filter> <input-file> -# -# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output -# The default value is: NO. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined -# cascading style sheets that are included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefore more robust against future updates. -# Doxygen will copy the style sheet files to the output directory. -# Note: The order of the extra style sheet files is of importance (e.g. the last -# style sheet in the list overrules the setting of the previous ones in the -# list). For an example see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the style sheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = NO - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler (hhc.exe). If non-empty, -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the master .chm file (NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated -# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it -# enables the Previous and Next buttons. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use <access key> + S -# (what the <access key> is depends on the OS and browser, but it is typically -# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down -# key> to jump into the search results window, the results can be navigated -# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel -# the search. The filter options can be selected when the cursor is inside the -# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys> -# to select a filter and <Enter> or <escape> to activate or cancel the filter -# option. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -SEARCHENGINE = YES - -# When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a web server instead of a web client using Javascript. There -# are two flavors of web server based searching depending on the EXTERNAL_SEARCH -# setting. When disabled, doxygen will generate a PHP script for searching and -# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing -# and searching needs to be provided by external tools. See the section -# "External Indexing and Searching" for details. -# The default value is: NO. -# This tag requires that the tag SEARCHENGINE is set to YES. - -SERVER_BASED_SEARCH = NO - -# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP -# script for searching. Instead the search results are written to an XML file -# which needs to be processed by an external indexer. Doxygen will invoke an -# external search engine pointed to by the SEARCHENGINE_URL option to obtain the -# search results. -# -# Doxygen ships with an example indexer (doxyindexer) and search engine -# (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). -# -# See the section "External Indexing and Searching" for details. -# The default value is: NO. -# This tag requires that the tag SEARCHENGINE is set to YES. - -EXTERNAL_SEARCH = NO - -# The SEARCHENGINE_URL should point to a search engine hosted by a web server -# which will return the search results when EXTERNAL_SEARCH is enabled. -# -# Doxygen ships with an example indexer (doxyindexer) and search engine -# (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). See the section "External Indexing and -# Searching" for details. -# This tag requires that the tag SEARCHENGINE is set to YES. - -SEARCHENGINE_URL = - -# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed -# search data is written to a file for indexing by an external tool. With the -# SEARCHDATA_FILE tag the name of this file can be specified. -# The default file is: searchdata.xml. -# This tag requires that the tag SEARCHENGINE is set to YES. - -SEARCHDATA_FILE = searchdata.xml - -# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the -# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is -# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple -# projects and redirect the results back to the right project. -# This tag requires that the tag SEARCHENGINE is set to YES. - -EXTERNAL_SEARCH_ID = - -# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen -# projects other than the one defined by this configuration file, but that are -# all added to the same external search index. Each project needs to have a -# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of -# to a relative location where the documentation can be found. The format is: -# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... -# This tag requires that the tag SEARCHENGINE is set to YES. - -EXTRA_SEARCH_MAPPINGS = - -#--------------------------------------------------------------------------- -# Configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. -# The default value is: YES. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: latex. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. -# -# Note that when enabling USE_PDFLATEX this option is only used for generating -# bitmaps for formulas in the HTML output, but not in the Makefile that is -# written to the output directory. -# The default file is: latex. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate -# index for LaTeX. -# The default file is: makeindex. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX -# documents. This may be useful for small projects and may help to save some -# trees in general. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used by the -# printer. -# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x -# 14 inches) and executive (7.25 x 10.5 inches). -# The default value is: a4. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -PAPER_TYPE = a4 - -# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names -# that should be included in the LaTeX output. To get the times font for -# instance you can specify -# EXTRA_PACKAGES=times -# If left blank no extra packages will be included. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the -# generated LaTeX document. The header should contain everything until the first -# chapter. If it is left blank doxygen will generate a standard header. See -# section "Doxygen usage" for information on how to let doxygen write the -# default header to a separate file. -# -# Note: Only use a user-defined header if you know what you are doing! The -# following commands have a special meaning inside the header: $title, -# $datetime, $date, $doxygenversion, $projectname, $projectnumber, -# $projectbrief, $projectlogo. Doxygen will replace $title with the empty -# string, for the replacement values of the other commands the user is referred -# to HTML_HEADER. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_HEADER = - -# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the -# generated LaTeX document. The footer should contain everything after the last -# chapter. If it is left blank doxygen will generate a standard footer. See -# LATEX_HEADER for more information on how to generate a default footer and what -# special commands can be used inside the footer. -# -# Note: Only use a user-defined footer if you know what you are doing! -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_FOOTER = - -# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined -# LaTeX style sheets that are included after the standard style sheets created -# by doxygen. Using this option one can overrule certain style aspects. Doxygen -# will copy the style sheet files to the output directory. -# Note: The order of the extra style sheet files is of importance (e.g. the last -# style sheet in the list overrules the setting of the previous ones in the -# list). -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_EXTRA_STYLESHEET = - -# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the LATEX_OUTPUT output -# directory. Note that the files will be copied as-is; there are no commands or -# markers available. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_EXTRA_FILES = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is -# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will -# contain links (just like the HTML output) instead of page references. This -# makes the output suitable for online browsing using a PDF viewer. -# The default value is: YES. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -PDF_HYPERLINKS = YES - -# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate -# the PDF file directly from the LaTeX files. Set this option to YES, to get a -# higher quality PDF documentation. -# The default value is: YES. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -USE_PDFLATEX = YES - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode -# command to the generated LaTeX files. This will instruct LaTeX to keep running -# if errors occur, instead of asking the user for help. This option is also used -# when generating formulas in HTML. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_BATCHMODE = NO - -# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the -# index chapters (such as File Index, Compound Index, etc.) in the output. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_HIDE_INDICES = NO - -# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source -# code with syntax highlighting in the LaTeX output. -# -# Note that which sources are shown also depends on other settings such as -# SOURCE_BROWSER. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_SOURCE_CODE = NO - -# The LATEX_BIB_STYLE tag can be used to specify the style to use for the -# bibliography, e.g. plainnat, or ieeetr. See -# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. -# The default value is: plain. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_BIB_STYLE = plain - -#--------------------------------------------------------------------------- -# Configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The -# RTF output is optimized for Word 97 and may not look too pretty with other RTF -# readers/editors. -# The default value is: NO. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: rtf. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF -# documents. This may be useful for small projects and may help to save some -# trees in general. -# The default value is: NO. -# This tag requires that the tag GENERATE_RTF is set to YES. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will -# contain hyperlink fields. The RTF file will contain links (just like the HTML -# output) instead of page references. This makes the output suitable for online -# browsing using Word or some other Word compatible readers that support those -# fields. -# -# Note: WordPad (write) and others do not support links. -# The default value is: NO. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's config -# file, i.e. a series of assignments. You only have to provide replacements, -# missing definitions are set to their default value. -# -# See also section "Doxygen usage" for information on how to generate the -# default style sheet that doxygen normally uses. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an RTF document. Syntax is -# similar to doxygen's config file. A template extensions file can be generated -# using doxygen -e rtf extensionFile. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_EXTENSIONS_FILE = - -# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code -# with syntax highlighting in the RTF output. -# -# Note that which sources are shown also depends on other settings such as -# SOURCE_BROWSER. -# The default value is: NO. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for -# classes and files. -# The default value is: NO. - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. A directory man3 will be created inside the directory specified by -# MAN_OUTPUT. -# The default directory is: man. -# This tag requires that the tag GENERATE_MAN is set to YES. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to the generated -# man pages. In case the manual section does not start with a number, the number -# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is -# optional. -# The default value is: .3. -# This tag requires that the tag GENERATE_MAN is set to YES. - -MAN_EXTENSION = .3 - -# The MAN_SUBDIR tag determines the name of the directory created within -# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by -# MAN_EXTENSION with the initial . removed. -# This tag requires that the tag GENERATE_MAN is set to YES. - -MAN_SUBDIR = - -# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it -# will generate one additional man file for each entity documented in the real -# man page(s). These additional files only source the real man page, but without -# them the man command would be unable to find the correct page. -# The default value is: NO. -# This tag requires that the tag GENERATE_MAN is set to YES. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that -# captures the structure of the code including all documentation. -# The default value is: NO. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: xml. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_OUTPUT = xml - -# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program -# listings (including syntax highlighting and cross-referencing information) to -# the XML output. Note that enabling this will significantly increase the size -# of the XML output. -# The default value is: YES. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the DOCBOOK output -#--------------------------------------------------------------------------- - -# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files -# that can be used to generate PDF. -# The default value is: NO. - -GENERATE_DOCBOOK = NO - -# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in -# front of it. -# The default directory is: docbook. -# This tag requires that the tag GENERATE_DOCBOOK is set to YES. - -DOCBOOK_OUTPUT = docbook - -# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the -# program listings (including syntax highlighting and cross-referencing -# information) to the DOCBOOK output. Note that enabling this will significantly -# increase the size of the DOCBOOK output. -# The default value is: NO. -# This tag requires that the tag GENERATE_DOCBOOK is set to YES. - -DOCBOOK_PROGRAMLISTING = NO - -#--------------------------------------------------------------------------- -# Configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an -# AutoGen Definitions (see http://autogen.sf.net) file that captures the -# structure of the code including all documentation. Note that this feature is -# still experimental and incomplete at the moment. -# The default value is: NO. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module -# file that captures the structure of the code including all documentation. -# -# Note that this feature is still experimental and incomplete at the moment. -# The default value is: NO. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary -# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI -# output from the Perl module output. -# The default value is: NO. -# This tag requires that the tag GENERATE_PERLMOD is set to YES. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely -# formatted so it can be parsed by a human reader. This is useful if you want to -# understand what is going on. On the other hand, if this tag is set to NO, the -# size of the Perl module output will be much smaller and Perl will parse it -# just the same. -# The default value is: YES. -# This tag requires that the tag GENERATE_PERLMOD is set to YES. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file are -# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful -# so different doxyrules.make files included by the same Makefile don't -# overwrite each other's variables. -# This tag requires that the tag GENERATE_PERLMOD is set to YES. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all -# C-preprocessor directives found in the sources and include files. -# The default value is: YES. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names -# in the source code. If set to NO, only conditional compilation will be -# performed. Macro expansion can be done in a controlled way by setting -# EXPAND_ONLY_PREDEF to YES. -# The default value is: NO. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -MACRO_EXPANSION = NO - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then -# the macro expansion is limited to the macros specified with the PREDEFINED and -# EXPAND_AS_DEFINED tags. -# The default value is: NO. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES, the include files in the -# INCLUDE_PATH will be searched if a #include is found. -# The default value is: YES. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by the -# preprocessor. -# This tag requires that the tag SEARCH_INCLUDES is set to YES. - -INCLUDE_PATH = - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will be -# used. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that are -# defined before the preprocessor is started (similar to the -D option of e.g. -# gcc). The argument of the tag is a list of macros of the form: name or -# name=definition (no spaces). If the definition and the "=" are omitted, "=1" -# is assumed. To prevent a macro definition from being undefined via #undef or -# recursively expanded use the := operator instead of the = operator. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this -# tag can be used to specify a list of macro names that should be expanded. The -# macro definition that is found in the sources will be used. Use the PREDEFINED -# tag if you want to use a different macro definition that overrules the -# definition found in the source code. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will -# remove all references to function-like macros that are alone on a line, have -# an all uppercase name, and do not end with a semicolon. Such function macros -# are typically used for boiler-plate code, and will confuse the parser if not -# removed. -# The default value is: YES. -# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES tag can be used to specify one or more tag files. For each tag -# file the location of the external documentation should be added. The format of -# a tag file without this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where loc1 and loc2 can be relative or absolute paths or URLs. See the -# section "Linking to external documentation" for more information about the use -# of tag files. -# Note: Each tag file must have a unique name (where the name does NOT include -# the path). If a tag file is not located in the directory in which doxygen is -# run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create a -# tag file that is based on the input files it reads. See section "Linking to -# external documentation" for more information about the usage of tag files. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES, all external class will be listed in -# the class index. If set to NO, only the inherited external classes will be -# listed. -# The default value is: NO. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will be -# listed. -# The default value is: YES. - -EXTERNAL_GROUPS = YES - -# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in -# the related pages index. If set to NO, only the current project's pages will -# be listed. -# The default value is: YES. - -EXTERNAL_PAGES = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of 'which perl'). -# The default file (with absolute path) is: /usr/bin/perl. - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram -# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to -# NO turns the diagrams off. Note that this option also works with HAVE_DOT -# disabled, but it is recommended to install and use dot, since it yields more -# powerful graphs. -# The default value is: YES. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see: -# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = - -# You can include diagrams made with dia in doxygen documentation. Doxygen will -# then run dia to produce the diagram and insert it in the documentation. The -# DIA_PATH tag allows you to specify the directory where the dia binary resides. -# If left empty dia is assumed to be found in the default search path. - -DIA_PATH = - -# If set to YES the inheritance and collaboration graphs will hide inheritance -# and usage relations if the target is undocumented or is not a class. -# The default value is: YES. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz (see: -# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent -# Bell Labs. The other options in this section have no effect if this option is -# set to NO -# The default value is: NO. - -HAVE_DOT = @DOXYGEN_HAVE_DOT@ - -# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed -# to run in parallel. When set to 0 doxygen will base this on the number of -# processors available in the system. You can set it explicitly to a value -# larger than 0 to get control over the balance between CPU load and processing -# speed. -# Minimum value: 0, maximum value: 32, default value: 0. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_NUM_THREADS = 0 - -# When you want a differently looking font in the dot files that doxygen -# generates you can specify the font name using DOT_FONTNAME. You need to make -# sure dot is able to find the font, which can be done by putting it in a -# standard location or by setting the DOTFONTPATH environment variable or by -# setting DOT_FONTPATH to the directory containing the font. -# The default value is: Helvetica. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_FONTNAME = Helvetica - -# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of -# dot graphs. -# Minimum value: 4, maximum value: 24, default value: 10. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_FONTSIZE = 10 - -# By default doxygen will tell dot to use the default font as specified with -# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set -# the path where dot can find it using this tag. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_FONTPATH = - -# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for -# each documented class showing the direct and indirect inheritance relations. -# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -CLASS_GRAPH = YES - -# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a -# graph for each documented class showing the direct and indirect implementation -# dependencies (inheritance, containment, and class references variables) of the -# class with other documented classes. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -COLLABORATION_GRAPH = YES - -# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for -# groups, showing the direct groups dependencies. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -UML_LOOK = NO - -# If the UML_LOOK tag is enabled, the fields and methods are shown inside the -# class node. If there are many fields or methods and many nodes the graph may -# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the -# number of items for each type to make the size more manageable. Set this to 0 -# for no limit. Note that the threshold may be exceeded by 50% before the limit -# is enforced. So when you set the threshold to 10, up to 15 fields may appear, -# but if the number exceeds 15, the total amount of fields shown is limited to -# 10. -# Minimum value: 0, maximum value: 100, default value: 10. -# This tag requires that the tag HAVE_DOT is set to YES. - -UML_LIMIT_NUM_FIELDS = 10 - -# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and -# collaboration graphs will show the relations between templates and their -# instances. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -TEMPLATE_RELATIONS = NO - -# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to -# YES then doxygen will generate a graph for each documented file showing the -# direct and indirect include dependencies of the file with other documented -# files. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -INCLUDE_GRAPH = YES - -# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are -# set to YES then doxygen will generate a graph for each documented file showing -# the direct and indirect include dependencies of the file with other documented -# files. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH tag is set to YES then doxygen will generate a call -# dependency graph for every global function or class method. -# -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller -# dependency graph for every global function or class method. -# -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical -# hierarchy of all classes instead of a textual one. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -GRAPHICAL_HIERARCHY = YES - -# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the -# dependencies a directory has on other directories in a graphical way. The -# dependency relations are determined by the #include relations between the -# files in the directories. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. -# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order -# to make the SVG files visible in IE 9+ (other browsers do not have this -# requirement). -# Possible values are: png, jpg, gif and svg. -# The default value is: png. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_IMAGE_FORMAT = png - -# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to -# enable generation of interactive SVG images that allow zooming and panning. -# -# Note that this requires a modern browser other than Internet Explorer. Tested -# and working are Firefox, Chrome, Safari, and Opera. -# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make -# the SVG files visible. Older versions of IE do not have SVG support. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -INTERACTIVE_SVG = NO - -# The DOT_PATH tag can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_PATH = @DOXYGEN_DOT_PATH@ - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the \dotfile -# command). -# This tag requires that the tag HAVE_DOT is set to YES. - -DOTFILE_DIRS = - -# The MSCFILE_DIRS tag can be used to specify one or more directories that -# contain msc files that are included in the documentation (see the \mscfile -# command). - -MSCFILE_DIRS = - -# The DIAFILE_DIRS tag can be used to specify one or more directories that -# contain dia files that are included in the documentation (see the \diafile -# command). - -DIAFILE_DIRS = - -# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the -# path where java can find the plantuml.jar file. If left blank, it is assumed -# PlantUML is not used or called during a preprocessing step. Doxygen will -# generate a warning when it encounters a \startuml command in this case and -# will not generate output for the diagram. - -PLANTUML_JAR_PATH = - -# When using plantuml, the specified paths are searched for files specified by -# the !include statement in a plantuml block. - -PLANTUML_INCLUDE_PATH = - -# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes -# that will be shown in the graph. If the number of nodes in a graph becomes -# larger than this value, doxygen will truncate the graph, which is visualized -# by representing a node as a red box. Note that doxygen if the number of direct -# children of the root node in a graph is already larger than -# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that -# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. -# Minimum value: 0, maximum value: 10000, default value: 50. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_GRAPH_MAX_NODES = 50 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs -# generated by dot. A depth value of 3 means that only nodes reachable from the -# root by following a path via at most 3 edges will be shown. Nodes that lay -# further from the root node will be omitted. Note that setting this option to 1 -# or 2 may greatly reduce the computation time needed for large code bases. Also -# note that the size of a graph can be further restricted by -# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. -# Minimum value: 0, maximum value: 1000, default value: 0. -# This tag requires that the tag HAVE_DOT is set to YES. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not seem -# to support this out of the box. -# -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) support -# this, this feature is disabled by default. -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page -# explaining the meaning of the various boxes and arrows in the dot generated -# graphs. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot -# files that are used to generate the various graphs. -# The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_CLEANUP = YES +# +# Doxyfile.in -- Doxygen file configured for Malikania Engine +# + +# +# 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 +# + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "Malikania Engine" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT@ + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = libclient/malikania \ + libcommon/malikania \ + libserver/malikania + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = @CMAKE_SOURCE_DIR@/libclient + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if <section_label> ... \endif and \cond <section_label> +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. +# Note: If this tag is empty the current directory is searched. + +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 +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = libclient/malikania/backend \ + libcommon/malikania/backend + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# <filter> <input-file> +# +# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: NO. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use <access key> + S +# (what the <access key> is depends on the OS and browser, but it is typically +# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down +# key> to jump into the search results window, the results can be navigated +# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel +# the search. The filter options can be selected when the cursor is inside the +# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys> +# to select a filter and <Enter> or <escape> to activate or cancel the filter +# option. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a web server instead of a web client using Javascript. There +# are two flavors of web server based searching depending on the EXTERNAL_SEARCH +# setting. When disabled, doxygen will generate a PHP script for searching and +# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing +# and searching needs to be provided by external tools. See the section +# "External Indexing and Searching" for details. +# The default value is: NO. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SERVER_BASED_SEARCH = NO + +# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP +# script for searching. Instead the search results are written to an XML file +# which needs to be processed by an external indexer. Doxygen will invoke an +# external search engine pointed to by the SEARCHENGINE_URL option to obtain the +# search results. +# +# Doxygen ships with an example indexer (doxyindexer) and search engine +# (doxysearch.cgi) which are based on the open source search engine library +# Xapian (see: http://xapian.org/). +# +# See the section "External Indexing and Searching" for details. +# The default value is: NO. +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTERNAL_SEARCH = NO + +# The SEARCHENGINE_URL should point to a search engine hosted by a web server +# which will return the search results when EXTERNAL_SEARCH is enabled. +# +# Doxygen ships with an example indexer (doxyindexer) and search engine +# (doxysearch.cgi) which are based on the open source search engine library +# Xapian (see: http://xapian.org/). See the section "External Indexing and +# Searching" for details. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SEARCHENGINE_URL = + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed +# search data is written to a file for indexing by an external tool. With the +# SEARCHDATA_FILE tag the name of this file can be specified. +# The default file is: searchdata.xml. +# This tag requires that the tag SEARCHENGINE is set to YES. + +SEARCHDATA_FILE = searchdata.xml + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the +# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is +# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple +# projects and redirect the results back to the right project. +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTERNAL_SEARCH_ID = + +# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen +# projects other than the one defined by this configuration file, but that are +# all added to the same external search index. Each project needs to have a +# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of +# to a relative location where the documentation can be found. The format is: +# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... +# This tag requires that the tag SEARCHENGINE is set to YES. + +EXTRA_SEARCH_MAPPINGS = + +#--------------------------------------------------------------------------- +# Configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. +# The default value is: YES. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: latex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. +# +# Note that when enabling USE_PDFLATEX this option is only used for generating +# bitmaps for formulas in the HTML output, but not in the Makefile that is +# written to the output directory. +# The default file is: latex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate +# index for LaTeX. +# The default file is: makeindex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX +# documents. This may be useful for small projects and may help to save some +# trees in general. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used by the +# printer. +# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x +# 14 inches) and executive (7.25 x 10.5 inches). +# The default value is: a4. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names +# that should be included in the LaTeX output. To get the times font for +# instance you can specify +# EXTRA_PACKAGES=times +# If left blank no extra packages will be included. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the +# generated LaTeX document. The header should contain everything until the first +# chapter. If it is left blank doxygen will generate a standard header. See +# section "Doxygen usage" for information on how to let doxygen write the +# default header to a separate file. +# +# Note: Only use a user-defined header if you know what you are doing! The +# following commands have a special meaning inside the header: $title, +# $datetime, $date, $doxygenversion, $projectname, $projectnumber, +# $projectbrief, $projectlogo. Doxygen will replace $title with the empty +# string, for the replacement values of the other commands the user is referred +# to HTML_HEADER. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the +# generated LaTeX document. The footer should contain everything after the last +# chapter. If it is left blank doxygen will generate a standard footer. See +# LATEX_HEADER for more information on how to generate a default footer and what +# special commands can be used inside the footer. +# +# Note: Only use a user-defined footer if you know what you are doing! +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_FOOTER = + +# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# LaTeX style sheets that are included after the standard style sheets created +# by doxygen. Using this option one can overrule certain style aspects. Doxygen +# will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_STYLESHEET = + +# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the LATEX_OUTPUT output +# directory. Note that the files will be copied as-is; there are no commands or +# markers available. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_FILES = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is +# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will +# contain links (just like the HTML output) instead of page references. This +# makes the output suitable for online browsing using a PDF viewer. +# The default value is: YES. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate +# the PDF file directly from the LaTeX files. Set this option to YES, to get a +# higher quality PDF documentation. +# The default value is: YES. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode +# command to the generated LaTeX files. This will instruct LaTeX to keep running +# if errors occur, instead of asking the user for help. This option is also used +# when generating formulas in HTML. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_BATCHMODE = NO + +# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the +# index chapters (such as File Index, Compound Index, etc.) in the output. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_HIDE_INDICES = NO + +# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source +# code with syntax highlighting in the LaTeX output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. See +# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. +# The default value is: plain. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# Configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The +# RTF output is optimized for Word 97 and may not look too pretty with other RTF +# readers/editors. +# The default value is: NO. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: rtf. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF +# documents. This may be useful for small projects and may help to save some +# trees in general. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will +# contain hyperlink fields. The RTF file will contain links (just like the HTML +# output) instead of page references. This makes the output suitable for online +# browsing using Word or some other Word compatible readers that support those +# fields. +# +# Note: WordPad (write) and others do not support links. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's config +# file, i.e. a series of assignments. You only have to provide replacements, +# missing definitions are set to their default value. +# +# See also section "Doxygen usage" for information on how to generate the +# default style sheet that doxygen normally uses. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an RTF document. Syntax is +# similar to doxygen's config file. A template extensions file can be generated +# using doxygen -e rtf extensionFile. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_EXTENSIONS_FILE = + +# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code +# with syntax highlighting in the RTF output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_SOURCE_CODE = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for +# classes and files. +# The default value is: NO. + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. A directory man3 will be created inside the directory specified by +# MAN_OUTPUT. +# The default directory is: man. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to the generated +# man pages. In case the manual section does not start with a number, the number +# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is +# optional. +# The default value is: .3. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_EXTENSION = .3 + +# The MAN_SUBDIR tag determines the name of the directory created within +# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by +# MAN_EXTENSION with the initial . removed. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_SUBDIR = + +# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it +# will generate one additional man file for each entity documented in the real +# man page(s). These additional files only source the real man page, but without +# them the man command would be unable to find the correct page. +# The default value is: NO. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that +# captures the structure of the code including all documentation. +# The default value is: NO. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: xml. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_OUTPUT = xml + +# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program +# listings (including syntax highlighting and cross-referencing information) to +# the XML output. Note that enabling this will significantly increase the size +# of the XML output. +# The default value is: YES. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the DOCBOOK output +#--------------------------------------------------------------------------- + +# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files +# that can be used to generate PDF. +# The default value is: NO. + +GENERATE_DOCBOOK = NO + +# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in +# front of it. +# The default directory is: docbook. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_OUTPUT = docbook + +# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the +# program listings (including syntax highlighting and cross-referencing +# information) to the DOCBOOK output. Note that enabling this will significantly +# increase the size of the DOCBOOK output. +# The default value is: NO. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_PROGRAMLISTING = NO + +#--------------------------------------------------------------------------- +# Configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an +# AutoGen Definitions (see http://autogen.sf.net) file that captures the +# structure of the code including all documentation. Note that this feature is +# still experimental and incomplete at the moment. +# The default value is: NO. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# Configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module +# file that captures the structure of the code including all documentation. +# +# Note that this feature is still experimental and incomplete at the moment. +# The default value is: NO. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary +# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI +# output from the Perl module output. +# The default value is: NO. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely +# formatted so it can be parsed by a human reader. This is useful if you want to +# understand what is going on. On the other hand, if this tag is set to NO, the +# size of the Perl module output will be much smaller and Perl will parse it +# just the same. +# The default value is: YES. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file are +# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful +# so different doxyrules.make files included by the same Makefile don't +# overwrite each other's variables. +# This tag requires that the tag GENERATE_PERLMOD is set to YES. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all +# C-preprocessor directives found in the sources and include files. +# The default value is: YES. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names +# in the source code. If set to NO, only conditional compilation will be +# performed. Macro expansion can be done in a controlled way by setting +# EXPAND_ONLY_PREDEF to YES. +# The default value is: NO. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then +# the macro expansion is limited to the macros specified with the PREDEFINED and +# EXPAND_AS_DEFINED tags. +# The default value is: NO. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES, the include files in the +# INCLUDE_PATH will be searched if a #include is found. +# The default value is: YES. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by the +# preprocessor. +# This tag requires that the tag SEARCH_INCLUDES is set to YES. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will be +# used. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that are +# defined before the preprocessor is started (similar to the -D option of e.g. +# gcc). The argument of the tag is a list of macros of the form: name or +# name=definition (no spaces). If the definition and the "=" are omitted, "=1" +# is assumed. To prevent a macro definition from being undefined via #undef or +# recursively expanded use the := operator instead of the = operator. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this +# tag can be used to specify a list of macro names that should be expanded. The +# macro definition that is found in the sources will be used. Use the PREDEFINED +# tag if you want to use a different macro definition that overrules the +# definition found in the source code. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will +# remove all references to function-like macros that are alone on a line, have +# an all uppercase name, and do not end with a semicolon. Such function macros +# are typically used for boiler-plate code, and will confuse the parser if not +# removed. +# The default value is: YES. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tag files. For each tag +# file the location of the external documentation should be added. The format of +# a tag file without this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where loc1 and loc2 can be relative or absolute paths or URLs. See the +# section "Linking to external documentation" for more information about the use +# of tag files. +# Note: Each tag file must have a unique name (where the name does NOT include +# the path). If a tag file is not located in the directory in which doxygen is +# run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create a +# tag file that is based on the input files it reads. See section "Linking to +# external documentation" for more information about the usage of tag files. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES, all external class will be listed in +# the class index. If set to NO, only the inherited external classes will be +# listed. +# The default value is: NO. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will be +# listed. +# The default value is: YES. + +EXTERNAL_GROUPS = YES + +# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in +# the related pages index. If set to NO, only the current project's pages will +# be listed. +# The default value is: YES. + +EXTERNAL_PAGES = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of 'which perl'). +# The default file (with absolute path) is: /usr/bin/perl. + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram +# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to +# NO turns the diagrams off. Note that this option also works with HAVE_DOT +# disabled, but it is recommended to install and use dot, since it yields more +# powerful graphs. +# The default value is: YES. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see: +# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# You can include diagrams made with dia in doxygen documentation. Doxygen will +# then run dia to produce the diagram and insert it in the documentation. The +# DIA_PATH tag allows you to specify the directory where the dia binary resides. +# If left empty dia is assumed to be found in the default search path. + +DIA_PATH = + +# If set to YES the inheritance and collaboration graphs will hide inheritance +# and usage relations if the target is undocumented or is not a class. +# The default value is: YES. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz (see: +# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent +# Bell Labs. The other options in this section have no effect if this option is +# set to NO +# The default value is: NO. + +HAVE_DOT = @DOXYGEN_HAVE_DOT@ + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed +# to run in parallel. When set to 0 doxygen will base this on the number of +# processors available in the system. You can set it explicitly to a value +# larger than 0 to get control over the balance between CPU load and processing +# speed. +# Minimum value: 0, maximum value: 32, default value: 0. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_NUM_THREADS = 0 + +# When you want a differently looking font in the dot files that doxygen +# generates you can specify the font name using DOT_FONTNAME. You need to make +# sure dot is able to find the font, which can be done by putting it in a +# standard location or by setting the DOTFONTPATH environment variable or by +# setting DOT_FONTPATH to the directory containing the font. +# The default value is: Helvetica. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of +# dot graphs. +# Minimum value: 4, maximum value: 24, default value: 10. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the default font as specified with +# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set +# the path where dot can find it using this tag. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_FONTPATH = + +# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for +# each documented class showing the direct and indirect inheritance relations. +# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a +# graph for each documented class showing the direct and indirect implementation +# dependencies (inheritance, containment, and class references variables) of the +# class with other documented classes. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for +# groups, showing the direct groups dependencies. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +UML_LOOK = NO + +# If the UML_LOOK tag is enabled, the fields and methods are shown inside the +# class node. If there are many fields or methods and many nodes the graph may +# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the +# number of items for each type to make the size more manageable. Set this to 0 +# for no limit. Note that the threshold may be exceeded by 50% before the limit +# is enforced. So when you set the threshold to 10, up to 15 fields may appear, +# but if the number exceeds 15, the total amount of fields shown is limited to +# 10. +# Minimum value: 0, maximum value: 100, default value: 10. +# This tag requires that the tag HAVE_DOT is set to YES. + +UML_LIMIT_NUM_FIELDS = 10 + +# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and +# collaboration graphs will show the relations between templates and their +# instances. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +TEMPLATE_RELATIONS = NO + +# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to +# YES then doxygen will generate a graph for each documented file showing the +# direct and indirect include dependencies of the file with other documented +# files. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +INCLUDE_GRAPH = YES + +# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are +# set to YES then doxygen will generate a graph for each documented file showing +# the direct and indirect include dependencies of the file with other documented +# files. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH tag is set to YES then doxygen will generate a call +# dependency graph for every global function or class method. +# +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller +# dependency graph for every global function or class method. +# +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical +# hierarchy of all classes instead of a textual one. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the +# dependencies a directory has on other directories in a graphical way. The +# dependency relations are determined by the #include relations between the +# files in the directories. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. +# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order +# to make the SVG files visible in IE 9+ (other browsers do not have this +# requirement). +# Possible values are: png, jpg, gif and svg. +# The default value is: png. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# +# Note that this requires a modern browser other than Internet Explorer. Tested +# and working are Firefox, Chrome, Safari, and Opera. +# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make +# the SVG files visible. Older versions of IE do not have SVG support. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +INTERACTIVE_SVG = NO + +# The DOT_PATH tag can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_PATH = @DOXYGEN_DOT_PATH@ + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the \dotfile +# command). +# This tag requires that the tag HAVE_DOT is set to YES. + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the \mscfile +# command). + +MSCFILE_DIRS = + +# The DIAFILE_DIRS tag can be used to specify one or more directories that +# contain dia files that are included in the documentation (see the \diafile +# command). + +DIAFILE_DIRS = + +# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the +# path where java can find the plantuml.jar file. If left blank, it is assumed +# PlantUML is not used or called during a preprocessing step. Doxygen will +# generate a warning when it encounters a \startuml command in this case and +# will not generate output for the diagram. + +PLANTUML_JAR_PATH = + +# When using plantuml, the specified paths are searched for files specified by +# the !include statement in a plantuml block. + +PLANTUML_INCLUDE_PATH = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes +# that will be shown in the graph. If the number of nodes in a graph becomes +# larger than this value, doxygen will truncate the graph, which is visualized +# by representing a node as a red box. Note that doxygen if the number of direct +# children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that +# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. +# Minimum value: 0, maximum value: 10000, default value: 50. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs +# generated by dot. A depth value of 3 means that only nodes reachable from the +# root by following a path via at most 3 edges will be shown. Nodes that lay +# further from the root node will be omitted. Note that setting this option to 1 +# or 2 may greatly reduce the computation time needed for large code bases. Also +# note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. +# Minimum value: 0, maximum value: 1000, default value: 0. +# This tag requires that the tag HAVE_DOT is set to YES. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not seem +# to support this out of the box. +# +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) support +# this, this feature is disabled by default. +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page +# explaining the meaning of the various boxes and arrows in the dot generated +# graphs. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot +# files that are used to generate the various graphs. +# The default value is: YES. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_CLEANUP = YES
--- a/libclient/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,105 +1,105 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -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 -) - -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 -) - -find_package(SDL2 REQUIRED) -find_package(SDL2_image REQUIRED) -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} -) - -target_compile_definitions(libclient PUBLIC ${DEFINITIONS}) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +set( + HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animation.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/animator.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-resources-loader.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-loading.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/client-target-map.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/color.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/font.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/image.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animation.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-animator.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-client-target.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-color.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-font.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-image.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-line.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-point.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-rectangle.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-sprite.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-window.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/label.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/line.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/point.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/rectangle.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/size.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/sprite.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/window.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/font-backend.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/image-backend.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/${WITH_BACKEND_DIRECTORY}/window-backend.hpp +) + +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 +) + +find_package(SDL2 REQUIRED) +find_package(SDL2_image REQUIRED) +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} +) + +target_compile_definitions(libclient PUBLIC ${DEFINITIONS})
--- a/libclient/malikania/animation.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -/* - * animation.h -- animation description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_ANIMATION_H -#define MALIKANIA_ANIMATION_H - -/** - * \file animation.h - * \brief Describe an animation. - */ - -#include <cassert> -#include <cstdint> -#include <memory> -#include <vector> - -#include "js.h" -#include "sprite.h" - -namespace malikania { - -class Window; - -/** - * \class AnimationFrame - * \brief Animation frame description. - * - * A frame is a duration before switching to the next sprite cell. It is currently implemented as a class for future - * usage. - */ -class AnimationFrame { -private: - 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) - { - } - - /** - * Get the the delay. - * - * \return the delay - */ - inline std::uint16_t delay() const noexcept - { - return m_delay; - } -}; - -/** - * \brief List of frames. - */ -using AnimationFrames = std::vector<AnimationFrame>; - -/** - * \class Animation - * \brief Animation description. - * - * An animation is a sprite with a set of frames containing a delay for showing all sprites in a specific amount of - * time. - * - * Because an animation contains an image, a state (time, current cell) it must be constructed with an Animator object - * so the user is able to use the same animation on different parts of the screen without having to duplicate - * resources. - * - * \see Animator - */ -class Animation : public duk::Bindable { -private: - 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)) - { - } - - /** - * 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; - } - - /** - * 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()); - - return m_frames[index]; - } -}; - -} // !malikania - -#endif // !MALIKANIA_ANIMATION_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/animation.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,155 @@ +/* + * animation.hpp -- animation description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_ANIMATION_HPP +#define MALIKANIA_ANIMATION_HPP + +/** + * \file animation.hpp + * \brief Describe an animation. + */ + +#include <cassert> +#include <cstdint> +#include <memory> +#include <vector> + +#include "js.hpp" +#include "sprite.hpp" + +namespace malikania { + +class Window; + +/** + * \class AnimationFrame + * \brief Animation frame description. + * + * A frame is a duration before switching to the next sprite cell. It is currently implemented as a class for future + * usage. + */ +class AnimationFrame { +private: + 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) + { + } + + /** + * Get the the delay. + * + * \return the delay + */ + inline std::uint16_t delay() const noexcept + { + return m_delay; + } +}; + +/** + * \brief List of frames. + */ +using AnimationFrames = std::vector<AnimationFrame>; + +/** + * \class Animation + * \brief Animation description. + * + * An animation is a sprite with a set of frames containing a delay for showing all sprites in a specific amount of + * time. + * + * Because an animation contains an image, a state (time, current cell) it must be constructed with an Animator object + * so the user is able to use the same animation on different parts of the screen without having to duplicate + * resources. + * + * \see Animator + */ +class Animation : public duk::Bindable { +private: + 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)) + { + } + + /** + * 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; + } + + /** + * 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()); + + return m_frames[index]; + } +}; + +} // !malikania + +#endif // !MALIKANIA_ANIMATION_HPP
--- a/libclient/malikania/animator.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/animator.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,53 +1,53 @@ -/* - * animator.cpp -- animation drawing object - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "animation.h" -#include "animator.h" - -namespace malikania { - -Animator::Animator(Animation &animation) noexcept - : m_animation(animation) -{ -} - -void Animator::update() noexcept -{ - unsigned total = m_animation.sprite().rows() * m_animation.sprite().columns(); - - if (m_current >= total) { - return; - } - - 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; - } - - m_animation.sprite().draw(window, m_current, point); -} - -} // !malikania +/* + * animator.cpp -- animation drawing object + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "animation.hpp" +#include "animator.hpp" + +namespace malikania { + +Animator::Animator(Animation &animation) noexcept + : m_animation(animation) +{ +} + +void Animator::update() noexcept +{ + unsigned total = m_animation.sprite().rows() * m_animation.sprite().columns(); + + if (m_current >= total) { + return; + } + + 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; + } + + m_animation.sprite().draw(window, m_current, point); +} + +} // !malikania
--- a/libclient/malikania/animator.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * animator.h -- animation drawing object - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_ANIMATOR_H -#define MALIKANIA_ANIMATOR_H - -/** - * \file animator.h - * \brief Draw animations. - */ - -#include "elapsed-timer.h" -#include "js.h" - -namespace malikania { - -class Animation; -class Point; -class Window; - -/** - * \class Animator - * \brief Object for drawing animations. - * - * The animator contains an animation and a state. - */ -class Animator : public duk::Bindable { -private: - 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; - - /** - * 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); -}; - -} // !malikania - -#endif // !MALIKANIA_ANIMATOR_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/animator.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,75 @@ +/* + * animator.hpp -- animation drawing object + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_ANIMATOR_HPP +#define MALIKANIA_ANIMATOR_HPP + +/** + * \file animator.hpp + * \brief Draw animations. + */ + +#include "elapsed-timer.hpp" +#include "js.hpp" + +namespace malikania { + +class Animation; +class Point; +class Window; + +/** + * \class Animator + * \brief Object for drawing animations. + * + * The animator contains an animation and a state. + */ +class Animator : public duk::Bindable { +private: + 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; + + /** + * 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); +}; + +} // !malikania + +#endif // !MALIKANIA_ANIMATOR_HPP
--- a/libclient/malikania/backend/sdl/font-backend.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/font-backend.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,57 +1,57 @@ -/* - * font-backend.cpp -- font object (SDL2 implementation) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <malikania/backend/sdl/common-sdl.h> - -#include <malikania/size.h> -#include <malikania/font.h> - -#include "font-backend.h" - -using namespace std::string_literals; - -namespace malikania { - -Font::Backend::Backend(std::string data, unsigned size) - : m_font(nullptr, nullptr) -{ - auto rw = sdl::RWFromBinary(std::move(data)); - - if (rw == nullptr) { - throw std::runtime_error(SDL_GetError()); - } - - m_font = Handle(TTF_OpenFontRW(rw, true, size), TTF_CloseFont); - - if (m_font == NULL) { - throw std::runtime_error(TTF_GetError()); - } -} - -Size Font::Backend::clip(const Font &, const std::string &text) const -{ - int width, height; - - if (TTF_SizeUTF8(m_font.get(), text.c_str(), &width, &height) != 0) { - throw std::runtime_error(SDL_GetError()); - } - - return Size((unsigned)width, (unsigned)height); -} - -} // !malikania +/* + * font-backend.cpp -- font object (SDL2 implementation) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <malikania/backend/sdl/common-sdl.hpp> + +#include <malikania/size.hpp> +#include <malikania/font.hpp> + +#include "font-backend.hpp" + +using namespace std::string_literals; + +namespace malikania { + +Font::Backend::Backend(std::string data, unsigned size) + : m_font(nullptr, nullptr) +{ + auto rw = sdl::RWFromBinary(std::move(data)); + + if (rw == nullptr) { + throw std::runtime_error(SDL_GetError()); + } + + m_font = Handle(TTF_OpenFontRW(rw, true, size), TTF_CloseFont); + + if (m_font == NULL) { + throw std::runtime_error(TTF_GetError()); + } +} + +Size Font::Backend::clip(const Font &, const std::string &text) const +{ + int width, height; + + if (TTF_SizeUTF8(m_font.get(), text.c_str(), &width, &height) != 0) { + throw std::runtime_error(SDL_GetError()); + } + + return Size((unsigned)width, (unsigned)height); +} + +} // !malikania
--- a/libclient/malikania/backend/sdl/font-backend.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * font-backend.h -- font object (SDL2 implementation) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_FONT_BACKEND_H -#define MALIKANIA_FONT_BACKEND_H - -#include <memory> - -#include <SDL.h> -#include <SDL_ttf.h> - -#include <malikania/font.h> - -namespace malikania { - -class Font; -class Size; - -class Font::Backend { -private: - using Handle = std::unique_ptr<TTF_Font, void (*)(TTF_Font*)>; - - Handle m_font; - -public: - Backend(std::string data, unsigned size); - - inline TTF_Font *font() noexcept - { - return m_font.get(); - } - - Size clip(const Font &self, const std::string &text) const; -}; - -} // !malikania - -#endif // !MALIKANIA_FONT_BACKEND_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/backend/sdl/font-backend.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,53 @@ +/* + * font-backend.hpp -- font object (SDL2 implementation) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_FONT_BACKEND_HPP +#define MALIKANIA_FONT_BACKEND_HPP + +#include <memory> + +#include <SDL.h> +#include <SDL_ttf.h> + +#include <malikania/font.hpp> + +namespace malikania { + +class Font; +class Size; + +class Font::Backend { +private: + using Handle = std::unique_ptr<TTF_Font, void (*)(TTF_Font*)>; + + Handle m_font; + +public: + Backend(std::string data, unsigned size); + + inline TTF_Font *font() noexcept + { + return m_font.get(); + } + + Size clip(const Font &self, const std::string &text) const; +}; + +} // !malikania + +#endif // !MALIKANIA_FONT_BACKEND_HPP
--- a/libclient/malikania/backend/sdl/image-backend.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/image-backend.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,110 +1,110 @@ -/* - * image-backend.cpp -- image object (SDL2 implementation) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <SDL_image.h> - -#include <malikania/backend/sdl/common-sdl.h> - -#include "image-backend.h" -#include "window-backend.h" - -using namespace std::string_literals; - -namespace malikania { - -void Image::Backend::createTexture(Window &window) -{ - m_texture = Texture(SDL_CreateTextureFromSurface(window.backend().renderer(), m_surface.get()), SDL_DestroyTexture); - - 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) -{ - /* Initialize the texture */ - auto rw = sdl::RWFromBinary(std::move(data)); - - if (rw == nullptr) { - throw std::runtime_error(SDL_GetError()); - } - - m_surface = Surface(IMG_Load_RW(rw, true), SDL_FreeSurface); - - if (!m_surface) { - throw std::runtime_error(SDL_GetError()); - } - - 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); - } - - 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(); - - 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); - } - - SDL_Rect sr, st; - - 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(); - - /* 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()); - } -} - -} // !malikania +/* + * image-backend.cpp -- image object (SDL2 implementation) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <SDL_image.h> + +#include <malikania/backend/sdl/common-sdl.hpp> + +#include "image-backend.hpp" +#include "window-backend.hpp" + +using namespace std::string_literals; + +namespace malikania { + +void Image::Backend::createTexture(Window &window) +{ + m_texture = Texture(SDL_CreateTextureFromSurface(window.backend().renderer(), m_surface.get()), SDL_DestroyTexture); + + 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) +{ + /* Initialize the texture */ + auto rw = sdl::RWFromBinary(std::move(data)); + + if (rw == nullptr) { + throw std::runtime_error(SDL_GetError()); + } + + m_surface = Surface(IMG_Load_RW(rw, true), SDL_FreeSurface); + + if (!m_surface) { + throw std::runtime_error(SDL_GetError()); + } + + 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); + } + + 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(); + + 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); + } + + SDL_Rect sr, st; + + 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(); + + /* 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()); + } +} + +} // !malikania
--- a/libclient/malikania/backend/sdl/image-backend.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * image-backend.h -- image object (SDL2 implementation) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_IMAGE_BACKEND_H -#define MALIKANIA_IMAGE_BACKEND_H - -#include <memory> - -#include <SDL.h> - -#include <malikania/size.h> -#include <malikania/image.h> - -namespace malikania { - -class Image; -class Point; -class Rectangle; -class Window; - -class Image::Backend { -private: - 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; - - void createTexture(Window &window); - -public: - Backend(Image &self, std::string data); - - inline SDL_Texture *texture() noexcept - { - return m_texture.get(); - } - - inline const Size &size() const noexcept - { - return m_size; - } - - void draw(Window &window, const Point &position); - - void draw(Window &window, const Rectangle &source, const Rectangle &target); -}; - -} // !malikania - -#endif // !MALIKANIA_IMAGE_BACKEND_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/backend/sdl/image-backend.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,67 @@ +/* + * image-backend.hpp -- image object (SDL2 implementation) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_IMAGE_BACKEND_HPP +#define MALIKANIA_IMAGE_BACKEND_HPP + +#include <memory> + +#include <SDL.h> + +#include <malikania/size.hpp> +#include <malikania/image.hpp> + +namespace malikania { + +class Image; +class Point; +class Rectangle; +class Window; + +class Image::Backend { +private: + 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; + + void createTexture(Window &window); + +public: + Backend(Image &self, std::string data); + + inline SDL_Texture *texture() noexcept + { + return m_texture.get(); + } + + inline const Size &size() const noexcept + { + return m_size; + } + + void draw(Window &window, const Point &position); + + void draw(Window &window, const Rectangle &source, const Rectangle &target); +}; + +} // !malikania + +#endif // !MALIKANIA_IMAGE_BACKEND_HPP
--- a/libclient/malikania/backend/sdl/window-backend.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/backend/sdl/window-backend.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,13 +21,13 @@ #include <stdexcept> -#include <malikania/color.h> -#include <malikania/line.h> -#include <malikania/point.h> -#include <malikania/rectangle.h> +#include <malikania/color.hpp> +#include <malikania/line.hpp> +#include <malikania/point.hpp> +#include <malikania/rectangle.hpp> -#include "font-backend.h" -#include "window-backend.h" +#include "font-backend.hpp" +#include "window-backend.hpp" namespace malikania { @@ -108,7 +108,7 @@ // 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; + height = current.hpp; } else { throw std::runtime_error("Could not get display mode for video display" + std::string(SDL_GetError())); }
--- a/libclient/malikania/backend/sdl/window-backend.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * window-backend.h -- window object (SDL2 implementation) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_WINDOW_BACKEND_H -#define MALIKANIA_WINDOW_BACKEND_H - -#include <memory> -#include <vector> - -#include <SDL.h> - -#include <malikania/window.h> - -namespace malikania { - -class Window::Backend { -private: - 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; - -public: - Backend(Window &self, unsigned width, unsigned height, const std::string &title); - - inline SDL_Renderer *renderer() noexcept - { - return m_renderer.get(); - } - - void poll(Window &self); - - void close(); - - void clear(); - - void present(); - - Color drawingColor() const; - - void setDrawingColor(const Color &color); - - void drawLine(const Line &line); - - void drawLines(const std::vector<Point> &points); - - void drawPoint(const Point &point); - - void drawPoints(const std::vector<Point> &points); - - void drawRectangle(const Rectangle &rect); - - void drawRectangles(const std::vector<Rectangle> &rects); - - void fillRectangle(const Rectangle &rect); - - 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 Point &point); -}; - -} // !malikania - -#endif // !MALIKANIA_WINDOW_BACKEND_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/backend/sdl/window-backend.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,82 @@ +/* + * window-backend.hpp -- window object (SDL2 implementation) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_WINDOW_BACKEND_HPP +#define MALIKANIA_WINDOW_BACKEND_HPP + +#include <memory> +#include <vector> + +#include <SDL.h> + +#include <malikania/window.hpp> + +namespace malikania { + +class Window::Backend { +private: + 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; + +public: + Backend(Window &self, unsigned width, unsigned height, const std::string &title); + + inline SDL_Renderer *renderer() noexcept + { + return m_renderer.get(); + } + + void poll(Window &self); + + void close(); + + void clear(); + + void present(); + + Color drawingColor() const; + + void setDrawingColor(const Color &color); + + void drawLine(const Line &line); + + void drawLines(const std::vector<Point> &points); + + void drawPoint(const Point &point); + + void drawPoints(const std::vector<Point> &points); + + void drawRectangle(const Rectangle &rect); + + void drawRectangles(const std::vector<Rectangle> &rects); + + void fillRectangle(const Rectangle &rect); + + 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 Point &point); +}; + +} // !malikania + +#endif // !MALIKANIA_WINDOW_BACKEND_HPP
--- a/libclient/malikania/client-resources-loader.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/client-resources-loader.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,124 +1,124 @@ -/* - * client-resources-loader.cpp -- load shared resources files for the client - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cassert> - -#include "animation.h" -#include "client-resources-loader.h" -#include "size.h" -#include "sprite.h" - -namespace malikania { - -Size ClientResourcesLoader::requireSize(const std::string &id, const json::Value &object, const std::string &property) const -{ - assert(object.isObject()); - - 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"); - } - - 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()); - - auto it = object.find(key); - - 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()); -} - -Font ClientResourcesLoader::loadFont(const std::string &id, unsigned size) -{ - return Font(locator().read(id), size); -} - -Image ClientResourcesLoader::loadImage(const std::string &id) -{ - return Image(locator().read(id)); -} - -Sprite ClientResourcesLoader::loadSprite(const std::string &id) -{ - json::Value value = json::fromString(locator().read(id)); - - 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") - ); -} - -Animation ClientResourcesLoader::loadAnimation(const std::string &id) -{ - json::Value value = json::fromString(locator().read(id)); - - if (!value.isObject()) { - throw std::runtime_error(id + ": not a JSON object"); - } - - Sprite sprite = loadSprite(requireString(id, value, "sprite")); - - /* Load all frames */ - json::Value property = value["frames"]; - - if (!property.isArray()) { - throw std::runtime_error(id + ": missing 'frames' property (array expected)"); - } - - 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"); - } - - 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)"); - } - - frames.emplace_back(delay->toInt()); - } - - return Animation(std::move(sprite), std::move(frames)); -} - -} // !malikania +/* + * client-resources-loader.cpp -- load shared resources files for the client + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cassert> + +#include "animation.hpp" +#include "client-resources-loader.hpp" +#include "size.hpp" +#include "sprite.hpp" + +namespace malikania { + +Size ClientResourcesLoader::requireSize(const std::string &id, const json::Value &object, const std::string &property) const +{ + assert(object.isObject()); + + 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"); + } + + 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()); + + auto it = object.find(key); + + 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()); +} + +Font ClientResourcesLoader::loadFont(const std::string &id, unsigned size) +{ + return Font(locator().read(id), size); +} + +Image ClientResourcesLoader::loadImage(const std::string &id) +{ + return Image(locator().read(id)); +} + +Sprite ClientResourcesLoader::loadSprite(const std::string &id) +{ + json::Value value = json::fromString(locator().read(id)); + + 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") + ); +} + +Animation ClientResourcesLoader::loadAnimation(const std::string &id) +{ + json::Value value = json::fromString(locator().read(id)); + + if (!value.isObject()) { + throw std::runtime_error(id + ": not a JSON object"); + } + + Sprite sprite = loadSprite(requireString(id, value, "sprite")); + + /* Load all frames */ + json::Value property = value["frames"]; + + if (!property.isArray()) { + throw std::runtime_error(id + ": missing 'frames' property (array expected)"); + } + + 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"); + } + + 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)"); + } + + frames.emplace_back(delay->toInt()); + } + + return Animation(std::move(sprite), std::move(frames)); +} + +} // !malikania
--- a/libclient/malikania/client-resources-loader.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * client-resources-loader.h -- load shared resources files for the client - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_CLIENT_RESOURCES_LOADER_H -#define MALIKANIA_CLIENT_RESOURCES_LOADER_H - -#include <malikania/resources-loader.h> - -#include "animation.h" -#include "font.h" -#include "image.h" -#include "size.h" -#include "sprite.h" - -namespace malikania { - -/** - * \class ClientResourcesLoader - * \brief Load client resources. - */ -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; - - /** - * 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) - { - } - - /** - * 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 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); -}; - -} // !malikania - -#endif // !MALIKANIA_CLIENT_RESOURCES_LOADER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client-resources-loader.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,117 @@ +/* + * client-resources-loader.hpp -- load shared resources files for the client + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_CLIENT_RESOURCES_LOADER_HPP +#define MALIKANIA_CLIENT_RESOURCES_LOADER_HPP + +#include <malikania/resources-loader.hpp> + +#include "animation.hpp" +#include "font.hpp" +#include "image.hpp" +#include "size.hpp" +#include "sprite.hpp" + +namespace malikania { + +/** + * \class ClientResourcesLoader + * \brief Load client resources. + */ +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; + + /** + * 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) + { + } + + /** + * 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 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); +}; + +} // !malikania + +#endif // !MALIKANIA_CLIENT_RESOURCES_LOADER_HPP
--- a/libclient/malikania/client-target-loading.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/client-target-loading.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-target-loading.h" +#include "client-target-loading.hpp" namespace malikania {
--- a/libclient/malikania/client-target-loading.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * client-target-loading.h -- client loading target - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_CLIENT_TARGET_LOADING_H -#define MALIKANIA_CLIENT_TARGET_LOADING_H - -#include "client-target.h" - -namespace malikania { - -class Client::LoadingTarget : public Client::Target { -public: - virtual void update(Client &client); - - virtual void draw(Client &client); -}; - -} // !malikania - -#endif // !MALIKANIA_CLIENT_TARGET_LOADING_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client-target-loading.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,35 @@ +/* + * client-target-loading.hpp -- client loading target + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_CLIENT_TARGET_LOADING_HPP +#define MALIKANIA_CLIENT_TARGET_LOADING_HPP + +#include "client-target.hpp" + +namespace malikania { + +class Client::LoadingTarget : public Client::Target { +public: + virtual void update(Client &client); + + virtual void draw(Client &client); +}; + +} // !malikania + +#endif // !MALIKANIA_CLIENT_TARGET_LOADING_HPP
--- a/libclient/malikania/client-target-map.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/client-target-map.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-target-map.h" +#include "client-target-map.hpp" namespace malikania {
--- a/libclient/malikania/client-target-map.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * client-target-map.h -- client map target - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_CLIENT_TARGET_MAP_H -#define MALIKANIA_CLIENT_TARGET_MAP_H - -#include "client-target.h" - -namespace malikania { - -class Client::MapTarget : public Client::Target { -public: - virtual void update(Client &client); - - virtual void draw(Client &client); -}; - -} // !malikania - -#endif // !MALIKANIA_CLIENT_TARGET_MAP_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client-target-map.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,35 @@ +/* + * client-target-map.hpp -- client map target + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_CLIENT_TARGET_MAP_HPP +#define MALIKANIA_CLIENT_TARGET_MAP_HPP + +#include "client-target.hpp" + +namespace malikania { + +class Client::MapTarget : public Client::Target { +public: + virtual void update(Client &client); + + virtual void draw(Client &client); +}; + +} // !malikania + +#endif // !MALIKANIA_CLIENT_TARGET_MAP_HPP
--- a/libclient/malikania/client-target.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * client-target.h -- client graphical target state - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_CLIENT_TARGET_H -#define MALIKANIA_CLIENT_TARGET_H - -#include "client.h" - -namespace malikania { - -class Client::Target : public duk::Bindable { -public: - Target() = default; - - virtual ~Target() = default; - - virtual void load(Client &client) - { - (void)client; - } - - virtual void update(Client &client) - { - (void)client; - } - - virtual void draw(Client &client) - { - (void)client; - } - - virtual void unload(Client &client) - { - (void)client; - } -}; - -} // !malikania - -#endif // !MALIKANIA_CLIENT_TARGET_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client-target.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,55 @@ +/* + * client-target.hpp -- client graphical target state + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_CLIENT_TARGET_HPP +#define MALIKANIA_CLIENT_TARGET_HPP + +#include "client.hpp" + +namespace malikania { + +class Client::Target : public duk::Bindable { +public: + Target() = default; + + virtual ~Target() = default; + + virtual void load(Client &client) + { + (void)client; + } + + virtual void update(Client &client) + { + (void)client; + } + + virtual void draw(Client &client) + { + (void)client; + } + + virtual void unload(Client &client) + { + (void)client; + } +}; + +} // !malikania + +#endif // !MALIKANIA_CLIENT_TARGET_HPP
--- a/libclient/malikania/client.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/client.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,9 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-target-loading.h" -#include "client-target-map.h" -#include "window.h" +#include "client-target-loading.hpp" +#include "client-target-map.hpp" +#include "window.hpp" namespace malikania {
--- a/libclient/malikania/client.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * client.h -- main client class - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_CLIENT_H -#define MALIKANIA_CLIENT_H - -#include <memory> - -#include "window.h" - -namespace malikania { - -class Client : public Window { -public: - class Target; - class LoadingTarget; - class MapTarget; - -private: - std::shared_ptr<LoadingTarget> m_loadingTarget; - std::shared_ptr<MapTarget> m_mapTarget; - - std::shared_ptr<Target> m_target; - std::shared_ptr<Target> m_targetNext; - -public: - Client(); - - 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 const std::shared_ptr<MapTarget> &mapTarget() noexcept - { - return m_mapTarget; - } - - inline void setMapTarget(std::shared_ptr<MapTarget> mapTarget) noexcept - { - m_mapTarget = std::move(mapTarget); - } - - void setTarget(std::shared_ptr<Target> target); - - void update(); - - void draw(); -}; - -} // !malikania - -#endif // !MALIKANIA_CLIENT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,73 @@ +/* + * client.hpp -- main client class + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_CLIENT_HPP +#define MALIKANIA_CLIENT_HPP + +#include <memory> + +#include "window.hpp" + +namespace malikania { + +class Client : public Window { +public: + class Target; + class LoadingTarget; + class MapTarget; + +private: + std::shared_ptr<LoadingTarget> m_loadingTarget; + std::shared_ptr<MapTarget> m_mapTarget; + + std::shared_ptr<Target> m_target; + std::shared_ptr<Target> m_targetNext; + +public: + Client(); + + 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 const std::shared_ptr<MapTarget> &mapTarget() noexcept + { + return m_mapTarget; + } + + inline void setMapTarget(std::shared_ptr<MapTarget> mapTarget) noexcept + { + m_mapTarget = std::move(mapTarget); + } + + void setTarget(std::shared_ptr<Target> target); + + void update(); + + void draw(); +}; + +} // !malikania + +#endif // !MALIKANIA_CLIENT_HPP
--- a/libclient/malikania/color.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/color.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,236 +1,236 @@ -/* - * color.cpp -- color description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <unordered_map> -#include <cctype> - -#include "color.h" - -namespace malikania { - -namespace { - -constexpr unsigned rgb(std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept -{ - return (0xff000000 | (r << 16) | (g << 8) | b); -} - -/* - * Convert hexadecimal value to the correct number. - */ -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)); - } - - return digit - 55; -} - -inline std::uint8_t value(char digit1, char 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) } -}; - -} // !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 (it == colors.end()) { - throw std::invalid_argument{name + " is not a valid color"}; - } - - /* Assign the color to *this */ - *this = it->second; - } - } -} - -} // !malikania +/* + * color.cpp -- color description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unordered_map> +#include <cctype> + +#include "color.hpp" + +namespace malikania { + +namespace { + +constexpr unsigned rgb(std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept +{ + return (0xff000000 | (r << 16) | (g << 8) | b); +} + +/* + * Convert hexadecimal value to the correct number. + */ +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)); + } + + return digit - 55; +} + +inline std::uint8_t value(char digit1, char 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) } +}; + +} // !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 (it == colors.end()) { + throw std::invalid_argument{name + " is not a valid color"}; + } + + /* Assign the color to *this */ + *this = it->second; + } + } +} + +} // !malikania
--- a/libclient/malikania/color.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - * color.h -- color description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_COLOR_H -#define MALIKANIA_COLOR_H - -#include <cstdint> -#include <string> - -namespace malikania { - -/** - * \class Color - * \brief Color description - */ -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}; - -public: - /** - * 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 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); - - /** - * 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 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; - } -}; - -} // !malikania - -#endif // !MALIKANIA_COLOR_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/color.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,126 @@ +/* + * color.hpp -- color description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_COLOR_HPP +#define MALIKANIA_COLOR_HPP + +#include <cstdint> +#include <string> + +namespace malikania { + +/** + * \class Color + * \brief Color description + */ +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}; + +public: + /** + * 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 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); + + /** + * 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 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; + } +}; + +} // !malikania + +#endif // !MALIKANIA_COLOR_HPP
--- a/libclient/malikania/font.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/font.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "font-backend.h" +#include "font-backend.hpp" namespace malikania {
--- a/libclient/malikania/font.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * font.h -- font object - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_FONT_H -#define MALIKANIA_FONT_H - -/** - * \file Font.h - * \brief Fonts. - */ - -#include <memory> -#include <string> - -#include "js.h" -#include "size.h" - -namespace malikania { - -/** - * \class Font - * \brief Font object. - */ -class Font : public duk::Bindable { -private: - class Backend; - - 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); - - /** - * Default move constructor. - * - * \param other the other font - */ - Font(Font &&other) noexcept; - - /** - * Default destructor. - */ - virtual ~Font() noexcept; - - /** - * 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; - } - - /** - * 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; - - /** - * Default move assignment operator. - * - * \param other the other font - * \return this - */ - Font &operator=(Font &&other) noexcept; -}; - -} // !malikania - -#endif // MALIKANIA_FONT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/font.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,116 @@ +/* + * font.hpp -- font object + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_FONT_HPP +#define MALIKANIA_FONT_HPP + +/** + * \file Font.hpp + * \brief Fonts. + */ + +#include <memory> +#include <string> + +#include "js.hpp" +#include "size.hpp" + +namespace malikania { + +/** + * \class Font + * \brief Font object. + */ +class Font : public duk::Bindable { +private: + class Backend; + + 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); + + /** + * Default move constructor. + * + * \param other the other font + */ + Font(Font &&other) noexcept; + + /** + * Default destructor. + */ + virtual ~Font() noexcept; + + /** + * 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; + } + + /** + * 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; + + /** + * Default move assignment operator. + * + * \param other the other font + * \return this + */ + Font &operator=(Font &&other) noexcept; +}; + +} // !malikania + +#endif // MALIKANIA_FONT_HPP
--- a/libclient/malikania/image.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/image.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "image-backend.h" +#include "image-backend.hpp" namespace malikania {
--- a/libclient/malikania/image.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* - * image.h -- image object - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_IMAGE_H -#define MALIKANIA_IMAGE_H - -/** - * \file image.h - * \brief Images. - */ - -#include <memory> -#include <string> - -#include "js.h" -#include "point.h" -#include "rectangle.h" -#include "size.h" - -namespace malikania { - -class Window; - -/** - * \class Image - * \brief Image object. - */ -class Image : public duk::Bindable { -private: - class 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); - - /** - * Default move constructor. - * - * \param other the other image - */ - Image(Image &&other) noexcept; - - /** - * Default destructor. - */ - ~Image() noexcept; - - /** - * 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 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}); - - /** - * 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; -}; - -} // !malikania - -#endif // !MALIKANIA_IMAGE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/image.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,125 @@ +/* + * image.hpp -- image object + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_IMAGE_HPP +#define MALIKANIA_IMAGE_HPP + +/** + * \file image.hpp + * \brief Images. + */ + +#include <memory> +#include <string> + +#include "js.hpp" +#include "point.hpp" +#include "rectangle.hpp" +#include "size.hpp" + +namespace malikania { + +class Window; + +/** + * \class Image + * \brief Image object. + */ +class Image : public duk::Bindable { +private: + class 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); + + /** + * Default move constructor. + * + * \param other the other image + */ + Image(Image &&other) noexcept; + + /** + * Default destructor. + */ + ~Image() noexcept; + + /** + * 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 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}); + + /** + * 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; +}; + +} // !malikania + +#endif // !MALIKANIA_IMAGE_HPP
--- a/libclient/malikania/js-animation.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-animation.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-resources-loader.h" -#include "js-animation.h" +#include "client-resources-loader.hpp" +#include "js-animation.hpp" namespace malikania {
--- a/libclient/malikania/js-animation.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * js-animation.h -- animation description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_ANIMATION_H -#define MALIKANIA_JS_ANIMATION_H - -#include "animation.h" -#include "js.h" - -namespace malikania { - -void loadMalikaniaAnimation(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_ANIMATION_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-animation.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,31 @@ +/* + * js-animation.hpp -- animation description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_ANIMATION_HPP +#define MALIKANIA_JS_ANIMATION_HPP + +#include "animation.hpp" +#include "js.hpp" + +namespace malikania { + +void loadMalikaniaAnimation(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_ANIMATION_HPP
--- a/libclient/malikania/js-animator.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-animator.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,10 +16,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-animation.h" -#include "js-animator.h" -#include "js-point.h" -#include "js-window.h" +#include "js-animation.hpp" +#include "js-animator.hpp" +#include "js-point.hpp" +#include "js-window.hpp" namespace malikania {
--- a/libclient/malikania/js-animator.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * js-animator.h -- animation drawing object (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_ANIMATOR_H -#define MALIKANIA_JS_ANIMATOR_H - -#include "animator.h" -#include "js.h" - -namespace malikania { - -void loadMalikaniaAnimator(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_ANIMATOR_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-animator.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,31 @@ +/* + * js-animator.hpp -- animation drawing object (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_ANIMATOR_HPP +#define MALIKANIA_JS_ANIMATOR_HPP + +#include "animator.hpp" +#include "js.hpp" + +namespace malikania { + +void loadMalikaniaAnimator(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_ANIMATOR_HPP
--- a/libclient/malikania/js-client-target.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-client-target.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -#include "js-client-target.h" +#include "js-client-target.hpp" namespace malikania {
--- a/libclient/malikania/js-client-target.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#ifndef MALIKANIA_JS_CLIENT_TARGET_H -#define MALIKANIA_JS_CLIENT_TARGET_H - -#include "client-target.h" -#include "js.h" - -namespace malikania { - -void loadMalikaniaClientTarget(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_CLIENT_TARGET_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-client-target.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,13 @@ +#ifndef MALIKANIA_JS_CLIENT_TARGET_HPP +#define MALIKANIA_JS_CLIENT_TARGET_HPP + +#include "client-target.hpp" +#include "js.hpp" + +namespace malikania { + +void loadMalikaniaClientTarget(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_CLIENT_TARGET_HPP
--- a/libclient/malikania/js-client.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-client.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -#include "js-client.h" -#include "js-client-target.h" -#include "js-window.h" +#include "js-client.hpp" +#include "js-client-target.hpp" +#include "js-window.hpp" namespace malikania {
--- a/libclient/malikania/js-client.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#ifndef MALIKANIA_JS_CLIENT_H -#define MALIKANIA_JS_CLIENT_H - -#include "client.h" -#include "js.h" - -namespace malikania { - -namespace duk { - -template <> -class TypeTraits<Client> { -public: - 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); - } -}; - -} // !duk - -void loadMalikaniaClient(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_CLIENT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-client.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,32 @@ +#ifndef MALIKANIA_JS_CLIENT_HPP +#define MALIKANIA_JS_CLIENT_HPP + +#include "client.hpp" +#include "js.hpp" + +namespace malikania { + +namespace duk { + +template <> +class TypeTraits<Client> { +public: + 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); + } +}; + +} // !duk + +void loadMalikaniaClient(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_CLIENT_HPP
--- a/libclient/malikania/js-color.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-color.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,8 +18,8 @@ #include <cassert> -#include "js-color.h" -#include "util.h" +#include "js-color.hpp" +#include "util.hpp" namespace malikania {
--- a/libclient/malikania/js-color.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * js-color.h -- color description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_COLOR_H -#define MALIKANIA_JS_COLOR_H - -#include "color.h" -#include "js.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Color. - * - * Colors can be created from plain JavaScript object. - * - * ```` - * { - * red: 0, - * green: 255, - * blue: 255, - * alpha: 255 - * } - * ```` - * - * It can also takes strings like "#rrggbbaa" and SVG names. - */ -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); - - /** - * 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); - - /** - * 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); -}; - -} // !duk - -void loadMalikaniaColor(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_COLOR_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-color.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,102 @@ +/* + * js-color.hpp -- color description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_COLOR_HPP +#define MALIKANIA_JS_COLOR_HPP + +#include "color.hpp" +#include "js.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Color. + * + * Colors can be created from plain JavaScript object. + * + * ```` + * { + * red: 0, + * green: 255, + * blue: 255, + * alpha: 255 + * } + * ```` + * + * It can also takes strings like "#rrggbbaa" and SVG names. + */ +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); + + /** + * 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); + + /** + * 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); +}; + +} // !duk + +void loadMalikaniaColor(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_COLOR_HPP \ No newline at end of file
--- a/libclient/malikania/js-font.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-font.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,9 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-resources-loader.h" -#include "js-font.h" -#include "js-size.h" +#include "client-resources-loader.hpp" +#include "js-font.hpp" +#include "js-size.hpp" namespace malikania {
--- a/libclient/malikania/js-font.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * js-font.h -- font object (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_FONT_H -#define MALIKANIA_JS_FONT_H - -#include "font.h" -#include "js.h" - -namespace malikania { - -void loadMalikaniaFont(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_FONT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-font.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,31 @@ +/* + * js-font.hpp -- font object (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_FONT_HPP +#define MALIKANIA_JS_FONT_HPP + +#include "font.hpp" +#include "js.hpp" + +namespace malikania { + +void loadMalikaniaFont(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_FONT_HPP
--- a/libclient/malikania/js-image.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-image.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-resources-loader.h" -#include "js-image.h" -#include "js-point.h" -#include "js-rectangle.h" -#include "js-size.h" -#include "js-window.h" +#include "client-resources-loader.hpp" +#include "js-image.hpp" +#include "js-point.hpp" +#include "js-rectangle.hpp" +#include "js-size.hpp" +#include "js-window.hpp" namespace malikania {
--- a/libclient/malikania/js-image.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * js-image.h -- image object (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_IMAGE_H -#define MALIKANIA_JS_IMAGE_H - -#include "image.h" -#include "js.h" - -namespace malikania { - -void loadMalikaniaImage(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_IMAGE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-image.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,31 @@ +/* + * js-image.hpp -- image object (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_IMAGE_HPP +#define MALIKANIA_JS_IMAGE_HPP + +#include "image.hpp" +#include "js.hpp" + +namespace malikania { + +void loadMalikaniaImage(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_IMAGE_HPP
--- a/libclient/malikania/js-line.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-line.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-line.h" +#include "js-line.hpp" namespace malikania {
--- a/libclient/malikania/js-line.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/* - * js-line.h -- line description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_LINE_H -#define MALIKANIA_JS_LINE_H - -#include "js.h" -#include "line.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Line. - * - * Lines are plain objects. - * - * ```` - * { - * x1: 10, - * y1: 10, - * x2: 50, - * y2: 50 - * } - * ```` - */ -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); - - /** - * 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); - - /** - * 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); -}; - -} // !duk - -void loadMalikaniaLine(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_LINE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-line.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,99 @@ +/* + * js-line.hpp -- line description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_LINE_HPP +#define MALIKANIA_JS_LINE_HPP + +#include "js.hpp" +#include "line.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Line. + * + * Lines are plain objects. + * + * ```` + * { + * x1: 10, + * y1: 10, + * x2: 50, + * y2: 50 + * } + * ```` + */ +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); + + /** + * 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); + + /** + * 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); +}; + +} // !duk + +void loadMalikaniaLine(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_LINE_HPP
--- a/libclient/malikania/js-point.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-point.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-point.h" +#include "js-point.hpp" namespace malikania {
--- a/libclient/malikania/js-point.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * js-point.h -- point description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_POINT_H -#define MALIKANIA_JS_POINT_H - -#include "js.h" -#include "point.h" - -namespace malikania { - -namespace duk { - -template <> -class TypeTraits<Point> { -public: - static Point get(ContextPtr ctx, Index index); - - static Point require(ContextPtr ctx, Index index); - - static Point optional(ContextPtr ctx, Index index, Point def); - - static void push(ContextPtr ctx, const Point &point); - - static void put(ContextPtr ctx, const Point &point); -}; - -} // !duk - -void loadMalikaniaPoint(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_POINT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-point.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,49 @@ +/* + * js-point.hpp -- point description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_POINT_HPP +#define MALIKANIA_JS_POINT_HPP + +#include "js.hpp" +#include "point.hpp" + +namespace malikania { + +namespace duk { + +template <> +class TypeTraits<Point> { +public: + static Point get(ContextPtr ctx, Index index); + + static Point require(ContextPtr ctx, Index index); + + static Point optional(ContextPtr ctx, Index index, Point def); + + static void push(ContextPtr ctx, const Point &point); + + static void put(ContextPtr ctx, const Point &point); +}; + +} // !duk + +void loadMalikaniaPoint(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_POINT_HPP
--- a/libclient/malikania/js-rectangle.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-rectangle.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-rectangle.h" +#include "js-rectangle.hpp" namespace malikania {
--- a/libclient/malikania/js-rectangle.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * js-rectangle.h -- rectangle description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_RECTANGLE_H -#define MALIKANIA_JS_RECTANGLE_H - -#include "js.h" -#include "rectangle.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Rectangle. - * - * Rectangles are plain objects. - * - * ```` - * { - * x: 10, - * y: 20, - * width: 100, - * height: 200 - * } - * ```` - */ -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); - - /** - * 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); - - /** - * 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); -}; - -} // !duk - -void loadMalikaniaRectangle(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_RECTANGLE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-rectangle.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,102 @@ +/* + * js-rectangle.hpp -- rectangle description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_RECTANGLE_HPP +#define MALIKANIA_JS_RECTANGLE_HPP + +#include "js.hpp" +#include "rectangle.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Rectangle. + * + * Rectangles are plain objects. + * + * ```` + * { + * x: 10, + * y: 20, + * width: 100, + * height: 200 + * } + * ```` + */ +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); + + /** + * 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); + + /** + * 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); +}; + +} // !duk + +void loadMalikaniaRectangle(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_RECTANGLE_HPP
--- a/libclient/malikania/js-size.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-size.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-size.h" +#include "js-size.hpp" namespace malikania {
--- a/libclient/malikania/js-size.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/* - * js-size.h -- size description (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_SIZE_H -#define MALIKANIA_JS_SIZE_H - -#include "js.h" -#include "size.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Size. - * - * Size are plain objects. - * - * ```` - * { - * width: 1000, - * height: 2000 - * } - * ```` - */ -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); - - /** - * 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); - - /** - * 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); -}; - -} // !duk - -void loadMalikaniaSize(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_SIZE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-size.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,99 @@ +/* + * js-size.hpp -- size description (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_SIZE_HPP +#define MALIKANIA_JS_SIZE_HPP + +#include "js.hpp" +#include "size.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Size. + * + * Size are plain objects. + * + * ```` + * { + * width: 1000, + * height: 2000 + * } + * ```` + */ +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); + + /** + * 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); + + /** + * 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); +}; + +} // !duk + +void loadMalikaniaSize(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_SIZE_HPP
--- a/libclient/malikania/js-sprite.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-sprite.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,11 +16,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "client-resources-loader.h" -#include "js-point.h" -#include "js-size.h" -#include "js-sprite.h" -#include "js-window.h" +#include "client-resources-loader.hpp" +#include "js-point.hpp" +#include "js-size.hpp" +#include "js-sprite.hpp" +#include "js-window.hpp" namespace malikania {
--- a/libclient/malikania/js-sprite.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * js-sprite.h -- sprite object (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_SPRITE_H -#define MALIKANIA_JS_SPRITE_H - -#include "js.h" -#include "sprite.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Sprite. - */ -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); - - 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 inheritance list. - * - * \return empty - */ - static inline std::vector<std::string> inherits() - { - return {}; - } -}; - -} // !duk - -void loadMalikaniaSprite(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_SPRITE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-sprite.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,78 @@ +/* + * js-sprite.hpp -- sprite object (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_SPRITE_HPP +#define MALIKANIA_JS_SPRITE_HPP + +#include "js.hpp" +#include "sprite.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Sprite. + */ +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); + + 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 inheritance list. + * + * \return empty + */ + static inline std::vector<std::string> inherits() + { + return {}; + } +}; + +} // !duk + +void loadMalikaniaSprite(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_SPRITE_HPP
--- a/libclient/malikania/js-window.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/js-window.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "js-color.h" -#include "js-font.h" -#include "js-line.h" -#include "js-point.h" -#include "js-rectangle.h" -#include "js-window.h" +#include "js-color.hpp" +#include "js-font.hpp" +#include "js-line.hpp" +#include "js-point.hpp" +#include "js-rectangle.hpp" +#include "js-window.hpp" namespace malikania {
--- a/libclient/malikania/js-window.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * js-window.h -- window management (JavaScript binding) - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_WINDOW_H -#define MALIKANIA_JS_WINDOW_H - -#include "js.h" -#include "window.h" - -namespace malikania { - -namespace duk { - -/** - * \brief JavaScript binding for Window. - */ -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); - - 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 - -void loadMalikaniaWindow(duk::ContextPtr ctx); - -} // !malikania - -#endif // !MALIKANIA_JS_WINDOW_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/js-window.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,58 @@ +/* + * js-window.hpp -- window management (JavaScript binding) + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_WINDOW_HPP +#define MALIKANIA_JS_WINDOW_HPP + +#include "js.hpp" +#include "window.hpp" + +namespace malikania { + +namespace duk { + +/** + * \brief JavaScript binding for Window. + */ +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); + + 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 + +void loadMalikaniaWindow(duk::ContextPtr ctx); + +} // !malikania + +#endif // !MALIKANIA_JS_WINDOW_HPP
--- a/libclient/malikania/label.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/label.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,42 +1,42 @@ -/* - * label.cpp -- GUI label - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "label.h" - -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)) -{ -} - -int Label::fontSize() const noexcept -{ - // TODO - return 12; -} - -void Label::draw(Window &, const Rectangle &) -{ -} - -}// !malikania +/* + * label.cpp -- GUI label + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "label.hpp" + +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)) +{ +} + +int Label::fontSize() const noexcept +{ + // TODO + return 12; +} + +void Label::draw(Window &, const Rectangle &) +{ +} + +}// !malikania
--- a/libclient/malikania/label.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * label.h -- GUI label - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_LABEL_H -#define MALIKANIA_LABEL_H - -#include "color.h" -#include "font.h" -#include "image.h" -#include "rectangle.h" - -namespace malikania { - -class Window; - -class Label { -private: - 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}); - - inline const std::string text() const 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 std::shared_ptr<Font> &font() noexcept - { - return m_font; - } - - int fontSize() const noexcept; - - void draw(Window &window, const Rectangle &rectangle); -}; - -}// !malikania - -#endif // !MALIKANIA_LABEL_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/label.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,69 @@ +/* + * label.hpp -- GUI label + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_LABEL_HPP +#define MALIKANIA_LABEL_HPP + +#include "color.hpp" +#include "font.hpp" +#include "image.hpp" +#include "rectangle.hpp" + +namespace malikania { + +class Window; + +class Label { +private: + 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}); + + inline const std::string text() const 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 std::shared_ptr<Font> &font() noexcept + { + return m_font; + } + + int fontSize() const noexcept; + + void draw(Window &window, const Rectangle &rectangle); +}; + +}// !malikania + +#endif // !MALIKANIA_LABEL_HPP
--- a/libclient/malikania/line.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - * line.h -- line description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_LINE_H -#define MALIKANIA_LINE_H - -/** - * \file line.h - * \brief Line description. - */ - -namespace malikania { - -/** - * \class Line - * \brief Line description. - * - * A line has an origin (x, y) and a destination (x, y). - */ -class Line { -private: - 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) - { - } - - /** - * 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 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; - } -}; - -/** - * Compare equality. - * - * \param l1 the first line - * \param l2 the second line - * \return true if they equal - */ -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(); -} - -/** - * Compare equality. - * - * \param l1 the first line - * \param l2 the second line - * \return false if they equal - */ -inline bool operator!=(const Line &l1, const Line &l2) noexcept -{ - return !(l1 == l2); -} - -} // !malikania - -#endif // !MALIKANIA_LINE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/line.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,126 @@ +/* + * line.hpp -- line description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_LINE_HPP +#define MALIKANIA_LINE_HPP + +/** + * \file line.hpp + * \brief Line description. + */ + +namespace malikania { + +/** + * \class Line + * \brief Line description. + * + * A line has an origin (x, y) and a destination (x, y). + */ +class Line { +private: + 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) + { + } + + /** + * 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 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; + } +}; + +/** + * Compare equality. + * + * \param l1 the first line + * \param l2 the second line + * \return true if they equal + */ +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(); +} + +/** + * Compare equality. + * + * \param l1 the first line + * \param l2 the second line + * \return false if they equal + */ +inline bool operator!=(const Line &l1, const Line &l2) noexcept +{ + return !(l1 == l2); +} + +} // !malikania + +#endif // !MALIKANIA_LINE_HPP
--- a/libclient/malikania/point.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * point.h -- point description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_POINT_H -#define MALIKANIA_POINT_H - -/** - * \file point.h - * \brief Point description. - */ - -namespace malikania { - -/** - * \class Point - * \brief Point coordinate. - */ -class Point { -private: - 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) - { - } - - /** - * 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; - } -}; - -/** - * Compare equality. - * - * \param p1 the first point - * \param p2 the second point - * \return true if they equal - */ -inline bool operator==(const Point &p1, const Point &p2) noexcept -{ - return p1.x() == p2.x() && p1.y() == p2.y(); -} - -/** - * Compare equality. - * - * \param p1 the first point - * \param p2 the second point - * \return false if they equal - */ -inline bool operator!=(const Point &p1, const Point &p2) noexcept -{ - return !(p1 == p2); -} - -} // !malikania - -#endif // !MALIKANIA_POINT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/point.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,98 @@ +/* + * point.hpp -- point description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_POINT_HPP +#define MALIKANIA_POINT_HPP + +/** + * \file point.hpp + * \brief Point description. + */ + +namespace malikania { + +/** + * \class Point + * \brief Point coordinate. + */ +class Point { +private: + 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) + { + } + + /** + * 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; + } +}; + +/** + * Compare equality. + * + * \param p1 the first point + * \param p2 the second point + * \return true if they equal + */ +inline bool operator==(const Point &p1, const Point &p2) noexcept +{ + return p1.x() == p2.x() && p1.y() == p2.y(); +} + +/** + * Compare equality. + * + * \param p1 the first point + * \param p2 the second point + * \return false if they equal + */ +inline bool operator!=(const Point &p1, const Point &p2) noexcept +{ + return !(p1 == p2); +} + +} // !malikania + +#endif // !MALIKANIA_POINT_HPP
--- a/libclient/malikania/rectangle.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * rectangle.h -- rectangle description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_RECTANGLE_H -#define MALIKANIA_RECTANGLE_H - -/** - * \file rectangle.h - * \brief Rectangle description. - */ - -namespace malikania { - -/** - * \class Rectangle - * \brief Rectangle description. - * - * A rectangle has coordinates (x, y) and dimensions (width, height). - * - * They are commonly used for clipping images into the window. - */ -class Rectangle { -private: - 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) - { - } - - /** - * 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 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; - } - - /** - * 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; - } -}; - -/** - * Compare equality. - * - * \param r1 the first rectangle - * \param r2 the second rectangle - * \return true if they equal - */ -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(); -} - -/** - * Compare equality. - * - * \param r1 the first rectangle - * \param r2 the second rectangle - * \return false if they equal - */ -inline bool operator!=(const Rectangle &r1, const Rectangle &r2) noexcept -{ - return !(r1 == r2); -} - -} // !malikania - -#endif // !MALIKANIA_RECTANGLE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/rectangle.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,138 @@ +/* + * rectangle.hpp -- rectangle description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_RECTANGLE_HPP +#define MALIKANIA_RECTANGLE_HPP + +/** + * \file rectangle.hpp + * \brief Rectangle description. + */ + +namespace malikania { + +/** + * \class Rectangle + * \brief Rectangle description. + * + * A rectangle has coordinates (x, y) and dimensions (width, height). + * + * They are commonly used for clipping images into the window. + */ +class Rectangle { +private: + 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) + { + } + + /** + * 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 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; + } + + /** + * 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; + } +}; + +/** + * Compare equality. + * + * \param r1 the first rectangle + * \param r2 the second rectangle + * \return true if they equal + */ +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(); +} + +/** + * Compare equality. + * + * \param r1 the first rectangle + * \param r2 the second rectangle + * \return false if they equal + */ +inline bool operator!=(const Rectangle &r1, const Rectangle &r2) noexcept +{ + return !(r1 == r2); +} + +} // !malikania + +#endif // !MALIKANIA_RECTANGLE_HPP
--- a/libclient/malikania/size.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * size.h -- size description - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_SIZE_H -#define MALIKANIA_SIZE_H - -namespace malikania { - -/** - * \class Size - * \brief Size description. - */ -class Size { -private: - 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) - { - } - - /** - * 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; - } - - /** - * 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; - } -}; - -/** - * Compare equality. - * - * \param s1 the first size - * \param s2 the second size - * \return true if they equal - */ -inline bool operator==(const Size &s1, const Size &s2) noexcept -{ - return s1.width() == s2.width() && s1.height() == s2.height(); -} - -/** - * Compare equality. - * - * \param s1 the first size - * \param s2 the second size - * \return false if they equal - */ -inline bool operator!=(const Size &s1, const Size &s2) noexcept -{ - return !(s1 == s2); -} - -} // !malikania - -#endif // !MALIKANIA_SIZE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/size.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,103 @@ +/* + * size.hpp -- size description + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_SIZE_HPP +#define MALIKANIA_SIZE_HPP + +namespace malikania { + +/** + * \class Size + * \brief Size description. + */ +class Size { +private: + 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) + { + } + + /** + * 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; + } + + /** + * 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; + } +}; + +/** + * Compare equality. + * + * \param s1 the first size + * \param s2 the second size + * \return true if they equal + */ +inline bool operator==(const Size &s1, const Size &s2) noexcept +{ + return s1.width() == s2.width() && s1.height() == s2.height(); +} + +/** + * Compare equality. + * + * \param s1 the first size + * \param s2 the second size + * \return false if they equal + */ +inline bool operator!=(const Size &s1, const Size &s2) noexcept +{ + return !(s1 == s2); +} + +} // !malikania + +#endif // !MALIKANIA_SIZE_HPP
--- a/libclient/malikania/sprite.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/sprite.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,61 +1,61 @@ -/* - * sprite.cpp -- image sprite - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "sprite.h" - -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)) -{ - 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(); - } - - /* 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); - - /* 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()); - - 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); -} - -} // !malikania +/* + * sprite.cpp -- image sprite + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "sprite.hpp" + +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)) +{ + 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(); + } + + /* 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); + + /* 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()); + + 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); +} + +} // !malikania
--- a/libclient/malikania/sprite.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/* - * sprite.h -- image sprite - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_SPRITE_H -#define MALIKANIA_SPRITE_H - -/** - * \file sprite.h - * \brief Sprite description. - */ - -#include <malikania/json.h> - -#include "image.h" -#include "js.h" - -namespace malikania { - -class Point; -class Window; - -/** - * \class Sprite - * \brief A Sprite is an image divided into cells. - */ -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; - -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; - - /** - * 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; - } - - /** - * 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 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 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); -}; - -} // !malikania - -#endif // !MALIKANIA_SPRITE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/sprite.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,147 @@ +/* + * sprite.hpp -- image sprite + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_SPRITE_HPP +#define MALIKANIA_SPRITE_HPP + +/** + * \file sprite.hpp + * \brief Sprite description. + */ + +#include <malikania/json.hpp> + +#include "image.hpp" +#include "js.hpp" + +namespace malikania { + +class Point; +class Window; + +/** + * \class Sprite + * \brief A Sprite is an image divided into cells. + */ +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; + +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; + + /** + * 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; + } + + /** + * 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 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 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); +}; + +} // !malikania + +#endif // !MALIKANIA_SPRITE_HPP
--- a/libclient/malikania/window.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libclient/malikania/window.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,118 +1,118 @@ -/* - * window.cpp -- main window and basic drawing - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stdexcept> - -#include "color.h" -#include "window-backend.h" - -namespace malikania { - -Window::Window(unsigned width, unsigned height, const std::string &title) - : m_backend(std::make_unique<Backend>(*this, width, height, title)) -{ -} - -Window::Window(Window &&) = default; - -Window::~Window() = default; - -void Window::poll() -{ - m_backend->poll(*this); -} - -void Window::clear() -{ - m_backend->clear(); -} - -void Window::present() -{ - m_backend->present(); -} - -void Window::close() noexcept -{ - m_isOpen = false; - m_backend->close(); -} - -Color Window::drawingColor() const -{ - return m_backend->drawingColor(); -} - -void Window::setDrawingColor(const Color &color) -{ - m_backend->setDrawingColor(color); -} - -void Window::drawLine(const Line &line) -{ - m_backend->drawLine(line); -} - -void Window::drawLines(const std::vector<Point> &points) -{ - m_backend->drawLines(points); -} - -void Window::drawPoint(const Point &point) -{ - m_backend->drawPoint(point); -} - -void Window::drawPoints(const std::vector<Point> &points) -{ - m_backend->drawPoints(points); -} - -void Window::drawRectangle(const Rectangle &rectangle) -{ - m_backend->drawRectangle(rectangle); -} - -void Window::drawRectangles(const std::vector<Rectangle> &rectangles) -{ - m_backend->drawRectangles(rectangles); -} - -void Window::fillRectangle(const Rectangle &rectangle) -{ - m_backend->fillRectangle(rectangle); -} - -void Window::fillRectangles(const std::vector<Rectangle> &rectangles) -{ - m_backend->fillRectangles(rectangles); -} - -void Window::drawText(const std::string &text, Font &font, const Rectangle &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); -} - -Window &Window::operator=(Window &&) = default; - -} // !malikania +/* + * window.cpp -- main window and basic drawing + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdexcept> + +#include "color.hpp" +#include "window-backend.hpp" + +namespace malikania { + +Window::Window(unsigned width, unsigned height, const std::string &title) + : m_backend(std::make_unique<Backend>(*this, width, height, title)) +{ +} + +Window::Window(Window &&) = default; + +Window::~Window() = default; + +void Window::poll() +{ + m_backend->poll(*this); +} + +void Window::clear() +{ + m_backend->clear(); +} + +void Window::present() +{ + m_backend->present(); +} + +void Window::close() noexcept +{ + m_isOpen = false; + m_backend->close(); +} + +Color Window::drawingColor() const +{ + return m_backend->drawingColor(); +} + +void Window::setDrawingColor(const Color &color) +{ + m_backend->setDrawingColor(color); +} + +void Window::drawLine(const Line &line) +{ + m_backend->drawLine(line); +} + +void Window::drawLines(const std::vector<Point> &points) +{ + m_backend->drawLines(points); +} + +void Window::drawPoint(const Point &point) +{ + m_backend->drawPoint(point); +} + +void Window::drawPoints(const std::vector<Point> &points) +{ + m_backend->drawPoints(points); +} + +void Window::drawRectangle(const Rectangle &rectangle) +{ + m_backend->drawRectangle(rectangle); +} + +void Window::drawRectangles(const std::vector<Rectangle> &rectangles) +{ + m_backend->drawRectangles(rectangles); +} + +void Window::fillRectangle(const Rectangle &rectangle) +{ + m_backend->fillRectangle(rectangle); +} + +void Window::fillRectangles(const std::vector<Rectangle> &rectangles) +{ + m_backend->fillRectangles(rectangles); +} + +void Window::drawText(const std::string &text, Font &font, const Rectangle &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); +} + +Window &Window::operator=(Window &&) = default; + +} // !malikania
--- a/libclient/malikania/window.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,270 +0,0 @@ -/* - * window.h -- main window and basic drawing - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_WINDOW_H -#define MALIKANIA_WINDOW_H - -/** - * \file window.h - * \brief Window and drawing. - */ - -#include <functional> -#include <memory> -#include <vector> -#include <string> - -#include "js.h" - -namespace malikania { - -class Color; -class Line; -class Font; -class Point; -class Rectangle; - -/** - * \brief Main window class and drawing. - */ -class Window : public duk::Bindable { -private: - class Backend; - - std::function<void ()> m_onQuit; - std::function<void (unsigned)> m_onKeyDown; - std::function<void (unsigned)> m_onKeyUp; - - std::unique_ptr<Backend> m_backend; - - bool m_isOpen{true}; - -public: - inline void onQuit() - { - if (m_onQuit) { - m_onQuit(); - } - } - - inline void onKeyDown(unsigned key) - { - if (m_onKeyDown) { - m_onKeyDown(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 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); - } - - /** - * 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 &&); - - /** - * Virtual destructor defaulted. - */ - virtual ~Window(); - - /** - * 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; - } - - /** - * Overloaded function. - * - * \return the backend - */ - inline Backend &backend() noexcept - { - return *m_backend; - } - - /** - * Poll pending events. - */ - void poll(); - - /** - * Clear the window content with the current drawing color. - */ - void clear(); - - /** - * Render the content of the window to the screen. - */ - void present(); - - /** - * Close the window. - */ - void close() noexcept; - - /** - * Get the current drawing color. - * - * \return the color - */ - Color drawingColor() const; - - /** - * 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 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 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 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 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); - - /** - * 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 &&); -}; - -} // !malikania - -#endif // !_MALIKANIA_WINDOW_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/window.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,270 @@ +/* + * window.hpp -- main window and basic drawing + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_WINDOW_HPP +#define MALIKANIA_WINDOW_HPP + +/** + * \file window.hpp + * \brief Window and drawing. + */ + +#include <functional> +#include <memory> +#include <vector> +#include <string> + +#include "js.hpp" + +namespace malikania { + +class Color; +class Line; +class Font; +class Point; +class Rectangle; + +/** + * \brief Main window class and drawing. + */ +class Window : public duk::Bindable { +private: + class Backend; + + std::function<void ()> m_onQuit; + std::function<void (unsigned)> m_onKeyDown; + std::function<void (unsigned)> m_onKeyUp; + + std::unique_ptr<Backend> m_backend; + + bool m_isOpen{true}; + +public: + inline void onQuit() + { + if (m_onQuit) { + m_onQuit(); + } + } + + inline void onKeyDown(unsigned key) + { + if (m_onKeyDown) { + m_onKeyDown(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 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); + } + + /** + * 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 &&); + + /** + * Virtual destructor defaulted. + */ + virtual ~Window(); + + /** + * 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; + } + + /** + * Overloaded function. + * + * \return the backend + */ + inline Backend &backend() noexcept + { + return *m_backend; + } + + /** + * Poll pending events. + */ + void poll(); + + /** + * Clear the window content with the current drawing color. + */ + void clear(); + + /** + * Render the content of the window to the screen. + */ + void present(); + + /** + * Close the window. + */ + void close() noexcept; + + /** + * Get the current drawing color. + * + * \return the color + */ + Color drawingColor() const; + + /** + * 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 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 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 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 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); + + /** + * 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 &&); +}; + +} // !malikania + +#endif // !_MALIKANIA_WINDOW_HPP_
--- a/libcommon/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,70 +1,70 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -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 -) - -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 -) - -if (WITH_BACKEND_SDL) - 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}) -endif () - -if (WIN32) - 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} -) - -set_target_properties(libcommon PROPERTIES PREFIX "") +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +set( + HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/application.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/elapsed-timer.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/game.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/id.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/js-elapsed-timer.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/json.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-loader.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/resources-locator.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/malikania/util.hpp +) + +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 +) + +if (WITH_BACKEND_SDL) + find_package(SDL2 REQUIRED) + + list(APPEND HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/malikania/backend/sdl/common-sdl.hpp) + 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) +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} +) + +set_target_properties(libcommon PROPERTIES PREFIX "")
--- a/libcommon/malikania/application.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/application.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,28 +1,28 @@ -/* - * application.cpp -- main application class - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "application.h" - -namespace malikania { - -Application::Application(int, char **) -{ - // TODO: find the executable path -} - -} // !malikania +/* + * application.cpp -- main application class + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "application.hpp" + +namespace malikania { + +Application::Application(int, char **) +{ + // TODO: find the executable path +} + +} // !malikania
--- a/libcommon/malikania/application.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * application.h -- main application class - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_APPLICATION_H -#define MALIKANIA_APPLICATION_H - -/** - * \file application.h - * \brief Main class for the client or server - */ - -namespace malikania { - -/** - * \class Application - * \brief Main class for argument parsing and executable path retrievement - */ -class Application { -public: - /** - * Construct the application. - * - * \param argc the argument count - * \param argv the arguments - */ - Application(int argc, char **argv); - - /** - * Virtual destructor defaulted. - */ - virtual ~Application() = default; -}; - -} // !malikania - -#endif // !MALIKANIA_APPLICATION_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/application.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,51 @@ +/* + * application.hpp -- main application class + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_APPLICATION_HPP +#define MALIKANIA_APPLICATION_HPP + +/** + * \file application.hpp + * \brief Main class for the client or server + */ + +namespace malikania { + +/** + * \class Application + * \brief Main class for argument parsing and executable path retrievement + */ +class Application { +public: + /** + * Construct the application. + * + * \param argc the argument count + * \param argv the arguments + */ + Application(int argc, char **argv); + + /** + * Virtual destructor defaulted. + */ + virtual ~Application() = default; +}; + +} // !malikania + +#endif // !MALIKANIA_APPLICATION_HPP
--- a/libcommon/malikania/backend/sdl/common-sdl.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/backend/sdl/common-sdl.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,153 +1,153 @@ -/* - * CommonSdl.cpp -- common SDL2 related code - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cerrno> -#include <cstdint> -#include <cstring> -#include <new> - -#include "common-sdl.h" - -namespace malikania { - -namespace sdl { - -namespace { - -/* - * RWFromBinary implementation - * ------------------------------------------------------------------ - * - * A little bit inspired by official SDL_RWFromMem implementation, largely modified to match our conventions and the - * C++ code. - */ - -class Buffer { -public: - 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()) - { - } -}; - -Sint64 size(SDL_RWops *ops) -{ - 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; - - 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; - - 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; - - 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); - - data->m_position += total; - - return (total / size); -} - -size_t write(SDL_RWops *, const void *, size_t, size_t) -{ - SDL_SetError("write not supported"); - - return -1; -} - -int close(SDL_RWops *ops) -{ - if (ops != nullptr) { - delete reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); - SDL_FreeRW(ops); - } - - return 0; -} - -} // !namespace - -SDL_RWops *RWFromBinary(std::string data) noexcept -{ - SDL_RWops *ops = SDL_AllocRW(); - - if (ops == nullptr) { - return nullptr; - } - - 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; - } - - ops->type = SDL_RWOPS_UNKNOWN; - ops->seek = seek; - ops->size = size; - ops->read = read; - ops->write = write; - ops->close = close; - - return ops; -} - -} // !sdl - -} // !malikania +/* + * CommonSdl.cpp -- common SDL2 related code + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cerrno> +#include <cstdint> +#include <cstring> +#include <new> + +#include "common-sdl.hpp" + +namespace malikania { + +namespace sdl { + +namespace { + +/* + * RWFromBinary implementation + * ------------------------------------------------------------------ + * + * A little bit inspired by official SDL_RWFromMem implementation, largely modified to match our conventions and the + * C++ code. + */ + +class Buffer { +public: + 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()) + { + } +}; + +Sint64 size(SDL_RWops *ops) +{ + 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; + + 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; + + 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; + + 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); + + data->m_position += total; + + return (total / size); +} + +size_t write(SDL_RWops *, const void *, size_t, size_t) +{ + SDL_SetError("write not supported"); + + return -1; +} + +int close(SDL_RWops *ops) +{ + if (ops != nullptr) { + delete reinterpret_cast<Buffer *>(ops->hidden.unknown.data1); + SDL_FreeRW(ops); + } + + return 0; +} + +} // !namespace + +SDL_RWops *RWFromBinary(std::string data) noexcept +{ + SDL_RWops *ops = SDL_AllocRW(); + + if (ops == nullptr) { + return nullptr; + } + + 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; + } + + ops->type = SDL_RWOPS_UNKNOWN; + ops->seek = seek; + ops->size = size; + ops->read = read; + ops->write = write; + ops->close = close; + + return ops; +} + +} // !sdl + +} // !malikania
--- a/libcommon/malikania/backend/sdl/common-sdl.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * CommonSdl.h -- common SDL2 related code - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_COMMON_SDL_H -#define MALIKANIA_COMMON_SDL_H - -#include <SDL.h> - -#include <string> - -namespace malikania { - -namespace sdl { - -/** - * Create a SDL_RWops that owns the binary data. - * - * This is a safe alternative to SDL_RWFromMem because it owns the memory pointed by data until it is closed. The - * data is moved so there are no copies. - * - * The stream has read-only support and can not write. - * - * Seeking past-the-end or past-the-begin readjust the position to the end or begin respectively. - * - * \param data the data - * \return the object or nullptr on errors - */ -SDL_RWops *RWFromBinary(std::string data) noexcept; - -} // !sdl - -} // !malikania - -#endif // !MALIKANIA_COMMON_SDL_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/backend/sdl/common-sdl.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,49 @@ +/* + * CommonSdl.hpp -- common SDL2 related code + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_COMMON_SDL_HPP +#define MALIKANIA_COMMON_SDL_HPP + +#include <SDL.h> + +#include <string> + +namespace malikania { + +namespace sdl { + +/** + * Create a SDL_RWops that owns the binary data. + * + * This is a safe alternative to SDL_RWFromMem because it owns the memory pointed by data until it is closed. The + * data is moved so there are no copies. + * + * The stream has read-only support and can not write. + * + * Seeking past-the-end or past-the-begin readjust the position to the end or begin respectively. + * + * \param data the data + * \return the object or nullptr on errors + */ +SDL_RWops *RWFromBinary(std::string data) noexcept; + +} // !sdl + +} // !malikania + +#endif // !MALIKANIA_COMMON_SDL_HPP
--- a/libcommon/malikania/common-config.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#ifndef COMMON_CONFIG_H -#define COMMON_CONFIG_H - -#if defined(_WIN32) -# if defined(MALIKANIA_COMMON_BUILD) -# define MALIKANIA_COMMON_EXPORT __declspec(dllexport) -# else -# define MALIKANIA_COMMON_EXPORT __declspec(dllimport) -# endif -#else -# define MALIKANIA_COMMON_EXPORT -#endif - -#endif // !COMMON_CONFIG_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/common-config.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,14 @@ +#ifndef COMMON_CONFIG_HPP +#define COMMON_CONFIG_HPP + +#if defined(_WIN32) +# if defined(MALIKANIA_COMMON_BUILD) +# define MALIKANIA_COMMON_EXPORT __declspec(dllexport) +# else +# define MALIKANIA_COMMON_EXPORT __declspec(dllimport) +# endif +#else +# define MALIKANIA_COMMON_EXPORT +#endif + +#endif // !COMMON_CONFIG_HPP \ No newline at end of file
--- a/libcommon/malikania/elapsed-timer.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/elapsed-timer.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,64 +1,64 @@ -/* - * elapsed-timer.cpp -- measure elapsed time - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "elapsed-timer.h" - -using std::chrono::duration_cast; -using std::chrono::high_resolution_clock; -using std::chrono::milliseconds; - -namespace malikania { - -ElapsedTimer::ElapsedTimer() noexcept -{ - 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; -} - -void ElapsedTimer::restart() noexcept -{ - m_paused = false; - m_last = high_resolution_clock::now(); -} - -void ElapsedTimer::reset() noexcept -{ - 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(); - } - - return m_elapsed; -} - -} // !malikania +/* + * elapsed-timer.cpp -- measure elapsed time + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "elapsed-timer.hpp" + +using std::chrono::duration_cast; +using std::chrono::high_resolution_clock; +using std::chrono::milliseconds; + +namespace malikania { + +ElapsedTimer::ElapsedTimer() noexcept +{ + 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; +} + +void ElapsedTimer::restart() noexcept +{ + m_paused = false; + m_last = high_resolution_clock::now(); +} + +void ElapsedTimer::reset() noexcept +{ + 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(); + } + + return m_elapsed; +} + +} // !malikania
--- a/libcommon/malikania/elapsed-timer.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * elapsed-timer.h -- measure elapsed time - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_ELAPSED_TIMER_H -#define MALIKANIA_ELAPSED_TIMER_H - -/** - * \file elapsed-timer.h - * \brief Measure elapsed time - */ - -#include <chrono> - -#include "js.h" - -namespace malikania { - -/** - * \class ElapsedTimer - * \brief Measure elapsed time - * - * This class provides an abstraction to measure elapsed time since the - * construction of the object. - * - * It uses std::chrono::high_resolution_clock for more precision and uses - * milliseconds only. - */ -class ElapsedTimer : public duk::Bindable { -public: - using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; - -private: - TimePoint m_last; - bool m_paused{false}; - unsigned m_elapsed{0}; - -public: - /** - * Construct the elapsed timer, start counting. - */ - ElapsedTimer() 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; - - /** - * Reset the timer to 0. - */ - void reset() noexcept; - - /** - * Get the number of elapsed milliseconds. - * - * \return the milliseconds - */ - unsigned elapsed() noexcept; -}; - -} // !malikania - -#endif // !MALIKANIA_ELAPSED_TIMER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/elapsed-timer.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,83 @@ +/* + * elapsed-timer.hpp -- measure elapsed time + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_ELAPSED_TIMER_HPP +#define MALIKANIA_ELAPSED_TIMER_HPP + +/** + * \file elapsed-timer.hpp + * \brief Measure elapsed time + */ + +#include <chrono> + +#include "js.hpp" + +namespace malikania { + +/** + * \class ElapsedTimer + * \brief Measure elapsed time + * + * This class provides an abstraction to measure elapsed time since the + * construction of the object. + * + * It uses std::chrono::high_resolution_clock for more precision and uses + * milliseconds only. + */ +class ElapsedTimer : public duk::Bindable { +public: + using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; + +private: + TimePoint m_last; + bool m_paused{false}; + unsigned m_elapsed{0}; + +public: + /** + * Construct the elapsed timer, start counting. + */ + ElapsedTimer() 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; + + /** + * Reset the timer to 0. + */ + void reset() noexcept; + + /** + * Get the number of elapsed milliseconds. + * + * \return the milliseconds + */ + unsigned elapsed() noexcept; +}; + +} // !malikania + +#endif // !MALIKANIA_ELAPSED_TIMER_HPP
--- a/libcommon/malikania/game.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -/* - * game.h -- basic game class - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_GAME_H -#define MALIKANIA_GAME_H - -#include <cassert> -#include <string> -#include <vector> - -namespace malikania { - -namespace json { - -class Document; - -} // !json - -/** - * \class Game - * \brief Basic game class. - */ -class Game { -private: - 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()); - } - - /** - * 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 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 engine version required to run the game. - * - * \return the version required - */ - inline const std::string &requires() const noexcept - { - return m_requires; - } -}; - -} // !malikania - -#endif // !MALIKANIA_GAME_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/game.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,124 @@ +/* + * game.hpp -- basic game class + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_GAME_HPP +#define MALIKANIA_GAME_HPP + +#include <cassert> +#include <string> +#include <vector> + +namespace malikania { + +namespace json { + +class Document; + +} // !json + +/** + * \class Game + * \brief Basic game class. + */ +class Game { +private: + 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()); + } + + /** + * 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 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 engine version required to run the game. + * + * \return the version required + */ + inline const std::string &requires() const noexcept + { + return m_requires; + } +}; + +} // !malikania + +#endif // !MALIKANIA_GAME_HPP
--- a/libcommon/malikania/id.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -/* - * id.h -- integer id generator - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_COMMON_ID_H -#define MALIKANIA_COMMON_ID_H - -/** - * \file id.h - * \brief Integer id generator - */ - -#include <limits> -#include <queue> -#include <stdexcept> - -namespace malikania { - -/** - * \class IdGen - * \brief Integer id generator - * - * This class helps generating and release unique integer id that can be used anywhere. The ids are generated in a - * sequence and when an id is released it is reused instead of incrementing the next number. - * - * The template can use any integral integer but unsigned are preferred. - * - * The maximum number of id is equal to std::numeric_limits<T>::max - 1. - */ -template <typename T> -class IdGen { -private: - static_assert(std::numeric_limits<T>::is_integer, "IdGen requires integral types"); - - 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(); - - /** - * 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; -}; - -template <typename T> -T IdGen<T>::next() -{ - 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"); - } - - id = m_current++; - } - - return id; -} - -template <typename T> -void IdGen<T>::reset() noexcept -{ - m_current = 0; - - while (!m_reusable.empty()) { - m_reusable.pop(); - } -} - -/** - * \class Id - * \brief RAII based id owner - * - * This class is similar to a std::lock_guard or std::unique_lock in a way that the id is acquired - * when the object is instanciated and released when destroyed. - * - * This class does not take ownership of the IdGen so it must still exists when the Id is destroyed. - */ -template <typename T> -class Id { -private: - 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 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); - } - - /** - * 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; - } -}; - -} // !malikania - -#endif // !MALIKANIA_COMMON_ID_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/id.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,176 @@ +/* + * id.hpp -- integer id generator + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_COMMON_ID_HPP +#define MALIKANIA_COMMON_ID_HPP + +/** + * \file id.hpp + * \brief Integer id generator + */ + +#include <limits> +#include <queue> +#include <stdexcept> + +namespace malikania { + +/** + * \class IdGen + * \brief Integer id generator + * + * This class helps generating and release unique integer id that can be used anywhere. The ids are generated in a + * sequence and when an id is released it is reused instead of incrementing the next number. + * + * The template can use any integral integer but unsigned are preferred. + * + * The maximum number of id is equal to std::numeric_limits<T>::max - 1. + */ +template <typename T> +class IdGen { +private: + static_assert(std::numeric_limits<T>::is_integer, "IdGen requires integral types"); + + 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(); + + /** + * 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; +}; + +template <typename T> +T IdGen<T>::next() +{ + 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"); + } + + id = m_current++; + } + + return id; +} + +template <typename T> +void IdGen<T>::reset() noexcept +{ + m_current = 0; + + while (!m_reusable.empty()) { + m_reusable.pop(); + } +} + +/** + * \class Id + * \brief RAII based id owner + * + * This class is similar to a std::lock_guard or std::unique_lock in a way that the id is acquired + * when the object is instanciated and released when destroyed. + * + * This class does not take ownership of the IdGen so it must still exists when the Id is destroyed. + */ +template <typename T> +class Id { +private: + 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 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); + } + + /** + * 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; + } +}; + +} // !malikania + +#endif // !MALIKANIA_COMMON_ID_HPP
--- a/libcommon/malikania/js-elapsed-timer.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/js-elapsed-timer.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "elapsed-timer.h" -#include "js.h" +#include "elapsed-timer.hpp" +#include "js.hpp" namespace malikania {
--- a/libcommon/malikania/js-elapsed-timer.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * js-elapsed-timer.h -- - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_ELAPSED_TIMER_H -#define MALIKANIA_JS_ELAPSED_TIMER_H - -#include "js.h" - -namespace malikania { - -void loadJsElapsedTimer(duk::ContextPtr ctx) noexcept; - -} // !malikania - -#endif // !MALIKANIA_JS_ELAPSED_TIMER_H -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/js-elapsed-timer.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,31 @@ +/* + * js-elapsed-timer.hpp -- + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_ELAPSED_TIMER_HPP +#define MALIKANIA_JS_ELAPSED_TIMER_HPP + +#include "js.hpp" + +namespace malikania { + +void loadJsElapsedTimer(duk::ContextPtr ctx) noexcept; + +} // !malikania + +#endif // !MALIKANIA_JS_ELAPSED_TIMER_HPP +
--- a/libcommon/malikania/js.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3103 +0,0 @@ -/* - * js.h -- JavaScript C++14 wrapper for Duktape - * - * Copyright (c) 2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JS_H -#define MALIKANIA_JS_H - -/** - * \file js.h - * \brief Bring JavaScript using Duktape. - * - * This file provides usual Duktape function renamed and placed into `duk` namespace. It also replaces error - * code with exceptions when possible. - * - * For convenience, this file also provides templated functions, overloads and much more. - */ - -/** - * \page js JavaScript binding - * \brief JavaScript binding using Duktape - * - * This page will show you how to setup this module to host JavaScript environment into your C++ application. - * - * ## Duktape - * - * Duktape is a C library designed for performance, small footprint and conformance. This wrapper is built top of it and - * requires it at build and runtime. - * - * It is highly recommended that you read the [Duktape guide](http://duktape.org/guide.html) before continuing because - * a lot of concepts are kept as-is. - * - * ## Installation - * - * You need the Duktape source amalgamation, it is provided with this module. - * - * When compiling, be sure to enable `-DDUK_OPT_CPP_EXCEPTIONS` and that Duktape source file has **cpp** extension. - * - * Just copy the **js.h** file and include it into your project. The header depends on **duktape.h** so be sure to - * provide it when compiling. - * - * @subpage js-init - * @subpage js-types - * @subpage js-basics - * @subpage js-more - * @subpage js-concepts - */ - -/** - * \page js-init Initialization - * \brief Context initialization. - * - * To host JavaScript, you need a context. Usually one is sufficient but you can create as many as you want but they - * won't share any resource. - * - * @code - * #include "js.h" - * - * int main() - * { - * duk::Context ctx; - * - * return 0; - * } - * @endcode - * - * The duk::Context class is a RAII based wrapper around the native duk_context structure. It is automatically created - * and closed in the destructor. - * - * Be sure to not keep any pointer to it. - */ - -/** - * \page js-types Predefined types - * \brief Default duk::TypeTraits specializations - * - * The following specializations are provided with libjs. - * - * ## Primitive types - * - * | Type | Support | Remarks | - * |----------------|----------------------------------|---------------------------------------| - * | `int` | get, is, optional, push, require | | - * | `bool` | get, is, optional, push, require | | - * | `double` | get, is, optional, push, require | | - * | `std::string` | get, is, optional, push, require | can contain '\0' and binary data | - * | `const char *` | get, is, optional, push, require | | - * | `unsigned` | get, is, optional, push, require | | - * | T * | get, is, optional, push, require | raw pointer, never deleted by Duktape | - * - * ## Special JavaScript types - * - * The following types are used to create or inspect JavaScript types. - * - * | Type | Support | Remarks | - * |------------------|----------|----------------------------------------| - * | duk::Array | is, push | | - * | duk::Function | is, push | is just check if the value is callable | - * | duk::FunctionMap | put | | - * | duk::Global | push | | - * | duk::Null | is, push | | - * | duk::Object | is, push | | - * | duk::This | push | | - * | duk::Undefined | is, push | | - * - * ## Partial specializations - * - * These partial specializations will use complete specialization for T. - * - * | Type | Support | Remarks | - * |------------------------------------|-----------|------------------------| - * | std::unordered_map<std::string, T> | push, put | push or put properties | - * | std::vector<T> | push, put | push array of values | - * - * ## Special types - * - * These types are used to export C++ object to JavaScript. See @ref js-more-t2 for more explanations and - * @ref js-concept-class. - * - * | Type | Support | Remarks | - * |--------------------|-----------------------------------------|--------------------------------| - * | std::shared_ptr<T> | construct, get, optional, push, require | T must have Class requirements | - */ - -/** - * \page js-basics Basics - * \brief Basics use case. - * - * The following topics are sample use case of the C++ front end. It does not use extended features that this module - * provides. - * - * @subpage js-basics-t1 - * @subpage js-basics-t2 - * @subpage js-basics-t3 - */ - -/** - * \page js-basics-t1 Example 1: call JavaScript code from C++ - * \brief Evaluate JavaScript code from C++. - * - * Let use JavaScript to compute a simple expression. - * - * @code - * #include "js.h" - * - * int main() - * { - * duk::Context ctx; - * - * duk::pevalString(ctx, "1 + 1"); - * std::cout << duk::get<int>(ctx -1) << std::endl; - * - * return 0; - * } - * @endcode - */ - -/** - * \page js-basics-t2 Example 2: call C++ code from JavaScript - * \brief Evaluate a function from JavaScript. - * - * In that example, we will add a C++ function to JavaScript and call it from the script. The function just compute the - * two arguments that are passed through the function and return the result. - * - * We take the benefits of C++11 to map the function. The lambda can not have a capture because Duktape use raw C - * function pointers and this module keep them. - * - * @code - * #include "js.h" - * - * int main() - * { - * duk::Context ctx; - * - * // Push a function as global "add" - * duk::putGlobal(ctx, "add", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { - * int x = duk::require<int>(ctx, 0); - * int y = duk::require<int>(ctx, 1); - * - * duk::push(ctx, x + y); - * - * return 1; - * }, 2}); - * - * // Evaluate from JavaScript - * duk::pevalString(ctx, "add(1, 2)"); - * - * return 0; - * } - * @endcode - * - * Please note the **2** at end of lambda which indicates that the function takes 2 arguments. If number of arguments - * is variadic, pass DUK_VARARGS there. - */ - -/** - * \page js-basics-t3 Example 3: pushing and getting values - * \brief Manage values between JavaScript and C++. - * - * As you have seen in the previous examples, we were pushing some values to the Duktape context. - * - * With the C Duktape frontend, you usually use duk_push_int, duk_push_string and all other related functions. The libjs - * module provides an uniform and convenient way for sharing values with the same functions. - * - * See the description of duk::TypeTraits to see the supported types. - * - * ## Push - * - * The duk::push function is a template that accept most of the primitives types. It uses the specializations of the - * duk::TypeTraits class (described later). - * - * Example of code - * - * @code - * duk::push(ctx, 123); // an integer - * duk::push(ctx, true); // a boolean - * @endcode - * - * The push function add a new value to the stack for any specialization of TypeTraits provided by libjs. - * - * ## Get - * - * The duk::get function is similar to duk_get_ functions. It usually does not check the value and return a sane default - * value. - * - * This template function does not take the template argument so it can't be deduced and must be specified explicitly. - * - * @code - * duk::get<int>(ctx, 0) // get an int at index 0 - * duk::get<std::string>(ctx, 1) // get a std::string at index 1 - * @endcode - * - * ## Require - * - * The duk::require function is similar to duk_require functions. It requires the exact type at the given index. If the - * value is invalid a JavaScript error is propagated. - * - * @code - * duk::require<int>(ctx, 0) // require an int at index 0 or raise an error - * @endcode - * - * ## Put - * - * This special function is similar to push except that it applies to the existing object at the top of the stack. It - * is usually implemented for map and vector. - * - * @code - * // Fill the object at the top of the stack with this map - * std:unordered_map<std::string, int> map{ - * { "value1", 1 }, - * { "value2", 2 } - * }; - * - * duk::put(ctx, map); - * @endcode - * - * ## Is - * - * This function duk::is checks if the value at the given index is of the given type and return true. - * - * Just like duk::get, this function need the explicit template parameter. - * - * @code - * duk::push(ctx, 1); - * duk::is<int>(ctx, -1); // true - * @endcode - * - * ## Optional - * - * The duk::optional function has no equivalent in Duktape C API. It is a convenient way to get values with a default - * replacement is not available. - * - * The common implementation uses duk::is and then duk::get. - * - * @code - * duk::optional<int>(ctx, -1, 123); // 123 is -1 has no value or is not an int - * @endcode - */ - -/** - * \page js-more Extensions and advanced features. - * \brief Evolved extensions provided by libjs. - * - * The following topics are provided by libjs and have no equivalent in Duktape C API. - * - * @subpage js-more-t1 - * @subpage js-more-t2 - */ - -/** - * \page js-more-t1 Advanced 1: adding your own types to TypeTraits - * \brief How to specialize duk::TypeTraits structure. - * - * This topic shows how you can specialize the duk::TypeTraits structure to add more types. - * - * Specializing the duk::TypeTraits is usually only needed when you want to convert a C++ object into JavaScript, for - * exporting a C++ class, see @ref js-more-t2. - * - * In this example we will convert a C++ small structure containing two integers to JavaScript. - * - * \note It is not required to implement all functions from duk::TypeTraits. Just provide which one you need. - * - * ## The C++ structure - * - * The point does not have any methods, it just a description of two integers. - * - * @code - * struct Point { - * int x; - * int y; - * }; - * @endcode - * - * ## The push function - * - * Let's add a push function that will create a JavaScript object with **x** and **y** properties. - * - * @code - * namespace duk { - * - * template <> - * class TypeTraits<Point> { - * public: - * static void push(ContextPtr ctx, const Point &point) - * { - * // Create an object - * push(ctx, Object()); - * - * // Set x - * putProperty(ctx, -1, "x", point.x); - * - * // Set y - * putProperty(ctx, -1, "y", point.y); - * } - * }; - * - * } - * @endcode - * - * You can safely use different type of reference as second argument. - * - * That's it, you can now safely invoke `duk::push(ctx, Point{100, 200});`. - * - * ## The get function - * - * The get function usually return a new object. The recommandation is to provide sane defaults except if you have any - * reason to not do so. - * - * @code - * namespace duk { - * - * template <> - * class TypeTraits<Point> { - * public: - * static Point get(ContextPtr ctx, Index index) - * { - * Point point{0, 0}; - * - * if (is<Object>(ctx, index)) { - * point.x = getProperty<int>(ctx, index, "x"); - * point.y = getProperty<int>(ctx, index, "y"); - * } - * - * return point; - * } - * }; - * - * } - * @endcode - * - * Now you can invoke `duk::get<Point>(ctx, 0)` to convert a JavaScript object to the Point structure. - * - * ## The require function - * - * The require function has the same signature as get. It's up to you to decide which criterias makes the object not - * suitable for conversion. - * - * In that example, we will require that object at the index is a JavaScript object and that **x**, **y** are present. - * - * @code - * namespace duk { - * - * template <> - * class TypeTraits<Point> { - * public: - * static Point require(ContextPtr ctx, Index index) - * { - * Point point; - * - * // Raise an error if not object - * if (!is<Object>(ctx, index)) - * duk::raise(ctx, TypeError("object required")); - * - * // Get x, for simplicity we just check that x and y exist. - * if (!hasProperty(ctx, index, "x")) - * duk::raise(ctx, TypeError("property x missing")); - * - * // Get y - * if (!hasProperty(ctx, index, "y")) - * duk::raise(ctx, TypeError("property y missing")); - * - * // Note: if you need more security, check that types are integers too. - * point.x = duk::getProperty<int>(ctx, index, "x"); - * point.y = duk::getProperty<int>(ctx, index, "y"); - * - * return point; - * } - * }; - * - * } - * @endcode - * - * ## The is function - * - * The is function returns a boolean. Again, you decide when the value is appropriate. - * - * @code - * - * namespace duk { - * - * template <> - * class TypeTraits<Point> { - * public: - * static bool is(ContextPtr ctx, Index index) - * { - * return is<Object>(ctx, index) && hasProperty(ctx, index, "x") && hasProperty(ctx, index, "y"); - * } - * }; - * - * } - * - * @endcode - * - * ## The optional function - * - * The optional function is like get, you should return a value when it is appropriate for conversion. The - * recommandation is to return the default value **only if** there is no value at the given index or it it not - * the correct type. - * - * Usual implementation looks like this: - * - * @code - * namespace duk { - * - * template <> - * class TypeTraits<Point> { - * public: - * static Point optional(ContextPtr ctx, Index index, Point def) - * { - * return is(ctx, index) ? get(ctx, index) : def; - * } - * }; - * - * } - * @endcode - */ - -/** - * \page js-more-t2 Advanced 2: exporting C++ class - * \brief How to export a C++ class through Duktape. - * - * This example shows how you can implement a C++ class and export it through C++ through the predefined - * std::shared_ptr duk::TypeTraits specialization. - * - * There are several steps to accomplish this and you must be familiar on how object oriented works in JavaScript. - * - * See this [introduction to OO in JavaScript][oojs]. - * - * \note [RTTI] is required in order to make typesafe binding. - * - * ## Ownership - * - * To facilitate communication between C++ and JavaScript, objects must be instanciated as `std::shared_ptr`. It - * guarantees polymorphic objects and ownership. - * - * ## The C++ class - * - * In that topic, we will implement a basic Car class that has only one drive function, the class must derive from duk::Bindable. - * - * @code - * #include <iostream> - * - * #include "js.h" - * - * class Car : public duk::Binding { - * public: - * void drive() - * { - * std::cout << "Driving the car..." << std::endl; - * } - * }; - * @endcode - * - * ## The JavaScript methods - * - * This is the drive method, put it in a map. The method does not take any argument so pass 0. - * - * @code - * duk::Ret drive(duk::ContextPtr ctx) - * { - * duk::self<std::shared_ptr<Car>>(ctx)->drive(); - * - * return 0; - * } - * - * const duk::FunctionMap methods{ - * { "drive", { drive, 0 } } - * }; - * @endcode - * - * ## Construction - * - * There are two ways to export a C++ object to JavaScript. - * - * 1. When constructed from the JavaScript new operator. You must provide a C function and use duk::construct to - * apply your object to it. - * - * 2. When pusing from C++ to JavaScript. You muse use Using duk::push and you will need to implement the `prototype` - * function in duk::TypeTraits (see below). - * - * ## Example 1: provide a constructor for JavaScript ownership - * - * This example provides a function to let the user constructing the object **from** JavaScript. - * - * ### Add a constructor - * - * Add the constructor that will be called from C++. - * - * @code - * duk::Ret constructor(duk::ContextPtr ctx) - * { - * duk::construct(ctx, std::make_shared<Car>()); - * - * return 0; - * } - * @endcode - * - * ### Main - * - * We register the constructor, add a prototype and call it from JavaScript. - * - * @code - * int main() - * { - * duk::Context ctx; - * - * // Push the Car constructor function - * duk::push(ctx, duk::Function{constructor}); - * - * // Push the methods as a new object and set it as the .prototype property - * duk::putProperty(ctx, -1, "prototype", methods); - * - * // Now store the Car function - * duk::putGlobal(ctx, "Car"); - * - * // Create a Car from JavaScript - * duk::pevalString(ctx, - * "c = new Car();" - * "c.drive();" - * ); - * - * return 0; - * } - * @endcode - * - * ## Example 2: the object is created from C++ - * - * This example allocates the Car object from C++ and pass it through JavaScript. It requires to implement the - * prototype function from duk::TypeTraits. - * - * ### Prototype function - * - * This function must push into the stack the prototype for the given object. You are free to store it where you want, - * here, we set it as internal global property. - * - * @code - * namespace duk { - * - * template <> - * class TypeTraits<Car> { - * public: - * static inline void prototype(ContextPtr ctx) - * { - * getGlobal<void>(ctx, "\xff""\xff""Car-prototype"); - * } - * }; - * - * } - * @endcode - * - * ### Main - * - * Now save this prototype and create the object from C++. - * - * @code - * int main() - * { - * duk::Context ctx; - * - * // Create a prototype directly from the methods table (from example 1) - * duk::putGlobal(ctx, "\xff""\xff""Car-prototype", methods); - * - * // Put a global Car object - * duk::putGlobal(ctx, "car", std::make_shared<Car>()); - * - * // Call the JavaScript code - * duk::pevalString(ctx, "car.drive();"); - * } - * @endcode - * - * [oojs]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript - * [RTTI]: https://en.wikipedia.org/wiki/Run-time_type_information - */ - -/** - * \page js-concepts Concepts - * - * @subpage js-concept-class - */ - -/** - * \page js-concept-class Class (Concept) - * \brief This concept is used when exporting C++ class through JavaScript. - * - * When using `std::shared_ptr<T>` with duk::TypeTraits, the user must implement some function by specializing - * duk::TypeTraits<T>. - * - * ## Public static member functions - * - * ### Prototype (optional) - * - * The prototype function is optional, it is only required when exporting the C++ object using duk::push. It must push - * the prototype of your object at the top of the stack. - * - * @code - * static void prototype(duk::ContextPtr ctx); - * @endcode - */ - -#include <cassert> -#include <functional> -#include <memory> -#include <string> -#include <type_traits> -#include <unordered_map> -#include <utility> -#include <vector> - -#include <duktape.h> - -namespace malikania { - -/** - * Duktape C++ namespace wrapper. - */ -namespace duk { - -class Context; - -/** - * \brief Typedef without pointer. - */ -using ContextPtr = duk_context *; - -/** - * \brief Typedef for duk_double_t. - */ -using Double = duk_double_t; - -/** - * \brief Typedef for duk_idx_t. - */ -using Index = duk_idx_t; - -/** - * \brief Typedef for duk_ret_t. - */ -using Ret = duk_ret_t; - -/** - * \brief Typedef for duk_int_t. - */ -using Int = duk_int_t; - -/** - * \brief Typedef for duk_uint_t; - */ -using Uint = duk_uint_t; - -/** - * \class StackAssert - * \brief Stack sanity checker. - * - * Instanciate this class where you need to manipulate the Duktape stack outside a Duktape/C function, its destructor - * will examinate if the stack size matches the user expected size. - * - * When compiled with NDEBUG, this class does nothing. - * - * To use it, just declare an lvalue at the beginning of your function. - */ -class StackAssert { -#if !defined(NDEBUG) -private: - 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 -#if !defined(NDEBUG) - : m_context(ctx) - , m_expected(expected) - , m_begin(static_cast<unsigned>(duk_get_top(ctx))) -#endif - { -#if defined(NDEBUG) - (void)ctx; - (void)expected; -#endif - } - - /** - * 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); -#endif - } -}; - -/** - * \brief Inherit this class to make type safe C++ objects into JavaScript - */ -class Bindable { -public: - /** - * Default constructor - */ - Bindable() = default; - - /** - * Default destructor. - */ - virtual ~Bindable() = default; -}; - -/** - * \class TypeTraits - * \brief Type information to implement new types in JavaScript's context. - * - * %This class depending on your needs may have the following functions: - * - * ## Construct - * - * Used by duk::construct, the function must place the value as this binding when the Duktape C function is - * new-constructed. - * - * @code - * static void construct(ContextPtr ctx, Type value); - * @endcode - * - * ## Get - * - * Convert the value at the given index and return it. Should return default object if value is invalid. - * - * @code - * static Type get(ContextPtr ctx, int index); - * @endcode - * - * ## Is - * - * Tells if the value at given index is of the requested type. - * - * @code - * static bool is(ContextPtr ctx, int index); - * @endcode - * - * ## Optional - * - * Get the value at the given index or return the defaultValue. - * - * @code - * static Type optional(ContextPtr ctx, int index, Type defaultValue); - * @endcode - * - * ## Push - * - * Push the value into the stack. - * - * @code - * static void push(ContextPtr ctx, Type value); - * @endcode - * - * ## Put - * - * Apply the value to the object at the top of the stack. - * - * @code - * static void put(ContextPtr ctx, Type value); - * @endcode - * - * ## Require - * - * Require a value at the given index. - * - * @code - * static Type require(ContextPtr ctx, int index); - * @endcode - * - */ -template <typename Type> -class TypeTraits; - -/** - * \class Object - * \brief Special type for duk::TypeTraits. - */ -class Object { -}; - -/** - * \class Array - * \brief Special type for duk::TypeTraits. - */ -class Array { -}; - -/** - * \class Global - * \brief Special type for duk::TypeTraits. - */ -class Global { -}; - -/** - * \class Undefined - * \brief Special type for duk::TypeTraits. - */ -class Undefined { -}; - -/** - * \class Null - * \brief Special type for duk::TypeTraits. - */ -class Null { -}; - -/** - * \class This - * \brief Special type for duk::TypeTraits. - */ -class This { -}; - -/** - * \class Function - * \brief Duktape/C function definition. - * - * This class wraps the std::function as a Duktape/C function by storing a copied pointer. - */ -class Function { -public: - /** - * The function pointer, must not be null. - */ - duk_c_function function; - - /** - * Number of args that the function takes - */ - duk_idx_t nargs{0}; -}; - -/** - * \brief Map of functions. - */ -using FunctionMap = std::unordered_map<std::string, Function>; - -/** - * \brief Map of any type. - */ -template <typename T> -using Map = std::unordered_map<std::string, T>; - -/** - * \class Exception - * \brief Error description. - * - * This class fills the fields got in an Error object. - */ -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 - - /** - * Get the error message. This effectively returns message field. - * - * \return the message - */ - const char *what() const noexcept override - { - return message.c_str(); - } -}; - -/** - * \class Context - * \brief RAII based Duktape handler. - * - * This class is implicitly convertible to duk_context for convenience. - */ -class Context { -private: - using Deleter = void (*)(duk_context *); - using Handle = std::unique_ptr<duk_context, Deleter>; - - Handle m_handle; - - Context(const Context &) = delete; - Context &operator=(const Context &) = delete; - -public: - /** - * Create default context. - */ - inline Context() - : m_handle(duk_create_heap_default(), duk_destroy_heap) - { - } - - /** - * 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 *() const noexcept - { - return m_handle.get(); - } - - /** - * Default move assignment operator. - */ - Context &operator=(Context &&) noexcept = delete; -}; - -/** - * @name Duktape C functions - * \brief The following functions are wrappers on top of the Duktape C functions. - * - * They are as close as possible to the original functions. - */ - -/** - * @{ - */ - -/** - * Wrapper for [duk_base64_decode](http://duktape.org/api.html#duk_base64_decode). - * - * \param ctx the context - * \param index the index - */ -inline void base64Decode(ContextPtr ctx, Index index) -{ - duk_base64_decode(ctx, index); -} - -/** - * Wrapper for [duk_base64_encode](http://duktape.org/api.html#duk_base64_encode). - * - * \param ctx the context - * \param index the index - * \return the base64 string - */ -inline std::string base64Encode(ContextPtr ctx, Index index) -{ - return duk_base64_encode(ctx, index); -} - -/** - * Wrapper for [duk_call](http://duktape.org/api.html#duk_call). - * - * \param ctx the context - * \param nargs the number of arguments - */ -inline void call(ContextPtr ctx, Index nargs = 0) -{ - duk_call(ctx, nargs); -} - -/** - * Wrapper for [duk_call_method](http://duktape.org/api.html#duk_call_method). - * - * \param ctx the context - * \param nargs the number of arguments - */ -inline void callMethod(ContextPtr ctx, Index nargs = 0) -{ - duk_call_method(ctx, nargs); -} - -/** - * Wrapper for [duk_call_prop](http://duktape.org/api.html#duk_call_prop). - * - * \param ctx the context - * \param index the object index - * \param nargs the number of arguments - */ -inline void callProperty(ContextPtr ctx, Index index, Index nargs = 0) -{ - duk_call_prop(ctx, index, nargs); -} - -/** - * Wrapper for [duk_char_code_at](http://duktape.org/api.html#duk_char_code_at). - * - * \param ctx the context - * \param index the index - * \param charOffset the offset - */ -inline duk_codepoint_t charCodeAt(ContextPtr ctx, Index index, duk_size_t charOffset) -{ - return duk_char_code_at(ctx, index, charOffset); -} - -/** - * Wrapper for [duk_check_stack](http://duktape.org/api.html#duk_check_stack). - * - * \param ctx the context - * \param extra the extra space - * \return true if space is available - */ -inline bool checkStack(ContextPtr ctx, Index extra) -{ - return duk_check_stack(ctx, extra); -} - -/** - * Wrapper for [duk_check_stack_top](http://duktape.org/api.html#duk_check_stack_top). - * - * \param ctx the context - * \param top the extra space - * \return true if space is available - */ -inline bool checkStackTop(ContextPtr ctx, Index top) -{ - return duk_check_stack_top(ctx, top); -} - -/** - * Wrapper for [duk_check_type](http://duktape.org/api.html#duk_check_type). - * - * \param ctx the context - * \param index the value index - * \param type the desired type - * \return true if object is given type - */ -inline bool checkType(ContextPtr ctx, Index index, int type) -{ - return duk_check_type(ctx, index, type); -} - -/** - * Wrapper for [duk_check_type_mask](http://duktape.org/api.html#duk_check_type_mask). - * - * \param ctx the context - * \param index the value index - * \param mask the desired mask - * \return true if object is one of the type - */ -inline bool checkTypeMask(ContextPtr ctx, Index index, unsigned mask) -{ - return duk_check_type_mask(ctx, index, mask); -} - -/** - * Wrapper for [duk_compact](http://duktape.org/api.html#duk_compact). - * - * \param ctx the context - * \param objIndex the object index - */ -inline void compact(ContextPtr ctx, Index objIndex) -{ - duk_compact(ctx, objIndex); -} - -/** - * Wrapper for [duk_concat](http://duktape.org/api.html#duk_concat). - * - * \param ctx the context - * \param count the number of values - */ -inline void concat(ContextPtr ctx, Index count) -{ - duk_concat(ctx, count); -} - -/** - * Wrapper for [duk_copy](http://duktape.org/api.html#duk_copy). - * - * \param ctx the context - * \param from the from index - * \param to the destination - */ -inline void copy(ContextPtr ctx, Index from, Index to) -{ - duk_copy(ctx, from, to); -} - -/** - * Wrapper for [duk_new](http://duktape.org/api.html#duk_new). - * - * \param ctx the context - * \param nargs the number of arguments - */ -inline void create(ContextPtr ctx, int nargs = 0) -{ - duk_new(ctx, nargs); -} - -/** - * Wrapper for [duk_def_prop](http://duktape.org/api.html#duk_def_prop). - * - * \param ctx the context - * \param index the object index - * \param flags the flags - */ -inline void defineProperty(ContextPtr ctx, Index index, unsigned flags) -{ - duk_def_prop(ctx, index, flags); -} - -/** - * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). - * - * \param ctx the context - * \param index the object index - * \return true if deleted - */ -inline bool deleteProperty(ContextPtr ctx, Index index) -{ - return duk_del_prop(ctx, index); -} - -/** - * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). - * - * \param ctx the context - * \param index the object index - * \param position the property index - * \return true if deleted - */ -inline bool deleteProperty(ContextPtr ctx, Index index, unsigned position) -{ - return duk_del_prop_index(ctx, index, position); -} - -/** - * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \return true if deleted - */ -inline bool deleteProperty(ContextPtr ctx, Index index, const std::string &name) -{ - return duk_del_prop_string(ctx, index, name.c_str()); -} - -/** - * Wrapper for [duk_dup](http://duktape.org/api.html#duk_dup). - * - * \param ctx the context - * \param index the value to copy - */ -inline void dup(ContextPtr ctx, int index = -1) -{ - duk_dup(ctx, index); -} - -/** - * Wrapper for [duk_equals](http://duktape.org/api.html#duk_equals). - * - * \param ctx the context - * \param index1 the first value - * \param index2 the second value - * \return true if they equal - */ -inline bool equals(ContextPtr ctx, Index index1, Index index2) -{ - return duk_equals(ctx, index1, index2); -} - -/** - * Wrapper for [duk_eval](http://duktape.org/api.html#duk_eval). - * - * \param ctx the context - */ -inline void eval(ContextPtr ctx) -{ - duk_eval(ctx); -} - -/** - * Wrapper for [duk_eval_file](http://duktape.org/api.html#duk_eval_file). - * - * \param ctx the context - * \param path the path - * \param result true to get the result at the top of the stack - */ -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()); -} - -/** - * Wrapper for [duk_eval_string](http://duktape.org/api.html#duk_eval_string). - * - * \param ctx the context - * \param src the source script - * \param result true to get the result at the top of the stack - */ -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()); -} -/** - * Wrapper for [duk_gc](http://duktape.org/api.html#duk_gc). - * - * \param ctx the context - * \param flags the flags - */ -inline void gc(ContextPtr ctx, unsigned flags = 0) -{ - duk_gc(ctx, flags); -} - -/** - * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). - * - * \param ctx the context - * \param index the object index - * \return true if has - */ -inline bool hasProperty(ContextPtr ctx, Index index) -{ - return duk_has_prop(ctx, index); -} - -/** - * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). - * - * \param ctx the context - * \param index the object index - * \param position the property index - * \return true if has - */ -inline bool hasProperty(ContextPtr ctx, Index index, unsigned position) -{ - return duk_has_prop_index(ctx, index, position); -} - -/** - * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \return true if has - */ -inline bool hasProperty(ContextPtr ctx, int index, const std::string &name) -{ - return duk_has_prop_string(ctx, index, name.c_str()); -} - -/** - * Wrapper for [duk_insert](http://duktape.org/api.html#duk_insert). - * - * \param ctx the context - * \param to the destination - * \note Wrapper of duk_insert - */ -inline void insert(ContextPtr ctx, Index to) -{ - duk_insert(ctx, to); -} - -/** - * Wrapper for [duk_instanceof](http://duktape.org/api.html#duk_instanceof). - * - * \param ctx the context - * \param idx1 the value to test - * \param idx2 the instance requested - * \return true if idx1 is instance of idx2 - */ -inline bool instanceof(ContextPtr ctx, Index idx1, Index idx2) -{ - return duk_instanceof(ctx, idx1, idx2); -} - -/** - * Wrapper for [duk_join](http://duktape.org/api.html#duk_join). - * - * \param ctx the context - * \param count the number of values - */ -inline void join(ContextPtr ctx, Index count) -{ - duk_join(ctx, count); -} - -/** - * Wrapper for [duk_json_decode](http://duktape.org/api.html#duk_json_decode). - * - * \param ctx the context - * \param index the index - */ -inline void jsonDecode(ContextPtr ctx, Index index) -{ - duk_json_decode(ctx, index); -} - -/** - * Wrapper for [duk_json_encode](http://duktape.org/api.html#duk_json_encode). - * - * \param ctx the context - * \param index the index - * \return the JSON string - */ -inline std::string jsonEncode(ContextPtr ctx, Index index) -{ - return duk_json_encode(ctx, index); -} - -/** - * Wrapper for [duk_normalize_index](http://duktape.org/api.html#duk_normalize_index). - * - * \param ctx the context - * \param index the index - */ -inline Index normalizeIndex(ContextPtr ctx, Index index) -{ - return duk_normalize_index(ctx, index); -} - -/** - * Wrapper for [duk_pcall](http://duktape.org/api.html#duk_pcall). - * - * \param ctx the context - * \param nargs the number of arguments - */ -inline int pcall(ContextPtr ctx, Index nargs = 0) -{ - return duk_pcall(ctx, nargs); -} - -/** - * Wrapper for [duk_pcall_method](http://duktape.org/api.html#duk_pcall_method). - * - * \param ctx the context - * \param nargs the number of arguments - */ -inline int pcallMethod(ContextPtr ctx, Index nargs = 0) -{ - return duk_pcall_method(ctx, nargs); -} - -/** - * Wrapper for [duk_pcall_prop](http://duktape.org/api.html#duk_pcall_prop). - * - * \param ctx the context - * \param index the object index - * \param nargs the number of arguments - */ -inline int pcallProperty(ContextPtr ctx, Index index, Index nargs = 0) -{ - return duk_pcall_prop(ctx, index, nargs); -} - -/** - * Wrapper for [duk_peval](http://duktape.org/api.html#duk_peval). - * - * \param ctx the context - */ -inline int peval(ContextPtr ctx) -{ - return duk_peval(ctx); -} - -/** - * Wrapper for [duk_peval_file](http://duktape.org/api.html#duk_peval_file). - * - * \param ctx the context - * \param path the path - * \param result true to get the result at the top of the stack - */ -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()); -} - -/** - * Wrapper for [duk_peval_string](http://duktape.org/api.html#duk_peval_string). - * - * \param ctx the context - * \param src the source script - * \param result true to get the result at the top of the stack - */ -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()); -} - -/** - * Wrapper for [duk_pop_n](http://duktape.org/api.html#duk_pop_n). - * - * \param ctx the context - * \param count the number of values to pop - */ -inline void pop(ContextPtr ctx, Index count = 1) -{ - duk_pop_n(ctx, count); -} - -/** - * Wrapper for [duk_put_prop](http://duktape.org/api.html#duk_put_prop). - * - * \param ctx the context - * \param index the object index - */ -inline void putProperty(ContextPtr ctx, Index index) -{ - duk_put_prop(ctx, index); -} - -/** - * Wrapper for [duk_put_prop_string](http://duktape.org/api.html#duk_put_prop_string). - * - * \param ctx the context - * \param index the object index - * \param name the property name - */ -inline void putProperty(ContextPtr ctx, Index index, const std::string &name) -{ - duk_put_prop_string(ctx, index, name.c_str()); -} - -/** - * Wrapper for [duk_put_prop_index](http://duktape.org/api.html#duk_put_prop_index). - * - * \param ctx the context - * \param index the object index - * \param position the array position - */ -inline void putProperty(ContextPtr ctx, Index index, unsigned position) -{ - duk_put_prop_index(ctx, index, position); -} - -/** - * Wrapper for [duk_remove](http://duktape.org/api.html#duk_remove). - * - * \param ctx the context - * \param index the value to remove - */ -inline void remove(ContextPtr ctx, Index index) -{ - duk_remove(ctx, index); -} - -/** - * Wrapper for [duk_replace](http://duktape.org/api.html#duk_replace). - * - * \param ctx the context - * \param index the value to replace by the value at the top of the stack - */ -inline void replace(ContextPtr ctx, Index index) -{ - duk_replace(ctx, index); -} - -/** - * Wrapper for [duk_set_prototype](http://duktape.org/api.html#duk_set_prototype). - * - * \param ctx the context - * \param index the value index - */ -inline void setPrototype(ContextPtr ctx, Index index) -{ - duk_set_prototype(ctx, index); -} - -/** - * Wrapper for [duk_swap](http://duktape.org/api.html#duk_swap). - * - * \param ctx the context - * \param index1 the first index - * \param index2 the second index - */ -inline void swap(ContextPtr ctx, Index index1, Index index2) -{ - duk_swap(ctx, index1, index2); -} - -/** - * Wrapper for [duk_swap_top](http://duktape.org/api.html#duk_swap_top). - * - * \param ctx the context - * \param index the index - */ -inline void swapTop(ContextPtr ctx, Index index) -{ - duk_swap_top(ctx, index); -} - -/** - * Wrapper for [duk_get_top](http://duktape.org/api.html#duk_get_top). - * - * \param ctx the context - * \return the stack size - */ -inline int top(ContextPtr ctx) -{ - return duk_get_top(ctx); -} - -/** - * Wrapper for [duk_throw](http://duktape.org/api.html#duk_throw). - * - * \param ctx the context - */ -inline void raise(ContextPtr ctx) -{ - duk_throw(ctx); -} - -/** - *Wrapper for [duk_error](http://duktape.org/api.html#duk_error). - * - * \param ctx the context - * \param type the error type (e.g. DUK_ERR_REFERENCE_ERROR) - * \param fmt the format string - * \param args the arguments - */ -template <typename... Args> -inline void raise(ContextPtr ctx, int type, const char *fmt, Args&&... args) -{ - duk_error(ctx, type, fmt, std::forward<Args>(args)...); -} - -/** - * Wrapper for [duk_get_type](http://duktape.org/api.html#duk_get_type). - * - * \param ctx the context - * \param index the idnex - * \return the type - */ -inline int type(ContextPtr ctx, Index index) -{ - return duk_get_type(ctx, index); -} - -/** - * @} - */ - -/** - * @name Extended functions - * \brief Extended functions for libjs. - * - * The following functions are largely modified or extensions to Duktape. - */ - -/** - * @{ - */ - -/** - * Get the error object when a JavaScript error has been thrown (e.g. eval failure). - * - * \param ctx the context - * \param index the index - * \return the information - */ -inline Exception exception(ContextPtr ctx, int index) -{ - Exception ex; - StackAssert sa(ctx); - - 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); - - return ex; -} - -/** - * Push a value into the stack. Calls TypeTraits<T>::push(ctx, value); - * - * \param ctx the context - * \param value the value to forward - */ -template <typename Type> -inline void push(ContextPtr ctx, Type &&value) -{ - TypeTraits<std::decay_t<Type>>::push(ctx, std::forward<Type>(value)); -} - -/** - * Put the value to the object at the top of the stack. Calls TypeTraits<T>::put(ctx, value); - * - * \param ctx the context - * \param value the value to apply - */ -template <typename Type> -inline void put(ContextPtr ctx, Type &&value) -{ - TypeTraits<std::decay_t<Type>>::put(ctx, std::forward<Type>(value)); -} - -/** - * Generic template function to get a value from the stack. - * - * \param ctx the context - * \param index the index - * \return the value - */ -template <typename Type> -inline auto get(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::get(ctx, 0)) -{ - return TypeTraits<Type>::get(ctx, index); -} - -/** - * Require a type at the specified index. - * - * \param ctx the context - * \param index the index - * \return the value - */ -template <typename Type> -inline auto require(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::require(ctx, 0)) -{ - return TypeTraits<Type>::require(ctx, index); -} - -/** - * Check if a value is a type of T. - * - * The TypeTraits<T> must have `static bool is(ContextPtr ptr, int index)`. - * - * \param ctx the context - * \param index the value index - * \return true if is the type - */ -template <typename T> -inline bool is(ContextPtr ctx, int index) -{ - return TypeTraits<T>::is(ctx, index); -} - -/** - * Get an optional value from the stack, if the value is not available of not the correct type, - * return defaultValue instead. - * - * The TypeTraits<T> must have `static T optional(Context &, int index, T &&defaultValue)`. - * - * \param ctx the context - * \param index the value index - * \param defaultValue the value replacement - * \return the value or defaultValue - */ -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)); -} - -/** - * Get the property `name' as value from the object at the specified index. - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \return the value - * \note The stack is unchanged - */ -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); - - return value; -} - -/** - * Get a property by index, for arrays. - * - * \param ctx the context - * \param index the object index - * \param position the position int the object - * \return the value - * \note The stack is unchanged - */ -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); - - return value; -} - -/** - * Get the property `name' and push it to the stack from the object at the specified index. - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \note The stack contains the property value - */ -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()); -} - -/** - * Get the property by index and push it to the stack from the object at the specified index. - * - * \param ctx the context - * \param index the object index - * \param position the position in the object - * \note The stack contains the property value - */ -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); -} - -/** - * Get an optional property `name` from the object at the specified index. - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \param def the default value - * \return the value or def - * \note The stack is unchanged - */ -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); - - return value; -} - -/** - * Get an optional property by index, for arrays - * - * \param ctx the context - * \param index the object index - * \param position the position int the object - * \param def the default value - * \return the value or def - * \note The stack is unchanged - */ -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); - - return value; -} - -/** - * Set a property to the object at the specified index. - * - * \param ctx the context - * \param index the object index - * \param name the property name - * \param value the value to forward - * \note The stack is unchanged - */ -template <typename Type> -void putProperty(ContextPtr ctx, int index, const std::string &name, Type &&value) -{ - index = duk_normalize_index(ctx, index); - - push(ctx, std::forward<Type>(value)); - duk_put_prop_string(ctx, index, name.c_str()); -} - -/** - * Set a property by index, for arrays. - * - * \param ctx the context - * \param index the object index - * \param position the position in the object - * \param value the value to forward - * \note The stack is unchanged - */ -template <typename Type> -void putProperty(ContextPtr ctx, int index, int position, Type &&value) -{ - index = duk_normalize_index(ctx, index); - - push(ctx, std::forward<Type>(value)); - duk_put_prop_index(ctx, index, position); -} - -/** - * Get a global value. - * - * \param ctx the context - * \param name the name of the global variable - * \return the value - */ -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); - - return value; -} - -/** - * Overload that push the value at the top of the stack instead of returning it. - */ -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()); -} - -/** - * Set a global variable. - * - * \param ctx the context - * \param name the name of the global variable - * \param type the value to set - */ -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()); -} - -/** - * Put the value at the top of the stack as global property. - * - * \param ctx the context - * \param name the property name - */ -inline void putGlobal(ContextPtr ctx, const std::string &name) -{ - duk_put_global_string(ctx, name.c_str()); -} - -/** - * Enumerate an object or an array at the specified index. - * - * \param ctx the context - * \param index the object or array index - * \param flags the optional flags to pass to duk_enum - * \param getvalue set to true if you want to extract the value - * \param func the function to call for each properties - */ -template <typename Func> -void enumerate(ContextPtr ctx, int index, duk_uint_t flags, duk_bool_t getvalue, Func &&func) -{ - duk_enum(ctx, index, flags); - - while (duk_next(ctx, -1, getvalue)) { - func(ctx); - duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); - } - - duk_pop(ctx); -} - -/** - * Return the this binding of the current function. - * - * \param ctx the context - * \return the this binding as the template given - */ -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); - - return value; -} - -/** - * Throw an ECMAScript exception. - * - * \param ctx the context - * \param ex the exception - */ -template <typename Exception> -void raise(ContextPtr ctx, const Exception &ex) -{ - ex.raise(ctx); -} - -/** - * Construct the object in place, setting value as this binding. - * - * The TypeTraits<T> must have the following requirements: - * - * - static void construct(Context &, T): must update this with the value and keep the stack unchanged - * - * \param ctx the context - * \param value the value to forward - * \see self - */ -template <typename T> -inline void construct(ContextPtr ctx, T &&value) -{ - TypeTraits<std::decay_t<T>>::construct(ctx, std::forward<T>(value)); -} - -/** - * @} - */ - -/** - * \class Error - * \brief Base ECMAScript error class. - * \warning Override the function create for your own exceptions - */ -class Error { -private: - 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)) - { - } - -public: - /** - * 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()); - } -}; - -/** - * \class EvalError - * \brief Error in eval() function. - */ -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)) - { - } -}; - -/** - * \class RangeError - * \brief Value is out of range. - */ -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)) - { - } -}; - -/** - * \class ReferenceError - * \brief Trying to use a variable that does not exist. - */ -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)) - { - } -}; - -/** - * \class SyntaxError - * \brief Syntax error in the script. - */ -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)) - { - } -}; - -/** - * \class TypeError - * \brief Invalid type given. - */ -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)) - { - } -}; - -/** - * \class URIError - * \brief URI manipulation failure. - */ -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)) - { - } -}; - -/* ------------------------------------------------------------------ - * Standard overloads for TypeTraits<T> - * ------------------------------------------------------------------ */ - -/** - * \class TypeTraits<int> - * \brief Default implementation for int. - * - * Provides: get, is, optional, push, require. - */ -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); - } - - /** - * 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; - } - - /** - * 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); - } -}; - -/** - * \class TypeTraits<bool> - * \brief Default implementation for bool. - * - * Provides: get, is, optional, push, require. - */ -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); - } - - /** - * 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; - } - - /** - * 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); - } -}; - -/** - * \class TypeTraits<double> - * \brief Default implementation for double. - * - * Provides: get, is, optional, push, require. - */ -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); - } - - /** - * 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; - } - - /** - * 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); - } -}; - -/** - * \class TypeTraits<std::string> - * \brief Default implementation for std::string. - * - * Provides: get, is, optional, push, require. - * - * Note: the functions allows embedded '\0'. - */ -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); - - 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); - } - - /** - * 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()); - } - - /** - * 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}; - } -}; - -/** - * \class TypeTraits<const char *> - * \brief Default implementation for const char literals. - * - * Provides: get, is, optional, push, require. - */ -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); - } - - /** - * 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; - } - - /** - * 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); - } -}; - -/** - * \class TypeTraits<unsigned> - * \brief Default implementation for unsigned. - * - * Provides: get, is, optional, push, require. - */ -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); - } - - /** - * 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; - } - - /** - * 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); - } -}; - -/** - * \brief Implementation for non-managed pointers. - * - * Provides: get, is, optional, push, require. - */ -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)); - } - - /** - * 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; - } - - /** - * 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)); - } -}; - -/** - * \class TypeTraits<Function> - * \brief Push C++ function to the stack. - * - * Provides: push. - * - * This implementation push a Duktape/C function that is wrapped as C++ for convenience. - */ -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); - } - - /** - * 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); - } -}; - -/** - * \class TypeTraits<FunctionMap> - * \brief Put the functions to the object at the top of the stack. - * - * Provides: put. - */ -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); - - 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()); - } - } -}; - -/** - * \class TypeTraits<Object> - * \brief Push empty object to the stack. - * - * Provides: is, push. - */ -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); - } - - /** - * Create an empty object on the stack. - * - * \param ctx the context - */ - static inline void push(ContextPtr ctx, const Object &) - { - duk_push_object(ctx); - } -}; - -/** - * \class TypeTraits<Array> - * \brief Push empty array to the stack. - * - * Provides: is, push. - */ -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); - } - - /** - * Create an empty array on the stack. - * - * \param ctx the context - */ - static inline void push(ContextPtr ctx, const Array &) - { - duk_push_array(ctx); - } -}; - -/** - * \class TypeTraits<Undefined> - * \brief Push undefined value to the stack. - * - * Provides: is, push. - */ -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); - } - - /** - * Push undefined value on the stack. - * - * \param ctx the context - */ - static inline void push(ContextPtr ctx, const Undefined &) - { - duk_push_undefined(ctx); - } -}; - -/** - * \class TypeTraits<Null> - * \brief Push null value to the stack. - * - * Provides: is, push. - */ -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); - } - - /** - * Push null value on the stack. - * - * \param ctx the context - */ - static inline void push(ContextPtr ctx, const Null &) - { - duk_push_null(ctx); - } -}; - -/** - * \brief Push this binding into the stack. - * - * Provides: push. - */ -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); - } -}; - -/** - * \class TypeTraits<Global> - * \brief Push the global object to the stack. - * - * Provides: push. - */ -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); - } -}; - -/** - * \brief Push a map of key-value pair as objects. - * - * Provides: push, put. - * - * This class is convenient for settings constants such as enums, string and such. - */ -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); - - 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); - - StackAssert sa(ctx); - - for (const auto &pair : map) { - TypeTraits<T>::push(ctx, pair.second); - duk_put_prop_string(ctx, -2, pair.first.c_str()); - } - } -}; - -/** - * \brief Push or get vectors as JavaScript arrays. - * - * Provides: get, push, put. - */ -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); - - std::vector<T> result; - - if (!duk_is_array(ctx, -1)) - return result; - - int total = duk_get_length(ctx, index); - - for (int i = 0; i < total; ++i) - result.push_back(getProperty<T>(ctx, index, i)); - - 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); - - 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); - - StackAssert sa(ctx); - - unsigned i = 0; - for (const auto &v : array) { - TypeTraits<T>::push(ctx, v); - duk_put_prop_index(ctx, -2, i++); - } - } -}; - -/** - * \brief Implementation of managed std::shared_ptr<T>. - * - * This specialization requires T to be @ref js-concept-class. - */ -template <typename T> -class TypeTraits<std::shared_ptr<T>> { -private: - 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"); - - 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"); - - StackAssert sa(ctx, 0); - - 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"); - - StackAssert sa(ctx, 1); - - 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"); - - StackAssert sa(ctx); - - auto ptr = getProperty<std::shared_ptr<Bindable> *>(ctx, index, "\xff""\xff""js-shared-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"); - - auto ptr = get(ctx, index); - - if (!ptr) - duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid this binding"); - - return ptr; - } -}; - -} // !duk - -} // !malikania - -#endif // !JS_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/js.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,3103 @@ +/* + * js.hpp -- JavaScript C++14 wrapper for Duktape + * + * Copyright (c) 2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JS_HPP +#define MALIKANIA_JS_HPP + +/** + * \file js.hpp + * \brief Bring JavaScript using Duktape. + * + * This file provides usual Duktape function renamed and placed into `duk` namespace. It also replaces error + * code with exceptions when possible. + * + * For convenience, this file also provides templated functions, overloads and much more. + */ + +/** + * \page js JavaScript binding + * \brief JavaScript binding using Duktape + * + * This page will show you how to setup this module to host JavaScript environment into your C++ application. + * + * ## Duktape + * + * Duktape is a C library designed for performance, small footprint and conformance. This wrapper is built top of it and + * requires it at build and runtime. + * + * It is highly recommended that you read the [Duktape guide](http://duktape.org/guide.html) before continuing because + * a lot of concepts are kept as-is. + * + * ## Installation + * + * You need the Duktape source amalgamation, it is provided with this module. + * + * When compiling, be sure to enable `-DDUK_OPT_CPP_EXCEPTIONS` and that Duktape source file has **cpp** extension. + * + * Just copy the **js.hpp** file and include it into your project. The header depends on **duktape.h** so be sure to + * provide it when compiling. + * + * @subpage js-init + * @subpage js-types + * @subpage js-basics + * @subpage js-more + * @subpage js-concepts + */ + +/** + * \page js-init Initialization + * \brief Context initialization. + * + * To host JavaScript, you need a context. Usually one is sufficient but you can create as many as you want but they + * won't share any resource. + * + * @code + * #include "js.hpp" + * + * int main() + * { + * duk::Context ctx; + * + * return 0; + * } + * @endcode + * + * The duk::Context class is a RAII based wrapper around the native duk_context structure. It is automatically created + * and closed in the destructor. + * + * Be sure to not keep any pointer to it. + */ + +/** + * \page js-types Predefined types + * \brief Default duk::TypeTraits specializations + * + * The following specializations are provided with libjs. + * + * ## Primitive types + * + * | Type | Support | Remarks | + * |----------------|----------------------------------|---------------------------------------| + * | `int` | get, is, optional, push, require | | + * | `bool` | get, is, optional, push, require | | + * | `double` | get, is, optional, push, require | | + * | `std::string` | get, is, optional, push, require | can contain '\0' and binary data | + * | `const char *` | get, is, optional, push, require | | + * | `unsigned` | get, is, optional, push, require | | + * | T * | get, is, optional, push, require | raw pointer, never deleted by Duktape | + * + * ## Special JavaScript types + * + * The following types are used to create or inspect JavaScript types. + * + * | Type | Support | Remarks | + * |------------------|----------|----------------------------------------| + * | duk::Array | is, push | | + * | duk::Function | is, push | is just check if the value is callable | + * | duk::FunctionMap | put | | + * | duk::Global | push | | + * | duk::Null | is, push | | + * | duk::Object | is, push | | + * | duk::This | push | | + * | duk::Undefined | is, push | | + * + * ## Partial specializations + * + * These partial specializations will use complete specialization for T. + * + * | Type | Support | Remarks | + * |------------------------------------|-----------|------------------------| + * | std::unordered_map<std::string, T> | push, put | push or put properties | + * | std::vector<T> | push, put | push array of values | + * + * ## Special types + * + * These types are used to export C++ object to JavaScript. See @ref js-more-t2 for more explanations and + * @ref js-concept-class. + * + * | Type | Support | Remarks | + * |--------------------|-----------------------------------------|--------------------------------| + * | std::shared_ptr<T> | construct, get, optional, push, require | T must have Class requirements | + */ + +/** + * \page js-basics Basics + * \brief Basics use case. + * + * The following topics are sample use case of the C++ front end. It does not use extended features that this module + * provides. + * + * @subpage js-basics-t1 + * @subpage js-basics-t2 + * @subpage js-basics-t3 + */ + +/** + * \page js-basics-t1 Example 1: call JavaScript code from C++ + * \brief Evaluate JavaScript code from C++. + * + * Let use JavaScript to compute a simple expression. + * + * @code + * #include "js.hpp" + * + * int main() + * { + * duk::Context ctx; + * + * duk::pevalString(ctx, "1 + 1"); + * std::cout << duk::get<int>(ctx -1) << std::endl; + * + * return 0; + * } + * @endcode + */ + +/** + * \page js-basics-t2 Example 2: call C++ code from JavaScript + * \brief Evaluate a function from JavaScript. + * + * In that example, we will add a C++ function to JavaScript and call it from the script. The function just compute the + * two arguments that are passed through the function and return the result. + * + * We take the benefits of C++11 to map the function. The lambda can not have a capture because Duktape use raw C + * function pointers and this module keep them. + * + * @code + * #include "js.hpp" + * + * int main() + * { + * duk::Context ctx; + * + * // Push a function as global "add" + * duk::putGlobal(ctx, "add", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { + * int x = duk::require<int>(ctx, 0); + * int y = duk::require<int>(ctx, 1); + * + * duk::push(ctx, x + y); + * + * return 1; + * }, 2}); + * + * // Evaluate from JavaScript + * duk::pevalString(ctx, "add(1, 2)"); + * + * return 0; + * } + * @endcode + * + * Please note the **2** at end of lambda which indicates that the function takes 2 arguments. If number of arguments + * is variadic, pass DUK_VARARGS there. + */ + +/** + * \page js-basics-t3 Example 3: pushing and getting values + * \brief Manage values between JavaScript and C++. + * + * As you have seen in the previous examples, we were pushing some values to the Duktape context. + * + * With the C Duktape frontend, you usually use duk_push_int, duk_push_string and all other related functions. The libjs + * module provides an uniform and convenient way for sharing values with the same functions. + * + * See the description of duk::TypeTraits to see the supported types. + * + * ## Push + * + * The duk::push function is a template that accept most of the primitives types. It uses the specializations of the + * duk::TypeTraits class (described later). + * + * Example of code + * + * @code + * duk::push(ctx, 123); // an integer + * duk::push(ctx, true); // a boolean + * @endcode + * + * The push function add a new value to the stack for any specialization of TypeTraits provided by libjs. + * + * ## Get + * + * The duk::get function is similar to duk_get_ functions. It usually does not check the value and return a sane default + * value. + * + * This template function does not take the template argument so it can't be deduced and must be specified explicitly. + * + * @code + * duk::get<int>(ctx, 0) // get an int at index 0 + * duk::get<std::string>(ctx, 1) // get a std::string at index 1 + * @endcode + * + * ## Require + * + * The duk::require function is similar to duk_require functions. It requires the exact type at the given index. If the + * value is invalid a JavaScript error is propagated. + * + * @code + * duk::require<int>(ctx, 0) // require an int at index 0 or raise an error + * @endcode + * + * ## Put + * + * This special function is similar to push except that it applies to the existing object at the top of the stack. It + * is usually implemented for map and vector. + * + * @code + * // Fill the object at the top of the stack with this map + * std:unordered_map<std::string, int> map{ + * { "value1", 1 }, + * { "value2", 2 } + * }; + * + * duk::put(ctx, map); + * @endcode + * + * ## Is + * + * This function duk::is checks if the value at the given index is of the given type and return true. + * + * Just like duk::get, this function need the explicit template parameter. + * + * @code + * duk::push(ctx, 1); + * duk::is<int>(ctx, -1); // true + * @endcode + * + * ## Optional + * + * The duk::optional function has no equivalent in Duktape C API. It is a convenient way to get values with a default + * replacement is not available. + * + * The common implementation uses duk::is and then duk::get. + * + * @code + * duk::optional<int>(ctx, -1, 123); // 123 is -1 has no value or is not an int + * @endcode + */ + +/** + * \page js-more Extensions and advanced features. + * \brief Evolved extensions provided by libjs. + * + * The following topics are provided by libjs and have no equivalent in Duktape C API. + * + * @subpage js-more-t1 + * @subpage js-more-t2 + */ + +/** + * \page js-more-t1 Advanced 1: adding your own types to TypeTraits + * \brief How to specialize duk::TypeTraits structure. + * + * This topic shows how you can specialize the duk::TypeTraits structure to add more types. + * + * Specializing the duk::TypeTraits is usually only needed when you want to convert a C++ object into JavaScript, for + * exporting a C++ class, see @ref js-more-t2. + * + * In this example we will convert a C++ small structure containing two integers to JavaScript. + * + * \note It is not required to implement all functions from duk::TypeTraits. Just provide which one you need. + * + * ## The C++ structure + * + * The point does not have any methods, it just a description of two integers. + * + * @code + * struct Point { + * int x; + * int y; + * }; + * @endcode + * + * ## The push function + * + * Let's add a push function that will create a JavaScript object with **x** and **y** properties. + * + * @code + * namespace duk { + * + * template <> + * class TypeTraits<Point> { + * public: + * static void push(ContextPtr ctx, const Point &point) + * { + * // Create an object + * push(ctx, Object()); + * + * // Set x + * putProperty(ctx, -1, "x", point.x); + * + * // Set y + * putProperty(ctx, -1, "y", point.y); + * } + * }; + * + * } + * @endcode + * + * You can safely use different type of reference as second argument. + * + * That's it, you can now safely invoke `duk::push(ctx, Point{100, 200});`. + * + * ## The get function + * + * The get function usually return a new object. The recommandation is to provide sane defaults except if you have any + * reason to not do so. + * + * @code + * namespace duk { + * + * template <> + * class TypeTraits<Point> { + * public: + * static Point get(ContextPtr ctx, Index index) + * { + * Point point{0, 0}; + * + * if (is<Object>(ctx, index)) { + * point.x = getProperty<int>(ctx, index, "x"); + * point.y = getProperty<int>(ctx, index, "y"); + * } + * + * return point; + * } + * }; + * + * } + * @endcode + * + * Now you can invoke `duk::get<Point>(ctx, 0)` to convert a JavaScript object to the Point structure. + * + * ## The require function + * + * The require function has the same signature as get. It's up to you to decide which criterias makes the object not + * suitable for conversion. + * + * In that example, we will require that object at the index is a JavaScript object and that **x**, **y** are present. + * + * @code + * namespace duk { + * + * template <> + * class TypeTraits<Point> { + * public: + * static Point require(ContextPtr ctx, Index index) + * { + * Point point; + * + * // Raise an error if not object + * if (!is<Object>(ctx, index)) + * duk::raise(ctx, TypeError("object required")); + * + * // Get x, for simplicity we just check that x and y exist. + * if (!hasProperty(ctx, index, "x")) + * duk::raise(ctx, TypeError("property x missing")); + * + * // Get y + * if (!hasProperty(ctx, index, "y")) + * duk::raise(ctx, TypeError("property y missing")); + * + * // Note: if you need more security, check that types are integers too. + * point.x = duk::getProperty<int>(ctx, index, "x"); + * point.y = duk::getProperty<int>(ctx, index, "y"); + * + * return point; + * } + * }; + * + * } + * @endcode + * + * ## The is function + * + * The is function returns a boolean. Again, you decide when the value is appropriate. + * + * @code + * + * namespace duk { + * + * template <> + * class TypeTraits<Point> { + * public: + * static bool is(ContextPtr ctx, Index index) + * { + * return is<Object>(ctx, index) && hasProperty(ctx, index, "x") && hasProperty(ctx, index, "y"); + * } + * }; + * + * } + * + * @endcode + * + * ## The optional function + * + * The optional function is like get, you should return a value when it is appropriate for conversion. The + * recommandation is to return the default value **only if** there is no value at the given index or it it not + * the correct type. + * + * Usual implementation looks like this: + * + * @code + * namespace duk { + * + * template <> + * class TypeTraits<Point> { + * public: + * static Point optional(ContextPtr ctx, Index index, Point def) + * { + * return is(ctx, index) ? get(ctx, index) : def; + * } + * }; + * + * } + * @endcode + */ + +/** + * \page js-more-t2 Advanced 2: exporting C++ class + * \brief How to export a C++ class through Duktape. + * + * This example shows how you can implement a C++ class and export it through C++ through the predefined + * std::shared_ptr duk::TypeTraits specialization. + * + * There are several steps to accomplish this and you must be familiar on how object oriented works in JavaScript. + * + * See this [introduction to OO in JavaScript][oojs]. + * + * \note [RTTI] is required in order to make typesafe binding. + * + * ## Ownership + * + * To facilitate communication between C++ and JavaScript, objects must be instanciated as `std::shared_ptr`. It + * guarantees polymorphic objects and ownership. + * + * ## The C++ class + * + * In that topic, we will implement a basic Car class that has only one drive function, the class must derive from duk::Bindable. + * + * @code + * #include <iostream> + * + * #include "js.hpp" + * + * class Car : public duk::Binding { + * public: + * void drive() + * { + * std::cout << "Driving the car..." << std::endl; + * } + * }; + * @endcode + * + * ## The JavaScript methods + * + * This is the drive method, put it in a map. The method does not take any argument so pass 0. + * + * @code + * duk::Ret drive(duk::ContextPtr ctx) + * { + * duk::self<std::shared_ptr<Car>>(ctx)->drive(); + * + * return 0; + * } + * + * const duk::FunctionMap methods{ + * { "drive", { drive, 0 } } + * }; + * @endcode + * + * ## Construction + * + * There are two ways to export a C++ object to JavaScript. + * + * 1. When constructed from the JavaScript new operator. You must provide a C function and use duk::construct to + * apply your object to it. + * + * 2. When pusing from C++ to JavaScript. You muse use Using duk::push and you will need to implement the `prototype` + * function in duk::TypeTraits (see below). + * + * ## Example 1: provide a constructor for JavaScript ownership + * + * This example provides a function to let the user constructing the object **from** JavaScript. + * + * ### Add a constructor + * + * Add the constructor that will be called from C++. + * + * @code + * duk::Ret constructor(duk::ContextPtr ctx) + * { + * duk::construct(ctx, std::make_shared<Car>()); + * + * return 0; + * } + * @endcode + * + * ### Main + * + * We register the constructor, add a prototype and call it from JavaScript. + * + * @code + * int main() + * { + * duk::Context ctx; + * + * // Push the Car constructor function + * duk::push(ctx, duk::Function{constructor}); + * + * // Push the methods as a new object and set it as the .prototype property + * duk::putProperty(ctx, -1, "prototype", methods); + * + * // Now store the Car function + * duk::putGlobal(ctx, "Car"); + * + * // Create a Car from JavaScript + * duk::pevalString(ctx, + * "c = new Car();" + * "c.drive();" + * ); + * + * return 0; + * } + * @endcode + * + * ## Example 2: the object is created from C++ + * + * This example allocates the Car object from C++ and pass it through JavaScript. It requires to implement the + * prototype function from duk::TypeTraits. + * + * ### Prototype function + * + * This function must push into the stack the prototype for the given object. You are free to store it where you want, + * here, we set it as internal global property. + * + * @code + * namespace duk { + * + * template <> + * class TypeTraits<Car> { + * public: + * static inline void prototype(ContextPtr ctx) + * { + * getGlobal<void>(ctx, "\xff""\xff""Car-prototype"); + * } + * }; + * + * } + * @endcode + * + * ### Main + * + * Now save this prototype and create the object from C++. + * + * @code + * int main() + * { + * duk::Context ctx; + * + * // Create a prototype directly from the methods table (from example 1) + * duk::putGlobal(ctx, "\xff""\xff""Car-prototype", methods); + * + * // Put a global Car object + * duk::putGlobal(ctx, "car", std::make_shared<Car>()); + * + * // Call the JavaScript code + * duk::pevalString(ctx, "car.drive();"); + * } + * @endcode + * + * [oojs]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript + * [RTTI]: https://en.wikipedia.org/wiki/Run-time_type_information + */ + +/** + * \page js-concepts Concepts + * + * @subpage js-concept-class + */ + +/** + * \page js-concept-class Class (Concept) + * \brief This concept is used when exporting C++ class through JavaScript. + * + * When using `std::shared_ptr<T>` with duk::TypeTraits, the user must implement some function by specializing + * duk::TypeTraits<T>. + * + * ## Public static member functions + * + * ### Prototype (optional) + * + * The prototype function is optional, it is only required when exporting the C++ object using duk::push. It must push + * the prototype of your object at the top of the stack. + * + * @code + * static void prototype(duk::ContextPtr ctx); + * @endcode + */ + +#include <cassert> +#include <functional> +#include <memory> +#include <string> +#include <type_traits> +#include <unordered_map> +#include <utility> +#include <vector> + +#include <duktape.h> + +namespace malikania { + +/** + * Duktape C++ namespace wrapper. + */ +namespace duk { + +class Context; + +/** + * \brief Typedef without pointer. + */ +using ContextPtr = duk_context *; + +/** + * \brief Typedef for duk_double_t. + */ +using Double = duk_double_t; + +/** + * \brief Typedef for duk_idx_t. + */ +using Index = duk_idx_t; + +/** + * \brief Typedef for duk_ret_t. + */ +using Ret = duk_ret_t; + +/** + * \brief Typedef for duk_int_t. + */ +using Int = duk_int_t; + +/** + * \brief Typedef for duk_uint_t; + */ +using Uint = duk_uint_t; + +/** + * \class StackAssert + * \brief Stack sanity checker. + * + * Instanciate this class where you need to manipulate the Duktape stack outside a Duktape/C function, its destructor + * will examinate if the stack size matches the user expected size. + * + * When compiled with NDEBUG, this class does nothing. + * + * To use it, just declare an lvalue at the beginning of your function. + */ +class StackAssert { +#if !defined(NDEBUG) +private: + 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 +#if !defined(NDEBUG) + : m_context(ctx) + , m_expected(expected) + , m_begin(static_cast<unsigned>(duk_get_top(ctx))) +#endif + { +#if defined(NDEBUG) + (void)ctx; + (void)expected; +#endif + } + + /** + * 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); +#endif + } +}; + +/** + * \brief Inherit this class to make type safe C++ objects into JavaScript + */ +class Bindable { +public: + /** + * Default constructor + */ + Bindable() = default; + + /** + * Default destructor. + */ + virtual ~Bindable() = default; +}; + +/** + * \class TypeTraits + * \brief Type information to implement new types in JavaScript's context. + * + * %This class depending on your needs may have the following functions: + * + * ## Construct + * + * Used by duk::construct, the function must place the value as this binding when the Duktape C function is + * new-constructed. + * + * @code + * static void construct(ContextPtr ctx, Type value); + * @endcode + * + * ## Get + * + * Convert the value at the given index and return it. Should return default object if value is invalid. + * + * @code + * static Type get(ContextPtr ctx, int index); + * @endcode + * + * ## Is + * + * Tells if the value at given index is of the requested type. + * + * @code + * static bool is(ContextPtr ctx, int index); + * @endcode + * + * ## Optional + * + * Get the value at the given index or return the defaultValue. + * + * @code + * static Type optional(ContextPtr ctx, int index, Type defaultValue); + * @endcode + * + * ## Push + * + * Push the value into the stack. + * + * @code + * static void push(ContextPtr ctx, Type value); + * @endcode + * + * ## Put + * + * Apply the value to the object at the top of the stack. + * + * @code + * static void put(ContextPtr ctx, Type value); + * @endcode + * + * ## Require + * + * Require a value at the given index. + * + * @code + * static Type require(ContextPtr ctx, int index); + * @endcode + * + */ +template <typename Type> +class TypeTraits; + +/** + * \class Object + * \brief Special type for duk::TypeTraits. + */ +class Object { +}; + +/** + * \class Array + * \brief Special type for duk::TypeTraits. + */ +class Array { +}; + +/** + * \class Global + * \brief Special type for duk::TypeTraits. + */ +class Global { +}; + +/** + * \class Undefined + * \brief Special type for duk::TypeTraits. + */ +class Undefined { +}; + +/** + * \class Null + * \brief Special type for duk::TypeTraits. + */ +class Null { +}; + +/** + * \class This + * \brief Special type for duk::TypeTraits. + */ +class This { +}; + +/** + * \class Function + * \brief Duktape/C function definition. + * + * This class wraps the std::function as a Duktape/C function by storing a copied pointer. + */ +class Function { +public: + /** + * The function pointer, must not be null. + */ + duk_c_function function; + + /** + * Number of args that the function takes + */ + duk_idx_t nargs{0}; +}; + +/** + * \brief Map of functions. + */ +using FunctionMap = std::unordered_map<std::string, Function>; + +/** + * \brief Map of any type. + */ +template <typename T> +using Map = std::unordered_map<std::string, T>; + +/** + * \class Exception + * \brief Error description. + * + * This class fills the fields got in an Error object. + */ +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 + + /** + * Get the error message. This effectively returns message field. + * + * \return the message + */ + const char *what() const noexcept override + { + return message.c_str(); + } +}; + +/** + * \class Context + * \brief RAII based Duktape handler. + * + * This class is implicitly convertible to duk_context for convenience. + */ +class Context { +private: + using Deleter = void (*)(duk_context *); + using Handle = std::unique_ptr<duk_context, Deleter>; + + Handle m_handle; + + Context(const Context &) = delete; + Context &operator=(const Context &) = delete; + +public: + /** + * Create default context. + */ + inline Context() + : m_handle(duk_create_heap_default(), duk_destroy_heap) + { + } + + /** + * 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 *() const noexcept + { + return m_handle.get(); + } + + /** + * Default move assignment operator. + */ + Context &operator=(Context &&) noexcept = delete; +}; + +/** + * @name Duktape C functions + * \brief The following functions are wrappers on top of the Duktape C functions. + * + * They are as close as possible to the original functions. + */ + +/** + * @{ + */ + +/** + * Wrapper for [duk_base64_decode](http://duktape.org/api.html#duk_base64_decode). + * + * \param ctx the context + * \param index the index + */ +inline void base64Decode(ContextPtr ctx, Index index) +{ + duk_base64_decode(ctx, index); +} + +/** + * Wrapper for [duk_base64_encode](http://duktape.org/api.html#duk_base64_encode). + * + * \param ctx the context + * \param index the index + * \return the base64 string + */ +inline std::string base64Encode(ContextPtr ctx, Index index) +{ + return duk_base64_encode(ctx, index); +} + +/** + * Wrapper for [duk_call](http://duktape.org/api.html#duk_call). + * + * \param ctx the context + * \param nargs the number of arguments + */ +inline void call(ContextPtr ctx, Index nargs = 0) +{ + duk_call(ctx, nargs); +} + +/** + * Wrapper for [duk_call_method](http://duktape.org/api.html#duk_call_method). + * + * \param ctx the context + * \param nargs the number of arguments + */ +inline void callMethod(ContextPtr ctx, Index nargs = 0) +{ + duk_call_method(ctx, nargs); +} + +/** + * Wrapper for [duk_call_prop](http://duktape.org/api.html#duk_call_prop). + * + * \param ctx the context + * \param index the object index + * \param nargs the number of arguments + */ +inline void callProperty(ContextPtr ctx, Index index, Index nargs = 0) +{ + duk_call_prop(ctx, index, nargs); +} + +/** + * Wrapper for [duk_char_code_at](http://duktape.org/api.html#duk_char_code_at). + * + * \param ctx the context + * \param index the index + * \param charOffset the offset + */ +inline duk_codepoint_t charCodeAt(ContextPtr ctx, Index index, duk_size_t charOffset) +{ + return duk_char_code_at(ctx, index, charOffset); +} + +/** + * Wrapper for [duk_check_stack](http://duktape.org/api.html#duk_check_stack). + * + * \param ctx the context + * \param extra the extra space + * \return true if space is available + */ +inline bool checkStack(ContextPtr ctx, Index extra) +{ + return duk_check_stack(ctx, extra); +} + +/** + * Wrapper for [duk_check_stack_top](http://duktape.org/api.html#duk_check_stack_top). + * + * \param ctx the context + * \param top the extra space + * \return true if space is available + */ +inline bool checkStackTop(ContextPtr ctx, Index top) +{ + return duk_check_stack_top(ctx, top); +} + +/** + * Wrapper for [duk_check_type](http://duktape.org/api.html#duk_check_type). + * + * \param ctx the context + * \param index the value index + * \param type the desired type + * \return true if object is given type + */ +inline bool checkType(ContextPtr ctx, Index index, int type) +{ + return duk_check_type(ctx, index, type); +} + +/** + * Wrapper for [duk_check_type_mask](http://duktape.org/api.html#duk_check_type_mask). + * + * \param ctx the context + * \param index the value index + * \param mask the desired mask + * \return true if object is one of the type + */ +inline bool checkTypeMask(ContextPtr ctx, Index index, unsigned mask) +{ + return duk_check_type_mask(ctx, index, mask); +} + +/** + * Wrapper for [duk_compact](http://duktape.org/api.html#duk_compact). + * + * \param ctx the context + * \param objIndex the object index + */ +inline void compact(ContextPtr ctx, Index objIndex) +{ + duk_compact(ctx, objIndex); +} + +/** + * Wrapper for [duk_concat](http://duktape.org/api.html#duk_concat). + * + * \param ctx the context + * \param count the number of values + */ +inline void concat(ContextPtr ctx, Index count) +{ + duk_concat(ctx, count); +} + +/** + * Wrapper for [duk_copy](http://duktape.org/api.html#duk_copy). + * + * \param ctx the context + * \param from the from index + * \param to the destination + */ +inline void copy(ContextPtr ctx, Index from, Index to) +{ + duk_copy(ctx, from, to); +} + +/** + * Wrapper for [duk_new](http://duktape.org/api.html#duk_new). + * + * \param ctx the context + * \param nargs the number of arguments + */ +inline void create(ContextPtr ctx, int nargs = 0) +{ + duk_new(ctx, nargs); +} + +/** + * Wrapper for [duk_def_prop](http://duktape.org/api.html#duk_def_prop). + * + * \param ctx the context + * \param index the object index + * \param flags the flags + */ +inline void defineProperty(ContextPtr ctx, Index index, unsigned flags) +{ + duk_def_prop(ctx, index, flags); +} + +/** + * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). + * + * \param ctx the context + * \param index the object index + * \return true if deleted + */ +inline bool deleteProperty(ContextPtr ctx, Index index) +{ + return duk_del_prop(ctx, index); +} + +/** + * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). + * + * \param ctx the context + * \param index the object index + * \param position the property index + * \return true if deleted + */ +inline bool deleteProperty(ContextPtr ctx, Index index, unsigned position) +{ + return duk_del_prop_index(ctx, index, position); +} + +/** + * Wrapper for [duk_del_prop](http://duktape.org/api.html#duk_del_prop). + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \return true if deleted + */ +inline bool deleteProperty(ContextPtr ctx, Index index, const std::string &name) +{ + return duk_del_prop_string(ctx, index, name.c_str()); +} + +/** + * Wrapper for [duk_dup](http://duktape.org/api.html#duk_dup). + * + * \param ctx the context + * \param index the value to copy + */ +inline void dup(ContextPtr ctx, int index = -1) +{ + duk_dup(ctx, index); +} + +/** + * Wrapper for [duk_equals](http://duktape.org/api.html#duk_equals). + * + * \param ctx the context + * \param index1 the first value + * \param index2 the second value + * \return true if they equal + */ +inline bool equals(ContextPtr ctx, Index index1, Index index2) +{ + return duk_equals(ctx, index1, index2); +} + +/** + * Wrapper for [duk_eval](http://duktape.org/api.html#duk_eval). + * + * \param ctx the context + */ +inline void eval(ContextPtr ctx) +{ + duk_eval(ctx); +} + +/** + * Wrapper for [duk_eval_file](http://duktape.org/api.html#duk_eval_file). + * + * \param ctx the context + * \param path the path + * \param result true to get the result at the top of the stack + */ +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()); +} + +/** + * Wrapper for [duk_eval_string](http://duktape.org/api.html#duk_eval_string). + * + * \param ctx the context + * \param src the source script + * \param result true to get the result at the top of the stack + */ +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()); +} +/** + * Wrapper for [duk_gc](http://duktape.org/api.html#duk_gc). + * + * \param ctx the context + * \param flags the flags + */ +inline void gc(ContextPtr ctx, unsigned flags = 0) +{ + duk_gc(ctx, flags); +} + +/** + * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). + * + * \param ctx the context + * \param index the object index + * \return true if has + */ +inline bool hasProperty(ContextPtr ctx, Index index) +{ + return duk_has_prop(ctx, index); +} + +/** + * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). + * + * \param ctx the context + * \param index the object index + * \param position the property index + * \return true if has + */ +inline bool hasProperty(ContextPtr ctx, Index index, unsigned position) +{ + return duk_has_prop_index(ctx, index, position); +} + +/** + * Wrapper for [duk_has_prop](http://duktape.org/api.html#duk_has_prop). + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \return true if has + */ +inline bool hasProperty(ContextPtr ctx, int index, const std::string &name) +{ + return duk_has_prop_string(ctx, index, name.c_str()); +} + +/** + * Wrapper for [duk_insert](http://duktape.org/api.html#duk_insert). + * + * \param ctx the context + * \param to the destination + * \note Wrapper of duk_insert + */ +inline void insert(ContextPtr ctx, Index to) +{ + duk_insert(ctx, to); +} + +/** + * Wrapper for [duk_instanceof](http://duktape.org/api.html#duk_instanceof). + * + * \param ctx the context + * \param idx1 the value to test + * \param idx2 the instance requested + * \return true if idx1 is instance of idx2 + */ +inline bool instanceof(ContextPtr ctx, Index idx1, Index idx2) +{ + return duk_instanceof(ctx, idx1, idx2); +} + +/** + * Wrapper for [duk_join](http://duktape.org/api.html#duk_join). + * + * \param ctx the context + * \param count the number of values + */ +inline void join(ContextPtr ctx, Index count) +{ + duk_join(ctx, count); +} + +/** + * Wrapper for [duk_json_decode](http://duktape.org/api.html#duk_json_decode). + * + * \param ctx the context + * \param index the index + */ +inline void jsonDecode(ContextPtr ctx, Index index) +{ + duk_json_decode(ctx, index); +} + +/** + * Wrapper for [duk_json_encode](http://duktape.org/api.html#duk_json_encode). + * + * \param ctx the context + * \param index the index + * \return the JSON string + */ +inline std::string jsonEncode(ContextPtr ctx, Index index) +{ + return duk_json_encode(ctx, index); +} + +/** + * Wrapper for [duk_normalize_index](http://duktape.org/api.html#duk_normalize_index). + * + * \param ctx the context + * \param index the index + */ +inline Index normalizeIndex(ContextPtr ctx, Index index) +{ + return duk_normalize_index(ctx, index); +} + +/** + * Wrapper for [duk_pcall](http://duktape.org/api.html#duk_pcall). + * + * \param ctx the context + * \param nargs the number of arguments + */ +inline int pcall(ContextPtr ctx, Index nargs = 0) +{ + return duk_pcall(ctx, nargs); +} + +/** + * Wrapper for [duk_pcall_method](http://duktape.org/api.html#duk_pcall_method). + * + * \param ctx the context + * \param nargs the number of arguments + */ +inline int pcallMethod(ContextPtr ctx, Index nargs = 0) +{ + return duk_pcall_method(ctx, nargs); +} + +/** + * Wrapper for [duk_pcall_prop](http://duktape.org/api.html#duk_pcall_prop). + * + * \param ctx the context + * \param index the object index + * \param nargs the number of arguments + */ +inline int pcallProperty(ContextPtr ctx, Index index, Index nargs = 0) +{ + return duk_pcall_prop(ctx, index, nargs); +} + +/** + * Wrapper for [duk_peval](http://duktape.org/api.html#duk_peval). + * + * \param ctx the context + */ +inline int peval(ContextPtr ctx) +{ + return duk_peval(ctx); +} + +/** + * Wrapper for [duk_peval_file](http://duktape.org/api.html#duk_peval_file). + * + * \param ctx the context + * \param path the path + * \param result true to get the result at the top of the stack + */ +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()); +} + +/** + * Wrapper for [duk_peval_string](http://duktape.org/api.html#duk_peval_string). + * + * \param ctx the context + * \param src the source script + * \param result true to get the result at the top of the stack + */ +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()); +} + +/** + * Wrapper for [duk_pop_n](http://duktape.org/api.html#duk_pop_n). + * + * \param ctx the context + * \param count the number of values to pop + */ +inline void pop(ContextPtr ctx, Index count = 1) +{ + duk_pop_n(ctx, count); +} + +/** + * Wrapper for [duk_put_prop](http://duktape.org/api.html#duk_put_prop). + * + * \param ctx the context + * \param index the object index + */ +inline void putProperty(ContextPtr ctx, Index index) +{ + duk_put_prop(ctx, index); +} + +/** + * Wrapper for [duk_put_prop_string](http://duktape.org/api.html#duk_put_prop_string). + * + * \param ctx the context + * \param index the object index + * \param name the property name + */ +inline void putProperty(ContextPtr ctx, Index index, const std::string &name) +{ + duk_put_prop_string(ctx, index, name.c_str()); +} + +/** + * Wrapper for [duk_put_prop_index](http://duktape.org/api.html#duk_put_prop_index). + * + * \param ctx the context + * \param index the object index + * \param position the array position + */ +inline void putProperty(ContextPtr ctx, Index index, unsigned position) +{ + duk_put_prop_index(ctx, index, position); +} + +/** + * Wrapper for [duk_remove](http://duktape.org/api.html#duk_remove). + * + * \param ctx the context + * \param index the value to remove + */ +inline void remove(ContextPtr ctx, Index index) +{ + duk_remove(ctx, index); +} + +/** + * Wrapper for [duk_replace](http://duktape.org/api.html#duk_replace). + * + * \param ctx the context + * \param index the value to replace by the value at the top of the stack + */ +inline void replace(ContextPtr ctx, Index index) +{ + duk_replace(ctx, index); +} + +/** + * Wrapper for [duk_set_prototype](http://duktape.org/api.html#duk_set_prototype). + * + * \param ctx the context + * \param index the value index + */ +inline void setPrototype(ContextPtr ctx, Index index) +{ + duk_set_prototype(ctx, index); +} + +/** + * Wrapper for [duk_swap](http://duktape.org/api.html#duk_swap). + * + * \param ctx the context + * \param index1 the first index + * \param index2 the second index + */ +inline void swap(ContextPtr ctx, Index index1, Index index2) +{ + duk_swap(ctx, index1, index2); +} + +/** + * Wrapper for [duk_swap_top](http://duktape.org/api.html#duk_swap_top). + * + * \param ctx the context + * \param index the index + */ +inline void swapTop(ContextPtr ctx, Index index) +{ + duk_swap_top(ctx, index); +} + +/** + * Wrapper for [duk_get_top](http://duktape.org/api.html#duk_get_top). + * + * \param ctx the context + * \return the stack size + */ +inline int top(ContextPtr ctx) +{ + return duk_get_top(ctx); +} + +/** + * Wrapper for [duk_throw](http://duktape.org/api.html#duk_throw). + * + * \param ctx the context + */ +inline void raise(ContextPtr ctx) +{ + duk_throw(ctx); +} + +/** + *Wrapper for [duk_error](http://duktape.org/api.html#duk_error). + * + * \param ctx the context + * \param type the error type (e.g. DUK_ERR_REFERENCE_ERROR) + * \param fmt the format string + * \param args the arguments + */ +template <typename... Args> +inline void raise(ContextPtr ctx, int type, const char *fmt, Args&&... args) +{ + duk_error(ctx, type, fmt, std::forward<Args>(args)...); +} + +/** + * Wrapper for [duk_get_type](http://duktape.org/api.html#duk_get_type). + * + * \param ctx the context + * \param index the idnex + * \return the type + */ +inline int type(ContextPtr ctx, Index index) +{ + return duk_get_type(ctx, index); +} + +/** + * @} + */ + +/** + * @name Extended functions + * \brief Extended functions for libjs. + * + * The following functions are largely modified or extensions to Duktape. + */ + +/** + * @{ + */ + +/** + * Get the error object when a JavaScript error has been thrown (e.g. eval failure). + * + * \param ctx the context + * \param index the index + * \return the information + */ +inline Exception exception(ContextPtr ctx, int index) +{ + Exception ex; + StackAssert sa(ctx); + + 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); + + return ex; +} + +/** + * Push a value into the stack. Calls TypeTraits<T>::push(ctx, value); + * + * \param ctx the context + * \param value the value to forward + */ +template <typename Type> +inline void push(ContextPtr ctx, Type &&value) +{ + TypeTraits<std::decay_t<Type>>::push(ctx, std::forward<Type>(value)); +} + +/** + * Put the value to the object at the top of the stack. Calls TypeTraits<T>::put(ctx, value); + * + * \param ctx the context + * \param value the value to apply + */ +template <typename Type> +inline void put(ContextPtr ctx, Type &&value) +{ + TypeTraits<std::decay_t<Type>>::put(ctx, std::forward<Type>(value)); +} + +/** + * Generic template function to get a value from the stack. + * + * \param ctx the context + * \param index the index + * \return the value + */ +template <typename Type> +inline auto get(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::get(ctx, 0)) +{ + return TypeTraits<Type>::get(ctx, index); +} + +/** + * Require a type at the specified index. + * + * \param ctx the context + * \param index the index + * \return the value + */ +template <typename Type> +inline auto require(ContextPtr ctx, int index) -> decltype(TypeTraits<Type>::require(ctx, 0)) +{ + return TypeTraits<Type>::require(ctx, index); +} + +/** + * Check if a value is a type of T. + * + * The TypeTraits<T> must have `static bool is(ContextPtr ptr, int index)`. + * + * \param ctx the context + * \param index the value index + * \return true if is the type + */ +template <typename T> +inline bool is(ContextPtr ctx, int index) +{ + return TypeTraits<T>::is(ctx, index); +} + +/** + * Get an optional value from the stack, if the value is not available of not the correct type, + * return defaultValue instead. + * + * The TypeTraits<T> must have `static T optional(Context &, int index, T &&defaultValue)`. + * + * \param ctx the context + * \param index the value index + * \param defaultValue the value replacement + * \return the value or defaultValue + */ +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)); +} + +/** + * Get the property `name' as value from the object at the specified index. + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \return the value + * \note The stack is unchanged + */ +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); + + return value; +} + +/** + * Get a property by index, for arrays. + * + * \param ctx the context + * \param index the object index + * \param position the position int the object + * \return the value + * \note The stack is unchanged + */ +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); + + return value; +} + +/** + * Get the property `name' and push it to the stack from the object at the specified index. + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \note The stack contains the property value + */ +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()); +} + +/** + * Get the property by index and push it to the stack from the object at the specified index. + * + * \param ctx the context + * \param index the object index + * \param position the position in the object + * \note The stack contains the property value + */ +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); +} + +/** + * Get an optional property `name` from the object at the specified index. + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \param def the default value + * \return the value or def + * \note The stack is unchanged + */ +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); + + return value; +} + +/** + * Get an optional property by index, for arrays + * + * \param ctx the context + * \param index the object index + * \param position the position int the object + * \param def the default value + * \return the value or def + * \note The stack is unchanged + */ +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); + + return value; +} + +/** + * Set a property to the object at the specified index. + * + * \param ctx the context + * \param index the object index + * \param name the property name + * \param value the value to forward + * \note The stack is unchanged + */ +template <typename Type> +void putProperty(ContextPtr ctx, int index, const std::string &name, Type &&value) +{ + index = duk_normalize_index(ctx, index); + + push(ctx, std::forward<Type>(value)); + duk_put_prop_string(ctx, index, name.c_str()); +} + +/** + * Set a property by index, for arrays. + * + * \param ctx the context + * \param index the object index + * \param position the position in the object + * \param value the value to forward + * \note The stack is unchanged + */ +template <typename Type> +void putProperty(ContextPtr ctx, int index, int position, Type &&value) +{ + index = duk_normalize_index(ctx, index); + + push(ctx, std::forward<Type>(value)); + duk_put_prop_index(ctx, index, position); +} + +/** + * Get a global value. + * + * \param ctx the context + * \param name the name of the global variable + * \return the value + */ +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); + + return value; +} + +/** + * Overload that push the value at the top of the stack instead of returning it. + */ +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()); +} + +/** + * Set a global variable. + * + * \param ctx the context + * \param name the name of the global variable + * \param type the value to set + */ +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()); +} + +/** + * Put the value at the top of the stack as global property. + * + * \param ctx the context + * \param name the property name + */ +inline void putGlobal(ContextPtr ctx, const std::string &name) +{ + duk_put_global_string(ctx, name.c_str()); +} + +/** + * Enumerate an object or an array at the specified index. + * + * \param ctx the context + * \param index the object or array index + * \param flags the optional flags to pass to duk_enum + * \param getvalue set to true if you want to extract the value + * \param func the function to call for each properties + */ +template <typename Func> +void enumerate(ContextPtr ctx, int index, duk_uint_t flags, duk_bool_t getvalue, Func &&func) +{ + duk_enum(ctx, index, flags); + + while (duk_next(ctx, -1, getvalue)) { + func(ctx); + duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); + } + + duk_pop(ctx); +} + +/** + * Return the this binding of the current function. + * + * \param ctx the context + * \return the this binding as the template given + */ +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); + + return value; +} + +/** + * Throw an ECMAScript exception. + * + * \param ctx the context + * \param ex the exception + */ +template <typename Exception> +void raise(ContextPtr ctx, const Exception &ex) +{ + ex.raise(ctx); +} + +/** + * Construct the object in place, setting value as this binding. + * + * The TypeTraits<T> must have the following requirements: + * + * - static void construct(Context &, T): must update this with the value and keep the stack unchanged + * + * \param ctx the context + * \param value the value to forward + * \see self + */ +template <typename T> +inline void construct(ContextPtr ctx, T &&value) +{ + TypeTraits<std::decay_t<T>>::construct(ctx, std::forward<T>(value)); +} + +/** + * @} + */ + +/** + * \class Error + * \brief Base ECMAScript error class. + * \warning Override the function create for your own exceptions + */ +class Error { +private: + 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)) + { + } + +public: + /** + * 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()); + } +}; + +/** + * \class EvalError + * \brief Error in eval() function. + */ +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)) + { + } +}; + +/** + * \class RangeError + * \brief Value is out of range. + */ +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)) + { + } +}; + +/** + * \class ReferenceError + * \brief Trying to use a variable that does not exist. + */ +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)) + { + } +}; + +/** + * \class SyntaxError + * \brief Syntax error in the script. + */ +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)) + { + } +}; + +/** + * \class TypeError + * \brief Invalid type given. + */ +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)) + { + } +}; + +/** + * \class URIError + * \brief URI manipulation failure. + */ +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)) + { + } +}; + +/* ------------------------------------------------------------------ + * Standard overloads for TypeTraits<T> + * ------------------------------------------------------------------ */ + +/** + * \class TypeTraits<int> + * \brief Default implementation for int. + * + * Provides: get, is, optional, push, require. + */ +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); + } + + /** + * 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; + } + + /** + * 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); + } +}; + +/** + * \class TypeTraits<bool> + * \brief Default implementation for bool. + * + * Provides: get, is, optional, push, require. + */ +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); + } + + /** + * 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; + } + + /** + * 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); + } +}; + +/** + * \class TypeTraits<double> + * \brief Default implementation for double. + * + * Provides: get, is, optional, push, require. + */ +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); + } + + /** + * 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; + } + + /** + * 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); + } +}; + +/** + * \class TypeTraits<std::string> + * \brief Default implementation for std::string. + * + * Provides: get, is, optional, push, require. + * + * Note: the functions allows embedded '\0'. + */ +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); + + 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); + } + + /** + * 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()); + } + + /** + * 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}; + } +}; + +/** + * \class TypeTraits<const char *> + * \brief Default implementation for const char literals. + * + * Provides: get, is, optional, push, require. + */ +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); + } + + /** + * 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; + } + + /** + * 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); + } +}; + +/** + * \class TypeTraits<unsigned> + * \brief Default implementation for unsigned. + * + * Provides: get, is, optional, push, require. + */ +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); + } + + /** + * 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; + } + + /** + * 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); + } +}; + +/** + * \brief Implementation for non-managed pointers. + * + * Provides: get, is, optional, push, require. + */ +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)); + } + + /** + * 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; + } + + /** + * 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)); + } +}; + +/** + * \class TypeTraits<Function> + * \brief Push C++ function to the stack. + * + * Provides: push. + * + * This implementation push a Duktape/C function that is wrapped as C++ for convenience. + */ +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); + } + + /** + * 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); + } +}; + +/** + * \class TypeTraits<FunctionMap> + * \brief Put the functions to the object at the top of the stack. + * + * Provides: put. + */ +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); + + 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()); + } + } +}; + +/** + * \class TypeTraits<Object> + * \brief Push empty object to the stack. + * + * Provides: is, push. + */ +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); + } + + /** + * Create an empty object on the stack. + * + * \param ctx the context + */ + static inline void push(ContextPtr ctx, const Object &) + { + duk_push_object(ctx); + } +}; + +/** + * \class TypeTraits<Array> + * \brief Push empty array to the stack. + * + * Provides: is, push. + */ +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); + } + + /** + * Create an empty array on the stack. + * + * \param ctx the context + */ + static inline void push(ContextPtr ctx, const Array &) + { + duk_push_array(ctx); + } +}; + +/** + * \class TypeTraits<Undefined> + * \brief Push undefined value to the stack. + * + * Provides: is, push. + */ +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); + } + + /** + * Push undefined value on the stack. + * + * \param ctx the context + */ + static inline void push(ContextPtr ctx, const Undefined &) + { + duk_push_undefined(ctx); + } +}; + +/** + * \class TypeTraits<Null> + * \brief Push null value to the stack. + * + * Provides: is, push. + */ +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); + } + + /** + * Push null value on the stack. + * + * \param ctx the context + */ + static inline void push(ContextPtr ctx, const Null &) + { + duk_push_null(ctx); + } +}; + +/** + * \brief Push this binding into the stack. + * + * Provides: push. + */ +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); + } +}; + +/** + * \class TypeTraits<Global> + * \brief Push the global object to the stack. + * + * Provides: push. + */ +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); + } +}; + +/** + * \brief Push a map of key-value pair as objects. + * + * Provides: push, put. + * + * This class is convenient for settings constants such as enums, string and such. + */ +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); + + 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); + + StackAssert sa(ctx); + + for (const auto &pair : map) { + TypeTraits<T>::push(ctx, pair.second); + duk_put_prop_string(ctx, -2, pair.first.c_str()); + } + } +}; + +/** + * \brief Push or get vectors as JavaScript arrays. + * + * Provides: get, push, put. + */ +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); + + std::vector<T> result; + + if (!duk_is_array(ctx, -1)) + return result; + + int total = duk_get_length(ctx, index); + + for (int i = 0; i < total; ++i) + result.push_back(getProperty<T>(ctx, index, i)); + + 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); + + 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); + + StackAssert sa(ctx); + + unsigned i = 0; + for (const auto &v : array) { + TypeTraits<T>::push(ctx, v); + duk_put_prop_index(ctx, -2, i++); + } + } +}; + +/** + * \brief Implementation of managed std::shared_ptr<T>. + * + * This specialization requires T to be @ref js-concept-class. + */ +template <typename T> +class TypeTraits<std::shared_ptr<T>> { +private: + 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"); + + 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"); + + StackAssert sa(ctx, 0); + + 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"); + + StackAssert sa(ctx, 1); + + 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"); + + StackAssert sa(ctx); + + auto ptr = getProperty<std::shared_ptr<Bindable> *>(ctx, index, "\xff""\xff""js-shared-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"); + + auto ptr = get(ctx, index); + + if (!ptr) + duk::raise(ctx, DUK_ERR_TYPE_ERROR, "invalid this binding"); + + return ptr; + } +}; + +} // !duk + +} // !malikania + +#endif // !JS_HPP
--- a/libcommon/malikania/json.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/json.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,345 +1,345 @@ -/* - * json.cpp -- C++14 JSON manipulation using jansson parser - * - * Copyright (c) 2015-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <jansson.h> - -#include <sstream> - -#include "json.h" - -namespace malikania { - -namespace json { - -namespace { - -void readObject(Value &parent, json_t *object); -void readArray(Value &parent, json_t *array); - -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); - - readObject(object, v); - - return object; - } - if (json_is_array(v)) { - Value array(Type::Array); - - readArray(array, v); - - return array; - } - - return Value(); -} - -void readObject(Value &parent, json_t *object) -{ - const char *key; - json_t *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; - - 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); - - if (json == nullptr) - throw Error(error.text, error.source, error.line, error.column, error.position); - - Value value; - - if (json_is_object(json)) { - value = Value(Type::Object); - readObject(value, json); - } else { - value = Value(Type::Array); - readArray(value, json); - } - - json_decref(json); - - return value; -} - -std::string indent(int param, int level) -{ - std::string str; - - if (param < 0) - str = std::string(level, '\t'); - else if (param > 0) - str = std::string(param * level, ' '); - - 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; - } - - 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; - } - - m_type = other.m_type; -} - -Value::Value(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; - } -} - -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; - } -} - -std::string Value::toString(bool coerce) const -{ - std::string result; - - if (m_type == Type::String) - result = m_string; - else if (coerce) - result = toJson(); - - return result; -} - -std::string Value::toJson(int level, int current) const -{ - std::ostringstream oss; - - 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" : ""); - } - - 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); - - /* Key and : */ - oss << "\"" << pair.first << "\":" << (level != 0 ? " " : ""); - - /* Value */ - oss << pair.second.toJson(level, current + 1); - - /* 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; - } - - return oss.str(); -} - -std::string escape(const std::string &value) -{ - 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; - } - } - - return result; -} - -Value fromString(const std::string &buffer) -{ - return convert(json_loads, buffer.c_str(), 0); -} - -Value fromFile(const std::string &path) -{ - return convert(json_load_file, path.c_str(), 0); -} - -} // !json - -} // !malikania +/* + * json.cpp -- C++14 JSON manipulation using jansson parser + * + * Copyright (c) 2015-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <jansson.h> + +#include <sstream> + +#include "json.hpp" + +namespace malikania { + +namespace json { + +namespace { + +void readObject(Value &parent, json_t *object); +void readArray(Value &parent, json_t *array); + +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); + + readObject(object, v); + + return object; + } + if (json_is_array(v)) { + Value array(Type::Array); + + readArray(array, v); + + return array; + } + + return Value(); +} + +void readObject(Value &parent, json_t *object) +{ + const char *key; + json_t *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; + + 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); + + if (json == nullptr) + throw Error(error.text, error.source, error.line, error.column, error.position); + + Value value; + + if (json_is_object(json)) { + value = Value(Type::Object); + readObject(value, json); + } else { + value = Value(Type::Array); + readArray(value, json); + } + + json_decref(json); + + return value; +} + +std::string indent(int param, int level) +{ + std::string str; + + if (param < 0) + str = std::string(level, '\t'); + else if (param > 0) + str = std::string(param * level, ' '); + + 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; + } + + 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; + } + + m_type = other.m_type; +} + +Value::Value(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; + } +} + +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; + } +} + +std::string Value::toString(bool coerce) const +{ + std::string result; + + if (m_type == Type::String) + result = m_string; + else if (coerce) + result = toJson(); + + return result; +} + +std::string Value::toJson(int level, int current) const +{ + std::ostringstream oss; + + 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" : ""); + } + + 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); + + /* Key and : */ + oss << "\"" << pair.first << "\":" << (level != 0 ? " " : ""); + + /* Value */ + oss << pair.second.toJson(level, current + 1); + + /* 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; + } + + return oss.str(); +} + +std::string escape(const std::string &value) +{ + 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; + } + } + + return result; +} + +Value fromString(const std::string &buffer) +{ + return convert(json_loads, buffer.c_str(), 0); +} + +Value fromFile(const std::string &path) +{ + return convert(json_load_file, path.c_str(), 0); +} + +} // !json + +} // !malikania
--- a/libcommon/malikania/json.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1200 +0,0 @@ -/* - * json.h -- C++14 JSON manipulation using jansson parser - * - * Copyright (c) 2015-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_JSON_H -#define MALIKANIA_JSON_H - -/** - * \file json.h - * \brief Jansson C++14 wrapper - */ - -#include <cassert> -#include <exception> -#include <initializer_list> -#include <map> -#include <string> -#include <utility> -#include <vector> - -namespace malikania { - -/** - * Json namespace. - */ -namespace json { - -/** - * @enum Type - * \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 -}; - -/** - * \class Error - * \brief Error description. - */ -class Error : public std::exception { -private: - 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) - { - } - - /** - * 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 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 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(); - } -}; - -/** - * \class Iterator - * \brief This is the base class for iterator and const_iterator - * - * This iterator works for both arrays and objects. Because of that purpose, it is only available - * as forward iterator. - * - * When iterator comes from an object, you can use key() otherwise you can use index(). - */ -template <typename ValueType, typename ArrayIteratorType, typename ObjectIteratorType> -class Iterator : public std::iterator<std::forward_iterator_tag, ValueType> { -private: - friend class Value; - - ValueType *m_parent{nullptr}; - ArrayIteratorType m_ita; - ObjectIteratorType m_itm; - - 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, ArrayIteratorType it) - : m_parent(parent) - , m_ita(it) - { - assert(parent); - } - -public: - /** - * 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()); - - 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()); - - 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())); - - 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())); - - 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(); - - 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(); - - 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; - } - - /** - * 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); - } -}; - -/** - * \class Value - * \brief Generic JSON value wrapper. - */ -class Value { -private: - 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; - }; - - 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>; - -public: - /** - * 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>; - - /** - * 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); - - /** - * 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) - { - } - - /** - * 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 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)); - } - - /** - * 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)); - } - - /** - * 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 operator. - * - * \param other the value to copy from - * \return *this - */ - inline Value &operator=(const Value &other) - { - copy(other); - - return *this; - } - - /** - * Move operator. - * - * \param other the value to move from - */ - inline Value &operator=(Value &&other) - { - move(std::move(other)); - - return *this; - } - - /** - * 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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 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 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; - - /** - * 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 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 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 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; - } - - /** - * 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(); - - return m_array.size(); - } - - /** - * 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(); - } - - /* - * 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; - - 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; - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - m_array.erase(m_array.begin() + position); - } - - /* - * 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; - - auto it = m_object.find(name); - - if (it == m_object.end()) - return defaultValue; - - 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; - - auto it = m_object.find(name); - - if (it == m_object.end() || it->second.typeOf() != type) - return defaultValue; - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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()); - - 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); - } -}; - -/** - * Escape the input. - * - * \param input the input - * \return the escaped string - */ -std::string escape(const std::string &input); - -/** - * Convenient function to create an empty array. - * - * \return an empty array - */ -inline Value array() -{ - return Value(Type::Array); -} - -/** - * Convenient function for creating array from initializer list. - * - * \param values the values - * \return the array - */ -inline Value array(std::initializer_list<Value> values) -{ - return Value(std::vector<Value>(values.begin(), values.end())); -} - -/** - * Convenient function to create an empty object. - * - * \return an empty object - */ -inline Value object() -{ - return Value(Type::Object); -} - -/** - * Convenient function for creating object from initializer list. - * - * \param values the values - * \return the object - */ -inline Value object(std::initializer_list<std::pair<std::string, Value>> values) -{ - return Value(std::map<std::string, Value>(values.begin(), values.end())); -} - -/** - * Construct a value from a buffer. - * - * \param data the JSON data - * \return the parsed value - * \throw Error on errors - */ -Value fromString(const std::string &data); - -/** - * Construct a value from a file. - * - * \param path the path to the file - * \return the parsed value - * \throw Error on errors - */ -Value fromFile(const std::string &path); - -} // !json - -} // !malikania - -#endif // !MALIKANIA_JSON_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/json.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,1200 @@ +/* + * json.hpp -- C++14 JSON manipulation using jansson parser + * + * Copyright (c) 2015-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_JSON_HPP +#define MALIKANIA_JSON_HPP + +/** + * \file json.hpp + * \brief Jansson C++14 wrapper + */ + +#include <cassert> +#include <exception> +#include <initializer_list> +#include <map> +#include <string> +#include <utility> +#include <vector> + +namespace malikania { + +/** + * Json namespace. + */ +namespace json { + +/** + * @enum Type + * \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 +}; + +/** + * \class Error + * \brief Error description. + */ +class Error : public std::exception { +private: + 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) + { + } + + /** + * 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 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 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(); + } +}; + +/** + * \class Iterator + * \brief This is the base class for iterator and const_iterator + * + * This iterator works for both arrays and objects. Because of that purpose, it is only available + * as forward iterator. + * + * When iterator comes from an object, you can use key() otherwise you can use index(). + */ +template <typename ValueType, typename ArrayIteratorType, typename ObjectIteratorType> +class Iterator : public std::iterator<std::forward_iterator_tag, ValueType> { +private: + friend class Value; + + ValueType *m_parent{nullptr}; + ArrayIteratorType m_ita; + ObjectIteratorType m_itm; + + 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, ArrayIteratorType it) + : m_parent(parent) + , m_ita(it) + { + assert(parent); + } + +public: + /** + * 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()); + + 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()); + + 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())); + + 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())); + + 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(); + + 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(); + + 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; + } + + /** + * 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); + } +}; + +/** + * \class Value + * \brief Generic JSON value wrapper. + */ +class Value { +private: + 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; + }; + + 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>; + +public: + /** + * 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>; + + /** + * 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); + + /** + * 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) + { + } + + /** + * 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 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)); + } + + /** + * 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)); + } + + /** + * 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 operator. + * + * \param other the value to copy from + * \return *this + */ + inline Value &operator=(const Value &other) + { + copy(other); + + return *this; + } + + /** + * Move operator. + * + * \param other the value to move from + */ + inline Value &operator=(Value &&other) + { + move(std::move(other)); + + return *this; + } + + /** + * 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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 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 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; + + /** + * 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 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 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 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; + } + + /** + * 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(); + + return m_array.size(); + } + + /** + * 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(); + } + + /* + * 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; + + 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; + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + m_array.erase(m_array.begin() + position); + } + + /* + * 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; + + auto it = m_object.find(name); + + if (it == m_object.end()) + return defaultValue; + + 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; + + auto it = m_object.find(name); + + if (it == m_object.end() || it->second.typeOf() != type) + return defaultValue; + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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()); + + 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); + } +}; + +/** + * Escape the input. + * + * \param input the input + * \return the escaped string + */ +std::string escape(const std::string &input); + +/** + * Convenient function to create an empty array. + * + * \return an empty array + */ +inline Value array() +{ + return Value(Type::Array); +} + +/** + * Convenient function for creating array from initializer list. + * + * \param values the values + * \return the array + */ +inline Value array(std::initializer_list<Value> values) +{ + return Value(std::vector<Value>(values.begin(), values.end())); +} + +/** + * Convenient function to create an empty object. + * + * \return an empty object + */ +inline Value object() +{ + return Value(Type::Object); +} + +/** + * Convenient function for creating object from initializer list. + * + * \param values the values + * \return the object + */ +inline Value object(std::initializer_list<std::pair<std::string, Value>> values) +{ + return Value(std::map<std::string, Value>(values.begin(), values.end())); +} + +/** + * Construct a value from a buffer. + * + * \param data the JSON data + * \return the parsed value + * \throw Error on errors + */ +Value fromString(const std::string &data); + +/** + * Construct a value from a file. + * + * \param path the path to the file + * \return the parsed value + * \throw Error on errors + */ +Value fromFile(const std::string &path); + +} // !json + +} // !malikania + +#endif // !MALIKANIA_JSON_HPP
--- a/libcommon/malikania/resources-loader.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/resources-loader.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,109 +1,109 @@ -/* - * resources-loader.cpp -- load shared resources files - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cassert> - -#include "game.h" -#include "resources-loader.h" -#include "resources-locator.h" - -namespace malikania { - -void ResourcesLoader::requires(const std::string &id, - const json::Value &object, - const std::unordered_map<std::string, json::Type> props) const -{ - assert(object.isObject()); - - 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 ("; - - 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)"; - - throw std::runtime_error(std::move(msg)); - } - } -} - -std::string ResourcesLoader::requireString(const std::string &id, - const json::Value &object, - const std::string &property) const -{ - assert(object.isObject()); - - auto it = object.find(property); - - if (it == object.end() || !it->isString()) { - throw std::runtime_error(id + ": missing '" + property + "' property (string expected)"); - } - - return it->toString(); -} - -ResourcesLoader::ResourcesLoader(ResourcesLocator &locator) - : m_locator(locator) -{ -} - -Game ResourcesLoader::loadGame() const -{ - json::Value value = json::fromString(m_locator.read("game.json")); - - 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 } - }); - - 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 +/* + * resources-loader.cpp -- load shared resources files + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cassert> + +#include "game.hpp" +#include "resources-loader.hpp" +#include "resources-locator.hpp" + +namespace malikania { + +void ResourcesLoader::requires(const std::string &id, + const json::Value &object, + const std::unordered_map<std::string, json::Type> props) const +{ + assert(object.isObject()); + + 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 ("; + + 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)"; + + throw std::runtime_error(std::move(msg)); + } + } +} + +std::string ResourcesLoader::requireString(const std::string &id, + const json::Value &object, + const std::string &property) const +{ + assert(object.isObject()); + + auto it = object.find(property); + + if (it == object.end() || !it->isString()) { + throw std::runtime_error(id + ": missing '" + property + "' property (string expected)"); + } + + return it->toString(); +} + +ResourcesLoader::ResourcesLoader(ResourcesLocator &locator) + : m_locator(locator) +{ +} + +Game ResourcesLoader::loadGame() const +{ + json::Value value = json::fromString(m_locator.read("game.json")); + + 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 } + }); + + 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 Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* - * resources-loader.h -- load shared resources files - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_RESOURCES_LOADER_H -#define MALIKANIA_RESOURCES_LOADER_H - -#include <string> -#include <unordered_map> - -#include "json.h" -#include "resources-locator.h" - -namespace malikania { - -class Game; - -/** - * \class ResourcesLoader - * \brief Open resources files using a ResourcesLocator. - * - * This class is used to load resources files that are common to the server and the client. - * - * \see ResourcesLoaderClient - * \see ResourcesLoaderServer - */ -class ResourcesLoader { -private: - 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; - - /** - * 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); - - /** - * Virtual destructor defaulted. - */ - virtual ~ResourcesLoader() = default; - - /** - * 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; -}; - -} // !malikania - -#endif // !MALIKANIA_RESOURCES_LOADER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/resources-loader.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,110 @@ +/* + * resources-loader.hpp -- load shared resources files + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_RESOURCES_LOADER_HPP +#define MALIKANIA_RESOURCES_LOADER_HPP + +#include <string> +#include <unordered_map> + +#include "json.hpp" +#include "resources-locator.hpp" + +namespace malikania { + +class Game; + +/** + * \class ResourcesLoader + * \brief Open resources files using a ResourcesLocator. + * + * This class is used to load resources files that are common to the server and the client. + * + * \see ResourcesLoaderClient + * \see ResourcesLoaderServer + */ +class ResourcesLoader { +private: + 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; + + /** + * 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); + + /** + * Virtual destructor defaulted. + */ + virtual ~ResourcesLoader() = default; + + /** + * 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; +}; + +} // !malikania + +#endif // !MALIKANIA_RESOURCES_LOADER_HPP
--- a/libcommon/malikania/resources-locator.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/resources-locator.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,56 +1,56 @@ -/* - * resources-locator.cpp -- file and stream loader - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cerrno> -#include <cstring> -#include <fstream> -#include <iterator> -#include <stdexcept> - -#include "resources-locator.h" - -namespace malikania { - -ResourcesLocatorDirectory::ResourcesLocatorDirectory(std::string path) noexcept - : 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); - - if (!in) { - throw std::runtime_error(std::strerror(errno)); - } - - 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); - - if (!(*ptr)) { - throw std::runtime_error(std::strerror(errno)); - } - - return ptr; -} - -} // !malikania +/* + * resources-locator.cpp -- file and stream loader + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cerrno> +#include <cstring> +#include <fstream> +#include <iterator> +#include <stdexcept> + +#include "resources-locator.hpp" + +namespace malikania { + +ResourcesLocatorDirectory::ResourcesLocatorDirectory(std::string path) noexcept + : 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); + + if (!in) { + throw std::runtime_error(std::strerror(errno)); + } + + 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); + + if (!(*ptr)) { + throw std::runtime_error(std::strerror(errno)); + } + + return ptr; +} + +} // !malikania
--- a/libcommon/malikania/resources-locator.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * resources-locator.h -- file and stream loader - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_RESOURCES_LOCATOR_H -#define MALIKANIA_RESOURCES_LOCATOR_H - -#include <string> -#include <memory> -#include <istream> - -namespace malikania { - -/** - * \class ResourcesLocator - * \brief Load files from directories and zip. - */ -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; - - /** - * 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; -}; - -/** - * \class ResourcesLocatorDirectory - * \brief Load a game from a directory. - */ -class ResourcesLocatorDirectory : public ResourcesLocator { -private: - std::string m_path; - -public: - /** - * 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::open - */ - std::unique_ptr<std::istream> open(const std::string &id) override; -}; - -} // !malikania - -#endif // !MALIKANIA_RESOURCES_LOCATOR_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/resources-locator.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,82 @@ +/* + * resources-locator.hpp -- file and stream loader + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_RESOURCES_LOCATOR_HPP +#define MALIKANIA_RESOURCES_LOCATOR_HPP + +#include <string> +#include <memory> +#include <istream> + +namespace malikania { + +/** + * \class ResourcesLocator + * \brief Load files from directories and zip. + */ +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; + + /** + * 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; +}; + +/** + * \class ResourcesLocatorDirectory + * \brief Load a game from a directory. + */ +class ResourcesLocatorDirectory : public ResourcesLocator { +private: + std::string m_path; + +public: + /** + * 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::open + */ + std::unique_ptr<std::istream> open(const std::string &id) override; +}; + +} // !malikania + +#endif // !MALIKANIA_RESOURCES_LOCATOR_HPP
--- a/libcommon/malikania/util.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libcommon/malikania/util.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,40 +1,40 @@ -/* - * util.cpp -- malikania utilities - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "util.h" - -namespace malikania { - -namespace util { - -std::vector<std::string> netsplit(std::string &input) -{ - 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); - } - - return ret; -} - -} // !util - -} // !malikania +/* + * util.cpp -- malikania utilities + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "util.hpp" + +namespace malikania { + +namespace util { + +std::vector<std::string> netsplit(std::string &input) +{ + 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); + } + + return ret; +} + +} // !util + +} // !malikania
--- a/libcommon/malikania/util.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * util.h -- malikania utilities - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_UTIL_H -#define MALIKANIA_UTIL_H - -/** - * \file util.h - * \brief Some utilities - */ - -#include <algorithm> -#include <string> -#include <vector> - -namespace malikania { - -namespace util { - -/** - * Split the network message buffer by \r\n\r\n and update the - * buffer in-place. - * - * \param input the buffer to split and update - * \return the list of received message or empty if not ready - */ -std::vector<std::string> netsplit(std::string &input); - -/** - * Clamp the value between low and high. - * - * \param value the value - * \param low the minimum value - * \param high the maximum value - * \return the value between minimum and maximum - */ -template <typename T> -constexpr T clamp(T value, T low, T high) noexcept -{ - return (value < high) ? std::max(value, low) : std::min(value, high); -} - -} // !util - -} // !malikania - -#endif // !MALIKANIA_UTIL_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcommon/malikania/util.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,62 @@ +/* + * util.hpp -- malikania utilities + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_UTIL_HPP +#define MALIKANIA_UTIL_HPP + +/** + * \file util.hpp + * \brief Some utilities + */ + +#include <algorithm> +#include <string> +#include <vector> + +namespace malikania { + +namespace util { + +/** + * Split the network message buffer by \r\n\r\n and update the + * buffer in-place. + * + * \param input the buffer to split and update + * \return the list of received message or empty if not ready + */ +std::vector<std::string> netsplit(std::string &input); + +/** + * Clamp the value between low and high. + * + * \param value the value + * \param low the minimum value + * \param high the maximum value + * \return the value between minimum and maximum + */ +template <typename T> +constexpr T clamp(T value, T low, T high) noexcept +{ + return (value < high) ? std::max(value, low) : std::min(value, high); +} + +} // !util + +} // !malikania + +#endif // !MALIKANIA_UTIL_HPP
--- a/libserver/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/libserver/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,41 +1,41 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -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 -) - -set( - 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_include_directories(libmlk-server PUBLIC ${libmlk-server_SOURCE_DIR}) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(libmlk-server) + +set( + HEADERS + ${libmlk-server_SOURCE_DIR}/malikania/account.hpp + ${libmlk-server_SOURCE_DIR}/malikania/dao-account.hpp + ${libmlk-server_SOURCE_DIR}/malikania/database.hpp + ${libmlk-server_SOURCE_DIR}/malikania/dynlib.hpp +) + +set( + 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_include_directories(libmlk-server PUBLIC ${libmlk-server_SOURCE_DIR})
--- a/libserver/malikania/account.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,180 +0,0 @@ -/* - * account.h -- account model - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_ACCOUNT_H -#define MALIKANIA_ACCOUNT_H - -/** - * \file account.h - * \brief Account model. - */ - -#include <cstdint> -#include <string> - -namespace malikania { - -/** - * \brief Account model - */ -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; - -public: - /** - * 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; - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * 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); - } -}; - -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(); -} - -inline bool operator!=(const Account &ac1, const Account &ac2) noexcept -{ - return !(ac1 == ac2); -} - -} // !malikania - -#endif // !MALIKANIA_ACCOUNT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserver/malikania/account.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,180 @@ +/* + * account.hpp -- account model + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_ACCOUNT_HPP +#define MALIKANIA_ACCOUNT_HPP + +/** + * \file account.hpp + * \brief Account model. + */ + +#include <cstdint> +#include <string> + +namespace malikania { + +/** + * \brief Account model + */ +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; + +public: + /** + * 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; + } + + /** + * 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); + } + + /** + * 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); + } + + /** + * 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); + } + + /** + * 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); + } + + /** + * 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); + } +}; + +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(); +} + +inline bool operator!=(const Account &ac1, const Account &ac2) noexcept +{ + return !(ac1 == ac2); +} + +} // !malikania + +#endif // !MALIKANIA_ACCOUNT_HPP
--- a/libserver/malikania/dao-account.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libserver/malikania/dao-account.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,9 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "account.h" -#include "dao-account.h" -#include "database.h" +#include "account.hpp" +#include "dao-account.hpp" +#include "database.hpp" namespace malikania {
--- a/libserver/malikania/dao-account.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * dao-account.h -- database account management - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_DAO_ACCOUNT_H -#define MALIKANIA_DAO_ACCOUNT_H - -/** - * \file dao-account.h - * \brief Database account management. - */ - -#include <cstdint> -#include <vector> - -namespace malikania { - -class Database; -class Account; - -/** - * \brief Account DAO. - */ -class AccountDao { -private: - Database &m_database; - -public: - /** - * 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); - - /** - * 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); - - /** - * 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 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(); -}; - -} // !malikania - -#endif // !MALIKANIA_DAO_ACCOUNT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserver/malikania/dao-account.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,113 @@ +/* + * dao-account.hpp -- database account management + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_DAO_ACCOUNT_HPP +#define MALIKANIA_DAO_ACCOUNT_HPP + +/** + * \file dao-account.hpp + * \brief Database account management. + */ + +#include <cstdint> +#include <vector> + +namespace malikania { + +class Database; +class Account; + +/** + * \brief Account DAO. + */ +class AccountDao { +private: + Database &m_database; + +public: + /** + * 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); + + /** + * 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); + + /** + * 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 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(); +}; + +} // !malikania + +#endif // !MALIKANIA_DAO_ACCOUNT_HPP
--- a/libserver/malikania/database.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/libserver/malikania/database.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "database.h" +#include "database.hpp" namespace malikania {
--- a/libserver/malikania/database.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * database.h -- generic database loader - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef MALIKANIA_DATABASE_H -#define MALIKANIA_DATABASE_H - -/** - * \file database.h - * \brief Generic database loader. - */ - -#include <string> -#include <unordered_map> - -#include "dynlib.h" - -namespace malikania { - -/** - * \brief Generic database. - */ -class Database { -private: - 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); - - /** - * Close the database. - */ - ~Database(); - - /** - * Get the associated dynlib handle. - */ - inline Dynlib &handle() noexcept - { - return m_dso; - } -}; - -} // !malikania - -#endif // !MALIKANIA_DATABASE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserver/malikania/database.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,69 @@ +/* + * database.hpp -- generic database loader + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MALIKANIA_DATABASE_HPP +#define MALIKANIA_DATABASE_HPP + +/** + * \file database.hpp + * \brief Generic database loader. + */ + +#include <string> +#include <unordered_map> + +#include "dynlib.hpp" + +namespace malikania { + +/** + * \brief Generic database. + */ +class Database { +private: + 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); + + /** + * Close the database. + */ + ~Database(); + + /** + * Get the associated dynlib handle. + */ + inline Dynlib &handle() noexcept + { + return m_dso; + } +}; + +} // !malikania + +#endif // !MALIKANIA_DATABASE_HPP
--- a/libserver/malikania/dynlib.h Fri Jun 17 13:07:05 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,338 +0,0 @@ -/* - * dynlib.hpp -- portable shared library loader - * - * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef DYNLIB_HPP -#define DYNLIB_HPP - -/** - * \file dynlib.hpp - * \brief Portable shared library loader. - * \author David Demelier <markand@malikania.fr> - */ - -/** - * \page Dynlib Dynlib - * \brief Portable shared library loader. - * - * The dynlib module let you open shared libraries dynamically at runtime. - * - * ## Operating system support - * - * | System | Support | Remarks | - * |---------|---------|--------------------| - * | Apple | Ok | | - * | FreeBSD | Ok | | - * | Linux | Ok | Needs -ldl library | - * | Windows | Ok | | - * - * ## How to export symbols - * - * When you want to dynamically load symbols from your shared library, make sure they are in a `extern "C"` block, if - * not they will be [mangled][name-mangling]. - * - * Note, this does not mean that you can't write C++ code, it just mean that you can't use namespaces and function - * overloading. - * - * Example of **plugin.cpp**: - * - * ````cpp - * #include <iostream> - * - * #include "dynlib.hpp" - * - * extern "C" { - * - * DYNLIB_EXPORT void plugin_load() - * { - * std::cout << "Loading plugin" << std::endl; - * } - * - * DYNLIB_EXPORT void plugin_unload() - * { - * std::cout << "Unloading plugin" << std::endl; - * } - * - * } - * ```` - * - * The \ref DYNLIB_EXPORT macro is necessary on some platforms to be sure that symbol will be visible. Make sure you always - * add it before any function. - * - * To compile, see your compiler documentation or build system. For gcc you can use the following: - * - * ```` - * gcc -std=c++14 -shared plugin.cpp -o plugin.so - * ```` - * - * ## How to load the library - * - * The dynlib module will search for the library in various places, thus you can use relative paths names but be sure - * that the library can be found. Otherwise, just use an absolute path to the file. - * - * ````cpp - * #include <iostream> - * - * #include "dynlib.hpp" - * - * int main() - * { - * try { - * Dynlib dso("./plugin" DYNLIB_SUFFIX); - * } catch (const std::exception &ex) { - * std::cerr << ex.what() << std::endl; - * } - * - * return 0; - * } - * ```` - * - * ## How to load symbol - * - * The last part is symbol loading, you muse use raw C function pointer and the Dynlib::sym function. - * - * ````cpp - * #include <iostream> - * - * #include "dynlib.hpp" - * - * using PluginLoad = void (*)(); - * using PluginUnload = void (*)(); - * - * int main() - * { - * 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; - * } - * - * return 0; - * } - * ```` - * - * [name-mangling]: https://en.wikipedia.org/wiki/Name_mangling - */ - -#include <stdexcept> -#include <string> - -#if defined(_WIN32) -# include <Windows.h> -#else -# include <dlfcn.h> -#endif - -/** - * \brief Export the symbol. - * - * This is required on some platforms and you should put it before your function signature. - * - * \code{.cpp} - * extern "C" { - * - * DYNLIB_EXPORT void my_function() - * { - * } - * - * } - * \endcode - */ -#if defined(_WIN32) -# define DYNLIB_EXPORT __declspec(dllexport) -#else -# define DYNLIB_EXPORT -#endif - -/** - * \brief Usual suffix for the library. - * - * This macro expands to the suffix convention for this platform. - * - * \code{.cpp} - * Dynlib library("./myplugin" DYNLIB_SUFFIX); - * \endcode - * - * \note Don't use the suffix expanded value shown in Doxygen as it may be wrong. - */ -#if defined(_WIN32) -# define DYNLIB_SUFFIX ".dll" -#elif defined(__APPLE__) -# define DYNLIB_SUFFIX ".dylib" -#else -# define DYNLIB_SUFFIX ".so" -#endif - -namespace malikania { - -/** - * \class Dynlib - * \brief Load a dynamic module. - * - * This class is a portable wrapper to load shared libraries on supported systems. - */ -class Dynlib { -private: -#if defined(_WIN32) - using Handle = HMODULE; - using Sym = FARPROC; -#else - using Handle = void *; - using Sym = void *; -#endif - -public: - /** - * \brief Policy for symbol resolution. - */ - enum Policy { - Immediately, //!< load symbols immediately - Lazy //!< load symbols when needed - }; - -private: - Handle m_handle; - - Dynlib(const Dynlib &) = delete; - Dynlib &operator=(const Dynlib &) = delete; - - Dynlib(Dynlib &&) = delete; - Dynlib &operator=(Dynlib &&) = delete; - -#if defined(_WIN32) - 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); - - if (error) { - errmsg = std::string(error); - LocalFree(error); - } - - 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); - - /** - * 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); -}; - -#if defined(_WIN32) - -/* - * Windows implementation - * ------------------------------------------------------------------ - */ - -inline Dynlib::Dynlib(const std::string &path, Policy) -{ - m_handle = LoadLibraryA(path.c_str()); - - if (m_handle == nullptr) - throw std::runtime_error(error()); -} - -inline Dynlib::~Dynlib() -{ - FreeLibrary(m_handle); - m_handle = nullptr; -} - -template <typename T> -T Dynlib::sym(const std::string &name) -{ - Sym sym = GetProcAddress(m_handle, name.c_str()); - - if (sym == nullptr) - throw std::runtime_error(error()); - - return reinterpret_cast<T>(sym); -} - -#else - -/* - * Unix implementation - * ------------------------------------------------------------------ - */ - -inline Dynlib::Dynlib(const std::string &path, Policy policy) -{ - m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); - - if (m_handle == nullptr) - throw std::runtime_error(dlerror()); -} - -inline Dynlib::~Dynlib() -{ - dlclose(m_handle); - m_handle = nullptr; -} - -template <typename T> -T Dynlib::sym(const std::string &name) -{ - Sym sym = dlsym(m_handle, name.c_str()); - - if (sym == nullptr) - throw std::runtime_error(dlerror()); - - return reinterpret_cast<T>(sym); -} - -#endif - -} // !malikania - -#endif // !DYNLIB_HPP
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserver/malikania/dynlib.hpp Fri Jun 17 13:12:35 2016 +0200 @@ -0,0 +1,338 @@ +/* + * dynlib.hpp -- portable shared library loader + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DYNLIB_HPP +#define DYNLIB_HPP + +/** + * \file dynlib.hpp + * \brief Portable shared library loader. + * \author David Demelier <markand@malikania.fr> + */ + +/** + * \page Dynlib Dynlib + * \brief Portable shared library loader. + * + * The dynlib module let you open shared libraries dynamically at runtime. + * + * ## Operating system support + * + * | System | Support | Remarks | + * |---------|---------|--------------------| + * | Apple | Ok | | + * | FreeBSD | Ok | | + * | Linux | Ok | Needs -ldl library | + * | Windows | Ok | | + * + * ## How to export symbols + * + * When you want to dynamically load symbols from your shared library, make sure they are in a `extern "C"` block, if + * not they will be [mangled][name-mangling]. + * + * Note, this does not mean that you can't write C++ code, it just mean that you can't use namespaces and function + * overloading. + * + * Example of **plugin.cpp**: + * + * ````cpp + * #include <iostream> + * + * #include "dynlib.hpp" + * + * extern "C" { + * + * DYNLIB_EXPORT void plugin_load() + * { + * std::cout << "Loading plugin" << std::endl; + * } + * + * DYNLIB_EXPORT void plugin_unload() + * { + * std::cout << "Unloading plugin" << std::endl; + * } + * + * } + * ```` + * + * The \ref DYNLIB_EXPORT macro is necessary on some platforms to be sure that symbol will be visible. Make sure you always + * add it before any function. + * + * To compile, see your compiler documentation or build system. For gcc you can use the following: + * + * ```` + * gcc -std=c++14 -shared plugin.cpp -o plugin.so + * ```` + * + * ## How to load the library + * + * The dynlib module will search for the library in various places, thus you can use relative paths names but be sure + * that the library can be found. Otherwise, just use an absolute path to the file. + * + * ````cpp + * #include <iostream> + * + * #include "dynlib.hpp" + * + * int main() + * { + * try { + * Dynlib dso("./plugin" DYNLIB_SUFFIX); + * } catch (const std::exception &ex) { + * std::cerr << ex.what() << std::endl; + * } + * + * return 0; + * } + * ```` + * + * ## How to load symbol + * + * The last part is symbol loading, you muse use raw C function pointer and the Dynlib::sym function. + * + * ````cpp + * #include <iostream> + * + * #include "dynlib.hpp" + * + * using PluginLoad = void (*)(); + * using PluginUnload = void (*)(); + * + * int main() + * { + * 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; + * } + * + * return 0; + * } + * ```` + * + * [name-mangling]: https://en.wikipedia.org/wiki/Name_mangling + */ + +#include <stdexcept> +#include <string> + +#if defined(_WIN32) +# include <Windows.h> +#else +# include <dlfcn.h> +#endif + +/** + * \brief Export the symbol. + * + * This is required on some platforms and you should put it before your function signature. + * + * \code{.cpp} + * extern "C" { + * + * DYNLIB_EXPORT void my_function() + * { + * } + * + * } + * \endcode + */ +#if defined(_WIN32) +# define DYNLIB_EXPORT __declspec(dllexport) +#else +# define DYNLIB_EXPORT +#endif + +/** + * \brief Usual suffix for the library. + * + * This macro expands to the suffix convention for this platform. + * + * \code{.cpp} + * Dynlib library("./myplugin" DYNLIB_SUFFIX); + * \endcode + * + * \note Don't use the suffix expanded value shown in Doxygen as it may be wrong. + */ +#if defined(_WIN32) +# define DYNLIB_SUFFIX ".dll" +#elif defined(__APPLE__) +# define DYNLIB_SUFFIX ".dylib" +#else +# define DYNLIB_SUFFIX ".so" +#endif + +namespace malikania { + +/** + * \class Dynlib + * \brief Load a dynamic module. + * + * This class is a portable wrapper to load shared libraries on supported systems. + */ +class Dynlib { +private: +#if defined(_WIN32) + using Handle = HMODULE; + using Sym = FARPROC; +#else + using Handle = void *; + using Sym = void *; +#endif + +public: + /** + * \brief Policy for symbol resolution. + */ + enum Policy { + Immediately, //!< load symbols immediately + Lazy //!< load symbols when needed + }; + +private: + Handle m_handle; + + Dynlib(const Dynlib &) = delete; + Dynlib &operator=(const Dynlib &) = delete; + + Dynlib(Dynlib &&) = delete; + Dynlib &operator=(Dynlib &&) = delete; + +#if defined(_WIN32) + 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); + + if (error) { + errmsg = std::string(error); + LocalFree(error); + } + + 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); + + /** + * 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); +}; + +#if defined(_WIN32) + +/* + * Windows implementation + * ------------------------------------------------------------------ + */ + +inline Dynlib::Dynlib(const std::string &path, Policy) +{ + m_handle = LoadLibraryA(path.c_str()); + + if (m_handle == nullptr) + throw std::runtime_error(error()); +} + +inline Dynlib::~Dynlib() +{ + FreeLibrary(m_handle); + m_handle = nullptr; +} + +template <typename T> +T Dynlib::sym(const std::string &name) +{ + Sym sym = GetProcAddress(m_handle, name.c_str()); + + if (sym == nullptr) + throw std::runtime_error(error()); + + return reinterpret_cast<T>(sym); +} + +#else + +/* + * Unix implementation + * ------------------------------------------------------------------ + */ + +inline Dynlib::Dynlib(const std::string &path, Policy policy) +{ + m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); + + if (m_handle == nullptr) + throw std::runtime_error(dlerror()); +} + +inline Dynlib::~Dynlib() +{ + dlclose(m_handle); + m_handle = nullptr; +} + +template <typename T> +T Dynlib::sym(const std::string &name) +{ + Sym sym = dlsym(m_handle, name.c_str()); + + if (sym == nullptr) + throw std::runtime_error(dlerror()); + + return reinterpret_cast<T>(sym); +} + +#endif + +} // !malikania + +#endif // !DYNLIB_HPP
--- a/server/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/server/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,22 +1,22 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(mlk-server) - -add_executable(mlk-server main.cpp) -target_link_libraries(mlk-server libmlk-server) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(mlk-server) + +add_executable(mlk-server main.cpp) +target_link_libraries(mlk-server libmlk-server)
--- a/server/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/server/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,55 +1,55 @@ -/* - * main.cpp -- main server executable file - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <iostream> - -#include "malikania/account.h" -#include "malikania/dao-account.h" -#include "malikania/database.h" - -using namespace malikania; - -int main(int, char **) -{ - try { - Database database("./pgsql", { - { "user", "kingdom" }, - { "host", "localhost" }, - { "database", "kingdomdb" } - }); - - AccountDao act(database); - Account account; - - account.setId(2); - - 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; - } - - return 0; -} +/* + * main.cpp -- main server executable file + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <iostream> + +#include "malikania/account.hpp" +#include "malikania/dao-account.hpp" +#include "malikania/database.hpp" + +using namespace malikania; + +int main(int, char **) +{ + try { + Database database("./pgsql", { + { "user", "kingdom" }, + { "host", "localhost" }, + { "database", "kingdomdb" } + }); + + AccountDao act(database); + Account account; + + account.setId(2); + + 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; + } + + return 0; +}
--- a/tests/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,31 +1,31 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -project(test) - -# -# Meta target to build all tests. -# -add_custom_target( - tests - COMMENT "Building tests" -) - -add_subdirectory(libclient) -add_subdirectory(libcommon) -add_subdirectory(libserver) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +project(test) + +# +# Meta target to build all tests. +# +add_custom_target( + tests + COMMENT "Building tests" +) + +add_subdirectory(libclient) +add_subdirectory(libcommon) +add_subdirectory(libserver)
--- a/tests/libclient/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,39 +1,39 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -add_subdirectory(animation) -add_subdirectory(color) -add_subdirectory(font) -add_subdirectory(image) -add_subdirectory(line) -add_subdirectory(point) -add_subdirectory(rectangle) -add_subdirectory(size) -add_subdirectory(sprite) - -# JavaScript bindings -add_subdirectory(js-animation) -add_subdirectory(js-color) -add_subdirectory(js-font) -add_subdirectory(js-image) -add_subdirectory(js-line) -add_subdirectory(js-point) -add_subdirectory(js-rectangle) -add_subdirectory(js-size) -add_subdirectory(js-sprite) -add_subdirectory(js-window) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +add_subdirectory(animation) +add_subdirectory(color) +add_subdirectory(font) +add_subdirectory(image) +add_subdirectory(line) +add_subdirectory(point) +add_subdirectory(rectangle) +add_subdirectory(size) +add_subdirectory(sprite) + +# JavaScript bindings +add_subdirectory(js-animation) +add_subdirectory(js-color) +add_subdirectory(js-font) +add_subdirectory(js-image) +add_subdirectory(js-line) +add_subdirectory(js-point) +add_subdirectory(js-rectangle) +add_subdirectory(js-size) +add_subdirectory(js-sprite) +add_subdirectory(js-window)
--- a/tests/libclient/animation/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/animation/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,27 +1,27 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME animation - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/animations/margins.json - resources/images/margins.png - resources/sprites/margins.json -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + 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 Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/animation/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,104 +1,104 @@ -/* - * main.cpp -- test Animation - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <chrono> -#include <thread> -#include <exception> - -#include <gtest/gtest.h> - -#include <malikania/animation.h> -#include <malikania/animator.h> -#include <malikania/client-resources-loader.h> -#include <malikania/resources-locator.h> -#include <malikania/window.h> - -using namespace malikania; - -using namespace std::chrono_literals; - -namespace { - -Window window(400, 400); - -} // !namespace - -class TestAnimation : public testing::Test { -protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; - -public: - TestAnimation() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } -}; - -TEST_F(TestAnimation, standard) -{ - 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(); - } -} - -TEST_F(TestAnimation, draw) -{ - ElapsedTimer timer; - - 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); - - 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); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Animation + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <chrono> +#include <thread> +#include <exception> + +#include <gtest/gtest.h> + +#include <malikania/animation.hpp> +#include <malikania/animator.hpp> +#include <malikania/client-resources-loader.hpp> +#include <malikania/resources-locator.hpp> +#include <malikania/window.hpp> + +using namespace malikania; + +using namespace std::chrono_literals; + +namespace { + +Window window(400, 400); + +} // !namespace + +class TestAnimation : public testing::Test { +protected: + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; + +public: + TestAnimation() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } +}; + +TEST_F(TestAnimation, standard) +{ + 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(); + } +} + +TEST_F(TestAnimation, draw) +{ + ElapsedTimer timer; + + 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); + + 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); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/animation/resources/animations/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/animation/resources/animations/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,17 +1,17 @@ -{ - "sprite": "sprites/margins.json", - "frames": [ - { "delay": 500 }, - { "delay": 501 }, - { "delay": 502 }, - { "delay": 503 }, - { "delay": 504 }, - { "delay": 505 }, - { "delay": 506 }, - { "delay": 507 }, - { "delay": 508 }, - { "delay": 509 }, - { "delay": 510 }, - { "delay": 511 } - ] -} +{ + "sprite": "sprites/margins.json", + "frames": [ + { "delay": 500 }, + { "delay": 501 }, + { "delay": 502 }, + { "delay": 503 }, + { "delay": 504 }, + { "delay": 505 }, + { "delay": 506 }, + { "delay": 507 }, + { "delay": 508 }, + { "delay": 509 }, + { "delay": 510 }, + { "delay": 511 } + ] +}
--- a/tests/libclient/animation/resources/sprites/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/animation/resources/sprites/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -{ - "image": "images/margins.png", - "cell": [ 32, 32 ], - "margin": [ 4, 6 ], - "space": [ 2, 3 ] -} +{ + "image": "images/margins.png", + "cell": [ 32, 32 ], + "margin": [ 4, 6 ], + "space": [ 2, 3 ] +}
--- a/tests/libclient/color/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/color/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME color - LIBRARIES libclient - SOURCES main.cpp +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME color + LIBRARIES libclient + SOURCES main.cpp ) \ No newline at end of file
--- a/tests/libclient/color/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/color/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,351 +1,351 @@ -/* - * main.cpp -- test Color - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/color.h> - -using namespace malikania; - -/* - * Separate arguments - * ------------------------------------------------------------------ - */ - -TEST(Basic, black) -{ - Color c; - - 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}; - - 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}; - - 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}; - - 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}; - - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); -} - -/* - * Hexadecimal - * ------------------------------------------------------------------ - */ - -TEST(Hex, black) -{ - Color c{0xff000000}; - - 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}; - - 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}; - - 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}; - - 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}; - - ASSERT_EQ(0, c.red()); - ASSERT_EQ(0, c.green()); - ASSERT_EQ(255, c.blue()); - ASSERT_EQ(255, c.alpha()); -} - -/* - * Names - * ------------------------------------------------------------------ - * - * Test most famous. - */ - -TEST(Named, black) -{ - Color c{"black"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * #rrggbb - * ------------------------------------------------------------------ - * - * Test most famous. - */ - -TEST(FullRgb, black) -{ - Color c{"#000000"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * #rgb - * ------------------------------------------------------------------ - * - * Test most famous. - */ - -TEST(ShortRgb, black) -{ - Color c{"#000"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - 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"}; - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Color + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/color.hpp> + +using namespace malikania; + +/* + * Separate arguments + * ------------------------------------------------------------------ + */ + +TEST(Basic, black) +{ + Color c; + + 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}; + + 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}; + + 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}; + + 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}; + + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); +} + +/* + * Hexadecimal + * ------------------------------------------------------------------ + */ + +TEST(Hex, black) +{ + Color c{0xff000000}; + + 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}; + + 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}; + + 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}; + + 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}; + + ASSERT_EQ(0, c.red()); + ASSERT_EQ(0, c.green()); + ASSERT_EQ(255, c.blue()); + ASSERT_EQ(255, c.alpha()); +} + +/* + * Names + * ------------------------------------------------------------------ + * + * Test most famous. + */ + +TEST(Named, black) +{ + Color c{"black"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * #rrggbb + * ------------------------------------------------------------------ + * + * Test most famous. + */ + +TEST(FullRgb, black) +{ + Color c{"#000000"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * #rgb + * ------------------------------------------------------------------ + * + * Test most famous. + */ + +TEST(ShortRgb, black) +{ + Color c{"#000"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + 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"}; + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/font/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/font/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,25 +1,25 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME font - LIBRARIES libclient - SOURCES main.cpp - RESOURCES - resources/DejaVuSans.ttf -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME font + LIBRARIES libclient + SOURCES main.cpp + RESOURCES + resources/DejaVuSans.ttf +)
--- a/tests/libclient/font/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/font/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,128 +1,128 @@ -/* - * main.cpp -- test Font - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <chrono> -#include <thread> - -#include <gtest/gtest.h> - -#include <malikania/client-resources-loader.h> -#include <malikania/color.h> -#include <malikania/font.h> -#include <malikania/point.h> -#include <malikania/resources-locator.h> -#include <malikania/window.h> - -using namespace malikania; - -using namespace std::chrono_literals; - -namespace { - -Window window(400, 400); - -} // !namespace - -class TestFont : public testing::Test { -protected: - 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(); - } -}; - -TEST_F(TestFont, topleft) -{ - window.setDrawingColor(Color("white")); - window.drawText("top left", m_font, Point(10, 10)); - window.present(); - - std::this_thread::sleep_for(1s); -} - -TEST_F(TestFont, topright) -{ - 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(); - - std::this_thread::sleep_for(1s); -} - - -TEST_F(TestFont, bottomleft) -{ - 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(); - - std::this_thread::sleep_for(1s); -} - -TEST_F(TestFont, bottomright) -{ - 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(); - - std::this_thread::sleep_for(1s); -} - -TEST_F(TestFont, 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(); - - std::this_thread::sleep_for(1s); -} - -TEST_F(TestFont, center2) -{ - 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(); - - std::this_thread::sleep_for(3s); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Font + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <chrono> +#include <thread> + +#include <gtest/gtest.h> + +#include <malikania/client-resources-loader.hpp> +#include <malikania/color.hpp> +#include <malikania/font.hpp> +#include <malikania/point.hpp> +#include <malikania/resources-locator.hpp> +#include <malikania/window.hpp> + +using namespace malikania; + +using namespace std::chrono_literals; + +namespace { + +Window window(400, 400); + +} // !namespace + +class TestFont : public testing::Test { +protected: + 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(); + } +}; + +TEST_F(TestFont, topleft) +{ + window.setDrawingColor(Color("white")); + window.drawText("top left", m_font, Point(10, 10)); + window.present(); + + std::this_thread::sleep_for(1s); +} + +TEST_F(TestFont, topright) +{ + 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(); + + std::this_thread::sleep_for(1s); +} + + +TEST_F(TestFont, bottomleft) +{ + 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(); + + std::this_thread::sleep_for(1s); +} + +TEST_F(TestFont, bottomright) +{ + 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(); + + std::this_thread::sleep_for(1s); +} + +TEST_F(TestFont, 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(); + + std::this_thread::sleep_for(1s); +} + +TEST_F(TestFont, center2) +{ + 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(); + + std::this_thread::sleep_for(3s); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/image/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/image/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,28 +1,28 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -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 -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +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 +)
--- a/tests/libclient/image/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/image/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,125 +1,125 @@ -/* - * main.cpp -- test Image - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <chrono> -#include <thread> - -#include <gtest/gtest.h> - -#include <malikania/client-resources-loader.h> -#include <malikania/image.h> -#include <malikania/resources-locator.h> -#include <malikania/window.h> - -using namespace malikania; - -using namespace std::chrono_literals; - -namespace { - -Window window(400, 400); - -} // !namespace - -class TestImage : public testing::Test { -protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; - -public: - TestImage() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } -}; - -TEST_F(TestImage, image100x10) -{ - 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(); - } -} - -TEST_F(TestImage, image16x16) -{ - 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(); - } -} - -TEST_F(TestImage, image10x100) -{ - 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(); - } -} - -TEST_F(TestImage, notfound) -{ - try { - m_loader.loadImage("image-not-found"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * Draw - * ------------------------------------------------------------------ - */ - -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); - - window.clear(); - image.draw(window, Point(x, y)); - window.present(); - - std::this_thread::sleep_for(3s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Image + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <chrono> +#include <thread> + +#include <gtest/gtest.h> + +#include <malikania/client-resources-loader.hpp> +#include <malikania/image.hpp> +#include <malikania/resources-locator.hpp> +#include <malikania/window.hpp> + +using namespace malikania; + +using namespace std::chrono_literals; + +namespace { + +Window window(400, 400); + +} // !namespace + +class TestImage : public testing::Test { +protected: + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; + +public: + TestImage() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } +}; + +TEST_F(TestImage, image100x10) +{ + 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(); + } +} + +TEST_F(TestImage, image16x16) +{ + 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(); + } +} + +TEST_F(TestImage, image10x100) +{ + 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(); + } +} + +TEST_F(TestImage, notfound) +{ + try { + m_loader.loadImage("image-not-found"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * Draw + * ------------------------------------------------------------------ + */ + +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); + + window.clear(); + image.draw(window, Point(x, y)); + window.present(); + + std::this_thread::sleep_for(3s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/js-animation/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-animation/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,12 +21,12 @@ #include <gtest/gtest.h> -#include <malikania/client-resources-loader.h> -#include <malikania/elapsed-timer.h> -#include <malikania/js-animation.h> -#include <malikania/js-animator.h> -#include <malikania/js-window.h> -#include <malikania/resources-locator.h> +#include <malikania/client-resources-loader.hpp> +#include <malikania/elapsed-timer.hpp> +#include <malikania/js-animation.hpp> +#include <malikania/js-animator.hpp> +#include <malikania/js-window.hpp> +#include <malikania/resources-locator.hpp> using namespace malikania;
--- a/tests/libclient/js-animation/resources/animations/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-animation/resources/animations/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,17 +1,17 @@ -{ - "sprite": "sprites/margins.json", - "frames": [ - { "delay": 500 }, - { "delay": 501 }, - { "delay": 502 }, - { "delay": 503 }, - { "delay": 504 }, - { "delay": 505 }, - { "delay": 506 }, - { "delay": 507 }, - { "delay": 508 }, - { "delay": 509 }, - { "delay": 510 }, - { "delay": 511 } - ] -} +{ + "sprite": "sprites/margins.json", + "frames": [ + { "delay": 500 }, + { "delay": 501 }, + { "delay": 502 }, + { "delay": 503 }, + { "delay": 504 }, + { "delay": 505 }, + { "delay": 506 }, + { "delay": 507 }, + { "delay": 508 }, + { "delay": 509 }, + { "delay": 510 }, + { "delay": 511 } + ] +}
--- a/tests/libclient/js-animation/resources/sprites/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-animation/resources/sprites/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -{ - "image": "images/margins.png", - "cell": [ 32, 32 ], - "margin": [ 4, 6 ], - "space": [ 2, 3 ] -} +{ + "image": "images/margins.png", + "cell": [ 32, 32 ], + "margin": [ 4, 6 ], + "space": [ 2, 3 ] +}
--- a/tests/libclient/js-color/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-color/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <malikania/js-color.h> +#include <malikania/js-color.hpp> using namespace malikania;
--- a/tests/libclient/js-font/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-font/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,10 +21,10 @@ #include <gtest/gtest.h> -#include <malikania/client-resources-loader.h> -#include <malikania/js-font.h> -#include <malikania/js-window.h> -#include <malikania/resources-locator.h> +#include <malikania/client-resources-loader.hpp> +#include <malikania/js-font.hpp> +#include <malikania/js-window.hpp> +#include <malikania/resources-locator.hpp> using namespace malikania;
--- a/tests/libclient/js-image/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-image/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,10 +21,10 @@ #include <gtest/gtest.h> -#include <malikania/client-resources-loader.h> -#include <malikania/js-image.h> -#include <malikania/js-window.h> -#include <malikania/resources-locator.h> +#include <malikania/client-resources-loader.hpp> +#include <malikania/js-image.hpp> +#include <malikania/js-window.hpp> +#include <malikania/resources-locator.hpp> using namespace malikania;
--- a/tests/libclient/js-line/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-line/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <malikania/js-line.h> +#include <malikania/js-line.hpp> using namespace malikania;
--- a/tests/libclient/js-point/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-point/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <malikania/js-point.h> +#include <malikania/js-point.hpp> using namespace malikania;
--- a/tests/libclient/js-rectangle/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-rectangle/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <malikania/js-rectangle.h> +#include <malikania/js-rectangle.hpp> using namespace malikania;
--- a/tests/libclient/js-size/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-size/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <malikania/js-size.h> +#include <malikania/js-size.hpp> using namespace malikania;
--- a/tests/libclient/js-sprite/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-sprite/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,11 +21,11 @@ #include <gtest/gtest.h> -#include <malikania/client-resources-loader.h> -#include <malikania/js-image.h> -#include <malikania/js-sprite.h> -#include <malikania/js-window.h> -#include <malikania/resources-locator.h> +#include <malikania/client-resources-loader.hpp> +#include <malikania/js-image.hpp> +#include <malikania/js-sprite.hpp> +#include <malikania/js-window.hpp> +#include <malikania/resources-locator.hpp> using namespace malikania;
--- a/tests/libclient/js-sprite/resources/sprites/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-sprite/resources/sprites/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -{ - "image": "images/margins.png", - "cell": [ 32, 32 ], - "margin": [ 4, 6 ], - "space": [ 2, 3 ] -} +{ + "image": "images/margins.png", + "cell": [ 32, 32 ], + "margin": [ 4, 6 ], + "space": [ 2, 3 ] +}
--- a/tests/libclient/js-window/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/js-window/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -21,7 +21,7 @@ #include <gtest/gtest.h> -#include <malikania/js-window.h> +#include <malikania/js-window.hpp> using namespace malikania;
--- a/tests/libclient/line/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/line/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME line - LIBRARIES libclient - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME line + LIBRARIES libclient + SOURCES main.cpp +)
--- a/tests/libclient/line/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/line/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,73 +1,73 @@ -/* - * main.cpp -- test Line - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/line.h> - -using namespace malikania; - -TEST(Basics, none) -{ - Line line; - - 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); - - 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; - - ASSERT_EQ(line1, line2); -} - -TEST(Basics, operatorEq1) -{ - Line line1(10, 20, 30, 40); - Line line2(10, 20, 30, 40); - - 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)); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Line + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/line.hpp> + +using namespace malikania; + +TEST(Basics, none) +{ + Line line; + + 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); + + 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; + + ASSERT_EQ(line1, line2); +} + +TEST(Basics, operatorEq1) +{ + Line line1(10, 20, 30, 40); + Line line2(10, 20, 30, 40); + + 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)); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/point/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/point/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME point - LIBRARIES libclient - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME point + LIBRARIES libclient + SOURCES main.cpp +)
--- a/tests/libclient/point/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/point/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,67 +1,67 @@ -/* - * main.cpp -- test Point - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/point.h> - -using namespace malikania; - -TEST(Basics, none) -{ - Point point; - - ASSERT_EQ(0, point.x()); - ASSERT_EQ(0, point.y()); -} - -TEST(Basics, standard) -{ - Point point(10, 20); - - ASSERT_EQ(10, point.x()); - ASSERT_EQ(20, point.y()); -} - -TEST(Basics, operatorEq) -{ - Point point1, point2; - - ASSERT_EQ(point1, point2); -} - -TEST(Basics, operatorEq1) -{ - Point point1(10, 20); - Point point2(10, 20); - - ASSERT_EQ(point1, point2); -} - -TEST(Basics, operatorNeq) -{ - ASSERT_NE(Point(10), Point(20)); - ASSERT_NE(Point(10, 10), Point(10, 20)); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Point + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/point.hpp> + +using namespace malikania; + +TEST(Basics, none) +{ + Point point; + + ASSERT_EQ(0, point.x()); + ASSERT_EQ(0, point.y()); +} + +TEST(Basics, standard) +{ + Point point(10, 20); + + ASSERT_EQ(10, point.x()); + ASSERT_EQ(20, point.y()); +} + +TEST(Basics, operatorEq) +{ + Point point1, point2; + + ASSERT_EQ(point1, point2); +} + +TEST(Basics, operatorEq1) +{ + Point point1(10, 20); + Point point2(10, 20); + + ASSERT_EQ(point1, point2); +} + +TEST(Basics, operatorNeq) +{ + ASSERT_NE(Point(10), Point(20)); + ASSERT_NE(Point(10, 10), Point(10, 20)); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/rectangle/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/rectangle/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME rectangle - LIBRARIES libclient - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME rectangle + LIBRARIES libclient + SOURCES main.cpp +)
--- a/tests/libclient/rectangle/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/rectangle/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,81 +1,81 @@ -/* - * main.cpp -- test Rectangle - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/rectangle.h> - -using namespace malikania; - -TEST(Basics, none) -{ - Rectangle rectangle; - - 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()); -} - -TEST(Basics, standard) -{ - 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()); -} - -TEST(Basics, operatorEq) -{ - Rectangle rectangle1, rectangle2; - - ASSERT_EQ(rectangle1, rectangle2); -} - -TEST(Basics, operatorEq1) -{ - Rectangle rectangle1(10, 20, 30, 40); - Rectangle rectangle2(10, 20, 30, 40); - - 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)); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Rectangle + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/rectangle.hpp> + +using namespace malikania; + +TEST(Basics, none) +{ + Rectangle rectangle; + + 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()); +} + +TEST(Basics, standard) +{ + 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()); +} + +TEST(Basics, operatorEq) +{ + Rectangle rectangle1, rectangle2; + + ASSERT_EQ(rectangle1, rectangle2); +} + +TEST(Basics, operatorEq1) +{ + Rectangle rectangle1(10, 20, 30, 40); + Rectangle rectangle2(10, 20, 30, 40); + + 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)); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/size/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/size/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME size - LIBRARIES libclient - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME size + LIBRARIES libclient + SOURCES main.cpp +)
--- a/tests/libclient/size/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/size/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,74 +1,74 @@ -/* - * main.cpp -- test Size - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/size.h> - -using namespace malikania; - -TEST(Basics, none) -{ - Size size; - - 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()); -} - -TEST(Basics, standard) -{ - Size size(10, 20); - - ASSERT_EQ(10U, size.width()); - ASSERT_EQ(20U, size.height()); -} - -TEST(Basics, operatorEq) -{ - Size size1, size2; - - ASSERT_EQ(size1, size2); -} - -TEST(Basics, operatorEq1) -{ - Size size1(10, 20); - Size size2(10, 20); - - ASSERT_EQ(size1, size2); -} - -TEST(Basics, operatorNeq) -{ - ASSERT_NE(Size(10), Size(20)); - ASSERT_NE(Size(10, 10), Size(10, 20)); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Size + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/size.hpp> + +using namespace malikania; + +TEST(Basics, none) +{ + Size size; + + 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()); +} + +TEST(Basics, standard) +{ + Size size(10, 20); + + ASSERT_EQ(10U, size.width()); + ASSERT_EQ(20U, size.height()); +} + +TEST(Basics, operatorEq) +{ + Size size1, size2; + + ASSERT_EQ(size1, size2); +} + +TEST(Basics, operatorEq1) +{ + Size size1(10, 20); + Size size2(10, 20); + + ASSERT_EQ(size1, size2); +} + +TEST(Basics, operatorNeq) +{ + ASSERT_NE(Size(10), Size(20)); + ASSERT_NE(Size(10, 10), Size(10, 20)); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/sprite/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,36 +1,36 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -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 -) - +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +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 +) +
--- a/tests/libclient/sprite/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,194 +1,194 @@ -/* - * main.cpp -- test Sprite - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <chrono> -#include <thread> -#include <exception> - -#include <gtest/gtest.h> - -#include <malikania/client-resources-loader.h> -#include <malikania/resources-locator.h> -#include <malikania/sprite.h> -#include <malikania/window.h> - -using namespace malikania; - -using namespace std::chrono_literals; - -namespace { - -Window window(400, 400); - -} // !namespace - -class TestSprite : public testing::Test { -protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; - -public: - TestSprite() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } -}; - -/* - * Missing properties - * ------------------------------------------------------------------ - */ - -TEST_F(TestSprite, missingPropertyImage) -{ - try { - m_loader.loadSprite("sprites/no-property-image.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -TEST_F(TestSprite, missingPropertyCell) -{ - try { - m_loader.loadSprite("sprites/no-property-cell.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * Invalid properties - * ------------------------------------------------------------------ - */ - -TEST_F(TestSprite, imageNotString) -{ - try { - m_loader.loadSprite("sprites/property-image-not-string.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -TEST_F(TestSprite, cellNotArray) -{ - try { - m_loader.loadSprite("sprites/property-cell-not-array.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -TEST_F(TestSprite, cellNotArray2) -{ - try { - m_loader.loadSprite("sprites/property-cell-not-array2.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * Other errors - * ------------------------------------------------------------------ - */ - -TEST_F(TestSprite, imageNotFound) -{ - try { - m_loader.loadSprite("sprites/image-not-found.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -TEST_F(TestSprite, notObject) -{ - try { - m_loader.loadSprite("sprites/not-object.json"); - - FAIL() << "exception expected"; - } catch (const std::exception &) { - } -} - -/* - * Valid sprites - * ------------------------------------------------------------------ - */ - -TEST_F(TestSprite, standard) -{ - 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(); - } -} - -TEST_F(TestSprite, margins) -{ - 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(); - } -} - -TEST_F(TestSprite, draw) -{ - try { - Sprite sprite = m_loader.loadSprite("sprites/margins.json"); - - unsigned total = sprite.rows() * sprite.columns(); - - 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(); - - std::this_thread::sleep_for(1s); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Sprite + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <chrono> +#include <thread> +#include <exception> + +#include <gtest/gtest.h> + +#include <malikania/client-resources-loader.hpp> +#include <malikania/resources-locator.hpp> +#include <malikania/sprite.hpp> +#include <malikania/window.hpp> + +using namespace malikania; + +using namespace std::chrono_literals; + +namespace { + +Window window(400, 400); + +} // !namespace + +class TestSprite : public testing::Test { +protected: + ResourcesLocatorDirectory m_locator; + ClientResourcesLoader m_loader; + +public: + TestSprite() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { + } +}; + +/* + * Missing properties + * ------------------------------------------------------------------ + */ + +TEST_F(TestSprite, missingPropertyImage) +{ + try { + m_loader.loadSprite("sprites/no-property-image.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +TEST_F(TestSprite, missingPropertyCell) +{ + try { + m_loader.loadSprite("sprites/no-property-cell.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * Invalid properties + * ------------------------------------------------------------------ + */ + +TEST_F(TestSprite, imageNotString) +{ + try { + m_loader.loadSprite("sprites/property-image-not-string.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +TEST_F(TestSprite, cellNotArray) +{ + try { + m_loader.loadSprite("sprites/property-cell-not-array.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +TEST_F(TestSprite, cellNotArray2) +{ + try { + m_loader.loadSprite("sprites/property-cell-not-array2.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * Other errors + * ------------------------------------------------------------------ + */ + +TEST_F(TestSprite, imageNotFound) +{ + try { + m_loader.loadSprite("sprites/image-not-found.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +TEST_F(TestSprite, notObject) +{ + try { + m_loader.loadSprite("sprites/not-object.json"); + + FAIL() << "exception expected"; + } catch (const std::exception &) { + } +} + +/* + * Valid sprites + * ------------------------------------------------------------------ + */ + +TEST_F(TestSprite, standard) +{ + 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(); + } +} + +TEST_F(TestSprite, margins) +{ + 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(); + } +} + +TEST_F(TestSprite, draw) +{ + try { + Sprite sprite = m_loader.loadSprite("sprites/margins.json"); + + unsigned total = sprite.rows() * sprite.columns(); + + 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(); + + std::this_thread::sleep_for(1s); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libclient/sprite/resources/sprites/image-not-found.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/image-not-found.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -{ - "image": "does-not-exist.png", - "cell": [ 0, 0 ] -} +{ + "image": "does-not-exist.png", + "cell": [ 0, 0 ] +}
--- a/tests/libclient/sprite/resources/sprites/margins.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/margins.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,6 +1,6 @@ -{ - "image": "images/margins.png", - "cell": [ 32, 32 ], - "margin": [ 4, 6 ], - "space": [ 2, 3 ] -} +{ + "image": "images/margins.png", + "cell": [ 32, 32 ], + "margin": [ 4, 6 ], + "space": [ 2, 3 ] +}
--- a/tests/libclient/sprite/resources/sprites/no-property-cell.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/no-property-cell.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,3 +1,3 @@ -{ - "image": "images/mokodemo.png" -} +{ + "image": "images/mokodemo.png" +}
--- a/tests/libclient/sprite/resources/sprites/no-property-image.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/no-property-image.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,3 +1,3 @@ -{ - "cell": [ 16, 16 ] -} +{ + "cell": [ 16, 16 ] +}
--- a/tests/libclient/sprite/resources/sprites/not-object.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/not-object.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,2 +1,2 @@ -[ -] +[ +]
--- a/tests/libclient/sprite/resources/sprites/property-cell-not-array.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/property-cell-not-array.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -{ - "image": "images/mokodemo.png", - "cell": "hello" -} +{ + "image": "images/mokodemo.png", + "cell": "hello" +}
--- a/tests/libclient/sprite/resources/sprites/property-cell-not-array2.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/property-cell-not-array2.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -{ - "image": "images/mokodemo.png", - "cell": [ true, false ] -} +{ + "image": "images/mokodemo.png", + "cell": [ true, false ] +}
--- a/tests/libclient/sprite/resources/sprites/property-image-not-string.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/property-image-not-string.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -{ - "image": 123, - "cell": [ 0, 0 ] -} +{ + "image": 123, + "cell": [ 0, 0 ] +}
--- a/tests/libclient/sprite/resources/sprites/simple.json Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libclient/sprite/resources/sprites/simple.json Fri Jun 17 13:12:35 2016 +0200 @@ -1,4 +1,4 @@ -{ - "image": "images/mokodemo.png", - "cell": [ 300, 300 ] -} +{ + "image": "images/mokodemo.png", + "cell": [ 300, 300 ] +}
--- a/tests/libcommon/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,21 +1,21 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -add_subdirectory(elapsed-timer) -add_subdirectory(js-elapsed-timer) -add_subdirectory(util) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +add_subdirectory(elapsed-timer) +add_subdirectory(js-elapsed-timer) +add_subdirectory(util)
--- a/tests/libcommon/elapsed-timer/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/elapsed-timer/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME elapsedtimer - LIBRARIES libcommon - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME elapsedtimer + LIBRARIES libcommon + SOURCES main.cpp +)
--- a/tests/libcommon/elapsed-timer/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/elapsed-timer/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,100 +1,100 @@ -/* - * main.cpp -- test ElapsedTimer - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <thread> - -#include <gtest/gtest.h> - -#include <malikania/elapsed-timer.h> - -using namespace malikania; -using namespace std::chrono_literals; - -/* - * For all tests, we tolerate 30 ms because some systems have bigger lags. - */ -static constexpr int margin = 30; - -class TestElapsedTimer : public testing::Test { -protected: - 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) << "]"; - } - } -}; - -TEST_F(TestElapsedTimer, standard) -{ - std::this_thread::sleep_for(300ms); - - assertRange(m_timer.elapsed(), 300); -} - -TEST_F(TestElapsedTimer, reset) -{ - std::this_thread::sleep_for(300ms); - - m_timer.reset(); - - 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); - - m_timer.pause(); - - std::this_thread::sleep_for(5ms); - - m_timer.restart(); - - std::this_thread::sleep_for(6ms); - - assertRange(m_timer.elapsed(), 16); -} - -TEST_F(TestElapsedTimer, doublecheck) -{ - std::this_thread::sleep_for(50ms); - - (void)m_timer.elapsed(); - - std::this_thread::sleep_for(50ms); - - assertRange(m_timer.elapsed(), 100); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test ElapsedTimer + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <thread> + +#include <gtest/gtest.h> + +#include <malikania/elapsed-timer.hpp> + +using namespace malikania; +using namespace std::chrono_literals; + +/* + * For all tests, we tolerate 30 ms because some systems have bigger lags. + */ +static constexpr int margin = 30; + +class TestElapsedTimer : public testing::Test { +protected: + 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) << "]"; + } + } +}; + +TEST_F(TestElapsedTimer, standard) +{ + std::this_thread::sleep_for(300ms); + + assertRange(m_timer.elapsed(), 300); +} + +TEST_F(TestElapsedTimer, reset) +{ + std::this_thread::sleep_for(300ms); + + m_timer.reset(); + + 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); + + m_timer.pause(); + + std::this_thread::sleep_for(5ms); + + m_timer.restart(); + + std::this_thread::sleep_for(6ms); + + assertRange(m_timer.elapsed(), 16); +} + +TEST_F(TestElapsedTimer, doublecheck) +{ + std::this_thread::sleep_for(50ms); + + (void)m_timer.elapsed(); + + std::this_thread::sleep_for(50ms); + + assertRange(m_timer.elapsed(), 100); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}
--- a/tests/libcommon/js-elapsed-timer/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/js-elapsed-timer/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -20,7 +20,7 @@ #include <thread> -#include <malikania/js-elapsed-timer.h> +#include <malikania/js-elapsed-timer.hpp> using namespace malikania;
--- a/tests/libcommon/util/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/util/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME util - LIBRARIES libcommon - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME util + LIBRARIES libcommon + SOURCES main.cpp +)
--- a/tests/libcommon/util/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libcommon/util/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,107 +1,107 @@ -/* - * main.cpp -- test util - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <gtest/gtest.h> - -#include <malikania/util.h> - -using namespace malikania; - -/* - * util::clamp - * ------------------------------------------------------------------ - */ - -TEST(Clamp, normal) -{ - ASSERT_EQ(5, util::clamp(5, 0, 10)); -} - -TEST(Clamp, minimum) -{ - ASSERT_EQ(0, util::clamp(0, 0, 10)); -} - -TEST(Clamp, maximum) -{ - ASSERT_EQ(10, util::clamp(10, 0, 10)); -} - -TEST(Clamp, less) -{ - ASSERT_EQ(0, util::clamp(-10, 0, 10)); -} - -TEST(Clamp, higher) -{ - ASSERT_EQ(10, util::clamp(20, 0, 10)); -} - -/* - * util::netsplit - * ------------------------------------------------------------------ - */ - -TEST(Netsplit, simple) -{ - 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()); -} - -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); - - 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); - - 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); - - 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); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test util + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <gtest/gtest.h> + +#include <malikania/util.hpp> + +using namespace malikania; + +/* + * util::clamp + * ------------------------------------------------------------------ + */ + +TEST(Clamp, normal) +{ + ASSERT_EQ(5, util::clamp(5, 0, 10)); +} + +TEST(Clamp, minimum) +{ + ASSERT_EQ(0, util::clamp(0, 0, 10)); +} + +TEST(Clamp, maximum) +{ + ASSERT_EQ(10, util::clamp(10, 0, 10)); +} + +TEST(Clamp, less) +{ + ASSERT_EQ(0, util::clamp(-10, 0, 10)); +} + +TEST(Clamp, higher) +{ + ASSERT_EQ(10, util::clamp(20, 0, 10)); +} + +/* + * util::netsplit + * ------------------------------------------------------------------ + */ + +TEST(Netsplit, simple) +{ + 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()); +} + +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); + + 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); + + 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); + + 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); + + return RUN_ALL_TESTS(); +}
--- a/tests/libserver/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libserver/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,20 +1,20 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -add_subdirectory(id) -add_subdirectory(dao-account) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +add_subdirectory(id) +add_subdirectory(dao-account)
--- a/tests/libserver/dao-account/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libserver/dao-account/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -22,9 +22,9 @@ #include <sysconfig-tests.h> -#include <malikania/account.h> -#include <malikania/dao-account.h> -#include <malikania/database.h> +#include <malikania/account.hpp> +#include <malikania/dao-account.hpp> +#include <malikania/database.hpp> using namespace malikania;
--- a/tests/libserver/id/CMakeLists.txt Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libserver/id/CMakeLists.txt Fri Jun 17 13:12:35 2016 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for malikania -# -# Copyright (c) 2013-2016 Malikania Authors -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -malikania_create_test( - NAME id - LIBRARIES libcommon - SOURCES main.cpp -) +# +# CMakeLists.txt -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +malikania_create_test( + NAME id + LIBRARIES libcommon + SOURCES main.cpp +)
--- a/tests/libserver/id/main.cpp Fri Jun 17 13:07:05 2016 +0200 +++ b/tests/libserver/id/main.cpp Fri Jun 17 13:12:35 2016 +0200 @@ -1,171 +1,171 @@ -/* - * main.cpp -- test Id - * - * Copyright (c) 2013-2016 Malikania Authors - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <cstdint> -#include <thread> - -#include <gtest/gtest.h> - -#include <malikania/id.h> - -using namespace malikania; - -/* -------------------------------------------------------- - * Basic use case - * -------------------------------------------------------- */ - -class TestId : public testing::Test { -protected: - IdGen<unsigned> m_idgen; - -public: - ~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()); -} - -TEST_F(TestId, reset) -{ - m_idgen.next(); - m_idgen.next(); - m_idgen.next(); - - m_idgen.reset(); - - 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); - - /* - * 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); - - /* - * 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()); -} - -/* -------------------------------------------------------- - * Id RAII class - * -------------------------------------------------------- */ - -TEST(IdLocker, basic) -{ - IdGen<int8_t> gen; - Id<int8_t> id(gen); - - ASSERT_EQ(0, id); -} - -TEST(IdLocker, two) -{ - IdGen<int8_t> gen; - Id<int8_t> id(gen); - Id<int8_t> id2(gen); - - ASSERT_EQ(0, id); - ASSERT_EQ(1, id2); -} - -TEST(IdLocker, already) -{ - IdGen<int8_t> gen; - Id<int8_t> id(gen, gen.next()); - - ASSERT_EQ(0, id); -} - -/* -------------------------------------------------------- - * Limit test - * -------------------------------------------------------- */ - -TEST(Limits, max) -{ - 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(); - } - - ASSERT_EQ(126, last); -} - -TEST(Limits, fail) -{ - IdGen<int8_t> idgen; - int8_t last; - - try { - for (int i = 0; i < 200; ++i) { - last = idgen.next(); - } - - FAIL() << "Exception expected"; - } catch (const std::exception &ex) { - } - - ASSERT_EQ(126, last); -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} +/* + * main.cpp -- test Id + * + * Copyright (c) 2013-2016 Malikania Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cstdint> +#include <thread> + +#include <gtest/gtest.h> + +#include <malikania/id.hpp> + +using namespace malikania; + +/* -------------------------------------------------------- + * Basic use case + * -------------------------------------------------------- */ + +class TestId : public testing::Test { +protected: + IdGen<unsigned> m_idgen; + +public: + ~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()); +} + +TEST_F(TestId, reset) +{ + m_idgen.next(); + m_idgen.next(); + m_idgen.next(); + + m_idgen.reset(); + + 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); + + /* + * 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); + + /* + * 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()); +} + +/* -------------------------------------------------------- + * Id RAII class + * -------------------------------------------------------- */ + +TEST(IdLocker, basic) +{ + IdGen<int8_t> gen; + Id<int8_t> id(gen); + + ASSERT_EQ(0, id); +} + +TEST(IdLocker, two) +{ + IdGen<int8_t> gen; + Id<int8_t> id(gen); + Id<int8_t> id2(gen); + + ASSERT_EQ(0, id); + ASSERT_EQ(1, id2); +} + +TEST(IdLocker, already) +{ + IdGen<int8_t> gen; + Id<int8_t> id(gen, gen.next()); + + ASSERT_EQ(0, id); +} + +/* -------------------------------------------------------- + * Limit test + * -------------------------------------------------------- */ + +TEST(Limits, max) +{ + 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(); + } + + ASSERT_EQ(126, last); +} + +TEST(Limits, fail) +{ + IdGen<int8_t> idgen; + int8_t last; + + try { + for (int i = 0; i < 200; ++i) { + last = idgen.next(); + } + + FAIL() << "Exception expected"; + } catch (const std::exception &ex) { + } + + ASSERT_EQ(126, last); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}