diff --git a/.travis.yml b/.travis.yml index e593d94..51965cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,12 +76,7 @@ before_script: - popd script: - - VERBOSE=1 cmake --build build - -after_success: - - pushd build - - GTEST_COLOR=1 ctest --verbose - - popd + - VERBOSE=1 cmake --build build && pushd build && GTEST_COLOR=1 ctest --verbose && popd notifications: slack: diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5d8f5b6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [unreleased] +### Added + - Custom plugin loaders (old version supported only shared libraries). + +### Changed + - Interface and implementation separation. + - Changed plugin API. + - Fixed MinGW build. + +[unreleased]: https://github.com/georgievlab/CeCe-core/compare/v0.6.0...HEAD diff --git a/CMake/Functions.cmake b/CMake/Functions.cmake new file mode 100644 index 0000000..f949aae --- /dev/null +++ b/CMake/Functions.cmake @@ -0,0 +1,128 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +## +## Add CeCe test. +## NAME: Test name +## +function (cece_add_test NAME) + if (NOT CECE_TESTS_BUILD) + return () + endif () + + set(FULLNAME "cece-${NAME}_test") + + include(CMakeParseArguments) + cmake_parse_arguments(ARG "" "" "SOURCES;LIBRARIES" ${ARGN}) + + # Create executable + add_executable(${FULLNAME} + ${ARG_SOURCES} + ) + + # Properties + set_target_properties(${FULLNAME} PROPERTIES + CXX_STANDARD 11 + CXX_EXTENSIONS Off + CXX_STANDARD_REQUIRED On + ) + + # Libraries + target_link_libraries(${FULLNAME} + PRIVATE cece + PRIVATE ${ARG_LIBRARIES} + PRIVATE gtest_main + ) + + if (CMAKE_COMPILER_IS_GNUCXX AND CECE_TESTS_BUILD AND CECE_COVERAGE) + target_compile_options(${FULLNAME} PRIVATE --coverage) + target_link_libraries(${FULLNAME} PRIVATE --coverage) + endif () + + # Register test + add_test( + NAME ${FULLNAME} + COMMAND ${FULLNAME} + WORKING_DIRECTORY $ + ) + + if (WIN32 OR MINGW) + # Windows doen't support rpath, so we need to copy the main library to the test executable + add_custom_command(TARGET ${FULLNAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + ) + endif () +endfunction () + +# ######################################################################### # + +## +## Initialize GIT submodule +## PATH: Submodule path +## [CHECK]: Path to tested file in submodule (default CMakeLists.txt) +## +function(cece_init_submodule PATH) + if (ARGC GREATER 1) + set(TEST_PATH "${PATH}/${ARGV1}") + else () + set(TEST_PATH "${PATH}/CMakeLists.txt") + endif () + + # Check if file exists + if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PATH}") + find_package(Git REQUIRED) + execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${PATH} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif () +endfunction () + +# ######################################################################### # + +## +## Initialize vendor submodule (in `vendor` directory). +## PATH: Vendor submodule name +## [CHECK]: Path to tested file in submodule (default CMakeLists.txt) +## +function(cece_init_vendor PATH) + cece_init_submodule(vendor/${PATH} ${ARGN}) +endfunction () + +# ######################################################################### # + +## +## Enable CCACHE for given directory. +## DIRECTORY: Cache directory. +## +function (cece_enable_ccache) + find_program(CCACHE_FOUND ccache) + if (CCACHE_FOUND) + set_property(DIRECTORY ${DIRECTORY} PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(DIRECTORY ${DIRECTORY} PROPERTY RULE_LAUNCH_LINK ccache) + endif () +endfunction () + +# ######################################################################### # diff --git a/CMakeLists.txt b/CMakeLists.txt index 5213778..8b92537 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,16 @@ cmake_minimum_required(VERSION 3.1) # ######################################################################### # project(cece - VERSION 0.6.0 + VERSION 0.7.0 LANGUAGES CXX ) # ######################################################################### # +include(CMake/Functions.cmake) + +# ######################################################################### # + # Options option(CECE_RENDER "Enable simulation rendering (vizualization support)" On) option(CECE_RENDER_CHECK_ERRORS "Enable renderer errors checking." Off) @@ -52,6 +56,11 @@ if (APPLE) set(MACOSX_VERSION_MIN "10.9" CACHE STRING "Minimum version of MacOS X to support") endif () +# Allow to enable code coverage, only for tests and GCC +if (CMAKE_COMPILER_IS_GNUCXX AND CECE_TESTS_BUILD) + option(CECE_COVERAGE "Enable code coverage generation for tests" Off) +endif () + # ######################################################################### # # Build unit tests @@ -59,13 +68,7 @@ if (CECE_TESTS_BUILD) enable_testing() # Init google test submodule - if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/googletest/CMakeLists.txt") - find_package(Git REQUIRED) - execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive vendor/googletest - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - endif () + cece_init_vendor(googletest) message(STATUS "Build unit tests") set(BUILD_GMOCK Off CACHE BOOL "" FORCE) @@ -75,21 +78,11 @@ if (CECE_TESTS_BUILD) add_subdirectory(vendor/googletest) target_include_directories(gtest INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/googletest/include) - find_program(CCACHE_FOUND ccache) - if (CCACHE_FOUND) - set_property(DIRECTORY vendor/googletest PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(DIRECTORY vendor/googletest PROPERTY RULE_LAUNCH_LINK ccache) - endif () + cece_enable_ccache(vendor/googletest) endif () -# Init google test submodule -if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/Box2D/Box2D/CMakeLists.txt") - find_package(Git REQUIRED) - execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive vendor/Box2D - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) -endif () +# Init Box2D submodule +cece_init_vendor(Box2D Box2D/CMakeLists.txt) # Add Box2D physics library set(BOX2D_BUILD_EXAMPLES Off CACHE BOOL "" FORCE) @@ -104,15 +97,47 @@ add_subdirectory(vendor/Box2D/Box2D) set_target_properties(Box2D PROPERTIES POSITION_INDEPENDENT_CODE On) target_include_directories(Box2D INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/Box2D/Box2D) -find_program(CCACHE_FOUND ccache) -if (CCACHE_FOUND) - set_property(DIRECTORY vendor/Box2D/Box2D PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(DIRECTORY vendor/Box2D/Box2D PROPERTY RULE_LAUNCH_LINK ccache) -endif () +cece_enable_ccache(vendor/Box2D/Box2D) # ######################################################################### # # CeCe library -add_subdirectory(cece) +add_subdirectory(src) + +# ######################################################################### # + +if (CECE_TESTS_BUILD) + add_subdirectory(unittests) + + if (CMAKE_COMPILER_IS_GNUCXX AND CECE_COVERAGE) + find_program(LCOV lcov) + find_program(GENHTML genhtml) + + if (NOT LCOV) + message(FATAL_ERROR "lcov not found!") + endif () + + if (NOT GENHTML) + message(FATAL_ERROR "genhtml not found!") + endif () + + # Add custom target for gcov + add_custom_target(cece-coverage + # Cleanup lcov + ${LCOV} --directory . --zerocounters + + # Run tests + COMMAND ctest + + # Capturing lcov counters and generating report + COMMAND ${LCOV} --directory . --capture --output-file coverage0.info + COMMAND ${LCOV} -r coverage0.info 'vendor/*' 'unittests/*' '/usr*' --output-file coverage.info + COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info + COMMAND ${CMAKE_COMMAND} -E remove coverage0.info + + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + endif () +endif () # ######################################################################### # diff --git a/appveyor.yml b/appveyor.yml index d258dad..cde765d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,7 +25,7 @@ os: Visual Studio 2015 -version: 0.6.0.{build} +version: 0.7.0.{build} environment: matrix: @@ -42,10 +42,6 @@ environment: - GENERATOR: MinGW Makefiles CECE_RENDER: Off -matrix: - allow_failures: - - GENERATOR: MinGW Makefiles - # Branches to build branches: except: @@ -62,6 +58,6 @@ build_script: - pushd build && cmake --build . --config Release & popd test_script: - - pushd build && ctest --verbose & popd + - pushd build && ctest -C Release --verbose & popd # ######################################################################### # diff --git a/cece/config/Configuration.hpp b/cece/config/Configuration.hpp deleted file mode 100644 index accaba6..0000000 --- a/cece/config/Configuration.hpp +++ /dev/null @@ -1,406 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/StringStream.hpp" -#include "cece/config/Exception.hpp" -#include "cece/config/Implementation.hpp" - -/* ************************************************************************ */ - -namespace cece { inline namespace core { class Parameters; } } - -/* ************************************************************************ */ - -namespace cece { -namespace config { - -/* ************************************************************************ */ - -/** - * @brief Container for configuration. - */ -class Configuration -{ - -// Public Ctors -public: - - - /** - * @brief Constructor. - * - * @param impl Implementation. - * @param parameters Optional parameters. - */ - Configuration(UniquePtr impl, ViewPtr parameters = nullptr) noexcept - : m_impl(std::move(impl)) - , m_parameters(parameters) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param impl Implementation. - * @param parameters Optional parameters. - */ - Configuration(Implementation* impl, ViewPtr parameters = nullptr) noexcept - : m_impl(impl) - , m_parameters(parameters) - { - // Nothign to do - } - - - /** - * @brief Constructor (memory version). - * - * @param parameters Optional parameters. - */ - explicit Configuration(ViewPtr parameters = nullptr) noexcept; - - -// Public Accessors -public: - - - /** - * @brief Returns if value exists under given name. - * - * @param name Value name. - * - * @return - */ - bool has(StringView name) const noexcept - { - return m_impl->has(name); - } - - - /** - * @brief Returns string value. - * - * @param name Value name. - * - * @return - * - * @throw ConfigException - */ - String get(StringView name) const - { - if (!has(name)) - throw config::Exception("Missing value for '" + String(name) + "'"); - - return replaceParameters(m_impl->get(name)); - } - - - /** - * @brief Returns string value. - * - * @param name Value name. - * @param def Default value if doesn't exists. - * - * @return - */ - String get(StringView name, String def) const - { - return has(name) ? replaceParameters(m_impl->get(name)) : std::move(def); - } - - - /** - * @brief Returns value of given type. - * - * @tparam T Required value type. - * - * @param name Value name. - * - * @return - * - * @throw ConfigException - */ - template - T get(StringView name) const - { - return castFrom(get(name)); - } - - - /** - * @brief Returns value of given type. - * - * @tparam T Required value type. - * - * @param name Value name. - * @param def Default value if doesn't exists. - * - * @return - */ - template - T get(StringView name, T def) const - { - return has(name) ? castFrom(replaceParameters(m_impl->get(name))) : std::move(def); - } - - - /** - * @brief Returns list of configuration names. - * - * @return - */ - DynamicArray getNames() const noexcept - { - return m_impl->getNames(); - } - - - /** - * @brief Returns if there is content. - * - * @return - */ - bool hasContent() const noexcept - { - return m_impl->hasContent(); - } - - - /** - * @brief Returns content. - * - * @return - */ - String getContent() const noexcept - { - return m_impl->getContent(); - } - - - /** - * @brief Check if subconfiguration exists. - * - * @param name Configuration name. - * - * @return Configuration or nullptr. - */ - bool hasConfiguration(StringView name) const noexcept - { - return m_impl->hasSubs(name); - } - - - /** - * @brief Returns the first sub-configuration. - * - * @param name Sub-configuration name. - * - * @return Sub-configuration. - * - * @throw ConfigException - */ - Configuration getConfiguration(StringView name) const - { - auto configurations = getConfigurations(name); - - if (configurations.empty()) - throw config::Exception("Sub-configuration '" + String(name) + "' doesn't exists"); - - return std::move(configurations[0]); - } - - - /** - * @brief Returns all sub-configurations with given name. - * - * @param name Sub-configuration name. - * - * @return List of valid sub-configurations. - */ - DynamicArray getConfigurations(StringView name) const noexcept; - - - /** - * @brief Returns list of sub-configuration names. - * - * @return - */ - DynamicArray getConfigurationNames() const noexcept - { - return m_impl->getSubNames(); - } - - -// Public Mutators -public: - - - /** - * @brief Store string value. - * - * @param name Value name. - * @param value Value to store. - */ - void set(StringView name, StringView value) noexcept - { - m_impl->set(name, value); - } - - - /** - * @brief Set integer value. - * - * @tparam T Value type. - * - * @param name Value name. - * @param value Value to store. - */ - template - void set(StringView name, T value) noexcept - { - m_impl->set(name, castTo(value)); - } - - - /** - * @brief Set content text. - * - * @param content Content text. - */ - void setContent(StringView content) noexcept - { - m_impl->setContent(content); - } - - - /** - * @brief Create new sub-configuration. - * - * @param name Sub-configuration name. - * - * @return New configuration. - */ - Configuration addConfiguration(StringView name) noexcept - { - return {m_impl->addSub(name)}; - } - - -// Public Operations -public: - - - /** - * @brief Copy configuration from other one. - * - * @param config Source configuration. - */ - void copyFrom(const Configuration& config); - - - /** - * @brief Clone configuration to memory. - * - * @return - */ - Configuration toMemory() const; - - -// Private Operations -private: - - - /** - * @brief Cast value from string into required type. - * - * @param value Value. - * - * @return - */ - template - static T castFrom(const String& value) - { - InStringStream is(value); - T res; - is >> std::noskipws >> std::boolalpha >> res; - return res; - } - - - /** - * @brief Cast value to string from given type. - * - * @param value Value. - * - * @return - */ - template - static String castTo(T&& value) - { - OutStringStream os; - os << value; - return os.str(); - } - - - /** - * @brief Replace parameters in given string. - * - * @param str Source string. - * - * @return Result string with replaced parameters. - */ - String replaceParameters(String str) const; - - -// Private Data Members -private: - - /// Configuration implementation. - UniquePtr m_impl; - - /// Optional parameters. - ViewPtr m_parameters; -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/config/MemoryImplementation.cpp b/cece/config/MemoryImplementation.cpp deleted file mode 100644 index b1cef09..0000000 --- a/cece/config/MemoryImplementation.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "cece/config/MemoryImplementation.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace config { - -/* ************************************************************************ */ - -DynamicArray MemoryImplementation::getNames() const noexcept -{ - DynamicArray names; - names.reserve(m_data->values.size()); - - for (const auto& p : m_data->values) - names.push_back(std::move(p.first)); - - return names; -} - -/* ************************************************************************ */ - -DynamicArray> MemoryImplementation::getSubs(StringView name) const noexcept -{ - DynamicArray> res; - - auto it = m_data->data.find(name.getData()); - - if (it == m_data->data.end()) - return res; - - for (const auto& ptr : it->second) - res.push_back(makeUnique(ptr)); - - return res; -} - -/* ************************************************************************ */ - -DynamicArray MemoryImplementation::getSubNames() const noexcept -{ - DynamicArray names; - names.reserve(m_data->data.size()); - - for (const auto& p : m_data->data) - names.push_back(p.first); - - return names; -} - -/* ************************************************************************ */ - -UniquePtr MemoryImplementation::addSub(StringView name) noexcept -{ - auto data = makeShared(); - - // Register data - m_data->data[name.getData()].push_back(data); - - return makeUnique(std::move(data)); -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/config/MemoryImplementation.hpp b/cece/config/MemoryImplementation.hpp deleted file mode 100644 index 4e61d83..0000000 --- a/cece/config/MemoryImplementation.hpp +++ /dev/null @@ -1,236 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/SharedPtr.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Map.hpp" -#include "cece/config/Implementation.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace config { - -/* ************************************************************************ */ - -/** - * @brief Memory configuration implementation. - */ -class MemoryImplementation : public Implementation -{ - -// Private Structures -private: - - - /** - * @brief Data storage. - */ - struct Data - { - /// Stored values. - Map values; - - /// Stored content. - String content; - - /// Subdata - Map>> data; - }; - - -// Public Ctors & Dtors -public: - - - /** - * @brief Constructor. - */ - MemoryImplementation() - : m_data(makeShared()) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param data Managed data. - */ - explicit MemoryImplementation(SharedPtr data) - : m_data(std::move(data)) - { - // Nothing to do - } - - -// Public Accessors -public: - - - /** - * @brief Check if value with given name exists. - * - * @param name Value name. - * - * @return - */ - bool has(StringView name) const noexcept override - { - return m_data->values.find(name.getData()) != m_data->values.end(); - } - - - /** - * @brief Returns string value. - * - * @param name Value name. - * - * @return - */ - String get(StringView name) const noexcept override - { - auto it = m_data->values.find(name.getData()); - return it != m_data->values.end() ? it->second : ""; - } - - - /** - * @brief Returns list of configuration names. - * - * @return - */ - DynamicArray getNames() const noexcept override; - - - /** - * @brief Returns if content string is set. - * - * @return - */ - bool hasContent() const noexcept override - { - return !m_data->content.empty(); - } - - - /** - * @brief Returns content string. - * - * @return - */ - String getContent() const noexcept override - { - return m_data->content; - } - - - /** - * @brief Returns if sub-configuration exists. - * - * @param name Sub-configuration name. - * - * @return - */ - bool hasSubs(StringView name) const noexcept override - { - return m_data->data.find(name.getData()) != m_data->data.end(); - } - - - /** - * @brief Returns all sub-configuration with given name. - * - * @param name Sub-configuration name. - * - * @return - */ - DynamicArray> getSubs(StringView name) const noexcept override; - - - /** - * @brief Returns list of sub-configuration names. - * - * @return - */ - DynamicArray getSubNames() const noexcept override; - - -// Public Mutators -public: - - - /** - * @brief Set string value. - * - * @param name Value name. - * @param value Value to store. - * - * @return - */ - void set(StringView name, StringView value) noexcept override - { - m_data->values[name.getData()] = value.getData(); - } - - - /** - * @brief Store content. - * - * @param content Content text. - */ - void setContent(StringView content) noexcept override - { - m_data->content = content.getData(); - } - - - /** - * @brief Create new sub-configuration. - * - * @param name Sub-configuration name. - * - * @return - */ - UniquePtr addSub(StringView name) noexcept override; - - -// Private Data Members -private: - - /// Shared data. - SharedPtr m_data; -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/CMakeLists.txt b/cece/core/CMakeLists.txt deleted file mode 100644 index 43a9447..0000000 --- a/cece/core/CMakeLists.txt +++ /dev/null @@ -1,128 +0,0 @@ -# ######################################################################### # -# Georgiev Lab (c) 2015-2016 # -# ######################################################################### # -# Department of Cybernetics # -# Faculty of Applied Sciences # -# University of West Bohemia in Pilsen # -# ######################################################################### # -# # -# This file is part of CeCe. # -# # -# CeCe is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# CeCe is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with CeCe. If not, see . # -# # -# ######################################################################### # - -set(SRCS - Macro.hpp - constants.hpp - fastexp.hpp - DynamicArray.hpp - StaticArray.hpp - StaticMatrix.hpp - Unit.hpp - Unit.cpp - UnitIo.hpp - UnitIo.cpp - UnitSymbol.hpp - Units.hpp - Units.cpp - UnitsCtors.hpp - Vector.hpp - Vector.cpp - VectorUnits.hpp - VectorUnits.cpp - Grid.hpp - Grid.cpp - AlignedAllocator.hpp - AlignedAllocator.cpp - ExpressionParser.hpp - ExpressionParser.cpp - Log.hpp - Log.cpp - TimeMeasurement.hpp - TimeMeasurement.cpp - String.hpp - StringView.hpp - FilePath.hpp - FilePath.cpp - Exception.hpp - OutStream.hpp - InStream.hpp - InOutStream.hpp - FileStream.hpp - CsvFile.hpp - CsvFile.cpp - DataExport.hpp - DataExport.cpp - DataExportCsv.hpp - DataExportCsv.cpp - DataExportFactory.hpp - DataExportFactory.cpp - DataExportCsvFactory.hpp - DataExportCsvFactory.cpp - ValueIterator.hpp - Range.hpp - VectorRange.hpp - IntegerSequence.hpp - Tuple.hpp - UniquePtr.hpp - ViewPtr.hpp - ListenerContainer.hpp - Zero.hpp - StringStream.hpp - Tokenizer.hpp - Real.hpp - Mutex.hpp - Pair.hpp - SharedPtr.hpp - Parameters.hpp - Parameters.cpp - Factory.hpp - FactoryManager.hpp - Shape.hpp - ShapeToGrid.hpp - PtrContainer.hpp - PtrNamedContainer.hpp - IterationType.hpp - IterationRange.hpp - CliColor.hpp - CliColor.cpp -) - -set(SRCS_TEST - AlignedAllocatorTest.cpp - DynamicArrayTest.cpp - IteratorRangeTest.cpp - VectorRangeTest.cpp - UnitsTest.cpp - StringViewTest.cpp - VectorTest.cpp - VectorUnitsTest.cpp - ExpressionParserTest.cpp - TokenizerTest.cpp - ParametersTest.cpp - PtrContainerTest.cpp - ViewPtrTest.cpp - FilePathTest.cpp -) - -# ######################################################################### # - -dir_pretend(SOURCES core/ ${SRCS}) -dir_pretend(SOURCES_TEST core/test/ ${SRCS_TEST}) - -set(SOURCES_CORE ${SOURCES} PARENT_SCOPE) -set(SOURCES_CORE_TEST ${SOURCES_TEST} PARENT_SCOPE) - -# ######################################################################### # diff --git a/cece/core/FilePath.hpp b/cece/core/FilePath.hpp deleted file mode 100644 index efba6af..0000000 --- a/cece/core/FilePath.hpp +++ /dev/null @@ -1,428 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include -#include - -#ifdef _WIN32 -# include -#endif - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -/** - * @brief File path type. - */ -class FilePath -{ - -// Public Constants -public: - - - /// Path separator. - static constexpr char SEPARATOR = '/'; - - -// Public Ctors & Dtors -public: - - - /** - * @brief Default constructor. - */ - FilePath() = default; - - - /** - * @brief Constructor. - * - * @param source - */ - FilePath(String source) - : m_path(std::move(source)) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param source - */ - FilePath(const char* source) - : m_path(source) - { - // Nothing to do - } - - -// Public Operators -public: - - - /** - * @brief Append path. - * - * @param path - * - * @return this - */ - FilePath& operator/=(const FilePath& path) - { - if (!m_path.empty()) - m_path += SEPARATOR; - m_path.append(path.m_path); - return *this; - } - - - /** - * @brief Append source. - * - * @param source - * - * @return this - */ - FilePath& operator/=(const String& source) - { - if (!m_path.empty()) - m_path += SEPARATOR; - m_path.append(source); - return *this; - } - - - /** - * @brief Append source. - * - * @param source - * - * @return this - */ - FilePath& operator/=(const char* source) - { - if (!m_path.empty()) - m_path += SEPARATOR; - m_path.append(source); - return *this; - } - - - /** - * @brief Append path. - * - * @param path - * - * @return - */ - FilePath operator/(const FilePath& path) const - { - return FilePath(*this) /= path; - } - - - /** - * @brief Append source. - * - * @param source - * - * @return - */ - FilePath operator/(const String& source) const - { - return FilePath(*this) /= source; - } - - - /** - * @brief Append source. - * - * @param source - * - * @return - */ - FilePath operator/(const char* source) const - { - return FilePath(*this) /= source; - } - - -// Public Accessors & Mutators -public: - - - /** - * @brief Check if path is empty. - * - * @return - */ - bool isEmpty() const noexcept - { - return m_path.empty(); - } - - - /** - * @brief Check if path is empty. - * - * @return - * - * @deprecated - */ - bool empty() const noexcept - { - return isEmpty(); - } - - - /** - * @brief Returns path file name. - * - * @return - */ - String getFilename() const noexcept; - - - /** - * @brief Returns path extension. - * - * @return - */ - String getExtension() const noexcept; - - - /** - * @brief Returns parent path. - * - * @return - */ - FilePath getParentPath() const noexcept; - - - /** - * @brief Returns path stem. - * - * @return - */ - FilePath getStem() const noexcept; - - - /** - * @brief Convert path to string. - * - * @return - */ - const char* c_str() const noexcept - { - return m_path.c_str(); - } - - - /** - * @brief Returns path length. - * - * @return - */ - String::size_type getSize() const noexcept - { - return m_path.size(); - } - - - /** - * @brief Convert path to string. - * - * @return - */ - String toString() const noexcept - { - return m_path; - } - - - /** - * @brief Convert path to string. - * - * @return - * - * @deprecated - */ - String string() const noexcept - { - return toString(); - } - - - /** - * @brief Append string to the path. - * - * @param str String to append. - * - * @return this - */ - FilePath& append(const String& str) - { - m_path.append(str); - return *this; - } - - - /** - * @brief Replace path extension. - * - * @param ext New extension. - * - * @return this - */ - FilePath& replaceExtension(const String& ext); - - -// Public Operations -public: - - - /** - * @brief Clear path. - */ - void clear() noexcept - { - m_path.clear(); - } - - - /** - * @brief Input stream operator. - * - * @param is - * @param path - * - * @return is - */ - friend InStream& operator>>(InStream& is, FilePath& path) - { - return is >> path.m_path; - } - - - /** - * @brief Output stream operator. - * - * @param os - * @param path - * - * @return os - */ - friend OutStream& operator<<(OutStream& os, const FilePath& path) - { - return os << path.m_path; - } - - -// Private Data Members -private: - - /// Path value. - String m_path; - -}; - -/* ************************************************************************ */ - -/** - * @brief Tests if path is a file. - * - * @param path - * - * @return - */ -bool isFile(const FilePath& path) noexcept; - -/* ************************************************************************ */ - -/** - * @brief Tests if path is a directory. - * - * @param path - * - * @return - */ -bool isDirectory(const FilePath& path) noexcept; - -/* ************************************************************************ */ - -/** - * @brief Tests if file path exists. - * - * @param path - * - * @return - */ -bool pathExists(const FilePath& path) noexcept; - -/* ************************************************************************ */ - -/** - * @brief Returns temporary directory. - * - * @return - */ -FilePath tempDirectory(); - -/* ************************************************************************ */ - -/** - * @brief Get all entries in given directory. - * - * @param dir - * - * @return - */ -DynamicArray openDirectory(const FilePath& dir); - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/Log.hpp b/cece/core/Log.hpp deleted file mode 100644 index 30371a4..0000000 --- a/cece/core/Log.hpp +++ /dev/null @@ -1,281 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/export.hpp" -#include "cece/core/String.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/StringStream.hpp" -#include "cece/core/CliColor.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -/** - * @brief Logging class. - */ -class Log -{ - -// Public Enums -public: - - - /** - * @brief Log message types. - */ - enum class Type - { - Default, - Info, - Warning, - Error, - Debug - }; - - -// Public Classes -public: - - - /** - * @brief Output class that handles log output. - */ - class Output - { - // Public Ctors & Dtors - public: - - /** - * @brief Destructor. - */ - virtual ~Output(); - - // Public Operations - public: - - /** - * @brief Write a message to output. - * - * @param type Message type. - * @param section Message section. - * @param msg Message to log. - */ - virtual void write(Type type, const String& section, const String& msg) = 0; - }; - - - /** - * @brief Output for output streams. - */ - class StreamOutput : public Output - { - // Public Ctors & Dtors - public: - - /** - * @brief Constructor. - * - * @param os - */ - explicit StreamOutput(OutStream* os) : m_os(os) {} - - - /** - * @brief Destructor. - */ - ~StreamOutput(); - - // Public Operations - public: - - /** - * @brief Write a message to output. - * - * @param type Message type. - * @param section Message section. - * @param msg Message to log. - */ - void write(Type type, const String& section, const String& msg) override; - - // Private Data Members - private: - - /// Output stream. - OutStream* m_os; - }; - - -// Public Mutators -public: - - - /** - * @brief Set output stream. - * - * @param os - */ - static void setOutput(Output* os) noexcept - { - s_output = os; - } - - - /** - * @brief Set error stream. - * - * @param os - */ - static void setError(Output* os) noexcept - { - s_error = os; - } - - -// Public Operators -public: - - - /** - * @brief Log info message. - * - * @param args - */ - template - static void info(Args&&... args) - { - if (s_output) - { - OutStringStream oss; - message(oss, std::forward(args)...); - s_output->write(Type::Info, String{}, oss.str()); - } - } - - - /** - * @brief Log debug message. - * - * @param args - */ - template - static void debug(Args&&... args) - { -#ifndef NDEBUG - if (s_output) - { - OutStringStream oss; - message(oss, std::forward(args)...); - s_output->write(Type::Debug, String{}, oss.str()); - } -#endif - } - - - /** - * @brief Log warning message. - * - * @param args - */ - template - static void warning(Args&&... args) - { - if (s_output) - { - OutStringStream oss; - message(oss, std::forward(args)...); - s_output->write(Type::Warning, String{}, oss.str()); - } - } - - - /** - * @brief Log error message. - * - * @param args - */ - template - static void error(Args&&... args) - { - if (s_error) - { - OutStringStream oss; - message(oss, std::forward(args)...); - s_error->write(Type::Error, String{}, oss.str()); - } - } - - -// Private Operations -private: - - - /** - * @brief Log message. - */ - static void message(OutStream& os) - { - // Nothing to do - } - - - /** - * @brief Log message. - * - * @param args - */ - template - static void message(OutStream& os, Arg&& arg, Args&&... args) - { - os << arg; - message(os, std::forward(args)...); - } - - -// Private Data Members -private: - - /// Standard output. - static CECE_EXPORT Output* s_output; - - /// Error output. - static CECE_EXPORT Output* s_error; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/PtrContainer.hpp b/cece/core/PtrContainer.hpp deleted file mode 100644 index ee823d0..0000000 --- a/cece/core/PtrContainer.hpp +++ /dev/null @@ -1,296 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include - -// CeCe -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/DynamicArray.hpp" - -/* ************************************************************************ */ - -/** - * @brief Define pointer container specialization. - */ -#define CECE_PTR_CONTAINER(...) \ - namespace cece { inline namespace core { template class PtrContainer<__VA_ARGS__>; } } - -/** - * @brief Define extern pointer container specialization. - */ -#define CECE_PTR_CONTAINER_EXTERN(...) \ - namespace cece { inline namespace core { extern template class PtrContainer<__VA_ARGS__>; } } - -/** - * @brief Define pointer container specialization. - */ -#define CECE_PTR_CONTAINER_INST(...) \ - namespace cece { inline namespace core { template class PtrContainer<__VA_ARGS__>; } } - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -/** - * @brief Container for pointers. - */ -template -class PtrContainer -{ - -// Public Types -public: - - - /// Pointer type. - using type = T; - - -// Public Operators -public: - - - /** - * @brief Returns n-th object. - * - * @param pos Required position. - * - * @return Pointer to object. - * - * @warning No boundary checking. - */ - ViewPtr operator[](std::size_t pos) const noexcept - { - return m_data[pos]; - } - - -// Public Accessors -public: - - - /** - * @brief Returns a number of stored objects. - * - * @return - */ - std::size_t getCount() const noexcept - { - return m_data.size(); - } - - - /** - * @brief Returns n-th object. - * - * @param pos Required position. - * - * @return Pointer to object. - */ - ViewPtr get(std::size_t pos) const - { - return m_data.at(pos); - } - - - /** - * @brief Returns begin iterator. - * - * @return - */ - typename DynamicArray>::const_iterator begin() const noexcept - { - return m_data.begin(); - } - - - /** - * @brief Returns begin iterator. - * - * @return - */ - typename DynamicArray>::const_iterator cbegin() const noexcept - { - return m_data.cbegin(); - } - - - /** - * @brief Returns end iterator. - * - * @return - */ - typename DynamicArray>::const_iterator end() const noexcept - { - return m_data.end(); - } - - - /** - * @brief Returns end iterator. - * - * @return - */ - typename DynamicArray>::const_iterator cend() const noexcept - { - return m_data.cend(); - } - - -// Public Mutators -public: - - - /** - * @brief Store an object. - * - * @param object The object to store. - * - * @return View pointer to stored object. - */ - ViewPtr add(UniquePtr object) - { - m_data.push_back(std::move(object)); - return m_data.back(); - } - - - /** - * @brief Create and store an object. - * - * @tparam Args Construction argument types. - * - * @param args Construction arguments. - * - * @return View pointer to stored object. - */ - template - ViewPtr create(Args&&... args) - { - return add(makeUnique(std::forward(args)...)); - } - - - /** - * @brief Create and store an object. - * - * @tparam T2 Type of constructed object. - * @tparam Args Construction argument types. - * - * @param args Construction arguments. - * - * @return View pointer to stored object. - */ - template - ViewPtr create(Args&&... args) - { - return add(makeUnique(std::forward(args)...)); - } - - - /** - * @brief Remove object from container. - * - * @param object The object to remove. - * - * @return A pointer to removed object. - */ - UniquePtr remove(ViewPtr object) - { - for (auto itB = m_data.begin(), itE = m_data.end(); itB != itE; ++itB) - { - if (itB->get() == object.get()) - { - auto ptr = std::move(*itB); - m_data.erase(itB); - return ptr; - } - } - - // Not found - return nullptr; - } - - - /** - * @brief Clear container. - */ - void clear() - { - m_data.clear(); - } - - -// Protected Operations -protected: - - - /** - * @brief Invoke a member function for all stored objects. - * - * @tparam Args A list of member function arguments. - * - * @param function A pointer to object's member function that will be - * called for all stored listeners. - * @param args... - */ - template - void invoke(Fn fn, Args2&&... args) const - { - static_assert(std::is_member_function_pointer::value, "Fn is not a member function."); - - // Foreach all object - for (const auto& object : m_data) - { - // Call member function with given arguments - (object.get()->*fn)(std::forward(args)...); - } - } - - -// Private Data Members -private: - - /// Stored pointers. - DynamicArray> m_data; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/PtrNamedContainer.hpp b/cece/core/PtrNamedContainer.hpp deleted file mode 100644 index deec982..0000000 --- a/cece/core/PtrNamedContainer.hpp +++ /dev/null @@ -1,392 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include - -// CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/DynamicArray.hpp" - -/* ************************************************************************ */ - -/** - * @brief Define pointer named container specialization. - */ -#define CECE_PTR_NAMED_CONTAINER(...) \ - namespace cece { inline namespace core { template class PtrNamedContainer<__VA_ARGS__>; } } - -/** - * @brief Define extern pointer named container specialization. - */ -#define CECE_PTR_NAMED_CONTAINER_EXTERN(...) \ - namespace cece { inline namespace core { extern template class PtrNamedContainer<__VA_ARGS__>; } } - -/** - * @brief Define pointer named container specialization. - */ -#define CECE_PTR_NAMED_CONTAINER_INST(...) \ - namespace cece { inline namespace core { template class PtrNamedContainer<__VA_ARGS__>; } } - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -/** - * @brief Container for named pointers. - */ -template -class PtrNamedContainer -{ - -// Public Types -public: - - - /// Pointer type. - using type = T; - - -// Public Structures -public: - - - /** - * @brief Container record. - */ - struct Record - { - /// Object name. - String name; - - /// Pointer to object. - UniquePtr object; - - - /** - * @brief Implicit cast to view pointer operator. - */ - operator ViewPtr() const noexcept - { - return object; - } - - - /** - * @brief Implicit cast to operator. - */ - operator T*() const noexcept - { - return object.get(); - } - - - /** - * @brief Dereference operator. - * - * @return Reference. - */ - T& operator*() const noexcept - { - return *object; - } - - - /** - * @brief Pointer access operator. - * - * @return Pointer. - */ - T* operator->() const noexcept - { - return object.get(); - } - }; - - -// Public Operators -public: - - - /** - * @brief Returns object with given name. - * - * @param name Object name. - * - * @return Pointer to object. - */ - ViewPtr operator[](StringView name) const noexcept - { - return get(name); - } - - -// Public Accessors -public: - - - /** - * @brief Returns a number of stored objects. - * - * @return - */ - std::size_t getCount() const noexcept - { - return m_data.size(); - } - - - /** - * @brief Returns if an object with given name exists. - * - * @param name Object name. - * - * @return - */ - bool exists(StringView name) const noexcept - { - return find(m_data, name) != nullptr; - } - - - /** - * @brief Returns object with given value. - * - * @param name Object name. - * - * @return Pointer to object. Can be nullptr. - */ - ViewPtr get(StringView name) const noexcept - { - auto ptr = find(m_data, name); - - if (ptr) - return *ptr; - - return nullptr; - } - - - /** - * @brief Returns object with given value. - * - * @tparam T2 Required type. - * - * @param name Object name. - * - * @return Pointer to object. Can be nullptr. - */ - template - ViewPtr get(StringView name) const noexcept - { - auto ptr = get(name); - if (!ptr) - return nullptr; - - CECE_ASSERT(dynamic_cast(ptr.get())); - return static_cast(ptr.get()); - } - - - /** - * @brief Returns begin iterator. - * - * @return - */ - typename DynamicArray::const_iterator begin() const noexcept - { - return m_data.begin(); - } - - - /** - * @brief Returns begin iterator. - * - * @return - */ - typename DynamicArray::const_iterator cbegin() const noexcept - { - return m_data.cbegin(); - } - - - /** - * @brief Returns end iterator. - * - * @return - */ - typename DynamicArray::const_iterator end() const noexcept - { - return m_data.end(); - } - - - /** - * @brief Returns end iterator. - * - * @return - */ - typename DynamicArray::const_iterator cend() const noexcept - { - return m_data.cend(); - } - - -// Public Mutators -public: - - - /** - * @brief Store and object. - * - * @param object The object to store. - * - * @return View pointer to stored object. - */ - ViewPtr add(String name, UniquePtr object) - { - auto ptr = find(m_data, name); - - if (ptr) - { - *ptr = std::move(object); - return *ptr; - } - else - { - m_data.emplace_back(Record{std::move(name), std::move(object)}); - return m_data.back().object; - } - } - - - /** - * @brief Remove object from container. - * - * @param name Object name. - * - * @return A pointer to removed object. - */ - UniquePtr remove(StringView name) - { - for (auto itB = m_data.begin(), itE = m_data.end(); itB != itE; ++itB) - { - if (itB->name == name) - { - auto ptr = std::move(itB->object); - m_data.erase(itB); - return ptr; - } - } - - // Not found - return nullptr; - } - - - /** - * @brief Clear container. - */ - void clear() - { - m_data.clear(); - } - - -// Protected Operations -protected: - - - /** - * @brief Invoke a member function for all stored objects. - * - * @tparam Args A list of member function arguments. - * - * @param function A pointer to object's member function that will be - * called for all stored listeners. - * @param args... - */ - template - void invoke(void (T::*fn)(Args...), Args&& ... args) const - { - // Foreach all object - for (const auto& object : m_data) - { - // Call member function with given arguments - (object.object.get()->*fn)(std::forward(args)...); - } - } - - -// Private Operations -private: - - - /** - * @brief Find an object in container. - * - * @param data - * - * @return - */ - template - static auto find(ContainerType& data, StringView name) noexcept -> decltype(&(data.begin()->object)) - { - auto it = std::find_if(data.begin(), data.end(), - [&name](const Record& p) { - return p.name == name; - } - ); - - return it != data.end() ? &(it->object) : nullptr; - } - - -// Private Data Members -private: - - /// Stored pointers. - DynamicArray m_data; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/StringView.hpp b/cece/core/StringView.hpp deleted file mode 100644 index 07c2414..0000000 --- a/cece/core/StringView.hpp +++ /dev/null @@ -1,280 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/DynamicArray.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -/** - * @brief View for string independent on string storage. - */ -class StringView -{ - -// Public Types -public: - - - /// Character type. - using CharType = char; - - /// Sequence length type. - using LengthType = std::size_t; - - /// Sequence position type. - using PositionType = std::size_t; - - -// Public Ctors & Dtors -public: - - - /** - * @brief Default constructor. - */ - StringView() = default; - - - /** - * @brief Constructor. - * - * @param ptr Sequence start pointer. - * @param len Sequence length. - */ - StringView(const CharType* ptr, LengthType len) noexcept - : m_ptr(ptr) - , m_length(len) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param ptr Sequence start pointer. - */ - StringView(const CharType* ptr) noexcept - : m_ptr(ptr) - , m_length(strlen(ptr)) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param str String. - */ - StringView(const String& str) noexcept - : m_ptr(str.c_str()) - , m_length(str.length()) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param str String. - */ - StringView(const DynamicArray& str) noexcept - : m_ptr(str.data()) - , m_length(str.size()) - { - // Nothing to do - } - - - /** - * @brief Constructor. - * - * @param str String. - */ - template - StringView(const StaticArray& str) noexcept - : m_ptr(str.data()) - , m_length(str.size()) - { - // Nothing to do - } - - -// Public Operators -public: - - - /** - * @brief Get character at given position. - * - * @param pos Character position. - * - * @return - */ - CharType operator[](PositionType pos) const noexcept - { - return m_ptr[pos]; - } - - - /** - * @brief Cast to String. - */ - explicit operator String() const noexcept - { - return String(m_ptr, m_length); - } - - -// Public Accessors -public: - - - /** - * @brief Returns sequence data. - * - * @return - */ - const CharType* getData() const noexcept - { - return m_ptr; - } - - - /** - * @brief Returns sequence length. - * - * @return - */ - LengthType getLength() const noexcept - { - return m_length; - } - - -// Private Data Members -private: - - /// Start of the string. - const CharType* m_ptr = nullptr; - - /// Length of the string. - LengthType m_length = 0; -}; - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return - */ -inline bool operator==(const StringView& lhs, const StringView& rhs) noexcept -{ - // Data pointer and length match -> same views. - if (lhs.getData() == rhs.getData() && lhs.getLength() == rhs.getLength()) - return true; - - // Different lengths - if (lhs.getLength() != rhs.getLength()) - return false; - - // Compare all characters - return !strncmp(lhs.getData(), rhs.getData(), lhs.getLength()); -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return - */ -inline bool operator!=(const StringView& lhs, const StringView& rhs) -{ - return !operator==(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Output stream operator for StringView. - * - * @param os Output stream. - * @param view View to print. - * - * @return os. - */ -inline OutStream& operator<<(OutStream& os, const StringView& view) noexcept -{ - return os.write(view.getData(), view.getLength()); -} - -/* ************************************************************************ */ - -/** - * @brief Input stream operator for StringView. - * - * @note StringView cannot be used as string storage. - * - * @param is Input stream. - * @param view Output view. - * - * @return is. - */ -inline InStream& operator<<(InStream& is, StringView& view) noexcept = delete; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/Unit.hpp b/cece/core/Unit.hpp deleted file mode 100644 index 16f6e5e..0000000 --- a/cece/core/Unit.hpp +++ /dev/null @@ -1,1615 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include -#include - -// CeCe -#include "cece/core/Real.hpp" -#include "cece/core/Zero.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/StaticArray.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -/** - * @brief Basic value. - */ -using Value = RealType; - -/* ************************************************************************ */ - -/// Base units exponents -static constexpr int LENGTH_EXPONENT = 6; -static constexpr int TIME_EXPONENT = 0; -static constexpr int MASS_EXPONENT = 6; -static constexpr int ELECTRIC_CURRENT_EXPONENT = 0; -static constexpr int THERMODYNAMIC_TEMPERATURE_EXPONENT = 0; -static constexpr int AMOUNT_OF_SUBSTANCE_EXPONENT = 6; -static constexpr int LUMINOUS_INTENSITY_EXPONENT = 0; - -/* ************************************************************************ */ - -/// @link http://stackoverflow.com/questions/26682812/argument-counting-macro-with-zero-arguments-for-visualstudio-2010/26685339#26685339 -#ifdef _MSC_VER // Microsoft compilers - -#define EXPAND(x) x -#define __NARGS(_1, _2, _3, _4, N, ...) N -#define NARGS_1(...) EXPAND(__NARGS(__VA_ARGS__, 3, 2, 1, 0)) - -#define AUGMENTER(...) unused, __VA_ARGS__ -#define NARG(...) NARGS_1(AUGMENTER(__VA_ARGS__)) - -#else // And normal compilers - -/// @link https://azraelplanet.wordpress.com/2012/03/30/number-of-arguments-in-__va_args__-gcc/ -#define ARG_N(_1, _2, _3, N, ...) N -#define NARG_(...) ARG_N(__VA_ARGS__) -#define NARG(...) NARG_(__VA_ARGS__, 3, 2, 1, 0) - -#endif - -/* ************************************************************************ */ - -/** - * @brief Defines base unit. - * - * @param name Unit Name. - * @param ord Unit order. - * @param exp Value coefficient exponent. - * @param ... Characters of unit symbol. - */ -#define DEFINE_BASE_UNIT(name, exp, ord, ...) \ - struct Base ## name {\ - static constexpr int exponent = exp; \ - static constexpr int order = ord;\ - static constexpr std::size_t symbolLength = NARG(__VA_ARGS__) + 1; \ - static constexpr StaticArray getSymbol() noexcept \ - { \ - return {{__VA_ARGS__, '\0'}};\ - } \ - } - -/* ************************************************************************ */ - -/** - * @brief Base SI units. - */ -DEFINE_BASE_UNIT(Length, LENGTH_EXPONENT, 0, 'm'); -DEFINE_BASE_UNIT(Time, TIME_EXPONENT, 1, 's'); -DEFINE_BASE_UNIT(Mass, MASS_EXPONENT, 2, 'g'); -DEFINE_BASE_UNIT(ElectricCurrent, ELECTRIC_CURRENT_EXPONENT, 3, 'A'); -DEFINE_BASE_UNIT(ThermodynamicTemperature, THERMODYNAMIC_TEMPERATURE_EXPONENT, 4, 'K'); -DEFINE_BASE_UNIT(AmountOfSubstance, AMOUNT_OF_SUBSTANCE_EXPONENT, 5, 'm', 'o', 'l'); -DEFINE_BASE_UNIT(LuminousIntensity, LUMINOUS_INTENSITY_EXPONENT, 6, 'c', 'd'); - -/* ************************************************************************ */ - -/** - * @brief Calculate coefficient from exponent. - * - * @param exponent - * - * @return Result coefficient - */ -inline constexpr Value exponentToCoefficient(int exponent) noexcept -{ - return (exponent == 0) - ? 1 - : (exponent > 0) - ? 10 * exponentToCoefficient(exponent - 1) - : 0.1 * exponentToCoefficient(exponent + 1) - ; -} - -/* ************************************************************************ */ - -/** - * @brief Less structure. - * - * @tparam T1 First base unit type. - * @tparam T2 Second base unit type. - */ -template -struct Less -{ - /// If T1 is less than T2 - static constexpr bool value = T1::order < T2::order; -}; - -/* ************************************************************************ */ - -/** - * @brief List of types. - * - * @tparam Types A list of types. - */ -template -struct List -{ - - /// Number of types in list. - static constexpr std::size_t size = sizeof...(Types); - -}; - -/* ************************************************************************ */ - -/** - * @brief Struct for calculating total coefficient exponent of given list. - * - * @tparam Types A list of unit types. - */ -template -struct Exponent; - -/* ************************************************************************ */ - -/** - * @brief Struct for calculating total coefficient exponent of given list. - * - * @tparam Types A list of unit types. - */ -template -struct Exponent> -{ - - /** - * @brief Add coefficient exponents. - * - * @param arg The first coefficient exponent. - * @param args Rest of the coefficient exponents. - * - * @return Result exponent. - */ - template - static constexpr int add(Arg&& arg, Args&&... args) noexcept - { - return arg + add(args...); - } - - - /** - * @brief Add coefficient exponents. - * - * @return 1. - */ - static constexpr int add() noexcept - { - return 0; - } - - - /// Calculate types coefficient exponent. - static constexpr int value = add(Types::exponent...); - -}; - -/* ************************************************************************ */ - -/** - * @brief Concatenate two lists. - * - * @tparam T Types. - */ -template -struct Concat; - -/* ************************************************************************ */ - -/** - * @brief Concatenated specialization for single list. - * - * @tparam Types Types of the list. - */ -template -struct Concat> -{ - /// Concatenated list. - using type = List; -}; - -/* ************************************************************************ */ - -/** - * @brief Concatenate two lists. - * - * @tparam Types1 Types of the first list. - * @tparam Types2 Types of the second list. - * @tparam Tail Remaining types. - */ -template -struct Concat, List, Tail...> -{ - /// Concatenated list. - using type = typename Concat, Tail...>::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam T Type to count. - * @tparam List List of types. - */ -template -struct Counter; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam T Type to count. - */ -template -struct Counter> -{ - /// Number of occurences. - static constexpr std::size_t value = 0; -}; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam T Type to count. - * @tparam Type The first type from types. - * @tparam List List of types. - */ -template -struct Counter> -{ - /// Number of occurences. - static constexpr std::size_t value = - (std::is_same::value ? 1 : 0) + - Counter>::value - ; -}; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam List List of types. - */ -template -struct CounterFirst; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam List List of types. - */ -template<> -struct CounterFirst> -{ - /// Number of occurences. - static constexpr std::size_t value = 0; -}; - -/* ************************************************************************ */ - -/** - * @brief Type counter. - * - * @tparam Type The first type from types. - * @tparam List List of types. - */ -template -struct CounterFirst> -{ - /// Number of occurences. - static constexpr std::size_t value = Counter>::value; -}; - -/* ************************************************************************ */ - -/** - * @brief Remove type from list. - * - * @tparam T Type to remove. - * @tparam List List of types. - */ -template -struct Remove; - -/* ************************************************************************ */ - -/** - * @brief Remove type from list. - * - * @tparam T Type to remove. - */ -template -struct Remove> -{ - // Not found - static constexpr bool value = false; - - // Remaining types. - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief Remove type element from list. - * - * @tparam T Type to remove. - * @tparam Type First type. - * @tparam Types Remaining types in the list. - */ -template -struct Remove> -{ - /// If types match. - static constexpr bool match = std::is_same::value; - - // Inner remove. - using RemoveInnerType = Remove>; - - // If type is found. - static constexpr bool value = match || RemoveInnerType::value; - - /// List type without the required type. - using type = typename std::conditional, - typename Concat, typename RemoveInnerType::type>::type - >::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Helper class to reduce units. - * - * @tparam Nom Nominators. - * @tparam Denom Denominators. - */ -template -struct ReduceInner; - -/* ************************************************************************ */ - -/** - * @brief Helper class to reduce units. - * - * @tparam Denominators List types. - */ -template -struct ReduceInner, List> -{ - using nominators = List<>; - using denominators = List; -}; - -/* ************************************************************************ */ - -/** - * @brief Helper class to simplify units. - * - * Type removes shared types in nominator and denominator. - * - * @tparam Nom First nominator. - * @tparam Nominators List types. - * @tparam Denominators List types. - */ -template -struct ReduceInner, List> -{ - /// Type of removing type. - using remove_type = Remove>; - - // Reduce without the first nominator - using reduce_inner = ReduceInner, typename remove_type::type>; - - /// List of nominators - using nominators = typename std::conditional, typename reduce_inner::nominators>::type - >::type; - - /// List of denominators - using denominators = typename reduce_inner::denominators; -}; - -/* ************************************************************************ */ - -/** - * @brief Remove all occurences of given type element from list. - * - * @tparam T Type to remove. - * @tparam List List of types. - */ -template -struct RemoveAll; - -/* ************************************************************************ */ - -/** - * @brief Remove all occurences of given type element from list. - * - * @tparam T Type to remove. - */ -template -struct RemoveAll> -{ - // Not found - static constexpr bool value = false; - - // Number of occurences. - static constexpr std::size_t count = 0; - - // Remaining types. - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief Remove all occurences of given type element from list. - * - * @tparam T Type to remove. - * @tparam Type First type. - * @tparam Types Remaining types in the list. - */ -template -struct RemoveAll> -{ - /// If types match. - static constexpr bool match = std::is_same::value; - - // Inner remove. - using RemoveInnerType = RemoveAll>; - - // If type is found. - static constexpr bool value = match || RemoveInnerType::value; - - // Number of occurences. - static constexpr std::size_t count = (match ? 1 : 0) + RemoveInnerType::count; - - /// List type without the required type. - using type = typename std::conditional, typename RemoveInnerType::type>::type - >::type; -}; - -/* ************************************************************************ */ - -/** - * @brief SI Unit. - * - * @tparam Nom List type. - * @tparam Denom List type. - */ -template -class Unit -{ - -// Public Types -public: - - - /// Value type. - using value_type = Value; - - /// List type. - using nominator = Nom; - - /// List type. - using denominator = Denom; - -// Public Constants -public: - - - /// Total unit coefficient. - static constexpr int exponent = Exponent::value - Exponent::value; - - /// Number of occurences of the first nominator. - static constexpr std::size_t firstCountNom = CounterFirst::value; - - /// Number of occurences of the first denominator. - static constexpr std::size_t firstCountDenom = CounterFirst::value; - - -// Public Ctors & Dtors -public: - - - /** - * @brief Default constructor. - */ - Unit() noexcept - : m_value{} - { - // Default ( = default) constructor and extern template are not - // friends in GCC - } - - - /** - * @brief Constructor. - * - * @param value Init value. - */ - explicit constexpr Unit(value_type value) noexcept - : m_value(value) - { - // Nothing to do - } - - - /** - * @brief Zero constructor. - */ - constexpr Unit(Zero_t) noexcept - : m_value(0) - { - // Nothing to do - } - - -// Public Operators -public: - - - /** - * @brief If value is set operator. - * - * @return - */ - explicit operator bool() const noexcept - { - return m_value != 0; - } - - - /** - * @brief Cast to value type. - * - * @return - */ - explicit operator Value() const noexcept - { - return m_value; - } - - - /** - * @brief Unary plus operator. - * - * @return New value. - */ - Unit operator+() const noexcept - { - return Unit(m_value); - } - - - /** - * @brief Unary minus operator. - * - * @return New value. - */ - Unit operator-() const noexcept - { - return Unit(-m_value); - } - - - /** - * @brief Addition operator. - * - * @param rhs - * - * @return *this. - */ - Unit& operator+=(Unit rhs) noexcept - { - m_value += rhs.m_value; - return *this; - } - - - /** - * @brief Substraction operator. - * - * @param rhs Right operand. - * - * @return *this. - */ - Unit& operator-=(Unit rhs) noexcept - { - m_value -= rhs.m_value; - return *this; - } - - - /** - * @brief Multiplication operator. - * - * @param rhs Right operand. - * - * @return *this. - */ - Unit& operator*=(value_type rhs) noexcept - { - m_value *= rhs; - return *this; - } - - - /** - * @brief Division operator. - * - * @param rhs Right operand. - * - * @return *this. - */ - Unit& operator/=(value_type rhs) noexcept - { - m_value /= rhs; - return *this; - } - - -// Public Accessors -public: - - - /** - * @brief Returns current value. - * - * @return - */ - constexpr value_type value() const noexcept - { - return m_value; - } - - -// Private Data Members -private: - - /// Stored value. - value_type m_value; - -}; - -/* ************************************************************************ */ - -/** - * @brief Reduce empty lists. - */ -template -struct ReduceEmpty -{ - /// Result unit type. - using type = Unit; -}; - -/* ************************************************************************ */ - -/** - * @brief Reduce empty lists. - */ -template<> -struct ReduceEmpty, List<>> -{ - /// Result unit type. - using type = Value; -}; - -/* ************************************************************************ */ - -/** - * @brief Value filter. - * - * @tparam T Type to filter. - * @tparam neg Negate less. - * @tparam Types Types. - */ -template -struct Filter; - -/* ************************************************************************ */ - -/** - * @brief Value filter. - * - * @tparam T Type to filter. - * @tparam neg Negate less. - * @tparam Type First type. - * @tparam Types Types. - */ -template -struct Filter> -{ - // List without the first type. - using tail = typename Filter>::type; - - using type = typename std::conditional< - neg ^ Less::value, - typename Concat, tail>::type, - tail - >::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Value filter. - * - * @tparam T Type to filter. - * @tparam neg Negate less. - */ -template -struct Filter> -{ - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief List sorting structure. - * - * @tparam Types Types. - */ -template -struct Sort; - -/* ************************************************************************ */ - -/** - * @brief List sorting structure. - * - * @tparam Type First type. - * @tparam Types A list of types. - */ -template -struct Sort> -{ - using front = typename Filter>::type; - using tail = typename Filter>::type; - - // Sorted list. - using type = typename Concat, tail>::type; -}; - -/* ************************************************************************ */ - -/** - * @brief List sorting structure. - * - * @tparam Type Type. - */ -template -struct Sort> -{ - using type = List; -}; - -/* ************************************************************************ */ - -/** - * @brief List sorting structure. - */ -template<> -struct Sort> -{ - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief Helper class to reduce units. - * - * @tparam Nom Nominators. - * @tparam Denom Denominators. - */ -template -struct Reduce; - -/* ************************************************************************ */ - -/** - * @brief Helper class to simplify units. - * - * Type removes shared types in nominator and denominator. - * - * @tparam Nom First nominator. - * @tparam Nominators List types. - * @tparam Denominators List types. - */ -template -struct Reduce, List> -{ - // Inner reduce - using inner = ReduceInner, List>; - - /// Result unit type. - using type = typename ReduceEmpty< - typename Sort::type, - typename Sort::type - >::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator==( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return std::abs(lhs.value() - rhs.value()) < std::numeric_limits::epsilon(); - //return lhs.value() == rhs.value(); -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator==( - Unit, List> lhs, Zero_t rhs -) noexcept -{ - return lhs == Unit, List>(Zero); -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator==( - Zero_t lhs, Unit, List> rhs -) noexcept -{ - return Unit, List>(Zero) == rhs; -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator!=( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return !operator==(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator!=( - Unit, List> lhs, Zero_t rhs -) noexcept -{ - return !operator==(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Compare operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator!=( - Zero_t lhs, Unit, List> rhs -) noexcept -{ - return !operator==(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Less operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator<( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return lhs.value() < rhs.value(); -} - -/* ************************************************************************ */ - -/** - * @brief Less operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Zero. - * - * @return Result value. - */ -template -inline constexpr bool operator<( - Unit, List> lhs, Zero_t -) noexcept -{ - return lhs.value() < 0; -} - -/* ************************************************************************ */ - -/** - * @brief Less operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Zero. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator<( - Zero_t, Unit, List> rhs -) noexcept -{ - return 0 < rhs.value(); -} - -/* ************************************************************************ */ - -/** - * @brief Less equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator<=( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return !operator>(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Less equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Zero. - * - * @return Result value. - */ -template -inline constexpr bool operator<=( - Unit, List> lhs, Zero_t -) noexcept -{ - return !operator>(lhs, Zero); -} - -/* ************************************************************************ */ - -/** - * @brief Less equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Zero. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator<=( - Zero_t, Unit, List> rhs -) noexcept -{ - return !operator>(Zero, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Greater operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator>( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return operator<(rhs, lhs); -} - -/* ************************************************************************ */ - -/** - * @brief Greater operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Zero. - * - * @return Result value. - */ -template -inline constexpr bool operator>( - Unit, List> lhs, Zero_t -) noexcept -{ - return operator<(Zero, lhs); -} - -/* ************************************************************************ */ - -/** - * @brief Greater operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Zero. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator>( - Zero_t, Unit, List> rhs -) noexcept -{ - return operator<(rhs, Zero); -} - -/* ************************************************************************ */ - -/** - * @brief Greater equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator>=( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return !operator<(lhs, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Greater equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Zero. - * - * @return Result value. - */ -template -inline constexpr bool operator>=( - Unit, List> lhs, Zero_t -) noexcept -{ - return !operator<(lhs, Zero); -} - -/* ************************************************************************ */ - -/** - * @brief Greater equals operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Zero. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr bool operator>=( - Zero_t, Unit, List> rhs -) noexcept -{ - return !operator<(Zero, rhs); -} - -/* ************************************************************************ */ - -/** - * @brief Addition operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator+( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return lhs += rhs; -} - -/* ************************************************************************ */ - -/** - * @brief Substraction operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator-( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return lhs -= rhs; -} - -/* ************************************************************************ */ - -/** - * @brief Multiplication operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator*( - Unit, List> lhs, - typename Unit, List>::value_type rhs) noexcept -{ - return lhs *= rhs; -} - -/* ************************************************************************ */ - -/** - * @brief Multiplication operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator*( - typename Unit, List>::value_type lhs, - Unit, List> rhs -) noexcept -{ - return rhs *= lhs; -} - -/* ************************************************************************ */ - -/** - * @brief Multiplication operator. - * - * @tparam Nominators1 A list of nominators. - * @tparam Denominators1 A list of denominators. - * @tparam Nominators2 A list of nominators. - * @tparam Denominators2 A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -typename Reduce, List>::type operator*( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return typename Reduce, List>::type{ - lhs.value() * rhs.value() - }; -} - -/* ************************************************************************ */ - -/** - * @brief Dividing operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator/( - Unit, List> lhs, - typename Unit, List>::value_type rhs -) noexcept -{ - return lhs /= rhs; -} - -/* ************************************************************************ */ - -/** - * @brief Dividing operator. - * - * @tparam Nominators A list of nominators. - * @tparam Denominators A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -Unit, List> operator/( - typename Unit, List>::value_type lhs, - Unit, List> rhs -) noexcept -{ - return Unit, List>(lhs / rhs.value()); -} - -/* ************************************************************************ */ - -/** - * @brief Dividing operator. - * - * @tparam Nominators1 A list of nominators. - * @tparam Denominators1 A list of denominators. - * @tparam Nominators2 A list of nominators. - * @tparam Denominators2 A list of denominators. - * - * @param lhs Left operand. - * @param rhs Right operand. - * - * @return Result value. - */ -template -inline constexpr -typename Reduce, List>::type operator/( - Unit, List> lhs, - Unit, List> rhs -) noexcept -{ - return typename Reduce, List>::type{ - lhs.value() / rhs.value() - }; -} - -/* ************************************************************************ */ - -/** - * @brief Remove type for Sqrt. - */ -template -struct SqrtRemove; - -/* ************************************************************************ */ - -/** - * @brief Remove type for Sqrt. - */ -template<> -struct SqrtRemove> -{ - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief Remove type for Sqrt. - */ -template -struct SqrtRemove> -{ - using Rem = Remove>; - static_assert(Rem::value, "List is not sqrt"); - - using Inner = SqrtRemove; - - using type = typename Concat, typename Inner::type>::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Square root type. - * - * @tparam Nom - * @tparam Denom - */ -template -struct Sqrt -{ - using Nominators = typename SqrtRemove::type; - using Denominators = typename SqrtRemove::type; - - using type = Unit; -}; - -/* ************************************************************************ */ - -template -typename Sqrt, List>::type -sqrt(const Unit, List>& value) noexcept -{ - return typename Sqrt, List>::type( - std::sqrt(value.value()) - ); -} - -/* ************************************************************************ */ - -/** - * @brief Division type - used for change nominator per denominator. - * - * @tparam Nom - * @tparam Denom - */ -template -struct Divide -{ - using type = decltype(Nom{} / Denom{}); -}; - -/* ************************************************************************ */ - -/** - * @brief Calculate inverse type (1 / type). - * - * @tparam T Unit type. - */ -template -struct Inverse; - -/* ************************************************************************ */ - -/** - * @brief Calculate inverse type (1 / type). - * - * @tparam Nominators - * @tparam Denominators - */ -template -struct Inverse, List>> -{ - using type = Unit, List>; -}; - -/* ************************************************************************ */ - -/** - * @brief Calculate prefix coefficient exponent. - * - * @param c SI prefix character. - * @param count Number of first SI base unit after prefix. - * - * @return Coefficient exponent. - */ -int calcPrefixExponent(char c, unsigned int count = 1); - -/* ************************************************************************ */ - -/** - * @brief Calculate prefix coefficient exponent. - * - * @param symbol SI unit symbol (or list of symbols). - * @param typeSymbol Required symbol (or list of symbols). - * @param count Number of first SI base unit after prefix. - * - * @return Coefficient exponent. - */ -int calcPrefixExponent(const String& symbol, StringView typeSymbol, unsigned int count = 1); - -/* ************************************************************************ */ - -/** - * @brief Calculate absolute value. - * - * @param unit - */ -template -inline constexpr -Unit, List> -abs(const Unit, List>& unit) -{ - return Unit, List>( - unit.value() > Value(0) - ? unit.value() - : -unit.value() - ); -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/UnitIo.cpp b/cece/core/UnitIo.cpp deleted file mode 100644 index b33bd14..0000000 --- a/cece/core/UnitIo.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "cece/core/UnitIo.hpp" - -// C++ -#include - -// CeCe -#include "cece/core/Exception.hpp" -#include "cece/core/UnitsCtors.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -namespace { - -/* ************************************************************************ */ - -/** - * @brief Check if given character can be a part of symbol. - * - * @param c - * - * @return - */ -bool isSymbolChar(char c) noexcept -{ - return ( - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - (c == '/') - ); -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -Value parse(InStream& is) -{ - String str; - is >> str; - - return parse(str); -} - -/* ************************************************************************ */ - -Value parse(StringView str) -{ - char* fSymbol; - - // Read float value - const Value value = std::strtod(str.getData(), &fSymbol); - - // Cannot be read - if (fSymbol == str.getData()) - throw InvalidArgumentException("Cannot parse unit value: " + String(str)); - - String symbol; - const char* eSymbol = str.getData() + str.getLength(); - - // Store symbol characters - for (; fSymbol != eSymbol && isSymbolChar(*fSymbol); ++fSymbol) - symbol.push_back(*fSymbol); - - // No symbol - if (symbol.empty()) - return value; - - // Predefined symbols -#define SYMBOL_TEST(nom) if (symbol == #nom) return nom(value).value() -#define SYMBOL_TEST2(nom, denom) if (symbol == #nom "/" #denom) return nom ## _ ## denom(value).value() - - SYMBOL_TEST(m); - SYMBOL_TEST(dm); - SYMBOL_TEST(mm); - SYMBOL_TEST(um); - SYMBOL_TEST(g); - SYMBOL_TEST(kg); - SYMBOL_TEST(mg); - SYMBOL_TEST(ug); - SYMBOL_TEST(ng); - SYMBOL_TEST(pg); - SYMBOL_TEST(s); - SYMBOL_TEST(ms); - SYMBOL_TEST(us); - SYMBOL_TEST(min); - SYMBOL_TEST(h); - SYMBOL_TEST(m2); - SYMBOL_TEST(dm2); - SYMBOL_TEST(mm2); - SYMBOL_TEST(um2); - SYMBOL_TEST(m3); - SYMBOL_TEST(dm3); - SYMBOL_TEST(mm3); - SYMBOL_TEST(um3); - SYMBOL_TEST2(m, s); - SYMBOL_TEST2(mm, s); - SYMBOL_TEST2(um, s); - SYMBOL_TEST2(m, s2); - SYMBOL_TEST2(mm, s2); - SYMBOL_TEST2(um, s2); - SYMBOL_TEST2(kgm, s2); - SYMBOL_TEST2(gm, s2); - SYMBOL_TEST2(mgm, s2); - SYMBOL_TEST(N); - SYMBOL_TEST(mN); - SYMBOL_TEST(uN); - SYMBOL_TEST2(Ns, m2); - SYMBOL_TEST(Pas); - SYMBOL_TEST(mPas); - SYMBOL_TEST2(m2, s); - SYMBOL_TEST2(mm2, s); - SYMBOL_TEST2(um2, s); - SYMBOL_TEST(mol); - SYMBOL_TEST(mmol); - SYMBOL_TEST(umol); - SYMBOL_TEST(nmol); - SYMBOL_TEST2(mol, m3); - SYMBOL_TEST2(mmol, m3); - SYMBOL_TEST2(umol, m3); - SYMBOL_TEST2(nmol, m3); - SYMBOL_TEST(M); - SYMBOL_TEST(mM); - SYMBOL_TEST(uM); - SYMBOL_TEST(nM); - SYMBOL_TEST2(mol, um3); - SYMBOL_TEST2(mmol, um3); - SYMBOL_TEST2(umol, um3); - SYMBOL_TEST2(nmol, um3); - -#undef SYMBOL_TEST -#undef SYMBOL_TEST2 - - // Special type - if (symbol == "/s") return (value / units::s(1)).value(); - - // Fallback - - int exponent = 0; - - // Foreach characters - for (auto it = symbol.begin(); it != symbol.end(); ++it) - { - switch (*it) - { - case 'g': - exponent += MASS_EXPONENT; - break; - - case 's': - exponent += TIME_EXPONENT; - break; - - case 'm': - // This is problematic, because it can be 'm' or 'mol' - if (*(it + 1) == 'o') - { - // Skip other two characters - it += 2; - - exponent += AMOUNT_OF_SUBSTANCE_EXPONENT; - } - else - { - exponent += LENGTH_EXPONENT; - } - break; - - default: - throw InvalidArgumentException("Unsupported unit character '" + String(1, *it) + "' in '" + symbol + "'"); - } - } - - return value * exponentToCoefficient(exponent); -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/UnitIo.hpp b/cece/core/UnitIo.hpp deleted file mode 100644 index 0526b0c..0000000 --- a/cece/core/UnitIo.hpp +++ /dev/null @@ -1,189 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/Unit.hpp" -#include "cece/core/UnitSymbol.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -/** - * @brief Parse units value. - * - * This function can handle unit suffix and convert it into proper coefficient. - * - * @note Unit prefix is not supported because there is issue with meters: - * `mg` - it's milligram or metergram? - * - * @param is Input stream. - * - * @return Result value. - */ -Value parse(InStream& is); - -/* ************************************************************************ */ - -/** - * @brief Parse units value. - * - * This function can handle unit suffix and convert it into proper coefficient. - * - * @note Unit prefix is not supported because there is issue with meters: - * `mg` - it's milligram or metergram? - * - * @param value Value to parse. - * - * @return Result value. - */ -Value parse(StringView value); - -/* ************************************************************************ */ - -/** - * @brief Input stream operator. - * - * @param is Input stream. - * @param unit Result value. - * - * @return is. - */ -template -InStream& operator>>(InStream& is, Unit, List>& unit) -{ - using Type = Unit, List>; - using SymbolType = Symbol; - - // Type symbol -#if _LIBCPP_VERSION || _MSC_VER - // MACOSX use old stdlib that doesnt support constexpr std::array. - static const auto typeSymbolNom = SymbolType::nominators::get(); - static const auto typeSymbolDenom = SymbolType::denominators::get(); -#else - static constexpr auto typeSymbolNom = SymbolType::nominators::get(); - static constexpr auto typeSymbolDenom = SymbolType::denominators::get(); -#endif - - Value val; - String symbol; - - is >> std::ws >> val; - - // Unable to load unit - if (!is) - return is; - - // No symbol given - if (!(is >> std::noskipws >> symbol)) - { - is.clear(); - - // Set value - unit = Type{val}; - return is; - } - - // Split symbol to two parts - const auto sepPos = symbol.find('/'); - - String symbolNom; - String symbolDenom; - - // Only nominators - if (sepPos == String::npos) - { - symbolNom = symbol; - } - else - { - symbolNom = symbol.substr(0, sepPos); - symbolDenom = symbol.substr(sepPos + 1); - } - - // Get coefficient exponent - const int exponent = 0 - // Base given by type - + Type::exponent - // Nominators - + calcPrefixExponent(symbolNom, typeSymbolNom, Type::firstCountNom) - // Denominators - - calcPrefixExponent(symbolDenom, typeSymbolDenom, Type::firstCountDenom) - ; - - // Value coefficient - const Value coefficient = exponentToCoefficient(exponent); - - // Set unit - unit = Type(val * coefficient); - - return is; -} - -/* ************************************************************************ */ - -/** - * @brief Output stream operator. - * - * @param os Output stream. - * @param unit Input value. - * - * @return os. - */ -template -OutStream& operator<<(OutStream& os, const Unit, List>& unit) noexcept -{ - os << unit.value(); - - // TODO: write suffix - - return os; -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/UnitSymbol.hpp b/cece/core/UnitSymbol.hpp deleted file mode 100644 index 363c726..0000000 --- a/cece/core/UnitSymbol.hpp +++ /dev/null @@ -1,505 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// C++ -#include -#include - -// CeCe -#include "cece/core/Units.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/IntegerSequence.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -/** - * @brief Group of unit symbol. - * - * @tparam Type Base unit type. - * @tparam Count Number of base unit occurences. - */ -template -struct SymbolGroup -{ - static_assert(Count > 1, "Count must be greater than 1"); - static_assert(Count < 10, "Count must be less than 10"); - - - /// Length of the base suffix. - static constexpr std::size_t length = Type::symbolLength + 1; - - - /** - * @brief Create symbol character array. - * - * @tparam Indices Indices from symbol array to use. - * - * @param symbol Type symbol. - * @param indices Sequence of indices. - * - * @return Result symbol. - */ - template - static constexpr StaticArray createSymbol( - const StaticArray& symbol, - IntegerSequence indices - ) noexcept - { - return {{symbol[Indices]..., '0' + Count, '\0'}}; - } - - - /** - * @brief Returns symbol character array. - * - * @return - */ - static constexpr StaticArray get() noexcept - { - return createSymbol(Type::getSymbol(), MakeIntegerSequence{}); - } -}; - -/* ************************************************************************ */ - -/** - * @brief Group of unit symbol specialization for single occurence. - * - * @tparam Type Base unit type. - */ -template -struct SymbolGroup -{ - /// Length of the base suffix. - static constexpr std::size_t length = Type::symbolLength; - - - /** - * @brief Returns symbol character array. - * - * @return - */ - static constexpr StaticArray get() noexcept - { - return Type::getSymbol(); - } -}; - -/* ************************************************************************ */ - -/** - * @brief Create SymbolGroup for list of types. - * - * @tparam Types A list of types. - */ -template -struct SymbolGrouper; - -/* ************************************************************************ */ - -/** - * @brief Create SymbolGroup for list of types. - * - * @tparam Types A list of types. - */ -template<> -struct SymbolGrouper> -{ - /// List of suffix groups - using type = List<>; -}; - -/* ************************************************************************ */ - -/** - * @brief Create SymbolGroup for list of types. - * - * @tparam Type The first type. - * @tparam Types A list of types. - */ -template -struct SymbolGrouper> -{ - using RemoveType = RemoveAll>; - - /// List of suffix groups. - using type = typename Concat< - List>, - typename SymbolGrouper::type - >::type; -}; - -/* ************************************************************************ */ - -/** - * @brief Symbol length. - * - * @tparam Types List of types. - */ -template -struct SymbolLength; - -/* ************************************************************************ */ - -/** - * @brief Symbol length. - * - * @tparam Types List of types. - */ -template -struct SymbolLength> -{ - - /** - * @brief Add lengths. - * - * @param arg The first length. - * @param args Rest of the lengths. - * - * @return Total length. - */ - template - static constexpr std::size_t add(Arg&& arg, Args&&... args) noexcept - { - return arg + add(args...); - } - - - /** - * @brief Add length. - * - * @return 0. - */ - static constexpr std::size_t add() noexcept - { - return std::size_t(0); - } - - - /// Symbol length with '\0' and without '\0' of each type. - static constexpr std::size_t value = add(Types::length...) - sizeof...(Types) + 1; - -}; - -/* ************************************************************************ */ - -/** - * @brief Unit type symbol. - * - * @tparam Types List of base types. - */ -template -struct SymbolBase; - -/* ************************************************************************ */ - -/** - * @brief Unit type symbol. - * - * @tparam Types List of base types. - */ -template -struct SymbolBase> -{ - - /// Symbol length. - static constexpr std::size_t length = SymbolLength>::value; - - - /** - * @brief Concatenate two symbols. - * - * @tparam N1 Length of the first symbol. - * @tparam N2 Length of the second symbol. - * @tparam Indices1 Indices for the first symbol. - * @tparam Indices2 Indices for the second symbol. - * - * @param symbol1 The first symbol. - * @param seq1 Indices for the first symbol. - * @param symbol2 The second symbol. - * @param seq2 Indices for the second symbol. - * - * @return Result symbol. - */ - template - static constexpr StaticArray concat( - const StaticArray& symbol1, - IntegerSequence seq1, - const StaticArray& symbol2, - IntegerSequence seq2 - ) noexcept - { - static_assert(N1 + N2 - 1 == sizeof...(Indices1) + sizeof...(Indices2) + 1, "Sizes doesn't match"); - - return {{symbol1[Indices1]..., symbol2[Indices2]..., '\0'}}; - } - - - /** - * @brief Create empty symbol. - * - * @return Empty array (only '\0'). - */ - static constexpr StaticArray createSymbol() noexcept - { - return {{'\0'}}; - } - - - /** - * @brief Create symbol from single symbol. - * - * @tparam N1 Length of the symbol. - * - * @param symbol Source symbol. - */ - template - static constexpr StaticArray createSymbol(StaticArray symbol) noexcept - { - return symbol; - } - - - /** - * @brief Create symbol from two symbols. - * - * @tparam N1 Length of the first symbol. - * @tparam N2 Length of the second symbol. - * - * @param symbol1 The first symbol. - * @param symbol2 The second symbol. - * - * @return Result symbol. - */ - template - static constexpr StaticArray createSymbol( - const StaticArray& symbol1, - const StaticArray& symbol2 - ) noexcept - { - return concat( - symbol1, MakeIntegerSequence{}, - symbol2, MakeIntegerSequence{} - ); - } - - - /** - * @brief Create symbol from three symbols. - * - * @tparam N1 Length of the first symbol. - * @tparam N2 Length of the second symbol. - * @tparam N3 Length of the third symbol. - * - * @param symbol1 The first symbol. - * @param symbol2 The second symbol. - * @param symbol3 The third symbol. - * - * @return Result symbol. - */ - template - static constexpr StaticArray createSymbol( - const StaticArray& symbol1, - const StaticArray& symbol2, - const StaticArray& symbol3) noexcept - { - return createSymbol(symbol1, createSymbol(symbol2, symbol3)); - } - - - /** - * @brief Returns suffix array string. - */ -#if 0 - // TODO: support for more symbols - template - static constexpr auto createSymbol(const StaticArray& a1, Arrays&&... arrays) noexcept - -> decltype(createSymbol(a1, createSymbol(std::forward(arrays)...))) - { - static_assert(sizeof...(Arrays) > 2, "Damn"); - - return createSymbol(a1, createSymbol(std::forward(arrays)...)); - } -#endif - - - /** - * @brief Returns symbol character array. - * - * @return - */ - static constexpr StaticArray get() noexcept - { - return createSymbol(Types::get()...); - } -}; - -/* ************************************************************************ */ - -/** - * @brief Symbol for unit type. - * - * @tparam Nominators List of nominators. - * @tparam Denominators List of denominators. - */ -template -struct SymbolBase, List> -{ - /// Nominators symbol. - using SymbolNominators = SymbolBase>::type>; - - /// Denominators symbol. - using SymbolDenominators = SymbolBase>::type>; - - - /// Length of nominator symbol. - static constexpr std::size_t nomLength = SymbolNominators::length; - - /// Length of denominator symbol. - static constexpr std::size_t denomLength = SymbolDenominators::length; - - /// Total symbol length. - static constexpr std::size_t length = nomLength + (denomLength == 1 ? 0 : denomLength); - - - /** - * @brief Concatenate nominator and denominator symbols. - * - * @tparam IndicesNom Indices for nominator symbol. - * @tparam IndicesDenom Indices for denominator symbol. - * - * @param nominatorSymbol Nominator symbol. - * @param denominatorSymbol Denominator symbol. - * - * @return Result symbol. - */ - template - static constexpr StaticArray concat( - const StaticArray& nominatorSymbol, - IntegerSequence, - const StaticArray& denominatorSymbol, - IntegerSequence - ) noexcept - { - return {{ - nominatorSymbol[IndicesNom]..., - '/', - denominatorSymbol[IndicesDenom]..., - '\0' - }}; - } - - - /** - * @brief Create symbol without denominator symbol. - * - * @tparam IndicesNom Indices for nominator symbol. - * - * @param nominatorSymbol Nominator symbol. - * - * @return Result symbol. - */ - template - static constexpr StaticArray concat( - const StaticArray& nominatorSymbol, - IntegerSequence, - const StaticArray&, - IntegerSequence - ) noexcept - { - return {{nominatorSymbol[IndicesNom]..., '\0'}}; - } - - - /** - * @brief Returns symbol character array. - * - * @return - */ - static constexpr StaticArray get() noexcept - { - return concat( - SymbolNominators::get(), - MakeIntegerSequence{}, - SymbolDenominators::get(), - MakeIntegerSequence{} - ); - } -}; - -/* ************************************************************************ */ - -/** - * @brief Symbol for specified unit type. - * - * @tparam UnitType - */ -template -struct Symbol; - -/* ************************************************************************ */ - -/** - * @brief Symbol for specified unit type. - * - * @tparam Nom List type. - * @tparam Denom List type. - */ -template -struct Symbol> -{ - /// Unit symbol type. - using type = SymbolBase; - - /// Symbol for nominators. - using nominators = typename type::SymbolNominators; - - /// Symbol for denominators. - using denominators = typename type::SymbolDenominators; -}; - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/Units.cpp b/cece/core/Units.cpp deleted file mode 100644 index 0c5927e..0000000 --- a/cece/core/Units.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "cece/core/Units.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -template class Unit, List<>>; -template class Unit, List<>>; -template class Unit, List<>>; -template class Unit, List<>>; -template class Unit, List<>>; -template class Unit, List<>>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List<>>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; -template class Unit, List>; - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/UnitsCtors.hpp b/cece/core/UnitsCtors.hpp deleted file mode 100644 index fbbe9e7..0000000 --- a/cece/core/UnitsCtors.hpp +++ /dev/null @@ -1,932 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/Units.hpp" - -/* ************************************************************************ */ - -namespace cece { -inline namespace core { - -/* ************************************************************************ */ - -namespace units { - -/* ************************************************************************ */ - -/** - * @brief Meter value. - * - * @param value Value. - * - * @return Length value. - */ -inline constexpr Length m(Value value) noexcept -{ - // 1m = 1'000mm - return Length(value * exponentToCoefficient(LENGTH_EXPONENT)); -} - -/* ************************************************************************ */ - -/** - * @brief Decimeter value. - * - * @param value Value. - * - * @return Length value. - */ -inline constexpr Length dm(Value value) noexcept -{ - return m(value * 1e-1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeter value. - * - * @param value Value. - * - * @return Length value. - */ -inline constexpr Length mm(Value value) noexcept -{ - // 1mm = 1/1'000m - return m(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometer value. - * - * @param value Value. - * - * @return Length value. - */ -inline constexpr Length um(Value value) noexcept -{ - // 1um = 1/1'000'000m - return m(value * 1e-6); -} - -/* ************************************************************************ */ - -/** - * @brief Grams value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass g(Value value) noexcept -{ - return Mass(value * exponentToCoefficient(MASS_EXPONENT)); -} - -/* ************************************************************************ */ - -/** - * @brief Kilograms value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass kg(Value value) noexcept -{ - // 1g = 1/1'000 kg - return g(value * 1e3); -} - -/* ************************************************************************ */ - -/** - * @brief Milligrams value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass mg(Value value) noexcept -{ - // 1mg = 1/1'000 g - return g(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Micrograms value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass ug(Value value) noexcept -{ - // 1ug = 1/1'000 mg - return mg(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Nanograms value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass ng(Value value) noexcept -{ - // 1ng = 1/1'000 ug - return ug(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Micrograms value. - * - * @param value Value. - * - * @return Mass value. - */ -inline constexpr Mass pg(Value value) noexcept -{ - // 1pg = 1/1'000 ng - return ng(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Seconds value. - * - * @param value Value. - * - * @return Time value. - */ -inline constexpr Time s(Value value) noexcept -{ - // 1s - return Time(value * exponentToCoefficient(TIME_EXPONENT)); -} - -/* ************************************************************************ */ - -/** - * @brief Milliseconds value. - * - * @param value Value. - * - * @return Time value. - */ -inline constexpr Time ms(Value value) noexcept -{ - // 1s = 1'000ms - return s(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Microseconds value. - * - * @param value Value. - * - * @return Time value. - */ -inline constexpr Time us(Value value) noexcept -{ - // 1ms = 1'000us - return ms(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Minutes value. - * - * @param value Value. - * - * @return Time value. - */ -inline constexpr Time min(Value value) noexcept -{ - // 60s = 1min - return s(60 * value); -} - -/* ************************************************************************ */ - -/** - * @brief Hours value. - * - * @param value Value. - * - * @return Time value. - */ -inline constexpr Time h(Value value) noexcept -{ - // 60min = 1h - return min(60 * value); -} - -/* ************************************************************************ */ - -/** - * @brief Meters^2 value. - * - * @param value Value. - * - * @return Area value. - */ -inline constexpr Area m2(Value value) noexcept -{ - return m(value) * m(1); -} - -/* ************************************************************************ */ - -/** - * @brief Decimeters^2 value. - * - * @param value Value. - * - * @return Area value. - */ -inline constexpr Area dm2(Value value) noexcept -{ - return dm(value) * dm(1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeters^2 value. - * - * @param value Value. - * - * @return Area value. - */ -inline constexpr Area mm2(Value value) noexcept -{ - return mm(value) * mm(1); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometers^2 value. - * - * @param value Value. - * - * @return Area value. - */ -inline constexpr Area um2(Value value) noexcept -{ - return um(value) * um(1); -} - -/* ************************************************************************ */ - -/** - * @brief Meters^3 value. - * - * @param value Value. - * - * @return Volume value. - */ -inline constexpr Volume m3(Value value) noexcept -{ - return m2(value) * m(1); -} - -/* ************************************************************************ */ - -/** - * @brief Decimeters^3 value. - * - * @param value Value. - * - * @return Volume value. - */ -inline constexpr Volume dm3(Value value) noexcept -{ - return dm2(value) * dm(1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeters^3 value. - * - * @param value Value. - * - * @return Volume value. - */ -inline constexpr Volume mm3(Value value) noexcept -{ - return mm2(value) * mm(1); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometers^3 value. - * - * @param value Value. - * - * @return Volume value. - */ -inline constexpr Volume um3(Value value) noexcept -{ - return um2(value) * um(1); -} - -/* ************************************************************************ */ - -/** - * @brief Meters per second value. - * - * @param value Value. - * - * @return Velocity value. - */ -inline constexpr Velocity m_s(Value value) noexcept -{ - return m(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeters per second value. - * - * @param value Value. - * - * @return Velocity value. - */ -inline constexpr Velocity mm_s(Value value) noexcept -{ - return mm(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometers per second value. - * - * @param value Value. - * - * @return Velocity value. - */ -inline constexpr Velocity um_s(Value value) noexcept -{ - return um(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Meters per second^2 value. - * - * @param value Value. - * - * @return Acceleration value. - */ -inline constexpr Acceleration m_s2(Value value) noexcept -{ - return m_s(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeters per second^2 value. - * - * @param value Value. - * - * @return Acceleration value. - */ -inline constexpr Acceleration mm_s2(Value value) noexcept -{ - return mm_s(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometers per second^2 value. - * - * @param value Value. - * - * @return Acceleration value. - */ -inline constexpr Acceleration um_s2(Value value) noexcept -{ - return um_s(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Kilogram meter per second^2 value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force kgm_s2(Value value) noexcept -{ - return kg(value) * m_s2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Gram meter per second^2 value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force gm_s2(Value value) noexcept -{ - return g(value) * m_s2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Milligram meter per second^2 value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force mgm_s2(Value value) noexcept -{ - return kg(value) * m_s2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Newton value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force N(Value value) noexcept -{ - return kgm_s2(value); -} - -/* ************************************************************************ */ - -/** - * @brief Millinewton value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force mN(Value value) noexcept -{ - return gm_s2(value); -} - -/* ************************************************************************ */ - -/** - * @brief Micronewton value. - * - * @param value Value. - * - * @return Force value. - */ -inline constexpr Force uN(Value value) noexcept -{ - return mgm_s2(value); -} - -/* ************************************************************************ */ - -/** - * @brief Kilogram per meter and second value. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr DynamicViscosity kg_m_s(Value value) noexcept -{ - return kg(value) / (m(1) * s(1)); -} - -/* ************************************************************************ */ - -/** - * @brief Kilogram per meter and second value. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr DynamicViscosity g_m_s(Value value) noexcept -{ - return g(value) / (m(1) * s(1)); -} - -/* ************************************************************************ */ - -/** - * @brief Newton second per meter square value. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr DynamicViscosity Ns_m2(Value value) noexcept -{ - return N(value) * s(1) / m2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Newton second per meter square value. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr DynamicViscosity Pas(Value value) noexcept -{ - return N(value) * s(1) / m2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Newton second per meter square value. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr DynamicViscosity mPas(Value value) noexcept -{ - return mN(value) * s(1) / m2(1); -} - -/* ************************************************************************ */ - -/** - * @brief Meter square per second. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr KinematicViscosity m2_s(Value value) noexcept -{ - return m2(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Millimeter square per second. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr KinematicViscosity mm2_s(Value value) noexcept -{ - return mm2(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Micrometer square per second. - * - * @param value Value. - * - * @return Viscosity value. - */ -inline constexpr KinematicViscosity um2_s(Value value) noexcept -{ - return um2(value) / s(1); -} - -/* ************************************************************************ */ - -/** - * @brief Mole value. - * - * @param value - * - * @return Amount of substance. - */ -inline constexpr AmountOfSubstance mol(Value value) noexcept -{ - return AmountOfSubstance(value * exponentToCoefficient(AMOUNT_OF_SUBSTANCE_EXPONENT)); -} - -/* ************************************************************************ */ - -/** - * @brief Millimole value. - * - * @param value - * - * @return Amount of substance. - */ -inline constexpr AmountOfSubstance mmol(Value value) noexcept -{ - return mol(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Micromole value. - * - * @param value - * - * @return Amount of substance. - */ -inline constexpr AmountOfSubstance umol(Value value) noexcept -{ - return mmol(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Nanomole value. - * - * @param value - * - * @return Amount of substance. - */ -inline constexpr AmountOfSubstance nmol(Value value) noexcept -{ - return umol(value * 1e-3); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in mole per meter cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration mol_m3(Value value) noexcept -{ - return mol(value) / m3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in millimole per meter cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration mmol_m3(Value value) noexcept -{ - return mmol(value) / m3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in micromole per meter cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration umol_m3(Value value) noexcept -{ - return umol(value) / m3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in nanomole per meter cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration nmol_m3(Value value) noexcept -{ - return nmol(value) / m3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in Molar. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration M(Value value) noexcept -{ - return mol(value) / dm3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in miniMolar. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration mM(Value value) noexcept -{ - return mmol(value) / dm3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in microMolar. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration uM(Value value) noexcept -{ - return umol(value) / dm3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in nanoMolar. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration nM(Value value) noexcept -{ - return nmol(value) / dm3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in mole per micrometer cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration mol_um3(Value value) noexcept -{ - return mol(value) / um3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in millimole per micrometer cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration mmol_um3(Value value) noexcept -{ - return mmol(value) / um3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in micromole per micrometer cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration umol_um3(Value value) noexcept -{ - return umol(value) / um3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Returns concentration in nanomole per micrometer cubic. - * - * @param value - * - * @return Molar concentration. - */ -inline constexpr MolarConcentration nmol_um3(Value value) noexcept -{ - return nmol(value) / um3(1); -} - -/* ************************************************************************ */ - -/** - * @brief Radian constructor. - * - * @param value Value in radians. - * - * @return Angle. - */ -inline constexpr Angle rad(Value value) noexcept -{ - return Angle(value); -} - -/* ************************************************************************ */ - -/** - * @brief Degree constructor. - * - * @param value Value in degrees. - * - * @return Angle. - */ -inline constexpr Angle deg(Value value) noexcept -{ - return rad(deg2rad(value)); -} - -/* ************************************************************************ */ - -/** - * @brief Probability constructor. - * - * @param value Value in precent. - * - * @return - */ -inline constexpr Probability precent(Value value) noexcept -{ - return Probability(value / 100.0); -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/UnitsSymbol.hpp b/cece/core/UnitsSymbol.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/cece/core/test/UnitsTest.cpp b/cece/core/test/UnitsTest.cpp deleted file mode 100644 index 2b4b118..0000000 --- a/cece/core/test/UnitsTest.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// GTest -#include - -// CeCe -#include "cece/core/StringStream.hpp" -#include "cece/core/UnitIo.hpp" -#include "cece/core/UnitSymbol.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/UnitsCtors.hpp" - -/* ************************************************************************ */ - -using namespace cece; - -/* ************************************************************************ */ - -TEST(UnitsTest, exponentToCoefficient) -{ - EXPECT_FLOAT_EQ(1e0, units::exponentToCoefficient(0)); - - EXPECT_FLOAT_EQ(1e1, units::exponentToCoefficient(1)); - EXPECT_FLOAT_EQ(1e2, units::exponentToCoefficient(2)); - EXPECT_FLOAT_EQ(1e3, units::exponentToCoefficient(3)); - EXPECT_FLOAT_EQ(1e4, units::exponentToCoefficient(4)); - EXPECT_FLOAT_EQ(1e5, units::exponentToCoefficient(5)); - EXPECT_FLOAT_EQ(1e6, units::exponentToCoefficient(6)); - EXPECT_FLOAT_EQ(1e7, units::exponentToCoefficient(7)); - EXPECT_FLOAT_EQ(1e8, units::exponentToCoefficient(8)); - - EXPECT_FLOAT_EQ(1e-1, units::exponentToCoefficient(-1)); - EXPECT_FLOAT_EQ(1e-2, units::exponentToCoefficient(-2)); - EXPECT_FLOAT_EQ(1e-3, units::exponentToCoefficient(-3)); - EXPECT_FLOAT_EQ(1e-4, units::exponentToCoefficient(-4)); - EXPECT_FLOAT_EQ(1e-5, units::exponentToCoefficient(-5)); - EXPECT_FLOAT_EQ(1e-6, units::exponentToCoefficient(-6)); - EXPECT_FLOAT_EQ(1e-7, units::exponentToCoefficient(-7)); - EXPECT_FLOAT_EQ(1e-8, units::exponentToCoefficient(-8)); -} - -/* ************************************************************************ */ - -TEST(UnitsTest, lengthValues) -{ - EXPECT_EQ(units::m(1), units::mm(1000)); - EXPECT_EQ(units::m(0.5), units::mm(500)); - EXPECT_EQ(units::mm(1000), units::m(1)); - EXPECT_EQ(units::m(1), units::mm(1000)); - //EXPECT_EQ(units::mm(5), units::um(5000)); // FIXME: float precision issue - //EXPECT_EQ(units::um(1), units::mm(0.001)); // FIXME: float precision issue -} - -/* ************************************************************************ */ - -TEST(UnitsTest, timeValues) -{ - EXPECT_EQ(units::s(1), units::ms(1000)); - EXPECT_EQ(units::ms(500), units::s(0.5)); -} - -/* ************************************************************************ */ - -TEST(UnitsTest, massValues) -{ - EXPECT_EQ(units::kg(1), units::g(1000)); - EXPECT_EQ(units::g(1), units::mg(1000)); - EXPECT_EQ(units::mg(1), units::ug(1000)); - EXPECT_EQ(units::ug(1), units::ng(1000)); - EXPECT_EQ(units::ng(1), units::pg(1000)); -} - -/* ************************************************************************ */ - -TEST(UnitsTest, multiplication) -{ - EXPECT_EQ(units::m(1) * units::m(1), units::m2(1)); - EXPECT_EQ(units::m(2) * units::m(2), units::m2(4)); - EXPECT_EQ(units::m(3) * units::m(4), units::m2(12)); - EXPECT_EQ(units::mm(2) * units::mm(3), units::mm2(6)); -} - -/* ************************************************************************ */ - -TEST(UnitsTest, dividion) -{ - EXPECT_FLOAT_EQ(units::m(1) / units::m(1), 1); - EXPECT_FLOAT_EQ(units::m(5) / units::m(5), 1); - EXPECT_FLOAT_EQ(units::m(6) / units::m(2), 3); - EXPECT_EQ(units::m(8) / units::s(2), units::m_s(4)); -} - -/* ************************************************************************ */ - -TEST(UnitsTest, symbol) -{ - using namespace units; - - { - using type = Unit, List<>>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m", symbol); - } - - { - using type = Unit, List<>>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m2", symbol); - } - - { - using type = Unit, List<>>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m3", symbol); - } - - { - using type = Unit, List<>>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m4", symbol); - } - - { - using type = Unit, List>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m2/s", symbol); - } - - { - using type = Unit, List>; - String symbol(Symbol::type::get().data()); - EXPECT_EQ("m/s2", symbol); - } -} - -/* ************************************************************************ */ - -TEST(UnitsTest, istream) -{ - { - InStringStream is("0"); - - units::Length val; - is >> val; - - EXPECT_EQ(units::um(0), val); - } - - { - InStringStream is("0um"); - - units::Length val; - is >> val; - - EXPECT_EQ(units::um(0), val); - } - -/* - // FIXME: Precision issues - { - InStringStream is("100um"); - - units::Length val; - is >> val; - - EXPECT_EQ(units::um(100), val); - } -*/ - - { - InStringStream is(" 500ms "); - - units::Time val; - is >> val; - - EXPECT_EQ(units::ms(500), val); - } - - { - InStringStream is("2um2"); - - units::Area val; - is >> val; - - EXPECT_EQ(units::um2(2), val); - } - - { - InStringStream is("1umol/um3"); - - units::MolarConcentration val; - is >> val; - - EXPECT_EQ(units::umol_um3(1), val); - } -} - -/* ************************************************************************ */ - -TEST(UnitsTest, abbr) -{ - { - InStringStream is("15mM"); // 1mM = 1mol/m3 - - units::MolarConcentration val; - is >> val; - - EXPECT_EQ(units::mol_m3(15), val); - } -} - -/* ************************************************************************ */ - -TEST(UnitsTest, parse) -{ - { - InStringStream is("0"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(0, val); - } - - { - InStringStream is("0um"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(0, val); - } - - { - InStringStream is("100um"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::um(100).value(), val); - } - - { - InStringStream is(" 500ms "); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::ms(500).value(), val); - } - - { - InStringStream is("2um2"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::um2(2).value(), val); - } - - { - InStringStream is("1umol/um3"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::umol_um3(1).value(), val); - } - - { - InStringStream is("15mM"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::mM(15).value(), val); - } - - { - InStringStream is("50nM"); - - units::Value val = units::parse(is); - - EXPECT_FLOAT_EQ(units::nM(50).value(), val); - } -} - -/* ************************************************************************ */ diff --git a/cece/object/CMakeLists.txt b/cece/object/CMakeLists.txt deleted file mode 100644 index b4fc755..0000000 --- a/cece/object/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# ######################################################################### # -# Georgiev Lab (c) 2015-2016 # -# ######################################################################### # -# Department of Cybernetics # -# Faculty of Applied Sciences # -# University of West Bohemia in Pilsen # -# ######################################################################### # -# # -# This file is part of CeCe. # -# # -# CeCe is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# CeCe is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with CeCe. If not, see . # -# # -# ######################################################################### # - -# Sources -set(SRCS - Object.hpp - Object.cpp - Type.hpp - TypeContainer.hpp - TypeContainer.cpp - Factory.hpp - Factory.cpp - FactoryManager.hpp - FactoryManager.cpp - Container.hpp - Container.cpp - BoundData.hpp - BoundData.cpp - ContactListener.hpp - ContactListener.cpp -) - -# ######################################################################### # - -dir_pretend(SOURCES object/ ${SRCS}) - -set(SOURCES_OBJECT ${SOURCES} PARENT_SCOPE) - -# ######################################################################### # diff --git a/cece/object/FactoryManager.cpp b/cece/object/FactoryManager.cpp deleted file mode 100644 index 73681da..0000000 --- a/cece/object/FactoryManager.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "cece/object/FactoryManager.hpp" - -// CeCe -#include "cece/object/Object.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace object { - -/* ************************************************************************ */ - -UniquePtr FactoryManager::createObject(StringView name, simulator::Simulation& simulation, Object::Type type) const -{ - return core::FactoryManager::createObject(name, simulation, String(name), type); -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Context.cpp b/cece/plugin/Context.cpp deleted file mode 100644 index a108c8b..0000000 --- a/cece/plugin/Context.cpp +++ /dev/null @@ -1,406 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "cece/plugin/Context.hpp" - -// CeCe -#include "cece/core/Log.hpp" -#include "cece/core/Exception.hpp" -#include "cece/plugin/Repository.hpp" -#include "cece/plugin/Manager.hpp" -#include "cece/plugin/Api.hpp" -#include "cece/loader/Loader.hpp" -#include "cece/init/Initializer.hpp" -#include "cece/module/Module.hpp" -#include "cece/object/Object.hpp" -#include "cece/program/Program.hpp" -#include "cece/simulator/Simulation.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -namespace { - -/* ************************************************************************ */ - -/** - * @brief Find factory name in all plugins to give a hint for user. - * - * @param name - * @param repo - * @param fn - * - * @return - */ -template -DynamicArray getPluginNames(StringView name, const Repository& repo, RecordFn fn) -{ - DynamicArray names; - const auto& manager = repo.getManager(); - - // Foreach repository records - for (const auto& record : repo.getRecords()) - { - const auto* mgr = fn(record.second); - CECE_ASSERT(mgr); - - if (mgr->exists(name)) - names.push_back(String(manager.getName(record.first))); - } - - return names; -} - -/* ************************************************************************ */ - -/** - * @brief Join strings from array. - * - * @param array - * - * @return - */ -String join(const DynamicArray& array) noexcept -{ - String res; - - for (auto it = array.begin(); it != array.end(); ++it) - { - if (it != array.begin()) - res += ", "; - - res += *it; - } - - return res; -} - -/* ************************************************************************ */ - -} - -/* ************************************************************************ */ - -bool Context::isImported(StringView name) const noexcept -{ - auto it = m_plugins.find(String(name)); - return it != m_plugins.end(); -} - -/* ************************************************************************ */ - -ViewPtr Context::importPlugin(StringView name) -{ - // Do not add duplicates - auto it = m_plugins.find(String(name)); - - // Already imported - if (it != m_plugins.end()) - return it->second; - - Log::info("Importing plugin '", name, "'..."); - - // Load plugin - auto api = getRepository().getManager().getApi(name); - - // Plugin not found - if (!api) - throw RuntimeException("Cannot import plugin: " + String(name)); - - // Check conflict plugins - for (const auto& pluginName : api->conflictPlugins()) - { - if (isImported(pluginName)) - throw RuntimeException("Cannot import plugin: " + String(name) + ". Confliction with plugin: " + pluginName); - } - - // Import required plugins - for (const auto& pluginName : api->requiredPlugins()) - importPlugin(pluginName); - - // Store API - m_plugins.emplace(String(name), api); - - return api; -} - -/* ************************************************************************ */ - -ViewPtr Context::removePlugin(StringView name) -{ - // Find plugin - auto it = m_plugins.find(String(name)); - - // Nothing to unload - if (it == m_plugins.end()) - return nullptr; - - // Store api to return - auto api = it->second; - - // Remove plugin - m_plugins.erase(it); - - return api; -} - -/* ************************************************************************ */ - -UniquePtr Context::createSimulation(const FilePath& filepath, ViewPtr parameters) const -{ - // File extension - auto ext = filepath.getExtension().substr(1); - - // Find loader by extension - auto loader = createLoader(ext); - CECE_ASSERT(loader); - - // Create a simulation - return loader->fromFile(getRepository(), filepath, parameters); -} - -/* ************************************************************************ */ - -UniquePtr Context::createSimulation(StringView type, StringView source) const -{ - auto loader = createLoader(type); - CECE_ASSERT(loader); - - // Create a simulation - return loader->fromSource(getRepository(), String(source)); -} - -/* ************************************************************************ */ - -UniquePtr Context::createSimulation(StringView type, StringView source, const FilePath& filepath) const -{ - auto loader = createLoader(type); - CECE_ASSERT(loader); - - // Create a simulation - return loader->fromSource(getRepository(), String(source), filepath); -} - -/* ************************************************************************ */ - -UniquePtr Context::createInitializer(StringView typeName) const -{ - ViewPtr resultFactoryManager; - DynamicArray importedNames; - - // Foreach loaded APIs and find factory - for (auto plugin : m_plugins) - { - // Get factory manager - auto factoryManager = getRepository().getInitFactoryManager(plugin.second); - - // Exists factory - if (factoryManager && factoryManager->exists(typeName)) - { - resultFactoryManager = factoryManager; - importedNames.push_back(plugin.first); - } - } - - // Multiple imports - if (importedNames.size() > 1) - { - throw RuntimeException( - "Multiple definition of module: " + String(typeName) + ". Module found in imported plugin(s): " + join(importedNames) - ); - } - - // Factory manager selected - if (resultFactoryManager) - return resultFactoryManager->createInitializer(typeName); - - // Find in other APIs to give a hint to user - auto names = getPluginNames(typeName, getRepository(), [](const RepositoryRecord& rec) { - return &(rec.getModuleFactoryManager()); - }); - - throw RuntimeException( - "Cannot create initializer: " + String(typeName) + ". Initializer found in plugin(s): " + join(names) - ); -} - -/* ************************************************************************ */ - -UniquePtr Context::createModule(StringView typeName, simulator::Simulation& simulation) const -{ - ViewPtr resultFactoryManager; - DynamicArray importedNames; - - // Foreach loaded APIs and find factory - for (auto plugin : m_plugins) - { - // Get factory manager - auto factoryManager = getRepository().getModuleFactoryManager(plugin.second); - - // Exists factory - if (factoryManager && factoryManager->exists(typeName)) - { - resultFactoryManager = factoryManager; - importedNames.push_back(plugin.first); - } - } - - // Multiple imports - if (importedNames.size() > 1) - { - throw RuntimeException( - "Multiple definition of module: " + String(typeName) + ". Module found in imported plugin(s): " + join(importedNames) - ); - } - - // Factory manager selected - if (resultFactoryManager) - return resultFactoryManager->createModule(typeName, simulation); - - // Find in other APIs to give a hint to user - auto names = getPluginNames(typeName, getRepository(), [](const RepositoryRecord& rec) { - return &(rec.getModuleFactoryManager()); - }); - - throw RuntimeException( - "Cannot create module: " + String(typeName) + ". Module found in plugin(s): " + join(names) - ); -} - -/* ************************************************************************ */ - -UniquePtr Context::createObject(StringView typeName, simulator::Simulation& simulation, object::Object::Type type) const -{ - ViewPtr resultFactoryManager; - DynamicArray importedNames; - - // Foreach loaded APIs and find factory - for (auto plugin : m_plugins) - { - // Get factory manager - auto factoryManager = getRepository().getObjectFactoryManager(plugin.second); - - // Exists factory - if (factoryManager && factoryManager->exists(typeName)) - { - resultFactoryManager = factoryManager; - importedNames.push_back(plugin.first); - } - } - - // Multiple imports - if (importedNames.size() > 1) - { - throw RuntimeException( - "Multiple definition of object: " + String(typeName) + ". Object found in imported plugin(s): " + join(importedNames) - ); - } - - // Factory manager selected - if (resultFactoryManager) - return resultFactoryManager->createObject(typeName, simulation, type); - - // Find in other APIs to give a hint to user - auto names = getPluginNames(typeName, getRepository(), [](const RepositoryRecord& rec) { - return &(rec.getObjectFactoryManager()); - }); - - throw RuntimeException( - "Cannot create object: " + String(typeName) + ". Object found in plugin(s): " + join(names) - ); -} - -/* ************************************************************************ */ - -UniquePtr Context::createProgram(StringView typeName) const -{ - ViewPtr resultFactoryManager; - DynamicArray importedNames; - - // Foreach loaded APIs and find factory - for (auto plugin : m_plugins) - { - // Get factory manager - auto factoryManager = getRepository().getProgramFactoryManager(plugin.second); - - // Exists factory - if (factoryManager && factoryManager->exists(typeName)) - { - resultFactoryManager = factoryManager; - importedNames.push_back(plugin.first); - } - } - - // Multiple imports - if (importedNames.size() > 1) - { - throw RuntimeException( - "Multiple definition of program: " + String(typeName) + ". Program found in imported plugin(s): " + join(importedNames) - ); - } - - // Factory manager selected - if (resultFactoryManager) - return resultFactoryManager->createProgram(typeName); - - // Find in other APIs to give a hint to user - auto names = getPluginNames(typeName, getRepository(), [](const RepositoryRecord& rec) { - return &(rec.getProgramFactoryManager()); - }); - - throw RuntimeException( - "Cannot create program: " + String(typeName) + ". Program found in plugin(s): " + join(names) - ); -} - -/* ************************************************************************ */ - -UniquePtr Context::createLoader(StringView name) const -{ - // Foreach repository records and find loader with given name - for (const auto& record : getRepository().getRecords()) - { - // Get factory manager - const auto& factoryManager = record.second.getLoaderFactoryManager(); - - // Exists factory - if (factoryManager.exists(name)) - return factoryManager.createLoader(name); - } - - throw RuntimeException("Unable to find loader '" + String(name) + "'"); -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Context.hpp b/cece/plugin/Context.hpp deleted file mode 100644 index 5bb634f..0000000 --- a/cece/plugin/Context.hpp +++ /dev/null @@ -1,257 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/FilePath.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/Parameters.hpp" - -/// @deprecated -#include "cece/object/Object.hpp" - -/* ************************************************************************ */ - -namespace cece { - namespace loader { class Loader; } - namespace init { class Initializer; } - namespace module { class Module; } - //namespace object { class Object; } - namespace object { class Type; } - namespace program { class Program; } - namespace simulator { class Simulation; } -} - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -class Api; -class Repository; - -/* ************************************************************************ */ - -/** - * @brief Plugins context for simulation. - */ -class Context -{ - -// Public Ctors & Dtors -public: - - - /** - * @brief Constructor. - * - * @param repository Plugins repository. - */ - explicit Context(const Repository& repository) noexcept - : m_repository(repository) - { - // Nothing to do - } - - -// Public Accessors -public: - - - /** - * @brief Returns context repository. - * - * @return - */ - const Repository& getRepository() const noexcept - { - return m_repository; - } - - - /** - * @brief Returns map of imported plugins. - * - * @return - */ - const Map>& getImported() const noexcept - { - return m_plugins; - } - - - /** - * @brief Returns if plugin is already imported. - * - * @param name Plugin name. - * - * @return - */ - bool isImported(StringView name) const noexcept; - - -// Public Operations -public: - - - /** - * @brief Import plugin. - * - * @param name Plugin name. - * - * @return Plugin API. - */ - ViewPtr importPlugin(StringView name); - - - /** - * @brief Remove plugin. - * - * @param name Plugin name. - * - * @return Plugin API. - */ - ViewPtr removePlugin(StringView name); - - - /** - * @brief Create a simulation from file. - * - * @param filepath Path to file. - * @param parameters Optional initialization parameters. - * - * @return Pointer to simulation. - * - * @throw In case of missing file or error in simulation file. - */ - UniquePtr createSimulation(const FilePath& filepath, ViewPtr parameters = nullptr) const; - - - /** - * @brief Create a simulation from source. - * - * @param type Type of used loader. - * @param source Source code. - * - * @return Pointer to simulation. - * - * @throw In case of missing file or error in simulation file. - */ - UniquePtr createSimulation(StringView type, StringView source) const; - - - /** - * @brief Create a simulation from source. - * - * @param type Type of used loader. - * @param source Source code. - * @param filepath Path to file. - * - * @return Pointer to simulation. - * - * @throw In case of missing file or error in simulation file. - */ - UniquePtr createSimulation(StringView type, StringView source, const FilePath& filepath) const; - - - /** - * @brief Create an initializer of given type name. - * - * @param typeName Type of required initializer. - * - * @return Pointer to created initializer. - */ - UniquePtr createInitializer(StringView typeName) const; - - - /** - * @brief Create a module of given type name. - * - * @param typeName Type of required module. - * @param simulation Simulation object. - * - * @return Pointer to created module. - */ - UniquePtr createModule(StringView typeName, simulator::Simulation& simulation) const; - - - /** - * @brief Create an object of given type name. - * - * @param typeName Type of required object. - * @param simulation Simulation object. - * @param type Type of created object. - * - * @return Pointer to created object. - */ - UniquePtr createObject(StringView typeName, simulator::Simulation& simulation, object::Object::Type type) const; - - - /** - * @brief Create a program of given type name. - * - * @param typeName Type of required program. - * - * @return Pointer to created program. - */ - UniquePtr createProgram(StringView typeName) const; - - -// Private Operations -private: - - - /** - * @brief Create a loader. - * - * @return A loader. - */ - UniquePtr createLoader(StringView name) const; - - -// Private Data Members -private: - - /// Plugins repository. - const Repository& m_repository; - - /// Imported plugins. - Map> m_plugins; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Library.cpp b/cece/plugin/Library.cpp deleted file mode 100644 index 26e2cc7..0000000 --- a/cece/plugin/Library.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// CeCe Config -#include "cece/config.hpp" - -/* ************************************************************************ */ - -// Declaration -#include "cece/plugin/Library.hpp" - -// C++ -#include -#include -#include - -#if __linux__ || __APPLE__ && __MACH__ -#include -#elif _WIN32 -#include -#else -#error Unsupported platform -#endif - -// CeCe -#include "cece/core/Log.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/plugin/definition.hpp" -#include "cece/plugin/Api.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -#if __linux__ -const String Library::FILE_PREFIX = "libcece-"; -#elif __MINGW32__ -const String Library::FILE_PREFIX = "libcece-"; -#elif _WIN32 -const String Library::FILE_PREFIX = "cece-"; -#elif __APPLE__ && __MACH__ -const String Library::FILE_PREFIX = "libcece-"; -#endif - -/* ************************************************************************ */ - -#if __linux__ -const String Library::FILE_EXTENSION = ".so"; -#elif _WIN32 -const String Library::FILE_EXTENSION = ".dll"; -#elif __APPLE__ && __MACH__ -const String Library::FILE_EXTENSION = ".dylib"; -#endif - -/* ************************************************************************ */ - -/** - * @brief OS dependent library implementation. - */ -struct Library::Impl -{ -// Public Ctors & Dtors -public: - - - /** - * @brief Constructor. - * - * @param path - */ - explicit Impl(FilePath path) - : m_path(std::move(path)) - { - Log::debug("Loading shared library: ", m_path); -#if __linux__ || __APPLE__ && __MACH__ - m_ptr = dlopen(m_path.c_str(), RTLD_LAZY); -#elif _WIN32 - String str = m_path.toString(); - int size = MultiByteToWideChar(CP_UTF8, 0, str.data(), (int) str.size(), NULL, 0); - std::wstring result(size, L'\0'); - MultiByteToWideChar(CP_UTF8, 0, str.data(), (int) str.size(), &result.front(), size); - - // Disable error reporting box (on Windows 7) - DWORD oldMode; - SetThreadErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX, &oldMode); - m_ptr = LoadLibraryW(result.c_str()); - SetThreadErrorMode(oldMode, NULL); -#endif - } - - - /** - * @brief Destructor. - */ - ~Impl() - { - Log::debug("Closing shared library: ", m_path); -#if __linux__ || __APPLE__ && __MACH__ - if (m_ptr) - dlclose(m_ptr); -#elif _WIN32 - FreeLibrary(m_ptr); -#endif - } - - -// Public Accessors -public: - - - /** - * @brief Returns if library is loaded. - * - * @return - */ - bool isLoaded() const noexcept - { - return m_ptr != nullptr; - } - - - /** - * @brief Returns error string. - * - * @return - */ - String getError() const noexcept - { -#if __linux__ || __APPLE__ && __MACH__ - return dlerror(); -#elif _WIN32 - // Get error message - const auto err = ::GetLastError(); - if (err == 0) - return {}; - - LPSTR buffer = nullptr; - auto size = FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&buffer, 0, NULL - ); - - // Remove trailing new lines. - while (size > 0 && (buffer[size - 1] == '\r' || buffer[size - 1] == '\n')) - --size; - - String message(buffer, size); - - // Free the buffer - LocalFree(buffer); - - return message; -#endif - } - - - /** - * @brief Returns address of required symbol. - * - * @param name - */ - void* getAddr(const char* name) const noexcept - { -#if __linux__ || __APPLE__ && __MACH__ - return dlsym(m_ptr, name); -#elif _WIN32 - return reinterpret_cast(reinterpret_cast(GetProcAddress(m_ptr, name))); -#endif - } - - - /** - * @brief Returns address of required symbol. - * - * @param name - */ - template - T getAddr(const char* name) const noexcept - { - return reinterpret_cast(reinterpret_cast(getAddr(name))); - } - - -// Private Data Members -private: - - /// Source file name. - FilePath m_path; - -#if __linux__ || __APPLE__ && __MACH__ - void* m_ptr; -#elif _WIN32 - HMODULE m_ptr; -#endif - -}; - -/* ************************************************************************ */ - -Library::Library(String name, UniquePtr api) - : m_name(std::move(name)) - , m_api(std::move(api)) -{ - // Nothing to do -} - -/* ************************************************************************ */ - -Library::Library(String name, FilePath path) - : m_name(std::move(name)) -{ - // Create dynamic implementation - m_impl.reset(new Impl{std::move(path)}); - - if (!m_impl->isLoaded()) - throw RuntimeException("Library '" + getName() + "' cannot be loaded: " + m_impl->getError()); - - // Get configuration - auto getConfigFn = m_impl->getAddr("get_config"); - - if (!getConfigFn) - throw RuntimeException("Library '" + getName() + "' doesn't contains 'get_config' function"); - - // Check configuration - checkConfig(getConfigFn()); - - // Get create API function - auto fn = m_impl->getAddr("create"); - - if (!fn) - throw RuntimeException("Library '" + getName() + "' doesn't contains 'create' function"); - - Log::debug("Library loaded `", getName(), "`."); - - // Create extension object - m_api.reset(fn()); -} - -/* ************************************************************************ */ - -Library::~Library() -{ - Log::debug("Library released `", getName(), "`."); -} - -/* ************************************************************************ */ - -void Library::checkConfig(Config* config) -{ - if (!config) - throw RuntimeException("Library '" + getName() + "' returns no config"); - - if (config->apiVersion != config::PLUGIN_API_VERSION) - throw RuntimeException("Library '" + getName() + "' is built against different API version than CeCe"); - - if (config->dimension != config::DIMENSION) - throw RuntimeException("Library '" + getName() + "' returns nullptr config"); - - if (config->realSize != sizeof(config::RealType)) - throw RuntimeException("Library '" + getName() + "' is built with different real type than CeCe"); - -#ifdef CECE_RENDER - if (!config->renderEnabled) - throw RuntimeException("Library '" + getName() + "' is built without render support, but CeCe did"); -#else - if (config->renderEnabled) - throw RuntimeException("Library '" + getName() + "' is built with render support, but CeCe didn't"); -#endif - -#ifdef CECE_THREAD_SAFE - if (!config->threadSafe) - throw RuntimeException("Library '" + getName() + "' is built without thread safety, but CeCe did"); -#else - if (config->threadSafe) - throw RuntimeException("Library '" + getName() + "' is built with thread safety, but CeCe didn't"); -#endif -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Manager.cpp b/cece/plugin/Manager.cpp deleted file mode 100644 index 101249c..0000000 --- a/cece/plugin/Manager.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -// Declaration -#include "Manager.hpp" - -// C++ -#include - -// CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/Log.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/IteratorRange.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/loader/Loader.hpp" -#include "cece/loader/FactoryManager.hpp" -#include "cece/plugin/Api.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -Manager::Manager() noexcept - : m_repository(*this) -{ - // Nothing to do -} - -/* ************************************************************************ */ - -DynamicArray Manager::getNames() const noexcept -{ - DynamicArray names; - names.reserve(m_paths.size()); - - for (const auto& p : m_paths) - names.push_back(p.first); - - return names; -} - -/* ************************************************************************ */ - -StringView Manager::getName(ViewPtr api) const noexcept -{ - for (const auto& p : m_loaded) - { - if (std::get<1>(p).getApi() == api) - return std::get<0>(p); - } - - return {}; -} - -/* ************************************************************************ */ - -void Manager::addDirectory(FilePath path) -{ - Log::debug("New plugins directory: `", path, "`"); - - m_directories.push_back(path); - - // Scan added directory - auto plugins = scanDirectory(path); - - // Append plugin directories - m_paths.insert(make_move_iterator(plugins.begin()), make_move_iterator(plugins.end())); -} - -/* ************************************************************************ */ - -void Manager::loadAll() -{ - for (const auto& name : getNames()) - load(name); -} - -/* ************************************************************************ */ - -ViewPtr Manager::load(StringView name) -{ - // Plugin is already loaded - if (isLoaded(name)) - return getApi(name); - - try - { - // Load internal - auto api = loadInternal(String(name)).getApi(); - CECE_ASSERT(api); - - // Load dependencies - for (const auto& plugin : api->requiredPlugins()) - { - // Recursive load - load(plugin); - } - - // Store plugin name for unload order (reversed) - // It's much easier to store in reverse order than in regular order. - // No duplicate are stored because isLoaded is checked before. - m_unloadOrderRev.push_back(String(name)); - - Log::debug("Loading plugin '", name, "'..."); - - // Load plugin - api->onLoad(getRepository()); - - return api; - } - catch (const Exception& e) - { - Log::warning(e.what()); - } - - return nullptr; -} - -/* ************************************************************************ */ - -Map Manager::scanDirectory(const FilePath& directory) noexcept -{ - Map result; - - Log::debug("Scanning `", directory, "` for plugins"); - - if (!isDirectory(directory)) - { - Log::warning("Directory `", directory, "` doesn't exists"); - return result; - } - - // Foreach directory - for (const auto& path : openDirectory(directory)) - { - // Only files - if (!isFile(path)) - { - Log::debug("Skipping `", path, "` - not a file"); - continue; - } - - // Get path - const auto filename = path.getFilename(); - const auto prefixLength = Library::FILE_PREFIX.length(); - const auto suffixLength = Library::FILE_EXTENSION.length(); - const auto suffixStart = filename.length() - suffixLength; - - Log::debug("Checking: ", filename); - - // Different prefix - if (filename.substr(0, prefixLength) != Library::FILE_PREFIX) - continue; - - // Different extension - if (filename.substr(suffixStart) != Library::FILE_EXTENSION) - continue; - - Log::debug("Plugin: ", filename.substr(prefixLength, suffixStart - prefixLength), " @ ", path); - - result.emplace(filename.substr(prefixLength, suffixStart - prefixLength), std::move(path)); - } - - return result; -} - -/* ************************************************************************ */ - -Map Manager::scanDirectories() const noexcept -{ - Map result; - - // Foreach directories - for (const auto& dirName : getDirectories()) - { - auto tmp = scanDirectory(dirName); - result.insert(make_move_iterator(tmp.begin()), make_move_iterator(tmp.end())); - } - - return result; -} - -/* ************************************************************************ */ - -Manager& Manager::s() -{ - static Manager instance; - return instance; -} - -/* ************************************************************************ */ - -Library& Manager::loadInternal(String name) -{ - // Try to find library in cache - auto it = m_loaded.find(name); - - // Found - if (it != m_loaded.end()) - return std::get<1>(*it); - - { - Log::debug("Loading external plugin `", name, "`..."); - - // Load plugin library - auto it = m_paths.find(name); - - if (it == m_paths.end()) - throw InvalidArgumentException("Unable to find plugin '" + name + "'"); - - // Insert into cache - auto ptr = m_loaded.emplace(std::piecewise_construct, - std::forward_as_tuple(name), - std::forward_as_tuple(name, it->second) - ); - - return std::get<1>(*std::get<0>(ptr)); - } -} - -/* ************************************************************************ */ - -void Manager::unloadPlugins() -{ - // List is in reverse order - for (auto i = m_unloadOrderRev.rbegin(); i != m_unloadOrderRev.rend(); ++i) - { - auto it = m_loaded.find(*i); - CECE_ASSERT(it != m_loaded.end()); - - Log::debug("Unloading plugin '", *i, "'..."); - - it->second.getApi()->onUnload(getRepository()); - } -} - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Manager.hpp b/cece/plugin/Manager.hpp deleted file mode 100644 index 65d5c19..0000000 --- a/cece/plugin/Manager.hpp +++ /dev/null @@ -1,342 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/plugin/Library.hpp" -#include "cece/plugin/Repository.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -class Api; - -/* ************************************************************************ */ - -/** - * @brief Manager of simulator plugins. - * - * This class is responsible for loading and unloading plugins. It all begins - * with registering plugins directory: - * @code - plugin::Manager m; - m.addDirectory("plugins"); - @endcode - * which scan given plugins directory and store paths of those plugins into internal - * variable. Then when plugin is required, it's loaded from given path. - * @code - plugin::Manager m; - auto pluginApi = m.load("myplugin"); - @endcode - * Loading plugin also loads dependent plugins. - */ -class Manager final -{ - -// Public Ctors & Dtors -public: - - - /** - * @brief Constructor. - */ - Manager() noexcept; - - - /** - * @brief Destructor. - */ - ~Manager() - { - unloadPlugins(); - } - - -// Public Accessors -public: - - - /** - * @brief Returns directories where plugins are stored. - * - * @return List of directories. - * - * @see addDirectory - */ - const DynamicArray& getDirectories() const noexcept - { - return m_directories; - } - - - /** - * @brief Check if plugin with given name exists. - * - * @param name Plugin name. - * - * @return If plugin exists. - */ - bool isAvailable(StringView name) const noexcept - { - // FIXME: In C++14 there is overloaded version of find - return m_paths.find(String(name)) != m_paths.end(); - } - - - /** - * @brief Return a list of plugins. - * - * @return An array of plugin names. - */ - DynamicArray getNames() const noexcept; - - - /** - * @brief Check if plugin is loaded. - * - * @param name Plugin name. - * - * @return - */ - bool isLoaded(StringView name) const noexcept - { - // FIXME: In C++14 there is overloaded version of find - return m_loaded.find(String(name)) != m_loaded.end(); - } - - - /** - * @brief Returns plugin API of loaded plugin. - * - * @param name Plugin name. - * - * @return Pointer to API or nullptr, if plugin is not loaded. - */ - ViewPtr getApi(StringView name) const noexcept - { - // Try to find library - // FIXME: In C++14 there is overloaded version of find - auto it = m_loaded.find(String(name)); - - if (it == m_loaded.end()) - return nullptr; - - return std::get<1>(*it).getApi(); - } - - - /** - * @brief Find API name. - * - * @param name Plugin API. - * - * @return Plugin name. - */ - StringView getName(ViewPtr api) const noexcept; - - - /** - * @brief Returns plugin repository. - * - * @return - */ - Repository& getRepository() noexcept - { - return m_repository; - } - - - /** - * @brief Returns plugin repository. - * - * @return - */ - const Repository& getRepository() const noexcept - { - return m_repository; - } - - -// Public Mutators -public: - - - /** - * @brief Store additional directories. - * - * @param directories List of directories. - * - * @see addDirectory - */ - void addDirectories(DynamicArray directories) - { - for (auto&& directory : directories) - addDirectory(std::move(directory)); - } - - - /** - * @brief Add directory where the plugins are stored. - * - * @param path - */ - void addDirectory(FilePath path); - - -// Public Operations -public: - - - /** - * @brief Load all plugins. - */ - void loadAll(); - - - /** - * @brief Load plugin. - * - * @param name Plugin name. - * - * @return Pointer to API or nullptr, if plugin is not loaded. - */ - ViewPtr load(StringView name); - - - /** - * @brief Scan directory for plugins. - * - * @param directory Plugins directory to scan. - * - * @return Paths to plugins. - */ - static Map scanDirectory(const FilePath& directory) noexcept; - - - /** - * @brief Scan plugins directories for plugins. - * - * @return - * - * @see scanDirectory - */ - Map scanDirectories() const noexcept; - - - /** - * @brief Rescan directories for extern plugins. - * - * @see scanDirectory - */ - void rescanDirectories() noexcept - { - m_paths = scanDirectories(); - } - - - /** - * @brief Release all loaded plugins. - * - * After this point the plugins features are not available. - */ - void releasePlugins() noexcept - { - // Unload plugins - unloadPlugins(); - - // Release plugins - m_loaded.clear(); - } - - - /** - * @brief Returns global instance of plugin manager. - * - * @return - */ - static Manager& s(); - - -// Private Operations -private: - - - /** - * @brief Load plugin (internal). - * - * @param name Plugin name. - * - * @return Reference to loaded plugin. - */ - Library& loadInternal(String name); - - - /** - * @brief Load all plugins. - * - * It calls `onUnload` for all loaded plugins. - */ - void unloadPlugins(); - - -// Private Data Members -private: - - /// Plugin repository. - Repository m_repository; - - /// Plugins directory paths. - DynamicArray m_directories; - - /// Paths to plugin libraries. - Map m_paths; - - /// Loaded plugins. - Map m_loaded; - - /// Order in which plugins should be unloaded (in reverse order). - DynamicArray m_unloadOrderRev; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/Repository.hpp b/cece/plugin/Repository.hpp deleted file mode 100644 index 336a115..0000000 --- a/cece/plugin/Repository.hpp +++ /dev/null @@ -1,324 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/Pair.hpp" -#include "cece/loader/FactoryManager.hpp" -#include "cece/init/FactoryManager.hpp" -#include "cece/object/FactoryManager.hpp" -#include "cece/module/FactoryManager.hpp" -#include "cece/program/FactoryManager.hpp" -#include "cece/plugin/RepositoryRecord.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -class Api; -class Manager; - -/* ************************************************************************ */ - -/** - * @brief Repository of simulation extensions offered by plugins. - */ -class Repository -{ - -// Public Ctors & Dtors -public: - - - /** - * @brief Constructor. - * - * @param manager Plugins manager. - */ - explicit Repository(const Manager& manager) noexcept - : m_manager(manager) - { - // Nothing to do - } - - -// Public Accessors -public: - - - /** - * @brief Returns plugin manager. - * - * @return - */ - const Manager& getManager() const noexcept - { - return m_manager; - } - - - /** - * @brief Returns repository records. - * - * @return - */ - const Map, RepositoryRecord>& getRecords() const noexcept - { - return m_records; - } - - - /** - * @brief Returns if given API has a record in repository. - * - * @param api Plugin API. - * - * @return - */ - bool exists(ViewPtr api) const noexcept - { - auto it = m_records.find(api); - return it != m_records.end(); - } - - - /** - * @brief Returns repository record for given API. - * - * @param api Plugin API. - * - * @return Repository record. - */ - ViewPtr get(ViewPtr api) noexcept - { - auto it = m_records.find(api); - return it != m_records.end() ? &(it->second) : nullptr; - } - - - /** - * @brief Returns repository record for given API. - * - * @param api Plugin API. - * - * @return Repository record. - */ - ViewPtr get(ViewPtr api) const noexcept - { - auto it = m_records.find(api); - return it != m_records.end() ? &(it->second) : nullptr; - } - - - /** - * @brief Returns loader factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getLoaderFactoryManager(ViewPtr api) noexcept - { - auto rec = get(api); - return rec ? &(rec->getLoaderFactoryManager()) : nullptr; - } - - - /** - * @brief Returns loader factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getLoaderFactoryManager(ViewPtr api) const noexcept - { - auto rec = get(api); - return rec ? &(rec->getLoaderFactoryManager()) : nullptr; - } - - - /** - * @brief Returns init factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getInitFactoryManager(ViewPtr api) noexcept - { - auto rec = get(api); - return rec ? &(rec->getInitFactoryManager()) : nullptr; - } - - - /** - * @brief Returns init factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getInitFactoryManager(ViewPtr api) const noexcept - { - auto rec = get(api); - return rec ? &(rec->getInitFactoryManager()) : nullptr; - } - - - /** - * @brief Returns module factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getModuleFactoryManager(ViewPtr api) noexcept - { - auto rec = get(api); - return rec ? &(rec->getModuleFactoryManager()) : nullptr; - } - - - /** - * @brief Returns module factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getModuleFactoryManager(ViewPtr api) const noexcept - { - auto rec = get(api); - return rec ? &(rec->getModuleFactoryManager()) : nullptr; - } - - - /** - * @brief Returns object factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getObjectFactoryManager(ViewPtr api) noexcept - { - auto rec = get(api); - return rec ? &(rec->getObjectFactoryManager()) : nullptr; - } - - - /** - * @brief Returns object factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getObjectFactoryManager(ViewPtr api) const noexcept - { - auto rec = get(api); - return rec ? &(rec->getObjectFactoryManager()) : nullptr; - } - - - /** - * @brief Returns program factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getProgramFactoryManager(ViewPtr api) noexcept - { - auto rec = get(api); - return rec ? &(rec->getProgramFactoryManager()) : nullptr; - } - - - /** - * @brief Returns program factory manager for given API. - * - * @param api Plugin API. - * - * @return Factory manager. - */ - ViewPtr getProgramFactoryManager(ViewPtr api) const noexcept - { - auto rec = get(api); - return rec ? &(rec->getProgramFactoryManager()) : nullptr; - } - - -// Public Mutators -public: - - - /** - * @brief Register API. - * - * @param api Plugin API. - * - * @return Repository record. - */ - RepositoryRecord& registerApi(ViewPtr api) noexcept; - - - /** - * @brief Unregister all API factories. - * - * @param api Plugin API. - */ - void unregisterApi(ViewPtr api) noexcept; - - -// Private Data Members -private: - - /// Plugins manager. - const Manager& m_manager; - - /// Repository records. - Map, RepositoryRecord> m_records; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/plugin/RepositoryRecord.hpp b/cece/plugin/RepositoryRecord.hpp deleted file mode 100644 index 11b84cd..0000000 --- a/cece/plugin/RepositoryRecord.hpp +++ /dev/null @@ -1,335 +0,0 @@ -/* ************************************************************************ */ -/* Georgiev Lab (c) 2015-2016 */ -/* ************************************************************************ */ -/* Department of Cybernetics */ -/* Faculty of Applied Sciences */ -/* University of West Bohemia in Pilsen */ -/* ************************************************************************ */ -/* */ -/* This file is part of CeCe. */ -/* */ -/* CeCe is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* CeCe is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with CeCe. If not, see . */ -/* */ -/* ************************************************************************ */ - -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/loader/FactoryManager.hpp" -#include "cece/init/FactoryManager.hpp" -#include "cece/object/FactoryManager.hpp" -#include "cece/module/FactoryManager.hpp" -#include "cece/program/FactoryManager.hpp" - -/* ************************************************************************ */ - -namespace cece { -namespace plugin { - -/* ************************************************************************ */ - -/** - * @brief Repository record. - */ -class RepositoryRecord -{ - -// Public Accessors -public: - - - /** - * @brief Returns loader factory manager. - * - * @return - */ - loader::FactoryManager& getLoaderFactoryManager() noexcept - { - return m_loaderFactoryManager; - } - - - /** - * @brief Returns loader factory manager. - * - * @return - */ - const loader::FactoryManager& getLoaderFactoryManager() const noexcept - { - return m_loaderFactoryManager; - } - - - /** - * @brief Returns initializer factory manager. - * - * @return - */ - init::FactoryManager& getInitFactoryManager() noexcept - { - return m_initFactoryManager; - } - - - /** - * @brief Returns initializer factory manager. - * - * @return - */ - const init::FactoryManager& getInitFactoryManager() const noexcept - { - return m_initFactoryManager; - } - - - /** - * @brief Returns module factory manager. - * - * @return - */ - module::FactoryManager& getModuleFactoryManager() noexcept - { - return m_moduleFactoryManager; - } - - - /** - * @brief Returns module factory manager. - * - * @return - */ - const module::FactoryManager& getModuleFactoryManager() const noexcept - { - return m_moduleFactoryManager; - } - - - /** - * @brief Returns object factory manager. - * - * @return - */ - object::FactoryManager& getObjectFactoryManager() noexcept - { - return m_objectFactoryManager; - } - - - /** - * @brief Returns object factory manager. - * - * @return - */ - const object::FactoryManager& getObjectFactoryManager() const noexcept - { - return m_objectFactoryManager; - } - - - /** - * @brief Returns program factory manager. - * - * @return - */ - program::FactoryManager& getProgramFactoryManager() noexcept - { - return m_programFactoryManager; - } - - - /** - * @brief Returns program factory manager. - * - * @return - */ - const program::FactoryManager& getProgramFactoryManager() const noexcept - { - return m_programFactoryManager; - } - - -// Public Mutators -public: - - - /** - * @brief Register new loader type and create factory for it. - * - * @tparam LoaderType Type of loader that is created by factory. - * - * @param name Factory name. - * - * @return *this. - */ - template - RepositoryRecord& registerLoader(String name) noexcept - { - m_loaderFactoryManager.createFor(std::move(name)); - return *this; - } - - - /** - * @brief Register new initializer type and create factory for it. - * - * @tparam InitializerType Type of initializer that is created by factory. - * - * @param name Initializer name. - * - * @return *this. - */ - template - RepositoryRecord& registerInitializer(String name) noexcept - { - m_initFactoryManager.createFor(std::move(name)); - return *this; - } - - - /** - * @brief Register new module type and create factory for it. - * - * @tparam ModuleType Type of module that is created by factory. - * - * @param name Factory name. - * - * @return *this. - */ - template - RepositoryRecord& registerModule(String name) noexcept - { - m_moduleFactoryManager.createFor(std::move(name)); - return *this; - } - - - /** - * @brief Register new object type and create factory for it. - * - * @tparam ObjectType Type of object that is created by factory. - * - * @param name Factory name. - * - * @return *this. - */ - template - RepositoryRecord& registerObject(String name) noexcept - { - m_objectFactoryManager.createFor(std::move(name)); - return *this; - } - - - /** - * @brief Register new program type and create factory for it. - * - * @tparam ObjectType Type of program that is created by factory. - * - * @param name Factory name. - * - * @return *this. - */ - template - RepositoryRecord& registerProgram(String name) noexcept - { - m_programFactoryManager.createFor(std::move(name)); - return *this; - } - - - /** - * @brief Unregister loader type. - * - * @param name Loader type name. - */ - void unregisterLoader(StringView name) noexcept - { - m_loaderFactoryManager.remove(name); - } - - - /** - * @brief Unregister initializer type. - * - * @param name Initializer type name. - */ - void unregisterInitializer(StringView name) noexcept - { - m_initFactoryManager.remove(name); - } - - - /** - * @brief Unregister module type. - * - * @param name Module type name. - */ - void unregisterModule(StringView name) noexcept - { - m_moduleFactoryManager.remove(name); - } - - - /** - * @brief Unregister object type. - * - * @param name Object type name. - */ - void unregisterObject(StringView name) noexcept - { - m_objectFactoryManager.remove(name); - } - - - /** - * @brief Unregister program type. - * - * @param name Program type name. - */ - void unregisterProgram(StringView name) noexcept - { - m_programFactoryManager.remove(name); - } - - -// Private Data Members -private: - - /// Loader factory manager. - loader::FactoryManager m_loaderFactoryManager; - - /// Initializer factory manager. - init::FactoryManager m_initFactoryManager; - - /// Module factory manager. - module::FactoryManager m_moduleFactoryManager; - - /// Object factory manager. - object::FactoryManager m_objectFactoryManager; - - /// Program factory manager. - program::FactoryManager m_programFactoryManager; - -}; - -/* ************************************************************************ */ - -} -} - -/* ************************************************************************ */ diff --git a/cece/core/AlignedAllocator.hpp b/include/cece/AlignedAllocator.hpp similarity index 96% rename from cece/core/AlignedAllocator.hpp rename to include/cece/AlignedAllocator.hpp index 83010cd..28a9469 100644 --- a/cece/core/AlignedAllocator.hpp +++ b/include/cece/AlignedAllocator.hpp @@ -41,8 +41,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { -namespace memory { /* ************************************************************************ */ @@ -65,10 +63,6 @@ void deallocate_aligned_memory(void* ptr) noexcept; /* ************************************************************************ */ -} - -/* ************************************************************************ */ - /** * @brief Aligned allocator. * @@ -205,7 +199,7 @@ class AlignedAllocator */ pointer allocate(size_type n, typename AlignedAllocator::const_pointer = 0) { - void* ptr = memory::allocate_aligned_memory(Align, n * sizeof(T)); + void* ptr = allocate_aligned_memory(Align, n * sizeof(T)); if (ptr == nullptr) throw std::bad_alloc(); @@ -221,7 +215,7 @@ class AlignedAllocator */ void deallocate(pointer p, size_type) noexcept { - memory::deallocate_aligned_memory(p); + deallocate_aligned_memory(p); } @@ -283,7 +277,6 @@ inline bool operator!=(const AlignedAllocator& t, const AlignedAlloca /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/Assert.hpp b/include/cece/Assert.hpp similarity index 99% rename from cece/core/Assert.hpp rename to include/cece/Assert.hpp index a4de220..e502d67 100644 --- a/cece/core/Assert.hpp +++ b/include/cece/Assert.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -52,7 +51,6 @@ inline namespace core { /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/include/cece/DynamicArray.hpp b/include/cece/DynamicArray.hpp new file mode 100644 index 0000000..24631bb --- /dev/null +++ b/include/cece/DynamicArray.hpp @@ -0,0 +1,115 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief An array with dynamic allocation. + * + * @tparam T Element type. + * @tparam Allocator Array allocator type. + */ +template> +class DynamicArray : protected std::vector +{ + using Parent = std::vector; + +// Public Types +public: + + + using value_type = typename Parent::value_type; + using allocator_type = typename Parent::allocator_type; + using size_type = typename Parent::size_type; + using difference_type = typename Parent::difference_type; + using reference = typename Parent::reference; + using const_reference = typename Parent::const_reference; + using pointer = typename Parent::pointer; + using const_pointer = typename Parent::const_pointer; + using iterator = typename Parent::iterator; + using const_iterator = typename Parent::const_iterator; + using reverse_iterator = typename Parent::reverse_iterator; + using const_reverse_iterator = typename Parent::const_reverse_iterator; + + +// Public Ctors & Dtors +public: + + + using Parent::Parent; + + +// Public Accessors & Mutators +public: + + + using Parent::operator=; + using Parent::operator[]; + using Parent::assign; + using Parent::at; + using Parent::back; + using Parent::front; + using Parent::data; + using Parent::begin; + using Parent::cbegin; + using Parent::end; + using Parent::cend; + using Parent::rbegin; + using Parent::crbegin; + using Parent::rend; + using Parent::crend; + using Parent::empty; + using Parent::size; + using Parent::max_size; + using Parent::reserve; + using Parent::capacity; + using Parent::shrink_to_fit; + using Parent::clear; + using Parent::insert; + using Parent::emplace; + using Parent::erase; + using Parent::push_back; + using Parent::emplace_back; + using Parent::pop_back; + using Parent::resize; + +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/core/Exception.hpp b/include/cece/Exception.hpp similarity index 99% rename from cece/core/Exception.hpp rename to include/cece/Exception.hpp index 151b6d4..68b1bc3 100644 --- a/cece/core/Exception.hpp +++ b/include/cece/Exception.hpp @@ -34,7 +34,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -125,7 +124,6 @@ struct InvalidCastException : public RuntimeException /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/include/cece/Function.hpp b/include/cece/Function.hpp new file mode 100644 index 0000000..566c4a2 --- /dev/null +++ b/include/cece/Function.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief std::function alias. + */ +template +using Function = std::function; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/core/IntegerSequence.hpp b/include/cece/IntegerSequence.hpp similarity index 99% rename from cece/core/IntegerSequence.hpp rename to include/cece/IntegerSequence.hpp index 113c1b4..9e11e1b 100644 --- a/cece/core/IntegerSequence.hpp +++ b/include/cece/IntegerSequence.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -98,7 +97,6 @@ using MakeIntegerSequence = typename IntegerSequenceGenerator::ty /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/IteratorRange.hpp b/include/cece/IteratorRange.hpp similarity index 90% rename from cece/core/IteratorRange.hpp rename to include/cece/IteratorRange.hpp index 164b797..4f01668 100644 --- a/cece/core/IteratorRange.hpp +++ b/include/cece/IteratorRange.hpp @@ -30,13 +30,9 @@ // C++ #include -// CeCe -#include "cece/core/ValueIterator.hpp" - /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -234,26 +230,6 @@ constexpr auto makeRange(Container& c) noexcept -> IteratorRange -constexpr IteratorRange> range(T begin, T end) noexcept -{ - return IteratorRange>{ValueIterator{begin}, ValueIterator{end}}; -} - -/* ************************************************************************ */ - -} } /* ************************************************************************ */ diff --git a/cece/core/Macro.hpp b/include/cece/Macro.hpp similarity index 100% rename from cece/core/Macro.hpp rename to include/cece/Macro.hpp diff --git a/include/cece/Map.hpp b/include/cece/Map.hpp new file mode 100644 index 0000000..c2b8b1f --- /dev/null +++ b/include/cece/Map.hpp @@ -0,0 +1,88 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief Container for mapping key to value. + * + * @tparam K Key type. + * @tparam T Value type. + */ +template +class Map : protected std::map +{ + using Parent = std::map; + + +// Public Ctors & Dtors +public: + + + using Parent::Parent; + + +// Public Accessors & Mutators +public: + + using Parent::operator=; + using Parent::operator[]; + using Parent::at; + using Parent::begin; + using Parent::cbegin; + using Parent::end; + using Parent::cend; + using Parent::rbegin; + using Parent::crbegin; + using Parent::rend; + using Parent::crend; + using Parent::empty; + using Parent::size; + using Parent::max_size; + using Parent::clear; + using Parent::insert; + using Parent::emplace; + using Parent::erase; + using Parent::count; + using Parent::find; + +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/core/Pair.hpp b/include/cece/Pair.hpp similarity index 99% rename from cece/core/Pair.hpp rename to include/cece/Pair.hpp index 84cdd23..a0036ac 100644 --- a/cece/core/Pair.hpp +++ b/include/cece/Pair.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -64,7 +63,6 @@ auto makePair(T1&& v1, T2&& v2) -> decltype(std::make_pair(v1, v2)) /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/Parameters.hpp b/include/cece/Parameters.hpp similarity index 97% rename from cece/core/Parameters.hpp rename to include/cece/Parameters.hpp index d9cf0fe..65ec61a 100644 --- a/cece/core/Parameters.hpp +++ b/include/cece/Parameters.hpp @@ -31,15 +31,14 @@ #include // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Exception.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -283,7 +282,6 @@ class Parameters /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/include/cece/PtrContainer.hpp b/include/cece/PtrContainer.hpp new file mode 100644 index 0000000..0a6fafd --- /dev/null +++ b/include/cece/PtrContainer.hpp @@ -0,0 +1,55 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/PtrDynamicArray.hpp' instead") +#else +#warning "Include 'cece/PtrDynamicArray.hpp' instead" +#endif +#include "cece/PtrDynamicArray.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief PtrDynamicArray alias. + * + * @deprecated + */ +template +using PtrContainer = PtrDynamicArray; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/include/cece/PtrDynamicArray.hpp b/include/cece/PtrDynamicArray.hpp new file mode 100644 index 0000000..b10ef4b --- /dev/null +++ b/include/cece/PtrDynamicArray.hpp @@ -0,0 +1,165 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include +#include +#include + +// CeCe +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/DynamicArray.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief An array with dynamic allocation for unique pointers. + * + * @tparam T Type the pointer points to. + * @tparam Allocator Array allocator type. + */ +template>> +class PtrDynamicArray : protected DynamicArray, Allocator> +{ + using Parent = DynamicArray, Allocator>; + +// Public Types +public: + + using value_type = typename Parent::value_type; + using allocator_type = typename Parent::allocator_type; + using size_type = typename Parent::size_type; + using difference_type = typename Parent::difference_type; + using reference = typename Parent::reference; + using const_reference = typename Parent::const_reference; + using pointer = typename Parent::pointer; + using const_pointer = typename Parent::const_pointer; + using iterator = typename Parent::iterator; + using const_iterator = typename Parent::const_iterator; + using reverse_iterator = typename Parent::reverse_iterator; + using const_reverse_iterator = typename Parent::const_reverse_iterator; + + +// Public Ctors & Dtors +public: + + + using Parent::Parent; + + +// Public Accessors & Mutators +public: + + + using Parent::operator=; + using Parent::operator[]; + using Parent::assign; + using Parent::at; + using Parent::back; + using Parent::front; + using Parent::data; + using Parent::begin; + using Parent::cbegin; + using Parent::end; + using Parent::cend; + using Parent::rbegin; + using Parent::crbegin; + using Parent::rend; + using Parent::crend; + using Parent::empty; + using Parent::size; + using Parent::max_size; + using Parent::reserve; + using Parent::capacity; + using Parent::shrink_to_fit; + using Parent::clear; + using Parent::insert; + using Parent::emplace; + using Parent::erase; + using Parent::push_back; + using Parent::emplace_back; + using Parent::pop_back; + using Parent::resize; + + + /** + * @brief Store a value. + * + * @param val The value to store. + * + * @return View pointer to stored value. + */ + ViewPtr add(UniquePtr val) + { + push_back(std::move(val)); + return back(); + } + + + /** + * @brief Create and store an object. + * + * @param[in] args Construction arguments. + * + * @tparam U Type of constructed object. + * @tparam Args Construction argument types. + * + * @return View pointer to stored object. + */ + template + ViewPtr create(Args&&... args) + { + return ViewPtr(add(makeUnique(std::forward(args)...))); + } + + + /** + * @brief Remove value from container. + * + * @param val The value to remove. + */ + void remove(ViewPtr val) + { + erase(std::remove_if(begin(), end(), [&val](const UniquePtr& ptr) { + return ptr.get() == val; + }), end()); + } + +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/include/cece/PtrNamedContainer.hpp b/include/cece/PtrNamedContainer.hpp new file mode 100644 index 0000000..a1d7ec5 --- /dev/null +++ b/include/cece/PtrNamedContainer.hpp @@ -0,0 +1,50 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/PtrStringMap.hpp' instead") +#else +#warning "Include 'cece/PtrStringMap.hpp' instead" +#endif +#include "cece/PtrStringMap.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +template +using PtrNamedContainer = PtrStringMap; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/include/cece/PtrStringMap.hpp b/include/cece/PtrStringMap.hpp new file mode 100644 index 0000000..38b0f8c --- /dev/null +++ b/include/cece/PtrStringMap.hpp @@ -0,0 +1,198 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/StringMap.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief Container for mapping string to value. + * + * @tparam T Value type. + */ +template +class PtrStringMap : protected StringMap> +{ + using Parent = StringMap>; + + +// Public Ctors & Dtors +public: + + + using Parent::Parent; + + +// Public Accessors & Mutators +public: + + + using Parent::operator[]; + using Parent::operator=; + using Parent::at; + using Parent::begin; + using Parent::cbegin; + using Parent::end; + using Parent::cend; + using Parent::rbegin; + using Parent::crbegin; + using Parent::rend; + using Parent::crend; + using Parent::empty; + using Parent::size; + using Parent::max_size; + using Parent::clear; + using Parent::insert; + using Parent::emplace; + using Parent::erase; + using Parent::count; + using Parent::find; + using Parent::exists; + + + /** + * @brief Returns value stored under given key. + * + * @param name Key name. + * + * @return Pointer to value. Can be nullptr. + */ + ViewPtr get(StringView name) const noexcept + { +#if __cplusplus >= 201402L + auto it = find(name); +#else + auto it = find(String(name)); +#endif + + if (it == end()) + return nullptr; + + return it->second; + } + + + /** + * @brief Returns object with given value. + * + * @tparam T2 Required type. + * + * @param name Object name. + * + * @return Pointer to object. Can be nullptr. + */ + template + ViewPtr get(StringView name) const noexcept + { +#if __cplusplus >= 201402L + auto it = find(name); +#else + auto it = find(String(name)); +#endif + + if (it == end()) + return nullptr; + + CECE_ASSERT(dynamic_cast(it->second.get())); + return static_cast(it->second.get()); + } + + + /** + * @brief Store a value under specified key. + * + * @param[in] name The key name. + * @param[in] value The value to store. + * + * @return View pointer to stored object. + */ + ViewPtr add(String name, UniquePtr value) + { + auto it = find(name); + + if (it != end()) + { + it->second = std::move(value); + } + else + { + std::tie(it, std::ignore) = emplace(std::move(name), std::move(value)); + } + + return it->second; + } + + + /** + * @brief Create and store an object. + * + * @param[in] name Key value. + * @param[in] args Construction arguments. + * + * @tparam U Type of constructed object. + * @tparam Args Construction argument types. + * + * @return View pointer to stored object. + */ + template + ViewPtr create(String name, Args&&... args) + { + return ViewPtr(add(std::move(name), makeUnique(std::forward(args)...))); + } + + + /** + * @brief Remove value from container. + * + * @param name Key name. + */ + void remove(StringView name) + { +#if __cplusplus >= 201402L + erase(name); +#else + erase(String(name)); +#endif + } + + +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/core/Range.hpp b/include/cece/Range.hpp similarity index 99% rename from cece/core/Range.hpp rename to include/cece/Range.hpp index 3b946c6..b67bb68 100644 --- a/cece/core/Range.hpp +++ b/include/cece/Range.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -137,7 +136,6 @@ class Range /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/Set.hpp b/include/cece/Set.hpp similarity index 98% rename from cece/core/Set.hpp rename to include/cece/Set.hpp index 7add731..2435ab3 100644 --- a/cece/core/Set.hpp +++ b/include/cece/Set.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -47,7 +46,6 @@ using Set = std::set; /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/SharedPtr.hpp b/include/cece/SharedPtr.hpp similarity index 76% rename from cece/core/SharedPtr.hpp rename to include/cece/SharedPtr.hpp index b6399de..a7b6249 100644 --- a/cece/core/SharedPtr.hpp +++ b/include/cece/SharedPtr.hpp @@ -33,14 +33,18 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { + +/* ************************************************************************ */ + +template +class ViewPtr; /* ************************************************************************ */ /** - * @brief Shared smart pointer class. + * @brief Shared smart pointer class. * - * @tparam T Type of managed object. + * @tparam T Type of managed object. */ template using SharedPtr = std::shared_ptr; @@ -48,9 +52,9 @@ using SharedPtr = std::shared_ptr; /* ************************************************************************ */ /** - * @brief Weak smart pointer class. + * @brief Weak smart pointer class. * - * @tparam T Type of managed object. + * @tparam T Type of managed object. */ template using WeakPtr = std::weak_ptr; @@ -58,9 +62,14 @@ using WeakPtr = std::weak_ptr; /* ************************************************************************ */ /** - * @brief Make unique ptr function. + * @brief Make unique ptr function. * - * @return + * @param[in] args Construction arguments. + * + * @tparam T Object type. + * @tparam Args Object construction argument types. + * + * @return Shared pointer. */ template SharedPtr makeShared(Args&&... args) @@ -70,7 +79,23 @@ SharedPtr makeShared(Args&&... args) /* ************************************************************************ */ +/** + * @brief Create a view from shared pointer. + * + * @param[in] ptr The shared pointer. + * + * @tparam T Object type. + * + * @return View pointer. + */ +template +ViewPtr makeView(const SharedPtr& ptr) noexcept +{ + return ViewPtr(ptr.get()); } + +/* ************************************************************************ */ + } /* ************************************************************************ */ diff --git a/cece/core/StaticArray.hpp b/include/cece/StaticArray.hpp similarity index 95% rename from cece/core/StaticArray.hpp rename to include/cece/StaticArray.hpp index 3ee1267..0127bd3 100644 --- a/cece/core/StaticArray.hpp +++ b/include/cece/StaticArray.hpp @@ -33,22 +33,20 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ /** - * @brief Static (stack allocated) array. + * @brief Static (stack allocated) array. * - * @tparam T Element type. - * @tparam N Number of elements. + * @tparam T Element type. + * @tparam N Number of elements. */ template using StaticArray = std::array; /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/plugin/definition.hpp b/include/cece/String.hpp similarity index 52% rename from cece/plugin/definition.hpp rename to include/cece/String.hpp index ef7d4f8..255f44d 100644 --- a/cece/plugin/definition.hpp +++ b/include/cece/String.hpp @@ -27,157 +27,186 @@ /* ************************************************************************ */ -// CeCe Config -#include "cece/config.hpp" +// C++ +#include /* ************************************************************************ */ -// CeCe -#include "cece/export.hpp" -#include "cece/plugin/Config.hpp" +namespace cece { /* ************************************************************************ */ -#ifdef CECE_RENDER -# define CECE_RENDER_VALUE 1 -#else -# define CECE_RENDER_VALUE 0 -#endif +/** + * @brief String type. + */ +using String = std::string; /* ************************************************************************ */ -#ifdef CECE_THREAD_SAFE -# define CECE_THREAD_SAFE_VALUE 1 -#else -# define CECE_THREAD_SAFE_VALUE 0 -#endif +/** + * @brief Converts integer value to string. + * + * @param value Input value. + * + * @return String value. + */ +String toString(int value) noexcept; /* ************************************************************************ */ /** - * @brief Define function name for extern plugins. + * @brief Converts long value to string. + * + * @param value Input value. * - * @param prefix Function prefix. - * @param name Plugin name. + * @return String value. */ -#define CECE_PLUGIN_PROTOTYPE_NAME_EXTERN(prefix, name) prefix +String toString(long value) noexcept; /* ************************************************************************ */ /** - * @brief Define function name for builtin plugins. + * @brief Converts long long value to string. + * + * @param value Input value. * - * @param prefix Function prefix. - * @param name Plugin name. + * @return String value. */ -#define CECE_PLUGIN_PROTOTYPE_NAME_BUILTIN(prefix, name) prefix ## _ ## name +String toString(long long value) noexcept; /* ************************************************************************ */ /** - * @brief Function name. + * @brief Converts unsigned value to string. * - * @param name Plugin name. + * @param value Input value. + * + * @return String value. */ -#if CECE_PLUGIN_BUILTIN -#define CECE_PLUGIN_PROTOTYPE_NAME(prefix, name) CECE_PLUGIN_PROTOTYPE_NAME_BUILTIN(prefix, name) -#else -#define CECE_PLUGIN_PROTOTYPE_NAME(prefix, name) CECE_PLUGIN_PROTOTYPE_NAME_EXTERN(prefix, name) -#endif +String toString(unsigned value) noexcept; /* ************************************************************************ */ /** - * @brief Prototype of function for creating plugin API object. + * @brief Converts unsigned long value to string. + * + * @param value Input value. * - * @param name Plugin name. + * @return String value. */ -#define CECE_PLUGIN_CREATE_PROTOTYPE(name) \ - extern "C" cece::plugin::Api* CECE_PLUGIN_PROTOTYPE_NAME(create, name)() +String toString(unsigned long value) noexcept; /* ************************************************************************ */ /** - * @brief Declare function for creating plugin API object. + * @brief Converts unsigned long long value to string. * - * @param name Plugin name. + * @param value Input value. + * + * @return String value. */ -#define CECE_DECLARE_PLUGIN_CREATE(name) CECE_PLUGIN_CREATE_PROTOTYPE(name) +String toString(unsigned long long value) noexcept; /* ************************************************************************ */ /** - * @brief Define function for creating plugin API object. + * @brief Converts float value to string. + * + * @param value Input value. * - * @param name Plugin name. - * @param className Plugin API class name. + * @return String value. */ -#define CECE_DEFINE_PLUGIN_CREATE(name, className) \ - CECE_PLUGIN_CREATE_PROTOTYPE(name) \ - { \ - return new className{}; \ - } +String toString(float value) noexcept; /* ************************************************************************ */ /** - * @brief Prototype of function for returning plugin configuration. + * @brief Converts double value to string. + * + * @param value Input value. * - * @param name Plugin name. + * @return String value. */ -#define CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) \ - extern "C" cece::plugin::Config* CECE_PLUGIN_PROTOTYPE_NAME(get_config, name)() +String toString(double value) noexcept; /* ************************************************************************ */ /** - * @brief Declare function for returning plugin configuration. + * @brief Converts long double value to string. * - * @param name Plugin name. + * @param value Input value. + * + * @return String value. */ -#define CECE_DECLARE_GET_CONFIG_VERSION(name) CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) +String toString(long double value) noexcept; /* ************************************************************************ */ /** - * @brief Define function for returning plugin configuration. + * @brief Converts string value to integer. + * + * @param value Input value. * - * @param name Plugin name. + * @return Parsed value. + * + * @throws InvalidArgumentException String cannot be converted. */ -#define CECE_DEFINE_GET_CONFIG_VERSION(name) \ - CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) \ - { \ - static cece::plugin::Config config = { \ - cece::config::PLUGIN_API_VERSION, /* apiVersion */ \ - sizeof(cece::config::RealType), /* realSize */ \ - CECE_RENDER_VALUE, /* renderEnabled */ \ - CECE_THREAD_SAFE_VALUE, /* threadSafe */ \ - cece::config::DIMENSION /* dimension */ \ - }; \ - return &config; \ - } +int str2i(const String& value); /* ************************************************************************ */ /** - * @brief Declare plugin functions. + * @brief Converts string value to integer. + * + * @param value Input value. + * + * @return Parsed value. * - * @param name Plugin name. + * @throws InvalidArgumentException String cannot be converted. */ -#define CECE_DECLARE_PLUGIN(name) \ - CECE_DECLARE_PLUGIN_CREATE(name); \ - CECE_DECLARE_GET_CONFIG_VERSION(name) +long str2l(const String& value); /* ************************************************************************ */ /** - * @brief Define plugin functions. + * @brief Converts string value to integer. + * + * @param value Input value. + * + * @return Parsed value. * - * @param name Plugin name. - * @param className Plugin API class name. + * @throws InvalidArgumentException String cannot be converted. */ -#define CECE_DEFINE_PLUGIN(name, className) \ - CECE_DEFINE_PLUGIN_CREATE(name, className) \ - CECE_DEFINE_GET_CONFIG_VERSION(name) +long long str2ll(const String& value); + +/* ************************************************************************ */ + +/** + * @brief Converts string value to integer. + * + * @param value Input value. + * + * @return Parsed value. + * + * @throws InvalidArgumentException String cannot be converted. + */ +float str2f(const String& value); + +/* ************************************************************************ */ + +/** + * @brief Converts string value to integer. + * + * @param value Input value. + * + * @return Parsed value. + * + * @throws InvalidArgumentException String cannot be converted. + */ +double str2d(const String& value); + +/* ************************************************************************ */ + +} /* ************************************************************************ */ diff --git a/include/cece/StringMap.hpp b/include/cece/StringMap.hpp new file mode 100644 index 0000000..1005ff5 --- /dev/null +++ b/include/cece/StringMap.hpp @@ -0,0 +1,107 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/Map.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief Container for mapping string to value. + * + * @tparam T Value type. + */ +template +class StringMap : protected Map +{ + using Parent = Map; + + +// Public Ctors & Dtors +public: + + + using Parent::Parent; + + +// Public Accessors & Mutators +public: + + + using Parent::operator[]; + using Parent::operator=; + using Parent::at; + using Parent::begin; + using Parent::cbegin; + using Parent::end; + using Parent::cend; + using Parent::rbegin; + using Parent::crbegin; + using Parent::rend; + using Parent::crend; + using Parent::empty; + using Parent::size; + using Parent::max_size; + using Parent::clear; + using Parent::insert; + using Parent::emplace; + using Parent::erase; + using Parent::count; + using Parent::find; + + + /** + * @brief Returns if an object with given name exists. + * + * @param name Object name. + * + * @return If a value exists. + */ + bool exists(StringView name) const noexcept + { +#if __cplusplus >= 201402L + return count(name) == 1; +#else + return count(String(name)) == 1; +#endif + } + +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/include/cece/StringView.hpp b/include/cece/StringView.hpp new file mode 100644 index 0000000..eb6831b --- /dev/null +++ b/include/cece/StringView.hpp @@ -0,0 +1,477 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include +#include +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/StaticArray.hpp" // @deprecated +#include "cece/DynamicArray.hpp" // @deprecated +#include "cece/io/OutStream.hpp" +#include "cece/io/InStream.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +/** + * @brief View for string independent on string storage. + */ +class StringView +{ + +// Public Types +public: + + + /// Character type. + using CharType = char; + + /// Sequence length type. + using LengthType = std::size_t; + + /// Sequence position type. + using PositionType = std::size_t; + + +// Public Ctors & Dtors +public: + + + /** + * @brief Default constructor. + */ + StringView() = default; + + + /** + * @brief Constructor. + * + * @param ptr Sequence start pointer. + * @param len Sequence length. + */ + StringView(const CharType* ptr, LengthType len) noexcept + : m_ptr(ptr) + , m_length(len) + { + // Nothing to do + } + + + /** + * @brief Constructor. + * + * @param ptr Sequence start pointer. + */ + StringView(const CharType* ptr) noexcept + : m_ptr(ptr) + , m_length(strlen(ptr)) + { + // Nothing to do + } + + + /** + * @brief Constructor. + * + * @param str String. + */ + StringView(const String& str) noexcept + : m_ptr(str.c_str()) + , m_length(str.length()) + { + // Nothing to do + } + + + /** + * @brief Constructor. + * + * @param str String. + * + * @deprecated + */ + StringView(const DynamicArray& str) noexcept + : m_ptr(str.data()) + , m_length(str.size()) + { + // Nothing to do + } + + + /** + * @brief Constructor. + * + * @param str String. + * + * @tparam N Array size. + * + * @deprecated + */ + template + StringView(const StaticArray& str) noexcept + : m_ptr(str.data()) + , m_length(str.size()) + { + // Nothing to do + } + + +// Public Operators +public: + + + /** + * @brief Get character at given position. + * + * @param pos Character position. + * + * @return Character at given position. + */ + constexpr CharType operator[](PositionType pos) const noexcept + { + return m_ptr[pos]; + } + + + /** + * @brief Cast to String. + */ + explicit operator String() const noexcept + { + return String(m_ptr, m_length); + } + + +// Public Accessors +public: + + + /** + * @brief Returns if view is empty. + * + * @return True if view is empty, False otherwise. + */ + constexpr bool isEmpty() const noexcept + { + return m_length == 0; + } + + + /** + * @brief Returns sequence data. + * + * @return A pointer to the sequence data. + */ + constexpr const CharType* getData() const noexcept + { + return m_ptr; + } + + + /** + * @brief Returns view length. + * + * @return The length of the view. + */ + constexpr LengthType getLength() const noexcept + { + return m_length; + } + + +// Private Data Members +private: + + /// Start of the string. + const CharType* m_ptr = nullptr; + + /// Length of the string. + LengthType m_length = 0; +}; + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return + */ +inline bool operator==(const StringView& lhs, const StringView& rhs) noexcept +{ + // Data pointer and length match -> same views. + if (lhs.getData() == rhs.getData() && lhs.getLength() == rhs.getLength()) + return true; + + // Different lengths + if (lhs.getLength() != rhs.getLength()) + return false; + + // Compare all characters + return !strncmp(lhs.getData(), rhs.getData(), lhs.getLength()); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return + */ +inline bool operator!=(const StringView& lhs, const StringView& rhs) +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<(const StringView& lhs, const StringView& rhs) noexcept +{ + return std::strncmp(lhs.getData(), rhs.getData(), + std::min(lhs.getLength(), rhs.getLength())) < 0; +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<(const StringView& lhs, const String& rhs) noexcept +{ + return operator<(lhs, StringView(rhs)); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<(const String& lhs, const StringView& rhs) noexcept +{ + return operator<(StringView(lhs), rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>(const StringView& lhs, const StringView& rhs) noexcept +{ + return operator<(rhs, lhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>(const StringView& lhs, const String& rhs) noexcept +{ + return operator>(lhs, StringView(rhs)); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>(const String& lhs, const StringView& rhs) noexcept +{ + return operator>(StringView(lhs), rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<=(const StringView& lhs, const StringView& rhs) noexcept +{ + return !operator>(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<=(const StringView& lhs, const String& rhs) noexcept +{ + return operator<=(lhs, StringView(rhs)); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator<=(const String& lhs, const StringView& rhs) noexcept +{ + return operator<=(StringView(lhs), rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>=(const StringView& lhs, const StringView& rhs) noexcept +{ + return !operator<(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>=(const StringView& lhs, const String& rhs) noexcept +{ + return operator>=(lhs, StringView(rhs)); +} + +/* ************************************************************************ */ + +/** + * @brief Compare operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @return Result of the relation. + */ +inline bool operator>=(const String& lhs, const StringView& rhs) noexcept +{ + return operator>=(StringView(lhs), rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Output stream operator for StringView. + * + * @param os Output stream. + * @param view View to print. + * + * @return os. + */ +inline io::OutStream& operator<<(io::OutStream& os, const StringView& view) noexcept +{ + return os.write(view.getData(), view.getLength()); +} + +/* ************************************************************************ */ + +/** + * @brief Input stream operator for StringView. + * + * @note StringView cannot be used as string storage. + * + * @param is Input stream. + * @param view Output view. + * + * @return is. + */ +inline io::InStream& operator<<(io::InStream& is, StringView& view) noexcept = delete; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/core/Tuple.hpp b/include/cece/Tuple.hpp similarity index 99% rename from cece/core/Tuple.hpp rename to include/cece/Tuple.hpp index a2e24de..4dde515 100644 --- a/cece/core/Tuple.hpp +++ b/include/cece/Tuple.hpp @@ -33,7 +33,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -103,7 +102,6 @@ constexpr auto getValue(const Tuple& t) -> decltype(std::get(t)) /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/UniquePtr.hpp b/include/cece/UniquePtr.hpp similarity index 71% rename from cece/core/UniquePtr.hpp rename to include/cece/UniquePtr.hpp index 42c6c27..0101af9 100644 --- a/cece/core/UniquePtr.hpp +++ b/include/cece/UniquePtr.hpp @@ -33,15 +33,19 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { + +/* ************************************************************************ */ + +template +class ViewPtr; /* ************************************************************************ */ /** - * @brief Unique smart pointer class. + * @brief Unique smart pointer class. * - * @tparam T Type of managed object. - * @tparam Deleter Deleter object type. + * @tparam T Type of managed object. + * @tparam Deleter Deleter object type. */ template> using UniquePtr = std::unique_ptr; @@ -49,9 +53,14 @@ using UniquePtr = std::unique_ptr; /* ************************************************************************ */ /** - * @brief Make unique ptr function. + * @brief Make unique ptr function. + * + * @param[in] args A list of construction arguments. * - * @return + * @tparam T Type of created object. + * @tparam Args Construction argument types. + * + * @return Unique pointer. */ template UniquePtr makeUnique(Args&&... args) @@ -62,22 +71,41 @@ UniquePtr makeUnique(Args&&... args) /* ************************************************************************ */ /** - * @brief Make unique ptr function for custom ctor & dtor. + * @brief Make unique ptr function for custom ctor & dtor. + * + * @param value Managed value. + * @param dtor Destructor function. * - * @param value Managed value. - * @param dtor Destructor function. + * @tparam T Value type. + * @tparam Dtor Destructor type. * - * @return + * @return Unique pointer. */ template -auto makeUniqueCustom(T* value, Dtor dtor) -> UniquePtr +UniquePtr makeUniqueResource(T* value, Dtor dtor) { return UniquePtr(value, dtor); } /* ************************************************************************ */ +/** + * @brief Create a view from unique pointer. + * + * @param[in] ptr The unique pointer. + * + * @tparam T Object type. + * + * @return View pointer. + */ +template +ViewPtr makeView(const UniquePtr& ptr) noexcept +{ + return ViewPtr(ptr.get()); } + +/* ************************************************************************ */ + } /* ************************************************************************ */ diff --git a/cece/core/ValueIterator.hpp b/include/cece/ValueIterator.hpp similarity index 93% rename from cece/core/ValueIterator.hpp rename to include/cece/ValueIterator.hpp index 06faa18..50b6233 100644 --- a/cece/core/ValueIterator.hpp +++ b/include/cece/ValueIterator.hpp @@ -32,10 +32,12 @@ #include #include +// CeCe +#include "cece/IteratorRange.hpp" + /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -376,7 +378,25 @@ class ValueIterator /* ************************************************************************ */ +/** + * @brief Make value range (for-loop like). + * + * @param begin Begin value. + * @param end End value. + * + * @note The end value is not a part of returned range, e.g. range(1, 10) + * returns values {1, 2, 3, 4, 5, 6, 7, 8, 9}. + * + * @return + */ +template +constexpr IteratorRange> range(T begin, T end) noexcept +{ + return IteratorRange>{ValueIterator{begin}, ValueIterator{end}}; } + +/* ************************************************************************ */ + } /* ************************************************************************ */ diff --git a/cece/core/ViewPtr.hpp b/include/cece/ViewPtr.hpp similarity index 99% rename from cece/core/ViewPtr.hpp rename to include/cece/ViewPtr.hpp index ff7cf7f..69b37d7 100644 --- a/cece/core/ViewPtr.hpp +++ b/include/cece/ViewPtr.hpp @@ -28,12 +28,11 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/UniquePtr.hpp" +#include "cece/UniquePtr.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -377,7 +376,6 @@ bool operator!=(std::nullptr_t, const ViewPtr& rhs) noexcept /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/core/Atomic.hpp b/include/cece/async/Atomic.hpp similarity index 99% rename from cece/core/Atomic.hpp rename to include/cece/async/Atomic.hpp index b33caa6..fc4fb9d 100644 --- a/cece/core/Atomic.hpp +++ b/include/cece/async/Atomic.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace async { /* ************************************************************************ */ diff --git a/cece/core/Mutex.hpp b/include/cece/async/Mutex.hpp similarity index 99% rename from cece/core/Mutex.hpp rename to include/cece/async/Mutex.hpp index 3829428..48c19bc 100644 --- a/cece/core/Mutex.hpp +++ b/include/cece/async/Mutex.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace async { /* ************************************************************************ */ diff --git a/include/cece/common.hpp b/include/cece/common.hpp new file mode 100644 index 0000000..3b40ab1 --- /dev/null +++ b/include/cece/common.hpp @@ -0,0 +1,41 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/config.hpp" + +/* ************************************************************************ */ + +#ifdef CECE_RENDER_REQUIRE +#ifndef CECE_RENDER +#error Rendering part requires enabled rendering. +#endif +#endif + +/* ************************************************************************ */ diff --git a/include/cece/config/Configuration.hpp b/include/cece/config/Configuration.hpp new file mode 100644 index 0000000..9212f92 --- /dev/null +++ b/include/cece/config/Configuration.hpp @@ -0,0 +1,359 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/SharedPtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/io/Converter.hpp" +#include "cece/config/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { class Parameters; } + +/* ************************************************************************ */ + +namespace cece { +namespace config { + +/* ************************************************************************ */ + +class Implementation; + +/* ************************************************************************ */ + +/** + * @brief A interface for configuration. + * + * @details The configuration is an interface for different configuration + * implementations (see `Implementation`). This class is just a + * layer used to hide real configuration implementation where the + * data can be stored in the memory or somewhere else. + */ +class Configuration +{ + +// Public Ctors +public: + + + /** + * @brief Constructor. + * + * @param impl Implementation. + * @param parameters Optional parameters. + */ + explicit Configuration(UniquePtr impl, ViewPtr parameters = nullptr); + + + /** + * @brief Constructor (memory version). + * + * @param parameters Optional parameters. + */ + explicit Configuration(ViewPtr parameters = nullptr); + + +// Public Accessors & Mutators +public: + + + /** + * @brief Checks if a value is stored under given name. + * + * @param name The name. + * + * @return `true` if value is stored, `false` otherwise. + */ + bool has(StringView name) const; + + + /** + * @brief Returns stored value. + * + * @param name The name. + * + * @return Stored value with replaced parameters. + * + * @throws NotFoundException When no value is stored. + */ + String get(StringView name) const; + + + /** + * @brief Returns stored value. + * + * @param name The name. + * @param def Default value returned if no value is stored.. + * + * @return Stored value with replaced parameters. + */ + String get(StringView name, String def) const; + + + /** + * @brief Returns stored value. + * + * @param name The name. + * @param def Default value returned if no value is stored.. + * + * @return Stored value with replaced parameters. + */ + String get(StringView name, const char* def) const + { + return get(name, String(def)); + } + + + /** + * @brief Store a value. + * + * @param name The name. + * @param value The value to store. + */ + void set(StringView name, String value); + + + /** + * @brief Store a value. + * + * @param name The name. + * @param value The value to store. + */ + void set(StringView name, const char* value) + { + set(name, String(value)); + } + + + /** + * @brief Returns stored value converted into required type. + * + * @details Conversion is done by `Converter` class which allows you to + * define custom conversion rules. + * + * @param name The name. + * + * @tparam T The required result type. + * + * @return Result value. + */ + template + T get(StringView name) const + { + return io::Converter::type>::fromString(get(name)); + } + + + /** + * @brief Returns stored value converted into required type. + * + * @details Conversion is done by `Converter` class which allows you to + * define custom conversion rules. + * + * @param name The name. + * @param def Default value returned if no value is stored.. + * + * @tparam T Required value type. + * + * @return Stored value with replaced parameters (the default value is + * not replaced). + */ + template + T get(StringView name, T def) const + { + return has(name) ? get(name) : std::move(def); + } + + + /** + * @brief Store a value. + * + * @details Conversion is done by `Converter` class which allows you to + * define custom conversion rules. + * + * @param name The name. + * @param value The value to store. + * + * @tparam T Value type. + */ + template + void set(StringView name, const T& value) noexcept + { + set(name, io::Converter::type>::toString(value)); + } + + + /** + * @brief Returns list of names under which values are stored. + * + * @return A list of names. + */ + DynamicArray getNames() const; + + + /** + * @brief Checks if the configuration contains a content. + * + * @return If content is present. + */ + bool hasContent() const; + + + /** + * @brief Returns the configuration content. + * + * @return The content with replaced parameters. + */ + String getContent() const; + + + /** + * @brief Change configuration content. + * + * @param content The new content. + */ + void setContent(String content); + + + /** + * @brief Check if at least one child configuration exists. + * + * @param name The child configuration name. + * + * @return `true` if exists, `false` otherwise. + */ + bool hasConfiguration(StringView name) const; + + + /** + * @brief Returns the first child configuration with given name. + * + * @param name The child configuration name. + * + * @return The child configuration. + * + * @throws NotFoundException If no child configuration exists: + * `hasConfiguration` returns `false`. + */ + Configuration getConfiguration(StringView name) const; + + + /** + * @brief Returns child configurations with given name. + * + * @param name The child configuration name. + * + * @return List of child configurations. + */ + DynamicArray getConfigurations(StringView name) const; + + + /** + * @brief Returns list of available child configuration names. + * + * @return A list of names. + */ + DynamicArray getConfigurationNames() const; + + + /** + * @brief Create new child configuration. + * + * @param name The child configuration name. + * + * @return New child configuration. + */ + Configuration addConfiguration(StringView name); + + +// Public Operations +public: + + + /** + * @brief Append configuration values from other one. + * + * @param src The source configuration. + */ + void append(const Configuration& src); + + + /** + * @brief Create a configuration which uses memory implementation. + * + * @details This function is useful when you need to store configuration + * for later use and the used implementation might not be valid + * at time when you wan to use. + * + * @return The new configuration. + */ + Configuration toMemory() const; + + +// Private Operations +private: + + + /** + * @brief Replace parameters in given string. + * + * @details Function replaces special expressions `{$name}` where the + * `name` is a parameter name. + * + * @param str The source string. + * + * @return Result string with replaced parameters. + */ + String replaceParameters(String str) const; + + +// Private Data Members +private: + + /// Configuration implementation. + SharedPtr m_impl; + + /// Optional parameters. + ViewPtr m_parameters; +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/plugin/Library.hpp b/include/cece/config/Exception.hpp similarity index 60% rename from cece/plugin/Library.hpp rename to include/cece/config/Exception.hpp index a59d611..85da884 100644 --- a/cece/plugin/Library.hpp +++ b/include/cece/config/Exception.hpp @@ -28,88 +28,112 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/plugin/Config.hpp" +#include "cece/String.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ namespace cece { -namespace plugin { +namespace config { /* ************************************************************************ */ -class Api; -class Context; +/** + * @brief Configuration exception. + */ +class Exception : public RuntimeException +{ + using RuntimeException::RuntimeException; +}; /* ************************************************************************ */ /** - * @brief Helper class for wrapping plugin. + * @brief Not found exception. */ -class Library final +class NotFoundException : public Exception { + using Exception::Exception; +}; -// Public Constants -public: - - - /// Library file prefix - static const String FILE_PREFIX; - - /// Library file extension - static const String FILE_EXTENSION; +/* ************************************************************************ */ +/** + * @brief Error when parameter is not properly terminated. + * + * @details Used in cases when the config parameter is not properly + * terminated: `{$name`. + */ +class UnterminatedParameterException : public Exception +{ -// Public Types +// Public Ctors & Dtors public: - /// Create API function pointer type. - using CreateFn = Api* (*)(); - - /// Returns plugin configuration. - using GetConfigFn = Config* (*)(); + /** + * @brief Constructor. + * + * @param[in] text The text where the replacement was taken place. + */ + explicit UnterminatedParameterException(String text); -// Public Ctors & Dtors +// Accessors & Mutators public: /** - * @brief Constructor. + * @brief Returns the text. * - * @param name Plugin name. - * @param api Plugin builtin api. + * @return The text. */ - Library(String name, UniquePtr api); + const String& getText() const noexcept + { + return m_text; + } - /** - * @brief Constructor. - * - * @param name Plugin name. - * @param path Path to plugin. - */ - Library(String name, FilePath path); +// Private Data Members +private: + + /// The text. + String m_text; + +}; + +/* ************************************************************************ */ + +/** + * @brief Invalid parameter name. + * + * @details Used in cases when the config parameter name contains invalid + * characters. + */ +class InvalidParameterNameException : public Exception +{ + +// Public Ctors & Dtors +public: /** - * @brief Destructor. + * @brief Constructor. + * + * @param[in] name The parameter name. + * @param[in] text The text where the replacement was taken place. */ - ~Library(); + explicit InvalidParameterNameException(String name, String text); -// Public Accessors +// Accessors & Mutators public: /** - * @brief Returns plugin name. + * @brief Returns parameter name. * - * @return + * @return The parameter name. */ const String& getName() const noexcept { @@ -118,42 +142,24 @@ class Library final /** - * @brief Returns API object. + * @brief Returns text. * - * @return + * @return The text. */ - ViewPtr getApi() const noexcept + const String& getText() const noexcept { - return m_api; + return m_text; } -// Private Operations -private: - - - /** - * @brief Check configuration file. - * - * @param config - * - * @throw - */ - void checkConfig(Config* config); - - // Private Data Members private: - /// Plugin name. + /// The parameter name. String m_name; - /// Implementation - struct Impl; - UniquePtr m_impl; - - /// Library API. - UniquePtr m_api; + /// The text. + String m_text; }; diff --git a/cece/config/Implementation.hpp b/include/cece/config/Implementation.hpp similarity index 52% rename from cece/config/Implementation.hpp rename to include/cece/config/Implementation.hpp index 0e97fcb..74694bd 100644 --- a/cece/config/Implementation.hpp +++ b/include/cece/config/Implementation.hpp @@ -28,10 +28,10 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/DynamicArray.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/PtrDynamicArray.hpp" /* ************************************************************************ */ @@ -40,8 +40,12 @@ namespace config { /* ************************************************************************ */ +class NotFoundException; + +/* ************************************************************************ */ + /** - * @brief Configuration implementation. + * @brief An interface for configuration implementation. */ class Implementation { @@ -51,118 +55,114 @@ class Implementation /** - * @brief Destructor. + * @brief Destructor. */ - virtual ~Implementation(); + virtual ~Implementation() = 0; -// Public Accessors +// Public Accessors & Mutators public: /** - * @brief Check if value with given name exists. + * @brief Check if there is a value stored under given name. * - * @param name Value name. + * @param name The name. * - * @return + * @return `true` if value is stored, `false` otherwise. */ - virtual bool has(StringView name) const noexcept = 0; + virtual bool has(StringView name) const = 0; /** - * @brief Returns list of configuration names. + * @brief Returns stored value. + * + * @param name The name. * - * @return + * @return The stored value. + * + * @throws NotFoundException When no value is stored. */ - virtual DynamicArray getNames() const noexcept = 0; + virtual String get(StringView name) const = 0; /** - * @brief Returns string value. - * - * @param name Value name. + * @brief Store a value. * - * @return + * @param name The name. + * @param value The value to store. */ - virtual String get(StringView name) const noexcept = 0; + virtual void set(StringView name, String value) = 0; /** - * @brief Returns if content string is set. + * @brief Returns list of names under which values are stored. * - * @return + * @return A list of names. */ - virtual bool hasContent() const noexcept = 0; + virtual DynamicArray getNames() const = 0; /** - * @brief Returns content string. + * @brief Checks if the configuration contains a content. * - * @return + * @return If content is present. */ - virtual String getContent() const noexcept = 0; + virtual bool hasContent() const = 0; /** - * @brief Returns if sub-configuration exists. - * - * @param name Sub-configuration name. + * @brief Returns the configuration content. * - * @return + * @return The content with replaced parameters. */ - virtual bool hasSubs(StringView name) const noexcept = 0; + virtual String getContent() const = 0; /** - * @brief Returns all sub-configuration with given name. + * @brief Change configuration content. * - * @param name Sub-configuration name. - * - * @return + * @param content The new content. */ - virtual DynamicArray> getSubs(StringView name) const noexcept = 0; - - -// Public Mutators -public: + virtual void setContent(String value) = 0; /** - * @brief Set string value. + * @brief Check if at least one child configuration exists. * - * @param name Value name. - * @param value Value to store. + * @param name The child configuration name. * - * @return + * @return `true` if exists, `false` otherwise. */ - virtual void set(StringView name, StringView value) noexcept = 0; + virtual bool hasChild(StringView name) const = 0; /** - * @brief Store content. + * @brief Returns child configurations with given name. * - * @param value Content. + * @param name The child configuration name. + * + * @return List of child configurations. */ - virtual void setContent(StringView value) noexcept = 0; + virtual PtrDynamicArray getChilds(StringView name) const = 0; /** - * @brief Create new sub-configuration. - * - * @param name Sub-configuration name. + * @brief Returns list of available child configuration names. * - * @return + * @return A list of names. */ - virtual UniquePtr addSub(StringView name) noexcept = 0; + virtual DynamicArray getChildNames() const = 0; /** - * @brief Returns list of sub-configuration names. + * @brief Create new child configuration. + * + * @param name The child configuration name. * - * @return + * @return New child configuration. */ - virtual DynamicArray getSubNames() const noexcept = 0; + virtual UniquePtr createChild(StringView name) = 0; }; diff --git a/include/cece/core/AlignedAllocator.hpp b/include/cece/core/AlignedAllocator.hpp new file mode 100644 index 0000000..043c779 --- /dev/null +++ b/include/cece/core/AlignedAllocator.hpp @@ -0,0 +1,60 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/AlignedAllocator.hpp' instead") +#else +#warning "Include 'cece/AlignedAllocator.hpp' instead" +#endif +#include "cece/AlignedAllocator.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +namespace memory { + +/* ************************************************************************ */ + +using cece::allocate_aligned_memory; +using cece::deallocate_aligned_memory; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +using cece::AlignedAllocator; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Assert.hpp b/include/cece/core/Assert.hpp new file mode 100644 index 0000000..a4c6b13 --- /dev/null +++ b/include/cece/core/Assert.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Assert.hpp' instead") +#else +#warning "Include 'cece/Assert.hpp' instead" +#endif +#include "cece/Assert.hpp" + +/* ************************************************************************ */ diff --git a/include/cece/core/Atomic.hpp b/include/cece/core/Atomic.hpp new file mode 100644 index 0000000..c2353b6 --- /dev/null +++ b/include/cece/core/Atomic.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/async/Atomic.hpp' instead") +#else +#warning "Include 'cece/async/Atomic.hpp' instead" +#endif +#include "cece/async/Atomic.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using async::Atomic; +using async::AtomicBool; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/BinaryInput.hpp b/include/cece/core/BinaryInput.hpp new file mode 100644 index 0000000..1e1f029 --- /dev/null +++ b/include/cece/core/BinaryInput.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/BinaryInput.hpp' instead") +#else +#warning "Include 'cece/io/BinaryInput.hpp' instead" +#endif +#include "cece/io/BinaryInput.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::BinaryInput; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/BinaryOutput.hpp b/include/cece/core/BinaryOutput.hpp new file mode 100644 index 0000000..48e9bc9 --- /dev/null +++ b/include/cece/core/BinaryOutput.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/BinaryOutput.hpp' instead") +#else +#warning "Include 'cece/io/BinaryOutput.hpp' instead" +#endif +#include "cece/io/BinaryOutput.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::BinaryOutput; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/CliColor.hpp b/include/cece/core/CliColor.hpp new file mode 100644 index 0000000..282a0b7 --- /dev/null +++ b/include/cece/core/CliColor.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/CliColor.hpp' instead") +#else +#warning "Include 'cece/io/CliColor.hpp' instead" +#endif +#include "cece/io/CliColor.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::CliColor; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/CsvFile.hpp b/include/cece/core/CsvFile.hpp new file mode 100644 index 0000000..bbd61a3 --- /dev/null +++ b/include/cece/core/CsvFile.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/CsvFile.hpp' instead") +#else +#warning "Include 'cece/io/CsvFile.hpp' instead" +#endif +#include "cece/io/CsvFile.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::CsvFile; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/DataExport.hpp b/include/cece/core/DataExport.hpp new file mode 100644 index 0000000..fec31e0 --- /dev/null +++ b/include/cece/core/DataExport.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/DataExport.hpp' instead") +#else +#warning "Include 'cece/io/DataExport.hpp' instead" +#endif +#include "cece/io/DataExport.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::DataExport; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/DataExportCsv.hpp b/include/cece/core/DataExportCsv.hpp new file mode 100644 index 0000000..59b8f34 --- /dev/null +++ b/include/cece/core/DataExportCsv.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/DataExportCsv.hpp' instead") +#else +#warning "Include 'cece/io/DataExportCsv.hpp' instead" +#endif +#include "cece/io/DataExportCsv.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::DataExportCsv; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/DataExportCsvFactory.hpp b/include/cece/core/DataExportCsvFactory.hpp new file mode 100644 index 0000000..ce2fa31 --- /dev/null +++ b/include/cece/core/DataExportCsvFactory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/DataExportCsvFactory.hpp' instead") +#else +#warning "Include 'cece/io/DataExportCsvFactory.hpp' instead" +#endif +#include "cece/io/DataExportCsvFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::DataExportCsvFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/DataExportFactory.hpp b/include/cece/core/DataExportFactory.hpp new file mode 100644 index 0000000..4e4f12f --- /dev/null +++ b/include/cece/core/DataExportFactory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/DataExportFactory.hpp' instead") +#else +#warning "Include 'cece/io/DataExportFactory.hpp' instead" +#endif +#include "cece/io/DataExportFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::DataExportFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/DynamicArray.hpp b/include/cece/core/DynamicArray.hpp new file mode 100644 index 0000000..7dd9115 --- /dev/null +++ b/include/cece/core/DynamicArray.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/DynamicArray.hpp' instead") +#else +#warning "Include 'cece/DynamicArray.hpp' instead" +#endif +#include "cece/DynamicArray.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::DynamicArray; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Exception.hpp b/include/cece/core/Exception.hpp new file mode 100644 index 0000000..29c583f --- /dev/null +++ b/include/cece/core/Exception.hpp @@ -0,0 +1,58 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Exception.hpp' instead") +#else +#warning "Include 'cece/Exception.hpp' instead" +#endif +#include "cece/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Exception; +using cece::LogicException; +using cece::InvalidArgumentException; +using cece::DomainException; +using cece::LengthException; +using cece::OutOfRangeException; +using cece::RuntimeException; +using cece::RangeException; +using cece::OverflowException; +using cece::UndeflowException; +using cece::BadCastException; +using cece::InvalidCastException; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/ExpressionParser.hpp b/include/cece/core/ExpressionParser.hpp new file mode 100644 index 0000000..8dc60e5 --- /dev/null +++ b/include/cece/core/ExpressionParser.hpp @@ -0,0 +1,53 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/lang/ExpressionParser.hpp' instead") +#else +#warning "Include 'cece/lang/ExpressionParser.hpp' instead" +#endif +#include "cece/lang/ExpressionParser.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using lang::ExpressionParserException; +using lang::EmptyExpressionException; +using lang::MissingParenthesisException; +using lang::UnknownConstantException; +using lang::UnknownFunctionException; +using lang::parseExpressionRef; +using lang::parseExpression; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Factory.hpp b/include/cece/core/Factory.hpp new file mode 100644 index 0000000..a752569 --- /dev/null +++ b/include/cece/core/Factory.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/factory/Factory.hpp' instead") +#else +#warning "Include 'cece/factory/Factory.hpp' instead" +#endif +#include "cece/factory/Factory.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using factory::Factory; +using factory::FactoryTyped; +using factory::FactoryCallable; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/FactoryManager.hpp b/include/cece/core/FactoryManager.hpp new file mode 100644 index 0000000..b303556 --- /dev/null +++ b/include/cece/core/FactoryManager.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/factory/FactoryManager.hpp' instead") +#else +#warning "Include 'cece/factory/FactoryManager.hpp' instead" +#endif +#include "cece/factory/FactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using factory::FactoryNotFoundException; +using factory::FactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/DynamicArray.hpp b/include/cece/core/FilePath.hpp similarity index 88% rename from cece/core/DynamicArray.hpp rename to include/cece/core/FilePath.hpp index 2cdf894..c7ac364 100644 --- a/cece/core/DynamicArray.hpp +++ b/include/cece/core/FilePath.hpp @@ -23,12 +23,12 @@ /* */ /* ************************************************************************ */ -#pragma once - -/* ************************************************************************ */ - -// C++ -#include +#if _MSC_VER +#pragma message("Include 'cece/io/FilePath.hpp' instead") +#else +#warning "Include 'cece/io/FilePath.hpp' instead" +#endif +#include "cece/io/FilePath.hpp" /* ************************************************************************ */ @@ -37,14 +37,12 @@ inline namespace core { /* ************************************************************************ */ -/** - * @brief Dynamic array. - * - * @tparam T - * @tparam Allocator - */ -template> -using DynamicArray = std::vector; +using io::FilePath; +using io::isFile; +using io::isDirectory; +using io::pathExists; +using io::tempDirectory; +using io::openDirectory; /* ************************************************************************ */ diff --git a/include/cece/core/FileStream.hpp b/include/cece/core/FileStream.hpp new file mode 100644 index 0000000..5f29d3e --- /dev/null +++ b/include/cece/core/FileStream.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/FileStream.hpp' instead") +#else +#warning "Include 'cece/io/FileStream.hpp' instead" +#endif +#include "cece/io/FileStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::InFileStream; +using io::OutFileStream; +using io::FileStream; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Grid.hpp b/include/cece/core/Grid.hpp new file mode 100644 index 0000000..4defd64 --- /dev/null +++ b/include/cece/core/Grid.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/Grid.hpp' instead") +#else +#warning "Include 'cece/math/Grid.hpp' instead" +#endif +#include "cece/math/Grid.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::Grid; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/InOutStream.hpp b/include/cece/core/InOutStream.hpp new file mode 100644 index 0000000..c4f9a35 --- /dev/null +++ b/include/cece/core/InOutStream.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/InOutStream.hpp' instead") +#else +#warning "Include 'cece/io/InOutStream.hpp' instead" +#endif +#include "cece/io/InOutStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::InOutStream; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/InStream.hpp b/include/cece/core/InStream.hpp new file mode 100644 index 0000000..36b9108 --- /dev/null +++ b/include/cece/core/InStream.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/InStream.hpp' instead") +#else +#warning "Include 'cece/io/InStream.hpp' instead" +#endif +#include "cece/io/InStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::InStream; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/IntegerSequence.hpp b/include/cece/core/IntegerSequence.hpp new file mode 100644 index 0000000..33c5803 --- /dev/null +++ b/include/cece/core/IntegerSequence.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/IntegerSequence.hpp' instead") +#else +#warning "Include 'cece/IntegerSequence.hpp' instead" +#endif +#include "cece/IntegerSequence.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::IntegerSequence; +using cece::IntegerSequenceGenerator; +using cece::MakeIntegerSequence; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/IterationRange.hpp b/include/cece/core/IterationRange.hpp new file mode 100644 index 0000000..9570e3d --- /dev/null +++ b/include/cece/core/IterationRange.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/IterationRange.hpp' instead") +#else +#warning "Include 'cece/simulation/IterationRange.hpp' instead" +#endif +#include "cece/simulation/IterationRange.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using simulation::IterationRange; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/IterationType.hpp b/include/cece/core/IterationType.hpp new file mode 100644 index 0000000..9c01a24 --- /dev/null +++ b/include/cece/core/IterationType.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/IterationType.hpp' instead") +#else +#warning "Include 'cece/simulation/IterationType.hpp' instead" +#endif +#include "cece/simulation/IterationType.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using simulation::IterationType; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/IteratorRange.hpp b/include/cece/core/IteratorRange.hpp new file mode 100644 index 0000000..206ae87 --- /dev/null +++ b/include/cece/core/IteratorRange.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/IteratorRange.hpp' instead") +#else +#warning "Include 'cece/IteratorRange.hpp' instead" +#endif +#include "cece/IteratorRange.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::IteratorRange; +using cece::makeRange; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/ListenerContainer.hpp b/include/cece/core/ListenerContainer.hpp similarity index 95% rename from cece/core/ListenerContainer.hpp rename to include/cece/core/ListenerContainer.hpp index 0370e5f..b8d80dc 100644 --- a/cece/core/ListenerContainer.hpp +++ b/include/cece/core/ListenerContainer.hpp @@ -27,8 +27,16 @@ /* ************************************************************************ */ +#if _MSC_VER +#pragma message("deprecated") +#else +#warning "deprecated" +#endif + +/* ************************************************************************ */ + // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" /* ************************************************************************ */ diff --git a/include/cece/core/Log.hpp b/include/cece/core/Log.hpp new file mode 100644 index 0000000..b2c9a15 --- /dev/null +++ b/include/cece/core/Log.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/log/Log.hpp' instead") +#else +#warning "Include 'cece/log/Log.hpp' instead" +#endif +#include "cece/log/Log.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using log::Log; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Macro.hpp b/include/cece/core/Macro.hpp new file mode 100644 index 0000000..3b800b7 --- /dev/null +++ b/include/cece/core/Macro.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Macro.hpp' instead") +#else +#warning "Include 'cece/Macro.hpp' instead" +#endif +#include "cece/Macro.hpp" + +/* ************************************************************************ */ diff --git a/include/cece/core/Map.hpp b/include/cece/core/Map.hpp new file mode 100644 index 0000000..8e19c42 --- /dev/null +++ b/include/cece/core/Map.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Map.hpp' instead") +#else +#warning "Include 'cece/Map.hpp' instead" +#endif +#include "cece/Map.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Map; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Mutex.hpp b/include/cece/core/Mutex.hpp new file mode 100644 index 0000000..108b1d8 --- /dev/null +++ b/include/cece/core/Mutex.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/async/Mutex.hpp' instead") +#else +#warning "Include 'cece/async/Mutex.hpp' instead" +#endif +#include "cece/async/Mutex.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using async::Mutex; +using async::MutexGuard; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/OutStream.hpp b/include/cece/core/OutStream.hpp new file mode 100644 index 0000000..b549882 --- /dev/null +++ b/include/cece/core/OutStream.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/OutStream.hpp' instead") +#else +#warning "Include 'cece/io/OutStream.hpp' instead" +#endif +#include "cece/io/OutStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::OutStream; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Pair.hpp b/include/cece/core/Pair.hpp new file mode 100644 index 0000000..3b9f5de --- /dev/null +++ b/include/cece/core/Pair.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Pair.hpp' instead") +#else +#warning "Include 'cece/Pair.hpp' instead" +#endif +#include "cece/Pair.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Pair; +using cece::makePair; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Parameters.hpp b/include/cece/core/Parameters.hpp new file mode 100644 index 0000000..09742f2 --- /dev/null +++ b/include/cece/core/Parameters.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Parameters.hpp' instead") +#else +#warning "Include 'cece/Parameters.hpp' instead" +#endif +#include "cece/Parameters.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Parameters; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Parser.hpp b/include/cece/core/Parser.hpp new file mode 100644 index 0000000..8fbbb49 --- /dev/null +++ b/include/cece/core/Parser.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/lang/Parser.hpp' instead") +#else +#warning "Include 'cece/lang/Parser.hpp' instead" +#endif +#include "cece/lang/Parser.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using lang::BasicParser; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/PtrContainer.hpp b/include/cece/core/PtrContainer.hpp new file mode 100644 index 0000000..05b4750 --- /dev/null +++ b/include/cece/core/PtrContainer.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/PtrContainer.hpp' instead") +#else +#warning "Include 'cece/PtrContainer.hpp' instead" +#endif +#include "cece/PtrContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::PtrContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/PtrNamedContainer.hpp b/include/cece/core/PtrNamedContainer.hpp new file mode 100644 index 0000000..2c8d720 --- /dev/null +++ b/include/cece/core/PtrNamedContainer.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/PtrNamedContainer.hpp' instead") +#else +#warning "Include 'cece/PtrNamedContainer.hpp' instead" +#endif +#include "cece/PtrNamedContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::PtrNamedContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Range.hpp b/include/cece/core/Range.hpp new file mode 100644 index 0000000..9338804 --- /dev/null +++ b/include/cece/core/Range.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Range.hpp' instead") +#else +#warning "Include 'cece/Range.hpp' instead" +#endif +#include "cece/Range.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Range; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/Real.hpp b/include/cece/core/Real.hpp similarity index 97% rename from cece/core/Real.hpp rename to include/cece/core/Real.hpp index b2af354..3095cfa 100644 --- a/cece/core/Real.hpp +++ b/include/cece/core/Real.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/config.hpp" +#include "cece/common.hpp" /* ************************************************************************ */ @@ -42,7 +42,7 @@ inline namespace core { * * @todo remove */ -using RealType = cece::config::RealType; +using RealType = cece::RealType; /* ************************************************************************ */ diff --git a/include/cece/core/Set.hpp b/include/cece/core/Set.hpp new file mode 100644 index 0000000..c80c232 --- /dev/null +++ b/include/cece/core/Set.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Set.hpp' instead") +#else +#warning "Include 'cece/Set.hpp' instead" +#endif +#include "cece/Set.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Set; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Shape.hpp b/include/cece/core/Shape.hpp new file mode 100644 index 0000000..61c6c5b --- /dev/null +++ b/include/cece/core/Shape.hpp @@ -0,0 +1,52 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/Shape.hpp' instead") +#else +#warning "Include 'cece/math/Shape.hpp' instead" +#endif +#include "cece/math/Shape.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::ShapeType; +using math::ShapeUndefined; +using math::ShapeCircle; +using math::ShapeRectangle; +using math::ShapeEdges; +using math::Shape; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/ShapeToGrid.hpp b/include/cece/core/ShapeToGrid.hpp new file mode 100644 index 0000000..0340a6b --- /dev/null +++ b/include/cece/core/ShapeToGrid.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/ShapeToGrid.hpp' instead") +#else +#warning "Include 'cece/math/ShapeToGrid.hpp' instead" +#endif +#include "cece/math/ShapeToGrid.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::mapShapeToGrid; +using math::mapShapeBorderToGrid; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/SharedPtr.hpp b/include/cece/core/SharedPtr.hpp new file mode 100644 index 0000000..2d256b4 --- /dev/null +++ b/include/cece/core/SharedPtr.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/SharedPtr.hpp' instead") +#else +#warning "Include 'cece/SharedPtr.hpp' instead" +#endif +#include "cece/SharedPtr.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::SharedPtr; +using cece::WeakPtr; +using cece::makeShared; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/StaticArray.hpp b/include/cece/core/StaticArray.hpp new file mode 100644 index 0000000..fe0d71d --- /dev/null +++ b/include/cece/core/StaticArray.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/StaticArray.hpp' instead") +#else +#warning "Include 'cece/StaticArray.hpp' instead" +#endif +#include "cece/StaticArray.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::StaticArray; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/StaticMatrix.hpp b/include/cece/core/StaticMatrix.hpp new file mode 100644 index 0000000..5db0ccf --- /dev/null +++ b/include/cece/core/StaticMatrix.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/StaticMatrix.hpp' instead") +#else +#warning "Include 'cece/math/StaticMatrix.hpp' instead" +#endif +#include "cece/math/StaticMatrix.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::StaticMatrix; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/String.hpp b/include/cece/core/String.hpp new file mode 100644 index 0000000..52d048c --- /dev/null +++ b/include/cece/core/String.hpp @@ -0,0 +1,50 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/String.hpp' instead") +#else +#warning "Include 'cece/String.hpp' instead" +#endif +#include "cece/String.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::String; +using cece::toString; +using cece::str2i; +using cece::str2f; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/StringStream.hpp b/include/cece/core/StringStream.hpp new file mode 100644 index 0000000..ad31093 --- /dev/null +++ b/include/cece/core/StringStream.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/io/StringStream.hpp' instead") +#else +#warning "Include 'cece/io/StringStream.hpp' instead" +#endif +#include "cece/io/StringStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using io::InStringStream; +using io::OutStringStream; +using io::StringStream; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/StringView.hpp b/include/cece/core/StringView.hpp new file mode 100644 index 0000000..0b5effe --- /dev/null +++ b/include/cece/core/StringView.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/StringView.hpp' instead") +#else +#warning "Include 'cece/StringView.hpp' instead" +#endif +#include "cece/StringView.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::StringView; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/TimeMeasurement.hpp b/include/cece/core/TimeMeasurement.hpp new file mode 100644 index 0000000..1e0c006 --- /dev/null +++ b/include/cece/core/TimeMeasurement.hpp @@ -0,0 +1,53 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/perf/TimeMeasurement' instead") +#else +#warning "Include 'cece/perf/TimeMeasurement.hpp' instead" +#endif +#include "cece/perf/TimeMeasurement.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using perf::Clock; +using perf::isMeasureTimeEnabled; +using perf::getMeasureTimeOutput; +using perf::setMeasureTimeOutput; +using perf::DefaultMeasurementOutput; +using perf::TimeMeasurementBase; +using perf::measure_time; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Tokenizer.hpp b/include/cece/core/Tokenizer.hpp new file mode 100644 index 0000000..a9b5776 --- /dev/null +++ b/include/cece/core/Tokenizer.hpp @@ -0,0 +1,50 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/lang/Tokenizer.hpp' instead") +#else +#warning "Include 'cece/lang/Tokenizer.hpp' instead" +#endif +#include "cece/lang/Tokenizer.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using lang::LexicalException; +using lang::BasicToken; +using lang::BasicTokenizerIterator; +using lang::BasicTokenizer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Tuple.hpp b/include/cece/core/Tuple.hpp new file mode 100644 index 0000000..b97b084 --- /dev/null +++ b/include/cece/core/Tuple.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/Tuple.hpp' instead") +#else +#warning "Include 'cece/Tuple.hpp' instead" +#endif +#include "cece/Tuple.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::Tuple; +using cece::makeTuple; +using cece::getValue; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/UniquePtr.hpp b/include/cece/core/UniquePtr.hpp new file mode 100644 index 0000000..06dd4f4 --- /dev/null +++ b/include/cece/core/UniquePtr.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/UniquePtr.hpp' instead") +#else +#warning "Include 'cece/UniquePtr.hpp' instead" +#endif +#include "cece/UniquePtr.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::UniquePtr; +using cece::makeUnique; +using cece::makeUniqueCustom; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Unit.hpp b/include/cece/core/Unit.hpp new file mode 100644 index 0000000..6a6db18 --- /dev/null +++ b/include/cece/core/Unit.hpp @@ -0,0 +1,66 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/Unit.hpp' instead") +#else +#warning "Include 'cece/unit/Unit.hpp' instead" +#endif +#include "cece/unit/Unit.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::Value; +using unit::Unit; +using unit::List; +using unit::BaseLength; +using unit::BaseMass; +using unit::BaseTime; +using unit::BaseElectricCurrent; +using unit::BaseThermodynamicTemperature; +using unit::BaseAmountOfSubstance; +using unit::BaseLuminousIntensity; +using unit::exponentToCoefficient; +using unit::LENGTH_EXPONENT; +using unit::TIME_EXPONENT; +using unit::MASS_EXPONENT; +using unit::ELECTRIC_CURRENT_EXPONENT; +using unit::THERMODYNAMIC_TEMPERATURE_EXPONENT; +using unit::AMOUNT_OF_SUBSTANCE_EXPONENT; +using unit::LUMINOUS_INTENSITY_EXPONENT; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/UnitIo.hpp b/include/cece/core/UnitIo.hpp new file mode 100644 index 0000000..95c5b9e --- /dev/null +++ b/include/cece/core/UnitIo.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/UnitIo.hpp' instead") +#else +#warning "Include 'cece/unit/UnitIo.hpp' instead" +#endif +#include "cece/unit/UnitIo.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::parse; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/UnitSymbol.hpp b/include/cece/core/UnitSymbol.hpp new file mode 100644 index 0000000..12969d6 --- /dev/null +++ b/include/cece/core/UnitSymbol.hpp @@ -0,0 +1,52 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/UnitSymbol.hpp' instead") +#else +#warning "Include 'cece/unit/UnitSymbol.hpp' instead" +#endif +#include "cece/unit/UnitSymbol.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::Symbol; +using unit::SymbolLength; +using unit::SymbolBase; +using unit::SymbolGroup; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Units.hpp b/include/cece/core/Units.hpp new file mode 100644 index 0000000..364942b --- /dev/null +++ b/include/cece/core/Units.hpp @@ -0,0 +1,71 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/Units.hpp' instead") +#else +#warning "Include 'cece/unit/Units.hpp' instead" +#endif +#include "cece/unit/Units.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::None; +using unit::Length; +using unit::Mass; +using unit::Time; +using unit::Duration; +using unit::Area; +using unit::Volume; +using unit::Velocity; +using unit::Acceleration; +using unit::Force; +using unit::Impulse; +using unit::Density; +using unit::DynamicViscosity; +using unit::KinematicViscosity; +using unit::AmountOfSubstance; +using unit::NumberConcentration; +using unit::MolarConcentration; +using unit::Angle; +using unit::AngularVelocity; +using unit::Probability; +using unit::VolumericFlow; +using unit::deg2rad; +using unit::rad2deg; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/UnitsCtors.hpp b/include/cece/core/UnitsCtors.hpp new file mode 100644 index 0000000..61274f0 --- /dev/null +++ b/include/cece/core/UnitsCtors.hpp @@ -0,0 +1,110 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/UnitsCtors.hpp' instead") +#else +#warning "Include 'cece/unit/UnitsCtors.hpp' instead" +#endif +#include "cece/unit/UnitsCtors.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::m; +using unit::dm; +using unit::mm; +using unit::um; +using unit::g; +using unit::kg; +using unit::mg; +using unit::ug; +using unit::ng; +using unit::pg; +using unit::s; +using unit::ms; +using unit::us; +using unit::min; +using unit::h; +using unit::m2; +using unit::dm2; +using unit::mm2; +using unit::um2; +using unit::m3; +using unit::dm3; +using unit::mm3; +using unit::um3; +using unit::m_s; +using unit::mm_s; +using unit::um_s; +using unit::m_s2; +using unit::mm_s2; +using unit::um_s2; +using unit::kgm_s2; +using unit::gm_s2; +using unit::mgm_s2; +using unit::N; +using unit::mN; +using unit::uN; +using unit::kg_m_s; +using unit::g_m_s; +using unit::Ns_m2; +using unit::Pas; +using unit::mPas; +using unit::m2_s; +using unit::mm2_s; +using unit::um2_s; +using unit::mol; +using unit::mmol; +using unit::umol; +using unit::nmol; +using unit::mol_m3; +using unit::mmol_m3; +using unit::umol_m3; +using unit::nmol_m3; +using unit::M; +using unit::mM; +using unit::uM; +using unit::nM; +using unit::mol_um3; +using unit::mmol_um3; +using unit::umol_um3; +using unit::nmol_um3; +using unit::rad; +using unit::deg; +using unit::precent; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/ValueIterator.hpp b/include/cece/core/ValueIterator.hpp new file mode 100644 index 0000000..84049d4 --- /dev/null +++ b/include/cece/core/ValueIterator.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/ValueIterator.hpp' instead") +#else +#warning "Include 'cece/ValueIterator.hpp' instead" +#endif +#include "cece/ValueIterator.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::ValueIterator; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Vector.hpp b/include/cece/core/Vector.hpp new file mode 100644 index 0000000..9465e4a --- /dev/null +++ b/include/cece/core/Vector.hpp @@ -0,0 +1,53 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/Vector.hpp' instead") +#else +#warning "Include 'cece/math/Vector.hpp' instead" +#endif +#include "cece/math/Vector.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::BasicVector; +using math::Vector; +using math::Size; +using math::Coordinate; +using math::VectorInt; +using math::VectorUint; +using math::VectorFloat; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/VectorRange.hpp b/include/cece/core/VectorRange.hpp new file mode 100644 index 0000000..afd7df0 --- /dev/null +++ b/include/cece/core/VectorRange.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/VectorRange.hpp' instead") +#else +#warning "Include 'cece/math/VectorRange.hpp' instead" +#endif +#include "cece/math/VectorRange.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::IteratorVector; +using math::range; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/VectorUnits.hpp b/include/cece/core/VectorUnits.hpp new file mode 100644 index 0000000..00a03c7 --- /dev/null +++ b/include/cece/core/VectorUnits.hpp @@ -0,0 +1,55 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/unit/VectorUnits.hpp' instead") +#else +#warning "Include 'cece/unit/VectorUnits.hpp' instead" +#endif +#include "cece/unit/VectorUnits.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace units { + +/* ************************************************************************ */ + +using unit::PositionVector; +using unit::VelocityVector; +using unit::AccelerationVector; +using unit::ForceVector; +using unit::ImpulseVector; +using unit::ScaleVector; +using unit::SizeVector; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/ViewPtr.hpp b/include/cece/core/ViewPtr.hpp new file mode 100644 index 0000000..c72891e --- /dev/null +++ b/include/cece/core/ViewPtr.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/ViewPtr.hpp' instead") +#else +#warning "Include 'cece/ViewPtr.hpp' instead" +#endif +#include "cece/ViewPtr.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using cece::ViewPtr; +using cece::makeView; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/Zero.hpp b/include/cece/core/Zero.hpp new file mode 100644 index 0000000..09457fe --- /dev/null +++ b/include/cece/core/Zero.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/Zero.hpp' instead") +#else +#warning "Include 'cece/math/Zero.hpp' instead" +#endif +#include "cece/math/Zero.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::Zero; +using math::Zero_t; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/constants.hpp b/include/cece/core/constants.hpp new file mode 100644 index 0000000..4d4ae6b --- /dev/null +++ b/include/cece/core/constants.hpp @@ -0,0 +1,50 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/constants.hpp' instead") +#else +#warning "Include 'cece/math/constants.hpp' instead" +#endif +#include "cece/math/constants.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { +namespace constants { + +/* ************************************************************************ */ + +using math::PI; +using math::E; + +/* ************************************************************************ */ + +} +} +} + +/* ************************************************************************ */ diff --git a/include/cece/core/fastexp.hpp b/include/cece/core/fastexp.hpp new file mode 100644 index 0000000..195452f --- /dev/null +++ b/include/cece/core/fastexp.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/math/fastexp.hpp' instead") +#else +#warning "Include 'cece/math/fastexp.hpp' instead" +#endif +#include "cece/math/fastexp.hpp" + +/* ************************************************************************ */ + +namespace cece { +inline namespace core { + +/* ************************************************************************ */ + +using math::fastexp; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/Factory.hpp b/include/cece/factory/Factory.hpp similarity index 90% rename from cece/core/Factory.hpp rename to include/cece/factory/Factory.hpp index 5eb2cbc..978bc70 100644 --- a/cece/core/Factory.hpp +++ b/include/cece/factory/Factory.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/UniquePtr.hpp" +#include "cece/UniquePtr.hpp" /* ************************************************************************ */ @@ -36,24 +36,24 @@ * @brief Define extern factory specialization. */ #define CECE_FACTORY(...) \ - namespace cece { inline namespace core { template class Factory<__VA_ARGS__>; } } + namespace cece { namespace factory { template class Factory<__VA_ARGS__>; } } /** * @brief Define extern factory specialization. */ #define CECE_FACTORY_EXTERN(...) \ - namespace cece { inline namespace core { extern template class Factory<__VA_ARGS__>; } } + namespace cece { namespace factory { extern template class Factory<__VA_ARGS__>; } } /** * @brief Define extern factory specialization. */ #define CECE_FACTORY_INST(...) \ - namespace cece { inline namespace core { template class Factory<__VA_ARGS__>; } } + namespace cece { namespace factory { template class Factory<__VA_ARGS__>; } } /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace factory { /* ************************************************************************ */ @@ -99,7 +99,7 @@ class Factory * * @return Created object pointer. */ - virtual UniquePtr create(Args... args) const noexcept = 0; + virtual UniquePtr create(Args... args) const = 0; }; @@ -137,7 +137,7 @@ class FactoryTyped, T> : public Factory * * @return Created object pointer. */ - UniquePtr create(Args... args) const noexcept override + UniquePtr create(Args... args) const override { return makeUnique(std::forward(args)...); } @@ -185,7 +185,7 @@ class FactoryCallable : public ParentFactory * * @return Created object pointer. */ - UniquePtr create(Args... args) const noexcept override + UniquePtr create(Args... args) const override { return m_callable(std::forward(args)...); } diff --git a/cece/core/FactoryManager.hpp b/include/cece/factory/FactoryManager.hpp similarity index 90% rename from cece/core/FactoryManager.hpp rename to include/cece/factory/FactoryManager.hpp index 9d4b45b..40a45fd 100644 --- a/cece/core/FactoryManager.hpp +++ b/include/cece/factory/FactoryManager.hpp @@ -31,14 +31,14 @@ #include // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/Factory.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/Map.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/Exception.hpp" +#include "cece/factory/Factory.hpp" /* ************************************************************************ */ @@ -46,24 +46,24 @@ * @brief Define extern factory manager specialization. */ #define CECE_FACTORY_MANAGER(...) \ - namespace cece { inline namespace core { template class FactoryManager<__VA_ARGS__>; } } + namespace cece { namespace factory { template class FactoryManager<__VA_ARGS__>; } } /** * @brief Define extern factory manager specialization. */ #define CECE_FACTORY_MANAGER_EXTERN(...) \ - namespace cece { inline namespace core { extern template class FactoryManager<__VA_ARGS__>; } } + namespace cece { namespace factory { extern template class FactoryManager<__VA_ARGS__>; } } /** * @brief Define extern factory manager specialization. */ #define CECE_FACTORY_MANAGER_INST(...) \ - namespace cece { inline namespace core { template class FactoryManager<__VA_ARGS__>; } } + namespace cece { namespace factory { template class FactoryManager<__VA_ARGS__>; } } /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace factory { /* ************************************************************************ */ @@ -169,7 +169,7 @@ class FactoryManager * @param name Factory name. */ template - void create(String name) noexcept + void create(String name) { static_assert( std::is_base_of::value, @@ -188,7 +188,7 @@ class FactoryManager * @param name Factory name. */ template - void createFor(String name) noexcept + void createFor(String name) { create>(std::move(name)); } diff --git a/include/cece/init/Container.hpp b/include/cece/init/Container.hpp new file mode 100644 index 0000000..d251484 --- /dev/null +++ b/include/cece/init/Container.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/InitializerContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/InitializerContainer.hpp' instead" +#endif +#include "cece/simulation/InitializerContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace init { + +/* ************************************************************************ */ + +using Container = simulation::InitializerContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/init/Factory.hpp b/include/cece/init/Factory.hpp new file mode 100644 index 0000000..c08564b --- /dev/null +++ b/include/cece/init/Factory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/InitializerFactory.hpp' instead") +#else +#warning "Include 'cece/simulation/InitializerFactory.hpp' instead" +#endif +#include "cece/simulation/InitializerFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace init { + +/* ************************************************************************ */ + +using Factory = simulation::InitializerFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/init/FactoryManager.hpp b/include/cece/init/FactoryManager.hpp new file mode 100644 index 0000000..f871e9a --- /dev/null +++ b/include/cece/init/FactoryManager.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/InitializerFactoryManager.hpp' instead") +#else +#warning "Include 'cece/simulation/InitializerFactoryManager.hpp' instead" +#endif +#include "cece/simulation/InitializerFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace init { + +/* ************************************************************************ */ + +using FactoryManager = simulation::InitializerFactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/init/Initializer.hpp b/include/cece/init/Initializer.hpp new file mode 100644 index 0000000..73a8611 --- /dev/null +++ b/include/cece/init/Initializer.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Initializer.hpp' instead") +#else +#warning "Include 'cece/simulation/Initializer.hpp' instead" +#endif +#include "cece/simulation/Initializer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace init { + +/* ************************************************************************ */ + +using simulation::Initializer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/BinaryInput.hpp b/include/cece/io/BinaryInput.hpp similarity index 97% rename from cece/core/BinaryInput.hpp rename to include/cece/io/BinaryInput.hpp index 4be76f8..3b7b042 100644 --- a/cece/core/BinaryInput.hpp +++ b/include/cece/io/BinaryInput.hpp @@ -31,15 +31,15 @@ #include // CeCe -#include "cece/core/InStream.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/Vector.hpp" +#include "cece/String.hpp" +#include "cece/StaticArray.hpp" +#include "cece/math/Vector.hpp" +#include "cece/io/InStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/BinaryOutput.hpp b/include/cece/io/BinaryOutput.hpp similarity index 96% rename from cece/core/BinaryOutput.hpp rename to include/cece/io/BinaryOutput.hpp index f3cbe9a..50026d8 100644 --- a/cece/core/BinaryOutput.hpp +++ b/include/cece/io/BinaryOutput.hpp @@ -31,16 +31,16 @@ #include // CeCe -#include "cece/core/OutStream.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/Vector.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/StaticArray.hpp" +#include "cece/math/Vector.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/CliColor.hpp b/include/cece/io/CliColor.hpp similarity index 98% rename from cece/core/CliColor.hpp rename to include/cece/io/CliColor.hpp index 04d9169..6a9368d 100644 --- a/cece/core/CliColor.hpp +++ b/include/cece/io/CliColor.hpp @@ -29,12 +29,12 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/OutStream.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/include/cece/io/Converter.hpp b/include/cece/io/Converter.hpp new file mode 100644 index 0000000..0aba862 --- /dev/null +++ b/include/cece/io/Converter.hpp @@ -0,0 +1,301 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/io/StringStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace io { + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter. + * + * @tparam T Type for conversion. + */ +template +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static T fromString(const String& value) + { + io::InStringStream iss(value); + + T res; + iss >> std::noskipws >> std::boolalpha >> res; + + return res; + } + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(const T& value) + { + io::OutStringStream oss; + + oss << std::boolalpha << value; + + return oss.str(); + } + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for boolean values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. Returns `true` when `value == "true"`, otherwise `false`. + */ + static bool fromString(const String& value) noexcept; + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(bool value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for int values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static int fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(int value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for int values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static unsigned int fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(unsigned int value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for long values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static long fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(long value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for long values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static unsigned long fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(unsigned long value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for float values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static float fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(float value) noexcept; + +}; + +/* ************************************************************************ */ + +/** + * @brief Configuration value converter for double values. + */ +template<> +struct Converter +{ + + /** + * @brief Convert from String to required type. + * + * @param[in] value The string value. + * + * @return The result value. + */ + static double fromString(const String& value); + + + /** + * @brief Convert to String from required type. + * + * @param[in] value The source value. + * + * @return The string value. + */ + static String toString(double value) noexcept; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/CsvFile.hpp b/include/cece/io/CsvFile.hpp similarity index 93% rename from cece/core/CsvFile.hpp rename to include/cece/io/CsvFile.hpp index 2b06408..2d31b38 100644 --- a/cece/core/CsvFile.hpp +++ b/include/cece/io/CsvFile.hpp @@ -31,17 +31,17 @@ #include // CeCe -#include "cece/core/Tuple.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/String.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/core/FileStream.hpp" -#include "cece/core/IntegerSequence.hpp" +#include "cece/Tuple.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/String.hpp" +#include "cece/IntegerSequence.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/FileStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ @@ -66,7 +66,7 @@ class CsvFile * * @param path Path to CSV file. */ - explicit CsvFile(FilePath path); + explicit CsvFile(io::FilePath path); // Public Accessors & Mutators @@ -85,7 +85,7 @@ class CsvFile * * @return */ - const FilePath& getPath() const noexcept + const io::FilePath& getPath() const noexcept { return m_path; } @@ -96,7 +96,7 @@ class CsvFile * * @param filePath */ - void setPath(FilePath path) noexcept + void setPath(io::FilePath path) noexcept { m_path = std::move(path); } @@ -117,7 +117,7 @@ class CsvFile * * @param path Path to CSV file. */ - void open(FilePath path); + void open(io::FilePath path); /** @@ -249,7 +249,7 @@ class CsvFile private: /// File path. - FilePath m_path; + io::FilePath m_path; /// File stream. FileStream m_file; diff --git a/cece/core/DataExport.hpp b/include/cece/io/DataExport.hpp similarity index 96% rename from cece/core/DataExport.hpp rename to include/cece/io/DataExport.hpp index 680e42b..9c14d71 100644 --- a/cece/core/DataExport.hpp +++ b/include/cece/io/DataExport.hpp @@ -32,18 +32,18 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/Tuple.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/IntegerSequence.hpp" -#include "cece/core/StringStream.hpp" -#include "cece/core/DataExportFactory.hpp" +#include "cece/String.hpp" +#include "cece/StaticArray.hpp" +#include "cece/Tuple.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/IntegerSequence.hpp" +#include "cece/io/StringStream.hpp" +#include "cece/io/DataExportFactory.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/DataExportCsv.hpp b/include/cece/io/DataExportCsv.hpp similarity index 93% rename from cece/core/DataExportCsv.hpp rename to include/cece/io/DataExportCsv.hpp index 9fa36e6..c4b9ef4 100644 --- a/cece/core/DataExportCsv.hpp +++ b/include/cece/io/DataExportCsv.hpp @@ -28,14 +28,14 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/DataExport.hpp" -#include "cece/core/CsvFile.hpp" -#include "cece/core/FilePath.hpp" +#include "cece/io/DataExport.hpp" +#include "cece/io/CsvFile.hpp" +#include "cece/io/FilePath.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ @@ -54,7 +54,7 @@ class DataExportCsv : public DataExport * * @param path */ - explicit DataExportCsv(FilePath path); + explicit DataExportCsv(io::FilePath path); /** @@ -72,7 +72,7 @@ class DataExportCsv : public DataExport * * @return */ - const FilePath& getFilePath() const noexcept + const io::FilePath& getFilePath() const noexcept { return m_file.getPath(); } diff --git a/cece/core/DataExportCsvFactory.hpp b/include/cece/io/DataExportCsvFactory.hpp similarity index 95% rename from cece/core/DataExportCsvFactory.hpp rename to include/cece/io/DataExportCsvFactory.hpp index c5957fe..c8a5d12 100644 --- a/cece/core/DataExportCsvFactory.hpp +++ b/include/cece/io/DataExportCsvFactory.hpp @@ -28,12 +28,12 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/DataExportFactory.hpp" +#include "cece/io/DataExportFactory.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ @@ -58,7 +58,7 @@ class DataExportCsvFactory : public DataExportFactory * * @return Created object pointer. */ - UniquePtr create(String name) const noexcept override; + UniquePtr create(String name) const override; }; diff --git a/cece/core/DataExportFactory.hpp b/include/cece/io/DataExportFactory.hpp similarity index 93% rename from cece/core/DataExportFactory.hpp rename to include/cece/io/DataExportFactory.hpp index 5619d37..383ed40 100644 --- a/cece/core/DataExportFactory.hpp +++ b/include/cece/io/DataExportFactory.hpp @@ -28,13 +28,13 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/Factory.hpp" +#include "cece/String.hpp" +#include "cece/factory/Factory.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ @@ -45,7 +45,7 @@ class DataExport; /** * @brief DataExport factory interface. */ -using DataExportFactory = Factory; +using DataExportFactory = factory::Factory; /* ************************************************************************ */ @@ -54,6 +54,6 @@ using DataExportFactory = Factory; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(DataExport, String) +CECE_FACTORY_EXTERN(io::DataExport, String) /* ************************************************************************ */ diff --git a/include/cece/io/FilePath.hpp b/include/cece/io/FilePath.hpp new file mode 100644 index 0000000..919cb5c --- /dev/null +++ b/include/cece/io/FilePath.hpp @@ -0,0 +1,691 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace io { + +/* ************************************************************************ */ + +/** + * @brief File path type. + */ +class FilePath +{ + +// Public Constants +public: + + + /// Path separator. + static constexpr char SEPARATOR = '/'; + + +// Public Ctors & Dtors +public: + + + /** + * @brief Default constructor. + */ + FilePath() = default; + + + /** + * @brief Constructor. + * + * @param source The source path. + */ + FilePath(String source); + + + /** + * @brief Constructor. + * + * @param source The source path. + */ + FilePath(const char* source); + + +// Public Operators +public: + + + /** + * @brief Append path. + * + * @param path The path to append. + * + * @return *this + */ + FilePath& operator/=(const FilePath& path) noexcept + { + return append(path); + } + + + /** + * @brief Append source. + * + * @param source The source to append. + * + * @return *this + */ + template + FilePath& operator/=(const Source& source) noexcept + { + return append(source); + } + + + /** + * @brief Append path. + * + * @param path The path to append. + * + * @return *this + */ + FilePath& operator+=(const FilePath& path) noexcept + { + return concat(path); + } + + + /** + * @brief Append source. + * + * @param source The source to append. + * + * @return *this + */ + template + FilePath& operator+=(const Source& source) noexcept + { + return concat(source); + } + + + /** + * @brief Append path. + * + * @param path The path to append. + * + * @return New file path. + */ + FilePath operator/(const FilePath& path) const noexcept + { + return FilePath(*this).append(path); + } + + + /** + * @brief Append source. + * + * @param source The source to append. + * + * @return New file path. + */ + template + FilePath operator/(const Source& source) const noexcept + { + return FilePath(*this).append(source); + } + + + /** + * @brief Append path. + * + * @param path The path to append. + * + * @return New file path. + */ + FilePath operator+(const FilePath& path) const noexcept + { + return FilePath(*this).concat(path); + } + + + /** + * @brief Append source. + * + * @param source The source to append. + * + * @return New file path. + */ + template + FilePath operator+(const Source& source) const noexcept + { + return FilePath(*this).concat(source); + } + + +// Public Accessors & Mutators +public: + + + /** + * @brief Check if path is empty. + * + * @return True if path is empty, False otherwise. + */ + bool isEmpty() const noexcept + { + return m_path.empty(); + } + + + /** + * @brief Returns path file name. + * + * @return The filename without directory. + */ + String getFilename() const noexcept; + + + /** + * @brief Returns path extension. + * + * @return The file extension. + */ + String getExtension() const noexcept; + + + /** + * @brief Returns parent path. + * + * @return The parent path. + */ + FilePath getParentPath() const noexcept; + + + /** + * @brief Returns path stem. + * + * @return The stem. + */ + FilePath getStem() const noexcept; + + + /** + * @brief Convert path to string. + * + * @return Null terminated string. + */ + const char* c_str() const noexcept + { + return m_path.c_str(); + } + + + /** + * @brief Returns path length. + * + * @return The path length. + */ + int getSize() const noexcept + { + return static_cast(m_path.size()); + } + + + /** + * @brief Convert path to string. + * + * @return String representation of the object. + */ + String toString() const noexcept + { + return m_path; + } + + + /** + * @brief Append path. + * + * @param source Path to append. + * + * @return *this + */ + FilePath& append(const FilePath& source) noexcept + { + if (!m_path.empty()) + m_path += SEPARATOR; + + m_path.append(source.m_path); + return *this; + } + + + /** + * @brief Append string to the path. + * + * @param source String to append. + * + * @return *this + */ + template + FilePath& append(const Source& source) noexcept + { + return append(FilePath(source)); + } + + + /** + * @brief Append path. + * + * @param source Path to append. + * + * @return *this + */ + FilePath& concat(const FilePath& source) noexcept + { + m_path.append(source.m_path); + return *this; + } + + + /** + * @brief Append string to the path. + * + * @param source String to append. + * + * @return *this + */ + template + FilePath& concat(const Source& source) noexcept + { + return concat(FilePath(source)); + } + + + /** + * @brief Replace path extension. + * + * @param ext New extension. + * + * @return this + */ + FilePath& replaceExtension(const String& ext); + + +// Public Operations +public: + + + /** + * @brief Clear path. + */ + void clear() noexcept + { + m_path.clear(); + } + + + /** + * @brief Input stream operator. + * + * @param is The input stream. + * @param path The path to write. + * + * @return The input stream. + */ + friend InStream& operator>>(InStream& is, FilePath& path) + { + return is >> path.m_path; + } + + + /** + * @brief Output stream operator. + * + * @param os The output stream. + * @param path The path read to. + * + * @return The output stream. + */ + friend OutStream& operator<<(OutStream& os, const FilePath& path) + { + return os << path.m_path; + } + + + /** + * @brief Returns current working directory. + * + * @return Current working directory. + */ + static FilePath getCurrent(); + + + /** + * @brief Changes current working directory. + * + * @param[in] path The new current path. + */ + static void setCurrent(const FilePath& path); + + + /** + * @brief Test if given path is a file. + * + * @param[in] path The path. + * + * @return True if path is a file, False otherwise. + */ + static bool isFile(const FilePath& path) noexcept; + + /** + * @brief Tests if path is a directory. + * + * @param path The path + * + * @return True if directory, False otherwise. + */ + static bool isDirectory(const FilePath& path) noexcept; + + + /** + * @brief Tests if file path exists. + * + * @param path The path + * + * @return True if path exists, False otherwise. + */ + static bool exists(const FilePath& path) noexcept; + + + /** + * @brief Returns temporary directory. + * + * @return Path to temporary directory. + */ + static FilePath getTempDirectory(); + + + /** + * @brief Get all entries in given directory. + * + * @param dir Directory to iterate. + * + * @return Result paths. `dot` and `dot-dot` are skipped. + */ + static DynamicArray openDirectory(const FilePath& dir); + + +// Private Data Members +private: + + /// Path value. + String m_path; +}; + +/* ************************************************************************ */ + +/** + * @brief Tests if path is a file. + * + * @param path + * + * @return + * + * @deprecated + */ +inline bool isFile(const FilePath& path) noexcept +{ + return FilePath::isFile(path); +} + +/* ************************************************************************ */ + +/** + * @brief Tests if path is a directory. + * + * @param path + * + * @return + * + * @deprecated + */ +inline bool isDirectory(const FilePath& path) noexcept +{ + return FilePath::isDirectory(path); +} + +/* ************************************************************************ */ + +/** + * @brief Tests if file path exists. + * + * @param path + * + * @return + * + * @deprecated + */ +inline bool pathExists(const FilePath& path) noexcept +{ + return FilePath::exists(path); +} + +/* ************************************************************************ */ + +/** + * @brief Returns temporary directory. + * + * @return + * + * @deprecated + */ +inline FilePath tempDirectory() +{ + return FilePath::getTempDirectory(); +} + +/* ************************************************************************ */ + +/** + * @brief Get all entries in given directory. + * + * @param dir + * + * @return + * + * @deprecated + */ +inline DynamicArray openDirectory(const FilePath& dir) +{ + return FilePath::openDirectory(dir); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are equal, `false` otherwise. + */ +inline bool operator==(const FilePath& lhs, const FilePath& rhs) noexcept +{ + return lhs.toString() == rhs.toString(); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are equal, `false` otherwise. + */ +inline bool operator==(const FilePath& lhs, const String& rhs) noexcept +{ + return lhs.toString() == rhs; +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are equal, `false` otherwise. + */ +inline bool operator==(const FilePath& lhs, const char* rhs) noexcept +{ + return lhs.toString() == rhs; +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are equal, `false` otherwise. + */ +inline bool operator==(const String& lhs, const FilePath& rhs) noexcept +{ + return lhs == rhs.toString(); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are equal, `false` otherwise. + */ +inline bool operator==(const char* lhs, const FilePath& rhs) noexcept +{ + return lhs == rhs.toString(); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are not equal, `false` otherwise. + */ +inline bool operator!=(const FilePath& lhs, const FilePath& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are not equal, `false` otherwise. + */ +inline bool operator!=(const FilePath& lhs, const String& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are not equal, `false` otherwise. + */ +inline bool operator!=(const FilePath& lhs, const char* rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are not equal, `false` otherwise. + */ +inline bool operator!=(const String& lhs, const FilePath& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +/** + * @brief Relational operator. + * + * @param[in] lhs The first path. + * @param[in] rhs The second path. + * + * @return `true` if paths are not equal, `false` otherwise. + */ +inline bool operator!=(const char* lhs, const FilePath& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/FileStream.hpp b/include/cece/io/FileStream.hpp similarity index 99% rename from cece/core/FileStream.hpp rename to include/cece/io/FileStream.hpp index a9ff483..adc37da 100644 --- a/cece/core/FileStream.hpp +++ b/include/cece/io/FileStream.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/InOutStream.hpp b/include/cece/io/InOutStream.hpp similarity index 99% rename from cece/core/InOutStream.hpp rename to include/cece/io/InOutStream.hpp index b372ed0..25ff57e 100644 --- a/cece/core/InOutStream.hpp +++ b/include/cece/io/InOutStream.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/InStream.hpp b/include/cece/io/InStream.hpp similarity index 99% rename from cece/core/InStream.hpp rename to include/cece/io/InStream.hpp index 41160dc..ce9d2d8 100644 --- a/cece/core/InStream.hpp +++ b/include/cece/io/InStream.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/OutStream.hpp b/include/cece/io/OutStream.hpp similarity index 99% rename from cece/core/OutStream.hpp rename to include/cece/io/OutStream.hpp index acc9439..aa89fa7 100644 --- a/cece/core/OutStream.hpp +++ b/include/cece/io/OutStream.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/StringStream.hpp b/include/cece/io/StringStream.hpp similarity index 99% rename from cece/core/StringStream.hpp rename to include/cece/io/StringStream.hpp index fb5e8d1..5bbb670 100644 --- a/cece/core/StringStream.hpp +++ b/include/cece/io/StringStream.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/ExpressionParser.hpp b/include/cece/lang/ExpressionParser.hpp similarity index 94% rename from cece/core/ExpressionParser.hpp rename to include/cece/lang/ExpressionParser.hpp index f8ace14..48b0014 100644 --- a/cece/core/ExpressionParser.hpp +++ b/include/cece/lang/ExpressionParser.hpp @@ -28,18 +28,18 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/IteratorRange.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/Real.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/Parser.hpp" -#include "cece/core/Parameters.hpp" +#include "cece/common.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/Map.hpp" +#include "cece/StringView.hpp" +#include "cece/Exception.hpp" +#include "cece/Parameters.hpp" +#include "cece/lang/Parser.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace lang { /* ************************************************************************ */ diff --git a/cece/core/Parser.hpp b/include/cece/lang/Parser.hpp similarity index 98% rename from cece/core/Parser.hpp rename to include/cece/lang/Parser.hpp index 058bf54..b063f8a 100644 --- a/cece/core/Parser.hpp +++ b/include/cece/lang/Parser.hpp @@ -28,14 +28,14 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Log.hpp" -#include "cece/core/IteratorRange.hpp" -#include "cece/core/Exception.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/Exception.hpp" +#include "cece/log/Log.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace lang { /* ************************************************************************ */ @@ -399,7 +399,7 @@ class BasicParser template void note(Message&& msg) const noexcept { - Log::info(msg); + log::Log::info(msg); } @@ -413,7 +413,7 @@ class BasicParser template void warning(Message&& msg) const noexcept { - Log::warning(msg); + log::Log::warning(msg); } @@ -427,7 +427,7 @@ class BasicParser template void error(Message&& msg) const { - Log::error(msg); + log::Log::error(msg); } diff --git a/cece/core/Tokenizer.hpp b/include/cece/lang/Tokenizer.hpp similarity index 98% rename from cece/core/Tokenizer.hpp rename to include/cece/lang/Tokenizer.hpp index dd531f7..81bab48 100644 --- a/cece/core/Tokenizer.hpp +++ b/include/cece/lang/Tokenizer.hpp @@ -28,16 +28,16 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Log.hpp" -#include "cece/core/IteratorRange.hpp" -#include "cece/core/Assert.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/StringView.hpp" +#include "cece/Assert.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/Exception.hpp" +#include "cece/StringView.hpp" +#include "cece/log/Log.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace lang { /* ************************************************************************ */ @@ -683,7 +683,7 @@ class BasicTokenizer template void note(Message&& msg) const noexcept { - Log::info(msg); + log::Log::info(msg); } @@ -697,7 +697,7 @@ class BasicTokenizer template void warning(Message&& msg) const noexcept { - Log::warning(msg); + log::Log::warning(msg); } @@ -711,7 +711,7 @@ class BasicTokenizer template void error(Message&& msg) const { - Log::error(msg); + log::Log::error(msg); } diff --git a/include/cece/loader/Factory.hpp b/include/cece/loader/Factory.hpp new file mode 100644 index 0000000..374cdad --- /dev/null +++ b/include/cece/loader/Factory.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/LoaderFactory.hpp' instead") +#else +#warning "Include 'cece/simulation/LoaderFactory.hpp' instead" +#endif +#include "cece/simulation/LoaderFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace loader { + +/* ************************************************************************ */ + +using simulation::Loader; +using Factory = simulation::LoaderFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/loader/FactoryManager.hpp b/include/cece/loader/FactoryManager.hpp new file mode 100644 index 0000000..aacb80c --- /dev/null +++ b/include/cece/loader/FactoryManager.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/LoaderFactoryManager.hpp' instead") +#else +#warning "Include 'cece/simulation/LoaderFactoryManager.hpp' instead" +#endif +#include "cece/simulation/LoaderFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace loader { + +/* ************************************************************************ */ + +using simulation::Loader; +using FactoryManager = simulation::LoaderFactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/loader/Loader.hpp b/include/cece/loader/Loader.hpp new file mode 100644 index 0000000..cce314f --- /dev/null +++ b/include/cece/loader/Loader.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Loader.hpp' instead") +#else +#warning "Include 'cece/simulation/Loader.hpp' instead" +#endif +#include "cece/simulation/Loader.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace loader { + +/* ************************************************************************ */ + +using simulation::Loader; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/FileOutput.hpp b/include/cece/log/FileOutput.hpp new file mode 100644 index 0000000..a68b5c0 --- /dev/null +++ b/include/cece/log/FileOutput.hpp @@ -0,0 +1,75 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/io/FilePath.hpp" +#include "cece/io/FileStream.hpp" +#include "cece/log/StreamOutput.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief The log output for output streams. + */ +class FileOutput : public StreamOutput +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param path Path to log file. + * + * @throws InvalidArgumentException If file cannot be open. + */ + explicit FileOutput(io::FilePath path); + + +// Private Data Members +private: + + /// Output file stream. + io::OutFileStream m_stream; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/Log.hpp b/include/cece/log/Log.hpp new file mode 100644 index 0000000..281a20f --- /dev/null +++ b/include/cece/log/Log.hpp @@ -0,0 +1,330 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/UniquePtr.hpp" +#include "cece/log/Logger.hpp" +#include "cece/log/Output.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief Returns the default logger. + * + * @return The logger. + */ +Logger& get_logger() noexcept; + +/* ************************************************************************ */ + +/** + * @brief Returns output. + * + * @return The output. + */ +inline ViewPtr get_output() noexcept +{ + return get_logger().getOutput(); +} + +/* ************************************************************************ */ + +/** + * @brief Change output. + * + * @param[in] output The pointer to output. + */ +inline void set_output(UniquePtr output) noexcept +{ + return get_logger().setOutput(std::move(output)); +} + +/* ************************************************************************ */ + +/** + * @brief Log a message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void msg(Args&&... args) +{ + get_logger().msg(std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log a message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void msgS(const String& section, Args&&... args) +{ + get_logger().msgS(section, std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log an info message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void info(Args&&... args) +{ + get_logger().info(std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log an info message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void infoS(const String& section, Args&&... args) +{ + get_logger().infoS(section, std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log a debug message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void debug(Args&&... args) +{ + get_logger().debug(std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log a debug message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void debugS(const String& section, Args&&... args) +{ + get_logger().debugS(section, std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log a warning message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void warning(Args&&... args) +{ + get_logger().warning(std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log a warning message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void warningS(const String& section, Args&&... args) +{ + get_logger().warningS(section, std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log an error message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void error(Args&&... args) +{ + get_logger().error(std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Log an error message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ +template +inline void errorS(const String& section, Args&&... args) +{ + get_logger().errorS(section, std::forward(args)...); +} + +/* ************************************************************************ */ + +/** + * @brief Logging main interface. + * + * @deprecated + */ +class Log +{ + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns output. + * + * @return The output. + */ + static ViewPtr getOutput() noexcept + { + return get_output(); + } + + + /** + * @brief Change output. + * + * @param[in] output The pointer to output. + */ + static void setOutput(UniquePtr output) noexcept + { + set_output(std::move(output)); + } + + +// Public Operators +public: + + + /** + * @brief Log an info message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + static void info(Args&&... args) + { + log::info(std::forward(args)...); + } + + + /** + * @brief Log a debug message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + static void debug(Args&&... args) + { + log::debug(std::forward(args)...); + } + + + /** + * @brief Log a warning message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + static void warning(Args&&... args) + { + log::warning(std::forward(args)...); + } + + + /** + * @brief Log an error message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + static void error(Args&&... args) + { + log::error(std::forward(args)...); + } + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/Logger.hpp b/include/cece/log/Logger.hpp new file mode 100644 index 0000000..901e38c --- /dev/null +++ b/include/cece/log/Logger.hpp @@ -0,0 +1,334 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/io/StringStream.hpp" +#include "cece/log/Severity.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +class Output; + +/* ************************************************************************ */ + +/** + * @brief The message logger. + */ +class Logger +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] output The output. + */ + explicit Logger(UniquePtr output) noexcept + : m_output(std::move(output)) + { + // Nothing to do + } + + +// Public Accessors & Mutators +public: + + + /** + * @brief Get the logger output. + * + * @return The output. + */ + ViewPtr getOutput() const noexcept + { + return makeView(m_output); + } + + + /** + * @brief Change default output. + * + * @param[in] output The pointer to output. + */ + void setOutput(UniquePtr output) noexcept + { + m_output = std::move(output); + } + + +// Public Operators +public: + + + /** + * @brief Log a default message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void msg(Args&&... args) + { + message(Severity::Default, std::forward(args)...); + } + + + /** + * @brief Log a default message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void msgS(const String& section, Args&&... args) + { + messageS(Severity::Default, section, std::forward(args)...); + } + + + /** + * @brief Log an info message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void info(Args&&... args) + { + message(Severity::Info, std::forward(args)...); + } + + + /** + * @brief Log an info message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void infoS(const String& section, Args&&... args) + { + messageS(Severity::Info, section, std::forward(args)...); + } + + + /** + * @brief Log a debug message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void debug(Args&&... args) + { + message(Severity::Debug, std::forward(args)...); + } + + + /** + * @brief Log a debug message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void debugS(const String& section, Args&&... args) + { + messageS(Severity::Debug, section, std::forward(args)...); + } + + + /** + * @brief Log a warning message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void warning(Args&&... args) + { + message(Severity::Warning, std::forward(args)...); + } + + + /** + * @brief Log a warning message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void warningS(const String& section, Args&&... args) + { + messageS(Severity::Warning, section, std::forward(args)...); + } + + + /** + * @brief Log an error message. + * + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void error(Args&&... args) + { + message(Severity::Error, std::forward(args)...); + } + + + /** + * @brief Log an error message. + * + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void errorS(const String& section, Args&&... args) + { + messageS(Severity::Error, section, std::forward(args)...); + } + + + /** + * @brief Log a message. + * + * @param[in] severity Message severity. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void message(Severity severity, Args&&... args) + { + messageS(severity, {}, std::forward(args)...); + } + + + /** + * @brief Log a message. + * + * @param[in] severity Message severity. + * @param[in] section Message section. + * @param[in] args Log arguments. + * + * @tparam Args Argument types. + */ + template + void messageS(Severity severity, const String& section, Args&&... args) + { + io::OutStringStream oss; + buildMessage(oss, std::forward(args)...); + writeMessage(severity, section, oss.str()); + } + + +// Private Operations +private: + + + /** + * @brief Write a message. + * + * @param[in] severity The message severity. + * @param[in] section The message section. + * @param[in] msg The message. + */ + void writeMessage(Severity severity, const String& section, const String& msg); + + + /** + * @brief Build a message. + * + * @param stream The output stream. + */ + static void buildMessage(io::OutStringStream& stream) + { + // Nothing to do + } + + + /** + * @brief Build a message. + * + * @param stream The output stream. + * @param[in] arg The fist argument. + * @param[in] args The remaining arguments. + * + * @tparam Arg Type of the first argument. + * @tparam Args Types of the remaining arguments. + */ + template + static void buildMessage(io::OutStringStream& stream, Arg&& arg, Args&&... args) + { + stream << arg; + buildMessage(stream, std::forward(args)...); + } + + +// Private Data Members +private: + + /// Standard output. + UniquePtr m_output; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/Output.hpp b/include/cece/log/Output.hpp new file mode 100644 index 0000000..c8fb963 --- /dev/null +++ b/include/cece/log/Output.hpp @@ -0,0 +1,76 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/log/Severity.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief Output class that handles log output. + */ +class Output +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Destructor. + */ + virtual ~Output() = 0; + + +// Public Operations +public: + + /** + * @brief Log a message. + * + * @param severity Message severity. + * @param section Message section. + * @param msg Message to log. + */ + virtual void write(Severity severity, const String& section, const String& msg) = 0; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/Severity.hpp b/include/cece/log/Severity.hpp new file mode 100644 index 0000000..f52e57e --- /dev/null +++ b/include/cece/log/Severity.hpp @@ -0,0 +1,52 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief Message log severity. + */ +enum class Severity +{ + Default, + Info, + Warning, + Error, + Debug +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/StdOutput.hpp b/include/cece/log/StdOutput.hpp new file mode 100644 index 0000000..56d0f4b --- /dev/null +++ b/include/cece/log/StdOutput.hpp @@ -0,0 +1,67 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/log/Output.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief The log output for standard outputs. + */ +class StdOutput : public Output +{ + + +// Public Operations +public: + + + /** + * @brief Log a message. + * + * @param severity Message severity. + * @param section Message section. + * @param msg Message to log. + */ + void write(Severity severity, const String& section, const String& msg) override; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/log/StreamOutput.hpp b/include/cece/log/StreamOutput.hpp new file mode 100644 index 0000000..40f19fd --- /dev/null +++ b/include/cece/log/StreamOutput.hpp @@ -0,0 +1,90 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/io/OutStream.hpp" +#include "cece/log/Output.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +/** + * @brief The log output for output streams. + */ +class StreamOutput : public Output +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param stream The output stream. + */ + explicit StreamOutput(io::OutStream& stream) noexcept + : m_stream(stream) + { + // Nothing to do + } + + +// Public Operations +public: + + + /** + * @brief Log a message. + * + * @param severity Message severity. + * @param section Message section. + * @param msg Message to log. + */ + void write(Severity severity, const String& section, const String& msg) override; + + +// Private Data Members +private: + + /// Output stream. + io::OutStream& m_stream; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/Grid.hpp b/include/cece/math/Grid.hpp similarity index 98% rename from cece/core/Grid.hpp rename to include/cece/math/Grid.hpp index b4ca8d5..c8016ae 100644 --- a/cece/core/Grid.hpp +++ b/include/cece/math/Grid.hpp @@ -28,14 +28,14 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/AlignedAllocator.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/AlignedAllocator.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ diff --git a/cece/core/Shape.hpp b/include/cece/math/Shape.hpp similarity index 90% rename from cece/core/Shape.hpp rename to include/cece/math/Shape.hpp index db4b8d4..e14e378 100644 --- a/cece/core/Shape.hpp +++ b/include/cece/math/Shape.hpp @@ -28,14 +28,14 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/VectorUnits.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ @@ -65,10 +65,10 @@ struct ShapeUndefined {}; struct ShapeCircle { /// Shape center. - units::PositionVector center; + unit::PositionVector center; /// Circle radius. - units::Length radius; + unit::Length radius; }; /* ************************************************************************ */ @@ -79,10 +79,10 @@ struct ShapeCircle struct ShapeRectangle { /// Shape center. - units::PositionVector center; + unit::PositionVector center; /// Rectangle size. - units::SizeVector size; + unit::SizeVector size; }; /* ************************************************************************ */ @@ -93,10 +93,10 @@ struct ShapeRectangle struct ShapeEdges { /// Shape center. - units::PositionVector center; + unit::PositionVector center; /// List of edges. - DynamicArray edges; + DynamicArray edges; }; /* ************************************************************************ */ @@ -263,7 +263,7 @@ class Shape * * @return */ - static Shape makeCircle(units::Length radius, units::PositionVector center = Zero) noexcept + static Shape makeCircle(unit::Length radius, unit::PositionVector center = Zero) noexcept { return Shape{ShapeCircle{center, radius}}; } @@ -277,7 +277,7 @@ class Shape * * @return */ - static Shape makeRectangle(units::SizeVector size, units::PositionVector center = Zero) noexcept + static Shape makeRectangle(unit::SizeVector size, unit::PositionVector center = Zero) noexcept { return Shape{ShapeRectangle{center, size}}; } @@ -291,7 +291,7 @@ class Shape * * @return */ - static Shape makeEdges(DynamicArray edges, units::PositionVector center = Zero) noexcept + static Shape makeEdges(DynamicArray edges, unit::PositionVector center = Zero) noexcept { return Shape{ShapeEdges{center, std::move(edges)}}; } diff --git a/cece/core/ShapeToGrid.hpp b/include/cece/math/ShapeToGrid.hpp similarity index 96% rename from cece/core/ShapeToGrid.hpp rename to include/cece/math/ShapeToGrid.hpp index d3db2eb..137e231 100644 --- a/cece/core/ShapeToGrid.hpp +++ b/include/cece/math/ShapeToGrid.hpp @@ -32,16 +32,16 @@ #include // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/Vector.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/Shape.hpp" -#include "cece/core/Real.hpp" +#include "cece/common.hpp" +#include "cece/Assert.hpp" +#include "cece/math/Vector.hpp" +#include "cece/math/Shape.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ @@ -62,7 +62,7 @@ inline namespace core { */ template void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const Shape& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { switch (shape.getType()) @@ -101,7 +101,7 @@ void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const Shape& shape, const Vector OutIt mapShapeToGrid(OutIt out, const Shape& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { mapShapeToGrid( @@ -130,7 +130,7 @@ OutIt mapShapeToGrid(OutIt out, const Shape& shape, const Vector& steps, */ template void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeCircle& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { // Get signed type @@ -184,7 +184,7 @@ void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeCircle& shape, const Vect */ template OutIt mapShapeToGrid(OutIt out, const ShapeCircle& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { mapShapeToGrid( @@ -213,7 +213,7 @@ OutIt mapShapeToGrid(OutIt out, const ShapeCircle& shape, const Vector& s */ template void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeRectangle& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { // Get signed type @@ -260,7 +260,7 @@ void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeRectangle& shape, const V */ template OutIt mapShapeToGrid(OutIt out, const ShapeEdges& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = Zero) { mapShapeToGrid( @@ -294,7 +294,7 @@ OutIt mapShapeToGrid(OutIt out, const ShapeEdges& shape, const Vector& st */ template void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeEdges& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = Zero) { // Get signed type @@ -446,7 +446,7 @@ void mapShapeToGrid(FnIn fnIn, FnOut fnOut, const ShapeEdges& shape, const Vecto */ template OutIt mapShapeToGrid(OutIt out, const ShapeRectangle& shape, const Vector& steps, - const Vector& center, units::Angle rotation, const Vector& max, + const Vector& center, unit::Angle rotation, const Vector& max, const Vector& min = {}) { mapShapeToGrid( diff --git a/cece/core/StaticMatrix.hpp b/include/cece/math/StaticMatrix.hpp similarity index 99% rename from cece/core/StaticMatrix.hpp rename to include/cece/math/StaticMatrix.hpp index 24b887a..a00ab22 100644 --- a/cece/core/StaticMatrix.hpp +++ b/include/cece/math/StaticMatrix.hpp @@ -32,13 +32,13 @@ #include // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ diff --git a/cece/core/Vector.hpp b/include/cece/math/Vector.hpp similarity index 98% rename from cece/core/Vector.hpp rename to include/cece/math/Vector.hpp index 77185d0..23c4480 100644 --- a/cece/core/Vector.hpp +++ b/include/cece/math/Vector.hpp @@ -32,19 +32,19 @@ #include // CeCe -#include "cece/config.hpp" -#include "cece/core/Real.hpp" -#include "cece/core/Assert.hpp" -#include "cece/core/Zero.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" +#include "cece/common.hpp" +#include "cece/Assert.hpp" +#include "cece/StaticArray.hpp" +#include "cece/math/Zero.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" +#include "cece/unit/math.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ @@ -937,11 +937,11 @@ class BasicVector * * @return */ - BasicVector rotated(units::Angle angle) const noexcept + BasicVector rotated(unit::Angle angle) const noexcept { return BasicVector( - static_cast(getX() * cos(angle.value()) - getY() * sin(angle.value())), - static_cast(getX() * sin(angle.value()) + getY() * cos(angle.value())) + static_cast(getX() * cos(static_cast(angle)) - getY() * sin(static_cast(angle))), + static_cast(getX() * sin(static_cast(angle)) + getY() * cos(static_cast(angle))) ); } @@ -1560,7 +1560,7 @@ class BasicVector * @brief Basic vector. */ template -using Vector = BasicVector; +using Vector = BasicVector; /* ************************************************************************ */ @@ -2558,7 +2558,7 @@ cross(const T1& lhs, const BasicVector& rhs) noexcept * @return is. */ template -InStream& operator>>(InStream& is, BasicVector& vector) +io::InStream& operator>>(io::InStream& is, BasicVector& vector) { unsigned i = 0; @@ -2590,7 +2590,7 @@ InStream& operator>>(InStream& is, BasicVector& vector) * @return os. */ template -OutStream& operator<<(OutStream& os, const BasicVector& vector) noexcept +io::OutStream& operator<<(io::OutStream& os, const BasicVector& vector) noexcept { for (unsigned i = 0; i < N; ++i) { @@ -2605,9 +2605,9 @@ OutStream& operator<<(OutStream& os, const BasicVector& vector) noexcept /* ************************************************************************ */ -extern template class BasicVector; -extern template class BasicVector; -extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; /* ************************************************************************ */ diff --git a/cece/core/VectorRange.hpp b/include/cece/math/VectorRange.hpp similarity index 98% rename from cece/core/VectorRange.hpp rename to include/cece/math/VectorRange.hpp index 7d05d16..1784654 100644 --- a/cece/core/VectorRange.hpp +++ b/include/cece/math/VectorRange.hpp @@ -28,13 +28,13 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/IteratorRange.hpp" -#include "cece/core/Vector.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ diff --git a/cece/core/Zero.hpp b/include/cece/math/Zero.hpp similarity index 99% rename from cece/core/Zero.hpp rename to include/cece/math/Zero.hpp index d22d456..b02b3ca 100644 --- a/cece/core/Zero.hpp +++ b/include/cece/math/Zero.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ diff --git a/cece/core/constants.hpp b/include/cece/math/constants.hpp similarity index 93% rename from cece/core/constants.hpp rename to include/cece/math/constants.hpp index 5818057..18a6a27 100644 --- a/cece/core/constants.hpp +++ b/include/cece/math/constants.hpp @@ -28,31 +28,29 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Real.hpp" +#include "cece/common.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { -namespace constants { +namespace math { /* ************************************************************************ */ /** * @brief PI constant. */ -static constexpr RealType PI = 3.14159265359; +constexpr RealType PI = 3.14159265359; /* ************************************************************************ */ /** * @brief Euler number constant. */ -static constexpr RealType E = 2.718281828459; +constexpr RealType E = 2.718281828459; /* ************************************************************************ */ -} } } diff --git a/cece/core/fastexp.hpp b/include/cece/math/fastexp.hpp similarity index 99% rename from cece/core/fastexp.hpp rename to include/cece/math/fastexp.hpp index f3c9e8b..bf4863c 100644 --- a/cece/core/fastexp.hpp +++ b/include/cece/math/fastexp.hpp @@ -34,7 +34,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ diff --git a/include/cece/module/Container.hpp b/include/cece/module/Container.hpp new file mode 100644 index 0000000..3a9cd1d --- /dev/null +++ b/include/cece/module/Container.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ModuleContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/ModuleContainer.hpp' instead" +#endif +#include "cece/simulation/ModuleContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace module { + +/* ************************************************************************ */ + +using Container = simulation::ModuleContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/module/ExportModule.hpp b/include/cece/module/ExportModule.hpp new file mode 100644 index 0000000..6a301ca --- /dev/null +++ b/include/cece/module/ExportModule.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ExportModule.hpp' instead") +#else +#warning "Include 'cece/simulation/ExportModule.hpp' instead" +#endif +#include "cece/simulation/ExportModule.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace module { + +/* ************************************************************************ */ + +using simulation::ExportModule; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/module/Factory.hpp b/include/cece/module/Factory.hpp new file mode 100644 index 0000000..84d19c4 --- /dev/null +++ b/include/cece/module/Factory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ModuleFactory.hpp' instead") +#else +#warning "Include 'cece/simulation/ModuleFactory.hpp' instead" +#endif +#include "cece/simulation/ModuleFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace module { + +/* ************************************************************************ */ + +using Factory = simulation::ModuleFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/module/FactoryManager.hpp b/include/cece/module/FactoryManager.hpp new file mode 100644 index 0000000..9067e42 --- /dev/null +++ b/include/cece/module/FactoryManager.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ModuleFactoryManager.hpp' instead") +#else +#warning "Include 'cece/simulation/ModuleFactoryManager.hpp' instead" +#endif +#include "cece/simulation/ModuleFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace module { + +/* ************************************************************************ */ + +using FactoryManager = simulation::ModuleFactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/module/Module.hpp b/include/cece/module/Module.hpp new file mode 100644 index 0000000..9eee276 --- /dev/null +++ b/include/cece/module/Module.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Module.hpp' instead") +#else +#warning "Include 'cece/simulation/Module.hpp' instead" +#endif +#include "cece/simulation/Module.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace module { + +/* ************************************************************************ */ + +using simulation::Module; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/BoundData.hpp b/include/cece/object/BoundData.hpp similarity index 89% rename from cece/object/BoundData.hpp rename to include/cece/object/BoundData.hpp index ed842ca..437d14f 100644 --- a/cece/object/BoundData.hpp +++ b/include/cece/object/BoundData.hpp @@ -23,7 +23,12 @@ /* */ /* ************************************************************************ */ -#pragma once +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectBoundData.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectBoundData.hpp' instead" +#endif +#include "cece/simulation/ObjectBoundData.hpp" /* ************************************************************************ */ @@ -32,22 +37,7 @@ namespace object { /* ************************************************************************ */ -/** - * @brief Bound data. - */ -class BoundData -{ - -// Public Ctors & Dtors -public: - - - /** - * @brief Destructor. - */ - virtual ~BoundData(); - -}; +using BoundData = simulation::ObjectBoundData; /* ************************************************************************ */ diff --git a/cece/object/ContactListener.hpp b/include/cece/object/ContactListener.hpp similarity index 81% rename from cece/object/ContactListener.hpp rename to include/cece/object/ContactListener.hpp index aeae7f4..27d39b3 100644 --- a/cece/object/ContactListener.hpp +++ b/include/cece/object/ContactListener.hpp @@ -23,7 +23,12 @@ /* */ /* ************************************************************************ */ -#pragma once +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectContactListener.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectContactListener.hpp' instead" +#endif +#include "cece/simulation/ObjectContactListener.hpp" /* ************************************************************************ */ @@ -32,39 +37,7 @@ namespace object { /* ************************************************************************ */ -class Object; - -/* ************************************************************************ */ - -/** - * @brief Object contact listener. - */ -class ContactListener -{ - -// Public Ctors & Dtors -public: - - - /** - * @brief Destructor. - */ - virtual ~ContactListener() = 0; - - -// Public Operations -public: - - - /** - * @brief When two objects contact. - * - * @param o1 The first object. - * @param o2 The second object. - */ - virtual void onContact(Object& o1, Object& o2) = 0; - -}; +using ContactListener = simulation::ObjectContactListener; /* ************************************************************************ */ diff --git a/include/cece/object/Container.hpp b/include/cece/object/Container.hpp new file mode 100644 index 0000000..0319f75 --- /dev/null +++ b/include/cece/object/Container.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectContainer.hpp' instead" +#endif +#include "cece/simulation/ObjectContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using Container = simulation::ObjectContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/object/Factory.hpp b/include/cece/object/Factory.hpp new file mode 100644 index 0000000..68204bc --- /dev/null +++ b/include/cece/object/Factory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectFactory.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectFactory.hpp' instead" +#endif +#include "cece/simulation/ObjectFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using Factory = simulation::ObjectFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/object/FactoryManager.hpp b/include/cece/object/FactoryManager.hpp new file mode 100644 index 0000000..38d9c71 --- /dev/null +++ b/include/cece/object/FactoryManager.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectFactoryManager.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectFactoryManager.hpp' instead" +#endif +#include "cece/simulation/ObjectFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using FactoryManager = simulation::ObjectFactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/object/Object.hpp b/include/cece/object/Object.hpp new file mode 100644 index 0000000..fc598ee --- /dev/null +++ b/include/cece/object/Object.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Object.hpp' instead") +#else +#warning "Include 'cece/simulation/Object.hpp' instead" +#endif +#include "cece/simulation/Object.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using simulation::Object; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/Type.hpp b/include/cece/object/Type.hpp similarity index 83% rename from cece/object/Type.hpp rename to include/cece/object/Type.hpp index 8e59f04..3ad0609 100644 --- a/cece/object/Type.hpp +++ b/include/cece/object/Type.hpp @@ -23,13 +23,12 @@ /* */ /* ************************************************************************ */ -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/String.hpp" -#include "cece/config/Configuration.hpp" +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectType.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectType.hpp' instead" +#endif +#include "cece/simulation/ObjectType.hpp" /* ************************************************************************ */ @@ -38,26 +37,7 @@ namespace object { /* ************************************************************************ */ -/** - * @brief Defines user defined object type. - */ -class Type -{ - -// Public Data Members -public: - - - /// Object type name. - String name; - - /// Basename type name. - String baseName; - - /// Object configuration. - config::Configuration config; - -}; +using Type = simulation::ObjectType; /* ************************************************************************ */ diff --git a/include/cece/object/TypeContainer.hpp b/include/cece/object/TypeContainer.hpp new file mode 100644 index 0000000..bba2c79 --- /dev/null +++ b/include/cece/object/TypeContainer.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ObjectTypeContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/ObjectTypeContainer.hpp' instead" +#endif +#include "cece/simulation/ObjectTypeContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using TypeContainer = simulation::ObjectTypeContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/simulator/Simulator.hpp b/include/cece/os/SharedLibrary.hpp similarity index 51% rename from cece/simulator/Simulator.hpp rename to include/cece/os/SharedLibrary.hpp index dff4c2b..53f506d 100644 --- a/cece/simulator/Simulator.hpp +++ b/include/cece/os/SharedLibrary.hpp @@ -27,195 +27,172 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" - -/* ************************************************************************ */ - -// C++ -#include - // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/UniquePtr.hpp" -#ifdef CECE_RENDER -#include "cece/render/Context.hpp" -#endif +#include "cece/export.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/io/FilePath.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { - -/* ************************************************************************ */ - -class Simulation; +namespace os { /* ************************************************************************ */ /** - * @brief Simulator class. + * @brief Shared library RAII wrapper. * - * Simulator handles simulation of the given (owned) simulation in current thread. + * @details It hides OS-specific shared library handling. */ -class Simulator final +class SharedLibrary final { -// Public Ctors & Dtors +// Public Constants public: - /** - * @brief Destructor. - */ - ~Simulator() - { - stop(); - } + /// Library file prefix + static const CECE_EXPORT String PREFIX; + /// Library file extension + static const CECE_EXPORT String EXTENSION; -/// Public Accessors + +// Public Ctors & Dtors public: /** - * @brief If simulation is running. - * - * @return + * @brief Default constructor. */ - bool isRunning() const noexcept - { - return m_isRunning; - } + SharedLibrary() = default; /** - * @brief Returns current simulation. + * @brief Constructor. * - * @return A pointer to current simulation or nullptr. + * @param path Path to shared library. */ - Simulation* getSimulation() const noexcept - { - return m_simulation.get(); - } - + explicit SharedLibrary(io::FilePath path); -#ifdef CECE_RENDER /** - * @brief Returns rendering context. - * - * @return + * @brief Destructor. */ - render::Context& getRenderContext() noexcept - { - return m_renderContext; - } + ~SharedLibrary(); /** - * @brief Returns rendering context. + * @brief Copy constructor. * - * @return + * @param[in] src Source object. */ - const render::Context& getRenderContext() const noexcept - { - return m_renderContext; - } + SharedLibrary(const SharedLibrary& src) = delete; /** - * @brief Returns if rendering context is initialized. + * @brief Move constructor. * - * @return + * @param[in] src Source object. */ - bool isDrawInitialized() noexcept - { - return m_renderContext.isInitialized(); - } + SharedLibrary(SharedLibrary&& src) noexcept; -#endif - -// Public Mutators +// Public Operators public: /** - * @brief Change current simulation. The old simulation will be deleted. + * @brief Copy assignment operator. + * + * @param[in] src Source object. * - * @param simulation New simulation. + * @return *this. */ - void setSimulation(UniquePtr simulation) noexcept - { - m_simulation = std::move(simulation); - } + SharedLibrary& operator=(const SharedLibrary& src) = delete; + + + /** + * @brief Move assignment operator. + * + * @param[in] src Source object. + * + * @return *this. + */ + SharedLibrary& operator=(SharedLibrary&& src) noexcept; -// Public Operations +// Public Accessors & Mutators public: /** - * @brief Start simulation. + * @brief Check if library is open. + * + * @return True if library is open, False otherwise. */ - void start(); + bool isOpen() const noexcept + { + return m_handle != nullptr; + } /** - * @brief Stop simulation. + * @brief Returns library path. + * + * @return Path to shared library. */ - void stop() + const io::FilePath& getPath() const noexcept { - m_isRunning = false; + return m_path; } /** - * @brief Update simulation by time step. + * @brief Returns address of required symbol. + * + * @param[in] name Symbol name. * - * @return If next step can be calculated. + * @return Pointer to symbol or nullptr. */ - bool update(); + void* getAddr(StringView name) const noexcept; -#ifdef CECE_RENDER - /** - * @brief Initialize simulation for rendering. + * @brief Returns address of required symbol. + * + * @param[in] name Symbol name. + * + * @tparam Signature Type of the symbol. * - * @param clearColor + * @return Pointer to symbol or nullptr. */ - void drawInit(const render::Color& clearColor = render::colors::WHITE) + template + Signature getAddr(StringView name) const noexcept { - m_renderContext.init(clearColor); + return reinterpret_cast(reinterpret_cast(getAddr(name))); } /** - * @brief Render simulation. + * @brief Format library name according to current platform. * - * @param width - * @param height + * @param[in] name The required library name. + * + * @return Platform shared library name. */ - void draw(unsigned int width, unsigned int height); - -#endif + static String formatName(String name); -// Data Members +// Private Data Members private: - /// Flag if thread is running - std::atomic m_isRunning{false}; - -#ifdef CECE_RENDER - /// Rendering context. - render::Context m_renderContext; -#endif + /// Path to library file. + io::FilePath m_path; - /// Current simulation - UniquePtr m_simulation; + /// Shared library handle. + void* m_handle = nullptr; }; diff --git a/cece/core/TimeMeasurement.hpp b/include/cece/perf/TimeMeasurement.hpp similarity index 95% rename from cece/core/TimeMeasurement.hpp rename to include/cece/perf/TimeMeasurement.hpp index a733d36..dd1565d 100644 --- a/cece/core/TimeMeasurement.hpp +++ b/include/cece/perf/TimeMeasurement.hpp @@ -31,13 +31,13 @@ #include // CeCe -#include "cece/core/OutStream.hpp" -#include "cece/core/String.hpp" +#include "cece/String.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace perf { /* ************************************************************************ */ @@ -62,7 +62,7 @@ bool isMeasureTimeEnabled() noexcept; * * @return */ -OutStream* getMeasureTimeOutput() noexcept; +io::OutStream* getMeasureTimeOutput() noexcept; /* ************************************************************************ */ @@ -71,7 +71,7 @@ OutStream* getMeasureTimeOutput() noexcept; * * @param output */ -void setMeasureTimeOutput(OutStream* output) noexcept; +void setMeasureTimeOutput(io::OutStream* output) noexcept; /* ************************************************************************ */ @@ -88,7 +88,7 @@ struct DefaultMeasurementOutput * @param name Measurement name. * @param dt Measured time. */ - void operator()(OutStream& out, const String& name, Clock::duration dt) const noexcept + void operator()(io::OutStream& out, const String& name, Clock::duration dt) const noexcept { using namespace std::chrono; out << name << ";" << duration_cast(dt).count() << "\n"; diff --git a/cece/plugin/Api.hpp b/include/cece/plugin/Api.hpp similarity index 56% rename from cece/plugin/Api.hpp rename to include/cece/plugin/Api.hpp index 5fb34af..fe9bc9b 100644 --- a/cece/plugin/Api.hpp +++ b/include/cece/plugin/Api.hpp @@ -27,16 +27,9 @@ /* ************************************************************************ */ -// CeCe -#include "cece/core/UniquePtr.hpp" -#include "cece/core/String.hpp" -#include "cece/core/DynamicArray.hpp" - -/* ************************************************************************ */ - namespace cece { namespace config { class Configuration; } - namespace simulator { class Simulation; } + namespace simulation { class Simulation; } } /* ************************************************************************ */ @@ -46,13 +39,29 @@ namespace plugin { /* ************************************************************************ */ -class Repository; +class RepositoryRecord; /* ************************************************************************ */ /** - * @brief Plugin API type. Custom plugins implements this class' functions - * to provide additional functionality to the simulator. + * @brief Plugin API abstract class. + * + * @details Custom plugins implements this class' functions to provide + * additional functionality to the simulator. + * + * Each valid plugin must export a function which create an instance + * of own Api class implementation. Api have several optional member + * functions which are called in different times. + * + * - `onLoad` - When the plugin is loaded into a Manager. Main purpose of this + * function is initialize plugin for global use and in most cases register + * offered extensions into repository. + * - `onUnload` - Opposite of the `onLoad` function. It's called when the plugin + * is being unloaded from the Manager. + * - `onImport` - When the plugin is being imported/used by the simulation. + * - `onRemove` - When the plugin is being de-imported by the simulation. + * - `storeConfig` - Support function used only when the memory representation + * needs to be stored. */ class Api { @@ -62,12 +71,9 @@ class Api /** - * @brief Destructor. + * @brief Destructor. */ - virtual ~Api() - { - // Nothing to do - } + virtual ~Api() = 0; // Public Operations @@ -75,92 +81,61 @@ class Api /** - * @brief Returns a list of required plugins. - * - * @return - */ - virtual DynamicArray requiredPlugins() const - { - return {}; - } - - - /** - * @brief Returns a list of plugins that will conflict with. + * @brief When the plugin is loaded by plugin manager. * - * @return + * @param repository Repository record for the plugin. */ - virtual DynamicArray conflictPlugins() const - { - return {}; - } - - - /** - * @brief On plugin load. - * - * @param repository Plugins repository. - */ - virtual void onLoad(Repository& repository) const + virtual void onLoad(RepositoryRecord& repository) { // Nothing to do } /** - * @brief On plugin unload. + * @brief When the plugin is unloaded from plugin manager. * - * @param repository Plugins repository. + * @param repository Repository record for the plugin. */ - virtual void onUnload(Repository& repository) const; - - - /** - * @brief Init simulation. - * - * @param simulation Simulation. - */ - virtual void initSimulation(simulator::Simulation& simulation) const + virtual void onUnload(RepositoryRecord& repository) { // Nothing to do } /** - * @brief Finalize simulation. + * @brief When the plugin is imported into simulation. * - * @param simulation Simulation. + * @param simulation The simulation which imports the plugin. + * @param[in] config Plugin import configuration. */ - virtual void finalizeSimulation(simulator::Simulation& simulation) const + virtual void onImport(simulation::Simulation& simulation, const config::Configuration& config) { // Nothing to do } /** - * @brief Load plugin configuration. + * @brief When the plugin is being removed from the simulation. * - * @param simulation Current simulation. - * @param config Plugin configuration. + * @param simulation The simulation. */ - virtual void loadConfig(simulator::Simulation& simulation, const config::Configuration& config) const + virtual void onRemove(simulation::Simulation& simulation) { // Nothing to do } /** - * @brief Store plugin configuration. + * @brief Store plugin configuration. * - * @param simulation Current simulation. - * @param config Plugin configuration. + * @param[in] simulation Current simulation. + * @param config Output plugin configuration. */ - virtual void storeConfig(const simulator::Simulation& simulation, config::Configuration& config) const + virtual void storeConfig(const simulation::Simulation& simulation, config::Configuration& config) const { // Nothing to do } - }; /* ************************************************************************ */ diff --git a/cece/plugin/Config.hpp b/include/cece/plugin/Config.hpp similarity index 85% rename from cece/plugin/Config.hpp rename to include/cece/plugin/Config.hpp index 68c647e..e6d2b43 100644 --- a/cece/plugin/Config.hpp +++ b/include/cece/plugin/Config.hpp @@ -33,16 +33,17 @@ namespace plugin { /* ************************************************************************ */ /** - * @brief Library configuration. Plugin with different configuration - * cannot be used in simulation. + * @brief Plugin build configuration. + * + * @details Plugin with different configuration cannot be used in a + * simulation. */ struct Config { - int apiVersion; - int realSize; - int renderEnabled; - int threadSafe; - int dimension; + int apiVersion; ///< Plugin API version. + int realSize; ///< Plugin real type size in bytes. + int renderEnabled; ///< If plugin supports rendering. + int threadSafe; ///< If plugin is built with thread support. }; /* ************************************************************************ */ diff --git a/include/cece/plugin/Context.hpp b/include/cece/plugin/Context.hpp new file mode 100644 index 0000000..da7957f --- /dev/null +++ b/include/cece/plugin/Context.hpp @@ -0,0 +1,242 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/StringView.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/Set.hpp" +#include "cece/Parameters.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/plugin/Manager.hpp" + +/// @deprecated +#include "cece/simulation/Object.hpp" + +/* ************************************************************************ */ + +namespace cece { + namespace simulation { class Loader; } + namespace simulation { class Initializer; } + namespace simulation { class Module; } + //namespace simulation { class Object; } + namespace simulation { class ObjectType; } + namespace simulation { class Program; } + namespace simulation { class Simulation; } +} + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +class Api; +class Repository; + +/* ************************************************************************ */ + +/** + * @brief Plugins context for simulation. + */ +class Context +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param manager Plugins manager. + */ + explicit Context(const Manager& manager) noexcept + : m_manager(manager) + { + // Nothing to do + } + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns plugin repository. + * + * @return The repository. + */ + const Repository& getRepository() const noexcept + { + return m_manager.getRepository(); + } + + + /** + * @brief Returns a set of imported plugin names. + * + * @return A set of imported plugin names. + */ + const Set& getImportedPlugins() const noexcept + { + return m_importedPlugins; + } + + + /** + * @brief Returns if plugin is already imported. + * + * @param name Plugin name. + * + * @return True if a plugin with given name is imported, False otherwise. + */ + bool isImported(StringView name) const noexcept + { + return m_importedPlugins.find(name) != m_importedPlugins.end(); + } + + +// Public Operations +public: + + + /** + * @brief Import plugin. + * + * @param name Plugin name. + * + * @return Imported plugin API. + * @throws PluginNotFoundException When plugin with given name is not loaded. + */ + ViewPtr importPlugin(StringView name); + + + /** + * @brief Remove imported plugin. + * + * @param name Plugin name. + * + * @return Plugin API. + */ + ViewPtr removePlugin(StringView name); + + + /** + * @brief Create a loader. + * + * @param name Loader registration name. + * + * @return Pointer to the created loader. + * @throws cece::Exception When a loader cannot be created. + * @throws ExtensionNotFoundException When a loader is not found. + */ + UniquePtr createLoader(StringView name) const; + + + /** + * @brief Create an initializer. + * + * @param name Initializer registration name. + * + * @return Pointer to the created initializer. + * @throws cece::Exception When an initializer cannot be created. + * @throws ExtensionNotFoundException When an initializer is not found in + * imported plugins. + * @throws MultipleExtensionsException When an initializer with same name is + * found in multiple plugins. + */ + UniquePtr createInitializer(StringView name) const; + + + /** + * @brief Create a module. + * + * @param name Module registration name. + * @param simulation Simulation object. + * + * @return Pointer to created module. + * @throws cece::Exception When a module cannot be created. + * @throws ExtensionNotFoundException When a module is not found in imported + * plugins. + * @throws MultipleExtensionsException When a module with same name is found + * in multiple plugins. + */ + UniquePtr createModule(StringView name, simulation::Simulation& simulation) const; + + + /** + * @brief Create an object. + * + * @param name Object registration name. + * @param simulation Simulation object. + * @param type Type of created object. + * + * @return Pointer to created object. + * @throws cece::Exception When an object cannot be created. + * @throws ExtensionNotFoundException When an object is not found in imported + * plugins. + * @throws MultipleExtensionsException When an object with same name is found + * in multiple plugins. + */ + UniquePtr createObject(StringView name, simulation::Simulation& simulation, simulation::Object::Type type) const; + + + /** + * @brief Create a program + * + * @param[in] name Program registration name. + * + * @return Pointer to created program. + * @throws cece::Exception When a program cannot be created. + * @throws ExtensionNotFoundException When a program is not found in imported + * plugins. + * @throws MultipleExtensionsException When a program with same name is found + * in multiple plugins. + */ + UniquePtr createProgram(StringView name) const; + + +// Private Data Members +private: + + /// Plugins manager. + const Manager& m_manager; + + /// Imported plugins. + Set m_importedPlugins; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/Exception.hpp b/include/cece/plugin/Exception.hpp new file mode 100644 index 0000000..940c3f1 --- /dev/null +++ b/include/cece/plugin/Exception.hpp @@ -0,0 +1,319 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/Exception.hpp" +#include "cece/DynamicArray.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Base class for all plugin exceptions. + */ +class Exception : public cece::RuntimeException +{ + +// Public Ctors & Dtors +public: + + using cece::RuntimeException::RuntimeException; +}; + +/* ************************************************************************ */ + +/** + * @brief Exception thrown in case of invalid plugin loading. + */ +class InvalidPluginException : public Exception +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] path The source plugin file path. + * @param[in] msg The error message. + */ + explicit InvalidPluginException(io::FilePath path, String msg) noexcept; + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns plugin file path. + * + * @return The plugin file path. + */ + const io::FilePath& getPath() const noexcept + { + return m_path; + } + + + /** + * @brief Returns the error message. + * + * @return The error message. + */ + const String& getErrorMessage() const noexcept + { + return m_errorMessage; + } + + +// Private Data Members +private: + + /// Plugin source path. + io::FilePath m_path; + + /// Error message. + String m_errorMessage; +}; + +/* ************************************************************************ */ + +/** + * @brief Expection used when used by repository. + */ +class RepositoryException : public Exception +{ + +// Public Ctors & Dtors +public: + + using Exception::Exception; + +}; + +/* ************************************************************************ */ + +/** + * @brief Expection used when trying to import plugin that doesn't exists. + */ +class PluginNotFoundException : public Exception +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] name The plugin name. + */ + explicit PluginNotFoundException(String name) noexcept; + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns plugin name. + * + * @return The plugin name. + */ + const String& getName() const noexcept + { + return m_name; + } + + +// Private Data Members +private: + + /// Plugin name. + String m_name; + +}; + +/* ************************************************************************ */ + +/** + * @brief Exception thrown in case of plugin extension multiple definition. + */ +class MultipleExtensionsException : public Exception +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] kind The extension kind. + * @param[in] name The extension name. + * @param[in] plugins The plugins where the extension was found. + */ + explicit MultipleExtensionsException(String kind, String name, DynamicArray plugins) noexcept; + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns extension kind. + * + * @return The extension kind. + */ + const String& getKind() const noexcept + { + return m_kind; + } + + + /** + * @brief Returns extension name. + * + * @return The extension name. + */ + const String& getName() const noexcept + { + return m_name; + } + + + /** + * @brief Returns a list of plugin names where the name was found. + * + * @return A list of plugin names. + */ + const DynamicArray& getPluginNames() const noexcept + { + return m_pluginNames; + } + + +// Private Data Members +private: + + /// Plugin extension kind. + String m_kind; + + /// Plugin extension name. + String m_name; + + /// A list of plugin names. + DynamicArray m_pluginNames; +}; + +/* ************************************************************************ */ + +/** + * @brief Exception thrown in case of plugin extension multiple definition. + */ +class ExtensionNotFoundException : public Exception +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] kind The extension kind. + * @param[in] name The extension name. + * @param[in] plugins The plugins where the extension was found. + */ + explicit ExtensionNotFoundException(String kind, String name, DynamicArray plugins) noexcept; + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns extension kind. + * + * @return The extension kind. + */ + const String& getKind() const noexcept + { + return m_kind; + } + + + /** + * @brief Returns extension name. + * + * @return The extension name. + */ + const String& getName() const noexcept + { + return m_name; + } + + + /** + * @brief Returns a list of plugin names where the name was found. + * + * @return A list of plugin names. + */ + const DynamicArray& getPluginNames() const noexcept + { + return m_pluginNames; + } + + +// Private Data Members +private: + + /// Plugin extension kind. + String m_kind; + + /// Plugin extension name. + String m_name; + + /// A list of plugin names. + DynamicArray m_pluginNames; +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/Loader.hpp b/include/cece/plugin/Loader.hpp new file mode 100644 index 0000000..214785d --- /dev/null +++ b/include/cece/plugin/Loader.hpp @@ -0,0 +1,85 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/ViewPtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/plugin/Plugin.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Plugin loader interface. Allows to load plugins other than shared + * library. + * + * @details Loader have to implement `loadAll` member function which scans + * given directory for plugins that match loader requirements. There + * is no checks if other loader loaded the same plugin. + */ +class Loader +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Destructor. + */ + virtual ~Loader() = 0; + + +// Public Operations +public: + + + /** + * @brief Load all plugins from given directory. + * + * @param directory Directory to where are plugins located. The + * directory may not exists. + * + * @return A list of loaded plugins. + */ + virtual DynamicArray loadAll(const io::FilePath& directory) = 0; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/Manager.hpp b/include/cece/plugin/Manager.hpp new file mode 100644 index 0000000..3481fb9 --- /dev/null +++ b/include/cece/plugin/Manager.hpp @@ -0,0 +1,255 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/plugin/Loader.hpp" +#include "cece/plugin/Repository.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +class Api; + +/* ************************************************************************ */ + +/** + * @brief Manager of simulator plugins. + * + * @details The functionality is based on two things: plugin loader and + * plugin directory. + * + * Plugin directory are path of directory where loaded plugins are + * stored and where loaders looks for available plugins. Loader + * looks into plugins directory and according to own rules it loads + * plugins found in plugins directory. By default, manager needs to + * add a plugin loader (SharedLibraryLoader is available) and + * specify plugins directory. No additional action is required, + * calling one either `addLoader` or `addDirectory` invoke plugins + * loading. For each loaded valid plugin the `Api::onLoad` is called + * and when the manager is being destroyed the `Api::onUnload` is + * called. + * + * @note The plugin loader is responsible for proper plugin loading and + * the plugin code must be loaded in memory until `Loader` is + * destroyed. + */ +class Manager final +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + */ + Manager(); + + + /** + * @brief Destructor. + */ + ~Manager(); + + +// Public Accessors +public: + + + /** + * @brief Returns mutable plugin repository. + * + * @return Manager's repository. + */ + Repository& getRepository() noexcept + { + return m_repository; + } + + + /** + * @brief Returns immutable plugin repository. + * + * @return Manager's repository. + */ + const Repository& getRepository() const noexcept + { + return m_repository; + } + + + /** + * @brief Returns plugin loaders. + * + * @return A list of plugin loaders. + */ + const DynamicArray>& getLoaders() const noexcept + { + return m_loaders; + } + + + /** + * @brief Returns plugins search directories. + * + * @return A list of directories. + */ + const DynamicArray& getDirectories() const noexcept + { + return m_directories; + } + + + /** + * @brief Return a list of plugins. + * + * @return An array of plugin names. + */ + DynamicArray getNames() const noexcept; + + + /** + * @brief Check if plugin is loaded. + * + * @param[in] name Plugin name. + * + * @return True if plugin is loaded, False otherwise. + */ + bool isLoaded(StringView name) const noexcept; + + + /** + * @brief Returns plugin API of loaded plugin. + * + * @param[in] name Plugin name. + * + * @return Pointer to API or nullptr, if plugin is not loaded. + */ + ViewPtr getApi(StringView name) const noexcept; + + +// Public Mutators +public: + + + /** + * @brief Add a plugin loader. + * + * It also invoke loader's scan function for all currently + * stored paths. + * + * @param[in] loader Pointer to plugin loader. + * + * @return *this. + */ + Manager& addLoader(UniquePtr loader); + + + /** + * @brief Store additional directories. + * + * @param[in] directories List of directories. + * + * @return *this. + */ + Manager& addDirectories(DynamicArray directories) + { + for (auto&& directory : directories) + addDirectory(std::move(directory)); + + return *this; + } + + + /** + * @brief Add directory where the plugins are stored. + * + * @details For all stored loaders, it invoke their scan function. + * + * @param[in] path Path with plugins. + * + * @return *this + */ + Manager& addDirectory(io::FilePath path); + + + /** + * @brief Register a custom plugin. + * + * @details The function also calls `Api::onLoad` function. + * + * @param[in] plugin The plugin. + */ + void addPlugin(Plugin plugin); + + +// Private Operations +private: + + + /** + * @brief Add plugins into inner list. + * + * @param[in] plugins Plugins to add. + */ + void appendPlugins(DynamicArray plugins); + + +// Private Data Members +private: + + /// Plugin loaders. + DynamicArray> m_loaders; + + /// Plugins directory paths. + DynamicArray m_directories; + + /// List of loaded plugins. + DynamicArray m_plugins; + + /// Plugin repository. + Repository m_repository; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/Plugin.hpp b/include/cece/plugin/Plugin.hpp new file mode 100644 index 0000000..7fb30c5 --- /dev/null +++ b/include/cece/plugin/Plugin.hpp @@ -0,0 +1,104 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/plugin/Api.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Loaded plugin information. + */ +class Plugin final +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + * + * @param[in] name Plugin name. + * @param[in] api Plugin API. + */ + explicit Plugin(String name, UniquePtr api) noexcept; + + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns plugin name. + * + * @return Plugin name. + */ + const String& getName() const noexcept + { + return m_name; + } + + + /** + * @brief Returns plugin API. + * + * @return Pointer view to plugin API. + */ + ViewPtr getApi() const noexcept + { + return m_api; + } + + +// Private Data Members +public: + + /// Plugin name. + String m_name; + + /// Plugin API. + UniquePtr m_api; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/Repository.hpp b/include/cece/plugin/Repository.hpp new file mode 100644 index 0000000..b0a5a97 --- /dev/null +++ b/include/cece/plugin/Repository.hpp @@ -0,0 +1,132 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/Map.hpp" +#include "cece/plugin/RepositoryRecord.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Repository is a set of repository record which hold information + * about simulation extensions. + */ +class Repository final +{ + +// Public Accessors & Mutators +public: + + + /** + * @brief Returns all repository records. + * + * @return A map of repository records. + */ + const Map& getRecords() const noexcept + { + return m_records; + } + + + /** + * @brief Returns if record with given name exists. + * + * @param[in] name Record name. + * + * @return Exists a record with given name? + */ + bool exists(StringView name) const noexcept; + + + /** + * @brief Returns repository record with given name. + * + * @param[in] name Record name. + * + * @return Repository record. + * @throws RepositoryException In case a record with given name doesn't + * exists. + */ + RepositoryRecord& get(StringView name); + + + /** + * @brief Returns repository record with given name. + * + * @param[in] name Record name. + * + * @return Repository record. + * @throws RepositoryException In case a record with given name doesn't + * exists. + */ + const RepositoryRecord& get(StringView name) const; + + + /** + * @brief Create a new record.. + * + * @param[in] name Record name. + * + * @return Repository record. + * @throws RepositoryException In case a record with given name already + * exists. + */ + RepositoryRecord& createRecord(String name); + + + /** + * @brief Remove repository record. + * + * @param[in] name Record name. + */ + void removeRecord(StringView name) noexcept; + + +// Private Data Members +private: + + /// Repository records. + Map m_records; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/RepositoryRecord.hpp b/include/cece/plugin/RepositoryRecord.hpp new file mode 100644 index 0000000..bcb1f7d --- /dev/null +++ b/include/cece/plugin/RepositoryRecord.hpp @@ -0,0 +1,392 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/simulation/LoaderFactoryManager.hpp" +#include "cece/simulation/InitializerFactoryManager.hpp" +#include "cece/simulation/ObjectFactoryManager.hpp" +#include "cece/simulation/ModuleFactoryManager.hpp" +#include "cece/simulation/ProgramFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Record for repository. + * + * @details Each record has own name and list of factory + * managers for each extension type. In most cases the plugin + * populate created record by offered objects. + * + * @code{.cpp} +record + .registerModule("my-module") + .registerProgram("my-program") +; + +auto module = record.createModule("my-module"); +auto program = record.createProgram("my-program"); +@endcode + */ +class RepositoryRecord final +{ + +// Public Accessors & Mutators +public: + + + /** + * @brief Checks if a loader is registered under given name. + * + * @param[in] name Registration name. + * + * @return Is a loader with given name registered? + */ + bool isRegisteredLoader(StringView name) const noexcept + { + return m_loaderFactoryManager.exists(name); + } + + + /** + * @brief Checks if an initializer is registered under given name. + * + * @param[in] name Registration name. + * + * @return Is an initializer with given name registered? + */ + bool isRegisteredInitializer(StringView name) const noexcept + { + return m_initFactoryManager.exists(name); + } + + + /** + * @brief Checks if a module is registered under given name. + * + * @param[in] name Registration name. + * + * @return Is an initializer with given name registered? + */ + bool isRegisteredModule(StringView name) const noexcept + { + return m_moduleFactoryManager.exists(name); + } + + + /** + * @brief Checks if an object is registered under given name. + * + * @param[in] name Registration name. + * + * @return Is an object with given name registered? + */ + bool isRegisteredObject(StringView name) const noexcept + { + return m_objectFactoryManager.exists(name); + } + + + /** + * @brief Checks if a program is registered under given name. + * + * @param[in] name Registration name. + * + * @return Is a program with given name registered? + */ + bool isRegisteredProgram(StringView name) const noexcept + { + return m_programFactoryManager.exists(name); + } + + +// Public Mutators +public: + + + /** + * @brief Register a new loader type. + * + * @param[in] name Loader registration name. + * + * @tparam LoaderType Type of a loader registered under given name. + * + * @return *this. + * @throws Exception If another loader is already registered under given name. + */ + template + RepositoryRecord& registerLoader(String name) + { + m_loaderFactoryManager.createFor(std::move(name)); + return *this; + } + + + /** + * @brief Register a new initializer type. + * + * @param[in] name Initializer registration name. + * + * @tparam InitializerType Type of an initializer registered under + * given name. + * + * @return *this. + * @throws Exception If another initializer is already registered under given + * name. + */ + template + RepositoryRecord& registerInitializer(String name) + { + m_initFactoryManager.createFor(std::move(name)); + return *this; + } + + + /** + * @brief Register a new module type. + * + * @param[in] name Module registration name. + * + * @tparam ModuleType Type of a module registered under given name. + * + * @return *this. + * @throws Exception If another module is already registered under given name. + */ + template + RepositoryRecord& registerModule(String name) + { + m_moduleFactoryManager.createFor(std::move(name)); + return *this; + } + + + /** + * @brief Register a new object type. + * + * @param[in] name Object registration name. + * + * @tparam ObjectType Type of an object registered under given name. + * + * @return *this. + * @throws Exception If another object is already registered under given name. + */ + template + RepositoryRecord& registerObject(String name) + { + m_objectFactoryManager.createFor(std::move(name)); + return *this; + } + + + /** + * @brief Register a new program type. + * + * @param[in] name Program registration name. + * + * @tparam ProgramType Type of a program registered under given name. + * + * @return *this. + * @throws Exception If another program is already registered under given + * name. + */ + template + RepositoryRecord& registerProgram(String name) + { + m_programFactoryManager.createFor(std::move(name)); + return *this; + } + + + /** + * @brief Unregister loader type. + * + * @param[in] name Loader registration name. + */ + void unregisterLoader(StringView name) noexcept + { + m_loaderFactoryManager.remove(name); + } + + + /** + * @brief Unregister initializer type. + * + * @param[in] name Initializer registration name. + */ + void unregisterInitializer(StringView name) noexcept + { + m_initFactoryManager.remove(name); + } + + + /** + * @brief Unregister module type. + * + * @param[in] name Module registration name. + */ + void unregisterModule(StringView name) noexcept + { + m_moduleFactoryManager.remove(name); + } + + + /** + * @brief Unregister object type. + * + * @param[in] name Object registration name. + */ + void unregisterObject(StringView name) noexcept + { + m_objectFactoryManager.remove(name); + } + + + /** + * @brief Unregister program type. + * + * @param[in] name Program registration name. + */ + void unregisterProgram(StringView name) noexcept + { + m_programFactoryManager.remove(name); + } + + +// Public Operations +public: + + + /** + * @brief Create a loader. + * + * @details Return value must be valid pointer (no `nullptr`). If a + * loader cannot be created an exception should be thrown. + * + * @param[in] name Loader registration name. + * + * @return A pointer to created loader. + * @throws Exception If loader cannot be created. + */ + UniquePtr createLoader(StringView name) const; + + + /** + * @brief Create an initializer. + * + * @details Return value must be valid pointer (no `nullptr`). If an + * initializer cannot be created an exception should be thrown. + * + * @param[in] name Initializer registration name. + * + * @return A pointer to created initializer. + * @throws Exception If initializer cannot be created. + */ + UniquePtr createInitializer(StringView name) const; + + + /** + * @brief Create a module. + * + * @details Return value must be valid pointer (no `nullptr`). If a + * module cannot be created an exception should be thrown. + * + * @param[in] name Module registration name. + * @param simulation The simulation + * + * @return A pointer to created module. + * @throws Exception If module cannot be created. + */ + UniquePtr createModule(StringView name, simulation::Simulation& simulation) const; + + + /** + * @brief Create an object. + * + * @details Return value must be valid pointer (no `nullptr`). If a + * module cannot be created an exception should be thrown. + * + * @param[in] name Module registration name. + * @param simulation The simulation + * @param[in] type The type + * + * @return A pointer to created module. + * @throws Exception If module cannot be created. + */ + UniquePtr createObject(StringView name, simulation::Simulation& simulation, simulation::Object::Type type) const; + + + /** + * @brief Create a program. + * + * @details Return value must be valid pointer (no `nullptr`). If a + * program cannot be created an exception should be thrown. + * + * @param[in] name Program registration name. + * + * @return A pointer to created program. + * @throws Exception If program cannot be created. + */ + UniquePtr createProgram(StringView name) const; + + +// Private Data Members +private: + + /// Loader factory manager. + simulation::LoaderFactoryManager m_loaderFactoryManager; + + /// Initializer factory manager. + simulation::InitializerFactoryManager m_initFactoryManager; + + /// Module factory manager. + simulation::ModuleFactoryManager m_moduleFactoryManager; + + /// Object factory manager. + simulation::ObjectFactoryManager m_objectFactoryManager; + + /// Program factory manager. + simulation::ProgramFactoryManager m_programFactoryManager; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/SharedLibrary.hpp b/include/cece/plugin/SharedLibrary.hpp new file mode 100644 index 0000000..e0ffe68 --- /dev/null +++ b/include/cece/plugin/SharedLibrary.hpp @@ -0,0 +1,48 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/os/SharedLibrary.hpp' instead") +#else +#warning "Include 'cece/os/SharedLibrary.hpp' instead" +#endif + +#include "cece/os/SharedLibrary.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +using os::SharedLibrary; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/SharedLibraryLoader.hpp b/include/cece/plugin/SharedLibraryLoader.hpp new file mode 100644 index 0000000..dee667f --- /dev/null +++ b/include/cece/plugin/SharedLibraryLoader.hpp @@ -0,0 +1,83 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/DynamicArray.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/plugin/Loader.hpp" +#include "cece/os/SharedLibrary.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +/** + * @brief Shared library plugin loader. + * + * @details Open shared libraries are open until object destruction. The + * reason for this is the plugin uses code from shared library and + * it must be loaded for whole time. Unloading removes those code + * from runtime and application will crash. After destruction of + * this object no plugin code should be called. Standard usage with + * `Manager` should guarantee that. + */ +class SharedLibraryLoader final : public Loader +{ + +// Public Operations +public: + + + /** + * @brief Scan given directory to load plugins. + * + * @param[in] directory Directory to scan. + * + * @return A list of loaded plugins. + */ + DynamicArray loadAll(const io::FilePath& directory) override; + + +// Private Data Members +private: + + /// Loaded libraries. + DynamicArray m_libraries; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/plugin/definition.hpp b/include/cece/plugin/definition.hpp new file mode 100644 index 0000000..19ae9aa --- /dev/null +++ b/include/cece/plugin/definition.hpp @@ -0,0 +1,181 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/common.hpp" +#include "cece/plugin/Config.hpp" + +/* ************************************************************************ */ + +#ifdef _WIN32 +// Required on Windows otherwise no symbols are exported +# define CECE_PLUGIN_EXPORT __declspec(dllexport) +#else +# define CECE_PLUGIN_EXPORT +#endif + +/* ************************************************************************ */ + +#ifdef CECE_RENDER +# define CECE_RENDER_VALUE 1 +#else +# define CECE_RENDER_VALUE 0 +#endif + +/* ************************************************************************ */ + +#ifdef CECE_THREAD_SAFE +# define CECE_THREAD_SAFE_VALUE 1 +#else +# define CECE_THREAD_SAFE_VALUE 0 +#endif + +/* ************************************************************************ */ + +/** + * @brief Plugin function prototype name. + * + * @param name Function name. + * @param plugin Plugin name. + * + * @return Function prototype. + */ +#define CECE_PLUGIN_PROTOTYPE_NAME(name, plugin) name + +/* ************************************************************************ */ + +/** + * @brief Prototype of function for creating plugin API object. + * + * @param name Plugin name. + * + * @return Create plugin function prototype. + */ +#define CECE_PLUGIN_CREATE_PROTOTYPE(name) \ + extern "C" CECE_PLUGIN_EXPORT cece::plugin::Api* CECE_PLUGIN_PROTOTYPE_NAME(create, name)() + +/* ************************************************************************ */ + +/** + * @brief Declare function for creating plugin API object. + * + * @param name Plugin name. + * + * @return Create plugin function declaration. + */ +#define CECE_PLUGIN_DECLARE_CREATE(name) CECE_PLUGIN_CREATE_PROTOTYPE(name) + +/* ************************************************************************ */ + +/** + * @brief Define function for creating plugin API object. + * + * @param name Plugin name. + * @param className Plugin API class name. + * + * @return Create plugin function definition. + */ +#define CECE_PLUGIN_DEFINE_CREATE(name, className) \ + CECE_PLUGIN_CREATE_PROTOTYPE(name) \ + { \ + return new className{}; \ + } + +/* ************************************************************************ */ + +/** + * @brief Prototype of function for returning plugin configuration. + * + * @param name Plugin name. + * + * @return Plugin get config function prototype. + */ +#define CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) \ + extern "C" CECE_PLUGIN_EXPORT cece::plugin::Config* CECE_PLUGIN_PROTOTYPE_NAME(get_config, name)() + +/* ************************************************************************ */ + +/** + * @brief Declare function for returning plugin configuration. + * + * @param name Plugin name. + * + * @return Plugin get config function definition. + */ +#define CECE_PLUGIN_DECLARE_GET_CONFIG(name) CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) + +/* ************************************************************************ */ + +/** + * @brief Define function for returning plugin configuration. + * + * @param name Plugin name. + * + * @return Plugin get config function definition. + */ +#define CECE_PLUGIN_DEFINE_GET_CONFIG(name) \ + CECE_PLUGIN_GET_CONFIG_PROTOTYPE(name) \ + { \ + static cece::plugin::Config config = { \ + cece::PLUGIN_API_VERSION, /* apiVersion */ \ + sizeof(cece::RealType), /* realSize */ \ + CECE_RENDER_VALUE, /* renderEnabled */ \ + CECE_THREAD_SAFE_VALUE /* threadSafe */ \ + }; \ + return &config; \ + } + +/* ************************************************************************ */ + +/** + * @brief Declare plugin functions. + * + * @param name Plugin name. + * + * @return Plugin functions declarations. + */ +#define CECE_PLUGIN_DECLARE(name) \ + CECE_PLUGIN_DECLARE_PLUGIN_CREATE(name); \ + CECE_PLUGIN_DECLARE_GET_CONFIG(name) + +/* ************************************************************************ */ + +/** + * @brief Define plugin functions. + * + * @param name Plugin name. + * @param className Plugin API class name. + * + * @return Plugin functions definitions. + */ +#define CECE_PLUGIN_DEFINE(name, className) \ + CECE_PLUGIN_DEFINE_CREATE(name, className) \ + CECE_PLUGIN_DEFINE_GET_CONFIG(name) + +/* ************************************************************************ */ diff --git a/include/cece/program/Container.hpp b/include/cece/program/Container.hpp new file mode 100644 index 0000000..0bb4839 --- /dev/null +++ b/include/cece/program/Container.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ProgramContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/ProgramContainer.hpp' instead" +#endif +#include "cece/simulation/ProgramContainer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using Container = simulation::ProgramContainer; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/program/Factory.hpp b/include/cece/program/Factory.hpp new file mode 100644 index 0000000..e136cb4 --- /dev/null +++ b/include/cece/program/Factory.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ProgramFactory.hpp' instead") +#else +#warning "Include 'cece/simulation/ProgramFactory.hpp' instead" +#endif +#include "cece/simulation/ProgramFactory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using Factory = simulation::ProgramFactory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/program/FactoryManager.hpp b/include/cece/program/FactoryManager.hpp new file mode 100644 index 0000000..5097b9e --- /dev/null +++ b/include/cece/program/FactoryManager.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/ProgramFactoryManager.hpp' instead") +#else +#warning "Include 'cece/simulation/ProgramFactoryManager.hpp' instead" +#endif +#include "cece/simulation/ProgramFactoryManager.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using FactoryManager = simulation::ProgramFactoryManager; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/program/NamedContainer.hpp b/include/cece/program/NamedContainer.hpp similarity index 85% rename from cece/program/NamedContainer.hpp rename to include/cece/program/NamedContainer.hpp index eb56197..98a5914 100644 --- a/cece/program/NamedContainer.hpp +++ b/include/cece/program/NamedContainer.hpp @@ -23,31 +23,21 @@ /* */ /* ************************************************************************ */ -#pragma once - -/* ************************************************************************ */ - -// CeCe -#include "cece/core/PtrNamedContainer.hpp" +#if _MSC_VER +#pragma message("Include 'cece/simulation/ProgramNamedContainer.hpp' instead") +#else +#warning "Include 'cece/simulation/ProgramNamedContainer.hpp' instead" +#endif +#include "cece/simulation/ProgramNamedContainer.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace object { /* ************************************************************************ */ -class Program; - -/* ************************************************************************ */ - -/** - * @brief Container for named programs. - */ -class NamedContainer : public PtrNamedContainer -{ - -}; +using NamedContainer = simulation::ProgramNamedContainer; /* ************************************************************************ */ diff --git a/include/cece/program/Program.hpp b/include/cece/program/Program.hpp new file mode 100644 index 0000000..e8b93ab --- /dev/null +++ b/include/cece/program/Program.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Program.hpp' instead") +#else +#warning "Include 'cece/simulation/Program.hpp' instead" +#endif +#include "cece/simulation/Program.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace object { + +/* ************************************************************************ */ + +using simulation::Program; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/render/Buffer.hpp b/include/cece/render/Buffer.hpp similarity index 100% rename from cece/render/Buffer.hpp rename to include/cece/render/Buffer.hpp diff --git a/cece/render/Camera.hpp b/include/cece/render/Camera.hpp similarity index 93% rename from cece/render/Camera.hpp rename to include/cece/render/Camera.hpp index 0f21c80..3857151 100644 --- a/cece/render/Camera.hpp +++ b/include/cece/render/Camera.hpp @@ -28,8 +28,8 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Real.hpp" -#include "cece/core/VectorUnits.hpp" +#include "cece/common.hpp" +#include "cece/unit/VectorUnits.hpp" /* ************************************************************************ */ @@ -63,7 +63,7 @@ class Camera * * @return */ - const units::PositionVector& getPosition() const noexcept + const unit::PositionVector& getPosition() const noexcept { return m_position; } @@ -89,7 +89,7 @@ class Camera * * @param pos */ - void setPosition(units::PositionVector pos) noexcept + void setPosition(unit::PositionVector pos) noexcept { m_position = std::move(pos); } @@ -110,7 +110,7 @@ class Camera private: /// Camera position. - units::PositionVector m_position; + unit::PositionVector m_position; /// Zoom value. RealType m_zoom = 1.0; diff --git a/cece/render/Circle.hpp b/include/cece/render/Circle.hpp similarity index 100% rename from cece/render/Circle.hpp rename to include/cece/render/Circle.hpp diff --git a/cece/render/Color.hpp b/include/cece/render/Color.hpp similarity index 98% rename from cece/render/Color.hpp rename to include/cece/render/Color.hpp index 7057b93..cdd0c83 100644 --- a/cece/render/Color.hpp +++ b/include/cece/render/Color.hpp @@ -34,9 +34,9 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Real.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" +#include "cece/common.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ @@ -518,7 +518,7 @@ inline Color operator/(RealType lhs, Color rhs) noexcept * * @return is. */ -InStream& operator>>(InStream& is, Color& color); +io::InStream& operator>>(io::InStream& is, Color& color); /* ************************************************************************ */ @@ -530,7 +530,7 @@ InStream& operator>>(InStream& is, Color& color); * * @return os. */ -OutStream& operator<<(OutStream& os, const Color& color) noexcept; +io::OutStream& operator<<(io::OutStream& os, const Color& color) noexcept; /* ************************************************************************ */ diff --git a/cece/render/Context.hpp b/include/cece/render/Context.hpp similarity index 92% rename from cece/render/Context.hpp rename to include/cece/render/Context.hpp index 16eda99..373f40c 100644 --- a/cece/render/Context.hpp +++ b/include/cece/render/Context.hpp @@ -27,23 +27,13 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" - -/* ************************************************************************ */ - -#ifndef CECE_RENDER -#error Rendering part requires enabled rendering. -#endif - -/* ************************************************************************ */ - // CeCe -#include "cece/core/Real.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/UniquePtr.hpp" +#define CECE_RENDER_REQUIRE +#include "cece/common.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/VectorUnits.hpp" #include "cece/render/Camera.hpp" #include "cece/render/Program.hpp" #include "cece/render/ImageData.hpp" @@ -130,7 +120,7 @@ class Context * * @return */ - Size getSize() const noexcept; + math::Size getSize() const noexcept; /** @@ -299,7 +289,7 @@ class Context * * @param pos Translation vector. */ - void matrixTranslate(const units::PositionVector& pos) noexcept; + void matrixTranslate(const unit::PositionVector& pos) noexcept; /** @@ -307,7 +297,7 @@ class Context * * @param scale Scale vector. */ - void matrixScale(const units::ScaleVector& scale) noexcept; + void matrixScale(const unit::ScaleVector& scale) noexcept; /** @@ -317,7 +307,7 @@ class Context */ void matrixScale(RealType scale) noexcept { - return matrixScale(units::ScaleVector::createSingle(scale)); + return matrixScale(unit::ScaleVector::createSingle(scale)); } @@ -326,7 +316,7 @@ class Context * * @param angle Angle of the rotation. */ - void matrixRotate(units::Angle angle) noexcept; + void matrixRotate(unit::Angle angle) noexcept; /** @@ -459,7 +449,7 @@ class Context * @param size Line size. * @param color Line color. */ - void drawLine(Vector pos, Vector size, const Color& color = colors::WHITE); + void drawLine(math::Vector pos, math::Vector size, const Color& color = colors::WHITE); /** diff --git a/cece/render/Grid.hpp b/include/cece/render/Grid.hpp similarity index 97% rename from cece/render/Grid.hpp rename to include/cece/render/Grid.hpp index c137c8b..86c29e3 100644 --- a/cece/render/Grid.hpp +++ b/include/cece/render/Grid.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" #include "cece/render/Buffer.hpp" #include "cece/render/GridBase.hpp" @@ -78,7 +78,7 @@ class Grid : public GridBase * * @param size New grid size. */ - void resize(Size size) noexcept; + void resize(math::Size size) noexcept; // Private Data Members diff --git a/cece/render/GridBase.hpp b/include/cece/render/GridBase.hpp similarity index 95% rename from cece/render/GridBase.hpp rename to include/cece/render/GridBase.hpp index 6648fb3..7b65432 100644 --- a/cece/render/GridBase.hpp +++ b/include/cece/render/GridBase.hpp @@ -31,7 +31,7 @@ #include // CeCe -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ @@ -59,7 +59,7 @@ class GridBase * * @return */ - const Size& getSize() const noexcept + const math::Size& getSize() const noexcept { return m_size; } @@ -75,7 +75,7 @@ class GridBase * * @param size */ - void resize(Size size) noexcept + void resize(math::Size size) noexcept { m_size = std::move(size); } @@ -86,7 +86,7 @@ class GridBase /// Grid size. - Size m_size; + math::Size m_size; }; diff --git a/cece/render/GridColor.hpp b/include/cece/render/GridColor.hpp similarity index 90% rename from cece/render/GridColor.hpp rename to include/cece/render/GridColor.hpp index b1252f3..7073d8b 100644 --- a/cece/render/GridColor.hpp +++ b/include/cece/render/GridColor.hpp @@ -28,8 +28,8 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" -#include "cece/core/Grid.hpp" +#include "cece/math/Vector.hpp" +#include "cece/math/Grid.hpp" #include "cece/render/Buffer.hpp" #include "cece/render/Color.hpp" #include "cece/render/Texture.hpp" @@ -71,7 +71,7 @@ class GridColor : public GridBase * @param context Rendering context. * @param size */ - GridColor(Context& context, Size size); + GridColor(Context& context, math::Size size); // Public Operators @@ -84,7 +84,7 @@ class GridColor : public GridBase * @param coord Pixel coordinates. * @param color Pixel color. */ - Color& operator[](const Coordinate& coord) noexcept + Color& operator[](const math::Coordinate& coord) noexcept { return get(coord); } @@ -96,7 +96,7 @@ class GridColor : public GridBase * @param coord Pixel coordinates. * @param color Pixel color. */ - const Color& operator[](const Coordinate& coord) const noexcept + const Color& operator[](const math::Coordinate& coord) const noexcept { return get(coord); } @@ -121,7 +121,7 @@ class GridColor : public GridBase * @param coord Pixel coordinates. * @param color Pixel color. */ - Color& get(const Coordinate& coord) noexcept + Color& get(const math::Coordinate& coord) noexcept { return m_colors[coord]; } @@ -133,7 +133,7 @@ class GridColor : public GridBase * @param coord Pixel coordinates. * @param color Pixel color. */ - const Color& get(const Coordinate& coord) const noexcept + const Color& get(const math::Coordinate& coord) const noexcept { return m_colors[coord]; } @@ -149,7 +149,7 @@ class GridColor : public GridBase * @param coord Pixel coordinates. * @param color Pixel color. */ - void set(const Coordinate& coord, const Color& color) noexcept + void set(const math::Coordinate& coord, const Color& color) noexcept { // Set color m_colors[coord] = color; @@ -191,7 +191,7 @@ class GridColor : public GridBase * @param size New grid size. * @param color Background color. */ - void resize(Size size, const Color& color = colors::BLACK); + void resize(math::Size size, const Color& color = colors::BLACK); /** @@ -218,7 +218,7 @@ class GridColor : public GridBase Buffer m_buffer; /// Buffer for storing texture data. - Grid m_colors; + math::Grid m_colors; /// If colors were updated. bool m_colorsUpdated = false; diff --git a/cece/render/GridColorColorMap.hpp b/include/cece/render/GridColorColorMap.hpp similarity index 98% rename from cece/render/GridColorColorMap.hpp rename to include/cece/render/GridColorColorMap.hpp index 23e8099..4833f78 100644 --- a/cece/render/GridColorColorMap.hpp +++ b/include/cece/render/GridColorColorMap.hpp @@ -67,7 +67,7 @@ class GridColorColorMap : public GridColor * @param context Rendering context. * @param size */ - GridColorColorMap(Context& context, Size size) + GridColorColorMap(Context& context, math::Size size) : GridColorColorMap(context) { resize(std::move(size)); diff --git a/cece/render/GridColorSmooth.hpp b/include/cece/render/GridColorSmooth.hpp similarity index 98% rename from cece/render/GridColorSmooth.hpp rename to include/cece/render/GridColorSmooth.hpp index c03df04..2c03e28 100644 --- a/cece/render/GridColorSmooth.hpp +++ b/include/cece/render/GridColorSmooth.hpp @@ -67,7 +67,7 @@ class GridColorSmooth : public GridColor * @param context Rendering context. * @param size */ - GridColorSmooth(Context& context, Size size) + GridColorSmooth(Context& context, math::Size size) : GridColorSmooth(context) { resize(std::move(size)); diff --git a/cece/render/GridVector.hpp b/include/cece/render/GridVector.hpp similarity index 87% rename from cece/render/GridVector.hpp rename to include/cece/render/GridVector.hpp index 9a008be..2e173d7 100644 --- a/cece/render/GridVector.hpp +++ b/include/cece/render/GridVector.hpp @@ -28,8 +28,8 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Real.hpp" -#include "cece/core/Vector.hpp" +#include "cece/common.hpp" +#include "cece/math/Vector.hpp" #include "cece/render/Buffer.hpp" #include "cece/render/GridBase.hpp" @@ -62,7 +62,7 @@ class GridVector : public GridBase * @param data Vector data. * @param max Maximum value. */ - GridVector(Context& context, Size size, const Vector* data, RealType max = 1); + GridVector(Context& context, math::Size size, const math::Vector* data, RealType max = 1); /** @@ -74,8 +74,8 @@ class GridVector : public GridBase * @param max Maximum value. */ template - GridVector(Context& context, Size size, const Vector* data, RealType max = 1) - : GridVector(context, std::move(size), reinterpret_cast*>(data), max) + GridVector(Context& context, math::Size size, const math::Vector* data, RealType max = 1) + : GridVector(context, std::move(size), reinterpret_cast*>(data), max) { static_assert(sizeof(T) == sizeof(RealType), "T must have same size as RealType"); } @@ -114,7 +114,7 @@ class GridVector : public GridBase * @param size * @param data */ - void resize(Size size, const Vector* data); + void resize(math::Size size, const math::Vector* data); /** @@ -122,7 +122,7 @@ class GridVector : public GridBase * * @param data */ - void update(const Vector* data) noexcept; + void update(const math::Vector* data) noexcept; /** @@ -133,10 +133,10 @@ class GridVector : public GridBase * @param data */ template - void update(const Vector* data) noexcept + void update(const math::Vector* data) noexcept { static_assert(sizeof(T) == sizeof(RealType), "T must have same size as RealType"); - update(reinterpret_cast*>(data)); + update(reinterpret_cast*>(data)); } diff --git a/cece/render/Image.hpp b/include/cece/render/Image.hpp similarity index 88% rename from cece/render/Image.hpp rename to include/cece/render/Image.hpp index b439fe1..1908d72 100644 --- a/cece/render/Image.hpp +++ b/include/cece/render/Image.hpp @@ -28,8 +28,8 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" -#include "cece/core/Grid.hpp" +#include "cece/math/Vector.hpp" +#include "cece/math/Grid.hpp" #include "cece/render/Color.hpp" /* ************************************************************************ */ @@ -60,7 +60,7 @@ class Image * * @param size Image size. */ - explicit Image(Size size); + explicit Image(math::Size size); // Public Operators @@ -73,7 +73,7 @@ class Image * @param coord Pixel coordinates. * @param color Pixel color. */ - Color& operator[](const Coordinate& coord) noexcept + Color& operator[](const math::Coordinate& coord) noexcept { return get(coord); } @@ -85,7 +85,7 @@ class Image * @param coord Pixel coordinates. * @param color Pixel color. */ - const Color& operator[](const Coordinate& coord) const noexcept + const Color& operator[](const math::Coordinate& coord) const noexcept { return get(coord); } @@ -101,7 +101,7 @@ class Image * @param coord Pixel coordinates. * @param color Pixel color. */ - Color& get(const Coordinate& coord) noexcept + Color& get(const math::Coordinate& coord) noexcept { return m_colors[coord]; } @@ -113,7 +113,7 @@ class Image * @param coord Pixel coordinates. * @param color Pixel color. */ - const Color& get(const Coordinate& coord) const noexcept + const Color& get(const math::Coordinate& coord) const noexcept { return m_colors[coord]; } @@ -125,7 +125,7 @@ class Image * @param coord Pixel coordinates. * @param color Pixel color. */ - void set(const Coordinate& coord, const Color& color) noexcept + void set(const math::Coordinate& coord, const Color& color) noexcept { m_colors[coord] = color; } @@ -136,7 +136,7 @@ class Image * * @return */ - Size getSize() const noexcept + math::Size getSize() const noexcept { return m_colors.getSize(); } @@ -163,7 +163,7 @@ class Image * @param size New grid size. * @param color Background color. */ - void resize(Size size, const Color& color = colors::BLACK); + void resize(math::Size size, const Color& color = colors::BLACK); /** @@ -178,7 +178,7 @@ class Image private: /// Buffer for storing texture data. - Grid m_colors; + math::Grid m_colors; }; diff --git a/cece/render/ImageData.hpp b/include/cece/render/ImageData.hpp similarity index 96% rename from cece/render/ImageData.hpp rename to include/cece/render/ImageData.hpp index 08e7c83..2aec651 100644 --- a/cece/render/ImageData.hpp +++ b/include/cece/render/ImageData.hpp @@ -31,8 +31,8 @@ #include // CeCe -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Vector.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ @@ -48,7 +48,7 @@ struct ImageData { /// Image size. - Size size; + math::Size size; /// Image data. DynamicArray data; diff --git a/cece/render/Lines.hpp b/include/cece/render/Lines.hpp similarity index 96% rename from cece/render/Lines.hpp rename to include/cece/render/Lines.hpp index 6a56986..4ced719 100644 --- a/cece/render/Lines.hpp +++ b/include/cece/render/Lines.hpp @@ -28,9 +28,9 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" -#include "cece/core/Pair.hpp" -#include "cece/core/DynamicArray.hpp" +#include "cece/Pair.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/math/Vector.hpp" #include "cece/render/Buffer.hpp" /* ************************************************************************ */ @@ -56,7 +56,7 @@ class Lines /// Point type - using PointType = Vector; + using PointType = math::Vector; /// Line type. using LineType = Pair; diff --git a/cece/render/Object.hpp b/include/cece/render/Object.hpp similarity index 99% rename from cece/render/Object.hpp rename to include/cece/render/Object.hpp index 036ee5f..7414f2e 100644 --- a/cece/render/Object.hpp +++ b/include/cece/render/Object.hpp @@ -31,7 +31,7 @@ #include // CeCe -#include "cece/core/Assert.hpp" +#include "cece/Assert.hpp" #include "cece/render/Context.hpp" /* ************************************************************************ */ diff --git a/cece/render/OpenGL.hpp b/include/cece/render/OpenGL.hpp similarity index 100% rename from cece/render/OpenGL.hpp rename to include/cece/render/OpenGL.hpp diff --git a/cece/render/PhysicsDebugger.hpp b/include/cece/render/PhysicsDebugger.hpp similarity index 99% rename from cece/render/PhysicsDebugger.hpp rename to include/cece/render/PhysicsDebugger.hpp index d716891..e0c3205 100644 --- a/cece/render/PhysicsDebugger.hpp +++ b/include/cece/render/PhysicsDebugger.hpp @@ -27,8 +27,8 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" +// CeCe +#include "cece/common.hpp" /* ************************************************************************ */ diff --git a/cece/render/Program.hpp b/include/cece/render/Program.hpp similarity index 100% rename from cece/render/Program.hpp rename to include/cece/render/Program.hpp diff --git a/cece/render/Rectangle.hpp b/include/cece/render/Rectangle.hpp similarity index 100% rename from cece/render/Rectangle.hpp rename to include/cece/render/Rectangle.hpp diff --git a/cece/render/Shader.hpp b/include/cece/render/Shader.hpp similarity index 99% rename from cece/render/Shader.hpp rename to include/cece/render/Shader.hpp index 8b694c9..85e8b43 100644 --- a/cece/render/Shader.hpp +++ b/include/cece/render/Shader.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/StaticArray.hpp" +#include "cece/StaticArray.hpp" /* ************************************************************************ */ diff --git a/cece/render/State.hpp b/include/cece/render/State.hpp similarity index 99% rename from cece/render/State.hpp rename to include/cece/render/State.hpp index b68dffb..a0be5f6 100644 --- a/cece/render/State.hpp +++ b/include/cece/render/State.hpp @@ -31,7 +31,7 @@ #include // CeCe -#include "cece/core/Assert.hpp" +#include "cece/Assert.hpp" #include "cece/render/Context.hpp" /* ************************************************************************ */ diff --git a/cece/render/Texture.hpp b/include/cece/render/Texture.hpp similarity index 91% rename from cece/render/Texture.hpp rename to include/cece/render/Texture.hpp index 62920ee..be1667a 100644 --- a/cece/render/Texture.hpp +++ b/include/cece/render/Texture.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" #include "cece/render/Color.hpp" /* ************************************************************************ */ @@ -79,7 +79,7 @@ class Texture * @param color Initialization color. * @param filter Min/Mag filter. */ - Texture(Context& context, Size size, const Color& color = colors::BLACK, bool filter = true); + Texture(Context& context, math::Size size, const Color& color = colors::BLACK, bool filter = true); /** @@ -108,7 +108,7 @@ class Texture * * @return */ - const Size& getSize() const noexcept + const math::Size& getSize() const noexcept { return m_size; } @@ -144,7 +144,7 @@ class Texture * @param size Texture size. * @param color Initialization color. */ - void resize(Size size, const Color& color = colors::BLACK); + void resize(math::Size size, const Color& color = colors::BLACK); /** @@ -161,7 +161,7 @@ class Texture * @param size Texture size. * @param color Initialization color. */ - void create(Size size, const Color* colors); + void create(math::Size size, const Color* colors); /** @@ -170,7 +170,7 @@ class Texture * @param size Texture size. * @param colors Texture colors. */ - void createGray(Size size, const unsigned char* colors); + void createGray(math::Size size, const unsigned char* colors); // Private Data Members @@ -180,7 +180,7 @@ class Texture Id m_id = 0; /// Texture size. - Size m_size; + math::Size m_size; }; /* ************************************************************************ */ diff --git a/cece/render/VertexElement.hpp b/include/cece/render/VertexElement.hpp similarity index 100% rename from cece/render/VertexElement.hpp rename to include/cece/render/VertexElement.hpp diff --git a/cece/render/VertexFormat.hpp b/include/cece/render/VertexFormat.hpp similarity index 99% rename from cece/render/VertexFormat.hpp rename to include/cece/render/VertexFormat.hpp index 0a30745..6ce0890 100644 --- a/cece/render/VertexFormat.hpp +++ b/include/cece/render/VertexFormat.hpp @@ -28,7 +28,7 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/VertexElement.hpp" /* ************************************************************************ */ diff --git a/cece/render/datatype.hpp b/include/cece/render/datatype.hpp similarity index 100% rename from cece/render/datatype.hpp rename to include/cece/render/datatype.hpp diff --git a/cece/render/errors.hpp b/include/cece/render/errors.hpp similarity index 100% rename from cece/render/errors.hpp rename to include/cece/render/errors.hpp diff --git a/cece/render/fs.colormap.hpp b/include/cece/render/fs.colormap.hpp similarity index 100% rename from cece/render/fs.colormap.hpp rename to include/cece/render/fs.colormap.hpp diff --git a/cece/render/fs.smooth.hpp b/include/cece/render/fs.smooth.hpp similarity index 100% rename from cece/render/fs.smooth.hpp rename to include/cece/render/fs.smooth.hpp diff --git a/cece/render/glext.h b/include/cece/render/glext.h similarity index 100% rename from cece/render/glext.h rename to include/cece/render/glext.h diff --git a/cece/render/vs.colormap.hpp b/include/cece/render/vs.colormap.hpp similarity index 100% rename from cece/render/vs.colormap.hpp rename to include/cece/render/vs.colormap.hpp diff --git a/cece/render/vs.smooth.hpp b/include/cece/render/vs.smooth.hpp similarity index 100% rename from cece/render/vs.smooth.hpp rename to include/cece/render/vs.smooth.hpp diff --git a/cece/simulator/DefaultSimulation.hpp b/include/cece/simulation/DefaultSimulation.hpp similarity index 77% rename from cece/simulator/DefaultSimulation.hpp rename to include/cece/simulation/DefaultSimulation.hpp index e71d27d..0c81567 100644 --- a/cece/simulator/DefaultSimulation.hpp +++ b/include/cece/simulation/DefaultSimulation.hpp @@ -27,40 +27,36 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" - -/* ************************************************************************ */ - // C++ #include // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/UnitsCtors.hpp" -#include "cece/core/Vector.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/core/Parameters.hpp" -#include "cece/core/IterationType.hpp" +#include "cece/common.hpp" +#include "cece/String.hpp" +#include "cece/Map.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/Parameters.hpp" +#include "cece/math/Vector.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/UnitsCtors.hpp" +#include "cece/unit/VectorUnits.hpp" #include "cece/plugin/Context.hpp" -#include "cece/init/Container.hpp" -#include "cece/module/Container.hpp" -#include "cece/object/Container.hpp" -#include "cece/object/TypeContainer.hpp" -#include "cece/program/NamedContainer.hpp" -#include "cece/simulator/Simulation.hpp" +#include "cece/simulation/InitializerContainer.hpp" +#include "cece/simulation/ModuleContainer.hpp" +#include "cece/simulation/ObjectContainer.hpp" +#include "cece/simulation/ObjectTypeContainer.hpp" +#include "cece/simulation/ProgramNamedContainer.hpp" +#include "cece/simulation/IterationType.hpp" +#include "cece/simulation/Simulation.hpp" #ifdef CECE_RENDER -#include "cece/simulator/Visualization.hpp" +#include "cece/simulation/Visualization.hpp" #endif #ifdef CECE_THREAD_SAFE -#include "cece/core/Mutex.hpp" +#include "cece/async/Mutex.hpp" #endif /* ************************************************************************ */ @@ -68,7 +64,7 @@ namespace cece { namespace config { class Configuration; } namespace plugin { class Api; } - namespace plugin { class Repository; } + namespace plugin { class Manager; } } class b2World; @@ -76,7 +72,7 @@ class b2World; /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -93,10 +89,10 @@ class DefaultSimulation : public Simulation /** * @brief Constructor. * - * @param repository Plugin repository. - * @param path Path to simulation file. + * @param manager Plugin manager. + * @param path Path to simulation file. */ - explicit DefaultSimulation(const plugin::Repository& repository, FilePath path = "") noexcept; + explicit DefaultSimulation(const plugin::Manager& manager, io::FilePath path = "") noexcept; /** @@ -158,7 +154,7 @@ class DefaultSimulation : public Simulation * * @return */ - module::Container& getModuleContainer() noexcept + simulation::ModuleContainer& getModuleContainer() noexcept { return m_modules; } @@ -169,7 +165,7 @@ class DefaultSimulation : public Simulation * * @return */ - const module::Container& getModuleContainer() const noexcept + const simulation::ModuleContainer& getModuleContainer() const noexcept { return m_modules; } @@ -180,7 +176,7 @@ class DefaultSimulation : public Simulation * * @return */ - object::Container& getObjectContainer() noexcept + simulation::ObjectContainer& getObjectContainer() noexcept { return m_objects; } @@ -191,7 +187,7 @@ class DefaultSimulation : public Simulation * * @return */ - const object::Container& getObjectContainer() const noexcept + const simulation::ObjectContainer& getObjectContainer() const noexcept { return m_objects; } @@ -202,7 +198,7 @@ class DefaultSimulation : public Simulation * * @return */ - program::NamedContainer& getProgramContainer() noexcept + simulation::ProgramNamedContainer& getProgramContainer() noexcept { return m_programs; } @@ -213,7 +209,7 @@ class DefaultSimulation : public Simulation * * @return */ - const program::NamedContainer& getProgramContainer() const noexcept + const simulation::ProgramNamedContainer& getProgramContainer() const noexcept { return m_programs; } @@ -224,7 +220,7 @@ class DefaultSimulation : public Simulation * * @return */ - const FilePath& getFileName() const noexcept override + const io::FilePath& getFileName() const noexcept override { return m_fileName; } @@ -235,7 +231,7 @@ class DefaultSimulation : public Simulation * * @return */ - const units::SizeVector& getWorldSize() const noexcept override + const unit::SizeVector& getWorldSize() const noexcept override { return m_worldSize; } @@ -279,7 +275,7 @@ class DefaultSimulation : public Simulation * * @return */ - units::Time getTimeStep() const noexcept override + unit::Time getTimeStep() const noexcept override { return m_timeStep; } @@ -290,7 +286,7 @@ class DefaultSimulation : public Simulation * * @return */ - units::Time getTotalTime() const noexcept override + unit::Time getTotalTime() const noexcept override { return m_totalTime; } @@ -329,7 +325,7 @@ class DefaultSimulation : public Simulation * * @return Pointer to resource stream or nullptr. */ - UniquePtr getResource(StringView name) noexcept override; + UniquePtr getResource(StringView name) noexcept override; /** @@ -371,7 +367,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr getModule(StringView name) const noexcept override; + ViewPtr getModule(StringView name) const noexcept override; /** @@ -393,7 +389,7 @@ class DefaultSimulation : public Simulation * * @return Pointer to program. */ - UniquePtr getProgram(StringView name) const override; + UniquePtr getProgram(StringView name) const override; /** @@ -419,7 +415,7 @@ class DefaultSimulation : public Simulation * * @return */ - DynamicArray> getObjects() const noexcept override; + DynamicArray> getObjects() const noexcept override; /** @@ -429,7 +425,7 @@ class DefaultSimulation : public Simulation * * @return */ - DynamicArray> getObjects(StringView type) const noexcept override; + DynamicArray> getObjects(StringView type) const noexcept override; /** @@ -437,7 +433,7 @@ class DefaultSimulation : public Simulation * * @return */ - units::AccelerationVector getGravity() const noexcept; + unit::AccelerationVector getGravity() const noexcept; /** @@ -467,7 +463,7 @@ class DefaultSimulation : public Simulation * * @return */ - units::Time getPhysicsEngineTimeStep() const noexcept; + unit::Time getPhysicsEngineTimeStep() const noexcept; /** @@ -475,7 +471,7 @@ class DefaultSimulation : public Simulation * * @return */ - units::Length getMaxObjectTranslation() const noexcept; + unit::Length getMaxObjectTranslation() const noexcept; // Public Mutators @@ -517,7 +513,7 @@ class DefaultSimulation : public Simulation * * @param size Simulation world size. */ - void setWorldSize(units::SizeVector size) noexcept override + void setWorldSize(unit::SizeVector size) noexcept override { m_worldSize = std::move(size); } @@ -528,7 +524,7 @@ class DefaultSimulation : public Simulation * * @param dt Time step. */ - void setTimeStep(units::Time dt) override; + void setTimeStep(unit::Time dt) override; /** @@ -547,7 +543,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr addInitializer(UniquePtr initializer) override; + ViewPtr addInitializer(UniquePtr initializer) override; /** @@ -557,7 +553,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr createInitializer(StringView type) override; + ViewPtr createInitializer(StringView type) override; /** @@ -567,7 +563,7 @@ class DefaultSimulation : public Simulation * * @return */ - void deleteInitializer(ViewPtr initializer) override; + void deleteInitializer(ViewPtr initializer) override; /** @@ -578,7 +574,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr addModule(String name, UniquePtr module) override; + ViewPtr addModule(String name, UniquePtr module) override; /** @@ -588,7 +584,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr createModule(StringView type) override; + ViewPtr createModule(StringView type) override; /** @@ -618,7 +614,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr addObject(UniquePtr object) override; + ViewPtr addObject(UniquePtr object) override; /** @@ -628,7 +624,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr createObject(StringView type) override; + ViewPtr createObject(StringView type) override; /** @@ -639,7 +635,7 @@ class DefaultSimulation : public Simulation * @return Pointer to created object. * @deprecated */ - ViewPtr createObject(StringView type, object::Object::Type state) override; + ViewPtr createObject(StringView type, simulation::Object::Type state) override; /** @@ -647,7 +643,7 @@ class DefaultSimulation : public Simulation * * @param object Pointer to deleted object. */ - void deleteObject(ViewPtr object) override; + void deleteObject(ViewPtr object) override; /** @@ -658,7 +654,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr addProgram(String name, UniquePtr program) override; + ViewPtr addProgram(String name, UniquePtr program) override; /** @@ -669,7 +665,7 @@ class DefaultSimulation : public Simulation * * @return */ - ViewPtr createProgram(String name, StringView type) override; + ViewPtr createProgram(String name, StringView type) override; /** @@ -685,7 +681,7 @@ class DefaultSimulation : public Simulation * * @param gravity */ - void setGravity(const units::AccelerationVector& gravity) noexcept; + void setGravity(const unit::AccelerationVector& gravity) noexcept; /** @@ -693,7 +689,7 @@ class DefaultSimulation : public Simulation * * @param dt Time step. */ - void setPhysicsEngineTimeStep(units::Time dt) noexcept; + void setPhysicsEngineTimeStep(unit::Time dt) noexcept; /** @@ -701,7 +697,7 @@ class DefaultSimulation : public Simulation * * @param listener New listener. */ - void setContactListener(object::ContactListener* listener) override; + void setContactListener(simulation::ObjectContactListener* listener) override; // Public Operations @@ -729,7 +725,7 @@ class DefaultSimulation : public Simulation * * @param flag Initialization flag. */ - void initialize(AtomicBool& flag) override; + void initialize(async::AtomicBool& flag) override; /** @@ -790,11 +786,14 @@ class DefaultSimulation : public Simulation // Private Data Members private: + /// Plugin manager. + const plugin::Manager& m_pluginManager; + /// Simulation plugin context. plugin::Context m_pluginContext; /// Path of simulation file. - FilePath m_fileName; + io::FilePath m_fileName; /// If simulation is initialized. bool m_initialized = false; @@ -806,25 +805,25 @@ class DefaultSimulation : public Simulation IterationType m_iterations = 0; /// Simulation step. - units::Time m_timeStep = Zero; + unit::Time m_timeStep = math::Zero; /// Total simulation time. - units::Time m_totalTime = Zero; + unit::Time m_totalTime = math::Zero; /// World size. - units::SizeVector m_worldSize{ units::um(400), units::um(400) }; + unit::SizeVector m_worldSize{ unit::um(400), unit::um(400) }; /// Simulation parameters. Parameters m_parameters; /// A list of simulation initializers. - init::Container m_initializers; + simulation::InitializerContainer m_initializers; /// Simulation modules. - module::Container m_modules; + simulation::ModuleContainer m_modules; /// Registered object types. - object::TypeContainer m_objectTypes; + simulation::ObjectTypeContainer m_objectTypes; /// Box2D world UniquePtr m_world; @@ -834,10 +833,10 @@ class DefaultSimulation : public Simulation UniquePtr m_contactListener; /// Simulation objects. - object::Container m_objects; + simulation::ObjectContainer m_objects; /// A map of preddefined programs. - program::NamedContainer m_programs; + simulation::ProgramNamedContainer m_programs; #ifdef CECE_RENDER /// Simulation visualization. @@ -849,7 +848,7 @@ class DefaultSimulation : public Simulation #endif #ifdef CECE_THREAD_SAFE - Mutex m_mutex; + async::Mutex m_mutex; #endif }; diff --git a/cece/module/ExportModule.hpp b/include/cece/simulation/ExportModule.hpp similarity index 83% rename from cece/module/ExportModule.hpp rename to include/cece/simulation/ExportModule.hpp index bcbde58..804d0aa 100644 --- a/cece/module/ExportModule.hpp +++ b/include/cece/simulation/ExportModule.hpp @@ -31,33 +31,33 @@ #include // CeCe -#include "cece/core/String.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/CsvFile.hpp" -#include "cece/core/IterationRange.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/DataExport.hpp" -#include "cece/module/Module.hpp" +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/io/DataExport.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/CsvFile.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/IterationRange.hpp" /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ /** * @brief Helper module for exporting other module data. */ -class ExportModule : public module::Module +class ExportModule : public Module { // Public Ctors & Dtors public: - using module::Module::Module; + using Module::Module; // Public Accessors @@ -69,7 +69,7 @@ class ExportModule : public module::Module * * @return */ - const FilePath& getFilePath() const noexcept + const io::FilePath& getFilePath() const noexcept { return m_filePath; } @@ -80,7 +80,7 @@ class ExportModule : public module::Module * * @return */ - const DynamicArray& getActive() const noexcept + const DynamicArray& getActive() const noexcept { return m_active; } @@ -93,7 +93,7 @@ class ExportModule : public module::Module * * @return */ - bool isActive(IterationType it) const noexcept; + bool isActive(simulation::IterationType it) const noexcept; // Public Mutators @@ -105,7 +105,7 @@ class ExportModule : public module::Module * * @param filePath */ - void setFilePath(FilePath filePath) noexcept + void setFilePath(io::FilePath filePath) noexcept { m_filePath = std::move(filePath); } @@ -116,7 +116,7 @@ class ExportModule : public module::Module * * @param active */ - void setActive(DynamicArray active) noexcept + void setActive(DynamicArray active) noexcept { m_active = std::move(active); } @@ -198,20 +198,20 @@ class ExportModule : public module::Module * * @return */ - static DynamicArray parseActive(String str); + static DynamicArray parseActive(String str); // Protected Data Members protected: /// Data exporter. - UniquePtr m_export; + UniquePtr m_export; /// File path. - FilePath m_filePath; + io::FilePath m_filePath; /// When is export active. - DynamicArray m_active; + DynamicArray m_active; }; diff --git a/cece/init/Initializer.hpp b/include/cece/simulation/Initializer.hpp similarity index 90% rename from cece/init/Initializer.hpp rename to include/cece/simulation/Initializer.hpp index 13ef8ae..65bf5c7 100644 --- a/cece/init/Initializer.hpp +++ b/include/cece/simulation/Initializer.hpp @@ -27,13 +27,13 @@ /* ************************************************************************ */ -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Simulation; } } namespace cece { namespace config { class Configuration; } } /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ @@ -68,7 +68,7 @@ class Initializer * @param simulation Current simulation. * @param config Source configuration. */ - virtual void loadConfig(simulator::Simulation& simulation, const config::Configuration& config); + virtual void loadConfig(Simulation& simulation, const config::Configuration& config); /** @@ -77,7 +77,7 @@ class Initializer * @param simulation Current simulation. * @param config Output configuration. */ - virtual void storeConfig(const simulator::Simulation& simulation, config::Configuration& config) const; + virtual void storeConfig(const Simulation& simulation, config::Configuration& config) const; /** @@ -85,7 +85,7 @@ class Initializer * * @param simulation Simulation. */ - virtual void init(simulator::Simulation& simulation) const = 0; + virtual void init(Simulation& simulation) const = 0; }; diff --git a/cece/init/Container.hpp b/include/cece/simulation/InitializerContainer.hpp similarity index 89% rename from cece/init/Container.hpp rename to include/cece/simulation/InitializerContainer.hpp index eb278bb..3b1b428 100644 --- a/cece/init/Container.hpp +++ b/include/cece/simulation/InitializerContainer.hpp @@ -28,24 +28,24 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/PtrContainer.hpp" +#include "cece/PtrDynamicArray.hpp" /* ************************************************************************ */ -namespace cece { namespace simulator { class Simulation; } } -namespace cece { namespace init { class Initializer; } } +namespace cece { namespace simulation { class Simulation; } } +namespace cece { namespace simulation { class Initializer; } } /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ /** * @brief Container for initializers. */ -class Container : public PtrContainer +class InitializerContainer : public PtrDynamicArray { // Public Operations @@ -57,7 +57,7 @@ class Container : public PtrContainer * * @param simulation Simulation object. */ - void init(simulator::Simulation& simulation) const; + void init(Simulation& simulation) const; }; diff --git a/cece/init/Factory.hpp b/include/cece/simulation/InitializerFactory.hpp similarity index 94% rename from cece/init/Factory.hpp rename to include/cece/simulation/InitializerFactory.hpp index 9fc3787..6868237 100644 --- a/cece/init/Factory.hpp +++ b/include/cece/simulation/InitializerFactory.hpp @@ -29,12 +29,12 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/Factory.hpp" +#include "cece/factory/Factory.hpp" /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ @@ -45,7 +45,7 @@ class Initializer; /** * @brief Initializer factory interface. */ -using Factory = Factory; +using InitializerFactory = factory::Factory; /* ************************************************************************ */ @@ -54,6 +54,6 @@ using Factory = Factory; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(init::Initializer) +CECE_FACTORY_EXTERN(simulation::Initializer) /* ************************************************************************ */ diff --git a/cece/init/FactoryManager.hpp b/include/cece/simulation/InitializerFactoryManager.hpp similarity index 90% rename from cece/init/FactoryManager.hpp rename to include/cece/simulation/InitializerFactoryManager.hpp index 57b3115..a19cf79 100644 --- a/cece/init/FactoryManager.hpp +++ b/include/cece/simulation/InitializerFactoryManager.hpp @@ -28,16 +28,16 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FactoryManager.hpp" -#include "cece/init/Factory.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/factory/FactoryManager.hpp" +#include "cece/simulation/InitializerFactory.hpp" /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ @@ -48,7 +48,7 @@ class Initializer; /** * @brief Initializer factory manager. */ -class FactoryManager : public core::FactoryManager +class InitializerFactoryManager : public factory::FactoryManager { // Public Mutators @@ -63,7 +63,7 @@ class FactoryManager : public core::FactoryManager * @param name Factory name. */ template - void createForInitializer(String name) noexcept + void createForInitializer(String name) { createFor(std::move(name)); } diff --git a/cece/core/IterationRange.hpp b/include/cece/simulation/IterationRange.hpp similarity index 98% rename from cece/core/IterationRange.hpp rename to include/cece/simulation/IterationRange.hpp index 45d5a96..dc0476a 100644 --- a/cece/core/IterationRange.hpp +++ b/include/cece/simulation/IterationRange.hpp @@ -28,12 +28,12 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/IterationType.hpp" +#include "cece/simulation/IterationType.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace simulation { /* ************************************************************************ */ diff --git a/cece/core/IterationType.hpp b/include/cece/simulation/IterationType.hpp similarity index 99% rename from cece/core/IterationType.hpp rename to include/cece/simulation/IterationType.hpp index 34c099f..0bf251f 100644 --- a/cece/core/IterationType.hpp +++ b/include/cece/simulation/IterationType.hpp @@ -33,7 +33,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace simulation { /* ************************************************************************ */ diff --git a/cece/loader/Loader.hpp b/include/cece/simulation/Loader.hpp similarity index 77% rename from cece/loader/Loader.hpp rename to include/cece/simulation/Loader.hpp index 1132de5..d0a212b 100644 --- a/cece/loader/Loader.hpp +++ b/include/cece/simulation/Loader.hpp @@ -28,25 +28,25 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/ViewPtr.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/core/String.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/String.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ namespace cece { - inline namespace core { class Parameters; } - namespace simulator { class Simulation; } - namespace plugin { class Repository; } + class Parameters; + namespace simulation { class Simulation; } + namespace plugin { class Manager; } } /* ************************************************************************ */ namespace cece { -namespace loader { +namespace simulation { /* ************************************************************************ */ @@ -82,8 +82,8 @@ class Loader * * @return Pointer to created simulation. */ - virtual UniquePtr fromFile( - const plugin::Repository& repository, const FilePath& filename, + virtual UniquePtr fromFile( + const plugin::Manager& manager, const io::FilePath& filename, ViewPtr parameters = nullptr) const; @@ -95,9 +95,9 @@ class Loader * * @return Pointer to created simulation. */ - virtual UniquePtr fromSource( - const plugin::Repository& repository, - const String& source, const FilePath& filename = "", + virtual UniquePtr fromSource( + const plugin::Manager& manager, + const String& source, const io::FilePath& filename = "", ViewPtr parameters = nullptr) const; @@ -107,8 +107,7 @@ class Loader * @param simulation Source simulation. * @param filename Path to source file. */ - virtual void toFile(const simulator::Simulation& simulation, - const FilePath& filename) const; + virtual void toFile(const Simulation& simulation, const io::FilePath& filename) const; /** @@ -118,8 +117,7 @@ class Loader * * @return Source code. */ - virtual String toSource(const simulator::Simulation& simulation, - const FilePath& filename = "") const; + virtual String toSource(const Simulation& simulation, const io::FilePath& filename = "") const; /** @@ -132,9 +130,9 @@ class Loader * * @return Created simulation. */ - virtual UniquePtr fromStream( - const plugin::Repository& repository, InStream& is, - const FilePath& filename = "", + virtual UniquePtr fromStream( + const plugin::Manager& manager, io::InStream& is, + const io::FilePath& filename = "", ViewPtr parameters = nullptr) const = 0; @@ -144,8 +142,8 @@ class Loader * @param os Output stream. * @param simulation Source simulation. */ - virtual void toStream(OutStream& os, const simulator::Simulation& simulation, - const FilePath& filename = "") const = 0; + virtual void toStream(io::OutStream& os, const Simulation& simulation, + const io::FilePath& filename = "") const = 0; }; diff --git a/cece/loader/Factory.hpp b/include/cece/simulation/LoaderFactory.hpp similarity index 94% rename from cece/loader/Factory.hpp rename to include/cece/simulation/LoaderFactory.hpp index 6da84c2..544f270 100644 --- a/cece/loader/Factory.hpp +++ b/include/cece/simulation/LoaderFactory.hpp @@ -29,12 +29,12 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/Factory.hpp" +#include "cece/factory/Factory.hpp" /* ************************************************************************ */ namespace cece { -namespace loader { +namespace simulation { /* ************************************************************************ */ @@ -45,7 +45,7 @@ class Loader; /** * @brief Simulation loader factory interface. */ -using Factory = core::Factory; +using LoaderFactory = factory::Factory; /* ************************************************************************ */ @@ -54,6 +54,6 @@ using Factory = core::Factory; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(loader::Loader) +CECE_FACTORY_EXTERN(simulation::Loader) /* ************************************************************************ */ diff --git a/cece/loader/FactoryManager.hpp b/include/cece/simulation/LoaderFactoryManager.hpp similarity index 88% rename from cece/loader/FactoryManager.hpp rename to include/cece/simulation/LoaderFactoryManager.hpp index 326df78..ff1e8d4 100644 --- a/cece/loader/FactoryManager.hpp +++ b/include/cece/simulation/LoaderFactoryManager.hpp @@ -28,16 +28,16 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FactoryManager.hpp" -#include "cece/loader/Factory.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/factory/FactoryManager.hpp" +#include "cece/simulation/LoaderFactory.hpp" /* ************************************************************************ */ namespace cece { -namespace loader { +namespace simulation { /* ************************************************************************ */ @@ -48,7 +48,7 @@ class Loader; /** * @brief Loader factory manager. */ -class FactoryManager : public core::FactoryManager +class LoaderFactoryManager : public factory::FactoryManager { // Public Mutators @@ -63,9 +63,9 @@ class FactoryManager : public core::FactoryManager * @param name Factory name. */ template - void createForLoader(String name) noexcept + void createForLoader(String name) { - create>(std::move(name)); + create>(std::move(name)); } diff --git a/cece/module/Module.hpp b/include/cece/simulation/Module.hpp similarity index 91% rename from cece/module/Module.hpp rename to include/cece/simulation/Module.hpp index 456e87d..f9d3a7b 100644 --- a/cece/module/Module.hpp +++ b/include/cece/simulation/Module.hpp @@ -27,30 +27,26 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" - -/* ************************************************************************ */ - // CeCe +#include "cece/common.hpp" #include "cece/export.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/Atomic.hpp" +#include "cece/async/Atomic.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Simulation; } } namespace cece { namespace config { class Configuration; } } #ifdef CECE_RENDER namespace cece { namespace render { class Context; } } -namespace cece { namespace simulator { class Visualization; } } +namespace cece { namespace simulation { class Visualization; } } #endif /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ @@ -110,7 +106,7 @@ class Module * * @param simulation */ - explicit Module(simulator::Simulation& simulation); + explicit Module(simulation::Simulation& simulation); /** @@ -128,7 +124,7 @@ class Module * * @return */ - simulator::Simulation& getSimulation() const noexcept + simulation::Simulation& getSimulation() const noexcept { return m_simulation; } @@ -216,7 +212,7 @@ class Module * @param flag Continuation flag. If initialization is expensive it should * test this variable in case a termination request is sent. */ - virtual void init(AtomicBool& flag); + virtual void init(async::AtomicBool& flag); /** @@ -244,7 +240,7 @@ class Module * @param visualization Visualization context. * @param context Rendering context. */ - virtual void draw(const simulator::Visualization& visualization, render::Context& context); + virtual void draw(const simulation::Visualization& visualization, render::Context& context); /** @@ -264,7 +260,7 @@ class Module * call and are used for rendering. * @param visualization Visualization context. */ - virtual void drawStoreState(const simulator::Visualization& visualization); + virtual void drawStoreState(const simulation::Visualization& visualization); /** @@ -292,7 +288,7 @@ class Module private: /// Simulation reference. - simulator::Simulation& m_simulation; + simulation::Simulation& m_simulation; /// Module update priority. PriorityType m_priority = 0; diff --git a/cece/module/Container.hpp b/include/cece/simulation/ModuleContainer.hpp similarity index 89% rename from cece/module/Container.hpp rename to include/cece/simulation/ModuleContainer.hpp index d1f6f5d..bcb992d 100644 --- a/cece/module/Container.hpp +++ b/include/cece/simulation/ModuleContainer.hpp @@ -28,11 +28,11 @@ /* ************************************************************************ */ // CeCe -#include "cece/config.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Atomic.hpp" -#include "cece/core/PtrNamedContainer.hpp" +#include "cece/common.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/PtrStringMap.hpp" +#include "cece/async/Atomic.hpp" #ifdef CECE_RENDER #include "cece/render/State.hpp" @@ -42,13 +42,13 @@ #ifdef CECE_RENDER namespace cece { namespace render { class Context; } } -namespace cece { namespace simulator { class Visualization; } } +namespace cece { namespace simulation { class Visualization; } } #endif /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ @@ -61,7 +61,7 @@ class Module; * * @todo Cache sorted list of modules. */ -class Container : public PtrNamedContainer +class ModuleContainer : public PtrStringMap { // Public Operations @@ -73,7 +73,7 @@ class Container : public PtrNamedContainer * * @param flag Continuation flag. */ - void init(AtomicBool& flag); + void init(async::AtomicBool& flag); /** @@ -95,14 +95,14 @@ class Container : public PtrNamedContainer * @param visualization Visualization context. * @param context Rendering context. */ - void draw(const simulator::Visualization& visualization, render::Context& context); + void draw(const simulation::Visualization& visualization, render::Context& context); /** * @brief Store modules drawing state. * @param visualization Visualization context. */ - void drawStoreState(const simulator::Visualization& visualization); + void drawStoreState(const simulation::Visualization& visualization); /** diff --git a/include/cece/simulation/ModuleFactory.hpp b/include/cece/simulation/ModuleFactory.hpp new file mode 100644 index 0000000..f6f2978 --- /dev/null +++ b/include/cece/simulation/ModuleFactory.hpp @@ -0,0 +1,60 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/export.hpp" +#include "cece/factory/Factory.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +class Module; +class Simulation; + +/* ************************************************************************ */ + +/** + * @brief Module factory interface. + */ +using ModuleFactory = factory::Factory; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ + +CECE_FACTORY_EXTERN(simulation::Module, simulation::Simulation&) + +/* ************************************************************************ */ diff --git a/cece/module/FactoryManager.hpp b/include/cece/simulation/ModuleFactoryManager.hpp similarity index 83% rename from cece/module/FactoryManager.hpp rename to include/cece/simulation/ModuleFactoryManager.hpp index 51dd76c..9b1a6eb 100644 --- a/cece/module/FactoryManager.hpp +++ b/include/cece/simulation/ModuleFactoryManager.hpp @@ -29,31 +29,28 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FactoryManager.hpp" -#include "cece/module/Factory.hpp" - -/* ************************************************************************ */ - -namespace cece { namespace simulator { class Simulation; } } +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/factory/FactoryManager.hpp" +#include "cece/simulation/ModuleFactory.hpp" /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ class Module; +class Simulation; /* ************************************************************************ */ /** * @brief Module factory manager. */ -class FactoryManager : public core::FactoryManager +class ModuleFactoryManager : public factory::FactoryManager { // Public Mutators @@ -66,9 +63,9 @@ class FactoryManager : public core::FactoryManager * @param name Factory name. */ template - void createForModule(String name) noexcept + void createForModule(String name) { - create>(std::move(name)); + create>(std::move(name)); } @@ -86,7 +83,7 @@ class FactoryManager : public core::FactoryManager * * @throw FactoryNotFoundException In case of factory with given name doesn't exists. */ - UniquePtr createModule(StringView name, simulator::Simulation& simulation) const; + UniquePtr createModule(StringView name, simulation::Simulation& simulation) const; }; diff --git a/cece/object/Object.hpp b/include/cece/simulation/Object.hpp similarity index 80% rename from cece/object/Object.hpp rename to include/cece/simulation/Object.hpp index 887794c..c5bc45b 100644 --- a/cece/object/Object.hpp +++ b/include/cece/simulation/Object.hpp @@ -31,23 +31,23 @@ #include // CeCe -#include "cece/config.hpp" -#include "cece/core/Assert.hpp" -#include "cece/core/SharedPtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/InStream.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/Shape.hpp" -#include "cece/core/Exception.hpp" -#include "cece/program/Program.hpp" -#include "cece/program/Container.hpp" -#include "cece/object/BoundData.hpp" +#include "cece/common.hpp" +#include "cece/Assert.hpp" +#include "cece/SharedPtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/Map.hpp" +#include "cece/StringView.hpp" +#include "cece/Exception.hpp" +#include "cece/math/Shape.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/VectorUnits.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/simulation/ProgramContainer.hpp" +#include "cece/simulation/ObjectBoundData.hpp" #ifdef CECE_RENDER # include "cece/render/Color.hpp" @@ -62,14 +62,14 @@ class b2Joint; namespace cece { namespace config { class Configuration; } - namespace simulator { class Simulation; } - namespace simulator { class Visualization; } + namespace simulation { class Simulation; } + namespace simulation { class Visualization; } } /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ @@ -115,7 +115,7 @@ class Object ViewPtr joint; /// Bound data - SharedPtr data; + SharedPtr data; }; @@ -138,7 +138,7 @@ class Object * @param typeName Type name of the object. * @param type Object type. */ - explicit Object(simulator::Simulation& simulation, String typeName = "simulator.Object", Type type = Type::Static) noexcept; + explicit Object(simulation::Simulation& simulation, String typeName = "simulation.Object", Type type = Type::Static) noexcept; /** @@ -178,7 +178,7 @@ class Object * * @return */ - simulator::Simulation& getSimulation() noexcept + simulation::Simulation& getSimulation() noexcept { return m_simulation; } @@ -189,7 +189,7 @@ class Object * * @return */ - const simulator::Simulation& getSimulation() const noexcept + const simulation::Simulation& getSimulation() const noexcept { return m_simulation; } @@ -248,7 +248,7 @@ class Object * * @return */ - units::Density getDensity() const noexcept + unit::Density getDensity() const noexcept { return m_density; } @@ -259,7 +259,7 @@ class Object * * @return */ - units::PositionVector getPosition() const noexcept; + unit::PositionVector getPosition() const noexcept; /** @@ -267,7 +267,7 @@ class Object * * @return */ - units::PositionVector getMassCenterPosition() const noexcept; + unit::PositionVector getMassCenterPosition() const noexcept; /** @@ -275,7 +275,7 @@ class Object * * @return */ - units::PositionVector getMassCenterOffset() const noexcept; + unit::PositionVector getMassCenterOffset() const noexcept; /** @@ -285,7 +285,7 @@ class Object * * @return */ - units::PositionVector getWorldPosition(units::PositionVector local) const noexcept; + unit::PositionVector getWorldPosition(unit::PositionVector local) const noexcept; /** @@ -293,7 +293,7 @@ class Object * * @return */ - units::Angle getRotation() const noexcept; + unit::Angle getRotation() const noexcept; /** @@ -301,7 +301,7 @@ class Object * * @return */ - units::VelocityVector getVelocity() const noexcept; + unit::VelocityVector getVelocity() const noexcept; /** @@ -309,7 +309,7 @@ class Object * * @return */ - units::AngularVelocity getAngularVelocity() const noexcept; + unit::AngularVelocity getAngularVelocity() const noexcept; /** @@ -317,7 +317,7 @@ class Object * * @return */ - const units::ForceVector& getForce() const noexcept + const unit::ForceVector& getForce() const noexcept { return m_force; } @@ -328,7 +328,7 @@ class Object * * @return */ - units::Mass getMass() const noexcept; + unit::Mass getMass() const noexcept; /** @@ -347,7 +347,7 @@ class Object * * @return */ - const DynamicArray& getShapes() const noexcept + const DynamicArray& getShapes() const noexcept { return m_shapes; } @@ -362,7 +362,7 @@ class Object * * @return */ - DynamicArray& getMutableShapes() noexcept + DynamicArray& getMutableShapes() noexcept { return m_shapes; } @@ -373,7 +373,7 @@ class Object * * @return */ - const program::Container& getPrograms() const noexcept + const simulation::ProgramContainer& getPrograms() const noexcept { return m_programs; } @@ -384,7 +384,7 @@ class Object * * @return */ - units::Length getMaxTranslation() const noexcept; + unit::Length getMaxTranslation() const noexcept; /** @@ -460,7 +460,7 @@ class Object * * @param density New density value. */ - void setDensity(units::Density density) noexcept + void setDensity(unit::Density density) noexcept { m_density = density; } @@ -471,7 +471,7 @@ class Object * * @param pos */ - void setPosition(units::PositionVector pos) noexcept; + void setPosition(unit::PositionVector pos) noexcept; /** @@ -479,7 +479,7 @@ class Object * * @param angle */ - void setRotation(units::Angle angle) noexcept; + void setRotation(unit::Angle angle) noexcept; /** @@ -487,7 +487,7 @@ class Object * * @param vel */ - void setVelocity(units::VelocityVector vel) noexcept; + void setVelocity(unit::VelocityVector vel) noexcept; /** @@ -495,7 +495,7 @@ class Object * * @param vel */ - void setAngularVelocity(units::AngularVelocity vel) noexcept; + void setAngularVelocity(unit::AngularVelocity vel) noexcept; /** @@ -503,7 +503,7 @@ class Object * * @param force */ - void setForce(units::ForceVector force) noexcept + void setForce(unit::ForceVector force) noexcept { m_force = std::move(force); } @@ -514,7 +514,7 @@ class Object * * @param force */ - void applyForce(const units::ForceVector& force) noexcept; + void applyForce(const unit::ForceVector& force) noexcept; /** @@ -523,7 +523,7 @@ class Object * @param force * @param offset Local offset. */ - void applyForce(const units::ForceVector& force, const units::PositionVector& offset) noexcept; + void applyForce(const unit::ForceVector& force, const unit::PositionVector& offset) noexcept; /** @@ -531,7 +531,7 @@ class Object * * @param impulse */ - void applyLinearImpulse(const units::ImpulseVector& impulse) noexcept + void applyLinearImpulse(const unit::ImpulseVector& impulse) noexcept { applyLinearImpulse(impulse, getMassCenterOffset()); } @@ -543,7 +543,7 @@ class Object * @param impulse * @param offset Local offset. */ - void applyLinearImpulse(const units::ImpulseVector& impulse, const units::PositionVector& offset) noexcept; + void applyLinearImpulse(const unit::ImpulseVector& impulse, const unit::PositionVector& offset) noexcept; /** @@ -551,7 +551,7 @@ class Object * * @param impulse */ - void applyAngularImpulse(const units::Impulse& impulse) noexcept; + void applyAngularImpulse(const unit::Impulse& impulse) noexcept; /** @@ -559,7 +559,7 @@ class Object * * @param shapes */ - void setShapes(DynamicArray shapes) noexcept + void setShapes(DynamicArray shapes) noexcept { m_shapes = std::move(shapes); } @@ -570,7 +570,7 @@ class Object * * @param programs */ - void setPrograms(program::Container programs) noexcept + void setPrograms(simulation::ProgramContainer programs) noexcept { m_programs = std::move(programs); } @@ -581,7 +581,7 @@ class Object * * @param program */ - void addProgram(UniquePtr program) noexcept + void addProgram(UniquePtr program) noexcept { // Store program and init m_programs.add(std::move(program))->init(getSimulation(), *this); @@ -698,7 +698,7 @@ class Object * @param other The other object. * @param data Optional bind data. */ - void createBound(Object& other, UniquePtr data = {}); + void createBound(Object& other, UniquePtr data = {}); /** @@ -713,7 +713,7 @@ class Object * * @param dt Simulation time step. */ - virtual void update(units::Duration dt); + virtual void update(unit::Time dt); /** @@ -722,7 +722,7 @@ class Object * @param config * @param simulation */ - virtual void configure(const config::Configuration& config, simulator::Simulation& simulation); + virtual void configure(const config::Configuration& config, simulation::Simulation& simulation); /** @@ -738,7 +738,7 @@ class Object * @param visualization Visualization context. * @param context Render context. */ - virtual void draw(const simulator::Visualization& visualization, render::Context& context); + virtual void draw(const simulation::Visualization& visualization, render::Context& context); /** @@ -756,7 +756,7 @@ class Object * call and are used for rendering. * @param visualization Visualization context. */ - virtual void drawStoreState(const simulator::Visualization& visualization); + virtual void drawStoreState(const simulation::Visualization& visualization); /** @@ -784,7 +784,7 @@ class Object private: /// Owning simulation. - simulator::Simulation& m_simulation; + simulation::Simulation& m_simulation; /// Object real type name. String m_realTypeName; @@ -796,13 +796,13 @@ class Object IdType m_id; /// A list of object shapes. - DynamicArray m_shapes; + DynamicArray m_shapes; /// Registered object programs. - program::Container m_programs; + simulation::ProgramContainer m_programs; /// Object density. - units::Density m_density = units::Density(1); // FIXME: use better value + unit::Density m_density = unit::Density(1); // FIXME: use better value /// Object type. Type m_type; @@ -833,10 +833,10 @@ class Object DynamicArray> m_bodyShapes; /// Box2D doesn't have accessor to force. - units::ForceVector m_force; + unit::ForceVector m_force; /// Outstream for object data - UniquePtr m_dataOut; + UniquePtr m_dataOut; }; @@ -850,17 +850,17 @@ class Object * * @return is. */ -inline InStream& operator>>(InStream& is, Object::Type& type) +inline io::InStream& operator>>(io::InStream& is, Object::Type& type) { String value; is >> value; if (value == "static") - type = object::Object::Type::Static; + type = simulation::Object::Type::Static; else if (value == "pinned") - type = object::Object::Type::Pinned; + type = simulation::Object::Type::Pinned; else - type = object::Object::Type::Dynamic; // Default + type = simulation::Object::Type::Dynamic; // Default return is; } diff --git a/include/cece/simulation/ObjectBoundData.hpp b/include/cece/simulation/ObjectBoundData.hpp new file mode 100644 index 0000000..613534f --- /dev/null +++ b/include/cece/simulation/ObjectBoundData.hpp @@ -0,0 +1,57 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +/** + * @brief Bound data. + */ +class ObjectBoundData +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Destructor. + */ + virtual ~ObjectBoundData(); + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/simulation/ObjectContactListener.hpp b/include/cece/simulation/ObjectContactListener.hpp new file mode 100644 index 0000000..001afc9 --- /dev/null +++ b/include/cece/simulation/ObjectContactListener.hpp @@ -0,0 +1,74 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +class Object; + +/* ************************************************************************ */ + +/** + * @brief Object contact listener. + */ +class ObjectContactListener +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Destructor. + */ + virtual ~ObjectContactListener() = 0; + + +// Public Operations +public: + + + /** + * @brief When two objects contact. + * + * @param o1 The first object. + * @param o2 The second object. + */ + virtual void onContact(Object& o1, Object& o2) = 0; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/Container.hpp b/include/cece/simulation/ObjectContainer.hpp similarity index 96% rename from cece/object/Container.hpp rename to include/cece/simulation/ObjectContainer.hpp index 6dee54a..8aa36e0 100644 --- a/cece/object/Container.hpp +++ b/include/cece/simulation/ObjectContainer.hpp @@ -28,12 +28,12 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/Pair.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/object/Object.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/Pair.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/simulation/Object.hpp" #ifdef CECE_RENDER #include "cece/render/State.hpp" @@ -48,14 +48,14 @@ namespace core { namespace render { class Context; } } /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ /** * @brief Container for objects. */ -class Container +class ObjectContainer { // Public Structures @@ -348,7 +348,7 @@ class Container * @brief Store objects drawing state. * @param visualization Visualization context. */ - void drawStoreState(const simulator::Visualization& visualization); + void drawStoreState(const simulation::Visualization& visualization); /** diff --git a/cece/object/Factory.hpp b/include/cece/simulation/ObjectFactory.hpp similarity index 87% rename from cece/object/Factory.hpp rename to include/cece/simulation/ObjectFactory.hpp index 2f3f196..75b54dd 100644 --- a/cece/object/Factory.hpp +++ b/include/cece/simulation/ObjectFactory.hpp @@ -29,18 +29,18 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/Factory.hpp" -#include "cece/core/String.hpp" -#include "cece/object/Object.hpp" +#include "cece/String.hpp" +#include "cece/factory/Factory.hpp" +#include "cece/simulation/Object.hpp" /* ************************************************************************ */ -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Simulation; } } /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ @@ -51,7 +51,7 @@ namespace object { /** * @brief Object factory interface. */ -using Factory = Factory; +using ObjectFactory = factory::Factory; /* ************************************************************************ */ @@ -60,6 +60,6 @@ using Factory = Factory; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(object::Object, simulator::Simulation&, String, object::Object::Type) +CECE_FACTORY_EXTERN(simulation::Object, simulation::Simulation&, String, simulation::Object::Type) /* ************************************************************************ */ diff --git a/cece/object/FactoryManager.hpp b/include/cece/simulation/ObjectFactoryManager.hpp similarity index 86% rename from cece/object/FactoryManager.hpp rename to include/cece/simulation/ObjectFactoryManager.hpp index d988782..199e4fb 100644 --- a/cece/object/FactoryManager.hpp +++ b/include/cece/simulation/ObjectFactoryManager.hpp @@ -28,20 +28,20 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FactoryManager.hpp" -#include "cece/object/Factory.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/factory/FactoryManager.hpp" +#include "cece/simulation/ObjectFactory.hpp" /* ************************************************************************ */ -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Simulation; } } /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ @@ -52,7 +52,7 @@ class Object; /** * @brief Object factory manager. */ -class FactoryManager : public core::FactoryManager +class ObjectFactoryManager : public factory::FactoryManager { // Public Operations @@ -70,7 +70,7 @@ class FactoryManager : public core::FactoryManager * * @throw ObjectFactoryNotFoundException In case of factory with given name doesn't exists. */ - UniquePtr createObject(StringView name, simulator::Simulation& simulation, Object::Type type) const; + UniquePtr createObject(StringView name, simulation::Simulation& simulation, Object::Type type) const; }; diff --git a/include/cece/simulation/ObjectType.hpp b/include/cece/simulation/ObjectType.hpp new file mode 100644 index 0000000..9202e06 --- /dev/null +++ b/include/cece/simulation/ObjectType.hpp @@ -0,0 +1,67 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/config/Configuration.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +/** + * @brief Defines user defined object type. + */ +class ObjectType +{ + +// Public Data Members +public: + + + /// Object type name. + String name; + + /// Basename type name. + String baseName; + + /// Object configuration. + config::Configuration config; + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/TypeContainer.hpp b/include/cece/simulation/ObjectTypeContainer.hpp similarity index 83% rename from cece/object/TypeContainer.hpp rename to include/cece/simulation/ObjectTypeContainer.hpp index 1646eb3..049e910 100644 --- a/cece/object/TypeContainer.hpp +++ b/include/cece/simulation/ObjectTypeContainer.hpp @@ -28,25 +28,25 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/Pair.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/object/Type.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/Pair.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/simulation/ObjectType.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ /** * @brief Container for object types. */ -class TypeContainer +class ObjectTypeContainer { @@ -71,7 +71,7 @@ class TypeContainer * * @return Pointer to object type. Can be nullptr. */ - ViewPtr get(StringView name) const noexcept; + ViewPtr get(StringView name) const noexcept; /** @@ -79,7 +79,7 @@ class TypeContainer * * @return */ - DynamicArray::const_iterator begin() const noexcept + DynamicArray::const_iterator begin() const noexcept { return m_types.begin(); } @@ -90,7 +90,7 @@ class TypeContainer * * @return */ - DynamicArray::const_iterator cbegin() const noexcept + DynamicArray::const_iterator cbegin() const noexcept { return m_types.cbegin(); } @@ -101,7 +101,7 @@ class TypeContainer * * @return */ - DynamicArray::const_iterator end() const noexcept + DynamicArray::const_iterator end() const noexcept { return m_types.end(); } @@ -112,7 +112,7 @@ class TypeContainer * * @return */ - DynamicArray::const_iterator cend() const noexcept + DynamicArray::const_iterator cend() const noexcept { return m_types.cend(); } @@ -127,14 +127,14 @@ class TypeContainer * * @param type Object type. */ - void add(Type type); + void add(ObjectType type); // Private Data Members private: /// Stored types. - DynamicArray m_types; + DynamicArray m_types; }; diff --git a/cece/program/Program.hpp b/include/cece/simulation/Program.hpp similarity index 85% rename from cece/program/Program.hpp rename to include/cece/simulation/Program.hpp index a2364b5..48fd48f 100644 --- a/cece/program/Program.hpp +++ b/include/cece/simulation/Program.hpp @@ -28,19 +28,19 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/UniquePtr.hpp" -#include "cece/core/Units.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ -namespace cece { namespace object { class Object; } } namespace cece { namespace config { class Configuration; } } -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Object; } } +namespace cece { namespace simulation { class Simulation; } } /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ @@ -83,7 +83,7 @@ class Program * @param simulation Current simulation. * @param config Source configuration. */ - virtual void loadConfig(simulator::Simulation& simulation, const config::Configuration& config) + virtual void loadConfig(simulation::Simulation& simulation, const config::Configuration& config) { // Nothing to do } @@ -95,7 +95,7 @@ class Program * @param simulation Current simulation. * @param config Output configuration. */ - virtual void storeConfig(const simulator::Simulation& simulation, config::Configuration& config) const + virtual void storeConfig(const simulation::Simulation& simulation, config::Configuration& config) const { // Nothing to do } @@ -107,7 +107,7 @@ class Program * @param simulation Simulation object. * @param object Object. */ - virtual void init(simulator::Simulation& simulation, object::Object& object) + virtual void init(simulation::Simulation& simulation, simulation::Object& object) { // Nothing to do } @@ -120,7 +120,7 @@ class Program * @param object Object. * @param dt Simulation time step. */ - virtual void call(simulator::Simulation& simulation, object::Object& object, units::Time dt) = 0; + virtual void call(simulation::Simulation& simulation, simulation::Object& object, unit::Time dt) = 0; /** @@ -129,7 +129,7 @@ class Program * @param simulation Simulation object. * @param object Object. */ - virtual void terminate(simulator::Simulation& simulation, object::Object& object) + virtual void terminate(simulation::Simulation& simulation, simulation::Object& object) { // Nothing to do } diff --git a/cece/program/Container.hpp b/include/cece/simulation/ProgramContainer.hpp similarity index 87% rename from cece/program/Container.hpp rename to include/cece/simulation/ProgramContainer.hpp index b6f6903..21c30b4 100644 --- a/cece/program/Container.hpp +++ b/include/cece/simulation/ProgramContainer.hpp @@ -28,18 +28,18 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/PtrContainer.hpp" +#include "cece/PtrDynamicArray.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ -namespace cece { namespace object { class Object; } } -namespace cece { namespace simulator { class Simulation; } } +namespace cece { namespace simulation { class Object; } } +namespace cece { namespace simulation { class Simulation; } } /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ @@ -50,7 +50,7 @@ class Program; /** * @brief Container for programs. */ -class Container : public PtrContainer +class ProgramContainer : public PtrDynamicArray { // Public Operations @@ -64,7 +64,7 @@ class Container : public PtrContainer * @param object Object. * @param dt Simulation time step. */ - void call(simulator::Simulation& simulation, object::Object& object, units::Time dt); + void call(simulation::Simulation& simulation, simulation::Object& object, unit::Time dt); /** @@ -72,7 +72,7 @@ class Container : public PtrContainer * * @return */ - Container clone() const; + ProgramContainer clone() const; }; diff --git a/cece/program/Factory.hpp b/include/cece/simulation/ProgramFactory.hpp similarity index 94% rename from cece/program/Factory.hpp rename to include/cece/simulation/ProgramFactory.hpp index 485b103..9f3d266 100644 --- a/cece/program/Factory.hpp +++ b/include/cece/simulation/ProgramFactory.hpp @@ -29,12 +29,12 @@ // CeCe #include "cece/export.hpp" -#include "cece/core/Factory.hpp" +#include "cece/factory/Factory.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ @@ -45,7 +45,7 @@ class Program; /** * @brief Program factory interface. */ -using Factory = Factory; +using ProgramFactory = factory::Factory; /* ************************************************************************ */ @@ -54,6 +54,6 @@ using Factory = Factory; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(program::Program) +CECE_FACTORY_EXTERN(simulation::Program) /* ************************************************************************ */ diff --git a/cece/program/FactoryManager.hpp b/include/cece/simulation/ProgramFactoryManager.hpp similarity index 91% rename from cece/program/FactoryManager.hpp rename to include/cece/simulation/ProgramFactoryManager.hpp index de56290..2f8c26b 100644 --- a/cece/program/FactoryManager.hpp +++ b/include/cece/simulation/ProgramFactoryManager.hpp @@ -28,16 +28,16 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/FactoryManager.hpp" -#include "cece/program/Factory.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/factory/FactoryManager.hpp" +#include "cece/simulation/ProgramFactory.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ @@ -48,7 +48,7 @@ class Program; /** * @brief Program factory manager. */ -class FactoryManager : public core::FactoryManager +class ProgramFactoryManager : public factory::FactoryManager { // Public Operations diff --git a/include/cece/simulation/ProgramNamedContainer.hpp b/include/cece/simulation/ProgramNamedContainer.hpp new file mode 100644 index 0000000..e725cbc --- /dev/null +++ b/include/cece/simulation/ProgramNamedContainer.hpp @@ -0,0 +1,57 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/PtrStringMap.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +class Program; + +/* ************************************************************************ */ + +/** + * @brief Container for named programs. + */ +class ProgramNamedContainer : public PtrStringMap +{ + +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/simulator/Simulation.hpp b/include/cece/simulation/Simulation.hpp similarity index 82% rename from cece/simulator/Simulation.hpp rename to include/cece/simulation/Simulation.hpp index efe0a61..7ebf58a 100644 --- a/cece/simulator/Simulation.hpp +++ b/include/cece/simulation/Simulation.hpp @@ -28,40 +28,40 @@ /* ************************************************************************ */ // CeCe -#include "cece/config.hpp" -#include "cece/core/Atomic.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/Vector.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/UniquePtr.hpp" -#include "cece/core/ViewPtr.hpp" -#include "cece/core/FilePath.hpp" -#include "cece/core/InOutStream.hpp" -#include "cece/core/IterationType.hpp" +#include "cece/common.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/math/Vector.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/VectorUnits.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/InOutStream.hpp" +#include "cece/async/Atomic.hpp" +#include "cece/simulation/IterationType.hpp" /// @deprecated -#include "cece/object/Object.hpp" +#include "cece/simulation/Object.hpp" /* ************************************************************************ */ namespace cece { /// @deprecated - inline namespace core { class Parameters; } + class Parameters; namespace config { class Configuration; } namespace plugin { class Api; } - namespace init { class Initializer; } - namespace module { class Module; } - //namespace object { class Object; } - namespace object { class ContactListener; } - namespace object { class Type; } + namespace simulation { class Initializer; } + namespace simulation { class Module; } + //namespace simulation { class Object; } + namespace simulation { class ObjectContactListener; } + namespace simulation { class ObjectType; } namespace program { class Program; } #ifdef CECE_RENDER namespace render { class Context; } - namespace simulator { class Visualization; } + namespace simulation { class Visualization; } #endif } @@ -71,7 +71,7 @@ class b2World; /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -118,7 +118,7 @@ class Simulation * * @return */ - virtual const FilePath& getFileName() const noexcept = 0; + virtual const io::FilePath& getFileName() const noexcept = 0; /** @@ -126,7 +126,7 @@ class Simulation * * @return */ - virtual const units::SizeVector& getWorldSize() const noexcept = 0; + virtual const unit::SizeVector& getWorldSize() const noexcept = 0; /** @@ -161,7 +161,7 @@ class Simulation * * @return */ - virtual units::Time getTimeStep() const noexcept = 0; + virtual unit::Time getTimeStep() const noexcept = 0; /** @@ -169,7 +169,7 @@ class Simulation * * @return */ - virtual units::Time getTotalTime() const noexcept = 0; + virtual unit::Time getTotalTime() const noexcept = 0; #ifdef CECE_RENDER @@ -207,7 +207,7 @@ class Simulation * * @return Pointer to resource stream or nullptr. */ - virtual UniquePtr getResource(StringView name) noexcept = 0; + virtual UniquePtr getResource(StringView name) noexcept = 0; /** @@ -263,7 +263,7 @@ class Simulation * * @return Pointer to module or nullptr. */ - virtual ViewPtr getModule(StringView name) const noexcept = 0; + virtual ViewPtr getModule(StringView name) const noexcept = 0; /** @@ -297,7 +297,7 @@ class Simulation * * @throw RuntimeException In case module is not found. */ - virtual ViewPtr requireModule(StringView name) const; + virtual ViewPtr requireModule(StringView name) const; /** @@ -339,7 +339,7 @@ class Simulation * * @return Pointer to program or nullptr. */ - virtual UniquePtr getProgram(StringView name) const = 0; + virtual UniquePtr getProgram(StringView name) const = 0; /** @@ -353,7 +353,7 @@ class Simulation * * @throw RuntimeException In case program is not found. */ - virtual UniquePtr requireProgram(StringView name) const; + virtual UniquePtr requireProgram(StringView name) const; /** @@ -379,7 +379,7 @@ class Simulation * * @return */ - virtual DynamicArray> getObjects() const noexcept = 0; + virtual DynamicArray> getObjects() const noexcept = 0; /** @@ -389,7 +389,7 @@ class Simulation * * @return */ - virtual DynamicArray> getObjects(StringView type) const noexcept; + virtual DynamicArray> getObjects(StringView type) const noexcept; /** @@ -416,7 +416,7 @@ class Simulation * @return * @deprecated */ - virtual units::Length getMaxObjectTranslation() const noexcept = 0; + virtual unit::Length getMaxObjectTranslation() const noexcept = 0; // Public Mutators @@ -466,7 +466,7 @@ class Simulation * * @param size Simulation world size. */ - virtual void setWorldSize(units::SizeVector size) noexcept = 0; + virtual void setWorldSize(unit::SizeVector size) noexcept = 0; /** @@ -474,7 +474,7 @@ class Simulation * * @param dt Time step. */ - virtual void setTimeStep(units::Time dt) = 0; + virtual void setTimeStep(unit::Time dt) = 0; /** @@ -493,7 +493,7 @@ class Simulation * * @return Added initializer. */ - virtual ViewPtr addInitializer(UniquePtr initializer) = 0; + virtual ViewPtr addInitializer(UniquePtr initializer) = 0; /** @@ -515,7 +515,7 @@ class Simulation * * @return Pointer to created initializer. */ - virtual ViewPtr createInitializer(StringView type) = 0; + virtual ViewPtr createInitializer(StringView type) = 0; /** @@ -525,7 +525,7 @@ class Simulation * * @return Pointer to created initializer. */ - virtual ViewPtr createInitializer(const config::Configuration& config); + virtual ViewPtr createInitializer(const config::Configuration& config); /** @@ -533,7 +533,7 @@ class Simulation * * @param initializer Initializer to delete. */ - virtual void deleteInitializer(ViewPtr initializer) = 0; + virtual void deleteInitializer(ViewPtr initializer) = 0; /** @@ -544,7 +544,7 @@ class Simulation * * @return Pointer to added module. */ - virtual ViewPtr addModule(String name, UniquePtr module) = 0; + virtual ViewPtr addModule(String name, UniquePtr module) = 0; /** @@ -570,7 +570,7 @@ class Simulation * * @return Pointer to created module. */ - virtual ViewPtr createModule(StringView type) = 0; + virtual ViewPtr createModule(StringView type) = 0; /** @@ -580,7 +580,7 @@ class Simulation * * @return Pointer to created module. */ - virtual ViewPtr createModule(const config::Configuration& config); + virtual ViewPtr createModule(const config::Configuration& config); /** @@ -616,7 +616,7 @@ class Simulation * * @return Pointer to added object. */ - virtual ViewPtr addObject(UniquePtr object) = 0; + virtual ViewPtr addObject(UniquePtr object) = 0; /** @@ -640,7 +640,7 @@ class Simulation * * @return Pointer to created object. */ - virtual ViewPtr createObject(StringView type) = 0; + virtual ViewPtr createObject(StringView type) = 0; /** @@ -651,7 +651,7 @@ class Simulation * @return Pointer to created object. * @deprecated */ - virtual ViewPtr createObject(StringView type, object::Object::Type state) = 0; + virtual ViewPtr createObject(StringView type, simulation::Object::Type state) = 0; /** @@ -662,7 +662,7 @@ class Simulation * * @return Pointer to created object. */ - virtual ViewPtr createObject(const config::Configuration& config); + virtual ViewPtr createObject(const config::Configuration& config); /** @@ -670,7 +670,7 @@ class Simulation * * @param object Pointer to deleted object. */ - virtual void deleteObject(ViewPtr object) = 0; + virtual void deleteObject(ViewPtr object) = 0; /** @@ -681,7 +681,7 @@ class Simulation * * @return Pointer to added program. */ - virtual ViewPtr addProgram(String name, UniquePtr program) = 0; + virtual ViewPtr addProgram(String name, UniquePtr program) = 0; /** @@ -692,7 +692,7 @@ class Simulation * * @return Pointer to created program. */ - virtual ViewPtr createProgram(String name, StringView type) = 0; + virtual ViewPtr createProgram(String name, StringView type) = 0; /** @@ -702,7 +702,7 @@ class Simulation * * @return Pointer to created program. */ - virtual ViewPtr createProgram(const config::Configuration& config); + virtual ViewPtr createProgram(const config::Configuration& config); /** @@ -718,7 +718,7 @@ class Simulation * * @param listener New listener. */ - virtual void setContactListener(object::ContactListener* listener); + virtual void setContactListener(simulation::ObjectContactListener* listener); // Public Operations @@ -746,7 +746,7 @@ class Simulation * * @param flag Initialization flag. */ - virtual void initialize(AtomicBool& flag) = 0; + virtual void initialize(async::AtomicBool& flag) = 0; /** diff --git a/cece/simulator/TimeMeasurement.hpp b/include/cece/simulation/TimeMeasurement.hpp similarity index 92% rename from cece/simulator/TimeMeasurement.hpp rename to include/cece/simulation/TimeMeasurement.hpp index c610f18..17bbf5b 100644 --- a/cece/simulator/TimeMeasurement.hpp +++ b/include/cece/simulation/TimeMeasurement.hpp @@ -28,15 +28,15 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/ViewPtr.hpp" -#include "cece/core/StringView.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/TimeMeasurement.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/StringView.hpp" +#include "cece/io/OutStream.hpp" +#include "cece/perf/TimeMeasurement.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -84,7 +84,7 @@ struct TimeMeasurement * @param name Measurement name. * @param dt Measured time. */ - void operator()(OutStream& out, StringView name, Clock::duration dt) const noexcept; + void operator()(io::OutStream& out, StringView name, perf::Clock::duration dt) const noexcept; }; diff --git a/cece/simulator/Visualization.hpp b/include/cece/simulation/Visualization.hpp similarity index 91% rename from cece/simulator/Visualization.hpp rename to include/cece/simulation/Visualization.hpp index 6438058..085b193 100644 --- a/cece/simulator/Visualization.hpp +++ b/include/cece/simulation/Visualization.hpp @@ -27,23 +27,16 @@ /* ************************************************************************ */ -// CeCe -#include "cece/config.hpp" - -/* ************************************************************************ */ - -#ifdef CECE_RENDER - -/* ************************************************************************ */ - // C++ #include // CeCe -#include "cece/core/StringView.hpp" -#include "cece/core/DynamicArray.hpp" +#define CECE_RENDER_REQUIRE +#include "cece/common.hpp" +#include "cece/StringView.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/Color.hpp" -#include "cece/simulator/VisualizationLayer.hpp" +#include "cece/simulation/VisualizationLayer.hpp" /* ************************************************************************ */ @@ -52,7 +45,7 @@ namespace cece { namespace config { class Configuration; } } /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -190,7 +183,3 @@ class Visualization } /* ************************************************************************ */ - -#endif - -/* ************************************************************************ */ diff --git a/cece/simulator/VisualizationLayer.hpp b/include/cece/simulation/VisualizationLayer.hpp similarity index 91% rename from cece/simulator/VisualizationLayer.hpp rename to include/cece/simulation/VisualizationLayer.hpp index 2571d7d..6513f9d 100644 --- a/cece/simulator/VisualizationLayer.hpp +++ b/include/cece/simulation/VisualizationLayer.hpp @@ -27,26 +27,18 @@ /* ************************************************************************ */ -// CeCe -#include "cece/config.hpp" - -/* ************************************************************************ */ - -#ifdef CECE_RENDER - -/* ************************************************************************ */ - // C++ #include // CeCe -#include "cece/config.hpp" -#include "cece/core/String.hpp" +#define CECE_RENDER_REQUIRE +#include "cece/common.hpp" +#include "cece/String.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -166,7 +158,3 @@ class VisualizationLayer } /* ************************************************************************ */ - -#endif - -/* ************************************************************************ */ diff --git a/cece/simulator/ConverterBox2D.hpp b/include/cece/simulator/ConverterBox2D.hpp similarity index 74% rename from cece/simulator/ConverterBox2D.hpp rename to include/cece/simulator/ConverterBox2D.hpp index fdc1455..5c9fbfd 100644 --- a/cece/simulator/ConverterBox2D.hpp +++ b/include/cece/simulator/ConverterBox2D.hpp @@ -27,8 +27,11 @@ /* ************************************************************************ */ -// CeCe config -#include "cece/config.hpp" +#if _MSC_VER +#pragma message("Private") +#else +#warning "Private" +#endif /* ************************************************************************ */ @@ -36,9 +39,10 @@ #include // CeCe -#include "cece/core/Units.hpp" -#include "cece/core/UnitsCtors.hpp" -#include "cece/core/VectorUnits.hpp" +#include "cece/common.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/UnitsCtors.hpp" +#include "cece/unit/VectorUnits.hpp" /* ************************************************************************ */ @@ -66,7 +70,7 @@ class ConverterBox2D * * @return */ - units::Time getTimeStep() const noexcept + unit::Time getTimeStep() const noexcept { return m_timeStep; } @@ -77,7 +81,7 @@ class ConverterBox2D * * @return */ - units::Time getTimeStepBox2D() const noexcept + unit::Time getTimeStepBox2D() const noexcept { return m_timeStepBox2D; } @@ -111,7 +115,7 @@ class ConverterBox2D * * @param timeStep */ - void setTimeStep(units::Time timeStep) noexcept + void setTimeStep(unit::Time timeStep) noexcept { m_timeStep = timeStep; } @@ -122,7 +126,7 @@ class ConverterBox2D * * @param timeStep */ - void setTimeStepBox2D(units::Time timeStep) noexcept + void setTimeStepBox2D(unit::Time timeStep) noexcept { m_timeStepBox2D = timeStep; } @@ -150,7 +154,7 @@ class ConverterBox2D * * @return */ - units::Length convertLength(float32 length) const noexcept; + unit::Length convertLength(float32 length) const noexcept; /** @@ -160,7 +164,7 @@ class ConverterBox2D * * @return */ - float32 convertLength(units::Length length) const noexcept; + float32 convertLength(unit::Length length) const noexcept; /** @@ -170,7 +174,7 @@ class ConverterBox2D * * @return */ - units::PositionVector convertPosition(b2Vec2 position) const noexcept; + unit::PositionVector convertPosition(b2Vec2 position) const noexcept; /** @@ -180,7 +184,7 @@ class ConverterBox2D * * @return */ - b2Vec2 convertPosition(units::PositionVector position) const noexcept; + b2Vec2 convertPosition(unit::PositionVector position) const noexcept; /** @@ -190,7 +194,7 @@ class ConverterBox2D * * @return */ - units::Angle convertAngle(float32 angle) const noexcept; + unit::Angle convertAngle(float32 angle) const noexcept; /** @@ -200,7 +204,7 @@ class ConverterBox2D * * @return */ - float32 convertAngle(units::Angle angle) const noexcept; + float32 convertAngle(unit::Angle angle) const noexcept; /** @@ -210,7 +214,7 @@ class ConverterBox2D * * @return */ - units::VelocityVector convertLinearVelocity(b2Vec2 velocity) const noexcept; + unit::VelocityVector convertLinearVelocity(b2Vec2 velocity) const noexcept; /** @@ -220,7 +224,7 @@ class ConverterBox2D * * @return */ - b2Vec2 convertLinearVelocity(units::VelocityVector velocity) const noexcept; + b2Vec2 convertLinearVelocity(unit::VelocityVector velocity) const noexcept; /** @@ -230,7 +234,7 @@ class ConverterBox2D * * @return */ - units::AngularVelocity convertAngularVelocity(float32 velocity) const noexcept; + unit::AngularVelocity convertAngularVelocity(float32 velocity) const noexcept; /** @@ -240,7 +244,7 @@ class ConverterBox2D * * @return */ - float32 convertAngularVelocity(units::AngularVelocity velocity) const noexcept; + float32 convertAngularVelocity(unit::AngularVelocity velocity) const noexcept; /** @@ -250,7 +254,7 @@ class ConverterBox2D * * @return */ - units::AccelerationVector convertLinearAcceleration(b2Vec2 acceleration) const noexcept; + unit::AccelerationVector convertLinearAcceleration(b2Vec2 acceleration) const noexcept; /** @@ -260,7 +264,7 @@ class ConverterBox2D * * @return */ - b2Vec2 convertLinearAcceleration(units::AccelerationVector acceleration) const noexcept; + b2Vec2 convertLinearAcceleration(unit::AccelerationVector acceleration) const noexcept; /** @@ -270,7 +274,7 @@ class ConverterBox2D * * @return */ - units::Acceleration convertAngularAcceleration(float32 acceleration) const noexcept; + unit::Acceleration convertAngularAcceleration(float32 acceleration) const noexcept; /** @@ -280,7 +284,7 @@ class ConverterBox2D * * @return */ - float32 convertAngularAcceleration(units::Acceleration acceleration) const noexcept; + float32 convertAngularAcceleration(unit::Acceleration acceleration) const noexcept; /** @@ -290,7 +294,7 @@ class ConverterBox2D * * @return */ - units::ForceVector convertForce(b2Vec2 force) const noexcept; + unit::ForceVector convertForce(b2Vec2 force) const noexcept; /** @@ -300,7 +304,7 @@ class ConverterBox2D * * @return */ - b2Vec2 convertForce(units::ForceVector force) const noexcept; + b2Vec2 convertForce(unit::ForceVector force) const noexcept; /** @@ -310,7 +314,7 @@ class ConverterBox2D * * @return */ - units::Force convertTorque(float32 torque) const noexcept; + unit::Force convertTorque(float32 torque) const noexcept; /** @@ -320,7 +324,7 @@ class ConverterBox2D * * @return */ - float32 convertTorque(units::Force torque) const noexcept; + float32 convertTorque(unit::Force torque) const noexcept; /** @@ -330,7 +334,7 @@ class ConverterBox2D * * @return */ - units::ImpulseVector convertLinearImpulse(b2Vec2 impulse) const noexcept; + unit::ImpulseVector convertLinearImpulse(b2Vec2 impulse) const noexcept; /** @@ -340,7 +344,7 @@ class ConverterBox2D * * @return */ - b2Vec2 convertLinearImpulse(units::ImpulseVector impulse) const noexcept; + b2Vec2 convertLinearImpulse(unit::ImpulseVector impulse) const noexcept; /** @@ -350,7 +354,7 @@ class ConverterBox2D * * @return */ - units::Impulse convertAngularImpulse(float32 impulse) const noexcept; + unit::Impulse convertAngularImpulse(float32 impulse) const noexcept; /** @@ -360,7 +364,7 @@ class ConverterBox2D * * @return */ - float32 convertAngularImpulse(units::Impulse impulse) const noexcept; + float32 convertAngularImpulse(unit::Impulse impulse) const noexcept; /** @@ -370,7 +374,7 @@ class ConverterBox2D * * @return */ - units::Mass convertMass(float32 mass) const noexcept; + unit::Mass convertMass(float32 mass) const noexcept; /** @@ -380,7 +384,7 @@ class ConverterBox2D * * @return */ - float32 convertMass(units::Mass mass) const noexcept; + float32 convertMass(unit::Mass mass) const noexcept; /** @@ -390,7 +394,7 @@ class ConverterBox2D * * @return */ - units::Density convertDensity(float32 density) const noexcept; + unit::Density convertDensity(float32 density) const noexcept; /** @@ -400,7 +404,7 @@ class ConverterBox2D * * @return */ - float32 convertDensity(units::Density density) const noexcept; + float32 convertDensity(unit::Density density) const noexcept; /** @@ -408,7 +412,7 @@ class ConverterBox2D * * @return */ - units::Length getMaxObjectTranslation() const noexcept; + unit::Length getMaxObjectTranslation() const noexcept; /** @@ -422,10 +426,10 @@ class ConverterBox2D private: /// Box2D time step. - units::Time m_timeStepBox2D = units::s(1.0 / 60.0); + unit::Time m_timeStepBox2D = unit::s(1.0 / 60.0); /// Simulation time step - units::Time m_timeStep; + unit::Time m_timeStep; /// Length coefficient. RealType m_lengthCoefficient = 1; diff --git a/include/cece/simulator/DefaultSimulation.hpp b/include/cece/simulator/DefaultSimulation.hpp new file mode 100644 index 0000000..3c13d64 --- /dev/null +++ b/include/cece/simulator/DefaultSimulation.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/DefaultSimulation.hpp' instead") +#else +#warning "Include 'cece/simulation/DefaultSimulation.hpp' instead" +#endif +#include "cece/simulation/DefaultSimulation.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulator { + +/* ************************************************************************ */ + +using simulation::DefaultSimulation; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/simulator/Simulation.hpp b/include/cece/simulator/Simulation.hpp new file mode 100644 index 0000000..9d1154d --- /dev/null +++ b/include/cece/simulator/Simulation.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Simulation.hpp' instead") +#else +#warning "Include 'cece/simulation/Simulation.hpp' instead" +#endif +#include "cece/simulation/Simulation.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulator { + +/* ************************************************************************ */ + +using simulation::Simulation; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/simulator/TimeMeasurement.hpp b/include/cece/simulator/TimeMeasurement.hpp new file mode 100644 index 0000000..a69a1cb --- /dev/null +++ b/include/cece/simulator/TimeMeasurement.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/TimeMeasurement.hpp' instead") +#else +#warning "Include 'cece/simulation/TimeMeasurement.hpp' instead" +#endif +#include "cece/simulation/TimeMeasurement.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulator { + +/* ************************************************************************ */ + +using simulation::TimeMeasurement; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/simulator/Visualization.hpp b/include/cece/simulator/Visualization.hpp new file mode 100644 index 0000000..e62bd9f --- /dev/null +++ b/include/cece/simulator/Visualization.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/Visualization.hpp' instead") +#else +#warning "Include 'cece/simulation/Visualization.hpp' instead" +#endif +#include "cece/simulation/Visualization.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulator { + +/* ************************************************************************ */ + +#ifdef CECE_RENDER +using simulation::Visualization; +#endif + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/include/cece/simulator/VisualizationLayer.hpp b/include/cece/simulator/VisualizationLayer.hpp new file mode 100644 index 0000000..1efbeb9 --- /dev/null +++ b/include/cece/simulator/VisualizationLayer.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#if _MSC_VER +#pragma message("Include 'cece/simulation/VisualizationLayer.hpp' instead") +#else +#warning "Include 'cece/simulation/VisualizationLayer.hpp' instead" +#endif +#include "cece/simulation/VisualizationLayer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulator { + +/* ************************************************************************ */ + +#ifdef CECE_RENDER +using simulation::VisualizationLayer; +#endif + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/config/Exception.hpp b/include/cece/unit/Exception.hpp similarity index 94% rename from cece/config/Exception.hpp rename to include/cece/unit/Exception.hpp index 2eeddf8..23db415 100644 --- a/cece/config/Exception.hpp +++ b/include/cece/unit/Exception.hpp @@ -28,19 +28,19 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Exception.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ namespace cece { -namespace config { +namespace unit { /* ************************************************************************ */ /** - * @brief Configuration exception. + * @brief Unit cast exception. */ -class Exception : public RuntimeException +class CastException : public RuntimeException { using RuntimeException::RuntimeException; }; diff --git a/include/cece/unit/Unit.hpp b/include/cece/unit/Unit.hpp new file mode 100644 index 0000000..07c9dd9 --- /dev/null +++ b/include/cece/unit/Unit.hpp @@ -0,0 +1,2222 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// C++ +#include +#include +#include + +// CeCe +#include "cece/common.hpp" +#include "cece/String.hpp" +#include "cece/math/Zero.hpp" +#include "cece/unit/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +/// Underlying type for units. +using ValueType = RealType; + +/* ************************************************************************ */ + +struct DynamicImpl; + +/* ************************************************************************ */ + +/** + * @brief Unit type static implementation. + * + * @tparam Length Number of length units. + * @tparam Time Number of time units. + * @tparam Mass Number of mass units. + * @tparam Current Number of electrical current units. + * @tparam Temperature Number of temperature units. + * @tparam Substance Number of amount of substance units. + * @tparam Intensity Number of intensity units. + */ +template< + int Length, + int Time, + int Mass, + int Current, + int Temperature, + int Substance, + int Intensity +> +struct StaticImpl +{ + + /// Stored value. + ValueType value{}; + + + /** + * @brief Default constructor. + */ + constexpr StaticImpl(); + + + /** + * @brief Constructor. + * + * @param[in] value The value. + */ + explicit constexpr StaticImpl(ValueType value) noexcept; + + + /** + * @brief Construct from dynamic implementation. + * + * @param[in] impl The implementation. + */ + StaticImpl(const DynamicImpl& impl); + + + /** + * @brief Assign from dynamic implementation. + * + * @param[in] impl The implementation. + */ + StaticImpl& operator=(const DynamicImpl& impl); + + + /** + * @brief Returns the length exponent. + * + * @return The length exponent. + */ + constexpr int getLengthExp() const noexcept; + + + /** + * @brief Returns the time exponent. + * + * @return The time exponent. + */ + constexpr int getTimeExp() const noexcept; + + + /** + * @brief Returns the mass exponent. + * + * @return The mass exponent. + */ + constexpr int getMassExp() const noexcept; + + + /** + * @brief Returns the current exponent. + * + * @return The current exponent. + */ + constexpr int getCurrentExp() const noexcept; + + + /** + * @brief Returns the temperature exponent. + * + * @return The temperature exponent. + */ + constexpr int getTemperatureExp() const noexcept; + + + /** + * @brief Returns the substance exponent. + * + * @return The substance exponent. + */ + constexpr int getSubstanceExp() const noexcept; + + + /** + * @brief Returns the intensity exponent. + * + * @return The intensity exponent. + */ + constexpr int getIntensityExp() const noexcept; + + + /** + * @brief Check dynamic implementation. + * + * @param[in] impl The implementation. + * + * @throw CastException If dynamic cannot be cast to static. + */ + void checkDynamic(const DynamicImpl& impl) const; + +}; + +/* ************************************************************************ */ + +/** + * @brief Unit type dynamic implementation. + */ +struct DynamicImpl +{ + + struct Detail + { + int length : 4; // -7, 7 + int time : 4; + int mass : 4; + int current : 4; + int temperature : 4; + int substance : 4; + int intensity : 4; + }; + + + /// Stored value. + ValueType value{}; + + /// Runtime detail. + Detail detail{}; + + + /** + * @brief Default constructor. + */ + DynamicImpl() = default; + + + /** + * @brief Constructor. + * + * @param[in] value The value. + * @param[in] detail The detail. + */ + explicit DynamicImpl(ValueType value, Detail detail = {}) noexcept; + + + /** + * @brief Construct from static implementation. + * + * @param[in] impl The implementation. + */ + template< + int Length, + int Time, + int Mass, + int Current, + int Temperature, + int Substance, + int Intensity + > + DynamicImpl(const StaticImpl& impl) noexcept; + + + /** + * @brief Assign from static implementation. + * + * @param[in] impl The implementation. + */ + template< + int Length, + int Time, + int Mass, + int Current, + int Temperature, + int Substance, + int Intensity + > + DynamicImpl& operator=(const StaticImpl& impl) noexcept; + + + /** + * @brief Returns the length exponent. + * + * @return The length exponent. + */ + constexpr int getLengthExp() const noexcept; + + + /** + * @brief Returns the time exponent. + * + * @return The time exponent. + */ + constexpr int getTimeExp() const noexcept; + + + /** + * @brief Returns the mass exponent. + * + * @return The mass exponent. + */ + constexpr int getMassExp() const noexcept; + + + /** + * @brief Returns the current exponent. + * + * @return The current exponent. + */ + constexpr int getCurrentExp() const noexcept; + + + /** + * @brief Returns the temperature exponent. + * + * @return The temperature exponent. + */ + constexpr int getTemperatureExp() const noexcept; + + + /** + * @brief Returns the substance exponent. + * + * @return The substance exponent. + */ + constexpr int getSubstanceExp() const noexcept; + + + /** + * @brief Returns the intensity exponent. + * + * @return The intensity exponent. + */ + constexpr int getIntensityExp() const noexcept; + +}; + +/* ************************************************************************ */ + +namespace detail { + +/* ************************************************************************ */ + +/** + * @brief Implementations helper. + * + * @tparam Impl1 The first implementation. + * @tparam Impl2 The second implementation. + */ +template +struct ImplHelper; + +/* ************************************************************************ */ + +/** + * @brief Implementation helper for 2 static implementations. + * + * @tparam Length1 Number of length units. + * @tparam Time1 Number of time units. + * @tparam Mass1 Number of mass units. + * @tparam Current1 Number of electrical current units. + * @tparam Temperature1 Number of temperature units. + * @tparam Substance1 Number of amount of substance units. + * @tparam Intensity1 Number of intensity units. + * @tparam Length2 Number of length units. + * @tparam Time2 Number of time units. + * @tparam Mass2 Number of mass units. + * @tparam Current2 Number of electrical current units. + * @tparam Temperature2 Number of temperature units. + * @tparam Substance2 Number of amount of substance units. + * @tparam Intensity2 Number of intensity units. + */ +template< + int Length1, + int Time1, + int Mass1, + int Current1, + int Temperature1, + int Substance1, + int Intensity1, + int Length2, + int Time2, + int Mass2, + int Current2, + int Temperature2, + int Substance2, + int Intensity2 +> +struct ImplHelper< + StaticImpl< + Length1, + Time1, + Mass1, + Current1, + Temperature1, + Substance1, + Intensity1 + >, StaticImpl< + Length2, + Time2, + Mass2, + Current2, + Temperature2, + Substance2, + Intensity2 + > +> +{ + /// If relational operations are supported + static constexpr bool isRelSupported = + Length1 == Length2 && + Time1 == Time2 && + Mass1 == Mass2 && + Current1 == Current2 && + Temperature1 == Temperature2 && + Substance1 == Substance2 && + Intensity1 == Intensity2 + ; + + /// If addition is supported + static constexpr bool isAddSupported = + Length1 == Length2 && + Time1 == Time2 && + Mass1 == Mass2 && + Current1 == Current2 && + Temperature1 == Temperature2 && + Substance1 == Substance2 && + Intensity1 == Intensity2 + ; + + /// If subtraction is supported + static constexpr bool isSubSupported = isAddSupported; + + /// Addition result implementation (only valid when `isAddSupported == true`) + using AddImplType = StaticImpl< + Length1, + Time1, + Mass1, + Current1, + Temperature1, + Substance1, + Intensity1 + >; + + /// Subtraction result implementation (only valid when `isSubSupported == true`) + using SubImplType = StaticImpl< + Length1, + Time1, + Mass1, + Current1, + Temperature1, + Substance1, + Intensity1 + >; + + /// Multiplicate result implementation. + using MulImplType = StaticImpl< + Length1 + Length2, + Time1 + Time2, + Mass1 + Mass2, + Current1 + Current2, + Temperature1 + Temperature2, + Substance1 + Substance2, + Intensity1 + Intensity2 + >; + + /// Divide result implementation. + using DivImplType = StaticImpl< + Length1 - Length2, + Time1 - Time2, + Mass1 - Mass2, + Current1 - Current2, + Temperature1 - Temperature2, + Substance1 - Substance2, + Intensity1 - Intensity2 + >; + +}; + +/* ************************************************************************ */ + +/** + * @brief Implementations inverter. + * + * @tparam Impl The implementation. + */ +template +struct ImplInverter +{ + using ImplType = Impl; +}; + +/* ************************************************************************ */ + +/** + * @brief Implementations inverter. + * + * @tparam Length Number of length units. + * @tparam Time Number of time units. + * @tparam Mass Number of mass units. + * @tparam Current Number of electrical current units. + * @tparam Temperature Number of temperature units. + * @tparam Substance Number of amount of substance units. + * @tparam Intensity Number of intensity units. + */ +template< + int Length, + int Time, + int Mass, + int Current, + int Temperature, + int Substance, + int Intensity +> +struct ImplInverter> +{ + using ImplType = StaticImpl< + -Length, + -Time, + -Mass, + -Current, + -Temperature, + -Substance, + -Intensity + >; +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +/** + * @brief SI Unit. + * + * @tparam Impl Unit implementation: `StaticImpl` or `DynamicImpl`. + */ +template +class UnitBase +{ + template friend class UnitBase; + +// Public Ctors & Dtors +public: + + + /** + * @brief Default constructor. + */ + constexpr UnitBase() noexcept; + + + /** + * @brief Constructor. + * + * @param value Init value. + */ + template>::value || + std::is_same::value, + int + >::type = 0 + > + constexpr UnitBase(ValueType value) noexcept; + + + /** + * @brief Constructor. + * + * @param[in] args Construction arguments. + * + * @tparam Args Argument types. + */ + template::value, + int + >::type = 0 + > + explicit constexpr UnitBase(Args&&... args); + + + /** + * @brief Zero constructor. + */ + constexpr UnitBase(math::Zero_t) noexcept; + + + /** + * @brief Constructor. + * + * @param[in] unit The unit. + */ + constexpr UnitBase(const UnitBase& unit); + + + /** + * @brief Constructor. + * + * @param[in] unit The unit. + */ + constexpr UnitBase(UnitBase&& unit); + + + /** + * @brief Constructor. + * + * @param[in] unit The unit. + * + * @tparam Impl2 The second unit implementation. + */ + template + constexpr UnitBase(const UnitBase& unit); + + + /** + * @brief Constructor. + * + * @param[in] unit The unit. + * + * @tparam Impl2 The second unit implementation. + */ + template + UnitBase(UnitBase&& unit); + + +// Public Operators +public: + + + /** + * @brief Assignment operator. + * + * @param[in] unit The unit. + */ + UnitBase& operator=(const UnitBase& unit); + + + /** + * @brief Assignment operator. + * + * @param[in] unit The unit. + */ + UnitBase& operator=(UnitBase&& unit) noexcept; + + + /** + * @brief Assignment operator. + * + * @param[in] unit The unit. + * + * @tparam Impl2 The second unit implementation. + */ + template + UnitBase& operator=(const UnitBase& unit); + + + /** + * @brief Cast to value type. + */ + template>::value, int>::type = 0 + > + operator ValueType() const noexcept; + + + /** + * @brief Cast to value type. + */ + template>::value, int>::type = 0 + > + explicit operator ValueType() const noexcept; + + + /** + * @brief Unary plus operator. + * + * @return New value. + */ + UnitBase operator+() const noexcept; + + + /** + * @brief Unary minus operator. + * + * @return New value. + */ + UnitBase operator-() const noexcept; + + + /** + * @brief Addition operator. + * + * @param rhs The right hand side. + * + * @return *this. + */ + UnitBase& operator+=(UnitBase rhs) noexcept; + + + /** + * @brief Substraction operator. + * + * @param rhs The right hand side. + * + * @return *this. + */ + UnitBase& operator-=(UnitBase rhs) noexcept; + + + /** + * @brief Multiplication operator. + * + * @param rhs The right hand side. + * + * @return *this. + */ + UnitBase& operator*=(ValueType rhs) noexcept; + + + /** + * @brief Division operator. + * + * @param rhs The right hand side. + * + * @return *this. + */ + UnitBase& operator/=(ValueType rhs) noexcept; + + +// Public Accessors +public: + + + /** + * @brief Returns underlying value. + * + * @return The underlying value. + */ + constexpr ValueType get() const noexcept; + + + /** + * @brief Returns underlying value. + * + * @return The underlying value. + * + * @deprecated + */ + constexpr ValueType value() const noexcept; + + + /** + * @brief Returns the length exponent. + * + * @return The length exponent. + */ + constexpr int getLengthExp() const noexcept; + + + /** + * @brief Returns the time exponent. + * + * @return The time exponent. + */ + constexpr int getTimeExp() const noexcept; + + + /** + * @brief Returns the mass exponent. + * + * @return The mass exponent. + */ + constexpr int getMassExp() const noexcept; + + + /** + * @brief Returns the current exponent. + * + * @return The current exponent. + */ + constexpr int getCurrentExp() const noexcept; + + + /** + * @brief Returns the temperature exponent. + * + * @return The temperature exponent. + */ + constexpr int getTemperatureExp() const noexcept; + + + /** + * @brief Returns the substance exponent. + * + * @return The substance exponent. + */ + constexpr int getSubstanceExp() const noexcept; + + + /** + * @brief Returns the intensity exponent. + * + * @return The intensity exponent. + */ + constexpr int getIntensityExp() const noexcept; + + +// Private Data Members +private: + + /// Unit implementation. + Impl m_impl; + +}; + +/* ************************************************************************ */ + +/** + * @brief Default unit is dynamic. + */ +using Unit = UnitBase; + +/* ************************************************************************ */ + +/** + * @brief Sum index values. + * + * @tparam Values The values to sum. + */ +template +struct ComposeSum; + +/* ************************************************************************ */ + +/** + * @brief Sum index values. + * + * @tparam Value The first value. + * @tparam Values The remaining values. + */ +template +struct ComposeSum +{ + /// Result sum value + static constexpr int value = Value + ComposeSum::value; +}; + +/* ************************************************************************ */ + +/** + * @brief Sum index values. + * + * @tparam Value The last value. + */ +template +struct ComposeSum +{ + /// Result sum value + static constexpr int value = Value; +}; + +/* ************************************************************************ */ + +/** + * @brief Compose unit types. + * + * @tparam Impls Implementations. + */ +template +struct Compose; + +/* ************************************************************************ */ + +/** + * @brief Compose unit types. + * + * @tparam Lengths A list of lengths. + * @tparam Times A list of times. + * @tparam Masses A list of masses. + * @tparam Currents A list of currents. + * @tparam Temperatures A list of temperatures. + * @tparam Substances A list of substances. + * @tparam Intensities A list of intensities. + */ +template< + int... Lengths, + int... Times, + int... Masses, + int... Currents, + int... Temperatures, + int... Substances, + int... Intensities +> +struct Compose>...> +{ + using type = UnitBase::value, + ComposeSum::value, + ComposeSum::value, + ComposeSum::value, + ComposeSum::value, + ComposeSum::value, + ComposeSum::value + >>; +}; + +/* ************************************************************************ */ + +/** + * @brief Define empty dynamic detail. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail none() noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension length. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail length(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension time. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail time(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension mass. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail mass(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension current. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail current(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension temperature. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail temperature(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension substance. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail substance(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Define dynamic detail for N-dimension intensity. + * + * @param[in] dim The dimension. + * + * @return Dynamic implementation detail. + */ +DynamicImpl::Detail intensity(int dim = 1) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Merge dynamic implementation detail. + * + * @param[in] lhs The left hand side. + * @param[in] rhs The right hand side. + * + * @return Result. + */ +DynamicImpl::Detail operator|(DynamicImpl::Detail lhs, DynamicImpl::Detail rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Merge dynamic implementation detail. + * + * @param[in] lhs The left hand side. + * @param[in] rhs The right hand side. + * + * @return Result. + */ +DynamicImpl::Detail operator/(DynamicImpl::Detail lhs, DynamicImpl::Detail rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator==(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator==(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator==(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Not equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator!=(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Not equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator!=(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Not equal operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator!=(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less than operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less than operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less than operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<=(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<=(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Less equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator<=(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater operator. + * + * @param rhs Right operand. + * @param lhs Left operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater operator. + * + * @param rhs Right operand. + * @param lhs Left operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater operator. + * + * @param rhs Right operand. + * @param lhs Left operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>=(const UnitBase& lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>=(const UnitBase& lhs, math::Zero_t rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Greater equals operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr bool operator>=(math::Zero_t lhs, const UnitBase& rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Addition operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr auto operator+(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::AddImplType>; + +/* ************************************************************************ */ + +/** + * @brief Substraction operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr auto operator-(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::SubImplType>; + +/* ************************************************************************ */ + +/** + * @brief Multiplication operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr auto operator*(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::MulImplType>; + +/* ************************************************************************ */ + +/** + * @brief Multiplication operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The unit implementation. + * + * @return Result value. + */ +template +inline constexpr UnitBase operator*(UnitBase lhs, RealType rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Multiplication operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The unit implementation. + * + * @return Result value. + */ +template +inline constexpr UnitBase operator*(RealType lhs, UnitBase rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Division operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The first unit implementation. + * @tparam Impl2 The second unit implementation. + * + * @return Result value. + */ +template +inline constexpr auto operator/(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::DivImplType>; + +/* ************************************************************************ */ + +/** + * @brief Division operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl1 The unit implementation. + * + * @return Result value. + */ +template +inline constexpr UnitBase operator/(UnitBase lhs, RealType rhs) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Division operator. + * + * @param lhs Left operand. + * @param rhs Right operand. + * + * @tparam Impl2 The unit implementation. + * + * @return Result value. + */ +template +inline constexpr auto operator/(RealType lhs, const UnitBase& rhs) noexcept + -> UnitBase::ImplType>; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ +/* ************************************************************************ */ +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +template +inline constexpr StaticImpl::StaticImpl() = default; + +/* ************************************************************************ */ + +template +inline constexpr StaticImpl::StaticImpl(ValueType value) noexcept + : value(value) +{ + // Check if +} + +/* ************************************************************************ */ + +template +inline StaticImpl::StaticImpl(const DynamicImpl& impl) + : value(impl.value) +{ + checkDynamic(impl); +} + +/* ************************************************************************ */ + +template +inline StaticImpl& StaticImpl::operator=(const DynamicImpl& impl) +{ + value = impl.value; + + checkDynamic(impl); + + return *this; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getLengthExp() const noexcept +{ + return Length; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getTimeExp() const noexcept +{ + return Time; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getMassExp() const noexcept +{ + return Mass; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getCurrentExp() const noexcept +{ + return Current; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getTemperatureExp() const noexcept +{ + return Temperature; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getSubstanceExp() const noexcept +{ + return Substance; +} + +/* ************************************************************************ */ + +template +inline constexpr int StaticImpl::getIntensityExp() const noexcept +{ + return Intensity; +} + +/* ************************************************************************ */ + +template +void StaticImpl::checkDynamic(const DynamicImpl& impl) const +{ + // Non-dimensional zero can be cast to anything + if (value == 0.0 && + impl.detail.length == 0 && + impl.detail.time == 0 && + impl.detail.mass == 0 && + impl.detail.current == 0 && + impl.detail.temperature == 0 && + impl.detail.substance == 0 && + impl.detail.intensity == 0) + return; + + // Check if can be converted + if (impl.detail.length != Length) + throw CastException("Length exponent mismatch: " + toString(impl.detail.length) + " vs " + toString(Length)); + + if (impl.detail.time != Time) + throw CastException("Time exponent mismatch: " + toString(impl.detail.time) + " vs " + toString(Time)); + + if (impl.detail.mass != Mass) + throw CastException("Mass exponent mismatch: " + toString(impl.detail.mass) + " vs " + toString(Mass)); + + if (impl.detail.current != Current) + throw CastException("Current exponent mismatch: " + toString(impl.detail.current) + " vs " + toString(Current)); + + if (impl.detail.temperature != Temperature) + throw CastException("Temperature exponent mismatch: " + toString(impl.detail.temperature) + " vs " + toString(Temperature)); + + if (impl.detail.substance != Substance) + throw CastException("Substance exponent mismatch: " + toString(impl.detail.substance) + " vs " + toString(Substance)); + + if (impl.detail.intensity != Intensity) + throw CastException("Intensity exponent mismatch: " + toString(impl.detail.intensity) + " vs " + toString(Intensity)); +} + +/* ************************************************************************ */ + +inline DynamicImpl::DynamicImpl(ValueType value, Detail detail) noexcept + : value(value) + , detail(detail) +{ + // Check if +} + +/* ************************************************************************ */ + +template +inline DynamicImpl::DynamicImpl(const StaticImpl& impl) noexcept + : value(impl.value) + , detail{Length, Time, Mass, Current, Temperature, Substance, Intensity} +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +inline DynamicImpl& DynamicImpl::operator=(const StaticImpl& impl) noexcept +{ + value = impl.value; + detail.length = Length; + detail.time = Time; + detail.mass = Mass; + detail.current = Current; + detail.temperature = Temperature; + detail.substance = Substance; + detail.intensity = Intensity; + + return *this; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getLengthExp() const noexcept +{ + return detail.length; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getTimeExp() const noexcept +{ + return detail.time; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getMassExp() const noexcept +{ + return detail.mass; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getCurrentExp() const noexcept +{ + return detail.current; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getTemperatureExp() const noexcept +{ + return detail.temperature; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getSubstanceExp() const noexcept +{ + return detail.substance; +} + +/* ************************************************************************ */ + +inline constexpr int DynamicImpl::getIntensityExp() const noexcept +{ + return detail.intensity; +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase::UnitBase() noexcept + : m_impl() +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +template>::value || + std::is_same::value, + int +>::type> +inline constexpr UnitBase::UnitBase(ValueType value) noexcept + : m_impl(value) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +template::value, + int +>::type> +inline constexpr UnitBase::UnitBase(Args&&... args) + : m_impl(std::forward(args)...) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase::UnitBase(math::Zero_t) noexcept + : m_impl() +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase::UnitBase(const UnitBase& unit) + : m_impl(unit.m_impl) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase::UnitBase(UnitBase&& unit) + : m_impl(unit.m_impl) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +template +inline constexpr UnitBase::UnitBase(const UnitBase& unit) + : m_impl(unit.m_impl) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +template +inline UnitBase::UnitBase(UnitBase&& unit) + : m_impl(unit.m_impl) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator=(const UnitBase& unit) +{ + m_impl = unit.m_impl; + return *this; +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator=(UnitBase&& unit) noexcept +{ + m_impl = unit.m_impl; + return *this; +} + +/* ************************************************************************ */ + +template +template +inline UnitBase& UnitBase::operator=(const UnitBase& unit) +{ + m_impl = unit.m_impl; + return *this; +} + +/* ************************************************************************ */ + +template +template>::value, int>::type> +inline UnitBase::operator ValueType() const noexcept +{ + return get(); +} + +/* ************************************************************************ */ + +template +template>::value, int>::type> +inline UnitBase::operator ValueType() const noexcept +{ + return get(); +} + +/* ************************************************************************ */ + +template +inline UnitBase UnitBase::operator+() const noexcept +{ + return UnitBase(m_impl.value); +} + +/* ************************************************************************ */ + +template +inline UnitBase UnitBase::operator-() const noexcept +{ + return UnitBase(-m_impl.value); +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator+=(UnitBase rhs) noexcept +{ + m_impl.value += rhs.m_impl.value; + return *this; +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator-=(UnitBase rhs) noexcept +{ + m_impl.value -= rhs.m_impl.value; + return *this; +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator*=(ValueType rhs) noexcept +{ + m_impl.value *= rhs; + return *this; +} + +/* ************************************************************************ */ + +template +inline UnitBase& UnitBase::operator/=(ValueType rhs) noexcept +{ + m_impl.value /= rhs; + return *this; +} + +/* ************************************************************************ */ + +template +inline constexpr ValueType UnitBase::get() const noexcept +{ + return m_impl.value; +} + +/* ************************************************************************ */ + +template +inline constexpr ValueType UnitBase::value() const noexcept +{ + return get(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getLengthExp() const noexcept +{ + return m_impl.getLengthExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getTimeExp() const noexcept +{ + return m_impl.getTimeExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getMassExp() const noexcept +{ + return m_impl.getMassExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getCurrentExp() const noexcept +{ + return m_impl.getCurrentExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getTemperatureExp() const noexcept +{ + return m_impl.getTemperatureExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getSubstanceExp() const noexcept +{ + return m_impl.getSubstanceExp(); +} + +/* ************************************************************************ */ + +template +inline constexpr int UnitBase::getIntensityExp() const noexcept +{ + return m_impl.getIntensityExp(); +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail none() noexcept +{ + return {}; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail length(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.length = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail time(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.time = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail mass(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.mass = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail current(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.current = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail temperature(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.temperature = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail substance(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.substance = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail intensity(int dim) noexcept +{ + DynamicImpl::Detail detail{}; + detail.intensity = dim; + return detail; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail operator|(DynamicImpl::Detail lhs, DynamicImpl::Detail rhs) noexcept +{ + lhs.length += rhs.length; + lhs.time += rhs.time; + lhs.mass += rhs.mass; + lhs.current += rhs.current; + lhs.temperature += rhs.temperature; + lhs.substance += rhs.substance; + lhs.intensity += rhs.intensity; + return lhs; +} + +/* ************************************************************************ */ + +inline DynamicImpl::Detail operator/(DynamicImpl::Detail lhs, DynamicImpl::Detail rhs) noexcept +{ + lhs.length -= rhs.length; + lhs.time -= rhs.time; + lhs.mass -= rhs.mass; + lhs.current -= rhs.current; + lhs.temperature -= rhs.temperature; + lhs.substance -= rhs.substance; + lhs.intensity -= rhs.intensity; + return lhs; +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator==(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + static_assert(detail::ImplHelper::isRelSupported, "Can't compare those units"); + + return std::abs(lhs.get() - rhs.get()) < std::numeric_limits::epsilon(); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator==(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return std::abs(lhs.get()) < std::numeric_limits::epsilon(); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator==(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return std::abs(rhs.get()) < std::numeric_limits::epsilon(); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator!=(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator!=(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator!=(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + static_assert(detail::ImplHelper::isRelSupported, "Can't compare those units"); + + return lhs.get() < rhs.get(); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return lhs.get() < 0; +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return 0 < rhs.get(); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<=(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + return !operator>(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<=(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return !operator>(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator<=(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return !operator>(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + return operator<(rhs, lhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return operator<(rhs, lhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return operator<(rhs, lhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>=(const UnitBase& lhs, const UnitBase& rhs) noexcept +{ + return !operator<(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>=(const UnitBase& lhs, math::Zero_t rhs) noexcept +{ + return !operator<(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr bool operator>=(math::Zero_t lhs, const UnitBase& rhs) noexcept +{ + return !operator<(lhs, rhs); +} + +/* ************************************************************************ */ + +template +inline constexpr auto operator+(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::AddImplType> +{ + static_assert(detail::ImplHelper::isAddSupported, "Can't add those units"); + + return UnitBase::AddImplType>( + lhs.get() + rhs.get() + ); +} + +/* ************************************************************************ */ + +template +inline constexpr auto operator-(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::SubImplType> +{ + static_assert(detail::ImplHelper::isSubSupported, "Can't subtract those units"); + + return UnitBase::SubImplType>( + lhs.get() - rhs.get() + ); +} + +/* ************************************************************************ */ + +template +inline constexpr auto operator*(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::MulImplType> +{ + return UnitBase::MulImplType>( + lhs.get() * rhs.get() + ); +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase operator*(UnitBase lhs, RealType rhs) noexcept +{ + return lhs *= rhs; +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase operator*(RealType lhs, UnitBase rhs) noexcept +{ + return rhs *= lhs; +} + +/* ************************************************************************ */ + +template +inline constexpr auto operator/(const UnitBase& lhs, const UnitBase& rhs) noexcept + -> UnitBase::DivImplType> +{ + return UnitBase::DivImplType>( + lhs.get() / rhs.get() + ); +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase operator/(UnitBase lhs, RealType rhs) noexcept +{ + return lhs /= rhs; +} + +/* ************************************************************************ */ + +template +inline constexpr auto operator/(RealType lhs, const UnitBase& rhs) noexcept + -> UnitBase::ImplType> +{ + return UnitBase::ImplType>(lhs / rhs.get()); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/String.hpp b/include/cece/unit/UnitIo.hpp similarity index 50% rename from cece/core/String.hpp rename to include/cece/unit/UnitIo.hpp index 35d03da..527fa71 100644 --- a/cece/core/String.hpp +++ b/include/cece/unit/UnitIo.hpp @@ -27,245 +27,165 @@ /* ************************************************************************ */ -// C++ -#include -#ifdef _WIN32 -# include -# include -#endif +// CeCe +#include "cece/Function.hpp" +#include "cece/StringView.hpp" +#include "cece/unit/Unit.hpp" +#include "cece/io/InStream.hpp" +#include "cece/io/OutStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace unit { /* ************************************************************************ */ /** - * @brief String type. - */ -using String = std::string; - -/* ************************************************************************ */ - -/** - * @brief Converts integer value to string. + * @brief Parse units value. * - * @param value Input value. + * @param[in] beg The string beginning. + * @param end The string end. After return it can be used as a pointer + * where the parsing ended. * - * @return String value. + * @return Result value. */ -inline String toString(int value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%d", value); - return buffer; - } -#else - return std::to_string(value); -#endif -} +Unit parse(const char* beg, const char*& end); /* ************************************************************************ */ /** - * @brief Converts long value to string. + * @brief Parse units value. + * + * @details This function can handle unit suffix and convert it into proper + * coefficient. + * + * @note Unit prefix is not supported because there is issue with meters: + * `mg` - it's milligram or metergram? * - * @param value Input value. + * @param is Input stream. * - * @return String value. + * @return Result value. */ -inline String toString(long value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%ld", value); - return buffer; - } -#else - return std::to_string(value); -#endif -} +Unit parse(io::InStream& is); /* ************************************************************************ */ /** - * @brief Converts long long value to string. + * @brief Parse units value. + * + * @details This function can handle unit suffix and convert it into proper + * coefficient. * - * @param value Input value. + * @note Unit prefix is not supported because there is issue with meters: + * `mg` - it's milligram or metergram? * - * @return String value. + * @param value Value to parse. + * + * @return Result value. */ -#ifndef _WIN32 -inline String toString(long long value) -{ - return std::to_string(value); -} -#endif +Unit parse(StringView value); /* ************************************************************************ */ /** - * @brief Converts unsigned value to string. + * @brief Register user defined symbol converter. * - * @param value Input value. + * @details Adds user defined symbol so for 'km' when it parse '15km' the + * `parse` function invoke given function with argument `15`. * - * @return String value. + * @param[in] name The symbol name. + * @param[in] fn The conversion function. */ -inline String toString(unsigned value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%u", value); - return buffer; - } -#else - return std::to_string(value); -#endif -} +void registerSymbol(String name, Function fn); /* ************************************************************************ */ /** - * @brief Converts unsigned long value to string. + * @brief Remove symbol from list. * - * @param value Input value. + * @param[in] name The symbol name. * - * @return String value. + * @note If conversion function is provided by plugin it should be + * unregistred before the plugin is unloaded because the function + * code might be in plugin code and after unload it will not be + * available to execute. */ -inline String toString(unsigned long value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%lu", value); - return buffer; - } -#else - return std::to_string(value); -#endif -} +void unregisterSymbol(StringView name); /* ************************************************************************ */ /** - * @brief Converts unsigned long long value to string. + * @brief Input stream operator. + * + * @param is Input stream. + * @param unit Result value. * - * @param value Input value. + * @tparam Impl Unit implementation. * - * @return String value. + * @return is. */ -inline String toString(unsigned long long value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%lu", static_cast(value)); - return buffer; - } -#else - return std::to_string(value); -#endif -} +template +io::InStream& operator>>(io::InStream& is, UnitBase& unit); /* ************************************************************************ */ /** - * @brief Converts float value to string. + * @brief Output stream operator. + * + * @param os Output stream. + * @param unit Input value. * - * @param value Input value. + * @tparam Impl The unit implementation. * - * @return String value. + * @return os. */ -inline String toString(float value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%f", value); - return buffer; - } -#else - return std::to_string(value); -#endif -} +template +io::OutStream& operator<<(io::OutStream& os, const UnitBase& unit) noexcept; /* ************************************************************************ */ -/** - * @brief Converts double value to string. - * - * @param value Input value. - * - * @return String value. - */ -inline String toString(double value) -{ -#if defined(_WIN32) - { - char buffer[64]; - snprintf(buffer, sizeof buffer, "%f", value); - return buffer; - } -#else - return std::to_string(value); -#endif +} } +/* ************************************************************************ */ +/* ************************************************************************ */ /* ************************************************************************ */ -/** - * @brief Converts long double value to string. - * - * @param value Input value. - * - * @return String value. - */ -#ifndef _WIN32 -inline String toString(long double value) -{ - return std::to_string(value); -} -#endif +namespace cece { +namespace unit { /* ************************************************************************ */ -/** - * @brief Converts string value to integer. - * - * @param value Input value. - * - * @return Parsed value. - */ -inline int str2i(const String& value) +template +inline io::InStream& operator>>(io::InStream& is, UnitBase& unit) { -#if defined(_WIN32) - return std::atoi(value.c_str()); -#else - return std::stoi(value); -#endif + // Parse unit and convert from dynamic to static or dynamic + unit = parse(is); + + return is; } /* ************************************************************************ */ /** - * @brief Converts string value to integer. + * @brief Output stream operator. * - * @param value Input value. + * @param os Output stream. + * @param unit Input value. * - * @return Parsed value. + * @tparam Impl The unit implementation. + * + * @return os. */ -inline float str2f(const String& value) +template +inline io::OutStream& operator<<(io::OutStream& os, const UnitBase& unit) noexcept { -#if defined(_WIN32) - return static_cast(std::atof(value.c_str())); -#else - return std::stof(value); -#endif + os << unit.get(); + + // TODO: write suffix + + return os; } /* ************************************************************************ */ diff --git a/cece/core/Map.hpp b/include/cece/unit/UnitSymbol.hpp similarity index 93% rename from cece/core/Map.hpp rename to include/cece/unit/UnitSymbol.hpp index fe12002..c249810 100644 --- a/cece/core/Map.hpp +++ b/include/cece/unit/UnitSymbol.hpp @@ -27,24 +27,23 @@ /* ************************************************************************ */ -// C++ -#include +// CeCe +#include "cece/unit/Units.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace unit { /* ************************************************************************ */ /** - * @brief Map class. + * @brief Symbol for specified unit type. * - * @tparam K - * @tparam T + * @tparam UnitType */ -template -using Map = std::map; +template +struct Symbol; /* ************************************************************************ */ diff --git a/include/cece/unit/Units.def b/include/cece/unit/Units.def new file mode 100644 index 0000000..52a477e --- /dev/null +++ b/include/cece/unit/Units.def @@ -0,0 +1,125 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#ifndef CECE_UNIT_SYMBOL +#define CECE_UNIT_SYMBOL(unit, base, sym, def) +#endif + +#ifndef CECE_UNIT_SYMBOL_BASE +#define CECE_UNIT_SYMBOL_BASE(unit, base, sym) CECE_UNIT_SYMBOL(unit, base, sym, 1) +#endif + +/* ************************************************************************ */ + +CECE_UNIT_SYMBOL_BASE(Length, m, "m") +CECE_UNIT_SYMBOL(Length, dm, "dm", m(1e-1)) +CECE_UNIT_SYMBOL(Length, cm, "cm", m(1e-2)) +CECE_UNIT_SYMBOL(Length, mm, "mm", m(1e-3)) +CECE_UNIT_SYMBOL(Length, um, "um", m(1e-6)) +CECE_UNIT_SYMBOL(Length, nm, "nm", m(1e-9)) +CECE_UNIT_SYMBOL(Length, pm, "pm", m(1e-12)) + +CECE_UNIT_SYMBOL_BASE(Mass, g, "g") +CECE_UNIT_SYMBOL(Mass, kg, "kg", g(1e3)) +CECE_UNIT_SYMBOL(Mass, mg, "mg", g(1e-3)) +CECE_UNIT_SYMBOL(Mass, ug, "ug", g(1e-6)) +CECE_UNIT_SYMBOL(Mass, ng, "ng", g(1e-9)) +CECE_UNIT_SYMBOL(Mass, pg, "pg", g(1e-12)) + +CECE_UNIT_SYMBOL_BASE(Time, s, "s") +CECE_UNIT_SYMBOL(Time, ms, "ms", s(1e-3)) +CECE_UNIT_SYMBOL(Time, us, "us", s(1e-6)) +CECE_UNIT_SYMBOL(Time, ns, "ns", s(1e-9)) +CECE_UNIT_SYMBOL(Time, min, "min", s(60)) +CECE_UNIT_SYMBOL(Time, h, "h", min(60)) + +CECE_UNIT_SYMBOL(Area, m2, "m2", m(1) * m(1)) +CECE_UNIT_SYMBOL(Area, dm2, "dm2", dm(1) * dm(1)) +CECE_UNIT_SYMBOL(Area, cm2, "cm2", cm(1) * cm(1)) +CECE_UNIT_SYMBOL(Area, mm2, "mm2", mm(1) * mm(1)) +CECE_UNIT_SYMBOL(Area, um2, "um2", um(1) * um(1)) + +CECE_UNIT_SYMBOL(Volume, m3, "m3", m2(1) * m(1)) +CECE_UNIT_SYMBOL(Volume, dm3, "dm3", dm2(1) * dm(1)) +CECE_UNIT_SYMBOL(Volume, cm3, "cm3", cm2(1) * cm(1)) +CECE_UNIT_SYMBOL(Volume, mm3, "mm3", mm2(1) * mm(1)) +CECE_UNIT_SYMBOL(Volume, um3, "um3", um2(1) * um(1)) + +CECE_UNIT_SYMBOL(Velocity, m_s, "m/s", m(1) / s(1)) +CECE_UNIT_SYMBOL(Velocity, mm_s, "mm/s", mm(1) / s(1)) +CECE_UNIT_SYMBOL(Velocity, um_s, "um/s", um(1) / s(1)) + +CECE_UNIT_SYMBOL(Acceleration, m_s2, "m/s2", m_s(1) / s(1)) +CECE_UNIT_SYMBOL(Acceleration, mm_s2, "mm/s2", mm_s(1) / s(1)) +CECE_UNIT_SYMBOL(Acceleration, um_s2, "um/s2", um_s(1) / s(1)) + +CECE_UNIT_SYMBOL(Force, kgm_s2, "kgm/s2", kg(1) * m_s2(1)) +CECE_UNIT_SYMBOL(Force, gm_s2, "gm/s2", g(1) * m_s2(1)) +CECE_UNIT_SYMBOL(Force, mgm_s2, "mgm/s2", mg(1) * m_s2(1)) +CECE_UNIT_SYMBOL(Force, N, "N", kgm_s2(1)) +CECE_UNIT_SYMBOL(Force, mN, "mN", gm_s2(1)) +CECE_UNIT_SYMBOL(Force, uN, "uN", mgm_s2(1)) + +CECE_UNIT_SYMBOL(DynamicViscosity, kg_ms, "kg/ms", kg(1) / m(1) / s(1)) +CECE_UNIT_SYMBOL(DynamicViscosity, g_ms, "g/ms", g(1) / m(1) / s(1)) +CECE_UNIT_SYMBOL(DynamicViscosity, Ns_m2, "Ns/m2", N(1) * s(1) / m2(1)) +CECE_UNIT_SYMBOL(DynamicViscosity, Pas, "Pas", N(1) * s(1) / m2(1)) +CECE_UNIT_SYMBOL(DynamicViscosity, mPas, "mPas", mN(1) * s(1) / m2(1)) + +CECE_UNIT_SYMBOL(KinematicViscosity, m2_s, "m2/s", m2(1) / s(1)) +CECE_UNIT_SYMBOL(KinematicViscosity, mm2_s, "mm2/s", mm2(1) / s(1)) +CECE_UNIT_SYMBOL(KinematicViscosity, um2_s, "um2/s", um2(1) / s(1)) + +CECE_UNIT_SYMBOL_BASE(AmountOfSubstance, mol, "mol") +CECE_UNIT_SYMBOL(AmountOfSubstance, mmol, "mmol", mol(1e-3)) +CECE_UNIT_SYMBOL(AmountOfSubstance, umol, "umol", mmol(1e-3)) +CECE_UNIT_SYMBOL(AmountOfSubstance, nmol, "nmol", umol(1e-3)) + +CECE_UNIT_SYMBOL(MolarConcentration, mol_m3, "mol/m3", mol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, mmol_m3, "mmol/m3", mmol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, umol_m3, "umol/m3", umol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, nmol_m3, "nmol/m3", nmol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, mM, "mM", mol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, uM, "uM", mmol(1) / m3(1)) +CECE_UNIT_SYMBOL(MolarConcentration, nM, "nM", umol(1) / m3(1)) + +CECE_UNIT_SYMBOL_BASE(Angle, rad, "rad") +CECE_UNIT_SYMBOL(Angle, deg, "deg", rad(deg2rad(1))) + +CECE_UNIT_SYMBOL_BASE(Frequency, _s, "/s") +CECE_UNIT_SYMBOL(Frequency, Hz, "Hz", _s(1)) +CECE_UNIT_SYMBOL(Frequency, kHz, "kHz", Hz(1e3)) +CECE_UNIT_SYMBOL(Frequency, MHz, "MHz", kHz(1e3)) +CECE_UNIT_SYMBOL(Frequency, GHz, "GHz", MHz(1e3)) +CECE_UNIT_SYMBOL(Frequency, THz, "THz", GHz(1e3)) + +CECE_UNIT_SYMBOL(Probability, precent, "%", 1 / 100.0) + +/* ************************************************************************ */ + +#undef CECE_UNIT_SYMBOL_BASE +#undef CECE_UNIT_SYMBOL + +/* ************************************************************************ */ diff --git a/cece/core/Units.hpp b/include/cece/unit/Units.hpp similarity index 53% rename from cece/core/Units.hpp rename to include/cece/unit/Units.hpp index 6cdccdc..ad6770d 100644 --- a/cece/core/Units.hpp +++ b/include/cece/unit/Units.hpp @@ -28,210 +28,194 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Unit.hpp" +#include "cece/unit/Unit.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace unit { /* ************************************************************************ */ -namespace units { +/** + * @brief Type without units. + */ +using None = UnitBase>; /* ************************************************************************ */ /** - * @brief Type without units. + * @brief Class for representing distance (meters). */ -using None = Unit, List<>>; +template +using BaseLength = UnitBase>; /* ************************************************************************ */ /** - * @brief Class for representing distance (meters). + * @brief Class for representing distance (meters). */ -using Length = Unit, List<>>; +using Length = BaseLength<1>; /* ************************************************************************ */ /** - * @brief Class for representing mass (kilograms). + * @brief Class for representing time (seconds). */ -using Mass = Unit, List<>>; +template +using BaseTime = UnitBase>; /* ************************************************************************ */ /** - * @brief Class for representing time (seconds). + * @brief Class for representing time (seconds). */ -using Time = Unit, List<>>; +using Time = BaseTime<1>; + +// @deprecated using Duration = Time; /* ************************************************************************ */ /** - * @brief Class for representing area. + * @brief Class for representing mass (kilograms). */ -using Area = Unit, List<>>; +template +using BaseMass = UnitBase>; /* ************************************************************************ */ /** - * @brief Class for representing volume. + * @brief Class for representing mass (kilograms). */ -using Volume = Unit, List<>>; +using Mass = BaseMass<1>; /* ************************************************************************ */ /** - * @brief Class for representing velocity (micrometers per second). + * @brief Class for representing area. */ -using Velocity = Unit, List>; +using Area = BaseLength<2>; /* ************************************************************************ */ /** - * @brief Class for representing acceleration (micrometers per second^2). + * @brief Class for representing volume. */ -using Acceleration = Unit, List>; +using Volume = BaseLength<3>; /* ************************************************************************ */ /** - * @brief Class for representing force (Newton). + * @brief Class for representing velocity (micrometers per second). */ -using Force = Unit, List>; +using Velocity = Compose>::type; /* ************************************************************************ */ /** - * @brief Class for representing impulse. + * @brief Class for representing acceleration (micrometers per second^2). */ -using Impulse = Unit, List>; +using Acceleration = Compose>::type; /* ************************************************************************ */ /** - * @brief Class for representing density. + * @brief Class for representing force (Newton). */ -using Density = Unit, List>; +using Force = Compose>::type; /* ************************************************************************ */ /** - * @brief Class for representing dynamic viscosity. + * @brief Class for representing impulse. */ -using DynamicViscosity = Unit, List>; +using Impulse = Compose>::type; /* ************************************************************************ */ /** - * @brief Class for representing kinematic viscosity. + * @brief Class for representing density. */ -using KinematicViscosity = Unit, List>; +using Density = Compose>::type; /* ************************************************************************ */ /** - * @brief Amount of substance. + * @brief Class for representing dynamic viscosity. */ -using AmountOfSubstance = Unit, List<>>; +using DynamicViscosity = Compose, BaseTime<-1>>::type; /* ************************************************************************ */ /** - * @brief Number concentration. + * @brief Class for representing kinematic viscosity. */ -using NumberConcentration = Unit, List>; +using KinematicViscosity = Compose>::type; /* ************************************************************************ */ /** - * @brief Molar concentration. + * @brief Amount of substance. */ -using MolarConcentration = Unit, List>; +template +using BaseAmountOfSubstance = UnitBase>; /* ************************************************************************ */ /** - * @brief Class for representing angle. + * @brief Amount of substance. */ -using Angle = Unit, List<>>; +using AmountOfSubstance = BaseAmountOfSubstance<1>; /* ************************************************************************ */ /** - * @brief Class for representing angular velocity (radian per second). + * @brief Number concentration. */ -using AngularVelocity = Unit, List>; +using NumberConcentration = BaseLength<-3>; /* ************************************************************************ */ /** - * @brief Class for representing probability. + * @brief Molar concentration. */ -using Probability = Unit, List<>>; +using MolarConcentration = Compose>::type; /* ************************************************************************ */ /** - * @brief Volumeric flow rate. + * @brief Class for representing angle. */ -using VolumericFlow = Unit, List>; +using Angle = None; /* ************************************************************************ */ /** - * @brief Convert degrees to radians. - * - * @param value - * - * @return + * @brief Class for representing angular velocity (radian per second). */ -inline constexpr Value deg2rad(Value value) noexcept -{ - return value * 0.01745329252f; -} +using AngularVelocity = BaseTime<-1>; /* ************************************************************************ */ /** - * @brief Convert radians to degrees. - * - * @param value - * - * @return + * @brief Class for representing probability. */ -inline constexpr Value rad2deg(Value value) noexcept -{ - return value * 57.2957795f; -} +using Probability = None; /* ************************************************************************ */ -extern template class Unit, List<>>; -extern template class Unit, List<>>; -extern template class Unit, List<>>; -extern template class Unit, List<>>; -extern template class Unit, List<>>; -extern template class Unit, List<>>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List<>>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; -extern template class Unit, List>; +/** + * @brief Volumeric flow rate. + */ +using VolumericFlow = Compose>::type; /* ************************************************************************ */ -} +/** + * @brief Frequency. + */ +using Frequency = BaseTime<-1>; /* ************************************************************************ */ diff --git a/include/cece/unit/UnitsCtors.hpp b/include/cece/unit/UnitsCtors.hpp new file mode 100644 index 0000000..ae0ec5e --- /dev/null +++ b/include/cece/unit/UnitsCtors.hpp @@ -0,0 +1,72 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/unit/math.hpp" +#include "cece/unit/Units.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +/// Base units exponents +/// @deprecated +static constexpr int LENGTH_EXPONENT = 6; +static constexpr int TIME_EXPONENT = 0; +static constexpr int MASS_EXPONENT = 6; +static constexpr int ELECTRIC_CURRENT_EXPONENT = 0; +static constexpr int THERMODYNAMIC_TEMPERATURE_EXPONENT = 0; +static constexpr int AMOUNT_OF_SUBSTANCE_EXPONENT = 6; +static constexpr int LUMINOUS_INTENSITY_EXPONENT = 0; + +/* ************************************************************************ */ + +#define CECE_UNIT_SYMBOL_BASE(unit, name, sym) \ + inline constexpr unit name(ValueType value) noexcept \ + { \ + return unit(value); \ + } + +#define CECE_UNIT_SYMBOL(unit, name, sym, def) \ + inline constexpr unit name(ValueType value) noexcept \ + { \ + return value * def; \ + } + +#include "Units.def" + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/VectorUnits.hpp b/include/cece/unit/VectorUnits.hpp similarity index 69% rename from cece/core/VectorUnits.hpp rename to include/cece/unit/VectorUnits.hpp index 31c48c7..2cecbdd 100644 --- a/cece/core/VectorUnits.hpp +++ b/include/cece/unit/VectorUnits.hpp @@ -28,67 +28,73 @@ /* ************************************************************************ */ // CeCe -#include "cece/core/Real.hpp" -#include "cece/core/Units.hpp" -#include "cece/core/Vector.hpp" +#include "cece/common.hpp" +#include "cece/math/Vector.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace unit { /* ************************************************************************ */ -namespace units { +/** + * @brief Position vector structure. + * @deprecated + */ +using PositionVector = math::Vector; /* ************************************************************************ */ /** - * @brief Position vector structure. + * @brief Position vector structure. */ -using PositionVector = Vector; +using LengthVector = math::Vector; /* ************************************************************************ */ /** - * @brief Velocity vector structure. + * @brief Velocity vector structure. */ -using VelocityVector = Vector; +using VelocityVector = math::Vector; /* ************************************************************************ */ /** - * @brief Acceleration vector structure. + * @brief Acceleration vector structure. */ -using AccelerationVector = Vector; +using AccelerationVector = math::Vector; /* ************************************************************************ */ /** - * @brief Force vector structure. + * @brief Force vector structure. */ -using ForceVector = Vector; +using ForceVector = math::Vector; /* ************************************************************************ */ /** - * @brief Impulse vector structure. + * @brief Impulse vector structure. */ -using ImpulseVector = Vector; +using ImpulseVector = math::Vector; /* ************************************************************************ */ /** - * @brief Scale vector. + * @brief Scale vector. + * @deprecated */ -using ScaleVector = Vector; +using ScaleVector = math::Vector; /* ************************************************************************ */ /** - * @brief Size vector. + * @brief Size vector. + * @deprecated */ -using SizeVector = Vector; +using SizeVector = math::Vector; /* ************************************************************************ */ @@ -96,16 +102,23 @@ using SizeVector = Vector; /* ************************************************************************ */ -extern template class BasicVector; -extern template class BasicVector; -extern template class BasicVector; -extern template class BasicVector; -extern template class BasicVector; -extern template class BasicVector; +namespace math { + +/* ************************************************************************ */ + +extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; +extern template class BasicVector; /* ************************************************************************ */ } + +/* ************************************************************************ */ + } /* ************************************************************************ */ diff --git a/include/cece/unit/math.hpp b/include/cece/unit/math.hpp new file mode 100644 index 0000000..100621f --- /dev/null +++ b/include/cece/unit/math.hpp @@ -0,0 +1,217 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// CeCe +#include "cece/math/constants.hpp" +#include "cece/unit/Unit.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +namespace detail { + +/* ************************************************************************ */ + +/** + * @brief Square root helper. + * + * @tparam Impl Implementation detail. + */ +template +struct SqrtHelper; + +/* ************************************************************************ */ + +/** + * @brief Square root helper. + * + * @tparam Length Number of length units. + * @tparam Time Number of time units. + * @tparam Mass Number of mass units. + * @tparam Current Number of electrical current units. + * @tparam Temperature Number of temperature units. + * @tparam Substance Number of amount of substance units. + * @tparam Intensity Number of intensity units. + */ +template< + int Length, + int Time, + int Mass, + int Current, + int Temperature, + int Substance, + int Intensity +> +struct SqrtHelper> +{ + + // Calculate if unit can be used as sqrt argument. + static constexpr bool isValid = + Length % 2 == 0 && + Time % 2 == 0 && + Mass % 2 == 0 && + Current % 2 == 0 && + Temperature % 2 == 0 && + Substance % 2 == 0 && + Intensity % 2 == 0 + ; + + using ImplType = StaticImpl< + Length / 2, + Time / 2, + Mass / 2, + Current / 2, + Temperature / 2, + Substance / 2, + Intensity / 2 + >; +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +/** + * @brief Calculate square root of given unit. + * + * @param[in] value The unit value. + * + * @tparam Impl The unit implementation. + * + * @return The square root value. + */ +template +auto sqrt(UnitBase value) noexcept -> UnitBase::ImplType>; + +/* ************************************************************************ */ + +/** + * @brief Calculate absolute value. + * + * @param unit The unit. + * + * @tparam Impl The unit implementation. + * + * @return The absolute value. + */ +template +constexpr UnitBase abs(UnitBase unit) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Convert degrees to radians. + * + * @param value Degrees. + * + * @return Radians + */ +constexpr ValueType deg2rad(ValueType value) noexcept; + +/* ************************************************************************ */ + +/** + * @brief Convert radians to degrees. + * + * @param value Radians. + * + * @return Degrees. + */ +constexpr ValueType rad2deg(ValueType value) noexcept; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ +/* ************************************************************************ */ +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +template +inline auto sqrt(UnitBase value) noexcept + -> UnitBase::ImplType> +{ + static_assert(detail::SqrtHelper::isValid, "Unit cannot be used as sqrt argument"); + + return UnitBase::ImplType>( + std::sqrt(value.get()) + ); +} + +/* ************************************************************************ */ + +template +inline constexpr UnitBase abs(UnitBase unit) noexcept +{ + return UnitBase(unit.get() > ValueType(0) + ? unit.get() + : -unit.get() + ); +} + +/* ************************************************************************ */ + +inline constexpr ValueType deg2rad(ValueType value) noexcept +{ + return value * math::PI / 180.0; +} + +/* ************************************************************************ */ + +inline constexpr ValueType rad2deg(ValueType value) noexcept +{ + return value * 180.0 / math::PI; +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/render/shaders/colormap.glsl b/resources/shaders/colormap.glsl similarity index 100% rename from cece/render/shaders/colormap.glsl rename to resources/shaders/colormap.glsl diff --git a/cece/render/shaders/smooth.glsl b/resources/shaders/smooth.glsl similarity index 100% rename from cece/render/shaders/smooth.glsl rename to resources/shaders/smooth.glsl diff --git a/scripts/shader-convert.py b/scripts/shader-convert.py index cdb8f5e..393d543 100755 --- a/scripts/shader-convert.py +++ b/scripts/shader-convert.py @@ -37,7 +37,7 @@ def convert(fOut, symbol, code): """ valueCounter = 0; - fOut.write("#include \"cece/core/StaticArray.hpp\"\n") + fOut.write("#include \"cece/StaticArray.hpp\"\n") fOut.write("\n"); fOut.write("// " + datetime.datetime.now().isoformat() + "\n"); fOut.write("// #" + str(hashlib.md5(code).hexdigest()) + "\n"); diff --git a/cece/core/AlignedAllocator.cpp b/src/AlignedAllocator.cpp similarity index 93% rename from cece/core/AlignedAllocator.cpp rename to src/AlignedAllocator.cpp index cc0892d..046c86d 100644 --- a/cece/core/AlignedAllocator.cpp +++ b/src/AlignedAllocator.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/AlignedAllocator.hpp" +#include "cece/AlignedAllocator.hpp" // C++ #include @@ -34,7 +34,7 @@ #endif // CeCe -#include "cece/core/Assert.hpp" +#include "cece/Assert.hpp" /* ************************************************************************ */ @@ -46,8 +46,10 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { -namespace memory { + +/* ************************************************************************ */ + +namespace { /* ************************************************************************ */ @@ -63,6 +65,10 @@ bool is_power_of_two(std::size_t x) noexcept /* ************************************************************************ */ +} + +/* ************************************************************************ */ + void* allocate_aligned_memory(std::size_t align, std::size_t size) { CECE_ASSERT(align >= sizeof(void*)); @@ -97,8 +103,6 @@ void deallocate_aligned_memory(void* ptr) noexcept /* ************************************************************************ */ -} -} } /* ************************************************************************ */ diff --git a/cece/CMakeLists.txt b/src/CMakeLists.txt similarity index 74% rename from cece/CMakeLists.txt rename to src/CMakeLists.txt index 2d2a3c0..b3af33d 100644 --- a/cece/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,8 @@ # ######################################################################### # # Create config file -configure_file(config.hpp.in config.hpp) +configure_file(config.hpp.in cece/config.hpp) +configure_file(version.hpp.in cece/version.hpp) # ######################################################################### # @@ -43,14 +44,21 @@ endfunction () # ######################################################################### # +set(CECE_SOURCES + Parameters.cpp + AlignedAllocator.cpp + String.cpp +) + # Core files -add_subdirectory(core) add_subdirectory(config) -add_subdirectory(loader) -add_subdirectory(init) -add_subdirectory(module) -add_subdirectory(object) -add_subdirectory(program) +add_subdirectory(os) +add_subdirectory(io) +add_subdirectory(log) +add_subdirectory(unit) +add_subdirectory(math) +add_subdirectory(lang) +add_subdirectory(perf) add_subdirectory(plugin) # Renderer files @@ -59,29 +67,12 @@ if (CECE_RENDER) endif () # Simulation files -add_subdirectory(simulator) +add_subdirectory(simulation) # ######################################################################### # -# Sources -set(SRCS - ${SOURCES_CORE} - ${SOURCES_CONFIG} - ${SOURCES_LOADER} - ${SOURCES_INIT} - ${SOURCES_MODULE} - ${SOURCES_OBJECT} - ${SOURCES_PROGRAM} - ${SOURCES_PLUGIN} - ${SOURCES_SIMULATOR} -) - -if (CECE_RENDER) - set(SRCS ${SRCS} ${SOURCES_RENDER}) -endif () - # Create library -add_library(${PROJECT_NAME} SHARED ${SRCS}) +add_library(${PROJECT_NAME} SHARED ${CECE_SOURCES}) # ######################################################################### # @@ -103,16 +94,34 @@ endif () # Include directories target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_BINARY_DIR}/.. + ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_BINARY_DIR} ) # Generate export header (MSVC) include(GenerateExportHeader) generate_export_header(${PROJECT_NAME} - EXPORT_FILE_NAME "export.hpp" + EXPORT_FILE_NAME "cece/export.hpp" ) +# Compiler warnings +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4) +else () + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif () + +# Export all for MINGW +if (MINGW) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols") +endif () + +if (CMAKE_COMPILER_IS_GNUCXX AND CECE_TESTS_BUILD AND CECE_COVERAGE) + target_compile_options(${PROJECT_NAME} PRIVATE --coverage) + target_link_libraries(${PROJECT_NAME} PRIVATE --coverage) +endif () + # ######################################################################### # # Link Box2D internally @@ -123,34 +132,11 @@ if (CECE_RENDER) # OpenGL library is required find_package(OpenGL REQUIRED) target_include_directories(${PROJECT_NAME} PUBLIC ${OPENGL_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENGL_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) endif () if (UNIX AND NOT APPLE) - target_link_libraries(${PROJECT_NAME} PUBLIC dl) -endif () - -# ######################################################################### # - -if (CECE_TESTS_BUILD) - add_executable(${PROJECT_NAME}_test - ${SOURCES_CORE_TEST} - ${SOURCES_RENDER_TEST} - ) - - # Properties - set_target_properties(${PROJECT_NAME}_test PROPERTIES - CXX_STANDARD 11 - CXX_EXTENSIONS Off - CXX_STANDARD_REQUIRED On - ) - - target_link_libraries(${PROJECT_NAME}_test - ${PROJECT_NAME} - gtest_main - ) - - add_test(${PROJECT_NAME} ${PROJECT_NAME}_test) + target_link_libraries(${PROJECT_NAME} PRIVATE dl) endif () # ######################################################################### # diff --git a/cece/core/Parameters.cpp b/src/Parameters.cpp similarity index 98% rename from cece/core/Parameters.cpp rename to src/Parameters.cpp index 3e45298..27b3f9f 100644 --- a/cece/core/Parameters.cpp +++ b/src/Parameters.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/Parameters.hpp" +#include "cece/Parameters.hpp" // C++ #include @@ -32,7 +32,6 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { /* ************************************************************************ */ @@ -131,7 +130,6 @@ void Parameters::append(const Parameters& parameters) noexcept /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/src/String.cpp b/src/String.cpp new file mode 100644 index 0000000..83ebb18 --- /dev/null +++ b/src/String.cpp @@ -0,0 +1,209 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/String.hpp" + +// C++ +#include +#include + +// CeCe +#include "cece/Assert.hpp" +#include "cece/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { + +/* ************************************************************************ */ + +String toString(int value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%d", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(long value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%ld", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(long long value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%lld", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(unsigned value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%u", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(unsigned long value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%lu", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(unsigned long long value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%llu", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(float value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%f", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(double value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%f", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +String toString(long double value) noexcept +{ + char buffer[64]; + const int count = std::snprintf(buffer, sizeof buffer, "%Lf", value); + CECE_ASSERT(count > 0); + CECE_ASSERT(count <= static_cast(sizeof buffer)); + return String(buffer, count); +} + +/* ************************************************************************ */ + +int str2i(const String& value) +{ + char* end; + int val = std::strtol(value.c_str(), &end, 10); + + if (value.empty() || end != value.c_str() + value.size()) + throw InvalidArgumentException("Cannot convert '" + value + "' to int"); + + return val; +} + +/* ************************************************************************ */ + +long str2l(const String& value) +{ + char* end; + long val = std::strtol(value.c_str(), &end, 10); + + if (value.empty() || end != value.c_str() + value.size()) + throw InvalidArgumentException("Cannot convert '" + value + "' to long"); + + return val; +} + +/* ************************************************************************ */ + +long long str2ll(const String& value) +{ + char* end; + long long val = std::strtoll(value.c_str(), &end, 10); + + if (value.empty() || end != value.c_str() + value.size()) + throw InvalidArgumentException("Cannot convert '" + value + "' to long long"); + + return val; +} + +/* ************************************************************************ */ + +float str2f(const String& value) +{ + char* end; + float val = std::strtof(value.c_str(), &end); + + if (value.empty() || end != value.c_str() + value.size()) + throw InvalidArgumentException("Cannot convert '" + value + "' to float"); + + return val; +} + +/* ************************************************************************ */ + +double str2d(const String& value) +{ + char* end; + double val = std::strtod(value.c_str(), &end); + + if (value.empty() || end != value.c_str() + value.size()) + throw InvalidArgumentException("Cannot convert '" + value + "' to double"); + + return val; +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ diff --git a/cece/config.hpp.in b/src/config.hpp.in similarity index 81% rename from cece/config.hpp.in rename to src/config.hpp.in index c6b3b17..7b1f563 100644 --- a/cece/config.hpp.in +++ b/src/config.hpp.in @@ -35,7 +35,6 @@ */ namespace cece { -namespace config { /* ************************************************************************ */ @@ -48,6 +47,7 @@ namespace config { /** * @brief Enable renderer errors checking. + * @deprecated Private configuration, it doesn't affect others. */ #cmakedefine CECE_RENDER_CHECK_ERRORS @@ -67,34 +67,6 @@ using RealType = ${CECE_REAL_TYPE}; /* ************************************************************************ */ -/** - * @brief CeCe version string. - */ -constexpr auto VERSION_STRING = "${PROJECT_VERSION}"; - -/* ************************************************************************ */ - -/** - * @brief CeCe major version. - */ -constexpr int VERSION_MAJOR = ${PROJECT_VERSION_MAJOR}; - -/* ************************************************************************ */ - -/** - * @brief CeCe minor version. - */ -constexpr int VERSION_MINOR = ${PROJECT_VERSION_MINOR}; - -/* ************************************************************************ */ - -/** - * @brief CeCe patch version. - */ -constexpr int VERSION_PATCH = ${PROJECT_VERSION_PATCH}; - -/* ************************************************************************ */ - /** * @brief Simulator space dimension - only 2D is supported now. * @deprecated @@ -106,11 +78,10 @@ constexpr unsigned int DIMENSION = 2; /** * @brief Plugin API version. */ -constexpr int PLUGIN_API_VERSION = 4; +constexpr int PLUGIN_API_VERSION = 5; /* ************************************************************************ */ -} } /* ************************************************************************ */ diff --git a/cece/config/CMakeLists.txt b/src/config/CMakeLists.txt similarity index 94% rename from cece/config/CMakeLists.txt rename to src/config/CMakeLists.txt index 5c3df08..ba4faec 100644 --- a/cece/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -25,11 +25,9 @@ # Sources set(SRCS - Implementation.hpp Implementation.cpp - Configuration.hpp Configuration.cpp - MemoryImplementation.hpp + Exception.cpp MemoryImplementation.cpp ) @@ -37,6 +35,6 @@ set(SRCS dir_pretend(SOURCES config/ ${SRCS}) -set(SOURCES_CONFIG ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/cece/config/Configuration.cpp b/src/config/Configuration.cpp similarity index 52% rename from cece/config/Configuration.cpp rename to src/config/Configuration.cpp index 18fb9a8..324d3ce 100644 --- a/cece/config/Configuration.cpp +++ b/src/config/Configuration.cpp @@ -27,11 +27,17 @@ #include "cece/config/Configuration.hpp" // C++ +#include #include // CeCe -#include "cece/core/Parameters.hpp" -#include "cece/config/MemoryImplementation.hpp" +#include "cece/Assert.hpp" +#include "cece/Parameters.hpp" +#include "cece/Exception.hpp" +#include "cece/config/Implementation.hpp" + +// Private +#include "MemoryImplementation.hpp" /* ************************************************************************ */ @@ -40,23 +46,116 @@ namespace config { /* ************************************************************************ */ -Configuration::Configuration(ViewPtr parameters) noexcept - : m_impl(makeUnique()) +Configuration::Configuration(UniquePtr impl, ViewPtr parameters) + : m_impl(std::move(impl)) , m_parameters(parameters) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +Configuration::Configuration(ViewPtr parameters) + : Configuration(makeUnique(), parameters) { // Nothign to do } /* ************************************************************************ */ -DynamicArray Configuration::getConfigurations(StringView name) const noexcept +bool Configuration::has(StringView name) const +{ + CECE_ASSERT(m_impl); + return m_impl->has(name); +} + +/* ************************************************************************ */ + +String Configuration::get(StringView name) const +{ + CECE_ASSERT(m_impl); + return replaceParameters(m_impl->get(name)); +} + +/* ************************************************************************ */ + +String Configuration::get(StringView name, String def) const +{ + CECE_ASSERT(m_impl); + return has(name) + ? replaceParameters(m_impl->get(name)) + : std::move(def) + ; +} + +/* ************************************************************************ */ + +void Configuration::set(StringView name, String value) +{ + CECE_ASSERT(m_impl); + m_impl->set(name, std::move(value)); +} + +/* ************************************************************************ */ + +DynamicArray Configuration::getNames() const +{ + CECE_ASSERT(m_impl); + return m_impl->getNames(); +} + +/* ************************************************************************ */ + +bool Configuration::hasContent() const +{ + CECE_ASSERT(m_impl); + return m_impl->hasContent(); +} + +/* ************************************************************************ */ + +String Configuration::getContent() const +{ + CECE_ASSERT(m_impl); + return replaceParameters(m_impl->getContent()); +} + +/* ************************************************************************ */ + +void Configuration::setContent(String content) +{ + CECE_ASSERT(m_impl); + m_impl->setContent(std::move(content)); +} + +/* ************************************************************************ */ + +bool Configuration::hasConfiguration(StringView name) const +{ + CECE_ASSERT(m_impl); + return m_impl->hasChild(name); +} + +/* ************************************************************************ */ + +Configuration Configuration::getConfiguration(StringView name) const { if (!hasConfiguration(name)) - return {}; + throw NotFoundException("No configuration found: " + String(name)); + + auto&& configs = getConfigurations(name); + CECE_ASSERT(!configs.empty()); + return configs[0]; +} + +/* ************************************************************************ */ +DynamicArray Configuration::getConfigurations(StringView name) const +{ DynamicArray res; - for (auto&& ptr : m_impl->getSubs(name)) + CECE_ASSERT(m_impl); + for (auto&& ptr : m_impl->getChilds(name)) res.emplace_back(std::move(ptr), m_parameters); return res; @@ -64,18 +163,37 @@ DynamicArray Configuration::getConfigurations(StringView name) co /* ************************************************************************ */ -void Configuration::copyFrom(const Configuration& config) +DynamicArray Configuration::getConfigurationNames() const +{ + CECE_ASSERT(m_impl); + return m_impl->getChildNames(); +} + +/* ************************************************************************ */ + +Configuration Configuration::addConfiguration(StringView name) +{ + CECE_ASSERT(m_impl); + return Configuration{m_impl->createChild(name)}; +} + +/* ************************************************************************ */ + +void Configuration::append(const Configuration& config) { + // Overwrite values for (const auto& name : config.getNames()) set(name, config.get(name)); - setContent(config.getContent()); + // Set content + if (config.hasContent()) + setContent(config.getContent()); - // Copy subconfigurations + // Append child configurations for (const auto& name : config.getConfigurationNames()) { for (auto&& cfg : config.getConfigurations(name)) - addConfiguration(name).copyFrom(cfg); + addConfiguration(name).append(cfg); } } @@ -84,7 +202,7 @@ void Configuration::copyFrom(const Configuration& config) Configuration Configuration::toMemory() const { Configuration config; - config.copyFrom(*this); + config.append(*this); return config; } @@ -92,6 +210,7 @@ Configuration Configuration::toMemory() const String Configuration::replaceParameters(String str) const { + // No parameters, nothing to replace if (!m_parameters) return str; @@ -107,7 +226,7 @@ String Configuration::replaceParameters(String str) const const auto end = str.find('}', start + 2); if (end == String::npos) - throw InvalidArgumentException("Missing closing parameter character '}' in '" + str + "'"); + throw UnterminatedParameterException(std::move(str)); // Copy name const String name = str.substr(start + 2, (end - start + 1) - 3); @@ -118,7 +237,7 @@ String Configuration::replaceParameters(String str) const }) == name.end(); if (!valid) - throw InvalidArgumentException("Parameter name '" + name + "' contains invalid characters"); + throw InvalidParameterNameException(std::move(name), std::move(str)); // Try to find parameter const auto value = m_parameters->get(name); diff --git a/cece/plugin/Repository.cpp b/src/config/Exception.cpp similarity index 81% rename from cece/plugin/Repository.cpp rename to src/config/Exception.cpp index d5fb686..a807667 100644 --- a/cece/plugin/Repository.cpp +++ b/src/config/Exception.cpp @@ -24,29 +24,30 @@ /* ************************************************************************ */ // Declaration -#include "cece/plugin/Repository.hpp" - -// CeCe -#include "cece/core/Log.hpp" +#include "cece/config/Exception.hpp" /* ************************************************************************ */ namespace cece { -namespace plugin { +namespace config { /* ************************************************************************ */ -RepositoryRecord& Repository::registerApi(ViewPtr api) noexcept +UnterminatedParameterException::UnterminatedParameterException(String text) + : Exception("Missing parameter closing character '}' in '" + text + "'") + , m_text(std::move(text)) { - auto it = m_records.emplace(api, RepositoryRecord{}); - return it.first->second; + // Nothing to do } /* ************************************************************************ */ -void Repository::unregisterApi(ViewPtr api) noexcept +InvalidParameterNameException::InvalidParameterNameException(String name, String text) + : Exception("Parameter name '" + name + "' contains invalid characters. In the '" + text + "'") + , m_name(std::move(name)) + , m_text(std::move(text)) { - m_records.erase(api); + // Nothing to do } /* ************************************************************************ */ diff --git a/cece/config/Implementation.cpp b/src/config/Implementation.cpp similarity index 100% rename from cece/config/Implementation.cpp rename to src/config/Implementation.cpp diff --git a/src/config/MemoryImplementation.cpp b/src/config/MemoryImplementation.cpp new file mode 100644 index 0000000..412cd0c --- /dev/null +++ b/src/config/MemoryImplementation.cpp @@ -0,0 +1,216 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "MemoryImplementation.hpp" + +// CeCe +#include "cece/Assert.hpp" +#include "cece/config/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace config { + +/* ************************************************************************ */ + +struct MemoryData +{ + /// Stored values. + StringMap values; + + /// Stored content. + String content; + + /// Child data + StringMap>> data; +}; + +/* ************************************************************************ */ + +MemoryImplementation::MemoryImplementation() + : MemoryImplementation(makeShared()) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +MemoryImplementation::MemoryImplementation(SharedPtr data) + : m_data(std::move(data)) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +bool MemoryImplementation::has(StringView name) const +{ + CECE_ASSERT(m_data); +#if __cplusplus >= 201402L + return m_data->values.find(name) != m_data->values.end(); +#else + return m_data->values.find(String(name)) != m_data->values.end(); +#endif +} + +/* ************************************************************************ */ + +String MemoryImplementation::get(StringView name) const +{ + CECE_ASSERT(m_data); +#if __cplusplus >= 201402L + auto it = m_data->values.find(name); +#else + auto it = m_data->values.find(String(name)); +#endif + + if (it == m_data->values.end()) + throw NotFoundException("No value found: " + String(name)); + + return it->second; +} + +/* ************************************************************************ */ + +void MemoryImplementation::set(StringView name, String value) +{ + CECE_ASSERT(m_data); + m_data->values[String(name)] = std::move(value); +} + +/* ************************************************************************ */ + +DynamicArray MemoryImplementation::getNames() const +{ + CECE_ASSERT(m_data); + + DynamicArray names; + names.reserve(m_data->values.size()); + + for (const auto& p : m_data->values) + names.push_back(p.first); + + return names; +} + +/* ************************************************************************ */ + +bool MemoryImplementation::hasContent() const +{ + CECE_ASSERT(m_data); + return !m_data->content.empty(); +} + +/* ************************************************************************ */ + +String MemoryImplementation::getContent() const +{ + CECE_ASSERT(m_data); + return m_data->content; +} + +/* ************************************************************************ */ + +void MemoryImplementation::setContent(String content) +{ + CECE_ASSERT(m_data); + m_data->content = std::move(content); +} + +/* ************************************************************************ */ + +bool MemoryImplementation::hasChild(StringView name) const +{ + CECE_ASSERT(m_data); +#if __cplusplus >= 201402L + return m_data->data.find(name) != m_data->data.end(); +#else + return m_data->data.find(String(name)) != m_data->data.end(); +#endif +} + +/* ************************************************************************ */ + +PtrDynamicArray MemoryImplementation::getChilds(StringView name) const +{ + CECE_ASSERT(m_data); + + // Find data +#if __cplusplus >= 201402L + auto it = m_data->data.find(name); +#else + auto it = m_data->data.find(String(name)); +#endif + + // Nothing found + if (it == m_data->data.end()) + return {}; + + PtrDynamicArray res; + + for (const auto& ptr : it->second) + res.push_back(makeUnique(ptr)); + + return res; +} + +/* ************************************************************************ */ + +DynamicArray MemoryImplementation::getChildNames() const +{ + CECE_ASSERT(m_data); + + DynamicArray names; + names.reserve(m_data->data.size()); + + for (const auto& p : m_data->data) + names.push_back(p.first); + + return names; +} + +/* ************************************************************************ */ + +UniquePtr MemoryImplementation::createChild(StringView name) +{ + // Create new shared data block + auto data = makeShared(); + + // Register data + CECE_ASSERT(m_data); + m_data->data[String(name)].push_back(data); + + // Create implementation + return makeUnique(std::move(data)); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/config/MemoryImplementation.hpp b/src/config/MemoryImplementation.hpp new file mode 100644 index 0000000..d015692 --- /dev/null +++ b/src/config/MemoryImplementation.hpp @@ -0,0 +1,186 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/String.hpp" +#include "cece/StringView.hpp" +#include "cece/SharedPtr.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/StringMap.hpp" +#include "cece/config/Implementation.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace config { + +/* ************************************************************************ */ + +struct MemoryData; + +/* ************************************************************************ */ + +/** + * @brief Memory configuration implementation. + */ +class MemoryImplementation final : public Implementation +{ + +// Public Ctors & Dtors +public: + + + /** + * @brief Constructor. + */ + MemoryImplementation(); + + + /** + * @brief Constructor. + * + * @param data Managed data. + */ + explicit MemoryImplementation(SharedPtr data); + + +// Public Accessors & Mutators +public: + + + /** + * @brief Check if there is a value stored under given name. + * + * @param name The name. + * + * @return `true` if value is stored, `false` otherwise. + */ + bool has(StringView name) const override; + + + /** + * @brief Returns stored value. + * + * @param name The name. + * + * @return The stored value. + * + * @throws NotFoundException When no value is stored. + */ + String get(StringView name) const override; + + + /** + * @brief Store a value. + * + * @param name The name. + * @param value The value to store. + */ + void set(StringView name, String value) override; + + + /** + * @brief Returns list of names under which values are stored. + * + * @return A list of names. + */ + DynamicArray getNames() const override; + + + /** + * @brief Checks if the configuration contains a content. + * + * @return If content is present. + */ + bool hasContent() const override; + + + /** + * @brief Returns the configuration content. + * + * @return The content with replaced parameters. + */ + String getContent() const override; + + + /** + * @brief Change configuration content. + * + * @param content The new content. + */ + void setContent(String content) override; + + + /** + * @brief Check if at least one child configuration exists. + * + * @param name The child configuration name. + * + * @return `true` if exists, `false` otherwise. + */ + bool hasChild(StringView name) const override; + + + /** + * @brief Returns child configurations with given name. + * + * @param name The child configuration name. + * + * @return List of child configurations. + */ + PtrDynamicArray getChilds(StringView name) const override; + + + /** + * @brief Returns list of available child configuration names. + * + * @return A list of names. + */ + DynamicArray getChildNames() const override; + + + /** + * @brief Create new child configuration. + * + * @param name The child configuration name. + * + * @return New child configuration. + */ + UniquePtr createChild(StringView name) override; + + +// Private Data Members +private: + + /// Shared data. + SharedPtr m_data; +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/program/CMakeLists.txt b/src/io/CMakeLists.txt similarity index 88% rename from cece/program/CMakeLists.txt rename to src/io/CMakeLists.txt index 39bbe0a..e20c54c 100644 --- a/cece/program/CMakeLists.txt +++ b/src/io/CMakeLists.txt @@ -25,21 +25,20 @@ # Sources set(SRCS - Program.hpp - Container.hpp - Container.cpp - NamedContainer.hpp - NamedContainer.cpp - Factory.hpp - Factory.cpp - FactoryManager.hpp - FactoryManager.cpp + FilePath.cpp + CliColor.cpp + CsvFile.cpp + DataExport.cpp + DataExportCsv.cpp + DataExportFactory.cpp + DataExportCsvFactory.cpp + Converter.cpp ) # ######################################################################### # -dir_pretend(SOURCES program/ ${SRCS}) +dir_pretend(SOURCES io/ ${SRCS}) -set(SOURCES_PROGRAM ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/cece/core/CliColor.cpp b/src/io/CliColor.cpp similarity index 99% rename from cece/core/CliColor.cpp rename to src/io/CliColor.cpp index 1e232d4..4c4437d 100644 --- a/cece/core/CliColor.cpp +++ b/src/io/CliColor.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/CliColor.hpp" +#include "cece/io/CliColor.hpp" // Windows #if _WIN32 @@ -34,7 +34,7 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/src/io/Converter.cpp b/src/io/Converter.cpp new file mode 100644 index 0000000..14de524 --- /dev/null +++ b/src/io/Converter.cpp @@ -0,0 +1,140 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/io/Converter.hpp" + +// CeCe +#include "cece/String.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace io { + +/* ************************************************************************ */ + +bool Converter::fromString(const String& value) noexcept +{ + return value == "true"; +} + +/* ************************************************************************ */ + +String Converter::toString(bool value) noexcept +{ + return value ? "true" : "false"; +} + +/* ************************************************************************ */ + +int Converter::fromString(const String& value) +{ + return str2i(value); +} + +/* ************************************************************************ */ + +String Converter::toString(int value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +unsigned int Converter::fromString(const String& value) +{ + return str2i(value); +} + +/* ************************************************************************ */ + +String Converter::toString(unsigned int value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +long Converter::fromString(const String& value) +{ + return str2l(value); +} + +/* ************************************************************************ */ + +String Converter::toString(long value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +unsigned long Converter::fromString(const String& value) +{ + return str2ll(value); +} + +/* ************************************************************************ */ + +String Converter::toString(unsigned long value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +float Converter::fromString(const String& value) +{ + return str2f(value); +} + +/* ************************************************************************ */ + +String Converter::toString(float value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +double Converter::fromString(const String& value) +{ + return str2d(value); +} + +/* ************************************************************************ */ + +String Converter::toString(double value) noexcept +{ + return cece::toString(value); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/CsvFile.cpp b/src/io/CsvFile.cpp similarity index 94% rename from cece/core/CsvFile.cpp rename to src/io/CsvFile.cpp index c802296..1a0689e 100644 --- a/cece/core/CsvFile.cpp +++ b/src/io/CsvFile.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/CsvFile.hpp" +#include "cece/io/CsvFile.hpp" // CeCe -#include "cece/core/Exception.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ -CsvFile::CsvFile(FilePath path) +CsvFile::CsvFile(io::FilePath path) { open(std::move(path)); } @@ -57,7 +57,7 @@ void CsvFile::open() /* ************************************************************************ */ -void CsvFile::open(FilePath path) +void CsvFile::open(io::FilePath path) { m_path = std::move(path); m_file.open(m_path.toString(), std::ios::binary | std::ios::out | std::ios::trunc); diff --git a/cece/core/DataExport.cpp b/src/io/DataExport.cpp similarity index 96% rename from cece/core/DataExport.cpp rename to src/io/DataExport.cpp index cbf17b4..2540b29 100644 --- a/cece/core/DataExport.cpp +++ b/src/io/DataExport.cpp @@ -24,18 +24,18 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/DataExport.hpp" +#include "cece/io/DataExport.hpp" // C++ #include // CeCe -#include "cece/core/DataExportCsvFactory.hpp" +#include "cece/io/DataExportCsvFactory.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ diff --git a/cece/core/DataExportCsv.cpp b/src/io/DataExportCsv.cpp similarity index 95% rename from cece/core/DataExportCsv.cpp rename to src/io/DataExportCsv.cpp index bddf4ea..356daa2 100644 --- a/cece/core/DataExportCsv.cpp +++ b/src/io/DataExportCsv.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/DataExportCsv.hpp" +#include "cece/io/DataExportCsv.hpp" // C++ #include @@ -32,17 +32,17 @@ #include // CeCe -#include "cece/core/DynamicArray.hpp" -#include "cece/core/StringStream.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/io/StringStream.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ -DataExportCsv::DataExportCsv(FilePath path) +DataExportCsv::DataExportCsv(io::FilePath path) : m_file(path.append(".csv")) { // Nothing to do diff --git a/cece/core/DataExportCsvFactory.cpp b/src/io/DataExportCsvFactory.cpp similarity index 95% rename from cece/core/DataExportCsvFactory.cpp rename to src/io/DataExportCsvFactory.cpp index e303659..1e8e6dd 100644 --- a/cece/core/DataExportCsvFactory.cpp +++ b/src/io/DataExportCsvFactory.cpp @@ -24,22 +24,22 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/DataExportCsvFactory.hpp" +#include "cece/io/DataExportCsvFactory.hpp" // C++ #include // CeCe -#include "cece/core/DataExportCsv.hpp" +#include "cece/io/DataExportCsv.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ -UniquePtr DataExportCsvFactory::create(String name) const noexcept +UniquePtr DataExportCsvFactory::create(String name) const { return makeUnique(std::move(name)); } diff --git a/cece/core/DataExportFactory.cpp b/src/io/DataExportFactory.cpp similarity index 94% rename from cece/core/DataExportFactory.cpp rename to src/io/DataExportFactory.cpp index ef4e815..b735075 100644 --- a/cece/core/DataExportFactory.cpp +++ b/src/io/DataExportFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/DataExportFactory.hpp" +#include "cece/io/DataExportFactory.hpp" // CeCe -#include "cece/core/DataExport.hpp" +#include "cece/io/DataExport.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(DataExport, String) +CECE_FACTORY_INST(io::DataExport, String) /* ************************************************************************ */ diff --git a/cece/core/FilePath.cpp b/src/io/FilePath.cpp similarity index 78% rename from cece/core/FilePath.cpp rename to src/io/FilePath.cpp index cc493b2..6136850 100644 --- a/cece/core/FilePath.cpp +++ b/src/io/FilePath.cpp @@ -24,14 +24,16 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/FilePath.hpp" +#include "cece/io/FilePath.hpp" // C++ #include +#include #include #ifdef _WIN32 # include +# include #else # include # include @@ -40,12 +42,12 @@ #endif // CeCe -#include "cece/core/Exception.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace io { /* ************************************************************************ */ @@ -80,6 +82,46 @@ String fromWide(const std::wstring& str) /* ************************************************************************ */ +#ifdef _WIN32 +String normalize(String str) +{ + // Replace back slashes with forward slashes + for (auto& c : str) + { + if (c == '\\') + c = '/'; + } + + return str; +} +#endif + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +FilePath::FilePath(String source) +#ifdef _WIN32 + : m_path(normalize(std::move(source))) +#else + : m_path(std::move(source)) +#endif +{ + // Nothing to do +} + +/* ************************************************************************ */ + +FilePath::FilePath(const char* source) +#ifdef _WIN32 + : m_path(normalize(source)) +#else + : m_path(source) +#endif +{ + // Nothing to do } /* ************************************************************************ */ @@ -166,7 +208,43 @@ FilePath& FilePath::replaceExtension(const String& ext) /* ************************************************************************ */ -bool isFile(const FilePath& path) noexcept +FilePath FilePath::getCurrent() +{ +#ifdef _WIN32 + TCHAR buffer[MAX_PATH]; + auto res = GetCurrentDirectory(MAX_PATH, buffer); + + if (res == 0) + throw RuntimeException("Cannot obtain current working directory"); + + return buffer; +#else + char buffer[PATH_MAX]; + const char* res = getcwd(buffer, PATH_MAX); + + if (res == nullptr) + throw RuntimeException("Cannot obtain current working directory"); + + return res; +#endif +} + +/* ************************************************************************ */ + +void FilePath::setCurrent(const FilePath& path) +{ +#ifdef _WIN32 + if (!SetCurrentDirectory(path.toString().c_str())) + throw RuntimeException("Cannot change current working directory"); +#else + if (chdir(path.m_path.c_str()) < 0) + throw RuntimeException("Cannot change current working directory"); +#endif +} + +/* ************************************************************************ */ + +bool FilePath::isFile(const FilePath& path) noexcept { #ifdef _WIN32 auto str = toWide(path.toString()); @@ -182,7 +260,7 @@ bool isFile(const FilePath& path) noexcept /* ************************************************************************ */ -bool isDirectory(const FilePath& path) noexcept +bool FilePath::isDirectory(const FilePath& path) noexcept { #ifdef _WIN32 auto str = toWide(path.toString()); @@ -200,7 +278,7 @@ bool isDirectory(const FilePath& path) noexcept /* ************************************************************************ */ -bool pathExists(const FilePath& path) noexcept +bool FilePath::exists(const FilePath& path) noexcept { #ifdef _WIN32 auto str = toWide(path.toString()); @@ -213,7 +291,7 @@ bool pathExists(const FilePath& path) noexcept /* ************************************************************************ */ -FilePath tempDirectory() +FilePath FilePath::getTempDirectory() { // Based on boost implementation @@ -286,9 +364,8 @@ FilePath tempDirectory() /* ************************************************************************ */ -DynamicArray openDirectory(const FilePath& dir) +DynamicArray FilePath::openDirectory(const FilePath& dir) { - #ifdef _WIN32 WIN32_FIND_DATAW ffd; auto str = toWide(dir.c_str()); @@ -301,6 +378,10 @@ DynamicArray openDirectory(const FilePath& dir) do { + // Skip '.' & '..' + if (!std::wcscmp(ffd.cFileName, L".") || !std::wcscmp(ffd.cFileName, L"..")) + continue; + entries.push_back(dir / fromWide(ffd.cFileName)); } while (FindNextFileW(hFind, &ffd) != 0); @@ -317,8 +398,14 @@ DynamicArray openDirectory(const FilePath& dir) DynamicArray entries; struct dirent* de; - while ((de = readdir(d)) != NULL) + while ((de = readdir(d)) != nullptr) + { + // Skip '.' & '..' + if (!std::strcmp(de->d_name, ".") || !std::strcmp(de->d_name, "..")) + continue; + entries.push_back(dir / de->d_name); + } closedir(d); diff --git a/cece/init/CMakeLists.txt b/src/lang/CMakeLists.txt similarity index 89% rename from cece/init/CMakeLists.txt rename to src/lang/CMakeLists.txt index 9419571..7d379d4 100644 --- a/cece/init/CMakeLists.txt +++ b/src/lang/CMakeLists.txt @@ -23,22 +23,14 @@ # # # ######################################################################### # -# Sources set(SRCS - Initializer.hpp - Initializer.cpp - Container.hpp - Container.cpp - Factory.hpp - Factory.cpp - FactoryManager.hpp - FactoryManager.cpp + ExpressionParser.cpp ) # ######################################################################### # -dir_pretend(SOURCES init/ ${SRCS}) +dir_pretend(SOURCES lang/ ${SRCS}) -set(SOURCES_INIT ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/cece/core/ExpressionParser.cpp b/src/lang/ExpressionParser.cpp similarity index 97% rename from cece/core/ExpressionParser.cpp rename to src/lang/ExpressionParser.cpp index dd04fd8..177c91b 100644 --- a/cece/core/ExpressionParser.cpp +++ b/src/lang/ExpressionParser.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/ExpressionParser.hpp" +#include "cece/lang/ExpressionParser.hpp" // C++ #include @@ -32,16 +32,16 @@ #include // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/Real.hpp" -#include "cece/core/constants.hpp" -#include "cece/core/Tokenizer.hpp" -#include "cece/core/UnitIo.hpp" +#include "cece/common.hpp" +#include "cece/Assert.hpp" +#include "cece/lang/Tokenizer.hpp" +#include "cece/math/constants.hpp" +#include "cece/unit/UnitIo.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace lang { /* ************************************************************************ */ @@ -407,12 +407,12 @@ class ExpressionParser if (local == "pi" || local == "PI") { skipWhitespace(); - return coeff * constants::PI; + return coeff * math::PI; } if (local == "e" || local == "E") { skipWhitespace(); - return coeff * constants::E; + return coeff * math::E; } if (!parameters.exists(local)) @@ -421,7 +421,7 @@ class ExpressionParser return coeff * function(local); } skipWhitespace(); - return coeff * units::parse(parameters.get(local)); + return coeff * unit::parse(parameters.get(local)).get(); } RealType function(String local) diff --git a/src/log/CMakeLists.txt b/src/log/CMakeLists.txt new file mode 100644 index 0000000..fb6a16d --- /dev/null +++ b/src/log/CMakeLists.txt @@ -0,0 +1,41 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +set(SRCS + Log.cpp + Logger.cpp + Output.cpp + StreamOutput.cpp + FileOutput.cpp + StdOutput.cpp +) + +# ######################################################################### # + +dir_pretend(SOURCES log/ ${SRCS}) + +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) + +# ######################################################################### # diff --git a/src/log/FileOutput.cpp b/src/log/FileOutput.cpp new file mode 100644 index 0000000..e3ca128 --- /dev/null +++ b/src/log/FileOutput.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/log/FileOutput.hpp" + +// C++ +#include + +// CeCe +#include "cece/Exception.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +FileOutput::FileOutput(io::FilePath path) + : StreamOutput(m_stream) + , m_stream(path.toString(), std::ios_base::out | std::ios_base::app) +{ + if (!m_stream.is_open()) + throw InvalidArgumentException("Cannot open file for writing: " + path.toString()); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/init/Container.cpp b/src/log/Log.cpp similarity index 92% rename from cece/init/Container.cpp rename to src/log/Log.cpp index b9273dd..4dc823d 100644 --- a/cece/init/Container.cpp +++ b/src/log/Log.cpp @@ -24,21 +24,22 @@ /* ************************************************************************ */ // Declaration -#include "cece/init/Container.hpp" +#include "cece/log/Log.hpp" // CeCe -#include "cece/init/Initializer.hpp" +#include "cece/log/StdOutput.hpp" /* ************************************************************************ */ namespace cece { -namespace init { +namespace log { /* ************************************************************************ */ -void Container::init(simulator::Simulation& simulation) const +Logger& get_logger() noexcept { - invoke(&Initializer::init, simulation); + static Logger logger(makeUnique()); + return logger; } /* ************************************************************************ */ diff --git a/src/log/Logger.cpp b/src/log/Logger.cpp new file mode 100644 index 0000000..4c6e5c7 --- /dev/null +++ b/src/log/Logger.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/log/Logger.hpp" + +// CeCe +#include "cece/Assert.hpp" +#include "cece/log/Output.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +void Logger::writeMessage(Severity severity, const String& section, const String& msg) +{ + CECE_ASSERT(m_output); + m_output->write(severity, section, msg); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/BoundData.cpp b/src/log/Output.cpp similarity index 96% rename from cece/object/BoundData.cpp rename to src/log/Output.cpp index 915d34d..a4cb50e 100644 --- a/cece/object/BoundData.cpp +++ b/src/log/Output.cpp @@ -24,16 +24,16 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/BoundData.hpp" +#include "cece/log/Output.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace log { /* ************************************************************************ */ -BoundData::~BoundData() = default; +Output::~Output() = default; /* ************************************************************************ */ diff --git a/src/log/StdOutput.cpp b/src/log/StdOutput.cpp new file mode 100644 index 0000000..c7c8aa9 --- /dev/null +++ b/src/log/StdOutput.cpp @@ -0,0 +1,67 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/log/StdOutput.hpp" + +// C++ +#include + +// CeCe +#include "cece/io/OutStream.hpp" +#include "cece/io/CliColor.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +void StdOutput::write(Severity severity, const String& section, const String& msg) +{ + io::OutStream& os = severity == Severity::Error ? std::cerr : std::cout; + + switch (severity) + { + case Severity::Default: break; + case Severity::Info: os << io::CliColor::LightGreen << "[INFO] " << io::CliColor::Default; break; + case Severity::Warning: os << io::CliColor::Yellow << "[WARN] " << io::CliColor::Default; break; + case Severity::Error: os << io::CliColor::Red << "[ERROR] " << io::CliColor::Default; break; + case Severity::Debug: os << io::CliColor::Green << "[DEBUG] " << io::CliColor::Default; break; + } + + if (!section.empty()) + os << "[" << section << "] "; + + os << msg << std::endl; +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/log/StreamOutput.cpp b/src/log/StreamOutput.cpp new file mode 100644 index 0000000..fb47f5a --- /dev/null +++ b/src/log/StreamOutput.cpp @@ -0,0 +1,61 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/log/StreamOutput.hpp" + +// C++ +#include + +/* ************************************************************************ */ + +namespace cece { +namespace log { + +/* ************************************************************************ */ + +void StreamOutput::write(Severity severity, const String& section, const String& msg) +{ + switch (severity) + { + case Severity::Default: break; + case Severity::Info: m_stream << "[INFO] "; break; + case Severity::Warning: m_stream << "[WARN] "; break; + case Severity::Error: m_stream << "[ERROR] "; break; + case Severity::Debug: m_stream << "[DEBUG] "; break; + } + + if (!section.empty()) + m_stream << "[" << section << "] "; + + m_stream << msg << std::endl; +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/math/CMakeLists.txt b/src/math/CMakeLists.txt new file mode 100644 index 0000000..526f590 --- /dev/null +++ b/src/math/CMakeLists.txt @@ -0,0 +1,37 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +set(SRCS + Vector.cpp + Grid.cpp +) + +# ######################################################################### # + +dir_pretend(SOURCES math/ ${SRCS}) + +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) + +# ######################################################################### # diff --git a/cece/core/Grid.cpp b/src/math/Grid.cpp similarity index 98% rename from cece/core/Grid.cpp rename to src/math/Grid.cpp index c7a7415..a8ddb6d 100644 --- a/cece/core/Grid.cpp +++ b/src/math/Grid.cpp @@ -24,6 +24,6 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/Grid.hpp" +#include "cece/math/Grid.hpp" /* ************************************************************************ */ diff --git a/cece/core/Vector.cpp b/src/math/Vector.cpp similarity index 90% rename from cece/core/Vector.cpp rename to src/math/Vector.cpp index 9c6755e..4e89d5d 100644 --- a/cece/core/Vector.cpp +++ b/src/math/Vector.cpp @@ -24,18 +24,18 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ -template class BasicVector; -template class BasicVector; -template class BasicVector; +template class BasicVector; +template class BasicVector; +template class BasicVector; /* ************************************************************************ */ diff --git a/cece/loader/CMakeLists.txt b/src/os/CMakeLists.txt similarity index 91% rename from cece/loader/CMakeLists.txt rename to src/os/CMakeLists.txt index 77e7a6d..a298a09 100644 --- a/cece/loader/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -25,18 +25,13 @@ # Sources set(SRCS - Loader.hpp - Loader.cpp - Factory.hpp - Factory.cpp - FactoryManager.hpp - FactoryManager.cpp + SharedLibrary.cpp ) # ######################################################################### # -dir_pretend(SOURCES loader/ ${SRCS}) +dir_pretend(SOURCES os/ ${SRCS}) -set(SOURCES_LOADER ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/src/os/SharedLibrary.cpp b/src/os/SharedLibrary.cpp new file mode 100644 index 0000000..38fe2a2 --- /dev/null +++ b/src/os/SharedLibrary.cpp @@ -0,0 +1,231 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/os/SharedLibrary.hpp" + +// C++ +#include +#include +#include + +#if _WIN32 +#include +#else +#include +#endif + +// CeCe +#include "cece/Exception.hpp" +#include "cece/log/Log.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace os { + +/* ************************************************************************ */ + +#if __linux__ || __MINGW32__ +const String SharedLibrary::PREFIX = "lib"; +#elif _WIN32 +const String SharedLibrary::PREFIX = ""; +#elif __APPLE__ && __MACH__ +const String SharedLibrary::PREFIX = "lib"; +#endif + +/* ************************************************************************ */ + +#if __linux__ +const String SharedLibrary::EXTENSION = ".so"; +#elif _WIN32 +const String SharedLibrary::EXTENSION = ".dll"; +#elif __APPLE__ && __MACH__ +const String SharedLibrary::EXTENSION = ".dylib"; +#endif + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Open shared library. + * + * @param path Path to library. + * + * @return Library handle. + */ +void* openLibrary(const io::FilePath& path) noexcept +{ +#if _WIN32 + String str = path.toString(); + int size = MultiByteToWideChar(CP_UTF8, 0, str.data(), (int) str.size(), NULL, 0); + std::wstring result(size, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, str.data(), (int) str.size(), &result.front(), size); + + DWORD oldMode; + SetThreadErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX, &oldMode); + auto handle = LoadLibraryW(result.c_str()); + SetThreadErrorMode(oldMode, NULL); + return reinterpret_cast(handle); +#else + // POSIX + return dlopen(path.c_str(), RTLD_LAZY); +#endif +} + +/* ************************************************************************ */ + +/** + * @brief Close shared library. + * + * @param handle Library handle. + */ +void closeLibrary(void* handle) noexcept +{ +#if _WIN32 + // WIN32 + FreeLibrary(reinterpret_cast(handle)); +#else + // POSIX + if (handle) + dlclose(handle); +#endif +} + +/* ************************************************************************ */ + +/** + * @brief Returns error string. + * + * @param[in] handle Handle to shared library. + * + * @return The error message. + */ +String getError(void* handle) noexcept +{ +#if _WIN32 + // Get error message + const auto err = ::GetLastError(); + if (err == 0) + return {}; + + LPSTR buffer = nullptr; + auto size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&buffer, 0, NULL + ); + + while (size > 0 && (buffer[size - 1] == '\r' || buffer[size - 1] == '\n')) + --size; + + String message(buffer, size); + + // Free the buffer + LocalFree(buffer); + + return message; +#else + return dlerror(); +#endif +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +SharedLibrary::SharedLibrary(io::FilePath path) + : m_path(std::move(path)) + , m_handle(openLibrary(m_path)) +{ + if (!isOpen()) + throw RuntimeException("Shared library `" + m_path.toString() + "` cannot be loaded: " + getError(m_handle)); + + log::Log::debug("Library loaded `", m_path, "`."); +} + +/* ************************************************************************ */ + +SharedLibrary::~SharedLibrary() +{ + if (isOpen()) + { + log::Log::debug("Closing shared library `", m_path, "`"); + closeLibrary(m_handle); + log::Log::debug("Shared library closed `", m_path, "`"); + } +} + +/* ************************************************************************ */ + +SharedLibrary::SharedLibrary(SharedLibrary&& src) noexcept + : m_path(std::move(src.m_path)) + , m_handle(src.m_handle) +{ + src.m_handle = nullptr; +} + +/* ************************************************************************ */ + +SharedLibrary& SharedLibrary::operator=(SharedLibrary&& src) noexcept +{ + using std::swap; + swap(m_path, src.m_path); + swap(m_handle, src.m_handle); + + return *this; +} + +/* ************************************************************************ */ + +void* SharedLibrary::getAddr(StringView name) const noexcept +{ +#if _WIN32 + return reinterpret_cast(reinterpret_cast( + GetProcAddress(reinterpret_cast(m_handle), name.getData()) + )); +#else + // POSIX + return dlsym(m_handle, name.getData()); +#endif +} + +/* ************************************************************************ */ + +String SharedLibrary::formatName(String name) +{ + return PREFIX + name + EXTENSION; +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/perf/CMakeLists.txt b/src/perf/CMakeLists.txt new file mode 100644 index 0000000..194eaee --- /dev/null +++ b/src/perf/CMakeLists.txt @@ -0,0 +1,36 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +set(SRCS + TimeMeasurement.cpp +) + +# ######################################################################### # + +dir_pretend(SOURCES perf/ ${SRCS}) + +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) + +# ######################################################################### # diff --git a/cece/core/TimeMeasurement.cpp b/src/perf/TimeMeasurement.cpp similarity index 92% rename from cece/core/TimeMeasurement.cpp rename to src/perf/TimeMeasurement.cpp index 3981f55..81cbc15 100644 --- a/cece/core/TimeMeasurement.cpp +++ b/src/perf/TimeMeasurement.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/TimeMeasurement.hpp" +#include "cece/perf/TimeMeasurement.hpp" // C++ #include @@ -32,11 +32,11 @@ /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace perf { /* ************************************************************************ */ -static OutStream* g_output = &std::cout; +static io::OutStream* g_output = &std::cout; /* ************************************************************************ */ @@ -51,14 +51,14 @@ bool isMeasureTimeEnabled() noexcept /* ************************************************************************ */ -OutStream* getMeasureTimeOutput() noexcept +io::OutStream* getMeasureTimeOutput() noexcept { return g_output; } /* ************************************************************************ */ -void setMeasureTimeOutput(OutStream* output) noexcept +void setMeasureTimeOutput(io::OutStream* output) noexcept { g_output = output; } diff --git a/cece/plugin/Api.cpp b/src/plugin/Api.cpp similarity index 94% rename from cece/plugin/Api.cpp rename to src/plugin/Api.cpp index 518db49..0371ad1 100644 --- a/cece/plugin/Api.cpp +++ b/src/plugin/Api.cpp @@ -26,9 +26,6 @@ // Declaration #include "cece/plugin/Api.hpp" -// CeCe -#include "cece/plugin/Repository.hpp" - /* ************************************************************************ */ namespace cece { @@ -36,10 +33,7 @@ namespace plugin { /* ************************************************************************ */ -void Api::onUnload(Repository& repository) const -{ - repository.unregisterApi(this); -} +Api::~Api() = default; /* ************************************************************************ */ diff --git a/cece/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt similarity index 91% rename from cece/plugin/CMakeLists.txt rename to src/plugin/CMakeLists.txt index 5c7c38e..6410113 100644 --- a/cece/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -25,25 +25,21 @@ # Sources set(SRCS - Config.hpp - definition.hpp - Library.hpp - Library.cpp - Api.hpp Api.cpp - Manager.hpp + Plugin.cpp Manager.cpp - RepositoryRecord.hpp - Repository.hpp + RepositoryRecord.cpp Repository.cpp - Context.hpp Context.cpp + Loader.cpp + SharedLibraryLoader.cpp + Exception.cpp ) # ######################################################################### # dir_pretend(SOURCES plugin/ ${SRCS}) -set(SOURCES_PLUGIN ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/src/plugin/Context.cpp b/src/plugin/Context.cpp new file mode 100644 index 0000000..e63d2a9 --- /dev/null +++ b/src/plugin/Context.cpp @@ -0,0 +1,272 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/plugin/Context.hpp" + +// C++ +#include + +// CeCe +#include "cece/log/Log.hpp" +#include "cece/plugin/Repository.hpp" +#include "cece/plugin/Manager.hpp" +#include "cece/plugin/Api.hpp" +#include "cece/plugin/Exception.hpp" +#include "cece/simulation/Loader.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/simulation/Simulation.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Find factory name in all plugins to give a hint for user. + * + * @param repo + * @param fn + * + * @return + */ +template +DynamicArray getPluginNames(const Repository& repo, RecordFn fn) +{ + DynamicArray names; + + // Foreach repository records + for (const auto& record : repo.getRecords()) + { + if (fn(record.second)) + names.push_back(record.first); + } + + return names; +} + +/* ************************************************************************ */ + +/** + * @brief Find repository record + * + * @param[in] ctx The context. + * @param[out] names The names + * @param[in] fn Function used to check the repository record. + * + * @tparam Fn Type of test function. + * + * @return Pointer to found record. Can be nullptr. + */ +template +ViewPtr findRecord(const Context& ctx, DynamicArray& names, Fn fn) +{ + ViewPtr result = nullptr; + + // Foreach imported and find repository record + for (const auto& plugin : ctx.getImportedPlugins()) + { + // Get record + const auto& rec = ctx.getRepository().get(plugin); + + // Exists factory + if (fn(rec)) + { + result = &rec; + names.push_back(String(plugin)); + } + } + + return result; +} + +/* ************************************************************************ */ + +/** + * @brief Helper function for plugin extension creation. + * + * @param[in] ctx The context. + * @param[in] kind The kind + * @param[in] name Extension registration name. + * @param[in] ctor The extension construct function. + * @param[in] tester The record test function. + * + * @tparam T Type of returned object. + * @tparam Creator Type of ctor function. + * @tparam Tester Type of tester function. + * + * @return Pointer to created object. + */ +template +UniquePtr createHelper(const Context& ctx, String kind, String name, Creator ctor, Tester tester) +{ + DynamicArray plugins; + + // Try to find record + auto record = findRecord(ctx, plugins, tester); + + // Multiple imports + if (plugins.size() > 1) + throw MultipleExtensionsException(std::move(kind), std::move(name), std::move(plugins)); + + // Factory manager selected + if (record) + return ctor(*record); + + // Find in other repositories to give a hint to user + plugins = getPluginNames(ctx.getRepository(), tester); + + throw ExtensionNotFoundException(std::move(kind), std::move(name), std::move(plugins)); +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +ViewPtr Context::importPlugin(StringView name) +{ + // Do not add duplicates + auto it = m_importedPlugins.find(name); + + // Already imported + if (it != m_importedPlugins.end()) + return m_manager.getApi(*it); + + log::Log::info("Importing plugin '", name, "'..."); + + // Check if plugin is loaded + if (!m_manager.isLoaded(name)) + throw PluginNotFoundException(String(name)); + + // Store name of the imported plugin + m_importedPlugins.insert(name); + + return m_manager.getApi(name); +} + +/* ************************************************************************ */ + +ViewPtr Context::removePlugin(StringView name) +{ + // Find plugin + auto it = m_importedPlugins.find(name); + + // Nothing to unload + if (it == m_importedPlugins.end()) + return nullptr; + + // Remove plugin + m_importedPlugins.erase(it); + + return m_manager.getApi(name); +} + +/* ************************************************************************ */ + +UniquePtr Context::createLoader(StringView name) const +{ + // Foreach repository records and find loader with given name + for (const auto& item : getRepository().getRecords()) + { + const auto& record = item.second; + + // Exists factory + if (record.isRegisteredLoader(name)) + return record.createLoader(name); + } + + // Not found in any available plugins + throw ExtensionNotFoundException("Loader", String(name), {}); +} + +/* ************************************************************************ */ + +UniquePtr Context::createInitializer(StringView name) const +{ + return createHelper(*this, "Initializer", String(name), + [&](const RepositoryRecord& rec) { + return rec.createInitializer(name); + }, + [&](const RepositoryRecord& rec) { + return rec.isRegisteredInitializer(name); + }); +} + +/* ************************************************************************ */ + +UniquePtr Context::createModule(StringView name, simulation::Simulation& simulation) const +{ + return createHelper(*this, "Module", String(name), + [&](const RepositoryRecord& rec) { + return rec.createModule(name, simulation); + }, + [&](const RepositoryRecord& rec) { + return rec.isRegisteredModule(name); + }); +} + +/* ************************************************************************ */ + +UniquePtr Context::createObject(StringView name, simulation::Simulation& simulation, simulation::Object::Type type) const +{ + return createHelper(*this, "Object", String(name), + [&](const RepositoryRecord& rec) { + return rec.createObject(name, simulation, type); + }, + [&](const RepositoryRecord& rec) { + return rec.isRegisteredObject(name); + }); +} + +/* ************************************************************************ */ + +UniquePtr Context::createProgram(StringView name) const +{ + return createHelper(*this, "Program", String(name), + [&](const RepositoryRecord& rec) { + return rec.createProgram(name); + }, + [&](const RepositoryRecord& rec) { + return rec.isRegisteredProgram(name); + }); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/plugin/Exception.cpp b/src/plugin/Exception.cpp new file mode 100644 index 0000000..f8e356e --- /dev/null +++ b/src/plugin/Exception.cpp @@ -0,0 +1,113 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/plugin/Exception.hpp" + +// C++ +#include + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Join strings from array. + * + * @param array + * + * @return + */ +String join(const DynamicArray& array) noexcept +{ + String res; + + for (auto it = array.begin(); it != array.end(); ++it) + { + if (it != array.begin()) + res += ", "; + + res += *it; + } + + return res; +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +InvalidPluginException::InvalidPluginException(io::FilePath path, String msg) noexcept + : Exception("Plugin `" + path.toString() + "`: " + msg) + , m_path(std::move(path)) + , m_errorMessage(std::move(msg)) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +PluginNotFoundException::PluginNotFoundException(String name) noexcept + : Exception("Plugin `" + name + "` not found.") + , m_name(std::move(name)) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +MultipleExtensionsException::MultipleExtensionsException(String kind, String name, DynamicArray plugins) noexcept + : Exception("Multiple extensions " + name + "(" + kind + ") found in imported plugins: " + join(plugins) + ".") + , m_name(std::move(name)) + , m_pluginNames(std::move(plugins)) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +ExtensionNotFoundException::ExtensionNotFoundException(String kind, String name, DynamicArray plugins) noexcept + : Exception("Extension " + name + "(" + kind + ") found in imported plugins. Found in plugins: " + join(plugins) + ".") + , m_name(std::move(name)) + , m_pluginNames(std::move(plugins)) +{ + // Nothing to do +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/ContactListener.cpp b/src/plugin/Loader.cpp similarity index 95% rename from cece/object/ContactListener.cpp rename to src/plugin/Loader.cpp index f0eb1c2..d0a8009 100644 --- a/cece/object/ContactListener.cpp +++ b/src/plugin/Loader.cpp @@ -24,16 +24,16 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/ContactListener.hpp" +#include "cece/plugin/Loader.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace plugin { /* ************************************************************************ */ -ContactListener::~ContactListener() = default; +Loader::~Loader() = default; /* ************************************************************************ */ diff --git a/cece/core/Unit.cpp b/src/plugin/Manager.cpp similarity index 54% rename from cece/core/Unit.cpp rename to src/plugin/Manager.cpp index e4abc16..2e54f87 100644 --- a/cece/core/Unit.cpp +++ b/src/plugin/Manager.cpp @@ -24,129 +24,134 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/Unit.hpp" +#include "cece/plugin/Manager.hpp" + +// C++ +#include // CeCe -#include "cece/core/Map.hpp" -#include "cece/core/Exception.hpp" +#include "cece/Assert.hpp" +#include "cece/Exception.hpp" +#include "cece/log/Log.hpp" +#include "cece/plugin/Api.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace plugin { /* ************************************************************************ */ -namespace units { +Manager::Manager() = default; /* ************************************************************************ */ -namespace { +Manager::~Manager() +{ + // Unload plugins + for (auto& plugin : m_plugins) + plugin.getApi()->onUnload(m_repository.get(plugin.getName())); +} /* ************************************************************************ */ -const Map g_abbreviations = { - // Molar (10e3 mol/m3) - {"M", 3}, - // Litre (10e-3 m3) - {"l", -3} -}; +DynamicArray Manager::getNames() const noexcept +{ + DynamicArray names; + names.reserve(m_plugins.size()); -/* ************************************************************************ */ + for (const auto& plugin : m_plugins) + names.emplace_back(plugin.getName()); + return names; } /* ************************************************************************ */ -int calcPrefixExponent(char c, unsigned int count) +bool Manager::isLoaded(StringView name) const noexcept { - if (count == 0) - throw InvalidArgumentException("Unit symbol prefix doesn't make sence without nominator"); - - // Result exponent - int exponent = 0; + CECE_ASSERT(!name.isEmpty()); - // Unit prefix - switch (c) + for (const auto& plugin : m_plugins) { - default: - throw InvalidArgumentException("Unknown/unsupported unit symbol prefix: " + String(1, c)); - - case 'G': - // Giga - exponent += 3; - case 'M': - // Mega - exponent += 3; - case 'k': - // Kilo - exponent += 3; - break; - - case 'n': - // Nano - exponent -= 3; - case 'u': - // Micro - exponent -= 3; - case 'm': - // Milli - exponent -= 1; - case 'c': - // Centi - exponent -= 1; - case 'd': - // Deci - exponent -= 1; + if (plugin.getName() == name) + return true; } - return exponent * count; + return false; } /* ************************************************************************ */ -int calcPrefixExponent(const String& symbol, StringView typeSymbol, unsigned int count) +ViewPtr Manager::getApi(StringView name) const noexcept { - if (symbol.empty()) - return 0; + CECE_ASSERT(!name.isEmpty()); - const auto pos = symbol.find(typeSymbol.getData()); - if (pos == String::npos) + for (const auto& plugin : m_plugins) { - // Try to find abbreviations without prefix - const auto it1 = g_abbreviations.find(symbol); + if (plugin.getName() == name) + return plugin.getApi(); + } - if (it1 != g_abbreviations.end()) - return it1->second; + return nullptr; +} - // Try to find abbreviations with prefix - const auto it2 = g_abbreviations.find(symbol.substr(1)); +/* ************************************************************************ */ - if (it2 != g_abbreviations.end()) - return calcPrefixExponent(symbol.front(), 1) + it2->second; +Manager& Manager::addLoader(UniquePtr loader) +{ + CECE_ASSERT(loader); - throw InvalidArgumentException( - "Invalid units symbol. " - "Expected '(prefix)" + String(typeSymbol) + "' " - "given '" + symbol + "'" - ); - } + log::Log::debug("New plugins loader."); - // Get unit prefix - if (pos == 1) - { - return calcPrefixExponent(symbol.front(), count); - } - else if (pos != 0) + m_loaders.push_back(std::move(loader)); + + // Scan directories + for (const auto& dir : m_directories) { - throw InvalidArgumentException("Unit symbol prefix is longer than expected"); + CECE_ASSERT(!m_loaders.empty()); + appendPlugins(m_loaders.back()->loadAll(dir)); } - return 0; + return *this; +} + +/* ************************************************************************ */ + +Manager& Manager::addDirectory(io::FilePath path) +{ + CECE_ASSERT(!path.isEmpty()); + + log::Log::debug("New plugins directory: `", path, "`."); + + // Add directory + m_directories.push_back(std::move(path)); + + // Scan directory by loaders + for (auto& loader : m_loaders) + appendPlugins(loader->loadAll(m_directories.back())); + + return *this; } /* ************************************************************************ */ +void Manager::addPlugin(Plugin plugin) +{ + // Create repository record + plugin.getApi()->onLoad(m_repository.createRecord(plugin.getName())); + + // Store plugin + m_plugins.push_back(std::move(plugin)); +} + +/* ************************************************************************ */ + +void Manager::appendPlugins(DynamicArray plugins) +{ + // Load and store plugins + for (auto&& plugin : plugins) + addPlugin(std::move(plugin)); } /* ************************************************************************ */ diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp new file mode 100644 index 0000000..5776b2c --- /dev/null +++ b/src/plugin/Plugin.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/plugin/Plugin.hpp" + +// C++ +#include + +// CeCe +#include "cece/Assert.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +Plugin::Plugin(String name, UniquePtr api) noexcept + : m_name(std::move(name)) + , m_api(std::move(api)) +{ + CECE_ASSERT(!m_name.empty()); + CECE_ASSERT(m_api.get() != nullptr); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/Log.cpp b/src/plugin/Repository.cpp similarity index 68% rename from cece/core/Log.cpp rename to src/plugin/Repository.cpp index 947cad2..c9a9472 100644 --- a/cece/core/Log.cpp +++ b/src/plugin/Repository.cpp @@ -24,61 +24,67 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/Log.hpp" +#include "cece/plugin/Repository.hpp" -// C++ -#include +// CeCe +#include "cece/Assert.hpp" +#include "cece/plugin/Exception.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace plugin { /* ************************************************************************ */ -static Log::StreamOutput g_output(&std::cout); +bool Repository::exists(StringView name) const noexcept +{ + return m_records.find(String(name)) != m_records.end(); +} /* ************************************************************************ */ -static Log::StreamOutput g_error(&std::cerr); +RepositoryRecord& Repository::get(StringView name) +{ + auto it = m_records.find(String(name)); -/* ************************************************************************ */ + if (it == m_records.end()) + throw RepositoryException("Record with name `" + String(name) + "` doesn't exists"); -Log::Output::~Output() = default; + return it->second; +} /* ************************************************************************ */ -Log::StreamOutput::~StreamOutput() = default; +const RepositoryRecord& Repository::get(StringView name) const +{ + auto it = m_records.find(String(name)); -/* ************************************************************************ */ + if (it == m_records.end()) + throw RepositoryException("Record with name `" + String(name) + "` doesn't exists"); -void Log::StreamOutput::write(Type type, const String& section, const String& msg) -{ - if (!m_os) - return; - - switch (type) - { - case Type::Default: break; - case Type::Info: *m_os << CliColor::LightGreen << "[INFO] " << CliColor::Default; break; - case Type::Warning: *m_os << CliColor::Yellow << "[WARN] " << CliColor::Default; break; - case Type::Error: *m_os << CliColor::Red << "[ERROR] " << CliColor::Default; break; - case Type::Debug: *m_os << CliColor::Green << "[DEBUG] " << CliColor::Default; break; - } - - if (!section.empty()) - *m_os << "[" << section << "] "; - - *m_os << msg << std::endl; + return it->second; } /* ************************************************************************ */ -Log::Output* Log::s_output = &g_output; +RepositoryRecord& Repository::createRecord(String name) +{ + // Try to find existing record + if (exists(name)) + throw RepositoryException("Record with name `" + name + "` already exists"); + + auto pair = m_records.emplace(name, RepositoryRecord{}); + CECE_ASSERT(pair.second); + return pair.first->second; +} /* ************************************************************************ */ -Log::Output* Log::s_error = &g_error; +void Repository::removeRecord(StringView name) noexcept +{ + m_records.erase(String(name)); +} /* ************************************************************************ */ diff --git a/src/plugin/RepositoryRecord.cpp b/src/plugin/RepositoryRecord.cpp new file mode 100644 index 0000000..38d0684 --- /dev/null +++ b/src/plugin/RepositoryRecord.cpp @@ -0,0 +1,81 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/plugin/RepositoryRecord.hpp" + +// CeCe +#include "cece/simulation/Loader.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +UniquePtr RepositoryRecord::createLoader(StringView name) const +{ + return m_loaderFactoryManager.createLoader(name); +} + +/* ************************************************************************ */ + +UniquePtr RepositoryRecord::createInitializer(StringView name) const +{ + return m_initFactoryManager.createInitializer(name); +} + +/* ************************************************************************ */ + +UniquePtr RepositoryRecord::createModule(StringView name, simulation::Simulation& simulation) const +{ + return m_moduleFactoryManager.createModule(name, simulation); +} + +/* ************************************************************************ */ + +UniquePtr RepositoryRecord::createObject(StringView name, simulation::Simulation& simulation, simulation::Object::Type type) const +{ + return m_objectFactoryManager.createObject(name, simulation, type); +} + +/* ************************************************************************ */ + +UniquePtr RepositoryRecord::createProgram(StringView name) const +{ + return m_programFactoryManager.createProgram(name); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/plugin/SharedLibraryLoader.cpp b/src/plugin/SharedLibraryLoader.cpp new file mode 100644 index 0000000..eee89bd --- /dev/null +++ b/src/plugin/SharedLibraryLoader.cpp @@ -0,0 +1,211 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/plugin/SharedLibraryLoader.hpp" + +// CeCe +#include "cece/common.hpp" +#include "cece/Assert.hpp" +#include "cece/ViewPtr.hpp" +#include "cece/log/Log.hpp" +#include "cece/plugin/Exception.hpp" +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace plugin { + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/// Create API function pointer type. +using CreateFn = Api* (*)(); + +/* ************************************************************************ */ + +/// Returns plugin configuration. +using GetConfigFn = Config* (*)(); + +/* ************************************************************************ */ + +/** + * @brief Check configuration file. + * + * @param[in] lib The shared library. + */ +void checkConfig(const os::SharedLibrary& lib) +{ + auto path = lib.getPath().toString(); + + // Get configuration + auto getConfigFn = lib.getAddr("get_config"); + + if (!getConfigFn) + throw InvalidPluginException(path, "Doesn't contains 'get_config' function"); + + // Get configuration + auto config = getConfigFn(); + + if (!config) + throw InvalidPluginException(path, "Returns no config"); + + if (config->apiVersion != PLUGIN_API_VERSION) + throw InvalidPluginException(path, "Built against different API version than CeCe"); + + if (config->realSize != sizeof(RealType)) + throw InvalidPluginException(path, "Built with different real type than CeCe"); + +#ifdef CECE_RENDER + if (!config->renderEnabled) + throw InvalidPluginException(path, "Built without render support, but CeCe did"); +#else + if (config->renderEnabled) + throw InvalidPluginException(path, "Built with render support, but CeCe didn't"); +#endif + +#ifdef CECE_THREAD_SAFE + if (!config->threadSafe) + throw InvalidPluginException(path, "Built without thread safety, but CeCe did"); +#else + if (config->threadSafe) + throw InvalidPluginException(path, "Built with thread safety, but CeCe didn't"); +#endif +} + +/* ************************************************************************ */ + +/** + * @brief Create API from shared library. + * + * @param lib Shared library. + * + * @return Plugin API. + */ +UniquePtr createApi(const os::SharedLibrary& lib) +{ + // Get create API function + auto fn = lib.getAddr("create"); + + if (!fn) + throw InvalidPluginException(lib.getPath(), "Doesn't contains 'create' function"); + + return UniquePtr(fn()); +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +DynamicArray SharedLibraryLoader::loadAll(const io::FilePath& directory) +{ + static const auto PREFIX = os::SharedLibrary::PREFIX + "cece-"; + static const auto EXTENSION = os::SharedLibrary::EXTENSION; + + log::Log::debug("Scanning `", directory, "` for shared library plugins"); + + // Not a directory + if (!isDirectory(directory)) + { + log::Log::warning("`", directory, "` is not a directory, skipping..."); + return {}; + } + + CECE_ASSERT(isDirectory(directory)); + + DynamicArray result; + + // Foreach directory + for (const auto& path : openDirectory(directory)) + { + // Only files + if (!isFile(path)) + { + log::Log::debug("Skipping `", path, "`: not a file"); + continue; + } + + // Get path + const auto filename = path.getFilename(); + const auto prefixLength = PREFIX.length(); + const auto suffixLength = EXTENSION.length(); + const auto suffixStart = filename.length() - suffixLength; + + log::Log::debug("Checking: `", filename, "`"); + + // Different prefix + if (filename.substr(0, prefixLength) != PREFIX) + continue; + + // Different extension + if (filename.substr(suffixStart) != EXTENSION) + continue; + + // Plugin name + const String name = filename.substr(prefixLength, suffixStart - prefixLength); + + log::Log::debug("Loading plugin: `", name, "` @ `", path, "`"); + + try + { + // Open shared library + os::SharedLibrary lib(path); + + // Check configuration + checkConfig(lib); + + // Obtain API from library + auto api = createApi(lib); + + // Store library + m_libraries.push_back(std::move(lib)); + result.emplace_back(name, std::move(api)); + } + catch (const InvalidPluginException& e) + { + log::Log::warning("Trying to load invalid plugin `", name, "` @ `", path, "`: ", e.what()); + } + catch (...) + { + log::Log::warning("Internal plugin error `", name, "` @ `", path); + } + } + + return result; +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/render/Buffer.cpp b/src/render/Buffer.cpp similarity index 99% rename from cece/render/Buffer.cpp rename to src/render/Buffer.cpp index 2e8de70..02b54b3 100644 --- a/cece/render/Buffer.cpp +++ b/src/render/Buffer.cpp @@ -27,7 +27,7 @@ #include "cece/render/Buffer.hpp" // CeCe -#include "cece/core/Assert.hpp" +#include "cece/Assert.hpp" #include "cece/render/OpenGL.hpp" #include "cece/render/errors.hpp" diff --git a/cece/render/CMakeLists.txt b/src/render/CMakeLists.txt similarity index 80% rename from cece/render/CMakeLists.txt rename to src/render/CMakeLists.txt index b69d5b3..1254965 100644 --- a/cece/render/CMakeLists.txt +++ b/src/render/CMakeLists.txt @@ -31,63 +31,31 @@ endif () # Sources set(SRCS - datatype.hpp - Color.hpp Color.cpp - errors.hpp errors.cpp - Context.hpp Context.cpp - Object.hpp Object.cpp - Camera.hpp Camera.cpp - Buffer.hpp Buffer.cpp - GridBase.hpp - Grid.hpp Grid.cpp - GridVector.hpp GridVector.cpp - GridColor.hpp GridColor.cpp - GridColorSmooth.hpp GridColorSmooth.cpp - GridColorColorMap.hpp GridColorColorMap.cpp - Shader.hpp Shader.cpp - Program.hpp Program.cpp - VertexElement.hpp - VertexFormat.hpp - Texture.hpp Texture.cpp - Circle.hpp Circle.cpp - Rectangle.hpp Rectangle.cpp - ImageData.hpp - Lines.hpp Lines.cpp - glext.h - State.hpp - Image.hpp Image.cpp - PhysicsDebugger.hpp PhysicsDebugger.cpp ) -set(SRCS_TEST - ColorTest.cpp -) - # ######################################################################### # dir_pretend(SOURCES render/ ${SRCS}) -dir_pretend(SOURCES_TEST render/test/ ${SRCS_TEST}) -set(SOURCES_RENDER ${SOURCES} PARENT_SCOPE) -set(SOURCES_RENDER_TEST ${SOURCES_TEST} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/cece/render/Camera.cpp b/src/render/Camera.cpp similarity index 100% rename from cece/render/Camera.cpp rename to src/render/Camera.cpp diff --git a/cece/render/Circle.cpp b/src/render/Circle.cpp similarity index 96% rename from cece/render/Circle.cpp rename to src/render/Circle.cpp index 9c13bed..8b1e31a 100644 --- a/cece/render/Circle.cpp +++ b/src/render/Circle.cpp @@ -27,7 +27,7 @@ #include "cece/render/Circle.hpp" // CeCe -#include "cece/core/constants.hpp" +#include "cece/math/constants.hpp" #include "cece/render/Color.hpp" #include "cece/render/Context.hpp" #include "cece/render/VertexFormat.hpp" @@ -63,7 +63,7 @@ StaticArray generateVertices() { StaticArray res; - constexpr RealType step = 2 * constants::PI / PARTS; + constexpr RealType step = 2 * math::PI / PARTS; res[0] = Vertex{0.f, 0.f}; @@ -71,7 +71,7 @@ StaticArray generateVertices() { const RealType angle = step * i; res[i] = Vertex{ - static_cast(std::cos(angle)), + static_cast(std::cos(angle)), static_cast(std::sin(angle)) }; } diff --git a/cece/render/Color.cpp b/src/render/Color.cpp similarity index 95% rename from cece/render/Color.cpp rename to src/render/Color.cpp index 9fddbcb..c5224b2 100644 --- a/cece/render/Color.cpp +++ b/src/render/Color.cpp @@ -27,10 +27,10 @@ #include "cece/render/Color.hpp" // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Map.hpp" -#include "cece/core/Exception.hpp" +#include "cece/Assert.hpp" +#include "cece/String.hpp" +#include "cece/Map.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ @@ -102,7 +102,7 @@ int parseHex(const char* str) /* ************************************************************************ */ -InStream& operator>>(InStream& is, Color& color) +io::InStream& operator>>(io::InStream& is, Color& color) { String str; is >> str; @@ -138,7 +138,7 @@ InStream& operator>>(InStream& is, Color& color) /* ************************************************************************ */ -OutStream& operator<<(OutStream& os, const Color& color) noexcept +io::OutStream& operator<<(io::OutStream& os, const Color& color) noexcept { // Store predefined color for (const auto& p : g_colors) diff --git a/cece/render/Context.cpp b/src/render/Context.cpp similarity index 95% rename from cece/render/Context.cpp rename to src/render/Context.cpp index a28b9ab..24c4088 100644 --- a/cece/render/Context.cpp +++ b/src/render/Context.cpp @@ -31,7 +31,7 @@ #include // CeCe -#include "cece/core/Assert.hpp" +#include "cece/Assert.hpp" #include "cece/render/OpenGL.hpp" #include "cece/render/Color.hpp" #include "cece/render/Buffer.hpp" @@ -125,7 +125,7 @@ Context::~Context() /* ************************************************************************ */ -Size Context::getSize() const noexcept +math::Size Context::getSize() const noexcept { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); @@ -133,7 +133,7 @@ Size Context::getSize() const noexcept const auto width = viewport[2]; const auto height = viewport[3]; - return Size(width, height); + return math::Size(width, height); } /* ************************************************************************ */ @@ -249,8 +249,8 @@ void Context::setView(int width, int height) noexcept // Move camera glTranslatef( - static_cast(m_camera.getPosition().getX().value()), - static_cast(m_camera.getPosition().getY().value()), + static_cast(m_camera.getPosition().getX()), + static_cast(m_camera.getPosition().getY()), 0 ); @@ -397,34 +397,34 @@ void Context::matrixIdentity() noexcept /* ************************************************************************ */ -void Context::matrixTranslate(const units::PositionVector& pos) noexcept +void Context::matrixTranslate(const unit::PositionVector& pos) noexcept { gl(glTranslatef( - static_cast(pos.getX().value()), - static_cast(pos.getY().value()), + static_cast(pos.getX()), + static_cast(pos.getY()), 0.0f )); } /* ************************************************************************ */ -void Context::matrixScale(const units::ScaleVector& scale) noexcept +void Context::matrixScale(const unit::ScaleVector& scale) noexcept { gl(glScalef( - static_cast(scale.getX()), - static_cast(scale.getY()), + static_cast(scale.getX()), + static_cast(scale.getY()), 1.0f )); } /* ************************************************************************ */ -void Context::matrixRotate(units::Angle angle) noexcept +void Context::matrixRotate(unit::Angle angle) noexcept { gl(glRotatef( - static_cast(units::rad2deg(angle.value())), - 0.f, - 0.f, + static_cast(unit::rad2deg(angle)), + 0.f, + 0.f, 1.f )); } @@ -631,9 +631,9 @@ void Context::draw(PrimitiveType type, unsigned int count, unsigned int offset) /* ************************************************************************ */ -void Context::drawLine(Vector pos, Vector size, const Color& color) +void Context::drawLine(math::Vector pos, math::Vector size, const Color& color) { - if (size == Zero) + if (size == math::Zero) return; const auto pos2 = pos + size; diff --git a/cece/render/Grid.cpp b/src/render/Grid.cpp similarity index 92% rename from cece/render/Grid.cpp rename to src/render/Grid.cpp index 77df491..12c9ed0 100644 --- a/cece/render/Grid.cpp +++ b/src/render/Grid.cpp @@ -27,7 +27,7 @@ #include "cece/render/Grid.hpp" // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/Context.hpp" #include "cece/render/VertexFormat.hpp" @@ -69,7 +69,7 @@ void Grid::draw(Context& context) noexcept /* ************************************************************************ */ -void Grid::resize(Size size) noexcept +void Grid::resize(math::Size size) noexcept { GridBase::resize(std::move(size)); @@ -77,8 +77,8 @@ void Grid::resize(Size size) noexcept const auto width = getSize().getWidth(); const auto height = getSize().getHeight(); - const auto start = Vector::createSingle(-0.5f); - const Vector step = getSize().inversed(); + const auto start = math::Vector::createSingle(-0.5f); + const math::Vector step = getSize().inversed(); struct Vertex { float x, y; }; @@ -86,14 +86,14 @@ void Grid::resize(Size size) noexcept vertices.reserve((width + 1) * (height + 1)); // X lines - for (Size::ValueType i = 0; i <= width; ++i) + for (math::Size::ValueType i = 0; i <= width; ++i) { vertices.push_back(Vertex{start.getX() + i * step.getX(), start.getY()}); vertices.push_back(Vertex{start.getX() + i * step.getX(), start.getY() + 1.f}); } // Y lines - for (Size::ValueType i = 0; i <= height; ++i) + for (math::Size::ValueType i = 0; i <= height; ++i) { vertices.push_back(Vertex{start.getX(), start.getY() + i * step.getY()}); vertices.push_back(Vertex{start.getX() + 1.f, start.getY() + i * step.getY()}); diff --git a/cece/render/GridColor.cpp b/src/render/GridColor.cpp similarity index 96% rename from cece/render/GridColor.cpp rename to src/render/GridColor.cpp index 54e0c2d..0985bbe 100644 --- a/cece/render/GridColor.cpp +++ b/src/render/GridColor.cpp @@ -27,7 +27,7 @@ #include "cece/render/GridColor.hpp" // CeCe -#include "cece/core/StaticArray.hpp" +#include "cece/StaticArray.hpp" #include "cece/render/Context.hpp" #include "cece/render/VertexFormat.hpp" #include "cece/render/Image.hpp" @@ -66,7 +66,7 @@ GridColor::GridColor(Context& context) /* ************************************************************************ */ -GridColor::GridColor(Context& context, Size size) +GridColor::GridColor(Context& context, math::Size size) : GridColor(context) { resize(std::move(size)); @@ -107,7 +107,7 @@ void GridColor::draw(Context& context) noexcept /* ************************************************************************ */ -void GridColor::resize(Size size, const Color& color) +void GridColor::resize(math::Size size, const Color& color) { GridBase::resize(std::move(size)); diff --git a/cece/render/GridColorColorMap.cpp b/src/render/GridColorColorMap.cpp similarity index 100% rename from cece/render/GridColorColorMap.cpp rename to src/render/GridColorColorMap.cpp diff --git a/cece/render/GridColorSmooth.cpp b/src/render/GridColorSmooth.cpp similarity index 100% rename from cece/render/GridColorSmooth.cpp rename to src/render/GridColorSmooth.cpp diff --git a/cece/render/GridVector.cpp b/src/render/GridVector.cpp similarity index 88% rename from cece/render/GridVector.cpp rename to src/render/GridVector.cpp index f3137c6..c5f46df 100644 --- a/cece/render/GridVector.cpp +++ b/src/render/GridVector.cpp @@ -30,7 +30,7 @@ #include // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/Context.hpp" #include "cece/render/VertexFormat.hpp" @@ -49,7 +49,7 @@ namespace render { /* ************************************************************************ */ -GridVector::GridVector(Context& context, Size size, const Vector* data, RealType max) +GridVector::GridVector(Context& context, math::Size size, const math::Vector* data, RealType max) : m_buffer(context) , m_max(max) { @@ -78,7 +78,7 @@ void GridVector::draw(Context& context) noexcept /* ************************************************************************ */ -void GridVector::resize(Size size, const Vector* data) +void GridVector::resize(math::Size size, const math::Vector* data) { GridBase::resize(std::move(size)); @@ -87,12 +87,12 @@ void GridVector::resize(Size size, const Vector* data) /* ************************************************************************ */ -void GridVector::update(const Vector* data) noexcept +void GridVector::update(const math::Vector* data) noexcept { const auto size = getSize(); - const auto start = Vector::createSingle(-0.5); - const Vector step = getSize().inversed(); + const auto start = math::Vector::createSingle(-0.5); + const math::Vector step = getSize().inversed(); const auto width = size.getWidth(); const auto height = size.getHeight(); @@ -101,19 +101,19 @@ void GridVector::update(const Vector* data) noexcept vertices.reserve(2 * width * height); // Draw grid vectors - for (Size::ValueType j = 0; j < height; ++j) + for (math::Size::ValueType j = 0; j < height; ++j) { - for (Size::ValueType i = 0; i < width; ++i) + for (math::Size::ValueType i = 0; i < width; ++i) { // Get vector normalized by max length const auto vec = data[i + j * width] / m_max; - const Vector pos{ + const math::Vector pos{ start.getX() + i * step.getX() + step.getX() / RealType(2.0), start.getY() + j * step.getY() + step.getY() / RealType(2.0) }; const RealType gray = std::min(vec.getLength(), 1.0); - const Vector dest = pos + vec * step; + const math::Vector dest = pos + vec * step; // Source vertex vertices.push_back(Vertex{ diff --git a/cece/render/Image.cpp b/src/render/Image.cpp similarity index 96% rename from cece/render/Image.cpp rename to src/render/Image.cpp index c34f2bd..653b11d 100644 --- a/cece/render/Image.cpp +++ b/src/render/Image.cpp @@ -37,14 +37,14 @@ Image::Image() = default; /* ************************************************************************ */ -Image::Image(Size size) +Image::Image(math::Size size) { resize(std::move(size)); } /* ************************************************************************ */ -void Image::resize(Size size, const Color& color) +void Image::resize(math::Size size, const Color& color) { // Resize color grid m_colors.resize(size, color); diff --git a/cece/render/Lines.cpp b/src/render/Lines.cpp similarity index 99% rename from cece/render/Lines.cpp rename to src/render/Lines.cpp index 3e19199..adc7f72 100644 --- a/cece/render/Lines.cpp +++ b/src/render/Lines.cpp @@ -30,7 +30,7 @@ #include // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/Color.hpp" #include "cece/render/Context.hpp" #include "cece/render/VertexFormat.hpp" diff --git a/cece/render/Object.cpp b/src/render/Object.cpp similarity index 100% rename from cece/render/Object.cpp rename to src/render/Object.cpp diff --git a/cece/render/PhysicsDebugger.cpp b/src/render/PhysicsDebugger.cpp similarity index 100% rename from cece/render/PhysicsDebugger.cpp rename to src/render/PhysicsDebugger.cpp diff --git a/cece/render/Program.cpp b/src/render/Program.cpp similarity index 97% rename from cece/render/Program.cpp rename to src/render/Program.cpp index 4e3c1df..47a6109 100644 --- a/cece/render/Program.cpp +++ b/src/render/Program.cpp @@ -27,10 +27,10 @@ #include "cece/render/Program.hpp" // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Exception.hpp" +#include "cece/Assert.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/String.hpp" +#include "cece/Exception.hpp" #include "cece/render/OpenGL.hpp" #include "cece/render/errors.hpp" diff --git a/cece/render/Rectangle.cpp b/src/render/Rectangle.cpp similarity index 100% rename from cece/render/Rectangle.cpp rename to src/render/Rectangle.cpp diff --git a/cece/render/Shader.cpp b/src/render/Shader.cpp similarity index 97% rename from cece/render/Shader.cpp rename to src/render/Shader.cpp index 68b4d3a..a0bfa4d 100644 --- a/cece/render/Shader.cpp +++ b/src/render/Shader.cpp @@ -27,10 +27,10 @@ #include "cece/render/Shader.hpp" // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/DynamicArray.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Exception.hpp" +#include "cece/Assert.hpp" +#include "cece/DynamicArray.hpp" +#include "cece/String.hpp" +#include "cece/Exception.hpp" #include "cece/render/OpenGL.hpp" #include "cece/render/errors.hpp" diff --git a/cece/render/Texture.cpp b/src/render/Texture.cpp similarity index 94% rename from cece/render/Texture.cpp rename to src/render/Texture.cpp index dd6d041..6e683d9 100644 --- a/cece/render/Texture.cpp +++ b/src/render/Texture.cpp @@ -27,8 +27,8 @@ #include "cece/render/Texture.hpp" // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/DynamicArray.hpp" +#include "cece/Assert.hpp" +#include "cece/DynamicArray.hpp" #include "cece/render/OpenGL.hpp" #include "cece/render/errors.hpp" @@ -87,7 +87,7 @@ Texture::Texture(Context& context, bool filter) /* ************************************************************************ */ -Texture::Texture(Context& context, Size size, const Color& color, bool filter) +Texture::Texture(Context& context, math::Size size, const Color& color, bool filter) : Texture(context, filter) { // Init texture @@ -117,7 +117,7 @@ void Texture::clear(const Color& color) /* ************************************************************************ */ -void Texture::resize(Size size, const Color& color) +void Texture::resize(math::Size size, const Color& color) { CECE_ASSERT(isInitialized()); @@ -146,7 +146,7 @@ void Texture::update(const Color* colors) /* ************************************************************************ */ -void Texture::create(Size size, const Color* colors) +void Texture::create(math::Size size, const Color* colors) { CECE_ASSERT(isInitialized()); @@ -161,7 +161,7 @@ void Texture::create(Size size, const Color* colors) /* ************************************************************************ */ -void Texture::createGray(Size size, const unsigned char* colors) +void Texture::createGray(math::Size size, const unsigned char* colors) { CECE_ASSERT(isInitialized()); diff --git a/cece/render/errors.cpp b/src/render/errors.cpp similarity index 94% rename from cece/render/errors.cpp rename to src/render/errors.cpp index 326b6a6..87bb4b3 100644 --- a/cece/render/errors.cpp +++ b/src/render/errors.cpp @@ -27,9 +27,9 @@ #include "cece/render/errors.hpp" // CeCe -#include "cece/core/Map.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Exception.hpp" +#include "cece/Map.hpp" +#include "cece/String.hpp" +#include "cece/Exception.hpp" /* ************************************************************************ */ diff --git a/src/render/fs.colormap.hpp b/src/render/fs.colormap.hpp new file mode 100644 index 0000000..4413860 --- /dev/null +++ b/src/render/fs.colormap.hpp @@ -0,0 +1,124 @@ +#include + +// 2015-11-24 16:01:57 CET +// #5673059437276135070 +static const std::array g_fragmentShader = {{ + 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x20, 0x31, 0x32, 0x30, 0x0a, 0x0a, 0x75, 0x6e, + 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, + 0x64, 0x61, 0x74, 0x61, 0x3b, 0x0a, 0x0a, 0x76, + 0x65, 0x63, 0x34, 0x20, 0x63, 0x6f, 0x6c, 0x6f, + 0x72, 0x6d, 0x61, 0x70, 0x28, 0x66, 0x6c, 0x6f, + 0x61, 0x74, 0x20, 0x78, 0x29, 0x3b, 0x0a, 0x0a, + 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x76, + 0x65, 0x63, 0x34, 0x20, 0x70, 0x69, 0x78, 0x20, + 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, + 0x65, 0x32, 0x44, 0x28, 0x64, 0x61, 0x74, 0x61, + 0x2c, 0x20, 0x67, 0x6c, 0x5f, 0x54, 0x65, 0x78, + 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b, 0x30, 0x5d, + 0x2e, 0x78, 0x79, 0x29, 0x3b, 0x0a, 0x09, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x28, 0x70, 0x69, 0x78, + 0x2e, 0x61, 0x20, 0x3e, 0x20, 0x30, 0x2e, 0x35, + 0x29, 0x0a, 0x09, 0x09, 0x67, 0x6c, 0x5f, 0x46, + 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, + 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x28, 0x70, 0x69, 0x78, 0x2e, + 0x72, 0x29, 0x3b, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x20, 0x0a, 0x09, 0x09, 0x67, 0x6c, 0x5f, + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, + 0x72, 0x20, 0x3d, 0x20, 0x70, 0x69, 0x78, 0x3b, + 0x0a, 0x7d, 0x0a, 0x0a, 0x2f, 0x2f, 0x20, 0x68, + 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x6b, 0x62, 0x69, 0x6e, 0x61, 0x6e, + 0x69, 0x2f, 0x67, 0x6c, 0x73, 0x6c, 0x2d, 0x63, + 0x6f, 0x6c, 0x6f, 0x72, 0x6d, 0x61, 0x70, 0x0a, + 0x2f, 0x2f, 0x20, 0x68, 0x74, 0x74, 0x70, 0x73, + 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x62, + 0x69, 0x6e, 0x61, 0x6e, 0x69, 0x2f, 0x67, 0x6c, + 0x73, 0x6c, 0x2d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x2f, 0x62, 0x6c, 0x6f, 0x62, + 0x2f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2f, + 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, + 0x4d, 0x41, 0x54, 0x4c, 0x41, 0x42, 0x5f, 0x6a, + 0x65, 0x74, 0x2e, 0x66, 0x72, 0x61, 0x67, 0x0a, + 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x63, + 0x6f, 0x6c, 0x6f, 0x72, 0x6d, 0x61, 0x70, 0x5f, + 0x72, 0x65, 0x64, 0x28, 0x66, 0x6c, 0x6f, 0x61, + 0x74, 0x20, 0x78, 0x29, 0x20, 0x7b, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x78, + 0x20, 0x3c, 0x20, 0x30, 0x2e, 0x37, 0x29, 0x20, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x34, 0x2e, 0x30, 0x20, 0x2a, 0x20, 0x78, + 0x20, 0x2d, 0x20, 0x31, 0x2e, 0x35, 0x3b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x7d, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x2d, 0x34, 0x2e, 0x30, + 0x20, 0x2a, 0x20, 0x78, 0x20, 0x2b, 0x20, 0x34, + 0x2e, 0x35, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x7d, 0x0a, 0x7d, 0x0a, 0x0a, 0x66, 0x6c, 0x6f, + 0x61, 0x74, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x5f, 0x67, 0x72, 0x65, 0x65, + 0x6e, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, + 0x78, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x28, 0x78, 0x20, 0x3c, + 0x20, 0x30, 0x2e, 0x35, 0x29, 0x20, 0x7b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, + 0x2e, 0x30, 0x20, 0x2a, 0x20, 0x78, 0x20, 0x2d, + 0x20, 0x30, 0x2e, 0x35, 0x3b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x7d, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x2d, 0x34, 0x2e, 0x30, 0x20, 0x2a, + 0x20, 0x78, 0x20, 0x2b, 0x20, 0x33, 0x2e, 0x35, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0a, + 0x7d, 0x0a, 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74, + 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x6d, 0x61, + 0x70, 0x5f, 0x62, 0x6c, 0x75, 0x65, 0x28, 0x66, + 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x78, 0x29, 0x20, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x28, 0x78, 0x20, 0x3c, 0x20, 0x30, 0x2e, + 0x33, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x34, 0x2e, 0x30, 0x20, 0x2a, + 0x20, 0x78, 0x20, 0x2b, 0x20, 0x30, 0x2e, 0x35, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x20, 0x7b, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x2d, 0x34, 0x2e, + 0x30, 0x20, 0x2a, 0x20, 0x78, 0x20, 0x2b, 0x20, + 0x32, 0x2e, 0x35, 0x3b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x7d, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, 0x65, + 0x63, 0x34, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x28, 0x66, 0x6c, 0x6f, 0x61, + 0x74, 0x20, 0x78, 0x29, 0x20, 0x7b, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, + 0x20, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x6d, 0x70, 0x28, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x5f, 0x72, 0x65, 0x64, 0x28, + 0x78, 0x29, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x2c, + 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, + 0x20, 0x67, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x6d, 0x70, 0x28, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x6d, 0x61, 0x70, 0x5f, 0x67, 0x72, 0x65, 0x65, + 0x6e, 0x28, 0x78, 0x29, 0x2c, 0x20, 0x30, 0x2e, + 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, + 0x61, 0x74, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x63, + 0x6c, 0x61, 0x6d, 0x70, 0x28, 0x63, 0x6f, 0x6c, + 0x6f, 0x72, 0x6d, 0x61, 0x70, 0x5f, 0x62, 0x6c, + 0x75, 0x65, 0x28, 0x78, 0x29, 0x2c, 0x20, 0x30, + 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x65, 0x63, + 0x34, 0x28, 0x72, 0x2c, 0x20, 0x67, 0x2c, 0x20, + 0x62, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, + 0x0a, 0x7d, 0x0a, 0x00 +}}; diff --git a/src/render/fs.smooth.hpp b/src/render/fs.smooth.hpp new file mode 100644 index 0000000..f2bd25b --- /dev/null +++ b/src/render/fs.smooth.hpp @@ -0,0 +1,116 @@ +#include + +// 2015-06-04 13:08:09 CEST +// #18384844364078070070 +static const std::array g_fragmentShader = { + 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x20, 0x31, 0x32, 0x30, 0x0a, 0x75, 0x6e, 0x69, + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x64, + 0x61, 0x74, 0x61, 0x3b, 0x0a, 0x75, 0x6e, 0x69, + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x69, 0x76, 0x65, + 0x63, 0x32, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, + 0x3d, 0x20, 0x69, 0x76, 0x65, 0x63, 0x32, 0x28, + 0x31, 0x36, 0x2c, 0x20, 0x31, 0x36, 0x29, 0x3b, + 0x0a, 0x0a, 0x76, 0x65, 0x63, 0x34, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x70, 0x69, 0x78, 0x65, 0x6c, + 0x28, 0x76, 0x65, 0x63, 0x32, 0x20, 0x70, 0x6f, + 0x73, 0x29, 0x20, 0x0a, 0x7b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, + 0x32, 0x44, 0x28, 0x64, 0x61, 0x74, 0x61, 0x2c, + 0x20, 0x70, 0x6f, 0x73, 0x29, 0x3b, 0x0a, 0x7d, + 0x0a, 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, + 0x74, 0x72, 0x69, 0x61, 0x6e, 0x67, 0x75, 0x6c, + 0x61, 0x72, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, + 0x20, 0x66, 0x29, 0x20, 0x0a, 0x7b, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x66, + 0x20, 0x2a, 0x20, 0x30, 0x2e, 0x35, 0x3b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, + 0x66, 0x20, 0x3c, 0x20, 0x30, 0x2e, 0x30, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x28, 0x66, 0x20, 0x2b, 0x20, 0x31, 0x2e, 0x30, + 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x28, 0x31, 0x2e, 0x30, 0x20, + 0x2d, 0x20, 0x66, 0x29, 0x3b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x30, 0x2e, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, + 0x0a, 0x76, 0x65, 0x63, 0x34, 0x20, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x70, 0x6f, 0x6c, 0x61, 0x74, + 0x65, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x28, + 0x76, 0x65, 0x63, 0x32, 0x20, 0x70, 0x6f, 0x73, + 0x29, 0x20, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x74, 0x65, + 0x78, 0x65, 0x6c, 0x53, 0x69, 0x7a, 0x65, 0x20, + 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x20, 0x2f, 0x20, + 0x73, 0x69, 0x7a, 0x65, 0x3b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x73, + 0x75, 0x6d, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, + 0x34, 0x28, 0x30, 0x2e, 0x30, 0x29, 0x3b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, + 0x20, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x20, 0x3d, + 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x30, 0x2e, + 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x62, 0x20, + 0x3d, 0x20, 0x66, 0x72, 0x61, 0x63, 0x74, 0x28, + 0x70, 0x6f, 0x73, 0x20, 0x2a, 0x20, 0x73, 0x69, + 0x7a, 0x65, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, + 0x72, 0x20, 0x28, 0x69, 0x6e, 0x74, 0x20, 0x6d, + 0x20, 0x3d, 0x20, 0x2d, 0x31, 0x3b, 0x20, 0x6d, + 0x20, 0x3c, 0x3d, 0x20, 0x32, 0x3b, 0x20, 0x6d, + 0x2b, 0x2b, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, + 0x72, 0x20, 0x28, 0x69, 0x6e, 0x74, 0x20, 0x6e, + 0x20, 0x3d, 0x20, 0x2d, 0x31, 0x3b, 0x20, 0x6e, + 0x20, 0x3c, 0x3d, 0x20, 0x32, 0x3b, 0x20, 0x6e, + 0x2b, 0x2b, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x6d, + 0x6e, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x32, + 0x28, 0x6d, 0x2c, 0x20, 0x6e, 0x29, 0x3b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, + 0x20, 0x70, 0x69, 0x78, 0x20, 0x3d, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x70, 0x69, 0x78, 0x65, 0x6c, + 0x28, 0x70, 0x6f, 0x73, 0x20, 0x2b, 0x20, 0x76, + 0x65, 0x63, 0x32, 0x28, 0x74, 0x65, 0x78, 0x65, + 0x6c, 0x53, 0x69, 0x7a, 0x65, 0x20, 0x2a, 0x20, + 0x6d, 0x6e, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x66, + 0x20, 0x3d, 0x20, 0x6d, 0x6e, 0x20, 0x2d, 0x20, + 0x61, 0x62, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x63, 0x20, + 0x3d, 0x20, 0x74, 0x72, 0x69, 0x61, 0x6e, 0x67, + 0x75, 0x6c, 0x61, 0x72, 0x28, 0x66, 0x2e, 0x78, + 0x29, 0x20, 0x2a, 0x20, 0x74, 0x72, 0x69, 0x61, + 0x6e, 0x67, 0x75, 0x6c, 0x61, 0x72, 0x28, 0x66, + 0x2e, 0x79, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x73, 0x75, 0x6d, 0x20, 0x2b, 0x3d, 0x20, + 0x70, 0x69, 0x78, 0x20, 0x2a, 0x20, 0x63, 0x3b, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x6e, + 0x6f, 0x6d, 0x20, 0x2b, 0x3d, 0x20, 0x63, 0x3b, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, + 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x28, 0x73, 0x75, + 0x6d, 0x20, 0x2f, 0x20, 0x64, 0x65, 0x6e, 0x6f, + 0x6d, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, + 0x28, 0x29, 0x20, 0x0a, 0x7b, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, + 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, + 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x6f, + 0x6c, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x28, 0x67, 0x6c, 0x5f, 0x54, 0x65, + 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b, 0x30, + 0x5d, 0x2e, 0x78, 0x79, 0x29, 0x3b, 0x0a, 0x7d, + 0x0a, 0x00 +}; diff --git a/src/render/vs.colormap.hpp b/src/render/vs.colormap.hpp new file mode 100644 index 0000000..e895b7d --- /dev/null +++ b/src/render/vs.colormap.hpp @@ -0,0 +1,17 @@ +#include + +// 2015-11-24 16:01:57 CET +// #9630938012333006964 +static const std::array g_vertexShader = {{ + 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, + 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, + 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x66, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, + 0x28, 0x29, 0x3b, 0x0a, 0x09, 0x67, 0x6c, 0x5f, + 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, + 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x6c, + 0x5f, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x54, 0x65, + 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, + 0x0a, 0x7d, 0x0a, 0x00 +}}; diff --git a/src/render/vs.smooth.hpp b/src/render/vs.smooth.hpp new file mode 100644 index 0000000..93ddcad --- /dev/null +++ b/src/render/vs.smooth.hpp @@ -0,0 +1,17 @@ +#include + +// 2015-06-04 13:08:09 CEST +// #7432198920397255447 +static const std::array g_vertexShader = { + 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x67, + 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x66, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x28, + 0x29, 0x3b, 0x0a, 0x09, 0x67, 0x6c, 0x5f, 0x54, + 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b, + 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x6c, 0x5f, + 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x54, 0x65, 0x78, + 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, + 0x7d, 0x0a, 0x00 +}; diff --git a/cece/simulator/CMakeLists.txt b/src/simulation/CMakeLists.txt similarity index 74% rename from cece/simulator/CMakeLists.txt rename to src/simulation/CMakeLists.txt index 42c5d9d..3db90b2 100644 --- a/cece/simulator/CMakeLists.txt +++ b/src/simulation/CMakeLists.txt @@ -25,25 +25,43 @@ # Sources set(SRCS - Simulation.hpp Simulation.cpp - Simulator.hpp - Simulator.cpp - TimeMeasurement.hpp TimeMeasurement.cpp - Visualization.hpp - Visualization.cpp - VisualizationLayer.hpp - DefaultSimulation.hpp DefaultSimulation.cpp - ConverterBox2D.hpp ConverterBox2D.cpp + Loader.cpp + LoaderFactory.cpp + LoaderFactoryManager.cpp + Module.cpp + ModuleFactory.cpp + ModuleFactoryManager.cpp + ModuleContainer.cpp + ExportModule.cpp + Initializer.cpp + InitializerContainer.cpp + InitializerFactory.cpp + InitializerFactoryManager.cpp + Object.cpp + ObjectTypeContainer.cpp + ObjectFactory.cpp + ObjectFactoryManager.cpp + ObjectContainer.cpp + ObjectBoundData.cpp + ObjectContactListener.cpp + ProgramContainer.cpp + ProgramNamedContainer.cpp + ProgramFactory.cpp + ProgramFactoryManager.cpp ) +if (CECE_RENDER) + set(SRCS ${SRCS} Visualization.cpp) +endif () + # ######################################################################### # -dir_pretend(SOURCES simulator/ ${SRCS}) +dir_pretend(SOURCES simulation/ ${SRCS}) -set(SOURCES_SIMULATOR ${SOURCES} PARENT_SCOPE) +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) # ######################################################################### # diff --git a/cece/simulator/ConverterBox2D.cpp b/src/simulation/ConverterBox2D.cpp similarity index 70% rename from cece/simulator/ConverterBox2D.cpp rename to src/simulation/ConverterBox2D.cpp index 39b2a35..e0e6303 100644 --- a/cece/simulator/ConverterBox2D.cpp +++ b/src/simulation/ConverterBox2D.cpp @@ -24,12 +24,12 @@ /* ************************************************************************ */ // Declaration -#include "cece/simulator/ConverterBox2D.hpp" +#include "ConverterBox2D.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -40,16 +40,16 @@ RealType ConverterBox2D::getTimeCoefficient() const noexcept /* ************************************************************************ */ -units::Length ConverterBox2D::convertLength(float32 length) const noexcept +unit::Length ConverterBox2D::convertLength(float32 length) const noexcept { const auto coeff = 1.0 / getLengthCoefficient(); - return coeff * units::Length(length); + return coeff * unit::Length(length); } /* ************************************************************************ */ -float32 ConverterBox2D::convertLength(units::Length length) const noexcept +float32 ConverterBox2D::convertLength(unit::Length length) const noexcept { const auto coeff = getLengthCoefficient(); @@ -58,19 +58,19 @@ float32 ConverterBox2D::convertLength(units::Length length) const noexcept /* ************************************************************************ */ -units::PositionVector ConverterBox2D::convertPosition(b2Vec2 position) const noexcept +unit::PositionVector ConverterBox2D::convertPosition(b2Vec2 position) const noexcept { const auto coeff = 1.0 / getLengthCoefficient(); - return coeff * units::PositionVector{ - units::Length(position.x), - units::Length(position.y) + return coeff * unit::PositionVector{ + unit::Length(position.x), + unit::Length(position.y) }; } /* ************************************************************************ */ -b2Vec2 ConverterBox2D::convertPosition(units::PositionVector position) const noexcept +b2Vec2 ConverterBox2D::convertPosition(unit::PositionVector position) const noexcept { const auto coeff = getLengthCoefficient(); @@ -82,33 +82,33 @@ b2Vec2 ConverterBox2D::convertPosition(units::PositionVector position) const noe /* ************************************************************************ */ -units::Angle ConverterBox2D::convertAngle(float32 angle) const noexcept +unit::Angle ConverterBox2D::convertAngle(float32 angle) const noexcept { - return units::Angle{angle}; + return unit::Angle{angle}; } /* ************************************************************************ */ -float32 ConverterBox2D::convertAngle(units::Angle angle) const noexcept +float32 ConverterBox2D::convertAngle(unit::Angle angle) const noexcept { return static_cast(angle.value()); } /* ************************************************************************ */ -units::VelocityVector ConverterBox2D::convertLinearVelocity(b2Vec2 velocity) const noexcept +unit::VelocityVector ConverterBox2D::convertLinearVelocity(b2Vec2 velocity) const noexcept { const auto coeff = getTimeCoefficient() / getLengthCoefficient(); - return coeff * units::VelocityVector{ - units::Velocity(velocity.x), - units::Velocity(velocity.y) + return coeff * unit::VelocityVector{ + unit::Velocity(velocity.x), + unit::Velocity(velocity.y) }; } /* ************************************************************************ */ -b2Vec2 ConverterBox2D::convertLinearVelocity(units::VelocityVector velocity) const noexcept +b2Vec2 ConverterBox2D::convertLinearVelocity(unit::VelocityVector velocity) const noexcept { const auto coeff = getLengthCoefficient() / getTimeCoefficient(); @@ -120,16 +120,16 @@ b2Vec2 ConverterBox2D::convertLinearVelocity(units::VelocityVector velocity) con /* ************************************************************************ */ -units::AngularVelocity ConverterBox2D::convertAngularVelocity(float32 velocity) const noexcept +unit::AngularVelocity ConverterBox2D::convertAngularVelocity(float32 velocity) const noexcept { const auto coeff = getTimeCoefficient(); - return coeff * units::AngularVelocity{velocity}; + return coeff * unit::AngularVelocity{velocity}; } /* ************************************************************************ */ -float32 ConverterBox2D::convertAngularVelocity(units::AngularVelocity velocity) const noexcept +float32 ConverterBox2D::convertAngularVelocity(unit::AngularVelocity velocity) const noexcept { const auto coeff = 1.0 / getTimeCoefficient(); @@ -138,19 +138,19 @@ float32 ConverterBox2D::convertAngularVelocity(units::AngularVelocity velocity) /* ************************************************************************ */ -units::AccelerationVector ConverterBox2D::convertLinearAcceleration(b2Vec2 acceleration) const noexcept +unit::AccelerationVector ConverterBox2D::convertLinearAcceleration(b2Vec2 acceleration) const noexcept { const auto coeff = (getTimeCoefficient() * getTimeCoefficient()) / getLengthCoefficient(); - return coeff * units::AccelerationVector( - units::Acceleration(acceleration.x), - units::Acceleration(acceleration.y) + return coeff * unit::AccelerationVector( + unit::Acceleration(acceleration.x), + unit::Acceleration(acceleration.y) ); } /* ************************************************************************ */ -b2Vec2 ConverterBox2D::convertLinearAcceleration(units::AccelerationVector acceleration) const noexcept +b2Vec2 ConverterBox2D::convertLinearAcceleration(unit::AccelerationVector acceleration) const noexcept { const auto coeff = getLengthCoefficient() / (getTimeCoefficient() * getTimeCoefficient()); @@ -162,35 +162,35 @@ b2Vec2 ConverterBox2D::convertLinearAcceleration(units::AccelerationVector accel /* ************************************************************************ */ -units::Acceleration ConverterBox2D::convertAngularAcceleration(float32 acceleration) const noexcept +unit::Acceleration ConverterBox2D::convertAngularAcceleration(float32 acceleration) const noexcept { const auto coeff = 1; - return coeff * units::Acceleration(acceleration); + return coeff * unit::Acceleration(acceleration); } /* ************************************************************************ */ -float32 ConverterBox2D::convertAngularAcceleration(units::Acceleration acceleration) const noexcept +float32 ConverterBox2D::convertAngularAcceleration(unit::Acceleration acceleration) const noexcept { return static_cast(acceleration.value()); } /* ************************************************************************ */ -units::ForceVector ConverterBox2D::convertForce(b2Vec2 force) const noexcept +unit::ForceVector ConverterBox2D::convertForce(b2Vec2 force) const noexcept { const auto coeff = (getTimeCoefficient() * getTimeCoefficient()) / getLengthCoefficient(); - return coeff * units::ForceVector( - units::Force(force.x), - units::Force(force.y) + return coeff * unit::ForceVector( + unit::Force(force.x), + unit::Force(force.y) ); } /* ************************************************************************ */ -b2Vec2 ConverterBox2D::convertForce(units::ForceVector force) const noexcept +b2Vec2 ConverterBox2D::convertForce(unit::ForceVector force) const noexcept { const auto coeff = getLengthCoefficient() / (getTimeCoefficient() * getTimeCoefficient()); @@ -202,16 +202,16 @@ b2Vec2 ConverterBox2D::convertForce(units::ForceVector force) const noexcept /* ************************************************************************ */ -units::Force ConverterBox2D::convertTorque(float32 torque) const noexcept +unit::Force ConverterBox2D::convertTorque(float32 torque) const noexcept { const auto coeff = (getTimeCoefficient() * getTimeCoefficient()) / getLengthCoefficient(); - return coeff * units::Force{torque}; + return coeff * unit::Force{torque}; } /* ************************************************************************ */ -float32 ConverterBox2D::convertTorque(units::Force torque) const noexcept +float32 ConverterBox2D::convertTorque(unit::Force torque) const noexcept { const auto coeff = getLengthCoefficient() / (getTimeCoefficient() * getTimeCoefficient()); @@ -220,19 +220,19 @@ float32 ConverterBox2D::convertTorque(units::Force torque) const noexcept /* ************************************************************************ */ -units::ImpulseVector ConverterBox2D::convertLinearImpulse(b2Vec2 impulse) const noexcept +unit::ImpulseVector ConverterBox2D::convertLinearImpulse(b2Vec2 impulse) const noexcept { const auto coeff = getTimeCoefficient() / getLengthCoefficient(); - return coeff * units::ImpulseVector( - units::Impulse(impulse.x), - units::Impulse(impulse.y) + return coeff * unit::ImpulseVector( + unit::Impulse(impulse.x), + unit::Impulse(impulse.y) ); } /* ************************************************************************ */ -b2Vec2 ConverterBox2D::convertLinearImpulse(units::ImpulseVector impulse) const noexcept +b2Vec2 ConverterBox2D::convertLinearImpulse(unit::ImpulseVector impulse) const noexcept { const auto coeff = getLengthCoefficient() / getTimeCoefficient(); @@ -244,16 +244,16 @@ b2Vec2 ConverterBox2D::convertLinearImpulse(units::ImpulseVector impulse) const /* ************************************************************************ */ -units::Impulse ConverterBox2D::convertAngularImpulse(float32 impulse) const noexcept +unit::Impulse ConverterBox2D::convertAngularImpulse(float32 impulse) const noexcept { const auto coeff = getTimeCoefficient() / getLengthCoefficient(); - return coeff * units::Impulse{impulse}; + return coeff * unit::Impulse{impulse}; } /* ************************************************************************ */ -float32 ConverterBox2D::convertAngularImpulse(units::Impulse impulse) const noexcept +float32 ConverterBox2D::convertAngularImpulse(unit::Impulse impulse) const noexcept { const auto coeff = getLengthCoefficient() / getTimeCoefficient(); @@ -262,30 +262,30 @@ float32 ConverterBox2D::convertAngularImpulse(units::Impulse impulse) const noex /* ************************************************************************ */ -units::Mass ConverterBox2D::convertMass(float32 mass) const noexcept +unit::Mass ConverterBox2D::convertMass(float32 mass) const noexcept { - return units::Mass(mass); + return unit::Mass(mass); } /* ************************************************************************ */ -float32 ConverterBox2D::convertMass(units::Mass mass) const noexcept +float32 ConverterBox2D::convertMass(unit::Mass mass) const noexcept { return static_cast(mass.value()); } /* ************************************************************************ */ -units::Density ConverterBox2D::convertDensity(float32 density) const noexcept +unit::Density ConverterBox2D::convertDensity(float32 density) const noexcept { const auto coeff = 1.0 / (getLengthCoefficient() * getLengthCoefficient() * getLengthCoefficient()); - return coeff * units::Density(density); + return coeff * unit::Density(density); } /* ************************************************************************ */ -float32 ConverterBox2D::convertDensity(units::Density density) const noexcept +float32 ConverterBox2D::convertDensity(unit::Density density) const noexcept { const auto coeff = getLengthCoefficient() * getLengthCoefficient() * getLengthCoefficient(); @@ -294,11 +294,11 @@ float32 ConverterBox2D::convertDensity(units::Density density) const noexcept /* ************************************************************************ */ -units::Length ConverterBox2D::getMaxObjectTranslation() const noexcept +unit::Length ConverterBox2D::getMaxObjectTranslation() const noexcept { const auto coeff = 1.0 / getLengthCoefficient(); - return coeff * units::Length{b2_maxTranslation}; + return coeff * unit::Length{b2_maxTranslation}; } /* ************************************************************************ */ diff --git a/src/simulation/ConverterBox2D.hpp b/src/simulation/ConverterBox2D.hpp new file mode 100644 index 0000000..6c07ede --- /dev/null +++ b/src/simulation/ConverterBox2D.hpp @@ -0,0 +1,435 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#pragma once + +/* ************************************************************************ */ + +// Box2D +#include + +// CeCe +#include "cece/common.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/UnitsCtors.hpp" +#include "cece/unit/VectorUnits.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +/** + * @brief Simulation units <-> physics units converter. + * + * Used physics engine library can be tuned to specific range of values that + * may not match simulation values, so this class is responsible to convert + * values between those two systems. + */ +class ConverterBox2D +{ + +// Public Accessors +public: + + + /** + * @brief Returns simulation time step. + * + * @return + */ + unit::Time getTimeStep() const noexcept + { + return m_timeStep; + } + + + /** + * @brief Returns Box2D time step. + * + * @return + */ + unit::Time getTimeStepBox2D() const noexcept + { + return m_timeStepBox2D; + } + + + /** + * @brief Returns time coefficient. + * + * @return + */ + RealType getTimeCoefficient() const noexcept; + + + /** + * @brief Returns length coefficient. + * + * @return + */ + RealType getLengthCoefficient() const noexcept + { + return m_lengthCoefficient; + } + + +// Public Mutators +public: + + + /** + * @brief Change simulation time step. + * + * @param timeStep + */ + void setTimeStep(unit::Time timeStep) noexcept + { + m_timeStep = timeStep; + } + + + /** + * @brief Set Box2D time step. + * + * @param timeStep + */ + void setTimeStepBox2D(unit::Time timeStep) noexcept + { + m_timeStepBox2D = timeStep; + } + + + /** + * @brief Set length coefficient. + * + * @param value + */ + void setLengthCoefficient(RealType value) noexcept + { + m_lengthCoefficient = value; + } + + +// Public Operations +public: + + + /** + * @brief Convert length. + * + * @param length + * + * @return + */ + unit::Length convertLength(float32 length) const noexcept; + + + /** + * @brief Convert length. + * + * @param length + * + * @return + */ + float32 convertLength(unit::Length length) const noexcept; + + + /** + * @brief Convert position. + * + * @param position + * + * @return + */ + unit::PositionVector convertPosition(b2Vec2 position) const noexcept; + + + /** + * @brief Convert position. + * + * @param position + * + * @return + */ + b2Vec2 convertPosition(unit::PositionVector position) const noexcept; + + + /** + * @brief Convert rotation. + * + * @param angle + * + * @return + */ + unit::Angle convertAngle(float32 angle) const noexcept; + + + /** + * @brief Convert rotation. + * + * @param angle + * + * @return + */ + float32 convertAngle(unit::Angle angle) const noexcept; + + + /** + * @brief Convert linear velocity. + * + * @param velocity + * + * @return + */ + unit::VelocityVector convertLinearVelocity(b2Vec2 velocity) const noexcept; + + + /** + * @brief Convert linear velocity. + * + * @param velocity + * + * @return + */ + b2Vec2 convertLinearVelocity(unit::VelocityVector velocity) const noexcept; + + + /** + * @brief Convert angular velocity. + * + * @param velocity + * + * @return + */ + unit::AngularVelocity convertAngularVelocity(float32 velocity) const noexcept; + + + /** + * @brief Convert angular velocity. + * + * @param velocity + * + * @return + */ + float32 convertAngularVelocity(unit::AngularVelocity velocity) const noexcept; + + + /** + * @brief Convert linear acceleration. + * + * @param acceleration + * + * @return + */ + unit::AccelerationVector convertLinearAcceleration(b2Vec2 acceleration) const noexcept; + + + /** + * @brief Convert linear acceleration. + * + * @param acceleration + * + * @return + */ + b2Vec2 convertLinearAcceleration(unit::AccelerationVector acceleration) const noexcept; + + + /** + * @brief Convert angular acceleration. + * + * @param acceleration + * + * @return + */ + unit::Acceleration convertAngularAcceleration(float32 acceleration) const noexcept; + + + /** + * @brief Convert angular acceleration. + * + * @param acceleration + * + * @return + */ + float32 convertAngularAcceleration(unit::Acceleration acceleration) const noexcept; + + + /** + * @brief Convert force. + * + * @param force + * + * @return + */ + unit::ForceVector convertForce(b2Vec2 force) const noexcept; + + + /** + * @brief Convert force. + * + * @param force + * + * @return + */ + b2Vec2 convertForce(unit::ForceVector force) const noexcept; + + + /** + * @brief Convert torque. + * + * @param torque + * + * @return + */ + unit::Force convertTorque(float32 torque) const noexcept; + + + /** + * @brief Convert torque. + * + * @param torque + * + * @return + */ + float32 convertTorque(unit::Force torque) const noexcept; + + + /** + * @brief Convert impulse. + * + * @param impulse + * + * @return + */ + unit::ImpulseVector convertLinearImpulse(b2Vec2 impulse) const noexcept; + + + /** + * @brief Convert impulse. + * + * @param force + * + * @return + */ + b2Vec2 convertLinearImpulse(unit::ImpulseVector impulse) const noexcept; + + + /** + * @brief Convert impulse. + * + * @param impulse + * + * @return + */ + unit::Impulse convertAngularImpulse(float32 impulse) const noexcept; + + + /** + * @brief Convert impulse. + * + * @param impulse + * + * @return + */ + float32 convertAngularImpulse(unit::Impulse impulse) const noexcept; + + + /** + * @brief Convert mass. + * + * @param mass + * + * @return + */ + unit::Mass convertMass(float32 mass) const noexcept; + + + /** + * @brief Convert mass. + * + * @param mass + * + * @return + */ + float32 convertMass(unit::Mass mass) const noexcept; + + + /** + * @brief Convert density. + * + * @param density + * + * @return + */ + unit::Density convertDensity(float32 density) const noexcept; + + + /** + * @brief Convert density. + * + * @param density + * + * @return + */ + float32 convertDensity(unit::Density density) const noexcept; + + + /** + * @brief Returns maximum translation distance per iteration. + * + * @return + */ + unit::Length getMaxObjectTranslation() const noexcept; + + + /** + * @brief Returns converter instance. + * @return + */ + static ConverterBox2D& getInstance() noexcept; + + +// Private Data Members +private: + + /// Box2D time step. + unit::Time m_timeStepBox2D = unit::s(1.0 / 60.0); + + /// Simulation time step + unit::Time m_timeStep; + + /// Length coefficient. + RealType m_lengthCoefficient = 1; +}; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/simulator/DefaultSimulation.cpp b/src/simulation/DefaultSimulation.cpp similarity index 79% rename from cece/simulator/DefaultSimulation.cpp rename to src/simulation/DefaultSimulation.cpp index e0e9d3a..fb1556b 100644 --- a/cece/simulator/DefaultSimulation.cpp +++ b/src/simulation/DefaultSimulation.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/simulator/DefaultSimulation.hpp" +#include "cece/simulation/DefaultSimulation.hpp" // C++ #include @@ -37,29 +37,30 @@ #include // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/Real.hpp" -#include "cece/core/Log.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/OutStream.hpp" -#include "cece/core/FileStream.hpp" -#include "cece/core/UnitIo.hpp" +#include "cece/Assert.hpp" +#include "cece/Exception.hpp" +#include "cece/log/Log.hpp" +#include "cece/unit/UnitIo.hpp" +#include "cece/io/FileStream.hpp" +#include "cece/io/OutStream.hpp" #include "cece/plugin/Api.hpp" #include "cece/plugin/Manager.hpp" -#include "cece/init/Initializer.hpp" -#include "cece/module/Module.hpp" -#include "cece/object/ContactListener.hpp" -#include "cece/simulator/TimeMeasurement.hpp" -#include "cece/simulator/ConverterBox2D.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/ObjectContactListener.hpp" +#include "cece/simulation/TimeMeasurement.hpp" #ifdef CECE_RENDER # include "cece/render/PhysicsDebugger.hpp" #endif +// CeCe private +#include "../simulation/ConverterBox2D.hpp" + /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -81,7 +82,7 @@ render::PhysicsDebugger g_physicsDebugger; struct DefaultSimulation::ContactListener : public b2ContactListener { - object::ContactListener* m_listener; + simulation::ObjectContactListener* m_listener; void BeginContact(b2Contact* contact) override { @@ -90,8 +91,8 @@ struct DefaultSimulation::ContactListener : public b2ContactListener auto body1 = contact->GetFixtureA()->GetBody(); auto body2 = contact->GetFixtureB()->GetBody(); - auto o1 = static_cast(body1->GetUserData()); - auto o2 = static_cast(body2->GetUserData()); + auto o1 = static_cast(body1->GetUserData()); + auto o2 = static_cast(body2->GetUserData()); m_listener->onContact(*o1, *o2); } @@ -99,8 +100,9 @@ struct DefaultSimulation::ContactListener : public b2ContactListener /* ************************************************************************ */ -DefaultSimulation::DefaultSimulation(const plugin::Repository& repository, FilePath path) noexcept - : m_pluginContext(repository) +DefaultSimulation::DefaultSimulation(const plugin::Manager& manager, io::FilePath path) noexcept + : m_pluginManager(manager) + , m_pluginContext(m_pluginManager) , m_fileName(std::move(path)) , m_world{makeUnique(b2Vec2{0.0f, 0.0f})} { @@ -125,7 +127,7 @@ DefaultSimulation::~DefaultSimulation() /* ************************************************************************ */ -UniquePtr DefaultSimulation::getResource(StringView name) noexcept +UniquePtr DefaultSimulation::getResource(StringView name) noexcept { // Path to resource const auto path = getFileName().getParentPath() / String(name); @@ -133,12 +135,12 @@ UniquePtr DefaultSimulation::getResource(StringView name) noexcept if (!pathExists(path)) return nullptr; - auto file = makeUnique(path.toString(), std::ios::in | std::ios::out | std::ios::binary); + auto file = makeUnique(path.toString(), std::ios::in | std::ios::out | std::ios::binary); if (!file->is_open()) return nullptr; - return UniquePtr{file.release()}; + return UniquePtr{file.release()}; } /* ************************************************************************ */ @@ -164,7 +166,7 @@ bool DefaultSimulation::hasModule(StringView name) const noexcept /* ************************************************************************ */ -ViewPtr DefaultSimulation::getModule(StringView name) const noexcept +ViewPtr DefaultSimulation::getModule(StringView name) const noexcept { return m_modules.get(name); } @@ -178,7 +180,7 @@ bool DefaultSimulation::hasProgram(StringView name) const noexcept /* ************************************************************************ */ -UniquePtr DefaultSimulation::getProgram(StringView name) const +UniquePtr DefaultSimulation::getProgram(StringView name) const { auto program = m_programs.get(name); @@ -204,9 +206,9 @@ std::size_t DefaultSimulation::getObjectCount(StringView type) const noexcept /* ************************************************************************ */ -DynamicArray> DefaultSimulation::getObjects() const noexcept +DynamicArray> DefaultSimulation::getObjects() const noexcept { - DynamicArray> objects; + DynamicArray> objects; objects.reserve(m_objects.getCount()); for (const auto& object : m_objects) @@ -217,28 +219,28 @@ DynamicArray> DefaultSimulation::getObjects() const noex /* ************************************************************************ */ -DynamicArray> DefaultSimulation::getObjects(StringView type) const noexcept +DynamicArray> DefaultSimulation::getObjects(StringView type) const noexcept { return m_objects.getByType(type); } /* ************************************************************************ */ -units::AccelerationVector DefaultSimulation::getGravity() const noexcept +unit::AccelerationVector DefaultSimulation::getGravity() const noexcept { return ConverterBox2D::getInstance().convertLinearAcceleration(m_world->GetGravity()); } /* ************************************************************************ */ -units::Time DefaultSimulation::getPhysicsEngineTimeStep() const noexcept +unit::Time DefaultSimulation::getPhysicsEngineTimeStep() const noexcept { return ConverterBox2D::getInstance().getTimeStepBox2D(); } /* ************************************************************************ */ -units::Length DefaultSimulation::getMaxObjectTranslation() const noexcept +unit::Length DefaultSimulation::getMaxObjectTranslation() const noexcept { return ConverterBox2D::getInstance().getMaxObjectTranslation(); } @@ -253,7 +255,7 @@ ViewPtr DefaultSimulation::loadPlugin(StringView name) return nullptr; // Init simulation - api->initSimulation(*this); + //api->initSimulation(*this); return api; } @@ -268,14 +270,14 @@ void DefaultSimulation::unloadPlugin(StringView name) return; // Finalize simulation - api->finalizeSimulation(*this); + //api->finalizeSimulation(*this); } /* ************************************************************************ */ -void DefaultSimulation::setTimeStep(units::Time dt) +void DefaultSimulation::setTimeStep(unit::Time dt) { - if (dt == Zero) + if (dt == math::Zero) throw InvalidArgumentException("Time step cannot be zero"); m_timeStep = dt; @@ -292,35 +294,35 @@ void DefaultSimulation::setParameter(String name, String value) /* ************************************************************************ */ -ViewPtr DefaultSimulation::addInitializer(UniquePtr initializer) +ViewPtr DefaultSimulation::addInitializer(UniquePtr initializer) { return m_initializers.add(std::move(initializer)); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::createInitializer(StringView type) +ViewPtr DefaultSimulation::createInitializer(StringView type) { return addInitializer(m_pluginContext.createInitializer(type)); } /* ************************************************************************ */ -void DefaultSimulation::deleteInitializer(ViewPtr initializer) +void DefaultSimulation::deleteInitializer(ViewPtr initializer) { m_initializers.remove(initializer); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::addModule(String name, UniquePtr module) +ViewPtr DefaultSimulation::addModule(String name, UniquePtr module) { return m_modules.add(std::move(name), std::move(module)); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::createModule(StringView type) +ViewPtr DefaultSimulation::createModule(StringView type) { return addModule(String(type), m_pluginContext.createModule(type, *this)); } @@ -336,7 +338,7 @@ void DefaultSimulation::deleteModule(StringView name) void DefaultSimulation::addObjectType(String name, String parent, const config::Configuration& config) { - return m_objectTypes.add(object::Type{ + return m_objectTypes.add(simulation::ObjectType{ std::move(name), std::move(parent), config.toMemory() @@ -345,21 +347,21 @@ void DefaultSimulation::addObjectType(String name, String parent, const config:: /* ************************************************************************ */ -ViewPtr DefaultSimulation::addObject(UniquePtr object) +ViewPtr DefaultSimulation::addObject(UniquePtr object) { return m_objects.add(std::move(object)); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::createObject(StringView type) +ViewPtr DefaultSimulation::createObject(StringView type) { - return createObject(type, object::Object::Type::Dynamic); + return createObject(type, simulation::Object::Type::Dynamic); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::createObject(StringView type, object::Object::Type state) +ViewPtr DefaultSimulation::createObject(StringView type, simulation::Object::Type state) { // Look in object types if (m_objectTypes.exists(type)) @@ -381,21 +383,21 @@ ViewPtr DefaultSimulation::createObject(StringView type, object: /* ************************************************************************ */ -void DefaultSimulation::deleteObject(ViewPtr object) +void DefaultSimulation::deleteObject(ViewPtr object) { m_objects.deleteObject(object); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::addProgram(String name, UniquePtr program) +ViewPtr DefaultSimulation::addProgram(String name, UniquePtr program) { return m_programs.add(std::move(name), std::move(program)); } /* ************************************************************************ */ -ViewPtr DefaultSimulation::createProgram(String name, StringView type) +ViewPtr DefaultSimulation::createProgram(String name, StringView type) { return addProgram(std::move(name), m_pluginContext.createProgram(type)); } @@ -409,21 +411,21 @@ void DefaultSimulation::deleteProgram(StringView name) /* ************************************************************************ */ -void DefaultSimulation::setGravity(const units::AccelerationVector& gravity) noexcept +void DefaultSimulation::setGravity(const unit::AccelerationVector& gravity) noexcept { m_world->SetGravity(ConverterBox2D::getInstance().convertLinearAcceleration(gravity)); } /* ************************************************************************ */ -void DefaultSimulation::setPhysicsEngineTimeStep(units::Time dt) noexcept +void DefaultSimulation::setPhysicsEngineTimeStep(unit::Time dt) noexcept { ConverterBox2D::getInstance().setTimeStepBox2D(dt); } /* ************************************************************************ */ -void DefaultSimulation::setContactListener(object::ContactListener* listener) +void DefaultSimulation::setContactListener(simulation::ObjectContactListener* listener) { if (listener) { @@ -448,7 +450,7 @@ void DefaultSimulation::loadConfig(const config::Configuration& config) // TODO make as simulation local ConverterBox2D::getInstance().setLengthCoefficient(config.get("length-coefficient")); #ifdef CECE_RENDER - g_physicsDebugger.setScale(1.0 / simulator::ConverterBox2D::getInstance().getLengthCoefficient()); + g_physicsDebugger.setScale(1.0 / ConverterBox2D::getInstance().getLengthCoefficient()); #endif } @@ -469,7 +471,7 @@ void DefaultSimulation::storeConfig(config::Configuration& config) const /* ************************************************************************ */ -void DefaultSimulation::initialize(AtomicBool& flag) +void DefaultSimulation::initialize(async::AtomicBool& flag) { CECE_ASSERT(!isInitialized()); @@ -523,7 +525,7 @@ bool DefaultSimulation::update() // Clear all stored forces for (auto& obj : m_objects) - obj->setForce(Zero); + obj->setForce(math::Zero); // Update modules updateModules(); @@ -532,9 +534,9 @@ bool DefaultSimulation::update() updateObjects(); { - auto _ = measure_time("sim.physics", TimeMeasurement(this)); + auto _ = perf::measure_time("sim.physics", TimeMeasurement(this)); - m_world->Step(static_cast(getPhysicsEngineTimeStep().value()), 10, 10); + m_world->Step(static_cast(getPhysicsEngineTimeStep().get()), 10, 10); } // Detect object that leaved the scene @@ -589,11 +591,12 @@ void DefaultSimulation::terminate() m_modules.terminate(); // Call finalize simulations for all plugins - const auto& plugins = m_pluginContext.getImported(); + const auto& plugins = m_pluginContext.getImportedPlugins(); for (auto it = plugins.rbegin(); it != plugins.rend(); ++it) { - CECE_ASSERT(it->second); - it->second->finalizeSimulation(*this); + auto api = m_pluginManager.getApi(*it); + CECE_ASSERT(api); + //api->finalizeSimulation(*this); } } @@ -628,7 +631,7 @@ void DefaultSimulation::draw(render::Context& context) void DefaultSimulation::updateModules() { - auto _ = measure_time("sim.modules", TimeMeasurement(this)); + auto _ = perf::measure_time("sim.modules", TimeMeasurement(this)); m_modules.update(); } @@ -636,11 +639,11 @@ void DefaultSimulation::updateModules() void DefaultSimulation::updateObjects() { - auto _ = measure_time("sim.objects", TimeMeasurement(this)); + auto _ = perf::measure_time("sim.objects", TimeMeasurement(this)); // Update simulations objects // Can't use range-for because update can add a new object. - for (object::Container::SizeType i = 0u; i < m_objects.getCount(); ++i) + for (simulation::ObjectContainer::SizeType i = 0u; i < m_objects.getCount(); ++i) { auto obj = m_objects[i]; @@ -659,7 +662,7 @@ void DefaultSimulation::detectDeserters() for (auto& obj : m_objects) { // Ignore static objects - if (obj->getType() == object::Object::Type::Static) + if (obj->getType() == simulation::Object::Type::Static) continue; // Get object position diff --git a/cece/module/ExportModule.cpp b/src/simulation/ExportModule.cpp similarity index 84% rename from cece/module/ExportModule.cpp rename to src/simulation/ExportModule.cpp index 2c98202..631ff8b 100644 --- a/cece/module/ExportModule.cpp +++ b/src/simulation/ExportModule.cpp @@ -24,21 +24,21 @@ /* ************************************************************************ */ // Declaration -#include "cece/module/ExportModule.hpp" +#include "cece/simulation/ExportModule.hpp" // CeCe -#include "cece/core/Log.hpp" -#include "cece/core/StringStream.hpp" +#include "cece/log/Log.hpp" +#include "cece/io/StringStream.hpp" #include "cece/config/Configuration.hpp" /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ -bool ExportModule::isActive(IterationType it) const noexcept +bool ExportModule::isActive(simulation::IterationType it) const noexcept { // No limitation if (m_active.empty()) @@ -57,7 +57,7 @@ bool ExportModule::isActive(IterationType it) const noexcept void ExportModule::loadConfig(const config::Configuration& config) { - setFilePath(config.get("filename")); + setFilePath(config.get("filename")); setActive(parseActive(config.get("active", String{}))); } @@ -74,16 +74,16 @@ void ExportModule::storeConfig(config::Configuration& config) const void ExportModule::init() { // Open CSV file - m_export = DataExport::create(m_filePath.toString()); + m_export = io::DataExport::create(m_filePath.toString()); - Log::info("Exporting data into: ", getFilePath()); + log::Log::info("Exporting data into: ", getFilePath()); } /* ************************************************************************ */ void ExportModule::terminate() { - Log::info("Data exported into: ", getFilePath()); + log::Log::info("Data exported into: ", getFilePath()); // Delete exporter m_export.reset(); @@ -91,22 +91,22 @@ void ExportModule::terminate() /* ************************************************************************ */ -DynamicArray ExportModule::parseActive(String str) +DynamicArray ExportModule::parseActive(String str) { - DynamicArray res; + DynamicArray res; - InStringStream iss(std::move(str)); + io::InStringStream iss(std::move(str)); while (true) { - IterationType it; + simulation::IterationType it; if (!(iss >> it)) break; if (iss.peek() == '-') { - IterationType itEnd; + simulation::IterationType itEnd; iss.ignore(); iss >> itEnd; diff --git a/cece/init/Initializer.cpp b/src/simulation/Initializer.cpp similarity index 90% rename from cece/init/Initializer.cpp rename to src/simulation/Initializer.cpp index ed94a6b..d6df8dc 100644 --- a/cece/init/Initializer.cpp +++ b/src/simulation/Initializer.cpp @@ -24,12 +24,12 @@ /* ************************************************************************ */ // Declaration -#include "cece/init/Initializer.hpp" +#include "cece/simulation/Initializer.hpp" /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ @@ -37,14 +37,14 @@ Initializer::~Initializer() = default; /* ************************************************************************ */ -void Initializer::loadConfig(simulator::Simulation& simulation, const config::Configuration& config) +void Initializer::loadConfig(Simulation& simulation, const config::Configuration& config) { // Nothing to do } /* ************************************************************************ */ -void Initializer::storeConfig(const simulator::Simulation& simulation, config::Configuration& config) const +void Initializer::storeConfig(const Simulation& simulation, config::Configuration& config) const { // Nothing to do } diff --git a/src/simulation/InitializerContainer.cpp b/src/simulation/InitializerContainer.cpp new file mode 100644 index 0000000..3dd7e5f --- /dev/null +++ b/src/simulation/InitializerContainer.cpp @@ -0,0 +1,50 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/simulation/InitializerContainer.hpp" + +// CeCe +#include "cece/simulation/Initializer.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +void InitializerContainer::init(Simulation& simulation) const +{ + for (const auto& val : *this) + val->init(simulation); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/loader/Factory.cpp b/src/simulation/InitializerFactory.cpp similarity index 93% rename from cece/loader/Factory.cpp rename to src/simulation/InitializerFactory.cpp index a7f92d3..7bc00c7 100644 --- a/cece/loader/Factory.cpp +++ b/src/simulation/InitializerFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/loader/Factory.hpp" +#include "cece/simulation/InitializerFactory.hpp" // CeCe -#include "cece/loader/Loader.hpp" +#include "cece/simulation/Initializer.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(loader::Loader) +CECE_FACTORY_INST(simulation::Initializer) /* ************************************************************************ */ diff --git a/cece/init/FactoryManager.cpp b/src/simulation/InitializerFactoryManager.cpp similarity index 91% rename from cece/init/FactoryManager.cpp rename to src/simulation/InitializerFactoryManager.cpp index f0d2fb1..5ca2c51 100644 --- a/cece/init/FactoryManager.cpp +++ b/src/simulation/InitializerFactoryManager.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/init/FactoryManager.hpp" +#include "cece/simulation/InitializerFactoryManager.hpp" // CeCe -#include "cece/init/Initializer.hpp" +#include "cece/simulation/Initializer.hpp" /* ************************************************************************ */ namespace cece { -namespace init { +namespace simulation { /* ************************************************************************ */ -UniquePtr FactoryManager::createInitializer(StringView name) const +UniquePtr InitializerFactoryManager::createInitializer(StringView name) const { return createObject(name); } diff --git a/cece/loader/Loader.cpp b/src/simulation/Loader.cpp similarity index 79% rename from cece/loader/Loader.cpp rename to src/simulation/Loader.cpp index ed15f33..12e11c5 100644 --- a/cece/loader/Loader.cpp +++ b/src/simulation/Loader.cpp @@ -24,44 +24,44 @@ /* ************************************************************************ */ // Declaration -#include "cece/loader/Loader.hpp" +#include "cece/simulation/Loader.hpp" // C++ #include #include // CeCe -#include "cece/core/Parameters.hpp" -#include "cece/simulator/Simulation.hpp" +#include "cece/Parameters.hpp" +#include "cece/simulation/Simulation.hpp" /* ************************************************************************ */ namespace cece { -namespace loader { +namespace simulation { /* ************************************************************************ */ -UniquePtr Loader::fromFile( - const plugin::Repository& repository, const FilePath& filename, +UniquePtr Loader::fromFile( + const plugin::Manager& manager, const io::FilePath& filename, ViewPtr parameters) const { std::ifstream file(filename.toString(), std::ios::in); - return fromStream(repository, file, filename, parameters); + return fromStream(manager, file, filename, parameters); } /* ************************************************************************ */ -UniquePtr Loader::fromSource( - const plugin::Repository& repository, const String& source, - const FilePath& filename, ViewPtr parameters) const +UniquePtr Loader::fromSource( + const plugin::Manager& manager, const String& source, + const io::FilePath& filename, ViewPtr parameters) const { std::istringstream is(source, std::ios::in); - return fromStream(repository, is, filename, parameters); + return fromStream(manager, is, filename, parameters); } /* ************************************************************************ */ -void Loader::toFile(const simulator::Simulation& simulation, const FilePath& filename) const +void Loader::toFile(const Simulation& simulation, const io::FilePath& filename) const { // Write code into file std::ofstream file(filename.toString(), std::ios::out); @@ -70,7 +70,7 @@ void Loader::toFile(const simulator::Simulation& simulation, const FilePath& fil /* ************************************************************************ */ -String Loader::toSource(const simulator::Simulation& simulation, const FilePath& filename) const +String Loader::toSource(const Simulation& simulation, const io::FilePath& filename) const { std::ostringstream os(std::ios::out); toStream(os, simulation, filename); diff --git a/cece/init/Factory.cpp b/src/simulation/LoaderFactory.cpp similarity index 94% rename from cece/init/Factory.cpp rename to src/simulation/LoaderFactory.cpp index a265544..4c6e98d 100644 --- a/cece/init/Factory.cpp +++ b/src/simulation/LoaderFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/init/Factory.hpp" +#include "cece/simulation/LoaderFactory.hpp" // CeCe -#include "cece/init/Initializer.hpp" +#include "cece/simulation/Loader.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(init::Initializer) +CECE_FACTORY_INST(simulation::Loader) /* ************************************************************************ */ diff --git a/cece/loader/FactoryManager.cpp b/src/simulation/LoaderFactoryManager.cpp similarity index 92% rename from cece/loader/FactoryManager.cpp rename to src/simulation/LoaderFactoryManager.cpp index 0718865..d1172f8 100644 --- a/cece/loader/FactoryManager.cpp +++ b/src/simulation/LoaderFactoryManager.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/loader/FactoryManager.hpp" +#include "cece/simulation/LoaderFactoryManager.hpp" // CeCe -#include "cece/loader/Loader.hpp" +#include "cece/simulation/Loader.hpp" /* ************************************************************************ */ namespace cece { -namespace loader { +namespace simulation { /* ************************************************************************ */ -UniquePtr FactoryManager::createLoader(StringView name) const +UniquePtr LoaderFactoryManager::createLoader(StringView name) const { return createObject(name); } diff --git a/cece/module/Module.cpp b/src/simulation/Module.cpp similarity index 93% rename from cece/module/Module.cpp rename to src/simulation/Module.cpp index 5e503cd..263fa96 100644 --- a/cece/module/Module.cpp +++ b/src/simulation/Module.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/module/Module.hpp" +#include "cece/simulation/Module.hpp" // CeCe #include "cece/config/Configuration.hpp" @@ -32,11 +32,11 @@ /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ -Module::Module(simulator::Simulation& simulation) +Module::Module(simulation::Simulation& simulation) : m_simulation(simulation) { // Nothing to do @@ -72,7 +72,7 @@ void Module::storeConfig(config::Configuration& config) const /* ************************************************************************ */ -void Module::init(AtomicBool& flag) +void Module::init(async::AtomicBool& flag) { // Forward without flag init(); @@ -102,7 +102,7 @@ void Module::terminate() /* ************************************************************************ */ #ifdef CECE_RENDER -void Module::draw(const simulator::Visualization&, render::Context& context) +void Module::draw(const simulation::Visualization&, render::Context& context) { // Forward draw(context); @@ -121,7 +121,7 @@ void Module::draw(render::Context& context) /* ************************************************************************ */ #ifdef CECE_RENDER -void Module::drawStoreState(const simulator::Visualization&) +void Module::drawStoreState(const simulation::Visualization&) { drawStoreState(); } diff --git a/cece/module/Container.cpp b/src/simulation/ModuleContainer.cpp similarity index 83% rename from cece/module/Container.cpp rename to src/simulation/ModuleContainer.cpp index 61dd74f..44a4a29 100644 --- a/cece/module/Container.cpp +++ b/src/simulation/ModuleContainer.cpp @@ -24,22 +24,22 @@ /* ************************************************************************ */ // Declaration -#include "cece/module/Container.hpp" +#include "cece/simulation/ModuleContainer.hpp" // C++ #include // CeCe -#include "cece/module/Module.hpp" +#include "cece/simulation/Module.hpp" /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ -void Container::init(AtomicBool& flag) +void ModuleContainer::init(async::AtomicBool& flag) { // Update modules for (auto& module : getSortedListAsc()) @@ -53,7 +53,7 @@ void Container::init(AtomicBool& flag) /* ************************************************************************ */ -void Container::update() +void ModuleContainer::update() { // Update modules for (auto& module : getSortedListAsc()) @@ -62,7 +62,7 @@ void Container::update() /* ************************************************************************ */ -void Container::terminate() +void ModuleContainer::terminate() { // Update modules for (auto& module : getSortedListDesc()) @@ -72,7 +72,7 @@ void Container::terminate() /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::draw(const simulator::Visualization& visualization, render::Context& context) +void ModuleContainer::draw(const simulation::Visualization& visualization, render::Context& context) { const RenderState& state = m_drawableState.getFront(); @@ -93,16 +93,16 @@ void Container::draw(const simulator::Visualization& visualization, render::Cont /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::drawStoreState(const simulator::Visualization& visualization) +void ModuleContainer::drawStoreState(const simulation::Visualization& visualization) { RenderState& state = m_drawableState.getBack(); state.modules.clear(); - for (auto& module : *this) + for (auto& p : *this) { - module->drawStoreState(visualization); + p.second->drawStoreState(visualization); // Store module to draw - state.modules.push_back(module); + state.modules.push_back(p.second); } } #endif @@ -110,10 +110,10 @@ void Container::drawStoreState(const simulator::Visualization& visualization) /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::drawSwapState() +void ModuleContainer::drawSwapState() { - for (auto& module : *this) - module->drawSwapState(); + for (auto& p : *this) + p.second->drawSwapState(); m_drawableState.swap(); } @@ -121,13 +121,13 @@ void Container::drawSwapState() /* ************************************************************************ */ -DynamicArray> Container::getSortedListAsc() const noexcept +DynamicArray> ModuleContainer::getSortedListAsc() const noexcept { DynamicArray> modules; // Copy modules (view pointer) - for (const auto& module : *this) - modules.push_back(module); + for (const auto& p : *this) + modules.push_back(p.second); // Sort modules by priority. Cannot be precomputed, because priority can change in previous iteration std::sort(modules.begin(), modules.end(), @@ -140,13 +140,13 @@ DynamicArray> Container::getSortedListAsc() const noexcept /* ************************************************************************ */ -DynamicArray> Container::getSortedListDesc() const noexcept +DynamicArray> ModuleContainer::getSortedListDesc() const noexcept { DynamicArray> modules; // Copy modules (view pointer) - for (const auto& module : *this) - modules.push_back(module); + for (const auto& p : *this) + modules.push_back(p.second); // Sort modules by priority. Cannot be precomputed, because priority can change in previous iteration std::sort(modules.begin(), modules.end(), diff --git a/cece/module/Factory.cpp b/src/simulation/ModuleFactory.cpp similarity index 93% rename from cece/module/Factory.cpp rename to src/simulation/ModuleFactory.cpp index be732cb..8691263 100644 --- a/cece/module/Factory.cpp +++ b/src/simulation/ModuleFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/module/Factory.hpp" +#include "cece/simulation/ModuleFactory.hpp" // CeCe -#include "cece/module/Module.hpp" +#include "cece/simulation/Module.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(module::Module, simulator::Simulation&) +CECE_FACTORY_INST(simulation::Module, simulation::Simulation&) /* ************************************************************************ */ diff --git a/cece/module/FactoryManager.cpp b/src/simulation/ModuleFactoryManager.cpp similarity index 91% rename from cece/module/FactoryManager.cpp rename to src/simulation/ModuleFactoryManager.cpp index fa2160c..ee63e03 100644 --- a/cece/module/FactoryManager.cpp +++ b/src/simulation/ModuleFactoryManager.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/module/FactoryManager.hpp" +#include "cece/simulation/ModuleFactoryManager.hpp" // CeCe -#include "cece/module/Module.hpp" +#include "cece/simulation/Module.hpp" /* ************************************************************************ */ namespace cece { -namespace module { +namespace simulation { /* ************************************************************************ */ -UniquePtr FactoryManager::createModule(StringView name, simulator::Simulation& simulation) const +UniquePtr ModuleFactoryManager::createModule(StringView name, simulation::Simulation& simulation) const { return createObject(name, simulation); } diff --git a/cece/object/Object.cpp b/src/simulation/Object.cpp similarity index 73% rename from cece/object/Object.cpp rename to src/simulation/Object.cpp index b1105c1..cee26c1 100644 --- a/cece/object/Object.cpp +++ b/src/simulation/Object.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/Object.hpp" +#include "cece/simulation/Object.hpp" // C++ #include @@ -34,20 +34,21 @@ #include // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/UnitIo.hpp" -#include "cece/core/Log.hpp" -#include "cece/core/Real.hpp" -#include "cece/core/FileStream.hpp" +#include "cece/Assert.hpp" +#include "cece/log/Log.hpp" +#include "cece/unit/UnitIo.hpp" +#include "cece/io/FileStream.hpp" #include "cece/config/Configuration.hpp" #include "cece/plugin/Context.hpp" -#include "cece/simulator/Simulation.hpp" -#include "cece/simulator/ConverterBox2D.hpp" +#include "cece/simulation/Simulation.hpp" + +// CeCe private +#include "../simulation/ConverterBox2D.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ @@ -107,7 +108,7 @@ Object::IdType s_id = 0; /* ************************************************************************ */ -Object::Object(simulator::Simulation& simulation, String typeName, Type type) noexcept +Object::Object(simulation::Simulation& simulation, String typeName, Type type) noexcept : m_simulation(simulation) , m_realTypeName(typeName) , m_typeName(typeName) @@ -157,75 +158,75 @@ Object::~Object() /* ************************************************************************ */ -units::PositionVector Object::getPosition() const noexcept +unit::PositionVector Object::getPosition() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertPosition(m_body->GetPosition()); + return simulation::ConverterBox2D::getInstance().convertPosition(m_body->GetPosition()); } /* ************************************************************************ */ -units::PositionVector Object::getMassCenterPosition() const noexcept +unit::PositionVector Object::getMassCenterPosition() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertPosition(m_body->GetWorldCenter()); + return simulation::ConverterBox2D::getInstance().convertPosition(m_body->GetWorldCenter()); } /* ************************************************************************ */ -units::PositionVector Object::getMassCenterOffset() const noexcept +unit::PositionVector Object::getMassCenterOffset() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertPosition(m_body->GetLocalCenter()); + return simulation::ConverterBox2D::getInstance().convertPosition(m_body->GetLocalCenter()); } /* ************************************************************************ */ -units::PositionVector Object::getWorldPosition(units::PositionVector local) const noexcept +unit::PositionVector Object::getWorldPosition(unit::PositionVector local) const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertPosition( - m_body->GetWorldPoint(simulator::ConverterBox2D::getInstance().convertPosition(local)) + return simulation::ConverterBox2D::getInstance().convertPosition( + m_body->GetWorldPoint(simulation::ConverterBox2D::getInstance().convertPosition(local)) ); } /* ************************************************************************ */ -units::Angle Object::getRotation() const noexcept +unit::Angle Object::getRotation() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertAngle(m_body->GetAngle()); + return simulation::ConverterBox2D::getInstance().convertAngle(m_body->GetAngle()); } /* ************************************************************************ */ -units::VelocityVector Object::getVelocity() const noexcept +unit::VelocityVector Object::getVelocity() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertLinearVelocity(m_body->GetLinearVelocity()); + return simulation::ConverterBox2D::getInstance().convertLinearVelocity(m_body->GetLinearVelocity()); } /* ************************************************************************ */ -units::AngularVelocity Object::getAngularVelocity() const noexcept +unit::AngularVelocity Object::getAngularVelocity() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertAngularVelocity(m_body->GetAngularVelocity()); + return simulation::ConverterBox2D::getInstance().convertAngularVelocity(m_body->GetAngularVelocity()); } /* ************************************************************************ */ -units::Mass Object::getMass() const noexcept +unit::Mass Object::getMass() const noexcept { CECE_ASSERT(m_body); - return simulator::ConverterBox2D::getInstance().convertMass(m_body->GetMass()); + return simulation::ConverterBox2D::getInstance().convertMass(m_body->GetMass()); } /* ************************************************************************ */ -units::Length Object::getMaxTranslation() const noexcept +unit::Length Object::getMaxTranslation() const noexcept { - return simulator::ConverterBox2D::getInstance().getMaxObjectTranslation(); + return simulation::ConverterBox2D::getInstance().getMaxObjectTranslation(); } /* ************************************************************************ */ @@ -251,55 +252,55 @@ void Object::setType(Type type) noexcept /* ************************************************************************ */ -void Object::setPosition(units::PositionVector pos) noexcept +void Object::setPosition(unit::PositionVector pos) noexcept { CECE_ASSERT(m_body); - m_body->SetTransform(simulator::ConverterBox2D::getInstance().convertPosition(pos), m_body->GetAngle()); + m_body->SetTransform(simulation::ConverterBox2D::getInstance().convertPosition(pos), m_body->GetAngle()); if (m_pinBody) - m_pinBody->SetTransform(simulator::ConverterBox2D::getInstance().convertPosition(pos), 0); + m_pinBody->SetTransform(simulation::ConverterBox2D::getInstance().convertPosition(pos), 0); } /* ************************************************************************ */ -void Object::setRotation(units::Angle angle) noexcept +void Object::setRotation(unit::Angle angle) noexcept { CECE_ASSERT(m_body); - m_body->SetTransform(m_body->GetPosition(), simulator::ConverterBox2D::getInstance().convertAngle(angle)); + m_body->SetTransform(m_body->GetPosition(), simulation::ConverterBox2D::getInstance().convertAngle(angle)); } /* ************************************************************************ */ -void Object::setVelocity(units::VelocityVector vel) noexcept +void Object::setVelocity(unit::VelocityVector vel) noexcept { CECE_ASSERT(m_body); - m_body->SetLinearVelocity(simulator::ConverterBox2D::getInstance().convertLinearVelocity(vel)); + m_body->SetLinearVelocity(simulation::ConverterBox2D::getInstance().convertLinearVelocity(vel)); } /* ************************************************************************ */ -void Object::setAngularVelocity(units::AngularVelocity vel) noexcept +void Object::setAngularVelocity(unit::AngularVelocity vel) noexcept { CECE_ASSERT(m_body); - m_body->SetAngularVelocity(simulator::ConverterBox2D::getInstance().convertAngularVelocity(vel)); + m_body->SetAngularVelocity(simulation::ConverterBox2D::getInstance().convertAngularVelocity(vel)); } /* ************************************************************************ */ -void Object::applyForce(const units::ForceVector& force) noexcept +void Object::applyForce(const unit::ForceVector& force) noexcept { CECE_ASSERT(m_body); - m_body->ApplyForceToCenter(simulator::ConverterBox2D::getInstance().convertForce(force), true); + m_body->ApplyForceToCenter(simulation::ConverterBox2D::getInstance().convertForce(force), true); } /* ************************************************************************ */ -void Object::applyForce(const units::ForceVector& force, const units::PositionVector& offset) noexcept +void Object::applyForce(const unit::ForceVector& force, const unit::PositionVector& offset) noexcept { CECE_ASSERT(m_body); m_body->ApplyForce( - simulator::ConverterBox2D::getInstance().convertForce(force), - m_body->GetWorldPoint(simulator::ConverterBox2D::getInstance().convertPosition(offset)), + simulation::ConverterBox2D::getInstance().convertForce(force), + m_body->GetWorldPoint(simulation::ConverterBox2D::getInstance().convertPosition(offset)), true ); @@ -308,22 +309,22 @@ void Object::applyForce(const units::ForceVector& force, const units::PositionVe /* ************************************************************************ */ -void Object::applyLinearImpulse(const units::ImpulseVector& impulse, const units::PositionVector& offset) noexcept +void Object::applyLinearImpulse(const unit::ImpulseVector& impulse, const unit::PositionVector& offset) noexcept { CECE_ASSERT(m_body); m_body->ApplyLinearImpulse( - simulator::ConverterBox2D::getInstance().convertLinearImpulse(impulse), - m_body->GetWorldPoint(simulator::ConverterBox2D::getInstance().convertPosition(offset)), + simulation::ConverterBox2D::getInstance().convertLinearImpulse(impulse), + m_body->GetWorldPoint(simulation::ConverterBox2D::getInstance().convertPosition(offset)), true ); } /* ************************************************************************ */ -void Object::applyAngularImpulse(const units::Impulse& impulse) noexcept +void Object::applyAngularImpulse(const unit::Impulse& impulse) noexcept { CECE_ASSERT(m_body); - m_body->ApplyAngularImpulse(simulator::ConverterBox2D::getInstance().convertAngularImpulse(impulse), true); + m_body->ApplyAngularImpulse(simulation::ConverterBox2D::getInstance().convertAngularImpulse(impulse), true); } /* ************************************************************************ */ @@ -335,7 +336,7 @@ void Object::useProgram(StringView name) noexcept if (program) addProgram(std::move(program)); else - Log::warning("Unable to create program '", name, "'"); + log::Log::warning("Unable to create program '", name, "'"); } /* ************************************************************************ */ @@ -347,10 +348,10 @@ void Object::destroy() /* ************************************************************************ */ -void Object::createBound(Object& other, UniquePtr data) +void Object::createBound(Object& other, UniquePtr data) { auto& world = getSimulation().getWorld(); - SharedPtr d = std::move(data); + SharedPtr d = std::move(data); b2WeldJointDef jointDef; jointDef.Initialize(m_body, other.m_body, m_body->GetWorldCenter()); @@ -394,7 +395,7 @@ void Object::removeBound(const Object& other) /* ************************************************************************ */ -void Object::update(units::Duration dt) +void Object::update(unit::Duration dt) { // Calculate new object position setPosition(getPosition() + getVelocity() * dt); @@ -434,7 +435,7 @@ void Object::update(units::Duration dt) // forceY force.getY().value() << ";" << // angle - getRotation() << ";" << + getRotation().get() << ";" << // omega getAngularVelocity().value() << "\n" @@ -446,7 +447,7 @@ void Object::update(units::Duration dt) /* ************************************************************************ */ -void Object::configure(const config::Configuration& config, simulator::Simulation& simulation) +void Object::configure(const config::Configuration& config, simulation::Simulation& simulation) { #ifdef CECE_RENDER setVisible(config.get("visible", isVisible())); @@ -471,7 +472,7 @@ void Object::configure(const config::Configuration& config, simulator::Simulatio if (config.has("data-out")) { - m_dataOut = makeUnique(config.get("data-out")); + m_dataOut = makeUnique(config.get("data-out")); *m_dataOut << "iteration;totalTime;id;x;y;massX;massY;velX;velY;forceX;forceY;angle;omega\n"; } } @@ -502,37 +503,37 @@ void Object::initShapes() switch (type) { - case ShapeType::Undefined: - Log::warning("[object] Undefined shape"); + case math::ShapeType::Undefined: + log::Log::warning("[object] Undefined shape"); break; - case ShapeType::Circle: + case math::ShapeType::Circle: { // Create body shape auto ptr = makeUnique(); - ptr->m_radius = simulator::ConverterBox2D::getInstance().convertLength(shape.getCircle().radius); - ptr->m_p = simulator::ConverterBox2D::getInstance().convertPosition(shape.getCircle().center); + ptr->m_radius = simulation::ConverterBox2D::getInstance().convertLength(shape.getCircle().radius); + ptr->m_p = simulation::ConverterBox2D::getInstance().convertPosition(shape.getCircle().center); bodyShape = std::move(ptr); break; } - case ShapeType::Rectangle: + case math::ShapeType::Rectangle: { // Create body shape auto ptr = makeUnique(); const auto sh = 0.5 * shape.getRectangle().size; - b2Vec2 box = simulator::ConverterBox2D::getInstance().convertPosition(sh); + b2Vec2 box = simulation::ConverterBox2D::getInstance().convertPosition(sh); ptr->SetAsBox(box.x, box.y); bodyShape = std::move(ptr); break; } - case ShapeType::Edges: + case math::ShapeType::Edges: { DynamicArray vertices; for (const auto& v : shape.getEdges().edges) - vertices.push_back(simulator::ConverterBox2D::getInstance().convertPosition(v)); + vertices.push_back(simulation::ConverterBox2D::getInstance().convertPosition(v)); auto ptr = makeUnique(); @@ -550,7 +551,7 @@ void Object::initShapes() // Store body shape if (bodyShape) { - getBody()->CreateFixture(bodyShape.get(), simulator::ConverterBox2D::getInstance().convertDensity(getDensity())); + getBody()->CreateFixture(bodyShape.get(), simulation::ConverterBox2D::getInstance().convertDensity(getDensity())); m_bodyShapes.push_back(std::move(bodyShape)); } } @@ -559,7 +560,7 @@ void Object::initShapes() /* ************************************************************************ */ #ifdef CECE_RENDER -void Object::draw(const simulator::Visualization&, render::Context& context) +void Object::draw(const simulation::Visualization&, render::Context& context) { draw(context); } @@ -577,7 +578,7 @@ void Object::draw(render::Context& context) /* ************************************************************************ */ #ifdef CECE_RENDER -void Object::drawStoreState(const simulator::Visualization&) +void Object::drawStoreState(const simulation::Visualization&) { drawStoreState(); } diff --git a/src/simulation/ObjectBoundData.cpp b/src/simulation/ObjectBoundData.cpp new file mode 100644 index 0000000..ef8e959 --- /dev/null +++ b/src/simulation/ObjectBoundData.cpp @@ -0,0 +1,43 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/simulation/ObjectBoundData.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +ObjectBoundData::~ObjectBoundData() = default; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/simulation/ObjectContactListener.cpp b/src/simulation/ObjectContactListener.cpp new file mode 100644 index 0000000..0f6a08e --- /dev/null +++ b/src/simulation/ObjectContactListener.cpp @@ -0,0 +1,43 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/simulation/ObjectContactListener.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +ObjectContactListener::~ObjectContactListener() = default; + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/Container.cpp b/src/simulation/ObjectContainer.cpp similarity index 87% rename from cece/object/Container.cpp rename to src/simulation/ObjectContainer.cpp index 46e12bc..6a54e07 100644 --- a/cece/object/Container.cpp +++ b/src/simulation/ObjectContainer.cpp @@ -24,22 +24,22 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/Container.hpp" +#include "cece/simulation/ObjectContainer.hpp" // C++ #include // CeCe -#include "cece/object/Object.hpp" +#include "cece/simulation/Object.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ -Container::SizeType Container::getCountByType(StringView typeName) const noexcept +ObjectContainer::SizeType ObjectContainer::getCountByType(StringView typeName) const noexcept { SizeType res = 0ul; @@ -54,7 +54,7 @@ Container::SizeType Container::getCountByType(StringView typeName) const noexcep /* ************************************************************************ */ -DynamicArray> Container::getByType(StringView typeName) const noexcept +DynamicArray> ObjectContainer::getByType(StringView typeName) const noexcept { DynamicArray> objects; objects.reserve(m_data.size()); @@ -70,7 +70,7 @@ DynamicArray> Container::getByType(StringView typeName) const no /* ************************************************************************ */ -void Container::deleteObject(ViewPtr object) +void ObjectContainer::deleteObject(ViewPtr object) { for (auto& obj : m_data) { @@ -84,7 +84,7 @@ void Container::deleteObject(ViewPtr object) /* ************************************************************************ */ -void Container::addPending() noexcept +void ObjectContainer::addPending() noexcept { // Move objects m_data.insert( @@ -98,7 +98,7 @@ void Container::addPending() noexcept /* ************************************************************************ */ -void Container::removeDeleted() noexcept +void ObjectContainer::removeDeleted() noexcept { // Delete objects m_data.erase(std::remove_if(m_data.begin(), m_data.end(), [](const Record& rec) { @@ -109,7 +109,7 @@ void Container::removeDeleted() noexcept /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::draw(render::Context& context) +void ObjectContainer::draw(render::Context& context) { const RenderState& state = m_drawableState.getFront(); @@ -126,7 +126,7 @@ void Container::draw(render::Context& context) /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::drawStoreState(const simulator::Visualization& visualization) +void ObjectContainer::drawStoreState(const simulation::Visualization& visualization) { RenderState& state = m_drawableState.getBack(); state.objects.clear(); @@ -147,7 +147,7 @@ void Container::drawStoreState(const simulator::Visualization& visualization) /* ************************************************************************ */ #ifdef CECE_RENDER -void Container::drawSwapState() +void ObjectContainer::drawSwapState() { for (const auto& obj : m_data) obj->drawSwapState(); diff --git a/cece/object/Factory.cpp b/src/simulation/ObjectFactory.cpp similarity index 92% rename from cece/object/Factory.cpp rename to src/simulation/ObjectFactory.cpp index 7124c8d..db23c9f 100644 --- a/cece/object/Factory.cpp +++ b/src/simulation/ObjectFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/Factory.hpp" +#include "cece/simulation/ObjectFactory.hpp" // CeCe -#include "cece/object/Object.hpp" +#include "cece/simulation/Object.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(object::Object, simulator::Simulation&, String, object::Object::Type) +CECE_FACTORY_INST(simulation::Object, simulation::Simulation&, String, simulation::Object::Type) /* ************************************************************************ */ diff --git a/src/simulation/ObjectFactoryManager.cpp b/src/simulation/ObjectFactoryManager.cpp new file mode 100644 index 0000000..805c471 --- /dev/null +++ b/src/simulation/ObjectFactoryManager.cpp @@ -0,0 +1,49 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/simulation/ObjectFactoryManager.hpp" + +// CeCe +#include "cece/simulation/Object.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace simulation { + +/* ************************************************************************ */ + +UniquePtr ObjectFactoryManager::createObject(StringView name, Simulation& simulation, Object::Type type) const +{ + return factory::FactoryManager::createObject(name, simulation, String(name), type); +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/object/TypeContainer.cpp b/src/simulation/ObjectTypeContainer.cpp similarity index 90% rename from cece/object/TypeContainer.cpp rename to src/simulation/ObjectTypeContainer.cpp index bb367cc..f87ef9e 100644 --- a/cece/object/TypeContainer.cpp +++ b/src/simulation/ObjectTypeContainer.cpp @@ -24,18 +24,18 @@ /* ************************************************************************ */ // Declaration -#include "cece/object/TypeContainer.hpp" +#include "cece/simulation/ObjectTypeContainer.hpp" // C++ #include -// Declaration -#include "cece/object/Type.hpp" +// CeCe +#include "cece/simulation/ObjectType.hpp" /* ************************************************************************ */ namespace cece { -namespace object { +namespace simulation { /* ************************************************************************ */ @@ -54,7 +54,7 @@ template auto find(Container& data, StringView name) noexcept -> decltype(&*data.begin()) { auto it = std::find_if(data.begin(), data.end(), - [name](const Type& p) { + [name](const ObjectType& p) { return p.name == name; } ); @@ -68,21 +68,21 @@ auto find(Container& data, StringView name) noexcept -> decltype(&*data.begin()) /* ************************************************************************ */ -bool TypeContainer::exists(StringView name) const noexcept +bool ObjectTypeContainer::exists(StringView name) const noexcept { return find(m_types, name) != nullptr; } /* ************************************************************************ */ -ViewPtr TypeContainer::get(StringView name) const noexcept +ViewPtr ObjectTypeContainer::get(StringView name) const noexcept { return find(m_types, name); } /* ************************************************************************ */ -void TypeContainer::add(Type type) +void ObjectTypeContainer::add(ObjectType type) { auto ptr = find(m_types, type.name); diff --git a/cece/program/Container.cpp b/src/simulation/ProgramContainer.cpp similarity index 87% rename from cece/program/Container.cpp rename to src/simulation/ProgramContainer.cpp index 9c18528..1dab763 100644 --- a/cece/program/Container.cpp +++ b/src/simulation/ProgramContainer.cpp @@ -24,29 +24,30 @@ /* ************************************************************************ */ // Declaration -#include "cece/program/Container.hpp" +#include "cece/simulation/ProgramContainer.hpp" // CeCe -#include "cece/program/Program.hpp" +#include "cece/simulation/Program.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ -void Container::call(simulator::Simulation& simulation, object::Object& object, units::Time dt) +void ProgramContainer::call(Simulation& simulation, Object& object, unit::Time dt) { // Invoke all stored programs - invoke(&Program::call, simulation, object, dt); + for (auto& val : *this) + val->call(simulation, object, dt); } /* ************************************************************************ */ -Container Container::clone() const +ProgramContainer ProgramContainer::clone() const { - Container container; + ProgramContainer container; // Clone programs for (const auto& program : *this) diff --git a/cece/program/Factory.cpp b/src/simulation/ProgramFactory.cpp similarity index 94% rename from cece/program/Factory.cpp rename to src/simulation/ProgramFactory.cpp index a774882..6247a0e 100644 --- a/cece/program/Factory.cpp +++ b/src/simulation/ProgramFactory.cpp @@ -24,13 +24,13 @@ /* ************************************************************************ */ // Declaration -#include "cece/program/Factory.hpp" +#include "cece/simulation/ProgramFactory.hpp" // CeCe -#include "cece/program/Program.hpp" +#include "cece/simulation/Program.hpp" /* ************************************************************************ */ -CECE_FACTORY_INST(program::Program) +CECE_FACTORY_INST(simulation::Program) /* ************************************************************************ */ diff --git a/cece/program/FactoryManager.cpp b/src/simulation/ProgramFactoryManager.cpp similarity index 92% rename from cece/program/FactoryManager.cpp rename to src/simulation/ProgramFactoryManager.cpp index 8426bd2..adae404 100644 --- a/cece/program/FactoryManager.cpp +++ b/src/simulation/ProgramFactoryManager.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/program/FactoryManager.hpp" +#include "cece/simulation/ProgramFactoryManager.hpp" // CeCe -#include "cece/program/Program.hpp" +#include "cece/simulation/Program.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ -UniquePtr FactoryManager::createProgram(StringView name) const +UniquePtr ProgramFactoryManager::createProgram(StringView name) const { return createObject(name); } diff --git a/cece/program/NamedContainer.cpp b/src/simulation/ProgramNamedContainer.cpp similarity index 96% rename from cece/program/NamedContainer.cpp rename to src/simulation/ProgramNamedContainer.cpp index fc7c8c8..9c2382c 100644 --- a/cece/program/NamedContainer.cpp +++ b/src/simulation/ProgramNamedContainer.cpp @@ -24,12 +24,12 @@ /* ************************************************************************ */ // Declaration -#include "cece/program/NamedContainer.hpp" +#include "cece/simulation/ProgramNamedContainer.hpp" /* ************************************************************************ */ namespace cece { -namespace program { +namespace simulation { /* ************************************************************************ */ diff --git a/cece/simulator/Simulation.cpp b/src/simulation/Simulation.cpp similarity index 85% rename from cece/simulator/Simulation.cpp rename to src/simulation/Simulation.cpp index 64f836a..9f2e197 100644 --- a/cece/simulator/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -24,25 +24,25 @@ /* ************************************************************************ */ // Declaration -#include "cece/simulator/Simulation.hpp" +#include "cece/simulation/Simulation.hpp" // C++ #include // CeCe -#include "cece/core/UnitIo.hpp" +#include "cece/unit/UnitIo.hpp" #include "cece/plugin/Api.hpp" -#include "cece/init/Initializer.hpp" -#include "cece/module/Module.hpp" -#include "cece/object/Type.hpp" -#include "cece/object/Object.hpp" -#include "cece/program/Program.hpp" -#include "cece/simulator/Visualization.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/ObjectType.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/simulation/Visualization.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ @@ -50,7 +50,7 @@ Simulation::~Simulation() = default; /* ************************************************************************ */ -ViewPtr Simulation::requireModule(StringView name) const +ViewPtr Simulation::requireModule(StringView name) const { auto module = getModule(name); @@ -62,7 +62,7 @@ ViewPtr Simulation::requireModule(StringView name) const /* ************************************************************************ */ -UniquePtr Simulation::requireProgram(StringView name) const +UniquePtr Simulation::requireProgram(StringView name) const { auto program = getProgram(name); @@ -89,11 +89,11 @@ std::size_t Simulation::getObjectCount(StringView type) const noexcept /* ************************************************************************ */ -DynamicArray> Simulation::getObjects(StringView type) const noexcept +DynamicArray> Simulation::getObjects(StringView type) const noexcept { const auto& objects = getObjects(); - DynamicArray> res; + DynamicArray> res; res.reserve(objects.size()); for (const auto& object : objects) @@ -115,15 +115,15 @@ ViewPtr Simulation::loadPlugin(const config::Configuration& c // Load plugin with given name name auto plugin = loadPlugin(name); - if (plugin) - plugin->loadConfig(*this, config); + //if (plugin) + // plugin->loadConfig(*this, config); return plugin; } /* ************************************************************************ */ -ViewPtr Simulation::createInitializer(const config::Configuration& config) +ViewPtr Simulation::createInitializer(const config::Configuration& config) { // Get initializer language/type const String name = config.has("language") @@ -143,7 +143,7 @@ ViewPtr Simulation::createInitializer(const config::Configura /* ************************************************************************ */ -ViewPtr Simulation::createModule(const config::Configuration& config) +ViewPtr Simulation::createModule(const config::Configuration& config) { // Get module language/type/name const String name = config.has("language") @@ -172,7 +172,7 @@ void Simulation::createObjectType(const config::Configuration& config) /* ************************************************************************ */ -ViewPtr Simulation::createObject(const config::Configuration& config) +ViewPtr Simulation::createObject(const config::Configuration& config) { // Get object type //const String type = config.has("type") @@ -180,7 +180,7 @@ ViewPtr Simulation::createObject(const config::Configuration& co // : config.get("class") //; const auto type = config.get("class"); - const auto mode = config.get("type", object::Object::Type::Dynamic); + const auto mode = config.get("type", simulation::Object::Type::Dynamic); // Create object auto object = createObject(type, mode); @@ -195,7 +195,7 @@ ViewPtr Simulation::createObject(const config::Configuration& co /* ************************************************************************ */ -ViewPtr Simulation::createProgram(const config::Configuration& config) +ViewPtr Simulation::createProgram(const config::Configuration& config) { // Get program language/type const String type = config.has("language") @@ -215,7 +215,7 @@ ViewPtr Simulation::createProgram(const config::Configuration& /* ************************************************************************ */ -void Simulation::setContactListener(object::ContactListener* listener) +void Simulation::setContactListener(simulation::ObjectContactListener* listener) { // Nothing to do } @@ -224,8 +224,8 @@ void Simulation::setContactListener(object::ContactListener* listener) void Simulation::loadConfig(const config::Configuration& config) { - setWorldSize(config.get("world-size")); - setTimeStep(config.get("dt")); + setWorldSize(config.get("world-size")); + setTimeStep(config.get("dt")); setIterations(config.get("iterations", getIterations())); #ifdef CECE_RENDER diff --git a/cece/simulator/Simulator.cpp b/src/simulation/Simulator.cpp similarity index 97% rename from cece/simulator/Simulator.cpp rename to src/simulation/Simulator.cpp index 7b39b4c..c28c1dd 100644 --- a/cece/simulator/Simulator.cpp +++ b/src/simulation/Simulator.cpp @@ -35,8 +35,8 @@ #include // CeCe -#include "cece/core/Assert.hpp" -#include "cece/simulator/Simulation.hpp" +#include "cece/Assert.hpp" +#include "cece/simulation/Simulation.hpp" /* ************************************************************************ */ diff --git a/cece/simulator/TimeMeasurement.cpp b/src/simulation/TimeMeasurement.cpp similarity index 91% rename from cece/simulator/TimeMeasurement.cpp rename to src/simulation/TimeMeasurement.cpp index e78c835..6e4f1f6 100644 --- a/cece/simulator/TimeMeasurement.cpp +++ b/src/simulation/TimeMeasurement.cpp @@ -24,19 +24,19 @@ /* ************************************************************************ */ // Declaration -#include "cece/simulator/TimeMeasurement.hpp" +#include "cece/simulation/TimeMeasurement.hpp" // CeCe -#include "cece/simulator/Simulation.hpp" +#include "cece/simulation/Simulation.hpp" /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ -void TimeMeasurement::operator()(OutStream& out, StringView name, Clock::duration dt) const noexcept +void TimeMeasurement::operator()(io::OutStream& out, StringView name, perf::Clock::duration dt) const noexcept { using namespace std::chrono; #pragma omp critical diff --git a/cece/simulator/Visualization.cpp b/src/simulation/Visualization.cpp similarity index 98% rename from cece/simulator/Visualization.cpp rename to src/simulation/Visualization.cpp index d88ce1c..dcb1425 100644 --- a/cece/simulator/Visualization.cpp +++ b/src/simulation/Visualization.cpp @@ -24,7 +24,7 @@ /* ************************************************************************ */ // Declaration -#include "cece/simulator/Visualization.hpp" +#include "cece/simulation/Visualization.hpp" // C++ #include @@ -39,7 +39,7 @@ /* ************************************************************************ */ namespace cece { -namespace simulator { +namespace simulation { /* ************************************************************************ */ diff --git a/src/unit/CMakeLists.txt b/src/unit/CMakeLists.txt new file mode 100644 index 0000000..682f944 --- /dev/null +++ b/src/unit/CMakeLists.txt @@ -0,0 +1,39 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +set(SRCS + Unit.cpp + UnitIo.cpp + Units.cpp + VectorUnits.cpp +) + +# ######################################################################### # + +dir_pretend(SOURCES unit/ ${SRCS}) + +set(CECE_SOURCES ${CECE_SOURCES} ${SOURCES} PARENT_SCOPE) + +# ######################################################################### # diff --git a/src/unit/Unit.cpp b/src/unit/Unit.cpp new file mode 100644 index 0000000..74b0ab0 --- /dev/null +++ b/src/unit/Unit.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/unit/Unit.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/unit/UnitIo.cpp b/src/unit/UnitIo.cpp new file mode 100644 index 0000000..245ab9e --- /dev/null +++ b/src/unit/UnitIo.cpp @@ -0,0 +1,167 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/unit/UnitIo.hpp" + +// C++ +#include + +// CeCe +#include "cece/Map.hpp" +#include "cece/Function.hpp" +#include "cece/Pair.hpp" +#include "cece/Exception.hpp" +#include "cece/unit/UnitsCtors.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Check if given character can be a part of symbol. + * + * @param c The tested character. + * + * @return True if symbol character, False otherwise. + */ +bool isSymbolChar(char c) noexcept +{ + return ( + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || + (c == '/') || (c == '%') + ); +} + +/* ************************************************************************ */ + +#define CECE_UNIT_SYMBOL(unit, name, sym, def) {sym, [] (ValueType value) -> Unit { return name(value); }}, + +const Map> symbols{ +#include "cece/unit/Units.def" +}; + +/* ************************************************************************ */ + +// User defined symbol parsers +Map> userSymbols; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +Unit parse(const char* beg, const char*& end) +{ + char* fend; + + // Read float value + const auto value = std::strtod(beg, &fend); + + // Not a float value + if (fend == beg) + throw InvalidArgumentException("Cannot parse unit value from: " + String(beg, end)); + + String symbol; + + // Store symbol characters + const char* pSym = fend; + for (; pSym != end && isSymbolChar(*pSym); ++pSym) + symbol.push_back(*pSym); + + // No symbol + if (symbol.empty()) + { + end = fend; + return Unit(value); + } + + end = pSym; + + // Use known symbol + auto it = symbols.find(symbol); + if (it != symbols.end()) + return it->second(value); + + auto it2 = userSymbols.find(symbol); + if (it2 != userSymbols.end()) + return it2->second(value); + + // Unknown symbol + throw InvalidArgumentException("Unsupported or invalid unit symbol: " + symbol); +} + +/* ************************************************************************ */ + +Unit parse(io::InStream& is) +{ + String str; + is >> str; + + return parse(str); +} + +/* ************************************************************************ */ + +Unit parse(StringView str) +{ + const char* end = str.getData() + str.getLength(); + return parse(str.getData(), end); +} + +/* ************************************************************************ */ + +void registerSymbol(String name, Function fn) +{ + userSymbols.emplace(std::move(name), std::move(fn)); +} + +/* ************************************************************************ */ + +void unregisterSymbol(StringView name) +{ +#if __cplusplus >= 201402L + userSymbols.erase(name); +#else + userSymbols.erase(String(name)); +#endif +} + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/src/unit/Units.cpp b/src/unit/Units.cpp new file mode 100644 index 0000000..b33a492 --- /dev/null +++ b/src/unit/Units.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// Declaration +#include "cece/unit/Units.hpp" + +/* ************************************************************************ */ + +namespace cece { +namespace unit { + +/* ************************************************************************ */ + +/* ************************************************************************ */ + +} +} + +/* ************************************************************************ */ diff --git a/cece/core/VectorUnits.cpp b/src/unit/VectorUnits.cpp similarity index 83% rename from cece/core/VectorUnits.cpp rename to src/unit/VectorUnits.cpp index 5a10edd..7972d18 100644 --- a/cece/core/VectorUnits.cpp +++ b/src/unit/VectorUnits.cpp @@ -24,21 +24,21 @@ /* ************************************************************************ */ // Declaration -#include "cece/core/VectorUnits.hpp" +#include "cece/unit/VectorUnits.hpp" /* ************************************************************************ */ namespace cece { -inline namespace core { +namespace math { /* ************************************************************************ */ -template class BasicVector; -template class BasicVector; -template class BasicVector; -template class BasicVector; -template class BasicVector; -template class BasicVector; +template class BasicVector; +template class BasicVector; +template class BasicVector; +template class BasicVector; +template class BasicVector; +template class BasicVector; /* ************************************************************************ */ diff --git a/cece/module/Factory.hpp b/src/version.hpp.in similarity index 85% rename from cece/module/Factory.hpp rename to src/version.hpp.in index cd4940f..73d4eaa 100644 --- a/cece/module/Factory.hpp +++ b/src/version.hpp.in @@ -27,37 +27,42 @@ /* ************************************************************************ */ -// CeCe -#include "cece/export.hpp" -#include "cece/core/Factory.hpp" - -/* ************************************************************************ */ +/** + * This file contains CeCe simulator version. + */ -namespace cece { namespace simulator { class Simulation; } } +namespace cece { /* ************************************************************************ */ -namespace cece { -namespace module { +/** + * @brief CeCe version string. + */ +constexpr auto VERSION_STRING = "${PROJECT_VERSION}"; /* ************************************************************************ */ -class Module; +/** + * @brief CeCe major version. + */ +constexpr int VERSION_MAJOR = ${PROJECT_VERSION_MAJOR}; /* ************************************************************************ */ /** - * @brief Module factory interface. + * @brief CeCe minor version. */ -using Factory = Factory; +constexpr int VERSION_MINOR = ${PROJECT_VERSION_MINOR}; /* ************************************************************************ */ -} -} +/** + * @brief CeCe patch version. + */ +constexpr int VERSION_PATCH = ${PROJECT_VERSION_PATCH}; /* ************************************************************************ */ -CECE_FACTORY_EXTERN(module::Module, simulator::Simulation&) +} /* ************************************************************************ */ diff --git a/cece/core/test/AlignedAllocatorTest.cpp b/unittests/AlignedAllocatorTest.cpp similarity index 97% rename from cece/core/test/AlignedAllocatorTest.cpp rename to unittests/AlignedAllocatorTest.cpp index 76c68f8..445a468 100644 --- a/cece/core/test/AlignedAllocatorTest.cpp +++ b/unittests/AlignedAllocatorTest.cpp @@ -27,15 +27,14 @@ #include // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/AlignedAllocator.hpp" +#include "cece/AlignedAllocator.hpp" /* ************************************************************************ */ using namespace cece; -using namespace cece::core::memory; /* ************************************************************************ */ diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt new file mode 100644 index 0000000..6184686 --- /dev/null +++ b/unittests/CMakeLists.txt @@ -0,0 +1,60 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cmake_minimum_required(VERSION 3.1) + +# ######################################################################### # + +cece_add_test(base + SOURCES + AlignedAllocatorTest.cpp + DynamicArrayTest.cpp + PtrDynamicArrayTest.cpp + MapTest.cpp + StringMapTest.cpp + PtrStringMapTest.cpp + StringTest.cpp + StringViewTest.cpp + ParametersTest.cpp + UniquePtrTest.cpp + SharedPtrTest.cpp + ViewPtrTest.cpp + IteratorRangeTest.cpp +) + +add_subdirectory(io) +add_subdirectory(os) +add_subdirectory(log) +add_subdirectory(math) +add_subdirectory(unit) +add_subdirectory(config) +add_subdirectory(plugin) +add_subdirectory(lang) + +if (CECE_RENDER) + add_subdirectory(render) +endif () + +# ######################################################################### # diff --git a/unittests/DynamicArrayTest.cpp b/unittests/DynamicArrayTest.cpp new file mode 100644 index 0000000..5518582 --- /dev/null +++ b/unittests/DynamicArrayTest.cpp @@ -0,0 +1,196 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/DynamicArray.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +struct Integer +{ + int value; + + Integer() : Integer(0) {} + Integer(int val) : value(val) {} +}; + +/* ************************************************************************ */ + +inline bool operator==(Integer lhs, int rhs) { return lhs.value == rhs; } +inline bool operator!=(Integer lhs, int rhs) { return lhs.value != rhs; } +inline bool operator==(Integer lhs, Integer rhs) { return lhs.value == rhs.value; } +inline bool operator!=(Integer lhs, Integer rhs) { return lhs.value != rhs.value; } +inline bool operator==(int lhs, Integer rhs) { return lhs == rhs.value; } +inline bool operator!=(int lhs, Integer rhs) { return lhs != rhs.value; } + +/* ************************************************************************ */ + +template +class DynamicArrayTest : public ::testing::Test {}; + +/* ************************************************************************ */ + +using TestTypes = ::testing::Types; +TYPED_TEST_CASE(DynamicArrayTest, TestTypes); + +/* ************************************************************************ */ + +TYPED_TEST(DynamicArrayTest, ctors) +{ + { + DynamicArray array; + EXPECT_EQ(0u, array.size()); + EXPECT_TRUE(array.empty()); + } + + { + DynamicArray array(5u, TypeParam(1)); + EXPECT_EQ(5u, array.size()); + EXPECT_FALSE(array.empty()); + + EXPECT_EQ(1, array[0]); + EXPECT_EQ(1, array[1]); + EXPECT_EQ(1, array[2]); + EXPECT_EQ(1, array[3]); + EXPECT_EQ(1, array[4]); + } + + { + DynamicArray array({1, 2, 3, 4}); + EXPECT_EQ(4u, array.size()); + EXPECT_FALSE(array.empty()); + + EXPECT_EQ(1, array[0]); + EXPECT_EQ(2, array[1]); + EXPECT_EQ(3, array[2]); + EXPECT_EQ(4, array[3]); + } + + { + const TypeParam src[4] = {1, 2, 3, 4}; + + DynamicArray array(std::begin(src), std::end(src)); + EXPECT_EQ(4u, array.size()); + EXPECT_FALSE(array.empty()); + + EXPECT_EQ(1, array[0]); + EXPECT_EQ(2, array[1]); + EXPECT_EQ(3, array[2]); + EXPECT_EQ(4, array[3]); + } +} + +/* ************************************************************************ */ + +TYPED_TEST(DynamicArrayTest, access) +{ + { + DynamicArray array({1, 2, 3, 4}); + EXPECT_EQ(4u, array.size()); + EXPECT_FALSE(array.empty()); + + EXPECT_EQ(1, array[0]); + EXPECT_EQ(2, array[1]); + EXPECT_EQ(3, array[2]); + EXPECT_EQ(4, array[3]); + } + + { + DynamicArray array({1, 2, 3, 4}); + EXPECT_EQ(4u, array.size()); + EXPECT_FALSE(array.empty()); + + EXPECT_EQ(1, array.at(0)); + EXPECT_EQ(2, array.at(1)); + EXPECT_EQ(3, array.at(2)); + EXPECT_EQ(4, array.at(3)); + EXPECT_ANY_THROW(array.at(4)); + } + + { + DynamicArray a1({1, 2, 3, 4}); + EXPECT_EQ(4u, a1.size()); + EXPECT_FALSE(a1.empty()); + + DynamicArray a2(a1); + EXPECT_EQ(4u, a2.size()); + EXPECT_FALSE(a2.empty()); + } + + { + DynamicArray a1({1, 2, 3, 4}); + EXPECT_EQ(4u, a1.size()); + EXPECT_FALSE(a1.empty()); + + DynamicArray a2(std::move(a1)); + EXPECT_EQ(4u, a2.size()); + EXPECT_FALSE(a2.empty()); + } +} + +/* ************************************************************************ */ + +TYPED_TEST(DynamicArrayTest, assign) +{ + { + DynamicArray a1({1, 2, 3, 4}); + EXPECT_EQ(4u, a1.size()); + EXPECT_FALSE(a1.empty()); + + DynamicArray a2 = a1; + EXPECT_EQ(4u, a2.size()); + EXPECT_FALSE(a2.empty()); + } + + { + DynamicArray a1({1, 2, 3, 4}); + EXPECT_EQ(4u, a1.size()); + EXPECT_FALSE(a1.empty()); + + DynamicArray a2 = std::move(a1); + EXPECT_EQ(4u, a2.size()); + EXPECT_FALSE(a2.empty()); + } +} + +/* ************************************************************************ */ + +TYPED_TEST(DynamicArrayTest, size) +{ + DynamicArray array; + EXPECT_EQ(0u, array.size()); + + array.resize(10u); + EXPECT_EQ(10u, array.size()); +} + +/* ************************************************************************ */ diff --git a/cece/core/test/IteratorRangeTest.cpp b/unittests/IteratorRangeTest.cpp similarity index 97% rename from cece/core/test/IteratorRangeTest.cpp rename to unittests/IteratorRangeTest.cpp index 23d8dc6..6208a59 100644 --- a/cece/core/test/IteratorRangeTest.cpp +++ b/unittests/IteratorRangeTest.cpp @@ -24,11 +24,12 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/IteratorRange.hpp" -#include "cece/core/DynamicArray.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/ValueIterator.hpp" +#include "cece/DynamicArray.hpp" /* ************************************************************************ */ diff --git a/unittests/MapTest.cpp b/unittests/MapTest.cpp new file mode 100644 index 0000000..0b2fb50 --- /dev/null +++ b/unittests/MapTest.cpp @@ -0,0 +1,68 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/Exception.hpp" +#include "cece/Map.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(MapTest, ctors) +{ + { + Map data; + EXPECT_EQ(0u, data.size()); + EXPECT_TRUE(data.empty()); + } + + { + Map data{{1, 2}, {2, 3}}; + EXPECT_EQ(2u, data.size()); + EXPECT_FALSE(data.empty()); + } +} + +/* ************************************************************************ */ + +TEST(MapTest, at) +{ + Map data; + data.emplace(0, 0); + data.emplace(1, 3); + EXPECT_EQ(2u, data.size()); + + EXPECT_EQ(0, data.at(0)); + EXPECT_EQ(3, data.at(1)); + EXPECT_THROW(data.at(2), OutOfRangeException); +} + +/* ************************************************************************ */ diff --git a/cece/core/test/ParametersTest.cpp b/unittests/ParametersTest.cpp similarity index 97% rename from cece/core/test/ParametersTest.cpp rename to unittests/ParametersTest.cpp index 8477d76..79a96ff 100644 --- a/cece/core/test/ParametersTest.cpp +++ b/unittests/ParametersTest.cpp @@ -27,12 +27,12 @@ #include // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/Parameters.hpp" +#include "cece/String.hpp" +#include "cece/StaticArray.hpp" +#include "cece/Parameters.hpp" /* ************************************************************************ */ diff --git a/cece/core/test/PtrContainerTest.cpp b/unittests/PtrDynamicArrayTest.cpp similarity index 75% rename from cece/core/test/PtrContainerTest.cpp rename to unittests/PtrDynamicArrayTest.cpp index fb92b9a..7f90869 100644 --- a/cece/core/test/PtrContainerTest.cpp +++ b/unittests/PtrDynamicArrayTest.cpp @@ -27,14 +27,14 @@ #include // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/UniquePtr.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Exception.hpp" -#include "cece/core/StaticArray.hpp" -#include "cece/core/PtrContainer.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/String.hpp" +#include "cece/Exception.hpp" +#include "cece/StaticArray.hpp" +#include "cece/PtrDynamicArray.hpp" /* ************************************************************************ */ @@ -42,25 +42,25 @@ using namespace cece; /* ************************************************************************ */ -TEST(PtrContainerTest, ctorEmpty) +TEST(PtrDynamicArrayTest, ctorEmpty) { - PtrContainer data; - EXPECT_EQ(0u, data.getCount()); + PtrDynamicArray data; + EXPECT_EQ(0u, data.size()); } /* ************************************************************************ */ -TEST(PtrContainerTest, read) +TEST(PtrDynamicArrayTest, read) { - PtrContainer data; + PtrDynamicArray data; data.create(5); - EXPECT_EQ(1u, data.getCount()); + EXPECT_EQ(1u, data.size()); EXPECT_EQ(5, *data[0]); data.create(0); data.create(566); - EXPECT_EQ(3u, data.getCount()); + EXPECT_EQ(3u, data.size()); EXPECT_EQ(5, *data[0]); EXPECT_EQ(0, *data[1]); @@ -69,34 +69,34 @@ TEST(PtrContainerTest, read) /* ************************************************************************ */ -TEST(PtrContainerTest, get) +TEST(PtrDynamicArrayTest, at) { - PtrContainer data; + PtrDynamicArray data; data.create(0); data.create(3); - EXPECT_EQ(2u, data.getCount()); + EXPECT_EQ(2u, data.size()); - EXPECT_EQ(0, *data.get(0)); - EXPECT_EQ(3, *data.get(1)); - EXPECT_THROW(data.get(2), OutOfRangeException); + EXPECT_EQ(0, *data.at(0)); + EXPECT_EQ(3, *data.at(1)); + EXPECT_THROW(data.at(2), OutOfRangeException); } /* ************************************************************************ */ -TEST(PtrContainerTest, write) +TEST(PtrDynamicArrayTest, write) { - PtrContainer data; + PtrDynamicArray data; data.add(makeUnique(10)); - EXPECT_EQ(1u, data.getCount()); + EXPECT_EQ(1u, data.size()); - EXPECT_EQ(10, *data.get(0)); + EXPECT_EQ(10, *data.at(0)); } /* ************************************************************************ */ -TEST(PtrContainerTest, remove) +TEST(PtrDynamicArrayTest, remove) { - PtrContainer data; + PtrDynamicArray data; auto ptr1 = data.create(1); auto ptr2 = data.create(2); auto ptr3 = data.create(3); @@ -104,39 +104,39 @@ TEST(PtrContainerTest, remove) EXPECT_EQ(1, *ptr1); EXPECT_EQ(2, *ptr2); EXPECT_EQ(3, *ptr3); - EXPECT_EQ(3u, data.getCount()); + EXPECT_EQ(3u, data.size()); data.remove(ptr2); data.remove(ptr1); - EXPECT_EQ(1u, data.getCount()); - EXPECT_EQ(*ptr3, *data.get(0)); - EXPECT_EQ(3, *data.get(0)); + EXPECT_EQ(1u, data.size()); + EXPECT_EQ(*ptr3, *data.at(0)); + EXPECT_EQ(3, *data.at(0)); } /* ************************************************************************ */ -TEST(PtrContainerTest, clear) +TEST(PtrDynamicArrayTest, clear) { - PtrContainer data; + PtrDynamicArray data; data.create(1); data.create(2); data.create(3); - EXPECT_EQ(3u, data.getCount()); + EXPECT_EQ(3u, data.size()); data.clear(); - EXPECT_EQ(0u, data.getCount()); + EXPECT_EQ(0u, data.size()); } /* ************************************************************************ */ -TEST(PtrContainerTest, iterate) +TEST(PtrDynamicArrayTest, iterate) { const StaticArray names{{"name1", "name2", "name3"}}; - PtrContainer data; - ASSERT_EQ(0u, data.getCount()); + PtrDynamicArray data; + ASSERT_EQ(0u, data.size()); for (const auto& name : names) data.create(name); diff --git a/unittests/PtrStringMapTest.cpp b/unittests/PtrStringMapTest.cpp new file mode 100644 index 0000000..0d5801d --- /dev/null +++ b/unittests/PtrStringMapTest.cpp @@ -0,0 +1,133 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/Exception.hpp" +#include "cece/PtrStringMap.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, ctors) +{ + { + PtrStringMap data; + EXPECT_EQ(0u, data.size()); + EXPECT_TRUE(data.empty()); + } + + { + PtrStringMap data; + data.create("one", 1); + data.create("two", 2); + EXPECT_EQ(2u, data.size()); + EXPECT_FALSE(data.empty()); + } +} + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, add) +{ + PtrStringMap data; + data.add("one", makeUnique(1)); + data.add("two", makeUnique(2)); + EXPECT_EQ(2u, data.size()); + + EXPECT_TRUE(data.exists("one")); + EXPECT_TRUE(data.exists("two")); + EXPECT_FALSE(data.exists("three")); + + // Replace + data.add("one", makeUnique(3)); + EXPECT_EQ(2u, data.size()); + EXPECT_TRUE(data.exists("one")); +} + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, exists) +{ + PtrStringMap data; + data.create("one", 1); + data.create("two", 2); + EXPECT_EQ(2u, data.size()); + + EXPECT_TRUE(data.exists("one")); + EXPECT_TRUE(data.exists("two")); + EXPECT_FALSE(data.exists("three")); +} + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, at) +{ + PtrStringMap data; + data.create("one", 1); + data.create("two", 2); + EXPECT_EQ(2u, data.size()); + + EXPECT_EQ(1, *data.at("one")); + EXPECT_EQ(2, *data.at("two")); + EXPECT_THROW(data.at("three"), OutOfRangeException); +} + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, get) +{ + PtrStringMap data; + data.create("one", 1); + data.create("two", 2); + EXPECT_EQ(2u, data.size()); + + ASSERT_NE(nullptr, data.get("one")); + EXPECT_EQ(1, *data.get("one")); + ASSERT_NE(nullptr, data.get("two")); + EXPECT_EQ(2, *data.get("two")); + EXPECT_EQ(nullptr, data.get("three")); +} + +/* ************************************************************************ */ + +TEST(PtrStringMapTest, remove) +{ + PtrStringMap data; + data.add("one", makeUnique(1)); + data.add("two", makeUnique(2)); + EXPECT_EQ(2u, data.size()); + + data.remove("one"); + + EXPECT_EQ(1u, data.size()); +} + +/* ************************************************************************ */ diff --git a/unittests/SharedPtrTest.cpp b/unittests/SharedPtrTest.cpp new file mode 100644 index 0000000..72ab469 --- /dev/null +++ b/unittests/SharedPtrTest.cpp @@ -0,0 +1,79 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/SharedPtr.hpp" +#include "cece/ViewPtr.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(SharedPtr, ctor) +{ + { + SharedPtr ptr; + EXPECT_EQ(nullptr, ptr); + } + + { + SharedPtr ptr(new int{5}); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(5, *ptr); + } +} + +/* ************************************************************************ */ + +TEST(SharedPtr, makeShared) +{ + { + auto ptr = makeShared(5); + ::testing::StaticAssertTypeEq>(); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(5, *ptr); + } +} + +/* ************************************************************************ */ + +TEST(SharedPtr, makeView) +{ + { + auto ptr = makeShared(10); + auto view = makeView(ptr); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(view.get(), ptr.get()); + EXPECT_EQ(10, *ptr); + EXPECT_EQ(10, *view); + } +} + +/* ************************************************************************ */ diff --git a/unittests/StringMapTest.cpp b/unittests/StringMapTest.cpp new file mode 100644 index 0000000..5fdb030 --- /dev/null +++ b/unittests/StringMapTest.cpp @@ -0,0 +1,80 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/Exception.hpp" +#include "cece/StringMap.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(StringMapTest, ctors) +{ + { + StringMap data; + EXPECT_EQ(0u, data.size()); + EXPECT_TRUE(data.empty()); + } + + { + StringMap data{{"one", 1}, {"two", 2}}; + EXPECT_EQ(2u, data.size()); + EXPECT_FALSE(data.empty()); + } +} + +/* ************************************************************************ */ + +TEST(StringMapTest, exists) +{ + StringMap data{{"one", 1}, {"two", 2}}; + EXPECT_EQ(2u, data.size()); + + EXPECT_TRUE(data.exists("one")); + EXPECT_TRUE(data.exists("two")); + EXPECT_FALSE(data.exists("three")); +} + +/* ************************************************************************ */ + +TEST(StringMapTest, at) +{ + StringMap data; + data.emplace("one", 1); + data.emplace("two", 2); + EXPECT_EQ(2u, data.size()); + + EXPECT_EQ(1, data.at("one")); + EXPECT_EQ(2, data.at("two")); + EXPECT_THROW(data.at("three"), OutOfRangeException); +} + +/* ************************************************************************ */ diff --git a/unittests/StringTest.cpp b/unittests/StringTest.cpp new file mode 100644 index 0000000..2eeb5fd --- /dev/null +++ b/unittests/StringTest.cpp @@ -0,0 +1,249 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/String.hpp" +#include "cece/Exception.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(String, toString) +{ + { + auto str = toString(0); + EXPECT_EQ("0", str); + } + + { + auto str = toString(4897232); + EXPECT_EQ("4897232", str); + } + + { + auto str = toString(-4897232); + EXPECT_EQ("-4897232", str); + } + + { + auto str = toString(48972321u); + EXPECT_EQ("48972321", str); + } + + { + auto str = toString(48972321l); + EXPECT_EQ("48972321", str); + } + + { + auto str = toString(48972321ul); + EXPECT_EQ("48972321", str); + } + + { + auto str = toString(48972324561ll); + EXPECT_EQ("48972324561", str); + } + + { + auto str = toString(48972324561ull); + EXPECT_EQ("48972324561", str); + } + + { + auto str = toString(1.3f); + EXPECT_EQ("1.300000", str); + } + + { + auto str = toString(1.3); + EXPECT_EQ("1.300000", str); + } + + { + auto str = toString(1.3l); + EXPECT_EQ("1.300000", str); + } +} + +/* ************************************************************************ */ + +TEST(String, str2i) +{ + { + auto val = str2i("0"); + EXPECT_EQ(0, val); + } + + { + auto val = str2i("484321"); + EXPECT_EQ(484321, val); + } + + { + auto val = str2i("-484321"); + EXPECT_EQ(-484321, val); + } + + { + EXPECT_THROW(str2i("abc04"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2i("1.456"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2i(""), InvalidArgumentException); + } +} + +/* ************************************************************************ */ + +TEST(String, str2l) +{ + { + auto val = str2l("0"); + EXPECT_EQ(0, val); + } + + { + auto val = str2l("484321"); + EXPECT_EQ(484321, val); + } + + { + auto val = str2l("-484321"); + EXPECT_EQ(-484321, val); + } + + { + EXPECT_THROW(str2l("abc04"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2l("1.456"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2l(""), InvalidArgumentException); + } +} + +/* ************************************************************************ */ + +TEST(String, str2ll) +{ + { + auto val = str2ll("0"); + EXPECT_EQ(0, val); + } + + { + auto val = str2ll("484321"); + EXPECT_EQ(484321, val); + } + + { + auto val = str2ll("-484321"); + EXPECT_EQ(-484321, val); + } + + { + EXPECT_THROW(str2ll("abc04"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2ll("1.456"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2ll(""), InvalidArgumentException); + } +} + +/* ************************************************************************ */ + +TEST(String, str2f) +{ + { + auto val = str2f("0"); + EXPECT_FLOAT_EQ(0, val); + } + + { + auto val = str2f(".41"); + EXPECT_FLOAT_EQ(.41, val); + } + + { + auto val = str2f("-484321"); + EXPECT_FLOAT_EQ(-484321, val); + } + + { + EXPECT_THROW(str2f("as45e12"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2f(""), InvalidArgumentException); + } +} + +/* ************************************************************************ */ + +TEST(String, str2d) +{ + { + auto val = str2d("0"); + EXPECT_FLOAT_EQ(0, val); + } + + { + auto val = str2d(".41"); + EXPECT_FLOAT_EQ(.41, val); + } + + { + auto val = str2d("-484321"); + EXPECT_FLOAT_EQ(-484321, val); + } + + { + EXPECT_THROW(str2d("as45e12"), InvalidArgumentException); + } + + { + EXPECT_THROW(str2d(""), InvalidArgumentException); + } +} + +/* ************************************************************************ */ diff --git a/cece/core/test/StringViewTest.cpp b/unittests/StringViewTest.cpp similarity index 82% rename from cece/core/test/StringViewTest.cpp rename to unittests/StringViewTest.cpp index 2c5c457..aa4a597 100644 --- a/cece/core/test/StringViewTest.cpp +++ b/unittests/StringViewTest.cpp @@ -24,11 +24,11 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/String.hpp" -#include "cece/core/StringView.hpp" +#include "cece/String.hpp" +#include "cece/StringView.hpp" /* ************************************************************************ */ @@ -67,6 +67,32 @@ TEST(StringView, compare) auto view = StringView(str); EXPECT_EQ("Hello World!", view); } + + { + auto v1 = StringView("aa"); + auto v2 = StringView("aa"); + EXPECT_EQ(v1, v2); + EXPECT_LE(v1, v2); + EXPECT_GE(v1, v2); + } + + { + auto v1 = StringView("a"); + auto v2 = StringView("b"); + EXPECT_LT(v1, v2); + EXPECT_LE(v1, v2); + EXPECT_GE(v2, v1); + EXPECT_GT(v2, v1); + } + + { + auto v1 = StringView("aa"); + auto v2 = StringView("b"); + EXPECT_LT(v1, v2); + EXPECT_LE(v1, v2); + EXPECT_GE(v2, v1); + EXPECT_GT(v2, v1); + } } /* ************************************************************************ */ diff --git a/unittests/UniquePtrTest.cpp b/unittests/UniquePtrTest.cpp new file mode 100644 index 0000000..5bd4906 --- /dev/null +++ b/unittests/UniquePtrTest.cpp @@ -0,0 +1,89 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/UniquePtr.hpp" +#include "cece/ViewPtr.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +TEST(UniquePtr, ctor) +{ + { + UniquePtr ptr; + EXPECT_EQ(nullptr, ptr); + } + + { + UniquePtr ptr(new int{5}); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(5, *ptr); + } +} + +/* ************************************************************************ */ + +TEST(UniquePtr, makeUnique) +{ + { + auto ptr = makeUnique(5); + ::testing::StaticAssertTypeEq>(); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(5, *ptr); + } +} + +/* ************************************************************************ */ + +TEST(UniquePtr, makeUniqueResource) +{ + { + auto ptr = makeUniqueResource((int*) malloc(sizeof(int)), free); + ASSERT_NE(nullptr, ptr); + } +} + +/* ************************************************************************ */ + +TEST(UniquePtr, makeView) +{ + { + auto ptr = makeUnique(10); + auto view = makeView(ptr); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ(view.get(), ptr.get()); + EXPECT_EQ(10, *ptr); + EXPECT_EQ(10, *view); + } +} + +/* ************************************************************************ */ diff --git a/cece/core/test/VectorTest.cpp b/unittests/VectorTest.cpp similarity index 98% rename from cece/core/test/VectorTest.cpp rename to unittests/VectorTest.cpp index 38b17e5..bd1f599 100644 --- a/cece/core/test/VectorTest.cpp +++ b/unittests/VectorTest.cpp @@ -23,19 +23,20 @@ /* */ /* ************************************************************************ */ -// GTest -#include - // C++ #include #include +// GTest +#include "gtest/gtest.h" + // CeCe -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::math; /* ************************************************************************ */ diff --git a/cece/core/test/ViewPtrTest.cpp b/unittests/ViewPtrTest.cpp similarity index 98% rename from cece/core/test/ViewPtrTest.cpp rename to unittests/ViewPtrTest.cpp index 356e403..1525860 100644 --- a/cece/core/test/ViewPtrTest.cpp +++ b/unittests/ViewPtrTest.cpp @@ -24,10 +24,10 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/ViewPtr.hpp" +#include "cece/ViewPtr.hpp" /* ************************************************************************ */ diff --git a/unittests/config/CMakeLists.txt b/unittests/config/CMakeLists.txt new file mode 100644 index 0000000..268c248 --- /dev/null +++ b/unittests/config/CMakeLists.txt @@ -0,0 +1,32 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(config + SOURCES + ExceptionTest.cpp + ConfigurationTest.cpp +) + +# ######################################################################### # diff --git a/unittests/config/ConfigurationTest.cpp b/unittests/config/ConfigurationTest.cpp new file mode 100644 index 0000000..038b899 --- /dev/null +++ b/unittests/config/ConfigurationTest.cpp @@ -0,0 +1,374 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// C++ +#include + +// CeCe +#include "cece/Parameters.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/Converter.hpp" +#include "cece/config/Configuration.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::config; + +/* ************************************************************************ */ + +/** + * @brief Sort given names. + * + * @param[in] names The names + * + * @return Sorted list of names. + */ +DynamicArray sortNames(DynamicArray names) +{ + // The interface doesn't define returned names order + std::sort(names.begin(), names.end()); + + return names; +} + +/* ************************************************************************ */ + +TEST(Configuration, memory) +{ + Configuration config; + EXPECT_FALSE(config.has("name1")); + EXPECT_FALSE(config.has("name2")); + EXPECT_FALSE(config.hasContent()); + + config.set("name1", "value1"); + EXPECT_TRUE(config.has("name1")); + EXPECT_FALSE(config.has("name2")); + EXPECT_FALSE(config.hasContent()); + EXPECT_EQ("value1", config.get("name1")); + EXPECT_EQ("value1", config.get("name1", "def-value1")); + + config.set("name2", "value2"); + EXPECT_TRUE(config.has("name1")); + EXPECT_TRUE(config.has("name2")); + EXPECT_FALSE(config.hasContent()); + EXPECT_EQ("value2", config.get("name2")); + EXPECT_EQ("value2", config.get("name2", "def-value2")); + + ASSERT_FALSE(config.has("name5")); + EXPECT_EQ("def-value5", config.get("name5", "def-value5")); + EXPECT_THROW(config.get("name5"), NotFoundException); + + config.setContent("Hello world"); + EXPECT_TRUE(config.has("name1")); + EXPECT_TRUE(config.has("name2")); + EXPECT_TRUE(config.hasContent()); + EXPECT_EQ("Hello world", config.getContent()); + + // Get names + auto names = sortNames(config.getNames()); + ASSERT_EQ(2, names.size()); + EXPECT_EQ("name1", names[0]); + EXPECT_EQ("name2", names[1]); +} + +/* ************************************************************************ */ + +TEST(Configuration, params) +{ + Parameters params; + params["value"] = "15"; + params["value2"] = "72"; + + Configuration config(makeView(¶ms)); + + config.set("name1", "{$value}"); + ASSERT_TRUE(config.has("name1")); + EXPECT_EQ("15", config.get("name1")); + + // Multiple replacements + config.set("str", "Number1 = {$value}, Number2 = {$value2}"); + ASSERT_TRUE(config.has("str")); + EXPECT_EQ("Number1 = 15, Number2 = 72", config.get("str")); + + // Unterminated block + config.set("name2", "{$value"); + ASSERT_TRUE(config.has("name2")); + EXPECT_THROW(config.get("name2"), UnterminatedParameterException); + + // Invalid characters in names + config.set("name3", "{$v-a_lue}"); + ASSERT_TRUE(config.has("name3")); + EXPECT_THROW(config.get("name3"), InvalidParameterNameException); +} + +/* ************************************************************************ */ + +TEST(Configuration, append) +{ + // Merge two configurations + Configuration config1; + Configuration config2; + + config1.set("name11", "11"); + config1.set("name12", "12"); + config1.set("name13", "13"); + { + auto child = config1.addConfiguration("child11"); + child.set("name111", "111"); + child.set("name112", "112"); + } + { + auto child = config1.addConfiguration("child12"); + child.set("name121", "121"); + child.set("name122", "122"); + } + { + auto child = config1.addConfiguration("shared"); + child.set("name", "value1"); + } + + config1.set("shared", "value1"); + config1.setContent("content1"); + + config2.set("name21", "21"); + config2.set("name22", "22"); + config2.set("name23", "23"); + { + auto child = config2.addConfiguration("child21"); + child.set("name211", "211"); + child.set("name212", "212"); + } + { + auto child = config2.addConfiguration("child22"); + child.set("name221", "221"); + child.set("name222", "222"); + } + { + auto child = config2.addConfiguration("shared"); + child.set("name", "value2"); + } + + config2.set("shared", "value2"); + config1.setContent("content2"); + + // Append configurations - overwrite shared values in config1 by config2 + config1.append(config2); + + ASSERT_TRUE(config1.has("name11")); + EXPECT_EQ("11", config1.get("name11")); + ASSERT_TRUE(config1.has("name12")); + EXPECT_EQ("12", config1.get("name12")); + ASSERT_TRUE(config1.has("name13")); + EXPECT_EQ("13", config1.get("name13")); + ASSERT_TRUE(config1.has("name21")); + EXPECT_EQ("21", config1.get("name21")); + ASSERT_TRUE(config1.has("name22")); + EXPECT_EQ("22", config1.get("name22")); + ASSERT_TRUE(config1.has("name23")); + EXPECT_EQ("23", config1.get("name23")); + ASSERT_TRUE(config1.has("shared")); + EXPECT_EQ("value2", config1.get("shared")); + ASSERT_TRUE(config1.hasContent()); + EXPECT_EQ("content2", config1.getContent()); + + // Names + auto names = sortNames(config1.getNames()); + ASSERT_EQ(7, names.size()); + EXPECT_EQ("name11", names[0]); + EXPECT_EQ("name12", names[1]); + EXPECT_EQ("name13", names[2]); + EXPECT_EQ("name21", names[3]); + EXPECT_EQ("name22", names[4]); + EXPECT_EQ("name23", names[5]); + EXPECT_EQ("shared", names[6]); + + // Child names + auto childNames = sortNames(config1.getConfigurationNames()); + ASSERT_EQ(5, childNames.size()); + EXPECT_EQ("child11", childNames[0]); + EXPECT_EQ("child12", childNames[1]); + EXPECT_EQ("child21", childNames[2]); + EXPECT_EQ("child22", childNames[3]); + EXPECT_EQ("shared", childNames[4]); + + auto childs = config1.getConfigurations("child11"); + ASSERT_EQ(1, childs.size()); + ASSERT_TRUE(childs[0].has("name111")); + EXPECT_EQ("111", childs[0].get("name111")); + ASSERT_TRUE(childs[0].has("name112")); + EXPECT_EQ("112", childs[0].get("name112")); + + childs = config1.getConfigurations("child12"); + ASSERT_EQ(1, childs.size()); + ASSERT_TRUE(childs[0].has("name121")); + EXPECT_EQ("121", childs[0].get("name121")); + ASSERT_TRUE(childs[0].has("name122")); + EXPECT_EQ("122", childs[0].get("name122")); + + childs = config1.getConfigurations("child21"); + ASSERT_EQ(1, childs.size()); + ASSERT_TRUE(childs[0].has("name211")); + EXPECT_EQ("211", childs[0].get("name211")); + ASSERT_TRUE(childs[0].has("name212")); + EXPECT_EQ("212", childs[0].get("name212")); + + childs = config1.getConfigurations("child22"); + ASSERT_EQ(1, childs.size()); + ASSERT_TRUE(childs[0].has("name221")); + EXPECT_EQ("221", childs[0].get("name221")); + ASSERT_TRUE(childs[0].has("name222")); + EXPECT_EQ("222", childs[0].get("name222")); + + childs = config1.getConfigurations("shared"); + ASSERT_EQ(2, childs.size()); + ASSERT_TRUE(childs[0].has("name")); + EXPECT_EQ("value1", childs[0].get("name")); + ASSERT_TRUE(childs[1].has("name")); + EXPECT_EQ("value2", childs[1].get("name")); +} + +/* ************************************************************************ */ + +TEST(Configuration, childs) +{ + Configuration config; + + // No child configuration + EXPECT_EQ(0, config.getConfigurationNames().size()); + EXPECT_FALSE(config.hasConfiguration("child1")); + EXPECT_FALSE(config.hasConfiguration("child2")); + + // Get childs + auto childs = config.getConfigurations("child1"); + EXPECT_EQ(0, childs.size()); + EXPECT_THROW(config.getConfiguration("child1"), NotFoundException); + + // Create child configuration + auto child1 = config.addConfiguration("child1"); + auto child2 = config.addConfiguration("child2"); + EXPECT_TRUE(config.hasConfiguration("child1")); + EXPECT_TRUE(config.hasConfiguration("child2")); + + auto names = sortNames(config.getConfigurationNames()); + ASSERT_EQ(2, names.size()); + EXPECT_EQ("child1", names[0]); + EXPECT_EQ("child2", names[1]); + + // It shouldn't throw + EXPECT_NO_THROW(config.getConfiguration("child1")); + + // One child + childs = config.getConfigurations("child1"); + EXPECT_EQ(1, childs.size()); +} + +/* ************************************************************************ */ + +TEST(Configuration, toMemory) +{ + Configuration config1; + config1.set("name1", "1"); + config1.set("name2", "2"); + + auto child1 = config1.addConfiguration("child1"); + child1.set("name11", "11"); + child1.setContent("content11"); + + // Create memory version + auto config2 = config1.toMemory(); + + ASSERT_TRUE(config2.has("name1")); + EXPECT_EQ("1", config2.get("name1")); + ASSERT_TRUE(config2.has("name2")); + EXPECT_EQ("2", config2.get("name2")); + + ASSERT_TRUE(config2.hasConfiguration("child1")); + auto child2 = config2.getConfiguration("child1"); + ASSERT_TRUE(child2.has("name11")); + EXPECT_EQ("11", child2.get("name11")); + ASSERT_TRUE(child2.hasContent()); + EXPECT_EQ("content11", child2.getContent()); +} + +/* ************************************************************************ */ + +TEST(Configuration, converter) +{ + Configuration config; + + config.set("bool", true); + ASSERT_TRUE(config.has("bool")); + EXPECT_TRUE(config.get("bool")); + EXPECT_TRUE(config.get("bool", false)); + + config.set("bool", false); + ASSERT_TRUE(config.has("bool")); + EXPECT_FALSE(config.get("bool")); + EXPECT_FALSE(config.get("bool", true)); + + config.set("int", 15); + ASSERT_TRUE(config.has("int")); + EXPECT_EQ(15, config.get("int")); + EXPECT_EQ(15, config.get("int", 753)); + + config.set("uint", 15u); + ASSERT_TRUE(config.has("uint")); + EXPECT_EQ(15u, config.get("uint")); + EXPECT_EQ(15u, config.get("uint", 45632u)); + + config.set("long", 1496423135l); + ASSERT_TRUE(config.has("long")); + EXPECT_EQ(1496423135l, config.get("long")); + EXPECT_EQ(1496423135l, config.get("long", 4244l)); + + config.set("ulong", 1496423135ul); + ASSERT_TRUE(config.has("ulong")); + EXPECT_EQ(1496423135ul, config.get("ulong")); + EXPECT_EQ(1496423135ul, config.get("ulong", 4244ul)); + + config.set("float", 0.31f); + ASSERT_TRUE(config.has("float")); + EXPECT_FLOAT_EQ(0.31f, config.get("float")); + EXPECT_FLOAT_EQ(0.31f, config.get("float", 0.1f)); + + config.set("double", 0.31); + ASSERT_TRUE(config.has("double")); + EXPECT_FLOAT_EQ(0.31, config.get("double")); + EXPECT_FLOAT_EQ(0.31, config.get("double", 0.0)); + + ASSERT_FALSE(config.has("double2")); + EXPECT_FLOAT_EQ(0.31, config.get("double2", 0.31)); + + config.set("path", io::FilePath("/home/user/file.txt")); + ASSERT_TRUE(config.has("path")); + EXPECT_EQ("/home/user/file.txt", config.get("path")); + EXPECT_EQ("/tmp", config.get("path2", "/tmp")); +} + +/* ************************************************************************ */ diff --git a/unittests/config/ExceptionTest.cpp b/unittests/config/ExceptionTest.cpp new file mode 100644 index 0000000..78b72c6 --- /dev/null +++ b/unittests/config/ExceptionTest.cpp @@ -0,0 +1,82 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/UniquePtr.hpp" +#include "cece/config/Exception.hpp" + +/* ************************************************************************ */ + +using namespace cece::config; + +/* ************************************************************************ */ + +TEST(Exception, base) +{ + Exception e("Test"); + + // Test virtual destructor + cece::UniquePtr ptr = cece::makeUnique("Test"); +} + +/* ************************************************************************ */ + +TEST(Exception, not_found) +{ + NotFoundException e("Test"); + + // Test virtual destructor + cece::UniquePtr ptr = cece::makeUnique("Test"); +} + +/* ************************************************************************ */ + +TEST(Exception, unterminated_parameter) +{ + UnterminatedParameterException e("{$name"); + + EXPECT_EQ("{$name", e.getText()); + + // Test virtual destructor + cece::UniquePtr ptr = cece::makeUnique("Test"); +} + +/* ************************************************************************ */ + +TEST(Exception, invalid_parameter_name) +{ + InvalidParameterNameException e("name 1", "{$name 1}"); + + EXPECT_EQ("name 1", e.getName()); + EXPECT_EQ("{$name 1}", e.getText()); + + // Test virtual destructor + cece::UniquePtr ptr = cece::makeUnique("Test", "Test"); +} + +/* ************************************************************************ */ diff --git a/cece/module/CMakeLists.txt b/unittests/io/CMakeLists.txt similarity index 85% rename from cece/module/CMakeLists.txt rename to unittests/io/CMakeLists.txt index 24ee7ba..b8db870 100644 --- a/cece/module/CMakeLists.txt +++ b/unittests/io/CMakeLists.txt @@ -23,24 +23,15 @@ # # # ######################################################################### # -# Sources -set(SRCS - Module.hpp - Module.cpp - Factory.hpp - Factory.cpp - FactoryManager.hpp - FactoryManager.cpp - Container.hpp - Container.cpp - ExportModule.hpp - ExportModule.cpp +cece_add_test(io + SOURCES + FilePathTest.cpp ) # ######################################################################### # -dir_pretend(SOURCES module/ ${SRCS}) - -set(SOURCES_MODULE ${SOURCES} PARENT_SCOPE) +file(GENERATE OUTPUT "$/file1.txt" CONTENT "Hello world!\n") +file(GENERATE OUTPUT "$/dir1/file2.txt" CONTENT "Hello world!\n") +file(GENERATE OUTPUT "$/dir1/file3.txt" CONTENT "Hello world!\n") # ######################################################################### # diff --git a/unittests/io/FilePathTest.cpp b/unittests/io/FilePathTest.cpp new file mode 100644 index 0000000..555bb91 --- /dev/null +++ b/unittests/io/FilePathTest.cpp @@ -0,0 +1,277 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// C++ +#include +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/io/StringStream.hpp" +#include "cece/io/FilePath.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::io; + +/* ************************************************************************ */ + +TEST(FilePath, construct) +{ + { + auto path = FilePath(); + EXPECT_TRUE(path.isEmpty()); + } + + { + const char* str = "filename1"; + auto path = FilePath(str); + EXPECT_FALSE(path.isEmpty()); + EXPECT_EQ(str, path.toString()); + } + + { + String str = "dirname/filename"; + auto path = FilePath(str); + EXPECT_FALSE(path.isEmpty()); + EXPECT_EQ(str, path.toString()); + } +} + +/* ************************************************************************ */ + +TEST(FilePath, append) +{ + { + auto path = FilePath("dir"); + path /= "filename"; + EXPECT_EQ("dir/filename", path.toString()); + } + + { + auto path = FilePath("dir"); + auto file = FilePath("filename"); + + auto p = path / file; + EXPECT_EQ("dir/filename", p.toString()); + } +} + +/* ************************************************************************ */ + +TEST(FilePath, concat) +{ + { + auto path = FilePath("dir"); + path += "filename"; + path += FilePath(".txt"); + EXPECT_EQ("dirfilename.txt", path.toString()); + } + + { + auto path = FilePath("dir"); + auto file = FilePath("filename"); + + auto p = path + file + ".txt"; + EXPECT_EQ("dirfilename.txt", p.toString()); + } +} + +/* ************************************************************************ */ + +TEST(FilePath, operations) +{ + FilePath emptyPath; + + EXPECT_TRUE(emptyPath.isEmpty()); + EXPECT_EQ("", emptyPath.toString()); + EXPECT_EQ("", emptyPath.getFilename()); + EXPECT_EQ("", emptyPath.getExtension()); + EXPECT_EQ("", emptyPath.getParentPath()); + EXPECT_EQ("", emptyPath.getStem()); + EXPECT_EQ(0, emptyPath.getSize()); + EXPECT_EQ(0, std::strlen(emptyPath.c_str())); + + emptyPath /= "file"; + EXPECT_EQ("file", emptyPath.toString()); + + emptyPath.replaceExtension(".txt"); + EXPECT_EQ("file.txt", emptyPath.toString()); + + emptyPath.replaceExtension("pdf"); + EXPECT_EQ("file.pdf", emptyPath.toString()); + + FilePath path("dir1/dir2/dir3/file.txt"); + + EXPECT_FALSE(path.isEmpty()); + EXPECT_EQ(23, path.getSize()); + EXPECT_EQ("dir1/dir2/dir3/file.txt", path.toString()); + EXPECT_EQ("file.txt", path.getFilename()); + EXPECT_EQ(".txt", path.getExtension()); + EXPECT_EQ("dir1/dir2/dir3", path.getParentPath().toString()); + EXPECT_EQ("dir1/dir2/dir3/file", path.getStem().toString()); + + path.replaceExtension(".img"); + EXPECT_EQ("dir1/dir2/dir3/file.img", path.toString()); + + path.concat(".txt"); + EXPECT_EQ("dir1/dir2/dir3/file.img.txt", path.toString()); +} + +/* ************************************************************************ */ + +TEST(FilePath, rel) +{ + const FilePath p1("file1"); + const FilePath p2("file2"); + const FilePath p3("file1"); + + EXPECT_EQ(p1, p1); + EXPECT_NE(p1, p2); + EXPECT_EQ(p1, p3); + EXPECT_NE(p2, p1); + EXPECT_EQ(p2, p2); + EXPECT_NE(p2, p3); + EXPECT_EQ(p3, p1); + EXPECT_NE(p3, p2); + EXPECT_EQ(p3, p3); + + EXPECT_EQ(p1, "file1"); + EXPECT_EQ(p1, String("file1")); + EXPECT_NE(p1, "file2"); + EXPECT_NE(p1, String("file2")); + + EXPECT_EQ("file1", p1); + EXPECT_EQ(String("file1"), p1); + EXPECT_NE("file2", p1); + EXPECT_NE(String("file2"), p1); +} + +/* ************************************************************************ */ + +TEST(FilePath, functions) +{ + EXPECT_TRUE(FilePath::exists("file1.txt")); + EXPECT_TRUE(FilePath::isFile("file1.txt")); + EXPECT_FALSE(FilePath::isDirectory("file1.txt")); + + EXPECT_TRUE(FilePath::exists("dir1")); + EXPECT_TRUE(FilePath::isDirectory("dir1")); + EXPECT_FALSE(FilePath::isFile("dir1")); + + EXPECT_TRUE(FilePath::exists("dir1/file2.txt")); + EXPECT_TRUE(FilePath::isFile("dir1/file2.txt")); + EXPECT_FALSE(FilePath::isDirectory("dir1/file2.txt")); + + EXPECT_FALSE(FilePath::exists("file2.txt")); + EXPECT_FALSE(FilePath::isFile("file2.txt")); + EXPECT_FALSE(FilePath::isDirectory("file2.txt")); + + auto temp = FilePath::getTempDirectory(); + EXPECT_TRUE(FilePath::exists(temp)); + EXPECT_TRUE(FilePath::isDirectory(temp)); + + // Deprecated + EXPECT_TRUE(pathExists("file1.txt")); + EXPECT_TRUE(isFile("file1.txt")); + EXPECT_FALSE(isDirectory("file1.txt")); + + EXPECT_TRUE(pathExists("dir1")); + EXPECT_TRUE(isDirectory("dir1")); + EXPECT_FALSE(isFile("dir1")); + + EXPECT_TRUE(pathExists("dir1/file2.txt")); + EXPECT_TRUE(isFile("dir1/file2.txt")); + EXPECT_FALSE(isDirectory("dir1/file2.txt")); + + EXPECT_FALSE(pathExists("file2.txt")); + EXPECT_FALSE(isFile("file2.txt")); + EXPECT_FALSE(isDirectory("file2.txt")); + + auto temp2 = tempDirectory(); + EXPECT_TRUE(pathExists(temp2)); + EXPECT_TRUE(isDirectory(temp2)); +} + +/* ************************************************************************ */ + +TEST(FilePath, cwd) +{ + const auto cwd = FilePath::getCurrent(); + EXPECT_TRUE(FilePath::exists(cwd)); + + FilePath::setCurrent(cwd / "dir1"); + const auto cwd2 = FilePath::getCurrent(); + EXPECT_TRUE(FilePath::exists(cwd2)); + EXPECT_EQ(cwd / "dir1", cwd2); + + // Reset working directory + FilePath::setCurrent(cwd); +} + +/* ************************************************************************ */ + +TEST(FilePath, openDirectory) +{ + { + ASSERT_FALSE(FilePath::exists("non-existent-directory")); + auto items = FilePath::openDirectory("non-existent-directory"); + EXPECT_EQ(0, items.size()); + } + + { + ASSERT_TRUE(FilePath::exists("dir1")); + auto items = FilePath::openDirectory("dir1"); + ASSERT_EQ(2, items.size()); + + // Files can be returned in any order, we need to sort them + std::sort(items.begin(), items.end(), [](const FilePath& lhs, const FilePath& rhs) { + return lhs.toString() < rhs.toString(); + }); + + EXPECT_EQ("dir1/file2.txt", items[0]); + EXPECT_EQ("dir1/file3.txt", items[1]); + } +} + +/* ************************************************************************ */ + +TEST(FilePath, inout) +{ + const FilePath in("dir1/dir2/file1"); + FilePath out; + + StringStream ss; + ss << in; + ss >> out; + + EXPECT_EQ(in, out); +} + +/* ************************************************************************ */ diff --git a/unittests/lang/CMakeLists.txt b/unittests/lang/CMakeLists.txt new file mode 100644 index 0000000..c453b59 --- /dev/null +++ b/unittests/lang/CMakeLists.txt @@ -0,0 +1,32 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(lang + SOURCES + ExpressionParserTest.cpp + TokenizerTest.cpp +) + +# ######################################################################### # diff --git a/cece/core/test/ExpressionParserTest.cpp b/unittests/lang/ExpressionParserTest.cpp similarity index 94% rename from cece/core/test/ExpressionParserTest.cpp rename to unittests/lang/ExpressionParserTest.cpp index 931e8a3..2945854 100644 --- a/cece/core/test/ExpressionParserTest.cpp +++ b/unittests/lang/ExpressionParserTest.cpp @@ -24,16 +24,17 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/IteratorRange.hpp" -#include "cece/core/ExpressionParser.hpp" -#include "cece/core/constants.hpp" +#include "cece/IteratorRange.hpp" +#include "cece/math/constants.hpp" +#include "cece/lang/ExpressionParser.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::lang; /* ************************************************************************ */ @@ -48,8 +49,8 @@ TEST(ExpressionParser, basic) EXPECT_FLOAT_EQ(-3.f, parseExpression("3 * (1 - 2)")); EXPECT_FLOAT_EQ(13.f, parseExpression("2 * 5 + 3")); EXPECT_FLOAT_EQ(11.f, parseExpression("5 + 2 * 3")); - EXPECT_FLOAT_EQ(constants::PI, parseExpression("pi")); - EXPECT_FLOAT_EQ(constants::E, parseExpression("e")); + EXPECT_FLOAT_EQ(math::PI, parseExpression("pi")); + EXPECT_FLOAT_EQ(math::E, parseExpression("e")); } /* ************************************************************************ */ diff --git a/cece/core/test/TokenizerTest.cpp b/unittests/lang/TokenizerTest.cpp similarity index 97% rename from cece/core/test/TokenizerTest.cpp rename to unittests/lang/TokenizerTest.cpp index 32294ad..b2758d2 100644 --- a/cece/core/test/TokenizerTest.cpp +++ b/unittests/lang/TokenizerTest.cpp @@ -23,20 +23,21 @@ /* */ /* ************************************************************************ */ -// GTest -#include - // C++ #include +// GTest +#include "gtest/gtest.h" + // CeCe -#include "cece/core/Assert.hpp" -#include "cece/core/String.hpp" -#include "cece/core/Tokenizer.hpp" +#include "cece/Assert.hpp" +#include "cece/String.hpp" +#include "cece/lang/Tokenizer.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::lang; /* ************************************************************************ */ diff --git a/unittests/log/CMakeLists.txt b/unittests/log/CMakeLists.txt new file mode 100644 index 0000000..11773e1 --- /dev/null +++ b/unittests/log/CMakeLists.txt @@ -0,0 +1,36 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(log + SOURCES + OutputTest.cpp + StreamOutputTest.cpp + FileOutputTest.cpp + StdOutputTest.cpp + LoggerTest.cpp + LogTest.cpp +) + +# ######################################################################### # diff --git a/unittests/log/FileOutputTest.cpp b/unittests/log/FileOutputTest.cpp new file mode 100644 index 0000000..4b92a2a --- /dev/null +++ b/unittests/log/FileOutputTest.cpp @@ -0,0 +1,187 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// C++ +#include +#include + +// CeCe +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/Exception.hpp" +#include "cece/io/FilePath.hpp" +#include "cece/io/FileStream.hpp" +#include "cece/log/FileOutput.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::log; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +String readfile(io::FilePath path) +{ + io::InFileStream file(path.toString()); + + return String( + std::istreambuf_iterator(file), + std::istreambuf_iterator() + ); +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(FileOutput, invalidFile) +{ + EXPECT_THROW(FileOutput("/invalid directory/test.log"), InvalidArgumentException); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write0) +{ + FileOutput output("write0.log"); + output.write(Severity::Default, {}, "Default message"); + + EXPECT_EQ("Default message\n", readfile("write0.log")); + remove("write0.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write1) +{ + FileOutput output("write1.log"); + output.write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", readfile("write1.log")); + remove("write1.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write2) +{ + FileOutput output("write2.log"); + output.write(Severity::Error, {}, "Error message"); + + EXPECT_EQ("[ERROR] Error message\n", readfile("write2.log")); + remove("write2.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write3) +{ + FileOutput output("write3.log"); + output.write(Severity::Debug, "section", "Debug message"); + + EXPECT_EQ("[DEBUG] [section] Debug message\n", readfile("write3.log")); + remove("write3.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write4) +{ + FileOutput output("write4.log"); + output.write(Severity::Warning, "important", "Warning message"); + + EXPECT_EQ("[WARN] [important] Warning message\n", readfile("write4.log")); + remove("write4.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write5) +{ + UniquePtr output = makeUnique("write5.log"); + output->write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", readfile("write5.log")); + remove("write5.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, write6) +{ + UniquePtr output = makeUnique("write6.log"); + output->write(Severity::Info, {}, "Info message"); + output->write(Severity::Warning, {}, "Warning message"); + output->write(Severity::Error, {}, "Error message"); + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n" + "[ERROR] Error message\n", + readfile("write6.log") + ); + + remove("write6.log"); +} + +/* ************************************************************************ */ + +TEST(FileOutput, append) +{ + { + FileOutput output("append.log"); + output.write(Severity::Info, {}, "Info message"); + } + + { + FileOutput output("append.log"); + output.write(Severity::Warning, {}, "Warning message"); + } + + { + FileOutput output("append.log"); + output.write(Severity::Error, {}, "Error message"); + } + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n" + "[ERROR] Error message\n", + readfile("append.log") + ); + + remove("append.log"); +} + +/* ************************************************************************ */ diff --git a/unittests/log/LogTest.cpp b/unittests/log/LogTest.cpp new file mode 100644 index 0000000..fa4507d --- /dev/null +++ b/unittests/log/LogTest.cpp @@ -0,0 +1,153 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// C++ +#ifndef _WIN32 +#include +#include +#endif + +// CeCe +#include "cece/String.hpp" +#include "cece/log/Log.hpp" + +/* ************************************************************************ */ + +using namespace cece; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Strips Linux color codes. + * + * @param[in] str The string + * + * @return str without color codes. + */ +String stripcolor(String str) +{ +#ifndef _WIN32 + // \x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK] + String res; + + std::regex re("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]"); + std::regex_replace(std::back_inserter(res), str.begin(), str.end(), re, ""); + + return res; +#else + return str; +#endif +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(Log, write0) +{ + testing::internal::CaptureStdout(); + + log::msg("Default message"); + + EXPECT_EQ("Default message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(Log, write1) +{ + testing::internal::CaptureStdout(); + + log::info("Info message"); + + EXPECT_EQ("[INFO] Info message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(Log, write2) +{ + testing::internal::CaptureStderr(); + + log::error("Error message"); + + EXPECT_EQ("[ERROR] Error message\n", stripcolor(testing::internal::GetCapturedStderr())); +} + +/* ************************************************************************ */ + +TEST(Log, write3) +{ + testing::internal::CaptureStdout(); + + log::debugS("section", "Debug message"); + + EXPECT_EQ("[DEBUG] [section] Debug message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(Log, write4) +{ + testing::internal::CaptureStdout(); + + log::warningS("important", "Warning message"); + + EXPECT_EQ("[WARN] [important] Warning message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(Log, write5) +{ + testing::internal::CaptureStdout(); + testing::internal::CaptureStderr(); + + log::info("Info message"); + log::warning("Warning message"); + log::error("Error message"); + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n", + stripcolor(testing::internal::GetCapturedStdout()) + ); + + EXPECT_EQ( + "[ERROR] Error message\n", + stripcolor(testing::internal::GetCapturedStderr()) + ); +} + +/* ************************************************************************ */ diff --git a/unittests/log/LoggerTest.cpp b/unittests/log/LoggerTest.cpp new file mode 100644 index 0000000..08f36f7 --- /dev/null +++ b/unittests/log/LoggerTest.cpp @@ -0,0 +1,162 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/log/Logger.hpp" +#include "cece/log/StreamOutput.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::log; + +/* ************************************************************************ */ + +TEST(Logger, write0) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.msg("Default message"); + + EXPECT_EQ("Default message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write1) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.info("Info", " message"); + + EXPECT_EQ("[INFO] Info message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write2) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.error("Error ", "message"); + + EXPECT_EQ("[ERROR] Error message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write3) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.debugS("section", "Debug message"); + + EXPECT_EQ("[DEBUG] [section] Debug message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write4) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.warningS("important", "Warning message"); + + EXPECT_EQ("[WARN] [important] Warning message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write5) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.info("Info message"); + + EXPECT_EQ("[INFO] Info message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, write6) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.info("Info message"); + logger.warning("Warning message"); + logger.error("Error message"); + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n" + "[ERROR] Error message\n", + stream.str() + ); +} + +/* ************************************************************************ */ + +TEST(Logger, merge) +{ + io::OutStringStream stream; + + Logger logger(makeUnique(stream)); + logger.info("Result = ", 10, "ms"); + + EXPECT_EQ("[INFO] Result = 10ms\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(Logger, output) +{ + io::OutStringStream stream; + + auto output1 = makeUnique(stream); + auto output1View = makeView(output1); + + Logger logger(std::move(output1)); + EXPECT_EQ(output1View, logger.getOutput()); + + auto output2 = makeUnique(stream); + auto output2View = makeView(output2); + + logger.setOutput(std::move(output2)); + EXPECT_EQ(output2View, logger.getOutput()); +} + +/* ************************************************************************ */ diff --git a/unittests/log/OutputTest.cpp b/unittests/log/OutputTest.cpp new file mode 100644 index 0000000..ad72981 --- /dev/null +++ b/unittests/log/OutputTest.cpp @@ -0,0 +1,78 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/log/Output.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::log; + +/* ************************************************************************ */ + +struct TestOutput : public Output +{ + int called = 0; + + void write(Severity severity, const String& section, const String& msg) override + { + EXPECT_EQ(Severity::Info, severity); + EXPECT_EQ("", section); + EXPECT_EQ("Message", msg); + + ++called; + } +}; + +/* ************************************************************************ */ + +TEST(Output, write) +{ + TestOutput output; + output.write(Severity::Info, {}, "Message"); + + EXPECT_EQ(1, output.called); +} + +/* ************************************************************************ */ + +TEST(Output, writeAbstract) +{ + UniquePtr output = makeUnique(); + EXPECT_NE(nullptr, output); + output->write(Severity::Info, {}, "Message"); + output->write(Severity::Info, {}, "Message"); + output->write(Severity::Info, {}, "Message"); + + EXPECT_EQ(3, static_cast(output.get())->called); +} + +/* ************************************************************************ */ diff --git a/unittests/log/StdOutputTest.cpp b/unittests/log/StdOutputTest.cpp new file mode 100644 index 0000000..7e079b6 --- /dev/null +++ b/unittests/log/StdOutputTest.cpp @@ -0,0 +1,173 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// C++ +#ifndef _WIN32 +#include +#include +#endif + +// CeCe +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/log/StdOutput.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::log; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +/** + * @brief Strips Linux color codes. + * + * @param[in] str The string + * + * @return str without color codes. + */ +String stripcolor(String str) +{ +#ifndef _WIN32 + // \x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK] + String res; + + std::regex re("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]"); + std::regex_replace(std::back_inserter(res), str.begin(), str.end(), re, ""); + + return res; +#else + return str; +#endif +} + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(StdOutput, write0) +{ + testing::internal::CaptureStdout(); + + StdOutput output; + output.write(Severity::Default, {}, "Default message"); + + EXPECT_EQ("Default message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write1) +{ + testing::internal::CaptureStdout(); + + StdOutput output; + output.write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write2) +{ + testing::internal::CaptureStderr(); + + StdOutput output; + output.write(Severity::Error, {}, "Error message"); + + EXPECT_EQ("[ERROR] Error message\n", stripcolor(testing::internal::GetCapturedStderr())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write3) +{ + testing::internal::CaptureStdout(); + + StdOutput output; + output.write(Severity::Debug, "section", "Debug message"); + + EXPECT_EQ("[DEBUG] [section] Debug message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write4) +{ + testing::internal::CaptureStdout(); + + StdOutput output; + output.write(Severity::Warning, "important", "Warning message"); + + EXPECT_EQ("[WARN] [important] Warning message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write5) +{ + testing::internal::CaptureStdout(); + + UniquePtr output = makeUnique(); + output->write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", stripcolor(testing::internal::GetCapturedStdout())); +} + +/* ************************************************************************ */ + +TEST(StdOutput, write6) +{ + testing::internal::CaptureStdout(); + testing::internal::CaptureStderr(); + + UniquePtr output = makeUnique(); + output->write(Severity::Info, {}, "Info message"); + output->write(Severity::Warning, {}, "Warning message"); + output->write(Severity::Error, {}, "Error message"); + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n", + stripcolor(testing::internal::GetCapturedStdout()) + ); + + EXPECT_EQ( + "[ERROR] Error message\n", + stripcolor(testing::internal::GetCapturedStderr()) + ); +} + +/* ************************************************************************ */ diff --git a/unittests/log/StreamOutputTest.cpp b/unittests/log/StreamOutputTest.cpp new file mode 100644 index 0000000..262588e --- /dev/null +++ b/unittests/log/StreamOutputTest.cpp @@ -0,0 +1,131 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/String.hpp" +#include "cece/UniquePtr.hpp" +#include "cece/io/StringStream.hpp" +#include "cece/log/StreamOutput.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::log; + +/* ************************************************************************ */ + +TEST(StreamOutput, write0) +{ + io::OutStringStream stream; + + StreamOutput output(stream); + output.write(Severity::Default, {}, "Default message"); + + EXPECT_EQ("Default message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write1) +{ + io::OutStringStream stream; + + StreamOutput output(stream); + output.write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write2) +{ + io::OutStringStream stream; + + StreamOutput output(stream); + output.write(Severity::Error, {}, "Error message"); + + EXPECT_EQ("[ERROR] Error message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write3) +{ + io::OutStringStream stream; + + StreamOutput output(stream); + output.write(Severity::Debug, "section", "Debug message"); + + EXPECT_EQ("[DEBUG] [section] Debug message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write4) +{ + io::OutStringStream stream; + + StreamOutput output(stream); + output.write(Severity::Warning, "important", "Warning message"); + + EXPECT_EQ("[WARN] [important] Warning message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write5) +{ + io::OutStringStream stream; + + UniquePtr output = makeUnique(stream); + output->write(Severity::Info, {}, "Info message"); + + EXPECT_EQ("[INFO] Info message\n", stream.str()); +} + +/* ************************************************************************ */ + +TEST(StreamOutput, write6) +{ + io::OutStringStream stream; + + UniquePtr output = makeUnique(stream); + output->write(Severity::Info, {}, "Info message"); + output->write(Severity::Warning, {}, "Warning message"); + output->write(Severity::Error, {}, "Error message"); + + EXPECT_EQ( + "[INFO] Info message\n" + "[WARN] Warning message\n" + "[ERROR] Error message\n", + stream.str() + ); +} + +/* ************************************************************************ */ diff --git a/unittests/math/CMakeLists.txt b/unittests/math/CMakeLists.txt new file mode 100644 index 0000000..03f6f4e --- /dev/null +++ b/unittests/math/CMakeLists.txt @@ -0,0 +1,31 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(core + SOURCES + VectorRangeTest.cpp +) + +# ######################################################################### # diff --git a/cece/core/test/VectorRangeTest.cpp b/unittests/math/VectorRangeTest.cpp similarity index 97% rename from cece/core/test/VectorRangeTest.cpp rename to unittests/math/VectorRangeTest.cpp index f0770bf..c6f75e8 100644 --- a/cece/core/test/VectorRangeTest.cpp +++ b/unittests/math/VectorRangeTest.cpp @@ -24,15 +24,16 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/VectorRange.hpp" -#include "cece/core/Vector.hpp" +#include "cece/math/Vector.hpp" +#include "cece/math/VectorRange.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::math; /* ************************************************************************ */ diff --git a/unittests/os/CMakeLists.txt b/unittests/os/CMakeLists.txt new file mode 100644 index 0000000..f609b59 --- /dev/null +++ b/unittests/os/CMakeLists.txt @@ -0,0 +1,61 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(os + SOURCES + SharedLibraryTest.cpp +) + +# ######################################################################### # + +## +## Helper function which build a test plugin. +## +function (add_test_library NAME SOURCE) + if (CECE_BUILD_TESTS) + return () + endif () + + set(FULLNAME ${NAME}) + + # Test plugin + add_library(${FULLNAME} SHARED + libraries/${SOURCE} + ) + + # Properties + set_target_properties(${FULLNAME} PROPERTIES + CXX_STANDARD 11 + CXX_EXTENSIONS Off + CXX_STANDARD_REQUIRED On + ) +endfunction () + +# ######################################################################### # + +# Test libraries +add_test_library(library1 Library1.cpp) + +# ######################################################################### # diff --git a/unittests/os/SharedLibraryTest.cpp b/unittests/os/SharedLibraryTest.cpp new file mode 100644 index 0000000..01868d7 --- /dev/null +++ b/unittests/os/SharedLibraryTest.cpp @@ -0,0 +1,120 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/os/SharedLibrary.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::os; +using namespace cece::io; + +/* ************************************************************************ */ + +TEST(SharedLibrary, formatName) +{ + EXPECT_EQ(SharedLibrary::PREFIX + "mylib" + SharedLibrary::EXTENSION, SharedLibrary::formatName("mylib")); +} + +/* ************************************************************************ */ + +TEST(SharedLibrary, ctor) +{ + ASSERT_PRED1(FilePath::exists, os::SharedLibrary::formatName("library1")); + ASSERT_PRED1(FilePath::exists, FilePath::getCurrent() / os::SharedLibrary::formatName("library1")); + + // Default + { + SharedLibrary lib; + EXPECT_FALSE(lib.isOpen()); + } + + // With path + { + SharedLibrary lib(FilePath::getCurrent() / SharedLibrary::formatName("library1")); + EXPECT_TRUE(lib.isOpen()); + } + + // Move + { + SharedLibrary lib(FilePath::getCurrent() / SharedLibrary::formatName("library1")); + EXPECT_TRUE(lib.isOpen()); + + SharedLibrary lib2(std::move(lib)); + EXPECT_TRUE(lib2.isOpen()); + + EXPECT_FALSE(lib.isOpen()); + } + + // Assignment + { + SharedLibrary lib; + EXPECT_FALSE(lib.isOpen()); + + lib = SharedLibrary(FilePath::getCurrent() / SharedLibrary::formatName("library1")); + EXPECT_TRUE(lib.isOpen()); + } + + // Move Assignment + { + SharedLibrary lib; + EXPECT_FALSE(lib.isOpen()); + + SharedLibrary lib2(FilePath::getCurrent() / SharedLibrary::formatName("library1")); + EXPECT_TRUE(lib2.isOpen()); + + lib = std::move(lib2); + EXPECT_TRUE(lib.isOpen()); + EXPECT_FALSE(lib2.isOpen()); + } +} + +/* ************************************************************************ */ + +TEST(SharedLibrary, open) +{ + SharedLibrary lib; + EXPECT_FALSE(lib.isOpen()); + + ASSERT_PRED1(FilePath::exists, os::SharedLibrary::formatName("library1")); + ASSERT_PRED1(FilePath::exists, FilePath::getCurrent() / os::SharedLibrary::formatName("library1")); + + ASSERT_NO_THROW(lib = SharedLibrary(FilePath::getCurrent() / SharedLibrary::formatName("library1"))); + ASSERT_TRUE(lib.isOpen()); + EXPECT_EQ((FilePath::getCurrent() / SharedLibrary::formatName("library1")).toString(), lib.getPath().toString()); + + // Get symbol + auto identity = lib.getAddr("identity"); + ASSERT_NE(nullptr, identity); + EXPECT_EQ(100, identity(100)); + + EXPECT_EQ(nullptr, lib.getAddr("other")); +} + +/* ************************************************************************ */ diff --git a/unittests/os/libraries/Library1.cpp b/unittests/os/libraries/Library1.cpp new file mode 100644 index 0000000..caa21ac --- /dev/null +++ b/unittests/os/libraries/Library1.cpp @@ -0,0 +1,39 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +#ifdef _WIN32 +# define EXPORT __declspec(dllexport) +#else +# define EXPORT +#endif + +/* ************************************************************************ */ + +extern "C" EXPORT int identity(int x) +{ + return x; +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/ApiTest.cpp b/unittests/plugin/ApiTest.cpp new file mode 100644 index 0000000..4e71990 --- /dev/null +++ b/unittests/plugin/ApiTest.cpp @@ -0,0 +1,190 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/ViewPtr.hpp" +#include "cece/plugin/Api.hpp" + +/* ************************************************************************ */ + +// We don't need access to those objects, just define forward declaration +namespace cece { namespace config { class Configuration; } } +namespace cece { namespace plugin { class Repository; } } +namespace cece { namespace simulation { class Simulation; } } + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +class DummyApi final : public Api {}; + +/* ************************************************************************ */ + +class TestApi final : public Api +{ + +// Public Operations +public: + + + /** + * @brief When the plugin is loaded by plugin manager. + * + * @param repository Repository record for the plugin. + */ + void onLoad(RepositoryRecord& repository) override + { + onLoadCalled = true; + } + + + /** + * @brief When the plugin is unloaded from plugin manager. + * + * @param repository Repository record for the plugin. + */ + void onUnload(RepositoryRecord& repository) override + { + onUnloadCalled = true; + } + + + /** + * @brief When the plugin is imported into simulation. + * + * @param simulation The simulation which imports the plugin. + * @param[in] config Plugin import configuration. + */ + void onImport(simulation::Simulation& simulation, const config::Configuration& config) override + { + onImportCalled = true; + } + + + /** + * @brief When the plugin is being removed from the simulation. + * + * @param simulation The simulation. + */ + void onRemove(simulation::Simulation& simulation) override + { + onRemoveCalled = true; + } + + + /** + * @brief Store plugin configuration. + * + * @param simulation Current simulation. + * @param config Plugin configuration. + */ + void storeConfig(const simulation::Simulation& simulation, config::Configuration& config) const override + { + storeConfigCalled = true; + } + + +// Public Data Members +public: + + mutable bool onLoadCalled = false; + mutable bool onUnloadCalled = false; + mutable bool onImportCalled = false; + mutable bool onRemoveCalled = false; + mutable bool storeConfigCalled = false; +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(Api, dummy) +{ + // Api with no override can be used + auto api = makeUnique(); + + // No access to those objects, just for passing references to the functions. + RepositoryRecord* record = nullptr; + config::Configuration* config = nullptr; + simulation::Simulation* sim = nullptr; + + api->onLoad(*record); + api->onUnload(*record); + api->onImport(*sim, *config); + api->onRemove(*sim); + api->storeConfig(*sim, *config); +} + +/* ************************************************************************ */ + +TEST(Api, virtualFunctions) +{ + auto api = makeUnique(); + ViewPtr base = api; + + ASSERT_NE(api, nullptr); + ASSERT_NE(base, nullptr); + ASSERT_EQ(base, api); + + // No access to those objects, just for passing references to the functions. + RepositoryRecord* record = nullptr; + config::Configuration* config = nullptr; + simulation::Simulation* sim = nullptr; + + EXPECT_FALSE(api->onLoadCalled); + base->onLoad(*record); + EXPECT_TRUE(api->onLoadCalled); + + EXPECT_FALSE(api->onUnloadCalled); + base->onUnload(*record); + EXPECT_TRUE(api->onUnloadCalled); + + EXPECT_FALSE(api->onImportCalled); + base->onImport(*sim, *config); + EXPECT_TRUE(api->onImportCalled); + + EXPECT_FALSE(api->onRemoveCalled); + base->onRemove(*sim); + EXPECT_TRUE(api->onRemoveCalled); + + EXPECT_FALSE(api->storeConfigCalled); + base->storeConfig(*sim, *config); + EXPECT_TRUE(api->storeConfigCalled); + +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/CMakeLists.txt b/unittests/plugin/CMakeLists.txt new file mode 100644 index 0000000..f7a7b8e --- /dev/null +++ b/unittests/plugin/CMakeLists.txt @@ -0,0 +1,91 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(plugin + SOURCES + ApiTest.cpp + PluginTest.cpp + RepositoryRecordTest.cpp + RepositoryTest.cpp + ManagerTest.cpp + ContextTest.cpp +) + +# ######################################################################### # + +## +## Helper function which build a test plugin. +## +function (add_test_plugin NAME SOURCE) + if (CECE_BUILD_TESTS) + return () + endif () + + set(FULLNAME cece-${NAME}) + + # Test plugin + add_library(${FULLNAME} SHARED + plugins/${SOURCE} + ) + + # Link dependency + target_link_libraries(${FULLNAME} + cece + ) + + # Properties + set_target_properties(${FULLNAME} PROPERTIES + CXX_STANDARD 11 + CXX_EXTENSIONS Off + CXX_STANDARD_REQUIRED On + ) + + target_include_directories(${FULLNAME} + PRIVATE ${CMAKE_SOURCE_DIR} + PRIVATE ${CMAKE_BINARY_DIR} + ) +endfunction () + +# ######################################################################### # + +# Test plugin +add_test_plugin(different-real-plugin DifferentRealPlugin.cpp) +add_test_plugin(invalid-plugin InvalidPlugin.cpp) +add_test_plugin(no-config-plugin NoConfigPlugin.cpp) +add_test_plugin(no-create-plugin NoCreatePlugin.cpp) +add_test_plugin(not-render-plugin NotRenderPlugin.cpp) +add_test_plugin(not-thread-safe-plugin NotThreadSafePlugin.cpp) +add_test_plugin(old-plugin OldPlugin.cpp) +add_test_plugin(test-plugin TestPlugin.cpp) + +file(GENERATE OUTPUT "$/${CMAKE_SHARED_LIBRARY_PREFIX}cece-python-plugin.py" + CONTENT "print('Hello')\n" +) + +file(GENERATE OUTPUT "$/${CMAKE_SHARED_LIBRARY_PREFIX}cece-no-shared-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}" + CONTENT "I'm no shared library\n" +) + +# ######################################################################### # diff --git a/unittests/plugin/ContextTest.cpp b/unittests/plugin/ContextTest.cpp new file mode 100644 index 0000000..850d1f5 --- /dev/null +++ b/unittests/plugin/ContextTest.cpp @@ -0,0 +1,263 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/plugin/Api.hpp" +#include "cece/plugin/Context.hpp" +#include "cece/plugin/Manager.hpp" +#include "cece/plugin/SharedLibraryLoader.hpp" +#include "cece/plugin/Exception.hpp" +#include "cece/simulation/Loader.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/simulation/DefaultSimulation.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +class TestLoader final : public simulation::Loader +{ +public: + + UniquePtr fromStream(const plugin::Manager& manager, io::InStream& is, + const io::FilePath& filename = "", + ViewPtr parameters = nullptr) const override + { + return makeUnique(manager, filename); + } + + void toStream(io::OutStream& os, const simulation::Simulation& simulation, + const io::FilePath& filename = "") const override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestInitializer final : public simulation::Initializer +{ +public: + using simulation::Initializer::Initializer; + + void init(simulation::Simulation& simulation) const override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestModule final : public simulation::Module +{ +public: + using simulation::Module::Module; +}; + +/* ************************************************************************ */ + +class TestObject final : public simulation::Object +{ +public: + using simulation::Object::Object; +}; + +/* ************************************************************************ */ + +class TestProgram final : public simulation::Program +{ +public: + using simulation::Program::Program; + + UniquePtr clone() const override + { + return makeUnique(*this); + } + + void call(simulation::Simulation& simulation, simulation::Object& object, unit::Time dt) override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestApi0 : public Api +{ + void onLoad(RepositoryRecord& repository) override + { + repository + .registerLoader("loader") + .registerInitializer("initializer") + .registerModule("module") + .registerObject("object") + .registerProgram("program") + ; + } +}; + +/* ************************************************************************ */ + +class TestApi1 : public Api +{ + void onLoad(RepositoryRecord& repository) override + { + repository.registerInitializer("initializer"); + } +}; + +/* ************************************************************************ */ + +class TestApi2 : public Api +{ + void onLoad(RepositoryRecord& repository) override + { + repository + .registerInitializer("initializer") + .registerInitializer("initializer2") + ; + } +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(Context, ctor) +{ + Manager mgr; + Context ctx(mgr); + + EXPECT_EQ(&mgr.getRepository(), &ctx.getRepository()); +} + +/* ************************************************************************ */ + +TEST(Context, import) +{ + Manager mgr; + + // Use shared library loader + mgr.addLoader(makeUnique()); + mgr.addDirectory("."); + + Context ctx(mgr); + + EXPECT_NO_THROW(ctx.importPlugin("test-plugin")); + EXPECT_THROW(ctx.importPlugin("old-plugin"), PluginNotFoundException); + + EXPECT_TRUE(ctx.isImported("test-plugin")); + EXPECT_FALSE(ctx.isImported("old-plugin")); + + EXPECT_NO_THROW(ctx.createInitializer("initializer")); + + ctx.removePlugin("test-plugin"); + EXPECT_FALSE(ctx.isImported("test-plugin")); + + // Import twice + EXPECT_NO_THROW(ctx.importPlugin("test-plugin")); + EXPECT_TRUE(ctx.isImported("test-plugin")); + EXPECT_NO_THROW(ctx.importPlugin("test-plugin")); + EXPECT_TRUE(ctx.isImported("test-plugin")); + + // Remove multiple time + EXPECT_NO_THROW(ctx.removePlugin("test-plugin")); + EXPECT_FALSE(ctx.isImported("test-plugin")); + EXPECT_NO_THROW(ctx.removePlugin("test-plugin")); + EXPECT_FALSE(ctx.isImported("test-plugin")); + EXPECT_NO_THROW(ctx.removePlugin("test-plugin")); + EXPECT_FALSE(ctx.isImported("test-plugin")); +} + +/* ************************************************************************ */ + +TEST(Context, ambiguous) +{ + Manager mgr; + mgr.addPlugin(Plugin{"plugin1", makeUnique()}); + mgr.addPlugin(Plugin{"plugin2", makeUnique()}); + + Context ctx(mgr); + ctx.importPlugin("plugin1"); + ctx.importPlugin("plugin2"); + + EXPECT_THROW(ctx.createInitializer("initializer"), MultipleExtensionsException); + EXPECT_NO_THROW(ctx.createInitializer("initializer2")); +} + +/* ************************************************************************ */ + +TEST(Context, not_imported) +{ + Manager mgr; + mgr.addPlugin(Plugin{"plugin1", makeUnique()}); + mgr.addPlugin(Plugin{"plugin2", makeUnique()}); + + Context ctx(mgr); + + EXPECT_THROW(ctx.createInitializer("initializer"), ExtensionNotFoundException); +} + +/* ************************************************************************ */ + +TEST(Context, create) +{ + Manager mgr; + mgr.addPlugin(Plugin{"plugin", makeUnique()}); + + Context ctx(mgr); + ctx.importPlugin("plugin"); + + simulation::DefaultSimulation simulation(mgr); + + EXPECT_NO_THROW(ctx.createLoader("loader")); + EXPECT_NO_THROW(ctx.createInitializer("initializer")); + EXPECT_NO_THROW(ctx.createModule("module", simulation)); + EXPECT_NO_THROW(ctx.createObject("object", simulation, simulation::Object::Type::Static)); + EXPECT_NO_THROW(ctx.createProgram("program")); + + EXPECT_THROW(ctx.createLoader("loader0"), ExtensionNotFoundException); + EXPECT_THROW(ctx.createInitializer("initializer0"), ExtensionNotFoundException); + EXPECT_THROW(ctx.createModule("module0", simulation), ExtensionNotFoundException); + EXPECT_THROW(ctx.createObject("object0", simulation, simulation::Object::Type::Static), ExtensionNotFoundException); + EXPECT_THROW(ctx.createProgram("program0"), ExtensionNotFoundException); +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/ManagerTest.cpp b/unittests/plugin/ManagerTest.cpp new file mode 100644 index 0000000..7cf955e --- /dev/null +++ b/unittests/plugin/ManagerTest.cpp @@ -0,0 +1,201 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/io/FilePath.hpp" +#include "cece/plugin/Manager.hpp" +#include "cece/plugin/SharedLibraryLoader.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::io; +using namespace cece::plugin; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +class TestLoader : public Loader +{ +public: + + int getCalled() const noexcept + { + return m_called; + } + + DynamicArray loadAll(const FilePath& directory) + { + ++m_called; + + return {}; + } + +private: + + int m_called = 0; +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(Manager, directories) +{ + Manager mgr; + + mgr.addDirectory("."); + mgr.addDirectory("plugins"); + + EXPECT_EQ(2, mgr.getDirectories().size()); + + mgr.addDirectories({"/home/cece/.cece/plugins", "/home/cece/.cece/python-plugins"}); + + EXPECT_EQ(4, mgr.getDirectories().size()); +} + +/* ************************************************************************ */ + +TEST(Manager, load) +{ + Manager mgr; + + // Use shared library loader + mgr.addLoader(makeUnique()); + mgr.addDirectory("."); + + // Loader should be able to handle non-existent directory without crash + EXPECT_NO_THROW(mgr.addDirectory("non-existent-directory")); + + ASSERT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-test-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-invalid-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-old-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-no-config-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-no-create-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-not-render-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-different-real-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::formatName("cece-no-shared-plugin")); + EXPECT_PRED1(FilePath::exists, os::SharedLibrary::PREFIX + "cece-python-plugin.py"); + + // Plugins should be loaded + EXPECT_TRUE(mgr.isLoaded("test-plugin")); + EXPECT_FALSE(mgr.isLoaded("invalid-plugin")); + EXPECT_FALSE(mgr.isLoaded("old-plugin")); + EXPECT_FALSE(mgr.isLoaded("no-config-plugin")); + EXPECT_FALSE(mgr.isLoaded("no-create-plugin")); + EXPECT_FALSE(mgr.isLoaded("different-real-plugin")); + EXPECT_FALSE(mgr.isLoaded("not-render-plugin")); + EXPECT_FALSE(mgr.isLoaded("not-thread-safe-plugin")); + EXPECT_FALSE(mgr.isLoaded("no-shared-plugin")); + EXPECT_FALSE(mgr.isLoaded("python-plugin")); + + // Only one plugin loaded + EXPECT_EQ(1, mgr.getNames().size()); + EXPECT_EQ("test-plugin", mgr.getNames()[0]); + + // Load test plugin + auto api = mgr.getApi("test-plugin"); + ASSERT_NE(nullptr, api); + + // Test plugin should add some testing classes to repository + ASSERT_TRUE(mgr.getRepository().exists("test-plugin")); + + // Get record + const RepositoryRecord* record; + ASSERT_NO_THROW({ + record = &mgr.getRepository().get("test-plugin"); + }); + + EXPECT_TRUE(record->isRegisteredInitializer("initializer")); + EXPECT_FALSE(record->isRegisteredInitializer("init")); + EXPECT_TRUE(record->isRegisteredModule("module")); + EXPECT_TRUE(record->isRegisteredObject("object")); + EXPECT_TRUE(record->isRegisteredProgram("program")); + + // Plugin cannot be loaded - missing functions + EXPECT_EQ(nullptr, mgr.getApi("invalid-plugin")); + + // Plugin cannot be loaded - old API + EXPECT_EQ(nullptr, mgr.getApi("old-plugin")); + + // Plugin cannot be loaded - missing config + EXPECT_EQ(nullptr, mgr.getApi("no-config-plugin")); + + // Plugin cannot be loaded - missing create + EXPECT_EQ(nullptr, mgr.getApi("no-create-plugin")); +} + +/* ************************************************************************ */ + +TEST(Manager, invoke1) +{ + Manager mgr; + + ASSERT_EQ(0, mgr.getLoaders().size()); + + // Add directory + mgr.addDirectory("."); + mgr.addDirectory("test"); + + // When a loader is added it's invoked with current directories + mgr.addLoader(makeUnique()); + + //ASSERT_EQ(1, mgr.getLoaders().size()); + const auto& loader = static_cast(mgr.getLoaders()[0].get()); + + EXPECT_EQ(2, loader->getCalled()); +} + +/* ************************************************************************ */ + +TEST(Manager, invoke2) +{ + Manager mgr; + + ASSERT_EQ(0, mgr.getLoaders().size()); + + // New loader + mgr.addLoader(makeUnique()); + + ASSERT_EQ(1, mgr.getLoaders().size()); + const auto& loader = static_cast(mgr.getLoaders()[0].get()); + + // When directory is added it's invoked for all current loaders. + mgr.addDirectory("."); + mgr.addDirectory("test"); + mgr.addDirectory("test2"); + + EXPECT_EQ(3, loader->getCalled()); +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/PluginTest.cpp b/unittests/plugin/PluginTest.cpp new file mode 100644 index 0000000..b362399 --- /dev/null +++ b/unittests/plugin/PluginTest.cpp @@ -0,0 +1,54 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/plugin/Plugin.hpp" +#include "cece/plugin/Api.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +class TestApi final : public Api {}; + +/* ************************************************************************ */ + +TEST(Plugin, accessors) +{ + { + Plugin plugin("plugin1", makeUnique()); + + EXPECT_EQ("plugin1", plugin.getName()); + EXPECT_NE(nullptr, plugin.getApi()); + } +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/RepositoryRecordTest.cpp b/unittests/plugin/RepositoryRecordTest.cpp new file mode 100644 index 0000000..a562099 --- /dev/null +++ b/unittests/plugin/RepositoryRecordTest.cpp @@ -0,0 +1,230 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/plugin/RepositoryRecord.hpp" +#include "cece/simulation/Loader.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/simulation/DefaultSimulation.hpp" +#include "cece/plugin/Repository.hpp" +#include "cece/plugin/Manager.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +class TestLoader final : public simulation::Loader +{ +public: + + UniquePtr fromStream(const plugin::Manager& manager, io::InStream& is, + const io::FilePath& filename = "", + ViewPtr parameters = nullptr) const override + { + return makeUnique(manager, filename); + } + + void toStream(io::OutStream& os, const simulation::Simulation& simulation, + const io::FilePath& filename = "") const override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestInitializer final : public simulation::Initializer +{ +public: + using simulation::Initializer::Initializer; + + void init(simulation::Simulation& simulation) const override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestModule final : public simulation::Module +{ +public: + using simulation::Module::Module; +}; + +/* ************************************************************************ */ + +class TestObject final : public simulation::Object +{ +public: + using simulation::Object::Object; +}; + +/* ************************************************************************ */ + +class TestProgram final : public simulation::Program +{ +public: + using simulation::Program::Program; + + UniquePtr clone() const override + { + return makeUnique(*this); + } + + void call(simulation::Simulation& simulation, simulation::Object& object, unit::Time dt) override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +TEST(RepositoryRecord, loader) +{ + RepositoryRecord record; + + EXPECT_FALSE(record.isRegisteredLoader("loader")); + EXPECT_FALSE(record.isRegisteredLoader("no-loader")); + record.registerLoader("loader"); + EXPECT_TRUE(record.isRegisteredLoader("loader")); + EXPECT_FALSE(record.isRegisteredLoader("no-loader")); + + // Create loader + auto loader = record.createLoader("loader"); + ASSERT_NE(nullptr, loader); + EXPECT_EQ(typeid(TestLoader), typeid(*loader)); + + EXPECT_ANY_THROW({ + record.createLoader("no-loader"); + }); +} + +/* ************************************************************************ */ + +TEST(RepositoryRecord, initializer) +{ + RepositoryRecord record; + + EXPECT_FALSE(record.isRegisteredInitializer("initializer")); + EXPECT_FALSE(record.isRegisteredInitializer("no-initializer")); + record.registerInitializer("initializer"); + EXPECT_TRUE(record.isRegisteredInitializer("initializer")); + EXPECT_FALSE(record.isRegisteredInitializer("no-initializer")); + + auto initializer = record.createInitializer("initializer"); + ASSERT_NE(nullptr, initializer); + EXPECT_EQ(typeid(TestInitializer), typeid(*initializer)); + + EXPECT_ANY_THROW({ + record.createInitializer("no-initializer"); + }); +} + +/* ************************************************************************ */ + +TEST(RepositoryRecord, module) +{ + RepositoryRecord record; + + EXPECT_FALSE(record.isRegisteredModule("module")); + EXPECT_FALSE(record.isRegisteredModule("no-module")); + record.registerModule("module"); + EXPECT_TRUE(record.isRegisteredModule("module")); + EXPECT_FALSE(record.isRegisteredModule("no-module")); + + plugin::Manager mgr; + simulation::DefaultSimulation simulation(mgr); + auto module = record.createModule("module", simulation); + ASSERT_NE(nullptr, module); + EXPECT_EQ(typeid(TestModule), typeid(*module)); + + EXPECT_ANY_THROW({ + record.createModule("no-module", simulation); + }); +} + +/* ************************************************************************ */ + +TEST(RepositoryRecord, object) +{ + RepositoryRecord record; + + EXPECT_FALSE(record.isRegisteredObject("object")); + EXPECT_FALSE(record.isRegisteredObject("no-object")); + record.registerObject("object"); + EXPECT_TRUE(record.isRegisteredObject("object")); + EXPECT_FALSE(record.isRegisteredObject("no-object")); + + plugin::Manager mgr; + simulation::DefaultSimulation simulation(mgr); + auto object = record.createObject("object", simulation, simulation::Object::Type::Static); + ASSERT_NE(nullptr, object); + EXPECT_EQ(typeid(TestObject), typeid(*object)); + + EXPECT_ANY_THROW({ + record.createObject("no-object", simulation, simulation::Object::Type::Static); + }); +} + +/* ************************************************************************ */ + +TEST(RepositoryRecord, program) +{ + RepositoryRecord record; + + EXPECT_FALSE(record.isRegisteredProgram("program")); + EXPECT_FALSE(record.isRegisteredProgram("no-program")); + record.registerProgram("program"); + EXPECT_TRUE(record.isRegisteredProgram("program")); + EXPECT_FALSE(record.isRegisteredProgram("no-program")); + + auto program = record.createProgram("program"); + ASSERT_NE(nullptr, program); + EXPECT_EQ(typeid(TestProgram), typeid(*program)); + + EXPECT_ANY_THROW({ + record.createProgram("no-program"); + }); +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/RepositoryTest.cpp b/unittests/plugin/RepositoryTest.cpp new file mode 100644 index 0000000..cff50b8 --- /dev/null +++ b/unittests/plugin/RepositoryTest.cpp @@ -0,0 +1,90 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/plugin/Repository.hpp" +#include "cece/plugin/Exception.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +TEST(Repository, records) +{ + Repository repo; + const Repository& crepo = repo; + + EXPECT_EQ(0, repo.getRecords().size()); + + auto& record1 = repo.createRecord("record1"); + EXPECT_EQ(1, repo.getRecords().size()); + EXPECT_TRUE(repo.exists("record1")); + EXPECT_FALSE(repo.exists("record2")); + EXPECT_NO_THROW(repo.get("record1")); + EXPECT_THROW(repo.get("record2"), RepositoryException); + + EXPECT_EQ(1, crepo.getRecords().size()); + EXPECT_TRUE(crepo.exists("record1")); + EXPECT_FALSE(crepo.exists("record2")); + EXPECT_NO_THROW(crepo.get("record1")); + EXPECT_THROW(crepo.get("record2"), RepositoryException); + + auto& record2 = repo.createRecord("record2"); + EXPECT_EQ(2, repo.getRecords().size()); + EXPECT_TRUE(repo.exists("record1")); + EXPECT_TRUE(repo.exists("record2")); + EXPECT_NO_THROW(repo.get("record1")); + EXPECT_NO_THROW(repo.get("record2")); + + EXPECT_EQ(2, crepo.getRecords().size()); + EXPECT_TRUE(crepo.exists("record1")); + EXPECT_TRUE(crepo.exists("record2")); + EXPECT_NO_THROW(crepo.get("record1")); + EXPECT_NO_THROW(crepo.get("record2")); + + repo.removeRecord("record1"); + EXPECT_EQ(1, repo.getRecords().size()); + EXPECT_FALSE(repo.exists("record1")); + EXPECT_TRUE(repo.exists("record2")); + EXPECT_THROW(repo.get("record1"), RepositoryException); + EXPECT_NO_THROW(repo.get("record2")); + + EXPECT_EQ(1, crepo.getRecords().size()); + EXPECT_FALSE(crepo.exists("record1")); + EXPECT_TRUE(crepo.exists("record2")); + EXPECT_THROW(crepo.get("record1"), RepositoryException); + EXPECT_NO_THROW(crepo.get("record2")); + + // Add duplicit record + EXPECT_THROW(repo.createRecord("record2"), RepositoryException); +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/DifferentRealPlugin.cpp b/unittests/plugin/plugins/DifferentRealPlugin.cpp new file mode 100644 index 0000000..4f774ea --- /dev/null +++ b/unittests/plugin/plugins/DifferentRealPlugin.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +class DifferentRealPluginApi : public cece::plugin::Api { }; + +// Create function +CECE_PLUGIN_DEFINE_CREATE(different_real_plugin, DifferentRealPluginApi) + +// Get config +CECE_PLUGIN_GET_CONFIG_PROTOTYPE(different_real_plugin) +{ + static cece::plugin::Config config = { + cece::PLUGIN_API_VERSION, + 16, // 128bit float + CECE_RENDER_VALUE, + CECE_THREAD_SAFE_VALUE + }; + return &config; +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/InvalidPlugin.cpp b/unittests/plugin/plugins/InvalidPlugin.cpp new file mode 100644 index 0000000..9411d12 --- /dev/null +++ b/unittests/plugin/plugins/InvalidPlugin.cpp @@ -0,0 +1,31 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/Api.hpp" + +class InvalidPluginApi : public cece::plugin::Api { }; + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/NoConfigPlugin.cpp b/unittests/plugin/plugins/NoConfigPlugin.cpp new file mode 100644 index 0000000..5b859bc --- /dev/null +++ b/unittests/plugin/plugins/NoConfigPlugin.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +class NoConfigPluginApi : public cece::plugin::Api { }; + +// Create function +CECE_PLUGIN_DEFINE_CREATE(no_config_plugin, NoConfigPluginApi) + +// Get config +CECE_PLUGIN_GET_CONFIG_PROTOTYPE(no_config_plugin) +{ + return nullptr; +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/NoCreatePlugin.cpp b/unittests/plugin/plugins/NoCreatePlugin.cpp new file mode 100644 index 0000000..f6a124c --- /dev/null +++ b/unittests/plugin/plugins/NoCreatePlugin.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +// Get config +CECE_PLUGIN_DEFINE_GET_CONFIG(no_create_plugin) + +/* ************************************************************************ */ diff --git a/cece/core/test/DynamicArrayTest.cpp b/unittests/plugin/plugins/NotRenderPlugin.cpp similarity index 80% rename from cece/core/test/DynamicArrayTest.cpp rename to unittests/plugin/plugins/NotRenderPlugin.cpp index f47a9cf..84ad5ad 100644 --- a/cece/core/test/DynamicArrayTest.cpp +++ b/unittests/plugin/plugins/NotRenderPlugin.cpp @@ -23,25 +23,25 @@ /* */ /* ************************************************************************ */ -// GTest -#include - // CeCe -#include "cece/core/DynamicArray.hpp" +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" -/* ************************************************************************ */ +class NotRenderPluginApi : public cece::plugin::Api { }; -using namespace cece; +// Create function +CECE_PLUGIN_DEFINE_CREATE(not_render_plugin, NotRenderPluginApi) -/* ************************************************************************ */ - -TEST(DynamicArrayTest, size) +// Get config +CECE_PLUGIN_GET_CONFIG_PROTOTYPE(not_render_plugin) { - DynamicArray array; - EXPECT_EQ(0u, array.size()); - - array.resize(10u); - EXPECT_EQ(10u, array.size()); + static cece::plugin::Config config = { + cece::PLUGIN_API_VERSION, + sizeof(cece::RealType), + !CECE_RENDER_VALUE, + CECE_THREAD_SAFE_VALUE + }; + return &config; } /* ************************************************************************ */ diff --git a/unittests/plugin/plugins/NotThreadSafePlugin.cpp b/unittests/plugin/plugins/NotThreadSafePlugin.cpp new file mode 100644 index 0000000..b98fe50 --- /dev/null +++ b/unittests/plugin/plugins/NotThreadSafePlugin.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +class NotThreadSafePluginApi : public cece::plugin::Api { }; + +// Create function +CECE_PLUGIN_DEFINE_CREATE(not_thread_safe_plugin, NotThreadSafePluginApi) + +// Get config +CECE_PLUGIN_GET_CONFIG_PROTOTYPE(not_thread_safe_plugin) +{ + static cece::plugin::Config config = { + cece::PLUGIN_API_VERSION, + sizeof(cece::RealType), + CECE_RENDER_VALUE, + !CECE_THREAD_SAFE_VALUE + }; + return &config; +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/OldPlugin.cpp b/unittests/plugin/plugins/OldPlugin.cpp new file mode 100644 index 0000000..f30f6eb --- /dev/null +++ b/unittests/plugin/plugins/OldPlugin.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" + +class OldPluginApi : public cece::plugin::Api { }; + +// Create function +CECE_PLUGIN_DEFINE_CREATE(old_plugin, OldPluginApi) + +// Get config +CECE_PLUGIN_GET_CONFIG_PROTOTYPE(old_plugin) +{ + static cece::plugin::Config config = { + cece::PLUGIN_API_VERSION - 1, // Previous API version + sizeof(cece::RealType), + CECE_RENDER_VALUE, + CECE_THREAD_SAFE_VALUE + }; + return &config; +} + +/* ************************************************************************ */ diff --git a/unittests/plugin/plugins/TestPlugin.cpp b/unittests/plugin/plugins/TestPlugin.cpp new file mode 100644 index 0000000..8364708 --- /dev/null +++ b/unittests/plugin/plugins/TestPlugin.cpp @@ -0,0 +1,138 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// CeCe +#include "cece/Exception.hpp" +#include "cece/simulation/Initializer.hpp" +#include "cece/simulation/Module.hpp" +#include "cece/simulation/Object.hpp" +#include "cece/simulation/Program.hpp" +#include "cece/plugin/definition.hpp" +#include "cece/plugin/Api.hpp" +#include "cece/plugin/Repository.hpp" +#include "cece/plugin/RepositoryRecord.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::plugin; + +/* ************************************************************************ */ + +namespace { + +/* ************************************************************************ */ + +class TestInitializer final : public simulation::Initializer +{ +public: + using simulation::Initializer::Initializer; + + void init(simulation::Simulation& simulation) const override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +class TestModule final : public simulation::Module +{ +public: + using simulation::Module::Module; +}; + +/* ************************************************************************ */ + +class TestObject final : public simulation::Object +{ +public: + using simulation::Object::Object; +}; + +/* ************************************************************************ */ + +class TestProgram final : public simulation::Program +{ +public: + using simulation::Program::Program; + + UniquePtr clone() const override + { + return makeUnique(*this); + } + + void call(simulation::Simulation& simulation, simulation::Object& object, unit::Time dt) override + { + // Nothing to do + } +}; + +/* ************************************************************************ */ + +} + +/* ************************************************************************ */ + +class TestPluginApi : public Api +{ + +public: + + void onLoad(RepositoryRecord& repository) override + { + if (m_count != 0) + throw RuntimeException("onLoad called multiple times"); + + ++m_count; + + repository + .registerInitializer("initializer") + .registerModule("module") + .registerObject("object") + .registerProgram("program") + ; + } + + void onUnload(RepositoryRecord& repository) override + { + --m_count; + + if (m_count != 0) + throw RuntimeException("onUnload called multiple times"); + } + +private: + + /// Number of onLoad calls + int m_count = 0; + +}; + +/* ************************************************************************ */ + +CECE_PLUGIN_DEFINE(test_plugin, TestPluginApi) + +/* ************************************************************************ */ diff --git a/unittests/render/CMakeLists.txt b/unittests/render/CMakeLists.txt new file mode 100644 index 0000000..6618258 --- /dev/null +++ b/unittests/render/CMakeLists.txt @@ -0,0 +1,31 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(render + SOURCES + ColorTest.cpp +) + +# ######################################################################### # diff --git a/cece/render/test/ColorTest.cpp b/unittests/render/ColorTest.cpp similarity index 98% rename from cece/render/test/ColorTest.cpp rename to unittests/render/ColorTest.cpp index 65304f2..ecfd53d 100644 --- a/cece/render/test/ColorTest.cpp +++ b/unittests/render/ColorTest.cpp @@ -24,15 +24,16 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/StringStream.hpp" +#include "cece/io/StringStream.hpp" #include "cece/render/Color.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::io; using namespace cece::render; /* ************************************************************************ */ diff --git a/unittests/unit/CMakeLists.txt b/unittests/unit/CMakeLists.txt new file mode 100644 index 0000000..2a51f12 --- /dev/null +++ b/unittests/unit/CMakeLists.txt @@ -0,0 +1,36 @@ +# ######################################################################### # +# Georgiev Lab (c) 2015-2016 # +# ######################################################################### # +# Department of Cybernetics # +# Faculty of Applied Sciences # +# University of West Bohemia in Pilsen # +# ######################################################################### # +# # +# This file is part of CeCe. # +# # +# CeCe is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# CeCe is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with CeCe. If not, see . # +# # +# ######################################################################### # + +cece_add_test(unit + SOURCES + Unit_test.cpp + Units_test.cpp + UnitIo_test.cpp + UnitsCtors_test.cpp + math_test.cpp + #VectorUnitsTest.cpp +) + +# ######################################################################### # diff --git a/unittests/unit/UnitIo_test.cpp b/unittests/unit/UnitIo_test.cpp new file mode 100644 index 0000000..820ddd3 --- /dev/null +++ b/unittests/unit/UnitIo_test.cpp @@ -0,0 +1,1179 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/io/StringStream.hpp" +#include "cece/unit/math.hpp" +#include "cece/unit/UnitIo.hpp" +#include "cece/unit/Units.hpp" +#include "cece/unit/UnitsCtors.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::unit; + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseLength) +{ + { + auto unit = parse("0"); + EXPECT_DOUBLE_EQ(0, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10m"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10dm"); + EXPECT_DOUBLE_EQ(10e-1, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10cm"); + EXPECT_DOUBLE_EQ(10e-2, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10mm"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10um"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10nm"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } + + { + auto unit = parse("10pm"); + EXPECT_DOUBLE_EQ(10e-12, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Length u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseTime) +{ + { + auto unit = parse("0"); + EXPECT_DOUBLE_EQ(0, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("10s"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("10ms"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("10us"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("10ns"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("5min"); + EXPECT_DOUBLE_EQ(5 * 60, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } + + { + auto unit = parse("1h"); + EXPECT_DOUBLE_EQ(1 * 3600, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Time u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseMass) +{ + { + auto unit = parse("0.1"); + EXPECT_DOUBLE_EQ(0.1, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_THROW({ Mass u(unit); }, CastException); + } + + { + auto unit = parse("10.5g"); + EXPECT_DOUBLE_EQ(10.5, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Mass u(unit); }); + } + + { + auto unit = parse("13mg"); + EXPECT_DOUBLE_EQ(13e-3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Mass u(unit); }); + } + + { + auto unit = parse("27ug"); + EXPECT_DOUBLE_EQ(27e-6, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Mass u(unit); }); + } + + { + auto unit = parse("10ng"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Mass u(unit); }); + } + + { + auto unit = parse("10pg"); + EXPECT_DOUBLE_EQ(10e-12, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Mass u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseArea) +{ + { + auto unit = parse("10m2"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Area u(unit); }); + } + + { + auto unit = parse("10dm2"); + EXPECT_DOUBLE_EQ(10e-2, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Area u(unit); }); + } + + { + auto unit = parse("10cm2"); + EXPECT_DOUBLE_EQ(10e-4, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Area u(unit); }); + } + + { + auto unit = parse("10mm2"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Area u(unit); }); + } + + { + auto unit = parse("10um2"); + EXPECT_DOUBLE_EQ(10e-12, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Area u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseVolume) +{ + { + auto unit = parse("10m3"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Volume u(unit); }); + } + + { + auto unit = parse("10dm3"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Volume u(unit); }); + } + + { + auto unit = parse("10cm3"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Volume u(unit); }); + } + + { + auto unit = parse("10mm3"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Volume u(unit); }); + } + + { + auto unit = parse("10um3"); + EXPECT_DOUBLE_EQ(10e-18, unit.get()); + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Volume u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseVelocity) +{ + { + auto unit = parse("10m/s"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Velocity u(unit); }); + } + + { + auto unit = parse("10mm/s"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Velocity u(unit); }); + } + + { + auto unit = parse("10um/s"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Velocity u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseAcceleration) +{ + { + auto unit = parse("10m/s2"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Acceleration u(unit); }); + } + + { + auto unit = parse("10mm/s2"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Acceleration u(unit); }); + } + + { + auto unit = parse("10um/s2"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Acceleration u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseForce) +{ + { + auto unit = parse("10kgm/s2"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } + + { + auto unit = parse("10gm/s2"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } + + { + auto unit = parse("10mgm/s2"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } + + { + auto unit = parse("10N"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } + + { + auto unit = parse("10mN"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } + + { + auto unit = parse("10uN"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Force u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseDynamicViscosity) +{ + { + auto unit = parse("10kg/ms"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ DynamicViscosity u(unit); }); + } + + { + auto unit = parse("10g/ms"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ DynamicViscosity u(unit); }); + } + + { + auto unit = parse("10Ns/m2"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ DynamicViscosity u(unit); }); + } + + { + auto unit = parse("10Pas"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ DynamicViscosity u(unit); }); + } + + { + auto unit = parse("10mPas"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ DynamicViscosity u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseKinematicViscosity) +{ + { + auto unit = parse("10m2/s"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ KinematicViscosity u(unit); }); + } + + { + auto unit = parse("10mm2/s"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ KinematicViscosity u(unit); }); + } + + { + auto unit = parse("10um2/s"); + EXPECT_DOUBLE_EQ(10e-12, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ KinematicViscosity u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseAmountOfSubstance) +{ + { + auto unit = parse("10mol"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ AmountOfSubstance u(unit); }); + } + + { + auto unit = parse("10mmol"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ AmountOfSubstance u(unit); }); + } + + { + auto unit = parse("10umol"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ AmountOfSubstance u(unit); }); + } + + { + auto unit = parse("10nmol"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ AmountOfSubstance u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseMolarConcentration) +{ + { + auto unit = parse("10mol/m3"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10mmol/m3"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10umol/m3"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10nmol/m3"); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10mM"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10uM"); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } + + { + auto unit = parse("10nM"); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ MolarConcentration u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseAngle) +{ + { + auto unit = parse("10rad"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Angle u(unit); }); + } + + { + auto unit = parse("10deg"); + EXPECT_DOUBLE_EQ(deg2rad(10), unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Angle u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseFrequency) +{ + { + auto unit = parse("10/s"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } + + { + auto unit = parse("10Hz"); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } + + { + auto unit = parse("10kHz"); + EXPECT_DOUBLE_EQ(10e3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } + + { + auto unit = parse("10MHz"); + EXPECT_DOUBLE_EQ(10e6, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } + + { + auto unit = parse("10GHz"); + EXPECT_DOUBLE_EQ(10e9, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } + + { + auto unit = parse("10THz"); + EXPECT_DOUBLE_EQ(10e12, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Frequency u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, parseProbability) +{ + { + auto unit = parse("0.1"); + EXPECT_DOUBLE_EQ(0.1, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Probability u(unit); }); + } + + { + auto unit = parse("10%"); + EXPECT_DOUBLE_EQ(0.1, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_NO_THROW({ Probability u(unit); }); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, stream) +{ + { + io::InStringStream iss("0.34um"); + + auto unit = parse(iss); + EXPECT_DOUBLE_EQ(0.34e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + io::InStringStream iss("0.34um"); + + Unit unit; + iss >> unit; + + EXPECT_DOUBLE_EQ(0.34e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + io::OutStringStream oss; + Length unit(10); // 10m + + oss << unit; + + // TODO suffix. + EXPECT_EQ("10", oss.str()); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, invalid) +{ + { + EXPECT_THROW(parse("m"), InvalidArgumentException); + } + + { + EXPECT_THROW(parse(".um"), InvalidArgumentException); + } + + { + EXPECT_THROW(parse("1GM"), InvalidArgumentException); + } +} + +/* ************************************************************************ */ + +TEST(UnitIoTest, userSymbols) +{ + { + EXPECT_THROW(parse("15ll"), InvalidArgumentException); + registerSymbol("ll", [](double value) { return Unit(value); }); + + Unit unit; + EXPECT_NO_THROW({ unit = parse("15ll"); }); + + EXPECT_DOUBLE_EQ(15, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + unregisterSymbol("ll"); + EXPECT_THROW(parse("15ll"), InvalidArgumentException); + } + + { + EXPECT_THROW(parse("15a"), InvalidArgumentException); + registerSymbol("a", [](double value) -> Unit { return value * m2(100); }); + + Unit unit; + EXPECT_NO_THROW({ unit = parse("15a"); }); + + EXPECT_DOUBLE_EQ(15 * 100, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + unregisterSymbol("a"); + EXPECT_THROW(parse("15a"), InvalidArgumentException); + } + + { + EXPECT_THROW(parse("15akr"), InvalidArgumentException); + registerSymbol("akr", [](double value) { return Unit(4046873 * value, length(2)); }); + + Unit unit; + EXPECT_NO_THROW({ unit = parse("15akr"); }); + + EXPECT_DOUBLE_EQ(15 * 4046873, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + unregisterSymbol("akr"); + EXPECT_THROW(parse("15akr"), InvalidArgumentException); + } +} + +/* ************************************************************************ */ diff --git a/unittests/unit/Unit_test.cpp b/unittests/unit/Unit_test.cpp new file mode 100644 index 0000000..7f7ffb0 --- /dev/null +++ b/unittests/unit/Unit_test.cpp @@ -0,0 +1,1145 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/math/Zero.hpp" +#include "cece/unit/Unit.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::math; +using namespace cece::unit; + +/* ************************************************************************ */ + +TEST(UnitsTest, ctor) +{ + using StaticUnit = UnitBase>; + using DynamicUnit = UnitBase; + using DynamicDetail = DynamicImpl::Detail; + + { + const StaticUnit unit; + EXPECT_DOUBLE_EQ(0, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const StaticUnit unit(Zero); + EXPECT_EQ(Zero, unit); + EXPECT_EQ(unit, Zero); + EXPECT_DOUBLE_EQ(0, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const StaticUnit unit(1); + EXPECT_DOUBLE_EQ(1, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const StaticUnit unit(0.345); + EXPECT_DOUBLE_EQ(0.345, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const DynamicUnit unit(156.45645); + EXPECT_DOUBLE_EQ(156.45645, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const DynamicUnit unit(156.45645, DynamicDetail{2, 1, 0, 0, 1, 0, 0}); + EXPECT_DOUBLE_EQ(156.45645, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(1, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + const StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const StaticUnit unit2(unit); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const DynamicUnit unit2(unit); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const DynamicUnit unit(45.3, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const StaticUnit unit2(unit); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const DynamicUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const DynamicUnit unit2(unit); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(0, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + // Move + { + StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const StaticUnit unit2(std::move(unit)); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const DynamicUnit unit2(std::move(unit)); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + DynamicUnit unit(45.3, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const StaticUnit unit2(std::move(unit)); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + DynamicUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + const DynamicUnit unit2(std::move(unit)); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(0, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, nodim) +{ + using StaticUnit = UnitBase>; + + { + StaticUnit unit; + EXPECT_DOUBLE_EQ(0.0, unit); + } + + { + StaticUnit unit(1.5); + EXPECT_DOUBLE_EQ(1.5, unit); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, assignment) +{ + using StaticUnit = UnitBase>; + using DynamicUnit = UnitBase; + using DynamicDetail = DynamicImpl::Detail; + + { + const StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, static_cast(unit)); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + StaticUnit unit2; + unit2 = unit; + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + DynamicUnit unit2; + unit2 = unit; + + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const DynamicUnit unit(45.3, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + StaticUnit unit2; + unit2 = unit; + + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + const DynamicUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + DynamicUnit unit2; + unit2 = unit; + + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + EXPECT_EQ(0, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + // Move + { + StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + StaticUnit unit2; + unit2 = std::move(unit); + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + StaticUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + DynamicUnit unit2; + unit2 = std::move(unit); + + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + DynamicUnit unit(45.3, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + StaticUnit unit2; + unit2 = std::move(unit); + + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } + + { + DynamicUnit unit(45.3); + EXPECT_DOUBLE_EQ(45.3, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + + DynamicUnit unit2; + unit2 = std::move(unit); + + EXPECT_DOUBLE_EQ(45.3, unit2.get()); + EXPECT_EQ(0, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, rel) +{ + using Unit = UnitBase>; + + const Unit unit1(1); + const Unit unit2(10); + const Unit unit3(0); + const Unit unit4(1); + + EXPECT_DOUBLE_EQ(1, unit1.get()); + EXPECT_DOUBLE_EQ(10, unit2.get()); + EXPECT_DOUBLE_EQ(0, unit3.get()); + EXPECT_DOUBLE_EQ(1, unit4.get()); + + EXPECT_EQ(unit1, unit1); + EXPECT_NE(unit1, unit2); + EXPECT_NE(unit1, unit3); + EXPECT_EQ(unit1, unit4); + + EXPECT_NE(unit2, unit1); + EXPECT_EQ(unit2, unit2); + EXPECT_NE(unit2, unit3); + EXPECT_NE(unit2, unit4); + + EXPECT_NE(unit3, unit1); + EXPECT_NE(unit3, unit2); + EXPECT_EQ(unit3, unit3); + EXPECT_NE(unit3, unit4); + + EXPECT_EQ(unit4, unit1); + EXPECT_NE(unit4, unit2); + EXPECT_NE(unit4, unit3); + EXPECT_EQ(unit4, unit4); + + EXPECT_GE(unit1, unit1); + EXPECT_LE(unit1, unit1); + EXPECT_LT(unit1, unit2); + EXPECT_LE(unit1, unit2); + EXPECT_GT(unit1, unit3); + EXPECT_GE(unit1, unit3); + EXPECT_GE(unit1, unit4); + EXPECT_LE(unit1, unit4); + + EXPECT_NE(Zero, unit1); + EXPECT_NE(Zero, unit2); + EXPECT_EQ(Zero, unit3); + EXPECT_NE(Zero, unit4); + + EXPECT_NE(unit1, Zero); + EXPECT_NE(unit2, Zero); + EXPECT_EQ(unit3, Zero); + EXPECT_NE(unit4, Zero); + + EXPECT_LE(Zero, unit1); + EXPECT_LT(Zero, unit1); + EXPECT_LE(Zero, unit2); + EXPECT_LT(Zero, unit2); + EXPECT_GE(Zero, unit3); + EXPECT_LE(Zero, unit3); + EXPECT_LE(Zero, unit4); + EXPECT_LT(Zero, unit4); + + EXPECT_GE(unit1, Zero); + EXPECT_GT(unit1, Zero); + EXPECT_GE(unit2, Zero); + EXPECT_GT(unit2, Zero); + EXPECT_LE(unit3, Zero); + EXPECT_GE(unit3, Zero); + EXPECT_GE(unit4, Zero); + EXPECT_GT(unit4, Zero); + +} + +/* ************************************************************************ */ + +TEST(UnitsTest, cast) +{ + using StaticUnit = UnitBase>; + using DynamicUnit = UnitBase; + using DynamicDetail = DynamicImpl::Detail; + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + + EXPECT_NO_THROW({StaticUnit unit2(unit);}); + } + + { + DynamicUnit unit(1, DynamicDetail{0, 0, 0, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 1, 0, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 1, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 1, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 1, 0, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 1, 0}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 0, 1}); + + EXPECT_THROW({StaticUnit unit2(unit);}, CastException); + } + + // Zero can be cast to anything + { + DynamicUnit unit(Zero); + + EXPECT_NO_THROW({StaticUnit unit2(unit);}); + } + + + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 0, 0}); + + EXPECT_NO_THROW({StaticUnit unit2; unit2 = unit;}); + } + + { + DynamicUnit unit(1, DynamicDetail{0, 0, 0, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 1, 0, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 1, 0, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 1, 0, 0, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 1, 0, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 1, 0}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + { + DynamicUnit unit(1, DynamicDetail{1, 0, 0, 0, 0, 0, 1}); + + EXPECT_THROW({StaticUnit unit2; unit2 = unit;}, CastException); + } + + // Zero can be cast to anything + { + DynamicUnit unit(Zero); + + EXPECT_NO_THROW({StaticUnit unit2; unit2 = unit;}); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, relDiff) +{ + using Unit1 = UnitBase>; + using Unit2 = UnitBase>; + + const Unit1 unit1(1); + const Unit2 unit2(1); + + // TODO: test compile failure +} + +/* ************************************************************************ */ + +TEST(UnitsTest, unary) +{ + using Unit = UnitBase>; + + const Unit unit1(1); + const Unit unit2(2); + const Unit unit3(3); + + const Unit unit1p = +unit1; + const Unit unit2p = +unit2; + const Unit unit3p = +unit3; + + EXPECT_DOUBLE_EQ(1, unit1p.get()); + EXPECT_DOUBLE_EQ(2, unit2p.get()); + EXPECT_DOUBLE_EQ(3, unit3p.get()); + + const Unit unit1m = -unit1; + const Unit unit2m = -unit2; + const Unit unit3m = -unit3; + + EXPECT_DOUBLE_EQ(-1, unit1m.get()); + EXPECT_DOUBLE_EQ(-2, unit2m.get()); + EXPECT_DOUBLE_EQ(-3, unit3m.get()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, plus) +{ + using Unit = UnitBase>; + + { + const Unit unit1(1); + const Unit unit2(2); + const Unit unit3(3); + + const Unit unit4 = unit1 + unit1; + EXPECT_DOUBLE_EQ(2, unit4.get()); + + const Unit unit5 = unit1 + unit2 + unit3 + unit4; + EXPECT_DOUBLE_EQ(8, unit5.get()); + } + + { + Unit unit1(1); + Unit unit2(2); + Unit unit3(3); + + unit1 += unit2; + unit2 += unit3; + + EXPECT_DOUBLE_EQ(3, unit1.get()); + EXPECT_DOUBLE_EQ(5, unit2.get()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, minus) +{ + using Unit = UnitBase>; + + { + const Unit unit1(1); + const Unit unit2(2); + const Unit unit3(3); + + const Unit unit4 = unit1 - unit1; + EXPECT_DOUBLE_EQ(0, unit4.get()); + + const Unit unit5 = unit1 - unit2 - unit3 - unit4; + EXPECT_DOUBLE_EQ(-4, unit5.get()); + } + + { + Unit unit1(1); + Unit unit2(2); + Unit unit3(3); + + unit1 -= unit2; + unit2 -= unit3; + + EXPECT_DOUBLE_EQ(-1, unit1.get()); + EXPECT_DOUBLE_EQ(-1, unit2.get()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, mult) +{ + using ::testing::StaticAssertTypeEq; + + using Unit = UnitBase>; + + { + const Unit unit1(1); + const Unit unit2(2); + const Unit unit3(3); + + const auto unit4 = unit1 * unit1; + EXPECT_DOUBLE_EQ(1, unit4.get()); + //StaticAssertTypeEq>>(); + + const auto unit5 = unit1 * unit2 * unit3 * unit4; + EXPECT_DOUBLE_EQ(6, unit5.get()); + //StaticAssertTypeEq>>(); + } + + { + const Unit unit1(1); + const Unit unit2(2); + const Unit unit3(3); + + const Unit unit4 = unit1 * 10; + const Unit unit5 = unit2 * 10; + const Unit unit6 = unit3 * 10; + + EXPECT_DOUBLE_EQ(10, unit4.get()); + EXPECT_DOUBLE_EQ(20, unit5.get()); + EXPECT_DOUBLE_EQ(30, unit6.get()); + } + + { + Unit unit1(1); + Unit unit2(2); + Unit unit3(3); + + unit1 *= 10; + unit2 *= 10; + unit3 *= 10; + + EXPECT_DOUBLE_EQ(10, unit1.get()); + EXPECT_DOUBLE_EQ(20, unit2.get()); + EXPECT_DOUBLE_EQ(30, unit3.get()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, div) +{ + using Unit = UnitBase>; + + { + const Unit unit1(10); + const Unit unit2(20); + const Unit unit3(30); + + const Unit unit4 = unit1 / 5; + const Unit unit5 = unit2 / 5; + const Unit unit6 = unit3 / 5; + + EXPECT_DOUBLE_EQ(2, unit4.get()); + EXPECT_DOUBLE_EQ(4, unit5.get()); + EXPECT_DOUBLE_EQ(6, unit6.get()); + } + + { + Unit unit1(10); + Unit unit2(20); + Unit unit3(30); + + unit1 /= 5; + unit2 /= 5; + unit3 /= 5; + + EXPECT_DOUBLE_EQ(2, unit1.get()); + EXPECT_DOUBLE_EQ(4, unit2.get()); + EXPECT_DOUBLE_EQ(6, unit3.get()); + } + + { + Unit unit1(10); + Unit unit2(5); + + auto unit3 = unit1 / unit2; + + EXPECT_DOUBLE_EQ(2, unit3.get()); + EXPECT_EQ(0, unit3.getLengthExp()); + EXPECT_EQ(0, unit3.getTimeExp()); + EXPECT_EQ(0, unit3.getMassExp()); + EXPECT_EQ(0, unit3.getCurrentExp()); + EXPECT_EQ(0, unit3.getTemperatureExp()); + EXPECT_EQ(0, unit3.getSubstanceExp()); + EXPECT_EQ(0, unit3.getIntensityExp()); + } + + { + Unit unit1(10); + + auto unit2 = 100 / unit1; + + EXPECT_DOUBLE_EQ(10, unit2.get()); + EXPECT_EQ(-1, unit2.getLengthExp()); + EXPECT_EQ(0, unit2.getTimeExp()); + EXPECT_EQ(0, unit2.getMassExp()); + EXPECT_EQ(0, unit2.getCurrentExp()); + EXPECT_EQ(0, unit2.getTemperatureExp()); + EXPECT_EQ(0, unit2.getSubstanceExp()); + EXPECT_EQ(0, unit2.getIntensityExp()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, builders) +{ + { + Unit unit(10); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, length(2)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, mass(1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, time(-2)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, current(1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(1, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, temperature(1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(1, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, substance()); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + Unit unit(10, intensity()); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(1, unit.getIntensityExp()); + } + + { + Unit unit(10, length(2) | mass(1) | time(-1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + // 1O/s + Unit unit(10, none() / time(1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + // 1O/ms (meter & second, not millisecond) + Unit unit(10, none() / length(1) / time(1)); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } +} + +/* ************************************************************************ */ + +TEST(UnitsTest, deprecated) +{ + { + Unit unit(456.1); + EXPECT_DOUBLE_EQ(456.1, unit.value()); + } +} + +/* ************************************************************************ */ diff --git a/unittests/unit/UnitsCtors_test.cpp b/unittests/unit/UnitsCtors_test.cpp new file mode 100644 index 0000000..7115d6f --- /dev/null +++ b/unittests/unit/UnitsCtors_test.cpp @@ -0,0 +1,102 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/unit/UnitsCtors.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::unit; + +/* ************************************************************************ */ + +TEST(UnitsCtorsTest, ctorLength) +{ + { + auto unit = m(10); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + auto unit = mm(10); + EXPECT_DOUBLE_EQ(10e-3, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + auto unit = um(10); + EXPECT_DOUBLE_EQ(10e-6, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + auto unit = nm(10); + EXPECT_DOUBLE_EQ(10e-9, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } + + { + auto unit = pm(10); + EXPECT_DOUBLE_EQ(10e-12, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); + } +} + +/* ************************************************************************ */ diff --git a/unittests/unit/Units_test.cpp b/unittests/unit/Units_test.cpp new file mode 100644 index 0000000..d6d7eb0 --- /dev/null +++ b/unittests/unit/Units_test.cpp @@ -0,0 +1,343 @@ +/* ************************************************************************ */ +/* Georgiev Lab (c) 2015-2016 */ +/* ************************************************************************ */ +/* Department of Cybernetics */ +/* Faculty of Applied Sciences */ +/* University of West Bohemia in Pilsen */ +/* ************************************************************************ */ +/* */ +/* This file is part of CeCe. */ +/* */ +/* CeCe is free software: you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* CeCe is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with CeCe. If not, see . */ +/* */ +/* ************************************************************************ */ + +// GTest +#include "gtest/gtest.h" + +// CeCe +#include "cece/unit/Units.hpp" +#include "cece/math/constants.hpp" + +/* ************************************************************************ */ + +using namespace cece; +using namespace cece::unit; + +/* ************************************************************************ */ + +TEST(UnitsTest, none) +{ + None unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, length) +{ + Length unit; + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, time) +{ + Time unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, mass) +{ + Mass unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, area) +{ + Area unit; + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, volume) +{ + Volume unit; + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, velocity) +{ + Velocity unit; + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, acceleration) +{ + Acceleration unit; + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, force) +{ + Force unit; + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-2, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, impulse) +{ + Impulse unit; + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, density) +{ + Density unit; + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, dynamicViscosity) +{ + DynamicViscosity unit; + EXPECT_EQ(-1, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(1, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, kinematicViscosity) +{ + KinematicViscosity unit; + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, amountOfSubstance) +{ + AmountOfSubstance unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, numberConcentration) +{ + NumberConcentration unit; + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, molarConcentration) +{ + MolarConcentration unit; + EXPECT_EQ(-3, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(1, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, angle) +{ + Angle unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, angularVelocity) +{ + AngularVelocity unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, probability) +{ + Probability unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, volumericFlow) +{ + VolumericFlow unit; + EXPECT_EQ(3, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, frequency) +{ + Frequency unit; + EXPECT_EQ(0, unit.getLengthExp()); + EXPECT_EQ(-1, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); +} + +/* ************************************************************************ */ + +TEST(UnitsTest, multiply) +{ + Area area(5); + Length length(10); + + Volume volume = area * length; + EXPECT_DOUBLE_EQ(50, volume.get()); +} + +/* ************************************************************************ */ diff --git a/cece/core/test/VectorUnitsTest.cpp b/unittests/unit/VectorUnitsTest.cpp similarity index 75% rename from cece/core/test/VectorUnitsTest.cpp rename to unittests/unit/VectorUnitsTest.cpp index c918c0b..571618e 100644 --- a/cece/core/test/VectorUnitsTest.cpp +++ b/unittests/unit/VectorUnitsTest.cpp @@ -23,20 +23,21 @@ /* */ /* ************************************************************************ */ -// GTest -#include - // C++ #include +// GTest +#include "gtest/gtest.h" + // CeCe -#include "cece/core/UnitIo.hpp" -#include "cece/core/VectorUnits.hpp" -#include "cece/core/UnitsCtors.hpp" +#include "cece/unit/UnitIo.hpp" +#include "cece/unit/VectorUnits.hpp" +#include "cece/unit/UnitsCtors.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::math; /* ************************************************************************ */ @@ -45,61 +46,61 @@ TEST(VectorUnitsTest, istream) { std::istringstream is("10 20"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(10), vec.getX()); - EXPECT_EQ(units::um(20), vec.getY()); + EXPECT_EQ(unit::um(10), vec.getX()); + EXPECT_EQ(unit::um(20), vec.getY()); } { std::istringstream is("10um 20um"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(10), vec.getX()); - EXPECT_EQ(units::um(20), vec.getY()); + EXPECT_EQ(unit::um(10), vec.getX()); + EXPECT_EQ(unit::um(20), vec.getY()); } { std::istringstream is("10um"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(10), vec.getX()); - EXPECT_EQ(units::um(10), vec.getY()); + EXPECT_EQ(unit::um(10), vec.getX()); + EXPECT_EQ(unit::um(10), vec.getY()); } { std::istringstream is("0 10um"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(0), vec.getX()); - EXPECT_EQ(units::um(10), vec.getY()); + EXPECT_EQ(unit::um(0), vec.getX()); + EXPECT_EQ(unit::um(10), vec.getY()); } { std::istringstream is("0um 10um"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(0), vec.getX()); - EXPECT_EQ(units::um(10), vec.getY()); + EXPECT_EQ(unit::um(0), vec.getX()); + EXPECT_EQ(unit::um(10), vec.getY()); } { std::istringstream is("5um 0"); - Vector vec; + Vector vec; is >> vec; - EXPECT_EQ(units::um(5), vec.getX()); - EXPECT_EQ(units::um(0), vec.getY()); + EXPECT_EQ(unit::um(5), vec.getX()); + EXPECT_EQ(unit::um(0), vec.getY()); } } diff --git a/cece/core/test/FilePathTest.cpp b/unittests/unit/math_test.cpp similarity index 59% rename from cece/core/test/FilePathTest.cpp rename to unittests/unit/math_test.cpp index 62360a2..01e5b20 100644 --- a/cece/core/test/FilePathTest.cpp +++ b/unittests/unit/math_test.cpp @@ -24,86 +24,84 @@ /* ************************************************************************ */ // GTest -#include +#include "gtest/gtest.h" // CeCe -#include "cece/core/String.hpp" -#include "cece/core/FilePath.hpp" +#include "cece/unit/math.hpp" +#include "cece/unit/Units.hpp" /* ************************************************************************ */ using namespace cece; +using namespace cece::unit; /* ************************************************************************ */ -TEST(FilePath, construct) +TEST(UnitMathTest, sqrt) { { - auto path = FilePath(); - EXPECT_TRUE(path.isEmpty()); - } - - { - const char* str = "filename1"; - auto path = FilePath(str); - EXPECT_FALSE(path.isEmpty()); - EXPECT_EQ(str, path.toString()); - } - - { - String str = "dirname/filename"; - auto path = FilePath(str); - EXPECT_FALSE(path.isEmpty()); - EXPECT_EQ(str, path.toString()); + Area area(100); + + auto unit = sqrt(area); + EXPECT_DOUBLE_EQ(10, unit.get()); + EXPECT_EQ(1, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); } } /* ************************************************************************ */ -TEST(FilePath, append) +TEST(UnitMathTest, abs) { { - auto path = FilePath("dir"); - path /= "filename"; - EXPECT_EQ("dir/filename", path.toString()); + Area area(100); + + auto unit = abs(area); + EXPECT_DOUBLE_EQ(100, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); } { - auto path = FilePath("dir"); - auto file = FilePath("filename"); - - auto p = path / file; - EXPECT_EQ("dir/filename", p.toString()); + Area area(-100); + + auto unit = abs(area); + EXPECT_DOUBLE_EQ(100, unit.get()); + EXPECT_EQ(2, unit.getLengthExp()); + EXPECT_EQ(0, unit.getTimeExp()); + EXPECT_EQ(0, unit.getMassExp()); + EXPECT_EQ(0, unit.getCurrentExp()); + EXPECT_EQ(0, unit.getTemperatureExp()); + EXPECT_EQ(0, unit.getSubstanceExp()); + EXPECT_EQ(0, unit.getIntensityExp()); } } /* ************************************************************************ */ -TEST(FilePath, operations) +TEST(UnitMathTest, angle) { - FilePath path("dir1/dir2/dir3/file.txt"); - - EXPECT_FALSE(path.isEmpty()); - EXPECT_EQ("dir1/dir2/dir3/file.txt", path.toString()); - EXPECT_EQ("file.txt", path.getFilename()); - EXPECT_EQ(".txt", path.getExtension()); - EXPECT_EQ("dir1/dir2/dir3", path.getParentPath().toString()); - EXPECT_EQ("dir1/dir2/dir3/file", path.getStem().toString()); + { + auto rad = deg2rad(10); - path.replaceExtension(".img"); - EXPECT_EQ("dir1/dir2/dir3/file.img", path.toString()); -} + EXPECT_DOUBLE_EQ(10 * math::PI / 180.0, rad); + } -/* ************************************************************************ */ + { + auto deg = rad2deg(3); -TEST(FilePath, functions) -{ - // TODO: test - // bool isFile(const FilePath& path) noexcept; - // bool isDirectory(const FilePath& path) noexcept; - // bool pathExists(const FilePath& path) noexcept; - // FilePath tempDirectory(); - // DynamicArray openDirectory(const FilePath& dir); + EXPECT_DOUBLE_EQ(3 * 180.0 / math::PI, deg); + } } /* ************************************************************************ */