00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __P2P_LIST_HPP__
00027 #define __P2P_LIST_HPP__
00028
00029 #include <list>
00030 #include <vector>
00031 #include <string>
00032 #include <istream>
00033 #include <ostream>
00034 #include <utility>
00035 #include <algorithm>
00036 #include <boost/scoped_array.hpp>
00037 #include <p2p/range.hpp>
00038 #include <p2p/compact_list.hpp>
00039
00040 namespace p2p {
00041 class list {
00042 public:
00043 typedef range range_type;
00044 typedef std::list<range_type> list_type;
00045 typedef list_type::size_type size_type;
00046 typedef list_type::iterator iterator;
00047 typedef list_type::const_iterator const_iterator;
00048 typedef std::istream istream_type;
00049 typedef std::ostream ostream_type;
00050 typedef std::string path_type;
00051
00052 enum file_type {
00053 file_auto,
00054 file_p2p,
00055 file_p2b1,
00056 file_p2b2,
00057 file_p2b3,
00058 file_p2b=file_p2b3
00059 };
00060
00061 private:
00062 list_type _ranges;
00063
00064 void _load_p2p(istream_type &stream);
00065 void _save_p2p(ostream_type &stream) const;
00066
00067 void _load_p2b(istream_type &stream);
00068
00069 void _save_p2b1(ostream_type &stream) const;
00070 void _save_p2b2(ostream_type &stream) const;
00071 void _save_p2b3(ostream_type &stream) const;
00072
00073 public:
00074 void insert(const range &r);
00075 void insert(const list &l);
00076 void erase(const range &r);
00077 void erase(const class compact_list &l);
00078
00079 void optimize(bool aggressive=false);
00080
00081 iterator begin() { return this->_ranges.begin(); }
00082 iterator end() { return this->_ranges.end(); }
00083
00084 const_iterator begin() const { return this->_ranges.begin(); }
00085 const_iterator end() const { return this->_ranges.end(); }
00086
00087 size_type size() const { return this->_ranges.size(); }
00088 void clear() { this->_ranges.clear(); }
00089
00090 void load(istream_type &stream, file_type type=file_auto);
00091 void load(const path_type &file, file_type type=file_auto);
00092 void save(ostream_type &stream, file_type type) const;
00093 void save(const path_type &file, file_type type) const;
00094
00095 list() {}
00096 list(const path_type &file, file_type type=file_auto) { this->load(file, type); }
00097 list(istream_type &stream, file_type type=file_auto) { this->load(stream, type); }
00098 };
00099 }
00100
00101 #endif