SpectMorph
|
00001 /* 00002 * Copyright (C) 2010 Stefan Westerfeld 00003 * 00004 * This library is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License as published by the 00006 * Free Software Foundation; either version 3 of the License, or (at your 00007 * option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00012 * for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef SPECTMORPH_MMAP_IN_HH 00019 #define SPECTMORPH_MMAP_IN_HH 00020 00021 #include <string> 00022 00023 #include "smgenericin.hh" 00024 00025 namespace SpectMorph 00026 { 00027 00028 class MMapIn : public GenericIn 00029 { 00030 unsigned char *mapfile; 00031 unsigned char *mapend; 00032 unsigned char *pos; 00033 int fd; 00034 00035 MMapIn (unsigned char *mapfile, unsigned char *mapend, int fd); 00036 ~MMapIn(); 00037 public: 00038 static GenericIn* open (const std::string& filename); 00039 static GenericIn* open_mem (unsigned char *mem_start, unsigned char *mem_end); 00040 00041 int get_byte(); // like fgetc 00042 int read (void *ptr, size_t size); 00043 bool skip (size_t size); 00044 unsigned char *mmap_mem (size_t& remaining); 00045 size_t get_pos(); 00046 GenericIn *open_subfile (size_t pos, size_t len); 00047 }; 00048 00049 } 00050 00051 #endif /* SPECTMORPH_MMAP_IN_HH */