GDCM  2.0.18
gdcmScanner.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004 
00005   Copyright (c) 2006-2011 Mathieu Malaterre
00006   All rights reserved.
00007   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 #ifndef GDCMSCANNER_H
00015 #define GDCMSCANNER_H
00016 
00017 #include "gdcmDirectory.h"
00018 #include "gdcmSubject.h"
00019 #include "gdcmTag.h"
00020 #include "gdcmPrivateTag.h"
00021 #include "gdcmSmartPointer.h"
00022 
00023 #include <map>
00024 #include <set>
00025 #include <string>
00026 
00027 #include <string.h> // strcmp
00028 
00029 namespace gdcm
00030 {
00031 class StringFilter;
00032 
00055 class GDCM_EXPORT Scanner : public Subject
00056 {
00057   friend std::ostream& operator<<(std::ostream &_os, const Scanner &s);
00058 public:
00059   Scanner():Values(),Filenames(),Mappings() {}
00060   ~Scanner();
00061 
00068   typedef std::map<Tag, const char*> TagToValue;
00069   //typedef std::map<Tag, ConstCharWrapper> TagToValue; //StringMap;
00070   //typedef TagToStringMap TagToValue;
00071   typedef TagToValue::value_type TagToValueValueType;
00072 
00074   void AddTag( Tag const & t );
00075   void ClearTags();
00076 
00077   // Work in progress do not use:
00078   void AddPrivateTag( PrivateTag const & t );
00079 
00081   void AddSkipTag( Tag const & t );
00082   void ClearSkipTags();
00083 
00085   bool Scan( Directory::FilenamesType const & filenames );
00086 
00087   Directory::FilenamesType const &GetFilenames() const { return Filenames; }
00088 
00090   void Print( std::ostream & os ) const;
00091 
00095   bool IsKey( const char * filename ) const;
00096 
00099   Directory::FilenamesType GetKeys() const;
00100 
00101   // struct to store all the values found:
00102   typedef std::set< std::string > ValuesType;
00103 
00105   ValuesType const & GetValues() const { return Values; }
00106 
00108   ValuesType GetValues(Tag const &t) const;
00109 
00113   Directory::FilenamesType GetOrderedValues(Tag const &t) const;
00114 
00115   /* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
00116   struct ltstr
00117     {
00118     bool operator()(const char* s1, const char* s2) const
00119       {
00120       assert( s1 && s2 );
00121       return strcmp(s1, s2) < 0;
00122       }
00123     };
00124   typedef std::map<const char *,TagToValue, ltstr> MappingType;
00125   typedef MappingType::const_iterator ConstIterator;
00126   ConstIterator Begin() const { return Mappings.begin(); }
00127   ConstIterator End() const { return Mappings.end(); }
00128 
00130   MappingType const & GetMappings() const { return Mappings; }
00131 
00133   TagToValue const & GetMapping(const char *filename) const;
00134 
00137   const char *GetFilenameFromTagToValue(Tag const &t, const char *valueref) const;
00138 
00141   Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const;
00142 
00144   // by a call to GetMapping()
00145   TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const;
00146 
00152   const char* GetValue(const char *filename, Tag const &t) const;
00153 
00155   static SmartPointer<Scanner> New() { return new Scanner; }
00156 
00157 protected:
00158   void ProcessPublicTag(StringFilter &sf, const char *filename);
00159 private:
00160   // struct to store all uniq tags in ascending order:
00161   typedef std::set< Tag > TagsType;
00162   typedef std::set< PrivateTag > PrivateTagsType;
00163   std::set< Tag > Tags;
00164   std::set< PrivateTag > PrivateTags;
00165   std::set< Tag > SkipTags;
00166   ValuesType Values;
00167   Directory::FilenamesType Filenames;
00168 
00169   // Main struct that will hold all mapping:
00170   MappingType Mappings;
00171 
00172   double Progress;
00173 };
00174 //-----------------------------------------------------------------------------
00175 inline std::ostream& operator<<(std::ostream &os, const Scanner &s)
00176 {
00177   s.Print( os );
00178   return os;
00179 }
00180 
00181 #if defined(SWIGPYTHON) || defined(SWIGCSHARP) || defined(SWIGJAVA)
00182 /*
00183  * HACK: I need this temp class to be able to manipulate a std::map from python,
00184  * swig does not support wrapping of simple class like std::map...
00185  */
00186 class SWIGTagToValue
00187 {
00188 public:
00189   SWIGTagToValue(Scanner::TagToValue const &t2v):Internal(t2v),it(t2v.begin()) {}
00190   const Scanner::TagToValueValueType& GetCurrent() const { return *it; }
00191   const Tag& GetCurrentTag() const { return it->first; }
00192   const char *GetCurrentValue() const { return it->second; }
00193   void Start() { it = Internal.begin(); }
00194   bool IsAtEnd() const { return it == Internal.end(); }
00195   void Next() { ++it; }
00196 private:
00197   const Scanner::TagToValue& Internal;
00198   Scanner::TagToValue::const_iterator it;
00199 };
00200 #endif /* SWIG */
00201 
00207 } // end namespace gdcm
00208 
00209 #endif //GDCMSCANNER_H

Generated on Tue Dec 6 2011 20:36:27 for GDCM by doxygen 1.7.5.1
SourceForge.net Logo