[uLib Geometry]

non working version!

+ adds ProgrammableAccessor
+ renaming of some Image structures ...
This commit is contained in:
Andrea Rigoni
2014-11-03 10:27:52 +00:00
commit 99e771a223
403 changed files with 61684 additions and 0 deletions

92
src/Core/Archives.cpp Normal file
View File

@@ -0,0 +1,92 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Core/Archives.h"
//#define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/archive_serializer_map.hpp>
// explicitly instantiate for this type of xml stream
#include <boost/archive/impl/archive_serializer_map.ipp>
#include <boost/archive/impl/basic_xml_oarchive.ipp>
#include <boost/archive/impl/xml_oarchive_impl.ipp>
#include <boost/archive/impl/basic_xml_iarchive.ipp>
#include <boost/archive/impl/xml_iarchive_impl.ipp>
#include <boost/archive/impl/basic_text_oarchive.ipp>
#include <boost/archive/impl/text_oarchive_impl.ipp>
#include <boost/archive/impl/basic_text_iarchive.ipp>
#include <boost/archive/impl/text_iarchive_impl.ipp>
#include <boost/archive/polymorphic_xml_oarchive.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
namespace boost {
namespace archive {
template class detail::archive_serializer_map <uLib::Archive::xml_oarchive> ;
template class basic_xml_oarchive <uLib::Archive::xml_oarchive> ;
template class xml_oarchive_impl <uLib::Archive::xml_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::xml_iarchive> ;
template class basic_xml_iarchive <uLib::Archive::xml_iarchive> ;
template class xml_iarchive_impl <uLib::Archive::xml_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::text_oarchive> ;
template class basic_text_oarchive <uLib::Archive::text_oarchive> ;
template class text_oarchive_impl <uLib::Archive::text_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::text_iarchive> ;
template class basic_text_iarchive <uLib::Archive::text_iarchive> ;
template class text_iarchive_impl <uLib::Archive::text_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::hrt_oarchive> ;
template class basic_text_oarchive <uLib::Archive::hrt_oarchive> ;
template class text_oarchive_impl <uLib::Archive::hrt_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::hrt_iarchive> ;
template class basic_text_iarchive <uLib::Archive::hrt_iarchive> ;
template class text_iarchive_impl <uLib::Archive::hrt_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::log_archive> ;
template class basic_xml_oarchive <uLib::Archive::log_archive> ;
template class xml_oarchive_impl <uLib::Archive::log_archive> ;
} // namespace archive
} // namespace boost

784
src/Core/Archives.h Normal file
View File

@@ -0,0 +1,784 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARCHIVES_H
#define U_CORE_ARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include "StringReader.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES //
namespace uLib {
namespace Archive {
class xml_iarchive;
class xml_oarchive;
class text_iarchive;
class text_oarchive;
class log_archive;
}
}
namespace boost {
namespace archive {
namespace detail {
template<class ArchiveImplementation> class polymorphic_oarchive_route;
template<class ArchiveImplementation> class polymorphic_iarchive_route;
}
}
}
namespace boost {
namespace serialization {
template <typename T> struct hrp;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION //
namespace uLib {
namespace Archive {
namespace detail {
struct adl_tag {};
}
}
}
namespace boost {
namespace archive {
namespace detail {
// This function gets called, but its only purpose is to participate
// in overload resolution with the functions declared by
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
template <class Serializable>
void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {}
}
}
}
// The function declaration generated by this macro never actually
// gets called, but its return type gets instantiated, and that's
// enough to cause registration of serialization functions between
// Archive and any exported Serializable type. See also:
// boost/serialization/export.hpp
# define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
namespace boost { namespace archive { namespace detail { \
\
template <class Serializable> \
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES //
namespace boost {
namespace archive {
namespace detail {
/**
* Custom implementation of boost interface_iarchive to add new operators
*/
template<class Archive>
class uLib_interface_iarchive
{
protected:
uLib_interface_iarchive(){};
public:
/////////////////////////////////////////////////////////
// archive public interface
typedef mpl::bool_<true> is_loading;
typedef mpl::bool_<false> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
template<class T>
const basic_pointer_iserializer *
register_type(T * = NULL){
const basic_pointer_iserializer & bpis =
boost::serialization::singleton<
pointer_iserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpis.get_basic_serializer());
return & bpis;
}
template<class T>
Archive & operator>>(T & t){
this->This()->load_override(t, 0);
return * this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
return *(this->This()) >> t;
}
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return * this->This();
}
};
/**
* Custom implementation of boost interface_oarchive to add new operators
*/
template <class Archive>
class uLib_interface_oarchive {
protected:
uLib_interface_oarchive(){};
public:
/////////////////////////////////////////////////////////
// archive public interface
typedef mpl::bool_<false> is_loading;
typedef mpl::bool_<true> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
template<class T>
const basic_pointer_oserializer *
register_type(const T * = NULL){
const basic_pointer_oserializer & bpos =
boost::serialization::singleton<
pointer_oserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpos.get_basic_serializer());
return & bpos;
}
template<class T>
Archive & operator<<(T & t){
// to get access you must redefine save_override by typing
// "using save_override" in archive impl
this->This()->save_override(t, 0);
return * this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
return * this->This() << const_cast<const T &>(t);
#else
return * this->This() << t;
#endif
}
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return * this->This();
}
};
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own
// extended interface //
template <>
class interface_iarchive <uLib::Archive::xml_iarchive> : public
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::xml_oarchive> : public
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {};
template <>
class interface_iarchive <uLib::Archive::text_iarchive> : public
uLib_interface_iarchive <uLib::Archive::text_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::text_oarchive> : public
uLib_interface_oarchive <uLib::Archive::text_oarchive> {};
template <>
class interface_oarchive <uLib::Archive::log_archive> : public
uLib_interface_oarchive <uLib::Archive::log_archive> {};
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
// template <class TypeSeq> \
// struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
// {};
//// Multiple size declaration //
//BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
//#undef _INERIT_NOFOLD_H
//#undef _INERIT_NOFOLD_V
} // detail
} // archive
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES DEFINITIONS //
namespace boost {
namespace archive {
//template<class Archive>
//inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
// typex::invoke(ar, t);
//}
//template<class Archive, class T>
//inline void load(Archive & ar, T &t){
// // if this assertion trips. It means we're trying to load a
// // const object with a compiler that doesn't have correct
// // funtion template ordering. On other compilers, this is
// // handled below.
// // detail::check_const_loading< T >();
// typedef
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
// mpl::identity<detail::load_pointer_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
// mpl::identity<detail::load_array_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
// mpl::identity<detail::load_enum_type<Archive> >
// ,//else
// mpl::identity<detail::load_non_pointer_type<Archive> >
// >
// >
// >::type typex;
// typex::invoke(ar, t);
//}
}
}
namespace uLib {
namespace Archive {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// POLYMORPHIC //
//class polymorphic_iarchive :
// public boost::archive::polymorphic_iarchive {
//public:
// void load_override(const char *t, BOOST_PFTO int)
// {
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t));
// }
//};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML //
class xml_iarchive :
public boost::archive::xml_iarchive_impl<xml_iarchive>,
public boost::archive::detail::shared_ptr_helper
{
typedef xml_iarchive Archive;
typedef boost::archive::xml_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_xml_iarchive<Archive>;
friend class boost::archive::load_access;
public:
xml_iarchive(std::istream & is, unsigned int flags = 0) :
xml_iarchive_impl<xml_iarchive>(is, flags)
{}
using basic_xml_iarchive::load_override;
// Anything not an attribute should be a name value pair as nvp or hrp
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive;
template<class T>
void load_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
boost::serialization::hrp< T > & t,
int v
){
this->This()->load_start(t.name());
this->detail_common_iarchive::load_override(t.value(), 0);
// t.stov();
this->This()->load_end(t.name());
}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
// StringReader sr(basic_text_iprimitive::is);
// sr >> str;
}
~xml_iarchive(){};
};
//typedef boost::archive::detail::polymorphic_iarchive_route<
//boost::archive::xml_iarchive_impl<xml_iarchive>
//> polymorphic_xml_iarchive;
template <class ArchiveImpl>
struct polymorphic_iarchive_route :
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl>
{
virtual void load(const char * t){
ArchiveImpl::load(t);
}
};
class polymorphic_xml_iarchive :
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> >
{
// give serialization implementation access to this class
// friend class boost::archive::detail::interface_iarchive<Archive>;
// friend class boost::archive::basic_xml_iarchive<Archive>;
// friend class boost::archive::load_access;
public:
virtual void load_override(const char *str, int v) {
;
}
};
class xml_oarchive :
public boost::archive::xml_oarchive_impl<xml_oarchive>
{
typedef xml_oarchive Archive;
typedef boost::archive::xml_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_xml_oarchive<Archive>;
friend class boost::archive::save_access;
public:
xml_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags)
{}
// example of implementing save_override for const char* //
// void save_override(const char *t, int) {
// std::cout << "found char: " << t << "\n";
// }
using basic_xml_oarchive::save_override;
// special treatment for name-value pairs.
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive;
template<class T>
void save_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
::boost::serialization::hrp< T > & t,
int v
){
this->This()->save_start(t.name());
// t.vtos();
// this->detail_common_oarchive::save_override(t.const_value(), 0);
this->This()->save_end(t.name());
}
void save_override(const char *str, int v) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
~xml_oarchive(){}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::xml_oarchive_impl<xml_oarchive>
//> polymorphic_xml_oarchive;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TEXT //
class text_iarchive :
public boost::archive::text_iarchive_impl<text_iarchive>,
public boost::archive::detail::shared_ptr_helper
{
typedef text_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
text_iarchive(std::istream & is, unsigned int flags = 0) :
text_iarchive_impl<Archive>(is, flags)
{}
using basic_text_iarchive::load_override;
void load_override(boost::archive::object_id_type & t, int) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
~text_iarchive() {};
};
typedef text_iarchive naked_text_iarchive;
//typedef boost::archive::detail::polymorphic_iarchive_route<
//naked_text_iarchive
//> polymorphic_text_iarchive;
class text_oarchive :
public boost::archive::text_oarchive_impl<text_oarchive>
{
typedef text_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
text_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::text_oarchive_impl<Archive>(os, flags)
{}
using basic_text_oarchive::save_override;
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
~text_oarchive(){}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::text_oarchive_impl<text_oarchive>
//> polymorphic_text_oarchive;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SIMPLE HUMAN READABLE TEXT //
class hrt_iarchive :
public boost::archive::text_iarchive_impl<hrt_iarchive>,
public boost::archive::detail::shared_ptr_helper
{
typedef hrt_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
hrt_iarchive(std::istream & is, unsigned int flags = 0) :
base(is, flags | boost::archive::no_header )
{}
using basic_text_iarchive::load_override;
// hide all archive props //
void load_override( boost::archive::object_id_type & t, int) {}
void load_override( boost::archive::object_reference_type & t, int) {}
void load_override( boost::archive::version_type & t, int) {}
void load_override( boost::archive::class_id_type & t, int) {}
void load_override( boost::archive::class_id_optional_type & t, int) {}
void load_override( boost::archive::class_id_reference_type & t, int){}
void load_override( boost::archive::class_name_type & t, int) {}
void load_override( boost::archive::tracking_type & t, int) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
~hrt_iarchive() {};
};
class hrt_oarchive :
public boost::archive::text_oarchive_impl<hrt_oarchive>
{
typedef hrt_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
hrt_oarchive(std::ostream & os, unsigned int flags = 0) :
base(os, flags | boost::archive::no_header )
{}
using basic_text_oarchive::save_override;
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
~hrt_oarchive(){}
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML FOR LOG OUTPUT PURPOUSE //
/////////////////////////////////////////////////////////////////////////
// log data to an output stream. This illustrates a simpler implemenation
// of text output which is useful for getting a formatted display of
// any serializable class. Intended to be useful as a debugging aid.
class log_archive :
/* protected ? */
public boost::archive::xml_oarchive_impl<log_archive>
{
typedef boost::archive::xml_oarchive_impl<log_archive> base;
typedef log_archive Archive;
// give serialization implementation access to this clas
friend class boost::archive::detail::interface_oarchive<log_archive>;
friend class boost::archive::basic_xml_oarchive<log_archive>;
friend class boost::archive::save_access;
public:
void save_override(const char *str, int v) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
template<class T>
void save_override(T & t, BOOST_PFTO int){
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
}
// activate this if you want to trap non nvp objects //
// template<class T>
// void save_override(T & t, BOOST_PFTO int)
// {
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // this->detail_common_oarchive::save_override(t, 0);
// }
template<class T>
void save_override(const boost::serialization::nvp<T> & t, int){
base::save_override(t, 0);
}
// specific overrides for attributes - not name value pairs so we
// want to trap them before the above "fall through"
// since we don't want to see these in the output - make them no-ops.
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
public:
log_archive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<log_archive>(
os,
flags | boost::archive::no_header
)
{}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::xml_oarchive_impl<log_archive>
//> polymorphic_log_archive;
} // Archive
} // uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_iarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_oarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_iarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive)
#endif // U_CORE_ARCHIVES_H

72
src/Core/Array.h Normal file
View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARRAY_H
#define U_CORE_ARRAY_H
#include <array> // std::array
#include "Types.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//// ERROR NOT WORKING CLASS, USE VECTOR INSTEAD //////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
template< typename T, Size_t size >
class Array : public std::array<T,size> {
};
template< typename T, Size_t size >
class SmartArray : public SmartPointer< Array<T,size> > {
typedef SmartPointer< Array<T,size> > ptr;
public:
SmartArray() : ptr(new Array<T,size>()) { }
SmartArray( const SmartArray &copy) : ptr(copy) { }
virtual ~SmartArray() {}
T& operator[](unsigned int p) {
return ptr::get()->at(p);
}
};
}
#endif // ARRAY_H

46
src/Core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,46 @@
set(HEADERS
Archives.h
Array.h
Collection.h
Debug.h
Export.h
Function.h
Macros.h
Mpl.h
Object.h
ObjectProps.h
Options.h
Serializable.h
Signal.h
Singleton.h
SmartPointer.h
StaticInterface.h
StringReader.h
Types.h
Uuid.h
Vector.h
CommaInitializer.h
ProgrammableAccessor.h
)
SET(SOURCES
Archives.cpp
Object.cpp
Options.cpp
Serializable.cpp
Signal.cpp
Uuid.cpp
)
set(LIBRARIES
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
)
uLib_add_shared_library(${uLib-module})
add_subdirectory(testing)

101
src/Core/Collection.h Normal file
View File

@@ -0,0 +1,101 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_COLLECTION_H
#define U_CORE_COLLECTION_H
#include <iostream>
#include <vector>
#include "SmartPointer.h"
#include "Vector.h"
////////////////////////////////////////////////////////////////////////////////
/////// COLLECTION TEMPLATE //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TODO: REWRITE THIS CLASS ... //
namespace uLib {
namespace Abstract {
template <typename T>
class Collection {
public:
virtual ~Collection() {}
virtual void AddItem(T obj) =0;
virtual void RemoveItem(int i) =0;
virtual int GetNumberOfItems() =0;
virtual T& At(unsigned int i) =0;
virtual void PrintSelf(std::ostream &o) =0;
};
}
template <typename T>
class Collection : public Abstract::Collection<T> {
public:
Collection() : data() {}
Collection(int size) : data(size) {}
~Collection() {}
inline void AddItem(T obj) { data->push_back(obj); }
inline void RemoveItem(int i) { data.remove_element(i); }
inline int GetNumberOfItems() { return data->size(); }
inline T& At(unsigned int i) { return data->at(i); }
inline T& operator[] (unsigned int i) { return data->at(i); }
inline void PrintSelf(std::ostream &o);
private:
SmartVector<T> data;
};
template<typename T>
void Collection<T>::PrintSelf(std::ostream &o)
{
o << " *** uLib Collection *** \n";
o << " n. of items = " << this->GetNumberOfItems() << "\n";
}
}
#endif // COLLECTION_H

View File

@@ -0,0 +1,89 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_COMMAINITIALIZER_H
#define U_CORE_COMMAINITIALIZER_H
namespace uLib {
// Comma Initializer template ...
// ContentT should provide operator[] and resize() methods.
// Waiting for Static interface check
template < typename ContainerT, typename ContentT >
struct CommaInitializer
{
inline explicit CommaInitializer(ContainerT *container, ContentT s)
: container(container)
{
this->index = 0;
container->resize(1);
this->container->operator[](0) = s;
}
inline CommaInitializer & operator, (ContentT s) {
this->index++;
container->resize(index + 1);
this->container->operator[](this->index) = s;
return *this;
}
ContainerT *container;
unsigned int index;
};
// Comma Initializer template for fixed array...
// ContentT should provide operator[] and size() methods.
// Waiting for Static interface check
template < typename ContainerT, typename ContentT >
struct CommaInitializerFixed
{
inline explicit CommaInitializerFixed(ContainerT *container, ContentT s)
: container(container)
{
this->index = 0;
this->container->operator[](0) = s;
}
inline CommaInitializerFixed & operator, (ContentT s) {
this->index++;
this->container->operator[](this->index) = s;
return *this;
}
ContainerT *container;
unsigned int index;
};
} // uLib
#endif // COMMAINITIALIZER_H

31
src/Core/Debug.cpp Normal file
View File

@@ -0,0 +1,31 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Debug.h"

148
src/Core/Debug.h Normal file
View File

@@ -0,0 +1,148 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_DEBUG_H
#define U_CORE_DEBUG_H
#include "ltk/ltkdebug.h"
#include "Macros.h"
#include "Types.h"
#include "Mpl.h"
#include "Vector.h"
#include <boost/any.hpp>
#include <TObject.h>
namespace uLib {
namespace detail {
struct DebugAdapterInterface {
virtual ~DebugAdapterInterface() {}
virtual void operator()(char val) {}
virtual void operator()(unsigned char val) {}
virtual void operator()(short val) {}
virtual void operator()(unsigned short val) {}
virtual void operator()(int val) {}
virtual void operator()(unsigned int val) {}
virtual void operator()(long val) {}
virtual void operator()(unsigned long val) {}
virtual void operator()(float val) {}
virtual void operator()(double val) {}
virtual void operator()(std::string val) {}
};
struct DebugAdapter {
struct AnyCastAdapterBase {
virtual ~AnyCastAdapterBase(){}
virtual void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) {}
};
template < typename T >
struct AnyCastAdapter : AnyCastAdapterBase {
void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) { ad->operator()(boost::any_cast<T>(val)); }
};
struct DItem {
DItem(){}
template <typename T> DItem(std::string str, T &t) :
m_adapter(new AnyCastAdapter<T>()),
m_name(str),
m_value(t) { }
SmartPointer<AnyCastAdapterBase> m_adapter;
std::string m_name;
boost::any m_value;
};
};
} // detail
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// text ADAPTER
class DebugAdapterText : public detail::DebugAdapterInterface {
std::ostream &m_out;
public:
DebugAdapterText(std::ostream &o) : m_out(o) {}
void operator()(int val) { m_out << "debug: " << val << "\n"; }
void operator()(std::string val) { m_out << "debug: " << val << "\n"; }
};
class Debug {
typedef detail::DebugAdapterInterface AdapterInterface;
typedef SmartPointer<detail::DebugAdapterInterface> Adapter;
typedef detail::DebugAdapter::DItem DItem;
public:
template <typename T> void operator() (std::string str, T &t) { m_v.push_back(DItem(str,t)); }
void AddAdapter(AdapterInterface &ad) { m_a.push_back(Adapter(ad)); }
void Update() {
foreach(Adapter &ad, m_a) {
foreach(DItem &item, m_v) {
item.m_adapter->operator()(ad, item.m_value);
}
}
}
private:
Vector<DItem> m_v;
Vector<Adapter> m_a;
};
} // uLib
#endif // DEBUG_H

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <TTree.h>
#include "DebugArchives.h"
namespace uLib {
namespace Archive {
namespace detail {
basic_Root_Ttree_oprimitive::basic_Root_Ttree_oprimitive(const char *tree_name)
{
m_tree = new TTree(tree_name,tree_name);
}
basic_Root_Ttree_oprimitive::~basic_Root_Ttree_oprimitive()
{
m_tree->Write();
m_tree->ResetBranchAddresses();
m_tree->Delete();
}
} // detail
} // Archive
} // uLib

289
src/Core/DebugArchives.h Normal file
View File

@@ -0,0 +1,289 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_DEBUGARCHIVES_H
#define U_CORE_DEBUGARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include "Archives.h"
#include "StringReader.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES //
namespace uLib {
namespace Archive {
class Root_debug_archive;
}
}
namespace boost {
namespace archive {
namespace detail {
template<class ArchiveImplementation> class polymorphic_oarchive_route;
template<class ArchiveImplementation> class polymorphic_iarchive_route;
}
}
}
namespace boost {
namespace serialization {
template <typename T> struct hrp;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION //
// in Archives.h
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES //
namespace boost {
namespace archive {
namespace detail {
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own
// extended interface //
template <>
class interface_iarchive <uLib::Archive::Root_debug_archive> : public
uLib_interface_iarchive <uLib::Archive::Root_debug_archive> {};
} // detail
} // archive
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES DEFINITIONS //
namespace boost {
namespace archive {
//template<class Archive>
//inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
// typex::invoke(ar, t);
//}
//template<class Archive, class T>
//inline void load(Archive & ar, T &t){
// // if this assertion trips. It means we're trying to load a
// // const object with a compiler that doesn't have correct
// // funtion template ordering. On other compilers, this is
// // handled below.
// // detail::check_const_loading< T >();
// typedef
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
// mpl::identity<detail::load_pointer_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
// mpl::identity<detail::load_array_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
// mpl::identity<detail::load_enum_type<Archive> >
// ,//else
// mpl::identity<detail::load_non_pointer_type<Archive> >
// >
// >
// >::type typex;
// typex::invoke(ar, t);
//}
}
}
// ROOT FWD
class TTree;
///////////
namespace uLib {
namespace Archive {
namespace detail {
class basic_Root_Ttree_oprimitive
{
TTree *m_tree;
public:
basic_Root_Ttree_oprimitive(const char *tree_name);
~basic_Root_Ttree_oprimitive();
};
} // detail
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML FOR LOG OUTPUT PURPOUSE //
///////////////////////////////////////////////////////////////////////////
//// log data to an output stream. This illustrates a simpler implemenation
//// of text output which is useful for getting a formatted display of
//// any serializable class. Intended to be useful as a debugging aid.
class Root_debug_archive :
/* protected ? */
public boost::archive::detail::common_oarchive<Archive>
{
typedef boost::archive::detail::common_oarchive<Root_debug_archive> base;
typedef Root_debug_archive Archive;
// give serialization implementation access to this clas
friend class boost::archive::detail::interface_oarchive<Root_debug_archive>;
friend class boost::archive::save_access;
public:
// void save_override(const char *str, int v) {
// // Do not save any human decoration string //
// // basic_text_oprimitive::save(str);
// }
// template<class T>
// void save_override(T & t, BOOST_PFTO int){
// base::save_override(boost::serialization::make_nvp(NULL, t), 0);
// }
// // activate this if you want to trap non nvp objects //
// // template<class T>
// // void save_override(T & t, BOOST_PFTO int)
// // {
// // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // // this->detail_common_oarchive::save_override(t, 0);
// // }
// template<class T>
// void save_override(const boost::serialization::nvp<T> & t, int){
// base::save_override(t, 0);
// }
// // specific overrides for attributes - not name value pairs so we
// // want to trap them before the above "fall through"
// // since we don't want to see these in the output - make them no-ops.
// void save_override(const boost::archive::object_id_type & t, int) {}
// void save_override(const boost::archive::object_reference_type & t, int) {}
// void save_override(const boost::archive::version_type & t, int) {}
// void save_override(const boost::archive::class_id_type & t, int) {}
// void save_override(const boost::archive::class_id_optional_type & t, int) {}
// void save_override(const boost::archive::class_id_reference_type & t, int){}
// void save_override(const boost::archive::class_name_type & t, int) {}
// void save_override(const boost::archive::tracking_type & t, int) {}
//public:
// Root_debug_archive(std::ostream & os, unsigned int flags = 0) :
// boost::archive::xml_oarchive_impl<log_archive>(
// os,
// flags | boost::archive::no_header
// )
// {}
};
} // Archive
} // uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::Root_debug_archive)
#endif // U_CORE_DEBUGARCHIVES_H

117
src/Core/Export.h Normal file
View File

@@ -0,0 +1,117 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_EXPORT_H
#define U_CORE_EXPORT_H
#include <utility>
#include <cstddef> // NULL
#include <iostream>
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
#include <boost/serialization/static_warning.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/force_include.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include "Core/Archives.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
namespace Archive {
namespace detail {
namespace extra_detail {
template<class T>
struct guid_initializer
{
void export_guid(mpl::false_) const {
// generates the statically-initialized objects whose constructors
// register the information allowing serialization of T objects
// through pointers to their base classes.
boost::archive::detail::
instantiate_ptr_serialization((T*)0, 0,
uLib::Archive::detail::adl_tag());
}
void export_guid(mpl::true_) const {
}
guid_initializer const & export_guid() const {
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
// note: exporting an abstract base class will have no effect
// and cannot be used to instantitiate serialization code
// (one might be using this in a DLL to instantiate code)
//BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
export_guid(boost::serialization::is_abstract< T >());
return *this;
}
};
template<typename T>
struct init_guid;
} // anonymous
} // namespace detail
} // namespace Archive
} // namespace uLib
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
namespace uLib { \
namespace Archive { \
namespace detail { \
namespace extra_detail { \
template<> \
struct init_guid< T > { \
static guid_initializer< T > const & g; \
}; \
guid_initializer< T > const & init_guid< T >::g = \
::boost::serialization::singleton< \
guid_initializer< T > \
>::get_mutable_instance().export_guid(); \
}}}} \
/**/
#endif // EXPORT_H

54
src/Core/Flags.h Normal file
View File

@@ -0,0 +1,54 @@
#ifndef FLAGS_H
#define FLAGS_H
#include <Core/Types.h>
namespace uLib {
template<typename Enum>
class Flags
{
int i;
public:
typedef Enum enum_type;
CONSTEXPR inline Flags(const Flags &f) : i(f.i) {}
CONSTEXPR inline Flags(Enum f) : i(f) {}
CONSTEXPR inline Flags() : i(0) {}
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
inline Flags &operator&=(int mask) { i &= mask; return *this; }
inline Flags &operator&=(uint mask) { i &= mask; return *this; }
inline Flags &operator|=(Flags f) { i |= f.i; return *this; }
inline Flags &operator|=(Enum f) { i |= f; return *this; }
inline Flags &operator^=(Flags f) { i ^= f.i; return *this; }
inline Flags &operator^=(Enum f) { i ^= f; return *this; }
CONSTEXPR inline operator int() const { return i; }
CONSTEXPR inline Flags operator|(Flags f) const { return Flags(Enum(i | f.i)); }
CONSTEXPR inline Flags operator|(Enum f) const { return Flags(Enum(i | f)); }
CONSTEXPR inline Flags operator^(Flags f) const { return Flags(Enum(i ^ f.i)); }
CONSTEXPR inline Flags operator^(Enum f) const { return Flags(Enum(i ^ f)); }
CONSTEXPR inline Flags operator&(int mask) const { return Flags(Enum(i & mask)); }
CONSTEXPR inline Flags operator&(uint mask) const { return Flags(Enum(i & mask)); }
CONSTEXPR inline Flags operator&(Enum f) const { return Flags(Enum(i & f)); }
CONSTEXPR inline Flags operator~() const { return Flags(Enum(~i)); }
CONSTEXPR inline bool operator!() const { return !i; }
inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
};
#define ULIB_OPERATORS_FOR_FLAGS(Flags) \
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
{ return f2 | f1; }
} // uLib
#endif // FLAGS_H

160
src/Core/Function.h Normal file
View File

@@ -0,0 +1,160 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_FUNCTION_H
#define U_CORE_FUNCTION_H
#include <typeinfo>
#include <boost/type_traits.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
//#include <boost/typeof/std/utility.hpp>
namespace uLib {
namespace detail {
////////////////////////////////////////////////////////////////////////////////
// type synthesize ( please read: boost implementation synthesize.hpp ) //
////////////////////////////////////////////////////////////////////////////////
// TODO: change this to boost implementation //
// return a reference to function ... as the boost signal signature wants
template <typename FuncT>
struct FunctionTypes {};
template <typename R, class O>
struct FunctionTypes< R(O::*)() > {
typedef R ref();
typedef R (ptr)();
typedef O obj;
};
template <typename R, class O, typename T0>
struct FunctionTypes< R(O::*)(T0) > {
typedef R ref(T0);
typedef R (ptr)(T0);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1>
struct FunctionTypes< R(O::*)(T0,T1) > {
typedef R ref(T0,T1);
typedef R (ptr)(T0,T1);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1, typename T2>
struct FunctionTypes< R(O::*)(T0,T1,T2) > {
typedef R ref(T0,T1,T2);
typedef R (ptr)(T0,T1,T2);
typedef O obj;
};
} // detail
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function Types //
template<typename Func>
struct FunctionTypes {
typedef typename boost::function_types::function_type<Func>::type Signature;
typedef typename detail::FunctionTypes<Func>::ref SignalSignature;
enum {
arity = boost::function_types::function_arity<Func>::value,
ismfp = boost::is_member_function_pointer<Func>::value
};
typedef boost::mpl::bool_< ismfp > HasObjectType;
typedef typename detail::FunctionTypes<Func>::obj Object;
typedef boost::function_traits< Signature > Traits;
virtual void PrintSelf( std::ostream &o ) {
o << "[fp: " << typeid(Signature).name()
<< " arity: " << arity << "]\n"; }
};
//////// generic mfp container object /////////////////////////////////////////
class GenericMFPtr {
typedef void (GenericMFPtr::*VoidMFPtr)();
public:
typedef VoidMFPtr type;
GenericMFPtr() {}
template <typename T>
GenericMFPtr(T in) {
m_ptr = reinterpret_cast<VoidMFPtr>(in);
}
template <typename T>
inline bool operator == (T in) {
return m_ptr == reinterpret_cast<VoidMFPtr>(in);
}
inline bool operator == (const GenericMFPtr &in) {
return m_ptr == in.m_ptr;
}
VoidMFPtr operator()() { return m_ptr; }
VoidMFPtr m_ptr;
private:
};
} // uLib
#endif // FUNCTION_H

173
src/Core/Macros.h Normal file
View File

@@ -0,0 +1,173 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_MACROS_H
#define U_CORE_MACROS_H
//#ifndef HAVE_CONFIG_H
#include "config.h"
//#endif
#include <assert.h>
#define uLibAssert(condition) assert(condition)
// Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility //
// http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol //
#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllexport))
#else
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
#endif
#else
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllimport))
#else
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
#endif
#endif
#define DLL_LOCAL
#else
#if __GNUC__ >= 4
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define DLL_PUBLIC
#define DLL_LOCAL
#endif
#endif
// foreach Qt style
#ifndef foreach
#include "boost/foreach.hpp"
#define foreach(ref, list) BOOST_FOREACH(ref,list)
#endif
// TODO: verificare necessita' di typecast ////////////////////////////////
#define uLibVGetMacro(name,type) \
virtual inline const type Get##name() const = 0;
#define uLibVSetMacro(name,type) \
virtual inline void Set##name(const type name) = 0;
#define uLibVGetSetMacro(name,type) \
uLibVGet(name,type); \
uLibVSet(name,type);
#define uLibVRefMacro(name,type) \
virtual inline type & name() = 0;
#define uLibPtrMacro(name,type) \
inline type name() const { return this->m_##name; }
#define uLibArrayMacro(name,type) \
inline type name() { return this->m_##name; }
#define uLibGetMacro(name,type) \
inline type Get##name() const { return this->m_##name; }
#define uLibSetMacro(name,type) \
inline void Set##name(type name) { this->m_##name = name; }
#define uLibGetSetMacro(name,type) \
inline type Get##name() const { return this->m_##name; } \
uLibSetMacro(name,type);
#define uLibRefMacro(name,type) \
inline type & name() { return this->m_##name; }
#define uLibConstRefMacro(name,type) \
inline const type & name() const { return this->m_##name; }
#define uLibAccessMacro(name,type) \
inline void name(type name) { this->m_##name = name; } \
uLibConstRefMacro(name,type)
#define uLib_CRTP_ACCESS(_Derive,_name) \
inline _Derive * _name() { return reinterpret_cast<_Derive *>(this); } \
inline const _Derive * _name() const { return reinterpret_cast<const _Derive *>(this); } \
//
#define uLib_CRTP_ACCESS_CASTED(_Derive,_Target,_name) \
inline _Target _name() { return (_Target)(static_cast<_Derive &>(*this)); } \
inline const _Target _name() const { return (const _Target)(static_cast<const _Derive &>(*this)); } \
//
/* Following macros override usual branch prediction of compiler
* These are to be used in conditional statement whose result might
* be Bayesian biased:
*
* // previous_line
* if (likely(a>1)) { // block_1 }
* else { block_2 }
*
* will write the block_1 code right after previous line, without using
* compiler branch prediction for results. Otherwise
*
* // previous_line
* if (unlikely(a>1)) { // block_1 }
* else { block_2 }
*
* will write block_2 after previous_line, leaving block_1 after
* (usually after the end of the whole function! Use with care!)
*/
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#define likely(expr) __builtin_expect(!!(expr), 1)
/* Fastsign
*/
// #define sign(x) (( x > 0 ) - ( x < 0 ))
template <typename T>
inline T sign(const T x) { return x>0 - x<0; }
#endif // MACROS_H

41
src/Core/Makefile.am Normal file
View File

@@ -0,0 +1,41 @@
SUBDIRS = .
include $(top_srcdir)/Common.am
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Core
library_include_HEADERS = \
Archives.h \
Array.h \
Collection.h \
Debug.h \
Export.h \
Function.h \
Macros.h \
Mpl.h \
Object.h \
ObjectProps.h \
Options.h \
Serializable.h \
Signal.h \
Singleton.h \
SmartPointer.h \
StaticInterface.h \
StringReader.h \
Types.h \
Uuid.h \
Vector.h
_CORE_SOURCES = \
Archives.cpp \
Debug.cpp \
Object.cpp \
Options.cpp \
Serializable.cpp \
Signal.cpp \
Uuid.cpp
noinst_LTLIBRARIES = libmutomcore.la
libmutomcore_la_SOURCES = ${_CORE_SOURCES}

139
src/Core/Mpl.h Normal file
View File

@@ -0,0 +1,139 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MPL_H
#define U_MPL_H
#include <boost/preprocessor.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector/vector0.hpp>
#include <boost/mpl/vector/vector10.hpp>
#include <boost/mpl/vector/vector20.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/mpl/filter_view.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/utility/enable_if.hpp>
/**
* Max size of nofold inerited capability
*/
#ifndef ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE
# define ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE 10
#endif
namespace uLib {
namespace mpl {
using namespace boost::mpl;
using namespace boost::mpl::placeholders;
//using boost::enable_if;
namespace detail {
/**
* Inerit nofold implementation, set ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE to
* desired max derivation size keeping in mind that total size accounts all
* mutiple inherited classes.
*/
template <class TypeSeq, unsigned int size>
struct inherit_nofold {};
// Horizontal repetition macro //
#define _INERIT_NOFOLD_H(hz,hn,hdata) \
BOOST_PP_COMMA_IF(hn) \
mpl::at<TypeSeq,mpl::int_<hn> >::type
// Veritical repetition macro //
#define _INERIT_NOFOLD_V(vz,vn,vdata) \
template <class TypeSeq> \
struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
{};
// Multiple size declaration //
BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
#undef _INERIT_NOFOLD_H
#undef _INERIT_NOFOLD_V
} // detail
/**
* Build a derivation tuple from mpl type sequence.
* The same behavior can be obtained by inherit_linearly but folding derivation
* results in a hard to read debugging
*/
template <class TypeSeq>
struct inherit_nofold {
typedef detail::inherit_nofold< TypeSeq, mpl::size<TypeSeq>::type::value > type;
};
/** INHERIT LINEARLY standard utility macro */
#define ULIB_MPL_INHERIT_SEQ(_TypeList) \
uLib::mpl::inherit_linearly< _TypeList, mpl::inherit< mpl::_1, mpl::_2 > >::type
/** INHERIT NOFOLD utility macro (see struct inherit_nofold template) */
#define ULIB_MPL_INHERIT_NOFOLD_SEQ(_TypeList) \
uLib::mpl::inherit_nofold< _TypeList >::type
template< class T>
struct type {
};
template <const char *N, class T>
struct nvp {
nvp() : name(N) {}
const char *name;
typedef T type;
};
} // mpl
} // uLib
#endif // MPL_H

227
src/Core/Object.cpp Normal file
View File

@@ -0,0 +1,227 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "config.h"
#include "Object.h"
#include "Vector.h"
#include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/archive/polymorphic_binary_oarchive.hpp"
#include "boost/archive/polymorphic_binary_iarchive.hpp"
namespace uLib {
const char *Version::PackageName = PACKAGE_NAME;
const char *Version::VersionNumber = PACKAGE_VERSION;
const char *Version::Release = SVN_REVISION;
////////////////////////////////////////////////////////////////////////////////
// Object Private //
class ObjectPrivate {
public:
struct Signal {
GenericMFPtr sigptr;
std::string sigstr;
SignalBase *signal;
};
struct Slot {
GenericMFPtr sloptr;
std::string slostr;
};
Vector<Signal> sigv;
Vector<Slot> slov;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT IMPLEMENTATION
Object::Object() :
d(new ObjectPrivate)
{}
Object::Object(const Object &copy) :
ObjectPropable(copy),
d(new ObjectPrivate(*copy.d))
{}
Object::~Object() {
delete d;
}
void Object::DeepCopy(const Object &copy)
{
// should lock to be tread safe //
memcpy(d,copy.d,sizeof(ObjectPrivate));
// ERROR! does not copy parameters ... <<<< FIXXXXX
}
void Object::SaveXml(std::ostream &os, Object &ob)
{
Archive::xml_oarchive ar(os);
ar << boost::serialization::make_nvp("Object",ob);
}
void Object::LoadXml(std::istream &is, Object &ob)
{
Archive::xml_iarchive ar(is);
ar >> boost::serialization::make_nvp("Object",ob);
}
// FINIRE
void Object::SaveConfig(std::ostream &os, int version)
{
Archive::xml_oarchive ar(os);
ObjectPropable::serialize(ar,0);
}
void Object::LoadConfig(std::istream &is, int version)
{
if(!props()) this->init_properties();
Archive::xml_iarchive ar(is);
ObjectPropable::serialize(ar,0);
}
void Object::PrintSelf(std::ostream &o) const
{
o << "OBJECT signals: ------------------\n";
Vector<ObjectPrivate::Signal>::Iterator itr;
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
{
o << " signal:[ " << itr->sigstr << " ]\n";
}
o << "--------------------------------------\n\n";
}
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name)
{
ObjectPrivate::Signal s = {fptr,std::string(name),sig};
d->sigv.push_back(s);
}
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name)
{
ObjectPrivate::Slot s = {fptr,std::string(name)};
d->slov.push_back(s);
}
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const
{
for(int i=0; i<d->sigv.size(); ++i)
{
if(d->sigv[i].sigptr == fptr)
return d->sigv[i].signal;
}
return NULL;
}
SignalBase *Object::findSignalImpl(const char *name) const
{
std::string in(name);
for(int i=0; i<d->sigv.size(); ++i)
{
if(d->sigv[i].sigstr == in)
return d->sigv[i].signal;
}
return NULL;
}
GenericMFPtr *Object::findSlotImpl(const char *name) const
{
std::string in(name);
for(int i=0; i<d->slov.size(); ++i)
{
if(d->slov[i].slostr == in)
return &d->slov[i].sloptr;
}
return NULL;
}
std::ostream &
operator << (std::ostream &os, uLib::Object &ob)
{
uLib::Object *op = &ob;
uLib::Archive::hrt_oarchive (os) << op;
return os;
}
std::ostream &
operator << (std::ostream &os, uLib::Object *ob)
{
uLib::Archive::hrt_oarchive(os) << ob;
return os;
}
std::istream &
operator >> (std::istream &is, uLib::Object &ob)
{
// uLib::Object *op = &ob;
uLib::Archive::hrt_iarchive(is) >> ob;
return is;
}
} // uLib

222
src/Core/Object.h Normal file
View File

@@ -0,0 +1,222 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OBJECT_H
#define U_CORE_OBJECT_H
#include <iostream>
// WARNING: COPILE ERROR if this goes after mpl/vector //
//#include "Core/Vector.h"
#include "Core/Types.h"
#include "Core/Debug.h"
#include "Core/Function.h"
#include "Core/Signal.h"
#include "Core/Mpl.h"
#include "Core/Serializable.h"
#include "Core/ObjectProps.h"
#include "Core/Uuid.h"
namespace boost {
namespace archive {
class polymorphic_iarchive;
class polymorphic_oarchive;
} // archive
} // boost
namespace uLib {
class Version {
public:
static const char *PackageName;
static const char *VersionNumber;
static const char *Release;
};
////////////////////////////////////////////////////////////////////////////////
//// OBJECT ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* @brief Object class is the object base implementation for uLib Framework.
*/
class Object : public ObjectPropable
{
public:
// std::string name;
// void PrintName() { std::cout << "Ob name: " << name << "\n"; }
Object();
Object(const Object &copy);
~Object();
////////////////////////////////////////////////////////////////////////////
// PARAMETERS //
// FIXX !!!
virtual void DeepCopy(const Object &copy);
////////////////////////////////////////////////////////////////////////////
// SERIALIZATION //
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
ObjectPropable::serialize(ar,version);
}
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
void SaveConfig(std::ostream &os, int version = 0);
void LoadConfig(std::istream &is, int version = 0);
static void SaveXml(std::ostream &os, Object &ob);
static void LoadXml(std::istream &is, Object &ob);
////////////////////////////////////////////////////////////////////////////
// SIGNALS //
// Qt4 style connector //
static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) {
// // NOT WORKING YET //
// 1) find slot pointer from name
// SignalBase *sig = ob1->findSignal(signal_name);
// GenericMFPtr *slo = receiver->findSlot(slot_name);
// if(sig && slo)
// return Object::connect(sig,slo->operator ()(),receiver);
// else return false;
}
// Qt5 style connector //
template <typename Func1, typename Func2>
static bool connect( typename FunctionTypes<Func1>::Object *sender, Func1 sigf,
typename FunctionTypes<Func2>::Object *receiver, Func2 slof)
{
SignalBase *sigb = sender->findOrAddSignal(sigf);
typedef boost::signals2::signal<typename FunctionTypes<Func2>::SignalSignature> SigT;
ConnectSignal(sigb,slof,receiver);
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal(sigb,slof,receiver);
}
template< typename FuncT >
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
addSignal(FuncT fun, const char *name) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
SignalBase *sig = NewSignal(fun);
addSignalImpl(sig,fun,name);
return (SigT *)sig;
}
template< typename FuncT>
inline bool addSlot(FuncT fun, const char *name) {
this->addSlotImpl(GenericMFPtr(fun),name);
}
template < typename FuncT >
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
findSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
}
template < typename FuncT >
inline typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type *
findOrAddSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
if(!sig) {
sig = NewSignal(fptr);
addSignalImpl(sig,fptr,"signal_name_to_be_implemented");
}
return (SigT *)sig;
}
inline SignalBase *
findSignal(const char *name) const
{
return findSignalImpl(name);
}
inline GenericMFPtr *
findSlot(const char *name) const
{
return findSlotImpl(name);
}
void PrintSelf(std::ostream &o) const;
inline const Object& operator = (const Object &copy)
{ this->DeepCopy(copy); return *this; }
private:
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
bool addSlotImpl(GenericMFPtr fptr, const char *name);
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
SignalBase *findSignalImpl(const char *name) const;
GenericMFPtr *findSlotImpl(const char *name) const;
friend class boost::serialization::access;
friend class ObjectPrivate;
class ObjectPrivate *d;
};
} // uLib
////////////////////////////////////////////////////////////////////////////////
std::ostream & operator << (std::ostream &os, uLib::Object &ob);
std::ostream & operator << (std::ostream &os, uLib::Object *ob);
std::istream & operator >> (std::istream &is, uLib::Object &ob);
#endif // U_OBJECT_H

278
src/Core/ObjectProps.h Normal file
View File

@@ -0,0 +1,278 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_OBJECTPROPS_H
#define U_OBJECTPROPS_H
#include <boost/algorithm/string/replace.hpp>
#include <Core/Mpl.h>
#include <Core/Types.h>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MACROS //
#define ULIB_props() \
public: struct ObjectProps; \
virtual void init_properties(); \
inline struct ObjectProps &p() { /* static const unsigned int offset = props_offset(this); */ \
/* NON FUNZIA! return * (struct ObjectProps *)(reinterpret_cast<char*>(props())+offset); */ \
return *props()->ptr<ObjectProps>(); } \
typedef uLib::mpl::bool_<true>::type propable_trait; \
public: struct DLL_PUBLIC ObjectProps
#define properties() ULIB_props()
#define default(vlaue)
#define $$ p()
#define $(_name) props_ref<_name>()
#define $_init() \
if(props(this)) return; \
props_new(this); \
uLib::detail::ObjectProps::initializer::init_object_baselist(this);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace serialization {
class access;
}
}
namespace uLib {
namespace detail {
struct ObjectProps {
/** Define a trait has_member to find if an Object is Propable*/
BOOST_MPL_HAS_XXX_TRAIT_DEF(propable_trait)
/** IsA ProbapleObject Implementation Template */
template <class T>
struct IsA : has_propable_trait<T> {};
/** Lambda to get Props member type */
template <class T>
struct props_type {
typedef typename T::ObjectProps type;
};
template <typename T>
struct get_props {
/** CFList has result but this method check for has BaseList */
typedef typename detail::TypeIntrospection::child_first<T>::type CFTypeList;
/** Filter List items that have not Propable feature */
typedef typename mpl::filter_view< CFTypeList, IsA<mpl::_> >::type FilteredCFTypeList;
/** Get Props from each Parent in Seq */
typedef typename mpl::transform_view< FilteredCFTypeList, props_type<mpl::_> >::type type;
// qui sotto ho un problema che ho temporaneamente tamponato //
// ovvero ho usato child_first_impl per ottenere la lista delle basi //
// vorrei farlo facendo un pop_back ma non va forse perche il tipo //
// non e' corretto. //
/** Get Parent list from CFTypeList */
typedef typename detail::TypeIntrospection::child_first_impl<T>::Childs CFBaseList;
/** Filter Parents that have not Propable feature */
typedef typename mpl::filter_view< CFBaseList, IsA<mpl::_> >::type FilteredCFBaseList;
};
// TODO: convert to pp const value,
// (non so se sia possibile con il dinamic casting intanto funziona cosi' )
template <typename T1, typename T2>
static unsigned int measure_offset(T1 base, T2 derived) {
return reinterpret_cast<char*>(derived) - reinterpret_cast<char*>(base);
}
struct initializer {
template <class _ObjectT>
struct lambda_init_object {
_ObjectT *o;
lambda_init_object(_ObjectT *o) : o(o) {}
template<class T> void operator()(T) {
o->T::init_properties();
}
};
/**
* This calls the internal init_properties() virtual function for each
* object parent defined in BaseList only if it is propable
*/
template <class T>
static void init_object_baselist(T *o) {
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFBaseList CFBaseList;
mpl::for_each<CFBaseList>(lambda_init_object<T>(o));
}
/**
* This calls the internal init_properties() virtual function only if
* object is propable ( implementation if not propable )
*/
template <class T>
static
typename boost::enable_if<mpl::not_<IsA<T> >,void>::type
init_object(T *o) {
; // do nothing //
}
/**
* This calls the internal init_properties() virtual function only if
* object is propable ( implementation if propable )
*/
template <class T>
static
typename boost::enable_if<IsA<T>,void>::type
init_object(T *o) {
o->init_properties();
}
};
template <class ThisClass, class Archive>
struct serialize_baselist {
ThisClass & m_object;
Archive & m_ar;
serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
// T is taken fron get_props<BaseList>::FilteredPList types to get
// type_info_name that is the type name defined by Type macro
typedef typename props_type<T>::type PType;
std::string name(TypeIntrospection::access<T>::type_info::name);
boost::algorithm::replace_all(name,"::","_");
m_ar & boost::serialization::make_nvp(
name.c_str() ,
boost::serialization::base_object<PType>(m_object));
}
};
};
} // detail
struct ObjectPropsBase {
virtual ~ObjectPropsBase() {}
virtual ObjectPropsBase *copy() = 0;
template <class T> inline T *ptr() { return dynamic_cast<T*>(this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {}
};
template <class T>
struct ObjectPropsImpl :
ObjectPropsBase,
ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props<T>::type)
{
typedef ObjectPropsImpl<T> ThisClass;
typedef typename uLib::detail::ObjectProps::get_props<T>::type CFList;
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFTypeList FilteredCFTypeList;
ObjectPropsBase *copy() { return new ThisClass(*this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
boost::serialization::void_cast_register<ThisClass,ObjectPropsBase>();
mpl::for_each<FilteredCFTypeList>(detail::ObjectProps::serialize_baselist<ThisClass,ArchiveT>(*this,ar));
}
};
class ObjectPropable {
ObjectPropsBase *m_props;
friend class uLib::detail::ObjectProps;
friend class boost::serialization::access;
public:
ObjectPropable() : m_props(NULL) {}
ObjectPropable(const ObjectPropable &c) { if(c.m_props) m_props = c.m_props->copy(); else m_props = NULL; }
~ObjectPropable() { if(m_props) delete m_props; }
template <class T> inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr<typename T::ObjectProps>(); else exit(1); }
template <class T> inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr<typename T::ObjectProps>(); else return NULL; }
protected:
ObjectPropsBase *props() const { return m_props; }
template <class T> inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl<T>; }
/** NOT working dynamic cache casting */
template <class T> inline unsigned int props_offset(T *ptr) const
{ if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr<T>()); else return -1; }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
if(m_props) ar & boost::serialization::make_nvp("properties",m_props);
}
public:
/**
* ObjectPropable is not directly propable itself to prevent Basclass
* duplication in inherit_nofold. And for the same reason ANY VIRTUAL BASE
* SHOULD NOT BE PROPABLE
*/
virtual void init_properties() {}
};
} // uLib
#endif // U_OBJECTPROPS_H

87
src/Core/Options.cpp Normal file
View File

@@ -0,0 +1,87 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Options.h"
#include <boost/program_options.hpp>
//class boost::program_options::error_with_option_name;
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>(int *);
namespace uLib {
Options::Options(const char *str) :
m_global(str),
m_configuration("Configuration")
{}
void Options::parse_command_line(int argc, char *argv[]) {
boost::program_options::store(boost::program_options::parse_command_line(argc,argv,m_global),m_vm);
boost::program_options::notify(m_vm);
if(m_vm.count("help")) {
std::cout << "\n" << m_global << "\n";
if(m_configuration.options().size()) {
std::cout << "\n" << m_configuration << "\n\n";
}
exit(1);
}
}
void Options::parse_config_file(std::string &str)
{
this->parse_config_file(str.c_str());
}
void Options::parse_config_file(const char *fname)
{
std::ifstream is;
is.open(fname);
boost::program_options::options_description fileopt;
fileopt.add(m_global).add(m_configuration);
if(is.is_open()) {
boost::program_options::store(boost::program_options::parse_config_file(is,fileopt,true),m_vm);
boost::program_options::notify(m_vm);
}
}
bool Options::count(const char *str) const
{
return (m_vm.count(str));
}
} // uLib

179
src/Core/Options.h Normal file
View File

@@ -0,0 +1,179 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OPTIONS_H
#define U_CORE_OPTIONS_H
#include <boost/program_options.hpp>
namespace uLib {
namespace detail {
struct Options {
/**
* Wrapper for boost program_options easy init syntax
*/
class options_description_easy_init {
typedef boost::program_options::options_description_easy_init InitClass;
InitClass m_init;
public:
options_description_easy_init(InitClass init) :
m_init(init) {}
options_description_easy_init&
operator()(const char* name,
const char* description)
{
m_init(name,description);
return *this;
}
options_description_easy_init&
operator()(const char* name,
const boost::program_options::value_semantic* s)
{
m_init(name,s);
return *this;
}
options_description_easy_init&
operator()(const char* name,
const boost::program_options::value_semantic* s,
const char* description)
{
m_init(name,s,description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const T default_value,
const char* description)
{
m_init(name,
boost::program_options::value<T>(value)->default_value(default_value),
description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const char* description)
{
assert(value);
m_init(name,
boost::program_options::value<T>(value)->default_value(*value),
description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const T default_value)
{
m_init(name,
boost::program_options::value<T>(value)->default_value(default_value));
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value)
{
assert(value);
m_init(name,
boost::program_options::value<T>(value)->default_value(*value));
return *this;
}
};
}; // Options
} // detail
class Options {
boost::program_options::options_description m_global;
boost::program_options::options_description m_configuration;
boost::program_options::positional_options_description m_posdesc;
boost::program_options::variables_map m_vm;
public:
typedef detail::Options::options_description_easy_init initType;
Options(const char *str = "Program options");
initType add_options() {
return initType(m_global.add_options());
}
initType add_config_options() {
return initType(m_configuration.add_options());
}
void add_positional_option(const char *name, int max_count) {
// TODO:
// m_posdesc(name,max_count);
}
void parse_command_line(int argc, char *argv[]);
void parse_config_file(std::string &str);
void parse_config_file(const char *fname);
template <typename T>
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
r->default_value(dvalue);
return r;
}
bool count(const char *str) const;
};
} // uLib
#endif // U_CORE_OPTIONS_H

View File

@@ -0,0 +1,140 @@
#ifndef U_CORE_PROGRAMMABLEACCESSOR_H
#define U_CORE_PROGRAMMABLEACCESSOR_H
#include <Core/Macros.h>
#include <Core/Types.h>
#include <Core/SmartPointer.h>
namespace uLib {
namespace detail {
template <typename R>
class ProgrammableAccessor_Base {
public:
virtual R Get(void *) const = 0;
virtual void Set(void *,const R) const = 0;
template <typename T>
T Get(void *ob) const {
return static_cast<T>(this->Get(ob));
}
template <typename T>
void Set(void *ob, const T data) const {
this->Set(ob,static_cast<R>(data));
}
virtual ~ProgrammableAccessor_Base() {}
};
template<typename R, typename T>
class functor_by_ref : public ProgrammableAccessor_Base<R>
{
public:
explicit functor_by_ref(R&(T::*__pf)()) : MFRef(__pf) {}
R Get(void * ptr) const
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*MFRef)()); }
void Set(void * ptr, const R data) const
{ ((reinterpret_cast<T *>(ptr)->*MFRef)()) = data; }
private:
R&(T::*MFRef)();
};
template<typename R, typename T>
class functor_by_mfptr_cc : public ProgrammableAccessor_Base<R>
{
typedef R(T::*GetterType)() const;
typedef void(T::*SetterType)(const R);
public:
explicit functor_by_mfptr_cc( GetterType _get, SetterType _set ) :
GetPtr(_get), SetPtr(_set) {}
R Get(void * ptr) const
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*GetPtr)()); }
void Set(void * ptr, const R data) const
{ if (SetPtr) (reinterpret_cast<T *>(ptr)->*SetPtr)(data); }
private:
GetterType GetPtr;
SetterType SetPtr;
};
template<typename R, typename T>
class functor_by_mfptr_vv : public ProgrammableAccessor_Base<R>
{
typedef R(T::*GetterType)();
typedef void(T::*SetterType)(R);
public:
explicit functor_by_mfptr_vv( GetterType _get, SetterType _set ) :
GetPtr(_get), SetPtr(_set) {}
R Get(void * ptr) const
{ return static_cast<R>((reinterpret_cast<T *>(ptr)->*GetPtr)()); }
void Set(void * ptr, const R data) const
{ if (SetPtr) (reinterpret_cast<T *>(ptr)->*SetPtr)(data); }
private:
GetterType GetPtr;
SetterType SetPtr;
};
template<typename R, typename T>
class functor_by_member : public ProgrammableAccessor_Base<R>
{
public:
explicit functor_by_member(R T::*__pf) : MDPtr(__pf) {}
R Get(void * ptr) const
{ return static_cast<R>(reinterpret_cast<T *>(ptr)->*MDPtr); }
void Set(void * ptr, const R data) const
{ (reinterpret_cast<T *>(ptr)->*MDPtr) = data; }
private:
R T::*MDPtr;
};
} // detail
////////////////////////////////////////////////////////////////////////////////
// Programmable Accessor Factory /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
template <typename R>
class ProgrammableAccessor {
public:
template <typename T>
ProgrammableAccessor(R(T::*_pg)()const, void(T::*_ps)(const R) = NULL) :
m_base(new detail::functor_by_mfptr_cc<R,T>(_pg,_ps)) {}
template <typename T>
ProgrammableAccessor(R(T::*_pg)(), void(T::*_ps)(R) = NULL) :
m_base(new detail::functor_by_mfptr_vv<R,T>(_pg,_ps)) {}
template <typename T>
ProgrammableAccessor(R&(T::*_pf)()) :
m_base(new detail::functor_by_ref<R,T>(_pf)) {}
template <typename T>
ProgrammableAccessor(R T::*_pf) :
m_base(new detail::functor_by_member<R,T>(_pf)) {}
template <typename OtherR>
inline OtherR Get(void *ob) const { return m_base->Get<OtherR>(ob); }
template <typename OtherR>
inline void Set(void *ob, const OtherR data) const { return m_base->Set<OtherR>(ob,data); }
private:
SmartPointer< detail::ProgrammableAccessor_Base<R> > m_base;
};
} // uLib
#endif // PROGRAMMABLEACCESSOR_H

95
src/Core/Serializable.cpp Normal file
View File

@@ -0,0 +1,95 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/archive/polymorphic_binary_oarchive.hpp"
#include "boost/archive/polymorphic_binary_iarchive.hpp"
#include "Serializable.h"
using namespace uLib;
//void Serializable::SaveXml(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_xml_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadXml(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_xml_iarchive(is);
// this->Load(*xia,this);
// delete xia;
//}
//void Serializable::SaveText(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_text_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadText(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_text_iarchive(is);
// this->Load(*xia,this);
// delete xia;
//}
//void Serializable::SaveBin(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_binary_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadBin(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_binary_iarchive(is);
// Serializable::Load(*xia,this);
// delete xia;
//}
//void Serializable::Save(boost::archive::polymorphic_oarchive &ar, Serializable *ob)
//{
// ar << boost::serialization::make_nvp("Object",ob);
//}
//void Serializable::Load(boost::archive::polymorphic_iarchive &ar, Serializable *ob)
//{
// ar >> boost::serialization::make_nvp("Object",ob);
//}

412
src/Core/Serializable.h Normal file
View File

@@ -0,0 +1,412 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_SERIALIZABLE_H
#define U_SERIALIZABLE_H
/* Serialization:
TODO:
* Problema nella serializzazione delle properties in test_archive
* implementare human readable make_hrp ... non riesco..
*/
#include <boost/serialization/access.hpp>
#include <boost/serialization/export.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/remove_if.hpp>
#include <boost/serialization/nvp.hpp>
//#include <boost/archive/xml_iarchive.hpp>
//#include <boost/archive/xml_oarchive.hpp>
//#include <boost/archive/text_iarchive.hpp>
//#include <boost/archive/text_oarchive.hpp>
//#include "boost/archive/polymorphic_iarchive.hpp"
//#include "boost/archive/polymorphic_oarchive.hpp"
#include <boost/preprocessor/comma_if.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/tuple/to_seq.hpp>
#include "Core/Mpl.h"
#include "Core/ObjectProps.h"
#include "Core/Archives.h"
#include "Core/Export.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// BOOST SERIALIZATION ADD-ON
namespace boost {
namespace serialization {
// ACCESS 2 //
template <class T> struct access2 {};
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
template<class T>
class hrp :
public wrapper_traits<const hrp< T > >
{
const char *m_name;
T *m_value;
std::string *m_str;
public:
explicit hrp(const char * name_, T &t) :
m_str(new std::string),
m_name(name_), m_value(&t) {}
const char * name() const {
return this->m_name;
}
template<class Archivex>
void save( Archivex & ar, const unsigned int /* file_version */) const {
//// ar.operator<<(const_value());
// std::stringstream ss;
// uLib::Archive::hrt_oarchive har(ss);
// har << make_nvp(m_name,*m_value);
// // (*m_str) = ss.str();
//// ar.operator << (make_nvp(m_name, ss.str());
}
template<class Archivex>
void load( Archivex & ar, const unsigned int /* file_version */) {
// ar.operator>>(value());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
template<class T>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
hrp< T > make_hrp(const char * name, T & t){
return hrp< T >(name, t);
}
#define HRP(name) \
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
} // serialization
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ULIB SERIALIZATION
namespace uLib {
#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
#define NVP(data) BOOST_SERIALIZATION_NVP(data)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SERIALIZTION MACROS //
// !!! WARNING !!! INTRUSIVE SERIALIZATION IS ACTUALLY NOT WORKING FEATURE
// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
#else
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
ULIB_CLASS_EXPORT_KEY(_Ob)
# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob)
# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
#endif
#define ULIB_SERIALIZE_ACCESS \
friend class boost::serialization::access; \
template <class T> friend class boost::serialization::access2;
#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass)
#define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass::ObjectProps) \
BOOST_CLASS_EXPORT_KEY(uLib::ObjectPropsImpl<_FullNamespaceClass>)
#define _SERIALIZE_IMPL_SEQ \
(uLib::Archive::text_iarchive) \
(uLib::Archive::text_oarchive) \
(uLib::Archive::hrt_iarchive) \
(uLib::Archive::hrt_oarchive) \
(uLib::Archive::xml_iarchive) \
(uLib::Archive::xml_oarchive) \
(uLib::Archive::log_archive)
/** Solving virtual class check problem */
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; }
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) //
#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
template void Class::serialize(Archive &ar,const unsigned int);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
typedef boost::mpl::bool_<true> serializable; \
typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \
void PrintSerializableListId() { boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); } \
template <class ArchiveT> void serialize(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void serialize_parents(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
template <class ArchiveT> void _Ob::serialize(ArchiveT &ar, const unsigned int version) { \
boost::serialization::void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); \
_Ob::serialize_parents(ar,version); \
_Ob::save_override(ar,version); }\
template <class ArchiveT> void _Ob::serialize_parents(ArchiveT &ar, const unsigned int v) { \
BOOST_PP_SEQ_FOR_EACH(_AR_OP,ar,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); } \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
namespace boost { \
namespace serialization { \
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \
{ ::new(o)_Ob(); o->init_parameters(); } }}\
template <class ArchiveT> void _Ob::save_override(ArchiveT &ar, const unsigned int version)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// UNINTRUSIVE SERIALIZATION
#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object<elem>(ob));
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i);
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data,elem)
// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
// different implementation
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }}
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override(ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,...) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
BOOST_PP_IF(BOOST_PP_VARIADIC_SIZE((__VA_ARGS__)),BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__)));,) } \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override (ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \
template <class ArchiveT> void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \
template <class ArchiveT> void save_override (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); }}
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
/* PP serialize */ BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); \
/* MPL serialize */ /*uLib::mpl::for_each<_Ob::BaseList>(uLib::detail::Serializable::serialize_baseobject<_Ob,ArchiveT>(ob,ar) );*/ } \
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *ob, const unsigned int file_version) { \
::new(ob)_Ob(); uLib::detail::ObjectProps::initializer::init_object(ob); } \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); /*fix*/ \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override (ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) { \
save_override (ar,ob,version); } }}\
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob::ObjectProps,_SERIALIZE_IMPL_SEQ)\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob::ObjectProps) \
ULIB_CLASS_EXPORT_IMPLEMENT(uLib::ObjectPropsImpl<_Ob>) \
template <class ArchiveT> void boost::serialization::save_override(ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name),ob.name)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace detail {
struct Serializable {
/**
* Serializable trait to check if an object type is serializable.
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
* cases a has_serialize trait should be implemented
*/
template <class T>
struct serializable_trait : mpl::bool_<false> {};
/**
* IsA Serializable Implementation Template
*/
template <class T>
struct IsA : serializable_trait<T> {};
template <class ThisClass, class Archive>
struct serialize_baseobject {
ThisClass & m_object;
Archive & m_ar;
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
m_ar & boost::serialization::make_nvp(
typeid(T).name() ,
boost::serialization::base_object<T>(m_object));
}
};
};
} // detail
struct Serializable {
friend class boost::serialization::access;
template <class T> friend class boost::serialization::access2;
virtual ~Serializable() {}
protected:
};
} // uLib
#endif // U_SERIALIZABLE_H

28
src/Core/Signal.cpp Normal file
View File

@@ -0,0 +1,28 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/

168
src/Core/Signal.h Normal file
View File

@@ -0,0 +1,168 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SIGNAL_H
#define U_CORE_SIGNAL_H
#include <boost/typeof/typeof.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/signals2/slot.hpp>
#include <boost/signals2/signal_type.hpp>
#include "Function.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Signals macro //
#define default(vlaue)
#define slots
#define signals /*virtual void init_signals();*/ public
#define emit
#define SLOT(a) BOOST_STRINGIZE(a)
#define SIGNAL(a) BOOST_STRINGIZE(a)
#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \
static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \
sig->operator()(__VA_ARGS__);
/**
* Utility macro to implement signal emission implementa una delle seguenti:
*
* // metodo standard con cast //
* SignalBase * sig = this->findSignal((void (Ob1::*)(void))&Ob1::V0);
* typedef Signal<void()>::type SigT;
* if(sig) reinterpret_cast<SigT*>(sig)->operator()();
*
* // cast automatico //
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
* sig->operator()();
*/
#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__)
namespace uLib {
// A boost::signal wrapper structure ///////////////////////////////////////////
// TODO ...
typedef boost::signals2::signal_base SignalBase;
template <typename T>
struct Signal {
typedef boost::signals2::signal<T> type;
};
////////////////////////////////////////////////////////////////////////////////
namespace detail {
template <typename FuncT, int arity>
struct ConnectSignal {};
template <typename FuncT>
struct ConnectSignal< FuncT, 0 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(slof);
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 1 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 2 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 3 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 4 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 5 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionTypes<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4));
}
};
} // detail
template <typename FuncT>
SignalBase *NewSignal(FuncT f) {
// seems to work wow !
return new Signal<void()>::type;
}
template <typename FuncT>
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionTypes<FuncT>::Object *receiver)
{
detail::ConnectSignal< FuncT, FunctionTypes<FuncT>::arity >::connect(sigb,slof,receiver);
}
} // uLib
#endif // SIGNAL_H

46
src/Core/Singleton.h Normal file
View File

@@ -0,0 +1,46 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SINGLETON_H
#define U_CORE_SINGLETON_H
#include <boost/serialization/singleton.hpp>
namespace uLib {
template <typename T>
struct Singleton : boost::serialization::singleton<T> {
};
}
#endif // SINGLETON_H

114
src/Core/SmartPointer.h Normal file
View File

@@ -0,0 +1,114 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SMARTPOINTER_H
#define U_CORE_SMARTPOINTER_H
namespace uLib {
class SmartPointerBase {};
template <typename T>
class SmartPointer : SmartPointerBase {
typedef T element_type;
public:
explicit
SmartPointer(T* ptr = NULL) : m_counter(0) {
// if(!ptr) ptr = new T;
if (ptr) m_counter = new ReferenceCounter(ptr); // ???
}
// TakeReference //
SmartPointer(T &ref) : m_counter(new ReferenceCounter(&ref,0)) { }
SmartPointer(const SmartPointer& copy) throw () {
acquire(copy.m_counter);
}
SmartPointer(SmartPointer * copy) throw () {
acquire(copy->m_counter);
}
virtual ~SmartPointer() { release(); }
SmartPointer & operator=(const SmartPointer& copy) {
if (this != &copy)
{
release();
acquire(copy.m_counter);
}
return *this;
}
T & operator*() const throw () { return *m_counter->ptr; }
T * operator->() const throw () { return m_counter->ptr; }
T * get() const throw () {
return m_counter ? m_counter->ptr : 0; }
bool unique() const throw () {
return (m_counter ? m_counter->count == 1 : true); }
private:
struct ReferenceCounter
{
ReferenceCounter(T* ptr = 0, unsigned c = 1) : ptr(ptr), count(c) { }
T* ptr;
unsigned count;
} * m_counter;
// increment the count
void acquire(ReferenceCounter* c) throw ()
{
m_counter = c;
if (c && c->count>0) ++c->count;
}
// decrement the count, delete if it is 0
void release() {
if (m_counter) {
if (--m_counter->count == 0) {
delete m_counter->ptr;
}
if (m_counter->count <= 0) {
delete m_counter;
m_counter = NULL;
}
}
}
};
}
#endif // SMARTPOINTER_H

View File

@@ -0,0 +1,77 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_STATICINTERFACE_H
#define U_CORE_STATICINTERFACE_H
namespace uLib {
#define MAKE_TRAITS ; // TODO
#define uLibCheckFunction(class_name,name,out, ... ) \
{ out (class_name::*x)(__VA_ARGS__) = &class_name::name; (void) x; }
#define uLibCheckConstFunction(class_name,name,out,...) \
{ out (class_name::*x)(__VA_ARGS__) const = &class_name::name; (void) x; }
#define uLibCheckMember(class_name,name,type) \
{ class_name x; type *y = &x.name; (void) y; }
namespace Interface {
// EXAMPLE :
//template <class T> struct Voxel {
// MAKE_TRAITS;
// template<class Self> void check_structural() {
// { float & (Self::*x)() = &Self::Density; (void) x; }
// { int & (Self::*x)() = &Self::TrackCount; (void) x; }
// }
//protected:
// ~Voxel() {}
//};
template <class T, class SI>
static inline void IsA() {
(void) ((void (SI::*)()) &SI::template check_structural<T>);
}
// not working
//template <class T, class SI>
//struct StaticIsA {
// void test() {
// static const void (SI::*x)() = SI::template check_structural<T>;
// }
//};
}
}
#endif // STATICINTERFACE_H

21
src/Core/String.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef U_CORE_STRING_H
#define U_CORE_STRING_H
#include <string>
#include <sstream>
namespace uLib {
typedef std::string String;
typedef std::wstring Stringw;
}
template < typename C >
std::basic_string<C> & operator << (std::basic_string<C> &str, const C *c_str) {
std::basic_stringstream<C> ss(c_str);
str += ss.str();
return str;
}
#endif // STRING_H

94
src/Core/StringReader.h Normal file
View File

@@ -0,0 +1,94 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_STRINGREADER_H
#define U_CORE_STRINGREADER_H
#include <istream>
#include <algorithm>
#include "Core/Vector.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
// RIPENSARE COMPLETAMENTE !!!
namespace uLib {
struct StringReader {
std::istream & m_is;
StringReader(std::istream &is) : m_is(is) {}
void ReadString(const char *str) {
// // clean compared string //
// char chars[] = " \t\n";
// for (unsigned int i = 0; i < strlen(chars); ++i)
// { cmps.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); }
// SISTEMARE !!!
int pos = 0;
char c;
while( pos < strlen(str) ) {
while( IsEscape(str[pos])) pos++;
if ( pos >= strlen(str) ) break;
while( IsEscape(c = m_is.get()) );
if (c == str[pos] ) pos++;
else pos = 0;
}
}
static inline bool IsEscape(char c){
const char *escapes = " \r\n\t";
for ( int i = 0 ; i < 4 ; ++i) {
if(c == escapes[i]) return true;
}
return false;
}
};
template <typename T>
inline StringReader & operator >> (StringReader &isr, T &t) {
isr.m_is >> t;
return isr;
}
inline StringReader & operator >> (StringReader &isr, const char *str) {
isr.ReadString(str);
return isr;
}
} // uLib
#endif // STRINGREADER_H

278
src/Core/Types.h Normal file
View File

@@ -0,0 +1,278 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_TYPES_H
#define U_CORE_TYPES_H
#include <iostream>
#include <typeinfo>
#include <boost/preprocessor.hpp>
#include <ltk/ltktypes.h>
#include "Core/Macros.h"
#include "Core/Mpl.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
namespace detail {
struct TypeIntrospection {
// BOOST IMPL //
BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
// SFINAE IMPL //
/*
template <typename T>
struct has_type_info {
typedef char yes[1];
typedef char no[2];
template <typename U> static yes& test(typename U::type_info::BaseList*);
template <typename > static no& test(...);
// struct apply {
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
typedef boost::mpl::bool_<value> type;
// };
};
*/
/** IsA Introspectable Object Implementation Template */
template <class T>
struct IsIntrospectable : has_type_info<T> {};
template <typename T> struct access {
typedef typename T::type_info type_info;
};
template <typename T>
struct child_first_impl {
template <class T1, bool cond>
struct lambda_CFList_f {
typedef mpl::vector<T1> type;
};
template <class T1>
struct lambda_CFList_f<T1,true> {
// typedef typename T1::type_info::CFList type;
typedef typename access<T1>::type_info::CFList type;
};
template <class T1>
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
/** Transforms all Base Type into proper CFList */
typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
, lambda_CFList<mpl::_>
>::type CFListSeq;
/** Folds each CFList into a new sequence */
typedef typename mpl::fold< CFListSeq
, mpl::vector<>
, mpl::copy< mpl::_1
, mpl::back_inserter<mpl::_2>
>
>::type Childs;
/** Add This Class to final CFList sequence */
typedef typename mpl::copy< Childs
, mpl::back_inserter< mpl::vector<T> >
>::type type;
};
/**
* Tests if T has a member called type_info then compile type CFList
*/
template <typename T>
struct child_first : mpl::if_< has_type_info<T>
, child_first_impl<T>
, mpl::vector<>
>::type {};
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE ADAPTERS // FINIRE !!!
//#define _REPETITION_V(vz,vn,vdata)
//template < class TypeList >
//class TypeAdapterInputInterface {
// virtual ~TypeAdapterInputInterface() {}
//public:
// virtual void operator()(int val) {}
// virtual void operator()(std::string val) {}
//};
} // detail ////////////////////////////////////////////////////////////////////
#define CONSTEXPR BOOST_CONSTEXPR
typedef ltk::Real_t Real_t;
typedef ltk::Id_t Id_t;
typedef ltk::Size_t Size_t;
typedef ltk::Pointer_t Pointer_t;
typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
//--- bit manipulation ---------------------------------------------------------
#ifndef BIT
#define BIT(n) (1ULL << (n))
#endif
#ifndef SETBIT
#define SETBIT(n,i) ((n) |= BIT(i))
#endif
#ifndef CLRBIT
#define CLRBIT(n,i) ((n) &= ~BIT(i))
#endif
#ifndef TESTBIT
#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
#endif
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE INTROSPECTION FOR OBJECTS //
#define uLibTypeMacro(thisClass,...) \
\
/* Friendship detail for accessing introspection */ \
template <typename> friend class uLib::detail::TypeIntrospection::access; \
\
/* type info structure*/ public: \
/* in GCC 4.8 must be public or dynamic_cast wont work */ \
struct type_info { \
/*WARNING: -std=c++0x required for this! */ \
constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \
typedef thisClass ThisClass; \
typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
}; \
\
public: \
typedef type_info::BaseClass BaseClass; \
virtual const char *type_name() const { return type_info::name; } \
/* Object Props fwd declaration*/ \
struct ObjectProps; \
/**/
/**
* TypeList inheritance introspection
*/
struct TypeIntrospection {
template <typename T>
struct child_first : detail::TypeIntrospection::child_first<T> {};
};
// SISTEMARE //
struct PrintTypeId {
template <class T>
void operator()(T) const
{ std::cout << typeid(T).name() << std::endl; }
template <typename SeqT>
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
template <typename Class>
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
};
// ACCESS //
struct Access {};
template <class T> struct Access2 {};
} // uLib
#endif // U_CORE_TYPES_H

45
src/Core/Uuid.cpp Normal file
View File

@@ -0,0 +1,45 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Uuid.h"
#include "Singleton.h"
using namespace uLib;
uLib::uuid_t uLib::uLib_dns_uuid;
TypeRegister* TypeRegister::s_Instance = new TypeRegister();
TypeRegister::TypeRegister() :
BaseClass(uLib_dns_uuid)
{}
TypeRegister * TypeRegister::Controller() {
return TypeRegister::s_Instance;
}

163
src/Core/Uuid.h Normal file
View File

@@ -0,0 +1,163 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_UUID_H
#define U_CORE_UUID_H
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "Core/Mpl.h"
#include "Core/Vector.h"
#include "Core/Object.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Object Registration //
typedef boost::uuids::uuid uuid_t;
extern uuid_t uLib_dns_uuid;
template < typename T >
class type_id : public boost::uuids::uuid {
public:
type_id() :
m_size(sizeof(T)),
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name()))
{
std::cout << "Request for register new type\n" <<
"name: " << typeid(T).name() << "\n" <<
"uuid: " << to_string(*this) << "\n";
}
explicit type_id(boost::uuids::uuid const& u)
: boost::uuids::uuid(u) {}
operator boost::uuids::uuid() {
return static_cast<boost::uuids::uuid&>(*this);
}
operator boost::uuids::uuid() const {
return static_cast<boost::uuids::uuid const&>(*this);
}
unsigned int size() const { return m_size; }
private:
unsigned int m_size;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE REGISTER //
namespace detail {
class TypeRegister {
typedef boost::uuids::name_generator IDGen_t;
public:
struct RegisterEntry {
uuid_t id;
int size;
};
TypeRegister(uuid_t const &dns) :
gen(dns) {}
template< typename T >
RegisterEntry * AddType(T *t = NULL) {
RegisterEntry en = { gen(typeid(T).name()), sizeof(T) };
for(int i=0; i < m_registry.size(); ++i)
if(en.id == m_registry[i].id) return &(m_registry[i]);
m_registry.push_back(en);
return &m_registry.back();
}
void PrintSelf(std::ostream &o) {
std::cout << "RegisterController: \n";
for (int i=0; i<m_registry.size(); ++i)
o << "type [" << i << "]: "
<< to_string(m_registry[i].id) << " "
<< m_registry[i].size << "\n";
o << "\n";
}
private:
IDGen_t gen;
Vector<RegisterEntry> m_registry;
};
} // detail
class TypeRegister : public detail::TypeRegister {
public:
typedef detail::TypeRegister BaseClass;
typedef detail::TypeRegister::RegisterEntry Entry;
static TypeRegister* Controller();
private:
TypeRegister(); // Blocks constructor
static TypeRegister *s_Instance; // Singleton instance
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT REGISTER //
} // uLib
#endif // UUID_H

195
src/Core/Vector.h Normal file
View File

@@ -0,0 +1,195 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_VECTOR_H
#define U_CORE_VECTOR_H
#include <vector>
#include <iostream>
#include <Core/Macros.h>
#include <Core/SmartPointer.h>
#include <Core/CommaInitializer.h>
namespace uLib {
// Vector Implemetation ... wraps std::vector
template <typename T>
class Vector : public std::vector<T, std::allocator<T> >
{
typedef std::vector< T,std::allocator<T> > BaseClass;
typedef std::allocator<T> Allocator;
public:
typedef T TypeData;
typedef __gnu_cxx::__normal_iterator<T*, BaseClass > Iterator;
typedef __gnu_cxx::__normal_iterator<const T*, BaseClass> ConstIterator;
typedef CommaInitializer< Vector<T> , T > VectorCommaInit;
Vector(unsigned int size) : BaseClass(size) {}
Vector(unsigned int size, T &value) : BaseClass(size,value) {}
Vector() : BaseClass(0) {}
inline VectorCommaInit operator <<(T scalar) {
return VectorCommaInit(this, scalar);
}
inline void PrintSelf(std::ostream &o);
void remove_element(unsigned int index) {
std::swap(this->at(index),this->back());
this->pop_back();
}
void remove_element(T &t) {
std::swap(t, this->back());
this->pop_back();
}
};
template<typename T>
void Vector<T>::PrintSelf(std::ostream &o)
{
o << " *** uLib Vector *** \n";
o << " n. of items = " << this->size() << "\n";
for(int i=0; i< this->size(); ++i)
o << (T)this->at(i) << " ";
o << "\n";
}
template <typename T>
std::ostream &operator << (std::ostream &o, const Vector<T> &v) {
for(int i=0; i< v.size(); ++i)
o << (T)v.at(i) << " ";
o << "\n";
return o;
}
template <typename T>
std::ofstream &operator << (std::ofstream &o, const Vector<T> &v) {
for(int i=0; i< v.size(); ++i)
o << (T)v.at(i) << " ";
return o;
}
// MATH OPERATIONS //
#define ULIB_CONTAINER_MATHOP(container,op) \
template < typename T1, typename T2 > \
inline container<T1> & operator op##= (container<T1> &src, const T2 data) { \
foreach (T1 &el, src) { \
el op##= static_cast<T1>(data); \
} \
} \
\
template < typename T1, typename T2 > \
inline container<T1> operator op (const container<T1> &src, const T2 data) { \
container<T1> out(src); \
out op##= data; \
return out; \
} \
//
ULIB_CONTAINER_MATHOP(Vector,+)
ULIB_CONTAINER_MATHOP(Vector,-)
ULIB_CONTAINER_MATHOP(Vector,*)
ULIB_CONTAINER_MATHOP(Vector,/)
// Smart pointer Vector Implementation //
template <typename T>
class SmartVector : public SmartPointer< Vector<T> > {
typedef SmartPointer< Vector<T> > Base;
public:
SmartVector() : Base(NULL) { }
// SmartVector() : Base(new Vector<T>()) { }
SmartVector( const SmartVector &copy) : Base(copy) { }
SmartVector(unsigned int size) : Base(new Vector<T>((int)size)) { }
virtual ~SmartVector() {}
T& operator[](int p) {
return Base::get()->at(p);
}
void swap_elements(unsigned int first, unsigned int second) {
std::swap(Base::get()->at(first),Base::get()->at(second));
}
void remove_element(unsigned int index) {
std::swap(Base::get()->at(index),Base::get()->back());
Base::get()->pop_back();
}
void remove_element(T &t) {
std::swap(t, Base::get()->back());
Base::get()->pop_back();
}
};
// ------ Utils ------------------------------------------------------------- //
// RIFARE con iteratore !
template <typename _Tp, class _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
_Tp it = _it;
_Tp end = _end-1;
for(it; it != end;)
{
if (_comp(*it,value)) ++it;
else if(_comp(*end,value)) std::swap(*it,*end--);
else --end;
}
return it - _it;
}
} // uLib
#endif // VECTOR_H

View File

@@ -0,0 +1,88 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Core/Object.h>
#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include "testing-prototype.h"
using namespace boost::accumulators;
using namespace boost;
using namespace boost::accumulators;
typedef accumulator_set<double, features<tag::density> > acc;
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
template <typename T>
class data_filler
{
public:
data_filler(){}
T operator()() { return rand()/(T)RAND_MAX; }
};
int main(int argc, char** argv)
{
//create some random data
std::vector<double> data(100);
std::generate(data.begin(), data.end(), data_filler<double>());
int c = data.size();//cache size for histogramm.
//create an accumulator
acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);
//fill accumulator
for (int j = 0; j < c; ++j)
{
myAccumulator(data[j]);
}
histogram_type hist = density(myAccumulator);
double total = 0.0;
for( int i = 0; i < hist.size(); i++ )
{
std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl;
total += hist[i].second;
}
std::cout << "Total: " << total << std::endl; //should be 1 (and it is)
return 0;
}

View File

@@ -0,0 +1,64 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Options.h"
#include "Core/Singleton.h"
#include "testing-prototype.h"
using namespace uLib;
struct A : Object {
A() : a(0) {}
int a;
};
int main(int argc, char **argv)
{
BEGIN_TESTING(Boost Mock);
A &a = Singleton<A>::get_mutable_instance();
a.a = 5552368;
const A &aa = Singleton<A>::get_const_instance();
std::cout << a.a << "\n";
std::cout << aa.a << "\n";
TEST1( a.a == 5552368 );
TEST1( aa.a == 5552368 );
END_TESTING;
}

View File

@@ -0,0 +1,34 @@
# TESTS
set( TESTS
SmartVectorTest
VectorTest
ObjectFlagsTest
ObjectParametersTest
ObjectCopyTest
StaticInterfaceTest
CommaInitTest
DebugTTreeDumpTest
BoostTest
BoostAccumulatorTest
PropertiesTest
FunctionTest
SignalTest
SerializeTest
SerializeDreadDiamondTest
DreadDiamondParameters
ObjectPropableTest
UuidTest
TypeIntrospectionTraversal
OptionsTest
)
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES}
)
uLib_add_tests(${uLib-module})

View File

@@ -0,0 +1,57 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include<stdio.h>
#define test_print(file,str,...) \
printf(str,__VA_ARGS__)
using namespace uLib;
int main()
{
BEGIN_TESTING( Comma Init );
Vector<int> test;
test << 1,2,3,4,5;
test.PrintSelf(std::cout);
test_print(stdout,"ciao %d \n",5);
printf("ciao\n");
END_TESTING;
}

View File

@@ -0,0 +1,118 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Debug.h"
#include <boost/any.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/include/push_back.hpp>
#include <Rtypes.h>
#include <TFile.h>
#include <TObject.h>
#include <TTree.h>
#include <TApplication.h>
#include <TBrowser.h>
using namespace uLib;
class DebugAdapterTTree : public detail::DebugAdapterInterface {
TTree *m_tree;
public:
DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {}
~DebugAdapterTTree() { delete m_tree; }
void operator()(int val) {
std::cout << "debugger 2 prints: " << val << "\n";
}
};
int main(int argc, char **argv)
{
{
Debug debug;
DebugAdapterText adapter(std::cout);
DebugAdapterTTree treead("test");
debug.AddAdapter(adapter);
debug.AddAdapter(treead);
int a = 5552368;
debug("a",a);
std::string str = "ciao";
debug("str",str);
debug.Update();
}
// TestTObject *test = new TestTObject;
TFile *file = new TFile("test_file.root","RECREATE");
file->cd();
TTree *tree = new TTree;
// tree->Branch("test",&test);
// for(int i=0;i<10;++i) {
// test->a = i;
// test->b = -i;
// tree->Fill();
// }
tree->Write();
gApplication = new TApplication("My ROOT Application", &argc, argv);
TBrowser *tbr = new TBrowser("test");
tbr->Show();
gApplication->Run();
return 0;
}

View File

@@ -0,0 +1,80 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include "testing-prototype.h"
#include "Core/Object.h"
#include "Math/Dense.h"
#include "Core/Mpl.h"
using namespace uLib;
//////////////////////////////////////////////////////////////////////////////
int main() {
}

76
src/Core/testing/Flags.h Normal file
View File

@@ -0,0 +1,76 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_FLAGS_H
#define U_CORE_FLAGS_H
namespace uLib {
template<typename T> class Flags
{
T i;
public:
typedef T EnumT;
inline Flags(const Flags &f) : i(f.i) {}
inline Flags() : i((T)0) {}
inline Flags(T f) : i(f) {}
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
inline Flags &operator&=(T mask) { i &= mask; return *this; }
inline Flags &operator|=(const Flags f) { i |= f.i; return *this; }
inline Flags &operator|=(const T f) { i |= f; return *this; }
inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; }
inline Flags &operator^=(const T f) { i ^= f; return *this; }
inline Flags operator|(const Flags f) const { return Flags(i | f.i); }
inline Flags operator|(const T f) const { return Flags(i | f); }
inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); }
inline Flags operator^(const T f) const { return Flags(i ^ f); }
inline Flags operator&(const Flags f) const { return Flags(i & f.i); }
inline Flags operator&(const T f) const { return Flags(i & f); }
inline Flags operator~() const { return Flags(~i); }
inline bool operator !() const { return !i; }
inline bool testFlag(const T f) const
{ return (i & f) == f && (f != 0 || i == f ); }
// inline bool operator==(const T f) const { return i==f; }
inline T operator()() { return i; }
inline operator T() const { return i; }
};
typedef Flags<unsigned short> Flags2B;
typedef Flags<unsigned int> Flags4B;
typedef Flags<unsigned long> Flags8B;
} // uLib
#endif // FLAGS_H

View File

@@ -0,0 +1,57 @@
#include <iostream>
#include <typeinfo>
#include <functional>
#include "testing-prototype.h"
#include "Core/Types.h"
#include <Core/Vector.h>
#include <Core/ProgrammableAccessor.h>
namespace uLib {
class TestVoxel {
public:
float m_data;
float Get() { return m_data; }
float ConstGet() const { return m_data; }
float & GetRef() { return m_data; }
const float & ConstGetRef() const { return m_data; }
};
} // uLib
using namespace uLib;
int main() {
BEGIN_TESTING(Function Test);
Vector<TestVoxel> v;
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v.push_back(TestVoxel());
v[5].m_data = 5552368.0;
ProgrammableAccessor<float> f1(&TestVoxel::m_data);
ProgrammableAccessor<float> f2(&TestVoxel::GetRef);
int i=0;
foreach (TestVoxel &el,v) {
f1.Set(&el,i++);
std::cout << " -> " << f2.Get<double>(&el) << "\n";
}
END_TESTING;
}

View File

@@ -0,0 +1,38 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
# if HAVE_CHECK
TESTS = SmartPointerTest \
SmartVectorTest \
VectorTest \
ObjectFlagsTest \
ObjectParametersTest \
ObjectCopyTest \
StaticInterfaceTest \
CommaInitTest \
DebugTTreeDumpTest \
BoostTest \
BoostAccumulatorTest \
PropertiesTest \
SignalTest \
SerializeTest \
SerializeDreadDiamondTest \
DreadDiamondParameters \
ObjectPropableTest \
TypeIntrospectionTraversal \
OptionsTest
# UuidTest
# else
# TEST =
# endif
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
check_PROGRAMS = $(TESTS)
all: $(TESTS)

View File

@@ -0,0 +1,50 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(ObjectParameters);
END_TESTING;
}

View File

@@ -0,0 +1,69 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Core/Object.h"
using namespace uLib;
//class Derived : public uLib::Object {
//public:
// Derived(int flags) : uLib::Object(flags) {}
// enum Flags {
// a = 1<<0, // 1
// b = 1<<1, // 2
// c = 1<<2 // 4
// };
//};
int main() {
BEGIN_TESTING(ObjectFlags);
// Object o(2);
// o.flags() = 4;
// o.flags() |= 1;
// TEST1( o.flags() == 5);
// o.flags() &= 1;
// TEST1( o.flags() == 1);
// TEST1( o.flags().testFlag(1) );
// Derived d( Derived::a | Derived::b);
// d.flags() = Derived::c;
// d.flags() |= Derived::a;
// TEST1( d.flags() == Derived::a | Derived::c);
// d.flags() &= 1;
// TEST1( d.flags() == Derived::a);
// TEST1( d.flags().testFlag(Derived::a) );
END_TESTING
}

View File

@@ -0,0 +1,11 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
LDADD = $(top_srcdir)/libmutom-0.1.la $(AM_LIBS_BOOST)
bin_PROGRAMS = ObjectMock
ObjectMock_SOURCES = main.cpp Ob.cpp Ob1.cpp Ob2.cpp

View File

@@ -0,0 +1,59 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob.h"
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob) // use this in cpp file
namespace uLib {
class ObPrivate {
public:
};
Ob::Ob() :
m_p(NULL),
m_s(NULL),
m_type_id(0),
d(new ObPrivate)
{
}
}

View File

@@ -0,0 +1,181 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB_H
#define OB_H
#include <fstream>
#include <ostream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/signals2/signal.hpp>
#include <Core/Object.h>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include "Core/Uuid.h"
#include "boost/typeof/typeof.hpp"
#include <boost/serialization/binary_object.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/serialization/extended_type_info_typeid.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/base_object.hpp>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Mock of serializable object system //
#define default(vlaue)
#define slots
#define signals public
#define emit
# define SLOT(a) a
# define SIGNAL(a) a
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
//// OB ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Ob {
public:
Ob();
~Ob() {
if(m_p) delete m_p;
}
//// init //////////////////////////////////////////////////////////////////
template <class T>
void init(){
if(!m_type_id) {
m_p = (Parameters *) new typename T::Parameters;
m_type_id = TypeRegister::Controller()->AddType< T >();
}
}
virtual void PrintSelf(std::ostream &o) const { o << "Base Object PrintSelf\n"; }
protected:
// parameters //////////////////////////////////////////////////////////////
struct Parameters { friend class boost::serialization::access; };
inline Parameters &p() { assert(m_p); return *m_p; }
inline const Parameters &p() const { assert(m_p); return *m_p; }
virtual void init() {}
// serialization access ////////////////////////////////////////////////////
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version) {
// ar & boost::serialization::make_nvp("instance_size", m_type_id->size);
// ar & boost::serialization::make_nvp("instance_data",boost::serialization::make_binary_object(this,m_type_id->size));
}
template <class Archive>
static void serialize(Archive &ar, Ob &ob, const unsigned int version) {}
template <class Archive>
static void serialize(Archive &ar, Ob::Parameters &p, const unsigned int version) {}
public:
TypeRegister::Entry * type_id() const { return m_type_id; }
private:
// members /////////////////////////////////////////////////////////////////
struct Parameters *m_p;
struct Signals *m_s;
friend class ObPrivate;
class ObPrivate *d;
TypeRegister::Entry * m_type_id;
};
}
////////////////////////////////////////////////////////////////////////////////
BOOST_CLASS_EXPORT_KEY(uLib::Ob)
#endif

View File

@@ -0,0 +1,80 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob1.h"
namespace uLib {
// created by moc // -------------------------------------------------------- //
void Ob1::init()
{
Ob::init<Ob1>();
boost::serialization::void_cast_register<Ob1,BaseClass>();
BaseClass::init();
// default parameters value //
p().a = 1;
p().b = 2;
}
//// serialization accessor that can be made by moc //
//template <class Archive>
//void Ob1::serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version)
//{
// Ob1::BaseClass::serialize<Archive>( ar,p,version );
// ar & boost::serialization::make_nvp("a",p.a);
// ar & boost::serialization::make_nvp("b",p.b);
//}
//template <class Archive>
//void Ob1::serialize(Archive &ar, Ob1 &ob, const unsigned int version )
//{
// Ob1::BaseClass::serialize<Archive>(ar,ob,version);
// // other members to be serialized //
//}
// -------------------------------------------------------------------------- //
}
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob1) // use this in cpp file

View File

@@ -0,0 +1,122 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB1_H
#define OB1_H
#include <string>
#include "Ob.h"
////////////////////////////////////////////////////////////////////////////////
// OB1 ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
class Ob1 : public Ob {
public:
typedef Ob BaseClass;
struct Parameters : public BaseClass::Parameters {
int a default(1);
int b default(2);
};
virtual ~Ob1() {}
// created by macro ////////////////////////////////////////////////////////
void init();
inline Parameters &p() { return (Parameters &)Ob::p(); }
inline const Parameters &p() const { return (Parameters &)Ob::p(); }
static Ob1 *New() { Ob1 *o = new Ob1; o->init(); return o; }
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version);
template <class Archive>
static void serialize(Archive & ar,
Ob1::Parameters & p,
const unsigned int version );
template <class Archive>
static void serialize(Archive &ar,
Ob1 &ob,
const unsigned int version );
////////////////////////////////////////////////////////////////////////////
virtual void PrintSelf(std::ostream &o) const { o << "Object Ob1 PrintSelf\n"; }
};
// serialize accessors in macro // ------------------------------------------ //
template <class Archive>
void serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version )
{
Ob1::serialize<Archive>(ar,p,version);
}
template<class Archive>
void Ob1::serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::make_nvp("parameters",p());
this->serialize<Archive>(ar,*this,version);
Ob::serialize(ar,version);
}
// -------------------------------------------------------------------------- //
// serialization accessor that can be made by moc //
template <class Archive>
void Ob1::serialize(Archive &ar, Ob1::Parameters &p, const unsigned int version)
{
Ob1::BaseClass::serialize<Archive>( ar,p,version );
ar & boost::serialization::make_nvp("a",p.a);
ar & boost::serialization::make_nvp("b",p.b);
}
template <class Archive>
void Ob1::serialize(Archive &ar, Ob1 &ob, const unsigned int version )
{
Ob1::BaseClass::serialize<Archive>(ar,ob,version);
// other members to be serialized //
}
} // namespace
BOOST_CLASS_EXPORT_KEY(uLib::Ob1) // use this in header
#endif

View File

@@ -0,0 +1,73 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob2.h"
namespace uLib {
// created by moc // -------------------------------------------------------- //
void Ob2::init()
{
Ob::init<Ob2>();
boost::serialization::void_cast_register<Ob2,BaseClass>();
BaseClass::init();
p().c = 3;
p().d = 4;
}
//template <class Archive>
//void Ob2::serialize(Archive &ar, Parameters &p, const unsigned int version)
//{
// Ob2::BaseClass::serialize<Archive>( ar,p,version );
// ar & boost::serialization::make_nvp("c",p.c);
// ar & boost::serialization::make_nvp("d",p.d);
//}
//template <class Archive>
//void Ob2::serialize(Archive &ar, Ob2 &o, const unsigned int version )
//{
// Ob2::BaseClass::serialize<Archive>(ar,o,version);
// ar & boost::serialization::make_nvp("serializzable_member",o.serializzable_member);
// // other members //
//}
// -------------------------------------------------------------------------- //
}
BOOST_CLASS_EXPORT_IMPLEMENT(uLib::Ob2) // use this in cpp file

View File

@@ -0,0 +1,135 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB2_H
#define OB2_H
#include "Ob.h"
#include "Ob1.h"
////////////////////////////////////////////////////////////////////////////////
// OB2 ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
class Ob2 : public Ob1 {
public:
typedef Ob1 BaseClass;
struct Parameters : public BaseClass::Parameters {
int c default(3),d default(4);
};
Ob2() {
serializzable_member = 0;
memset(non_serializable_member,0,sizeof(char[250]));
}
virtual ~Ob2() {}
// created by macro ////////////////////////////////////////////
void init();
inline Parameters &p() { return (Parameters &)Ob::p(); }
inline const Parameters &p() const { return (Parameters &)Ob::p(); }
static Ob2 *New() { Ob2 *o = new Ob2; o->init(); return o; }
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version);
template <class Archive>
static void serialize(Archive & ar, Parameters & p, const unsigned int version );
template <class Archive>
static void serialize(Archive &ar, Ob2 &o, const unsigned int version );
////////////////////////////////////////////////////////////////
virtual void PrintSelf(std::ostream &o) const { o << "Object Ob2 PrintSelf\n"; }
int serializzable_member;
char non_serializable_member[250];
private:
};
template <class Archive>
void serialize(Archive &ar, Ob2::Parameters &p, const unsigned int version )
{
Ob2::serialize<Archive>(ar,p,version);
}
template<class Archive>
void Ob2::serialize(Archive & ar, const unsigned int version)
{
// boost::serialization::split_member(ar, *this, version);
ar & boost::serialization::make_nvp("parameters",p());
this->serialize<Archive>(ar,*this,version);
Ob::serialize(ar,version);
}
template <class Archive>
void Ob2::serialize(Archive &ar, Parameters &p, const unsigned int version)
{
Ob2::BaseClass::serialize<Archive>( ar,p,version );
ar & boost::serialization::make_nvp("c",p.c);
ar & boost::serialization::make_nvp("d",p.d);
}
template <class Archive>
void Ob2::serialize(Archive &ar, Ob2 &o, const unsigned int version )
{
Ob2::BaseClass::serialize<Archive>(ar,o,version);
ar & boost::serialization::make_nvp("serializzable_member",o.serializzable_member);
// other members //
}
}
BOOST_CLASS_EXPORT_KEY(uLib::Ob2) // use this in header
//BOOST_SERIALIZATION_FACTORY_0(uLib::Ob2) // use this for plugin construction
#endif

View File

@@ -0,0 +1,174 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/signals2/signal.hpp>
#include "Ob.h"
#include "Ob1.h"
#include "Ob2.h"
using namespace uLib;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//// test boost ETI system //
// used in external plugin construction mechanism //
int test_boost_eti () {
boost::serialization::extended_type_info_typeid<Ob2> i_eti;
std::cout << "int eti guid key: " << i_eti.get_key() << "\n";
Ob2 *test = (Ob2*)i_eti.construct(0);
test->init();
std::cout << "int eti typeid name: " << i_eti.get_typeid().name() << "\n";
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// main //
int main()
{
// ////////////////////////////////////////////////////
// // serialization tests
{
Ob1 ob1;
ob1.init();
std::cout << "ob1 param: " <<
ob1.p().a << " " <<
ob1.p().b << "\n";
Ob2 *ob2 = Ob2::New();
std::cout << "ob2 param: " <<
ob2->p().a << " " <<
ob2->p().b << " " <<
ob2->p().c << " " <<
ob2->p().d << "\n";
std::cout << "ob2 uuid: " <<
to_string(ob2->type_id()->id) << "\n";
// // serialize ob2 to file //
// {
// std::ofstream ofs("_BoostTest.xml");
// boost::archive::xml_oarchive oa(ofs);
// oa << BOOST_SERIALIZATION_NVP(ob2);
// }
// serialize ob2 to file via objact base cast //
{
Ob *ob = Ob2::New();
sprintf(static_cast<Ob2 *>(ob)->non_serializable_member,
"deserializzati dati interni attraverso dump binario");
std::ofstream ofs("_BoostTest.xml");
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ob);
}
// delete ob2;
// deserialize ob2 from file //
{
Ob2 *newob2 = Ob2::New();
newob2->p().c = 0;
std::ifstream ifs("_BoostTest.xml");
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(*newob2);
printf("%s\n",newob2->non_serializable_member);
std::cout << "deserialized ob2: > " <<
newob2->p().a << " " <<
newob2->p().b << " " <<
newob2->p().c << " " <<
newob2->p().d << "\n";
std::cout << "deserialized ob2 member: " <<
"serializable_member = " << newob2->serializzable_member << "\n";
std::cout << "deserialized ob2 uuid: " <<
to_string(newob2->type_id()->id) << "\n";
}
}
}

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;

View File

@@ -0,0 +1,61 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include "Core/Object.h"
#include "Math/Dense.h"
#include "testing-prototype.h"
using namespace uLib;
int main() {
}

View File

@@ -0,0 +1,237 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Types.h"
#include "Core/Object.h"
#include "Core/ObjectProps.h"
#include "Core/StringReader.h"
#include "Math/Dense.h"
#include "boost/archive/text_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include "testing-prototype.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// STRUCTURES //
struct A : virtual Object {
uLibTypeMacro(A, Object)
properties() {
int p_a;
Vector3f p_3f;
};
int m_a;
};
void A::init_properties() {
$_init();
$$.p_a = 0;
$$.p_3f << 1,2,3;
}
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); }
ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); }
struct B : A {
uLibTypeMacro(B,A)
properties() {
std::string p;
};
B() : m_b(324) {}
int m_b;
};
void B::init_properties() {
$_init();
$$.p = "ciao";
}
ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); }
ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); }
struct C {
int m_c;
std::string m_str;
};
ULIB_SERIALIZABLE(C)
ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); }
struct D : virtual Object, B {
uLibTypeMacro(D,Object,B)
properties() {
C p_c;
};
};
void D::init_properties() {
$_init();
$$.p_c.m_c = 1234;
}
ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D,Object) {}
ULIB_SERIALIZE_OBJECT_PROPS(D) {
ar & AR(p_c);
}
class E : public C, public D {
uLibTypeMacro(E,D,C)
public:
E() : m_Ea(5552368) {}
int m_Ea;
};
ULIB_SERIALIZABLE_OBJECT(E)
ULIB_SERIALIZE_OBJECT(E,C,D) {
ar & AR(m_Ea);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TESTS //
int test_xml_direct() {
// TEST ARCHIVE SAVE AND LOAD direct //
E o; o.init_properties();
o.$$.p_c.m_str = "works";
{
std::ofstream file("test.xml");
Archive::xml_oarchive ar(file);
ar << NVP(o);
}
o.$$.p_c.m_str = "hola";
{
std::ifstream file("test.xml");
Archive::xml_iarchive ar(file);
ar >> NVP(o);
}
std::cout << o.$$.p_c.m_str << "\n";
return ( o.$$.p_c.m_str == "works" );
}
int test_xml_pointer() {
// TEST ARCHIVE SAVE AND LOAD from pointer //
E *o = new E; o->init_properties();
o->$$.p_c.m_str = "works";
{
std::ofstream file("test.xml");
Archive::xml_oarchive ar(file);
ar << NVP(o);
}
o->$$.p_c.m_str = "hola";
{
std::ifstream file("test.xml");
Archive::xml_iarchive ar(file);
ar >> NVP(o);
}
std::cout << o->$$.p_c.m_str << "\n";
return ( o->$$.p_c.m_str == "works" );
}
int test_xml_objsave() {
// TEST SELF SAVE
E o; o.init_properties();
o.$(B).p = "works";
{
std::ofstream file("test.xml");
Object::SaveXml(file,o);
}
o.$(B).p = "hola";
{
std::ifstream file("test.xml");
Object::LoadXml(file,o);
}
std::cout << o.$(B).p << "\n";
return ( o.$(B).p == "works" );
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MAIN //
int main()
{
BEGIN_TESTING(PropableTest);
TEST1( test_xml_direct() );
TEST1( test_xml_pointer() );
TEST1( test_xml_objsave() );
END_TESTING;
}

View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Options.h"
#include "testing-prototype.h"
using namespace uLib;
int main(int argc, char **argv)
{
BEGIN_TESTING(Boost ProgramOptions);
std::string optfile("configuration.ini");
int a = 0;
int b = 0;
Options opt;
opt.add_options()
("help", "printout help")
("value",&a,"value")
("config",&optfile,"config_file");
opt.add_config_options()
("B.value",&b,"b vlaue");
opt.parse_command_line(argc,argv);
opt.parse_config_file(optfile.c_str());
std::cout << "a = " << a << "\n";
std::cout << "b = " << b << "\n";
END_TESTING;
}

View File

@@ -0,0 +1,96 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <boost/signals2/signal.hpp>
#include "Core/Object.h"
#include "testing-prototype.h"
#define emit
template <typename T, bool copyable = true>
class property
{
typedef boost::signals2::signal<void(const property<T>& )> signal_t;
public:
property() : m_changed(new signal_t) {}
property(const T in) : value(in) , m_changed(new signal_t) {}
inline operator T const & () const { return value; }
inline operator T & () { return value; }
inline T & operator = (const T &i) { value = i; return value; }
template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
inline signal_t & valueChanged() { return *m_changed; }
private:
T value;
boost::shared_ptr<signal_t> m_changed;
};
//template <typename T>
//class property <T,false> {
// typedef boost::signals2::signal<void( T )> signal_t;
//public:
// property() : m_changed() {}
// property(const T in) : value(in) , m_changed() {}
// inline operator T const & () const { return value; }
// inline operator T & () { valueChanged()(value); return value; }
// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; }
// template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
// inline signal_t &valueChanged() { return m_changed; }
//private:
// property(const property<T> &);
// property<T> &operator = (const property<T>&);
// T value;
// signal_t m_changed;
//};
// test generic void function slot //
void PrintSlot(const property<int> &i) { std::cout << "slot called, new value = " << i << "!\n"; }
int main()
{
}

View File

@@ -0,0 +1,114 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Object.h"
#include "testing-prototype.h"
using namespace uLib;
struct A : Object {
uLibTypeMacro(A,Object)
A() : numa(5552368) {}
int numa;
};
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) {
ar & AR(numa);
}
struct B : virtual Object {
uLibTypeMacro(B,Object)
B() : numb(5552369) {}
int numb;
};
ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); }
struct C : B {
uLibTypeMacro(C,B)
C() : numc(5552370) {}
int numc;
};
ULIB_SERIALIZABLE_OBJECT(C)
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
struct D : A,B {
uLibTypeMacro(D,A,B)
D() : numd(5552371) {}
int numd;
};
ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); }
main() {
A o; o.init_properties();
Archive::xml_oarchive(std::cout) << NVP(o);
}

View File

@@ -0,0 +1,13 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
LDADD = $(top_srcdir)/libmutom-0.1.la $(AM_LIBS_BOOST)
bin_PROGRAMS = SerializeMock
SerializeMock_SOURCES = main.cpp Ob.cpp Ob1.cpp
#log_archive.cpp

View File

@@ -0,0 +1,103 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// polymorphic_base.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
//#include <boost/archive/polymorphic_oarchive.hpp>
//#include <boost/archive/polymorphic_iarchive.hpp>
//#include <boost/archive/xml_oarchive.hpp>
//#include <boost/archive/xml_iarchive.hpp>
#include "Ob.h"
//// A /////////////////////////////////////////////////////////////////////////
template <class Archive>
void A::serialize(Archive &ar, unsigned int v) {
ar & BOOST_SERIALIZATION_NVP(i);
}
//_SERIALIZE_IMPL(A,boost::archive::polymorphic_oarchive)
SERILIZE_IMPL(A)
void A::Save(boost::archive::polymorphic_oarchive &ar)
{ ar << boost::serialization::make_nvp(boost::serialization::guid<A>(),this); }
// note: only the most derived classes need be exported
// BOOST_CLASS_EXPORT(A)
//// B /////////////////////////////////////////////////////////////////////////
template <class Ar>
void B::serialize(Ar &ar, unsigned int v) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
}
SERILIZE_IMPL(B)
void B::Save(boost::archive::polymorphic_oarchive &ar)
{ ar << boost::serialization::make_nvp(boost::serialization::guid<B>(),this); }
_SPECIALIZE_IS_VIRTUAL_BASE(A,B)
BOOST_CLASS_EXPORT_IMPLEMENT(B)
//// C /////////////////////////////////////////////////////////////////////////
template <class Ar>
void C::serialize(Ar &ar, unsigned int v) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
}
SERILIZE_IMPL(C)
void C::Save(boost::archive::polymorphic_oarchive &ar)
{ ar << boost::serialization::make_nvp(boost::serialization::guid<C>(),this); }
_SPECIALIZE_IS_VIRTUAL_BASE(A,C)
BOOST_CLASS_EXPORT_IMPLEMENT(C)

View File

@@ -0,0 +1,112 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB_H
#define OB_H
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_polymorphic2.hpp
// (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <ostream>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/export.hpp>
#include <boost/preprocessor/seq.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#define _SERIALIZE_IMPL_SEQ \
(boost::archive::polymorphic_iarchive) \
(boost::archive::polymorphic_oarchive) \
(boost::archive::xml_iarchive) \
(boost::archive::xml_oarchive)
#define _SERIALIZE_IMPL(Class,Archive) \
template void Class::serialize(Archive &ar,const unsigned int);
#define _SERIALIZE_IMPL_OP(r,data,elem) _SERIALIZE_IMPL(data,elem)
#define SERILIZE_IMPL(Class) BOOST_PP_SEQ_FOR_EACH(_SERIALIZE_IMPL_OP,Class,_SERIALIZE_IMPL_SEQ)
#define _SPECIALIZE_IS_VIRTUAL_BASE(Base,Derived) namespace boost{ template<> struct is_virtual_base_of<Base,Derived>: public boost::mpl::true_ {}; }
#define _SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _SPECIALIZE_IS_VIRTUAL_BASE(data,elem)
// should pass compilation and execution
namespace boost {
namespace archive {
class polymorphic_oarchive;
class polymorphic_iarchive;
}
}
struct A {
virtual ~A() {}
template <class Archive> void serialize(Archive &ar, unsigned int v);
virtual void Save(boost::archive::polymorphic_oarchive &ar);
int i;
};
struct B : virtual A {
template <class Ar> void serialize(Ar &ar, unsigned int v);
virtual void Save(boost::archive::polymorphic_oarchive &ar);
};
BOOST_CLASS_EXPORT_KEY(B)
struct C : virtual A {
template <class Ar> void serialize(Ar &ar, unsigned int v);
virtual void Save(boost::archive::polymorphic_oarchive &ar);
};
BOOST_CLASS_EXPORT_KEY(C)
#endif

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <boost/serialization/export.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include "Ob.h"
#include "Ob1.h"
template <class Ar>
void D::serialize(Ar &ar, unsigned int v) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(C);
}
SERILIZE_IMPL(D)
void D::Save(boost::archive::polymorphic_oarchive &ar)
{ ar << boost::serialization::make_nvp(boost::serialization::guid<D>(),this); }
_SPECIALIZE_IS_VIRTUAL_BASE(B,D)
_SPECIALIZE_IS_VIRTUAL_BASE(C,D)
BOOST_CLASS_EXPORT_IMPLEMENT(D)

View File

@@ -0,0 +1,45 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB1_H
#define OB1_H
#include "Ob.h"
struct D : B,C {
template <class Ar> void serialize(Ar &ar, unsigned int v);
virtual void Save(boost::archive::polymorphic_oarchive &ar);
};
BOOST_CLASS_EXPORT_KEY(D)
#endif // OB1_H

View File

@@ -0,0 +1,111 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <typeinfo>
#include <fstream>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/serialization/export.hpp"
#include "Ob.h"
#include "Ob1.h"
#include "boost/archive/detail/basic_pointer_oserializer.hpp"
//template class boost::archive::detail::archive_serializer_map<boost::archive::polymorphic_xml_oarchive>;
int main(int /*argc*/, char* /*argv*/[])
{
D d;
A *a = &d;
a->i = 5552368;
A *la = NULL;
D *dla = NULL;
{
std::ofstream file;
file.open("test.xml");
boost::archive::polymorphic_xml_oarchive oa_implementation(file,0);
boost::archive::polymorphic_oarchive & opa = oa_implementation;
opa << BOOST_SERIALIZATION_NVP(a);
a->Save(opa);
file.close();
}
{
std::ifstream file;
file.open("test.xml");
boost::archive::polymorphic_xml_iarchive ia_implementation(file,0);
boost::archive::polymorphic_iarchive & ipa = ia_implementation;
ipa >> BOOST_SERIALIZATION_NVP(la);
ipa >> BOOST_SERIALIZATION_NVP(dla);
file.close();
}
boost::archive::polymorphic_xml_oarchive xoa(std::cout);
dla->Save(xoa);
}

View File

@@ -0,0 +1,249 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Archives.h"
#include "ParticlePhysics/MuonTomography/MuonScatter.h"
#include "testing-prototype.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MANUAL SERIALIZATION //
struct V3f {
float x,y,z;
V3f()
{ x = y = z =0; }
V3f(float x, float y, float z) :
x(x), y(y), z(z) {}
template <class Archive>
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::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 //
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";
Archive::hrt_iarchive ar(ss); ar >> v2;
std::cout << "v2 --> " << v2 << "\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);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT SERIALIZATION //
class A : public virtual Object {
uLibTypeMacro(A,Object)
ULIB_SERIALIZE_ACCESS
public:
A() : m_a(5552368) {}
properties() {
std::string p_a;
};
uLibRefMacro (a,int);
private:
int m_a;
};
void A::init_properties() {
$_init();
$$.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_PROPS(A) {
ar
& "Object A properties: "
& "---> p_a = " & AR(p_a) & "\n";
}
int testing_xml_class() {
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);
}
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();
{
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" );
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MUON SCATTER EXAMPLE //
int testing_mu()
{
std::stringstream ss;
MuonScatter mu;
mu.SetMomentumIn(555);
mu.SetMomentumOut(2368);
{
std::ofstream file("test.txt");
file << mu;
}
mu.SetMomentumIn(0);
mu.SetMomentumOut(0);
{
std::ifstream file("test.txt");
file >> mu;
}
std::cout << mu << "\n";
}
int main() {
BEGIN_TESTING(Serialize Test);
TEST1( test_V3f() );
TEST1( testing_xml_class() );
// testing_hrt_class(); ///// << ERRORE in HRT with properties
TEST1( testing_mu() );
END_TESTING;
}

View File

@@ -0,0 +1,11 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
LDADD = $(top_srcdir)/libmutom-0.1.la $(AM_LIBS_BOOST)
bin_PROGRAMS = SignalMock
SignalMock_SOURCES = main.cpp Ob.cpp Ob1.cpp Ob2.cpp

View File

@@ -0,0 +1,104 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob.h"
namespace uLib {
namespace SignalMock {
class ObPrivate {
public:
struct Signal {
GenericMFPtr sigptr;
std::string sigstr;
SignalBase *signal;
};
Vector<Signal> sigv;
};
Ob::Ob() :
d(new ObPrivate)
{}
void Ob::PrintSelf(std::ostream &o) const
{
o << "OBJECT signal Mock: ------------------\n";
Vector<ObPrivate::Signal>::Iterator itr;
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
{
o << " signal:[ " << itr->sigstr << " ]\n";
}
o << "--------------------------------------\n\n";
}
bool Ob::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name)
{
ObPrivate::Signal s = {fptr,std::string(name),sig};
d->sigv.push_back(s);
}
SignalBase *Ob::findSignalImpl(const GenericMFPtr &fptr)
{
for(int i=0; i<d->sigv.size(); ++i)
{
if(d->sigv[i].sigptr == fptr)
return d->sigv[i].signal;
}
return NULL;
}
}
}

View File

@@ -0,0 +1,348 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef OB_H
#define OB_H
#include <fstream>
#include <ostream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/type_traits.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/typeof/std/utility.hpp>
#include <Core/Object.h>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include "boost/typeof/typeof.hpp"
#include <boost/serialization/binary_object.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/serialization/extended_type_info_typeid.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/base_object.hpp>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Mock of serializable object system //
#define default(vlaue)
#define slots
#define signals public
#define emit
# define SLOT(a) a
# define SIGNAL(a) a
namespace uLib {
namespace SignalMock {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function pointers //
////////////////////////////////////////////////////////////////////////////////
// type synthesize ( please read: boost implementation synthesize.hpp ) //
////////////////////////////////////////////////////////////////////////////////
// TODO: change this to boost implementation //
// return a reference to function ... as the boost signal signature wants
template <typename FuncT>
struct FunctionTypes {};
template <typename R, class O>
struct FunctionTypes< R(O::*)() > {
typedef R ref();
typedef R (ptr)();
typedef O obj;
};
template <typename R, class O, typename T0>
struct FunctionTypes< R(O::*)(T0) > {
typedef R ref(T0);
typedef R (ptr)(T0);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1>
struct FunctionTypes< R(O::*)(T0,T1) > {
typedef R ref(T0,T1);
typedef R (ptr)(T0,T1);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1, typename T2>
struct FunctionTypes< R(O::*)(T0,T1,T2) > {
typedef R ref(T0,T1,T2);
typedef R (ptr)(T0,T1,T2);
typedef O obj;
};
template<typename Func>
struct FunctionPointer {
typedef typename boost::function_types::function_type<Func>::type Signature;
typedef typename FunctionTypes<Func>::ref SignalSignature;
enum {
arity = boost::function_types::function_arity<Func>::value,
ismfp = boost::is_member_function_pointer<Func>::value
};
typedef boost::mpl::bool_< ismfp > HasObjectType;
typedef typename FunctionTypes<Func>::obj Object;
typedef boost::function_traits< Signature > Traits;
virtual void PrintSelf( std::ostream &o ) {
o << "[fp: " << typeid(Signature).name()
<< " arity: " << arity << "]\n"; }
};
//////// generic function holder ///////////////////////////////////////////////
class GenericMFPtr {
typedef void (GenericMFPtr::*_MFPtrStub_t)();
public:
typedef _MFPtrStub_t Type;
GenericMFPtr() {}
template <typename T>
GenericMFPtr(T in) {
m_ptr = reinterpret_cast<_MFPtrStub_t>(in);
}
template <typename T>
inline bool operator == (T in) {
return m_ptr == reinterpret_cast<_MFPtrStub_t>(in);
}
inline bool operator == (const GenericMFPtr &in) {
return m_ptr == in.m_ptr;
}
Type operator()() { return m_ptr; }
_MFPtrStub_t m_ptr;
private:
};
// A boost::signal wrapper structure ///////////////////////////////////////////
// TODO ...
typedef boost::signals2::signal_base SignalBase;
template <typename T>
struct Signal {
typedef boost::signals2::signal<T> type;
};
template <typename FuncT>
SignalBase *NewSignal(FuncT f) {
// seems to work !
return new Signal<void()>::type;
}
////////////////////////////////////////////////////////////////////////////////
template <typename FuncT, int arity>
struct ConnectSignal {};
template <typename FuncT>
struct ConnectSignal< FuncT, 0 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(slof);
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 1 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 2 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 3 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
}
};
////////////////////////////////////////////////////////////////////////////////
//// OB ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Ob {
public:
Ob();
// Qt4 style connector //
static bool connect(const Ob *ob1, const char *signal, const Ob *receiver, const char *slot) {
// 1) find slot pointer from name
// 2) find a way to do connection with no type
// TODO: finire
}
// Qt5 style connector //
template <typename Func1, typename Func2>
static bool connect( typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof)
{
SignalBase *sigb = sender->findSignal(sigf);
typedef boost::signals2::signal<typename FunctionPointer<Func2>::SignalSignature> SigT;
ConnectSignal<Func2,FunctionPointer<Func2>::arity>::connect(sigb,slof,receiver);
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Ob *receiver) {
ConnectSignal<FuncT,FunctionPointer<FuncT>::arity>::connect(sigb,slof,receiver);
}
template< typename FuncT >
inline bool addSignal(FuncT fun, const char *name) {
SignalBase *sig = NewSignal(fun);
addSignalImpl(sig,fun,name);
}
template < typename FuncT >
inline SignalBase *findSignal(FuncT fptr)
{
return findSignalImpl(GenericMFPtr(fptr));
}
template < typename FuncT >
inline boost::signals2::signal< typename FunctionPointer<FuncT>::SignalSignature> *findSignal2(FuncT fptr)
{
return (boost::signals2::signal<typename FunctionPointer<FuncT>::SignalSignature> *)findSignalImpl(GenericMFPtr(fptr));
}
void PrintSelf(std::ostream &o) const;
private:
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
SignalBase *findSignalImpl(const GenericMFPtr &fptr);
friend class ObPrivate;
class ObPrivate *d;
};
} // SignalMock
}
////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,55 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob1.h"
namespace uLib {
void SignalMock::Ob1::PrintHelloOb1() {
std::cout << "Hello Ob1!\n";
}
// created by moc // -------------------------------------------------------- //
// -------------------------------------------------------------------------- //
}

View File

@@ -0,0 +1,68 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef SOB1_H
#define SOB1_H
#include <string>
#include "Ob.h"
////////////////////////////////////////////////////////////////////////////////
// OB1 ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
namespace SignalMock {
class Ob1 : public Ob {
public:
signals:
void TestSignal();
public slots:
void PrintHelloOb1();
};
// serialize accessors in macro // ------------------------------------------ //
// -------------------------------------------------------------------------- //
}
} // namespace
#endif

View File

@@ -0,0 +1,44 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Ob2.h"
namespace uLib {
// created by moc // -------------------------------------------------------- //
// -------------------------------------------------------------------------- //
}

View File

@@ -0,0 +1,57 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef SOB2_H
#define SOB2_H
#include "Ob.h"
#include "Ob1.h"
////////////////////////////////////////////////////////////////////////////////
// OB2 ///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
namespace SignalMock {
class Ob2 : public Ob1 {
public:
typedef Ob1 BaseClass;
private:
};
}
}
#endif

View File

@@ -0,0 +1,180 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <fstream>
#include <boost/signals2/signal.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/typeof/std/utility.hpp>
#include "Ob.h"
#include "Ob1.h"
#include "Ob2.h"
using namespace uLib;
using namespace SignalMock;;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// main //
class OBT1 : public Ob {
public:
signals:
void Sig_v();
void Sig_v(int i);
void Sig_v(int i, int j);
int Sig_i(int i, int j);
int SignalTest(int i,int j);
public slots:
void Slot() {
std::cout << "slot v0 called\n";
}
void Slot(int i) {
std::cout << "slot v1i called with i=" << i << "\n";
}
void Slot(int i,int j) {
std::cout << "slot v2i called with i=" << i << " j=" << j << "\n";
}
int SlotAdd(int i,int j) {
std::cout << "slot i2i called with i=" << i << " j=" << j << "\n";
return i+j;
}
};
// Wrote by moc //
void OBT1::Sig_v() {
// SignalBase * sig = this->findSignal((void(OBT1::*)())&OBT1::Sig_v);
// typedef SignalMock::Signal<void()>::type SigT;
// if(sig) reinterpret_cast<SigT*>(sig)->operator()();
BOOST_AUTO(sig, this->findSignal2((void(OBT1::*)())&OBT1::Sig_v));
sig->operator()();
}
void OBT1::Sig_v(int i) {
SignalBase * sig = this->findSignal((void(OBT1::*)(int))&OBT1::Sig_v);
typedef SignalMock::Signal<void(int)>::type SigT;
if(sig) reinterpret_cast<SigT*>(sig)->operator()(i);
}
void OBT1::Sig_v(int i, int j) {
SignalBase * sig = this->findSignal((void(OBT1::*)(int,int))&OBT1::Sig_v);
typedef SignalMock::Signal<void(int,int)>::type SigT;
if(sig) reinterpret_cast<SigT *>(sig)->operator()(i,j);
}
int OBT1::Sig_i(int i, int j)
{
SignalBase * sig = this->findSignal(&OBT1::Sig_i);
typedef SignalMock::Signal<int(int,int)>::type SigT;
if(sig) return *reinterpret_cast<SigT *>(sig)->operator()(i,j);
else return 0;
}
int OBT1::SignalTest(int i, int j)
{
SignalBase * sig = this->findSignal(&OBT1::SignalTest);
typedef SignalMock::Signal<int(int,int)>::type SigT;
if(sig) return *reinterpret_cast<SigT *>(sig)->operator()(i,j);
else return 0;
}
int main()
{
OBT1 o1,o2;
o1.addSignal(&OBT1::SignalTest, "OBT1::SignalTest");
o1.addSignal((void(OBT1::*)())&OBT1::Sig_v, "OBT1::Sig_v0");
o1.addSignal((void(OBT1::*)(int))&OBT1::Sig_v, "OBT1::Sig_v1i");
Ob::connect(&o1,(void(OBT1::*)())&OBT1::Sig_v,
&o2,(void(OBT1::*)())&OBT1::Slot);
Ob::connect(&o1,(void(OBT1::*)(int))&OBT1::Sig_v,
&o2,(void(OBT1::*)(int))&OBT1::Slot);
Ob::connect(&o1,&OBT1::SignalTest,&o2,&OBT1::SlotAdd);
o1.PrintSelf(std::cout);
// Qt style emit //
emit o1.Sig_v();
emit o1.Sig_v(1);
emit o1.Sig_v(1,2);
std::cout << "return val2 = " << o1.SignalTest(3,4) << "\n";
return 0;
}

View File

@@ -0,0 +1,169 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/typeof/std/utility.hpp>
#include "Ob.h"
#include "Ob1.h"
#include "Ob2.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// main //
class Test : public Ob{
public:
signals:
void PrintSng() { }
void PrintSng2(int i);
void PrintSng3(int i, char c);
};
// written by moc //
void Test::PrintSng2(int i)
{
std::cout << "[Emit signal: PrintSgn2(" << i <<")]\n";
typedef void(Test::* FPtr)(int);
FPtr fptr = &Test::PrintSng2;
typedef Signal<FunctionTypes<FPtr>::arity, typename FunctionTypes<FPtr>::Signature > SType;
SignalBase *s = this->findSignal(fptr);
static_cast<SType *>(s)->m_signal(*this,i);
}
// written by moc //
void Test::PrintSng3(int i,char c)
{
}
class TestSlot: public Ob {
public:
TestSlot(const char *name) : m_name(name) {}
public slots:
void PrintInt(int i) {
std::cout << "SLOT [" << m_name << "]>> TestSlot::PrintInt(" << i << ")\n";
}
private:
std::string m_name;
};
void freeFunction0() {}
void freeFunction1(int i) {}
template <typename FuncT>
void printSignature(FuncT f){
typedef typename boost::function_types::function_type<FuncT>::type Signature;
typedef boost::mpl::if_< boost::mpl::bool_<boost::is_member_function_pointer<FuncT>::value > , typename boost::function_traits< Signature >::arg1_type, void > Object;
std::cout << "***Function Signature ***\n"
<< " type_name : " << typeid(typename boost::function_types::function_type<FuncT>::type).name() << "\n"
// << " object type : " << typeid(typename boost::function_traits< typename boost::function_types::function_type<FuncT>::type >::arg1_type).name() << "\n"
<< " object type : " << typeid(Object).name() << "\n"
<< " is memfn : " << (boost::is_member_function_pointer<FuncT>::value == true) << "\n"
<< " n aguments : " << boost::function_types::function_arity<FuncT>::value << "\n\n";
}
int main()
{
Test t1;
TestSlot t2("slotOb1"),t3("slotOb2");
// in moc we add signals
t1.addSignal(&Test::PrintSng2,"Test::PrintSng2(int)");
t1.addSignal(&Test::PrintSng3,"Test::PrintSng3(int,char)");
SignalBase * signal = t1.findSignal(&Test::PrintSng2);
if(signal)
std::cout << "signal found" << "\n";
Ob::connect(&t1, &Test::PrintSng2,
&t2, &TestSlot::PrintInt);
Ob::connect(&t1, &Test::PrintSng2,
&t3, &TestSlot::PrintInt);
emit t1.PrintSng2(5552368);
// SignalBase *s = NewSignal(&Test::PrintSng2);
// printSignature(&freeFunction0);
printSignature(&freeFunction1);
printSignature(&Test::PrintSng2);
return 0;
}

View File

@@ -0,0 +1,216 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/signals2/signal.hpp>
#include "Ob.h"
#include "Ob1.h"
#include "Ob2.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// main //
class SignalBase {
public:
virtual void call() = 0;
};
template <typename T>
struct Signal : public boost::noncopyable, SignalBase
{
typedef T PtrSignature;
virtual void call() {}
};
template <typename Ret, class Obj>
struct Signal<Ret(Obj::*)()> : public boost::noncopyable, SignalBase
{
typedef boost::function_traits< Ret() > SignatureTraits;
typedef boost::signals2::signal<Ret()> SignalType;
typedef typename SignalType::slot_function_type SlotFunctionType;
typedef typename SignalType::result_type ResultType;
typedef boost::signals2::connection ConnectionType;
Signal() : m_signal() {};
virtual ~Signal() {};
void call() { m_signal(); }
SignalType & signal() { return m_signal; }
protected:
SignalType m_signal;
};
template <typename Ret, class Obj, typename Arg>
struct Signal<Ret(Obj::*)(Arg)> : public boost::noncopyable, SignalBase
{
typedef boost::function_traits< Ret(Arg) > SignatureTraits;
typedef boost::signals2::signal<Ret(Arg)> SignalType;
typedef typename SignalType::slot_function_type SlotFunctionType;
typedef typename SignalType::result_type ResultType;
typedef boost::signals2::connection ConnectionType;
Signal() : m_signal() {};
virtual ~Signal() {};
void call() { m_signal(0); }
SignalType & signal() { return m_signal; }
protected:
SignalType m_signal;
};
template < typename T >
static SignalBase * BuildSig(typename FunctionTypes<T>::Object *obj, T f) {
Signal<T> *s = new Signal<T>;
typename FunctionTypes<T>::Object::TS ts = {
static_cast<SignalBase *>(s),
reinterpret_cast<void *>(f)
};
obj->v.push_back(ts);
return static_cast<SignalBase *>(s);
}
template < typename T >
static SignalBase * FindSignal(typename FunctionTypes<T>::Object *obj, T f) {
void *ptr = reinterpret_cast<void *>(f);
for (int i=0; i<obj->v.size(); ++i)
if(obj->v[i].ptr == ptr) return obj->v[i].sig;
return NULL;
}
template < typename T1, typename T2 >
static bool Connect(typename FunctionTypes<T1>::Object *sender, T1 signal,
typename FunctionTypes<T2>::Object *receiver, T2 slot)
{
SignalBase *s = FindSignal(sender,signal);
if(!s) return false;
static_cast< Signal<T1> * >(s)->signal().connect(boost::bind(slot,receiver));
return true;
}
class Test : public Ob {
public:
struct TS{
SignalBase *sig;
void *ptr;
};
Vector<TS> v;
Test() {
BuildSig(this, &Test::TestSignal);
BuildSig(this, &Test::TestSignal1);
// BuildSig(this, &Test::TestSignal2);
}
signals:
void TestSignal();
void TestSignal1(int);
void TestSignal2(int,int);
public slots:
void PrintHello() { std::cout << "Hello!\n"; }
};
// moc it //
void Test::TestSignal(){
// static SignalBase *signal = BuildSig(this, &Test::TestSignal);
static SignalBase *signal = FindSignal(this,&Test::TestSignal);
signal->call();
// signal->call();
}
void Test::TestSignal1(int)
{
static SignalBase *signal = FindSignal(this,&Test::TestSignal1);
signal->call();
}
void Test::TestSignal2(int,int)
{
// static SignalBase *signal = FindSignal(this,&Test::TestSignal2);
// signal->call();
}
int main()
{
////////////////////////////////////////////////////
// signalling tests
Test test;
// test.addSignal(&Test::TestSignal,"TestSignal()");
// Test::connect(&test,&Test::TestSignal,&test,&Test::PrintHello);
Connect(&test,&Test::TestSignal,&test,&Test::PrintHello);
emit test.TestSignal();
return 0;
}

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;

View File

@@ -0,0 +1,115 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h"
#include "Core/Signal.h"
using namespace uLib;
class Ob1 : public Object {
public:
signals:
void V0();
int V1(int a);
};
// should be done by moc //
void Ob1::V0() {
ULIB_SIGNAL_EMIT(Ob1::V0);
}
int Ob1::V1(int a) {
ULIB_SIGNAL_EMIT(Ob1::V1,a);
}
class Ob2 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob2 prints V0\n" << std::flush;
}
};
class Ob3 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob3 prints V0\n" << std::flush;
}
void PrintNumber(int n) {
std::cout << "Ob3 is printing number: " << n << "\n";
}
};
int main() {
BEGIN_TESTING(Signals);
Ob1 ob1;
Ob2 ob2;
Ob3 ob3;
Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0);
Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0);
Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber);
// not working yet
// Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0())
ob1.PrintSelf(std::cout);
emit ob1.V0();
emit ob1.V1(5552368);
END_TESTING;
}

View File

@@ -0,0 +1,94 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "Core/SmartPointer.h"
#include "testing-prototype.h"
using namespace uLib;
namespace Test {
struct ObjectMockInterface {
virtual void PrintValue()=0;
virtual int& Value()=0;
};
class ObjectMock : ObjectMockInterface {
int value;
public:
int& Value() { return value; }
void PrintValue() { std::cout << "Value: " << value << "\n"; }
};
} // Test
bool test_smpt(SmartPointer<Test::ObjectMock> &p) {
SmartPointer<Test::ObjectMock> spt = p;
spt->Value() = 5552368;
{
SmartPointer<Test::ObjectMock> copy = spt;
copy->Value() = 123;
}
return (spt->Value() == 123);
}
int main () {
BEGIN_TESTING(SmartPointer);
// HOLD REFERENCE //
{
SmartPointer<Test::ObjectMock> spt(new Test::ObjectMock);
TEST1(test_smpt(spt));
}
{
SmartPointer<Test::ObjectMock> spt;
TEST1(test_smpt(spt));
}
{
SmartPointer<Test::ObjectMock> spt = new SmartPointer<Test::ObjectMock>;
TEST1(test_smpt(spt));
}
// TAKE REFERENCE //
{
Test::ObjectMock obj;
SmartPointer<Test::ObjectMock> spt(obj);
TEST1(test_smpt(spt));
}
END_TESTING;
}

View File

@@ -0,0 +1,120 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include "Core/Object.h"
using namespace uLib;
static int instanziated_objects_number;
class ObjectTest : public Object {
public:
ObjectTest() {
data[0] = 0;
data[1] = 1;
data[2] = 2;
instanziated_objects_number++;
}
ObjectTest(const ObjectTest &copy) {
data[0] = copy.data[0];
data[1] = copy.data[1];
data[2] = copy.data[2];
instanziated_objects_number++;
}
~ObjectTest()
{
instanziated_objects_number--;
}
float data[3];
};
int main() {
BEGIN_TESTING(SmartVector);
instanziated_objects_number =0;
///////////////////////// SMART POINTER FUNCIONALITY ///////////////////////
// int smart vector //
SmartVector<int> sv(10);
for (int i=0;i<10;++i)
sv[i] = i;
// new shallow copy inside a code block //
{
SmartVector<int> newsv = sv;
newsv[5] = 5552368;
TEST1(sv[5] == newsv[5]);
}
// verify that newsv destruction does not delete instance //
TEST1( sv[5] == 5552368 );
SmartVector<ObjectTest> svo(10);
for (int i=0;i<10;++i)
svo[i] = ObjectTest();
TEST1(instanziated_objects_number == 10);
{
SmartVector<ObjectTest> newsvo = svo;
newsvo[5].data[1] = 5552368.0;
TEST1(svo[5].data[1] == newsvo[5].data[1]);
TEST1(instanziated_objects_number == 10);
}
TEST1(instanziated_objects_number == 10);
/////////////////////////// ITERATOR FUNCIONALITY //////////////////////////
Vector<int> v(10);
Vector<int>::Iterator it;
int i=1;
for(it=v.begin() ; it==v.end(); it++, i++)
*it = i;
for(i = 0; i<v.size(); i++)
TEST1( v[i] = i+1 );
Vector<int>::ConstIterator cit;
i=1;
for(cit=v.begin(); cit==v.end(); cit++, i++)
TEST1( *cit == i+1 );
END_TESTING
}

View File

@@ -0,0 +1,112 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include <Core/StaticInterface.h>
namespace uLib {
//// INTERFACE TO COMPLEX CLASS /////
namespace Interface {
struct Test {
MAKE_TRAITS
template<class Self> void check_structural() {
uLibCheckFunction(Self,test,bool,int,float);
uLibCheckMember(Self,testmemb,int);
}
};
}
struct Test {
bool test(int i, float f){}
int testmemb;
};
//// INTERFAC TO SIMPLE CLASS ///////////
namespace Interface {
struct Simple {
MAKE_TRAITS
template<class Self> void check_structural() {
uLibCheckMember(Self,memb1,int);
uLibCheckMember(Self,memb2,float);
}
};
}
struct Simple {
int memb1;
float memb2;
};
/////////////////////////
template <class T>
class UseTest {
public:
UseTest() {
Interface::IsA<T,Interface::Test>();
T t;
int i; float f;
t.test(i,f);
}
};
template <class T>
class UseSimple {
public:
UseSimple() {
Interface::IsA<T,Interface::Simple>();
}
};
}
int main()
{
BEGIN_TESTING(Static Interface);
uLib::UseTest<uLib::Test> u;
uLib::UseSimple<uLib::Simple> s;
END_TESTING;
}

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Types.h"
#include "Core/Object.h"
#include "testing-prototype.h"
using namespace uLib;
int main() {
}

View File

@@ -0,0 +1,45 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "Core/Object.h"
#include "Core/Uuid.h"
#include "testing-prototype.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(uuid);
END_TESTING;
}

View File

@@ -0,0 +1,84 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Core/Vector.h>
#include "testing-prototype.h"
#include <algorithm>
template < typename T >
struct __Cmp {
bool operator()(const T &data, const float value) {
return data <= value;
}
};
template<typename _Tp, typename _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
_Tp it = _it;
_Tp end = _end-1;
for(it; it != end; )
{
if ( _comp(*it, value) ) it++;
else if( _comp(*end, value) )
{
std::swap(*it,*end--);
}
else --end;
}
return it - _it;
}
int main()
{
BEGIN_TESTING(Vector);
uLib::Vector<float> v;
v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3;
int id = VectorSplice(v.begin(),v.end(),3,__Cmp<float>());
std::cout << "id: " << id << "\n";
std::cout << "vector: ";
for(uLib::Vector<float>::Iterator it = v.begin(); it!=v.end(); it++)
std::cout << *it <<" ";
std::cout << std::endl;
// std::sort(v.begin(),v.end(),LT<float>());
END_TESTING;
}

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;