GDCM 3.0.24
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
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 );
77
78 // Work in progress do not use:
79 bool AddPrivateTag( PrivateTag const & pt );
81
83 bool AddSkipTag( Tag const & t );
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
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
115
118
123
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 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
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//-----------------------------------------------------------------------------
200inline 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
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner)
Definition gdcmPrivateTag.h:39
Scanner2.
Definition gdcmScanner2.h:56
std::map< const char *, PrivateTagToValue, ltstr > PrivateMappingType
Definition gdcmScanner2.h:140
PublicConstIterator End() const
Definition gdcmScanner2.h:138
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
Directory::FilenamesType const & GetFilenames() const
Return the list of filenames.
Definition gdcmScanner2.h:90
bool AddPrivateTag(PrivateTag const &pt)
PublicConstIterator Begin() const
Definition gdcmScanner2.h:137
const char * GetFilenameFromPublicTagToValue(Tag const &t, const char *valueref) const
std::map< Tag, const char * > PublicTagToValue
Definition gdcmScanner2.h:68
static SmartPointer< Scanner2 > New()
for wrapped language: instantiate a reference counted object
Definition gdcmScanner2.h:177
std::map< PrivateTag, const char * > PrivateTagToValue
Definition gdcmScanner2.h:71
PrivateTagToValue const & GetMappingFromPrivateTagToValue(PrivateTag const &pt, const char *value) const
void ClearPrivateTags()
Directory::FilenamesType GetAllFilenamesFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const
Scanner2()
Definition gdcmScanner2.h:59
PrivateMappingType const & GetPrivateMappings() const
Definition gdcmScanner2.h:147
PublicTagToValue const & GetPublicMapping(const char *filename) const
Get the std::map mapping filenames to value for file 'filename'.
void Print(std::ostream &os) const override
Print result.
std::set< std::string > ValuesType
Definition gdcmScanner2.h:108
std::map< const char *, PublicTagToValue, ltstr > PublicMappingType
Definition gdcmScanner2.h:135
const char * GetFilenameFromPrivateTagToValue(PrivateTag const &pt, const char *valueref) const
void PrintTable(std::ostream &os, bool header=false) const
Print result as CSV table.
PublicTagToValue const & GetMappingFromPublicTagToValue(Tag const &t, const char *value) const
See GetFilenameFromTagToValue(). This is simply GetFilenameFromTagToValue followed.
PrivateTagToValue::value_type PrivateTagToValueValueType
Definition gdcmScanner2.h:72
Directory::FilenamesType GetPrivateOrderedValues(PrivateTag const &pt) const
void ClearSkipTags()
void ProcessPublicTag(StringFilter &sf, const char *filename)
PrivateConstIterator PrivateBegin() const
Definition gdcmScanner2.h:142
PublicMappingType const & GetPublicMappings() const
Mappings are the mapping from a particular tag to the map, mapping filename to value:
Definition gdcmScanner2.h:146
PrivateTagToValue const & GetPrivateMapping(const char *filename) const
const char * GetPublicValue(const char *filename, Tag const &t) const
PublicTagToValue::value_type PublicTagToValueValueType
Definition gdcmScanner2.h:69
ValuesType GetPublicValues(Tag const &t) const
Get all the values found (in lexicographic order) associated with Tag 't'.
bool IsKey(const char *filename) const
Directory::FilenamesType GetPublicOrderedValues(Tag const &t) const
PublicMappingType::const_iterator PublicConstIterator
Definition gdcmScanner2.h:136
bool AddPublicTag(Tag const &t)
Add a tag that will need to be read. Those are root level tags.
void ProcessPrivateTag(StringFilter &sf, const char *filename)
PrivateConstIterator PrivateEnd() const
Definition gdcmScanner2.h:143
void ClearPublicTags()
Directory::FilenamesType GetAllFilenamesFromPublicTagToValue(Tag const &t, const char *valueref) const
~Scanner2() override
ValuesType const & GetValues() const
Get all the values found (in lexicographic order)
Definition gdcmScanner2.h:111
bool AddSkipTag(Tag const &t)
Add a tag that will need to be skipped. Those are root level skip tags.
ValuesType GetPrivateValues(PrivateTag const &pt) const
Get all the values found (in lexicographic order) associated with PrivateTag 'pt'.
Directory::FilenamesType GetKeys() const
const char * GetPrivateValue(const char *filename, PrivateTag const &t) const
PrivateMappingType::const_iterator PrivateConstIterator
Definition gdcmScanner2.h:141
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
StringFilter.
Definition gdcmStringFilter.h:30
Subject.
Definition gdcmSubject.h:29
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
#define GDCM_EXPORT
Definition gdcmWin32.h:34
Definition gdcmASN1.h:21
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88
Definition gdcmScanner2.h:128
bool operator()(const char *s1, const char *s2) const
Definition gdcmScanner2.h:129