# gdcmPersonName.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
    00016 #ifndef __gdcmPersonName_h
    00017 #define __gdcmPersonName_h
    00018
    00019 #include "gdcmTypes.h"
    00020 #include <vector>
    00021 #include <algorithm> // std::min
    00022 #include <string.h> // strlen
    00023
    00024 namespace gdcm
    00025 {
    00026
    00030 class GDCM_EXPORT PersonName
    00031 {
    00032 public:
    00033   static const unsigned int MaxNumberOfComponents = 5;
    00034   static const unsigned int MaxLength = 64;
    00035   char Component[MaxNumberOfComponents][MaxLength+1];
    00036   static const char Separator = '^';
    00037   static const char Padding   = ' ';
    00038
    00039   unsigned int GetNumberOfComponents() const {
    00040     unsigned int r = 0;
    00041     for(unsigned int i = 0; i < 5; ++i) {
    00042       if( *Component[i] != '\0' ) r = i;
    00043       }
    00044     return r+1;
    00045   }
    00046   unsigned int GetMaxLength() const { return MaxLength; };
    00047   void SetBlob(const std::vector<char>& v) {
    00048   (void)v;
    00049     //assert(0); //TODO
    00050   }
    00051   void SetComponents(const char *comp1 = "",
    00052     const char *comp2 = "",
    00053     const char *comp3 = "",
    00054     const char *comp4 = "",
    00055     const char *comp5 = "") {
    00056     const char *components[5] = { comp1, comp2, comp3, comp4, comp5 };
    00057     SetComponents( components );
    00058   }
    00059   void SetComponents(const char *components[]) {
    00060     for(unsigned int i = 0; i < 5; ++i) {
    00061       //strncpy(Component[i], components[i], std::min( (unsigned int)strlen(components[i]), GetMaxLength() ) );
    00062       assert( strlen(components[i]) < GetMaxLength() );
    00063       strcpy(Component[i], components[i]);
    00064       assert( strlen(Component[i]) < GetMaxLength() );
    00065       }
    00066   }
    00067   void Print(std::ostream &os) const
    00068   {
    00069     //os << "Family Name Complex: " << Component[0] << std::endl;
    00070     //os << "Given  Name Complex: " << Component[1] << std::endl;
    00071     //os << "Middle Name        : " << Component[2] << std::endl;
    00072     //os << "Name Suffix        : " << Component[3] << std::endl;
    00073     //os << "Name Prefix        : " << Component[4] << std::endl;
    00074     os << Component[0] << '^';
    00075     os << Component[1] << '^';
    00076     os << Component[2] << '^';
    00077     os << Component[3] << '^';
    00078     os << Component[4];
    00079   }
    00080 };
    00081
    00082 } // end namespace gdcm
    00083
    00084 #endif //__gdcmPersonName_h
    00085