Mailinglist Archive: zypp-devel (148 mails)
| < Previous | Next > |
Re: [zypp-devel] api proposal for locks
- From: Josef Reidinger <jreidinger@xxxxxxx>
- Date: Fri, 28 Mar 2008 14:56:56 +0100
- Message-id: <47ECF928.4030001@xxxxxxx>
Josef Reidinger wrote:
When I do this I get idea what about make universal serializeToFile function which take as input iterators to object which have operator<< and also recoveryFromFile. It can be part of base
something like this
template <class InputIter>
void serializeToFile( InputIter begin, InputIter end, const Pathname &file){
ofstream s( file.c_str(),ofstream::trunc | ofstream::out );
s.exceptions( ofstream::bad );
try {
copy(begin,end,ostream_iterator<typeof(*begin)>(s));
} catch (ofstream::failure f) {
ZYPP_THROW(something about file failure);
}
}
template <class Data, class OutputIterator>
void recoveryFromFile(const Pathname &file,OutputIterator out){
ifstream s( file.c_str(),ifstream::trunc | ifstream::out );
s.exceptions( ifstream::bad );
try {
copy(istream_iterator<Data>(s),istream_iterator<Data>(),out);
} catch (ifstream::failure f) {
ZYPP_THROW(something about file failure);
}
}
also append to file can be usefull.
So when pool stores queries which have << and >> operators, they can easy serialize and recovery it.
e.g.
set<PoolQuery> locks;
//load locks
insert_iterator<list<PoolQuery> > ii(locks, locks.end());
recoveryFromFile<PoolQuery>( "/etc/zypp/locks", ii);
//save to file
serializeToFile(locks.begin(),locks.end(),"/etc/zypp/locks");
and thats all
What do you think about this?
Pepa
--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx
Ok, so I only make seriazeble and deseriazable of PoolQuery (may I use >> and <<?)...and add saveQueriesToFile and LoadQueriesFromFile functions which move between container(of queries) and file. Rest of handling with locks I relinguish to pool (like make locks container, adding and removing from container or locking solvables from queries). Is this what you mean?
When I do this I get idea what about make universal serializeToFile function which take as input iterators to object which have operator<< and also recoveryFromFile. It can be part of base
something like this
template <class InputIter>
void serializeToFile( InputIter begin, InputIter end, const Pathname &file){
ofstream s( file.c_str(),ofstream::trunc | ofstream::out );
s.exceptions( ofstream::bad );
try {
copy(begin,end,ostream_iterator<typeof(*begin)>(s));
} catch (ofstream::failure f) {
ZYPP_THROW(something about file failure);
}
}
template <class Data, class OutputIterator>
void recoveryFromFile(const Pathname &file,OutputIterator out){
ifstream s( file.c_str(),ifstream::trunc | ifstream::out );
s.exceptions( ifstream::bad );
try {
copy(istream_iterator<Data>(s),istream_iterator<Data>(),out);
} catch (ifstream::failure f) {
ZYPP_THROW(something about file failure);
}
}
also append to file can be usefull.
So when pool stores queries which have << and >> operators, they can easy serialize and recovery it.
e.g.
set<PoolQuery> locks;
//load locks
insert_iterator<list<PoolQuery> > ii(locks, locks.end());
recoveryFromFile<PoolQuery>( "/etc/zypp/locks", ii);
//save to file
serializeToFile(locks.begin(),locks.end(),"/etc/zypp/locks");
and thats all
What do you think about this?
Pepa
--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx
| < Previous | Next > |