GDCM  2.2.0
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 
29 namespace gdcm
30 {
31 class StringFilter;
32 
55 class GDCM_EXPORT Scanner : public Subject
56 {
57  friend std::ostream& operator<<(std::ostream &_os, const Scanner &s);
58 public:
59  Scanner():Values(),Filenames(),Mappings() {}
60  ~Scanner();
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;
91 
95  bool IsKey( const char * filename ) const;
96 
99  Directory::FilenamesType GetKeys() const;
100 
101  // struct to store all the values found:
102  typedef std::set< std::string > ValuesType;
103 
105  ValuesType const & GetValues() const { return Values; }
106 
108  ValuesType GetValues(Tag const &t) const;
109 
113  Directory::FilenamesType GetOrderedValues(Tag const &t) const;
114 
115  /* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
116  struct ltstr
117  {
118  bool operator()(const char* s1, const char* s2) const
119  {
120  assert( s1 && s2 );
121  return strcmp(s1, s2) < 0;
122  }
123  };
124  typedef std::map<const char *,TagToValue, ltstr> MappingType;
125  typedef MappingType::const_iterator ConstIterator;
126  ConstIterator Begin() const { return Mappings.begin(); }
127  ConstIterator End() const { return Mappings.end(); }
128 
130  MappingType const & GetMappings() const { return Mappings; }
131 
133  TagToValue const & GetMapping(const char *filename) const;
134 
137  const char *GetFilenameFromTagToValue(Tag const &t, const char *valueref) const;
138 
141  Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const;
142 
144  // by a call to GetMapping()
145  TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const;
146 
152  const char* GetValue(const char *filename, Tag const &t) const;
153 
155  static SmartPointer<Scanner> New() { return new Scanner; }
156 
157 protected:
158  void ProcessPublicTag(StringFilter &sf, const char *filename);
159 private:
160  // struct to store all uniq tags in ascending order:
161  typedef std::set< Tag > TagsType;
162  typedef std::set< PrivateTag > PrivateTagsType;
163  std::set< Tag > Tags;
164  std::set< PrivateTag > PrivateTags;
165  std::set< Tag > SkipTags;
166  ValuesType Values;
167  Directory::FilenamesType Filenames;
168 
169  // Main struct that will hold all mapping:
170  MappingType Mappings;
171 
172  double Progress;
173 };
174 //-----------------------------------------------------------------------------
175 inline std::ostream& operator<<(std::ostream &os, const Scanner &s)
176 {
177  s.Print( os );
178  return os;
179 }
180 
181 #if defined(SWIGPYTHON) || defined(SWIGCSHARP) || defined(SWIGJAVA)
182 /*
183  * HACK: I need this temp class to be able to manipulate a std::map from python,
184  * swig does not support wrapping of simple class like std::map...
185  */
186 class SWIGTagToValue
187 {
188 public:
189  SWIGTagToValue(Scanner::TagToValue const &t2v):Internal(t2v),it(t2v.begin()) {}
190  const Scanner::TagToValueValueType& GetCurrent() const { return *it; }
191  const Tag& GetCurrentTag() const { return it->first; }
192  const char *GetCurrentValue() const { return it->second; }
193  void Start() { it = Internal.begin(); }
194  bool IsAtEnd() const { return it == Internal.end(); }
195  void Next() { ++it; }
196 private:
197  const Scanner::TagToValue& Internal;
198  Scanner::TagToValue::const_iterator it;
199 };
200 #endif /* SWIG */
201 
207 } // end namespace gdcm
208 
209 #endif //GDCMSCANNER_H

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo