#include <zypp/base/Logger.h>
#include <zypp/base/Exception.h>
-#include <zypp/Range.h>
-#include <zypp/Edition.h>
+#include <zypp/base/String.h>
+#include <zypp/base/Exception.h>
+#include <zypp/base/PtrTypes.h>
+
+#include <zypp/PathInfo.h>
+#include <zypp/SourceFactory.h>
+#include <zypp/source/Builtin.h>
+#include <zypp/source/susetags/SuseTagsImpl.h>
+
+#include <zypp/ResFilters.h>
using namespace std;
using namespace zypp;
-template<class _Compare>
- void allCompare( const Edition & lhs, const Edition & rhs,
- _Compare compare )
- {
- MIL << "===============" << endl;
-#define CMP(O) DBG << compare(lhs,rhs) << '\t' << lhs << '\t' << Rel::O << '\t' << rhs << "\t==> " << compareByRel( Rel::O, lhs, rhs, compare ) << endl
- CMP( NONE );
- CMP( ANY );
- CMP( LT );
- CMP( LE );
- CMP( EQ );
- CMP( GE );
- CMP( GT );
- CMP( NE );
-#undef CMP
- }
+///////////////////////////////////////////////////////////////////
+
+bool all( const ResObject::Ptr & )
+{ return true; }
+
+bool doPrintM( const ResObject::Ptr & p )
+{
+ MIL << *p << endl;
+ return true;
+}
+bool doPrint( const ResObject::Ptr & p )
+{
+ DBG << *p << endl;
+ return true;
+}
-template<class _Compare>
- void allRange( const Edition & lhs, const Edition & rhs)
+struct Print
+{
+ Print( const std::string & name_r )
+ : _name( name_r )
+ {}
+ std::string _name;
+ bool operator()( ResObject::Ptr p ) const
{
- typedef Range<Edition,_Compare> Range;
-
- MIL << "===============" << endl;
-#define CMP(L,R) DBG << Rel::L<<' '<<lhs<< '\t' <<Rel::R<<' '<<rhs << '\t' << overlaps( Range(Rel::L,lhs), Range(Rel::R,rhs) ) << endl
-
- CMP( NONE, NONE );
- CMP( ANY, ANY );
- CMP( LT, LT );
- CMP( LE , LE );
- CMP( EQ, EQ );
- CMP( GE, GE );
- CMP( GT, GT );
- CMP( NE, NE );
-#undef CMP
+ DBG << _name << endl;
+ return true;
}
+};
+
+
/******************************************************************
**
** FUNCTION NAME : main
{
INT << "===[START]==========================================" << endl;
- Edition l( "1.0" );
- Edition r( "1.0","1" );
-
- allRange<Edition::Compare>( l, r );
- allRange<Edition::Match>( l, r );
-
-#if 0
- Edition::Range any;
- DBG << any << endl;
-
- Edition l( "1.0" );
- Edition r( "2.0" );
-
-#define R(O,E) Edition::Range( Rel::O, E )
-
-#define NONE(E) R(NONE,E)
-#define ANY(E) R(ANY,E)
-#define LT(E) R(LT,E)
-#define LE(E) R(LE,E)
-#define EQ(E) R(EQ,E)
-#define GE(E) R(GE,E)
-#define GT(E) R(GT,E)
-#define NE(E) R(NE,E)
-
-#define OV(L,R) DBG << #L << " <> " << #R << " ==> " << Edition::Range::overlaps( L, R ) << endl
-
- ERR << "Omitting Rel::NE" << endl;
-
-#define OVALL( L ) \
- DBG << "----------------------------" << endl; \
- OV( L, NONE(r) ); \
- OV( L, ANY(r) ); \
- OV( L, LT(r) ); \
- OV( L, LE(r) ); \
- OV( L, EQ(r) ); \
- OV( L, GE(r) ); \
- OV( L, GT(r) ); \
- DBG << "----------------------------" << endl;
-
- OVALL( NONE(l) );
- OVALL( ANY(l) );
- OVALL( LT(l) );
- OVALL( LE(l) );
- OVALL( EQ(l) );
- OVALL( GE(l) );
- OVALL( GT(l) );
-
- // same for l > r and l == r
-#endif
+ Pathname f( "./p" );
+ Source src( SourceFactory().createFrom( new source::SuseTagsImpl( f ) ) );
+ INT << src.resolvables().size() << endl;
+
+ src.resolvables().forEach( chain( resfilter::ByKind( ResTraits<Package>::kind ),
+ resfilter::ByName( "rpm" )
+ ),
+ resfilter::chain( Print("1"),
+ chain( resfilter::chain( Print("A"), resfilter::chain( Print("B"), Print("C") ) ),
+ Print("2")
+ )
+ )
+ );
+
+
+
INT << "===[END]============================================" << endl;
return 0;
}
#include <iterator>
#include <zypp/base/Logger.h>
-#include <zypp/base/Exception.h>
#include <zypp/base/String.h>
+#include <zypp/base/Exception.h>
#include <zypp/base/PtrTypes.h>
-#include <zypp/source/susetags/PackagesParser.h>
+#include <zypp/SourceFactory.h>
+
+//#include <zypp/ResStore.h>
+//#include <zypp/ResFilters.h>
using std::endl;
}
};
////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace parser
- { /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- namespace tagfile
- { /////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
- } // namespace tagfile
- ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- } // namespace parser
- ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
using namespace zypp;
using namespace std;
+////////////////////////////////////
+
+struct ResFilter {};
+struct ResActor {};
+
+///////////////////////////////////////////////////////////////////
+
+template<bool _val>
+ struct Always
+ {
+ bool operator()( ResObject::Ptr ) const
+ { return _val; }
+ };
+
+///////////////////////////////////////////////////////////////////
+
+ /** Filter by name. */
+ template <class _Function>
+ struct ByNameFilter
+ {
+ ByNameFilter( const std::string & name_r, const _Function & fnc_r = _Function() )
+ : _name( name_r )
+ , _fnc( fnc_r )
+ {}
+
+ bool operator()( ResObject::Ptr p ) const
+ {
+ return ( p->name() == _name ) && _fnc( p );
+ }
+
+ std::string _name;
+ const _Function & _fnc;
+ };
+
+ /** Convenience creating appropriate ByNameFilter. */
+ template <class _Function>
+ ByNameFilter<_Function> byName( const std::string & name_r, const _Function & fnc_r )
+ { return ByNameFilter<_Function>( name_r, fnc_r ); }
+
+ ByNameFilter<Always<true> > byName( const std::string & name_r )
+ { return ByNameFilter<Always<true> >( name_r ); }
+
+
+///////////////////////////////////////////////////////////////////
+
+ResStore store;
+
+template <class _Function, class _Filter>
+ unsigned sforEach( _Filter filter_r, _Function fnc_r )
+ {
+ unsigned cnt = 0;
+ for ( ResStore::const_iterator it = store.begin(); it != store.end(); ++it )
+ {
+ if ( filter_r( *it ) )
+ {
+ if ( fnc_r( *it ) )
+ ++cnt;
+ else
+ break;
+ }
+ }
+ return cnt;
+ }
+
+template <class _Function>
+ unsigned sforEach( _Function fnc_r )
+ {
+ return sforEach( Always<true>(), fnc_r );
+ }
+
+////////////////////////////////////////////////////////////////////////////
+
+
////////////////////////////////////////////////////////////////////////////
//
// Main
{
std::list<Package::Ptr> result( source::susetags::parsePackages( infile ) );
SEC << result.size() << endl;
+ store.insert( result.begin(), result.end() );
+ MIL << store.size() << endl;
}
catch( Exception & excpt )
{
ZYPP_RETHROW( excpt );
}
+ INT << sforEach( byName("rpm"), Always<true>() ) << endl;
+
INT << "===[END]============================================" << endl;
return 0;
}
Resolvable.h \
ResTraits.h \
ResStore.h \
+ ResFilters.h \
Package.h \
Pathname.h \
Selection.h \
/** Returns current users permission (<tt>[0-7]</tt>)*/
mode_t userMay() const;
- bool userMayR() const { return( userMay() & 01 ); }
+ bool userMayR() const { return( userMay() & 04 ); }
bool userMayW() const { return( userMay() & 02 ); }
- bool userMayX() const { return( userMay() & 04 ); }
+ bool userMayX() const { return( userMay() & 01 ); }
- bool userMayRW() const { return( (userMay() & 03) == 03 ); }
+ bool userMayRW() const { return( (userMay() & 06) == 06 ); }
bool userMayRX() const { return( (userMay() & 05) == 05 ); }
- bool userMayWX() const { return( (userMay() & 06) == 06 ); }
+ bool userMayWX() const { return( (userMay() & 03) == 03 ); }
bool userMayRWX() const { return( userMay() == 07 ); }
//@}
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ResFilters.h
+ *
+*/
+#ifndef ZYPP_RESFILTERS_H
+#define ZYPP_RESFILTERS_H
+
+#include <iosfwd>
+
+#include "zypp/Resolvable.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace resfilter
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // Predefined filters
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ struct True
+ {
+ bool operator()( ResObject::Ptr ) const
+ {
+ return true;
+ }
+ };
+
+ True true_c()
+ { return True(); }
+
+ ///////////////////////////////////////////////////////////////////
+
+ struct False
+ {
+ bool operator()( ResObject::Ptr ) const
+ {
+ return false;
+ }
+ };
+
+ False false_c()
+ { return False(); }
+
+ ///////////////////////////////////////////////////////////////////
+
+ template<class _Condition>
+ struct Not
+ {
+ Not( _Condition cond_r )
+ : _cond( cond_r )
+ {}
+ bool operator()( ResObject::Ptr p ) const
+ {
+ return ! _cond( p );
+ }
+ _Condition _cond;
+ };
+
+ template<class _Condition>
+ Not<_Condition> not_c( _Condition cond_r )
+ {
+ return Not<_Condition>( cond_r );
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ template<class _ACondition, class _BCondition>
+ struct Chain
+ {
+ Chain( _ACondition conda_r, _BCondition condb_r )
+ : _conda( conda_r )
+ , _condb( condb_r )
+ {}
+ bool operator()( ResObject::Ptr p ) const
+ {
+ return _conda( p ) && _condb( p );
+ }
+ _ACondition _conda;
+ _BCondition _condb;
+ };
+
+ template<class _ACondition, class _BCondition>
+ Chain<_ACondition, _BCondition> chain( _ACondition conda_r, _BCondition condb_r )
+ {
+ return Chain<_ACondition, _BCondition>( conda_r, condb_r );
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // Now some Resolvable attributes
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ struct ByKind
+ {
+ ByKind( const ResObject::Kind & kind_r )
+ : _kind( kind_r )
+ {}
+ bool operator()( ResObject::Ptr p ) const
+ {
+ return p->kind() == _kind;
+ }
+ ResObject::Kind _kind;
+ };
+
+ struct ByName
+ {
+ ByName( const std::string & name_r )
+ : _name( name_r )
+ {}
+ bool operator()( ResObject::Ptr p ) const
+ {
+ return p->name() == _name;
+ }
+ std::string _name;
+ };
+
+
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace resfilter
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_RESFILTERS_H
void clear()
{ store().clear(); }
- // query
- template <class _Function>
- _Function forEach( _Function fnc_r )
- { return std::for_each( store().begin(), store().end(), fnc_r ); }
+ /** Query inerface.
+ * Both, \a filter_r and \a fnc_r are expected to be
+ * functions or functors taking a <tt>ResObject::Ptr<\tt>
+ * as argument and return a \c bool.
+ *
+ * forEach iterates over all ResObjects and invokes \a fnc_r,
+ * iff \a filter_r returned \c true. If \a fnc_r returnes
+ * \c false the loop is aborted.
+ *
+ * forEach returns the number of \a fnc_r invocations. Positive
+ * if the loop succeeded. Negative if some call to \a fnc_r
+ * returned \c false.
+ +
+ * \see ResFilters for a collection of predefined filters.
+ */
+ template <class _Function, class _Filter>
+ int forEach( _Filter filter_r, _Function fnc_r ) const
+ {
+ int cnt = 0;
+ for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
+ {
+ if ( filter_r( *it ) )
+ {
+ ++cnt;
+ if ( ! fnc_r( *it ) )
+ return -cnt;
+ }
+ }
+ return cnt;
+ }
template <class _Function>
- _Function forEach( _Function fnc_r ) const
- { return std::for_each( store().begin(), store().end(), fnc_r ); }
+ int forEach( _Function fnc_r ) const
+ {
+ int cnt = 0;
+ for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
+ {
+ ++cnt;
+ if ( ! fnc_r( *it ) )
+ return -cnt;
+ }
+ return cnt;
+ }
private:
/** */
/** \relates ResStore Stream output */
std::ostream & operator<<( std::ostream & str, const ResStore & obj );
- ///////////////////////////////////////////////////////////////////
- //
- // Predefined filters
- //
- ///////////////////////////////////////////////////////////////////
-
- /** Filter by kind. */
- template <class _Function>
- struct ByKindFilter
- {
- ByKindFilter( const ResObject::Kind & kind_r, const _Function & fnc_r )
- : _kind( kind_r )
- , _fnc( fnc_r )
- {}
-
- void operator()( ResObject::Ptr p ) const
- {
- if ( p->kind() == _kind )
- _fnc( p );
- }
-
- ResObject::Kind _kind;
- const _Function & _fnc;
- };
-
- /** Convenience creating appropriate ByKindFilter. */
- template <class _Function>
- ByKindFilter<_Function> byKind( const ResObject::Kind & kind_r, const _Function & fnc_r )
- { return ByKindFilter<_Function>( kind_r, fnc_r ); }
-
- /** Convenience creating appropriate ByKindFilter. */
- template <class _Res, class _Function>
- ByKindFilter<_Function> byKind( const _Function & fnc_r )
- { return ByKindFilter<_Function>( ResTraits<_Res>::kind, fnc_r ); }
-
- ///////////////////////////////////////////////////////////////////
-
- /** Filter by name. */
- template <class _Function>
- struct ByNameFilter
- {
- ByNameFilter( const std::string & name_r, const _Function & fnc_r )
- : _name( name_r )
- , _fnc( fnc_r )
- {}
-
- void operator()( ResObject::Ptr p ) const
- {
- if ( p->name() == _name )
- _fnc( p );
- }
-
- std::string _name;
- const _Function & _fnc;
- };
-
- /** Convenience creating appropriate ByNameFilter. */
- template <class _Function>
- ByNameFilter<_Function> byName( const std::string & name_r, const _Function & fnc_r )
- { return ByNameFilter<_Function>( name_r, fnc_r ); }
-
- ///////////////////////////////////////////////////////////////////
-
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
/** Stream output. */
std::ostream & dumpOn( std::ostream & str ) const;
- public:
+ private:
/** Pointer to implementation */
RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
};
#include <iosfwd>
#include "zypp/source/SourceImpl.h"
+#include "zypp/source/susetags/SuseTagsImpl.h"
#include "zypp/source/yum/YUMSource.h"
///////////////////////////////////////////////////////////////////
sourceincludedir = $(pkgincludedir)/source
sourceinclude_HEADERS = \
- PackagesParser.h
+ PackagesParser.h\
+ SuseTagsImpl.h
noinst_LTLIBRARIES = lib@PACKAGE@_source_susetags.la
## ##################################################
lib@PACKAGE@_source_susetags_la_SOURCES = \
- PackagesParser.cc
+ PackagesParser.cc \
+ SuseTagsImpl.cc
lib@PACKAGE@_source_susetags_la_LIBADD =
ZYPP_THROW( ParseException( "Pkg" ) );
newPkg();
- nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[4]) );
+ nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[3]) );
}
}
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/source/susetags/SuseTagsImpl.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/base/Exception.h"
+
+#include "zypp/PathInfo.h"
+
+#include "zypp/source/susetags/SuseTagsImpl.h"
+#include "zypp/source/susetags/PackagesParser.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace source
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace susetags
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : SuseTagsImpl::SuseTagsImpl
+ // METHOD TYPE : Ctor
+ //
+ SuseTagsImpl::SuseTagsImpl( const Pathname & localDir_r )
+ {
+ PathInfo p( localDir_r );
+ if ( p.isDir() )
+ p( localDir_r + "packages" );
+ if ( ! p.isFile() )
+ ZYPP_THROW( Exception( p.asString()+" is not a file" ) );
+ if ( ! p.userMayR() )
+ ZYPP_THROW( Exception( p.asString()+" no permission to read" ) );
+
+ DBG << "Going to parse " << p << endl;
+ std::list<Package::Ptr> content( parsePackages( p.path() ) );
+ _store.insert( content.begin(), content.end() );
+ DBG << "SuseTagsImpl (fake) from " << p.path() << ": "
+ << content.size() << " packages" << endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : SuseTagsImpl::~SuseTagsImpl
+ // METHOD TYPE : Dtor
+ //
+ SuseTagsImpl::~SuseTagsImpl()
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : SuseTagsImpl::dumpOn
+ // METHOD TYPE : std::ostream &
+ //
+ std::ostream & SuseTagsImpl::dumpOn( std::ostream & str ) const
+ {
+ return str << "SuseTagsImpl";
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace susetags
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace source
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/source/susetags/SuseTagsImpl.h
+ *
+*/
+#ifndef ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H
+#define ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H
+
+#include <iosfwd>
+
+#include "zypp/Pathname.h"
+#include "zypp/source/SourceImpl.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace source
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace susetags
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : SuseTagsImpl
+ //
+ /** */
+ class SuseTagsImpl : public SourceImpl
+ {
+ public:
+ /** \deprecated Interim ctor
+ * \throw EXCEPTION on parse error
+ */
+ SuseTagsImpl( const Pathname & localDir_r );
+ /** Dtor */
+ ~SuseTagsImpl();
+
+ public:
+ /** Stream output. */
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+
+ public:
+
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace susetags
+ ///////////////////////////////////////////////////////////////////
+
+ using susetags::SuseTagsImpl;
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace source
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H
--- /dev/null
+# SuseTagsImpl.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.14 (1.1220.2.195 2005/02/12 12:12:33)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object='.libs/SuseTagsImpl.o'
+
+# Name of the non-PIC object.
+non_pic_object=none
+