ome-files  0.3.1
Field.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_FIELD_H
39 #define OME_FILES_TIFF_FIELD_H
40 
41 #include <memory>
42 #include <string>
43 
44 #include <ome/files/tiff/Tags.h>
45 #include <ome/files/tiff/Exception.h>
46 
47 namespace ome
48 {
49  namespace files
50  {
51  namespace tiff
52  {
53 
54  class IFD;
55 
59  class FieldBase
60  {
61  protected:
68  FieldBase(std::shared_ptr<IFD> ifd,
69  tag_type tag);
70 
71  public:
73  virtual
74  ~FieldBase();
75 
82  Type
83  type() const;
84 
92  bool
93  passCount() const;
94 
104  int
105  readCount() const;
106 
116  int
117  writeCount() const;
118 
125  tag_type
126  tagNumber() const;
127 
135  std::string
136  name() const;
137 
143  std::shared_ptr<IFD>
144  getIFD() const;
145 
146  protected:
147  class Impl;
149  std::shared_ptr<Impl> impl;
150  };
151 
155  template<typename Tag>
156  class Field : public FieldBase
157  {
158  public:
160  typedef Tag tag_category;
162  typedef typename ::ome::files::detail::tiff::TagProperties<tag_category>::value_type value_type;
163 
164  friend class IFD;
165 
166  protected:
173  Field(std::shared_ptr<IFD> ifd,
174  tag_category tag):
175  FieldBase(ifd, getWrappedTag(tag)),
176  tag(tag)
177  {}
178 
179 
180  public:
182  virtual ~Field()
183  {}
184 
190  void
191  get(value_type& value) const;
192 
198  void
199  set(const value_type& value);
200 
207  Field&
208  operator=(const Field& field)
209  {
210  set(field);
211  return *this;
212  }
213 
217  operator value_type()
218  {
219  value_type v;
220  get(v);
221  return v;
222  }
223 
224  protected:
226  tag_category tag;
227  };
228 
238  template<typename V>
240  {
241  public:
243  typedef V value_type;
244 
245  private:
247  V& value;
248 
249  public:
255  explicit
256  ValueProxy(value_type& value):
257  value(value)
258  {}
259 
262  {}
263 
270  ValueProxy&
271  operator= (const ValueProxy& value)
272  { this->value = value.value; }
273 
280  ValueProxy&
281  operator= (const value_type& value)
282  {
283  this->value = value;
284  }
285 
292  template<typename F>
293  ValueProxy&
294  operator= (const Field<F>& field)
295  {
296  field.get(value);
297  return *this;
298  }
299 
305  value_type&
306  get()
307  {
308  return value;
309  }
310 
316  const value_type&
317  get() const
318  {
319  return value;
320  }
321  };
322 
329  template<typename V>
330  class Value
331  {
332  public:
334  typedef V value_type;
335 
336  private:
338  V value;
339 
340  public:
342  explicit
343  Value():
344  value()
345  {}
346 
349  {}
350 
357  Value&
358  operator= (const Value& value)
359  { this->value = value.value; }
360 
367  Value&
368  operator= (const value_type& value)
369  {
370  this->value = value;
371  }
372 
379  template<typename F>
380  Value&
381  operator= (const Field<F>& field)
382  {
383  field.get(value);
384  return *this;
385  }
386 
392  value_type&
393  get()
394  {
395  return value;
396  }
397 
403  const value_type&
404  get() const
405  {
406  return value;
407  }
408  };
409 
410  }
411  }
412 }
413 
414 #endif // OME_FILES_TIFF_FIELD_H
415 
416 /*
417  * Local Variables:
418  * mode:C++
419  * End:
420  */
virtual ~FieldBase()
Destructor.
Definition: Field.cpp:186
void get(value_type &value) const
Get the value for this field.
V & value
The wrapped value.
Definition: Field.h:247
ValueProxy(value_type &value)
Construct from value.
Definition: Field.h:256
Field & operator=(const Field &field)
Assign a field value.
Definition: Field.h:208
Internal implementation details of FieldBase.
Definition: Field.cpp:60
virtual ~Field()
Destructor.
Definition: Field.h:182
unsigned int tag_type
Tag number.
Definition: Types.h:68
int writeCount() const
Get field write count requirement.
Definition: Field.cpp:255
Field value.
Definition: Field.h:330
int readCount() const
Get field read count requirement.
Definition: Field.cpp:241
Value()
Constructor.
Definition: Field.h:343
V value
The value.
Definition: Field.h:338
std::shared_ptr< Impl > impl
Private implementation details.
Definition: Field.h:147
Field(std::shared_ptr< IFD > ifd, tag_category tag)
Constructor.
Definition: Field.h:173
Open Microscopy Environment C++.
::ome::files::detail::tiff::TagProperties< tag_category >::value_type value_type
The tag value type (C++ type).
Definition: Field.h:162
V value_type
The value type being wrapped.
Definition: Field.h:243
std::shared_ptr< IFD > getIFD() const
Get the directory this field belongs to.
Definition: Field.cpp:275
FieldBase(std::shared_ptr< IFD > ifd, tag_type tag)
Constructor.
Definition: Field.cpp:180
~Value()
Destructor.
Definition: Field.h:348
Common functionality for fields of all types.
Definition: Field.h:59
std::string name() const
Get field tag name.
Definition: Field.cpp:191
~ValueProxy()
Destructor.
Definition: Field.h:261
Tag tag_category
The tag type (C++ enum type).
Definition: Field.h:160
Field representing a tag value.
Definition: Field.h:156
Proxy for getting and setting a Field value.
Definition: Field.h:239
Type type() const
Get field data type.
Definition: Field.cpp:213
V value_type
The value type being wrapped.
Definition: Field.h:334
tag_type getWrappedTag(StringTag1 tag)
Get the TIFF tag number for the specified tag.
Definition: Tags.cpp:66
Image File Directory (IFD).
Definition: IFD.h:70
tag_category tag
The tag identifying this field.
Definition: Field.h:226
bool passCount() const
Get field count requirement.
Definition: Field.cpp:227
Type
Tag types.
Definition: Types.h:71
tag_type tagNumber() const
Get field tag number.
Definition: Field.cpp:269