gdcmScanner.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMSCANNER_H
#define GDCMSCANNER_H
#include "gdcmDirectory.h"
#include "gdcmSubject.h"
#include "gdcmTag.h"
#include "gdcmPrivateTag.h"
#include "gdcmSmartPointer.h"
#include <map>
#include <set>
#include <string>
#include <string.h> // strcmp
namespace gdcm
{
class StringFilter;
class GDCM_EXPORT Scanner : public Subject
{
friend std::ostream& operator<<(std::ostream &_os, const Scanner &s);
public:
Scanner():Values(),Filenames(),Mappings() {}
~Scanner() override;
typedef std::map<Tag, const char*> TagToValue;
//typedef std::map<Tag, ConstCharWrapper> TagToValue; //StringMap;
//typedef TagToStringMap TagToValue;
typedef TagToValue::value_type TagToValueValueType;
void AddTag( Tag const & t );
void ClearTags();
// Work in progress do not use:
void AddPrivateTag( PrivateTag const & t );
void AddSkipTag( Tag const & t );
void ClearSkipTags();
bool Scan( Directory::FilenamesType const & filenames );
Directory::FilenamesType const &GetFilenames() const { return Filenames; }
void Print( std::ostream & os ) const override;
void PrintTable( std::ostream & os ) const;
bool IsKey( const char * filename ) const;
Directory::FilenamesType GetKeys() const;
// struct to store all the values found:
typedef std::set< std::string > ValuesType;
ValuesType const & GetValues() const { return Values; }
ValuesType GetValues(Tag const &t) const;
Directory::FilenamesType GetOrderedValues(Tag const &t) const;
/* ltstr is CRITICAL, otherwise pointers value are used to do the key comparison */
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
assert( s1 && s2 );
return strcmp(s1, s2) < 0;
}
};
typedef std::map<const char *,TagToValue, ltstr> MappingType;
typedef MappingType::const_iterator ConstIterator;
ConstIterator Begin() const { return Mappings.begin(); }
ConstIterator End() const { return Mappings.end(); }
MappingType const & GetMappings() const { return Mappings; }
TagToValue const & GetMapping(const char *filename) const;
const char *GetFilenameFromTagToValue(Tag const &t, const char *valueref) const;
Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const;
// by a call to GetMapping()
TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const;
const char* GetValue(const char *filename, Tag const &t) const;
static SmartPointer<Scanner> New() { return new Scanner; }
protected:
void ProcessPublicTag(StringFilter &sf, const char *filename);
private:
// struct to store all uniq tags in ascending order:
typedef std::set< Tag > TagsType;
typedef std::set< PrivateTag > PrivateTagsType;
std::set< Tag > Tags;
std::set< PrivateTag > PrivateTags;
std::set< Tag > SkipTags;
ValuesType Values;
Directory::FilenamesType Filenames;
// Main struct that will hold all mapping:
MappingType Mappings;
double Progress;
};
//-----------------------------------------------------------------------------
inline std::ostream& operator<<(std::ostream &os, const Scanner &s)
{
s.Print( os );
return os;
}
#if defined(SWIGPYTHON) || defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPHP)
/*
* HACK: I need this temp class to be able to manipulate a std::map from python,
* swig does not support wrapping of simple class like std::map...
*/
class SWIGTagToValue
{
public:
SWIGTagToValue(Scanner::TagToValue const &t2v):Internal(t2v),it(t2v.begin()) {}
const Scanner::TagToValueValueType& GetCurrent() const { return *it; }
const Tag& GetCurrentTag() const { return it->first; }
const char *GetCurrentValue() const { return it->second; }
void Start() { it = Internal.begin(); }
bool IsAtEnd() const { return it == Internal.end(); }
void Next() { ++it; }
private:
const Scanner::TagToValue& Internal;
Scanner::TagToValue::const_iterator it;
};
#endif /* SWIG */
} // end namespace gdcm
#endif //GDCMSCANNER_H
gdcm::Directory::FilenamesType
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
gdcm::PrivateTag
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner).
Definition gdcmPrivateTag.h:39
gdcm::Scanner::GetValues
ValuesType GetValues(Tag const &t) const
Get all the values found (in lexicographic order) associated with Tag 't'.
gdcm::Scanner::Print
void Print(std::ostream &os) const override
Print result.
gdcm::Scanner::ClearSkipTags
void ClearSkipTags()
gdcm::Scanner::GetMapping
TagToValue const & GetMapping(const char *filename) const
Get the std::map mapping filenames to value for file 'filename'.
gdcm::Scanner::TagToValue
std::map< Tag, const char * > TagToValue
Definition gdcmScanner.h:68
gdcm::Scanner::GetFilenameFromTagToValue
const char * GetFilenameFromTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner::AddSkipTag
void AddSkipTag(Tag const &t)
Add a tag that will need to be skipped. Those are root level skip tags.
gdcm::Scanner::ProcessPublicTag
void ProcessPublicTag(StringFilter &sf, const char *filename)
gdcm::Scanner::GetKeys
Directory::FilenamesType GetKeys() const
gdcm::Scanner::New
static SmartPointer< Scanner > New()
for wrapped language: instantiate a reference counted object
Definition gdcmScanner.h:157
gdcm::Scanner::~Scanner
~Scanner() override
gdcm::Scanner::PrintTable
void PrintTable(std::ostream &os) const
gdcm::Scanner::TagToValueValueType
TagToValue::value_type TagToValueValueType
Definition gdcmScanner.h:71
gdcm::Scanner::GetMappings
MappingType const & GetMappings() const
Mappings are the mapping from a particular tag to the map, mapping filename to value:
Definition gdcmScanner.h:132
gdcm::Scanner::GetMappingFromTagToValue
TagToValue const & GetMappingFromTagToValue(Tag const &t, const char *value) const
See GetFilenameFromTagToValue(). This is simply GetFilenameFromTagToValue followed.
gdcm::Scanner::IsKey
bool IsKey(const char *filename) const
gdcm::Scanner::Scanner
Scanner()
Definition gdcmScanner.h:59
gdcm::Scanner::Begin
ConstIterator Begin() const
Definition gdcmScanner.h:128
gdcm::Scanner::AddTag
void AddTag(Tag const &t)
Add a tag that will need to be read. Those are root level tags.
gdcm::Scanner::GetValue
const char * GetValue(const char *filename, Tag const &t) const
gdcm::Scanner::End
ConstIterator End() const
Definition gdcmScanner.h:129
gdcm::Scanner::ValuesType
std::set< std::string > ValuesType
Definition gdcmScanner.h:104
gdcm::Scanner::MappingType
std::map< const char *, TagToValue, ltstr > MappingType
Definition gdcmScanner.h:126
gdcm::Scanner::ConstIterator
MappingType::const_iterator ConstIterator
Definition gdcmScanner.h:127
gdcm::Scanner::GetFilenames
Directory::FilenamesType const & GetFilenames() const
Definition gdcmScanner.h:87
gdcm::Scanner::Scan
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
gdcm::Scanner::GetAllFilenamesFromTagToValue
Directory::FilenamesType GetAllFilenamesFromTagToValue(Tag const &t, const char *valueref) const
gdcm::Scanner::GetValues
ValuesType const & GetValues() const
Get all the values found (in lexicographic order).
Definition gdcmScanner.h:107
gdcm::Scanner::AddPrivateTag
void AddPrivateTag(PrivateTag const &t)
gdcm::Scanner::operator<<
friend std::ostream & operator<<(std::ostream &_os, const Scanner &s)
Definition gdcmScanner.h:177
gdcm::Scanner::GetOrderedValues
Directory::FilenamesType GetOrderedValues(Tag const &t) const
gdcm::Scanner::ClearTags
void ClearTags()
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::StringFilter
StringFilter.
Definition gdcmStringFilter.h:30
gdcm::Subject::Subject
Subject()
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmDirectory.h
gdcmPrivateTag.h
gdcmSmartPointer.h
gdcmSubject.h
gdcmTag.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21
gdcm::operator<<
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88
gdcm::Scanner::ltstr
Definition gdcmScanner.h:119
gdcm::Scanner::ltstr::operator()
bool operator()(const char *s1, const char *s2) const
Definition gdcmScanner.h:120