ome-files  0.5.0
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 
165  friend class IFD;
166 
167  protected:
174  Field(std::shared_ptr<IFD> ifd,
175  tag_category tag):
176  FieldBase(ifd, getWrappedTag(tag)),
177  tag(tag)
178  {}
179 
180 
181  public:
183  virtual ~Field()
184  {}
185 
191  void
192  get(value_type& value) const;
193 
199  void
200  set(const value_type& value);
201 
208  Field&
209  operator=(const Field& field)
210  {
211  set(field);
212  return *this;
213  }
214 
218  operator value_type()
219  {
220  value_type v;
221  get(v);
222  return v;
223  }
224 
225  protected:
227  tag_category tag;
228  };
229 
239  template<typename V>
241  {
242  public:
244  typedef V value_type;
245 
246  private:
248  V& value;
249 
250  public:
256  explicit
257  ValueProxy(value_type& value):
258  value(value)
259  {}
260 
263  {}
264 
271  ValueProxy&
272  operator= (const ValueProxy& value)
273  { this->value = value.value; }
274 
281  ValueProxy&
282  operator= (const value_type& value)
283  {
284  this->value = value;
285  }
286 
293  template<typename F>
294  ValueProxy&
295  operator= (const Field<F>& field)
296  {
297  field.get(value);
298  return *this;
299  }
300 
306  value_type&
307  get()
308  {
309  return value;
310  }
311 
317  const value_type&
318  get() const
319  {
320  return value;
321  }
322  };
323 
330  template<typename V>
331  class Value
332  {
333  public:
335  typedef V value_type;
336 
337  private:
339  V value;
340 
341  public:
343  explicit
344  Value():
345  value()
346  {}
347 
350  {}
351 
358  Value&
359  operator= (const Value& value)
360  { this->value = value.value; }
361 
368  Value&
369  operator= (const value_type& value)
370  {
371  this->value = value;
372  }
373 
380  template<typename F>
381  Value&
382  operator= (const Field<F>& field)
383  {
384  field.get(value);
385  return *this;
386  }
387 
393  value_type&
394  get()
395  {
396  return value;
397  }
398 
404  const value_type&
405  get() const
406  {
407  return value;
408  }
409  };
410 
411  }
412  }
413 }
414 
415 #endif // OME_FILES_TIFF_FIELD_H
416 
417 /*
418  * Local Variables:
419  * mode:C++
420  * End:
421  */
virtual ~FieldBase()
Destructor.
Definition: Field.cpp:195
void get(value_type &value) const
Get the value for this field.
V & value
The wrapped value.
Definition: Field.h:248
ValueProxy(value_type &value)
Construct from value.
Definition: Field.h:257
Field & operator=(const Field &field)
Assign a field value.
Definition: Field.h:209
Internal implementation details of FieldBase.
Definition: Field.cpp:61
virtual ~Field()
Destructor.
Definition: Field.h:183
unsigned int tag_type
Tag number.
Definition: Types.h:68
int writeCount() const
Get field write count requirement.
Definition: Field.cpp:264
Field value.
Definition: Field.h:331
int readCount() const
Get field read count requirement.
Definition: Field.cpp:250
Value()
Constructor.
Definition: Field.h:344
V value
The value.
Definition: Field.h:339
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:174
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:244
std::shared_ptr< IFD > getIFD() const
Get the directory this field belongs to.
Definition: Field.cpp:284
FieldBase(std::shared_ptr< IFD > ifd, tag_type tag)
Constructor.
Definition: Field.cpp:189
~Value()
Destructor.
Definition: Field.h:349
Common functionality for fields of all types.
Definition: Field.h:59
std::string name() const
Get field tag name.
Definition: Field.cpp:200
~ValueProxy()
Destructor.
Definition: Field.h:262
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:240
Type type() const
Get field data type.
Definition: Field.cpp:222
V value_type
The value type being wrapped.
Definition: Field.h:335
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:227
bool passCount() const
Get field count requirement.
Definition: Field.cpp:236
Type
Tag types.
Definition: Types.h:71
tag_type tagNumber() const
Get field tag number.
Definition: Field.cpp:278