bioformats  5.1.2
Field.h
1 /*
2  * #%L
3  * OME-BIOFORMATS 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_BIOFORMATS_TIFF_FIELD_H
39 #define OME_BIOFORMATS_TIFF_FIELD_H
40 
41 #include <ome/compat/memory.h>
42 
43 #include <string>
44 
45 #include <ome/bioformats/tiff/Tags.h>
46 #include <ome/bioformats/tiff/Exception.h>
47 
48 namespace ome
49 {
50  namespace bioformats
51  {
52  namespace tiff
53  {
54 
55  class IFD;
56 
60  class FieldBase
61  {
62  protected:
69  FieldBase(ome::compat::shared_ptr<IFD> ifd,
70  tag_type tag);
71 
72  public:
74  virtual
75  ~FieldBase();
76 
83  Type
84  type() const;
85 
93  bool
94  passCount() const;
95 
105  int
106  readCount() const;
107 
117  int
118  writeCount() const;
119 
126  tag_type
127  tagNumber() const;
128 
136  std::string
137  name() const;
138 
144  ome::compat::shared_ptr<IFD>
145  getIFD() const;
146 
147  protected:
148  class Impl;
150  ome::compat::shared_ptr<Impl> impl;
151  };
152 
156  template<typename Tag>
157  class Field : public FieldBase
158  {
159  public:
161  typedef Tag tag_category;
163  typedef typename ::ome::bioformats::detail::tiff::TagProperties<tag_category>::value_type value_type;
164 
165  friend class IFD;
166 
167  protected:
174  Field(ome::compat::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_BIOFORMATS_TIFF_FIELD_H
416 
417 /*
418  * Local Variables:
419  * mode:C++
420  * End:
421  */
Memory type substitution.
Proxy for getting and setting a Field value.
Definition: Field.h:240
Tag tag_category
The tag type (C++ enum type).
Definition: Field.h:161
tag_type getWrappedTag(StringTag1 tag)
Get the TIFF tag number for the specified tag.
Definition: Tags.cpp:66
Value & operator=(const Value &value)
Assign from a Value.
Definition: Field.h:359
Field & operator=(const Field &field)
Assign a field value.
Definition: Field.h:209
tag_category tag
The tag identifying this field.
Definition: Field.h:227
~ValueProxy()
Destructor.
Definition: Field.h:262
::ome::bioformats::detail::tiff::TagProperties< tag_category >::value_type value_type
The tag value type (C++ type).
Definition: Field.h:163
Field representing a tag value.
Definition: Field.h:157
V & value
The wrapped value.
Definition: Field.h:248
std::string name() const
Get field tag name.
Definition: Field.cpp:250
~Value()
Destructor.
Definition: Field.h:349
ValueProxy & operator=(const ValueProxy &value)
Assign from a ValueProxy.
Definition: Field.h:272
Type
Tag types.
Definition: Types.h:62
ValueProxy(value_type &value)
Construct from value.
Definition: Field.h:257
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
tag_type tagNumber() const
Get field tag number.
Definition: Field.cpp:338
Field(ome::compat::shared_ptr< IFD > ifd, tag_category tag)
Constructor.
Definition: Field.h:174
V value
The value.
Definition: Field.h:339
int readCount() const
Get field read count requirement.
Definition: Field.cpp:306
Internal implementation details of FieldBase.
Definition: Field.cpp:115
Type type() const
Get field data type.
Definition: Field.cpp:274
virtual ~FieldBase()
Destructor.
Definition: Field.cpp:245
bool passCount() const
Get field count requirement.
Definition: Field.cpp:290
Value()
Constructor.
Definition: Field.h:344
int writeCount() const
Get field write count requirement.
Definition: Field.cpp:322
FieldBase(ome::compat::shared_ptr< IFD > ifd, tag_type tag)
Constructor.
Definition: Field.cpp:239
void set(const value_type &value)
Set the value for this field.
virtual ~Field()
Destructor.
Definition: Field.h:183
Image File Directory (IFD).
Definition: IFD.h:71
void get(value_type &value) const
Get the value for this field.
Field value.
Definition: Field.h:331
V value_type
The value type being wrapped.
Definition: Field.h:335
ome::compat::shared_ptr< Impl > impl
Private implementation details.
Definition: Field.h:148
ome::compat::shared_ptr< IFD > getIFD() const
Get the directory this field belongs to.
Definition: Field.cpp:344
V value_type
The value type being wrapped.
Definition: Field.h:244
unsigned int tag_type
Tag number.
Definition: Types.h:59
Common functionality for fields of all types.
Definition: Field.h:60