From 1770d63675a7299ee7c4893290d6ba2b06ee5cca Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Sun, 22 Jan 2006 14:58:12 +0000 Subject: [PATCH] - added devel configure switch zo disable building zmd (in case you one temporarily can't update to requires sqlite) - Added ctor from Resovable::conPtr to NVR, NVRA, NVRAD - base/Iterator.h make some of the iterators provided by the boost iterator library available in zypp. --- Makefile.am | 7 +- configure.ac | 40 +++++-- devel/devel.ma/Main.cc | 302 +++++++++++++++++++++++++++++++++++++------------ zypp/NVR.cc | 9 ++ zypp/NVR.h | 5 + zypp/NVRA.cc | 14 ++- zypp/NVRA.h | 4 + zypp/NVRAD.cc | 10 ++ zypp/NVRAD.h | 6 +- zypp/ResFilters.h | 5 + zypp/base/Iterator.h | 74 ++++++++++++ zypp/base/Makefile.am | 1 + zypp/base/PtrTypes.h | 11 +- 13 files changed, 396 insertions(+), 92 deletions(-) create mode 100644 zypp/base/Iterator.h diff --git a/Makefile.am b/Makefile.am index 80dae86..00e77d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,12 @@ # Do NOT list 'devel' in subdirs. It's developers playgound # and must not prevent anything from building. -SUBDIRS = zypp testsuite zmd +if BUILD_ZMD + SUB_ZMD=zmd +else + SUB_ZMD= +endif +SUBDIRS = zypp testsuite $(SUB_ZMD) ## ################################################## diff --git a/configure.ac b/configure.ac index 55ce23d..269b347 100644 --- a/configure.ac +++ b/configure.ac @@ -109,13 +109,25 @@ if test -z "$XGETTEXT" ; then AC_MSG_ERROR(xgettext is missing; please install gettext-devel.) fi - AC_PATH_PROG(MYRUNTEST, runtest) if test -z "$MYRUNTEST" ; then AC_MSG_ERROR(runtest is missing; please install dejagnu.) fi dnl ================================================== +dnl +dnl Switches during develpoment only. They disable code using +dnl certain libraries (e.g. hal, sqlite) which may be temporarily +dnl unavailable or broken. This is just to allow building and testing +dnl the remaining parts of zypp. +dnl +AC_ARG_ENABLE(faked-hal, [ --enable-faked-hal do not use libhal (DEVELOPMENT ONLY)], + devel_faked_hal=yes, devel_faked_hal=no) + +AC_ARG_ENABLE(faked-zmd, [ --enable-faked-zmd do not build zmd (DEVELOPMENT ONLY)], + devel_faked_zmd=yes, devel_faked_zmd=no) + +dnl ================================================== dnl checks for libraries AC_CHECK_LIB([z], [gzopen], [:], @@ -125,17 +137,18 @@ AC_CHECK_LIB([xml2], [xmlNewTextReader], AC_MSG_ERROR([libxml2 not found. please install libxml2-devel])) dnl sqlite -PKG_CHECK_MODULES(SQLITE, sqlite3, pkg_sqlite=yes, pkg_sqlite=no) -if test ! -f $SQLITE_LIBS/libsqlite3.so; then - echo - AC_MSG_ERROR([Could not find sqlite3 library, please install sqlite-devel]) +if test "x$devel_faked_zmd" = "xyes"; then + AM_CONDITIONAL(BUILD_ZMD, false) +else + AM_CONDITIONAL(BUILD_ZMD, true) + PKG_CHECK_MODULES(SQLITE, sqlite3, pkg_sqlite=yes, pkg_sqlite=no) + if test ! -f $SQLITE_LIBS/libsqlite3.so; then + echo + AC_MSG_ERROR([Could not find sqlite3 library, please install sqlite-devel]) + fi fi - dnl ================================================== -AC_ARG_ENABLE(faked-hal, [ --devel-faked-hal do not use libhal], - devel_faked_hal=yes, devel_faked_hal=no) - if test "x$devel_faked_hal" = "xyes"; then HAL_CFLAGS=-DFAKE_HAL else @@ -235,4 +248,13 @@ Configuration: PREFIX: ${prefix} LIBDIR: ${libdir} + " +if test "x$devel_faked_hal" = "xyes"; then + echo "**WARNIG: faked_hal" +fi +if test "x$devel_faked_zmd" = "xyes"; then + echo "**WARNIG: faked_zmd" +fi +echo + diff --git a/devel/devel.ma/Main.cc b/devel/devel.ma/Main.cc index 21dd202..7d0d594 100644 --- a/devel/devel.ma/Main.cc +++ b/devel/devel.ma/Main.cc @@ -1,9 +1,14 @@ -#include #include -#include -#include +#include +#include +#include +#include + +#include +#include +#include #include #include #include @@ -13,6 +18,15 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + + #include #include #include @@ -21,93 +35,213 @@ using namespace std; using namespace zypp; /////////////////////////////////////////////////////////////////// +#if 0 namespace zypp { -} -/////////////////////////////////////////////////////////////////// + /** + */ -namespace zypp -{ - /** Status bitfield. - * - * \li \c StateField Whether the resolvable is installed - * or uninstalled (available). - * \li \c FreshenField Freshen status computed by the solver. - * \li \c TransactField Wheter to transact this resolvable - * (delete if installed install if uninstalled). - * \li \c TransactByField Who triggered the transaction. Transaction - * bit may be reset by higer levels only. - * \li \c TransactDetailField Reason why the Resolvable transacts. - * Splitted into \c InstallDetailValue and \c RemoveDetailValue - * dependent on the kind of transaction. + template + struct PoolItem + { + typedef ResTraits<_Res>::PtrType Res_Ptr; + typedef ResTraits<_Res>::constPtrType Res_constPtr; + + PoolItem( Res_Ptr res_r ) + : _resolvable( res_r ) + {} + + ResStatus _status; + Res_Ptr _resolvable; + }; + + /** */ - class ResStatus + class Pool { - typedef char FieldType; - // Bit Ranges within FieldType defined by 1st bit and size: - typedef bit::Range StateField; - typedef bit::Range FreshenField; - typedef bit::Range TransactField; - typedef bit::Range TransactByField; - typedef bit::Range TransactDetailField; - // enlarge FieldType if more bit's needed. It's not yet - // checked by the compiler. public: + typedef PoolItem Item; + typedef PoolItem::Res Res; + typedef PoolItem::Res_Ptr Res_Ptr; + typedef PoolItem::Res_constPtr Res_constPtr; - enum StateValue - { - UNINSTALLED = 0, - INSTALLED = StateField::minval - }; - enum FreshenValue - { - UNDETERMINED = 0, - NO_TRIGGER = FreshenField::minval, - TRIGGER_OK, - TRIGGER_FAILED - }; - enum TransactValue - { - KEEP_STATE = 0, - TRANSACT = TransactField::minval - }; - enum TransactByValue - { - SOLVER = 0, - APPL_LOW = TransactByField::minval, - APPL_HIGH, - USER - }; + //private: + typedef ResObject ResT; + typedef ResTraits::KindType ResKindT; + typedef ResTraits::PtrType Res_Ptr; + typedef ResTraits::constPtrType Res_constPtr; - enum InstallDetailValue - { - EXPLICIT_INSTALL = 0, - SOFT_REQUIRES = TransactDetailField::minval - }; - enum RemoveDetailValue - { - EXPLICIT_REMOVE = 0, - DUE_TO_OBSOLETE = TransactDetailField::minval, - DUE_TO_UNLINK - }; + typedef PoolItem ItemT; + typedef std::set KindStoreT; + typedef std::map StorageT; public: - ResStatus() + template + void addResolvables( _InputIterator first_r, _InputIterator last_r ) + + + + //private: + /** */ + StorageT _store; + /** */ + StorageT & store() + { return _store; } + /** */ + const StorageT & store() const + { return _store; } + }; + +} +/////////////////////////////////////////////////////////////////// + +#endif +/////////////////////////////////////////////////////////////////// + +template + struct Counter + { + Counter() + : _value( _IntT(0) ) + {} + + Counter( _IntT value_r ) + : _value( _IntT( value_r ) ) + {} + + operator _IntT &() + { return _value; } + + operator const _IntT &() const + { return _value; } + + _IntT _value; + }; + + +template + class RefFunctor + { + public: + typedef typename _Functor::argument_type argument_type; + typedef typename _Functor::result_type result_type; + + RefFunctor( _Functor & f_r ) + : _f( f_r ) {} - // get/set functions, returnig \c true if requested status change - // was successfull (i.e. leading to the desired transaction). - // If a lower level (e.g.SOLVER) wants to transact, but it's - // already set by a higher level, \c true should be returned. - // Removing a higher levels transaction bit should fail. + result_type operator()( argument_type a1 ) const + { + return _f.operator()( a1 ); + } private: - bit::BitField _bitfield; + _Functor & _f; }; +template + RefFunctor<_Functor> refFunctor( _Functor & f_r ) + { return RefFunctor<_Functor>( f_r ); } + +/////////////////////////////////////////////////////////////////// + +template + typename _Impl::ResType::Ptr fakeResKind( Resolvable::Ptr from_r ) + { + // fake different kind based on NVRAD + NVRAD nvrad( from_r ); + shared_ptr<_Impl> impl; + return detail::makeResolvableAndImpl( nvrad, impl ); + } + +/////////////////////////////////////////////////////////////////// + +struct Rstats : public std::unary_function +{ + void operator()( Resolvable::constPtr ptr ) + { + ++_total; + ++_perKind[ptr->kind()]; + } + + typedef std::map > KindMap; + Counter _total; + KindMap _perKind; +}; + +std::ostream & operator<<( std::ostream & str, const Rstats & obj ) +{ + str << "Total: " << obj._total; + for( Rstats::KindMap::const_iterator it = obj._perKind.begin(); it != obj._perKind.end(); ++it ) + { + str << endl << " " << it->first << ":\t" << it->second; + } + return str; } +/////////////////////////////////////////////////////////////////// + +struct FakeConv : public std::unary_function +{ + void operator()( Resolvable::Ptr ptr ) + { + if ( ptr->name()[0] == 's' ) + { + ptr = fakeResKind( ptr ); + } + else if ( ptr->name()[0] == 'p' ) + { + ptr = fakeResKind( ptr ); + } + _store.insert( ptr ); + } + + std::set _store; + + typedef std::set ContainerT; + typedef ContainerT::iterator IteratorT; + typedef ContainerT::const_iterator ConstIteratorT; + + ConstIteratorT begin() const + { return _store.begin(); } + + ConstIteratorT end() const + { return _store.end(); } + + + template + boost::filter_iterator<_Filter, ConstIteratorT> begin() const + { return boost::make_filter_iterator( _Filter(), begin(), end() ); } + + template + boost::filter_iterator<_Filter, ConstIteratorT> begin( _Filter f ) const + { return boost::make_filter_iterator( f, begin(), end() ); } + + template + boost::filter_iterator<_Filter, ConstIteratorT> end() const + { return boost::make_filter_iterator( _Filter(), end(), end() ); } + + template + boost::filter_iterator<_Filter, ConstIteratorT> end( _Filter f ) const + { return boost::make_filter_iterator( f, end(), end() ); } + +}; + +/////////////////////////////////////////////////////////////////// + +struct xTrue +{ + bool operator()( Resolvable::Ptr p ) const + { + SEC << __FUNCTION__ << ' ' << p << endl; + return true; + } +}; + + + + /****************************************************************** ** ** FUNCTION NAME : main @@ -116,8 +250,34 @@ namespace zypp int main( int argc, char * argv[] ) { INT << "===[START]==========================================" << endl; + string infile( "p" ); + if (argc >= 2 ) + infile = argv[1]; + + Source src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) ); + MIL << src.resolvables().size() << endl; + + FakeConv fakeconv; + for_each( src.resolvables().begin(), src.resolvables().end(), refFunctor(fakeconv) ); + + Rstats rstats = Rstats(); + for_each( fakeconv.begin( resfilter::byKind() ), + fakeconv.end( resfilter::ByName( "Foo" ) ), + refFunctor(rstats) ); + MIL << rstats << endl; + + +#if 0 + rstats = Rstats(); + for_each( boost::make_filter_iterator( resfilter::byKind(), begin, end ), + boost::make_filter_iterator( resfilter::byKind(), end, end ), + refFunctor(rstats) ); + MIL << rstats << endl; +#endif + INT << "===[END]============================================" << endl; return 0; } + diff --git a/zypp/NVR.cc b/zypp/NVR.cc index bb6daf5..fefc97d 100644 --- a/zypp/NVR.cc +++ b/zypp/NVR.cc @@ -12,11 +12,20 @@ #include #include "zypp/NVR.h" +#include "zypp/Resolvable.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + NVR::NVR( Resolvable::constPtr res_r ); + { + if ( res_r ) + { + *this = NVR( res_r->name(), res_r->edition() ); + } + } + /****************************************************************** ** ** FUNCTION NAME : operator<< diff --git a/zypp/NVR.h b/zypp/NVR.h index 0c7ef27..4af39be 100644 --- a/zypp/NVR.h +++ b/zypp/NVR.h @@ -16,6 +16,7 @@ #include #include "zypp/Edition.h" +#include "zypp/ResTraits.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -40,6 +41,10 @@ namespace zypp , edition( edition_r ) {} + /** Ctor from Resolvable::constPtr */ + explicit + NVR( ResTraits::constPtrType res_r ); + /** */ std::string name; /** */ diff --git a/zypp/NVRA.cc b/zypp/NVRA.cc index 96d7e84..5c269f2 100644 --- a/zypp/NVRA.cc +++ b/zypp/NVRA.cc @@ -10,9 +10,9 @@ * */ #include -//#include "zypp/base/Logger.h" #include "zypp/NVRA.h" +#include "zypp/Resolvable.h" using std::endl; @@ -20,11 +20,13 @@ using std::endl; namespace zypp { ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : NVRA - // - /////////////////////////////////////////////////////////////////// + NVRA::NVRA( Resolvable::constPtr res_r ); + { + if ( res_r ) + { + *this = NVRA( res_r->name(), res_r->edition(), res_r->arch() ); + } + } /****************************************************************** ** diff --git a/zypp/NVRA.h b/zypp/NVRA.h index 9f7fd12..d57179e 100644 --- a/zypp/NVRA.h +++ b/zypp/NVRA.h @@ -49,6 +49,10 @@ namespace zypp , arch( arch_r ) {} + /** Ctor from Resolvable::constPtr */ + explicit + NVRA( ResTraits::constPtrType res_r ); + /** */ Arch arch; }; diff --git a/zypp/NVRAD.cc b/zypp/NVRAD.cc index 1506e63..77f2bbc 100644 --- a/zypp/NVRAD.cc +++ b/zypp/NVRAD.cc @@ -11,11 +11,21 @@ */ #include "zypp/NVRAD.h" +#include "zypp/Resolvable.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + NVRAD::NVRAD( Resolvable::constPtr res_r ) + { + if ( res_r ) + { + *this = NVRAD( res_r->name(), res_r->edition(), res_r->arch(), + res_r->deps() ); + } + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/NVRAD.h b/zypp/NVRAD.h index f28107d..275ee85 100644 --- a/zypp/NVRAD.h +++ b/zypp/NVRAD.h @@ -49,7 +49,7 @@ namespace zypp , Dependencies( deps_r ) {} - /** Ctor */ + /** Ctor from Resolvable::constPtr */ explicit NVRAD( const NVR & nvr_r, const Arch & arch_r = Arch(), @@ -57,6 +57,10 @@ namespace zypp : NVRA( nvr_r, arch_r ) , Dependencies( deps_r ) {} + + /** Ctor */ + explicit + NVRAD( Resolvable::constPtr res_r ); }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/ResFilters.h b/zypp/ResFilters.h index a48bd07..47784f9 100644 --- a/zypp/ResFilters.h +++ b/zypp/ResFilters.h @@ -235,6 +235,7 @@ namespace zypp ByKind( const Resolvable::Kind & kind_r ) : _kind( kind_r ) {} + bool operator()( Resolvable::Ptr p ) const { return p->kind() == _kind; @@ -242,6 +243,10 @@ namespace zypp Resolvable::Kind _kind; }; + template + ByKind byKind() + { return ByKind( ResTraits<_Res>::kind ); } + struct ByName { ByName( const std::string & name_r ) diff --git a/zypp/base/Iterator.h b/zypp/base/Iterator.h new file mode 100644 index 0000000..22f7f72 --- /dev/null +++ b/zypp/base/Iterator.h @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/base/Iterator.h + * +*/ +#ifndef ZYPP_BASE_ITERATOR_H +#define ZYPP_BASE_ITERATOR_H + +#include +#include + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + + /** \defgroup ITERATOR Boost.Iterator Library + * + * \see http://www.boost.org/libs/iterator/doc/index.html + * + * \li \b counting_iterator: an iterator over a sequence of + * consecutive values. Implements a "lazy sequence" + * \li \b filter_iterator: an iterator over the subset of elements + * of some sequence which satisfy a given predicate + * \li \b function_output_iterator: an output iterator wrapping a + * unary function object; each time an element is written into + * the dereferenced iterator, it is passed as a parameter to + * the function object. + * \li \b indirect_iterator: an iterator over the objects pointed-to + * by the elements of some sequence. + * \li \b permutation_iterator: an iterator over the elements of + * some random-access sequence, rearranged according to some + * sequence of integer indices. + * \li \b reverse_iterator: an iterator which traverses the elements + * of some bidirectional sequence in reverse. Corrects many of the shortcomings of C++98's std::reverse_iterator. + * \li \b shared_container_iterator: an iterator over elements of + * a container whose lifetime is maintained by a shared_ptr + * stored in the iterator. + * \li \b transform_iterator: an iterator over elements which are + * the result of applying some functional transformation to + * the elements of an underlying sequence. This component + * also replaces the old projection_iterator_adaptor. + * \li \b zip_iterator: an iterator over tuples of the elements + * at corresponding positions of heterogeneous underlying + * iterators. + * + * There are in fact more interesting iterator concepts + * available than the ones listed above. Have a look at them. + * + * Some of the iterator types are already dragged into namespace + * zypp. Feel free to add what's missing. + * + * \todo Separate them into individual zypp header files. + */ + //@{ + + /** \class filter_iterator + */ + using boost::filter_iterator; + + /** \class transform_iterator + */ + using boost::transform_iterator; + + //@} + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_BASE_ITERATOR_H diff --git a/zypp/base/Makefile.am b/zypp/base/Makefile.am index ca5f28d..36b15e3 100644 --- a/zypp/base/Makefile.am +++ b/zypp/base/Makefile.am @@ -15,6 +15,7 @@ baseinclude_HEADERS = \ Exception.h \ Gettext.h \ IOStream.h \ + Iterator.h \ NonCopyable.h \ PtrTypes.h \ ReferenceCounted.h \ diff --git a/zypp/base/PtrTypes.h b/zypp/base/PtrTypes.h index 4d0360a..7194cd3 100644 --- a/zypp/base/PtrTypes.h +++ b/zypp/base/PtrTypes.h @@ -41,20 +41,23 @@ namespace zypp */ /*@{*/ - /** */ + /** \class scoped_ptr scoped_ptr */ using boost::scoped_ptr; - /** */ + /** \class shared_ptr */ using boost::shared_ptr; - /** */ + /** \class weak_ptr */ using boost::weak_ptr; - /** Use boost::intrusive_ptr as Ptr type */ + /** \class intrusive_ptr */ using boost::intrusive_ptr; + /** */ using boost::static_pointer_cast; + /** */ using boost::const_pointer_cast; + /** */ using boost::dynamic_pointer_cast; /////////////////////////////////////////////////////////////////// -- 2.7.4