1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/SolvIdentFile.h
12 #ifndef ZYPP_TARGET_SOLVIDENTFILE_H
13 #define ZYPP_TARGET_SOLVIDENTFILE_H
17 #include "zypp/base/PtrTypes.h"
19 #include "zypp/IdString.h"
20 #include "zypp/Pathname.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
30 /// \class SolvIdentFile
31 /// \short Save and restore a list of solvable names (ident IdString)
32 ///////////////////////////////////////////////////////////////////
35 friend std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
37 typedef std::tr1::unordered_set<IdString> Data;
40 /** Ctor taking the file to read/write. */
41 SolvIdentFile( const Pathname & file_r )
45 /** Return the file path. */
46 const Pathname & file() const
50 * The file is read once on demand. Returns empty \ref Data if
51 * the file does not exist or is not readable.
53 const Data & data() const
57 _dataPtr.reset( new Data );
58 Data & mydata( *_dataPtr );
59 load( _file, mydata );
64 /** Store new \ref Data.
65 * Write the new \ref Data to file, unless we know it
66 * did not change. The directory containing file must
69 void setData( const Data & data_r )
72 _dataPtr.reset( new Data );
74 if ( differs( *_dataPtr, data_r ) )
76 store( _file, data_r );
82 /** Helper testing whether two \ref Data differ. */
83 bool differs( const Data & lhs, const Data & rhs ) const
86 if ( lhs.size() != rhs.size() )
88 for_( it, lhs.begin(), lhs.end() )
90 if ( rhs.find( *it ) == rhs.end() )
95 /** Read \ref Data from \c file_r. */
96 static void load( const Pathname & file_r, Data & data_r );
97 /** Write \ref Data to \c file_r. */
98 static void store( const Pathname & file_r, const Data & data_r );
102 mutable scoped_ptr<Data> _dataPtr;
104 ///////////////////////////////////////////////////////////////////
106 /** \relates SolvIdentFile Stream output */
107 std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
109 /////////////////////////////////////////////////////////////////
110 } // namespace target
111 ///////////////////////////////////////////////////////////////////
112 /////////////////////////////////////////////////////////////////
114 ///////////////////////////////////////////////////////////////////
115 #endif // ZYPP_TARGET_SOLVIDENTFILE_H