refactor: Update CMake build system and streamline Core object serialization and property handling.

This commit is contained in:
AndreaRigoni
2026-02-21 16:16:28 +00:00
parent 7ded15d596
commit d56758d0b3
24 changed files with 830 additions and 1056 deletions

View File

@@ -82,7 +82,7 @@ ENDMACRO(uLib_add_target)
# TESTS and LIBRARIES must be defined # TESTS and LIBRARIES must be defined
macro(uLib_add_tests name) macro(uLib_add_tests name)
foreach(tn ${TESTS}) foreach(tn ${TESTS})
add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp) add_executable(${tn} ${tn}.cpp)
add_test(NAME ${tn} COMMAND ${tn}) add_test(NAME ${tn} COMMAND ${tn})
target_link_libraries(${tn} ${LIBRARIES}) target_link_libraries(${tn} ${LIBRARIES})

View File

@@ -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") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UULIB_SERIALIZATION_ON -Wno-cpp")
# CTEST framework # CTEST framework
include(CTest)
enable_testing() enable_testing()
@@ -85,7 +86,7 @@ set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_USE_STATIC_RUNTIME OFF)
message(STATUS "CMAKE_PREFIX_PATH is ${CMAKE_PREFIX_PATH}") 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}) include_directories(${Boost_INCLUDE_DIRS})
find_package(Eigen3 CONFIG REQUIRED) find_package(Eigen3 CONFIG REQUIRED)

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARCHIVES_H #ifndef U_CORE_ARCHIVES_H
#define U_CORE_ARCHIVES_H #define U_CORE_ARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp> #include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp> #include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <iostream>
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_oarchive.hpp>
@@ -40,25 +38,20 @@
#include <boost/archive/detail/register_archive.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_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp> #include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp> #include <boost/archive/polymorphic_text_oarchive.hpp>
#include "StringReader.h" #include "StringReader.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES // // FWD DECLARATIONS OF ARCHIVES //
namespace uLib { namespace uLib {
namespace Archive { namespace Archive {
@@ -68,40 +61,36 @@ class text_iarchive;
class text_oarchive; class text_oarchive;
class log_archive; class log_archive;
} // namespace Archive
} } // namespace uLib
}
namespace boost { namespace boost {
namespace archive { namespace archive {
namespace detail { namespace detail {
template <class ArchiveImplementation> class polymorphic_oarchive_route; template <class ArchiveImplementation> class polymorphic_oarchive_route;
template <class ArchiveImplementation> class polymorphic_iarchive_route; template <class ArchiveImplementation> class polymorphic_iarchive_route;
} } // namespace detail
} } // namespace archive
} } // namespace boost
namespace boost { namespace boost {
namespace serialization { namespace serialization {
template <typename T> struct hrp; template <typename T> struct hrp;
} }
} } // namespace boost
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION // // ARCHIVES REGISTRATION //
namespace uLib { namespace uLib {
namespace Archive { namespace Archive {
namespace detail { namespace detail {
struct adl_tag {}; struct adl_tag {};
} } // namespace detail
} } // namespace Archive
} } // namespace uLib
namespace boost { namespace boost {
namespace archive { namespace archive {
@@ -110,10 +99,11 @@ namespace detail {
// in overload resolution with the functions declared by // in overload resolution with the functions declared by
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below. // BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
template <class Serializable> template <class Serializable>
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 // The function declaration generated by this macro never actually
// gets called, but its return type gets instantiated, and that's // gets called, but its return type gets instantiated, and that's
@@ -121,23 +111,24 @@ void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::ad
// Archive and any exported Serializable type. See also: // Archive and any exported Serializable type. See also:
// boost/serialization/export.hpp // boost/serialization/export.hpp
#define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \ #define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
namespace boost { namespace archive { namespace detail { \ namespace boost { \
namespace archive { \
namespace detail { \
\ \
template <class Serializable> \ template <class Serializable> \
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \ BOOST_DEDUCED_TYPENAME \
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}} _ptr_serialization_support<_Archive, Serializable>::type \
instantiate_ptr_serialization(Serializable *, _Archive *, \
uLib::Archive::detail::adl_tag); \
} \
} \
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES // // ARCHIVES IO INTERFACES //
namespace boost { namespace boost {
namespace archive { namespace archive {
namespace detail { namespace detail {
@@ -145,11 +136,10 @@ namespace detail {
/** /**
* Custom implementation of boost interface_iarchive to add new operators * Custom implementation of boost interface_iarchive to add new operators
*/ */
template<class Archive> template <class Archive> class uLib_interface_iarchive {
class uLib_interface_iarchive
{
protected: protected:
uLib_interface_iarchive() {}; uLib_interface_iarchive() {};
public: public:
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// archive public interface // archive public interface
@@ -157,54 +147,40 @@ public:
typedef mpl::bool_<false> is_saving; typedef mpl::bool_<false> is_saving;
// return a pointer to the most derived class // return a pointer to the most derived class
Archive * This(){ Archive *This() { return static_cast<Archive *>(this); }
return static_cast<Archive *>(this);
}
template <class T> template <class T>
const basic_pointer_iserializer * const basic_pointer_iserializer *register_type(T * = NULL) {
register_type(T * = NULL){ const basic_pointer_iserializer &bpis = boost::serialization::singleton<
const basic_pointer_iserializer & bpis = pointer_iserializer<Archive, T>>::get_const_instance();
boost::serialization::singleton<
pointer_iserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpis.get_basic_serializer()); this->This()->register_basic_serializer(bpis.get_basic_serializer());
return &bpis; return &bpis;
} }
template<class T> template <class T> Archive &operator>>(T &t) {
Archive & operator>>(T & t){ this->This()->load_override(t);
this->This()->load_override(t, 0);
return *this->This(); return *this->This();
} }
// the & operator // the & operator
template<class T> template <class T> Archive &operator&(T &t) { return *(this->This()) >> t; }
Archive & operator&(T & t){
return *(this->This()) >> t;
}
// the == operator // the == operator
template <class T> template <class T> Archive &operator==(T &t) { return this->operator&(t); }
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access // the != operator for human readable access
template <class T> template <class T> Archive &operator!=(T &t) {
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return *this->This(); return *this->This();
} }
}; };
/** /**
* Custom implementation of boost interface_oarchive to add new operators * Custom implementation of boost interface_oarchive to add new operators
*/ */
template <class Archive> template <class Archive> class uLib_interface_oarchive {
class uLib_interface_oarchive {
protected: protected:
uLib_interface_oarchive() {}; uLib_interface_oarchive() {};
public: public:
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// archive public interface // archive public interface
@@ -212,32 +188,25 @@ public:
typedef mpl::bool_<true> is_saving; typedef mpl::bool_<true> is_saving;
// return a pointer to the most derived class // return a pointer to the most derived class
Archive * This(){ Archive *This() { return static_cast<Archive *>(this); }
return static_cast<Archive *>(this);
}
template <class T> template <class T>
const basic_pointer_oserializer * const basic_pointer_oserializer *register_type(const T * = NULL) {
register_type(const T * = NULL){ const basic_pointer_oserializer &bpos = boost::serialization::singleton<
const basic_pointer_oserializer & bpos = pointer_oserializer<Archive, T>>::get_const_instance();
boost::serialization::singleton<
pointer_oserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpos.get_basic_serializer()); this->This()->register_basic_serializer(bpos.get_basic_serializer());
return &bpos; return &bpos;
} }
template<class T> template <class T> Archive &operator<<(T &t) {
Archive & operator<<(T & t){
// to get access you must redefine save_override by typing // to get access you must redefine save_override by typing
// "using save_override" in archive impl // "using save_override" in archive impl
this->This()->save_override(t, 0); this->This()->save_override(t);
return *this->This(); return *this->This();
} }
// the & operator // the & operator
template<class T> template <class T> Archive &operator&(T &t) {
Archive & operator&(T & t){
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
return *this->This() << const_cast<const T &>(t); return *this->This() << const_cast<const T &>(t);
#else #else
@@ -246,45 +215,38 @@ public:
} }
// the == operator // the == operator
template <class T> template <class T> Archive &operator==(T &t) { return this->operator&(t); }
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access // the != operator for human readable access
template <class T> template <class T> Archive &operator!=(T &t) {
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return *this->This(); return *this->This();
} }
}; };
// DECLARE INTERFACE SPECIALIZATIONS /////////////////////////////////////////// // DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own // With this declarations all uLib archive Implementation will use their own
// extended interface // // extended interface //
template <> template <>
class interface_iarchive <uLib::Archive::xml_iarchive> : public class interface_iarchive<uLib::Archive::xml_iarchive>
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {}; : public uLib_interface_iarchive<uLib::Archive::xml_iarchive> {};
template <> template <>
class interface_oarchive <uLib::Archive::xml_oarchive> : public class interface_oarchive<uLib::Archive::xml_oarchive>
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {}; : public uLib_interface_oarchive<uLib::Archive::xml_oarchive> {};
template <> template <>
class interface_iarchive <uLib::Archive::text_iarchive> : public class interface_iarchive<uLib::Archive::text_iarchive>
uLib_interface_iarchive <uLib::Archive::text_iarchive> {}; : public uLib_interface_iarchive<uLib::Archive::text_iarchive> {};
template <> template <>
class interface_oarchive <uLib::Archive::text_oarchive> : public class interface_oarchive<uLib::Archive::text_oarchive>
uLib_interface_oarchive <uLib::Archive::text_oarchive> {}; : public uLib_interface_oarchive<uLib::Archive::text_oarchive> {};
template <> template <>
class interface_oarchive <uLib::Archive::log_archive> : public class interface_oarchive<uLib::Archive::log_archive>
uLib_interface_oarchive <uLib::Archive::log_archive> {}; : public uLib_interface_oarchive<uLib::Archive::log_archive> {};
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!! //// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
// #define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \ // #define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
@@ -299,22 +261,9 @@ class interface_oarchive <uLib::Archive::log_archive> : public
// #undef _INERIT_NOFOLD_H // #undef _INERIT_NOFOLD_H
// #undef _INERIT_NOFOLD_V // #undef _INERIT_NOFOLD_V
} // namespace detail
} // detail } // namespace archive
} // archive } // namespace boost
} // boost
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -332,8 +281,8 @@ namespace archive {
// template<class Archive> // template<class Archive>
// inline void load_const_override(Archive & ar, const char *t ){ // inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex; // typedef typename mpl::identity<detail::load_non_pointer_type<Archive>
// typex::invoke(ar, t); // >::type typex; typex::invoke(ar, t);
// } // }
// template<class Archive, class T> // template<class Archive, class T>
@@ -360,45 +309,36 @@ namespace archive {
// typex::invoke(ar, t); // typex::invoke(ar, t);
// } // }
} // namespace archive
} // namespace boost
}
}
namespace uLib { namespace uLib {
namespace Archive { namespace Archive {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// POLYMORPHIC // // POLYMORPHIC //
// class polymorphic_iarchive : // class polymorphic_iarchive :
// public boost::archive::polymorphic_iarchive { // public boost::archive::polymorphic_iarchive {
// public: // public:
// void load_override(const char *t, BOOST_PFTO int) // void load_override(const char *t, BOOST_PFTO int)
// { // {
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t)); // boost::archive::load_const_override(* this->This(),
// const_cast<char*>(t));
// } // }
//}; //};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// XML // // XML //
class xml_iarchive : class xml_iarchive : public boost::archive::xml_iarchive_impl<xml_iarchive> {
public boost::archive::xml_iarchive_impl<xml_iarchive>
{
typedef xml_iarchive Archive; typedef xml_iarchive Archive;
typedef boost::archive::xml_iarchive_impl<Archive> base; typedef boost::archive::xml_iarchive_impl<Archive> base;
@@ -406,36 +346,34 @@ class xml_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>; friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_xml_iarchive<Archive>; friend class boost::archive::basic_xml_iarchive<Archive>;
friend class boost::archive::load_access; friend class boost::archive::load_access;
public: public:
xml_iarchive(std::istream & is, unsigned int flags = 0) : xml_iarchive(std::istream &is, unsigned int flags = 0)
xml_iarchive_impl<xml_iarchive>(is, flags) : xml_iarchive_impl<xml_iarchive>(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 // Anything not an attribute should be a name value pair as nvp or hrp
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive; typedef boost::archive::detail::common_iarchive<Archive>
detail_common_iarchive;
template <class T> template <class T>
void load_override( void load_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const const
#endif #endif
boost::serialization::hrp< T > & t, boost::serialization::hrp<T> &t) {
int v
){
this->This()->load_start(t.name()); this->This()->load_start(t.name());
this->detail_common_iarchive::load_override(t.value(), 0); this->detail_common_iarchive::load_override(t.value());
// t.stov(); // t.stov();
this->This()->load_end(t.name()); this->This()->load_end(t.name());
} }
// class_name_type can't be handled here as it depends upon the // class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation. // char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base .. // derived in this case is xml_iarchive_impl or base ..
using base::load_override; using base::load_override;
void load_override(const char *str, int v) { void load_override(const char *str) {
// StringReader sr(basic_text_iprimitive::is); // StringReader sr(basic_text_iprimitive::is);
// sr >> str; // sr >> str;
} }
@@ -448,33 +386,23 @@ public:
//> polymorphic_xml_iarchive; //> polymorphic_xml_iarchive;
template <class ArchiveImpl> template <class ArchiveImpl>
struct polymorphic_iarchive_route : struct polymorphic_iarchive_route
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl> : boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl> {
{ virtual void load(const char *t) { ArchiveImpl::load(t); }
virtual void load(const char * t){
ArchiveImpl::load(t);
}
}; };
class polymorphic_xml_iarchive
class polymorphic_xml_iarchive : : public polymorphic_iarchive_route<
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> > boost::archive::xml_iarchive_impl<xml_iarchive>> {
{
// give serialization implementation access to this class // give serialization implementation access to this class
// friend class boost::archive::detail::interface_iarchive<Archive>; // friend class boost::archive::detail::interface_iarchive<Archive>;
// friend class boost::archive::basic_xml_iarchive<Archive>; // friend class boost::archive::basic_xml_iarchive<Archive>;
// friend class boost::archive::load_access; // friend class boost::archive::load_access;
public: 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<xml_oarchive> {
class xml_oarchive :
public boost::archive::xml_oarchive_impl<xml_oarchive>
{
typedef xml_oarchive Archive; typedef xml_oarchive Archive;
typedef boost::archive::xml_oarchive_impl<Archive> base; typedef boost::archive::xml_oarchive_impl<Archive> base;
@@ -482,10 +410,10 @@ class xml_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>; friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_xml_oarchive<Archive>; friend class boost::archive::basic_xml_oarchive<Archive>;
friend class boost::archive::save_access; friend class boost::archive::save_access;
public: public:
xml_oarchive(std::ostream & os, unsigned int flags = 0) : xml_oarchive(std::ostream &os, unsigned int flags = 0)
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags) : boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags) {}
{}
// example of implementing save_override for const char* // // example of implementing save_override for const char* //
// void save_override(const char *t, int) { // void save_override(const char *t, int) {
@@ -495,22 +423,21 @@ public:
using basic_xml_oarchive::save_override; using basic_xml_oarchive::save_override;
// special treatment for name-value pairs. // special treatment for name-value pairs.
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive; typedef boost::archive::detail::common_oarchive<Archive>
detail_common_oarchive;
template <class T> template <class T>
void save_override( void save_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const const
#endif #endif
::boost::serialization::hrp< T > & t, ::boost::serialization::hrp<T> &t) {
int v
){
this->This()->save_start(t.name()); this->This()->save_start(t.name());
// t.vtos(); // t.vtos();
// this->detail_common_oarchive::save_override(t.const_value(), 0); // this->detail_common_oarchive::save_override(t.const_value());
this->This()->save_end(t.name()); this->This()->save_end(t.name());
} }
void save_override(const char *str, int v) { void save_override(const char *str) {
// Do not save any human decoration string // // Do not save any human decoration string //
// basic_text_oprimitive::save(str); // basic_text_oprimitive::save(str);
} }
@@ -527,9 +454,7 @@ public:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TEXT // // TEXT //
class text_iarchive : class text_iarchive : public boost::archive::text_iarchive_impl<text_iarchive> {
public boost::archive::text_iarchive_impl<text_iarchive>
{
typedef text_iarchive Archive; typedef text_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base; typedef boost::archive::text_iarchive_impl<Archive> base;
@@ -537,21 +462,21 @@ class text_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>; friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>; friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access; friend class boost::archive::load_access;
public: public:
text_iarchive(std::istream & is, unsigned int flags = 0) : text_iarchive(std::istream &is, unsigned int flags = 0)
text_iarchive_impl<Archive>(is, flags) : text_iarchive_impl<Archive>(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 // class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation. // char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base .. // derived in this case is xml_iarchive_impl or base ..
using base::load_override; using base::load_override;
void load_override(const char *str, int v) { void load_override(const char *str) {
StringReader sr(basic_text_iprimitive::is); StringReader sr(basic_text_iprimitive::is);
sr >> str; sr >> str;
} }
@@ -565,11 +490,7 @@ typedef text_iarchive naked_text_iarchive;
// naked_text_iarchive // naked_text_iarchive
//> polymorphic_text_iarchive; //> polymorphic_text_iarchive;
class text_oarchive : public boost::archive::text_oarchive_impl<text_oarchive> {
class text_oarchive :
public boost::archive::text_oarchive_impl<text_oarchive>
{
typedef text_oarchive Archive; typedef text_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base; typedef boost::archive::text_oarchive_impl<Archive> base;
@@ -577,16 +498,14 @@ class text_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>; friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>; friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access; friend class boost::archive::save_access;
public: public:
text_oarchive(std::ostream & os, unsigned int flags = 0) : text_oarchive(std::ostream &os, unsigned int flags = 0)
boost::archive::text_oarchive_impl<Archive>(os, flags) : boost::archive::text_oarchive_impl<Archive>(os, flags) {}
{}
using basic_text_oarchive::save_override; using basic_text_oarchive::save_override;
void save_override(const char *str, int v) { void save_override(const char *str) { basic_text_oprimitive::save(str); }
basic_text_oprimitive::save(str);
}
~text_oarchive() {} ~text_oarchive() {}
}; };
@@ -595,15 +514,12 @@ public:
// boost::archive::text_oarchive_impl<text_oarchive> // boost::archive::text_oarchive_impl<text_oarchive>
//> polymorphic_text_oarchive; //> polymorphic_text_oarchive;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SIMPLE HUMAN READABLE TEXT // // SIMPLE HUMAN READABLE TEXT //
class hrt_iarchive : class hrt_iarchive : public boost::archive::text_iarchive_impl<hrt_iarchive> {
public boost::archive::text_iarchive_impl<hrt_iarchive>
{
typedef hrt_iarchive Archive; typedef hrt_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base; typedef boost::archive::text_iarchive_impl<Archive> base;
@@ -611,29 +527,29 @@ class hrt_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>; friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>; friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access; friend class boost::archive::load_access;
public: public:
hrt_iarchive(std::istream & is, unsigned int flags = 0) : hrt_iarchive(std::istream &is, unsigned int flags = 0)
base(is, flags | boost::archive::no_header ) : base(is, flags | boost::archive::no_header) {}
{}
using basic_text_iarchive::load_override; using basic_text_iarchive::load_override;
// hide all archive props // // hide all archive props //
void load_override( boost::archive::object_id_type & t, int) {} void load_override(boost::archive::object_id_type &t) {}
void load_override( boost::archive::object_reference_type & t, int) {} void load_override(boost::archive::object_reference_type &t) {}
void load_override( boost::archive::version_type & t, int) {} void load_override(boost::archive::version_type &t) {}
void load_override( boost::archive::class_id_type & t, int) {} void load_override(boost::archive::class_id_type &t) {}
void load_override( boost::archive::class_id_optional_type & t, int) {} void load_override(boost::archive::class_id_optional_type &t) {}
void load_override( boost::archive::class_id_reference_type & t, int){} void load_override(boost::archive::class_id_reference_type &t) {}
void load_override( boost::archive::class_name_type & t, int) {} void load_override(boost::archive::class_name_type &t) {}
void load_override( boost::archive::tracking_type & t, int) {} void load_override(boost::archive::tracking_type &t) {}
// class_name_type can't be handled here as it depends upon the // class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation. // char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base .. // derived in this case is xml_iarchive_impl or base ..
using base::load_override; using base::load_override;
void load_override(const char *str, int v) { void load_override(const char *str) {
StringReader sr(basic_text_iprimitive::is); StringReader sr(basic_text_iprimitive::is);
sr >> str; sr >> str;
} }
@@ -641,10 +557,7 @@ public:
~hrt_iarchive() {}; ~hrt_iarchive() {};
}; };
class hrt_oarchive : public boost::archive::text_oarchive_impl<hrt_oarchive> {
class hrt_oarchive :
public boost::archive::text_oarchive_impl<hrt_oarchive>
{
typedef hrt_oarchive Archive; typedef hrt_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base; typedef boost::archive::text_oarchive_impl<Archive> base;
@@ -652,33 +565,27 @@ class hrt_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>; friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>; friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access; friend class boost::archive::save_access;
public: public:
hrt_oarchive(std::ostream & os, unsigned int flags = 0) : hrt_oarchive(std::ostream &os, unsigned int flags = 0)
base(os, flags | boost::archive::no_header ) : base(os, flags | boost::archive::no_header) {}
{}
using basic_text_oarchive::save_override; using basic_text_oarchive::save_override;
void save_override(const boost::archive::object_id_type & t, int) {} void save_override(const boost::archive::object_id_type &t) {}
void save_override(const boost::archive::object_reference_type & t, int) {} void save_override(const boost::archive::object_reference_type &t) {}
void save_override(const boost::archive::version_type & t, int) {} void save_override(const boost::archive::version_type &t) {}
void save_override(const boost::archive::class_id_type & t, int) {} void save_override(const boost::archive::class_id_type &t) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {} void save_override(const boost::archive::class_id_optional_type &t) {}
void save_override(const boost::archive::class_id_reference_type & t, int){} void save_override(const boost::archive::class_id_reference_type &t) {}
void save_override(const boost::archive::class_name_type & t, int) {} void save_override(const boost::archive::class_name_type &t) {}
void save_override(const boost::archive::tracking_type & t, int) {} void save_override(const boost::archive::tracking_type &t) {}
void save_override(const char *str) { basic_text_oprimitive::save(str); }
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
~hrt_oarchive() {} ~hrt_oarchive() {}
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -690,8 +597,7 @@ class hrt_oarchive :
// any serializable class. Intended to be useful as a debugging aid. // any serializable class. Intended to be useful as a debugging aid.
class log_archive : class log_archive :
/* protected ? */ /* protected ? */
public boost::archive::xml_oarchive_impl<log_archive> public boost::archive::xml_oarchive_impl<log_archive> {
{
typedef boost::archive::xml_oarchive_impl<log_archive> base; typedef boost::archive::xml_oarchive_impl<log_archive> base;
typedef log_archive Archive; typedef log_archive Archive;
// give serialization implementation access to this clas // give serialization implementation access to this clas
@@ -700,66 +606,52 @@ class log_archive :
friend class boost::archive::save_access; friend class boost::archive::save_access;
public: public:
void save_override(const char *str) {
void save_override(const char *str, int v) {
// Do not save any human decoration string // // Do not save any human decoration string //
// basic_text_oprimitive::save(str); // basic_text_oprimitive::save(str);
} }
template<class T> template <class T> void save_override(T &t) {
void save_override(T & t, BOOST_PFTO int){ base::save_override(boost::serialization::make_nvp(NULL, t));
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
} }
// activate this if you want to trap non nvp objects // // activate this if you want to trap non nvp objects //
// template<class T> // template<class T>
// void save_override(T & t, BOOST_PFTO int) // void save_override(T & t)
// { // {
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >)); // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // this->detail_common_oarchive::save_override(t, 0); // // this->detail_common_oarchive::save_override(t);
// } // }
template<class T> template <class T> void save_override(const boost::serialization::nvp<T> &t) {
void save_override(const boost::serialization::nvp<T> & t, int){ base::save_override(t);
base::save_override(t, 0);
} }
// specific overrides for attributes - not name value pairs so we // specific overrides for attributes - not name value pairs so we
// want to trap them before the above "fall through" // want to trap them before the above "fall through"
// since we don't want to see these in the output - make them no-ops. // 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_id_type &t) {}
void save_override(const boost::archive::object_reference_type & t, int) {} void save_override(const boost::archive::object_reference_type &t) {}
void save_override(const boost::archive::version_type & t, int) {} void save_override(const boost::archive::version_type &t) {}
void save_override(const boost::archive::class_id_type & t, int) {} void save_override(const boost::archive::class_id_type &t) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {} void save_override(const boost::archive::class_id_optional_type &t) {}
void save_override(const boost::archive::class_id_reference_type & t, int){} void save_override(const boost::archive::class_id_reference_type &t) {}
void save_override(const boost::archive::class_name_type & t, int) {} void save_override(const boost::archive::class_name_type &t) {}
void save_override(const boost::archive::tracking_type & t, int) {} void save_override(const boost::archive::tracking_type &t) {}
public: public:
log_archive(std::ostream & os, unsigned int flags = 0) : log_archive(std::ostream &os, unsigned int flags = 0)
boost::archive::xml_oarchive_impl<log_archive>( : boost::archive::xml_oarchive_impl<log_archive>(
os, os, flags | boost::archive::no_header) {}
flags | boost::archive::no_header
)
{}
}; };
// typedef boost::archive::detail::polymorphic_oarchive_route< // typedef boost::archive::detail::polymorphic_oarchive_route<
// boost::archive::xml_oarchive_impl<log_archive> // boost::archive::xml_oarchive_impl<log_archive>
//> polymorphic_log_archive; //> polymorphic_log_archive;
} // namespace Archive
} // namespace uLib
} // Archive
} // uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive) ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive) ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
@@ -775,7 +667,4 @@ ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
// ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive) // 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_log_archive)
#endif // U_CORE_ARCHIVES_H #endif // U_CORE_ARCHIVES_H

View File

@@ -1,10 +1,9 @@
set(HEADERS Options.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)
StaticInterface.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(libname ${PACKAGE_LIBPREFIX}Core)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE) 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) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -23,60 +23,51 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_EXPORT_H #ifndef U_CORE_EXPORT_H
#define U_CORE_EXPORT_H #define U_CORE_EXPORT_H
#include <utility>
#include <cstddef> // NULL #include <cstddef> // NULL
#include <iostream> #include <iostream>
#include <utility>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_polymorphic.hpp> #include <boost/type_traits/is_polymorphic.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/and.hpp> #include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp> #include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/mpl/not.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/assume_abstract.hpp>
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
#include <boost/serialization/force_include.hpp> #include <boost/serialization/force_include.hpp>
#include <boost/serialization/singleton.hpp> #include <boost/serialization/singleton.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/archive/detail/register_archive.hpp> #include <boost/archive/detail/register_archive.hpp>
#include "Core/Archives.h" #include "Core/Archives.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace uLib { namespace uLib {
namespace Archive { namespace Archive {
namespace detail { namespace detail {
namespace extra_detail { namespace extra_detail {
template<class T> template <class T> struct guid_initializer {
struct guid_initializer void export_guid(boost::mpl::false_) const {
{
void export_guid(mpl::false_) const {
// generates the statically-initialized objects whose constructors // generates the statically-initialized objects whose constructors
// register the information allowing serialization of T objects // register the information allowing serialization of T objects
// through pointers to their base classes. // through pointers to their base classes.
boost::archive::detail:: boost::archive::detail::instantiate_ptr_serialization(
instantiate_ptr_serialization((T*)0, 0, (T *)0, 0, uLib::Archive::detail::adl_tag());
uLib::Archive::detail::adl_tag());
}
void export_guid(mpl::true_) const {
} }
void export_guid(boost::mpl::true_) const {}
guid_initializer const &export_guid() const { guid_initializer const &export_guid() const {
BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value); BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
// note: exporting an abstract base class will have no effect // note: exporting an abstract base class will have no effect
@@ -88,30 +79,29 @@ struct guid_initializer
} }
}; };
template<typename T> template <typename T> struct init_guid;
struct init_guid;
} // anonymous } // namespace extra_detail
} // namespace detail } // namespace detail
} // namespace Archive } // namespace Archive
} // namespace uLib } // namespace uLib
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \ #define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
namespace uLib { \ namespace uLib { \
namespace Archive { \ namespace Archive { \
namespace detail { \ namespace detail { \
namespace extra_detail { \ namespace extra_detail { \
template<> \ template <> struct init_guid<T> { \
struct init_guid< T > { \
static guid_initializer<T> const &g; \ static guid_initializer<T> const &g; \
}; \ }; \
guid_initializer<T> const &init_guid<T>::g = \ guid_initializer<T> const &init_guid<T>::g = \
::boost::serialization::singleton< \ ::boost::serialization::singleton< \
guid_initializer< T > \ guid_initializer<T>>::get_mutable_instance() \
>::get_mutable_instance().export_guid(); \ .export_guid(); \
}}}} \ } \
} \
} \
} \
/**/ /**/
#endif // EXPORT_H #endif // EXPORT_H

View File

@@ -110,11 +110,13 @@ bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr,
const char *name) { const char *name) {
ObjectPrivate::Signal s = {fptr, std::string(name), sig}; ObjectPrivate::Signal s = {fptr, std::string(name), sig};
d->sigv.push_back(s); d->sigv.push_back(s);
return true;
} }
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) { bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) {
ObjectPrivate::Slot s = {fptr, std::string(name)}; ObjectPrivate::Slot s = {fptr, std::string(name)};
d->slov.push_back(s); d->slov.push_back(s);
return true;
} }
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const { SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const {

View File

@@ -107,6 +107,7 @@ public:
// if(sig && slo) // if(sig && slo)
// return Object::connect(sig,slo->operator ()(),receiver); // return Object::connect(sig,slo->operator ()(),receiver);
// else return false; // else return false;
return false;
} }
// Qt5 style connector // // Qt5 style connector //
@@ -119,11 +120,13 @@ public:
typename FunctionPointer<Func2>::SignalSignature> typename FunctionPointer<Func2>::SignalSignature>
SigT; SigT;
ConnectSignal(sigb, slof, receiver); ConnectSignal(sigb, slof, receiver);
return true;
} }
template <typename FuncT> template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) { static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal(sigb, slof, receiver); ConnectSignal(sigb, slof, receiver);
return true;
} }
template <typename FuncT> template <typename FuncT>
@@ -139,7 +142,7 @@ public:
} }
template <typename FuncT> inline bool addSlot(FuncT fun, const char *name) { template <typename FuncT> inline bool addSlot(FuncT fun, const char *name) {
this->addSlotImpl(GenericMFPtr(fun), name); return this->addSlotImpl(GenericMFPtr(fun), name);
} }
template <typename FuncT> template <typename FuncT>

View File

@@ -23,21 +23,19 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SIGNAL_H #ifndef U_CORE_SIGNAL_H
#define U_CORE_SIGNAL_H #define U_CORE_SIGNAL_H
#include <boost/typeof/typeof.hpp> #include <boost/typeof/typeof.hpp>
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#include <boost/signals2/slot.hpp>
#include <boost/signals2/signal_type.hpp> #include <boost/signals2/signal_type.hpp>
#include <boost/signals2/slot.hpp>
#include "Function.h" #include "Function.h"
#include <boost/bind/bind.hpp>
using namespace boost::placeholders;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -67,102 +65,104 @@
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0)); * static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
* sig->operator()(); * 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 { namespace uLib {
// A boost::signal wrapper structure /////////////////////////////////////////// // A boost::signal wrapper structure ///////////////////////////////////////////
// TODO ... // TODO ...
typedef boost::signals2::signal_base SignalBase; typedef boost::signals2::signal_base SignalBase;
template <typename T> template <typename T> struct Signal {
struct Signal {
typedef boost::signals2::signal<T> type; typedef boost::signals2::signal<T> type;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace detail { namespace detail {
template <typename FuncT, int arity> struct ConnectSignal {};
template <typename FuncT, int arity> template <typename FuncT> struct ConnectSignal<FuncT, 0> {
struct ConnectSignal {}; static void connect(SignalBase *sigb, FuncT slof,
typename FunctionPointer<FuncT>::Object *receiver) {
template <typename FuncT> typedef
struct ConnectSignal< FuncT, 0 > { typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { SigT;
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT *>(sigb)->connect(slof); reinterpret_cast<SigT *>(sigb)->connect(slof);
} }
}; };
template <typename FuncT> template <typename FuncT> struct ConnectSignal<FuncT, 1> {
struct ConnectSignal< FuncT, 1 > { static void connect(SignalBase *sigb, FuncT slof,
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typedef
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver)); reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver));
} }
}; };
template <typename FuncT> template <typename FuncT> struct ConnectSignal<FuncT, 2> {
struct ConnectSignal< FuncT, 2 > { static void connect(SignalBase *sigb, FuncT slof,
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typedef
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver, _1)); reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver, _1));
} }
}; };
template <typename FuncT> template <typename FuncT> struct ConnectSignal<FuncT, 3> {
struct ConnectSignal< FuncT, 3 > { static void connect(SignalBase *sigb, FuncT slof,
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typedef
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2)); typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2));
} }
}; };
template <typename FuncT> template <typename FuncT> struct ConnectSignal<FuncT, 4> {
struct ConnectSignal< FuncT, 4 > { static void connect(SignalBase *sigb, FuncT slof,
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typedef
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3)); typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2, _3));
} }
}; };
template <typename FuncT> template <typename FuncT> struct ConnectSignal<FuncT, 5> {
struct ConnectSignal< FuncT, 5 > { static void connect(SignalBase *sigb, FuncT slof,
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typedef
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4)); typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2, _3, _4));
} }
}; };
} // namespace detail
} // detail template <typename FuncT> SignalBase *NewSignal(FuncT f) {
template <typename FuncT>
SignalBase *NewSignal(FuncT f) {
// seems to work wow ! // seems to work wow !
return new Signal<void()>::type; return new Signal<void()>::type;
} }
template <typename FuncT> template <typename FuncT>
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) void ConnectSignal(SignalBase *sigb, FuncT slof,
{ typename FunctionPointer<FuncT>::Object *receiver) {
detail::ConnectSignal< FuncT, FunctionPointer<FuncT>::arity >::connect(sigb,slof,receiver); detail::ConnectSignal<FuncT, FunctionPointer<FuncT>::arity>::connect(
sigb, slof, receiver);
} }
} // namespace uLib
} // uLib
#endif // SIGNAL_H #endif // SIGNAL_H

View File

@@ -24,9 +24,8 @@ set( TESTS
set(LIBRARIES set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
${Boost_SERIALIZATION_LIBRARY} Boost::serialization
${Boost_SIGNALS_LIBRARY} Boost::program_options
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
) )
uLib_add_tests(${uLib-module}) uLib_add_tests(Core)

View File

@@ -23,13 +23,10 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream> #include <fstream>
#include <typeinfo> #include <iostream>
#include <string> #include <string>
#include <typeinfo>
#include "Core/Object.h" #include "Core/Object.h"
@@ -37,37 +34,24 @@
using namespace uLib; using namespace uLib;
struct A : Object { struct A : Object {
uLibTypeMacro(A,Object) uLibTypeMacro(A, Object) A() : numa(5552368) {}
A() : numa(5552368) {}
int numa; int numa;
}; };
ULIB_SERIALIZABLE_OBJECT(A) ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) { ULIB_SERIALIZE_OBJECT(A, Object) { ar &AR(numa); }
ar & AR(numa);
}
struct B : virtual Object { struct B : virtual Object {
uLibTypeMacro(B,Object) uLibTypeMacro(B, Object) B() : numb(5552369) {}
B() : numb(5552369) {}
int numb; int numb;
}; };
ULIB_SERIALIZABLE_OBJECT(B) ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B, Object) { ar &AR(numb); } ULIB_SERIALIZE_OBJECT(B, Object) { ar &AR(numb); }
struct C : B { struct C : B {
uLibTypeMacro(C,B) uLibTypeMacro(C, B) C() : numc(5552370) {}
C() : numc(5552370) {}
int numc; int numc;
}; };
@@ -77,38 +61,16 @@ ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
struct D : A, B { struct D : A, B {
uLibTypeMacro(D, A, B) uLibTypeMacro(D, A, B)
D() : numd(5552371) {} D()
: numd(5552371) {}
int numd; int numd;
}; };
ULIB_SERIALIZABLE_OBJECT(D) 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);
} }

View File

@@ -23,20 +23,16 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include "Core/Object.h"
#include "Core/Archives.h" #include "Core/Archives.h"
#include "Core/Object.h"
#include "testing-prototype.h" #include "testing-prototype.h"
using namespace uLib; using namespace uLib;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -46,48 +42,40 @@ using namespace uLib;
struct V3f { struct V3f {
float x, y, z; float x, y, z;
V3f() V3f() { x = y = z = 0; }
{ x = y = z =0; }
V3f(float x, float y, float z) : V3f(float x, float y, float z) : x(x), y(y), z(z) {}
x(x), y(y), z(z) {}
template <class Archive> template <class Archive> void serialize(Archive &ar, unsigned int v) {
void serialize (Archive &ar,unsigned int v) { ar & "<" & NVP(x) & NVP(y) & NVP(z) & ">";
ar
& "<" & NVP(x) & NVP(y) & NVP(z) & ">";
} }
}; };
ULIB_CLASS_EXPORT_KEY(V3f); ULIB_CLASS_EXPORT_KEY(V3f);
ULIB_CLASS_EXPORT_IMPLEMENT(V3f); ULIB_CLASS_EXPORT_IMPLEMENT(V3f);
inline std::ostream &operator<<(std::ostream &o, const V3f &v) {
inline std::ostream &
operator <<(std::ostream &o, const V3f &v) {
Archive::hrt_oarchive(o) << v; Archive::hrt_oarchive(o) << v;
return o; return o;
} }
inline std::istream & inline std::istream &operator>>(std::istream &is, V3f &v) {
operator >>(std::istream &is, V3f &v) {
Archive::hrt_iarchive(is) >> v; Archive::hrt_iarchive(is) >> v;
return is; return is;
} }
int test_V3f() { 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; V3f v1(1, 2, 3), v2, v3, v4;
std::cout << "v --> " << v1 << "\n"; std::cout << "v --> " << v1 << "\n";
std::stringstream ss; ss << v1; std::stringstream ss;
ss << v1;
std::cout << "ss.v --> " << ss.str() << "\n"; std::cout << "ss.v --> " << ss.str() << "\n";
Archive::hrt_iarchive ar(ss); ar >> v2; Archive::hrt_iarchive ar(ss);
ar >> v2;
std::cout << "v2 --> " << v2 << "\n"; std::cout << "v2 --> " << v2 << "\n";
std::stringstream("<2 3 4>") >> v3; std::stringstream("<2 3 4>") >> v3;
@@ -98,10 +86,6 @@ int test_V3f() {
return (1); return (1);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -109,70 +93,56 @@ int test_V3f() {
// OBJECT SERIALIZATION // // OBJECT SERIALIZATION //
class A : public virtual Object { class A : public virtual Object {
uLibTypeMacro(A,Object) uLibTypeMacro(A, Object) ULIB_SERIALIZE_ACCESS public : A() : m_a(5552368) {}
ULIB_SERIALIZE_ACCESS
public:
A() : m_a(5552368) {}
properties() { void init_properties();
std::string p_a; std::string p_a;
};
uLibRefMacro(a, int); uLibRefMacro(a, int);
private: private:
int m_a; int m_a;
}; };
void A::init_properties() { void A::init_properties() { p_a = "A property string"; }
$_init();
$$.p_a = "A property string";
}
ULIB_SERIALIZABLE_OBJECT(A) ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A, Object) { ULIB_SERIALIZE_OBJECT(A, Object) {
ar ar & "Object A : " & "--> m_a = " & AR(m_a) & "\n" & "Object A properties: " &
& "Object A : " "---> p_a = " & AR(p_a) & "\n";
& "--> m_a = " & AR(m_a)
& "\n";
} }
ULIB_SERIALIZE_OBJECT_PROPS(A) {
ar
& "Object A properties: "
& "---> p_a = " & AR(p_a) & "\n";
}
int testing_xml_class() { int testing_xml_class() {
A a; a.init_properties(); A a;
a.init_properties();
{ {
std::ofstream file("test.xml"); std::ofstream file("test.xml");
Archive::xml_oarchive(file) << NVP(a); Archive::xml_oarchive(file) << NVP(a);
} }
a.a() = 0; a.a() = 0;
a.$$.p_a = "zero string"; a.p_a = "zero string";
{ {
std::ifstream file("test.xml"); std::ifstream file("test.xml");
Archive::xml_iarchive(file) >> NVP(a); Archive::xml_iarchive(file) >> NVP(a);
} }
Archive::xml_oarchive(std::cout) << NVP(a); Archive::xml_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); return (a.a() == 5552368 && a.p_a == "A property string");
} }
int testing_hrt_class() { int testing_hrt_class() {
A a; a.init_properties(); A a;
a.init_properties();
{ {
std::ofstream file("test.xml"); std::ofstream file("test.xml");
Archive::hrt_oarchive(file) << NVP(a); Archive::hrt_oarchive(file) << NVP(a);
} }
a.a() = 0; a.a() = 0;
a.$$.p_a = "zero string"; a.p_a = "zero string";
{ {
// ERRORE FIX ! // ERRORE FIX !
// std::ifstream file("test.xml"); // std::ifstream file("test.xml");
@@ -180,14 +150,9 @@ int testing_hrt_class() {
} }
Archive::hrt_oarchive(std::cout) << NVP(a); Archive::hrt_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); return (a.a() == 5552368 && a.p_a == "A property string");
} }
int main() { int main() {
BEGIN_TESTING(Serialize Test); BEGIN_TESTING(Serialize Test);
@@ -197,16 +162,3 @@ int main() {
END_TESTING; END_TESTING;
} }

View File

@@ -23,16 +23,11 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream> #include <iostream>
#include "testing-prototype.h" #include "testing-prototype.h"
#include <Core/StaticInterface.h> #include <Core/StaticInterface.h>
namespace uLib { namespace uLib {
//// INTERFACE TO COMPLEX CLASS ///// //// INTERFACE TO COMPLEX CLASS /////
@@ -45,15 +40,13 @@ struct Test {
uLibCheckMember(Self, testmemb, int); uLibCheckMember(Self, testmemb, int);
} }
}; };
} } // namespace Interface
struct Test { struct Test {
bool test(int i, float f){} bool test(int i, float f) { return true; }
int testmemb; int testmemb;
}; };
//// INTERFAC TO SIMPLE CLASS /////////// //// INTERFAC TO SIMPLE CLASS ///////////
namespace Interface { namespace Interface {
@@ -64,49 +57,39 @@ struct Simple {
uLibCheckMember(Self, memb2, float); uLibCheckMember(Self, memb2, float);
} }
}; };
} } // namespace Interface
struct Simple { struct Simple {
int memb1; int memb1;
float memb2; float memb2;
}; };
///////////////////////// /////////////////////////
template <class T> template <class T> class UseTest {
class UseTest {
public: public:
UseTest() { UseTest() {
Interface::IsA<T, Interface::Test>(); Interface::IsA<T, Interface::Test>();
T t; T t;
int i; float f; int i;
float f;
t.test(i, f); t.test(i, f);
} }
}; };
template <class T> template <class T> class UseSimple {
class UseSimple {
public: public:
UseSimple() { UseSimple() { Interface::IsA<T, Interface::Simple>(); }
Interface::IsA<T,Interface::Simple>();
}
}; };
} // namespace uLib
int main() {
}
int main()
{
BEGIN_TESTING(Static Interface); BEGIN_TESTING(Static Interface);
uLib::UseTest<uLib::Test> u; uLib::UseTest<uLib::Test> u;
uLib::UseSimple<uLib::Simple> s; uLib::UseSimple<uLib::Simple> s;
END_TESTING; END_TESTING;
} }

View File

@@ -5,3 +5,8 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
install(FILES ${HEADERS} install(FILES ${HEADERS}
DESTINATION ${INSTALL_INC_DIR}/Detectors) DESTINATION ${INSTALL_INC_DIR}/Detectors)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -1,18 +1,15 @@
# TESTS # TESTS
set( TESTS set( TESTS
GDMLSolidTest # GDMLSolidTest
HierarchicalEncodingTest HierarchicalEncodingTest
) )
#set(LIBRARIES set(LIBRARIES
# ${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
# ${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
# ${PACKAGE_LIBPREFIX}Detectors Boost::serialization
# ${Boost_SERIALIZATION_LIBRARY} Boost::program_options
# ${Boost_SIGNALS_LIBRARY} Eigen3::Eigen
# ${Boost_PROGRAM_OPTIONS_LIBRARY} ${ROOT_LIBRARIES}
# ${Eigen_LIBRARY} )
# ${Geant4_LIBRARIES} uLib_add_tests(Detectors)
# ${ROOT_LIBRARIES}
#)
uLib_add_tests(${uLib-module})

View File

@@ -54,7 +54,8 @@ install(TARGETS ${libname}
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math)
# TESTING if(BUILD_TESTING)
# include(uLibTargetMacros) include(uLibTargetMacros)
# add_subdirectory(testing) add_subdirectory(testing)
endif()

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "Math/Accumulator.h" #include "Math/Accumulator.h"
#include "testing-prototype.h" #include "testing-prototype.h"
#include <TRandom.h> #include <TRandom.h>
#include <iostream>
#include <vector>
// #include <boost/accumulators/framework/accumulator_set.hpp> // #include <boost/accumulators/framework/accumulator_set.hpp>
// #include <boost/accumulators/statistics/count.hpp> // #include <boost/accumulators/statistics/count.hpp>
@@ -45,7 +43,8 @@ int test_ABTrim() {
acc.SetABTrim(1, 1); acc.SetABTrim(1, 1);
std::vector<float> v; std::vector<float> v;
for(float tmpf : {1,5,5,5,300}) v.push_back(tmpf); for (float tmpf : {1, 5, 5, 5, 300})
v.push_back(tmpf);
// v << 1,5,5,5,300; // v << 1,5,5,5,300;
for (std::vector<float>::iterator itr = v.begin(); itr < v.end(); itr++) for (std::vector<float>::iterator itr = v.begin(); itr < v.end(); itr++)
@@ -56,50 +55,53 @@ int test_ABTrim() {
// << v << " ... out = " << acc() << "\n"; // << v << " ... out = " << acc() << "\n";
return (acc() == 15.0); return (acc() == 15.0);
} }
int test_Mean() { int test_Mean() {
Accumulator_Mean<float> mean; Accumulator_Mean<float> mean;
TRandom rnd; TRandom rnd;
const int c = 10000000; const int c = 10000000;
std::vector<float> v; std::vector<float> v;
v.reserve(c); v.reserve(c);
for(int i=0;i<c;++i) v.push_back( rnd.Gaus(2000,5) ); for (int i = 0; i < c; ++i)
v.push_back(rnd.Gaus(2000, 5));
float m = 0; float m = 0;
for(int i=0;i<c;++i) m += v[i]; for (int i = 0; i < c; ++i)
m += v[i];
m /= c; m /= c;
std::cout << "simple mean: " << m << "\n"; std::cout << "simple mean: " << m << "\n";
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
mean.AddPass(); mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]); for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n"; std::cout << "mean pass: " << mean() << "\n";
return 1;
} }
int main(void) { int main(void) {
BEGIN_TESTING(Accumulator); BEGIN_TESTING(Accumulator);

View File

@@ -17,6 +17,8 @@ set(TESTS
set(LIBRARIES set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
Boost::serialization
Eigen3::Eigen
) )
uLib_add_tests(Math) uLib_add_tests(Math)

View File

@@ -23,18 +23,14 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h" #include "testing-prototype.h"
#include "Math/TriangleMesh.h" #include "Math/TriangleMesh.h"
#include <iostream>
using namespace uLib; using namespace uLib;
int main() int main() {
{
BEGIN_TESTING(Triangle Mesh); BEGIN_TESTING(Triangle Mesh);
TriangleMesh mesh; TriangleMesh mesh;
@@ -45,7 +41,6 @@ int main()
mesh.AddTriangle(Vector3i(0, 1, 2)); mesh.AddTriangle(Vector3i(0, 1, 2));
mesh.PrintSelf(std::cout); mesh.PrintSelf(std::cout);
END_TESTING; END_TESTING;

View File

@@ -23,18 +23,14 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Math/VoxRaytracer.h" #include "Math/VoxRaytracer.h"
#include "Math/StructuredGrid.h"
#include "testing-prototype.h" #include "testing-prototype.h"
#include <iostream>
using namespace uLib; using namespace uLib;
int Vector4f0(Vector4f c) {
int Vector4f0(Vector4f c)
{
c(3) = 0; 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; return 0;
@@ -50,11 +46,9 @@ int Vector4f0(Vector4f c)
// return out == 0; // return out == 0;
// } // }
typedef VoxRaytracer Raytracer; typedef VoxRaytracer Raytracer;
int main() int main() {
{
BEGIN_TESTING(Math VoxRaytracer); BEGIN_TESTING(Math VoxRaytracer);
StructuredGrid img(Vector3i(2, 2, 2)); StructuredGrid img(Vector3i(2, 2, 2));
@@ -93,14 +87,13 @@ int main()
TEST1(ray.GetEntryPoint(line, pt)); TEST1(ray.GetEntryPoint(line, pt));
TEST1(pt == HPoint3f(-3, -3, -3)); TEST1(pt == HPoint3f(-3, -3, -3));
Raytracer::RayData rdata = ray.TraceBetweenPoints(HPoint3f(-3,-3,-3), HPoint3f(3,3,3)); Raytracer::RayData rdata =
for(const Raytracer::RayData::Element &el : rdata.Data()) 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"; std::cout << " " << el.vox_id << " , " << el.L << "\n";
} }
} }
{ {
HPoint3f pt1(1, -0.5, 1); HPoint3f pt1(1, -0.5, 1);
HPoint3f pt2(1, 4.5, 1); HPoint3f pt2(1, 4.5, 1);
@@ -141,11 +134,3 @@ int main()
END_TESTING END_TESTING
} }

View File

@@ -62,4 +62,7 @@ install(TARGETS ${libname}
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -8,9 +8,8 @@ set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
${PACKAGE_LIBPREFIX}Root ${PACKAGE_LIBPREFIX}Root
${Boost_SERIALIZATION_LIBRARY} Boost::serialization
${Boost_SIGNALS_LIBRARY} Boost::program_options
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
) )
uLib_add_tests(${uLib-module}) uLib_add_tests(Root)

View File

@@ -36,3 +36,7 @@ install(TARGETS ${libname}
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -14,5 +14,5 @@ set(LIBRARIES
${PACKAGE_LIBPREFIX}Vtk ${PACKAGE_LIBPREFIX}Vtk
) )
include(${VTK_USE_FILE}) # include(${VTK_USE_FILE})
uLib_add_tests(${uLib-module}) uLib_add_tests(Vtk)

View File

@@ -67,9 +67,8 @@ if(ULIB_FOUND)
############################################################################ ############################################################################
# MANUAL INLCLUDE EXTERNAL DEPENDENCIES # MANUAL INLCLUDE EXTERNAL DEPENDENCIES
# ${Boost_SERIALIZATION_LIBRARY} # Boost::serialization
# ${Boost_SIGNALS_LIBRARY} # Boost::program_options
# ${Boost_PROGRAM_OPTIONS_LIBRARY}
# ${Geant4_LIBRARIES} # ${Geant4_LIBRARIES}
# ${ROOT_LIBRARIES} # ${ROOT_LIBRARIES}
# ${VTK_LIBRARIES} # all VTK libs # ${VTK_LIBRARIES} # all VTK libs