GDCM  2.2.0
gdcmPersonName.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004 
00005   Copyright (c) 2006-2011 Mathieu Malaterre
00006   All rights reserved.
00007   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 
00015 #ifndef GDCMPERSONNAME_H
00016 #define GDCMPERSONNAME_H
00017 
00018 #include "gdcmTypes.h"
00019 #include <vector>
00020 #include <algorithm> // std::min
00021 #include <string.h> // strlen
00022 
00023 namespace gdcm
00024 {
00025 
00029 class GDCM_EXPORT PersonName
00030 {
00031 public:
00032   static const unsigned int MaxNumberOfComponents = 5;
00033   static const unsigned int MaxLength = 64;
00034   char Component[MaxNumberOfComponents][MaxLength+1];
00035   static const char Separator = '^';
00036   static const char Padding   = ' ';
00037 
00038   unsigned int GetNumberOfComponents() const {
00039     unsigned int r = 0;
00040     for(unsigned int i = 0; i < 5; ++i) {
00041       if( *Component[i] != '\0' ) r = i;
00042       }
00043     return r+1;
00044   }
00045   unsigned int GetMaxLength() const { return MaxLength; };
00046   void SetBlob(const std::vector<char>& v) {
00047   (void)v;
00048     //assert(0); //TODO
00049   }
00050   void SetComponents(const char *comp1 = "",
00051     const char *comp2 = "",
00052     const char *comp3 = "",
00053     const char *comp4 = "",
00054     const char *comp5 = "") {
00055     const char *components[5] = { comp1, comp2, comp3, comp4, comp5 };
00056     SetComponents( components );
00057   }
00058   void SetComponents(const char *components[]) {
00059     for(unsigned int i = 0; i < 5; ++i) {
00060       //strncpy(Component[i], components[i], std::min( (unsigned int)strlen(components[i]), GetMaxLength() ) );
00061       assert( strlen(components[i]) < GetMaxLength() );
00062       strcpy(Component[i], components[i]);
00063       assert( strlen(Component[i]) < GetMaxLength() );
00064       }
00065   }
00066   void Print(std::ostream &os) const
00067   {
00068     //os << "Family Name Complex: " << Component[0] << std::endl;
00069     //os << "Given  Name Complex: " << Component[1] << std::endl;
00070     //os << "Middle Name        : " << Component[2] << std::endl;
00071     //os << "Name Suffix        : " << Component[3] << std::endl;
00072     //os << "Name Prefix        : " << Component[4] << std::endl;
00073     os << Component[0] << '^';
00074     os << Component[1] << '^';
00075     os << Component[2] << '^';
00076     os << Component[3] << '^';
00077     os << Component[4];
00078   }
00079 };
00080 
00081 } // end namespace gdcm
00082 
00083 #endif //GDCMPERSONNAME_H

Generated on Fri Jun 1 2012 19:00:32 for GDCM by doxygen 1.7.6.1
SourceForge.net Logo