1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* libopenraw - rawcontainer.h
*
* Copyright (C) 2006-2007 Hubert Figuiere
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef _RAWCONTAINER_H_
#define _RAWCONTAINER_H_
#include <sys/types.h>
#include <libopenraw/io.h>
#include <libopenraw/types.h>
namespace OpenRaw {
namespace IO {
class Stream;
}
namespace Internals {
/**
Generic interface for the RAW file container
*/
class RawContainer
{
public:
/** define the endian of the container */
typedef enum {
ENDIAN_NULL = 0, /** no endian found: means invalid file */
ENDIAN_BIG, /** big endian found */
ENDIAN_LITTLE /** little endian found */
} EndianType;
/**
@param file the stream to read from
@param offset the offset since starting the
beginning of the file for the container
*/
RawContainer(IO::Stream *_file, off_t offset);
/** destructor */
virtual ~RawContainer();
IO::Stream *file()
{
return m_file;
}
EndianType endian() const
{
return m_endian;
}
bool readInt8(IO::Stream *f, int8_t & v);
bool readUInt8(IO::Stream *f, uint8_t & v);
/** Read an int16 following the m_endian set */
bool readInt16(IO::Stream *f, int16_t & v);
/** Read an int32 following the m_endian set */
bool readInt32(IO::Stream *f, int32_t & v);
/** Read an uint16 following the m_endian set */
bool readUInt16(IO::Stream *f, uint16_t & v);
/** Read an uint32 following the m_endian set */
bool readUInt32(IO::Stream *f, uint32_t & v);
/**
* Fetch the data chunk from the file
* @param buf the buffer to load into
* @param offset the offset
* @param buf_size the size of the data to fetch
* @return the size retrieved, <= buf_size likely equal
*/
size_t fetchData(void *buf, const off_t offset, const size_t buf_size);
protected:
RawContainer(const RawContainer&);
RawContainer & operator=(const RawContainer &);
void setEndian(EndianType _endian)
{
m_endian = _endian;
}
/** the file handle */
IO::Stream *m_file;
/** the offset from the beginning of the file */
off_t m_offset;
EndianType m_endian;
};
}
}
#endif
|