File: MetadataModel.cs

package info (click to toggle)
freeimage 3.18.0%2Bds2-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,824 kB
  • sloc: cpp: 42,339; cs: 36,178; pascal: 4,629; ansic: 1,294; makefile: 101; sh: 84
file content (941 lines) | stat: -rw-r--r-- 25,283 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
// ==========================================================
// FreeImage 3 .NET wrapper
// Original FreeImage 3 functions and .NET compatible derived functions
//
// Design and implementation by
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
// - Carsten Klein (cklein05@users.sourceforge.net)
//
// Contributors:
// - David Boland (davidboland@vodafone.ie)
//
// Main reference : MSDN Knowlede Base
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================

// ==========================================================
// CVS
// $Revision: 1.8 $
// $Date: 2009/02/27 16:34:31 $
// $Id: MetadataModel.cs,v 1.8 2009/02/27 16:34:31 cklein05 Exp $
// ==========================================================

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace FreeImageAPI.Metadata
{
	/// <summary>
	/// Base class that represents a collection of all tags contained in a metadata model.
	/// </summary>
	/// <remarks>
	/// The <b>MetedataModel</b> class is an abstract base class, which is inherited by
	/// several derived classes, one for each existing metadata model.
	/// </remarks> 
	public abstract class MetadataModel : IEnumerable
	{
		/// <summary>
		/// Handle to the encapsulated FreeImage-bitmap.
		/// </summary>
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		protected readonly FIBITMAP dib;

		/// <summary>
		/// Initializes a new instance of this class.
		/// </summary>
		/// <param name="dib">Handle to a FreeImage bitmap.</param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="dib"/> is null.</exception>
		protected MetadataModel(FIBITMAP dib)
		{
			if (dib.IsNull)
			{
				throw new ArgumentNullException("dib");
			}
			this.dib = dib;
		}

		/// <summary>
		/// Retrieves the datamodel that this instance represents.
		/// </summary>
		public abstract FREE_IMAGE_MDMODEL Model
		{
			get;
		}

		/// <summary>
		/// Adds new tag to the bitmap or updates its value in case it already exists.
		/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
		/// </summary>
		/// <param name="tag">The tag to add or update.</param>
		/// <returns>Returns true on success, false on failure.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="tag"/> is null.</exception>
		/// <exception cref="ArgumentException">
		/// The tags model differs from this instances model.</exception>
		public bool AddTag(MetadataTag tag)
		{
			if (tag == null)
			{
				throw new ArgumentNullException("tag");
			}
			if (tag.Model != Model)
			{
				throw new ArgumentException("tag.Model");
			}
			return tag.AddToImage(dib);
		}

		/// <summary>
		/// Adds a list of tags to the bitmap or updates their values in case they already exist.
		/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
		/// </summary>
		/// <param name="list">A list of tags to add or update.</param>
		/// <returns>Returns the number of successfully added tags.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="list"/> is null.</exception>
		public int AddTag(IEnumerable<MetadataTag> list)
		{
			if (list == null)
			{
				throw new ArgumentNullException("list");
			}
			int count = 0;
			foreach (MetadataTag tag in list)
			{
				if (tag.Model == Model && tag.AddToImage(dib))
				{
					count++;
				}
			}
			return count;
		}

		/// <summary>
		/// Removes the specified tag from the bitmap.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>Returns true on success, false on failure.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="key"/> is null.</exception>
		public bool RemoveTag(string key)
		{
			if (key == null)
			{
				throw new ArgumentNullException("key");
			}
			return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero);
		}

		/// <summary>
		/// Destroys the metadata model
		/// which will remove all tags of this model from the bitmap.
		/// </summary>
		/// <returns>Returns true on success, false on failure.</returns>
		public bool DestoryModel()
		{
			return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero);
		}

		/// <summary>
		/// Returns the specified metadata tag.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>The metadata tag.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="key"/> is null.</exception>
		public MetadataTag GetTag(string key)
		{
			if (key == null)
			{
				throw new ArgumentNullException("key");
			}
			MetadataTag tag;
			return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null;
		}

		/// <summary>
		/// Returns whether the specified tag exists.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>True in case the tag exists, else false.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="key"/> is null.</exception>
		public bool TagExists(string key)
		{
			if (key == null)
			{
				throw new ArgumentNullException("key");
			}
			MetadataTag tag;
			return FreeImage.GetMetadata(Model, dib, key, out tag);
		}

		/// <summary>
		/// Returns a list of all metadata tags this instance represents.
		/// </summary>
		public List<MetadataTag> List
		{
			get
			{
				List<MetadataTag> list = new List<MetadataTag>((int)FreeImage.GetMetadataCount(Model, dib));
				MetadataTag tag;
				FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag);
				if (!mdHandle.IsNull)
				{
					do
					{
						list.Add(tag);
					}
					while (FreeImage.FindNextMetadata(mdHandle, out tag));
					FreeImage.FindCloseMetadata(mdHandle);
				}
				return list;
			}
		}

		/// <summary>
		/// Returns the tag at the given index.
		/// </summary>
		/// <param name="index">Index of the tag to return.</param>
		/// <returns>The tag at the given index.</returns>
		protected MetadataTag GetTagFromIndex(int index)
		{
			if (index >= Count || index < 0)
			{
				throw new ArgumentOutOfRangeException("index");
			}
			MetadataTag tag;
			int count = 0;
			FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag);
			if (!mdHandle.IsNull)
			{
				try
				{
					do
					{
						if (count++ == index)
						{
							break;
						}
					}
					while (FreeImage.FindNextMetadata(mdHandle, out tag));
				}
				finally
				{
					FreeImage.FindCloseMetadata(mdHandle);
				}
			}
			return tag;
		}

		/// <summary>
		/// Returns the metadata tag at the given index. This operation is slow when accessing all tags.
		/// </summary>
		/// <param name="index">Index of the tag.</param>
		/// <returns>The metadata tag.</returns>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <paramref name="index"/> is greater or equal <b>Count</b>
		/// or index is less than zero.</exception>
		public MetadataTag this[int index]
		{
			get
			{
				return GetTagFromIndex(index);
			}
		}

		/// <summary>
		/// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel.
		/// </summary>
		/// <returns>An <see cref="IEnumerator"/> for the
		/// <see cref="FreeImageAPI.Metadata.MetadataModel"/>.</returns>
		public IEnumerator GetEnumerator()
		{
			return List.GetEnumerator();
		}

		/// <summary>
		/// Returns the number of metadata tags this instance represents.
		/// </summary>
		public int Count
		{
			get { return (int)FreeImage.GetMetadataCount(Model, dib); }
		}

		/// <summary>
		/// Returns whether this model exists in the bitmaps metadata structure.
		/// </summary>
		public bool Exists
		{
			get
			{
				return Count > 0;
			}
		}

		/// <summary>
		/// Searches for a pattern in each metadata tag and returns the result as a list.
		/// </summary>
		/// <param name="searchPattern">The regular expression to use for the search.</param>
		/// <param name="flags">A bitfield that controls which fields should be searched in.</param>
		/// <returns>A list containing all found metadata tags.</returns>
		/// <exception cref="ArgumentNullException">
		/// <typeparamref name="searchPattern"/> is null.</exception>
		/// <exception cref="ArgumentException">
		/// <typeparamref name="searchPattern"/> is empty.</exception>
		public List<MetadataTag> RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags)
		{
			if (searchPattern == null)
			{
				throw new ArgumentNullException("searchString");
			}
			if (searchPattern.Length == 0)
			{
				throw new ArgumentException("searchString is empty");
			}
			List<MetadataTag> result = new List<MetadataTag>(Count);
			Regex regex = new Regex(searchPattern);
			List<MetadataTag> list = List;
			foreach (MetadataTag tag in list)
			{
				if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success)
				{
					result.Add(tag);
					continue;
				}
				if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success)
				{
					result.Add(tag);
					continue;
				}
				if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success)
				{
					result.Add(tag);
					continue;
				}
			}
			result.Capacity = result.Count;
			return result;
		}

		/// <summary>
		/// Returns the value of the specified tag.
		/// </summary>
		/// <typeparam name="T">Type of the tag's data.</typeparam>
		/// <param name="key">The key of the tag.</param>
		/// <returns>The value of the specified tag.</returns>
		protected T? GetTagValue<T>(string key) where T : struct
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			MetadataTag tag = GetTag(key);
			if (tag != null)
			{
				T[] value = tag.Value as T[];
				if ((value != null) && (value.Length != 0))
				{
					return value[0];
				}
			}
			return null;
		}

		/// <summary>
		/// Returns an array containing the data of the specified tag.
		/// </summary>
		/// <typeparam name="T">The type of the tag's data.</typeparam>
		/// <param name="key">The key of the tag.</param>
		/// <returns>An array containing the data of the specified tag.</returns>
		protected T[] GetTagArray<T>(string key) where T : struct
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			MetadataTag tag = GetTag(key);
			return (tag == null) ? null : tag.Value as T[];
		}

		/// <summary>
		/// Returns the string contained by the specified tag.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>The string contained by the specified tag.</returns>
		protected string GetTagText(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			MetadataTag tag = GetTag(key);
			return (tag == null) ? null : tag.Value as string;
		}

		/// <summary>
		/// Returns an array containg the data of the specified tag
		/// as unsigned 32bit integer.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>An array containg the data of the specified tag
		/// as unsigned 32bit integer.</returns>
		protected uint[] GetUInt32Array(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			uint[] result = null;
			MetadataTag tag = GetTag(key);
			if (tag != null)
			{
				object value = tag.Value;
				if (value != null)
				{
					if (value is ushort[])
					{
						ushort[] array = (ushort[])value;
						result = new uint[array.Length];
						for (int i = 0, j = array.Length; i < j; i++)
						{
							result[i] = (uint)array[i];
						}
					}
					else if (value is uint[])
					{
						result = (uint[])value;
					}
				}
			}
			return result;
		}

		/// <summary>
		/// Returns the value of the tag as unsigned 32bit integer.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <returns>The value of the tag as unsigned 32bit integer.</returns>
		protected uint? GetUInt32Value(string key)
		{
			uint[] value = GetUInt32Array(key);
			return value == null ? default(uint?) : value[0];
		}	

		/// <summary>
		/// Sets the value of the specified tag.
		/// </summary>
		/// <typeparam name="T">The type of the tag's data.</typeparam>
		/// <param name="key">The key of the tag.</param>
		/// <param name="value">The new value of the specified tag or null.</param>
		protected void SetTagValue<T>(string key, T? value) where T : struct
		{
			SetTagValue(key, value.HasValue ? new T[] { value.Value } : null);
		}

		/// <summary>
		/// Sets the value of the specified tag.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <param name="value">The new value of the specified tag or null.</param>
		protected void SetTagValue(string key, object value)
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			if (value == null)
			{
				RemoveTag(key);
			}
			else
			{
				MetadataTag tag = GetTag(key);
				if (tag == null)
				{
					tag = new MetadataTag(Model);
					tag.Key = key;
					tag.Value = value;
					AddTag(tag);
				}
				else
				{
					tag.Value = value;
				}
			}
		}

		/// <summary>
		/// Sets the value of the specified tag as undefined.
		/// </summary>
		/// <param name="key">The key of the tag.</param>
		/// <param name="value">The new value of the specified tag or null.</param>
		protected void SetTagValueUndefined(string key, byte[] value)
		{
			if (string.IsNullOrEmpty(key))
			{
				throw new ArgumentNullException("key");
			}
			if (value == null)
			{
				RemoveTag(key);
			}
			else
			{
				MetadataTag tag = GetTag(key);
				if (tag == null)
				{
					tag = new MetadataTag(Model);
					tag.Key = key;
					tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED);
					AddTag(tag);
				}
				else
				{
					tag.Value = value;
				}
			}
		}

		/// <summary>
		/// Returns the equivalent <see cref="DirectionReference"/> for the
		/// specified <see cref="String"/>.
		/// </summary>
		/// <param name="s">The string containing the <see cref="DirectionReference"/>.</param>
		/// <returns>The equivalent <see cref="DirectionReference"/> for the
		/// specified <see cref="String"/>.</returns>
		protected static DirectionReference? ToDirectionType(string s)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			switch (s[0])
			{
				case 'T':
					return DirectionReference.TrueDirection;
				case 'M':
					return DirectionReference.MagneticDirection;
				default:
					return DirectionReference.Undefined;
			}
		}

		/// <summary>
		/// Returns the equivalent <see cref="String"/> for the
		/// specified <see cref="DirectionReference"/>.
		/// </summary>
		/// <param name="type">The <see cref="DirectionReference"/> to convert.</param>
		/// <returns>The equivalent <see cref="String"/> for the
		/// specified <see cref="DirectionReference"/>.</returns>
		protected static string ToString(DirectionReference? type)
		{
			if (type.HasValue)
			{
				switch (type.Value)
				{
					case DirectionReference.TrueDirection:
						return "T";
					case DirectionReference.MagneticDirection:
						return "M";
					default:
						return "\0";
				}
			}
			return null;
		}

		/// <summary>
		/// Returns the equivalent <see cref="VelocityUnit"/> for the
		/// specified <see cref="String"/>.
		/// </summary>
		/// <param name="s">The string containing the <see cref="VelocityUnit"/>.</param>
		/// <returns>The equivalent <see cref="VelocityUnit"/> for the
		/// specified <see cref="String"/>.</returns>
		protected static VelocityUnit? ToUnitType(string s)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			switch (s[0])
			{
				case 'K':
					return VelocityUnit.Kilometers;
				case 'M':
					return VelocityUnit.Miles;
				case 'N':
					return VelocityUnit.Knots;
				default:
					return VelocityUnit.Undefinied;
			}
		}

		/// <summary>
		/// Returns the equivalent <see cref="String"/> for the
		/// specified <see cref="VelocityUnit"/>.
		/// </summary>
		/// <param name="type">The <see cref="VelocityUnit"/> to convert.</param>
		/// <returns>The equivalent <see cref="String"/> for the
		/// specified <see cref="VelocityUnit"/>.</returns>
		protected static string ToString(VelocityUnit? type)
		{
			if (type.HasValue)
			{
				switch (type.Value)
				{
					case VelocityUnit.Kilometers:
						return "K";
					case VelocityUnit.Miles:
						return "M";
					case VelocityUnit.Knots:
						return "N";
					default:
						return "\0";
				}
			}
			return null;
		}

		/// <summary>
		/// Returns the equivalent <see cref="LongitudeType"/> for the
		/// specified <see cref="String"/>.
		/// </summary>
		/// <param name="s">The string containing the <see cref="LongitudeType"/>.</param>
		/// <returns>The equivalent <see cref="LongitudeType"/> for the
		/// specified <see cref="String"/>.</returns>
		protected static LongitudeType? ToLongitudeType(string s)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			switch (s[0])
			{
				case 'E':
					return LongitudeType.East;
				case 'W':
					return LongitudeType.West;
				default:
					return LongitudeType.Undefined;
			}
		}

		/// <summary>
		/// Returns the equivalent <see cref="String"/> for the
		/// specified <see cref="LongitudeType"/>.
		/// </summary>
		/// <param name="type">The <see cref="LongitudeType"/> to convert.</param>
		/// <returns>The equivalent <see cref="String"/> for the
		/// specified <see cref="LongitudeType"/>.</returns>
		protected static string ToString(LongitudeType? type)
		{
			if (type.HasValue)
			{
				switch (type.Value)
				{
					case LongitudeType.East:
						return "E";
					case LongitudeType.West:
						return "W";
					default:
						return "\0";
				}
			}
			return null;
		}

		/// <summary>
		/// Returns the equivalent <see cref="LatitudeType"/> for the
		/// specified <see cref="String"/>.
		/// </summary>
		/// <param name="s">The string containing the <see cref="LatitudeType"/>.</param>
		/// <returns>The equivalent <see cref="LatitudeType"/> for the
		/// specified <see cref="String"/>.</returns>
		protected static LatitudeType? ToLatitudeType(string s)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			switch (s[0])
			{
				case 'N':
					return LatitudeType.North;
				case 'S':
					return LatitudeType.South;
				default:
					return LatitudeType.Undefined;
			}
		}

		/// <summary>
		/// Returns the equivalent <see cref="String"/> for the
		/// specified <see cref="LatitudeType"/>.
		/// </summary>
		/// <param name="type">The <see cref="LatitudeType"/> to convert.</param>
		/// <returns>The equivalent <see cref="String"/> for the
		/// specified <see cref="LatitudeType"/>.</returns>
		protected static string ToString(LatitudeType? type)
		{
			if (type.HasValue)
			{
				switch (type.Value)
				{
					case LatitudeType.North:
						return "N";
					case LatitudeType.South:
						return "S";
					default:
						return "\0";
				}
			}
			return null;
		}

		/// <summary>
		/// Returns the equivalent <see cref="InteroperabilityMode"/> for the
		/// specified <see cref="String"/>.
		/// </summary>
		/// <param name="s">The string containing the <see cref="InteroperabilityMode"/>.</param>
		/// <returns>The equivalent <see cref="InteroperabilityMode"/> for the
		/// specified <see cref="String"/>.</returns>
		protected static InteroperabilityMode? ToInteroperabilityType(string s)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			if (s.StartsWith("R98"))
				return InteroperabilityMode.R98;
			if (s.StartsWith("THM"))
				return InteroperabilityMode.THM;
			return InteroperabilityMode.Undefined;
		}

		/// <summary>
		/// Returns the equivalent <see cref="String"/> for the
		/// specified <see cref="InteroperabilityMode"/>.
		/// </summary>
		/// <param name="type">The <see cref="InteroperabilityMode"/> to convert.</param>
		/// <returns>The equivalent <see cref="String"/> for the
		/// specified <see cref="InteroperabilityMode"/>.</returns>
		protected static string ToString(InteroperabilityMode? type)
		{
			if (type.HasValue)
			{
				switch (type.Value)
				{
					case InteroperabilityMode.R98:
						return "R98";
					case InteroperabilityMode.THM:
						return "THM";
					default:
						return "\0\0\0";
				}
			}
			return null;
		}

		/// <summary>
		/// Specified different unit types.
		/// </summary>
		public enum VelocityUnit
		{
			/// <summary>
			/// No or unknown type.
			/// </summary>
			Undefinied,

			/// <summary>
			/// Kilometers per hour.
			/// </summary>
			Kilometers,

			/// <summary>
			/// Miles per hour.
			/// </summary>
			Miles,

			/// <summary>
			/// Knots.
			/// </summary>
			Knots,
		}

		/// <summary>
		/// Specifies different direction types.
		/// </summary>
		public enum DirectionReference
		{
			/// <summary>
			/// No or unknown direction type.
			/// </summary>
			Undefined,

			/// <summary>
			/// True direction.
			/// </summary>
			TrueDirection,

			/// <summary>
			/// Magnatic direction.
			/// </summary>
			MagneticDirection,
		}

		/// <summary>
		/// Specifies the type of a latitude value.
		/// </summary>
		public enum LatitudeType
		{
			/// <summary>
			/// No or unknown type.
			/// </summary>
			Undefined,

			/// <summary>
			/// North.
			/// </summary>
			North,

			/// <summary>
			/// South.
			/// </summary>
			South,
		}

		/// <summary>
		/// Specifies the type of a longitude value.
		/// </summary>
		public enum LongitudeType
		{
			/// <summary>
			/// No or unknown type.
			/// </summary>
			Undefined,

			/// <summary>
			/// East.
			/// </summary>
			East,

			/// <summary>
			/// West.
			/// </summary>
			West,
		}

		/// <summary>
		/// Specifies different altitude types.
		/// </summary>
		public enum AltitudeType
		{
			/// <summary>
			/// No or unknown type.
			/// </summary>
			Undefined,

			/// <summary>
			/// East.
			/// </summary>
			AboveSeaLevel,

			/// <summary>
			/// West.
			/// </summary>
			BelowSeaLevel,
		}

		/// <summary>
		/// Specifies interoperability types.
		/// </summary>
		public enum InteroperabilityMode
		{
			/// <summary>
			/// No or unknown type.
			/// </summary>
			Undefined,

			/// <summary>
			/// Indicates a file conforming to R98 file specification of Recommended
			/// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated
			/// by Design Rule for Camera File System.
			/// </summary>
			R98,

			/// <summary>
			/// Indicates a file conforming to DCF thumbnail file stipulated by Design
			/// rule for Camera File System. 
			/// </summary>
			THM,
		}

		/// <summary>
		/// Specifies orientation of images.
		/// </summary>
		public enum ExifImageOrientation : ushort
		{
			/// <summary>
			/// Undefinied orientation.
			/// </summary>
			Undefined,

			/// <summary>
			/// TopLeft.
			/// </summary>
			TopLeft = 1,

			/// <summary>
			/// TopRight.
			/// </summary>
			TopRight,

			/// <summary>
			/// BottomRight.
			/// </summary>
			BottomRight,

			/// <summary>
			/// BottomLeft.
			/// </summary>
			BottomLeft,

			/// <summary>
			/// LeftTop.
			/// </summary>
			LeftTop,

			/// <summary>
			/// RightTop.
			/// </summary>
			RightTop,

			/// <summary>
			/// RightBottom.
			/// </summary>
			RightBottom,

			/// <summary>
			/// LeftBottom.
			/// </summary>
			LeftBottom,
		}

		/// <summary>
		/// Converts the model of the MetadataModel object to its equivalent string representation.
		/// </summary>
		/// <returns>The string representation of the value of this instance.</returns>
		public override string ToString()
		{
			return Model.ToString();
		}
	}
}