diff --git a/Core/CppMicroServices/.travis.yml b/Core/CppMicroServices/.travis.yml index a1b3311ec7..45adf24b5d 100644 --- a/Core/CppMicroServices/.travis.yml +++ b/Core/CppMicroServices/.travis.yml @@ -1,27 +1,20 @@ language: cpp compiler: - gcc - clang env: - BUILD_CONFIGURATION=0 - BUILD_CONFIGURATION=1 - BUILD_CONFIGURATION=2 - BUILD_CONFIGURATION=3 - BUILD_CONFIGURATION=4 - BUILD_CONFIGURATION=5 - BUILD_CONFIGURATION=6 - BUILD_CONFIGURATION=7 - - BUILD_CONFIGURATION=8 - - BUILD_CONFIGURATION=9 - - BUILD_CONFIGURATION=10 - - BUILD_CONFIGURATION=11 - - BUILD_CONFIGURATION=12 - - BUILD_CONFIGURATION=13 - - BUILD_CONFIGURATION=14 - - BUILD_CONFIGURATION=15 branches: only: - master + - development script: ctest -VV -S ./CMake/usCTestScript_travis.cmake diff --git a/Core/CppMicroServices/CMake/usCTestScript.cmake b/Core/CppMicroServices/CMake/usCTestScript.cmake index 071307d494..29a4b57aeb 100644 --- a/Core/CppMicroServices/CMake/usCTestScript.cmake +++ b/Core/CppMicroServices/CMake/usCTestScript.cmake @@ -1,114 +1,102 @@ macro(build_and_test) set(CTEST_SOURCE_DIRECTORY ${US_SOURCE_DIR}) set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${CTEST_PROJECT_NAME}_${CTEST_DASHBOARD_NAME}") #if(NOT CTEST_BUILD_NAME) # set(CTEST_BUILD_NAME "${CMAKE_SYSTEM}_${CTEST_COMPILER}_${CTEST_DASHBOARD_NAME}") #endif() ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) ctest_start("Experimental") if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt") file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "${CTEST_INITIAL_CACHE}") endif() ctest_configure(RETURN_VALUE res) if (res) message(FATAL_ERROR "CMake configure error") endif() ctest_build(RETURN_VALUE res) if (res) message(FATAL_ERROR "CMake build error") endif() ctest_test(RETURN_VALUE res PARALLEL_LEVEL ${CTEST_PARALLEL_LEVEL}) if (res) message(FATAL_ERROR "CMake test error") endif() if(WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND) ctest_memcheck() endif() if(WITH_COVERAGE AND CTEST_COVERAGE_COMMAND) ctest_coverage() endif() #ctest_submit() endmacro() -function(create_initial_cache var _shared _threading _cxx11 _autoload) +function(create_initial_cache var _shared _threading _autoload) set(_initial_cache " US_BUILD_TESTING:BOOL=ON US_BUILD_SHARED_LIBS:BOOL=${_shared} US_ENABLE_THREADING_SUPPORT:BOOL=${_threading} - US_USE_C++11:BOOL=${_cxx11} US_ENABLE_AUTOLOADING_SUPPORT:BOOL=${_autoload} ") if(_shared) set(_initial_cache "${_initial_cache} US_BUILD_EXAMPLES:BOOL=ON ") endif() set(${var} ${_initial_cache} PARENT_SCOPE) if(_shared) set(CTEST_DASHBOARD_NAME "shared") else() set(CTEST_DASHBOARD_NAME "static") endif() if(_threading) set(CTEST_DASHBOARD_NAME "${CTEST_DASHBOARD_NAME}-threading") endif() - if(_cxx11) - set(CTEST_DASHBOARD_NAME "${CTEST_DASHBOARD_NAME}-cxx11") - endif() if(_autoload) set(CTEST_DASHBOARD_NAME "${CTEST_DASHBOARD_NAME}-autoloading") endif() set(CTEST_DASHBOARD_NAME ${CTEST_DASHBOARD_NAME} PARENT_SCOPE) endfunction() #========================================================= set(CTEST_PROJECT_NAME CppMicroServices) if(NOT CTEST_PARALLEL_LEVEL) set(CTEST_PARALLEL_LEVEL 1) endif() -# SHARED THREADING C++11 AUTOLOAD - -set(config0 0 0 0 0 ) -set(config1 0 0 0 1 ) -set(config2 0 0 1 0 ) -set(config3 0 0 1 1 ) -set(config4 0 1 0 0 ) -set(config5 0 1 0 1 ) -set(config6 0 1 1 0 ) -set(config7 0 1 1 1 ) -set(config8 1 0 0 0 ) -set(config9 1 0 0 1 ) -set(config10 1 0 1 0 ) -set(config11 1 0 1 1 ) -set(config12 1 1 0 0 ) -set(config13 1 1 0 1 ) -set(config14 1 1 1 0 ) -set(config15 1 1 1 1 ) +# SHARED THREADING AUTOLOAD + +set(config0 0 0 0 ) +set(config1 0 0 1 ) +set(config2 0 1 0 ) +set(config3 0 1 1 ) +set(config4 1 0 0 ) +set(config5 1 0 1 ) +set(config6 1 1 0 ) +set(config7 1 1 1 ) foreach(i ${US_BUILD_CONFIGURATION}) create_initial_cache(CTEST_INITIAL_CACHE ${config${i}}) message("Testing build configuration: ${CTEST_DASHBOARD_NAME}") build_and_test() endforeach() diff --git a/Core/CppMicroServices/CMake/usCTestScript_custom.cmake b/Core/CppMicroServices/CMake/usCTestScript_custom.cmake index 755cb82719..c378062467 100644 --- a/Core/CppMicroServices/CMake/usCTestScript_custom.cmake +++ b/Core/CppMicroServices/CMake/usCTestScript_custom.cmake @@ -1,24 +1,24 @@ find_program(CTEST_COVERAGE_COMMAND NAMES gcov) find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) find_program(CTEST_GIT_COMMAND NAMES git) set(CTEST_SITE "bigeye") set(CTEST_DASHBOARD_ROOT "/tmp") #set(CTEST_COMPILER "gcc-4.5") set(CTEST_CMAKE_GENERATOR "Unix Makefiles") set(CTEST_BUILD_FLAGS "-j") set(CTEST_BUILD_CONFIGURATION Debug) set(CTEST_PARALLEL_LEVEL 4) set(US_TEST_SHARED 1) set(US_TEST_STATIC 1) set(US_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../") set(US_BUILD_CONFIGURATION ) -foreach(i RANGE 15) +foreach(i RANGE 7) list(APPEND US_BUILD_CONFIGURATION ${i}) endforeach() include(${US_SOURCE_DIR}/CMake/usCTestScript.cmake) diff --git a/Core/CppMicroServices/CMakeLists.txt b/Core/CppMicroServices/CMakeLists.txt index 2e43cb7b22..5a6c46a53b 100644 --- a/Core/CppMicroServices/CMakeLists.txt +++ b/Core/CppMicroServices/CMakeLists.txt @@ -1,382 +1,462 @@ project(CppMicroServices) -set(${PROJECT_NAME}_MAJOR_VERSION 1) -set(${PROJECT_NAME}_MINOR_VERSION 99) +set(${PROJECT_NAME}_MAJOR_VERSION 2) +set(${PROJECT_NAME}_MINOR_VERSION 0) set(${PROJECT_NAME}_PATCH_VERSION 0) set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_VERSION}) cmake_minimum_required(VERSION 2.8) cmake_policy(VERSION 2.8) cmake_policy(SET CMP0017 NEW) #----------------------------------------------------------------------------- # Update CMake module path #------------------------------------------------------------------------------ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH} ) #----------------------------------------------------------------------------- # CMake function(s) and macro(s) #----------------------------------------------------------------------------- include(CMakeParseArguments) include(CMakePackageConfigHelpers) include(CheckCXXSourceCompiles) include(usFunctionCheckCompilerFlags) include(usFunctionEmbedResources) include(usFunctionGetGccVersion) include(usFunctionGenerateModuleInit) include(usFunctionGenerateExecutableInit) #----------------------------------------------------------------------------- # Init output directories #----------------------------------------------------------------------------- set(US_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") set(US_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") set(US_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") foreach(_type ARCHIVE LIBRARY RUNTIME) if(NOT CMAKE_${_type}_OUTPUT_DIRECTORY) set(CMAKE_${_type}_OUTPUT_DIRECTORY ${US_${_type}_OUTPUT_DIRECTORY}) endif() endforeach() #----------------------------------------------------------------------------- # Set a default build type if none was specified #----------------------------------------------------------------------------- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'Debug' as none was specified.") set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() #----------------------------------------------------------------------------- # CMake options #----------------------------------------------------------------------------- function(us_cache_var _var_name _var_default _var_type _var_help) set(_advanced 0) set(_force) foreach(_argn ${ARGN}) if(_argn STREQUAL ADVANCED) set(_advanced 1) elseif(_argn STREQUAL FORCE) set(_force FORCE) endif() endforeach() if(US_IS_EMBEDDED) if(NOT DEFINED ${_var_name} OR _force) set(${_var_name} ${_var_default} PARENT_SCOPE) endif() else() set(${_var_name} ${_var_default} CACHE ${_var_type} "${_var_help}" ${_force}) if(_advanced) mark_as_advanced(${_var_name}) endif() endif() endfunction() # Determine if we are being build inside a larger project if(NOT DEFINED US_IS_EMBEDDED) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(US_IS_EMBEDDED 0) else() set(US_IS_EMBEDDED 1) set(CppMicroServices_EXPORTS 1) endif() endif() # Determine the name of the install component for "SDK" artifacts. # The default is "sdk" if(NOT DEFINED US_SDK_INSTALL_COMPONENT) set(US_SDK_INSTALL_COMPONENT COMPONENT sdk) elseif(US_SDK_INSTALL_COMPONENT) set(US_SDK_INSTALL_COMPONENT COMPONENT ${US_SDK_INSTALL_COMPONENT}) endif() us_cache_var(US_ENABLE_AUTOLOADING_SUPPORT OFF BOOL "Enable module auto-loading support") us_cache_var(US_ENABLE_THREADING_SUPPORT OFF BOOL "Enable threading support") us_cache_var(US_ENABLE_DEBUG_OUTPUT OFF BOOL "Enable debug messages" ADVANCED) us_cache_var(US_ENABLE_RESOURCE_COMPRESSION ON BOOL "Enable resource compression" ADVANCED) us_cache_var(US_BUILD_SHARED_LIBS ON BOOL "Build shared libraries") us_cache_var(US_BUILD_TESTING OFF BOOL "Build tests") if(WIN32 AND NOT CYGWIN) set(default_runtime_install_dir bin/) set(default_library_install_dir bin/) set(default_archive_install_dir lib/) set(default_header_install_dir include/) set(default_auxiliary_install_dir share/) else() set(default_runtime_install_dir bin/) set(default_library_install_dir lib/${PROJECT_NAME}) set(default_archive_install_dir lib/${PROJECT_NAME}) set(default_header_install_dir include/${PROJECT_NAME}) set(default_auxiliary_install_dir share/${PROJECT_NAME}) endif() us_cache_var(RUNTIME_INSTALL_DIR ${default_runtime_install_dir} STRING "Relative install location for binaries" ADVANCED) us_cache_var(LIBRARY_INSTALL_DIR ${default_library_install_dir} STRING "Relative install location for libraries" ADVANCED) us_cache_var(ARCHIVE_INSTALL_DIR ${default_archive_install_dir} STRING "Relative install location for archives" ADVANCED) us_cache_var(HEADER_INSTALL_DIR ${default_header_install_dir} STRING "Relative install location for headers" ADVANCED) us_cache_var(AUXILIARY_INSTALL_DIR ${default_auxiliary_install_dir} STRING "Relative install location for auxiliary files" ADVANCED) -if(MSVC10 OR MSVC11 OR MSVC12) - # Visual Studio 2010 and newer have support for C++11 enabled by default - set(US_USE_C++11 1) -else() - us_cache_var(US_USE_C++11 OFF BOOL "Enable the use of C++11 features" ADVANCED) -endif() - us_cache_var(US_NAMESPACE "us" STRING "The namespace for the C++ micro services entities") us_cache_var(US_HEADER_PREFIX "" STRING "The file name prefix for the public C++ micro services header files") set(BUILD_SHARED_LIBS ${US_BUILD_SHARED_LIBS}) set(${PROJECT_NAME}_MODULE_INIT_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/CMake/usModuleInit.cpp") set(${PROJECT_NAME}_EXECUTABLE_INIT_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/CMake/usExecutableInit.cpp") #----------------------------------------------------------------------------- # US C/CXX Flags #----------------------------------------------------------------------------- set(US_C_FLAGS) set(US_C_FLAGS_RELEASE) set(US_CXX_FLAGS) set(US_CXX_FLAGS_RELEASE) -# This is used as a preprocessor define -set(US_USE_CXX11 ${US_USE_C++11}) - # Set C++ compiler flags if(NOT MSVC) foreach(_cxxflag -Werror -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo -fdiagnostics-show-option) usFunctionCheckCompilerFlags(${_cxxflag} US_CXX_FLAGS) endforeach() - - if(US_USE_C++11) - usFunctionCheckCompilerFlags("-std=c++0x" US_CXX_FLAGS) - endif() endif() if(CMAKE_COMPILER_IS_GNUCXX) usFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION) if(${GCC_VERSION} VERSION_LESS "4.0.0") message(FATAL_ERROR "gcc version ${GCC_VERSION} not supported. Please use gcc >= 4.") endif() # With older versions of gcc the flag -fstack-protector-all requires an extra dependency to libssp.so. # If the gcc version is lower than 4.4.0 and the build type is Release let's not include the flag. if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0")) usFunctionCheckCompilerFlags("-fstack-protector-all" US_CXX_FLAGS) endif() if(MINGW) # suppress warnings about auto imported symbols set(US_CXX_FLAGS "-Wl,--enable-auto-import ${US_CXX_FLAGS}") # we need to define a Windows version set(US_CXX_FLAGS "-D_WIN32_WINNT=0x0500 ${US_CXX_FLAGS}") else() # Enable visibility support if(NOT ${GCC_VERSION} VERSION_LESS "4.5") usFunctionCheckCompilerFlags("-fvisibility=hidden -fvisibility-inlines-hidden" US_CXX_FLAGS) else() set(US_GCC_RTTI_WORKAROUND_NEEDED 1) endif() endif() usFunctionCheckCompilerFlags("-O1 -D_FORTIFY_SOURCE=2" _fortify_source_flag) if(_fortify_source_flag) set(US_CXX_FLAGS_RELEASE "${US_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") endif() elseif(MSVC) - set(US_CXX_FLAGS "/MP /wd4996 /wd4251 /wd4503 ${US_CXX_FLAGS}") + set(US_CXX_FLAGS "/MP /WX /wd4996 /wd4251 /wd4503 ${US_CXX_FLAGS}") endif() if(NOT US_IS_EMBEDDED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${US_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${US_CXX_FLAGS_RELEASE}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${US_C_FLAGS}") set(CMAKE_C_FLAGS_REALEASE "${CMAKE_C_FLAGS_RELEASE} ${US_C_FLAGS_RELEASE}") endif() #----------------------------------------------------------------------------- # US Link Flags #----------------------------------------------------------------------------- set(US_LINK_FLAGS ) if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) foreach(_linkflag -Wl,--no-undefined) set(_add_flag) usFunctionCheckCompilerFlags("${_linkflag}" _add_flag) if(_add_flag) set(US_LINK_FLAGS "${US_LINK_FLAGS} ${_linkflag}") endif() endforeach() endif() #----------------------------------------------------------------------------- # US Header Checks #----------------------------------------------------------------------------- -include(CheckIncludeFile) +include(CheckIncludeFileCXX) +include(CheckCXXSourceCompiles) -CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT) +CHECK_INCLUDE_FILE_CXX(stdint.h US_HAVE_STDINT_H) +CHECK_INCLUDE_FILE_CXX(tr1/unordered_map US_HAVE_TR1_UNORDERED_MAP_H) +CHECK_INCLUDE_FILE_CXX(tr1/unordered_set US_HAVE_TR1_UNORDERED_SET_H) +CHECK_INCLUDE_FILE_CXX(tr1/functional US_HAVE_TR1_FUNCTIONAL_H) +CHECK_INCLUDE_FILE_CXX(unordered_map US_HAVE_UNORDERED_MAP_H) +CHECK_INCLUDE_FILE_CXX(unordered_set US_HAVE_UNORDERED_SET_H) +CHECK_INCLUDE_FILE_CXX(functional US_HAVE_FUNCTIONAL_H) + +if(US_HAVE_UNORDERED_MAP_H) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::unordered_map m; return 0; }" + US_HAVE_TR1_UNORDERED_MAP) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::unordered_map m; return 0; }" + US_HAVE_STD_UNORDERED_MAP) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::hash(); return 0; }" + US_HAVE_TR1_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::hash(); return 0; }" + US_HAVE_STD_HASH) + if(US_HAVE_STD_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend struct std::hash; }; int main() { return 0; }" + US_HAVE_STD_HASH_STRUCT) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend class std::hash; }; int main() { return 0; }" + US_HAVE_STD_HASH_CLASS) + elseif(US_HAVE_TR1_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend struct std::tr1::hash; }; int main() { return 0; }" + US_HAVE_TR1_HASH_STRUCT) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend class std::tr1::hash; }; int main() { return 0; }" + US_HAVE_TR1_HASH_CLASS) + endif() +elseif(US_HAVE_TR1_UNORDERED_MAP_H) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::unordered_map m; return 0; }" + US_HAVE_TR1_UNORDERED_MAP) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::unordered_map m; return 0; }" + US_HAVE_STD_UNORDERED_MAP) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::hash(); return 0; }" + US_HAVE_TR1_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::hash(); return 0; }" + US_HAVE_STD_HASH) + if(US_HAVE_STD_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend struct std::hash; }; int main() { return 0; }" + US_HAVE_STD_HASH_STRUCT) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend class std::hash; }; int main() { return 0; }" + US_HAVE_STD_HASH_CLASS) + elseif(US_HAVE_TR1_HASH) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend struct std::tr1::hash; }; int main() { return 0; }" + US_HAVE_TR1_HASH_STRUCT) + CHECK_CXX_SOURCE_COMPILES("#include \nstruct A { friend class std::tr1::hash; }; int main() { return 0; }" + US_HAVE_TR1_HASH_CLASS) + endif() +else() + message(SEND_ERROR "The header file \"unordered_map\" is not available.") +endif() +if(NOT (US_HAVE_TR1_UNORDERED_MAP OR US_HAVE_STD_UNORDERED_MAP)) + message(SEND_ERROR "The \"unordered_map\" type is not available.") +endif() + +if(US_HAVE_UNORDERED_SET_H) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::unordered_set s; return 0; }" + US_HAVE_TR1_UNORDERED_SET) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::unordered_set s; return 0; }" + US_HAVE_STD_UNORDERED_SET) +elseif(US_HAVE_TR1_UNORDERED_SET_H) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::unordered_set s; return 0; }" + US_HAVE_TR1_UNORDERED_SET) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::unordered_set s; return 0; }" + US_HAVE_STD_UNORDERED_SET) +else() + message(SEND_ERROR "The header file \"unordered_set\" is not available.") +endif() +if(NOT (US_HAVE_TR1_UNORDERED_SET OR US_HAVE_STD_UNORDERED_SET)) + message(SEND_ERROR "The \"unordered_set\" type is not available.") +endif() + +if(NOT (US_HAVE_FUNCTIONAL_H OR US_HAVE_TR1_FUNCTIONAL_H)) + message(SEND_ERROR "The header file \"functional\" is not available.") +endif() + +if(US_HAVE_FUNCTIONAL_H) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::function f(main); return 0; }" + US_HAVE_TR1_FUNCTION) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::function f(main); return 0; }" + US_HAVE_STD_FUNCTION) +endif() +if((NOT (US_HAVE_STD_FUNCTION OR US_HAVE_TR1_FUNCTION)) AND US_HAVE_TR1_FUNCTIONAL_H) + unset(US_HAVE_TR1_FUNCTION CACHE) + unset(US_HAVE_STD_FUNCTION CACHE) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::tr1::function f(main); return 0; }" + US_HAVE_TR1_FUNCTION) + CHECK_CXX_SOURCE_COMPILES("#include \nint main() { std::function f(main); return 0; }" + US_HAVE_STD_FUNCTION) +endif() + +if(NOT (US_HAVE_STD_FUNCTION OR US_HAVE_TR1_FUNCTION)) + message(SEND_ERROR "The \"function\" type is not available.") +endif() #----------------------------------------------------------------------------- # US include dirs and libraries #----------------------------------------------------------------------------- set(US_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/include ) set(US_INTERNAL_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src/util ${CMAKE_CURRENT_SOURCE_DIR}/src/service ${CMAKE_CURRENT_SOURCE_DIR}/src/module ) # link library for third party libs if(US_IS_EMBEDDED) set(US_LIBRARY_TARGET ${US_EMBEDDING_LIBRARY}) else() set(US_LIBRARY_TARGET ${PROJECT_NAME}) endif() # link libraries for the CppMicroServices lib set(US_LINK_LIBRARIES ) if(UNIX) list(APPEND US_LINK_LIBRARIES dl) endif() #----------------------------------------------------------------------------- # Source directory #----------------------------------------------------------------------------- set(us_config_h_file "${PROJECT_BINARY_DIR}/include/usConfig.h") configure_file(usConfig.h.in ${us_config_h_file}) set(US_RCC_EXECUTABLE_NAME usResourceCompiler) set(CppMicroServices_RCC_EXECUTABLE_NAME ${US_RCC_EXECUTABLE_NAME}) add_subdirectory(tools) add_subdirectory(src) #----------------------------------------------------------------------------- # US testing #----------------------------------------------------------------------------- if(US_BUILD_TESTING) enable_testing() add_subdirectory(test) endif() #----------------------------------------------------------------------------- # Documentation #----------------------------------------------------------------------------- add_subdirectory(documentation) #----------------------------------------------------------------------------- # Last configuration and install steps #----------------------------------------------------------------------------- if(NOT US_IS_EMBEDDED) export(TARGETS ${PROJECT_NAME} ${US_RCC_EXECUTABLE_NAME} FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake) install(EXPORT ${PROJECT_NAME}Targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${AUXILIARY_INSTALL_DIR}/CMake/) endif() set(_install_cmake_scripts ${${PROJECT_NAME}_MODULE_INIT_TEMPLATE} ${${PROJECT_NAME}_EXECUTABLE_INIT_TEMPLATE} ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CMakeParseArguments.cmake ${CMAKE_CURRENT_SOURCE_DIR}/CMake/usFunctionGenerateModuleInit.cmake ${CMAKE_CURRENT_SOURCE_DIR}/CMake/usFunctionGenerateExecutableInit.cmake ${CMAKE_CURRENT_SOURCE_DIR}/CMake/usFunctionEmbedResources.cmake ) install(FILES ${_install_cmake_scripts} DESTINATION ${AUXILIARY_INSTALL_DIR}/CMake/ ) # Configure CppMicroServicesConfig.cmake for the build tree set(PACKAGE_CONFIG_INCLUDE_DIR ${US_INCLUDE_DIRS}) set(PACKAGE_CONFIG_RUNTIME_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set(PACKAGE_CONFIG_CMAKE_DIR ${PROJECT_SOURCE_DIR}/CMake) if(US_IS_EMBEDDED) set(PACKAGE_EMBEDDED "if(@PROJECT_NAME@_IS_EMBEDDED) set(@PROJECT_NAME@_INTERNAL_INCLUDE_DIRS @US_INTERNAL_INCLUDE_DIRS@) set(@PROJECT_NAME@_SOURCES @US_SOURCES@) set(@PROJECT_NAME@_PUBLIC_HEADERS @US_PUBLIC_HEADERS@) set(@PROJECT_NAME@_PRIVATE_HEADERS @US_PRIVATE_HEADERS@) endif()") else() set(PACKAGE_EMBEDDED ) endif() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY ) # Configure CppMicroServicesConfig.cmake for the install tree set(CONFIG_INCLUDE_DIR ${HEADER_INSTALL_DIR}) set(CONFIG_RUNTIME_DIR ${RUNTIME_INSTALL_DIR}) set(CONFIG_CMAKE_DIR ${AUXILIARY_INSTALL_DIR}/CMake) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${AUXILIARY_INSTALL_DIR}/CMake/ PATH_VARS CONFIG_INCLUDE_DIR CONFIG_RUNTIME_DIR CONFIG_CMAKE_DIR NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO ) # Version information configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}ConfigVersion.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake @ONLY ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION ${AUXILIARY_INSTALL_DIR}/CMake/ ${US_SDK_INSTALL_COMPONENT} ) #----------------------------------------------------------------------------- # Build the examples #----------------------------------------------------------------------------- option(US_BUILD_EXAMPLES "Build example projects" OFF) if(US_BUILD_EXAMPLES) if(NOT US_BUILD_SHARED_LIBS) message(WARNING "Examples are not available if US_BUILD_SHARED_LIBS is OFF") else() set(CppMicroServices_DIR ${PROJECT_BINARY_DIR}) add_subdirectory(examples) endif() endif() diff --git a/Core/CppMicroServices/CppMicroServicesConfig.cmake.in b/Core/CppMicroServices/CppMicroServicesConfig.cmake.in index 0a8e57d74d..45c131937a 100644 --- a/Core/CppMicroServices/CppMicroServicesConfig.cmake.in +++ b/Core/CppMicroServices/CppMicroServicesConfig.cmake.in @@ -1,36 +1,34 @@ @PACKAGE_INIT@ -set(@PROJECT_NAME@_USE_CXX11 @US_USE_CXX11@) - set(@PROJECT_NAME@_CXX_FLAGS "@US_CXX_FLAGS@") set(@PROJECT_NAME@_CXX_FLAGS_RELEASE "@US_CXX_FLAGS_RELEASE@") set(@PROJECT_NAME@_CXX_FLAGS_DEBUG "@US_CXX_FLAGS_DEBUG@") set(@PROJECT_NAME@_C_FLAGS "@US_C_FLAGS@") set(@PROJECT_NAME@_C_FLAGS_RELEASE "@US_C_FLAGS_RELEASE@") set(@PROJECT_NAME@_C_FLAGS_DEBUG "@US_C_FLAGS_DEBUG@") set(@PROJECT_NAME@_INCLUDE_DIR @PACKAGE_CONFIG_INCLUDE_DIR@) set(@PROJECT_NAME@_RCC_EXECUTABLE_NAME @CppMicroServices_RCC_EXECUTABLE_NAME@) set(@PROJECT_NAME@_MODULE_INIT_TEMPLATE @PACKAGE_CONFIG_CMAKE_DIR@/usModuleInit.cpp) set(@PROJECT_NAME@_EXECUTABLE_INIT_TEMPLATE @PACKAGE_CONFIG_CMAKE_DIR@/usExecutableInit.cpp) set(@PROJECT_NAME@_INCLUDE_DIRS ${@PROJECT_NAME@_INCLUDE_DIR}) set(@PROJECT_NAME@_LIBRARIES @US_LIBRARY_TARGET@) find_program(@PROJECT_NAME@_RCC_EXECUTABLE ${@PROJECT_NAME@_RCC_EXECUTABLE_NAME} PATHS "@PACKAGE_CONFIG_RUNTIME_DIR@" PATH_SUFFIXES Release Debug RelWithDebInfo MinSizeRel) mark_as_advanced(@PROJECT_NAME@_RCC_EXECUTABLE) set(@PROJECT_NAME@_IS_EMBEDDED @US_IS_EMBEDDED@) @PACKAGE_EMBEDDED@ if(NOT TARGET @PROJECT_NAME@ AND NOT @PROJECT_NAME@_IS_EMBEDDED) include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake) endif() include(@PACKAGE_CONFIG_CMAKE_DIR@/CMakeParseArguments.cmake) include(@PACKAGE_CONFIG_CMAKE_DIR@/usFunctionGenerateModuleInit.cmake) include(@PACKAGE_CONFIG_CMAKE_DIR@/usFunctionGenerateExecutableInit.cmake) include(@PACKAGE_CONFIG_CMAKE_DIR@/usFunctionEmbedResources.cmake) diff --git a/Core/CppMicroServices/documentation/doxygen/standalone/BuildInstructions.md b/Core/CppMicroServices/documentation/doxygen/standalone/BuildInstructions.md index 99f4d7d581..c76fbeefc8 100644 --- a/Core/CppMicroServices/documentation/doxygen/standalone/BuildInstructions.md +++ b/Core/CppMicroServices/documentation/doxygen/standalone/BuildInstructions.md @@ -1,59 +1,57 @@ Build Instructions {#BuildInstructions} ================== The C++ Micro Services library provides [CMake][cmake] build scripts which allow the generation of platform and IDE specific project files. The library should compile on many different platforms. Below is a list of tested compiler/OS combinations: - GCC 4.5 (Ubuntu 11.04 and MacOS X 10.6) - GCC 4.7 (Ubuntu 12.10) - Visual Studio 2008, 2010, and 2012 - Clang 3.0 (Ubuntu 12.10 and MacOS X 10.6) Prerequisites ------------- - [CMake][cmake] 2.8 (Visual Studio 2010 and 2012 users should use the latest CMake version available) Configuring the Build --------------------- When building the C++ Micro Services library, you have a few configuration options at hand. ### General build options - **CMAKE_INSTALL_PREFIX** The installation path. - **US_BUILD_SHARED_LIBS** Specify if the library should be build shared or static. See \ref MicroServices_StaticModules for detailed information about static CppMicroServices modules. - **US_BUILD_TESTING** Build unit tests and code snippets. - **US_ENABLE_AUTOLOADING_SUPPORT** Enable auto-loading of modules located in special sub-directories. See \ref MicroServices_AutoLoading for detailed information about this feature. - **US_ENABLE_THREADING_SUPPORT** Enable the use of synchronization primitives (atomics and pthread mutexes or Windows primitives) to make the API thread-safe. If your application is not multi-threaded, turn this option OFF to get maximum performance. -- **US_USE_C++11 (advanced)** - Enable the usage of C++11 constructs. - **US_ENABLE_RESOURCE_COMPRESSION (advanced)** Enable compression of embedded resources. See \ref MicroServices_Resources for detailed information about the resource system. ### Customizing naming conventions - **US_NAMESPACE** The default namespace is `us` but you may override this at will. - **US_HEADER_PREFIX** By default, all public headers have a "us" prefix. You may specify an arbitrary prefix to match your naming conventions. The above options are mainly useful when embedding the C++ Micro Services source code in your own library and you want to make it look like native source code. [cmake]: http://www.cmake.org diff --git a/Core/CppMicroServices/src/CMakeLists.txt b/Core/CppMicroServices/src/CMakeLists.txt index 37a740200f..dae249894e 100644 --- a/Core/CppMicroServices/src/CMakeLists.txt +++ b/Core/CppMicroServices/src/CMakeLists.txt @@ -1,212 +1,213 @@ #----------------------------------------------------------------------------- # US source files #----------------------------------------------------------------------------- set(_srcs util/usAny.cpp util/jsoncpp.cpp util/usLDAPProp.cpp util/usSharedLibrary.cpp util/usUncompressResourceData.c util/usUncompressResourceData.cpp util/usUtils.cpp service/usLDAPExpr.cpp service/usLDAPFilter.cpp service/usServiceException.cpp service/usServiceEvent.cpp service/usServiceEventListenerHook.cpp service/usServiceFindHook.cpp service/usServiceHooks.cpp service/usServiceListenerEntry.cpp service/usServiceListenerEntry_p.h service/usServiceListenerHook.cpp service/usServiceListeners.cpp service/usServiceListeners_p.h service/usServiceObjects.cpp service/usServiceProperties.cpp service/usServicePropertiesImpl.cpp service/usServiceReferenceBase.cpp service/usServiceReferenceBasePrivate.cpp service/usServiceRegistrationBase.cpp service/usServiceRegistrationBasePrivate.cpp service/usServiceRegistry.cpp service/usServiceRegistry_p.h module/usCoreModuleActivator.cpp module/usCoreModuleContext_p.h module/usCoreModuleContext.cpp module/usModuleContext.cpp module/usModule.cpp module/usModuleEvent.cpp module/usModuleEventHook.cpp module/usModuleFindHook.cpp module/usModuleHooks.cpp module/usModuleInfo.cpp module/usModuleManifest.cpp module/usModulePrivate.cpp module/usModuleRegistry.cpp module/usModuleResource.cpp module/usModuleResourceBuffer.cpp module/usModuleResourceStream.cpp module/usModuleResourceTree.cpp module/usModuleSettings.cpp module/usModuleUtils.cpp module/usModuleVersion.cpp ) set(_private_headers util/usAtomicInt_p.h - util/usFunctor_p.h util/usListenerFunctors_p.h util/usLog_p.h util/usStaticInit_p.h util/usThreads_p.h util/usUtils_p.h util/usWaitCondition_p.h util/dirent_win32_p.h util/stdint_p.h util/stdint_vc_p.h service/usServiceHooks_p.h service/usServiceListenerHook_p.h service/usServicePropertiesImpl_p.h service/usServiceTracker.tpp service/usServiceTrackerPrivate.h service/usServiceTrackerPrivate.tpp service/usTrackedService_p.h service/usTrackedServiceListener_p.h service/usTrackedService.tpp module/usModuleAbstractTracked_p.h module/usModuleAbstractTracked.tpp module/usModuleHooks_p.h module/usModuleResourceBuffer_p.h module/usModuleResourceTree_p.h module/usModuleUtils_p.h ) set(_public_headers util/usAny.h util/usLDAPProp.h util/usSharedData.h util/usSharedLibrary.h util/usShrinkableMap.h util/usShrinkableVector.h util/usUncompressResourceData.h service/usLDAPFilter.h service/usPrototypeServiceFactory.h service/usServiceEvent.h service/usServiceEventListenerHook.h service/usServiceException.h service/usServiceFactory.h service/usServiceFindHook.h service/usServiceInterface.h service/usServiceListenerHook.h service/usServiceObjects.h service/usServiceProperties.h service/usServiceReference.h service/usServiceReferenceBase.h service/usServiceRegistration.h service/usServiceRegistrationBase.h service/usServiceTracker.h service/usServiceTrackerCustomizer.h module/usGetModuleContext.h module/usModule.h module/usModuleActivator.h module/usModuleContext.h module/usModuleEvent.h module/usModuleEventHook.h module/usModuleFindHook.h module/usModuleImport.h module/usModuleInfo.h module/usModuleInitialization.h module/usModuleRegistry.h module/usModuleResource.h module/usModuleResourceStream.h module/usModuleSettings.h module/usModuleVersion.h ) if(US_IS_EMBEDDED) set(US_SOURCES ) get_filename_component(_path_prefix "${PROJECT_SOURCE_DIR}" NAME) set(_path_prefix "${_path_prefix}/src") foreach(_src ${_srcs} ${_public_headers} ${_private_headers}) list(APPEND US_SOURCES ${_path_prefix}/${_src}) endforeach() set(US_SOURCES ${US_SOURCES} PARENT_SCOPE) endif() #----------------------------------------------------------------------------- # Create library (only if not in embedded mode) #----------------------------------------------------------------------------- if(NOT US_IS_EMBEDDED) include_directories(${US_INTERNAL_INCLUDE_DIRS}) usFunctionGenerateModuleInit(_srcs NAME ${PROJECT_NAME}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/resources/manifest.json.in + ${CMAKE_CURRENT_BINARY_DIR}/resources/manifest.json) usFunctionEmbedResources(_srcs LIBRARY_NAME ${PROJECT_NAME} - ROOT_DIR resources + ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/resources FILES manifest.json) add_library(${PROJECT_NAME} ${_srcs} ${_public_headers} ${_private_headers} ${us_config_h_file}) if(US_LINK_FLAGS) set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${US_LINK_FLAGS}") endif() set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS US_FORCE_MODULE_INIT) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${${PROJECT_NAME}_VERSION} ) if(US_LINK_LIBRARIES) target_link_libraries(${PROJECT_NAME} ${US_LINK_LIBRARIES}) endif() endif() #----------------------------------------------------------------------------- # Configure public header wrappers #----------------------------------------------------------------------------- set(US_PUBLIC_HEADERS ${_public_headers}) if(US_HEADER_PREFIX) set(US_PUBLIC_HEADERS ) foreach(_public_header ${_public_headers}) get_filename_component(_public_header_basename ${_public_header} NAME_WE) set(_us_public_header ${_public_header_basename}.h) string(SUBSTRING "${_public_header_basename}" 2 -1 _public_header_basename) set(_header_wrapper "${PROJECT_BINARY_DIR}/include/${US_HEADER_PREFIX}${_public_header_basename}.h") configure_file(${PROJECT_SOURCE_DIR}/CMake/usPublicHeaderWrapper.h.in ${_header_wrapper} @ONLY) list(APPEND US_PUBLIC_HEADERS ${_header_wrapper}) endforeach() endif() foreach(_header ${_public_headers} ${_private_headers}) get_filename_component(_header_name "${_header}" NAME) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${_header} "${PROJECT_BINARY_DIR}/include/${_header_name}") endforeach() if(NOT US_IS_EMBEDDED) set_property(TARGET ${PROJECT_NAME} PROPERTY PUBLIC_HEADER ${US_PUBLIC_HEADERS}) set_property(TARGET ${PROJECT_NAME} PROPERTY PRIVATE_HEADER ${_private_headers} ${us_config_h_file}) else() set(US_PUBLIC_HEADERS ${US_PUBLIC_HEADERS} PARENT_SCOPE) set(US_PRIVATE_HEADERS ${US_PRIVATE_HEADERS} PARENT_SCOPE) endif() #----------------------------------------------------------------------------- # Install support (only if not in embedded mode) #----------------------------------------------------------------------------- if(NOT US_IS_EMBEDDED) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT} LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT} ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT} PUBLIC_HEADER DESTINATION ${HEADER_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT} PRIVATE_HEADER DESTINATION ${HEADER_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT}) endif() diff --git a/Core/CppMicroServices/src/resources/manifest.json b/Core/CppMicroServices/src/resources/manifest.json deleted file mode 100644 index b2359aec43..0000000000 --- a/Core/CppMicroServices/src/resources/manifest.json +++ /dev/null @@ -1 +0,0 @@ -{ "module.version" : "1.99.0" } diff --git a/Core/CppMicroServices/src/resources/manifest.json.in b/Core/CppMicroServices/src/resources/manifest.json.in new file mode 100644 index 0000000000..86982a461b --- /dev/null +++ b/Core/CppMicroServices/src/resources/manifest.json.in @@ -0,0 +1 @@ +{ "module.version" : "@CppMicroServices_VERSION@" } diff --git a/Core/CppMicroServices/src/util/stdint_p.h b/Core/CppMicroServices/src/util/stdint_p.h index 242332bac2..b0238abc1b 100644 --- a/Core/CppMicroServices/src/util/stdint_p.h +++ b/Core/CppMicroServices/src/util/stdint_p.h @@ -1,33 +1,33 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USSTDINT_H #define USSTDINT_H -#ifdef HAVE_STDINT +#ifdef US_HAVE_STDINT_H #include #elif defined(_MSC_VER) #include "stdint_vc_p.h" #else #error The stdint.h header is not available #endif #endif // USSTDINT_H diff --git a/Core/CppMicroServices/src/util/usFunctor_p.h b/Core/CppMicroServices/src/util/usFunctor_p.h deleted file mode 100644 index 0fc5a5c78b..0000000000 --- a/Core/CppMicroServices/src/util/usFunctor_p.h +++ /dev/null @@ -1,160 +0,0 @@ -/*============================================================================= - - Library: CppMicroServices - - Copyright (c) German Cancer Research Center, - Division of Medical and Biological Informatics - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -=============================================================================*/ - - -#ifndef USFUNCTOR_H -#define USFUNCTOR_H - -#include - -US_BEGIN_NAMESPACE - -template -class FunctorImpl -{ -public: - - virtual void operator()(Arg) = 0; - virtual FunctorImpl* Clone() const = 0; - - bool operator==(const FunctorImpl& o) const - { return typeid(*this) == typeid(o) && IsEqual(o); } - - virtual ~FunctorImpl() {} - - virtual void* target() const = 0; - -private: - - virtual bool IsEqual(const FunctorImpl& o) const = 0; -}; - -template -class FunctorHandler : public FunctorImpl -{ -public: - - FunctorHandler(const Fun& fun) : m_Fun(fun) {} - - FunctorHandler* Clone() const - { return new FunctorHandler(*this); } - - void operator()(Arg a) - { m_Fun(a); } - - void* target() const - { - void* result = NULL; - std::memcpy(&result, &m_Fun, sizeof(void*)); - return result; - } - -private: - - bool IsEqual(const FunctorImpl& o) const - { return this->m_Fun == static_cast(o).m_Fun; } - - Fun m_Fun; -}; - -template -class MemFunHandler : public FunctorImpl -{ -public: - - MemFunHandler(const PointerToObj& pObj, PointerToMemFn pMemFn) - : m_pObj(pObj), m_pMemFn(pMemFn) - {} - - MemFunHandler* Clone() const - { return new MemFunHandler(*this); } - - void operator()(Arg a) - { ((*m_pObj).*m_pMemFn)(a); } - - void* target() const - { - void* result = NULL; - std::memcpy(&result, &m_pMemFn, sizeof(void*)); - return result; - } - -private: - - bool IsEqual(const FunctorImpl& o) const - { return this->m_pObj == static_cast(o).m_pObj && - this->m_pMemFn == static_cast(o).m_pMemFn; } - - PointerToObj m_pObj; - PointerToMemFn m_pMemFn; - -}; - -template -class Functor -{ -public: - - Functor() : m_Impl(0) {} - - template - Functor(const Fun& fun) - : m_Impl(new FunctorHandler(fun)) - {} - - template - Functor(const PtrObj& p, MemFn memFn) - : m_Impl(new MemFunHandler(p, memFn)) - {} - - Functor(const Functor& f) : m_Impl(f.m_Impl->Clone()) {} - - Functor& operator=(const Functor& f) - { - Impl* tmp = f.m_Impl->Clone(); - std::swap(tmp, m_Impl); - delete tmp; - } - - bool operator==(const Functor& f) const - { return (*m_Impl) == (*f.m_Impl); } - - ~Functor() { delete m_Impl; } - - void operator()(Arg a) - { - (*m_Impl)(a); - } - - void* target() const - { - return m_Impl->target(); - } - -private: - - typedef FunctorImpl Impl; - Impl* m_Impl; -}; - -US_END_NAMESPACE - -#endif // USFUNCTOR_H diff --git a/Core/CppMicroServices/src/util/usListenerFunctors_p.h b/Core/CppMicroServices/src/util/usListenerFunctors_p.h index 385ad8cf58..4f6037e317 100644 --- a/Core/CppMicroServices/src/util/usListenerFunctors_p.h +++ b/Core/CppMicroServices/src/util/usListenerFunctors_p.h @@ -1,136 +1,86 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USLISTENERFUNCTORS_P_H #define USLISTENERFUNCTORS_P_H #include #include #include #include #include -#if defined(US_USE_CXX11) || defined(__GNUC__) - - #ifdef US_USE_CXX11 - #include - #define US_MODULE_LISTENER_FUNCTOR std::function - #define US_SERVICE_LISTENER_FUNCTOR std::function - #else - #include - #define US_MODULE_LISTENER_FUNCTOR std::tr1::function - #define US_SERVICE_LISTENER_FUNCTOR std::tr1::function - #endif - - US_BEGIN_NAMESPACE - template - US_MODULE_LISTENER_FUNCTOR ModuleListenerMemberFunctor(X* x, void (X::*memFn)(const US_PREPEND_NAMESPACE(ModuleEvent))) - { return std::bind1st(std::mem_fun(memFn), x); } - US_END_NAMESPACE - - US_BEGIN_NAMESPACE - struct ModuleListenerCompare : std::binary_function, - std::pair, bool> - { - bool operator()(const std::pair& p1, - const std::pair& p2) const - { - return p1.second == p2.second && - p1.first.target() == p2.first.target(); - } - }; - US_END_NAMESPACE - - US_BEGIN_NAMESPACE - template - US_SERVICE_LISTENER_FUNCTOR ServiceListenerMemberFunctor(X* x, void (X::*memFn)(const US_PREPEND_NAMESPACE(ServiceEvent))) - { return std::bind1st(std::mem_fun(memFn), x); } - US_END_NAMESPACE - - US_BEGIN_NAMESPACE - struct ServiceListenerCompare : std::binary_function - { - bool operator()(const US_SERVICE_LISTENER_FUNCTOR& f1, - const US_SERVICE_LISTENER_FUNCTOR& f2) const - { - return f1.target() == f2.target(); - } - }; - US_END_NAMESPACE - - US_HASH_FUNCTION_NAMESPACE_BEGIN - US_HASH_FUNCTION_BEGIN(US_SERVICE_LISTENER_FUNCTOR) - void(*targetFunc)(const US_PREPEND_NAMESPACE(ServiceEvent)&) = arg.target(); - void* targetPtr = NULL; - std::memcpy(&targetPtr, &targetFunc, sizeof(void*)); - return US_HASH_FUNCTION(void*, targetPtr); - US_HASH_FUNCTION_END - US_HASH_FUNCTION_NAMESPACE_END - -#else - - #include - - #define US_MODULE_LISTENER_FUNCTOR US_PREPEND_NAMESPACE(Functor) - - US_BEGIN_NAMESPACE - template - US_MODULE_LISTENER_FUNCTOR ModuleListenerMemberFunctor(X* x, MemFn memFn) - { return Functor(x, memFn); } - US_END_NAMESPACE - - US_BEGIN_NAMESPACE - struct ModuleListenerCompare : std::binary_function, - std::pair, bool> - { - bool operator()(const std::pair& p1, - const std::pair& p2) const - { return p1.second == p2.second && p1.first == p2.first; } - }; - US_END_NAMESPACE - - #define US_SERVICE_LISTENER_FUNCTOR US_PREPEND_NAMESPACE(Functor) - - US_BEGIN_NAMESPACE - template - US_SERVICE_LISTENER_FUNCTOR ServiceListenerMemberFunctor(X* x, MemFn memFn) - { return Functor(x, memFn); } - US_END_NAMESPACE - - US_BEGIN_NAMESPACE - struct ServiceListenerCompare : std::binary_function - { - bool operator()(const US_SERVICE_LISTENER_FUNCTOR& f1, - const US_SERVICE_LISTENER_FUNCTOR& f2) const - { return f1 == f2; } - }; - US_END_NAMESPACE - - US_HASH_FUNCTION_NAMESPACE_BEGIN - US_HASH_FUNCTION_BEGIN(US_SERVICE_LISTENER_FUNCTOR) - return US_HASH_FUNCTION(void*, reinterpret_cast(arg.target())); - US_HASH_FUNCTION_END - US_HASH_FUNCTION_NAMESPACE_END +#ifdef US_HAVE_TR1_FUNCTIONAL_H + #include +#elif defined(US_HAVE_FUNCTIONAL_H) + #include +#endif +#ifdef US_HAVE_STD_FUNCTION + #define US_FUNCTION_TYPE std::function +#elif defined(US_HAVE_TR1_FUNCTION) + #define US_FUNCTION_TYPE std::tr1::function #endif +#define US_MODULE_LISTENER_FUNCTOR US_FUNCTION_TYPE +#define US_SERVICE_LISTENER_FUNCTOR US_FUNCTION_TYPE + +US_BEGIN_NAMESPACE + template + US_MODULE_LISTENER_FUNCTOR ModuleListenerMemberFunctor(X* x, void (X::*memFn)(const US_PREPEND_NAMESPACE(ModuleEvent))) + { return std::bind1st(std::mem_fun(memFn), x); } + + struct ModuleListenerCompare : std::binary_function, + std::pair, bool> + { + bool operator()(const std::pair& p1, + const std::pair& p2) const + { + return p1.second == p2.second && + p1.first.target() == p2.first.target(); + } + }; + + template + US_SERVICE_LISTENER_FUNCTOR ServiceListenerMemberFunctor(X* x, void (X::*memFn)(const US_PREPEND_NAMESPACE(ServiceEvent))) + { return std::bind1st(std::mem_fun(memFn), x); } + + struct ServiceListenerCompare : std::binary_function + { + bool operator()(const US_SERVICE_LISTENER_FUNCTOR& f1, + const US_SERVICE_LISTENER_FUNCTOR& f2) const + { + return f1.target() == f2.target(); + } + }; +US_END_NAMESPACE + +US_HASH_FUNCTION_NAMESPACE_BEGIN +US_HASH_FUNCTION_BEGIN(US_SERVICE_LISTENER_FUNCTOR) + void(*targetFunc)(const US_PREPEND_NAMESPACE(ServiceEvent)&) = arg.target(); + void* targetPtr = NULL; + std::memcpy(&targetPtr, &targetFunc, sizeof(void*)); + return US_HASH_FUNCTION(void*, targetPtr); +US_HASH_FUNCTION_END +US_HASH_FUNCTION_NAMESPACE_END + #endif // USLISTENERFUNCTORS_P_H diff --git a/Core/CppMicroServices/test/usModuleTest.cpp b/Core/CppMicroServices/test/usModuleTest.cpp index ef04695e9f..98cbf2cf3f 100644 --- a/Core/CppMicroServices/test/usModuleTest.cpp +++ b/Core/CppMicroServices/test/usModuleTest.cpp @@ -1,342 +1,343 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include #include #include #include #include #include "usTestUtilModuleListener.h" #include "usTestingMacros.h" #include "usTestingConfig.h" US_USE_NAMESPACE namespace { #ifdef US_PLATFORM_WINDOWS static const std::string LIB_PATH = US_RUNTIME_OUTPUT_DIRECTORY; static const char PATH_SEPARATOR = '\\'; #else static const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY; static const char PATH_SEPARATOR = '/'; #endif // Verify that the same member function pointers registered as listeners // with different receivers works. void frame02a() { ModuleContext* mc = GetModuleContext(); TestModuleListener listener1; TestModuleListener listener2; try { mc->RemoveModuleListener(&listener1, &TestModuleListener::ModuleChanged); mc->AddModuleListener(&listener1, &TestModuleListener::ModuleChanged); mc->RemoveModuleListener(&listener2, &TestModuleListener::ModuleChanged); mc->AddModuleListener(&listener2, &TestModuleListener::ModuleChanged); } catch (const std::logic_error& ise) { US_TEST_FAILED_MSG( << "module listener registration failed " << ise.what() << " : frameSL02a:FAIL" ); } SharedLibrary target(LIB_PATH, "TestModuleA"); #ifdef US_BUILD_SHARED_LIBS // Start the test target try { target.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG( << "Failed to load module, got exception: " << e.what() << " + in frameSL02a:FAIL" ); } Module* moduleA = ModuleRegistry::GetModule("TestModuleA Module"); US_TEST_CONDITION_REQUIRED(moduleA != 0, "Test for existing module TestModuleA") #endif std::vector pEvts; #ifdef US_BUILD_SHARED_LIBS pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleA)); pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleA)); #endif std::vector seEvts; US_TEST_CONDITION(listener1.CheckListenerEvents(pEvts, seEvts), "Check first module listener") US_TEST_CONDITION(listener2.CheckListenerEvents(pEvts, seEvts), "Check second module listener") mc->RemoveModuleListener(&listener1, &TestModuleListener::ModuleChanged); mc->RemoveModuleListener(&listener2, &TestModuleListener::ModuleChanged); target.Unload(); } // Verify information from the ModuleInfo struct void frame005a(ModuleContext* mc) { Module* m = mc->GetModule(); // check expected headers #ifdef US_BUILD_SHARED_LIBS - US_TEST_CONDITION("CppMicroServicesTestDriver" == m->GetName(), "Test module name"); - US_TEST_CONDITION(ModuleVersion(0,1,0) == m->GetVersion(), "Test module version") + US_TEST_CONDITION("CppMicroServicesTestDriver" == m->GetName(), "Test module name") + US_TEST_CONDITION(ModuleVersion(0,1,0) == m->GetVersion(), "Test test driver module version") + US_TEST_CONDITION(ModuleVersion(CppMicroServices_MAJOR_VERSION, CppMicroServices_MINOR_VERSION, CppMicroServices_PATCH_VERSION) == ModuleRegistry::GetModule(1)->GetVersion(), "Test CppMicroServices version") #else - US_TEST_CONDITION("CppMicroServices" == m->GetName(), "Test module name"); - US_TEST_CONDITION(ModuleVersion(1,99,0) == m->GetVersion(), "Test module version") + US_TEST_CONDITION("CppMicroServices" == m->GetName(), "Test module name") + US_TEST_CONDITION(ModuleVersion(CppMicroServices_MAJOR_VERSION, CppMicroServices_MINOR_VERSION, CppMicroServices_PATCH_VERSION) == m->GetVersion(), "Test module version") #endif } // Get context id, location and status of the module void frame010a(ModuleContext* mc) { Module* m = mc->GetModule(); long int contextid = m->GetModuleId(); US_DEBUG << "CONTEXT ID:" << contextid; std::string location = m->GetLocation(); US_DEBUG << "LOCATION:" << location; US_TEST_CONDITION(!location.empty(), "Test for non-empty module location") US_TEST_CONDITION(m->IsLoaded(), "Test for loaded flag") US_TEST_CONDITION(ModuleSettings::GetStoragePath().empty(), "Test for empty base storage path") US_TEST_CONDITION(m->GetModuleContext()->GetDataFile("").empty(), "Test for empty data path") US_TEST_CONDITION(m->GetModuleContext()->GetDataFile("bla").empty(), "Test for empty data file path") } //---------------------------------------------------------------------------- //Test result of GetService(ServiceReference()). Should throw std::invalid_argument void frame018a(ModuleContext* mc) { try { mc->GetService(ServiceReferenceU()); US_DEBUG << "Got service object, expected std::invalid_argument exception"; US_TEST_FAILED_MSG(<< "Got service object, excpected std::invalid_argument exception") } catch (const std::invalid_argument& ) {} catch (...) { US_TEST_FAILED_MSG(<< "Got wrong exception, expected std::invalid_argument") } } // Load libA and check that it exists and that the service it registers exists, // also check that the expected events occur and that the storage paths are correct void frame020a(ModuleContext* mc, TestModuleListener& listener, #ifdef US_BUILD_SHARED_LIBS SharedLibrary& libA) { ModuleSettings::SetStoragePath(std::string("/tmp") + PATH_SEPARATOR); US_TEST_CONDITION(ModuleSettings::GetStoragePath() == "/tmp", "Test for valid base storage path") try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } Module* moduleA = ModuleRegistry::GetModule("TestModuleA Module"); US_TEST_CONDITION_REQUIRED(moduleA != 0, "Test for existing module TestModuleA") US_TEST_CONDITION(moduleA->GetName() == "TestModuleA Module", "Test module name") std::cout << moduleA->GetModuleContext()->GetDataFile(""); std::stringstream ss; ss << moduleA->GetModuleId(); const std::string baseStoragePath = std::string("/tmp") + PATH_SEPARATOR + ss.str() + "_TestModuleA" + PATH_SEPARATOR; US_TEST_CONDITION(moduleA->GetModuleContext()->GetDataFile("") == baseStoragePath, "Test for valid data path") US_TEST_CONDITION(moduleA->GetModuleContext()->GetDataFile("bla") == baseStoragePath + "bla", "Test for valid data file path") #else SharedLibrary& /*libA*/) { #endif // Check if libA registered the expected service try { ServiceReferenceU sr1 = mc->GetServiceReference("org.cppmicroservices.TestModuleAService"); InterfaceMap o1 = mc->GetService(sr1); US_TEST_CONDITION(!o1.empty(), "Test if service object found"); try { US_TEST_CONDITION(mc->UngetService(sr1), "Test if Service UnGet returns true"); } catch (const std::logic_error le) { US_TEST_FAILED_MSG(<< "UnGetService exception: " << le.what()) } // check the listeners for events std::vector pEvts; #ifdef US_BUILD_SHARED_LIBS pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleA)); pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleA)); #endif std::vector seEvts; #ifdef US_BUILD_SHARED_LIBS seEvts.push_back(ServiceEvent(ServiceEvent::REGISTERED, sr1)); #endif US_TEST_CONDITION(listener.CheckListenerEvents(pEvts, seEvts), "Test for unexpected events"); } catch (const ServiceException& /*se*/) { US_TEST_FAILED_MSG(<< "test module, expected service not found"); } #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(moduleA->IsLoaded() == true, "Test if loaded correctly"); #endif } // Unload libA and check for correct events void frame030b(ModuleContext* mc, TestModuleListener& listener, SharedLibrary& libA) { #ifdef US_BUILD_SHARED_LIBS Module* moduleA = ModuleRegistry::GetModule("TestModuleA Module"); US_TEST_CONDITION_REQUIRED(moduleA != 0, "Test for non-null module") #endif ServiceReferenceU sr1 = mc->GetServiceReference("org.cppmicroservices.TestModuleAService"); US_TEST_CONDITION(sr1, "Test for valid service reference") try { libA.Unload(); #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(moduleA->IsLoaded() == false, "Test for unloaded state") #endif } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "UnLoad module exception: " << e.what()) } std::vector pEvts; #ifdef US_BUILD_SHARED_LIBS pEvts.push_back(ModuleEvent(ModuleEvent::UNLOADING, moduleA)); pEvts.push_back(ModuleEvent(ModuleEvent::UNLOADED, moduleA)); #endif std::vector seEvts; #ifdef US_BUILD_SHARED_LIBS seEvts.push_back(ServiceEvent(ServiceEvent::UNREGISTERING, sr1)); #endif US_TEST_CONDITION(listener.CheckListenerEvents(pEvts, seEvts), "Test for unexpected events"); } struct LocalListener { void ServiceChanged(const ServiceEvent) {} }; // Add a service listener with a broken LDAP filter to Get an exception void frame045a(ModuleContext* mc) { LocalListener sListen1; std::string brokenFilter = "A broken LDAP filter"; try { mc->AddServiceListener(&sListen1, &LocalListener::ServiceChanged, brokenFilter); } catch (const std::invalid_argument& /*ia*/) { //assertEquals("InvalidSyntaxException.GetFilter should be same as input string", brokenFilter, ise.GetFilter()); } catch (...) { US_TEST_FAILED_MSG(<< "test module, wrong exception on broken LDAP filter:"); } } } // end unnamed namespace int usModuleTest(int /*argc*/, char* /*argv*/[]) { US_TEST_BEGIN("ModuleTest"); frame02a(); ModuleContext* mc = GetModuleContext(); TestModuleListener listener; try { mc->AddModuleListener(&listener, &TestModuleListener::ModuleChanged); } catch (const std::logic_error& ise) { US_TEST_OUTPUT( << "module listener registration failed " << ise.what() ); throw; } try { mc->AddServiceListener(&listener, &TestModuleListener::ServiceChanged); } catch (const std::logic_error& ise) { US_TEST_OUTPUT( << "service listener registration failed " << ise.what() ); throw; } frame005a(mc); frame010a(mc); frame018a(mc); SharedLibrary libA(LIB_PATH, "TestModuleA"); frame020a(mc, listener, libA); frame030b(mc, listener, libA); frame045a(mc); mc->RemoveModuleListener(&listener, &TestModuleListener::ModuleChanged); mc->RemoveServiceListener(&listener, &TestModuleListener::ServiceChanged); US_TEST_END() } diff --git a/Core/CppMicroServices/usConfig.h.in b/Core/CppMicroServices/usConfig.h.in index bc7ea6392d..1b951bbb18 100644 --- a/Core/CppMicroServices/usConfig.h.in +++ b/Core/CppMicroServices/usConfig.h.in @@ -1,229 +1,228 @@ /* USCONFIG.h this file is generated. Do not change! */ #ifndef USCONFIG_H #define USCONFIG_H #cmakedefine US_BUILD_SHARED_LIBS #cmakedefine CppMicroServices_EXPORTS #cmakedefine US_ENABLE_AUTOLOADING_SUPPORT #cmakedefine US_ENABLE_THREADING_SUPPORT #cmakedefine US_ENABLE_RESOURCE_COMPRESSION -#cmakedefine US_USE_CXX11 #cmakedefine US_GCC_RTTI_WORKAROUND_NEEDED +//------------------------------------------------------------------- +// Header Availability +//------------------------------------------------------------------- + +#cmakedefine US_HAVE_STDINT_H +#cmakedefine US_HAVE_TR1_UNORDERED_MAP_H +#cmakedefine US_HAVE_TR1_UNORDERED_SET_H +#cmakedefine US_HAVE_TR1_FUNCTIONAL_H +#cmakedefine US_HAVE_UNORDERED_MAP_H +#cmakedefine US_HAVE_UNORDERED_SET_H +#cmakedefine US_HAVE_FUNCTIONAL_H + +#cmakedefine US_HAVE_TR1_UNORDERED_MAP +#cmakedefine US_HAVE_TR1_UNORDERED_SET +#cmakedefine US_HAVE_TR1_FUNCTION +#cmakedefine US_HAVE_STD_UNORDERED_MAP +#cmakedefine US_HAVE_STD_UNORDERED_SET +#cmakedefine US_HAVE_STD_FUNCTION + +#cmakedefine US_HAVE_TR1_HASH +#cmakedefine US_HAVE_TR1_HASH_STRUCT +#cmakedefine US_HAVE_TR1_HASH_CLASS +#cmakedefine US_HAVE_STD_HASH +#cmakedefine US_HAVE_STD_HASH_STRUCT +#cmakedefine US_HAVE_STD_HASH_CLASS + ///------------------------------------------------------------------- // Version information //------------------------------------------------------------------- -#define CppMicroServices_VERSION_MAJOR @CppMicroServices_VERSION_MAJOR@ -#define CppMicroServices_VERSION_MINOR @CppMicroServices_VERSION_MINOR@ -#define CppMicroServices_VERSION_PATH @CppMicroServices_VERSION_PATCH@ +#define CppMicroServices_MAJOR_VERSION @CppMicroServices_MAJOR_VERSION@ +#define CppMicroServices_MINOR_VERSION @CppMicroServices_MINOR_VERSION@ +#define CppMicroServices_PATCH_VERSION @CppMicroServices_PATCH_VERSION@ #define CppMicroServices_VERSION @CppMicroServices_VERSION@ #define CppMicroServices_VERSION_STR "@CppMicroServices_VERSION@" ///------------------------------------------------------------------- // Macros used by the unit tests //------------------------------------------------------------------- #define CppMicroServices_SOURCE_DIR "@CppMicroServices_SOURCE_DIR@" ///------------------------------------------------------------------- // Macros for import/export declarations //------------------------------------------------------------------- #if defined(WIN32) #define US_ABI_EXPORT __declspec(dllexport) #define US_ABI_IMPORT __declspec(dllimport) #define US_ABI_LOCAL #else #define US_ABI_EXPORT __attribute__ ((visibility ("default"))) #define US_ABI_IMPORT __attribute__ ((visibility ("default"))) #define US_ABI_LOCAL __attribute__ ((visibility ("hidden"))) #endif #ifdef US_BUILD_SHARED_LIBS // We are building a shared lib #ifdef CppMicroServices_EXPORTS #define US_EXPORT US_ABI_EXPORT #else #define US_EXPORT US_ABI_IMPORT #endif #else // We are building a static lib // Don't hide RTTI symbols of definitions in the C++ Micro Services // headers that are included in DSOs with hidden visibility #define US_EXPORT US_ABI_EXPORT #endif //------------------------------------------------------------------- // Namespace customization //------------------------------------------------------------------- #define US_NAMESPACE @US_NAMESPACE@ #ifndef US_NAMESPACE /* user namespace */ # define US_PREPEND_NAMESPACE(name) ::name # define US_USE_NAMESPACE # define US_BEGIN_NAMESPACE # define US_END_NAMESPACE # define US_FORWARD_DECLARE_CLASS(name) class name; # define US_FORWARD_DECLARE_STRUCT(name) struct name; #else /* user namespace */ # define US_PREPEND_NAMESPACE(name) ::US_NAMESPACE::name # define US_USE_NAMESPACE using namespace ::US_NAMESPACE; # define US_BEGIN_NAMESPACE namespace US_NAMESPACE { # define US_END_NAMESPACE } # define US_FORWARD_DECLARE_CLASS(name) \ US_BEGIN_NAMESPACE class name; US_END_NAMESPACE # define US_FORWARD_DECLARE_STRUCT(name) \ US_BEGIN_NAMESPACE struct name; US_END_NAMESPACE namespace US_NAMESPACE {} #endif /* user namespace */ //------------------------------------------------------------------- // Platform defines //------------------------------------------------------------------- #if defined(__APPLE__) #define US_PLATFORM_APPLE #endif #if defined(__linux__) #define US_PLATFORM_LINUX #endif #if defined(_WIN32) || defined(_WIN64) #define US_PLATFORM_WINDOWS #else #define US_PLATFORM_POSIX #endif //------------------------------------------------------------------- // Macros for suppressing warnings //------------------------------------------------------------------- #ifdef _MSC_VER #define US_MSVC_PUSH_DISABLE_WARNING(wn) \ __pragma(warning(push)) \ __pragma(warning(disable:wn)) #define US_MSVC_POP_WARNING \ __pragma(warning(pop)) #define US_MSVC_DISABLE_WARNING(wn) \ __pragma(warning(disable:wn)) #else #define US_MSVC_PUSH_DISABLE_WARNING(wn) #define US_MSVC_POP_WARNING #define US_MSVC_DISABLE_WARNING(wn) #endif // Do not warn about the usage of deprecated unsafe functions US_MSVC_DISABLE_WARNING(4996) // Mark a variable or expression result as unused #define US_UNUSED(x) (void)(x) //------------------------------------------------------------------- // Debuging & Logging //------------------------------------------------------------------- #cmakedefine US_ENABLE_DEBUG_OUTPUT US_BEGIN_NAMESPACE enum MsgType { DebugMsg = 0, InfoMsg = 1, WarningMsg = 2, ErrorMsg = 3 }; typedef void (*MsgHandler)(MsgType, const char *); US_EXPORT MsgHandler installMsgHandler(MsgHandler); US_END_NAMESPACE //------------------------------------------------------------------- // Hash Container //------------------------------------------------------------------- -#ifdef US_USE_CXX11 - +#ifdef US_HAVE_UNORDERED_MAP_H #include - #include - - #define US_HASH_FUNCTION_BEGIN(type) \ - template<> \ - struct hash : std::unary_function { \ - std::size_t operator()(const type& arg) const { - - #define US_HASH_FUNCTION_END } }; - - #define US_HASH_FUNCTION(type, arg) hash()(arg) +#elif defined(US_HAVE_TR1_UNORDERED_MAP_H) + #include +#endif - #if defined(US_PLATFORM_WINDOWS) && (_MSC_VER < 1700) - #define US_HASH_FUNCTION_FRIEND(type) friend class ::std::hash - #else - #define US_HASH_FUNCTION_FRIEND(type) friend struct ::std::hash - #endif +#ifdef US_HAVE_UNORDERED_SET_H + #include +#elif defined(US_HAVE_TR1_UNORDERED_SET_H) + #include +#endif +#ifdef US_HAVE_STD_UNORDERED_MAP #define US_UNORDERED_MAP_TYPE ::std::unordered_map +#elif defined(US_HAVE_TR1_UNORDERED_MAP) + #define US_UNORDERED_MAP_TYPE ::std::tr1::unordered_map +#endif + +#ifdef US_HAVE_STD_UNORDERED_SET #define US_UNORDERED_SET_TYPE ::std::unordered_set +#elif defined(US_HAVE_TR1_UNORDERED_SET) + #define US_UNORDERED_SET_TYPE ::std::tr1::unordered_set +#endif +#ifdef US_HAVE_STD_HASH #define US_HASH_FUNCTION_NAMESPACE ::std + #ifdef US_HAVE_STD_HASH_STRUCT + #define US_HASH_FUNCTION_FRIEND(type) friend struct ::std::hash + #elif defined(US_HAVE_STD_HASH_CLASS) + #define US_HASH_FUNCTION_FRIEND(type) friend class ::std::hash + #endif #define US_HASH_FUNCTION_NAMESPACE_BEGIN namespace std { #define US_HASH_FUNCTION_NAMESPACE_END } - -#elif defined(__GNUC__) - - #include - #include - - #define US_HASH_FUNCTION_BEGIN(type) \ - template<> \ - struct hash : std::unary_function { \ - std::size_t operator()(const type& arg) const { - - #define US_HASH_FUNCTION_END } }; - - #define US_HASH_FUNCTION(type, arg) hash()(arg) - #define US_HASH_FUNCTION_FRIEND(type) friend struct ::std::tr1::hash - - #define US_UNORDERED_MAP_TYPE ::std::tr1::unordered_map - #define US_UNORDERED_SET_TYPE ::std::tr1::unordered_set - - #define US_HASH_FUNCTION_NAMESPACE ::std::tr1 - #define US_HASH_FUNCTION_NAMESPACE_BEGIN namespace std { namespace tr1 { - #define US_HASH_FUNCTION_NAMESPACE_END }} - -#elif _MSC_VER <= 1500 // Visual Studio 2008 and lower - - #include - #include - - #define US_HASH_FUNCTION_BEGIN(type) \ - template<> \ - class hash : std::unary_function { \ - public: std::size_t operator()(const type& arg) const { - - #define US_HASH_FUNCTION_END } }; - - #define US_HASH_FUNCTION(type, arg) hash()(arg) - #define US_HASH_FUNCTION_FRIEND(type) friend class ::std::tr1::hash - - #define US_UNORDERED_MAP_TYPE ::std::tr1::unordered_map - #define US_UNORDERED_SET_TYPE ::std::tr1::unordered_set - +#elif defined(US_HAVE_TR1_HASH) #define US_HASH_FUNCTION_NAMESPACE ::std::tr1 + #ifdef US_HAVE_TR1_HASH_STRUCT + #define US_HASH_FUNCTION_FRIEND(type) friend struct ::std::tr1::hash + #elif defined(US_HAVE_TR1_HASH_CLASS) + #define US_HASH_FUNCTION_FRIEND(type) friend class ::std::tr1::hash + #endif #define US_HASH_FUNCTION_NAMESPACE_BEGIN namespace std { namespace tr1 { #define US_HASH_FUNCTION_NAMESPACE_END }} - #endif -//------------------------------------------------------------------- -// Header Availability -//------------------------------------------------------------------- +#define US_HASH_FUNCTION_BEGIN(type) \ +template<> \ +struct hash : std::unary_function { \ +std::size_t operator()(const type& arg) const { + +#define US_HASH_FUNCTION_END } }; -#cmakedefine HAVE_STDINT +#define US_HASH_FUNCTION(type, arg) hash()(arg) #endif // USCONFIG_H