GDCM 2.0.17

gdcmScanner.h

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

Generated on Wed Feb 2 2011 19:21:02 for GDCM by doxygen 1.7.3
SourceForge.net Logo