GDCM: gdcmScanner2.h Source File

GDCM 3.2.10

gdcmScanner2.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 GDCMSCANNER2_H
15#define GDCMSCANNER2_H
16
17#include "gdcmDirectory.h"
18#include "gdcmSubject.h"
19#include "gdcmTag.h"
20#include "gdcmPrivateTag.h"
21#include "gdcmSmartPointer.h"
22
23#include <map>
24#include <set>
25#include <string>
26
27#include <string.h> // strcmp
28
29namespace gdcm
30{
31class StringFilter;
32
55 class GDCM_EXPORT Scanner2 : public Subject
56{
57 friend std::ostream& operator<<(std::ostream &_os, const Scanner2 &s);
58public:
59 Scanner2():Values(),Filenames(),PublicMappings(),PrivateMappings(),Progress(0.0) {}
60 ~Scanner2() override;
61
68 typedef std::map<Tag, const char*> PublicTagToValue;
69 typedef PublicTagToValue::value_type PublicTagToValueValueType;
70
71 typedef std::map<PrivateTag, const char*> PrivateTagToValue;
72 typedef PrivateTagToValue::value_type PrivateTagToValueValueType;
73
75 bool AddPublicTag( Tag const & t );
76 void ClearPublicTags();
77
78 // Work in progress do not use:
79 bool AddPrivateTag( PrivateTag const & pt );
80 void ClearPrivateTags();
81
83 bool AddSkipTag( Tag const & t );
84 void ClearSkipTags();
85
87 bool Scan( Directory::FilenamesType const & filenames );
88
90 Directory::FilenamesType const &GetFilenames() const { return Filenames; }
91
93 void Print( std::ostream & os ) const override;
94
96 void PrintTable( std::ostream & os, bool header = false ) const;
97
101 bool IsKey( const char * filename ) const;
102
105 Directory::FilenamesType GetKeys() const;
106
107 // struct to store all the values found:
108 typedef std::set< std::string > ValuesType;
109
111 ValuesType const & GetValues() const { return Values; }
112
114 ValuesType GetPublicValues(Tag const &t) const;
115
117 ValuesType GetPrivateValues(PrivateTag const &pt) const;
118
122 Directory::FilenamesType GetPublicOrderedValues(Tag const &t) const;
123
124 Directory::FilenamesType GetPrivateOrderedValues(PrivateTag const &pt) const;
125
126 /* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
127 struct ltstr
128 {
129 bool operator()(const char* s1, const char* s2) const
130 {
131 gdcm_assert( s1 && s2 );
132 return strcmp(s1, s2) < 0;
133 }
134 };
135 typedef std::map<const char *,PublicTagToValue, ltstr> PublicMappingType;
136 typedef PublicMappingType::const_iterator PublicConstIterator;
137 PublicConstIterator Begin() const { return PublicMappings.begin(); }
138 PublicConstIterator End() const { return PublicMappings.end(); }
139
140 typedef std::map<const char *,PrivateTagToValue, ltstr> PrivateMappingType;
141 typedef PrivateMappingType::const_iterator PrivateConstIterator;
142 PrivateConstIterator PrivateBegin() const { return PrivateMappings.begin(); }
143 PrivateConstIterator PrivateEnd() const { return PrivateMappings.end(); }
144
146 PublicMappingType const & GetPublicMappings() const { return PublicMappings; }
147 PrivateMappingType const & GetPrivateMappings() const { return PrivateMappings; }
148
150 PublicTagToValue const & GetPublicMapping(const char *filename) const;
151 PrivateTagToValue const & GetPrivateMapping(const char *filename) const;
152
155 const char *GetFilenameFromPublicTagToValue(Tag const &t, const char *valueref) const;
156 const char *GetFilenameFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const;
157
160 Directory::FilenamesType GetAllFilenamesFromPublicTagToValue(Tag const &t, const char *valueref) const;
161 Directory::FilenamesType GetAllFilenamesFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const;
162
164 // by a call to GetMapping()
165 PublicTagToValue const & GetMappingFromPublicTagToValue(Tag const &t, const char *value) const;
166 PrivateTagToValue const & GetMappingFromPrivateTagToValue(PrivateTag const &pt, const char *value) const;
167
173 const char* GetPublicValue(const char *filename, Tag const &t) const;
174 const char* GetPrivateValue(const char *filename, PrivateTag const &t) const;
175
177 static SmartPointer<Scanner2> New() { return new Scanner2; }
178
179protected:
180 void ProcessPublicTag(StringFilter &sf, const char *filename);
181 void ProcessPrivateTag(StringFilter &sf, const char *filename);
182private:
183 // struct to store all uniq tags in ascending order:
184 typedef std::set< Tag > PublicTagsType;
185 typedef std::set< PrivateTag > PrivateTagsType;
186 std::set< Tag > PublicTags; // Public and Private Creator
187 std::set< PrivateTag > PrivateTags; // Only Private (no Private Creator)
188 std::set< Tag > SkipTags;
189 ValuesType Values;
190 Directory::FilenamesType Filenames;
191
192 // Main struct that will hold all public mapping:
193 PublicMappingType PublicMappings;
194 // Main struct that will hold all private mapping:
195 PrivateMappingType PrivateMappings;
196
197 double Progress;
198};
199//-----------------------------------------------------------------------------
200 inline std::ostream& operator<<(std::ostream &os, const Scanner2 &s)
201{
202 s.Print( os );
203 return os;
204}
205
206} // end namespace gdcm
207
208#endif //GDCMSCANNER2_H
gdcm::Directory::FilenamesType
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
gdcm::PrivateTag
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner).
Definition gdcmPrivateTag.h:39
gdcm::Scanner2::PrivateMappingType
std::map< const char *, PrivateTagToValue, ltstr > PrivateMappingType
Definition gdcmScanner2.h:140
gdcm::Scanner2::End
PublicConstIterator End() const
Definition gdcmScanner2.h:138
gdcm::Scanner2::Scan
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
gdcm::Scanner2::GetFilenames
Directory::FilenamesType const & GetFilenames() const
Return the list of filenames.
Definition gdcmScanner2.h:90
gdcm::Scanner2::AddPrivateTag
bool AddPrivateTag(PrivateTag const &pt)
gdcm::Scanner2::Begin
PublicConstIterator Begin() const
Definition gdcmScanner2.h:137
gdcm::Scanner2::GetFilenameFromPublicTagToValue
const char * GetFilenameFromPublicTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner2::PublicTagToValue
std::map< Tag, const char * > PublicTagToValue
Definition gdcmScanner2.h:68
gdcm::Scanner2::New
static SmartPointer< Scanner2 > New()
for wrapped language: instantiate a reference counted object
Definition gdcmScanner2.h:177
gdcm::Scanner2::PrivateTagToValue
std::map< PrivateTag, const char * > PrivateTagToValue
Definition gdcmScanner2.h:71
gdcm::Scanner2::GetMappingFromPrivateTagToValue
PrivateTagToValue const & GetMappingFromPrivateTagToValue(PrivateTag const &pt, const char *value) const
gdcm::Scanner2::ClearPrivateTags
void ClearPrivateTags()
gdcm::Scanner2::GetAllFilenamesFromPrivateTagToValue
Directory::FilenamesType GetAllFilenamesFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const
gdcm::Scanner2::Scanner2
Scanner2()
Definition gdcmScanner2.h:59
gdcm::Scanner2::GetPrivateMappings
PrivateMappingType const & GetPrivateMappings() const
Definition gdcmScanner2.h:147
gdcm::Scanner2::GetPublicMapping
PublicTagToValue const & GetPublicMapping(const char *filename) const
Get the std::map mapping filenames to value for file 'filename'.
gdcm::Scanner2::Print
void Print(std::ostream &os) const override
Print result.
gdcm::Scanner2::ValuesType
std::set< std::string > ValuesType
Definition gdcmScanner2.h:108
gdcm::Scanner2::PublicMappingType
std::map< const char *, PublicTagToValue, ltstr > PublicMappingType
Definition gdcmScanner2.h:135
gdcm::Scanner2::GetFilenameFromPrivateTagToValue
const char * GetFilenameFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const
gdcm::Scanner2::PrintTable
void PrintTable(std::ostream &os, bool header=false) const
Print result as CSV table.
gdcm::Scanner2::GetMappingFromPublicTagToValue
PublicTagToValue const & GetMappingFromPublicTagToValue(Tag const &t, const char *value) const
See GetFilenameFromTagToValue(). This is simply GetFilenameFromTagToValue followed.
gdcm::Scanner2::PrivateTagToValueValueType
PrivateTagToValue::value_type PrivateTagToValueValueType
Definition gdcmScanner2.h:72
gdcm::Scanner2::GetPrivateOrderedValues
Directory::FilenamesType GetPrivateOrderedValues(PrivateTag const &pt) const
gdcm::Scanner2::ClearSkipTags
void ClearSkipTags()
gdcm::Scanner2::ProcessPublicTag
void ProcessPublicTag(StringFilter &sf, const char *filename)
gdcm::Scanner2::PrivateBegin
PrivateConstIterator PrivateBegin() const
Definition gdcmScanner2.h:142
gdcm::Scanner2::GetPublicMappings
PublicMappingType const & GetPublicMappings() const
Mappings are the mapping from a particular tag to the map, mapping filename to value:
Definition gdcmScanner2.h:146
gdcm::Scanner2::GetPrivateMapping
PrivateTagToValue const & GetPrivateMapping(const char *filename) const
gdcm::Scanner2::GetPublicValue
const char * GetPublicValue(const char *filename, Tag const &t) const
gdcm::Scanner2::PublicTagToValueValueType
PublicTagToValue::value_type PublicTagToValueValueType
Definition gdcmScanner2.h:69
gdcm::Scanner2::GetPublicValues
ValuesType GetPublicValues(Tag const &t) const
Get all the values found (in lexicographic order) associated with Tag 't'.
gdcm::Scanner2::IsKey
bool IsKey(const char *filename) const
gdcm::Scanner2::GetPublicOrderedValues
Directory::FilenamesType GetPublicOrderedValues(Tag const &t) const
gdcm::Scanner2::PublicConstIterator
PublicMappingType::const_iterator PublicConstIterator
Definition gdcmScanner2.h:136
gdcm::Scanner2::AddPublicTag
bool AddPublicTag(Tag const &t)
Add a tag that will need to be read. Those are root level tags.
gdcm::Scanner2::ProcessPrivateTag
void ProcessPrivateTag(StringFilter &sf, const char *filename)
gdcm::Scanner2::PrivateEnd
PrivateConstIterator PrivateEnd() const
Definition gdcmScanner2.h:143
gdcm::Scanner2::ClearPublicTags
void ClearPublicTags()
gdcm::Scanner2::GetAllFilenamesFromPublicTagToValue
Directory::FilenamesType GetAllFilenamesFromPublicTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner2::~Scanner2
~Scanner2() override
gdcm::Scanner2::GetValues
ValuesType const & GetValues() const
Get all the values found (in lexicographic order).
Definition gdcmScanner2.h:111
gdcm::Scanner2::AddSkipTag
bool AddSkipTag(Tag const &t)
Add a tag that will need to be skipped. Those are root level skip tags.
gdcm::Scanner2::GetPrivateValues
ValuesType GetPrivateValues(PrivateTag const &pt) const
Get all the values found (in lexicographic order) associated with PrivateTag 'pt'.
gdcm::Scanner2::GetKeys
Directory::FilenamesType GetKeys() const
gdcm::Scanner2::GetPrivateValue
const char * GetPrivateValue(const char *filename, PrivateTag const &t) const
gdcm::Scanner2::operator<<
friend std::ostream & operator<<(std::ostream &_os, const Scanner2 &s)
Definition gdcmScanner2.h:200
gdcm::Scanner2::PrivateConstIterator
PrivateMappingType::const_iterator PrivateConstIterator
Definition gdcmScanner2.h:141
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::StringFilter
StringFilter.
Definition gdcmStringFilter.h:30
gdcm::Subject::Subject
Subject()
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmDirectory.h
gdcm_assert
#define gdcm_assert(cond)
Definition gdcmException.h:104
gdcmPrivateTag.h
gdcmSmartPointer.h
gdcmSubject.h
gdcmTag.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21
gdcm::operator<<
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88
gdcm::Scanner2::ltstr
Definition gdcmScanner2.h:128
gdcm::Scanner2::ltstr::operator()
bool operator()(const char *s1, const char *s2) const
Definition gdcmScanner2.h:129