GDCM 2.2.1

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

- File List
- File Members

gdcmCodeString.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 #ifndef GDCMCODESTRING_H
15 #define GDCMCODESTRING_H
16
17 #include "gdcmString.h"
18
19 namespace gdcm
20 {
21
39 // Note to myself: because note all wrapped language support exception
40 // we could not support throwing an exception during object construction.
41 class GDCM_EXPORT CodeString
42 {
43 friend std::ostream& operator<< (std::ostream& os, const CodeString& str);
44 friend bool operator==(const CodeString &ref, const CodeString& cs);
45 friend bool operator!=(const CodeString &ref, const CodeString& cs);
46 typedef String<'\\',16> InternalClass;
47 public:
48 typedef InternalClass::value_type value_type;
49 typedef InternalClass::pointer pointer;
50 typedef InternalClass::reference reference;
51 typedef InternalClass::const_reference const_reference;
52 typedef InternalClass::size_type size_type;
53 typedef InternalClass::difference_type difference_type;
54 typedef InternalClass::iterator iterator;
55 typedef InternalClass::const_iterator const_iterator;
56 typedef InternalClass::reverse_iterator reverse_iterator;
57 typedef InternalClass::const_reverse_iterator const_reverse_iterator;
58
60 CodeString(): Internal() {}
61 CodeString(const value_type* s): Internal(s) { Internal = Internal.Trim(); }
62 CodeString(const value_type* s, size_type n): Internal(s, n) {
63 Internal = Internal.Trim(); }
64 CodeString(const InternalClass& s, size_type pos=0, size_type n=InternalClass::npos):
65 Internal(s, pos, n) { Internal = Internal.Trim(); }
66
68 bool IsValid() const;
69
71 std::string GetAsString() const {
72 return Internal;
73 }
74
76 size_type Size() const { return Internal.size(); }
77
78 protected:
79 std::string TrimInternal() const {
80 return Internal.Trim();
81 }
82
83 private:
84 String<'\\',16> Internal;
85 };
86
87 inline std::ostream& operator<< (std::ostream& os, const CodeString& str)
88 {
89 os << str.Internal;
90 return os;
91 }
92
93 inline bool operator==(const CodeString &ref, const CodeString& cs)
94 {
95 return ref.Internal == cs.Internal;
96 }
97 inline bool operator!=(const CodeString &ref, const CodeString& cs)
98 {
99 return ref.Internal != cs.Internal;
100 }
101
102
103 } // end namespace gdcm
104
105 #endif //GDCMCODESTRING_H