ome-files  0.5.0
TIFF.h
1 /*
2  * #%L
3  * OME-FILES C++ library for image IO.
4  * Copyright © 2006 - 2015 Open Microscopy Environment:
5  * - Massachusetts Institute of Technology
6  * - National Institutes of Health
7  * - University of Dundee
8  * - Board of Regents of the University of Wisconsin-Madison
9  * - Glencoe Software, Inc.
10  * %%
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  * The views and conclusions contained in the software and documentation are
33  * those of the authors and should not be interpreted as representing official
34  * policies, either expressed or implied, of any organization.
35  * #L%
36  */
37 
38 #ifndef OME_FILES_TIFF_TIFF_H
39 #define OME_FILES_TIFF_TIFF_H
40 
41 #include <cstdint>
42 #include <memory>
43 #include <string>
44 
45 #include <boost/filesystem/path.hpp>
46 #include <boost/iterator/iterator_facade.hpp>
47 
48 #include <ome/files/tiff/Types.h>
49 
50 namespace ome
51 {
52  namespace files
53  {
57  namespace tiff
58  {
59 
60  class IFD;
61 
65  template<typename Value>
66  class IFDIterator : public boost::iterator_facade<IFDIterator<Value>,
67  std::shared_ptr<Value>,
68  boost::forward_traversal_tag>
69  {
70  public:
77  pos()
78  {}
79 
87  IFDIterator(std::shared_ptr<IFD>& ifd):
88  pos(ifd)
89  {}
90 
96  template <class OtherValue>
98  : pos(rhs.pos) {}
99 
100  private:
107  mutable std::shared_ptr<Value> pos;
108 
112  template <class> friend class IFDIterator;
113 
121  void
122  increment();
123 
130  bool
131  equal(IFDIterator const& rhs) const
132  {
133  return this->pos == rhs.pos;
134  }
135 
141  std::shared_ptr<Value>&
142  dereference() const
143  {
144  return pos;
145  }
146  };
147 
156  class TIFF : public std::enable_shared_from_this<TIFF>
157  {
158  private:
159  class Impl;
160  class wrapped_type;
162  std::shared_ptr<Impl> impl;
163 
164  protected:
173  TIFF(const boost::filesystem::path& filename,
174  const std::string& mode);
175 
177  TIFF (const TIFF&) = delete;
178 
179  TIFF&
180  operator= (const TIFF&) = delete;
182 
183  public:
185  ~TIFF();
186 
199  static std::shared_ptr<TIFF>
200  open(const boost::filesystem::path& filename,
201  const std::string& mode);
202 
210  void
211  close();
212 
219  operator bool ();
220 
227  directoryCount() const;
228 
237  std::shared_ptr<IFD>
238  getDirectoryByIndex(directory_index_type index) const;
239 
248  std::shared_ptr<IFD>
249  getDirectoryByOffset(offset_type offset) const;
250 
257  std::shared_ptr<IFD>
258  getCurrentDirectory() const;
259 
268  void
269  writeCurrentDirectory();
270 
290  wrapped_type *
291  getWrapped() const;
292 
294  friend class IFD;
295 
300 
306  iterator
307  begin();
308 
314  const_iterator
315  begin() const;
316 
322  iterator
323  end();
324 
330  const_iterator
331  end() const;
332 
333  private:
335  void
336  registerImageJTags();
337  };
338 
339  }
340  }
341 }
342 
343 #endif // OME_FILES_TIFF_TIFF_H
344 
345 /*
346  * Local Variables:
347  * mode:C++
348  * End:
349  */
std::shared_ptr< Value > & dereference() const
Dereference the iterator.
Definition: TIFF.h:142
Internal implementation details of TIFF.
Definition: TIFF.cpp:109
Tagged Image File Format (TIFF).
Definition: TIFF.h:156
std::shared_ptr< Value > pos
The current position.
Definition: TIFF.h:107
IFDIterator()
Default constructor.
Definition: TIFF.h:76
IFDIterator< IFD > iterator
IFD iterator.
Definition: TIFF.h:297
void increment()
Increment the iterator by one position.
uint64_t offset_type
IFD offset.
Definition: Types.h:65
Iterator for IFDs contained within a TIFF.
Definition: TIFF.h:66
Open Microscopy Environment C++.
IFDIterator(std::shared_ptr< IFD > &ifd)
Construct with an initial starting position.
Definition: TIFF.h:87
IFDIterator(const IFDIterator< OtherValue > &rhs)
Construct from an existing iterator.
Definition: TIFF.h:97
std::shared_ptr< Impl > impl
Private implementation details.
Definition: TIFF.h:160
bool equal(IFDIterator const &rhs) const
Check for equality.
Definition: TIFF.h:131
friend class boost::iterator_core_access
IFD iterator internals uses internal TIFF state.
Definition: TIFF.h:110
IFDIterator< const IFD > const_iterator
const IFD iterator.
Definition: TIFF.h:299
uint16_t directory_index_type
IFD index.
Definition: Types.h:62
Image File Directory (IFD).
Definition: IFD.h:70