From d56758d0b3b6a3f99551598a1d3cb9bd0e416856 Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Sat, 21 Feb 2026 16:16:28 +0000 Subject: [PATCH] refactor: Update CMake build system and streamline Core object serialization and property handling. --- CMake/uLibTargetMacros.cmake | 2 +- CMakeLists.txt | 3 +- src/Core/Archives.h | 861 ++++++++---------- src/Core/CMakeLists.txt | 13 +- src/Core/Export.h | 96 +- src/Core/Object.cpp | 2 + src/Core/Object.h | 5 +- src/Core/Signal.h | 148 +-- src/Core/testing/CMakeLists.txt | 7 +- .../testing/SerializeDreadDiamondTest.cpp | 80 +- src/Core/testing/SerializeTest.cpp | 192 ++-- src/Core/testing/StaticInterfaceTest.cpp | 85 +- src/Detectors/CMakeLists.txt | 5 + src/Detectors/testing/CMakeLists.txt | 23 +- src/Math/CMakeLists.txt | 7 +- src/Math/testing/AccumulatorTest.cpp | 120 +-- src/Math/testing/CMakeLists.txt | 2 + src/Math/testing/TriangleMeshTest.cpp | 25 +- src/Math/testing/VoxRaytracerTest.cpp | 185 ++-- src/Root/CMakeLists.txt | 5 +- src/Root/testing/CMakeLists.txt | 7 +- src/Vtk/CMakeLists.txt | 4 + src/Vtk/testing/CMakeLists.txt | 4 +- src/utils/make_recipe/src/CMakeLists.txt | 5 +- 24 files changed, 830 insertions(+), 1056 deletions(-) diff --git a/CMake/uLibTargetMacros.cmake b/CMake/uLibTargetMacros.cmake index b0f1655..886a382 100644 --- a/CMake/uLibTargetMacros.cmake +++ b/CMake/uLibTargetMacros.cmake @@ -82,7 +82,7 @@ ENDMACRO(uLib_add_target) # TESTS and LIBRARIES must be defined macro(uLib_add_tests name) foreach(tn ${TESTS}) - add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp) + add_executable(${tn} ${tn}.cpp) add_test(NAME ${tn} COMMAND ${tn}) target_link_libraries(${tn} ${LIBRARIES}) diff --git a/CMakeLists.txt b/CMakeLists.txt index aeb4459..08bc6a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_WARNING_OPTION}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UULIB_SERIALIZATION_ON -Wno-cpp") # CTEST framework +include(CTest) enable_testing() @@ -85,7 +86,7 @@ set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) message(STATUS "CMAKE_PREFIX_PATH is ${CMAKE_PREFIX_PATH}") -find_package(Boost 1.45.0 COMPONENTS program_options REQUIRED) +find_package(Boost 1.45.0 COMPONENTS program_options serialization unit_test_framework REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) find_package(Eigen3 CONFIG REQUIRED) diff --git a/src/Core/Archives.h b/src/Core/Archives.h index d9f9071..1a71072 100644 --- a/src/Core/Archives.h +++ b/src/Core/Archives.h @@ -23,14 +23,12 @@ //////////////////////////////////////////////////////////////////////////////*/ - - #ifndef U_CORE_ARCHIVES_H #define U_CORE_ARCHIVES_H - #include #include +#include #include #include @@ -40,25 +38,20 @@ #include -#include -#include #include #include +#include +#include #include #include "StringReader.h" - - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // FWD DECLARATIONS OF ARCHIVES // - - - namespace uLib { namespace Archive { @@ -68,40 +61,36 @@ class text_iarchive; class text_oarchive; class log_archive; - -} -} - +} // namespace Archive +} // namespace uLib namespace boost { namespace archive { namespace detail { -template class polymorphic_oarchive_route; -template class polymorphic_iarchive_route; -} -} -} +template class polymorphic_oarchive_route; +template class polymorphic_iarchive_route; +} // namespace detail +} // namespace archive +} // namespace boost namespace boost { namespace serialization { - template struct hrp; +template struct hrp; } -} - +} // namespace boost //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // ARCHIVES REGISTRATION // - namespace uLib { namespace Archive { namespace detail { struct adl_tag {}; -} -} -} +} // namespace detail +} // namespace Archive +} // namespace uLib namespace boost { namespace archive { @@ -110,34 +99,36 @@ namespace detail { // in overload resolution with the functions declared by // BOOST_SERIALIZATION_REGISTER_ARCHIVE, below. template -void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {} -} -} -} +void instantiate_ptr_serialization(Serializable *, int, + uLib::Archive::detail::adl_tag) {} +} // namespace detail +} // namespace archive +} // namespace boost // 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 \ -BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \ -instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}} - - - - - +#define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \ + namespace boost { \ + namespace archive { \ + namespace detail { \ + \ + template \ + 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 { @@ -145,176 +136,134 @@ namespace detail { /** * Custom implementation of boost interface_iarchive to add new operators */ -template -class uLib_interface_iarchive -{ +template class uLib_interface_iarchive { protected: - uLib_interface_iarchive(){}; + uLib_interface_iarchive() {}; + public: - ///////////////////////////////////////////////////////// - // archive public interface - typedef mpl::bool_ is_loading; - typedef mpl::bool_ is_saving; + ///////////////////////////////////////////////////////// + // archive public interface + typedef mpl::bool_ is_loading; + typedef mpl::bool_ is_saving; - // return a pointer to the most derived class - Archive * This(){ - return static_cast(this); - } + // return a pointer to the most derived class + Archive *This() { return static_cast(this); } - template - const basic_pointer_iserializer * - register_type(T * = NULL){ - const basic_pointer_iserializer & bpis = - boost::serialization::singleton< - pointer_iserializer - >::get_const_instance(); - this->This()->register_basic_serializer(bpis.get_basic_serializer()); - return & bpis; - } - template - Archive & operator>>(T & t){ - this->This()->load_override(t, 0); - return * this->This(); - } + template + const basic_pointer_iserializer *register_type(T * = NULL) { + const basic_pointer_iserializer &bpis = boost::serialization::singleton< + pointer_iserializer>::get_const_instance(); + this->This()->register_basic_serializer(bpis.get_basic_serializer()); + return &bpis; + } + template Archive &operator>>(T &t) { + this->This()->load_override(t); + return *this->This(); + } - // the & operator - template - Archive & operator&(T & t){ - return *(this->This()) >> t; - } + // the & operator + template Archive &operator&(T &t) { return *(this->This()) >> t; } - // the == operator - template - Archive & operator == (T & t) { - return this->operator &(t); - } + // the == operator + template Archive &operator==(T &t) { return this->operator&(t); } - // the != operator for human readable access - template - Archive & operator != (T & t) { - std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! - return * this->This(); - } + // the != operator for human readable access + template 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 uLib_interface_oarchive { +template class uLib_interface_oarchive { protected: - uLib_interface_oarchive(){}; + uLib_interface_oarchive() {}; + public: - ///////////////////////////////////////////////////////// - // archive public interface - typedef mpl::bool_ is_loading; - typedef mpl::bool_ is_saving; + ///////////////////////////////////////////////////////// + // archive public interface + typedef mpl::bool_ is_loading; + typedef mpl::bool_ is_saving; - // return a pointer to the most derived class - Archive * This(){ - return static_cast(this); - } + // return a pointer to the most derived class + Archive *This() { return static_cast(this); } - template - const basic_pointer_oserializer * - register_type(const T * = NULL){ - const basic_pointer_oserializer & bpos = - boost::serialization::singleton< - pointer_oserializer - >::get_const_instance(); - this->This()->register_basic_serializer(bpos.get_basic_serializer()); - return & bpos; - } + template + const basic_pointer_oserializer *register_type(const T * = NULL) { + const basic_pointer_oserializer &bpos = boost::serialization::singleton< + pointer_oserializer>::get_const_instance(); + this->This()->register_basic_serializer(bpos.get_basic_serializer()); + return &bpos; + } - template - 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(); - } + template 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); + return *this->This(); + } - // the & operator - template - Archive & operator&(T & t){ - #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - return * this->This() << const_cast(t); - #else - return * this->This() << t; - #endif - } + // the & operator + template Archive &operator&(T &t) { +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + return *this->This() << const_cast(t); +#else + return *this->This() << t; +#endif + } - // the == operator - template - Archive & operator == (T & t) { - return this->operator &(t); - } + // the == operator + template Archive &operator==(T &t) { return this->operator&(t); } - // the != operator for human readable access - template - Archive & operator != (T & t) { - std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! - return * this->This(); - } + // the != operator for human readable access + template 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 : public - uLib_interface_iarchive {}; +class interface_iarchive + : public uLib_interface_iarchive {}; template <> -class interface_oarchive : public - uLib_interface_oarchive {}; +class interface_oarchive + : public uLib_interface_oarchive {}; template <> -class interface_iarchive : public - uLib_interface_iarchive {}; +class interface_iarchive + : public uLib_interface_iarchive {}; template <> -class interface_oarchive : public - uLib_interface_oarchive {}; +class interface_oarchive + : public uLib_interface_oarchive {}; template <> -class interface_oarchive : public - uLib_interface_oarchive {}; - +class interface_oarchive + : public uLib_interface_oarchive {}; //// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!! -//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \ -// template \ -// struct inherit_nofold : \ -// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \ -// {}; +// #define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \ +// template \ +// struct inherit_nofold : \ +// 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 - - - - - - - - - - +// BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~) +// #undef _INERIT_NOFOLD_H +// #undef _INERIT_NOFOLD_V +} // namespace detail +} // namespace archive +} // namespace boost //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -330,196 +279,174 @@ class interface_oarchive : public namespace boost { namespace archive { -//template -//inline void load_const_override(Archive & ar, const char *t ){ -// typedef typename mpl::identity >::type typex; -// typex::invoke(ar, t); -//} - -//template -//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, -// mpl::identity > -// ,//else -// BOOST_DEDUCED_TYPENAME mpl::eval_if, -// mpl::identity > -// ,//else -// BOOST_DEDUCED_TYPENAME mpl::eval_if, -// mpl::identity > -// ,//else -// mpl::identity > -// > -// > -// >::type typex; -// typex::invoke(ar, t); -//} - - - -} -} - +// template +// inline void load_const_override(Archive & ar, const char *t ){ +// typedef typename mpl::identity +// >::type typex; typex::invoke(ar, t); +// } +// template +// 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, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// mpl::identity > +// > +// > +// >::type typex; +// typex::invoke(ar, t); +// } +} // namespace archive +} // namespace boost namespace uLib { namespace Archive { - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // POLYMORPHIC // +// class polymorphic_iarchive : +// public boost::archive::polymorphic_iarchive { -//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(t)); -// } +// public: +// void load_override(const char *t, BOOST_PFTO int) +// { +// boost::archive::load_const_override(* this->This(), +// const_cast(t)); +// } //}; - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // XML // -class xml_iarchive : - public boost::archive::xml_iarchive_impl -{ - typedef xml_iarchive Archive; - typedef boost::archive::xml_iarchive_impl base; +class xml_iarchive : public boost::archive::xml_iarchive_impl { + typedef xml_iarchive Archive; + typedef boost::archive::xml_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_xml_iarchive; + friend class boost::archive::load_access; - // give serialization implementation access to this class - friend class boost::archive::detail::interface_iarchive; - friend class boost::archive::basic_xml_iarchive; - friend class boost::archive::load_access; public: - xml_iarchive(std::istream & is, unsigned int flags = 0) : - xml_iarchive_impl(is, flags) - {} + xml_iarchive(std::istream &is, unsigned int flags = 0) + : xml_iarchive_impl(is, flags) {} - using basic_xml_iarchive::load_override; + 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 detail_common_iarchive; - template - 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()); - } + // Anything not an attribute should be a name value pair as nvp or hrp + typedef boost::archive::detail::common_iarchive + detail_common_iarchive; + template + void load_override( +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + const +#endif + boost::serialization::hrp &t) { + this->This()->load_start(t.name()); + this->detail_common_iarchive::load_override(t.value()); + // 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; - // 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) { + // StringReader sr(basic_text_iprimitive::is); + // sr >> str; + } - void load_override(const char *str, int v) { - // StringReader sr(basic_text_iprimitive::is); - // sr >> str; - } - - ~xml_iarchive(){}; + ~xml_iarchive() {}; }; -//typedef boost::archive::detail::polymorphic_iarchive_route< -//boost::archive::xml_iarchive_impl +// typedef boost::archive::detail::polymorphic_iarchive_route< +// boost::archive::xml_iarchive_impl //> polymorphic_xml_iarchive; template -struct polymorphic_iarchive_route : - boost::archive::detail::polymorphic_iarchive_route -{ - virtual void load(const char * t){ - ArchiveImpl::load(t); - } +struct polymorphic_iarchive_route + : boost::archive::detail::polymorphic_iarchive_route { + virtual void load(const char *t) { ArchiveImpl::load(t); } }; - -class polymorphic_xml_iarchive : - public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl > -{ - // give serialization implementation access to this class -// friend class boost::archive::detail::interface_iarchive; -// friend class boost::archive::basic_xml_iarchive; -// friend class boost::archive::load_access; +class polymorphic_xml_iarchive + : public polymorphic_iarchive_route< + boost::archive::xml_iarchive_impl> { + // give serialization implementation access to this class + // friend class boost::archive::detail::interface_iarchive; + // friend class boost::archive::basic_xml_iarchive; + // friend class boost::archive::load_access; public: - virtual void load_override(const char *str, int v) { - ; - } + virtual void load_override(const char *str) { ; } }; +class xml_oarchive : public boost::archive::xml_oarchive_impl { + typedef xml_oarchive Archive; + typedef boost::archive::xml_oarchive_impl base; + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_xml_oarchive; + friend class boost::archive::save_access; -class xml_oarchive : - public boost::archive::xml_oarchive_impl -{ - typedef xml_oarchive Archive; - typedef boost::archive::xml_oarchive_impl base; - - // give serialization implementation access to this class - friend class boost::archive::detail::interface_oarchive; - friend class boost::archive::basic_xml_oarchive; - friend class boost::archive::save_access; public: - xml_oarchive(std::ostream & os, unsigned int flags = 0) : - boost::archive::xml_oarchive_impl(os, flags) - {} + xml_oarchive(std::ostream &os, unsigned int flags = 0) + : boost::archive::xml_oarchive_impl(os, flags) {} - // example of implementing save_override for const char* // - // void save_override(const char *t, int) { - // std::cout << "found char: " << t << "\n"; - // } + // 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; + using basic_xml_oarchive::save_override; - // special treatment for name-value pairs. - typedef boost::archive::detail::common_oarchive detail_common_oarchive; - template - 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()); - } + // special treatment for name-value pairs. + typedef boost::archive::detail::common_oarchive + detail_common_oarchive; + template + void save_override( +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + const +#endif + ::boost::serialization::hrp &t) { + this->This()->save_start(t.name()); + // t.vtos(); + // this->detail_common_oarchive::save_override(t.const_value()); + 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); - } + void save_override(const char *str) { + // Do not save any human decoration string // + // basic_text_oprimitive::save(str); + } - ~xml_oarchive(){} + ~xml_oarchive() {} }; -//typedef boost::archive::detail::polymorphic_oarchive_route< -//boost::archive::xml_oarchive_impl +// typedef boost::archive::detail::polymorphic_oarchive_route< +// boost::archive::xml_oarchive_impl //> polymorphic_xml_oarchive; //////////////////////////////////////////////////////////////////////////////// @@ -527,157 +454,137 @@ public: //////////////////////////////////////////////////////////////////////////////// // TEXT // -class text_iarchive : - public boost::archive::text_iarchive_impl -{ - typedef text_iarchive Archive; - typedef boost::archive::text_iarchive_impl base; +class text_iarchive : public boost::archive::text_iarchive_impl { + typedef text_iarchive Archive; + typedef boost::archive::text_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_text_iarchive; + friend class boost::archive::load_access; - // give serialization implementation access to this class - friend class boost::archive::detail::interface_iarchive; - friend class boost::archive::basic_text_iarchive; - friend class boost::archive::load_access; public: - text_iarchive(std::istream & is, unsigned int flags = 0) : - text_iarchive_impl(is, flags) - {} + text_iarchive(std::istream &is, unsigned int flags = 0) + : text_iarchive_impl(is, flags) {} - using basic_text_iarchive::load_override; + using basic_text_iarchive::load_override; - void load_override(boost::archive::object_id_type & t, int) {} + void load_override(boost::archive::object_id_type &t) {} - // 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; + // 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; - } + void load_override(const char *str) { + StringReader sr(basic_text_iprimitive::is); + sr >> str; + } - ~text_iarchive() {}; + ~text_iarchive() {}; }; typedef text_iarchive naked_text_iarchive; -//typedef boost::archive::detail::polymorphic_iarchive_route< -//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 { + typedef text_oarchive Archive; + typedef boost::archive::text_oarchive_impl base; + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_text_oarchive; + friend class boost::archive::save_access; -class text_oarchive : - public boost::archive::text_oarchive_impl -{ - typedef text_oarchive Archive; - typedef boost::archive::text_oarchive_impl base; - - // give serialization implementation access to this class - friend class boost::archive::detail::interface_oarchive; - friend class boost::archive::basic_text_oarchive; - friend class boost::archive::save_access; public: - text_oarchive(std::ostream & os, unsigned int flags = 0) : - boost::archive::text_oarchive_impl(os, flags) - {} + text_oarchive(std::ostream &os, unsigned int flags = 0) + : boost::archive::text_oarchive_impl(os, flags) {} - using basic_text_oarchive::save_override; + using basic_text_oarchive::save_override; - void save_override(const char *str, int v) { - basic_text_oprimitive::save(str); - } + void save_override(const char *str) { basic_text_oprimitive::save(str); } - ~text_oarchive(){} + ~text_oarchive() {} }; -//typedef boost::archive::detail::polymorphic_oarchive_route< -//boost::archive::text_oarchive_impl +// typedef boost::archive::detail::polymorphic_oarchive_route< +// boost::archive::text_oarchive_impl //> polymorphic_text_oarchive; - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // SIMPLE HUMAN READABLE TEXT // -class hrt_iarchive : - public boost::archive::text_iarchive_impl -{ - typedef hrt_iarchive Archive; - typedef boost::archive::text_iarchive_impl base; +class hrt_iarchive : public boost::archive::text_iarchive_impl { + typedef hrt_iarchive Archive; + typedef boost::archive::text_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_text_iarchive; + friend class boost::archive::load_access; - // give serialization implementation access to this class - friend class boost::archive::detail::interface_iarchive; - friend class boost::archive::basic_text_iarchive; - friend class boost::archive::load_access; public: - hrt_iarchive(std::istream & is, unsigned int flags = 0) : - base(is, flags | boost::archive::no_header ) - {} + hrt_iarchive(std::istream &is, unsigned int flags = 0) + : base(is, flags | boost::archive::no_header) {} - using basic_text_iarchive::load_override; + 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) {} + // hide all archive props // + void load_override(boost::archive::object_id_type &t) {} + void load_override(boost::archive::object_reference_type &t) {} + void load_override(boost::archive::version_type &t) {} + void load_override(boost::archive::class_id_type &t) {} + void load_override(boost::archive::class_id_optional_type &t) {} + void load_override(boost::archive::class_id_reference_type &t) {} + void load_override(boost::archive::class_name_type &t) {} + void load_override(boost::archive::tracking_type &t) {} - // 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; + // 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; - } + void load_override(const char *str) { + StringReader sr(basic_text_iprimitive::is); + sr >> str; + } - ~hrt_iarchive() {}; + ~hrt_iarchive() {}; }; +class hrt_oarchive : public boost::archive::text_oarchive_impl { + typedef hrt_oarchive Archive; + typedef boost::archive::text_oarchive_impl base; -class hrt_oarchive : - public boost::archive::text_oarchive_impl - { - typedef hrt_oarchive Archive; - typedef boost::archive::text_oarchive_impl base; + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_text_oarchive; + friend class boost::archive::save_access; - // give serialization implementation access to this class - friend class boost::archive::detail::interface_oarchive; - friend class boost::archive::basic_text_oarchive; - friend class boost::archive::save_access; - public: - hrt_oarchive(std::ostream & os, unsigned int flags = 0) : - base(os, flags | boost::archive::no_header ) - {} +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(){} - }; + using basic_text_oarchive::save_override; + void save_override(const boost::archive::object_id_type &t) {} + void save_override(const boost::archive::object_reference_type &t) {} + void save_override(const boost::archive::version_type &t) {} + void save_override(const boost::archive::class_id_type &t) {} + void save_override(const boost::archive::class_id_optional_type &t) {} + void save_override(const boost::archive::class_id_reference_type &t) {} + void save_override(const boost::archive::class_name_type &t) {} + void save_override(const boost::archive::tracking_type &t) {} + void save_override(const char *str) { basic_text_oprimitive::save(str); } + ~hrt_oarchive() {} +}; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -690,76 +597,61 @@ class hrt_oarchive : // any serializable class. Intended to be useful as a debugging aid. class log_archive : /* protected ? */ - public boost::archive::xml_oarchive_impl -{ - typedef boost::archive::xml_oarchive_impl base; - typedef log_archive Archive; - // give serialization implementation access to this clas - friend class boost::archive::detail::interface_oarchive; - friend class boost::archive::basic_xml_oarchive; - friend class boost::archive::save_access; + public boost::archive::xml_oarchive_impl { + typedef boost::archive::xml_oarchive_impl base; + typedef log_archive Archive; + // give serialization implementation access to this clas + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_xml_oarchive; + friend class boost::archive::save_access; public: + void save_override(const char *str) { + // Do not save any human decoration string // + // basic_text_oprimitive::save(str); + } - void save_override(const char *str, int v) { - // Do not save any human decoration string // - // basic_text_oprimitive::save(str); - } + template void save_override(T &t) { + base::save_override(boost::serialization::make_nvp(NULL, t)); + } - template - 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 + // void save_override(T & t) + // { + // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >)); + // // this->detail_common_oarchive::save_override(t); + // } - // activate this if you want to trap non nvp objects // - // template - // 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 - void save_override(const boost::serialization::nvp & 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) {} + template void save_override(const boost::serialization::nvp &t) { + base::save_override(t); + } + // 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) {} + void save_override(const boost::archive::object_reference_type &t) {} + void save_override(const boost::archive::version_type &t) {} + void save_override(const boost::archive::class_id_type &t) {} + void save_override(const boost::archive::class_id_optional_type &t) {} + void save_override(const boost::archive::class_id_reference_type &t) {} + void save_override(const boost::archive::class_name_type &t) {} + void save_override(const boost::archive::tracking_type &t) {} public: - log_archive(std::ostream & os, unsigned int flags = 0) : - boost::archive::xml_oarchive_impl( - os, - flags | boost::archive::no_header - ) - {} + log_archive(std::ostream &os, unsigned int flags = 0) + : boost::archive::xml_oarchive_impl( + os, flags | boost::archive::no_header) {} }; -//typedef boost::archive::detail::polymorphic_oarchive_route< -//boost::archive::xml_oarchive_impl +// typedef boost::archive::detail::polymorphic_oarchive_route< +// boost::archive::xml_oarchive_impl //> polymorphic_log_archive; +} // namespace Archive - - -} // Archive - - - -} // uLib - +} // namespace uLib ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive) ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive) @@ -769,13 +661,10 @@ 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) - - - +// 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 diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 296f1ce..bbbe149 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -1,10 +1,9 @@ -set(HEADERS Options.h - StaticInterface.h) +set(HEADERS Archives.h Array.h Collection.h Debug.h Export.h Function.h Macros.h Mpl.h Object.h Options.h Serializable.h Signal.h Singleton.h SmartPointer.h StaticInterface.h StringReader.h Types.h Uuid.h Vector.h) -set(SOURCES Options.cpp) +set(SOURCES Archives.cpp Debug.cpp Object.cpp Options.cpp Serializable.cpp Signal.cpp Uuid.cpp) -set(LIBRARIES ${Boost_PROGRAM_OPTIONS_LIBRARY}) +set(LIBRARIES Boost::program_options) set(libname ${PACKAGE_LIBPREFIX}Core) set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE) @@ -23,5 +22,7 @@ install(TARGETS ${libname} install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core) - - +if(BUILD_TESTING) + include(uLibTargetMacros) + add_subdirectory(testing) +endif() diff --git a/src/Core/Export.h b/src/Core/Export.h index 1b43cd0..88c6ef6 100644 --- a/src/Core/Export.h +++ b/src/Core/Export.h @@ -23,95 +23,85 @@ //////////////////////////////////////////////////////////////////////////////*/ - - #ifndef U_CORE_EXPORT_H #define U_CORE_EXPORT_H -#include #include // NULL #include +#include #include -#include #include +#include #include -#include #include -#include +#include #include +#include -#include // for guid_defined only -#include #include +#include // for guid_defined only #include #include +#include #include - #include "Core/Archives.h" //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - - namespace uLib { namespace Archive { namespace detail { namespace extra_detail { -template -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 struct guid_initializer { + void export_guid(boost::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(boost::mpl::true_) const {} + guid_initializer const &export_guid() const { + BOOST_STATIC_WARNING(boost::is_polymorphic::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()); + return *this; + } }; -template -struct init_guid; +template struct init_guid; -} // anonymous +} // namespace extra_detail } // 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(); \ - }}}} \ -/**/ +#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \ + namespace uLib { \ + namespace Archive { \ + namespace detail { \ + namespace extra_detail { \ + template <> struct init_guid { \ + static guid_initializer const &g; \ + }; \ + guid_initializer const &init_guid::g = \ + ::boost::serialization::singleton< \ + guid_initializer>::get_mutable_instance() \ + .export_guid(); \ + } \ + } \ + } \ + } \ + /**/ #endif // EXPORT_H diff --git a/src/Core/Object.cpp b/src/Core/Object.cpp index 56ec798..3998ce2 100644 --- a/src/Core/Object.cpp +++ b/src/Core/Object.cpp @@ -110,11 +110,13 @@ bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name) { ObjectPrivate::Signal s = {fptr, std::string(name), sig}; d->sigv.push_back(s); + return true; } bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) { ObjectPrivate::Slot s = {fptr, std::string(name)}; d->slov.push_back(s); + return true; } SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const { diff --git a/src/Core/Object.h b/src/Core/Object.h index 5d1b51e..4f4a278 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -107,6 +107,7 @@ public: // if(sig && slo) // return Object::connect(sig,slo->operator ()(),receiver); // else return false; + return false; } // Qt5 style connector // @@ -119,11 +120,13 @@ public: typename FunctionPointer::SignalSignature> SigT; ConnectSignal(sigb, slof, receiver); + return true; } template static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) { ConnectSignal(sigb, slof, receiver); + return true; } template @@ -139,7 +142,7 @@ public: } template inline bool addSlot(FuncT fun, const char *name) { - this->addSlotImpl(GenericMFPtr(fun), name); + return this->addSlotImpl(GenericMFPtr(fun), name); } template diff --git a/src/Core/Signal.h b/src/Core/Signal.h index 624dd49..ee0ad99 100644 --- a/src/Core/Signal.h +++ b/src/Core/Signal.h @@ -23,21 +23,19 @@ //////////////////////////////////////////////////////////////////////////////*/ - - #ifndef U_CORE_SIGNAL_H #define U_CORE_SIGNAL_H #include #include -#include #include +#include #include "Function.h" +#include - - +using namespace boost::placeholders; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -48,12 +46,12 @@ #define slots #define signals /*virtual void init_signals();*/ public #define emit -#define SLOT(a) BOOST_STRINGIZE(a) -#define SIGNAL(a) BOOST_STRINGIZE(a) +#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__); +#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: @@ -66,103 +64,105 @@ * // cast automatico // * static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0)); * sig->operator()(); -*/ -#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__) - + */ +#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 -struct Signal { - typedef boost::signals2::signal type; +template struct Signal { + typedef boost::signals2::signal type; }; - - //////////////////////////////////////////////////////////////////////////////// - namespace detail { +template struct ConnectSignal {}; -template -struct ConnectSignal {}; - -template -struct ConnectSignal< FuncT, 0 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(slof); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect(slof); + } }; -template -struct ConnectSignal< FuncT, 1 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(boost::bind(slof,receiver)); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof, receiver)); + } }; -template -struct ConnectSignal< FuncT, 2 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1)); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof, receiver, _1)); + } }; -template -struct ConnectSignal< FuncT, 3 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2)); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect( + boost::bind(slof, receiver, _1, _2)); + } }; -template -struct ConnectSignal< FuncT, 4 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3)); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect( + boost::bind(slof, receiver, _1, _2, _3)); + } }; -template -struct ConnectSignal< FuncT, 5 > { - static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { - typedef typename Signal::SignalSignature>::type SigT; - reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4)); - } +template struct ConnectSignal { + static void connect(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + typedef + typename Signal::SignalSignature>::type + SigT; + reinterpret_cast(sigb)->connect( + boost::bind(slof, receiver, _1, _2, _3, _4)); + } }; +} // namespace detail -} // detail - - - -template -SignalBase *NewSignal(FuncT f) { - // seems to work wow ! - return new Signal::type; +template SignalBase *NewSignal(FuncT f) { + // seems to work wow ! + return new Signal::type; } template -void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) -{ - detail::ConnectSignal< FuncT, FunctionPointer::arity >::connect(sigb,slof,receiver); +void ConnectSignal(SignalBase *sigb, FuncT slof, + typename FunctionPointer::Object *receiver) { + detail::ConnectSignal::arity>::connect( + sigb, slof, receiver); } - - - -} // uLib +} // namespace uLib #endif // SIGNAL_H diff --git a/src/Core/testing/CMakeLists.txt b/src/Core/testing/CMakeLists.txt index 05d28af..c045b98 100644 --- a/src/Core/testing/CMakeLists.txt +++ b/src/Core/testing/CMakeLists.txt @@ -24,9 +24,8 @@ set( TESTS set(LIBRARIES ${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Math - ${Boost_SERIALIZATION_LIBRARY} - ${Boost_SIGNALS_LIBRARY} - ${Boost_PROGRAM_OPTIONS_LIBRARY} + Boost::serialization + Boost::program_options ${ROOT_LIBRARIES} ) -uLib_add_tests(${uLib-module}) +uLib_add_tests(Core) diff --git a/src/Core/testing/SerializeDreadDiamondTest.cpp b/src/Core/testing/SerializeDreadDiamondTest.cpp index 5bd3a57..2e455e0 100644 --- a/src/Core/testing/SerializeDreadDiamondTest.cpp +++ b/src/Core/testing/SerializeDreadDiamondTest.cpp @@ -23,13 +23,10 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - -#include #include -#include +#include #include +#include #include "Core/Object.h" @@ -37,78 +34,43 @@ using namespace uLib; - - - - - - -struct A : Object { - uLibTypeMacro(A,Object) - A() : numa(5552368) {} - int numa; +struct A : Object { + uLibTypeMacro(A, Object) A() : numa(5552368) {} + int numa; }; - ULIB_SERIALIZABLE_OBJECT(A) -ULIB_SERIALIZE_OBJECT(A,Object) { - ar & AR(numa); -} +ULIB_SERIALIZE_OBJECT(A, Object) { ar &AR(numa); } struct B : virtual Object { - uLibTypeMacro(B,Object) - B() : numb(5552369) {} - int numb; + uLibTypeMacro(B, Object) B() : numb(5552369) {} + int numb; }; ULIB_SERIALIZABLE_OBJECT(B) -ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); } - +ULIB_SERIALIZE_OBJECT(B, Object) { ar &AR(numb); } struct C : B { - uLibTypeMacro(C,B) - C() : numc(5552370) {} - int numc; + uLibTypeMacro(C, B) C() : numc(5552370) {} + int numc; }; ULIB_SERIALIZABLE_OBJECT(C) -ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); } +ULIB_SERIALIZE_OBJECT(C, B) { ar &AR(numc); } -struct D : A,B { - uLibTypeMacro(D,A,B) +struct D : A, B { + uLibTypeMacro(D, A, B) - D() : numd(5552371) {} - int numd; + D() + : numd(5552371) {} + int numd; }; ULIB_SERIALIZABLE_OBJECT(D) -ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); } +ULIB_SERIALIZE_OBJECT(D, A, B) { ar &AR(numd); } +int main() { + A o; - -main() { - A o; o.init_properties(); - - Archive::xml_oarchive(std::cout) << NVP(o); - + Archive::xml_oarchive(std::cout) << NVP(o); } - - - - - - - - - - - - - - - - - - - - diff --git a/src/Core/testing/SerializeTest.cpp b/src/Core/testing/SerializeTest.cpp index c0466cc..31a5bc0 100644 --- a/src/Core/testing/SerializeTest.cpp +++ b/src/Core/testing/SerializeTest.cpp @@ -23,20 +23,16 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - -#include #include +#include -#include "Core/Object.h" #include "Core/Archives.h" +#include "Core/Object.h" #include "testing-prototype.h" using namespace uLib; - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -45,63 +41,51 @@ using namespace uLib; struct V3f { - float x,y,z; - V3f() - { x = y = z =0; } + float x, y, z; + V3f() { x = y = z = 0; } - V3f(float x, float y, float z) : - x(x), y(y), z(z) {} + V3f(float x, float y, float z) : x(x), y(y), z(z) {} - template - void serialize (Archive &ar,unsigned int v) { - ar - & "<" & NVP(x) & NVP(y) & NVP(z) & ">"; - } + template void serialize(Archive &ar, unsigned int v) { + ar & "<" & NVP(x) & NVP(y) & NVP(z) & ">"; + } }; ULIB_CLASS_EXPORT_KEY(V3f); ULIB_CLASS_EXPORT_IMPLEMENT(V3f); - -inline std::ostream & -operator <<(std::ostream &o, const V3f &v) { - Archive::hrt_oarchive(o) << v; - return o; +inline std::ostream &operator<<(std::ostream &o, const V3f &v) { + Archive::hrt_oarchive(o) << v; + return o; } -inline std::istream & -operator >>(std::istream &is, V3f &v) { - Archive::hrt_iarchive(is) >> v; - return is; +inline std::istream &operator>>(std::istream &is, V3f &v) { + Archive::hrt_iarchive(is) >> v; + return is; } - - - int test_V3f() { - // testing human readble archive with simple serializable structure // + // testing human readble archive with simple serializable structure // - V3f v1(1,2,3),v2,v3,v4; - std::cout << "v --> " << v1 << "\n"; + V3f v1(1, 2, 3), v2, v3, v4; + std::cout << "v --> " << v1 << "\n"; - std::stringstream ss; ss << v1; - std::cout << "ss.v --> " << ss.str() << "\n"; + std::stringstream ss; + ss << v1; + std::cout << "ss.v --> " << ss.str() << "\n"; - Archive::hrt_iarchive ar(ss); ar >> v2; - std::cout << "v2 --> " << v2 << "\n"; + Archive::hrt_iarchive ar(ss); + ar >> v2; + std::cout << "v2 --> " << v2 << "\n"; - std::stringstream("<2 3 4>") >> v3; - std::cout << "v3 --> " << v3 << "\n"; + std::stringstream("<2 3 4>") >> v3; + std::cout << "v3 --> " << v3 << "\n"; - // std::cout << "insert V3f string to parse: "; std::cin >> v4; - // std::cout << "v4 --> " << v4 << "\n"; - return (1); + // std::cout << "insert V3f string to parse: "; std::cin >> v4; + // std::cout << "v4 --> " << v4 << "\n"; + return (1); } - - - - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -109,104 +93,72 @@ int test_V3f() { // OBJECT SERIALIZATION // class A : public virtual Object { - uLibTypeMacro(A,Object) - ULIB_SERIALIZE_ACCESS -public: - A() : m_a(5552368) {} +uLibTypeMacro(A, Object) ULIB_SERIALIZE_ACCESS public : A() : m_a(5552368) {} - properties() { - std::string p_a; - }; + void init_properties(); + std::string p_a; + + uLibRefMacro(a, int); - uLibRefMacro (a,int); private: - int m_a; + int m_a; }; -void A::init_properties() { - $_init(); - $$.p_a = "A property string"; -} +void A::init_properties() { p_a = "A property string"; } ULIB_SERIALIZABLE_OBJECT(A) -ULIB_SERIALIZE_OBJECT(A,Object) { - ar - & "Object A : " - & "--> m_a = " & AR(m_a) - & "\n"; +ULIB_SERIALIZE_OBJECT(A, Object) { + ar & "Object A : " & "--> m_a = " & AR(m_a) & "\n" & "Object A properties: " & + "---> p_a = " & AR(p_a) & "\n"; } -ULIB_SERIALIZE_OBJECT_PROPS(A) { - ar - & "Object A properties: " - & "---> p_a = " & AR(p_a) & "\n"; -} - - - int testing_xml_class() { - A a; a.init_properties(); + A a; + a.init_properties(); - { - std::ofstream file("test.xml"); - Archive::xml_oarchive(file) << NVP(a); - } - a.a() = 0; - a.$$.p_a = "zero string"; - { - std::ifstream file("test.xml"); - Archive::xml_iarchive(file) >> NVP(a); - } + { + std::ofstream file("test.xml"); + Archive::xml_oarchive(file) << NVP(a); + } + a.a() = 0; + a.p_a = "zero string"; + { + std::ifstream file("test.xml"); + Archive::xml_iarchive(file) >> NVP(a); + } - Archive::xml_oarchive(std::cout) << NVP(a); - return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); + Archive::xml_oarchive(std::cout) << NVP(a); + return (a.a() == 5552368 && a.p_a == "A property string"); } int testing_hrt_class() { - A a; a.init_properties(); + A a; + a.init_properties(); - { - std::ofstream file("test.xml"); - Archive::hrt_oarchive(file) << NVP(a); - } - a.a() = 0; - a.$$.p_a = "zero string"; - { - // ERRORE FIX ! - // std::ifstream file("test.xml"); - // Archive::hrt_iarchive(file) >> NVP(a); - } + { + std::ofstream file("test.xml"); + Archive::hrt_oarchive(file) << NVP(a); + } + a.a() = 0; + a.p_a = "zero string"; + { + // ERRORE FIX ! + // std::ifstream file("test.xml"); + // Archive::hrt_iarchive(file) >> NVP(a); + } - Archive::hrt_oarchive(std::cout) << NVP(a); - return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); + Archive::hrt_oarchive(std::cout) << NVP(a); + return (a.a() == 5552368 && a.p_a == "A property string"); } - - - - - int main() { - BEGIN_TESTING(Serialize Test); + BEGIN_TESTING(Serialize Test); - TEST1( test_V3f() ); - TEST1( testing_xml_class() ); - // testing_hrt_class(); ///// << ERRORE in HRT with properties + TEST1(test_V3f()); + TEST1(testing_xml_class()); + // testing_hrt_class(); ///// << ERRORE in HRT with properties - END_TESTING; + END_TESTING; } - - - - - - - - - - - - - diff --git a/src/Core/testing/StaticInterfaceTest.cpp b/src/Core/testing/StaticInterfaceTest.cpp index a618c44..c4e8b1d 100644 --- a/src/Core/testing/StaticInterfaceTest.cpp +++ b/src/Core/testing/StaticInterfaceTest.cpp @@ -23,90 +23,73 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - #include #include "testing-prototype.h" #include - - namespace uLib { //// INTERFACE TO COMPLEX CLASS ///// namespace Interface { struct Test { - MAKE_TRAITS - template void check_structural() { - uLibCheckFunction(Self,test,bool,int,float); - uLibCheckMember(Self,testmemb,int); - } + MAKE_TRAITS + template void check_structural() { + uLibCheckFunction(Self, test, bool, int, float); + uLibCheckMember(Self, testmemb, int); + } }; -} +} // namespace Interface struct Test { - bool test(int i, float f){} - int testmemb; + bool test(int i, float f) { return true; } + int testmemb; }; - - //// INTERFAC TO SIMPLE CLASS /////////// namespace Interface { struct Simple { - MAKE_TRAITS - template void check_structural() { - uLibCheckMember(Self,memb1,int); - uLibCheckMember(Self,memb2,float); - } + MAKE_TRAITS + template void check_structural() { + uLibCheckMember(Self, memb1, int); + uLibCheckMember(Self, memb2, float); + } }; -} +} // namespace Interface struct Simple { - int memb1; - float memb2; + int memb1; + float memb2; }; - ///////////////////////// -template -class UseTest { +template class UseTest { public: - UseTest() { - Interface::IsA(); - T t; - int i; float f; - t.test(i,f); - } + UseTest() { + Interface::IsA(); + T t; + int i; + float f; + t.test(i, f); + } }; -template -class UseSimple { +template class UseSimple { public: - UseSimple() { - Interface::IsA(); - } + UseSimple() { Interface::IsA(); } }; +} // namespace uLib +int main() { + BEGIN_TESTING(Static Interface); + uLib::UseTest u; + + uLib::UseSimple s; + + END_TESTING; } - -int main() -{ - BEGIN_TESTING(Static Interface); - - - - uLib::UseTest u; - - uLib::UseSimple s; - - END_TESTING; -} - diff --git a/src/Detectors/CMakeLists.txt b/src/Detectors/CMakeLists.txt index 7d03249..0022084 100644 --- a/src/Detectors/CMakeLists.txt +++ b/src/Detectors/CMakeLists.txt @@ -5,3 +5,8 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Detectors) + +if(BUILD_TESTING) + include(uLibTargetMacros) + add_subdirectory(testing) +endif() diff --git a/src/Detectors/testing/CMakeLists.txt b/src/Detectors/testing/CMakeLists.txt index d3bff8f..12c7566 100644 --- a/src/Detectors/testing/CMakeLists.txt +++ b/src/Detectors/testing/CMakeLists.txt @@ -1,18 +1,15 @@ # TESTS set( TESTS - GDMLSolidTest +# GDMLSolidTest HierarchicalEncodingTest ) -#set(LIBRARIES -# ${PACKAGE_LIBPREFIX}Core -# ${PACKAGE_LIBPREFIX}Math -# ${PACKAGE_LIBPREFIX}Detectors -# ${Boost_SERIALIZATION_LIBRARY} -# ${Boost_SIGNALS_LIBRARY} -# ${Boost_PROGRAM_OPTIONS_LIBRARY} -# ${Eigen_LIBRARY} -# ${Geant4_LIBRARIES} -# ${ROOT_LIBRARIES} -#) -uLib_add_tests(${uLib-module}) +set(LIBRARIES + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math + Boost::serialization + Boost::program_options + Eigen3::Eigen + ${ROOT_LIBRARIES} +) +uLib_add_tests(Detectors) diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 9aec9ee..bf35202 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -54,7 +54,8 @@ install(TARGETS ${libname} install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math) -# TESTING -# include(uLibTargetMacros) -# add_subdirectory(testing) +if(BUILD_TESTING) + include(uLibTargetMacros) + add_subdirectory(testing) +endif() diff --git a/src/Math/testing/AccumulatorTest.cpp b/src/Math/testing/AccumulatorTest.cpp index 1c3c441..8118751 100644 --- a/src/Math/testing/AccumulatorTest.cpp +++ b/src/Math/testing/AccumulatorTest.cpp @@ -23,88 +23,90 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - #include "Math/Accumulator.h" #include "testing-prototype.h" #include +#include +#include - -//#include -//#include -//#include +// #include +// #include +// #include using namespace uLib; int test_ABTrim() { - Accumulator_ABTrim acc; + Accumulator_ABTrim acc; - acc.SetABTrim(1,1); + acc.SetABTrim(1, 1); - std::vector v; - for(float tmpf : {1,5,5,5,300}) v.push_back(tmpf); - //v << 1,5,5,5,300; + std::vector v; + for (float tmpf : {1, 5, 5, 5, 300}) + v.push_back(tmpf); + // v << 1,5,5,5,300; - for(std::vector::iterator itr=v.begin(); itr::iterator itr = v.begin(); itr < v.end(); itr++) + acc += *itr; - // TODO missing operator << - //std::cout << "Accumulating Trim(1,1) vector: " - // << v << " ... out = " << acc() << "\n"; - - return( acc() == 15.0 ); + // TODO missing operator << + // std::cout << "Accumulating Trim(1,1) vector: " + // << v << " ... out = " << acc() << "\n"; + return (acc() == 15.0); } - int test_Mean() { - Accumulator_Mean mean; - TRandom rnd; - const int c = 10000000; - std::vector v; - v.reserve(c); - for(int i=0;i mean; + TRandom rnd; + const int c = 10000000; + std::vector v; + v.reserve(c); + for (int i = 0; i < c; ++i) + v.push_back(rnd.Gaus(2000, 5)); + float m = 0; + for (int i = 0; i < c; ++i) + m += v[i]; + m /= c; + std::cout << "simple mean: " << m << "\n"; + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + mean.AddPass(); + for (int i = 0; i < c; ++i) + mean(v[i]); + std::cout << "mean pass: " << mean() << "\n"; + return 1; } - - - int main(void) { - BEGIN_TESTING(Accumulator); + BEGIN_TESTING(Accumulator); - //TEST1( test_ABTrim() ); - test_Mean(); + // TEST1( test_ABTrim() ); + test_Mean(); - END_TESTING; + END_TESTING; } diff --git a/src/Math/testing/CMakeLists.txt b/src/Math/testing/CMakeLists.txt index 256f58e..5c5c686 100644 --- a/src/Math/testing/CMakeLists.txt +++ b/src/Math/testing/CMakeLists.txt @@ -17,6 +17,8 @@ set(TESTS set(LIBRARIES ${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Math + Boost::serialization + Eigen3::Eigen ) uLib_add_tests(Math) diff --git a/src/Math/testing/TriangleMeshTest.cpp b/src/Math/testing/TriangleMeshTest.cpp index bd89a03..f44be3e 100644 --- a/src/Math/testing/TriangleMeshTest.cpp +++ b/src/Math/testing/TriangleMeshTest.cpp @@ -23,30 +23,25 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - #include "testing-prototype.h" #include "Math/TriangleMesh.h" - +#include using namespace uLib; -int main() -{ - BEGIN_TESTING(Triangle Mesh); +int main() { + BEGIN_TESTING(Triangle Mesh); - TriangleMesh mesh; + TriangleMesh mesh; - mesh.AddPoint(Vector3f(0,0,0)); - mesh.AddPoint(Vector3f(0,1,0)); - mesh.AddPoint(Vector3f(1,0,0)); + mesh.AddPoint(Vector3f(0, 0, 0)); + mesh.AddPoint(Vector3f(0, 1, 0)); + mesh.AddPoint(Vector3f(1, 0, 0)); - mesh.AddTriangle(Vector3i(0,1,2)); + mesh.AddTriangle(Vector3i(0, 1, 2)); + mesh.PrintSelf(std::cout); - mesh.PrintSelf(std::cout); - - END_TESTING; + END_TESTING; } diff --git a/src/Math/testing/VoxRaytracerTest.cpp b/src/Math/testing/VoxRaytracerTest.cpp index af46a82..c9d5bb9 100644 --- a/src/Math/testing/VoxRaytracerTest.cpp +++ b/src/Math/testing/VoxRaytracerTest.cpp @@ -23,129 +23,114 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - -#include "Math/StructuredGrid.h" #include "Math/VoxRaytracer.h" +#include "Math/StructuredGrid.h" #include "testing-prototype.h" +#include using namespace uLib; - -int Vector4f0(Vector4f c) -{ +int Vector4f0(Vector4f c) { c(3) = 0; - if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) + if (fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001) return 0; else return 1; } -//bool Comapare(const &t1, const T2 &t2) +// bool Comapare(const &t1, const T2 &t2) //{ -// int out = 0; -// out += t1.vox_id != t2.vox_id; -// out += (fabs(t1.L) - fabs(t2.L)) > 0.001; -// return out == 0; -//} - +// int out = 0; +// out += t1.vox_id != t2.vox_id; +// out += (fabs(t1.L) - fabs(t2.L)) > 0.001; +// return out == 0; +// } typedef VoxRaytracer Raytracer; -int main() -{ - BEGIN_TESTING(Math VoxRaytracer); +int main() { + BEGIN_TESTING(Math VoxRaytracer); - StructuredGrid img(Vector3i(2,2,2)); - img.SetSpacing(Vector3f(2,2,2)); - img.SetPosition(Vector3f(-2,0,-2)); + StructuredGrid img(Vector3i(2, 2, 2)); + img.SetSpacing(Vector3f(2, 2, 2)); + img.SetPosition(Vector3f(-2, 0, -2)); - { - HLine3f line; - line.origin << 0.1, 4.1, 0.1, 1; - line.direction << 0.1, -0.1, 0.1,0; - Raytracer rt(img); - HPoint3f pt; - TEST1( rt.GetEntryPoint(line,pt) ); - TEST0( Vector4f0( pt - HPoint3f(0.2,4,0.2) ) ); + { + HLine3f line; + line.origin << 0.1, 4.1, 0.1, 1; + line.direction << 0.1, -0.1, 0.1, 0; + Raytracer rt(img); + HPoint3f pt; + TEST1(rt.GetEntryPoint(line, pt)); + TEST0(Vector4f0(pt - HPoint3f(0.2, 4, 0.2))); + } + + { + HLine3f line; + line.origin << 4, 0, 4, 1; + line.direction << -0.1, 0.1, -0.1, 0; + Raytracer rt(img); + HPoint3f pt; + TEST1(rt.GetEntryPoint(line, pt)); + TEST0(Vector4f0(pt - HPoint3f(2, 2, 2))); + } + + { // Test a point inside image // + StructuredGrid img(Vector3i(4, 4, 4)); + img.SetSpacing(Vector3f(2, 2, 2)); + img.SetPosition(Vector3f(-4, -4, -4)); + Raytracer ray(img); + HPoint3f pt; + HLine3f line; + line.origin = HPoint3f(-3, -3, -3); + // line.direction = HVector3f(1,1,1); // + TEST1(ray.GetEntryPoint(line, pt)); + TEST1(pt == HPoint3f(-3, -3, -3)); + + Raytracer::RayData rdata = + ray.TraceBetweenPoints(HPoint3f(-3, -3, -3), HPoint3f(3, 3, 3)); + for (const Raytracer::RayData::Element &el : rdata.Data()) { + std::cout << " " << el.vox_id << " , " << el.L << "\n"; } + } - { - HLine3f line; - line.origin << 4,0,4, 1; - line.direction << -0.1, 0.1, -0.1, 0; - Raytracer rt(img); - HPoint3f pt; - TEST1( rt.GetEntryPoint(line,pt) ); - TEST0( Vector4f0( pt - HPoint3f(2,2,2) ) ); - } + { + HPoint3f pt1(1, -0.5, 1); + HPoint3f pt2(1, 4.5, 1); + Raytracer rt(img); - { // Test a point inside image // - StructuredGrid img(Vector3i(4,4,4)); - img.SetSpacing(Vector3f(2,2,2)); - img.SetPosition(Vector3f(-4,-4,-4)); - Raytracer ray(img); - HPoint3f pt; - HLine3f line; - line.origin = HPoint3f(-3,-3,-3); - // line.direction = HVector3f(1,1,1); // - TEST1( ray.GetEntryPoint(line,pt) ); - TEST1( pt == HPoint3f(-3,-3,-3) ); + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2); + TEST1(ray.Data().size() == 2); + TEST1(ray.Data().at(0).vox_id == 6); + TEST1(ray.Data().at(1).vox_id == 7); + ray.PrintSelf(std::cout); + } - Raytracer::RayData rdata = ray.TraceBetweenPoints(HPoint3f(-3,-3,-3), HPoint3f(3,3,3)); - for(const Raytracer::RayData::Element &el : rdata.Data()) - { - std::cout << " " << el.vox_id << " , " << el.L << "\n"; - } - } + { + HPoint3f pt1(5, 1, 1); + HPoint3f pt2(-3, 1, 1); + Raytracer rt(img); + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2); + TEST1(ray.Data().size() == 2); + TEST1(ray.Data().at(0).vox_id == 6); + TEST1(ray.Data().at(1).vox_id == 4); + ray.PrintSelf(std::cout); + } - { - HPoint3f pt1(1,-0.5,1); - HPoint3f pt2(1,4.5,1); - Raytracer rt(img); + { + HPoint3f pt1(1, 1, 1); + HPoint3f pt2(-1, 3, -1); + Raytracer rt(img); - Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); - TEST1( ray.Data().size() == 2 ); - TEST1( ray.Data().at(0).vox_id == 6 ); - TEST1( ray.Data().at(1).vox_id == 7 ); - ray.PrintSelf(std::cout); - } + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2); + TEST1(ray.Data().size() == 4); + TEST1(ray.Data().at(0).vox_id == 6); + TEST1(ray.Data().at(1).vox_id == 4); + TEST1(ray.Data().at(2).vox_id == 5); + TEST1(ray.Data().at(3).vox_id == 1); + ray.PrintSelf(std::cout); + } - { - HPoint3f pt1(5,1,1); - HPoint3f pt2(-3,1,1); - Raytracer rt(img); - - Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); - TEST1( ray.Data().size() == 2 ); - TEST1( ray.Data().at(0).vox_id == 6 ); - TEST1( ray.Data().at(1).vox_id == 4 ); - ray.PrintSelf(std::cout); - } - - { - HPoint3f pt1(1,1,1); - HPoint3f pt2(-1,3,-1); - Raytracer rt(img); - - Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); - TEST1( ray.Data().size() == 4 ); - TEST1( ray.Data().at(0).vox_id == 6 ); - TEST1( ray.Data().at(1).vox_id == 4 ); - TEST1( ray.Data().at(2).vox_id == 5 ); - TEST1( ray.Data().at(3).vox_id == 1 ); - ray.PrintSelf(std::cout); - } - - END_TESTING + END_TESTING } - - - - - - - - diff --git a/src/Root/CMakeLists.txt b/src/Root/CMakeLists.txt index 6e76dfb..91efbf3 100644 --- a/src/Root/CMakeLists.txt +++ b/src/Root/CMakeLists.txt @@ -62,4 +62,7 @@ install(TARGETS ${libname} install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root) - +if(BUILD_TESTING) + include(uLibTargetMacros) + add_subdirectory(testing) +endif() diff --git a/src/Root/testing/CMakeLists.txt b/src/Root/testing/CMakeLists.txt index 67cb15a..cd56f0d 100644 --- a/src/Root/testing/CMakeLists.txt +++ b/src/Root/testing/CMakeLists.txt @@ -8,9 +8,8 @@ set(LIBRARIES ${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Root - ${Boost_SERIALIZATION_LIBRARY} - ${Boost_SIGNALS_LIBRARY} - ${Boost_PROGRAM_OPTIONS_LIBRARY} + Boost::serialization + Boost::program_options ${ROOT_LIBRARIES} ) -uLib_add_tests(${uLib-module}) +uLib_add_tests(Root) diff --git a/src/Vtk/CMakeLists.txt b/src/Vtk/CMakeLists.txt index 9b8351b..9c193ea 100644 --- a/src/Vtk/CMakeLists.txt +++ b/src/Vtk/CMakeLists.txt @@ -36,3 +36,7 @@ install(TARGETS ${libname} install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk) +if(BUILD_TESTING) + include(uLibTargetMacros) + add_subdirectory(testing) +endif() diff --git a/src/Vtk/testing/CMakeLists.txt b/src/Vtk/testing/CMakeLists.txt index 66f7c98..a9c3521 100644 --- a/src/Vtk/testing/CMakeLists.txt +++ b/src/Vtk/testing/CMakeLists.txt @@ -14,5 +14,5 @@ set(LIBRARIES ${PACKAGE_LIBPREFIX}Vtk ) -include(${VTK_USE_FILE}) -uLib_add_tests(${uLib-module}) +# include(${VTK_USE_FILE}) +uLib_add_tests(Vtk) diff --git a/src/utils/make_recipe/src/CMakeLists.txt b/src/utils/make_recipe/src/CMakeLists.txt index 05e35c0..631800e 100644 --- a/src/utils/make_recipe/src/CMakeLists.txt +++ b/src/utils/make_recipe/src/CMakeLists.txt @@ -67,9 +67,8 @@ if(ULIB_FOUND) ############################################################################ # MANUAL INLCLUDE EXTERNAL DEPENDENCIES - # ${Boost_SERIALIZATION_LIBRARY} - # ${Boost_SIGNALS_LIBRARY} - # ${Boost_PROGRAM_OPTIONS_LIBRARY} + # Boost::serialization + # Boost::program_options # ${Geant4_LIBRARIES} # ${ROOT_LIBRARIES} # ${VTK_LIBRARIES} # all VTK libs