libopenraw
ifddir.h
1 /*
2  * libopenraw - ifddir.h
3  *
4  * Copyright (C) 2006-2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef _OPENRAW_INTERNALS_IFDDIR_H
23 #define _OPENRAW_INTERNALS_IFDDIR_H
24 
25 #include <map>
26 
27 #include <boost/config.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include "ifdentry.h"
30 #include "trace.h"
31 
32 namespace OpenRaw {
33  namespace Internals {
34 
35  class IFDFileContainer;
36 
37  class IFDDir
38  {
39  public:
40  typedef boost::shared_ptr<IFDDir> Ref;
41  typedef std::vector<Ref> RefVec;
42  struct isPrimary
43  {
44  bool operator()(const Ref &dir);
45  };
46  struct isThumbnail
47  {
48  bool operator()(const Ref &dir);
49  };
50 
51  IFDDir(off_t _offset, IFDFileContainer & _container);
52  virtual ~IFDDir();
53 
55  off_t offset() const
56  {
57  return m_offset;
58  }
59 
61  bool load();
63  int numTags()
64  {
65  return m_entries.size();
66  }
67  IFDEntry::Ref getEntry(uint16_t id) const ;
68 
74  template <typename T>
75  bool getValue(uint16_t id, T &v) const
76  {
77  bool success = false;
78  IFDEntry::Ref e = getEntry(id);
79  if (e != NULL) {
80  try {
81  v = IFDTypeTrait<T>::get(*e);
82  success = true;
83  }
84  catch(const std::exception & ex) {
85  Debug::Trace(ERROR) << "Exception raised " << ex.what()
86  << " fetch value for " << id << "\n";
87  }
88  }
89  return success;
90  }
91 
100  bool getIntegerValue(uint16_t id, uint32_t &v);
101 
105  off_t nextIFD();
106 
110  Ref getSubIFD(uint32_t idx = 0) const;
115  bool getSubIFDs(std::vector<IFDDir::Ref> & ifds);
116 
120  Ref getExifIFD();
121  private:
122  off_t m_offset;
123  IFDFileContainer & m_container;
124  std::map<uint16_t, IFDEntry::Ref> m_entries;
125  };
126 
127 
128  }
129 }
130 
131 
132 #endif
133 
static T get(IFDEntry &e, uint32_t idx=0, bool ignore_type=false)
Definition: ifdentry.h:211
bool getIntegerValue(uint16_t id, uint32_t &v)
Definition: ifddir.cpp:100
bool getSubIFDs(std::vector< IFDDir::Ref > &ifds)
Definition: ifddir.cpp:175
off_t offset() const
Definition: ifddir.h:55
Ref getSubIFD(uint32_t idx=0) const
Definition: ifddir.cpp:154
bool getValue(uint16_t id, T &v) const
Definition: ifddir.h:75
boost::shared_ptr< IFDEntry > Ref
Definition: ifdentry.h:122