list.hpp

00001 /*
00002    Copyright (C) 2004-2005 Cory Nelson
00003 
00004    This software is provided 'as-is', without any express or implied
00005    warranty.  In no event will the authors be held liable for any damages
00006    arising from the use of this software.
00007 
00008    Permission is granted to anyone to use this software for any purpose,
00009    including commercial applications, and to alter it and redistribute it
00010    freely, subject to the following restrictions:
00011 
00012    1. The origin of this software must not be misrepresented; you must not
00013       claim that you wrote the original software. If you use this software
00014       in a product, an acknowledgment in the product documentation would be
00015       appreciated but is not required.
00016    2. Altered source versions must be plainly marked as such, and must not be
00017       misrepresented as being the original software.
00018    3. This notice may not be removed or altered from any source distribution.
00019    
00020    CVS Info :
00021       $Author: phrostbyte $
00022       $Date: 2005/07/13 06:46:18 $
00023       $Revision: 1.6 $
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

Generated on Fri Nov 2 16:10:05 2007 for CP2PListLibrary by  doxygen 1.5.4