7 #include <zypp/base/Logger.h>
8 #include <zypp/base/Exception.h>
9 #include <zypp/base/String.h>
10 #include <zypp/base/PtrTypes.h>
12 #include <zypp/parser/tagfile/Parser.h>
13 #include <zypp/Package.h>
14 #include <zypp/CapSet.h>
15 #include <zypp/CapFactory.h>
16 #include <zypp/detail/PackageImpl.h>
18 #include <zypp/NVRA.h>
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
33 struct PackagesParser : public Parser
35 std::list<Package::Ptr> result;
37 shared_ptr<detail::PackageImpl> pkgImpl;
40 bool pkgPending() const
43 void collectPkg( const shared_ptr<detail::PackageImpl> & nextPkg_r
44 = shared_ptr<detail::PackageImpl>() )
48 result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) );
55 collectPkg( shared_ptr<detail::PackageImpl>(new detail::PackageImpl) );
58 void collectDeps( const std::list<std::string> & depstr_r, CapSet & capset )
60 for ( std::list<std::string>::const_iterator it = depstr_r.begin();
61 it != depstr_r.end(); ++it )
63 capset.insert( CapFactory().parse( ResTraits<Package>::kind, *it ) );
67 /* Consume SingleTag data. */
68 virtual void consume( const STag & stag_r )
70 if ( stag_r.stag.isPlain( "Pkg" ) )
72 std::vector<std::string> words;
73 str::split( stag_r.value, std::back_inserter(words) );
75 if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
76 ZYPP_THROW( ParseException( "Pkg" ) );
79 nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[4]) );
83 /* Consume MulitTag data. */
84 virtual void consume( const MTag & mtag_r )
89 if ( mtag_r.stag.isPlain( "Prv" ) )
91 collectDeps( mtag_r.value, nvrad.provides );
93 else if ( mtag_r.stag.isPlain( "Prq" ) )
95 collectDeps( mtag_r.value, nvrad.prerequires );
97 else if ( mtag_r.stag.isPlain( "Req" ) )
99 collectDeps( mtag_r.value, nvrad.requires );
101 else if ( mtag_r.stag.isPlain( "Con" ) )
103 collectDeps( mtag_r.value, nvrad.conflicts );
105 else if ( mtag_r.stag.isPlain( "Obs" ) )
107 collectDeps( mtag_r.value, nvrad.obsoletes );
111 virtual void parseEnd()
115 /////////////////////////////////////////////////////////////////
116 } // namespace tagfile
117 ///////////////////////////////////////////////////////////////////
118 /////////////////////////////////////////////////////////////////
119 } // namespace parser
120 ///////////////////////////////////////////////////////////////////
121 /////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////////////////////
128 ////////////////////////////////////////////////////////////////////////////
131 using namespace zypp;
132 using namespace zypp::parser::tagfile;
134 ////////////////////////////////////////////////////////////////////////////
136 // Just for the stats
138 ////////////////////////////////////////////////////////////////////////////
143 : _begin( time(NULL) )
145 USR << "START MEASURE..." << endl;
149 USR << "DURATION: " << (time(NULL)-_begin) << " sec." << endl;
152 ////////////////////////////////////////////////////////////////////////////
156 ////////////////////////////////////////////////////////////////////////////
160 ////////////////////////////////////////////////////////////////////////////
161 int main( int argc, char* argv[] )
163 INT << "===[START]==========================================" << endl;
164 string infile( "p" );
171 SEC << p.result.size() << endl;
172 MIL << *p.result.front() << endl;
173 MIL << p.result.front()->deps() << endl;
175 INT << "===[END]============================================" << endl;