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-2009 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 "gdcmTag.h"
00020 
00021 #include <map>
00022 #include <set>
00023 #include <string>
00024 
00025 #include <string.h> // strcmp
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   //typedef std::map<Tag, ConstCharWrapper> TagToValue; //StringMap;
00054   //typedef TagToStringMap TagToValue;
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   // struct to store all the values found:
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   /* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
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   // by a call to GetMapping()
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   // struct to store all uniq tags in ascending order:
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   // Main struct that will hold all mapping:
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  * HACK: I need this temp class to be able to manipulate a std::map from python,
00148  * swig does not support wrapping of simple class like std::map...
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 /* SWIG */
00165 
00171 } // end namespace gdcm
00172 
00173 #endif //__gdcmScanner_h

Generated on Thu Jul 1 06:40:26 2010 for GDCM by doxygen 1.6.3
SourceForge.net Logo