libopenraw  0.3.7
rawcontainer.hpp
1 /* -*- Mode: C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
2 /*
3  * libopenraw - rawcontainer.h
4  *
5  * Copyright (C) 2006-2020 Hubert Figuière
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <sys/types.h>
27 
28 #include <vector>
29 
30 #include "io/stream.hpp"
31 #include "option.hpp"
32 
33 namespace OpenRaw {
34 
35 namespace Internals {
36 
40 class RawContainer {
41 public:
43  typedef enum {
48 
54  RawContainer(const IO::Stream::Ptr &_file, off_t offset);
56  virtual ~RawContainer();
57 
58  const IO::Stream::Ptr &file() const { return m_file; }
59  EndianType endian() const { return m_endian; }
60  off_t offset() const { return m_offset; }
61  // This only make sense for IFD.
62  virtual int exifOffsetCorrection() const
63  {
64  return 0;
65  }
66 
67  bool skip(off_t offset);
68  Option<int8_t> readInt8(const IO::Stream::Ptr& f) const;
69  Option<uint8_t> readUInt8(const IO::Stream::Ptr& f) const;
71  Option<int16_t> readInt16(const IO::Stream::Ptr& f, EndianType endian) const;
73  Option<int32_t> readInt32(const IO::Stream::Ptr& f, EndianType endian) const;
75  Option<uint16_t> readUInt16(const IO::Stream::Ptr& f, EndianType endian) const;
81  size_t readUInt16Array(const IO::Stream::Ptr& f, std::vector<uint16_t>& v, size_t count) const;
83  Option<uint32_t> readUInt32(const IO::Stream::Ptr& f, EndianType endian) const;
91  size_t fetchData(void* buf, off_t offset, size_t buf_size) const;
92 
96  off_t size() const;
97 protected:
98  RawContainer(const RawContainer &) = delete;
99  RawContainer(RawContainer&&) = default;
100  RawContainer &operator=(const RawContainer &) = delete;
101 
102  void setEndian(EndianType _endian) { m_endian = _endian; }
103 
107  off_t m_offset;
108  EndianType m_endian;
109 };
110 
111 }
112 }
std::shared_ptr< Stream > Ptr
Definition: stream.hpp:47
Generic interface for the RAW file container.
Option< uint32_t > readUInt32(const IO::Stream::Ptr &f, EndianType endian) const
Read an uint32 following the m_endian set.
Option< uint16_t > readUInt16(const IO::Stream::Ptr &f, EndianType endian) const
Read an uint16 following the m_endian set.
IO::Stream::Ptr m_file
The file handle.
EndianType
Define the endian of the container.
size_t fetchData(void *buf, off_t offset, size_t buf_size) const
Fetch the data chunk from the file.
Option< int32_t > readInt32(const IO::Stream::Ptr &f, EndianType endian) const
Read an int32 following the m_endian set.
Option< int16_t > readInt16(const IO::Stream::Ptr &f, EndianType endian) const
Read an int16 following the m_endian set.
off_t size() const
Return the effective size of the container.
size_t readUInt16Array(const IO::Stream::Ptr &f, std::vector< uint16_t > &v, size_t count) const
Read an array of uint16 following the m_endian set.
off_t m_offset
The offset from the beginning of the file.
RawContainer(const IO::Stream::Ptr &_file, off_t offset)
An option type inspired by Rust.
Definition: option.hpp:47
Global namespace for libopenraw.
Definition: arwfile.cpp:29