# gdcmVM.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2009 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef __gdcmVM_h
    00016 #define __gdcmVM_h
    00017
    00018 #include "gdcmTypes.h"
    00019 #include <iostream>
    00020
    00021 namespace gdcm
    00022 {
    00023
    00068 class GDCM_EXPORT VM
    00069 {
    00070 public:
    00071   typedef enum {
    00072     VM0 = 0, // aka the invalid VM
    00073     VM1 = 1,
    00074     VM2 = 2,
    00075     VM3 = 4,
    00076     VM4 = 8,
    00077     VM5 = 16,
    00078     VM6 = 32,
    00079     VM8 = 64,
    00080     VM9 = 128,
    00081     VM10 = 256,
    00082     VM12 = 512, //1024,
    00083     VM16 = 1024, //2048,
    00084     VM18 = 2048, //4096,
    00085     VM24 = 4096, //8192,
    00086     VM28 = 8192, //16384,
    00087     VM32 = 16384, //32768,
    00088     VM35 = 32768, //65536,
    00089     VM99 = 65536, //131072,
    00090     VM256 = 131072, //262144,
    00091     VM1_2  = VM1 | VM2,
    00092     VM1_3  = VM1 | VM2 | VM3,
    00093     VM1_4  = VM1 | VM2 | VM3 | VM4,
    00094     VM1_5  = VM1 | VM2 | VM3 | VM4 | VM5,
    00095     VM1_8  = VM1 | VM2 | VM3 | VM4 | VM5 | VM6 | VM8,
    00096 // The following need some work:
    00097     VM1_32 = VM1 | VM2 | VM3 | VM4 | VM5 | VM6 | VM8 | VM9 | VM16 | VM24 | VM32,
    00098     VM1_99 = VM1 | VM2 | VM3 | VM4 | VM5 | VM6 | VM8 | VM9 | VM16 | VM24 | VM32 | VM99,
    00099     VM1_n  = VM1 | VM2 | VM3 | VM4 | VM5 | VM6 | VM8 | VM9 | VM16 | VM24 | VM32 | VM99 | VM256,
    00100     VM2_2n =       VM2       | VM4       | VM6 | VM8       | VM16 | VM24 | VM32        | VM256,
    00101     VM2_n  =       VM2 | VM3 | VM4 | VM5 | VM6 | VM8 | VM9 | VM16 | VM24 | VM32 | VM99 | VM256,
    00102     VM3_4  =             VM3 | VM4,
    00103     VM3_3n =             VM3 |             VM6       | VM9        | VM24        | VM99 | VM256,
    00104     VM3_n  =             VM3 | VM4 | VM5 | VM6 | VM8 | VM9 | VM16 | VM24 | VM32 | VM99 | VM256,
    00105     VM4_4n =                   VM4                         | VM16 | VM24 | VM32        | VM256,
    00106     VM6_6n =                               VM6             | VM12 | VM18 | VM24               ,
    00107     VM7_7n,
    00108     VM30_30n,
    00109     VM47_47n,
    00110     VM_END = VM1_n + 1  // Custom tag to count number of entry
    00111   } VMType;
    00112
    00115   static const char* GetVMString(VMType vm);
    00116   static VMType GetVMType(const char *vm);
    00117
    00120   static bool IsValid(int vm1, VMType vm2);
    00121   //bool IsValid() { return VMField != VM0 && VMField < VM_END; }
    00122
    00126   bool Compatible(VM const &vm) const;
    00127
    00129   static VMType GetVMTypeFromLength(unsigned int length, unsigned int size);
    00130   static unsigned int GetNumberOfElementsFromArray(const char *array, unsigned int length);
    00131
    00132   VM(VMType type = VM0):VMField(type) {}
    00133   operator VMType () const { return VMField; }
    00134   unsigned int GetLength() const;
    00135
    00136   friend std::ostream &operator<<(std::ostream &os, const VM &vm);
    00137 protected:
    00138   static unsigned int GetIndex(VMType vm);
    00139
    00140 private:
    00141   VMType VMField;
    00142 };
    00143 //-----------------------------------------------------------------------------
    00144 inline std::ostream& operator<<(std::ostream& _os, const VM &_val)
    00145 {
    00146   assert( VM::GetVMString(_val) );
    00147   _os << VM::GetVMString(_val);
    00148   return _os;
    00149 }
    00150
    00151 //template <int TVM> struct LengthToVM;
    00152 //template <> struct LengthToVM<1>
    00153 //{ enum { TVM = VM::VM1 }; };
    00154
    00155 template<int T> struct VMToLength;
    00156 #define TYPETOLENGTH(type,length) \
    00157   template<> struct VMToLength<VM::type> \
    00158   { enum { Length = length }; };
    00159 // TODO: Could be generated from XML file
    00160 //TYPETOLENGTH(VM0,1)
    00161 TYPETOLENGTH(VM1,1)
    00162 TYPETOLENGTH(VM2,2)
    00163 TYPETOLENGTH(VM3,3)
    00164 TYPETOLENGTH(VM4,4)
    00165 TYPETOLENGTH(VM5,5)
    00166 TYPETOLENGTH(VM6,6)
    00167 TYPETOLENGTH(VM8,8)
    00168 TYPETOLENGTH(VM9,9)
    00169 TYPETOLENGTH(VM10,10)
    00170 TYPETOLENGTH(VM12,12)
    00171 TYPETOLENGTH(VM16,16)
    00172 TYPETOLENGTH(VM18,18)
    00173 TYPETOLENGTH(VM24,24)
    00174 TYPETOLENGTH(VM28,28)
    00175 TYPETOLENGTH(VM32,32)
    00176 TYPETOLENGTH(VM35,35)
    00177 TYPETOLENGTH(VM99,99)
    00178 TYPETOLENGTH(VM256,256)
    00179 //TYPETOLENGTH(VM1_2,2)
    00180 //TYPETOLENGTH(VM1_3,3)
    00181 //TYPETOLENGTH(VM1_8,8)
    00182 //TYPETOLENGTH(VM1_32,32)
    00183 //TYPETOLENGTH(VM1_99,99)
    00184 //TYPETOLENGTH(VM1_n,
    00185 //TYPETOLENGTH(VM2_2n,
    00186 //TYPETOLENGTH(VM2_n,
    00187 //TYPETOLENGTH(VM3_3n,
    00188 //TYPETOLENGTH(VM3_n,
    00189
    00190 } // end namespace gdcm
    00191
    00192 #endif //__gdcmVM_h