gdcmScanner.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __gdcmScanner_h
00016 #define __gdcmScanner_h
00017
00018 #include "gdcmDirectory.h"
00019 #include "gdcmTag.h"
00020
00021 #include <map>
00022 #include <set>
00023 #include <string>
00024
00025 #include <string.h>
00026
00027 namespace gdcm
00028 {
00039 class GDCM_EXPORT Scanner
00040 {
00041 friend std::ostream& operator<<(std::ostream &_os, const Scanner &s);
00042 public:
00043 Scanner():Values(),Filenames(),Mappings() {}
00044 ~Scanner();
00045
00052 typedef std::map<Tag, const char*> TagToValue;
00053
00054
00055 typedef TagToValue::value_type TagToValueValueType;
00056
00058 void AddTag( Tag const & t );
00059 void ClearTags();
00060
00062 void AddSkipTag( Tag const & t );
00063 void ClearSkipTags();
00064
00066 bool Scan( Directory::FilenamesType const & filenames );
00067
00068 Directory::FilenamesType const &GetFilenames() const { return Filenames; }
00069
00071 void Print( std::ostream & os ) const;
00072
00076 bool IsKey( const char * filename ) const;
00077
00080 Directory::FilenamesType GetKeys() const;
00081
00082
00083 typedef std::set< std::string > ValuesType;
00084
00086 ValuesType const & GetValues() const { return Values; }
00087
00089 ValuesType GetValues(Tag const &t) const;
00090
00091
00092 struct ltstr
00093 {
00094 bool operator()(const char* s1, const char* s2) const
00095 {
00096 return strcmp(s1, s2) < 0;
00097 }
00098 };
00099 typedef std::map<const char *,TagToValue, ltstr> MappingType;
00100 typedef MappingType::const_iterator ConstIterator;
00101 ConstIterator Begin() const { return Mappings.begin(); }
00102 ConstIterator End() const { return Mappings.end(); }
00103
00105 MappingType const & GetMappings() const { return Mappings; }
00106
00108 TagToValue const & GetMapping(const char *filename) const;
00109
00112 const char *GetFilenameFromTagToValue(Tag const &t, const char *valueref) const;
00113
00115
00116 TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const;
00117
00123 const char* GetValue(const char *filename, Tag const &t) const;
00124
00125 private:
00126
00127 typedef std::set< Tag > TagsType;
00128 std::set< Tag > Tags;
00129 std::set< Tag > SkipTags;
00130 ValuesType Values;
00131 Directory::FilenamesType Filenames;
00132
00133
00134 MappingType Mappings;
00135
00136 double Progress;
00137 };
00138
00139 inline std::ostream& operator<<(std::ostream &os, const Scanner &s)
00140 {
00141 s.Print( os );
00142 return os;
00143 }
00144
00145 #if defined(SWIGPYTHON) || defined(SWIGCSHARP) || defined(SWIGJAVA)
00146
00147
00148
00149
00150 class SWIGTagToValue
00151 {
00152 public:
00153 SWIGTagToValue(Scanner::TagToValue const &t2v):Internal(t2v),it(t2v.begin()) {}
00154 const Scanner::TagToValueValueType& GetCurrent() const { return *it; }
00155 const Tag& GetCurrentTag() const { return it->first; }
00156 const char *GetCurrentValue() const { return it->second; }
00157 void Start() { it = Internal.begin(); }
00158 bool IsAtEnd() const { return it == Internal.end(); }
00159 void Next() { ++it; }
00160 private:
00161 const Scanner::TagToValue& Internal;
00162 Scanner::TagToValue::const_iterator it;
00163 };
00164 #endif
00165
00171 }
00172
00173 #endif //__gdcmScanner_h