GDCM: gdcmScanner.h Source File

GDCM 3.2.10

gdcmScanner.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 GDCMSCANNER_H
15#define GDCMSCANNER_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 Scanner : public Subject
56{
57 friend std::ostream& operator<<(std::ostream &_os, const Scanner &s);
58public:
59 Scanner():Values(),Filenames(),Mappings(),Progress(0.0) {}
60 ~Scanner() override;
61
68 typedef std::map<Tag, const char*> TagToValue;
69 //typedef std::map<Tag, ConstCharWrapper> TagToValue; //StringMap;
70 //typedef TagToStringMap TagToValue;
71 typedef TagToValue::value_type TagToValueValueType;
72
74 void AddTag( Tag const & t );
75 void ClearTags();
76
77 // Work in progress do not use:
78 void AddPrivateTag( PrivateTag const & t );
79
81 void AddSkipTag( Tag const & t );
82 void ClearSkipTags();
83
85 bool Scan( Directory::FilenamesType const & filenames );
86
87 Directory::FilenamesType const &GetFilenames() const { return Filenames; }
88
90 void Print( std::ostream & os ) const override;
91
92 void PrintTable( std::ostream & os ) const;
93
97 bool IsKey( const char * filename ) const;
98
101 Directory::FilenamesType GetKeys() const;
102
103 // struct to store all the values found:
104 typedef std::set< std::string > ValuesType;
105
107 ValuesType const & GetValues() const { return Values; }
108
110 ValuesType GetValues(Tag const &t) const;
111
115 Directory::FilenamesType GetOrderedValues(Tag const &t) const;
116
117 /* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
118 struct ltstr
119 {
120 bool operator()(const char* s1, const char* s2) const
121 {
122 gdcm_assert( s1 && s2 );
123 return strcmp(s1, s2) < 0;
124 }
125 };
126 typedef std::map<const char *,TagToValue, ltstr> MappingType;
127 typedef MappingType::const_iterator ConstIterator;
128 ConstIterator Begin() const { return Mappings.begin(); }
129 ConstIterator End() const { return Mappings.end(); }
130
132 MappingType const & GetMappings() const { return Mappings; }
133
135 TagToValue const & GetMapping(const char *filename) const;
136
139 const char *GetFilenameFromTagToValue(Tag const &t, const char *valueref) const;
140
143 Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const;
144
146 // by a call to GetMapping()
147 TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const;
148
154 const char* GetValue(const char *filename, Tag const &t) const;
155
157 static SmartPointer<Scanner> New() { return new Scanner; }
158
159protected:
160 void ProcessPublicTag(StringFilter &sf, const char *filename);
161private:
162 // struct to store all uniq tags in ascending order:
163 typedef std::set< Tag > TagsType;
164 typedef std::set< PrivateTag > PrivateTagsType;
165 std::set< Tag > Tags;
166 std::set< PrivateTag > PrivateTags;
167 std::set< Tag > SkipTags;
168 ValuesType Values;
169 Directory::FilenamesType Filenames;
170
171 // Main struct that will hold all mapping:
172 MappingType Mappings;
173
174 double Progress;
175};
176//-----------------------------------------------------------------------------
177 inline std::ostream& operator<<(std::ostream &os, const Scanner &s)
178{
179 s.Print( os );
180 return os;
181}
182
183#if defined(SWIGPYTHON) || defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPHP)
184/*
185 * HACK: I need this temp class to be able to manipulate a std::map from python,
186 * swig does not support wrapping of simple class like std::map...
187 */
188class SWIGTagToValue
189{
190public:
191 SWIGTagToValue(Scanner::TagToValue const &t2v):Internal(t2v),it(t2v.begin()) {}
192 const Scanner::TagToValueValueType& GetCurrent() const { return *it; }
193 const Tag& GetCurrentTag() const { return it->first; }
194 const char *GetCurrentValue() const { return it->second; }
195 void Start() { it = Internal.begin(); }
196 bool IsAtEnd() const { return it == Internal.end(); }
197 void Next() { ++it; }
198private:
199 const Scanner::TagToValue& Internal;
200 Scanner::TagToValue::const_iterator it;
201};
202#endif /* SWIG */
203
208
209} // end namespace gdcm
210
211#endif //GDCMSCANNER_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::Scanner::GetValues
ValuesType GetValues(Tag const &t) const
Get all the values found (in lexicographic order) associated with Tag 't'.
gdcm::Scanner::Print
void Print(std::ostream &os) const override
Print result.
gdcm::Scanner::ClearSkipTags
void ClearSkipTags()
gdcm::Scanner::GetMapping
TagToValue const & GetMapping(const char *filename) const
Get the std::map mapping filenames to value for file 'filename'.
gdcm::Scanner::TagToValue
std::map< Tag, const char * > TagToValue
Definition gdcmScanner.h:68
gdcm::Scanner::GetFilenameFromTagToValue
const char * GetFilenameFromTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner::AddSkipTag
void AddSkipTag(Tag const &t)
Add a tag that will need to be skipped. Those are root level skip tags.
gdcm::Scanner::ProcessPublicTag
void ProcessPublicTag(StringFilter &sf, const char *filename)
gdcm::Scanner::GetKeys
Directory::FilenamesType GetKeys() const
gdcm::Scanner::New
static SmartPointer< Scanner > New()
for wrapped language: instantiate a reference counted object
Definition gdcmScanner.h:157
gdcm::Scanner::~Scanner
~Scanner() override
gdcm::Scanner::PrintTable
void PrintTable(std::ostream &os) const
gdcm::Scanner::TagToValueValueType
TagToValue::value_type TagToValueValueType
Definition gdcmScanner.h:71
gdcm::Scanner::GetMappings
MappingType const & GetMappings() const
Mappings are the mapping from a particular tag to the map, mapping filename to value:
Definition gdcmScanner.h:132
gdcm::Scanner::GetMappingFromTagToValue
TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const
See GetFilenameFromTagToValue(). This is simply GetFilenameFromTagToValue followed.
gdcm::Scanner::IsKey
bool IsKey(const char *filename) const
gdcm::Scanner::Scanner
Scanner()
Definition gdcmScanner.h:59
gdcm::Scanner::Begin
ConstIterator Begin() const
Definition gdcmScanner.h:128
gdcm::Scanner::AddTag
void AddTag(Tag const &t)
Add a tag that will need to be read. Those are root level tags.
gdcm::Scanner::GetValue
const char * GetValue(const char *filename, Tag const &t) const
gdcm::Scanner::End
ConstIterator End() const
Definition gdcmScanner.h:129
gdcm::Scanner::ValuesType
std::set< std::string > ValuesType
Definition gdcmScanner.h:104
gdcm::Scanner::MappingType
std::map< const char *, TagToValue, ltstr > MappingType
Definition gdcmScanner.h:126
gdcm::Scanner::ConstIterator
MappingType::const_iterator ConstIterator
Definition gdcmScanner.h:127
gdcm::Scanner::GetFilenames
Directory::FilenamesType const & GetFilenames() const
Definition gdcmScanner.h:87
gdcm::Scanner::Scan
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
gdcm::Scanner::GetAllFilenamesFromTagToValue
Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner::GetValues
ValuesType const & GetValues() const
Get all the values found (in lexicographic order).
Definition gdcmScanner.h:107
gdcm::Scanner::AddPrivateTag
void AddPrivateTag(PrivateTag const &t)
gdcm::Scanner::operator<<
friend std::ostream & operator<<(std::ostream &_os, const Scanner &s)
Definition gdcmScanner.h:177
gdcm::Scanner::GetOrderedValues
Directory::FilenamesType GetOrderedValues(Tag const &t) const
gdcm::Scanner::ClearTags
void ClearTags()
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::Scanner::ltstr
Definition gdcmScanner.h:119
gdcm::Scanner::ltstr::operator()
bool operator()(const char *s1, const char *s2) const
Definition gdcmScanner.h:120