PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/DICOM/DicomVM.cs

https://github.com/petnet/fo-dicom
C# | 106 lines | 89 code | 17 blank | 0 comment | 12 complexity | 80935f9b5bedd23932d6400249cf2d26 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Dicom {
  7. public class DicomVM {
  8. private static IDictionary<string, DicomVM> _vm = new Dictionary<string, DicomVM>();
  9. public readonly static DicomVM VM_1 = DicomVM.Parse("1");
  10. public readonly static DicomVM VM_1_2 = DicomVM.Parse("1-2");
  11. public readonly static DicomVM VM_1_3 = DicomVM.Parse("1-3");
  12. public readonly static DicomVM VM_1_8 = DicomVM.Parse("1-8");
  13. public readonly static DicomVM VM_1_32 = DicomVM.Parse("1-32");
  14. public readonly static DicomVM VM_1_99 = DicomVM.Parse("1-99");
  15. public readonly static DicomVM VM_1_n = DicomVM.Parse("1-n");
  16. public readonly static DicomVM VM_2 = DicomVM.Parse("2");
  17. public readonly static DicomVM VM_2_n = DicomVM.Parse("2-n");
  18. public readonly static DicomVM VM_2_2n = DicomVM.Parse("2-2n");
  19. public readonly static DicomVM VM_3 = DicomVM.Parse("3");
  20. public readonly static DicomVM VM_3_n = DicomVM.Parse("3-n");
  21. public readonly static DicomVM VM_3_3n = DicomVM.Parse("3-3n");
  22. public readonly static DicomVM VM_4 = DicomVM.Parse("4");
  23. public readonly static DicomVM VM_6 = DicomVM.Parse("6");
  24. public readonly static DicomVM VM_16 = DicomVM.Parse("16");
  25. public DicomVM(int minimum, int maximum, int multiplicity) {
  26. Minimum = minimum;
  27. Maximum = maximum;
  28. Multiplicity = multiplicity;
  29. }
  30. private DicomVM() {
  31. Minimum = 1;
  32. Maximum = 1;
  33. Multiplicity = 1;
  34. }
  35. public int Minimum {
  36. get;
  37. private set;
  38. }
  39. public int Maximum {
  40. get;
  41. private set;
  42. }
  43. public int Multiplicity {
  44. get;
  45. private set;
  46. }
  47. public override string ToString() {
  48. if (Minimum == Maximum)
  49. return Minimum.ToString();
  50. if (Maximum == int.MaxValue) {
  51. if (Multiplicity > 1)
  52. return String.Format(@"{0}-{1}n", Minimum, Multiplicity);
  53. else
  54. return String.Format(@"{0}-n", Minimum);
  55. }
  56. return String.Format(@"{0}-{1}", Minimum, Maximum);
  57. }
  58. public static DicomVM Parse(string s) {
  59. try {
  60. DicomVM vm = null;
  61. if (_vm.TryGetValue(s, out vm))
  62. return vm;
  63. string[] parts = s.Split('-');
  64. if (parts.Length == 1) {
  65. vm = new DicomVM();
  66. vm.Minimum = int.Parse(parts[0]);
  67. vm.Maximum = vm.Minimum;
  68. vm.Multiplicity = vm.Minimum;
  69. } else {
  70. vm = new DicomVM();
  71. vm.Minimum = int.Parse(parts[0]);
  72. vm.Multiplicity = 1;
  73. if (parts[1].EndsWith("n", StringComparison.InvariantCultureIgnoreCase)) {
  74. vm.Maximum = int.MaxValue;
  75. parts[1] = parts[1].TrimEnd('n', 'N');
  76. if (parts[1].Length > 0)
  77. vm.Multiplicity = int.Parse(parts[1]);
  78. } else {
  79. vm.Maximum = int.Parse(parts[1]);
  80. }
  81. }
  82. _vm.Add(s, vm);
  83. return vm;
  84. } catch (Exception e) {
  85. throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
  86. }
  87. }
  88. }
  89. }