PoolQueryUtil.tcc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00014 #ifndef ZYPP_POOLQUERYUTIL_TCC
00015 #define ZYPP_POOLQUERYUTIL_TCC
00016
00017 #include <fstream>
00018
00019 #include "zypp/Pathname.h"
00020 #include "zypp/PoolQuery.h"
00021 #include "zypp/base/String.h"
00022
00023 namespace zypp
00024 {
00025
00035 template <class OutputIterator>
00036 void readPoolQueriesFromFile(const zypp::filesystem::Pathname &file,
00037 OutputIterator out )
00038 {
00039 bool found;
00040 std::ifstream fin( file.c_str() );
00041
00042 if (!fin)
00043 ZYPP_THROW(Exception(str::form("Cannot open file %s",file.c_str())));
00044
00045 do
00046 {
00047 zypp::PoolQuery q;
00048 found = q.recover( fin );
00049 if (found)
00050 *out++ = q;
00051 } while ( found );
00052
00053 fin.close();
00054 }
00055
00060 template <class InputIterator>
00061 void writePoolQueriesToFile(const zypp::filesystem::Pathname &file,
00062 InputIterator begin, InputIterator end )
00063 {
00064 std::ofstream fout( file.c_str(), std::ios_base::out | std::ios_base::trunc );
00065
00066 if (!fout)
00067 ZYPP_THROW(Exception(str::form("Cannot open file %s",file.c_str())));
00068
00069 for_( it, begin, end )
00070 {
00071 it->serialize( fout );
00072 }
00073
00074 fout.close();
00075 }
00076
00077 }
00078 #endif // ZYPP_POOLQUERYUTIL_H