GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

gdcmPersonName.h
Go to the documentation of this file.
1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14
15 #ifndef GDCMPERSONNAME_H
16 #define GDCMPERSONNAME_H
17
18 #include "gdcmTypes.h"
19 #include <vector>
20 #include <algorithm> // std::min
21 #include <string.h> // strlen
22
23 namespace gdcm
24 {
25
29 class GDCM_EXPORT PersonName
30 {
31 public:
32 static const unsigned int MaxNumberOfComponents = 5;
33 static const unsigned int MaxLength = 64;
34 char Component[MaxNumberOfComponents][MaxLength+1];
35 static const char Separator = '^';
36 static const char Padding = ' ';
37
38 unsigned int GetNumberOfComponents() const {
39 unsigned int r = 0;
40 for(unsigned int i = 0; i < 5; ++i) {
41 if( *Component[i] != '\0' ) r = i;
42 }
43 return r+1;
44 }
45 unsigned int GetMaxLength() const { return MaxLength; };
46 void SetBlob(const std::vector<char>& v) {
47 (void)v;
48 //assert(0); //TODO
49 }
50 void SetComponents(const char *comp1 = "",
51 const char *comp2 = "",
52 const char *comp3 = "",
53 const char *comp4 = "",
54 const char *comp5 = "") {
55 const char *components[5] = { comp1, comp2, comp3, comp4, comp5 };
56 SetComponents( components );
57 }
58 void SetComponents(const char *components[]) {
59 for(unsigned int i = 0; i < 5; ++i) {
60 //strncpy(Component[i], components[i], std::min( (unsigned int)strlen(components[i]), GetMaxLength() ) );
61 assert( strlen(components[i]) < GetMaxLength() );
62 strcpy(Component[i], components[i]);
63 assert( strlen(Component[i]) < GetMaxLength() );
64 }
65 }
66 void Print(std::ostream &os) const
67 {
68 //os << "Family Name Complex: " << Component[0] << std::endl;
69 //os << "Given Name Complex: " << Component[1] << std::endl;
70 //os << "Middle Name : " << Component[2] << std::endl;
71 //os << "Name Suffix : " << Component[3] << std::endl;
72 //os << "Name Prefix : " << Component[4] << std::endl;
73 os << Component[0] << '^';
74 os << Component[1] << '^';
75 os << Component[2] << '^';
76 os << Component[3] << '^';
77 os << Component[4];
78 }
79 };
80
81 } // end namespace gdcm
82
83 #endif //GDCMPERSONNAME_H