1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/ProductFileReader.h
12 #ifndef ZYPP_PARSER_PRODUCTSDREADER_H
13 #define ZYPP_PARSER_PRODUCTSDREADER_H
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Function.h"
19 #include "zypp/base/InputStream.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/IdString.h"
23 #include "zypp/Edition.h"
24 #include "zypp/Arch.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : ProductFileData
37 /** Data returned by \ref ProductFileReader
38 * \see \ref ProductFileReader
44 /** Ctor takes ownership of \c allocated_r. */
45 ProductFileData( Impl * allocated_r = 0 );
47 /** Whether this is an empty object without valid data. */
49 { return name().empty(); }
52 IdString vendor() const;
53 IdString name() const;
54 Edition edition() const;
57 std::string shortName() const;
58 std::string summary() const;
61 std::string productline() const;
62 std::string registerTarget() const;
63 std::string registerRelease() const;
64 std::string registerFlavor() const;
67 std::string updaterepokey() const;
70 ///////////////////////////////////////////////////////////////////
71 /** \see http://en.opensuse.org/Product_Management/Code11/Upgrade */
76 /** Ctor takes ownership of \c allocated_r. */
77 Upgrade( Impl * allocated_r = 0 );
80 std::string name() const;
81 std::string summary() const;
82 std::string repository() const;
83 std::string product() const;
85 std::string status() const;
88 RWCOW_pointer<Impl> _pimpl;
90 ///////////////////////////////////////////////////////////////////
92 typedef std::vector<Upgrade> Upgrades;
93 const Upgrades & upgrades() const;
96 RWCOW_pointer<Impl> _pimpl;
98 ///////////////////////////////////////////////////////////////////
100 /** \relates ProductFileData Stream output */
101 std::ostream & operator<<( std::ostream & str, const ProductFileData & obj );
103 /** \relates ProductFileData::Upgrade Stream output */
104 std::ostream & operator<<( std::ostream & str, const ProductFileData::Upgrade & obj );
106 ///////////////////////////////////////////////////////////////////
108 // CLASS NAME : ProductFileReader
110 /** Parser for /etc/products.d enries (just relevant entires).
113 * #include "zypp/base/Functional.h" // functor::getAll
115 * std::vector<ProductFileData> result;
116 * ProductFileReader::scanDir( functor::getAll( std::back_inserter( result ) ),
117 * "/etc/products.d" );
120 class ProductFileReader
123 /** Callback being invoked for each \ref ProductFileData parsed.
124 * Return \c false to stop parsing.
126 typedef function<bool( const ProductFileData & )> Consumer;
132 ProductFileReader( const Consumer & consumer_r )
133 : _consumer( consumer_r )
136 ProductFileReader( const Consumer & consumer_r, const InputStream & input_r )
137 : _consumer( consumer_r )
138 { parse( input_r ); }
141 const Consumer & consumer() const
142 { return _consumer; }
144 void setConsumer( const Consumer & consumer_r )
145 { _consumer = consumer_r; }
148 /** Parse the input stream and call \c _consumer for each
151 * Returns \c false if the \c _consumer requested to stop parsing.
153 bool parse( const InputStream & input_r = InputStream() ) const;
156 /** Parse all files (no symlinks) in \c dir_r and call \c consumer_r
157 * for each \ref ProductFileData parsed.
159 * Returns \c false if the \c _consumer requested to stop parsing.
161 static bool scanDir( const Consumer & consumer_r, const Pathname & dir_r );
163 /** Parse one file (or symlink) and return the \ref ProductFileData parsed.
165 static ProductFileData scanFile( const Pathname & file_r );
170 ///////////////////////////////////////////////////////////////////
172 /////////////////////////////////////////////////////////////////
173 } // namespace parser
174 ///////////////////////////////////////////////////////////////////
175 /////////////////////////////////////////////////////////////////
177 ///////////////////////////////////////////////////////////////////
178 #endif // ZYPP_PARSER_PRODUCTSDREADER_H