backup
[platform/upstream/libzypp.git] / devel / Example.createResolvable.cc
1 #include <iostream>
2 #include <list>
3 #include <string>
4 #include <zypp/base/Logger.h>
5
6 #include <zypp/Package.h>
7 #include <zypp/detail/PackageImpl.h>
8 #include <zypp/CapFactory.h>
9 #include <zypp/CapSet.h>
10
11 using namespace std;
12 using namespace zypp;
13
14 // refine parsing and add it to lib
15 //
16 template<typename _Res>
17   struct CapSetInsert : public std::unary_function<const std::string &, void>
18   {
19     CapSet &   _x;
20     CapFactory _f;
21     CapSetInsert( CapSet & x )
22     : _x(x)
23     {}
24     void operator()( const std::string & v )
25     { _x.insert( _f.parse( ResTraits<_Res>::kind, v ) ); }
26   };
27
28 inline std::list<std::string> parseDeps()
29 {
30   const char * init[] = {
31     "xextra:/usr/X11R6/bin/Xvfb"
32     "/bin/sh",
33     "rpmlib(PayloadFilesHavePrefix) <= 4.0-1",
34     "rpmlib(CompressedFileNames) <= 3.0.4-1",
35     "/bin/sh",
36     "libc.so.6",
37     "libc.so.6(GLIBC_2.0)",
38     "libc.so.6(GLIBC_2.3.4)",
39     "libhd.so.11",
40     "libsysfs.so.1",
41     "rpmlib(PayloadIsBzip2) <= 3.0.5-1",
42   };
43   const char ** begin = init;
44   const char ** end   = init + ( sizeof(init) / sizeof(const char *) );
45
46   std::list<std::string> ret( begin, end );
47   return ret;
48 }
49
50 /******************************************************************
51 **
52 **
53 **      FUNCTION NAME : main
54 **      FUNCTION TYPE : int
55 **
56 **      DESCRIPTION :
57 */
58 int main( int argc, char * argv[] )
59 {
60   INT << "===[START]==========================================" << endl;
61
62   // Collect basic Resolvable data
63   NVRAD dataCollect;
64
65   // parse basic values
66   dataCollect.name    = "foo";
67   dataCollect.edition = Edition("1.0","42");
68   dataCollect.arch    = Arch_i386;
69
70   // parse dependencies
71   std::list<std::string> depList( parseDeps() );
72   try
73     {
74       for_each( depList.begin(), depList.end(),
75                 CapSetInsert<Package>(dataCollect[Dep::PROVIDES]) );
76     }
77   catch(...)
78     {
79       INT << dataCollect[Dep::PROVIDES] << endl;
80     }
81   // ...parse other deps
82
83   // create the object
84   detail::ResImplTraits<detail::PackageImpl>::Ptr pkgImpl;
85   Package::Ptr pkg( detail::makeResolvableAndImpl( dataCollect, pkgImpl ) );
86   DBG << *pkg << endl;
87   DBG << pkg->deps() << endl;
88
89
90   // finalize implementation class construction
91   // ... aditional data ...
92
93   DBG << pkg << endl;
94   DBG << *pkg << endl;
95   DBG << pkg->deps() << endl;
96
97
98   INT << "===[END]============================================" << endl;
99   return 0;
100 }
101