ome-files 0.2.2

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 <ome/compat/memory.h>
42
43 #include <string>
44
45 #include <ome/files/tiff/Tags.h>
46 #include <ome/files/tiff/Exception.h>
47
48 namespace ome
49 {
50 namespace files
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::files::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>
240 class ValueProxy
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
262 ~ValueProxy()
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
349 ~Value()
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 */
ome::files::tiff::FieldBase::~FieldBase
virtual ~FieldBase()
Destructor.
Definition: Field.cpp:186
ome::files::tiff::Field::Field
Field(ome::compat::shared_ptr< IFD > ifd, tag_category tag)
Constructor.
Definition: Field.h:174
ome::files::tiff::Field::get
void get(value_type &value) const
Get the value for this field.
ome::files::tiff::ValueProxy::value
V & value
The wrapped value.
Definition: Field.h:248
ome::files::tiff::ValueProxy::ValueProxy
ValueProxy(value_type &value)
Construct from value.
Definition: Field.h:257
ome::files::tiff::Field::operator=
Field & operator=(const Field &field)
Assign a field value.
Definition: Field.h:209
ome::files::tiff::FieldBase::Impl
Internal implementation details of FieldBase.
Definition: Field.cpp:60
ome::files::tiff::Field::~Field
virtual ~Field()
Destructor.
Definition: Field.h:183
ome::files::tiff::tag_type
unsigned int tag_type
Tag number.
Definition: Types.h:68
ome::files::tiff::FieldBase::writeCount
int writeCount() const
Get field write count requirement.
Definition: Field.cpp:255
ome::files::tiff::FieldBase::impl
ome::compat::shared_ptr< Impl > impl
Private implementation details.
Definition: Field.h:148
ome::files::tiff::Value
Field value.
Definition: Field.h:331
ome::files::tiff::FieldBase::readCount
int readCount() const
Get field read count requirement.
Definition: Field.cpp:241
ome::files::tiff::Value::Value
Value()
Constructor.
Definition: Field.h:344
ome::files::tiff::FieldBase::getIFD
ome::compat::shared_ptr< IFD > getIFD() const
Get the directory this field belongs to.
Definition: Field.cpp:275
ome::files::tiff::Value::value
V value
The value.
Definition: Field.h:339
ome
Open Microscopy Environment C++.
ome::files::tiff::Field::value_type
::ome::files::detail::tiff::TagProperties< tag_category >::value_type value_type
The tag value type (C++ type).
Definition: Field.h:163
ome::files::tiff::ValueProxy::value_type
V value_type
The value type being wrapped.
Definition: Field.h:244
ome::files::tiff::Value::~Value
~Value()
Destructor.
Definition: Field.h:349
ome::files::tiff::FieldBase
Common functionality for fields of all types.
Definition: Field.h:60
ome::files::tiff::FieldBase::name
std::string name() const
Get field tag name.
Definition: Field.cpp:191
memory.h
ome::files::tiff::ValueProxy::~ValueProxy
~ValueProxy()
Destructor.
Definition: Field.h:262
ome::files::tiff::Field::tag_category
Tag tag_category
The tag type (C++ enum type).
Definition: Field.h:161
ome::files::tiff::Field
Field representing a tag value.
Definition: Field.h:157
ome::files::tiff::ValueProxy
Proxy for getting and setting a Field value.
Definition: Field.h:240
ome::files::tiff::FieldBase::type
Type type() const
Get field data type.
Definition: Field.cpp:213
ome::files::tiff::Value::value_type
V value_type
The value type being wrapped.
Definition: Field.h:335
ome::files::tiff::getWrappedTag
tag_type getWrappedTag(StringTag1 tag)
Get the TIFF tag number for the specified tag.
Definition: Tags.cpp:66
ome::files::tiff::IFD
Image File Directory (IFD).
Definition: IFD.h:71
ome::files::tiff::Field::tag
tag_category tag
The tag identifying this field.
Definition: Field.h:227
ome::files::tiff::FieldBase::FieldBase
FieldBase(ome::compat::shared_ptr< IFD > ifd, tag_type tag)
Constructor.
Definition: Field.cpp:180
ome::files::tiff::FieldBase::passCount
bool passCount() const
Get field count requirement.
Definition: Field.cpp:227
ome::files::tiff::Type
Type
Tag types.
Definition: Types.h:71
ome::files::tiff::FieldBase::tagNumber
tag_type tagNumber() const
Get field tag number.
Definition: Field.cpp:269