/* BSD 2-Clause license Copyright (c) 2014, Domen Vrankar All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ARCHIVE_READER_HPP_INCLUDED #define ARCHIVE_READER_HPP_INCLUDED #include #include #include #include #include "archive_reader_format.hpp" #include "archive_reader_filter.hpp" #include "archive_reader_entry.hpp" #include "archive_reader_iterator.hpp" namespace ns_archive { namespace ns_reader { ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff ); } // ns_reader class reader { public: reader(reader&&) = default; reader(const reader&) = delete; reader& operator=(const reader&) = delete; template static reader make_reader( std::istream& stream, size_t block_size ); template static reader make_reader( std::istream& stream, size_t block_size); template static reader make_reader( std::istream& stream, size_t block_size); ns_reader::entry* get_next_entry(); bool has_next_entry(); ns_reader::iterator begin(); ns_reader::iterator end(); private: reader( std::istream& stream, size_t block_size ); template void init_format(); template void init_filter(); void init_data(); std::shared_ptr _archive; ns_reader::entry *_next_entry = nullptr; class reader_container { public: reader_container( std::istream& stream, size_t block_size ) : _stream( stream ) { _buff.resize( block_size ); } public: std::istream& _stream; std::vector _buff; } _reader_container; friend ssize_t ns_reader::reader_callback( archive* archive, void* in_reader_container, const void** buff ); }; } // ns_archive #include "archive_reader.ipp" #endif // ARCHIVE_READER_HPP_INCLUDED