mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-05 23:11:31 +01:00
[uLib Geometry]
non working version! + adds ProgrammableAccessor + renaming of some Image structures ...
This commit is contained in:
8
AUTHORS
Normal file
8
AUTHORS
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* CMT - Written and Mantained by:
|
||||
*
|
||||
* A. Rigoni ( andrea.rigoni@pd.infn.it )
|
||||
* M. Furlan ( matteo.furlan@pd.infn.it )
|
||||
* S. Vanini ( sara.vanini@pd.infn.it )
|
||||
*
|
||||
**/
|
||||
81
CMake/FindEigen3.cmake
Normal file
81
CMake/FindEigen3.cmake
Normal file
@@ -0,0 +1,81 @@
|
||||
# - Try to find Eigen3 lib
|
||||
#
|
||||
# This module supports requiring a minimum version, e.g. you can do
|
||||
# find_package(Eigen3 3.1.2)
|
||||
# to require version 3.1.2 or newer of Eigen3.
|
||||
#
|
||||
# Once done this will define
|
||||
#
|
||||
# EIGEN3_FOUND - system has eigen lib with correct version
|
||||
# EIGEN3_INCLUDE_DIR - the eigen include directory
|
||||
# EIGEN3_VERSION - eigen version
|
||||
|
||||
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
||||
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
|
||||
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
||||
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
|
||||
|
||||
if(NOT Eigen3_FIND_VERSION)
|
||||
if(NOT Eigen3_FIND_VERSION_MAJOR)
|
||||
set(Eigen3_FIND_VERSION_MAJOR 2)
|
||||
endif(NOT Eigen3_FIND_VERSION_MAJOR)
|
||||
if(NOT Eigen3_FIND_VERSION_MINOR)
|
||||
set(Eigen3_FIND_VERSION_MINOR 91)
|
||||
endif(NOT Eigen3_FIND_VERSION_MINOR)
|
||||
if(NOT Eigen3_FIND_VERSION_PATCH)
|
||||
set(Eigen3_FIND_VERSION_PATCH 0)
|
||||
endif(NOT Eigen3_FIND_VERSION_PATCH)
|
||||
|
||||
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
|
||||
endif(NOT Eigen3_FIND_VERSION)
|
||||
|
||||
macro(_eigen3_check_version)
|
||||
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
|
||||
|
||||
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
|
||||
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
|
||||
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
|
||||
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
||||
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
|
||||
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
|
||||
|
||||
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
|
||||
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||
set(EIGEN3_VERSION_OK FALSE)
|
||||
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||
set(EIGEN3_VERSION_OK TRUE)
|
||||
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||
|
||||
if(NOT EIGEN3_VERSION_OK)
|
||||
|
||||
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
|
||||
"but at least version ${Eigen3_FIND_VERSION} is required")
|
||||
endif(NOT EIGEN3_VERSION_OK)
|
||||
endmacro(_eigen3_check_version)
|
||||
|
||||
if (EIGEN3_INCLUDE_DIR)
|
||||
|
||||
# in cache already
|
||||
_eigen3_check_version()
|
||||
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
||||
|
||||
else (EIGEN3_INCLUDE_DIR)
|
||||
|
||||
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
|
||||
PATHS
|
||||
${CMAKE_INSTALL_PREFIX}/include
|
||||
${KDE4_INCLUDE_DIR}
|
||||
PATH_SUFFIXES eigen3 eigen
|
||||
)
|
||||
|
||||
if(EIGEN3_INCLUDE_DIR)
|
||||
_eigen3_check_version()
|
||||
endif(EIGEN3_INCLUDE_DIR)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
|
||||
|
||||
mark_as_advanced(EIGEN3_INCLUDE_DIR)
|
||||
|
||||
endif(EIGEN3_INCLUDE_DIR)
|
||||
|
||||
63
CMake/FindGEANT4.cmake
Normal file
63
CMake/FindGEANT4.cmake
Normal file
@@ -0,0 +1,63 @@
|
||||
# - Try to find GEANT4
|
||||
# Once done this will define
|
||||
#
|
||||
# GEANT4_FOUND - system has GEANT4
|
||||
# GEANT4_INCLUDE_DIR - the GEANT4 include directory
|
||||
# GEANT4_LIBRARIES - The libraries needed to use GEANT4
|
||||
# GEANT4_DEFINITIONS - Compiler switches required for using GEANT4
|
||||
#
|
||||
|
||||
if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||
SET (GEANT4_INCLUDE_DIR GEANT4_INCLUDE_DIR-NOTFOUND)
|
||||
SET (GEANT4_LIB_DIR GEANT4_LIB_DIR-NOTFOUND)
|
||||
SET (GEANT4_PLISTS_LIB_DIR GEANT4_PLISTS_LIB_DIR-NOTFOUND)
|
||||
SET (GEANT4_DIR GEANT4_DIR-NOTFOUND)
|
||||
endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||
|
||||
MESSAGE(STATUS "Looking for GEANT4...")
|
||||
|
||||
FIND_PATH(GEANT4_DIR NAMES env.sh PATHS
|
||||
${SIMPATH}/transport/geant4
|
||||
${SIMPATH}/transport/geant4/source
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
FIND_PATH(GEANT4_INCLUDE_DIR NAMES G4Event.hh PATHS
|
||||
${SIMPATH}/transport/geant4/include
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
SET(GEANT4_INCLUDE_DIR
|
||||
${SIMPATH}/transport/geant4/include
|
||||
${SIMPATH}/transport/geant4/source/interfaces/common/include
|
||||
${SIMPATH}/transport/geant4/physics_lists/hadronic/Packaging/include
|
||||
${SIMPATH}/transport/geant4/physics_lists/hadronic/QGSP/include
|
||||
)
|
||||
|
||||
FIND_PATH(GEANT4_LIB_DIR NAMES libG4baryons.so libG4baryons.dylib PATHS
|
||||
${SIMPATH}/transport/geant4/lib/Linux-g++
|
||||
${SIMPATH}/transport/geant4/lib/Linux-icc
|
||||
${SIMPATH}/transport/geant4/lib
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
IF (GEANT4_LIB_DIR)
|
||||
SET(GEANT4_LIBRARY_DIR ${GEANT4_LIB_DIR})
|
||||
ENDIF (GEANT4_LIB_DIR)
|
||||
|
||||
if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||
set(GEANT4_FOUND TRUE)
|
||||
endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||
|
||||
if (GEANT4_FOUND)
|
||||
if (NOT GEANT4_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Looking for GEANT4... - found ${GEANT4_LIBRARY_DIR}")
|
||||
# message(STATUS "Found ${GEANT4_LIBRARY_DIR}")
|
||||
endif (NOT GEANT4_FIND_QUIETLY)
|
||||
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4_LIBRARY_DIR})
|
||||
else (GEANT4_FOUND)
|
||||
if (GEANT4_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Looking for GEANT4... - Not found")
|
||||
endif (GEANT4_FIND_REQUIRED)
|
||||
endif (GEANT4_FOUND)
|
||||
|
||||
97
CMake/FindGEANT4VMC.cmake
Normal file
97
CMake/FindGEANT4VMC.cmake
Normal file
@@ -0,0 +1,97 @@
|
||||
# - Try to find GEANT4VMC
|
||||
# Once done this will define
|
||||
#
|
||||
# GEANT4VMC_FOUND - system has GEANT3
|
||||
# GEANT4VMC_INCLUDE_DIR - the GEANT3 include directory
|
||||
# GEANT4VMC_LIBRARIES - The libraries needed to use GEANT3
|
||||
# GEANT4VMC_DEFINITIONS - Compiler switches required for using GEANT3
|
||||
#
|
||||
|
||||
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||
SET (GEANT4VMC_INCLUDE_DIR GEANT4VMC_INCLUDE_DIR-NOTFOUND)
|
||||
SET (GEANT4VMC_LIB_DIR GEANT4VMC_LIB_DIR-NOTFOUND)
|
||||
SET (GEANT4VMC_PLISTS_LIB_DIR GEANT4VMC_PLISTS_LIB_DIR-NOTFOUND)
|
||||
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||
|
||||
MESSAGE(STATUS "Looking for GEANT4VMC...")
|
||||
|
||||
FIND_PATH(GEANT4VMC_INCLUDE_DIR NAMES TG4G3Units.h PATHS
|
||||
${SIMPATH}/transport/geant4_vmc/include
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
set(GEANT4VMC_INCLUDE_DIR
|
||||
${SIMPATH}/transport/geant4_vmc/source/global/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/geometry/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/digits+hits/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/physics/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/event/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/run/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/interfaces/include
|
||||
${SIMPATH}/transport/geant4_vmc/source/visualization/include
|
||||
${SIMPATH}/transport/geant4_vmc/include
|
||||
${SIMPATH}/transport/vgm/packages/BaseVGM/include
|
||||
${SIMPATH}/transport/vgm/packages/ClhepVGM/include
|
||||
${SIMPATH}/transport/vgm/packages/Geant4GM/include
|
||||
${SIMPATH}/transport/vgm/packages/RootGM/include
|
||||
${SIMPATH}/transport/vgm/packages/VGM/include
|
||||
${SIMPATH}/transport/vgm/packages/XmlVGM/include
|
||||
)
|
||||
|
||||
|
||||
FIND_PATH(GEANT4VMC_LIBRARY_DIR NAMES libgeant4vmc.so libgeant4vmc.dylib PATHS
|
||||
${SIMPATH}/transport/geant4_vmc/lib/tgt_linux
|
||||
${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxicc
|
||||
${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxx8664gcc
|
||||
${SIMPATH}/transport/geant4_vmc/lib
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
# check for existence of header file, which is needed in CbmRunConfiguration
|
||||
# The file is only present in old versions of VMC
|
||||
FIND_FILE(GEANT4_MODULAR_PHYSICS_LIST TG4ModularPhysicsList.h PATHS
|
||||
${GEANT4VMC_INCLUDE_DIR}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||
if (NOT GEANT4VMC_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Looking for GEANT4VMC... - found ${GEANT4VMC_LIBRARY_DIR}")
|
||||
endif (NOT GEANT4VMC_FIND_QUIETLY)
|
||||
else (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||
if (GEANT4VMC_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Looking for GEANT4VMC... - Not found ")
|
||||
endif (GEANT4VMC_FIND_REQUIRED)
|
||||
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||
|
||||
|
||||
MESSAGE(STATUS "Looking for VGM...")
|
||||
|
||||
FIND_PATH(VGM_LIBRARY_DIR NAMES libBaseVGM.so libBaseVGM.dylib PATHS
|
||||
${SIMPATH}/transport/vgm/lib/Linux-g++
|
||||
${SIMPATH}/transport/vgm.2.08.04/lib/Linux-g++
|
||||
${SIMPATH}/transport/vgm/lib/Linux-icc
|
||||
${SIMPATH}/transport/vgm/lib
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if (VGM_LIBRARY_DIR)
|
||||
if (NOT GEANT4VMC_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Looking for VGM... - found ${VGM_LIBRARY_DIR}")
|
||||
endif (NOT GEANT4VMC_FIND_QUIETLY)
|
||||
else (VGM_LIBRARY_DIR)
|
||||
if (GEANT4VMC_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Looking for VGM... - Not found ")
|
||||
endif (GEANT4VMC_FIND_REQUIRED)
|
||||
endif (VGM_LIBRARY_DIR)
|
||||
|
||||
|
||||
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR)
|
||||
set(GEANT4VMC_FOUND TRUE)
|
||||
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR)
|
||||
|
||||
if (GEANT4VMC_FOUND)
|
||||
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4VMC_LIBRARY_DIR}
|
||||
${VGM_LIBRARY_DIR})
|
||||
endif (GEANT4VMC_FOUND)
|
||||
|
||||
279
CMake/FindROOT.cmake
Normal file
279
CMake/FindROOT.cmake
Normal file
@@ -0,0 +1,279 @@
|
||||
# - Find ROOT instalation
|
||||
# This module tries to find the ROOT installation on your system.
|
||||
# It tries to find the root-config script which gives you all the needed information.
|
||||
# If the system variable ROOTSYS is set this is straight forward.
|
||||
# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
|
||||
# If you need an other path you should add this path to this varaible.
|
||||
# The root-config script is then used to detect basically everything else.
|
||||
# This module defines a number of key variables and macros.
|
||||
|
||||
# F.Uhlig@gsi.de (fairroot.gsi.de)
|
||||
|
||||
|
||||
MESSAGE(STATUS "Looking for Root...")
|
||||
|
||||
SET(ROOT_CONFIG_SEARCHPATH
|
||||
/usr/local/bin
|
||||
${SIMPATH}/tools/root/bin
|
||||
$ENV{ROOTSYS}/bin
|
||||
)
|
||||
|
||||
SET(ROOT_DEFINITIONS "")
|
||||
|
||||
SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
|
||||
|
||||
SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
|
||||
|
||||
FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
|
||||
${ROOT_CONFIG_SEARCHPATH}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||
MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
|
||||
set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
|
||||
subdirectory cmake/modules.")
|
||||
ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||
STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
|
||||
SET( ENV{ROOTSYS} ${test})
|
||||
set( ROOTSYS ${test})
|
||||
ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||
|
||||
|
||||
IF (ROOT_CONFIG_EXECUTABLE)
|
||||
|
||||
SET(ROOT_FOUND FALSE)
|
||||
|
||||
EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
|
||||
|
||||
MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
|
||||
MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")
|
||||
|
||||
# we need at least version 5.00/00
|
||||
IF (NOT ROOT_MIN_VERSION)
|
||||
SET(ROOT_MIN_VERSION "5.00/00")
|
||||
ENDIF (NOT ROOT_MIN_VERSION)
|
||||
|
||||
# now parse the parts of the user given version string into variables
|
||||
STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
|
||||
STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
|
||||
STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
|
||||
|
||||
# and now the version string given by qmake
|
||||
STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
|
||||
STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
|
||||
STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
|
||||
|
||||
IF (found_root_major_vers LESS 5)
|
||||
MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
|
||||
ENDIF (found_root_major_vers LESS 5)
|
||||
|
||||
# compute an overall version number which can be compared at once
|
||||
MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
|
||||
MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
|
||||
|
||||
IF (found_vers LESS req_vers)
|
||||
SET(ROOT_FOUND FALSE)
|
||||
SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
|
||||
ELSE (found_vers LESS req_vers)
|
||||
SET(ROOT_FOUND TRUE)
|
||||
ENDIF (found_vers LESS req_vers)
|
||||
|
||||
ENDIF (ROOT_CONFIG_EXECUTABLE)
|
||||
|
||||
|
||||
IF (ROOT_FOUND)
|
||||
|
||||
# ask root-config for the library dir
|
||||
# Set ROOT_LIBRARY_DIR
|
||||
|
||||
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||
ARGS "--libdir"
|
||||
OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
|
||||
|
||||
IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||
SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
|
||||
ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||
MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
|
||||
MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
|
||||
ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||
|
||||
# ask root-config for the binary dir
|
||||
EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
|
||||
ARGS "--bindir"
|
||||
OUTPUT_VARIABLE root_bins )
|
||||
SET(ROOT_BINARY_DIR ${root_bins})
|
||||
|
||||
# ask root-config for the include dir
|
||||
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||
ARGS "--incdir"
|
||||
OUTPUT_VARIABLE root_headers )
|
||||
SET(ROOT_INCLUDE_DIR ${root_headers})
|
||||
# CACHE INTERNAL "")
|
||||
|
||||
# ask root-config for the library varaibles
|
||||
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||
# ARGS "--noldflags --noauxlibs --libs"
|
||||
ARGS "--glibs"
|
||||
OUTPUT_VARIABLE root_flags )
|
||||
|
||||
# STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
|
||||
# STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
|
||||
# REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
|
||||
|
||||
SET(ROOT_LIBRARIES ${root_flags})
|
||||
|
||||
# Make variables changeble to the advanced user
|
||||
MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
|
||||
|
||||
# Set ROOT_INCLUDES
|
||||
SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
|
||||
|
||||
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
|
||||
|
||||
#######################################
|
||||
#
|
||||
# Check the executables of ROOT
|
||||
# ( rootcint )
|
||||
#
|
||||
#######################################
|
||||
|
||||
FIND_PROGRAM(ROOT_CINT_EXECUTABLE
|
||||
NAMES rootcint
|
||||
PATHS ${ROOT_BINARY_DIR}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
ENDIF (ROOT_FOUND)
|
||||
|
||||
|
||||
|
||||
###########################################
|
||||
#
|
||||
# Macros for building ROOT dictionary
|
||||
#
|
||||
###########################################
|
||||
|
||||
MACRO (ROOT_GENERATE_DICTIONARY_OLD )
|
||||
|
||||
set(INFILES "")
|
||||
|
||||
foreach (_current_FILE ${ARGN})
|
||||
|
||||
IF (${_current_FILE} MATCHES "^.*\\.h$")
|
||||
IF (${_current_FILE} MATCHES "^.*Link.*$")
|
||||
set(LINKDEF_FILE ${_current_FILE})
|
||||
ELSE (${_current_FILE} MATCHES "^.*Link.*$")
|
||||
set(INFILES ${INFILES} ${_current_FILE})
|
||||
ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
|
||||
ELSE (${_current_FILE} MATCHES "^.*\\.h$")
|
||||
IF (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||
set(OUTFILE ${_current_FILE})
|
||||
ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||
set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
|
||||
ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||
ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
|
||||
|
||||
endforeach (_current_FILE ${ARGN})
|
||||
|
||||
# MESSAGE("INFILES: ${INFILES}")
|
||||
# MESSAGE("OutFILE: ${OUTFILE}")
|
||||
# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
|
||||
# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
|
||||
|
||||
STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
|
||||
# MESSAGE("BLA: ${bla}")
|
||||
SET (OUTFILES ${OUTFILE} ${bla})
|
||||
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||
COMMAND ${ROOT_CINT_EXECUTABLE}
|
||||
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
|
||||
|
||||
# MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
|
||||
|
||||
ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
|
||||
|
||||
###########################################
|
||||
#
|
||||
# Macros for building ROOT dictionary
|
||||
#
|
||||
###########################################
|
||||
|
||||
MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
|
||||
|
||||
set(INCLUDE_DIRS)
|
||||
|
||||
foreach (_current_FILE ${INCLUDE_DIRS_IN})
|
||||
set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
|
||||
endforeach (_current_FILE ${INCLUDE_DIRS_IN})
|
||||
|
||||
|
||||
# MESSAGE("INFILES: ${INFILES}")
|
||||
# MESSAGE("OutFILE: ${OUTFILE}")
|
||||
# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
|
||||
# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
|
||||
|
||||
STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
|
||||
# MESSAGE("BLA: ${bla}")
|
||||
SET (OUTFILES ${OUTFILE} ${bla})
|
||||
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||
COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
|
||||
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
|
||||
else (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||
COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
|
||||
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
|
||||
endif (CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||
|
||||
ENDMACRO (ROOT_GENERATE_DICTIONARY)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME)
|
||||
|
||||
get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH)
|
||||
get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT)
|
||||
get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE)
|
||||
set(shell_script_name "${file_name}.sh")
|
||||
|
||||
#MESSAGE("PATH: ${path_name}")
|
||||
#MESSAGE("Ext: ${file_extension}")
|
||||
#MESSAGE("Name: ${file_name}")
|
||||
#MESSAGE("Shell Name: ${shell_script_name}")
|
||||
|
||||
string(REPLACE ${PROJECT_SOURCE_DIR}
|
||||
${PROJECT_BINARY_DIR} new_path ${path_name}
|
||||
)
|
||||
|
||||
#MESSAGE("New PATH: ${new_path}")
|
||||
|
||||
file(MAKE_DIRECTORY ${new_path}/data)
|
||||
|
||||
CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH})
|
||||
set(MY_LD_LIBRARY_PATH ${output})
|
||||
set(my_script_name ${SCRIPT_FULL_NAME})
|
||||
|
||||
if(CMAKE_SYSTEM MATCHES Darwin)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in
|
||||
${new_path}/${shell_script_name}
|
||||
)
|
||||
else(CMAKE_SYSTEM MATCHES Darwin)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in
|
||||
${new_path}/${shell_script_name}
|
||||
)
|
||||
endif(CMAKE_SYSTEM MATCHES Darwin)
|
||||
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${new_path}/${shell_script_name}")
|
||||
|
||||
ENDMACRO (GENERATE_ROOT_TEST_SCRIPT)
|
||||
164
CMake/FindROOTv6.cmake
Normal file
164
CMake/FindROOTv6.cmake
Normal file
@@ -0,0 +1,164 @@
|
||||
# - Finds ROOT instalation
|
||||
# This module sets up ROOT information
|
||||
# It defines:
|
||||
# ROOT_FOUND If the ROOT is found
|
||||
# ROOT_INCLUDE_DIR PATH to the include directory
|
||||
# ROOT_LIBRARIES Most common libraries
|
||||
# ROOT_LIBRARY_DIR PATH to the library directory
|
||||
#
|
||||
# Updated by K. Smith (ksmith37@nd.edu) to properly handle
|
||||
# dependncies in ROOT_GENERATE_DICTIONARY
|
||||
|
||||
set(ROOT_ROOTSYS $ENV{ROOTSYS} CACHE PATH "path of root installation")
|
||||
|
||||
|
||||
unset(ROOT_CONFIG_EXECUTABLE CACHE)
|
||||
find_program(ROOT_CONFIG_EXECUTABLE root-config
|
||||
PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH)
|
||||
|
||||
if(NOT ROOT_CONFIG_EXECUTABLE)
|
||||
set(ROOT_FOUND FALSE)
|
||||
else()
|
||||
set(ROOT_FOUND TRUE)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix
|
||||
OUTPUT_VARIABLE ROOTSYS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${ROOT_CONFIG_EXECUTABLE} --version
|
||||
OUTPUT_VARIABLE ROOT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
|
||||
OUTPUT_VARIABLE ROOT_INCLUDE_DIR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs
|
||||
OUTPUT_VARIABLE ROOT_LIBRARIES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lThread -lMinuit -lHtml -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lProof)
|
||||
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lProofPlayer -lMLP -lSpectrum -lEve -lRGL -lGed -lXMLParser -lPhysics)
|
||||
set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE
|
||||
ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR)
|
||||
|
||||
mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
|
||||
|
||||
include(CMakeParseArguments)
|
||||
unset(ROOT_CINT_EXECUTABLE CACHE)
|
||||
find_program(ROOT_CINT_EXECUTABLE rootcint PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH )
|
||||
mark_as_advanced(ROOT_CINT_EXECUTABLE)
|
||||
|
||||
|
||||
unset(ROOT_GENREFLEX_EXECUTABLE CACHE)
|
||||
find_program(ROOT_GENREFLEX_EXECUTABLE genreflex PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH)
|
||||
mark_as_advanced(ROOT_GENREFLEX_EXECUTABLE)
|
||||
|
||||
find_package(GCCXML)
|
||||
|
||||
include(uLibDebugMacro)
|
||||
#----------------------------------------------------------------------------
|
||||
# function ROOT_GENERATE_DICTIONARY( dictionary
|
||||
# header1 header2 ...
|
||||
# LINKDEF linkdef1 ...
|
||||
# OPTIONS opt1...)
|
||||
function(ROOT_GENERATE_DICTIONARY dictionary)
|
||||
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
|
||||
message(" -- generating rootcint dictionary --------------------------------------- ")
|
||||
#---Get the list of include directories------------------
|
||||
get_directory_property(incdirs INCLUDE_DIRECTORIES)
|
||||
set(includedirs)
|
||||
foreach( d ${incdirs})
|
||||
set(includedirs ${includedirs} -I${d})
|
||||
endforeach()
|
||||
#---Get the list of header files-------------------------
|
||||
set(headerfiles)
|
||||
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
|
||||
find_file(headerFile ${fp} PATHS ${incdirs})
|
||||
set(headerfiles ${headerfiles} ${headerFile})
|
||||
debug(headerFile)
|
||||
unset(headerFile CACHE)
|
||||
endforeach()
|
||||
#---Get LinkDef.h file------------------------------------
|
||||
set(linkdefs)
|
||||
foreach( f ${ARG_LINKDEF})
|
||||
find_file(linkFile ${f} PATHS ${incdirs})
|
||||
set(linkdefs ${linkdefs} ${linkFile})
|
||||
debug(linkdefs)
|
||||
unset(linkFile CACHE)
|
||||
endforeach()
|
||||
#---call rootcint------------------------------------------
|
||||
add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h
|
||||
COMMAND ${ROOT_CINT_EXECUTABLE} -cint -f ${dictionary}.cxx
|
||||
-c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
|
||||
DEPENDS ${headerfiles} ${linkdefs} VERBATIM)
|
||||
message(" -- ---------------------------------------------------------------------- ")
|
||||
endfunction()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# function REFLEX_GENERATE_DICTIONARY(dictionary
|
||||
# header1 header2 ...
|
||||
# SELECTION selectionfile ...
|
||||
# OPTIONS opt1...)
|
||||
function(REFLEX_GENERATE_DICTIONARY dictionary)
|
||||
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN})
|
||||
#---Get the list of header files-------------------------
|
||||
set(headerfiles)
|
||||
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
|
||||
file(GLOB files ${fp})
|
||||
if(files)
|
||||
foreach(f ${files})
|
||||
set(headerfiles ${headerfiles} ${f})
|
||||
endforeach()
|
||||
else()
|
||||
set(headerfiles ${headerfiles} ${fp})
|
||||
endif()
|
||||
endforeach()
|
||||
#---Get Selection file------------------------------------
|
||||
if(IS_ABSOLUTE ${ARG_SELECTION})
|
||||
set(selectionfile ${ARG_SELECTION})
|
||||
else()
|
||||
set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION})
|
||||
endif()
|
||||
#---Get the list of include directories------------------
|
||||
get_directory_property(incdirs INCLUDE_DIRECTORIES)
|
||||
set(includedirs)
|
||||
foreach( d ${incdirs})
|
||||
set(includedirs ${includedirs} -I${d})
|
||||
endforeach()
|
||||
#---Get preprocessor definitions--------------------------
|
||||
get_directory_property(defs COMPILE_DEFINITIONS)
|
||||
foreach( d ${defs})
|
||||
set(definitions ${definitions} -D${d})
|
||||
endforeach()
|
||||
#---Nanes and others---------------------------------------
|
||||
set(gensrcdict ${dictionary}.cpp)
|
||||
if(MSVC)
|
||||
set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"")
|
||||
else()
|
||||
#set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'")
|
||||
set(gccxmlopts)
|
||||
endif()
|
||||
#set(rootmapname ${dictionary}Dict.rootmap)
|
||||
#set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict)
|
||||
#---Check GCCXML and get path-----------------------------
|
||||
if(GCCXML)
|
||||
get_filename_component(gccxmlpath ${GCCXML} PATH)
|
||||
else()
|
||||
message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable")
|
||||
endif()
|
||||
#---Actual command----------------------------------------
|
||||
add_custom_command(OUTPUT ${gensrcdict} ${rootmapname}
|
||||
COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile}
|
||||
--gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions}
|
||||
DEPENDS ${headerfiles} ${selectionfile})
|
||||
endfunction()
|
||||
|
||||
23
CMake/FindReadLine.cmake
Normal file
23
CMake/FindReadLine.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
# Base Io build system
|
||||
# Written by Jeremy Tregunna <jeremy.tregunna@me.com>
|
||||
#
|
||||
# Find libreadline.
|
||||
|
||||
FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h readline/history.h)
|
||||
|
||||
SET(READLINE_NAMES ${READLINE_NAMES} readline libreadline history libhistory)
|
||||
FIND_LIBRARY(READLINE_LIBRARY NAMES ${READLINE_NAMES} PATH)
|
||||
|
||||
IF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||
SET(READLINE_FOUND TRUE)
|
||||
ENDIF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||
|
||||
IF(READLINE_FOUND)
|
||||
IF(NOT Readline_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found Readline: ${READLINE_LIBRARY}")
|
||||
ENDIF (NOT Readline_FIND_QUIETLY)
|
||||
ELSE(READLINE_FOUND)
|
||||
IF(Readline_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find readline")
|
||||
ENDIF(Readline_FIND_REQUIRED)
|
||||
ENDIF (READLINE_FOUND)
|
||||
141
CMake/FindVTK.cmake
Normal file
141
CMake/FindVTK.cmake
Normal file
@@ -0,0 +1,141 @@
|
||||
# - Find a VTK installation or build tree.
|
||||
# The following variables are set if VTK is found. If VTK is not
|
||||
# found, VTK_FOUND is set to false.
|
||||
# VTK_FOUND - Set to true when VTK is found.
|
||||
# VTK_USE_FILE - CMake file to use VTK.
|
||||
# VTK_MAJOR_VERSION - The VTK major version number.
|
||||
# VTK_MINOR_VERSION - The VTK minor version number
|
||||
# (odd non-release).
|
||||
# VTK_BUILD_VERSION - The VTK patch level
|
||||
# (meaningless for odd minor).
|
||||
# VTK_INCLUDE_DIRS - Include directories for VTK
|
||||
# VTK_LIBRARY_DIRS - Link directories for VTK libraries
|
||||
# VTK_KITS - List of VTK kits, in CAPS
|
||||
# (COMMON,IO,) etc.
|
||||
# VTK_LANGUAGES - List of wrapped languages, in CAPS
|
||||
# (TCL, PYHTON,) etc.
|
||||
# The following cache entries must be set by the user to locate VTK:
|
||||
# VTK_DIR - The directory containing VTKConfig.cmake.
|
||||
# This is either the root of the build tree,
|
||||
# or the lib/vtk directory. This is the
|
||||
# only cache entry.
|
||||
# The following variables are set for backward compatibility and
|
||||
# should not be used in new code:
|
||||
# USE_VTK_FILE - The full path to the UseVTK.cmake file.
|
||||
# This is provided for backward
|
||||
# compatibility. Use VTK_USE_FILE
|
||||
# instead.
|
||||
#
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2001-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# Assume not found.
|
||||
SET(VTK_FOUND 0)
|
||||
|
||||
# VTK 4.0 did not provide VTKConfig.cmake.
|
||||
IF("${VTK_FIND_VERSION}" VERSION_LESS 4.1)
|
||||
SET(_VTK_40_ALLOW 1)
|
||||
IF(VTK_FIND_VERSION)
|
||||
SET(_VTK_40_ONLY 1)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Construct consitent error messages for use below.
|
||||
SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
|
||||
IF(_VTK_40_ALLOW)
|
||||
SET(VTK_DIR_DESCRIPTION "${VTK_DIR_DESCRIPTION} For VTK 4.0, this is the location of UseVTK.cmake. This is either the root of the build tree or PREFIX/include/vtk for an installation.")
|
||||
ENDIF()
|
||||
SET(VTK_DIR_MESSAGE "VTK not found. Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
|
||||
|
||||
# Check whether VTK 4.0 has already been found.
|
||||
IF(_VTK_40_ALLOW AND VTK_DIR)
|
||||
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
SET(VTK_FOUND 1)
|
||||
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Use the Config mode of the find_package() command to find VTKConfig.
|
||||
# If this succeeds (possibly because VTK_DIR is already set), the
|
||||
# command will have already loaded VTKConfig.cmake and set VTK_FOUND.
|
||||
IF(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
|
||||
FIND_PACKAGE(VTK QUIET NO_MODULE)
|
||||
ENDIF()
|
||||
|
||||
# Special search for VTK 4.0.
|
||||
IF(_VTK_40_ALLOW AND NOT VTK_DIR)
|
||||
# Old scripts may set these directories in the CMakeCache.txt file.
|
||||
# They can tell us where to find VTKConfig.cmake.
|
||||
SET(VTK_DIR_SEARCH_LEGACY "")
|
||||
IF(VTK_BINARY_PATH AND USE_BUILT_VTK)
|
||||
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
|
||||
ENDIF(VTK_BINARY_PATH AND USE_BUILT_VTK)
|
||||
IF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
|
||||
${VTK_INSTALL_PATH}/lib/vtk)
|
||||
ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||
|
||||
# Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
|
||||
FIND_PATH(VTK_DIR
|
||||
NAMES UseVTK.cmake
|
||||
PATH_SUFFIXES vtk-4.0 vtk
|
||||
HINTS $ENV{VTK_DIR}
|
||||
|
||||
PATHS
|
||||
|
||||
# Support legacy cache files.
|
||||
${VTK_DIR_SEARCH_LEGACY}
|
||||
|
||||
# Read from the CMakeSetup registry entries. It is likely that
|
||||
# VTK will have been recently built.
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
|
||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
|
||||
|
||||
# Help the user find it if we cannot.
|
||||
DOC "The ${VTK_DIR_DESCRIPTION}"
|
||||
)
|
||||
|
||||
IF(VTK_DIR)
|
||||
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
SET(VTK_FOUND 1)
|
||||
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||
ELSE()
|
||||
# We found the wrong version. Pretend we did not find it.
|
||||
SET(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
IF(VTK_FOUND)
|
||||
# Set USE_VTK_FILE for backward-compatability.
|
||||
SET(USE_VTK_FILE ${VTK_USE_FILE})
|
||||
ELSE(VTK_FOUND)
|
||||
# VTK not found, explain to the user how to specify its location.
|
||||
IF(VTK_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR ${VTK_DIR_MESSAGE})
|
||||
ELSE(VTK_FIND_REQUIRED)
|
||||
IF(NOT VTK_FIND_QUIETLY)
|
||||
MESSAGE(STATUS ${VTK_DIR_MESSAGE})
|
||||
ENDIF(NOT VTK_FIND_QUIETLY)
|
||||
ENDIF(VTK_FIND_REQUIRED)
|
||||
ENDIF(VTK_FOUND)
|
||||
62
CMake/FinduLib.cmake
Normal file
62
CMake/FinduLib.cmake
Normal file
@@ -0,0 +1,62 @@
|
||||
# - Finds ROOT instalation
|
||||
# This module sets up ROOT information
|
||||
# It defines:
|
||||
# ULIB_FOUND If the uLib is found
|
||||
# ULIB_INCLUDE_DIRS PATH to the include directory
|
||||
# ULIB_LIBRARIES Most common libraries
|
||||
# ULIB_LIBRARY_DIRS PATH to the library directory
|
||||
#
|
||||
|
||||
include(uLibFindDependencies)
|
||||
include(uLibDebugMacro)
|
||||
|
||||
## CONFIG FIND -------------------------------------------------------------- ##
|
||||
|
||||
set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")
|
||||
unset(ULIB_CONFIG)
|
||||
find_package(ULIB ${ULIB_PACKAGE_VERSION} CONFIG
|
||||
NAMES uLib
|
||||
PATH_SUFFIXES ${ULIB_PACKAGE_NAME}
|
||||
)
|
||||
|
||||
debug(ULIB_CONFIG)
|
||||
debug(ULIB_CONSIDERED_CONFIGS)
|
||||
debug(ULIB_CONSIDERED_VERSIONS)
|
||||
debug(ULIB_INCLUDE_DIRS)
|
||||
debug(ULIB_LIBRARIES)
|
||||
|
||||
if(ULIB_CONFIG)
|
||||
set(ULIB_FOUND true)
|
||||
endif()
|
||||
|
||||
## MODULE FIND -------------------------------------------------------------- ##
|
||||
|
||||
#find_path(uLib_INCLUDE_DIR
|
||||
# NAMES ulib.h
|
||||
# PATH_SUFFIXES mutom-0.2
|
||||
#)
|
||||
#debug(uLib_INCLUDE_DIR)
|
||||
|
||||
#find_file(uLib_USE_FILE
|
||||
# NAMES uLib_exported_targets.cmake
|
||||
# PATHS lib lib64
|
||||
# PATH_SUFFIXES mutom-0.2
|
||||
#)
|
||||
#debug(uLib_USE_FILE)
|
||||
|
||||
#find_library(uLib_LIBRARY
|
||||
# NAMES libmutomCore.so
|
||||
# PATH_SUFFIXES mutom-0.2
|
||||
# )
|
||||
#debug(uLib_LIBRARY)
|
||||
|
||||
##set( uLib_PROCESS_INCLUDES uLib_INCLUDE_DIR ULIB_INCLUDE_DIRS )
|
||||
##set( uLib_PROCESS_LIBS uLib_LIBRARY ULIB_LIBRARIES )
|
||||
##libfind_process(uLib)
|
||||
|
||||
#set( ULIB_INCLUDE_DIRS ${uLib_INCLUDE_DIR} )
|
||||
#set( ULIB_LIBRARIES ${uLib_LIBRARY} )
|
||||
#include(FindPackageHandleStandardArgs)
|
||||
#find_package_handle_standard_args(uLib DEFAULT_MSG
|
||||
# uLib_LIBRARY uLib_INCLUDE_DIR)
|
||||
#mark_as_advanced(uLib_INCLUDE_DIR uLib_LIBRARY)
|
||||
11
CMake/clean-all.cmake
Normal file
11
CMake/clean-all.cmake
Normal file
@@ -0,0 +1,11 @@
|
||||
set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt
|
||||
${CMAKE_BINARY_DIR}/cmake_install.cmake
|
||||
${CMAKE_BINARY_DIR}/Makefile
|
||||
${CMAKE_BINARY_DIR}/CMakeFiles
|
||||
)
|
||||
|
||||
foreach(file ${cmake_generated})
|
||||
if (EXISTS ${file})
|
||||
file(REMOVE_RECURSE ${file})
|
||||
endif()
|
||||
endforeach(file)
|
||||
47
CMake/rmake.in
Normal file
47
CMake/rmake.in
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CONNECTION ---------------------------------------------------------------- ##
|
||||
USER=@REMOTE_BUILD_USER@
|
||||
MACHINES="@REMOTE_BUILD_MACHINES@"
|
||||
SSH=@REMOTE_BUILD_SSHBIN@
|
||||
PORT=@REMOTE_BUILD_SSHPORT@
|
||||
|
||||
# BUILD --------------------------------------------------------------------- ##
|
||||
|
||||
MAKE=@REMOTE_BUILD_MAKEBIN@
|
||||
BUILD_DIR=@REMOTE_BUILD_BULIDIR@
|
||||
SOURCE_DIR=@REMOTE_BUILD_SRCDIR@
|
||||
CURRENT_DIR=`pwd`
|
||||
ARGS=$@
|
||||
|
||||
|
||||
# FIND RELATIVE PATH -------------------------------------------------------- ##
|
||||
|
||||
function relpath {
|
||||
# both $1 and $2 are absolute paths
|
||||
# returns $2 relative to $1
|
||||
source=$1
|
||||
target=$2
|
||||
common_part=$source
|
||||
back=
|
||||
while [ "${target#$common_part}" = "${target}" ]; do
|
||||
common_part=$(dirname $common_part)
|
||||
back="../${back}"
|
||||
done
|
||||
echo ${back}${target#$common_part/}
|
||||
}
|
||||
|
||||
CURRENT_SRCDIR=$(cd -- ${CURRENT_DIR}/$(relpath $BUILD_DIR/ $SOURCE_DIR/)/ && pwd)
|
||||
|
||||
|
||||
|
||||
for m in ${MACHINES}; do
|
||||
echo "building into machine: ${m}"
|
||||
echo "remote commands: --------------------------------------------------------------------------------------------------------------"
|
||||
echo "source dir = ${SOURCE_DIR}"
|
||||
echo "build dir = ${BUILD_DIR}"
|
||||
echo "repath to LOCAL MACHINE source dir = ${CURRENT_SRCDIR}"
|
||||
echo "${SSH} -p ${PORT} ${USER}@${m} ${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g' 3>&1 1>&2 2>&3"
|
||||
echo " ------------------------------------------------------------------------------------------------------------------------------"
|
||||
${SSH} -p ${PORT} ${USER}@${m} "${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g'" 3>&1 1>&2 2>&3
|
||||
done
|
||||
64
CMake/uLibCommon.cmake
Normal file
64
CMake/uLibCommon.cmake
Normal file
@@ -0,0 +1,64 @@
|
||||
include(uLibMacros)
|
||||
include_guard(ULIB_COMMON_CMAKE)
|
||||
|
||||
include(uLibDebugMacro)
|
||||
|
||||
## DIRECTORIES -------------------------------------------------------------- ##
|
||||
|
||||
set(ULIB_PARENT_PATH "${PROJECT_SOURCE_DIR}")
|
||||
message(STATUS "Setting uLib parent path to: ${ULIB_PARENT_PATH}")
|
||||
|
||||
## Build directories ##
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "build path for lib")
|
||||
mark_as_advanced(LIBRARY_OUTPUT_PATH)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "build path for binaries")
|
||||
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
|
||||
|
||||
## Install directories ##
|
||||
set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
|
||||
set(PACKAGE_INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
|
||||
set(PACKAGE_INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
|
||||
set(PACKAGE_INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
set(DEF_INSTALL_CMAKE_DIR CMake)
|
||||
else()
|
||||
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
|
||||
endif()
|
||||
set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
|
||||
|
||||
# Make relative paths absolute (needed later on)
|
||||
foreach(p LIB BIN INC DATA CMAKE)
|
||||
set(var PACKAGE_INSTALL_${p}_DIR)
|
||||
if(NOT IS_ABSOLUTE "${${var}}")
|
||||
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
|
||||
endif()
|
||||
mark_as_advanced(PACKAGE_INSTALL_${p}_DIR)
|
||||
debug(PACKAGE_INSTALL_${p}_DIR)
|
||||
endforeach()
|
||||
|
||||
# add the binary tree to the search path for include files
|
||||
# so that we will find config.h
|
||||
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||
include_directories(${PROJECT_BINARY_DIR})
|
||||
include_directories(${SRC_DIR})
|
||||
|
||||
|
||||
## GLOBAL OPTIONS ----------------------------------------------------------- ##
|
||||
|
||||
# Set a default build type to RELEASE WITH DEBUG INFO if none was specified
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "Setting build type to 'Release' as none was specified.")
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo 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()
|
||||
|
||||
set(CMAKE_CXX_WARNING_OPTION "" CACHE STRING "Warning level -WAll to verbose all warnings")
|
||||
set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE STRING "Verbose compile output switch")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}")
|
||||
|
||||
|
||||
|
||||
|
||||
57
CMake/uLibConfigHeader.cmake
Normal file
57
CMake/uLibConfigHeader.cmake
Normal file
@@ -0,0 +1,57 @@
|
||||
include(uLibMacros)
|
||||
include_guard(ULIB_CONFIG_HEADER_CMAKE)
|
||||
|
||||
|
||||
## CONFIG ------------------------------------------------------------------- ##
|
||||
|
||||
message("/////////// CONFIG HEADER //////////////")
|
||||
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
## force to use PP variadics (FIX) ##
|
||||
set(BOOST_PP_VARIADICS ON)
|
||||
|
||||
message(STATUS "PROJECT NAME = ${PROJECT_NAME}")
|
||||
message(STATUS "PACKAGE VERSION = ${PACKAGE_VERSION}")
|
||||
message(STATUS "PACKAGE NAME = ${PACKAGE_NAME}")
|
||||
execute_process(COMMAND "svnversion"
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE SVN_REVISION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE )
|
||||
|
||||
message(STATUS "SVN REVISION = ${SVN_REVISION}")
|
||||
|
||||
CHECK_INCLUDE_FILES(inittypes.h HAVE_INITTYPES_H)
|
||||
CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
|
||||
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
|
||||
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
|
||||
|
||||
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
|
||||
CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
|
||||
CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC)
|
||||
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)
|
||||
|
||||
CHECK_INCLUDE_FILES(math.h HAVE_MATH_H)
|
||||
CHECK_FUNCTION_EXISTS(fsetround HAVE_FSETROUND)
|
||||
CHECK_FUNCTION_EXISTS(floor HAVE_FLOOR)
|
||||
CHECK_FUNCTION_EXISTS(pow HAVE_POW)
|
||||
CHECK_FUNCTION_EXISTS(sqrt HAVE_SQRT)
|
||||
|
||||
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
|
||||
CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR)
|
||||
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
|
||||
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
|
||||
|
||||
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
|
||||
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
|
||||
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
|
||||
|
||||
CHECK_INCLUDE_FILES(assert.h HAVE_ASSERT_H)
|
||||
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/CMakeConfig.in.h"
|
||||
"${PROJECT_BINARY_DIR}/config.h"
|
||||
)
|
||||
54
CMake/uLibDebugMacro.cmake
Normal file
54
CMake/uLibDebugMacro.cmake
Normal file
@@ -0,0 +1,54 @@
|
||||
include(uLibMacros)
|
||||
include_guard(ULIB_DEBUG_MACRO_CMAKE)
|
||||
|
||||
|
||||
set(CMAKE_CONFIGURE_DEBUG_ENABLE ON CACHE BOOL "cmake configure debugger")
|
||||
set(CMAKE_CONFIGURE_DEBUG_LIST OFF CACHE BOOL "cmake debugger show list enable")
|
||||
mark_as_advanced(
|
||||
CMAKE_CONFIGURE_DEBUG_ENABLE
|
||||
CMAKE_CONFIGURE_DEBUG_LIST
|
||||
)
|
||||
|
||||
macro(debug str)
|
||||
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||
set(var ${${str}})
|
||||
list(LENGTH var len)
|
||||
if((${len} GREATER 1) AND CMAKE_CONFIGURE_DEBUG_LIST)
|
||||
message(STATUS "[DEBUG] [${str}] list: ")
|
||||
foreach(item ${var})
|
||||
message(STATUS " -> ${item}")
|
||||
endforeach()
|
||||
else()
|
||||
message(STATUS "[DEBUG] [${str}] ${var}")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(debug_list str)
|
||||
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||
set(var ${${str}})
|
||||
list(LENGTH var len)
|
||||
if((${len} GREATER 1))
|
||||
message(STATUS "[DEBUG] [${str}] list: ")
|
||||
foreach(item ${var})
|
||||
message(STATUS " -> ${item}")
|
||||
endforeach()
|
||||
else()
|
||||
message(STATUS "[DEBUG] [${str}] ${var}")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(debug_package str)
|
||||
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||
set(have ${str}_FOUND)
|
||||
if(${have})
|
||||
debug("${str}_INCLUDE_DIRS")
|
||||
debug("${str}_LIBRARIES")
|
||||
debug("${str}_LIBRARY_DIRS")
|
||||
debug("${str}_DEFINITIONS")
|
||||
else(${have})
|
||||
message(WARNING "package ${str} not found")
|
||||
endif(${have})
|
||||
endif(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||
endmacro()
|
||||
122
CMake/uLibFindDependencies.cmake
Normal file
122
CMake/uLibFindDependencies.cmake
Normal file
@@ -0,0 +1,122 @@
|
||||
include(uLibMacros)
|
||||
include_guard(ULIB_FIND_DEPENDENCIES_CMAKE)
|
||||
|
||||
include(uLibDebugMacro)
|
||||
|
||||
################################################################################
|
||||
## PKG FIND ##
|
||||
message("/////////// LOOKING FOR EXTERNAL PACKAGES //////////////")
|
||||
|
||||
## BOOST ##
|
||||
message(STATUS "## BOOST ##")
|
||||
set(Boost_USE_STATIC_LIBS OFF)
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
set(Boost_USE_STATIC_RUNTIME OFF)
|
||||
|
||||
find_package(Boost 1.45.0 COMPONENTS serialization signals program_options REQUIRED)
|
||||
if(Boost_FOUND)
|
||||
set(HAVE_BOOST true)
|
||||
endif(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
## OPEN MP ##
|
||||
message(STATUS "## OPEN MP ##")
|
||||
find_package(OpenMP)
|
||||
option(OpenMP_ACTIVE "Activate OpenMP parallel compilation" ON)
|
||||
if(OPENMP_FOUND AND OpenMP_ACTIVE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
|
||||
endif(OPENMP_FOUND AND OpenMP_ACTIVE)
|
||||
|
||||
## EIGEN ##
|
||||
message(STATUS "## EIGEN ##")
|
||||
# option(USE_EIGEN ON) ## REQUIRED
|
||||
find_package(Eigen3 REQUIRED)
|
||||
debug(EIGEN3_INCLUDE_DIR)
|
||||
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||
|
||||
## ROOT ##
|
||||
message(STATUS "## ROOT ##")
|
||||
option(ULIB_USE_ROOT "Activate use of Root integration" ON)
|
||||
### <<<--- ROOT IS REQUIRED FOR THE MOMENT ###
|
||||
#if(ULIB_USE_ROOT)
|
||||
include(FindROOTv6)
|
||||
find_package(ROOT REQUIRED)
|
||||
if(ROOT_FOUND)
|
||||
set(HAVE_ROOT true)
|
||||
include_directories(${ROOT_INCLUDE_DIR})
|
||||
link_directories(${ROOT_LIBRARY_DIR})
|
||||
debug(ROOT_INCLUDE_DIR)
|
||||
debug(ROOT_LIBRARY_DIR)
|
||||
debug(ROOT_LIBRARIES)
|
||||
else()
|
||||
message(WARNING "Root not found")
|
||||
endif(ROOT_FOUND)
|
||||
#endif(ULIB_USE_ROOT)
|
||||
|
||||
|
||||
## VTK ##
|
||||
option(ULIB_USE_VTK "Activate use of Vtk Visual Pipelines" ON)
|
||||
if(ULIB_USE_VTK)
|
||||
message(STATUS "## VTK ##")
|
||||
message(STATUS "Looking for VTK...")
|
||||
set(VTK_DIR "PATH/TO/VTK/BUILD/DIRECTORY")
|
||||
mark_as_advanced(VTK_DIR)
|
||||
find_package(VTK REQUIRED)
|
||||
include(${VTK_USE_FILE})
|
||||
#message(STATUS "VTK included libraries: ${VTK_LIBRARIES}")
|
||||
debug(VTK_USE_FILE)
|
||||
debug(VTK_INCLUDE_DIRS)
|
||||
debug(VTK_LIBRARY_DIRS)
|
||||
debug(VTK_LIBRARIES)
|
||||
# get_directory_property(compile_def COMPILE_DEFINITIONS)
|
||||
# debug(compile_def)
|
||||
endif(ULIB_USE_VTK)
|
||||
|
||||
|
||||
## GEANT ##
|
||||
option(ULIB_USE_GEANT4 "Activate use of GEANT Integration" ON)
|
||||
message(STATUS "## GEANT 4 ##")
|
||||
#include(FindGEANT4) # disabled using system finder
|
||||
find_package(Geant4)
|
||||
set(GEANT4_FOUND Geant4_DIR)
|
||||
if(GEANT4_FOUND AND ULIB_USE_GEANT4)
|
||||
message(STATUS "Looking for Geant4... - Geant4 found in ${Geant4_DIR}")
|
||||
set(HAVE_GEANT4 true)
|
||||
include_directories(${Geant4_INCLUDE_DIRS}) # Add -I type paths
|
||||
add_definitions(${Geant4_DEFINITIONS}) # Add -D type defs
|
||||
debug_package(Geant4)
|
||||
endif(GEANT4_FOUND AND ULIB_USE_GEANT4)
|
||||
|
||||
## QT4 ##
|
||||
option(ULIB_USE_QT4 "Activate use of Qt Framework" ON)
|
||||
if(ULIB_USE_QT4)
|
||||
message(STATUS "## QT4 ##")
|
||||
find_package(Qt4)
|
||||
# include_directories(${Qt4_INCLUDE_DIRS})
|
||||
# debug(Qt4_INCLUDE_DIRS)
|
||||
endif(ULIB_USE_QT4)
|
||||
|
||||
## QT5 ##
|
||||
option(ULIB_USE_QT5 "Activate use of Qt Framework" ON)
|
||||
if(ULIB_USE_QT5)
|
||||
message(STATUS "## QT5 ##")
|
||||
find_package(Qt5Widgets)
|
||||
# include_directories(${Qt5_INCLUDE_DIRS})
|
||||
# debug(Qt5_INCLUDE_DIRS)
|
||||
endif(ULIB_USE_QT5)
|
||||
|
||||
## READLINE ##
|
||||
message(STATUS "## READLINE ##")
|
||||
find_package(ReadLine)
|
||||
include_directories(${READLINE_INCLUDE_DIR})
|
||||
debug(READLINE_INCLUDE_DIR)
|
||||
|
||||
## STD MATH REQUIRED ##
|
||||
#message(STATUS "## STD MATH ##")
|
||||
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
|
||||
set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m)
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
47
CMake/uLibGenerateRMake.cmake
Normal file
47
CMake/uLibGenerateRMake.cmake
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
include(uLibMacros)
|
||||
include(uLibDebugMacro)
|
||||
|
||||
## MAKE REMOTE -------------------------------------------------------------- ##
|
||||
|
||||
#set(BUILD_REMOTE_MACHINES "10.62.19.4" CACHE STRING "remote build in cloud machine")
|
||||
#set(BUILD_REMOTE_USER "rigoni" CACHE STRING "remote build user")
|
||||
#set(BUILD_REMOTE_CMD "${SSH_COMMAND} ${BUILD_REMOTE_USER}@${BUILD_REMOTE_MACHINES} \"make -C \"")
|
||||
#add_custom_target(cloud COMMAND ${SSH_COMMAND})
|
||||
|
||||
|
||||
|
||||
set(REMOTE_BUILD_USER "$ENV{USER}" CACHE STRING "ssh remote build user name")
|
||||
|
||||
execute_process(COMMAND hostname -I OUTPUT_VARIABLE HOSTNAME_IP)
|
||||
set(REMOTE_BUILD_MACHINES ${HOSTNAME_IP} CACHE STRING "ssh remote build machines")
|
||||
|
||||
find_file(SSH_EXECUTABLE ssh PATHS /bin/local/bin /usr/bin /bin)
|
||||
set(REMOTE_BUILD_SSHBIN ${SSH_EXECUTABLE} CACHE FILEPATH "ssh remote build command path")
|
||||
set(REMOTE_BUILD_SSHPORT 22 CACHE STRING "ssh remote build port")
|
||||
|
||||
find_file(MAKE_EXECUTABLE make PATHS /usr/local/bin /usr/bin /bin)
|
||||
set(REMOTE_BUILD_MAKEBIN ${MAKE_EXECUTABLE} CACHE FILEPATH "ssh remote build make path")
|
||||
set(REMOTE_BUILD_BULIDIR ${PROJECT_BINARY_DIR} CACHE PATH "ssh remote build build path")
|
||||
set(REMOTE_BUILD_SRCDIR ${PROJECT_SOURCE_DIR} CACHE PATH "ssh remote build source path")
|
||||
|
||||
message("remote build ----------------------------------------------------------")
|
||||
debug(REMOTE_BUILD_USER)
|
||||
debug(REMOTE_BUILD_MACHINES)
|
||||
debug(REMOTE_BUILD_SSHBIN)
|
||||
debug(REMOTE_BUILD_SSHPORT)
|
||||
debug(REMOTE_BUILD_MAKEBIN)
|
||||
message("-----------------------------------------------------------------------")
|
||||
|
||||
|
||||
find_file(RMAKE_IN_FILE rmake.in PATHS ${CMAKE_MODULE_PATH})
|
||||
configure_file(
|
||||
"${RMAKE_IN_FILE}"
|
||||
"${PROJECT_BINARY_DIR}/CMake/rmake" @ONLY
|
||||
)
|
||||
|
||||
file(COPY "${PROJECT_BINARY_DIR}/CMake/rmake"
|
||||
DESTINATION "${PROJECT_BINARY_DIR}"
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
|
||||
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
12
CMake/uLibMacros.cmake
Normal file
12
CMake/uLibMacros.cmake
Normal file
@@ -0,0 +1,12 @@
|
||||
#if(ULIB_MACROS_CMAKE)
|
||||
# return()
|
||||
#endif()
|
||||
#set(ULIB_MACROS_CMAKE 1)
|
||||
|
||||
|
||||
function(include_guard var)
|
||||
if(${var})
|
||||
return()
|
||||
endif()
|
||||
set(${var} 1)
|
||||
endfunction()
|
||||
186
CMake/uLibTargetMacros.cmake
Normal file
186
CMake/uLibTargetMacros.cmake
Normal file
@@ -0,0 +1,186 @@
|
||||
|
||||
include(uLibMacros)
|
||||
include_guard(ULIB_TARGET_MACRO_CMAKE)
|
||||
|
||||
## adds library target
|
||||
macro(uLib_add_library name)
|
||||
add_library(${name} ${ARGN})
|
||||
if(NOT ULIB_INSTALL_NO_LIBRARIES)
|
||||
set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name})
|
||||
endif(NOT ULIB_INSTALL_NO_LIBRARIES)
|
||||
endmacro(uLib_add_library)
|
||||
|
||||
################################################################################
|
||||
## Add SHARED library target ##
|
||||
|
||||
# HEADERS and SOURCES must be defined as list of library headers and sources
|
||||
macro(uLib_add_shared_library name)
|
||||
if(COMMAND cmake_policy)
|
||||
# cmake_policy( SET CMP0022 NEW )
|
||||
endif(COMMAND cmake_policy)
|
||||
|
||||
set(mname ${PACKAGE_LIBPREFIX}${name})
|
||||
|
||||
if(SOURCES)
|
||||
uLib_add_library(${mname} SHARED ${SOURCES})
|
||||
set(shared ${ULIB_SHARED_LIBRARIES})
|
||||
list(APPEND shared ${mname})
|
||||
set(ULIB_SHARED_LIBRARIES ${shared} PARENT_SCOPE)
|
||||
source_group("${project_name}\\${name}" FILES ${SOURCES})
|
||||
set_target_properties(${mname} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_SOVERSION}
|
||||
INTERFACE_LINK_LIBRARIES "${LIBRARIES}"
|
||||
LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- ok for cmake from 2.12 ?
|
||||
IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- breaks cmake after 2.11 ?
|
||||
# PUBLIC_HEADER ""
|
||||
)
|
||||
debug(LIBRARIES)
|
||||
|
||||
install(TARGETS ${mname}
|
||||
EXPORT "${PROJECT_NAME}Targets"
|
||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib
|
||||
# PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev
|
||||
)
|
||||
endif(SOURCES)
|
||||
|
||||
if(HEADERS)
|
||||
foreach(header ${HEADERS})
|
||||
install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name})
|
||||
endforeach(header)
|
||||
endif(HEADERS)
|
||||
|
||||
endmacro(uLib_add_shared_library)
|
||||
|
||||
|
||||
################################################################################
|
||||
## Add Target ##
|
||||
|
||||
macro(uLib_add_target name)
|
||||
debug(${name})
|
||||
add_executable(${name} ${ARGN})
|
||||
set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name})
|
||||
|
||||
set(exported ${ULIB_EXPORTED_TARGETS})
|
||||
list(APPEND exported ${name})
|
||||
set(ULIB_EXPORTED_TARGETS ${exported} PARENT_SCOPE)
|
||||
|
||||
install(TARGETS ${name}
|
||||
EXPORT "${PROJECT_NAME}Targets"
|
||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
||||
)
|
||||
ENDMACRO(uLib_add_target)
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
## TESTS ##
|
||||
|
||||
# TESTS and LIBRARIES must be defined
|
||||
macro(uLib_add_tests name)
|
||||
foreach(tn ${TESTS})
|
||||
add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp)
|
||||
add_test(${tn} ${PACKAGE_INSTALL_BIN_DIR}/${tn})
|
||||
|
||||
# adds dependencies to all selected modules in uLib
|
||||
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||
# add_dependencies(${tn} ${project_name}${module})
|
||||
# endforeach(module)
|
||||
|
||||
# adds libraries dependencies
|
||||
foreach(library ${LIBRARIES})
|
||||
target_link_libraries(${tn} ${library})
|
||||
endforeach(library)
|
||||
|
||||
endforeach(tn)
|
||||
|
||||
# custom target to compile all tests
|
||||
add_custom_target(all-${name}-tests)
|
||||
add_dependencies(all-${name}-tests ${TESTS})
|
||||
endmacro(uLib_add_tests name)
|
||||
|
||||
|
||||
################################################################################
|
||||
## UTILS ##
|
||||
|
||||
# UTILS and LIBRARIES must be defined
|
||||
macro(uLib_add_utils name)
|
||||
foreach(tn ${UTILS})
|
||||
add_executable(${tn} ${tn}.cpp)
|
||||
install(TARGETS ${tn} RUNTIME DESTINATION bin)
|
||||
|
||||
# adds dependencies to all selected modules in uLib
|
||||
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||
# add_dependencies(${tn} ${project_name}${module})
|
||||
# endforeach(module)
|
||||
|
||||
# adds libraries dependencies
|
||||
foreach(library ${LIBRARIES})
|
||||
target_link_libraries(${tn} ${library})
|
||||
endforeach(library)
|
||||
|
||||
endforeach(tn)
|
||||
|
||||
# custom target to compile all tests
|
||||
add_custom_target(all-${name})
|
||||
add_dependencies(all-${name} ${UTILS})
|
||||
|
||||
endmacro(uLib_add_utils name)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function(get_gcc_compile_flags target out_flags)
|
||||
string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" name)
|
||||
set(flags "${${name}} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILER_ARG1}")
|
||||
get_target_property(value ${target} COMPILE_FLAGS)
|
||||
if (value)
|
||||
list(APPEND flags ${value})
|
||||
endif()
|
||||
get_target_property(value ${target} TYPE)
|
||||
get_target_property(value ${target} COMPILE_DEFINITIONS)
|
||||
if (value)
|
||||
foreach(item ${value})
|
||||
list(APPEND flags "-D${item}")
|
||||
endforeach()
|
||||
endif()
|
||||
STRING(TOUPPER "COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE}" name)
|
||||
get_target_property(value ${target} ${name})
|
||||
if (value)
|
||||
foreach(item ${value})
|
||||
list(APPEND flags "-D${item}")
|
||||
endforeach()
|
||||
endif()
|
||||
get_directory_property(value DEFINITIONS)
|
||||
if (value)
|
||||
list(APPEND flags ${value})
|
||||
endif()
|
||||
get_directory_property(value INCLUDE_DIRECTORIES)
|
||||
if (value)
|
||||
foreach(item ${value})
|
||||
list(APPEND flags "-I${item}")
|
||||
endforeach()
|
||||
endif()
|
||||
set(${out_flags} ${flags} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_gcc_link_flags target out_flags)
|
||||
set(flags)
|
||||
get_target_property(value ${target} LINK_FLAGS_RELEASE)
|
||||
if (value)
|
||||
message(STATUS "-> ${flags}")
|
||||
list(APPEND flags ${value})
|
||||
endif()
|
||||
get_directory_property(value LINK_DIRECTORIES)
|
||||
if (value)
|
||||
message(STATUS "-> ${flags}")
|
||||
foreach(item ${value})
|
||||
list(APPEND flags "-L${item}")
|
||||
endforeach()
|
||||
endif()
|
||||
message(STATUS "-> ${flags}")
|
||||
set(${out_flags} ${flags} PARENT_SCOPE)
|
||||
endfunction()
|
||||
128
CMakeConfig.in.h
Normal file
128
CMakeConfig.in.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
#ifndef HAVE_CONFIG_H
|
||||
#define HAVE_CONFIG_H
|
||||
|
||||
/* Compiler must have variadic macros */
|
||||
//#cmakedefine BOOST_PP_VARIADICS
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#cmakedefine HAVE_ASSERT_H
|
||||
|
||||
/* Defined if the requested minimum BOOST version is satisfied */
|
||||
#cmakedefine HAVE_BOOST
|
||||
|
||||
/* Define to 1 if you have <boost/archive/text_oarchive.hpp> */
|
||||
#cmakedefine HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP
|
||||
|
||||
/* Define to 1 if you have <boost/array.hpp> */
|
||||
#cmakedefine HAVE_BOOST_ARRAY_HPP
|
||||
|
||||
/* Define to 1 if you have <boost/program_options.hpp> */
|
||||
#cmakedefine HAVE_BOOST_PROGRAM_OPTIONS_HPP
|
||||
|
||||
/* Define to 1 if you have <boost/signal.hpp> */
|
||||
#cmakedefine HAVE_BOOST_SIGNAL_HPP
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#cmakedefine HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `fesetround' function. */
|
||||
#cmakedefine HAVE_FESETROUND
|
||||
|
||||
/* Define to 1 if you have the `floor' function. */
|
||||
#cmakedefine HAVE_FLOOR
|
||||
|
||||
/* Having Geant4 installed */
|
||||
#cmakedefine HAVE_GEANT4
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#cmakedefine HAVE_INTTYPES_H
|
||||
|
||||
/* Define if you have libreadline */
|
||||
#cmakedefine HAVE_LIBREADLINE
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#cmakedefine HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#cmakedefine HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `pow' function. */
|
||||
#cmakedefine HAVE_POW
|
||||
|
||||
/* Having root installed */
|
||||
#cmakedefine HAVE_ROOT
|
||||
|
||||
/* Define to 1 if you have the `sqrt' function. */
|
||||
#cmakedefine HAVE_SQRT
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#cmakedefine HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#cmakedefine HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#cmakedefine HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#cmakedefine HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#cmakedefine HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#cmakedefine HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strstr' function. */
|
||||
#cmakedefine HAVE_STRSTR
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#cmakedefine HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#cmakedefine HAVE__BOOL
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#cmakedefine LT_OBJDIR
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#cmakedefine PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#cmakedefine PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#cmakedefine PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#cmakedefine PACKAGE_URL "@PACKAGE_URL@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#cmakedefine STDC_HEADERS
|
||||
|
||||
/* SVN revision number */
|
||||
#cmakedefine SVN_REVISION "@SVN_REVISION@"
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
#endif // HAVE_CONFIG_H
|
||||
234
CMakeLists.txt
Normal file
234
CMakeLists.txt
Normal file
@@ -0,0 +1,234 @@
|
||||
|
||||
################################################################################
|
||||
##### CMAKE LISTS ##############################################################
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
execute_process(COMMAND "clear")
|
||||
message("//////////////////////////////////////////////////////////////////////")
|
||||
message("/////////////////// CMAKE PJOJECT CONFIGURATION //////////////////////")
|
||||
message("//////////////////////////////////////////////////////////////////////")
|
||||
|
||||
## -------------------------------------------------------------------------- ##
|
||||
|
||||
project(uLib)
|
||||
|
||||
# The version number.
|
||||
set(PROJECT_VERSION_MAJOR 0)
|
||||
set(PROJECT_VERSION_MINOR 2)
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
|
||||
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
|
||||
|
||||
set(PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
set(PACKAGE_NAME "mutom-${PROJECT_VERSION}" CACHE STRING "name of the package defined inside code (config.h)")
|
||||
set(PACKAGE_LIBPREFIX "mutom" CACHE STRING "suffix for each library component name")
|
||||
set(PACKAGE_URL "http:://mutom.pd.infn.it" CACHE STRING "url of the project")
|
||||
set(PACKAGE_AUTHOR "Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>")
|
||||
|
||||
|
||||
## MACROS ------------------------------------------------------------------- ##
|
||||
|
||||
set(ULIB_CMAKE_DIR "${PROJECT_SOURCE_DIR}/CMake")
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
|
||||
message(STATUS "Module path: ${CMAKE_MODULE_PATH}")
|
||||
|
||||
include(uLibMacros)
|
||||
include(uLibDebugMacro)
|
||||
include(uLibTargetMacros)
|
||||
include(uLibGenerateRMake)
|
||||
|
||||
|
||||
|
||||
## GLOBALS ------------------------------------------------------------------ ##
|
||||
|
||||
include(uLibCommon)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") ## Add flags here ##
|
||||
|
||||
enable_testing()
|
||||
|
||||
## FIND PACKAGES ------------------------------------------------------------ ##
|
||||
|
||||
include(uLibFindDependencies)
|
||||
|
||||
|
||||
## CONFIG ------------------------------------------------------------------- ##
|
||||
|
||||
include(uLibConfigHeader)
|
||||
|
||||
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
|
||||
|
||||
## select modules ##
|
||||
set(ULIB_SELECTED_MODULES
|
||||
ltk
|
||||
Core
|
||||
Math
|
||||
Detectors
|
||||
Root
|
||||
)
|
||||
|
||||
## uLib_add_shared_library puts names there
|
||||
set(ULIB_SHARED_LIBRARIES)
|
||||
|
||||
if(ULIB_USE_VTK)
|
||||
LIST(APPEND ULIB_SELECTED_MODULES Vtk)
|
||||
endif(ULIB_USE_VTK)
|
||||
|
||||
## this gets ulib modules into a variable ##
|
||||
function(uLib_modules result)
|
||||
set(out)
|
||||
foreach(module ${ULIB_SELECTED_MODULES})
|
||||
list(APPEND out ${PACKAGE_LIBPREFIX}${module})
|
||||
endforeach(module)
|
||||
set(${result} "${out}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
||||
## ENTERING MODULES SUBDIRECTORIES ##
|
||||
message("/////////// SELECTED MODULES //////////////")
|
||||
foreach(module ${ULIB_SELECTED_MODULES})
|
||||
message(STATUS "adding module: ${module}")
|
||||
set( uLib-module ${module})
|
||||
include_directories(${SRC_DIR}/${module})
|
||||
add_subdirectory(${SRC_DIR}/${module})
|
||||
endforeach(module)
|
||||
|
||||
## SINGLE LIBRARY LINKING ## (work in progress ... )
|
||||
option(ULIB_SINGLELIBRARY "Link everything to a single library" OFF)
|
||||
if(ULIB_SINGLELIBRARY)
|
||||
# set(modgrp)
|
||||
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||
# set(grpn srcgrp_${module})
|
||||
# list(APPEND modgrp ${grpn})
|
||||
# endforeach(module)
|
||||
# add_library(${project_name} SHARED ${srcgrp_Core})
|
||||
endif(ULIB_SINGLELIBRARY)
|
||||
|
||||
## UTILITIES ##
|
||||
add_subdirectory("${SRC_DIR}/utils/make_recipe")
|
||||
|
||||
|
||||
## PKG CONFIG compatible file ----------------------------------------------- ##
|
||||
|
||||
set(PKGCONFIG_FILE_ENABLE OFF CACHE BOOL "enable pkg-config file")
|
||||
if(PKGCONFIG_FILE_ENABLE)
|
||||
message("/////////// PKG-CONFIG DISTILLER //////////////")
|
||||
set(PKGCONFIG_FILE_DESTDIR "/lib/pkgconfig/" CACHE PATH "destination path for pkg-config file")
|
||||
set(PKGCONFIG_LIBS)
|
||||
|
||||
message(STATUS "[cflags] ${CMAKE_C_FLAGS}")
|
||||
message(STATUS "[cxxflags] ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
foreach(module ${ULIB_SHARED_LIBRARIES})
|
||||
set(PKGCONFIG_LIBS "${PKGCONFIG_LIBS} ${CMAKE_LINK_LIBRARY_FLAG}${module}")
|
||||
endforeach(module)
|
||||
message(STATUS "[libs] ${PKGCONFIG_LIBS}")
|
||||
|
||||
set(PKGCONFIG_FLAGS)
|
||||
#add_custom_target(Dummy)
|
||||
|
||||
# add the executable
|
||||
uLib_add_target(Dummy test.cpp)
|
||||
target_link_libraries(Dummy ${PACKAGE_LIBPREFIX}Core)
|
||||
target_link_libraries(Dummy ${Boost_SERIALIZATION_LIBRARY})
|
||||
target_link_libraries(Dummy ${Boost_SIGNALS_LIBRARY})
|
||||
target_link_libraries(Dummy ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
target_link_libraries(Dummy ${Geant4_LIBRARIES})
|
||||
target_link_libraries(Dummy ${ROOT_LIBRARIES})
|
||||
target_link_libraries(Dummy ${VTK_LIBRARIES})
|
||||
|
||||
get_gcc_compile_flags(Dummy, gcc_flags_list)
|
||||
foreach(item ${gcc_flags_list})
|
||||
message(STATUS "[gcc cflags] ${item}")
|
||||
set(PKGCONFIG_FLAGS "${PKGCONFIG_FLAGS} ${item}")
|
||||
endforeach(item)
|
||||
message(STATUS "[includes] ${PKGCONFIG_FLAGS}")
|
||||
|
||||
get_gcc_link_flags(Dummy, gcc_flags_list)
|
||||
foreach(item ${gcc_flags_list})
|
||||
message(STATUS "[gcc libs] ${item}")
|
||||
endforeach(item)
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/CMakePkgConfig.pc.in"
|
||||
"${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc"
|
||||
)
|
||||
INSTALL_FILES(${PKGCONFIG_FILE_DESTDIR} FILES ${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc)
|
||||
|
||||
message("///////////////////////////////////////////")
|
||||
endif(PKGCONFIG_FILE_ENABLE)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## INSTALLS AND EXPORTS ----------------------------------------------------- ##
|
||||
|
||||
#export(PACKAGE uLib)
|
||||
export(PACKAGE ULIB)
|
||||
export(TARGETS ${ULIB_SHARED_LIBRARIES} ${ULIB_EXPORTED_TARGETS}
|
||||
FILE "${PROJECT_BINARY_DIR}/uLibTargets.cmake" )
|
||||
#export(TARGETS ${ULIB_EXPORTED_TARGETS}
|
||||
# FILE "${PROJECT_BINARY_DIR}/uLibExeTargets.cmake" )
|
||||
|
||||
|
||||
# Create the FooBarConfig.cmake and FooBarConfigVersion files
|
||||
file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
|
||||
"${PACKAGE_INSTALL_INC_DIR}")
|
||||
# ... for the build tree
|
||||
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
|
||||
configure_file(uLibConfig.cmake.in
|
||||
"${PROJECT_BINARY_DIR}/uLibConfig.cmake" @ONLY)
|
||||
# ... for the install tree
|
||||
set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
|
||||
configure_file(uLibConfig.cmake.in
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake" @ONLY)
|
||||
# ... for both
|
||||
configure_file(uLibConfigVersion.cmake.in
|
||||
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
|
||||
|
||||
# Install the FooBarConfig.cmake and FooBarConfigVersion.cmake
|
||||
install(FILES
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
|
||||
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake"
|
||||
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||
|
||||
# Install the export set for use with the install-tree
|
||||
install(EXPORT "${PROJECT_NAME}Targets" DESTINATION
|
||||
"${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/ulib.h DESTINATION ${PACKAGE_INSTALL_INC_DIR})
|
||||
|
||||
|
||||
|
||||
## dummy main executable ---------------------------------------------------- ##
|
||||
|
||||
# add the executable
|
||||
add_executable(Coretest test.cpp)
|
||||
target_link_libraries(Coretest ${PACKAGE_LIBPREFIX}Core)
|
||||
#target_link_libraries(Coretest ${Boost_SERIALIZATION_LIBRARY})
|
||||
#target_link_libraries(Coretest ${Boost_SIGNALS_LIBRARY})
|
||||
#target_link_libraries(Coretest ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
#target_link_libraries(Coretest ${Geant4_LIBRARIES})
|
||||
#target_link_libraries(Coretest ${ROOT_LIBRARIES})
|
||||
#target_link_libraries(Coretest ${VTK_LIBRARIES})
|
||||
|
||||
#message( "---------------------------------------------------------------------" )
|
||||
#execute_process(COMMAND
|
||||
# "ls"
|
||||
## "cmake --find-package -DNAME=uLib -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=COMPILE"
|
||||
# )
|
||||
#message( "---------------------------------------------------------------------" )
|
||||
|
||||
## -------------------------------------------------------------------------- ##
|
||||
|
||||
|
||||
# TODO clean also subdirectories
|
||||
add_custom_target(clean-cmake-files
|
||||
COMMAND ${CMAKE_COMMAND} -P ${ULIB_CMAKE_DIR}/clean-all.cmake
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13
CMakePkgConfig.pc.in
Normal file
13
CMakePkgConfig.pc.in
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: Mutom Library (INFN)
|
||||
Description: Library for Muon Tomography experiments.
|
||||
Url: @PACKAGE_URL@
|
||||
Version: @PACKAGE_VERSION@
|
||||
Requires: eigen3
|
||||
Libs: -L${libdir} @PKGCONFIG_LIBS@
|
||||
Cflags: @CMAKE_C_FLAGS@ @CMAKE_CXX_FLAGS@ @PKGCONFIG_INCLUDES@
|
||||
54
Common.am
Normal file
54
Common.am
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
|
||||
if DEBUG
|
||||
OPT = -D_DEBUG -g3 -O0
|
||||
OPT_LD = -no-install
|
||||
else
|
||||
OPT = -DNDEBUG -O3
|
||||
OPT_LD =
|
||||
endif
|
||||
|
||||
if PARAL_MP
|
||||
OPEN_MP = -fopenmp
|
||||
else
|
||||
OPEN_MP =
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# fix it with proper macro expansion
|
||||
EIGEN = $(EIGEN3_CFLAGS)
|
||||
|
||||
# Root Flags
|
||||
ROOTCFLAGS = @ROOTCFLAGS@
|
||||
ROOTLDFLAGS = -L@ROOTLIBDIR@
|
||||
|
||||
# Boost required libraries
|
||||
BOOST_FLAGS = $(BOOST_SERIALIZATION_LDFLAGS) $(BOOST_SIGNALS_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
|
||||
BOOST_LIBS = $(BOOST_SERIALIZATION_LIBS) $(BOOST_SIGNALS_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS)
|
||||
|
||||
ULIB_INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/src/ltk
|
||||
|
||||
AM_CFLAGS = $(OPT) $(OPEN_MP)
|
||||
AM_CXXFLAGS = -std=c++0x $(OPT) $(OPEN_MP) $(EIGEN) $(ROOTCFLAGS) $(GEANT4CFLAGS) $(BOOST_CPPFLAGS) $(ULIB_INCLUDES) $(QT4_CFLAGS)
|
||||
AM_LDFLAGS = $(OPT_LD) $(ROOTLDFLAGS) # $(BOOST_FLAGS)
|
||||
|
||||
AM_LIBS_ROOT = @ROOTLIBS@
|
||||
AM_LIBS_GEANT4 = $(GEANT4LIBS)
|
||||
AM_LIBS_QT4 = $(QT4_LIBS)
|
||||
AM_LIBS_BOOST = $(BOOST_LIBS)
|
||||
|
||||
AM_LIBS_ALL = @LIBS@ \
|
||||
@LIBADD_DL@ \
|
||||
@LIBREADLINE@ \
|
||||
$(AM_LIBS_ROOT) \
|
||||
$(AM_LIBS_BOOST) \
|
||||
$(AM_LIBS_GEANT4) \
|
||||
$(AM_LIBS_QT4)
|
||||
|
||||
AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
|
||||
# clean_all:
|
||||
# rm -f *~ *# *.vtk *.vti *.ply
|
||||
# @echo "all cleaned up!"
|
||||
52
Makefile.am
Normal file
52
Makefile.am
Normal file
@@ -0,0 +1,52 @@
|
||||
if ENABLE_VTK
|
||||
VTK_SUBDIR = src/Vtk
|
||||
VTK_CONLIB = src/Vtk/libconvtk.la
|
||||
endif
|
||||
|
||||
SUBDIRS = src $(VTK_SUBDIR) .
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
include Common.am
|
||||
|
||||
if ENABLE_VTK
|
||||
include src/Vtk/Vtk.am
|
||||
endif
|
||||
|
||||
|
||||
_uLib_SOURCES =
|
||||
|
||||
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/
|
||||
library_include_HEADERS = config.h \
|
||||
ulib.h
|
||||
|
||||
|
||||
bin_PROGRAMS = test
|
||||
test_LDADD = libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
|
||||
|
||||
if ENABLE_VTK
|
||||
bin_PROGRAMS += vtk_test
|
||||
vtk_test_LDADD = libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
|
||||
endif
|
||||
|
||||
|
||||
##PACKAGE_MAJOR=@PACKAGE_MAJOR@
|
||||
##PACKAGE_MINOR=@PACKAGE_MINOR@
|
||||
|
||||
LIBRARY_VERSION = 1:0:0
|
||||
|
||||
CONLIBS = src/Core/libmutomcore.la \
|
||||
src/Root/libmutomroot.la \
|
||||
src/Math/libmutommath.la \
|
||||
src/Detectors/libmutomdetectors.la
|
||||
|
||||
|
||||
lib_LTLIBRARIES = libmutom-0.2.la
|
||||
libmutom_0_2_la_SOURCES = ${_uLib_SOURCES}
|
||||
libmutom_0_2_la_LDFLAGS = -version-info $(LIBRARY_VERSION)
|
||||
libmutom_0_2_la_LIBADD = $(AM_LIBS_ALL) ${CONLIBS} ${VTK_CONLIB}
|
||||
###libmutom_0_2_la_LDFLAGS = -release $(PACKAGE_VERSION) -version-info $(LIBRARY_VERSION)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libmutom-${PACKAGE_VERSION}.pc
|
||||
|
||||
14
SCRATCH.org
Normal file
14
SCRATCH.org
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#+TITLE: Documento Scratch per la raccolta delle idee:
|
||||
|
||||
|
||||
* IDEAS
|
||||
|
||||
** TODO Uso dell __atribute__ transparent_union per l'accesso trasparente ai membri della union data in un vettore.
|
||||
L'accesso union dichiarato anonimo e' incompatibile con il c99 questo potrebbe sistemare la cosa?
|
||||
|
||||
** TODO Uso dell __attribute__ packed per salvare lo spazio dedicato alle union per i bitfield dei flags
|
||||
|
||||
|
||||
|
||||
* ISSUES
|
||||
21
bootstrap
Executable file
21
bootstrap
Executable file
@@ -0,0 +1,21 @@
|
||||
#! /bin/sh
|
||||
|
||||
ROOTDIR=`root-config --prefix`
|
||||
|
||||
if [ -e /usr/share/aclocal/root.m4 ]
|
||||
then
|
||||
ROOTM4=.
|
||||
elif [ -e $ROOTDIR/build/misc/root.m4 ]
|
||||
then
|
||||
ROOTM4=$ROOTDIR/build/misc
|
||||
fi
|
||||
|
||||
aclocal -I ./m4
|
||||
|
||||
autoheader
|
||||
|
||||
libtoolize
|
||||
|
||||
automake --add-missing --gnu
|
||||
|
||||
autoconf
|
||||
210
configure.ac
Normal file
210
configure.ac
Normal file
@@ -0,0 +1,210 @@
|
||||
|
||||
########################
|
||||
## CONFIG FILE FOR AC ##
|
||||
########################
|
||||
|
||||
# M4 PREABLE
|
||||
|
||||
# uLib version:
|
||||
m4_define([uLib_major_version], [0])
|
||||
m4_define([uLib_minor_version], [2])
|
||||
# if the minor version number is odd, then we want debugging. Otherwise
|
||||
# we only want minimal debugging support.
|
||||
##m4_define([IB_debug_default],
|
||||
## [m4_if(m4_eval(IB_minor_version % 2), [1], [yes])])
|
||||
|
||||
|
||||
########### INIT #######################################
|
||||
AC_INIT([MuSteel uLib],[uLib_major_version.uLib_minor_version],[andrea.rigoni@pd.infn.it])
|
||||
AM_INIT_AUTOMAKE([subdir-objects])
|
||||
|
||||
##AC_PREREQ([2.67])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
|
||||
AC_CONFIG_SRCDIR([ulib.h])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
# Checks for programs.
|
||||
CFLAGS=""
|
||||
CXXFLAGS=""
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
|
||||
|
||||
######### ROOT MACROS ###################################
|
||||
AC_DEFINE([HAVE_ROOT], [no], [Having root installed])
|
||||
ROOT_PATH( [5.0] , [HAVE_ROOT=1], [HAVE_ROOT=0])
|
||||
AM_CONDITIONAL(HAVE_ROOT, [test HAVE_ROOT=1])
|
||||
AS_IF([test HAVE_ROOT=1],[AC_DEFINE([HAVE_ROOT],[1],[])] )
|
||||
|
||||
AC_DEFINE([HAVE_GEANT4], [no], [Having Geant4 installed])
|
||||
GEANT4_PATH( [9.6] , [HAVE_GEANT4=1], [HAVE_GEANT4=0])
|
||||
AM_CONDITIONAL(HAVE_GEANT4, [test HAVE_GEANT4])
|
||||
AS_IF([test HAVE_GEANT4=1],[AC_DEFINE([HAVE_GEANT4],[1],[])] )
|
||||
|
||||
######### LIBTOOL ########################################
|
||||
AC_PROG_LIBTOOL
|
||||
LIBADD_DL="-ldl"
|
||||
AC_SUBST(LIBADD_DL)
|
||||
|
||||
AC_SEARCH_LIBS([strerror],[cposix])
|
||||
|
||||
LT_INIT()
|
||||
AC_SUBST([LIBTOOL_DEPS])
|
||||
|
||||
|
||||
|
||||
######### CHECKS ########################################
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([stdlib.h string.h assert.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_HEADER_STDBOOL
|
||||
AC_C_INLINE
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_CHECK_FUNCS([fesetround floor pow sqrt strdup strstr])
|
||||
|
||||
AC_SEARCH_LIBS([strerror],[cposix])
|
||||
|
||||
# Check for BOOST Libraries
|
||||
BOOST_REQUIRE([1.34])
|
||||
|
||||
BOOST_ARRAY
|
||||
# BOOST_DATE_TIME
|
||||
BOOST_SERIALIZATION
|
||||
BOOST_SIGNALS
|
||||
BOOST_PROGRAM_OPTIONS(mt-p)
|
||||
|
||||
|
||||
# Check for Vtk installation
|
||||
AM_OPTIONS_VTK
|
||||
AM_PATH_VTK([5.0],[HAVE_VTK=1],[HAVE_VTK=0])
|
||||
# AM_CONDITIONAL([HAVE_VTK], [test HAVE_VTK=1] ) # fix?
|
||||
AM_CONDITIONAL([VTK_5_x], [1])
|
||||
|
||||
|
||||
PKG_CHECK_MODULES([EIGEN3],[eigen3 >= 0.1])
|
||||
|
||||
PKG_CHECK_MODULES(QT4, [QtCore QtGui >= 4.4.0], [
|
||||
AC_PATH_PROGS(MOC, [moc-qt4 moc], moc,`eval pkg-config --variable=exec_prefix QtCore`/bin)
|
||||
AC_PATH_PROG(RCC, rcc, rcc,`eval pkg-config --variable=exec_prefix QtCore`/bin)
|
||||
AC_PATH_PROGS(UIC, [uic-qt4 uic], uic,`eval pkg-config --variable=exec_prefix QtCore`/bin)
|
||||
],[HAVE_QT=0])
|
||||
|
||||
|
||||
########## CONDITIONALS ##################################
|
||||
|
||||
|
||||
# Configure script arguments
|
||||
dnl declare --enable-* args and collect ac_help strings
|
||||
AC_ARG_ENABLE(debug,
|
||||
AS_HELP_STRING([--enable-debug=no/yes],[turn on debugging, default: no]),
|
||||
[case "${enableval}" in
|
||||
yes) debug=true ;;
|
||||
no) debug=false ;;
|
||||
*) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
|
||||
esac],
|
||||
[debug=false])
|
||||
|
||||
AC_ARG_ENABLE(parallel,
|
||||
AS_HELP_STRING([--enable-parallel=no/yes],[turn on openMP parallel processing, default: yes]),
|
||||
[case "${enableval}" in
|
||||
yes) parallel=true ;;
|
||||
no) parallel=false ;;
|
||||
*) AC_MSG_ERROR([bad value ${enableval} for --enable-parallel]) ;;
|
||||
esac],
|
||||
[parallel=true])
|
||||
|
||||
AC_ARG_ENABLE(autovector,
|
||||
AS_HELP_STRING([--enable-autovector=no/yes],[turn on gcc auto vectorize loops with simd instructions, default: no]),
|
||||
[case "${enableval}" in
|
||||
yes) autovector=true ;;
|
||||
no) autovector=false ;;
|
||||
*) AC_MSG_ERROR([bad value ${enableval} for --enable-autovector]) ;;
|
||||
esac],
|
||||
[autovector=false])
|
||||
|
||||
AC_ARG_ENABLE(vtk,
|
||||
AS_HELP_STRING([--enable-vtk=no/yes],[turn on vtk visualization wrappers, default: no]),
|
||||
[case "${enableval}" in
|
||||
yes) vtk=true ;;
|
||||
no) vtk=false ;;
|
||||
*) AC_MSG_ERROR([bad value ${enableval} for --enable-vtk]) ;;
|
||||
esac],
|
||||
[vtk=false])
|
||||
|
||||
|
||||
AC_ARG_WITH([readline],
|
||||
[AS_HELP_STRING([--with-readline],
|
||||
[support fancy command line editing @<:@default=check@:>@])],
|
||||
[],
|
||||
[with_readline=check])
|
||||
|
||||
LIBREADLINE=
|
||||
AS_IF([test "x$with_readline" != xno],
|
||||
[AC_CHECK_LIB([readline], [main],
|
||||
[AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
|
||||
AC_DEFINE([HAVE_LIBREADLINE], [1],
|
||||
[Define if you have libreadline])
|
||||
],
|
||||
[if test "x$with_readline" != xcheck; then
|
||||
AC_MSG_FAILURE(
|
||||
[--with-readline was given, but test for readline failed])
|
||||
fi
|
||||
], -lncurses)])
|
||||
|
||||
AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")
|
||||
AM_CONDITIONAL(PARAL_MP, test x"$parallel" = x"true")
|
||||
AM_CONDITIONAL(SIMD_AUTOVECTOR, test x"$autovector" = x"true")
|
||||
AM_CONDITIONAL(ENABLE_VTK, [test x"$vtk" = x"true"])
|
||||
|
||||
|
||||
SVN_REVISION=`svnversion .`
|
||||
AC_SUBST(SVN_REVISION)
|
||||
AC_DEFINE_UNQUOTED(SVN_REVISION,"$SVN_REVISION",[SVN revision number])
|
||||
|
||||
# Forcing variadic macro compiler feature (for gcc without cxx11 flag)
|
||||
AC_DEFINE_UNQUOTED(BOOST_PP_VARIADICS,1,[Compiler must have variadic macros])
|
||||
|
||||
|
||||
|
||||
######### MAKEFILES #########################################
|
||||
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
src/Makefile
|
||||
src/ltk/Makefile
|
||||
src/ltk/testing/Makefile
|
||||
src/Core/Makefile
|
||||
src/Core/testing/Makefile
|
||||
src/Core/testing/ObjectMock/Makefile
|
||||
src/Core/testing/SignalMock/Makefile
|
||||
src/Core/testing/SerializeMock/Makefile
|
||||
src/Root/Makefile
|
||||
src/Root/testing/Makefile
|
||||
src/Math/Makefile
|
||||
src/Math/testing/Makefile
|
||||
src/Detectors/Makefile
|
||||
src/Detectors/testing/Makefile
|
||||
src/ParticlePhysics/MuonTomography/Makefile
|
||||
src/ParticlePhysics/Geant/Makefile
|
||||
src/Vtk/Makefile
|
||||
src/Vtk/testing/Makefile
|
||||
src/Gui/Qt/QVTKViewport2/Makefile
|
||||
tmp/BuildTruck/Makefile
|
||||
libmutom-0.2.pc
|
||||
])
|
||||
AC_OUTPUT
|
||||
|
||||
# src/Vtk/Math/Makefile
|
||||
# src/Vtk/Math/testing/Makefile
|
||||
# src/Vtk/Detectors/Makefile
|
||||
# src/Vtk/Detectors/testing/Makefile
|
||||
# src/Vtk/ParticlePhysics/MuonTomography/Makefile
|
||||
# src/Vtk/ParticlePhysics/Geant/Makefile
|
||||
|
||||
11
libmutom-0.2.pc.in
Normal file
11
libmutom-0.2.pc.in
Normal file
@@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: Mutom Library (INFN)
|
||||
Description: Library for Muon Tomography experiments.
|
||||
Requires: eigen3
|
||||
Version: @PACKAGE_VERSION@
|
||||
Libs: -L${libdir} -lmutom-0.2 -lboost_program_options
|
||||
Cflags: -I${includedir}/libmutom-@PACKAGE_VERSION@ -I${libdir}/libmutom-@PACKAGE_VERSION@/include
|
||||
1186
m4/boost.m4
Normal file
1186
m4/boost.m4
Normal file
File diff suppressed because it is too large
Load Diff
361
m4/geant4.bkp
Normal file
361
m4/geant4.bkp
Normal file
@@ -0,0 +1,361 @@
|
||||
dnl
|
||||
dnl m4 macros for setting up Geant4
|
||||
dnl
|
||||
|
||||
# call all the Geant4 macros
|
||||
AC_DEFUN( [GDML_SETUP_GEANT4], [
|
||||
|
||||
GDML_WITH_GEANT4
|
||||
AC_GEANT4_VERSION
|
||||
GDML_WITH_G4SYSTEM
|
||||
GDML_WITH_GEANT4_INCLUDE
|
||||
GDML_WITH_GEANT4_LIBDIR
|
||||
GDML_ENABLE_GEANT4_GRANULAR_LIBS
|
||||
GDML_SUBST_GEANT4
|
||||
|
||||
GDML_CHECK_NIST
|
||||
GDML_ENABLE_NIST
|
||||
|
||||
AC_HAVE_G4TESSELLATED
|
||||
AC_HAVE_G4TET
|
||||
AC_HAVE_G4TWISTEDBOX
|
||||
AC_HAVE_G4TWISTEDTRD
|
||||
AC_HAVE_G4TWISTEDTRAP
|
||||
AC_HAVE_G4TWISTEDTUBS
|
||||
AC_HAVE_G4ELLIPSOID
|
||||
AC_HAVE_G4EXTRUDEDSOLID
|
||||
|
||||
])
|
||||
|
||||
# macro to set GEANT4 base dir (G4INSTALL)
|
||||
AC_DEFUN( GDML_WITH_GEANT4, [
|
||||
|
||||
AC_MSG_CHECKING(for GEANT4 installation setting)
|
||||
|
||||
AC_ARG_WITH(geant4,
|
||||
AC_HELP_STRING([--with-geant4=<path>],[Geant4 installation base [[G4INSTALL]] ]),
|
||||
[GEANT4_PREFIX=$with_geant4],
|
||||
[GEANT4_PREFIX=$G4INSTALL])
|
||||
|
||||
AC_MSG_RESULT([$GEANT4_PREFIX])
|
||||
|
||||
GDML_CHECK_PKG_DIR( [$GEANT4_PREFIX], [Geant4])
|
||||
|
||||
])
|
||||
|
||||
# macro to set G4SYSTEM
|
||||
AC_DEFUN( GDML_WITH_G4SYSTEM, [
|
||||
|
||||
AC_MSG_CHECKING(for G4SYSTEM setting)
|
||||
|
||||
AC_ARG_WITH(geant4-system,
|
||||
AC_HELP_STRING([--with-geant4-system=<value>],[Value of G4SYSTEM variable]),
|
||||
[G4SYSTEM=$with_geant4_g4system])
|
||||
|
||||
if test -z "${G4SYSTEM}"; then
|
||||
G4SYSTEM=`uname`-${CXX}
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([$G4SYSTEM])
|
||||
|
||||
AC_SUBST(G4SYSTEM)
|
||||
|
||||
])
|
||||
|
||||
# macro to set GEANT4 include dir
|
||||
AC_DEFUN( GDML_WITH_GEANT4_INCLUDE, [
|
||||
|
||||
AC_MSG_CHECKING([for Geant4 include dir setting])
|
||||
|
||||
AC_ARG_WITH([geant4-include],
|
||||
AC_HELP_STRING([--with-geant4-include=<path>],[Geant4 alternate headers dir]),
|
||||
[GEANT4_INCLUDE=$with_geant4_include],
|
||||
[GEANT4_INCLUDE=$GEANT4_PREFIX/include])
|
||||
|
||||
AC_MSG_RESULT([$GEANT4_INCLUDE])
|
||||
|
||||
GDML_CHECK_PKG_DIR( [$GEANT4_INCLUDE],
|
||||
[GEANT4],
|
||||
[G4RunManager.hh])
|
||||
])
|
||||
|
||||
AC_MSG_RESULT(yes)
|
||||
|
||||
# macro to set GEANT4 lib dir
|
||||
AC_DEFUN( GDML_WITH_GEANT4_LIBDIR, [
|
||||
|
||||
AC_MSG_CHECKING([for Geant4 lib dir])
|
||||
|
||||
AC_ARG_WITH([geant4-libdir],
|
||||
AC_HELP_STRING([--with-geant4-libdir=<path>], [Geant4 alternate library dir]),
|
||||
[GEANT4_LIBDIR=$with_geant4_libdir],
|
||||
[GEANT4_LIBDIR=$GEANT4_PREFIX/lib/$G4SYSTEM])
|
||||
|
||||
AC_MSG_RESULT([$GEANT4_LIBDIR])
|
||||
|
||||
GDML_CHECK_PKG_DIR( [$GEANT4_LIBDIR],
|
||||
[GEANT4])
|
||||
])
|
||||
|
||||
# macro to substitute GEANT4 vars to output
|
||||
AC_DEFUN( GDML_SUBST_GEANT4, [
|
||||
|
||||
AC_SUBST(GEANT4_PREFIX)
|
||||
AC_SUBST(GEANT4_INCLUDE)
|
||||
AC_SUBST(GEANT4_LIBDIR)
|
||||
|
||||
])
|
||||
|
||||
# macro to select granular libs
|
||||
AC_DEFUN( GDML_ENABLE_GEANT4_GRANULAR_LIBS, [
|
||||
|
||||
AC_MSG_CHECKING(whether to use Geant4 granular libs)
|
||||
|
||||
AC_ARG_ENABLE([geant4-granular-libs],
|
||||
AC_HELP_STRING( [--enable-geant4-granular-libs], [Enable linking against granular rather than global Geant4 libs] ),
|
||||
[ac_g4_use_granular=$enable_geant4_granular_libs],
|
||||
[ac_g4_use_granular=no])
|
||||
|
||||
# no option?
|
||||
if test -z "${with_geant4_granular_libs}"; then
|
||||
# set in env?
|
||||
if test -n "${G4LIB_USE_GRANULAR}"; then
|
||||
ac_g4_use_granular=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([$ac_g4_use_granular])
|
||||
|
||||
if test "${ac_g4_use_granular}" = "yes"; then
|
||||
GEANT4_USE_GRANULAR=1
|
||||
AC_SUBST(GEANT4_USE_GRANULAR)
|
||||
else
|
||||
GEANT4_USE_GLOBAL=1
|
||||
AC_SUBST(GEANT4_USE_GLOBAL)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# macro to check whether NIST is supported by the current Geant4 version
|
||||
AC_DEFUN(GDML_CHECK_NIST, [
|
||||
|
||||
HAVE_NIST=no
|
||||
|
||||
AC_CHECK_FILE([$GEANT4_PREFIX/source/materials/include/G4NistManager.hh],HAVE_NIST=yes)
|
||||
|
||||
if test "$HAVE_NIST" = "yes"
|
||||
then
|
||||
AC_DEFINE(HAVE_NIST)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# macro to enable/disable NIST support
|
||||
AC_DEFUN(GDML_ENABLE_NIST, [
|
||||
|
||||
dnl Removed because this is somehow getting put in front of GEANT4_PREFIX setting, which breaks NIST config.
|
||||
dnl AC_REQUIRE([GDML_CHECK_NIST])
|
||||
|
||||
AC_MSG_CHECKING(whether to enable Geant4 NIST support for material lookup)
|
||||
|
||||
AC_ARG_ENABLE([nist],
|
||||
AC_HELP_STRING([--enable-nist=<setting>]., [Turn NIST support on or off.]))
|
||||
|
||||
# default to using NIST if not set from the enable-nist option
|
||||
if test "X$enable_nist" = "X"
|
||||
then
|
||||
enable_nist=yes
|
||||
fi
|
||||
|
||||
if test "X$enable_nist" = "Xyes"
|
||||
then
|
||||
if test "X$HAVE_NIST" = "Xyes"
|
||||
then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(GDML_USE_NIST)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_WARN(NIST was selected but your version of Geant4 does not support it)
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
dnl Macro to extract the Geant4 version from G4Version.hh or G4RunManagerKernel.hh, if the former file does not exist.
|
||||
AC_DEFUN(AC_GEANT4_VERSION, [
|
||||
|
||||
AC_MSG_CHECKING(for Geant4 full version)
|
||||
|
||||
if test -n "$GEANT4_PREFIX"
|
||||
then
|
||||
|
||||
if ! test -d $GEANT4_PREFIX; then
|
||||
AC_MSG_ERROR(G4INSTALL does not point to a directory)
|
||||
fi
|
||||
|
||||
if ! test -e $GEANT4_PREFIX/source/run/include/G4RunManager.hh; then
|
||||
AC_MSG_ERROR(G4INSTALL does not appear to contain the Geant4 source code)
|
||||
fi
|
||||
|
||||
if test -e "$GEANT4_PREFIX/source/global/management/include/G4Version.hh"
|
||||
then
|
||||
GEANT4_FULL_VERSION=$(sed -n -e '/#define G4VERSION_NUMBER/s/#define G4VERSION_NUMBER //p' $GEANT4_PREFIX/source/global/management/include/G4Version.hh | \
|
||||
awk 'BEGIN { FS="" } ; { print [$]1"."[$]2"."[$]3 }')
|
||||
elif test -e "$GEANT4_PREFIX/source/run/src/G4RunManagerKernel.cc"
|
||||
then
|
||||
GEANT4_FULL_VERSION=$(sed -n -e '/\/\/ GEANT4 tag /s/.*\(geant4-[[0-9]]*-[[0-9]]*[[0-9a-z-]]*\).*/\1/p' \
|
||||
$GEANT4_PREFIX/source/run/src/G4RunManagerKernel.cc | sed -e 's/geant4-//g' -e 's/patch-//g' -e 's/-/./g')
|
||||
else
|
||||
AC_MSG_ERROR(could not determine Geant4 version because G4Version.hh or G4RunManagerKernel.hh was not found in $GEANT4_PREFIX)
|
||||
fi
|
||||
else
|
||||
AC_MSG_ERROR(G4INSTALL is not set in the environment)
|
||||
fi
|
||||
|
||||
GEANT4_MAJOR_VERSION=$(echo "$GEANT4_FULL_VERSION" | awk 'BEGIN{ FS="." } { print [$]1 }' | sed 's/0*//')
|
||||
GEANT4_MINOR_VERSION=$(echo "$GEANT4_FULL_VERSION" | awk 'BEGIN{ FS="." } { print [$]2 }' | sed 's/0*//')
|
||||
GEANT4_PATCH_VERSION=$(echo "$GEANT4_FULL_VERSION" | awk 'BEGIN{ FS="." } { print [$]3 }' | sed 's/0*//')
|
||||
|
||||
if test -z "$GEANT4_MINOR_VERSION";
|
||||
then
|
||||
GEANT4_MINOR_VERSION=0
|
||||
fi
|
||||
|
||||
if test -z "$GEANT4_PATCH_VERSION";
|
||||
then
|
||||
GEANT4_PATCH_VERSION=0
|
||||
fi
|
||||
|
||||
GEANT4_FULL_VERSION=$GEANT4_MAJOR_VERSION"."$GEANT4_MINOR_VERSION"."$GEANT4_PATCH_VERSION
|
||||
|
||||
AC_MSG_RESULT($GEANT4_FULL_VERSION)
|
||||
|
||||
AC_MSG_CHECKING(for Geant4 major version level)
|
||||
AC_MSG_RESULT($GEANT4_MAJOR_VERSION)
|
||||
|
||||
AC_MSG_CHECKING(for Geant4 minor version level)
|
||||
AC_MSG_RESULT($GEANT4_MINOR_VERSION)
|
||||
|
||||
AC_MSG_CHECKING(for Geant4 patch level)
|
||||
AC_MSG_RESULT($GEANT4_PATCH_VERSION)
|
||||
|
||||
AC_SUBST(GEANT4_FULL_VERSION)
|
||||
AC_SUBST(GEANT4_MAJOR_VERSION)
|
||||
AC_SUBST(GEANT4_MINOR_VERSION)
|
||||
AC_SUBST(GEANT4_PATCH_VERSION)
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TESSELLATED if G4TessellatedSolid.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TESSELLATED, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4TessellatedSolid)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4TessellatedSolid.hh; then
|
||||
AC_DEFINE(HAVE_G4TESSELLATEDSOLID)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TET if G4Tet.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TET, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4Tet)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4Tet.hh; then
|
||||
AC_DEFINE(HAVE_G4TET)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TWISTEDBOX if G4TwistedBox.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TWISTEDBOX, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4TwistedBox)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4TwistedBox.hh; then
|
||||
AC_DEFINE(HAVE_G4TWISTEDBOX)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TWISTEDTRD if G4TwistedTrd.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TWISTEDTRD, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4TwistedTrd)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4TwistedTrd.hh; then
|
||||
AC_DEFINE(HAVE_G4TWISTEDTRD)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TWISTEDTRAP if G4TwistedTrap.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TWISTEDTRAP, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4TwistedTrap)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4TwistedTrap.hh; then
|
||||
AC_DEFINE(HAVE_G4TWISTEDTRAP)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4TWISTEDTUBS if G4TwistedTubs.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4TWISTEDTUBS, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4TwistedTubs)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4TwistedTubs.hh; then
|
||||
AC_DEFINE(HAVE_G4TWISTEDTUBS)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4ELLIPSOID if G4Ellipsoid.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4ELLIPSOID, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4Ellipsoid)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4Ellipsoid.hh; then
|
||||
AC_DEFINE(HAVE_G4ELLIPSOID)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
|
||||
# Macro to set HAVE_G4EXTRUDEDSOLID if G4ExtrudedSolid.hh exists.
|
||||
AC_DEFUN(AC_HAVE_G4EXTRUDEDSOLID, [
|
||||
|
||||
AC_MSG_CHECKING(whether to enable G4ExtrudedSolid)
|
||||
|
||||
if test -e $GEANT4_PREFIX/source/geometry/solids/specific/include/G4ExtrudedSolid.hh; then
|
||||
AC_DEFINE(HAVE_G4EXTRUDEDSOLID)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
])
|
||||
64
m4/geant4.m4
Normal file
64
m4/geant4.m4
Normal file
@@ -0,0 +1,64 @@
|
||||
dnl
|
||||
dnl m4 macros for setting up Geant4
|
||||
dnl
|
||||
|
||||
|
||||
##
|
||||
## Geant4 Config
|
||||
##
|
||||
|
||||
AC_DEFUN([GEANT4_PATH],
|
||||
[
|
||||
AC_ARG_WITH(gean4sys,
|
||||
[ --with-geant4sys top of the GEANT4 installation directory],
|
||||
user_genat4sys=$withval,
|
||||
user_geant4sys="none")
|
||||
if test ! x"$user_geant4sys" = xnone; then
|
||||
geant4bin="$user_geant4sys/bin"
|
||||
elif test ! x"$GEANT4SYS" = x ; then
|
||||
geant4bin="$GEANT4SYS/bin"
|
||||
else
|
||||
geant4bin=$PATH
|
||||
fi
|
||||
AC_PATH_PROG(GEANT4CONF, geant4-config , no, $geant4bin)
|
||||
|
||||
if test ! x"$GEANT4CONF" = "xno"; then
|
||||
|
||||
# define some variables
|
||||
GEANT4CFLAGS=`$GEANT4CONF --cflags`
|
||||
GEANT4LIBS=`$GEANT4CONF --libs`
|
||||
GEANT4VERSION=`$GEANT4CONF --version`
|
||||
|
||||
if test $1 ; then
|
||||
AC_MSG_CHECKING(wether GEANT4 version >= [$1])
|
||||
vers=`$GEANT4CONF --version | tr './' ' ' | awk 'BEGIN { FS = " "; } { printf "%d", ($''1 * 1000 + $''2) * 1000 + $''3;}'`
|
||||
requ=`echo $1 | tr './' ' ' | awk 'BEGIN { FS = " "; } { printf "%d", ($''1 * 1000 + $''2) * 1000 + $''3;}'`
|
||||
if test $vers -lt $requ ; then
|
||||
AC_MSG_RESULT(no)
|
||||
no_geant4="yes"
|
||||
else
|
||||
AC_MSG_RESULT(yes)
|
||||
no_genat4="no"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# otherwise, we say no_GEANT4
|
||||
no_geant4="yes"
|
||||
fi
|
||||
|
||||
AC_SUBST(GEANT4CFLAGS)
|
||||
AC_SUBST(GEANT4LIBS)
|
||||
AC_SUBST(GEANT4VERSION)
|
||||
|
||||
if test "x$no_geant4" = "x" ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
ifelse([$3], , :, [$3])
|
||||
fi
|
||||
])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
98
m4/openmp.m4
Normal file
98
m4/openmp.m4
Normal file
@@ -0,0 +1,98 @@
|
||||
# openmp.m4 serial 7
|
||||
dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl This file can be removed once we assume autoconf >= 2.62.
|
||||
|
||||
dnl Expand to nothing in autoconf >= 2.62. m4_copy has a different
|
||||
dnl semantic in autoconf > 2.63.
|
||||
m4_ifdef([AC_OPENMP], [], [
|
||||
|
||||
# _AC_LANG_OPENMP
|
||||
# ---------------
|
||||
# Expands to some language dependent source code for testing the presence of
|
||||
# OpenMP.
|
||||
AC_DEFUN([_AC_LANG_OPENMP],
|
||||
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
|
||||
|
||||
# _AC_LANG_OPENMP(C)
|
||||
# ------------------
|
||||
m4_define([_AC_LANG_OPENMP(C)],
|
||||
[
|
||||
#ifndef _OPENMP
|
||||
choke me
|
||||
#endif
|
||||
#include <omp.h>
|
||||
int main () { return omp_get_num_threads (); }
|
||||
])
|
||||
|
||||
# _AC_LANG_OPENMP(C++)
|
||||
# --------------------
|
||||
m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
|
||||
|
||||
# _AC_LANG_OPENMP(Fortran 77)
|
||||
# ---------------------------
|
||||
m4_define([_AC_LANG_OPENMP(Fortran 77)],
|
||||
[AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
|
||||
|
||||
# _AC_LANG_OPENMP(Fortran)
|
||||
# ---------------------------
|
||||
m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
|
||||
|
||||
# AC_OPENMP
|
||||
# ---------
|
||||
# Check which options need to be passed to the C compiler to support OpenMP.
|
||||
# Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
|
||||
# options.
|
||||
# The options are necessary at compile time (so the #pragmas are understood)
|
||||
# and at link time (so the appropriate library is linked with).
|
||||
# This macro takes care to not produce redundant options if $CC $CFLAGS already
|
||||
# supports OpenMP. It also is careful to not pass options to compilers that
|
||||
# misinterpret them; for example, most compilers accept "-openmp" and create
|
||||
# an output file called 'penmp' rather than activating OpenMP support.
|
||||
AC_DEFUN([AC_OPENMP],
|
||||
[
|
||||
OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
|
||||
AC_ARG_ENABLE([openmp],
|
||||
[AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
|
||||
if test "$enable_openmp" != no; then
|
||||
AC_CACHE_CHECK([for $CC option to support OpenMP],
|
||||
[ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
|
||||
[AC_LINK_IFELSE([_AC_LANG_OPENMP],
|
||||
[ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
|
||||
[ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
|
||||
dnl Try these flags:
|
||||
dnl GCC >= 4.2 -fopenmp
|
||||
dnl SunPRO C -xopenmp
|
||||
dnl Intel C -openmp
|
||||
dnl SGI C, PGI C -mp
|
||||
dnl Tru64 Compaq C -omp
|
||||
dnl IBM C (AIX, Linux) -qsmp=omp
|
||||
dnl If in this loop a compiler is passed an option that it doesn't
|
||||
dnl understand or that it misinterprets, the AC_LINK_IFELSE test
|
||||
dnl will fail (since we know that it failed without the option),
|
||||
dnl therefore the loop will continue searching for an option, and
|
||||
dnl no output file called 'penmp' or 'mp' is created.
|
||||
for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
|
||||
ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
|
||||
AC_LINK_IFELSE([_AC_LANG_OPENMP],
|
||||
[ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
|
||||
_AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
|
||||
if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
|
||||
break
|
||||
fi
|
||||
done])])
|
||||
case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
|
||||
"none needed" | unsupported)
|
||||
;; #(
|
||||
*)
|
||||
OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
|
||||
esac
|
||||
fi
|
||||
AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
|
||||
])
|
||||
|
||||
])
|
||||
125
m4/root.m4
Normal file
125
m4/root.m4
Normal file
@@ -0,0 +1,125 @@
|
||||
dnl -*- mode: autoconf -*-
|
||||
dnl
|
||||
dnl $Id: root.m4,v 1.3 2005/03/21 21:42:21 rdm Exp $
|
||||
dnl $Author: rdm $
|
||||
dnl $Date: 2005/03/21 21:42:21 $
|
||||
dnl
|
||||
dnl Autoconf macro to check for existence or ROOT on the system
|
||||
dnl Synopsis:
|
||||
dnl
|
||||
dnl ROOT_PATH([MINIMUM-VERSION, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
|
||||
dnl
|
||||
dnl Some examples:
|
||||
dnl
|
||||
dnl ROOT_PATH(3.03/05, , AC_MSG_ERROR(Your ROOT version is too old))
|
||||
dnl ROOT_PATH(, AC_DEFINE([HAVE_ROOT]))
|
||||
dnl
|
||||
dnl The macro defines the following substitution variables
|
||||
dnl
|
||||
dnl ROOTCONF full path to root-config
|
||||
dnl ROOTEXEC full path to root
|
||||
dnl ROOTCINT full path to rootcint
|
||||
dnl ROOTLIBDIR Where the ROOT libraries are
|
||||
dnl ROOTINCDIR Where the ROOT headers are
|
||||
dnl ROOTCFLAGS Extra compiler flags
|
||||
dnl ROOTLIBS ROOT basic libraries
|
||||
dnl ROOTGLIBS ROOT basic + GUI libraries
|
||||
dnl ROOTAUXLIBS Auxilary libraries and linker flags for ROOT
|
||||
dnl ROOTAUXCFLAGS Auxilary compiler flags
|
||||
dnl ROOTRPATH Same as ROOTLIBDIR
|
||||
dnl
|
||||
dnl The macro will fail if root-config and rootcint isn't found.
|
||||
dnl
|
||||
dnl Christian Holm Christensen <cholm@nbi.dk>
|
||||
dnl
|
||||
AC_DEFUN([ROOT_PATH],
|
||||
[
|
||||
AC_ARG_WITH(rootsys,
|
||||
[ --with-rootsys top of the ROOT installation directory],
|
||||
user_rootsys=$withval,
|
||||
user_rootsys="none")
|
||||
if test ! x"$user_rootsys" = xnone; then
|
||||
rootbin="$user_rootsys/bin"
|
||||
elif test ! x"$ROOTSYS" = x ; then
|
||||
rootbin="$ROOTSYS/bin"
|
||||
else
|
||||
rootbin=$PATH
|
||||
fi
|
||||
AC_PATH_PROG(ROOTCONF, root-config , no, $rootbin)
|
||||
AC_PATH_PROG(ROOTEXEC, root , no, $rootbin)
|
||||
AC_PATH_PROG(ROOTCINT, rootcint , no, $rootbin)
|
||||
|
||||
if test ! x"$ROOTCONF" = "xno" && \
|
||||
test ! x"$ROOTCINT" = "xno" ; then
|
||||
|
||||
# define some variables
|
||||
ROOTLIBDIR=`$ROOTCONF --libdir`
|
||||
ROOTINCDIR=`$ROOTCONF --incdir`
|
||||
ROOTCFLAGS=`$ROOTCONF --noauxcflags --cflags`
|
||||
ROOTLIBS=`$ROOTCONF --noauxlibs --noldflags --libs`
|
||||
ROOTGLIBS=`$ROOTCONF --noauxlibs --noldflags --glibs`
|
||||
ROOTAUXCFLAGS=`$ROOTCONF --auxcflags`
|
||||
ROOTAUXLIBS=`$ROOTCONF --auxlibs`
|
||||
ROOTRPATH=$ROOTLIBDIR
|
||||
ROOTVERSION=`$ROOTCONF --version`
|
||||
ROOTSOVERSION=`dirname $ROOTVERSION`
|
||||
|
||||
if test $1 ; then
|
||||
AC_MSG_CHECKING(wether ROOT version >= [$1])
|
||||
vers=`$ROOTCONF --version | tr './' ' ' | awk 'BEGIN { FS = " "; } { printf "%d", ($''1 * 1000 + $''2) * 1000 + $''3;}'`
|
||||
requ=`echo $1 | tr './' ' ' | awk 'BEGIN { FS = " "; } { printf "%d", ($''1 * 1000 + $''2) * 1000 + $''3;}'`
|
||||
if test $vers -lt $requ ; then
|
||||
AC_MSG_RESULT(no)
|
||||
no_root="yes"
|
||||
else
|
||||
AC_MSG_RESULT(yes)
|
||||
no_root="no"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# otherwise, we say no_root
|
||||
no_root="yes"
|
||||
fi
|
||||
|
||||
AC_SUBST(ROOTLIBDIR)
|
||||
AC_SUBST(ROOTINCDIR)
|
||||
AC_SUBST(ROOTCFLAGS)
|
||||
AC_SUBST(ROOTLIBS)
|
||||
AC_SUBST(ROOTGLIBS)
|
||||
AC_SUBST(ROOTAUXLIBS)
|
||||
AC_SUBST(ROOTAUXCFLAGS)
|
||||
AC_SUBST(ROOTRPATH)
|
||||
AC_SUBST(ROOTVERSION)
|
||||
AC_SUBST(ROOTSOVERSION)
|
||||
|
||||
if test "x$no_root" = "x" ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
ifelse([$3], , :, [$3])
|
||||
fi
|
||||
])
|
||||
|
||||
#
|
||||
# Macro to check if ROOT has a specific feature:
|
||||
#
|
||||
# ROOT_FEATURE(FEATURE,[ACTION_IF_HAVE,[ACTION_IF_NOT]])
|
||||
#
|
||||
# For example
|
||||
#
|
||||
# ROOT_FEATURE([ldap],[AC_DEFINE([HAVE_ROOT_LDAP])])
|
||||
#
|
||||
AC_DEFUN([ROOT_FEATURE],
|
||||
[
|
||||
AC_REQUIRE([ROOT_PATH])
|
||||
feat=$1
|
||||
res=`$ROOTCONF --has-$feat`
|
||||
if test "x$res" = "xyes" ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
ifelse([$3], , :, [$3])
|
||||
fi
|
||||
])
|
||||
|
||||
#
|
||||
# EOF
|
||||
#
|
||||
166
m4/vtk.m4
Normal file
166
m4/vtk.m4
Normal file
@@ -0,0 +1,166 @@
|
||||
dnl ======================================================================================
|
||||
dnl Author: Francesco Montorsi
|
||||
dnl RCS-ID: $Id: vtk.m4,v 1.1 2005/11/20 14:47:40 frm Exp $
|
||||
dnl
|
||||
dnl Implements the AM_OPTIONS_VTK, to add the --with-vtk=path option, and the
|
||||
dnl AM_PATH_VTK macro used to detect VTK presence, location and version.
|
||||
dnl ======================================================================================
|
||||
|
||||
|
||||
|
||||
dnl
|
||||
dnl AM_OPTIONS_VTK
|
||||
dnl ------------------------------------------------------------------------
|
||||
dnl Adds the --with-vtk=path option to the configure options
|
||||
dnl
|
||||
AC_DEFUN([AM_OPTIONS_VTK],
|
||||
[
|
||||
AC_ARG_WITH([vtk-path],
|
||||
[AC_HELP_STRING([--with-vtk-path],
|
||||
[The prefix where VTK is installed (default is /usr/local)])],
|
||||
[with_vtk=$withval],
|
||||
[with_vtk="/usr/local"])
|
||||
|
||||
AC_ARG_WITH([vtk-version],
|
||||
[AC_HELP_STRING([--with-vtk-version],
|
||||
[VTK's include directory name is vtk-suffix, e.g. vtk-5.0/. What's the suffix? (Default -5.10)])],
|
||||
[vtk_suffix=$withval],
|
||||
[vtk_suffix="-5.10"])
|
||||
|
||||
])# AM_OPTIONS_VTK
|
||||
|
||||
|
||||
|
||||
dnl
|
||||
dnl AM_PATH_VTK([minimum-version], [action-if-found], [action-if-not-found])
|
||||
dnl ------------------------------------------------------------------------
|
||||
dnl
|
||||
dnl NOTE: [minimum-version] must be in the form [X.Y.Z]
|
||||
dnl
|
||||
AC_DEFUN([AM_PATH_VTK],
|
||||
[
|
||||
dnl do we want to check for VTK ?
|
||||
if test "$with_vtk" = yes; then
|
||||
dnl in case user wrote --with-vtk=yes
|
||||
with_vtk="/usr/local"
|
||||
fi
|
||||
|
||||
if test "$with_vtk" != no; then
|
||||
dnl
|
||||
dnl A path was provided in $with_vtk...try hard to find the VTK library {{{
|
||||
VTK_PREFIX="$with_vtk"
|
||||
|
||||
AC_CHECK_FILE([$VTK_PREFIX/include/vtk$vtk_suffix/vtkObject.h], [vtkFound="OK"])
|
||||
AC_MSG_CHECKING([if VTK is installed in $VTK_PREFIX])
|
||||
|
||||
if test -z "$vtkFound"; then
|
||||
dnl
|
||||
dnl VTK was not found! ...execute $3 unconditionally {{{
|
||||
AC_MSG_RESULT([no])
|
||||
$3
|
||||
dnl }}}
|
||||
dnl
|
||||
else
|
||||
dnl
|
||||
dnl VTK was found! ...execute $2 if version matches {{{
|
||||
AC_MSG_RESULT([yes])
|
||||
|
||||
dnl these are the VTK libraries of a default build
|
||||
VTK_LIBS=""
|
||||
|
||||
dnl set VTK c,cpp,ld flags
|
||||
VTK_CFLAGS="-I$VTK_PREFIX/include/vtk$vtk_suffix"
|
||||
VTK_CXXFLAGS="$VTK_CFLAGS"
|
||||
VTK_LDFLAGS="-L$VTK_PREFIX/lib/vtk$vtk_suffix $VTK_LIBS"
|
||||
|
||||
|
||||
AC_SUBST(VTK_LIBS)
|
||||
AC_SUBST(VTK_CFLAGS)
|
||||
AC_SUBST(VTK_CXXFLAGS)
|
||||
AC_SUBST(VTK_LDFLAGS)
|
||||
|
||||
dnl now, eventually check version {{{
|
||||
if test -n "$1"; then
|
||||
dnl
|
||||
dnl A version was specified... parse the version string in $1 {{{
|
||||
|
||||
dnl The version of VTK that we need: {{{
|
||||
maj=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
|
||||
min=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
|
||||
rel=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
|
||||
AC_MSG_CHECKING([if VTK version is at least $maj.$min.$rel])
|
||||
dnl }}}
|
||||
|
||||
dnl Compare required version of VTK against installed version: {{{
|
||||
dnl
|
||||
dnl Note that in order to be able to compile the following test program,
|
||||
dnl we need to add to the current flags, the VTK settings...
|
||||
OLD_CFLAGS=$CFLAGS
|
||||
OLD_CXXFLAGS=$CXXFLAGS
|
||||
OLD_LDFLAGS=$LDFLAGS
|
||||
CFLAGS="$VTK_CFLAGS $CFLAGS"
|
||||
CXXFLAGS="$VTK_CXXFLAGS $CXXFLAGS"
|
||||
LDFLAGS="$VTK_LDFLAGS $LDFLAGS"
|
||||
dnl
|
||||
dnl check if the installed VTK is greater or not
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <vtkConfigure.h>
|
||||
#include <stdio.h>
|
||||
],
|
||||
[
|
||||
printf("VTK version is: %d.%d.%d", VTK_MAJOR_VERSION, VTK_MINOR_VERSION, VTK_BUILD_VERSION);
|
||||
if VTK_MAJOR_VERSION < $maj
|
||||
error Installed VTK is too old !
|
||||
endif
|
||||
if VTK_MINOR_VERSION < $min
|
||||
error Installed VTK is too old !
|
||||
endif
|
||||
if VTK_BUILD_VERSION < $rel
|
||||
error Installed VTK is too old !
|
||||
endif
|
||||
])
|
||||
], [vtkVersion="OK"])
|
||||
dnl
|
||||
dnl restore all flags without VTK values
|
||||
CFLAGS=$OLD_CFLAGS
|
||||
CXXFLAGS=$OLD_CXXFLAGS
|
||||
LDFLAGS=$OLD_LDFLAGS
|
||||
dnl }}}
|
||||
|
||||
dnl Execute $2 if version is ok, otherwise execute $3 {{{
|
||||
if test "$vtkVersion" = "OK"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
$2
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
$3
|
||||
fi
|
||||
dnl }}}
|
||||
|
||||
dnl }}}
|
||||
dnl
|
||||
else
|
||||
dnl
|
||||
dnl A target version number was not provided... execute $2 unconditionally {{{
|
||||
|
||||
dnl if we don't have to check for minimum version (because the user did not set that option),
|
||||
dnl then we can execute here the block action-if-found
|
||||
CFLAGS="$VTK_CFLAGS $CFLAGS"
|
||||
CXXFLAGS="$VTK_CXXFLAGS $CXXFLAGS"
|
||||
LDFLAGS="$VTK_LDFLAGS $LDFLAGS"
|
||||
$2
|
||||
dnl }}}
|
||||
dnl
|
||||
fi
|
||||
dnl }}}
|
||||
|
||||
dnl }}}
|
||||
dnl
|
||||
fi
|
||||
dnl }}}
|
||||
dnl
|
||||
fi
|
||||
])# AM_PATH_VTK
|
||||
dnl
|
||||
dnl vim: foldmethod=marker foldlevel=1 ts=2 sw=2
|
||||
90
m4/zeromq.m4
Normal file
90
m4/zeromq.m4
Normal file
@@ -0,0 +1,90 @@
|
||||
#
|
||||
# Configure paths and flags for the ZeroMQ library.
|
||||
# Denis Arnaud <denis_arnaud at users dot sourceforge dot net>, May 2011
|
||||
#
|
||||
# Variables set by this macro:
|
||||
# * AM_PATH_ZEROMQ
|
||||
# * ZEROMQ_VERSION
|
||||
# * ZEROMQ_CFLAGS
|
||||
# * ZEROMQ_LIBS
|
||||
#
|
||||
|
||||
AC_DEFUN([AM_PATH_ZEROMQ],
|
||||
[
|
||||
AC_LANG_SAVE
|
||||
AC_LANG([C++])
|
||||
|
||||
##
|
||||
AC_ARG_WITH(zeromq,
|
||||
[[ --with-zeromq[=PFX] Prefix where ZeroMQ is installed (optional) ]],
|
||||
zeromq_dir="$withval",
|
||||
zeromq_dir="")
|
||||
|
||||
ac_zeromq_path=""
|
||||
if test "x${zeromq_dir}" = "xno"
|
||||
then
|
||||
without_zeromq=yes
|
||||
elif test "x${zeromq_dir}" != "xyes"
|
||||
then
|
||||
with_arg="${zeromq_dir}/include:-L${zeromq_dir}/lib ${zeromq_dir}/include/zeromq:-L${zeromq_dir}/lib"
|
||||
fi
|
||||
|
||||
##
|
||||
AC_MSG_CHECKING(for zmq.hpp)
|
||||
|
||||
if test "x$without_zeromq" != "xyes"
|
||||
then
|
||||
for i in $with_arg /usr/include: /usr/local/include:-L/usr/local/lib \
|
||||
/usr/pkg/include:-L/usr/pkg/lib
|
||||
do
|
||||
ac_zeromq_path=`echo "$i" | sed 's/:.*//'`
|
||||
lib=`echo "$i" | sed 's/.*://'`
|
||||
|
||||
if test -f ${ac_zeromq_path}/zmq.hpp
|
||||
then
|
||||
AC_MSG_RESULT(${ac_zeromq_path}/zmq.hpp)
|
||||
ZEROMQ_LIBS="$lib -lzmq"
|
||||
|
||||
AC_DEFINE(HAVE_ZEROMQ, 1, [define if you have ZeroMQ])
|
||||
have_zeromq=yes
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if test "x$have_zeromq" != "xyes"; then
|
||||
AC_MSG_ERROR([The ZeroMQ library cannot be found. You may want to install zeromq-devel (RPM-based)/zeromq-dev (Debian-based) package.])
|
||||
fi
|
||||
|
||||
## ZeroMQ version
|
||||
zeromq_lib_version_req=ifelse([$1], ,2.0,$1)
|
||||
AC_MSG_CHECKING(for zeromq lib version >= $zeromq_lib_version_req)
|
||||
succeeded=no
|
||||
zeromq_lib_version_req_shorten=`expr $zeromq_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
|
||||
zeromq_lib_version_req_major=`expr $zeromq_lib_version_req : '\([[0-9]]*\)'`
|
||||
zeromq_lib_version_req_minor=`expr $zeromq_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
|
||||
WANT_ZEROMQ_VERSION=`expr $zeromq_lib_version_req_major \* 100 \+ $zeromq_lib_version_req_minor`
|
||||
|
||||
# The lines specifying the ZeroMQ version are like the following:
|
||||
#define ZMQ_VERSION_MAJOR 2
|
||||
#define ZMQ_VERSION_MINOR 1
|
||||
#define ZMQ_VERSION_PATCH 4
|
||||
zeromq_version_major=`grep "define ZMQ_VERSION_MAJOR" ${ac_zeromq_path}/zmq.h | cut -d' ' -f3`
|
||||
zeromq_version_minor=`grep "define ZMQ_VERSION_MINOR" ${ac_zeromq_path}/zmq.h | cut -d' ' -f3`
|
||||
zeromq_version_computed=`expr $zeromq_version_major \* 100 \+ $zeromq_version_minor`
|
||||
ZEROMQ_VERSION="${zeromq_version_major}.${zeromq_version_minor}"
|
||||
|
||||
if test ${zeromq_version_computed} -ge ${WANT_ZEROMQ_VERSION}
|
||||
then
|
||||
AC_MSG_RESULT([yes (${ZEROMQ_VERSION}.)])
|
||||
else
|
||||
AC_MSG_ERROR([The version (${ZEROMQ_VERSION}) of the ZeroMQ library is too old. You may want to upgrade your zeromq package.])
|
||||
fi
|
||||
|
||||
##
|
||||
AC_SUBST([ZEROMQ_VERSION])
|
||||
AC_SUBST([ZEROMQ_CFLAGS])
|
||||
AC_SUBST([ZEROMQ_LIBS])
|
||||
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
92
src/Core/Archives.cpp
Normal file
92
src/Core/Archives.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Core/Archives.h"
|
||||
|
||||
//#define BOOST_ARCHIVE_SOURCE
|
||||
#include <boost/archive/detail/archive_serializer_map.hpp>
|
||||
|
||||
// explicitly instantiate for this type of xml stream
|
||||
#include <boost/archive/impl/archive_serializer_map.ipp>
|
||||
|
||||
#include <boost/archive/impl/basic_xml_oarchive.ipp>
|
||||
#include <boost/archive/impl/xml_oarchive_impl.ipp>
|
||||
|
||||
#include <boost/archive/impl/basic_xml_iarchive.ipp>
|
||||
#include <boost/archive/impl/xml_iarchive_impl.ipp>
|
||||
|
||||
#include <boost/archive/impl/basic_text_oarchive.ipp>
|
||||
#include <boost/archive/impl/text_oarchive_impl.ipp>
|
||||
|
||||
#include <boost/archive/impl/basic_text_iarchive.ipp>
|
||||
#include <boost/archive/impl/text_iarchive_impl.ipp>
|
||||
|
||||
#include <boost/archive/polymorphic_xml_oarchive.hpp>
|
||||
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
|
||||
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::xml_oarchive> ;
|
||||
template class basic_xml_oarchive <uLib::Archive::xml_oarchive> ;
|
||||
template class xml_oarchive_impl <uLib::Archive::xml_oarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::xml_iarchive> ;
|
||||
template class basic_xml_iarchive <uLib::Archive::xml_iarchive> ;
|
||||
template class xml_iarchive_impl <uLib::Archive::xml_iarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::text_oarchive> ;
|
||||
template class basic_text_oarchive <uLib::Archive::text_oarchive> ;
|
||||
template class text_oarchive_impl <uLib::Archive::text_oarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::text_iarchive> ;
|
||||
template class basic_text_iarchive <uLib::Archive::text_iarchive> ;
|
||||
template class text_iarchive_impl <uLib::Archive::text_iarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::hrt_oarchive> ;
|
||||
template class basic_text_oarchive <uLib::Archive::hrt_oarchive> ;
|
||||
template class text_oarchive_impl <uLib::Archive::hrt_oarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::hrt_iarchive> ;
|
||||
template class basic_text_iarchive <uLib::Archive::hrt_iarchive> ;
|
||||
template class text_iarchive_impl <uLib::Archive::hrt_iarchive> ;
|
||||
|
||||
template class detail::archive_serializer_map <uLib::Archive::log_archive> ;
|
||||
template class basic_xml_oarchive <uLib::Archive::log_archive> ;
|
||||
template class xml_oarchive_impl <uLib::Archive::log_archive> ;
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace archive
|
||||
} // namespace boost
|
||||
784
src/Core/Archives.h
Normal file
784
src/Core/Archives.h
Normal file
@@ -0,0 +1,784 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_ARCHIVES_H
|
||||
#define U_CORE_ARCHIVES_H
|
||||
|
||||
|
||||
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
|
||||
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
|
||||
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
|
||||
#include <boost/archive/detail/register_archive.hpp>
|
||||
|
||||
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
|
||||
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
|
||||
|
||||
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||
|
||||
#include "StringReader.h"
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// FWD DECLARATIONS OF ARCHIVES //
|
||||
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
|
||||
class xml_iarchive;
|
||||
class xml_oarchive;
|
||||
class text_iarchive;
|
||||
class text_oarchive;
|
||||
class log_archive;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
template<class ArchiveImplementation> class polymorphic_oarchive_route;
|
||||
template<class ArchiveImplementation> class polymorphic_iarchive_route;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
template <typename T> struct hrp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES REGISTRATION //
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
namespace detail {
|
||||
struct adl_tag {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
// This function gets called, but its only purpose is to participate
|
||||
// in overload resolution with the functions declared by
|
||||
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
|
||||
template <class Serializable>
|
||||
void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The function declaration generated by this macro never actually
|
||||
// gets called, but its return type gets instantiated, and that's
|
||||
// enough to cause registration of serialization functions between
|
||||
// Archive and any exported Serializable type. See also:
|
||||
// boost/serialization/export.hpp
|
||||
# define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
|
||||
namespace boost { namespace archive { namespace detail { \
|
||||
\
|
||||
template <class Serializable> \
|
||||
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \
|
||||
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES IO INTERFACES //
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
|
||||
/**
|
||||
* Custom implementation of boost interface_iarchive to add new operators
|
||||
*/
|
||||
template<class Archive>
|
||||
class uLib_interface_iarchive
|
||||
{
|
||||
protected:
|
||||
uLib_interface_iarchive(){};
|
||||
public:
|
||||
/////////////////////////////////////////////////////////
|
||||
// archive public interface
|
||||
typedef mpl::bool_<true> is_loading;
|
||||
typedef mpl::bool_<false> is_saving;
|
||||
|
||||
// return a pointer to the most derived class
|
||||
Archive * This(){
|
||||
return static_cast<Archive *>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const basic_pointer_iserializer *
|
||||
register_type(T * = NULL){
|
||||
const basic_pointer_iserializer & bpis =
|
||||
boost::serialization::singleton<
|
||||
pointer_iserializer<Archive, T>
|
||||
>::get_const_instance();
|
||||
this->This()->register_basic_serializer(bpis.get_basic_serializer());
|
||||
return & bpis;
|
||||
}
|
||||
template<class T>
|
||||
Archive & operator>>(T & t){
|
||||
this->This()->load_override(t, 0);
|
||||
return * this->This();
|
||||
}
|
||||
|
||||
// the & operator
|
||||
template<class T>
|
||||
Archive & operator&(T & t){
|
||||
return *(this->This()) >> t;
|
||||
}
|
||||
|
||||
// the == operator
|
||||
template <class T>
|
||||
Archive & operator == (T & t) {
|
||||
return this->operator &(t);
|
||||
}
|
||||
|
||||
// the != operator for human readable access
|
||||
template <class T>
|
||||
Archive & operator != (T & t) {
|
||||
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
|
||||
return * this->This();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Custom implementation of boost interface_oarchive to add new operators
|
||||
*/
|
||||
template <class Archive>
|
||||
class uLib_interface_oarchive {
|
||||
protected:
|
||||
uLib_interface_oarchive(){};
|
||||
public:
|
||||
/////////////////////////////////////////////////////////
|
||||
// archive public interface
|
||||
typedef mpl::bool_<false> is_loading;
|
||||
typedef mpl::bool_<true> is_saving;
|
||||
|
||||
// return a pointer to the most derived class
|
||||
Archive * This(){
|
||||
return static_cast<Archive *>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const basic_pointer_oserializer *
|
||||
register_type(const T * = NULL){
|
||||
const basic_pointer_oserializer & bpos =
|
||||
boost::serialization::singleton<
|
||||
pointer_oserializer<Archive, T>
|
||||
>::get_const_instance();
|
||||
this->This()->register_basic_serializer(bpos.get_basic_serializer());
|
||||
return & bpos;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Archive & operator<<(T & t){
|
||||
// to get access you must redefine save_override by typing
|
||||
// "using save_override" in archive impl
|
||||
this->This()->save_override(t, 0);
|
||||
return * this->This();
|
||||
}
|
||||
|
||||
// the & operator
|
||||
template<class T>
|
||||
Archive & operator&(T & t){
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
return * this->This() << const_cast<const T &>(t);
|
||||
#else
|
||||
return * this->This() << t;
|
||||
#endif
|
||||
}
|
||||
|
||||
// the == operator
|
||||
template <class T>
|
||||
Archive & operator == (T & t) {
|
||||
return this->operator &(t);
|
||||
}
|
||||
|
||||
// the != operator for human readable access
|
||||
template <class T>
|
||||
Archive & operator != (T & t) {
|
||||
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
|
||||
return * this->This();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
|
||||
// With this declarations all uLib archive Implementation will use their own
|
||||
// extended interface //
|
||||
|
||||
template <>
|
||||
class interface_iarchive <uLib::Archive::xml_iarchive> : public
|
||||
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {};
|
||||
|
||||
template <>
|
||||
class interface_oarchive <uLib::Archive::xml_oarchive> : public
|
||||
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {};
|
||||
|
||||
template <>
|
||||
class interface_iarchive <uLib::Archive::text_iarchive> : public
|
||||
uLib_interface_iarchive <uLib::Archive::text_iarchive> {};
|
||||
|
||||
template <>
|
||||
class interface_oarchive <uLib::Archive::text_oarchive> : public
|
||||
uLib_interface_oarchive <uLib::Archive::text_oarchive> {};
|
||||
|
||||
template <>
|
||||
class interface_oarchive <uLib::Archive::log_archive> : public
|
||||
uLib_interface_oarchive <uLib::Archive::log_archive> {};
|
||||
|
||||
|
||||
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
|
||||
// template <class TypeSeq> \
|
||||
// struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
|
||||
// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
|
||||
// {};
|
||||
|
||||
//// Multiple size declaration //
|
||||
//BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
|
||||
|
||||
//#undef _INERIT_NOFOLD_H
|
||||
//#undef _INERIT_NOFOLD_V
|
||||
|
||||
|
||||
} // detail
|
||||
} // archive
|
||||
} // boost
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES DEFINITIONS //
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
|
||||
//template<class Archive>
|
||||
//inline void load_const_override(Archive & ar, const char *t ){
|
||||
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
|
||||
// typex::invoke(ar, t);
|
||||
//}
|
||||
|
||||
//template<class Archive, class T>
|
||||
//inline void load(Archive & ar, T &t){
|
||||
// // if this assertion trips. It means we're trying to load a
|
||||
// // const object with a compiler that doesn't have correct
|
||||
// // funtion template ordering. On other compilers, this is
|
||||
// // handled below.
|
||||
// // detail::check_const_loading< T >();
|
||||
// typedef
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
|
||||
// mpl::identity<detail::load_pointer_type<Archive> >
|
||||
// ,//else
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
|
||||
// mpl::identity<detail::load_array_type<Archive> >
|
||||
// ,//else
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
|
||||
// mpl::identity<detail::load_enum_type<Archive> >
|
||||
// ,//else
|
||||
// mpl::identity<detail::load_non_pointer_type<Archive> >
|
||||
// >
|
||||
// >
|
||||
// >::type typex;
|
||||
// typex::invoke(ar, t);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
namespace Archive {
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// POLYMORPHIC //
|
||||
|
||||
|
||||
//class polymorphic_iarchive :
|
||||
// public boost::archive::polymorphic_iarchive {
|
||||
|
||||
//public:
|
||||
// void load_override(const char *t, BOOST_PFTO int)
|
||||
// {
|
||||
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t));
|
||||
// }
|
||||
|
||||
//};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XML //
|
||||
|
||||
class xml_iarchive :
|
||||
public boost::archive::xml_iarchive_impl<xml_iarchive>,
|
||||
public boost::archive::detail::shared_ptr_helper
|
||||
{
|
||||
typedef xml_iarchive Archive;
|
||||
typedef boost::archive::xml_iarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||
friend class boost::archive::basic_xml_iarchive<Archive>;
|
||||
friend class boost::archive::load_access;
|
||||
public:
|
||||
xml_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||
xml_iarchive_impl<xml_iarchive>(is, flags)
|
||||
{}
|
||||
|
||||
using basic_xml_iarchive::load_override;
|
||||
|
||||
// Anything not an attribute should be a name value pair as nvp or hrp
|
||||
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive;
|
||||
template<class T>
|
||||
void load_override(
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
const
|
||||
#endif
|
||||
boost::serialization::hrp< T > & t,
|
||||
int v
|
||||
){
|
||||
this->This()->load_start(t.name());
|
||||
this->detail_common_iarchive::load_override(t.value(), 0);
|
||||
// t.stov();
|
||||
this->This()->load_end(t.name());
|
||||
}
|
||||
|
||||
|
||||
// class_name_type can't be handled here as it depends upon the
|
||||
// char type used by the stream. So require the derived implementation.
|
||||
// derived in this case is xml_iarchive_impl or base ..
|
||||
using base::load_override;
|
||||
|
||||
void load_override(const char *str, int v) {
|
||||
// StringReader sr(basic_text_iprimitive::is);
|
||||
// sr >> str;
|
||||
}
|
||||
|
||||
~xml_iarchive(){};
|
||||
};
|
||||
|
||||
//typedef boost::archive::detail::polymorphic_iarchive_route<
|
||||
//boost::archive::xml_iarchive_impl<xml_iarchive>
|
||||
//> polymorphic_xml_iarchive;
|
||||
|
||||
template <class ArchiveImpl>
|
||||
struct polymorphic_iarchive_route :
|
||||
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl>
|
||||
{
|
||||
virtual void load(const char * t){
|
||||
ArchiveImpl::load(t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class polymorphic_xml_iarchive :
|
||||
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> >
|
||||
{
|
||||
// give serialization implementation access to this class
|
||||
// friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||
// friend class boost::archive::basic_xml_iarchive<Archive>;
|
||||
// friend class boost::archive::load_access;
|
||||
public:
|
||||
virtual void load_override(const char *str, int v) {
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class xml_oarchive :
|
||||
public boost::archive::xml_oarchive_impl<xml_oarchive>
|
||||
{
|
||||
typedef xml_oarchive Archive;
|
||||
typedef boost::archive::xml_oarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||
friend class boost::archive::basic_xml_oarchive<Archive>;
|
||||
friend class boost::archive::save_access;
|
||||
public:
|
||||
xml_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags)
|
||||
{}
|
||||
|
||||
// example of implementing save_override for const char* //
|
||||
// void save_override(const char *t, int) {
|
||||
// std::cout << "found char: " << t << "\n";
|
||||
// }
|
||||
|
||||
using basic_xml_oarchive::save_override;
|
||||
|
||||
// special treatment for name-value pairs.
|
||||
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive;
|
||||
template<class T>
|
||||
void save_override(
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
const
|
||||
#endif
|
||||
::boost::serialization::hrp< T > & t,
|
||||
int v
|
||||
){
|
||||
this->This()->save_start(t.name());
|
||||
// t.vtos();
|
||||
// this->detail_common_oarchive::save_override(t.const_value(), 0);
|
||||
this->This()->save_end(t.name());
|
||||
}
|
||||
|
||||
void save_override(const char *str, int v) {
|
||||
// Do not save any human decoration string //
|
||||
// basic_text_oprimitive::save(str);
|
||||
}
|
||||
|
||||
~xml_oarchive(){}
|
||||
};
|
||||
|
||||
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||
//boost::archive::xml_oarchive_impl<xml_oarchive>
|
||||
//> polymorphic_xml_oarchive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TEXT //
|
||||
|
||||
class text_iarchive :
|
||||
public boost::archive::text_iarchive_impl<text_iarchive>,
|
||||
public boost::archive::detail::shared_ptr_helper
|
||||
{
|
||||
typedef text_iarchive Archive;
|
||||
typedef boost::archive::text_iarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||
friend class boost::archive::basic_text_iarchive<Archive>;
|
||||
friend class boost::archive::load_access;
|
||||
public:
|
||||
text_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||
text_iarchive_impl<Archive>(is, flags)
|
||||
{}
|
||||
|
||||
using basic_text_iarchive::load_override;
|
||||
|
||||
void load_override(boost::archive::object_id_type & t, int) {}
|
||||
|
||||
// class_name_type can't be handled here as it depends upon the
|
||||
// char type used by the stream. So require the derived implementation.
|
||||
// derived in this case is xml_iarchive_impl or base ..
|
||||
using base::load_override;
|
||||
|
||||
void load_override(const char *str, int v) {
|
||||
StringReader sr(basic_text_iprimitive::is);
|
||||
sr >> str;
|
||||
}
|
||||
|
||||
~text_iarchive() {};
|
||||
};
|
||||
|
||||
typedef text_iarchive naked_text_iarchive;
|
||||
|
||||
//typedef boost::archive::detail::polymorphic_iarchive_route<
|
||||
//naked_text_iarchive
|
||||
//> polymorphic_text_iarchive;
|
||||
|
||||
|
||||
|
||||
class text_oarchive :
|
||||
public boost::archive::text_oarchive_impl<text_oarchive>
|
||||
{
|
||||
typedef text_oarchive Archive;
|
||||
typedef boost::archive::text_oarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||
friend class boost::archive::basic_text_oarchive<Archive>;
|
||||
friend class boost::archive::save_access;
|
||||
public:
|
||||
text_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||
boost::archive::text_oarchive_impl<Archive>(os, flags)
|
||||
{}
|
||||
|
||||
using basic_text_oarchive::save_override;
|
||||
|
||||
void save_override(const char *str, int v) {
|
||||
basic_text_oprimitive::save(str);
|
||||
}
|
||||
|
||||
~text_oarchive(){}
|
||||
};
|
||||
|
||||
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||
//boost::archive::text_oarchive_impl<text_oarchive>
|
||||
//> polymorphic_text_oarchive;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SIMPLE HUMAN READABLE TEXT //
|
||||
|
||||
class hrt_iarchive :
|
||||
public boost::archive::text_iarchive_impl<hrt_iarchive>,
|
||||
public boost::archive::detail::shared_ptr_helper
|
||||
{
|
||||
typedef hrt_iarchive Archive;
|
||||
typedef boost::archive::text_iarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||
friend class boost::archive::basic_text_iarchive<Archive>;
|
||||
friend class boost::archive::load_access;
|
||||
public:
|
||||
hrt_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||
base(is, flags | boost::archive::no_header )
|
||||
{}
|
||||
|
||||
using basic_text_iarchive::load_override;
|
||||
|
||||
// hide all archive props //
|
||||
void load_override( boost::archive::object_id_type & t, int) {}
|
||||
void load_override( boost::archive::object_reference_type & t, int) {}
|
||||
void load_override( boost::archive::version_type & t, int) {}
|
||||
void load_override( boost::archive::class_id_type & t, int) {}
|
||||
void load_override( boost::archive::class_id_optional_type & t, int) {}
|
||||
void load_override( boost::archive::class_id_reference_type & t, int){}
|
||||
void load_override( boost::archive::class_name_type & t, int) {}
|
||||
void load_override( boost::archive::tracking_type & t, int) {}
|
||||
|
||||
// class_name_type can't be handled here as it depends upon the
|
||||
// char type used by the stream. So require the derived implementation.
|
||||
// derived in this case is xml_iarchive_impl or base ..
|
||||
using base::load_override;
|
||||
|
||||
void load_override(const char *str, int v) {
|
||||
StringReader sr(basic_text_iprimitive::is);
|
||||
sr >> str;
|
||||
}
|
||||
|
||||
~hrt_iarchive() {};
|
||||
};
|
||||
|
||||
|
||||
class hrt_oarchive :
|
||||
public boost::archive::text_oarchive_impl<hrt_oarchive>
|
||||
{
|
||||
typedef hrt_oarchive Archive;
|
||||
typedef boost::archive::text_oarchive_impl<Archive> base;
|
||||
|
||||
// give serialization implementation access to this class
|
||||
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||
friend class boost::archive::basic_text_oarchive<Archive>;
|
||||
friend class boost::archive::save_access;
|
||||
public:
|
||||
hrt_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||
base(os, flags | boost::archive::no_header )
|
||||
{}
|
||||
|
||||
using basic_text_oarchive::save_override;
|
||||
|
||||
void save_override(const boost::archive::object_id_type & t, int) {}
|
||||
void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||
void save_override(const boost::archive::version_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||
void save_override(const boost::archive::class_name_type & t, int) {}
|
||||
void save_override(const boost::archive::tracking_type & t, int) {}
|
||||
|
||||
|
||||
void save_override(const char *str, int v) {
|
||||
basic_text_oprimitive::save(str);
|
||||
}
|
||||
|
||||
~hrt_oarchive(){}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XML FOR LOG OUTPUT PURPOUSE //
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// log data to an output stream. This illustrates a simpler implemenation
|
||||
// of text output which is useful for getting a formatted display of
|
||||
// any serializable class. Intended to be useful as a debugging aid.
|
||||
class log_archive :
|
||||
/* protected ? */
|
||||
public boost::archive::xml_oarchive_impl<log_archive>
|
||||
{
|
||||
typedef boost::archive::xml_oarchive_impl<log_archive> base;
|
||||
typedef log_archive Archive;
|
||||
// give serialization implementation access to this clas
|
||||
friend class boost::archive::detail::interface_oarchive<log_archive>;
|
||||
friend class boost::archive::basic_xml_oarchive<log_archive>;
|
||||
friend class boost::archive::save_access;
|
||||
|
||||
public:
|
||||
|
||||
void save_override(const char *str, int v) {
|
||||
// Do not save any human decoration string //
|
||||
// basic_text_oprimitive::save(str);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void save_override(T & t, BOOST_PFTO int){
|
||||
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
|
||||
}
|
||||
|
||||
// activate this if you want to trap non nvp objects //
|
||||
// template<class T>
|
||||
// void save_override(T & t, BOOST_PFTO int)
|
||||
// {
|
||||
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
|
||||
// // this->detail_common_oarchive::save_override(t, 0);
|
||||
// }
|
||||
|
||||
template<class T>
|
||||
void save_override(const boost::serialization::nvp<T> & t, int){
|
||||
base::save_override(t, 0);
|
||||
}
|
||||
|
||||
|
||||
// specific overrides for attributes - not name value pairs so we
|
||||
// want to trap them before the above "fall through"
|
||||
// since we don't want to see these in the output - make them no-ops.
|
||||
void save_override(const boost::archive::object_id_type & t, int) {}
|
||||
void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||
void save_override(const boost::archive::version_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||
void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||
void save_override(const boost::archive::class_name_type & t, int) {}
|
||||
void save_override(const boost::archive::tracking_type & t, int) {}
|
||||
|
||||
|
||||
public:
|
||||
log_archive(std::ostream & os, unsigned int flags = 0) :
|
||||
boost::archive::xml_oarchive_impl<log_archive>(
|
||||
os,
|
||||
flags | boost::archive::no_header
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||
//boost::archive::xml_oarchive_impl<log_archive>
|
||||
//> polymorphic_log_archive;
|
||||
|
||||
|
||||
|
||||
|
||||
} // Archive
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_iarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_oarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_iarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_oarchive)
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
|
||||
|
||||
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_iarchive)
|
||||
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_oarchive)
|
||||
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_iarchive)
|
||||
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive)
|
||||
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // U_CORE_ARCHIVES_H
|
||||
72
src/Core/Array.h
Normal file
72
src/Core/Array.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_ARRAY_H
|
||||
#define U_CORE_ARRAY_H
|
||||
|
||||
#include <array> // std::array
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// ERROR NOT WORKING CLASS, USE VECTOR INSTEAD //////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
template< typename T, Size_t size >
|
||||
class Array : public std::array<T,size> {
|
||||
|
||||
};
|
||||
|
||||
|
||||
template< typename T, Size_t size >
|
||||
class SmartArray : public SmartPointer< Array<T,size> > {
|
||||
typedef SmartPointer< Array<T,size> > ptr;
|
||||
public:
|
||||
SmartArray() : ptr(new Array<T,size>()) { }
|
||||
SmartArray( const SmartArray ©) : ptr(copy) { }
|
||||
virtual ~SmartArray() {}
|
||||
|
||||
T& operator[](unsigned int p) {
|
||||
return ptr::get()->at(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // ARRAY_H
|
||||
46
src/Core/CMakeLists.txt
Normal file
46
src/Core/CMakeLists.txt
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
set(HEADERS
|
||||
Archives.h
|
||||
Array.h
|
||||
Collection.h
|
||||
Debug.h
|
||||
Export.h
|
||||
Function.h
|
||||
Macros.h
|
||||
Mpl.h
|
||||
Object.h
|
||||
ObjectProps.h
|
||||
Options.h
|
||||
Serializable.h
|
||||
Signal.h
|
||||
Singleton.h
|
||||
SmartPointer.h
|
||||
StaticInterface.h
|
||||
StringReader.h
|
||||
Types.h
|
||||
Uuid.h
|
||||
Vector.h
|
||||
CommaInitializer.h
|
||||
ProgrammableAccessor.h
|
||||
)
|
||||
|
||||
SET(SOURCES
|
||||
Archives.cpp
|
||||
Object.cpp
|
||||
Options.cpp
|
||||
Serializable.cpp
|
||||
Signal.cpp
|
||||
Uuid.cpp
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
${Boost_SERIALIZATION_LIBRARY}
|
||||
${Boost_SIGNALS_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${ROOT_LIBRARIES}
|
||||
${PACKAGE_LIBPREFIX}Core
|
||||
${PACKAGE_LIBPREFIX}Math
|
||||
)
|
||||
|
||||
uLib_add_shared_library(${uLib-module})
|
||||
add_subdirectory(testing)
|
||||
101
src/Core/Collection.h
Normal file
101
src/Core/Collection.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_COLLECTION_H
|
||||
#define U_CORE_COLLECTION_H
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "SmartPointer.h"
|
||||
#include "Vector.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////// COLLECTION TEMPLATE //////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: REWRITE THIS CLASS ... //
|
||||
|
||||
namespace uLib {
|
||||
|
||||
namespace Abstract {
|
||||
|
||||
template <typename T>
|
||||
class Collection {
|
||||
public:
|
||||
virtual ~Collection() {}
|
||||
|
||||
virtual void AddItem(T obj) =0;
|
||||
virtual void RemoveItem(int i) =0;
|
||||
virtual int GetNumberOfItems() =0;
|
||||
virtual T& At(unsigned int i) =0;
|
||||
|
||||
virtual void PrintSelf(std::ostream &o) =0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
class Collection : public Abstract::Collection<T> {
|
||||
|
||||
public:
|
||||
Collection() : data() {}
|
||||
Collection(int size) : data(size) {}
|
||||
~Collection() {}
|
||||
|
||||
inline void AddItem(T obj) { data->push_back(obj); }
|
||||
inline void RemoveItem(int i) { data.remove_element(i); }
|
||||
inline int GetNumberOfItems() { return data->size(); }
|
||||
|
||||
inline T& At(unsigned int i) { return data->at(i); }
|
||||
inline T& operator[] (unsigned int i) { return data->at(i); }
|
||||
|
||||
inline void PrintSelf(std::ostream &o);
|
||||
|
||||
private:
|
||||
SmartVector<T> data;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
void Collection<T>::PrintSelf(std::ostream &o)
|
||||
{
|
||||
o << " *** uLib Collection *** \n";
|
||||
o << " n. of items = " << this->GetNumberOfItems() << "\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // COLLECTION_H
|
||||
89
src/Core/CommaInitializer.h
Normal file
89
src/Core/CommaInitializer.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#ifndef U_CORE_COMMAINITIALIZER_H
|
||||
#define U_CORE_COMMAINITIALIZER_H
|
||||
|
||||
namespace uLib {
|
||||
|
||||
// Comma Initializer template ...
|
||||
// ContentT should provide operator[] and resize() methods.
|
||||
// Waiting for Static interface check
|
||||
|
||||
template < typename ContainerT, typename ContentT >
|
||||
struct CommaInitializer
|
||||
{
|
||||
inline explicit CommaInitializer(ContainerT *container, ContentT s)
|
||||
: container(container)
|
||||
{
|
||||
this->index = 0;
|
||||
container->resize(1);
|
||||
this->container->operator[](0) = s;
|
||||
}
|
||||
inline CommaInitializer & operator, (ContentT s) {
|
||||
this->index++;
|
||||
container->resize(index + 1);
|
||||
this->container->operator[](this->index) = s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ContainerT *container;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
|
||||
// Comma Initializer template for fixed array...
|
||||
// ContentT should provide operator[] and size() methods.
|
||||
// Waiting for Static interface check
|
||||
|
||||
template < typename ContainerT, typename ContentT >
|
||||
struct CommaInitializerFixed
|
||||
{
|
||||
inline explicit CommaInitializerFixed(ContainerT *container, ContentT s)
|
||||
: container(container)
|
||||
{
|
||||
this->index = 0;
|
||||
this->container->operator[](0) = s;
|
||||
}
|
||||
inline CommaInitializerFixed & operator, (ContentT s) {
|
||||
this->index++;
|
||||
this->container->operator[](this->index) = s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ContainerT *container;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
#endif // COMMAINITIALIZER_H
|
||||
31
src/Core/Debug.cpp
Normal file
31
src/Core/Debug.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Debug.h"
|
||||
|
||||
|
||||
148
src/Core/Debug.h
Normal file
148
src/Core/Debug.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_DEBUG_H
|
||||
#define U_CORE_DEBUG_H
|
||||
|
||||
|
||||
|
||||
#include "ltk/ltkdebug.h"
|
||||
#include "Macros.h"
|
||||
#include "Types.h"
|
||||
#include "Mpl.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <TObject.h>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct DebugAdapterInterface {
|
||||
virtual ~DebugAdapterInterface() {}
|
||||
|
||||
virtual void operator()(char val) {}
|
||||
virtual void operator()(unsigned char val) {}
|
||||
virtual void operator()(short val) {}
|
||||
virtual void operator()(unsigned short val) {}
|
||||
virtual void operator()(int val) {}
|
||||
virtual void operator()(unsigned int val) {}
|
||||
virtual void operator()(long val) {}
|
||||
virtual void operator()(unsigned long val) {}
|
||||
|
||||
virtual void operator()(float val) {}
|
||||
virtual void operator()(double val) {}
|
||||
|
||||
virtual void operator()(std::string val) {}
|
||||
};
|
||||
|
||||
|
||||
struct DebugAdapter {
|
||||
struct AnyCastAdapterBase {
|
||||
virtual ~AnyCastAdapterBase(){}
|
||||
virtual void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) {}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct AnyCastAdapter : AnyCastAdapterBase {
|
||||
void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) { ad->operator()(boost::any_cast<T>(val)); }
|
||||
};
|
||||
|
||||
struct DItem {
|
||||
DItem(){}
|
||||
template <typename T> DItem(std::string str, T &t) :
|
||||
m_adapter(new AnyCastAdapter<T>()),
|
||||
m_name(str),
|
||||
m_value(t) { }
|
||||
|
||||
SmartPointer<AnyCastAdapterBase> m_adapter;
|
||||
std::string m_name;
|
||||
boost::any m_value;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// text ADAPTER
|
||||
|
||||
class DebugAdapterText : public detail::DebugAdapterInterface {
|
||||
std::ostream &m_out;
|
||||
public:
|
||||
DebugAdapterText(std::ostream &o) : m_out(o) {}
|
||||
void operator()(int val) { m_out << "debug: " << val << "\n"; }
|
||||
void operator()(std::string val) { m_out << "debug: " << val << "\n"; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Debug {
|
||||
typedef detail::DebugAdapterInterface AdapterInterface;
|
||||
typedef SmartPointer<detail::DebugAdapterInterface> Adapter;
|
||||
typedef detail::DebugAdapter::DItem DItem;
|
||||
public:
|
||||
|
||||
template <typename T> void operator() (std::string str, T &t) { m_v.push_back(DItem(str,t)); }
|
||||
|
||||
void AddAdapter(AdapterInterface &ad) { m_a.push_back(Adapter(ad)); }
|
||||
|
||||
void Update() {
|
||||
foreach(Adapter &ad, m_a) {
|
||||
foreach(DItem &item, m_v) {
|
||||
item.m_adapter->operator()(ad, item.m_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Vector<DItem> m_v;
|
||||
Vector<Adapter> m_a;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // DEBUG_H
|
||||
52
src/Core/DebugArchives.cpp
Normal file
52
src/Core/DebugArchives.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <TTree.h>
|
||||
#include "DebugArchives.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
namespace detail {
|
||||
|
||||
basic_Root_Ttree_oprimitive::basic_Root_Ttree_oprimitive(const char *tree_name)
|
||||
{
|
||||
m_tree = new TTree(tree_name,tree_name);
|
||||
}
|
||||
|
||||
basic_Root_Ttree_oprimitive::~basic_Root_Ttree_oprimitive()
|
||||
{
|
||||
m_tree->Write();
|
||||
m_tree->ResetBranchAddresses();
|
||||
m_tree->Delete();
|
||||
}
|
||||
|
||||
} // detail
|
||||
} // Archive
|
||||
} // uLib
|
||||
|
||||
289
src/Core/DebugArchives.h
Normal file
289
src/Core/DebugArchives.h
Normal file
@@ -0,0 +1,289 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_DEBUGARCHIVES_H
|
||||
#define U_CORE_DEBUGARCHIVES_H
|
||||
|
||||
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
|
||||
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
|
||||
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
|
||||
#include <boost/archive/detail/register_archive.hpp>
|
||||
|
||||
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
|
||||
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
|
||||
|
||||
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||
|
||||
#include "Archives.h"
|
||||
#include "StringReader.h"
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// FWD DECLARATIONS OF ARCHIVES //
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
|
||||
class Root_debug_archive;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
template<class ArchiveImplementation> class polymorphic_oarchive_route;
|
||||
template<class ArchiveImplementation> class polymorphic_iarchive_route;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
template <typename T> struct hrp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES REGISTRATION //
|
||||
|
||||
// in Archives.h
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES IO INTERFACES //
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
namespace detail {
|
||||
|
||||
|
||||
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
|
||||
// With this declarations all uLib archive Implementation will use their own
|
||||
// extended interface //
|
||||
|
||||
template <>
|
||||
class interface_iarchive <uLib::Archive::Root_debug_archive> : public
|
||||
uLib_interface_iarchive <uLib::Archive::Root_debug_archive> {};
|
||||
|
||||
|
||||
} // detail
|
||||
} // archive
|
||||
} // boost
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ARCHIVES DEFINITIONS //
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
|
||||
//template<class Archive>
|
||||
//inline void load_const_override(Archive & ar, const char *t ){
|
||||
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
|
||||
// typex::invoke(ar, t);
|
||||
//}
|
||||
|
||||
//template<class Archive, class T>
|
||||
//inline void load(Archive & ar, T &t){
|
||||
// // if this assertion trips. It means we're trying to load a
|
||||
// // const object with a compiler that doesn't have correct
|
||||
// // funtion template ordering. On other compilers, this is
|
||||
// // handled below.
|
||||
// // detail::check_const_loading< T >();
|
||||
// typedef
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
|
||||
// mpl::identity<detail::load_pointer_type<Archive> >
|
||||
// ,//else
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
|
||||
// mpl::identity<detail::load_array_type<Archive> >
|
||||
// ,//else
|
||||
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
|
||||
// mpl::identity<detail::load_enum_type<Archive> >
|
||||
// ,//else
|
||||
// mpl::identity<detail::load_non_pointer_type<Archive> >
|
||||
// >
|
||||
// >
|
||||
// >::type typex;
|
||||
// typex::invoke(ar, t);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ROOT FWD
|
||||
class TTree;
|
||||
///////////
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
|
||||
namespace detail {
|
||||
|
||||
class basic_Root_Ttree_oprimitive
|
||||
{
|
||||
TTree *m_tree;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
basic_Root_Ttree_oprimitive(const char *tree_name);
|
||||
~basic_Root_Ttree_oprimitive();
|
||||
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XML FOR LOG OUTPUT PURPOUSE //
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//// log data to an output stream. This illustrates a simpler implemenation
|
||||
//// of text output which is useful for getting a formatted display of
|
||||
//// any serializable class. Intended to be useful as a debugging aid.
|
||||
class Root_debug_archive :
|
||||
/* protected ? */
|
||||
public boost::archive::detail::common_oarchive<Archive>
|
||||
{
|
||||
typedef boost::archive::detail::common_oarchive<Root_debug_archive> base;
|
||||
typedef Root_debug_archive Archive;
|
||||
|
||||
// give serialization implementation access to this clas
|
||||
friend class boost::archive::detail::interface_oarchive<Root_debug_archive>;
|
||||
friend class boost::archive::save_access;
|
||||
|
||||
public:
|
||||
|
||||
// void save_override(const char *str, int v) {
|
||||
// // Do not save any human decoration string //
|
||||
// // basic_text_oprimitive::save(str);
|
||||
// }
|
||||
|
||||
// template<class T>
|
||||
// void save_override(T & t, BOOST_PFTO int){
|
||||
// base::save_override(boost::serialization::make_nvp(NULL, t), 0);
|
||||
// }
|
||||
|
||||
// // activate this if you want to trap non nvp objects //
|
||||
// // template<class T>
|
||||
// // void save_override(T & t, BOOST_PFTO int)
|
||||
// // {
|
||||
// // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
|
||||
// // // this->detail_common_oarchive::save_override(t, 0);
|
||||
// // }
|
||||
|
||||
// template<class T>
|
||||
// void save_override(const boost::serialization::nvp<T> & t, int){
|
||||
// base::save_override(t, 0);
|
||||
// }
|
||||
|
||||
|
||||
// // specific overrides for attributes - not name value pairs so we
|
||||
// // want to trap them before the above "fall through"
|
||||
// // since we don't want to see these in the output - make them no-ops.
|
||||
// void save_override(const boost::archive::object_id_type & t, int) {}
|
||||
// void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||
// void save_override(const boost::archive::version_type & t, int) {}
|
||||
// void save_override(const boost::archive::class_id_type & t, int) {}
|
||||
// void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||
// void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||
// void save_override(const boost::archive::class_name_type & t, int) {}
|
||||
// void save_override(const boost::archive::tracking_type & t, int) {}
|
||||
|
||||
|
||||
//public:
|
||||
// Root_debug_archive(std::ostream & os, unsigned int flags = 0) :
|
||||
// boost::archive::xml_oarchive_impl<log_archive>(
|
||||
// os,
|
||||
// flags | boost::archive::no_header
|
||||
// )
|
||||
// {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // Archive
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::Root_debug_archive)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // U_CORE_DEBUGARCHIVES_H
|
||||
117
src/Core/Export.h
Normal file
117
src/Core/Export.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_EXPORT_H
|
||||
#define U_CORE_EXPORT_H
|
||||
|
||||
#include <utility>
|
||||
#include <cstddef> // NULL
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/type_traits/is_polymorphic.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
|
||||
#include <boost/serialization/static_warning.hpp>
|
||||
#include <boost/serialization/assume_abstract.hpp>
|
||||
#include <boost/serialization/force_include.hpp>
|
||||
#include <boost/serialization/singleton.hpp>
|
||||
|
||||
#include <boost/archive/detail/register_archive.hpp>
|
||||
|
||||
|
||||
#include "Core/Archives.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Archive {
|
||||
namespace detail {
|
||||
namespace extra_detail {
|
||||
|
||||
template<class T>
|
||||
struct guid_initializer
|
||||
{
|
||||
void export_guid(mpl::false_) const {
|
||||
// generates the statically-initialized objects whose constructors
|
||||
// register the information allowing serialization of T objects
|
||||
// through pointers to their base classes.
|
||||
boost::archive::detail::
|
||||
instantiate_ptr_serialization((T*)0, 0,
|
||||
uLib::Archive::detail::adl_tag());
|
||||
}
|
||||
void export_guid(mpl::true_) const {
|
||||
}
|
||||
guid_initializer const & export_guid() const {
|
||||
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
|
||||
// note: exporting an abstract base class will have no effect
|
||||
// and cannot be used to instantitiate serialization code
|
||||
// (one might be using this in a DLL to instantiate code)
|
||||
//BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
|
||||
export_guid(boost::serialization::is_abstract< T >());
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct init_guid;
|
||||
|
||||
} // anonymous
|
||||
} // namespace detail
|
||||
} // namespace Archive
|
||||
} // namespace uLib
|
||||
|
||||
|
||||
|
||||
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
|
||||
namespace uLib { \
|
||||
namespace Archive { \
|
||||
namespace detail { \
|
||||
namespace extra_detail { \
|
||||
template<> \
|
||||
struct init_guid< T > { \
|
||||
static guid_initializer< T > const & g; \
|
||||
}; \
|
||||
guid_initializer< T > const & init_guid< T >::g = \
|
||||
::boost::serialization::singleton< \
|
||||
guid_initializer< T > \
|
||||
>::get_mutable_instance().export_guid(); \
|
||||
}}}} \
|
||||
/**/
|
||||
|
||||
#endif // EXPORT_H
|
||||
54
src/Core/Flags.h
Normal file
54
src/Core/Flags.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef FLAGS_H
|
||||
#define FLAGS_H
|
||||
|
||||
#include <Core/Types.h>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
template<typename Enum>
|
||||
class Flags
|
||||
{
|
||||
int i;
|
||||
public:
|
||||
typedef Enum enum_type;
|
||||
CONSTEXPR inline Flags(const Flags &f) : i(f.i) {}
|
||||
CONSTEXPR inline Flags(Enum f) : i(f) {}
|
||||
CONSTEXPR inline Flags() : i(0) {}
|
||||
|
||||
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
|
||||
inline Flags &operator&=(int mask) { i &= mask; return *this; }
|
||||
inline Flags &operator&=(uint mask) { i &= mask; return *this; }
|
||||
inline Flags &operator|=(Flags f) { i |= f.i; return *this; }
|
||||
inline Flags &operator|=(Enum f) { i |= f; return *this; }
|
||||
inline Flags &operator^=(Flags f) { i ^= f.i; return *this; }
|
||||
inline Flags &operator^=(Enum f) { i ^= f; return *this; }
|
||||
|
||||
CONSTEXPR inline operator int() const { return i; }
|
||||
|
||||
CONSTEXPR inline Flags operator|(Flags f) const { return Flags(Enum(i | f.i)); }
|
||||
CONSTEXPR inline Flags operator|(Enum f) const { return Flags(Enum(i | f)); }
|
||||
CONSTEXPR inline Flags operator^(Flags f) const { return Flags(Enum(i ^ f.i)); }
|
||||
CONSTEXPR inline Flags operator^(Enum f) const { return Flags(Enum(i ^ f)); }
|
||||
CONSTEXPR inline Flags operator&(int mask) const { return Flags(Enum(i & mask)); }
|
||||
CONSTEXPR inline Flags operator&(uint mask) const { return Flags(Enum(i & mask)); }
|
||||
CONSTEXPR inline Flags operator&(Enum f) const { return Flags(Enum(i & f)); }
|
||||
CONSTEXPR inline Flags operator~() const { return Flags(Enum(~i)); }
|
||||
|
||||
CONSTEXPR inline bool operator!() const { return !i; }
|
||||
|
||||
inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
|
||||
};
|
||||
|
||||
#define ULIB_OPERATORS_FOR_FLAGS(Flags) \
|
||||
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
|
||||
{ return QFlags<Flags::enum_type>(f1) | f2; } \
|
||||
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
|
||||
{ return f2 | f1; }
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // FLAGS_H
|
||||
160
src/Core/Function.h
Normal file
160
src/Core/Function.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_FUNCTION_H
|
||||
#define U_CORE_FUNCTION_H
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/type_traits/is_member_function_pointer.hpp>
|
||||
|
||||
#include <boost/function_types/function_type.hpp>
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_arity.hpp>
|
||||
|
||||
|
||||
//#include <boost/typeof/std/utility.hpp>
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// type synthesize ( please read: boost implementation synthesize.hpp ) //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO: change this to boost implementation //
|
||||
// return a reference to function ... as the boost signal signature wants
|
||||
|
||||
template <typename FuncT>
|
||||
struct FunctionTypes {};
|
||||
|
||||
template <typename R, class O>
|
||||
struct FunctionTypes< R(O::*)() > {
|
||||
typedef R ref();
|
||||
typedef R (ptr)();
|
||||
typedef O obj;
|
||||
};
|
||||
|
||||
template <typename R, class O, typename T0>
|
||||
struct FunctionTypes< R(O::*)(T0) > {
|
||||
typedef R ref(T0);
|
||||
typedef R (ptr)(T0);
|
||||
typedef O obj;
|
||||
};
|
||||
|
||||
template <typename R, class O, typename T0, typename T1>
|
||||
struct FunctionTypes< R(O::*)(T0,T1) > {
|
||||
typedef R ref(T0,T1);
|
||||
typedef R (ptr)(T0,T1);
|
||||
typedef O obj;
|
||||
};
|
||||
|
||||
template <typename R, class O, typename T0, typename T1, typename T2>
|
||||
struct FunctionTypes< R(O::*)(T0,T1,T2) > {
|
||||
typedef R ref(T0,T1,T2);
|
||||
typedef R (ptr)(T0,T1,T2);
|
||||
typedef O obj;
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Function Types //
|
||||
|
||||
template<typename Func>
|
||||
struct FunctionTypes {
|
||||
typedef typename boost::function_types::function_type<Func>::type Signature;
|
||||
typedef typename detail::FunctionTypes<Func>::ref SignalSignature;
|
||||
enum {
|
||||
arity = boost::function_types::function_arity<Func>::value,
|
||||
ismfp = boost::is_member_function_pointer<Func>::value
|
||||
};
|
||||
|
||||
typedef boost::mpl::bool_< ismfp > HasObjectType;
|
||||
typedef typename detail::FunctionTypes<Func>::obj Object;
|
||||
typedef boost::function_traits< Signature > Traits;
|
||||
|
||||
virtual void PrintSelf( std::ostream &o ) {
|
||||
o << "[fp: " << typeid(Signature).name()
|
||||
<< " arity: " << arity << "]\n"; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////// generic mfp container object /////////////////////////////////////////
|
||||
|
||||
class GenericMFPtr {
|
||||
typedef void (GenericMFPtr::*VoidMFPtr)();
|
||||
public:
|
||||
typedef VoidMFPtr type;
|
||||
|
||||
GenericMFPtr() {}
|
||||
|
||||
template <typename T>
|
||||
GenericMFPtr(T in) {
|
||||
m_ptr = reinterpret_cast<VoidMFPtr>(in);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator == (T in) {
|
||||
return m_ptr == reinterpret_cast<VoidMFPtr>(in);
|
||||
}
|
||||
|
||||
inline bool operator == (const GenericMFPtr &in) {
|
||||
return m_ptr == in.m_ptr;
|
||||
}
|
||||
|
||||
VoidMFPtr operator()() { return m_ptr; }
|
||||
|
||||
VoidMFPtr m_ptr;
|
||||
private:
|
||||
};
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // FUNCTION_H
|
||||
173
src/Core/Macros.h
Normal file
173
src/Core/Macros.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_MACROS_H
|
||||
#define U_CORE_MACROS_H
|
||||
|
||||
//#ifndef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
//#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define uLibAssert(condition) assert(condition)
|
||||
|
||||
|
||||
// Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility //
|
||||
// http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol //
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
#ifdef BUILDING_DLL
|
||||
#ifdef __GNUC__
|
||||
#define DLL_PUBLIC __attribute__ ((dllexport))
|
||||
#else
|
||||
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
|
||||
#endif
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#define DLL_PUBLIC __attribute__ ((dllimport))
|
||||
#else
|
||||
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
|
||||
#endif
|
||||
#endif
|
||||
#define DLL_LOCAL
|
||||
#else
|
||||
#if __GNUC__ >= 4
|
||||
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
|
||||
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
||||
#else
|
||||
#define DLL_PUBLIC
|
||||
#define DLL_LOCAL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// foreach Qt style
|
||||
#ifndef foreach
|
||||
#include "boost/foreach.hpp"
|
||||
#define foreach(ref, list) BOOST_FOREACH(ref,list)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: verificare necessita' di typecast ////////////////////////////////
|
||||
|
||||
#define uLibVGetMacro(name,type) \
|
||||
virtual inline const type Get##name() const = 0;
|
||||
|
||||
#define uLibVSetMacro(name,type) \
|
||||
virtual inline void Set##name(const type name) = 0;
|
||||
|
||||
#define uLibVGetSetMacro(name,type) \
|
||||
uLibVGet(name,type); \
|
||||
uLibVSet(name,type);
|
||||
|
||||
#define uLibVRefMacro(name,type) \
|
||||
virtual inline type & name() = 0;
|
||||
|
||||
#define uLibPtrMacro(name,type) \
|
||||
inline type name() const { return this->m_##name; }
|
||||
|
||||
#define uLibArrayMacro(name,type) \
|
||||
inline type name() { return this->m_##name; }
|
||||
|
||||
#define uLibGetMacro(name,type) \
|
||||
inline type Get##name() const { return this->m_##name; }
|
||||
|
||||
#define uLibSetMacro(name,type) \
|
||||
inline void Set##name(type name) { this->m_##name = name; }
|
||||
|
||||
#define uLibGetSetMacro(name,type) \
|
||||
inline type Get##name() const { return this->m_##name; } \
|
||||
uLibSetMacro(name,type);
|
||||
|
||||
#define uLibRefMacro(name,type) \
|
||||
inline type & name() { return this->m_##name; }
|
||||
|
||||
#define uLibConstRefMacro(name,type) \
|
||||
inline const type & name() const { return this->m_##name; }
|
||||
|
||||
#define uLibAccessMacro(name,type) \
|
||||
inline void name(type name) { this->m_##name = name; } \
|
||||
uLibConstRefMacro(name,type)
|
||||
|
||||
|
||||
#define uLib_CRTP_ACCESS(_Derive,_name) \
|
||||
inline _Derive * _name() { return reinterpret_cast<_Derive *>(this); } \
|
||||
inline const _Derive * _name() const { return reinterpret_cast<const _Derive *>(this); } \
|
||||
//
|
||||
|
||||
#define uLib_CRTP_ACCESS_CASTED(_Derive,_Target,_name) \
|
||||
inline _Target _name() { return (_Target)(static_cast<_Derive &>(*this)); } \
|
||||
inline const _Target _name() const { return (const _Target)(static_cast<const _Derive &>(*this)); } \
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Following macros override usual branch prediction of compiler
|
||||
* These are to be used in conditional statement whose result might
|
||||
* be Bayesian biased:
|
||||
*
|
||||
* // previous_line
|
||||
* if (likely(a>1)) { // block_1 }
|
||||
* else { block_2 }
|
||||
*
|
||||
* will write the block_1 code right after previous line, without using
|
||||
* compiler branch prediction for results. Otherwise
|
||||
*
|
||||
* // previous_line
|
||||
* if (unlikely(a>1)) { // block_1 }
|
||||
* else { block_2 }
|
||||
*
|
||||
* will write block_2 after previous_line, leaving block_1 after
|
||||
* (usually after the end of the whole function! Use with care!)
|
||||
*/
|
||||
|
||||
#define unlikely(expr) __builtin_expect(!!(expr), 0)
|
||||
|
||||
#define likely(expr) __builtin_expect(!!(expr), 1)
|
||||
|
||||
/* Fastsign
|
||||
*/
|
||||
// #define sign(x) (( x > 0 ) - ( x < 0 ))
|
||||
template <typename T>
|
||||
inline T sign(const T x) { return x>0 - x<0; }
|
||||
|
||||
|
||||
#endif // MACROS_H
|
||||
41
src/Core/Makefile.am
Normal file
41
src/Core/Makefile.am
Normal file
@@ -0,0 +1,41 @@
|
||||
SUBDIRS = .
|
||||
|
||||
include $(top_srcdir)/Common.am
|
||||
|
||||
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Core
|
||||
|
||||
library_include_HEADERS = \
|
||||
Archives.h \
|
||||
Array.h \
|
||||
Collection.h \
|
||||
Debug.h \
|
||||
Export.h \
|
||||
Function.h \
|
||||
Macros.h \
|
||||
Mpl.h \
|
||||
Object.h \
|
||||
ObjectProps.h \
|
||||
Options.h \
|
||||
Serializable.h \
|
||||
Signal.h \
|
||||
Singleton.h \
|
||||
SmartPointer.h \
|
||||
StaticInterface.h \
|
||||
StringReader.h \
|
||||
Types.h \
|
||||
Uuid.h \
|
||||
Vector.h
|
||||
|
||||
|
||||
_CORE_SOURCES = \
|
||||
Archives.cpp \
|
||||
Debug.cpp \
|
||||
Object.cpp \
|
||||
Options.cpp \
|
||||
Serializable.cpp \
|
||||
Signal.cpp \
|
||||
Uuid.cpp
|
||||
|
||||
|
||||
noinst_LTLIBRARIES = libmutomcore.la
|
||||
libmutomcore_la_SOURCES = ${_CORE_SOURCES}
|
||||
139
src/Core/Mpl.h
Normal file
139
src/Core/Mpl.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_MPL_H
|
||||
#define U_MPL_H
|
||||
|
||||
#include <boost/preprocessor.hpp>
|
||||
|
||||
#include <boost/mpl/fold.hpp>
|
||||
#include <boost/mpl/inherit_linearly.hpp>
|
||||
#include <boost/mpl/inherit.hpp>
|
||||
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/mpl/vector/vector0.hpp>
|
||||
#include <boost/mpl/vector/vector10.hpp>
|
||||
#include <boost/mpl/vector/vector20.hpp>
|
||||
#include <boost/mpl/copy.hpp>
|
||||
|
||||
#include <boost/mpl/transform.hpp>
|
||||
#include <boost/mpl/transform_view.hpp>
|
||||
#include <boost/mpl/filter_view.hpp>
|
||||
|
||||
#include <boost/mpl/list.hpp>
|
||||
#include <boost/mpl/string.hpp>
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
/**
|
||||
* Max size of nofold inerited capability
|
||||
*/
|
||||
#ifndef ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE
|
||||
# define ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE 10
|
||||
#endif
|
||||
|
||||
namespace uLib {
|
||||
|
||||
namespace mpl {
|
||||
|
||||
using namespace boost::mpl;
|
||||
using namespace boost::mpl::placeholders;
|
||||
|
||||
//using boost::enable_if;
|
||||
|
||||
namespace detail {
|
||||
|
||||
/**
|
||||
* Inerit nofold implementation, set ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE to
|
||||
* desired max derivation size keeping in mind that total size accounts all
|
||||
* mutiple inherited classes.
|
||||
*/
|
||||
template <class TypeSeq, unsigned int size>
|
||||
struct inherit_nofold {};
|
||||
|
||||
// Horizontal repetition macro //
|
||||
#define _INERIT_NOFOLD_H(hz,hn,hdata) \
|
||||
BOOST_PP_COMMA_IF(hn) \
|
||||
mpl::at<TypeSeq,mpl::int_<hn> >::type
|
||||
|
||||
// Veritical repetition macro //
|
||||
#define _INERIT_NOFOLD_V(vz,vn,vdata) \
|
||||
template <class TypeSeq> \
|
||||
struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
|
||||
BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
|
||||
{};
|
||||
|
||||
// Multiple size declaration //
|
||||
BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
|
||||
|
||||
#undef _INERIT_NOFOLD_H
|
||||
#undef _INERIT_NOFOLD_V
|
||||
|
||||
|
||||
} // detail
|
||||
|
||||
/**
|
||||
* Build a derivation tuple from mpl type sequence.
|
||||
* The same behavior can be obtained by inherit_linearly but folding derivation
|
||||
* results in a hard to read debugging
|
||||
*/
|
||||
template <class TypeSeq>
|
||||
struct inherit_nofold {
|
||||
typedef detail::inherit_nofold< TypeSeq, mpl::size<TypeSeq>::type::value > type;
|
||||
};
|
||||
|
||||
/** INHERIT LINEARLY standard utility macro */
|
||||
#define ULIB_MPL_INHERIT_SEQ(_TypeList) \
|
||||
uLib::mpl::inherit_linearly< _TypeList, mpl::inherit< mpl::_1, mpl::_2 > >::type
|
||||
|
||||
/** INHERIT NOFOLD utility macro (see struct inherit_nofold template) */
|
||||
#define ULIB_MPL_INHERIT_NOFOLD_SEQ(_TypeList) \
|
||||
uLib::mpl::inherit_nofold< _TypeList >::type
|
||||
|
||||
|
||||
|
||||
|
||||
template< class T>
|
||||
struct type {
|
||||
|
||||
};
|
||||
|
||||
template <const char *N, class T>
|
||||
struct nvp {
|
||||
nvp() : name(N) {}
|
||||
const char *name;
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
|
||||
} // mpl
|
||||
|
||||
} // uLib
|
||||
|
||||
#endif // MPL_H
|
||||
227
src/Core/Object.cpp
Normal file
227
src/Core/Object.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "Object.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include "boost/archive/polymorphic_xml_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_xml_iarchive.hpp"
|
||||
#include "boost/archive/polymorphic_text_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_text_iarchive.hpp"
|
||||
#include "boost/archive/polymorphic_binary_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_binary_iarchive.hpp"
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
const char *Version::PackageName = PACKAGE_NAME;
|
||||
const char *Version::VersionNumber = PACKAGE_VERSION;
|
||||
const char *Version::Release = SVN_REVISION;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Object Private //
|
||||
|
||||
class ObjectPrivate {
|
||||
public:
|
||||
|
||||
struct Signal {
|
||||
GenericMFPtr sigptr;
|
||||
std::string sigstr;
|
||||
SignalBase *signal;
|
||||
};
|
||||
|
||||
struct Slot {
|
||||
GenericMFPtr sloptr;
|
||||
std::string slostr;
|
||||
};
|
||||
|
||||
|
||||
Vector<Signal> sigv;
|
||||
Vector<Slot> slov;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// OBJECT IMPLEMENTATION
|
||||
|
||||
|
||||
|
||||
Object::Object() :
|
||||
d(new ObjectPrivate)
|
||||
{}
|
||||
|
||||
Object::Object(const Object ©) :
|
||||
ObjectPropable(copy),
|
||||
d(new ObjectPrivate(*copy.d))
|
||||
{}
|
||||
|
||||
Object::~Object() {
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Object::DeepCopy(const Object ©)
|
||||
{
|
||||
// should lock to be tread safe //
|
||||
memcpy(d,copy.d,sizeof(ObjectPrivate));
|
||||
// ERROR! does not copy parameters ... <<<< FIXXXXX
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Object::SaveXml(std::ostream &os, Object &ob)
|
||||
{
|
||||
Archive::xml_oarchive ar(os);
|
||||
ar << boost::serialization::make_nvp("Object",ob);
|
||||
}
|
||||
|
||||
void Object::LoadXml(std::istream &is, Object &ob)
|
||||
{
|
||||
Archive::xml_iarchive ar(is);
|
||||
ar >> boost::serialization::make_nvp("Object",ob);
|
||||
}
|
||||
|
||||
|
||||
// FINIRE
|
||||
void Object::SaveConfig(std::ostream &os, int version)
|
||||
{
|
||||
Archive::xml_oarchive ar(os);
|
||||
ObjectPropable::serialize(ar,0);
|
||||
}
|
||||
|
||||
void Object::LoadConfig(std::istream &is, int version)
|
||||
{
|
||||
if(!props()) this->init_properties();
|
||||
Archive::xml_iarchive ar(is);
|
||||
ObjectPropable::serialize(ar,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Object::PrintSelf(std::ostream &o) const
|
||||
{
|
||||
o << "OBJECT signals: ------------------\n";
|
||||
Vector<ObjectPrivate::Signal>::Iterator itr;
|
||||
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
|
||||
{
|
||||
o << " signal:[ " << itr->sigstr << " ]\n";
|
||||
}
|
||||
o << "--------------------------------------\n\n";
|
||||
}
|
||||
|
||||
|
||||
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name)
|
||||
{
|
||||
ObjectPrivate::Signal s = {fptr,std::string(name),sig};
|
||||
d->sigv.push_back(s);
|
||||
}
|
||||
|
||||
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name)
|
||||
{
|
||||
ObjectPrivate::Slot s = {fptr,std::string(name)};
|
||||
d->slov.push_back(s);
|
||||
}
|
||||
|
||||
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const
|
||||
{
|
||||
for(int i=0; i<d->sigv.size(); ++i)
|
||||
{
|
||||
if(d->sigv[i].sigptr == fptr)
|
||||
return d->sigv[i].signal;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SignalBase *Object::findSignalImpl(const char *name) const
|
||||
{
|
||||
std::string in(name);
|
||||
for(int i=0; i<d->sigv.size(); ++i)
|
||||
{
|
||||
if(d->sigv[i].sigstr == in)
|
||||
return d->sigv[i].signal;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GenericMFPtr *Object::findSlotImpl(const char *name) const
|
||||
{
|
||||
std::string in(name);
|
||||
for(int i=0; i<d->slov.size(); ++i)
|
||||
{
|
||||
if(d->slov[i].slostr == in)
|
||||
return &d->slov[i].sloptr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::ostream &
|
||||
operator << (std::ostream &os, uLib::Object &ob)
|
||||
{
|
||||
uLib::Object *op = &ob;
|
||||
uLib::Archive::hrt_oarchive (os) << op;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator << (std::ostream &os, uLib::Object *ob)
|
||||
{
|
||||
uLib::Archive::hrt_oarchive(os) << ob;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::istream &
|
||||
operator >> (std::istream &is, uLib::Object &ob)
|
||||
{
|
||||
// uLib::Object *op = &ob;
|
||||
uLib::Archive::hrt_iarchive(is) >> ob;
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
222
src/Core/Object.h
Normal file
222
src/Core/Object.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_OBJECT_H
|
||||
#define U_CORE_OBJECT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// WARNING: COPILE ERROR if this goes after mpl/vector //
|
||||
//#include "Core/Vector.h"
|
||||
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Debug.h"
|
||||
|
||||
#include "Core/Function.h"
|
||||
#include "Core/Signal.h"
|
||||
|
||||
#include "Core/Mpl.h"
|
||||
#include "Core/Serializable.h"
|
||||
#include "Core/ObjectProps.h"
|
||||
#include "Core/Uuid.h"
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
class polymorphic_iarchive;
|
||||
class polymorphic_oarchive;
|
||||
} // archive
|
||||
} // boost
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
class Version {
|
||||
public:
|
||||
static const char *PackageName;
|
||||
static const char *VersionNumber;
|
||||
static const char *Release;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// OBJECT ////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Object class is the object base implementation for uLib Framework.
|
||||
*/
|
||||
class Object : public ObjectPropable
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
// std::string name;
|
||||
// void PrintName() { std::cout << "Ob name: " << name << "\n"; }
|
||||
|
||||
Object();
|
||||
Object(const Object ©);
|
||||
~Object();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PARAMETERS //
|
||||
|
||||
// FIXX !!!
|
||||
virtual void DeepCopy(const Object ©);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// SERIALIZATION //
|
||||
|
||||
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||
ObjectPropable::serialize(ar,version);
|
||||
}
|
||||
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
|
||||
|
||||
void SaveConfig(std::ostream &os, int version = 0);
|
||||
void LoadConfig(std::istream &is, int version = 0);
|
||||
|
||||
static void SaveXml(std::ostream &os, Object &ob);
|
||||
static void LoadXml(std::istream &is, Object &ob);
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// SIGNALS //
|
||||
|
||||
// Qt4 style connector //
|
||||
static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) {
|
||||
// // NOT WORKING YET //
|
||||
// 1) find slot pointer from name
|
||||
// SignalBase *sig = ob1->findSignal(signal_name);
|
||||
// GenericMFPtr *slo = receiver->findSlot(slot_name);
|
||||
// if(sig && slo)
|
||||
// return Object::connect(sig,slo->operator ()(),receiver);
|
||||
// else return false;
|
||||
}
|
||||
|
||||
// Qt5 style connector //
|
||||
template <typename Func1, typename Func2>
|
||||
static bool connect( typename FunctionTypes<Func1>::Object *sender, Func1 sigf,
|
||||
typename FunctionTypes<Func2>::Object *receiver, Func2 slof)
|
||||
{
|
||||
SignalBase *sigb = sender->findOrAddSignal(sigf);
|
||||
typedef boost::signals2::signal<typename FunctionTypes<Func2>::SignalSignature> SigT;
|
||||
ConnectSignal(sigb,slof,receiver);
|
||||
}
|
||||
|
||||
template <typename FuncT>
|
||||
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
|
||||
ConnectSignal(sigb,slof,receiver);
|
||||
}
|
||||
|
||||
|
||||
template< typename FuncT >
|
||||
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
|
||||
addSignal(FuncT fun, const char *name) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
SignalBase *sig = NewSignal(fun);
|
||||
addSignalImpl(sig,fun,name);
|
||||
return (SigT *)sig;
|
||||
}
|
||||
|
||||
template< typename FuncT>
|
||||
inline bool addSlot(FuncT fun, const char *name) {
|
||||
this->addSlotImpl(GenericMFPtr(fun),name);
|
||||
}
|
||||
|
||||
template < typename FuncT >
|
||||
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
|
||||
findSignal(FuncT fptr)
|
||||
{
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
|
||||
}
|
||||
|
||||
template < typename FuncT >
|
||||
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
|
||||
findOrAddSignal(FuncT fptr)
|
||||
{
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
|
||||
if(!sig) {
|
||||
sig = NewSignal(fptr);
|
||||
addSignalImpl(sig,fptr,"signal_name_to_be_implemented");
|
||||
}
|
||||
return (SigT *)sig;
|
||||
}
|
||||
|
||||
|
||||
inline SignalBase *
|
||||
findSignal(const char *name) const
|
||||
{
|
||||
return findSignalImpl(name);
|
||||
}
|
||||
|
||||
inline GenericMFPtr *
|
||||
findSlot(const char *name) const
|
||||
{
|
||||
return findSlotImpl(name);
|
||||
}
|
||||
|
||||
|
||||
void PrintSelf(std::ostream &o) const;
|
||||
|
||||
inline const Object& operator = (const Object ©)
|
||||
{ this->DeepCopy(copy); return *this; }
|
||||
|
||||
|
||||
private:
|
||||
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
|
||||
bool addSlotImpl(GenericMFPtr fptr, const char *name);
|
||||
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
|
||||
SignalBase *findSignalImpl(const char *name) const;
|
||||
GenericMFPtr *findSlotImpl(const char *name) const;
|
||||
|
||||
friend class boost::serialization::access;
|
||||
friend class ObjectPrivate;
|
||||
class ObjectPrivate *d;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::ostream & operator << (std::ostream &os, uLib::Object &ob);
|
||||
std::ostream & operator << (std::ostream &os, uLib::Object *ob);
|
||||
std::istream & operator >> (std::istream &is, uLib::Object &ob);
|
||||
|
||||
|
||||
#endif // U_OBJECT_H
|
||||
278
src/Core/ObjectProps.h
Normal file
278
src/Core/ObjectProps.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_OBJECTPROPS_H
|
||||
#define U_OBJECTPROPS_H
|
||||
|
||||
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include <Core/Mpl.h>
|
||||
#include <Core/Types.h>
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MACROS //
|
||||
|
||||
|
||||
#define ULIB_props() \
|
||||
public: struct ObjectProps; \
|
||||
virtual void init_properties(); \
|
||||
inline struct ObjectProps &p() { /* static const unsigned int offset = props_offset(this); */ \
|
||||
/* NON FUNZIA! return * (struct ObjectProps *)(reinterpret_cast<char*>(props())+offset); */ \
|
||||
return *props()->ptr<ObjectProps>(); } \
|
||||
typedef uLib::mpl::bool_<true>::type propable_trait; \
|
||||
public: struct DLL_PUBLIC ObjectProps
|
||||
|
||||
#define properties() ULIB_props()
|
||||
|
||||
#define default(vlaue)
|
||||
|
||||
#define $$ p()
|
||||
|
||||
#define $(_name) props_ref<_name>()
|
||||
|
||||
#define $_init() \
|
||||
if(props(this)) return; \
|
||||
props_new(this); \
|
||||
uLib::detail::ObjectProps::initializer::init_object_baselist(this);
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
class access;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct ObjectProps {
|
||||
|
||||
/** Define a trait has_member to find if an Object is Propable*/
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(propable_trait)
|
||||
|
||||
/** IsA ProbapleObject Implementation Template */
|
||||
template <class T>
|
||||
struct IsA : has_propable_trait<T> {};
|
||||
|
||||
/** Lambda to get Props member type */
|
||||
template <class T>
|
||||
struct props_type {
|
||||
typedef typename T::ObjectProps type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct get_props {
|
||||
|
||||
/** CFList has result but this method check for has BaseList */
|
||||
typedef typename detail::TypeIntrospection::child_first<T>::type CFTypeList;
|
||||
|
||||
/** Filter List items that have not Propable feature */
|
||||
typedef typename mpl::filter_view< CFTypeList, IsA<mpl::_> >::type FilteredCFTypeList;
|
||||
|
||||
/** Get Props from each Parent in Seq */
|
||||
typedef typename mpl::transform_view< FilteredCFTypeList, props_type<mpl::_> >::type type;
|
||||
|
||||
|
||||
// qui sotto ho un problema che ho temporaneamente tamponato //
|
||||
// ovvero ho usato child_first_impl per ottenere la lista delle basi //
|
||||
// vorrei farlo facendo un pop_back ma non va forse perche il tipo //
|
||||
// non e' corretto. //
|
||||
|
||||
/** Get Parent list from CFTypeList */
|
||||
typedef typename detail::TypeIntrospection::child_first_impl<T>::Childs CFBaseList;
|
||||
|
||||
/** Filter Parents that have not Propable feature */
|
||||
typedef typename mpl::filter_view< CFBaseList, IsA<mpl::_> >::type FilteredCFBaseList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// TODO: convert to pp const value,
|
||||
// (non so se sia possibile con il dinamic casting intanto funziona cosi' )
|
||||
template <typename T1, typename T2>
|
||||
static unsigned int measure_offset(T1 base, T2 derived) {
|
||||
return reinterpret_cast<char*>(derived) - reinterpret_cast<char*>(base);
|
||||
}
|
||||
|
||||
struct initializer {
|
||||
|
||||
template <class _ObjectT>
|
||||
struct lambda_init_object {
|
||||
_ObjectT *o;
|
||||
lambda_init_object(_ObjectT *o) : o(o) {}
|
||||
template<class T> void operator()(T) {
|
||||
o->T::init_properties();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This calls the internal init_properties() virtual function for each
|
||||
* object parent defined in BaseList only if it is propable
|
||||
*/
|
||||
template <class T>
|
||||
static void init_object_baselist(T *o) {
|
||||
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFBaseList CFBaseList;
|
||||
mpl::for_each<CFBaseList>(lambda_init_object<T>(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls the internal init_properties() virtual function only if
|
||||
* object is propable ( implementation if not propable )
|
||||
*/
|
||||
template <class T>
|
||||
static
|
||||
typename boost::enable_if<mpl::not_<IsA<T> >,void>::type
|
||||
init_object(T *o) {
|
||||
; // do nothing //
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls the internal init_properties() virtual function only if
|
||||
* object is propable ( implementation if propable )
|
||||
*/
|
||||
template <class T>
|
||||
static
|
||||
typename boost::enable_if<IsA<T>,void>::type
|
||||
init_object(T *o) {
|
||||
o->init_properties();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class ThisClass, class Archive>
|
||||
struct serialize_baselist {
|
||||
ThisClass & m_object;
|
||||
Archive & m_ar;
|
||||
serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
|
||||
template <class T> void operator()(T &o) {
|
||||
// T is taken fron get_props<BaseList>::FilteredPList types to get
|
||||
// type_info_name that is the type name defined by Type macro
|
||||
typedef typename props_type<T>::type PType;
|
||||
std::string name(TypeIntrospection::access<T>::type_info::name);
|
||||
boost::algorithm::replace_all(name,"::","_");
|
||||
m_ar & boost::serialization::make_nvp(
|
||||
name.c_str() ,
|
||||
boost::serialization::base_object<PType>(m_object));
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct ObjectPropsBase {
|
||||
virtual ~ObjectPropsBase() {}
|
||||
virtual ObjectPropsBase *copy() = 0;
|
||||
|
||||
template <class T> inline T *ptr() { return dynamic_cast<T*>(this); }
|
||||
|
||||
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
struct ObjectPropsImpl :
|
||||
ObjectPropsBase,
|
||||
ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props<T>::type)
|
||||
{
|
||||
typedef ObjectPropsImpl<T> ThisClass;
|
||||
typedef typename uLib::detail::ObjectProps::get_props<T>::type CFList;
|
||||
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFTypeList FilteredCFTypeList;
|
||||
ObjectPropsBase *copy() { return new ThisClass(*this); }
|
||||
|
||||
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||
boost::serialization::void_cast_register<ThisClass,ObjectPropsBase>();
|
||||
mpl::for_each<FilteredCFTypeList>(detail::ObjectProps::serialize_baselist<ThisClass,ArchiveT>(*this,ar));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ObjectPropable {
|
||||
|
||||
ObjectPropsBase *m_props;
|
||||
friend class uLib::detail::ObjectProps;
|
||||
friend class boost::serialization::access;
|
||||
public:
|
||||
ObjectPropable() : m_props(NULL) {}
|
||||
ObjectPropable(const ObjectPropable &c) { if(c.m_props) m_props = c.m_props->copy(); else m_props = NULL; }
|
||||
~ObjectPropable() { if(m_props) delete m_props; }
|
||||
|
||||
|
||||
template <class T> inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr<typename T::ObjectProps>(); else exit(1); }
|
||||
template <class T> inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr<typename T::ObjectProps>(); else return NULL; }
|
||||
protected:
|
||||
ObjectPropsBase *props() const { return m_props; }
|
||||
template <class T> inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl<T>; }
|
||||
|
||||
/** NOT working dynamic cache casting */
|
||||
template <class T> inline unsigned int props_offset(T *ptr) const
|
||||
{ if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr<T>()); else return -1; }
|
||||
|
||||
|
||||
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||
if(m_props) ar & boost::serialization::make_nvp("properties",m_props);
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* ObjectPropable is not directly propable itself to prevent Basclass
|
||||
* duplication in inherit_nofold. And for the same reason ANY VIRTUAL BASE
|
||||
* SHOULD NOT BE PROPABLE
|
||||
*/
|
||||
virtual void init_properties() {}
|
||||
|
||||
};
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // U_OBJECTPROPS_H
|
||||
87
src/Core/Options.cpp
Normal file
87
src/Core/Options.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "Core/Options.h"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
|
||||
//class boost::program_options::error_with_option_name;
|
||||
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
|
||||
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>(int *);
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
Options::Options(const char *str) :
|
||||
m_global(str),
|
||||
m_configuration("Configuration")
|
||||
{}
|
||||
|
||||
void Options::parse_command_line(int argc, char *argv[]) {
|
||||
boost::program_options::store(boost::program_options::parse_command_line(argc,argv,m_global),m_vm);
|
||||
boost::program_options::notify(m_vm);
|
||||
|
||||
if(m_vm.count("help")) {
|
||||
std::cout << "\n" << m_global << "\n";
|
||||
if(m_configuration.options().size()) {
|
||||
std::cout << "\n" << m_configuration << "\n\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Options::parse_config_file(std::string &str)
|
||||
{
|
||||
this->parse_config_file(str.c_str());
|
||||
}
|
||||
|
||||
void Options::parse_config_file(const char *fname)
|
||||
{
|
||||
std::ifstream is;
|
||||
is.open(fname);
|
||||
boost::program_options::options_description fileopt;
|
||||
fileopt.add(m_global).add(m_configuration);
|
||||
if(is.is_open()) {
|
||||
boost::program_options::store(boost::program_options::parse_config_file(is,fileopt,true),m_vm);
|
||||
boost::program_options::notify(m_vm);
|
||||
}
|
||||
}
|
||||
|
||||
bool Options::count(const char *str) const
|
||||
{
|
||||
return (m_vm.count(str));
|
||||
}
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
179
src/Core/Options.h
Normal file
179
src/Core/Options.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_OPTIONS_H
|
||||
#define U_CORE_OPTIONS_H
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct Options {
|
||||
|
||||
/**
|
||||
* Wrapper for boost program_options easy init syntax
|
||||
*/
|
||||
class options_description_easy_init {
|
||||
typedef boost::program_options::options_description_easy_init InitClass;
|
||||
InitClass m_init;
|
||||
public:
|
||||
options_description_easy_init(InitClass init) :
|
||||
m_init(init) {}
|
||||
|
||||
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
const char* description)
|
||||
{
|
||||
m_init(name,description);
|
||||
return *this;
|
||||
}
|
||||
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
const boost::program_options::value_semantic* s)
|
||||
{
|
||||
m_init(name,s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
const boost::program_options::value_semantic* s,
|
||||
const char* description)
|
||||
{
|
||||
m_init(name,s,description);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
T * value,
|
||||
const T default_value,
|
||||
const char* description)
|
||||
{
|
||||
m_init(name,
|
||||
boost::program_options::value<T>(value)->default_value(default_value),
|
||||
description);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
T * value,
|
||||
const char* description)
|
||||
{
|
||||
assert(value);
|
||||
m_init(name,
|
||||
boost::program_options::value<T>(value)->default_value(*value),
|
||||
description);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
T * value,
|
||||
const T default_value)
|
||||
{
|
||||
m_init(name,
|
||||
boost::program_options::value<T>(value)->default_value(default_value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
options_description_easy_init&
|
||||
operator()(const char* name,
|
||||
T * value)
|
||||
{
|
||||
assert(value);
|
||||
m_init(name,
|
||||
boost::program_options::value<T>(value)->default_value(*value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}; // Options
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
class Options {
|
||||
boost::program_options::options_description m_global;
|
||||
boost::program_options::options_description m_configuration;
|
||||
boost::program_options::positional_options_description m_posdesc;
|
||||
boost::program_options::variables_map m_vm;
|
||||
|
||||
public:
|
||||
typedef detail::Options::options_description_easy_init initType;
|
||||
|
||||
Options(const char *str = "Program options");
|
||||
|
||||
initType add_options() {
|
||||
return initType(m_global.add_options());
|
||||
}
|
||||
|
||||
initType add_config_options() {
|
||||
return initType(m_configuration.add_options());
|
||||
}
|
||||
|
||||
void add_positional_option(const char *name, int max_count) {
|
||||
// TODO:
|
||||
// m_posdesc(name,max_count);
|
||||
}
|
||||
|
||||
void parse_command_line(int argc, char *argv[]);
|
||||
|
||||
void parse_config_file(std::string &str);
|
||||
|
||||
void parse_config_file(const char *fname);
|
||||
|
||||
template <typename T>
|
||||
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
|
||||
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
|
||||
r->default_value(dvalue);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool count(const char *str) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
#endif // U_CORE_OPTIONS_H
|
||||
140
src/Core/ProgrammableAccessor.h
Normal file
140
src/Core/ProgrammableAccessor.h
Normal file
@@ -0,0 +1,140 @@
|
||||
#ifndef U_CORE_PROGRAMMABLEACCESSOR_H
|
||||
#define U_CORE_PROGRAMMABLEACCESSOR_H
|
||||
|
||||
#include <Core/Macros.h>
|
||||
#include <Core/Types.h>
|
||||
#include <Core/SmartPointer.h>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename R>
|
||||
class ProgrammableAccessor_Base {
|
||||
public:
|
||||
virtual R Get(void *) const = 0;
|
||||
virtual void Set(void *,const R) const = 0;
|
||||
|
||||
template <typename T>
|
||||
T Get(void *ob) const {
|
||||
return static_cast<T>(this->Get(ob));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Set(void *ob, const T data) const {
|
||||
this->Set(ob,static_cast<R>(data));
|
||||
}
|
||||
|
||||
virtual ~ProgrammableAccessor_Base() {}
|
||||
};
|
||||
|
||||
|
||||
template<typename R, typename T>
|
||||
class functor_by_ref : public ProgrammableAccessor_Base<R>
|
||||
{
|
||||
public:
|
||||
explicit functor_by_ref(R&(T::*__pf)()) : MFRef(__pf) {}
|
||||
R Get(void * ptr) const
|
||||
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*MFRef)()); }
|
||||
void Set(void * ptr, const R data) const
|
||||
{ ((reinterpret_cast<T *>(ptr)->*MFRef)()) = data; }
|
||||
private:
|
||||
R&(T::*MFRef)();
|
||||
};
|
||||
|
||||
template<typename R, typename T>
|
||||
class functor_by_mfptr_cc : public ProgrammableAccessor_Base<R>
|
||||
{
|
||||
typedef R(T::*GetterType)() const;
|
||||
typedef void(T::*SetterType)(const R);
|
||||
public:
|
||||
explicit functor_by_mfptr_cc( GetterType _get, SetterType _set ) :
|
||||
GetPtr(_get), SetPtr(_set) {}
|
||||
R Get(void * ptr) const
|
||||
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*GetPtr)()); }
|
||||
void Set(void * ptr, const R data) const
|
||||
{ if (SetPtr) (reinterpret_cast<T *>(ptr)->*SetPtr)(data); }
|
||||
|
||||
private:
|
||||
GetterType GetPtr;
|
||||
SetterType SetPtr;
|
||||
};
|
||||
|
||||
template<typename R, typename T>
|
||||
class functor_by_mfptr_vv : public ProgrammableAccessor_Base<R>
|
||||
{
|
||||
typedef R(T::*GetterType)();
|
||||
typedef void(T::*SetterType)(R);
|
||||
public:
|
||||
explicit functor_by_mfptr_vv( GetterType _get, SetterType _set ) :
|
||||
GetPtr(_get), SetPtr(_set) {}
|
||||
R Get(void * ptr) const
|
||||
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*GetPtr)()); }
|
||||
void Set(void * ptr, const R data) const
|
||||
{ if (SetPtr) (reinterpret_cast<T *>(ptr)->*SetPtr)(data); }
|
||||
|
||||
private:
|
||||
GetterType GetPtr;
|
||||
SetterType SetPtr;
|
||||
};
|
||||
|
||||
|
||||
template<typename R, typename T>
|
||||
class functor_by_member : public ProgrammableAccessor_Base<R>
|
||||
{
|
||||
public:
|
||||
explicit functor_by_member(R T::*__pf) : MDPtr(__pf) {}
|
||||
R Get(void * ptr) const
|
||||
{ return static_cast<R>(reinterpret_cast<T *>(ptr)->*MDPtr); }
|
||||
void Set(void * ptr, const R data) const
|
||||
{ (reinterpret_cast<T *>(ptr)->*MDPtr) = data; }
|
||||
private:
|
||||
R T::*MDPtr;
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Programmable Accessor Factory /////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template <typename R>
|
||||
class ProgrammableAccessor {
|
||||
public:
|
||||
template <typename T>
|
||||
ProgrammableAccessor(R(T::*_pg)()const, void(T::*_ps)(const R) = NULL) :
|
||||
m_base(new detail::functor_by_mfptr_cc<R,T>(_pg,_ps)) {}
|
||||
|
||||
template <typename T>
|
||||
ProgrammableAccessor(R(T::*_pg)(), void(T::*_ps)(R) = NULL) :
|
||||
m_base(new detail::functor_by_mfptr_vv<R,T>(_pg,_ps)) {}
|
||||
|
||||
template <typename T>
|
||||
ProgrammableAccessor(R&(T::*_pf)()) :
|
||||
m_base(new detail::functor_by_ref<R,T>(_pf)) {}
|
||||
|
||||
template <typename T>
|
||||
ProgrammableAccessor(R T::*_pf) :
|
||||
m_base(new detail::functor_by_member<R,T>(_pf)) {}
|
||||
|
||||
template <typename OtherR>
|
||||
inline OtherR Get(void *ob) const { return m_base->Get<OtherR>(ob); }
|
||||
|
||||
template <typename OtherR>
|
||||
inline void Set(void *ob, const OtherR data) const { return m_base->Set<OtherR>(ob,data); }
|
||||
|
||||
private:
|
||||
SmartPointer< detail::ProgrammableAccessor_Base<R> > m_base;
|
||||
};
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
#endif // PROGRAMMABLEACCESSOR_H
|
||||
95
src/Core/Serializable.cpp
Normal file
95
src/Core/Serializable.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include "boost/archive/polymorphic_xml_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_xml_iarchive.hpp"
|
||||
#include "boost/archive/polymorphic_text_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_text_iarchive.hpp"
|
||||
#include "boost/archive/polymorphic_binary_oarchive.hpp"
|
||||
#include "boost/archive/polymorphic_binary_iarchive.hpp"
|
||||
|
||||
#include "Serializable.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
//void Serializable::SaveXml(std::ostream &os, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_xml_oarchive(os);
|
||||
// this->Save(*xoa);
|
||||
// delete xoa;
|
||||
//}
|
||||
|
||||
//void Serializable::LoadXml(std::istream &is, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_xml_iarchive(is);
|
||||
// this->Load(*xia,this);
|
||||
// delete xia;
|
||||
//}
|
||||
|
||||
//void Serializable::SaveText(std::ostream &os, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_text_oarchive(os);
|
||||
// this->Save(*xoa);
|
||||
// delete xoa;
|
||||
//}
|
||||
|
||||
//void Serializable::LoadText(std::istream &is, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_text_iarchive(is);
|
||||
// this->Load(*xia,this);
|
||||
// delete xia;
|
||||
//}
|
||||
|
||||
//void Serializable::SaveBin(std::ostream &os, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_binary_oarchive(os);
|
||||
// this->Save(*xoa);
|
||||
// delete xoa;
|
||||
//}
|
||||
|
||||
//void Serializable::LoadBin(std::istream &is, const char *name)
|
||||
//{
|
||||
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_binary_iarchive(is);
|
||||
// Serializable::Load(*xia,this);
|
||||
// delete xia;
|
||||
//}
|
||||
|
||||
|
||||
//void Serializable::Save(boost::archive::polymorphic_oarchive &ar, Serializable *ob)
|
||||
//{
|
||||
// ar << boost::serialization::make_nvp("Object",ob);
|
||||
//}
|
||||
|
||||
//void Serializable::Load(boost::archive::polymorphic_iarchive &ar, Serializable *ob)
|
||||
//{
|
||||
// ar >> boost::serialization::make_nvp("Object",ob);
|
||||
//}
|
||||
|
||||
|
||||
412
src/Core/Serializable.h
Normal file
412
src/Core/Serializable.h
Normal file
@@ -0,0 +1,412 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_SERIALIZABLE_H
|
||||
#define U_SERIALIZABLE_H
|
||||
|
||||
/* Serialization:
|
||||
|
||||
|
||||
|
||||
TODO:
|
||||
* Problema nella serializzazione delle properties in test_archive
|
||||
* implementare human readable make_hrp ... non riesco..
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/remove_if.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
||||
//#include <boost/archive/xml_iarchive.hpp>
|
||||
//#include <boost/archive/xml_oarchive.hpp>
|
||||
//#include <boost/archive/text_iarchive.hpp>
|
||||
//#include <boost/archive/text_oarchive.hpp>
|
||||
//#include "boost/archive/polymorphic_iarchive.hpp"
|
||||
//#include "boost/archive/polymorphic_oarchive.hpp"
|
||||
|
||||
#include <boost/preprocessor/comma_if.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/inc.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/tuple/to_seq.hpp>
|
||||
|
||||
|
||||
#include "Core/Mpl.h"
|
||||
#include "Core/ObjectProps.h"
|
||||
#include "Core/Archives.h"
|
||||
#include "Core/Export.h"
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BOOST SERIALIZATION ADD-ON
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
// ACCESS 2 //
|
||||
template <class T> struct access2 {};
|
||||
|
||||
|
||||
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
|
||||
template<class T>
|
||||
class hrp :
|
||||
public wrapper_traits<const hrp< T > >
|
||||
{
|
||||
const char *m_name;
|
||||
T *m_value;
|
||||
std::string *m_str;
|
||||
|
||||
public:
|
||||
explicit hrp(const char * name_, T &t) :
|
||||
m_str(new std::string),
|
||||
m_name(name_), m_value(&t) {}
|
||||
|
||||
const char * name() const {
|
||||
return this->m_name;
|
||||
}
|
||||
|
||||
|
||||
template<class Archivex>
|
||||
void save( Archivex & ar, const unsigned int /* file_version */) const {
|
||||
//// ar.operator<<(const_value());
|
||||
// std::stringstream ss;
|
||||
// uLib::Archive::hrt_oarchive har(ss);
|
||||
// har << make_nvp(m_name,*m_value);
|
||||
// // (*m_str) = ss.str();
|
||||
//// ar.operator << (make_nvp(m_name, ss.str());
|
||||
}
|
||||
template<class Archivex>
|
||||
void load( Archivex & ar, const unsigned int /* file_version */) {
|
||||
// ar.operator>>(value());
|
||||
}
|
||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
const
|
||||
#endif
|
||||
hrp< T > make_hrp(const char * name, T & t){
|
||||
return hrp< T >(name, t);
|
||||
}
|
||||
|
||||
#define HRP(name) \
|
||||
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
|
||||
|
||||
|
||||
} // serialization
|
||||
} // boost
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ULIB SERIALIZATION
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
|
||||
|
||||
#define NVP(data) BOOST_SERIALIZATION_NVP(data)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SERIALIZTION MACROS //
|
||||
|
||||
// !!! WARNING !!! INTRUSIVE SERIALIZATION IS ACTUALLY NOT WORKING FEATURE
|
||||
// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED
|
||||
|
||||
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
|
||||
# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
|
||||
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
|
||||
# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
|
||||
#else
|
||||
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
|
||||
ULIB_CLASS_EXPORT_KEY(_Ob)
|
||||
# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
|
||||
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__)
|
||||
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
|
||||
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
|
||||
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
|
||||
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob)
|
||||
# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
|
||||
# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
|
||||
#endif
|
||||
|
||||
|
||||
#define ULIB_SERIALIZE_ACCESS \
|
||||
friend class boost::serialization::access; \
|
||||
template <class T> friend class boost::serialization::access2;
|
||||
|
||||
#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \
|
||||
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass)
|
||||
|
||||
#define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \
|
||||
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) \
|
||||
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass::ObjectProps) \
|
||||
BOOST_CLASS_EXPORT_KEY(uLib::ObjectPropsImpl<_FullNamespaceClass>)
|
||||
|
||||
|
||||
#define _SERIALIZE_IMPL_SEQ \
|
||||
(uLib::Archive::text_iarchive) \
|
||||
(uLib::Archive::text_oarchive) \
|
||||
(uLib::Archive::hrt_iarchive) \
|
||||
(uLib::Archive::hrt_oarchive) \
|
||||
(uLib::Archive::xml_iarchive) \
|
||||
(uLib::Archive::xml_oarchive) \
|
||||
(uLib::Archive::log_archive)
|
||||
|
||||
|
||||
/** Solving virtual class check problem */
|
||||
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; }
|
||||
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data)
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) //
|
||||
|
||||
#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name);
|
||||
|
||||
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
|
||||
template void Class::serialize(Archive &ar,const unsigned int);
|
||||
|
||||
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem);
|
||||
|
||||
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
|
||||
typedef boost::mpl::bool_<true> serializable; \
|
||||
typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \
|
||||
void PrintSerializableListId() { boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); } \
|
||||
template <class ArchiveT> void serialize(ArchiveT &ar,const unsigned int version); \
|
||||
template <class ArchiveT> void serialize_parents(ArchiveT &ar,const unsigned int version); \
|
||||
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version);
|
||||
|
||||
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
|
||||
template <class ArchiveT> void _Ob::serialize(ArchiveT &ar, const unsigned int version) { \
|
||||
boost::serialization::void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); \
|
||||
_Ob::serialize_parents(ar,version); \
|
||||
_Ob::save_override(ar,version); }\
|
||||
template <class ArchiveT> void _Ob::serialize_parents(ArchiveT &ar, const unsigned int v) { \
|
||||
BOOST_PP_SEQ_FOR_EACH(_AR_OP,ar,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); } \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||
namespace boost { \
|
||||
namespace serialization { \
|
||||
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \
|
||||
{ ::new(o)_Ob(); o->init_parameters(); } }}\
|
||||
template <class ArchiveT> void _Ob::save_override(ArchiveT &ar, const unsigned int version)
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// UNINTRUSIVE SERIALIZATION
|
||||
|
||||
#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object<elem>(ob));
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
|
||||
template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i);
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data,elem)
|
||||
|
||||
|
||||
// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
|
||||
// different implementation
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }}
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||
serialize_parents(ar,ob,version); \
|
||||
access2< _Ob >::save_override(ar,ob,version); } }}\
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,...) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
|
||||
BOOST_PP_IF(BOOST_PP_VARIADIC_SIZE((__VA_ARGS__)),BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__)));,) } \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||
serialize_parents(ar,ob,version); \
|
||||
access2< _Ob >::save_override (ar,ob,version); } }}\
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ) \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \
|
||||
template <class ArchiveT> void save_override (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); }}
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
|
||||
/* PP serialize */ BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); \
|
||||
/* MPL serialize */ /*uLib::mpl::for_each<_Ob::BaseList>(uLib::detail::Serializable::serialize_baseobject<_Ob,ArchiveT>(ob,ar) );*/ } \
|
||||
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *ob, const unsigned int file_version) { \
|
||||
::new(ob)_Ob(); uLib::detail::ObjectProps::initializer::init_object(ob); } \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||
void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); /*fix*/ \
|
||||
serialize_parents(ar,ob,version); \
|
||||
access2< _Ob >::save_override (ar,ob,version); } }}\
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) \
|
||||
namespace boost { namespace serialization { \
|
||||
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) { \
|
||||
save_override (ar,ob,version); } }}\
|
||||
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob::ObjectProps,_SERIALIZE_IMPL_SEQ)\
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob::ObjectProps) \
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(uLib::ObjectPropsImpl<_Ob>) \
|
||||
template <class ArchiveT> void boost::serialization::save_override(ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version)
|
||||
|
||||
|
||||
#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name),ob.name)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct Serializable {
|
||||
|
||||
/**
|
||||
* Serializable trait to check if an object type is serializable.
|
||||
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
|
||||
* cases a has_serialize trait should be implemented
|
||||
*/
|
||||
template <class T>
|
||||
struct serializable_trait : mpl::bool_<false> {};
|
||||
|
||||
/**
|
||||
* IsA Serializable Implementation Template
|
||||
*/
|
||||
template <class T>
|
||||
struct IsA : serializable_trait<T> {};
|
||||
|
||||
template <class ThisClass, class Archive>
|
||||
struct serialize_baseobject {
|
||||
ThisClass & m_object;
|
||||
Archive & m_ar;
|
||||
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
|
||||
template <class T> void operator()(T &o) {
|
||||
m_ar & boost::serialization::make_nvp(
|
||||
typeid(T).name() ,
|
||||
boost::serialization::base_object<T>(m_object));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Serializable {
|
||||
friend class boost::serialization::access;
|
||||
template <class T> friend class boost::serialization::access2;
|
||||
virtual ~Serializable() {}
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // U_SERIALIZABLE_H
|
||||
28
src/Core/Signal.cpp
Normal file
28
src/Core/Signal.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
168
src/Core/Signal.h
Normal file
168
src/Core/Signal.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_SIGNAL_H
|
||||
#define U_CORE_SIGNAL_H
|
||||
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <boost/signals2/slot.hpp>
|
||||
#include <boost/signals2/signal_type.hpp>
|
||||
|
||||
#include "Function.h"
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Signals macro //
|
||||
|
||||
#define default(vlaue)
|
||||
#define slots
|
||||
#define signals /*virtual void init_signals();*/ public
|
||||
#define emit
|
||||
#define SLOT(a) BOOST_STRINGIZE(a)
|
||||
#define SIGNAL(a) BOOST_STRINGIZE(a)
|
||||
|
||||
#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \
|
||||
static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \
|
||||
sig->operator()(__VA_ARGS__);
|
||||
|
||||
/**
|
||||
* Utility macro to implement signal emission implementa una delle seguenti:
|
||||
*
|
||||
* // metodo standard con cast //
|
||||
* SignalBase * sig = this->findSignal((void (Ob1::*)(void))&Ob1::V0);
|
||||
* typedef Signal<void()>::type SigT;
|
||||
* if(sig) reinterpret_cast<SigT*>(sig)->operator()();
|
||||
*
|
||||
* // cast automatico //
|
||||
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
|
||||
* sig->operator()();
|
||||
*/
|
||||
#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__)
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
// A boost::signal wrapper structure ///////////////////////////////////////////
|
||||
|
||||
// TODO ...
|
||||
|
||||
typedef boost::signals2::signal_base SignalBase;
|
||||
|
||||
template <typename T>
|
||||
struct Signal {
|
||||
typedef boost::signals2::signal<T> type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
||||
template <typename FuncT, int arity>
|
||||
struct ConnectSignal {};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 0 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(slof);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 1 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 2 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 3 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 4 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT>
|
||||
struct ConnectSignal< FuncT, 5 > {
|
||||
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
|
||||
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
template <typename FuncT>
|
||||
SignalBase *NewSignal(FuncT f) {
|
||||
// seems to work wow !
|
||||
return new Signal<void()>::type;
|
||||
}
|
||||
|
||||
template <typename FuncT>
|
||||
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver)
|
||||
{
|
||||
detail::ConnectSignal< FuncT, FunctionTypes<FuncT>::arity >::connect(sigb,slof,receiver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
#endif // SIGNAL_H
|
||||
46
src/Core/Singleton.h
Normal file
46
src/Core/Singleton.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_SINGLETON_H
|
||||
#define U_CORE_SINGLETON_H
|
||||
|
||||
#include <boost/serialization/singleton.hpp>
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
template <typename T>
|
||||
struct Singleton : boost::serialization::singleton<T> {
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // SINGLETON_H
|
||||
114
src/Core/SmartPointer.h
Normal file
114
src/Core/SmartPointer.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_SMARTPOINTER_H
|
||||
#define U_CORE_SMARTPOINTER_H
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class SmartPointerBase {};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class SmartPointer : SmartPointerBase {
|
||||
typedef T element_type;
|
||||
public:
|
||||
|
||||
explicit
|
||||
SmartPointer(T* ptr = NULL) : m_counter(0) {
|
||||
// if(!ptr) ptr = new T;
|
||||
if (ptr) m_counter = new ReferenceCounter(ptr); // ???
|
||||
}
|
||||
|
||||
// TakeReference //
|
||||
SmartPointer(T &ref) : m_counter(new ReferenceCounter(&ref,0)) { }
|
||||
|
||||
SmartPointer(const SmartPointer& copy) throw () {
|
||||
acquire(copy.m_counter);
|
||||
}
|
||||
|
||||
SmartPointer(SmartPointer * copy) throw () {
|
||||
acquire(copy->m_counter);
|
||||
}
|
||||
|
||||
virtual ~SmartPointer() { release(); }
|
||||
|
||||
SmartPointer & operator=(const SmartPointer& copy) {
|
||||
if (this != ©)
|
||||
{
|
||||
release();
|
||||
acquire(copy.m_counter);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
T & operator*() const throw () { return *m_counter->ptr; }
|
||||
T * operator->() const throw () { return m_counter->ptr; }
|
||||
|
||||
T * get() const throw () {
|
||||
return m_counter ? m_counter->ptr : 0; }
|
||||
bool unique() const throw () {
|
||||
return (m_counter ? m_counter->count == 1 : true); }
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct ReferenceCounter
|
||||
{
|
||||
ReferenceCounter(T* ptr = 0, unsigned c = 1) : ptr(ptr), count(c) { }
|
||||
T* ptr;
|
||||
unsigned count;
|
||||
} * m_counter;
|
||||
|
||||
// increment the count
|
||||
void acquire(ReferenceCounter* c) throw ()
|
||||
{
|
||||
m_counter = c;
|
||||
if (c && c->count>0) ++c->count;
|
||||
}
|
||||
|
||||
// decrement the count, delete if it is 0
|
||||
void release() {
|
||||
if (m_counter) {
|
||||
if (--m_counter->count == 0) {
|
||||
delete m_counter->ptr;
|
||||
}
|
||||
if (m_counter->count <= 0) {
|
||||
delete m_counter;
|
||||
m_counter = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // SMARTPOINTER_H
|
||||
77
src/Core/StaticInterface.h
Normal file
77
src/Core/StaticInterface.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_STATICINTERFACE_H
|
||||
#define U_CORE_STATICINTERFACE_H
|
||||
|
||||
namespace uLib {
|
||||
|
||||
#define MAKE_TRAITS ; // TODO
|
||||
|
||||
#define uLibCheckFunction(class_name,name,out, ... ) \
|
||||
{ out (class_name::*x)(__VA_ARGS__) = &class_name::name; (void) x; }
|
||||
|
||||
#define uLibCheckConstFunction(class_name,name,out,...) \
|
||||
{ out (class_name::*x)(__VA_ARGS__) const = &class_name::name; (void) x; }
|
||||
|
||||
#define uLibCheckMember(class_name,name,type) \
|
||||
{ class_name x; type *y = &x.name; (void) y; }
|
||||
|
||||
|
||||
namespace Interface {
|
||||
|
||||
// EXAMPLE :
|
||||
//template <class T> struct Voxel {
|
||||
// MAKE_TRAITS;
|
||||
// template<class Self> void check_structural() {
|
||||
// { float & (Self::*x)() = &Self::Density; (void) x; }
|
||||
// { int & (Self::*x)() = &Self::TrackCount; (void) x; }
|
||||
// }
|
||||
//protected:
|
||||
// ~Voxel() {}
|
||||
//};
|
||||
|
||||
template <class T, class SI>
|
||||
static inline void IsA() {
|
||||
(void) ((void (SI::*)()) &SI::template check_structural<T>);
|
||||
}
|
||||
|
||||
// not working
|
||||
//template <class T, class SI>
|
||||
//struct StaticIsA {
|
||||
// void test() {
|
||||
// static const void (SI::*x)() = SI::template check_structural<T>;
|
||||
// }
|
||||
//};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // STATICINTERFACE_H
|
||||
21
src/Core/String.h
Normal file
21
src/Core/String.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef U_CORE_STRING_H
|
||||
#define U_CORE_STRING_H
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
typedef std::string String;
|
||||
typedef std::wstring Stringw;
|
||||
|
||||
}
|
||||
|
||||
template < typename C >
|
||||
std::basic_string<C> & operator << (std::basic_string<C> &str, const C *c_str) {
|
||||
std::basic_stringstream<C> ss(c_str);
|
||||
str += ss.str();
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif // STRING_H
|
||||
94
src/Core/StringReader.h
Normal file
94
src/Core/StringReader.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_STRINGREADER_H
|
||||
#define U_CORE_STRINGREADER_H
|
||||
|
||||
#include <istream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Core/Vector.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
|
||||
// RIPENSARE COMPLETAMENTE !!!
|
||||
|
||||
namespace uLib {
|
||||
|
||||
struct StringReader {
|
||||
|
||||
std::istream & m_is;
|
||||
|
||||
StringReader(std::istream &is) : m_is(is) {}
|
||||
|
||||
void ReadString(const char *str) {
|
||||
// // clean compared string //
|
||||
// char chars[] = " \t\n";
|
||||
// for (unsigned int i = 0; i < strlen(chars); ++i)
|
||||
// { cmps.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); }
|
||||
|
||||
// SISTEMARE !!!
|
||||
|
||||
int pos = 0;
|
||||
char c;
|
||||
while( pos < strlen(str) ) {
|
||||
while( IsEscape(str[pos])) pos++;
|
||||
if ( pos >= strlen(str) ) break;
|
||||
while( IsEscape(c = m_is.get()) );
|
||||
if (c == str[pos] ) pos++;
|
||||
else pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool IsEscape(char c){
|
||||
const char *escapes = " \r\n\t";
|
||||
for ( int i = 0 ; i < 4 ; ++i) {
|
||||
if(c == escapes[i]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline StringReader & operator >> (StringReader &isr, T &t) {
|
||||
isr.m_is >> t;
|
||||
return isr;
|
||||
}
|
||||
|
||||
inline StringReader & operator >> (StringReader &isr, const char *str) {
|
||||
isr.ReadString(str);
|
||||
return isr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
#endif // STRINGREADER_H
|
||||
278
src/Core/Types.h
Normal file
278
src/Core/Types.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_TYPES_H
|
||||
#define U_CORE_TYPES_H
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <boost/preprocessor.hpp>
|
||||
|
||||
#include <ltk/ltktypes.h>
|
||||
|
||||
#include "Core/Macros.h"
|
||||
#include "Core/Mpl.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct TypeIntrospection {
|
||||
|
||||
// BOOST IMPL //
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
|
||||
|
||||
// SFINAE IMPL //
|
||||
/*
|
||||
template <typename T>
|
||||
struct has_type_info {
|
||||
typedef char yes[1];
|
||||
typedef char no[2];
|
||||
template <typename U> static yes& test(typename U::type_info::BaseList*);
|
||||
template <typename > static no& test(...);
|
||||
// struct apply {
|
||||
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
|
||||
typedef boost::mpl::bool_<value> type;
|
||||
// };
|
||||
};
|
||||
*/
|
||||
|
||||
/** IsA Introspectable Object Implementation Template */
|
||||
template <class T>
|
||||
struct IsIntrospectable : has_type_info<T> {};
|
||||
|
||||
template <typename T> struct access {
|
||||
typedef typename T::type_info type_info;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct child_first_impl {
|
||||
|
||||
template <class T1, bool cond>
|
||||
struct lambda_CFList_f {
|
||||
typedef mpl::vector<T1> type;
|
||||
};
|
||||
|
||||
template <class T1>
|
||||
struct lambda_CFList_f<T1,true> {
|
||||
// typedef typename T1::type_info::CFList type;
|
||||
typedef typename access<T1>::type_info::CFList type;
|
||||
};
|
||||
|
||||
template <class T1>
|
||||
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
|
||||
|
||||
/** Transforms all Base Type into proper CFList */
|
||||
typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
|
||||
, lambda_CFList<mpl::_>
|
||||
>::type CFListSeq;
|
||||
|
||||
/** Folds each CFList into a new sequence */
|
||||
typedef typename mpl::fold< CFListSeq
|
||||
, mpl::vector<>
|
||||
, mpl::copy< mpl::_1
|
||||
, mpl::back_inserter<mpl::_2>
|
||||
>
|
||||
>::type Childs;
|
||||
|
||||
/** Add This Class to final CFList sequence */
|
||||
typedef typename mpl::copy< Childs
|
||||
, mpl::back_inserter< mpl::vector<T> >
|
||||
>::type type;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Tests if T has a member called type_info then compile type CFList
|
||||
*/
|
||||
template <typename T>
|
||||
struct child_first : mpl::if_< has_type_info<T>
|
||||
, child_first_impl<T>
|
||||
, mpl::vector<>
|
||||
>::type {};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TYPE ADAPTERS // FINIRE !!!
|
||||
|
||||
//#define _REPETITION_V(vz,vn,vdata)
|
||||
|
||||
|
||||
//template < class TypeList >
|
||||
//class TypeAdapterInputInterface {
|
||||
// virtual ~TypeAdapterInputInterface() {}
|
||||
//public:
|
||||
|
||||
|
||||
|
||||
// virtual void operator()(int val) {}
|
||||
// virtual void operator()(std::string val) {}
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // detail ////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#define CONSTEXPR BOOST_CONSTEXPR
|
||||
|
||||
|
||||
typedef ltk::Real_t Real_t;
|
||||
typedef ltk::Id_t Id_t;
|
||||
typedef ltk::Size_t Size_t;
|
||||
typedef ltk::Pointer_t Pointer_t;
|
||||
typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
|
||||
|
||||
//--- bit manipulation ---------------------------------------------------------
|
||||
#ifndef BIT
|
||||
#define BIT(n) (1ULL << (n))
|
||||
#endif
|
||||
|
||||
#ifndef SETBIT
|
||||
#define SETBIT(n,i) ((n) |= BIT(i))
|
||||
#endif
|
||||
|
||||
#ifndef CLRBIT
|
||||
#define CLRBIT(n,i) ((n) &= ~BIT(i))
|
||||
#endif
|
||||
|
||||
#ifndef TESTBIT
|
||||
#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TYPE INTROSPECTION FOR OBJECTS //
|
||||
|
||||
|
||||
|
||||
#define uLibTypeMacro(thisClass,...) \
|
||||
\
|
||||
/* Friendship detail for accessing introspection */ \
|
||||
template <typename> friend class uLib::detail::TypeIntrospection::access; \
|
||||
\
|
||||
/* type info structure*/ public: \
|
||||
/* in GCC 4.8 must be public or dynamic_cast wont work */ \
|
||||
struct type_info { \
|
||||
/*WARNING: -std=c++0x required for this! */ \
|
||||
constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
|
||||
typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \
|
||||
typedef thisClass ThisClass; \
|
||||
typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \
|
||||
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
|
||||
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
|
||||
}; \
|
||||
\
|
||||
public: \
|
||||
typedef type_info::BaseClass BaseClass; \
|
||||
virtual const char *type_name() const { return type_info::name; } \
|
||||
/* Object Props fwd declaration*/ \
|
||||
struct ObjectProps; \
|
||||
/**/
|
||||
|
||||
|
||||
/**
|
||||
* TypeList inheritance introspection
|
||||
*/
|
||||
struct TypeIntrospection {
|
||||
template <typename T>
|
||||
struct child_first : detail::TypeIntrospection::child_first<T> {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// SISTEMARE //
|
||||
struct PrintTypeId {
|
||||
template <class T>
|
||||
void operator()(T) const
|
||||
{ std::cout << typeid(T).name() << std::endl; }
|
||||
|
||||
template <typename SeqT>
|
||||
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
|
||||
|
||||
template <typename Class>
|
||||
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ACCESS //
|
||||
struct Access {};
|
||||
template <class T> struct Access2 {};
|
||||
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
#endif // U_CORE_TYPES_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
45
src/Core/Uuid.cpp
Normal file
45
src/Core/Uuid.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include "Uuid.h"
|
||||
#include "Singleton.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
uLib::uuid_t uLib::uLib_dns_uuid;
|
||||
TypeRegister* TypeRegister::s_Instance = new TypeRegister();
|
||||
|
||||
TypeRegister::TypeRegister() :
|
||||
BaseClass(uLib_dns_uuid)
|
||||
{}
|
||||
|
||||
TypeRegister * TypeRegister::Controller() {
|
||||
return TypeRegister::s_Instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
163
src/Core/Uuid.h
Normal file
163
src/Core/Uuid.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_UUID_H
|
||||
#define U_CORE_UUID_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/name_generator.hpp>
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
#include "Core/Mpl.h"
|
||||
#include "Core/Vector.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Object Registration //
|
||||
|
||||
|
||||
typedef boost::uuids::uuid uuid_t;
|
||||
|
||||
extern uuid_t uLib_dns_uuid;
|
||||
|
||||
template < typename T >
|
||||
class type_id : public boost::uuids::uuid {
|
||||
public:
|
||||
type_id() :
|
||||
m_size(sizeof(T)),
|
||||
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name()))
|
||||
{
|
||||
std::cout << "Request for register new type\n" <<
|
||||
"name: " << typeid(T).name() << "\n" <<
|
||||
"uuid: " << to_string(*this) << "\n";
|
||||
}
|
||||
|
||||
explicit type_id(boost::uuids::uuid const& u)
|
||||
: boost::uuids::uuid(u) {}
|
||||
|
||||
operator boost::uuids::uuid() {
|
||||
return static_cast<boost::uuids::uuid&>(*this);
|
||||
}
|
||||
|
||||
operator boost::uuids::uuid() const {
|
||||
return static_cast<boost::uuids::uuid const&>(*this);
|
||||
}
|
||||
|
||||
unsigned int size() const { return m_size; }
|
||||
|
||||
private:
|
||||
unsigned int m_size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TYPE REGISTER //
|
||||
|
||||
namespace detail {
|
||||
|
||||
class TypeRegister {
|
||||
typedef boost::uuids::name_generator IDGen_t;
|
||||
public:
|
||||
struct RegisterEntry {
|
||||
uuid_t id;
|
||||
int size;
|
||||
};
|
||||
|
||||
TypeRegister(uuid_t const &dns) :
|
||||
gen(dns) {}
|
||||
|
||||
|
||||
template< typename T >
|
||||
RegisterEntry * AddType(T *t = NULL) {
|
||||
RegisterEntry en = { gen(typeid(T).name()), sizeof(T) };
|
||||
for(int i=0; i < m_registry.size(); ++i)
|
||||
if(en.id == m_registry[i].id) return &(m_registry[i]);
|
||||
m_registry.push_back(en);
|
||||
return &m_registry.back();
|
||||
}
|
||||
|
||||
void PrintSelf(std::ostream &o) {
|
||||
std::cout << "RegisterController: \n";
|
||||
for (int i=0; i<m_registry.size(); ++i)
|
||||
o << "type [" << i << "]: "
|
||||
<< to_string(m_registry[i].id) << " "
|
||||
<< m_registry[i].size << "\n";
|
||||
o << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
IDGen_t gen;
|
||||
Vector<RegisterEntry> m_registry;
|
||||
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
|
||||
class TypeRegister : public detail::TypeRegister {
|
||||
public:
|
||||
typedef detail::TypeRegister BaseClass;
|
||||
typedef detail::TypeRegister::RegisterEntry Entry;
|
||||
|
||||
static TypeRegister* Controller();
|
||||
|
||||
private:
|
||||
TypeRegister(); // Blocks constructor
|
||||
static TypeRegister *s_Instance; // Singleton instance
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// OBJECT REGISTER //
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
#endif // UUID_H
|
||||
195
src/Core/Vector.h
Normal file
195
src/Core/Vector.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_VECTOR_H
|
||||
#define U_CORE_VECTOR_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <Core/Macros.h>
|
||||
#include <Core/SmartPointer.h>
|
||||
#include <Core/CommaInitializer.h>
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
// Vector Implemetation ... wraps std::vector
|
||||
template <typename T>
|
||||
class Vector : public std::vector<T, std::allocator<T> >
|
||||
{
|
||||
typedef std::vector< T,std::allocator<T> > BaseClass;
|
||||
typedef std::allocator<T> Allocator;
|
||||
public:
|
||||
typedef T TypeData;
|
||||
typedef __gnu_cxx::__normal_iterator<T*, BaseClass > Iterator;
|
||||
typedef __gnu_cxx::__normal_iterator<const T*, BaseClass> ConstIterator;
|
||||
|
||||
typedef CommaInitializer< Vector<T> , T > VectorCommaInit;
|
||||
|
||||
Vector(unsigned int size) : BaseClass(size) {}
|
||||
Vector(unsigned int size, T &value) : BaseClass(size,value) {}
|
||||
Vector() : BaseClass(0) {}
|
||||
|
||||
inline VectorCommaInit operator <<(T scalar) {
|
||||
return VectorCommaInit(this, scalar);
|
||||
}
|
||||
|
||||
inline void PrintSelf(std::ostream &o);
|
||||
|
||||
void remove_element(unsigned int index) {
|
||||
std::swap(this->at(index),this->back());
|
||||
this->pop_back();
|
||||
}
|
||||
|
||||
void remove_element(T &t) {
|
||||
std::swap(t, this->back());
|
||||
this->pop_back();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void Vector<T>::PrintSelf(std::ostream &o)
|
||||
{
|
||||
o << " *** uLib Vector *** \n";
|
||||
o << " n. of items = " << this->size() << "\n";
|
||||
for(int i=0; i< this->size(); ++i)
|
||||
o << (T)this->at(i) << " ";
|
||||
o << "\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream &operator << (std::ostream &o, const Vector<T> &v) {
|
||||
for(int i=0; i< v.size(); ++i)
|
||||
o << (T)v.at(i) << " ";
|
||||
o << "\n";
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ofstream &operator << (std::ofstream &o, const Vector<T> &v) {
|
||||
for(int i=0; i< v.size(); ++i)
|
||||
o << (T)v.at(i) << " ";
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
// MATH OPERATIONS //
|
||||
|
||||
#define ULIB_CONTAINER_MATHOP(container,op) \
|
||||
template < typename T1, typename T2 > \
|
||||
inline container<T1> & operator op##= (container<T1> &src, const T2 data) { \
|
||||
foreach (T1 &el, src) { \
|
||||
el op##= static_cast<T1>(data); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
template < typename T1, typename T2 > \
|
||||
inline container<T1> operator op (const container<T1> &src, const T2 data) { \
|
||||
container<T1> out(src); \
|
||||
out op##= data; \
|
||||
return out; \
|
||||
} \
|
||||
//
|
||||
ULIB_CONTAINER_MATHOP(Vector,+)
|
||||
ULIB_CONTAINER_MATHOP(Vector,-)
|
||||
ULIB_CONTAINER_MATHOP(Vector,*)
|
||||
ULIB_CONTAINER_MATHOP(Vector,/)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Smart pointer Vector Implementation //
|
||||
|
||||
|
||||
template <typename T>
|
||||
class SmartVector : public SmartPointer< Vector<T> > {
|
||||
typedef SmartPointer< Vector<T> > Base;
|
||||
public:
|
||||
|
||||
SmartVector() : Base(NULL) { }
|
||||
// SmartVector() : Base(new Vector<T>()) { }
|
||||
SmartVector( const SmartVector ©) : Base(copy) { }
|
||||
SmartVector(unsigned int size) : Base(new Vector<T>((int)size)) { }
|
||||
|
||||
virtual ~SmartVector() {}
|
||||
|
||||
T& operator[](int p) {
|
||||
return Base::get()->at(p);
|
||||
}
|
||||
|
||||
void swap_elements(unsigned int first, unsigned int second) {
|
||||
std::swap(Base::get()->at(first),Base::get()->at(second));
|
||||
}
|
||||
|
||||
void remove_element(unsigned int index) {
|
||||
std::swap(Base::get()->at(index),Base::get()->back());
|
||||
Base::get()->pop_back();
|
||||
}
|
||||
|
||||
void remove_element(T &t) {
|
||||
std::swap(t, Base::get()->back());
|
||||
Base::get()->pop_back();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// ------ Utils ------------------------------------------------------------- //
|
||||
|
||||
|
||||
|
||||
// RIFARE con iteratore !
|
||||
template <typename _Tp, class _CmpT>
|
||||
inline const unsigned long
|
||||
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
|
||||
{
|
||||
_Tp it = _it;
|
||||
_Tp end = _end-1;
|
||||
for(it; it != end;)
|
||||
{
|
||||
if (_comp(*it,value)) ++it;
|
||||
else if(_comp(*end,value)) std::swap(*it,*end--);
|
||||
else --end;
|
||||
}
|
||||
return it - _it;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // VECTOR_H
|
||||
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <Core/Object.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/accumulators/accumulators.hpp>
|
||||
#include <boost/accumulators/statistics/stats.hpp>
|
||||
#include <boost/accumulators/statistics/mean.hpp>
|
||||
#include <boost/accumulators/statistics/moment.hpp>
|
||||
#include <boost/accumulators/statistics/density.hpp>
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace boost::accumulators;
|
||||
|
||||
using namespace boost;
|
||||
using namespace boost::accumulators;
|
||||
|
||||
typedef accumulator_set<double, features<tag::density> > acc;
|
||||
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
|
||||
|
||||
template <typename T>
|
||||
class data_filler
|
||||
{
|
||||
public:
|
||||
data_filler(){}
|
||||
T operator()() { return rand()/(T)RAND_MAX; }
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
//create some random data
|
||||
std::vector<double> data(100);
|
||||
std::generate(data.begin(), data.end(), data_filler<double>());
|
||||
int c = data.size();//cache size for histogramm.
|
||||
|
||||
//create an accumulator
|
||||
acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);
|
||||
|
||||
//fill accumulator
|
||||
for (int j = 0; j < c; ++j)
|
||||
{
|
||||
myAccumulator(data[j]);
|
||||
}
|
||||
|
||||
histogram_type hist = density(myAccumulator);
|
||||
|
||||
double total = 0.0;
|
||||
|
||||
for( int i = 0; i < hist.size(); i++ )
|
||||
{
|
||||
std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl;
|
||||
total += hist[i].second;
|
||||
}
|
||||
|
||||
std::cout << "Total: " << total << std::endl; //should be 1 (and it is)
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
src/Core/testing/BoostTest.cpp
Normal file
64
src/Core/testing/BoostTest.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Options.h"
|
||||
|
||||
#include "Core/Singleton.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
struct A : Object {
|
||||
A() : a(0) {}
|
||||
int a;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BEGIN_TESTING(Boost Mock);
|
||||
|
||||
A &a = Singleton<A>::get_mutable_instance();
|
||||
a.a = 5552368;
|
||||
|
||||
const A &aa = Singleton<A>::get_const_instance();
|
||||
|
||||
std::cout << a.a << "\n";
|
||||
std::cout << aa.a << "\n";
|
||||
|
||||
TEST1( a.a == 5552368 );
|
||||
TEST1( aa.a == 5552368 );
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
34
src/Core/testing/CMakeLists.txt
Normal file
34
src/Core/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
# TESTS
|
||||
set( TESTS
|
||||
SmartVectorTest
|
||||
VectorTest
|
||||
ObjectFlagsTest
|
||||
ObjectParametersTest
|
||||
ObjectCopyTest
|
||||
StaticInterfaceTest
|
||||
CommaInitTest
|
||||
DebugTTreeDumpTest
|
||||
BoostTest
|
||||
BoostAccumulatorTest
|
||||
PropertiesTest
|
||||
FunctionTest
|
||||
SignalTest
|
||||
SerializeTest
|
||||
SerializeDreadDiamondTest
|
||||
DreadDiamondParameters
|
||||
ObjectPropableTest
|
||||
UuidTest
|
||||
TypeIntrospectionTraversal
|
||||
OptionsTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
${PACKAGE_LIBPREFIX}Core
|
||||
${PACKAGE_LIBPREFIX}Math
|
||||
${Boost_SERIALIZATION_LIBRARY}
|
||||
${Boost_SIGNALS_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${ROOT_LIBRARIES}
|
||||
)
|
||||
uLib_add_tests(${uLib-module})
|
||||
57
src/Core/testing/CommaInitTest.cpp
Executable file
57
src/Core/testing/CommaInitTest.cpp
Executable file
@@ -0,0 +1,57 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Vector.h"
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
#define test_print(file,str,...) \
|
||||
printf(str,__VA_ARGS__)
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING( Comma Init );
|
||||
|
||||
Vector<int> test;
|
||||
|
||||
test << 1,2,3,4,5;
|
||||
|
||||
test.PrintSelf(std::cout);
|
||||
|
||||
|
||||
test_print(stdout,"ciao %d \n",5);
|
||||
|
||||
printf("ciao\n");
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Debug.h"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/include/sequence.hpp>
|
||||
|
||||
#include <boost/fusion/container.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/push_back.hpp>
|
||||
#include <boost/fusion/include/push_back.hpp>
|
||||
|
||||
|
||||
#include <Rtypes.h>
|
||||
#include <TFile.h>
|
||||
#include <TObject.h>
|
||||
#include <TTree.h>
|
||||
#include <TApplication.h>
|
||||
#include <TBrowser.h>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
class DebugAdapterTTree : public detail::DebugAdapterInterface {
|
||||
TTree *m_tree;
|
||||
public:
|
||||
|
||||
DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {}
|
||||
~DebugAdapterTTree() { delete m_tree; }
|
||||
|
||||
void operator()(int val) {
|
||||
std::cout << "debugger 2 prints: " << val << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
{
|
||||
Debug debug;
|
||||
DebugAdapterText adapter(std::cout);
|
||||
DebugAdapterTTree treead("test");
|
||||
|
||||
debug.AddAdapter(adapter);
|
||||
debug.AddAdapter(treead);
|
||||
|
||||
int a = 5552368;
|
||||
debug("a",a);
|
||||
|
||||
std::string str = "ciao";
|
||||
debug("str",str);
|
||||
|
||||
debug.Update();
|
||||
}
|
||||
|
||||
|
||||
// TestTObject *test = new TestTObject;
|
||||
|
||||
|
||||
TFile *file = new TFile("test_file.root","RECREATE");
|
||||
file->cd();
|
||||
TTree *tree = new TTree;
|
||||
// tree->Branch("test",&test);
|
||||
|
||||
// for(int i=0;i<10;++i) {
|
||||
// test->a = i;
|
||||
// test->b = -i;
|
||||
// tree->Fill();
|
||||
// }
|
||||
tree->Write();
|
||||
|
||||
gApplication = new TApplication("My ROOT Application", &argc, argv);
|
||||
TBrowser *tbr = new TBrowser("test");
|
||||
tbr->Show();
|
||||
|
||||
|
||||
gApplication->Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
#include "boost/archive/xml_oarchive.hpp"
|
||||
#include "boost/archive/xml_iarchive.hpp"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Core/Mpl.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
76
src/Core/testing/Flags.h
Normal file
76
src/Core/testing/Flags.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_FLAGS_H
|
||||
#define U_CORE_FLAGS_H
|
||||
|
||||
namespace uLib {
|
||||
|
||||
template<typename T> class Flags
|
||||
{
|
||||
T i;
|
||||
public:
|
||||
typedef T EnumT;
|
||||
|
||||
inline Flags(const Flags &f) : i(f.i) {}
|
||||
inline Flags() : i((T)0) {}
|
||||
inline Flags(T f) : i(f) {}
|
||||
|
||||
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
|
||||
inline Flags &operator&=(T mask) { i &= mask; return *this; }
|
||||
|
||||
inline Flags &operator|=(const Flags f) { i |= f.i; return *this; }
|
||||
inline Flags &operator|=(const T f) { i |= f; return *this; }
|
||||
inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; }
|
||||
inline Flags &operator^=(const T f) { i ^= f; return *this; }
|
||||
|
||||
inline Flags operator|(const Flags f) const { return Flags(i | f.i); }
|
||||
inline Flags operator|(const T f) const { return Flags(i | f); }
|
||||
inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); }
|
||||
inline Flags operator^(const T f) const { return Flags(i ^ f); }
|
||||
inline Flags operator&(const Flags f) const { return Flags(i & f.i); }
|
||||
inline Flags operator&(const T f) const { return Flags(i & f); }
|
||||
inline Flags operator~() const { return Flags(~i); }
|
||||
|
||||
inline bool operator !() const { return !i; }
|
||||
inline bool testFlag(const T f) const
|
||||
{ return (i & f) == f && (f != 0 || i == f ); }
|
||||
// inline bool operator==(const T f) const { return i==f; }
|
||||
|
||||
inline T operator()() { return i; }
|
||||
inline operator T() const { return i; }
|
||||
};
|
||||
|
||||
|
||||
typedef Flags<unsigned short> Flags2B;
|
||||
typedef Flags<unsigned int> Flags4B;
|
||||
typedef Flags<unsigned long> Flags8B;
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
#endif // FLAGS_H
|
||||
57
src/Core/testing/FunctionTest.cpp
Normal file
57
src/Core/testing/FunctionTest.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include <functional>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Types.h"
|
||||
|
||||
#include <Core/Vector.h>
|
||||
#include <Core/ProgrammableAccessor.h>
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class TestVoxel {
|
||||
public:
|
||||
float m_data;
|
||||
float Get() { return m_data; }
|
||||
float ConstGet() const { return m_data; }
|
||||
float & GetRef() { return m_data; }
|
||||
const float & ConstGetRef() const { return m_data; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // uLib
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(Function Test);
|
||||
|
||||
|
||||
Vector<TestVoxel> v;
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
v.push_back(TestVoxel());
|
||||
|
||||
|
||||
v[5].m_data = 5552368.0;
|
||||
|
||||
ProgrammableAccessor<float> f1(&TestVoxel::m_data);
|
||||
ProgrammableAccessor<float> f2(&TestVoxel::GetRef);
|
||||
|
||||
int i=0;
|
||||
foreach (TestVoxel &el,v) {
|
||||
f1.Set(&el,i++);
|
||||
std::cout << " -> " << f2.Get<double>(&el) << "\n";
|
||||
}
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
38
src/Core/testing/Makefile.am
Normal file
38
src/Core/testing/Makefile.am
Normal file
@@ -0,0 +1,38 @@
|
||||
include $(top_srcdir)/Common.am
|
||||
|
||||
#AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
# if HAVE_CHECK
|
||||
TESTS = SmartPointerTest \
|
||||
SmartVectorTest \
|
||||
VectorTest \
|
||||
ObjectFlagsTest \
|
||||
ObjectParametersTest \
|
||||
ObjectCopyTest \
|
||||
StaticInterfaceTest \
|
||||
CommaInitTest \
|
||||
DebugTTreeDumpTest \
|
||||
BoostTest \
|
||||
BoostAccumulatorTest \
|
||||
PropertiesTest \
|
||||
SignalTest \
|
||||
SerializeTest \
|
||||
SerializeDreadDiamondTest \
|
||||
DreadDiamondParameters \
|
||||
ObjectPropableTest \
|
||||
TypeIntrospectionTraversal \
|
||||
OptionsTest
|
||||
|
||||
# UuidTest
|
||||
|
||||
# else
|
||||
# TEST =
|
||||
# endif
|
||||
|
||||
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(ObjectParameters);
|
||||
|
||||
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
//class Derived : public uLib::Object {
|
||||
//public:
|
||||
// Derived(int flags) : uLib::Object(flags) {}
|
||||
// enum Flags {
|
||||
// a = 1<<0, // 1
|
||||
// b = 1<<1, // 2
|
||||
// c = 1<<2 // 4
|
||||
// };
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(ObjectFlags);
|
||||
|
||||
// Object o(2);
|
||||
// o.flags() = 4;
|
||||
// o.flags() |= 1;
|
||||
// TEST1( o.flags() == 5);
|
||||
// o.flags() &= 1;
|
||||
// TEST1( o.flags() == 1);
|
||||
// TEST1( o.flags().testFlag(1) );
|
||||
|
||||
// Derived d( Derived::a | Derived::b);
|
||||
// d.flags() = Derived::c;
|
||||
// d.flags() |= Derived::a;
|
||||
// TEST1( d.flags() == Derived::a | Derived::c);
|
||||
// d.flags() &= 1;
|
||||
// TEST1( d.flags() == Derived::a);
|
||||
// TEST1( d.flags().testFlag(Derived::a) );
|
||||
|
||||
END_TESTING
|
||||
}
|
||||
11
src/Core/testing/ObjectMock/Makefile.am
Normal file
11
src/Core/testing/ObjectMock/Makefile.am
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
include $(top_srcdir)/Common.am
|
||||
|
||||
#AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
|
||||
LDADD = $(top_srcdir)/libmutom-0.1.la $(AM_LIBS_BOOST)
|
||||
|
||||
bin_PROGRAMS = ObjectMock
|
||||
ObjectMock_SOURCES = main.cpp Ob.cpp Ob1.cpp Ob2.cpp
|
||||
|
||||
59
src/Core/testing/ObjectMock/Ob.cpp
Normal file
59
src/Core/testing/ObjectMock/Ob.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Ob.h"
|
||||
|
||||
|
||||
|
||||
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob) // use this in cpp file
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class ObPrivate {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Ob::Ob() :
|
||||
m_p(NULL),
|
||||
m_s(NULL),
|
||||
m_type_id(0),
|
||||
d(new ObPrivate)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
181
src/Core/testing/ObjectMock/Ob.h
Normal file
181
src/Core/testing/ObjectMock/Ob.h
Normal file
@@ -0,0 +1,181 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef OB_H
|
||||
#define OB_H
|
||||
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
#include <Core/Object.h>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Core/Vector.h"
|
||||
#include "Core/Uuid.h"
|
||||
|
||||
#include "boost/typeof/typeof.hpp"
|
||||
#include <boost/serialization/binary_object.hpp>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/name_generator.hpp>
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
|
||||
#include <boost/serialization/extended_type_info_typeid.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Mock of serializable object system //
|
||||
|
||||
#define default(vlaue)
|
||||
#define slots
|
||||
#define signals public
|
||||
#define emit
|
||||
# define SLOT(a) a
|
||||
# define SIGNAL(a) a
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// OB ///////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Ob {
|
||||
|
||||
public:
|
||||
|
||||
Ob();
|
||||
~Ob() {
|
||||
if(m_p) delete m_p;
|
||||
}
|
||||
|
||||
//// init //////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
void init(){
|
||||
if(!m_type_id) {
|
||||
m_p = (Parameters *) new typename T::Parameters;
|
||||
m_type_id = TypeRegister::Controller()->AddType< T >();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void PrintSelf(std::ostream &o) const { o << "Base Object PrintSelf\n"; }
|
||||
|
||||
protected:
|
||||
// parameters //////////////////////////////////////////////////////////////
|
||||
struct Parameters { friend class boost::serialization::access; };
|
||||
inline Parameters &p() { assert(m_p); return *m_p; }
|
||||
inline const Parameters &p() const { assert(m_p); return *m_p; }
|
||||
virtual void init() {}
|
||||
|
||||
|
||||
// serialization access ////////////////////////////////////////////////////
|
||||
friend class boost::serialization::access;
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
// ar & boost::serialization::make_nvp("instance_size", m_type_id->size);
|
||||
// ar & boost::serialization::make_nvp("instance_data",boost::serialization::make_binary_object(this,m_type_id->size));
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
static void serialize(Archive &ar, Ob &ob, const unsigned int version) {}
|
||||
|
||||
template <class Archive>
|
||||
static void serialize(Archive &ar, Ob::Parameters &p, const unsigned int version) {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
TypeRegister::Entry * type_id() const { return m_type_id; }
|
||||
|
||||
private:
|
||||
|
||||
// members /////////////////////////////////////////////////////////////////
|
||||
struct Parameters *m_p;
|
||||
struct Signals *m_s;
|
||||
|
||||
friend class ObPrivate;
|
||||
class ObPrivate *d;
|
||||
|
||||
TypeRegister::Entry * m_type_id;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(uLib::Ob)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
80
src/Core/testing/ObjectMock/Ob1.cpp
Normal file
80
src/Core/testing/ObjectMock/Ob1.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Ob1.h"
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// created by moc // -------------------------------------------------------- //
|
||||
|
||||
|
||||
void Ob1::init()
|
||||
{
|
||||
Ob::init<Ob1>();
|
||||
boost::serialization::void_cast_register<Ob1,BaseClass>();
|
||||
BaseClass::init();
|
||||
// default parameters value //
|
||||
p().a = 1;
|
||||
p().b = 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//// serialization accessor that can be made by moc //
|
||||
|
||||
//template <class Archive>
|
||||
//void Ob1::serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version)
|
||||
//{
|
||||
// Ob1::BaseClass::serialize<Archive>( ar,p,version );
|
||||
// ar & boost::serialization::make_nvp("a",p.a);
|
||||
// ar & boost::serialization::make_nvp("b",p.b);
|
||||
//}
|
||||
|
||||
//template <class Archive>
|
||||
//void Ob1::serialize(Archive &ar, Ob1 &ob, const unsigned int version )
|
||||
//{
|
||||
// Ob1::BaseClass::serialize<Archive>(ar,ob,version);
|
||||
// // other members to be serialized //
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob1) // use this in cpp file
|
||||
|
||||
122
src/Core/testing/ObjectMock/Ob1.h
Normal file
122
src/Core/testing/ObjectMock/Ob1.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef OB1_H
|
||||
#define OB1_H
|
||||
|
||||
#include <string>
|
||||
#include "Ob.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// OB1 ///////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class Ob1 : public Ob {
|
||||
public:
|
||||
|
||||
typedef Ob BaseClass;
|
||||
struct Parameters : public BaseClass::Parameters {
|
||||
int a default(1);
|
||||
int b default(2);
|
||||
};
|
||||
virtual ~Ob1() {}
|
||||
|
||||
// created by macro ////////////////////////////////////////////////////////
|
||||
void init();
|
||||
inline Parameters &p() { return (Parameters &)Ob::p(); }
|
||||
inline const Parameters &p() const { return (Parameters &)Ob::p(); }
|
||||
static Ob1 *New() { Ob1 *o = new Ob1; o->init(); return o; }
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, const unsigned int version);
|
||||
|
||||
template <class Archive>
|
||||
static void serialize(Archive & ar,
|
||||
Ob1::Parameters & p,
|
||||
const unsigned int version );
|
||||
|
||||
template <class Archive>
|
||||
static void serialize(Archive &ar,
|
||||
Ob1 &ob,
|
||||
const unsigned int version );
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void PrintSelf(std::ostream &o) const { o << "Object Ob1 PrintSelf\n"; }
|
||||
|
||||
|
||||
};
|
||||
|
||||
// serialize accessors in macro // ------------------------------------------ //
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version )
|
||||
{
|
||||
Ob1::serialize<Archive>(ar,p,version);
|
||||
}
|
||||
|
||||
|
||||
template<class Archive>
|
||||
void Ob1::serialize(Archive & ar, const unsigned int version)
|
||||
{
|
||||
ar & boost::serialization::make_nvp("parameters",p());
|
||||
this->serialize<Archive>(ar,*this,version);
|
||||
Ob::serialize(ar,version);
|
||||
}
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
// serialization accessor that can be made by moc //
|
||||
|
||||
template <class Archive>
|
||||
void Ob1::serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version)
|
||||
{
|
||||
Ob1::BaseClass::serialize<Archive>( ar,p,version );
|
||||
ar & boost::serialization::make_nvp("a",p.a);
|
||||
ar & boost::serialization::make_nvp("b",p.b);
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void Ob1::serialize(Archive &ar, Ob1 &ob, const unsigned int version )
|
||||
{
|
||||
Ob1::BaseClass::serialize<Archive>(ar,ob,version);
|
||||
// other members to be serialized //
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(uLib::Ob1) // use this in header
|
||||
|
||||
|
||||
#endif
|
||||
73
src/Core/testing/ObjectMock/Ob2.cpp
Normal file
73
src/Core/testing/ObjectMock/Ob2.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Ob2.h"
|
||||
|
||||
namespace uLib {
|
||||
|
||||
|
||||
// created by moc // -------------------------------------------------------- //
|
||||
|
||||
|
||||
|
||||
|
||||
void Ob2::init()
|
||||
{
|
||||
Ob::init<Ob2>();
|
||||
boost::serialization::void_cast_register<Ob2,BaseClass>();
|
||||
BaseClass::init();
|
||||
p().c = 3;
|
||||
p().d = 4;
|
||||
}
|
||||
|
||||
//template <class Archive>
|
||||
//void Ob2::serialize(Archive &ar, Parameters &p, const unsigned int version)
|
||||
//{
|
||||
// Ob2::BaseClass::serialize<Archive>( ar,p,version );
|
||||
// ar & boost::serialization::make_nvp("c",p.c);
|
||||
// ar & boost::serialization::make_nvp("d",p.d);
|
||||
//}
|
||||
|
||||
//template <class Archive>
|
||||
//void Ob2::serialize(Archive &ar, Ob2 &o, const unsigned int version )
|
||||
//{
|
||||
// Ob2::BaseClass::serialize<Archive>(ar,o,version);
|
||||
// ar & boost::serialization::make_nvp("serializzable_member",o.serializzable_member);
|
||||
// // other members //
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob2) // use this in cpp file
|
||||
135
src/Core/testing/ObjectMock/Ob2.h
Normal file
135
src/Core/testing/ObjectMock/Ob2.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef OB2_H
|
||||
#define OB2_H
|
||||
|
||||
|
||||
#include "Ob.h"
|
||||
#include "Ob1.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// OB2 ///////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class Ob2 : public Ob1 {
|
||||
public:
|
||||
typedef Ob1 BaseClass;
|
||||
|
||||
struct Parameters : public BaseClass::Parameters {
|
||||
int c default(3),d default(4);
|
||||
};
|
||||
|
||||
Ob2() {
|
||||
serializzable_member = 0;
|
||||
memset(non_serializable_member,0,sizeof(char[250]));
|
||||
}
|
||||
|
||||
virtual ~Ob2() {}
|
||||
|
||||
// created by macro ////////////////////////////////////////////
|
||||
void init();
|
||||
inline Parameters &p() { return (Parameters &)Ob::p(); }
|
||||
inline const Parameters &p() const { return (Parameters &)Ob::p(); }
|
||||
static Ob2 *New() { Ob2 *o = new Ob2; o->init(); return o; }
|
||||
|
||||
friend class boost::serialization::access;
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, const unsigned int version);
|
||||
template <class Archive>
|
||||
static void serialize(Archive & ar, Parameters & p, const unsigned int version );
|
||||
template <class Archive>
|
||||
static void serialize(Archive &ar, Ob2 &o, const unsigned int version );
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void PrintSelf(std::ostream &o) const { o << "Object Ob2 PrintSelf\n"; }
|
||||
|
||||
int serializzable_member;
|
||||
char non_serializable_member[250];
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, Ob2::Parameters &p, const unsigned int version )
|
||||
{
|
||||
Ob2::serialize<Archive>(ar,p,version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Archive>
|
||||
void Ob2::serialize(Archive & ar, const unsigned int version)
|
||||
{
|
||||
// boost::serialization::split_member(ar, *this, version);
|
||||
ar & boost::serialization::make_nvp("parameters",p());
|
||||
this->serialize<Archive>(ar,*this,version);
|
||||
Ob::serialize(ar,version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class Archive>
|
||||
void Ob2::serialize(Archive &ar, Parameters &p, const unsigned int version)
|
||||
{
|
||||
Ob2::BaseClass::serialize<Archive>( ar,p,version );
|
||||
ar & boost::serialization::make_nvp("c",p.c);
|
||||
ar & boost::serialization::make_nvp("d",p.d);
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void Ob2::serialize(Archive &ar, Ob2 &o, const unsigned int version )
|
||||
{
|
||||
Ob2::BaseClass::serialize<Archive>(ar,o,version);
|
||||
ar & boost::serialization::make_nvp("serializzable_member",o.serializzable_member);
|
||||
// other members //
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(uLib::Ob2) // use this in header
|
||||
//BOOST_SERIALIZATION_FACTORY_0(uLib::Ob2) // use this for plugin construction
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
174
src/Core/testing/ObjectMock/main.cpp
Normal file
174
src/Core/testing/ObjectMock/main.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
|
||||
|
||||
#include "Ob.h"
|
||||
#include "Ob1.h"
|
||||
#include "Ob2.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//// test boost ETI system //
|
||||
|
||||
// used in external plugin construction mechanism //
|
||||
int test_boost_eti () {
|
||||
|
||||
boost::serialization::extended_type_info_typeid<Ob2> i_eti;
|
||||
|
||||
std::cout << "int eti guid key: " << i_eti.get_key() << "\n";
|
||||
|
||||
Ob2 *test = (Ob2*)i_eti.construct(0);
|
||||
test->init();
|
||||
|
||||
std::cout << "int eti typeid name: " << i_eti.get_typeid().name() << "\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// main //
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
// ////////////////////////////////////////////////////
|
||||
// // serialization tests
|
||||
{
|
||||
Ob1 ob1;
|
||||
ob1.init();
|
||||
std::cout << "ob1 param: " <<
|
||||
ob1.p().a << " " <<
|
||||
ob1.p().b << "\n";
|
||||
|
||||
|
||||
|
||||
Ob2 *ob2 = Ob2::New();
|
||||
std::cout << "ob2 param: " <<
|
||||
ob2->p().a << " " <<
|
||||
ob2->p().b << " " <<
|
||||
ob2->p().c << " " <<
|
||||
ob2->p().d << "\n";
|
||||
std::cout << "ob2 uuid: " <<
|
||||
to_string(ob2->type_id()->id) << "\n";
|
||||
|
||||
|
||||
// // serialize ob2 to file //
|
||||
// {
|
||||
// std::ofstream ofs("_BoostTest.xml");
|
||||
// boost::archive::xml_oarchive oa(ofs);
|
||||
// oa << BOOST_SERIALIZATION_NVP(ob2);
|
||||
// }
|
||||
|
||||
// serialize ob2 to file via objact base cast //
|
||||
{
|
||||
Ob *ob = Ob2::New();
|
||||
sprintf(static_cast<Ob2 *>(ob)->non_serializable_member,
|
||||
"deserializzati dati interni attraverso dump binario");
|
||||
std::ofstream ofs("_BoostTest.xml");
|
||||
boost::archive::xml_oarchive oa(ofs);
|
||||
oa << BOOST_SERIALIZATION_NVP(ob);
|
||||
}
|
||||
|
||||
|
||||
// delete ob2;
|
||||
|
||||
// deserialize ob2 from file //
|
||||
{
|
||||
Ob2 *newob2 = Ob2::New();
|
||||
newob2->p().c = 0;
|
||||
std::ifstream ifs("_BoostTest.xml");
|
||||
boost::archive::xml_iarchive ia(ifs);
|
||||
ia >> BOOST_SERIALIZATION_NVP(*newob2);
|
||||
printf("%s\n",newob2->non_serializable_member);
|
||||
std::cout << "deserialized ob2: > " <<
|
||||
newob2->p().a << " " <<
|
||||
newob2->p().b << " " <<
|
||||
newob2->p().c << " " <<
|
||||
newob2->p().d << "\n";
|
||||
std::cout << "deserialized ob2 member: " <<
|
||||
"serializable_member = " << newob2->serializzable_member << "\n";
|
||||
std::cout << "deserialized ob2 uuid: " <<
|
||||
to_string(newob2->type_id()->id) << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
37
src/Core/testing/ObjectMock/testing-prototype.h
Normal file
37
src/Core/testing/ObjectMock/testing-prototype.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BEGIN_TESTING(name) \
|
||||
static int _fail = 0; \
|
||||
printf("..:: Testing " #name " ::..\n");
|
||||
|
||||
#define TEST1(val) _fail += (val)==0
|
||||
#define TEST0(val) _fail += (val)!=0
|
||||
#define END_TESTING return _fail;
|
||||
|
||||
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
#include "boost/archive/xml_oarchive.hpp"
|
||||
#include "boost/archive/xml_iarchive.hpp"
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Core/ObjectProps.h"
|
||||
#include "Core/StringReader.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "boost/archive/text_oarchive.hpp"
|
||||
#include "boost/archive/text_iarchive.hpp"
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// STRUCTURES //
|
||||
|
||||
|
||||
struct A : virtual Object {
|
||||
|
||||
uLibTypeMacro(A, Object)
|
||||
|
||||
properties() {
|
||||
int p_a;
|
||||
Vector3f p_3f;
|
||||
};
|
||||
|
||||
int m_a;
|
||||
};
|
||||
|
||||
void A::init_properties() {
|
||||
$_init();
|
||||
$$.p_a = 0;
|
||||
$$.p_3f << 1,2,3;
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(A)
|
||||
ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); }
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); }
|
||||
|
||||
|
||||
|
||||
|
||||
struct B : A {
|
||||
uLibTypeMacro(B,A)
|
||||
|
||||
properties() {
|
||||
std::string p;
|
||||
};
|
||||
|
||||
B() : m_b(324) {}
|
||||
|
||||
int m_b;
|
||||
};
|
||||
|
||||
|
||||
void B::init_properties() {
|
||||
$_init();
|
||||
$$.p = "ciao";
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(B)
|
||||
ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); }
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); }
|
||||
|
||||
|
||||
|
||||
struct C {
|
||||
int m_c;
|
||||
std::string m_str;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE(C)
|
||||
ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); }
|
||||
|
||||
|
||||
|
||||
struct D : virtual Object, B {
|
||||
uLibTypeMacro(D,Object,B)
|
||||
|
||||
properties() {
|
||||
C p_c;
|
||||
};
|
||||
};
|
||||
|
||||
void D::init_properties() {
|
||||
$_init();
|
||||
$$.p_c.m_c = 1234;
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(D)
|
||||
ULIB_SERIALIZE_OBJECT(D,Object) {}
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(D) {
|
||||
ar & AR(p_c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class E : public C, public D {
|
||||
uLibTypeMacro(E,D,C)
|
||||
public:
|
||||
E() : m_Ea(5552368) {}
|
||||
int m_Ea;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(E)
|
||||
ULIB_SERIALIZE_OBJECT(E,C,D) {
|
||||
ar & AR(m_Ea);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TESTS //
|
||||
|
||||
|
||||
int test_xml_direct() {
|
||||
// TEST ARCHIVE SAVE AND LOAD direct //
|
||||
E o; o.init_properties();
|
||||
o.$$.p_c.m_str = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::xml_oarchive ar(file);
|
||||
ar << NVP(o);
|
||||
}
|
||||
o.$$.p_c.m_str = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Archive::xml_iarchive ar(file);
|
||||
ar >> NVP(o);
|
||||
}
|
||||
std::cout << o.$$.p_c.m_str << "\n";
|
||||
return ( o.$$.p_c.m_str == "works" );
|
||||
}
|
||||
|
||||
|
||||
int test_xml_pointer() {
|
||||
// TEST ARCHIVE SAVE AND LOAD from pointer //
|
||||
E *o = new E; o->init_properties();
|
||||
o->$$.p_c.m_str = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::xml_oarchive ar(file);
|
||||
ar << NVP(o);
|
||||
}
|
||||
o->$$.p_c.m_str = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Archive::xml_iarchive ar(file);
|
||||
ar >> NVP(o);
|
||||
}
|
||||
std::cout << o->$$.p_c.m_str << "\n";
|
||||
return ( o->$$.p_c.m_str == "works" );
|
||||
}
|
||||
|
||||
|
||||
int test_xml_objsave() {
|
||||
// TEST SELF SAVE
|
||||
E o; o.init_properties();
|
||||
o.$(B).p = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Object::SaveXml(file,o);
|
||||
}
|
||||
o.$(B).p = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Object::LoadXml(file,o);
|
||||
}
|
||||
|
||||
std::cout << o.$(B).p << "\n";
|
||||
return ( o.$(B).p == "works" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MAIN //
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(PropableTest);
|
||||
|
||||
TEST1( test_xml_direct() );
|
||||
TEST1( test_xml_pointer() );
|
||||
TEST1( test_xml_objsave() );
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
72
src/Core/testing/OptionsTest.cpp
Normal file
72
src/Core/testing/OptionsTest.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Options.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BEGIN_TESTING(Boost ProgramOptions);
|
||||
|
||||
|
||||
std::string optfile("configuration.ini");
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
Options opt;
|
||||
|
||||
opt.add_options()
|
||||
("help", "printout help")
|
||||
("value",&a,"value")
|
||||
("config",&optfile,"config_file");
|
||||
|
||||
opt.add_config_options()
|
||||
("B.value",&b,"b vlaue");
|
||||
|
||||
opt.parse_command_line(argc,argv);
|
||||
opt.parse_config_file(optfile.c_str());
|
||||
|
||||
std::cout << "a = " << a << "\n";
|
||||
std::cout << "b = " << b << "\n";
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
96
src/Core/testing/PropertiesTest.cpp
Normal file
96
src/Core/testing/PropertiesTest.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#define emit
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T, bool copyable = true>
|
||||
class property
|
||||
{
|
||||
typedef boost::signals2::signal<void(const property<T>& )> signal_t;
|
||||
|
||||
public:
|
||||
property() : m_changed(new signal_t) {}
|
||||
property(const T in) : value(in) , m_changed(new signal_t) {}
|
||||
|
||||
inline operator T const & () const { return value; }
|
||||
inline operator T & () { return value; }
|
||||
inline T & operator = (const T &i) { value = i; return value; }
|
||||
template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||
inline signal_t & valueChanged() { return *m_changed; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
boost::shared_ptr<signal_t> m_changed;
|
||||
};
|
||||
|
||||
|
||||
//template <typename T>
|
||||
//class property <T,false> {
|
||||
// typedef boost::signals2::signal<void( T )> signal_t;
|
||||
|
||||
//public:
|
||||
// property() : m_changed() {}
|
||||
// property(const T in) : value(in) , m_changed() {}
|
||||
|
||||
// inline operator T const & () const { return value; }
|
||||
// inline operator T & () { valueChanged()(value); return value; }
|
||||
// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; }
|
||||
// template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||
// inline signal_t &valueChanged() { return m_changed; }
|
||||
|
||||
//private:
|
||||
// property(const property<T> &);
|
||||
// property<T> &operator = (const property<T>&);
|
||||
|
||||
// T value;
|
||||
// signal_t m_changed;
|
||||
//};
|
||||
|
||||
// test generic void function slot //
|
||||
void PrintSlot(const property<int> &i) { std::cout << "slot called, new value = " << i << "!\n"; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
#include "Core/Object.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct A : Object {
|
||||
uLibTypeMacro(A,Object)
|
||||
A() : numa(5552368) {}
|
||||
int numa;
|
||||
};
|
||||
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(A)
|
||||
ULIB_SERIALIZE_OBJECT(A,Object) {
|
||||
ar & AR(numa);
|
||||
}
|
||||
|
||||
struct B : virtual Object {
|
||||
uLibTypeMacro(B,Object)
|
||||
B() : numb(5552369) {}
|
||||
int numb;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(B)
|
||||
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); }
|
||||
|
||||
|
||||
struct C : B {
|
||||
uLibTypeMacro(C,B)
|
||||
C() : numc(5552370) {}
|
||||
int numc;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(C)
|
||||
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
|
||||
|
||||
struct D : A,B {
|
||||
uLibTypeMacro(D,A,B)
|
||||
|
||||
D() : numd(5552371) {}
|
||||
int numd;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(D)
|
||||
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); }
|
||||
|
||||
|
||||
|
||||
main() {
|
||||
A o; o.init_properties();
|
||||
|
||||
Archive::xml_oarchive(std::cout) << NVP(o);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13
src/Core/testing/SerializeMock/Makefile.am
Normal file
13
src/Core/testing/SerializeMock/Makefile.am
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
include $(top_srcdir)/Common.am
|
||||
#AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
|
||||
LDADD = $(top_srcdir)/libmutom-0.1.la $(AM_LIBS_BOOST)
|
||||
|
||||
|
||||
|
||||
bin_PROGRAMS = SerializeMock
|
||||
SerializeMock_SOURCES = main.cpp Ob.cpp Ob1.cpp
|
||||
#log_archive.cpp
|
||||
|
||||
103
src/Core/testing/SerializeMock/Ob.cpp
Normal file
103
src/Core/testing/SerializeMock/Ob.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// polymorphic_base.cpp
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
//#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
//#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
//#include <boost/archive/xml_oarchive.hpp>
|
||||
//#include <boost/archive/xml_iarchive.hpp>
|
||||
|
||||
#include "Ob.h"
|
||||
|
||||
|
||||
//// A /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Archive>
|
||||
void A::serialize(Archive &ar, unsigned int v) {
|
||||
ar & BOOST_SERIALIZATION_NVP(i);
|
||||
}
|
||||
|
||||
//_SERIALIZE_IMPL(A,boost::archive::polymorphic_oarchive)
|
||||
SERILIZE_IMPL(A)
|
||||
|
||||
void A::Save(boost::archive::polymorphic_oarchive &ar)
|
||||
{ ar << boost::serialization::make_nvp(boost::serialization::guid<A>(),this); }
|
||||
|
||||
// note: only the most derived classes need be exported
|
||||
// BOOST_CLASS_EXPORT(A)
|
||||
|
||||
|
||||
|
||||
|
||||
//// B /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Ar>
|
||||
void B::serialize(Ar &ar, unsigned int v) {
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
|
||||
}
|
||||
|
||||
SERILIZE_IMPL(B)
|
||||
|
||||
void B::Save(boost::archive::polymorphic_oarchive &ar)
|
||||
{ ar << boost::serialization::make_nvp(boost::serialization::guid<B>(),this); }
|
||||
|
||||
_SPECIALIZE_IS_VIRTUAL_BASE(A,B)
|
||||
BOOST_CLASS_EXPORT_IMPLEMENT(B)
|
||||
|
||||
|
||||
|
||||
|
||||
//// C /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Ar>
|
||||
void C::serialize(Ar &ar, unsigned int v) {
|
||||
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
|
||||
}
|
||||
|
||||
SERILIZE_IMPL(C)
|
||||
|
||||
void C::Save(boost::archive::polymorphic_oarchive &ar)
|
||||
{ ar << boost::serialization::make_nvp(boost::serialization::guid<C>(),this); }
|
||||
|
||||
_SPECIALIZE_IS_VIRTUAL_BASE(A,C)
|
||||
BOOST_CLASS_EXPORT_IMPLEMENT(C)
|
||||
|
||||
|
||||
|
||||
|
||||
112
src/Core/testing/SerializeMock/Ob.h
Normal file
112
src/Core/testing/SerializeMock/Ob.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef OB_H
|
||||
#define OB_H
|
||||
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_polymorphic2.hpp
|
||||
|
||||
// (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <ostream>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#include <boost/preprocessor/seq.hpp>
|
||||
|
||||
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
|
||||
|
||||
|
||||
#define _SERIALIZE_IMPL_SEQ \
|
||||
(boost::archive::polymorphic_iarchive) \
|
||||
(boost::archive::polymorphic_oarchive) \
|
||||
(boost::archive::xml_iarchive) \
|
||||
(boost::archive::xml_oarchive)
|
||||
|
||||
#define _SERIALIZE_IMPL(Class,Archive) \
|
||||
template void Class::serialize(Archive &ar,const unsigned int);
|
||||
|
||||
#define _SERIALIZE_IMPL_OP(r,data,elem) _SERIALIZE_IMPL(data,elem)
|
||||
|
||||
#define SERILIZE_IMPL(Class) BOOST_PP_SEQ_FOR_EACH(_SERIALIZE_IMPL_OP,Class,_SERIALIZE_IMPL_SEQ)
|
||||
|
||||
#define _SPECIALIZE_IS_VIRTUAL_BASE(Base,Derived) namespace boost{ template<> struct is_virtual_base_of<Base,Derived>: public boost::mpl::true_ {}; }
|
||||
#define _SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _SPECIALIZE_IS_VIRTUAL_BASE(data,elem)
|
||||
|
||||
|
||||
|
||||
|
||||
// should pass compilation and execution
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
class polymorphic_oarchive;
|
||||
class polymorphic_iarchive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct A {
|
||||
virtual ~A() {}
|
||||
|
||||
template <class Archive> void serialize(Archive &ar, unsigned int v);
|
||||
virtual void Save(boost::archive::polymorphic_oarchive &ar);
|
||||
|
||||
int i;
|
||||
};
|
||||
|
||||
|
||||
struct B : virtual A {
|
||||
|
||||
template <class Ar> void serialize(Ar &ar, unsigned int v);
|
||||
virtual void Save(boost::archive::polymorphic_oarchive &ar);
|
||||
|
||||
};
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(B)
|
||||
|
||||
struct C : virtual A {
|
||||
|
||||
template <class Ar> void serialize(Ar &ar, unsigned int v);
|
||||
virtual void Save(boost::archive::polymorphic_oarchive &ar);
|
||||
};
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(C)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user