MeVisLab Toolbox Reference
mlDICOMCachedIOFileHandle.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//----------------------------------------------------------------------------------
6
11//----------------------------------------------------------------------------------
12
13#pragma once
14
18
19#include <mlUtilsSystemC.h>
20#include <mlFileSystem.h>
21#include <FMEThirdPartyWarningsDisable.h>
22#include <string>
23#include <vector>
24#include <FMEThirdPartyWarningsRestore.h>
25
27
28//----------------------------------------------------------------------------------
39//----------------------------------------------------------------------------------
40template<typename CT>
42public std::basic_string<CT>
43{
44
45public:
48
50 inline DICOMCachedIOFileHandleBase(const std::basic_string<CT>& str)
51 {
52 (*this).erase();
53 (*this).assign(str);
54 }
55
59 inline bool isMultiFrameHandle() const
60 {
61 // Do emptiness check and check für "*" to speed up the check in normal cases.
62 return !this->empty() && ((*this)[0] == '*') && (_getMLintFrameIndex() >= 0);
63 }
64
70 inline bool fileExists(bool allowEmpty) const
71 {
72 if (this->empty() && allowEmpty) {
73 return true;
74 }
75 return MLFileExists((this->isMultiFrameHandle() ? getOriginalFrameHandle() : *this).c_str()) != 0;
76 }
77
83 {
85
86 // Extract original handle if it is a multi-frame handle.
87 if (_getMLintFrameIndex() >= 0){
88 retHandle = this->substr(1, this->find('#') - 1);
89 }
90 return retHandle;
91 }
92
98 inline unsigned int getFrameIndex() const
99 {
100 const MLint index = _getMLintFrameIndex();
102 }
103
110 inline std::basic_string<CT> getFilename() const
111 {
112 std::basic_string<CT> filename = "";
113 if(!this->empty()) {
114 const DICOMCachedIOFileHandleProvider& fileHandleProvider = DICOMCachedIOFileHandleProvider::singleton();
115 const std::vector<DICOMCachedIOFileHandlePlugin *> &plugins = fileHandleProvider.getConstFileHandlePlugins();
116 std::vector<DICOMCachedIOFileHandlePlugin *>::const_iterator iter = plugins.begin(),endIt=plugins.end();
117 for( ; iter!=endIt; ++iter) {
118 if (*iter) {
119 filename = (*iter)->resolveFilename(*this);
120 if (!filename.empty()) {
121 break;
122 }
123 }
124 }
125 }
126 return filename;
127 }
128
129 private:
130
133 inline MLint _getMLintFrameIndex() const
134 {
135 // Extract original handle if it is a multi-frame handle.
136 MLint index = -1;
137 if (!this->empty() && ((*this)[0] == '*')){
138 const size_t hashPos = this->rfind('#');
139 if (hashPos != this->npos){
140 // Looks like a multi-frame handle, extract its index as string.
141 const std::string idxStr = this->substr(hashPos + 1);
142 if (1 != sscanf(idxStr.c_str(), "%lld", &index)) {
143 // We expect exactly one scanned argument so we failed if we
144 // reach here. Reset returned index to 0 in this case.
145 index = -1;
146 }
147 // Check for valid range.
148 if ((index < 0) || (index > ML_UINT32_MAX)){
149 index = -1;
150 }
151 }
152 }
153 return index;
154 }
155};
156
158typedef DICOMCachedIOFileHandleBase<char> DICOMCachedIOFileHandle;
159
Project global and OS specific declarations.
#define MLDICOMCachedIO_EXPORT
If included by external modules, exported symbols are declared as import symbols.
Forward template declaration for typedef'ing.
std::basic_string< CT > getFilename() const
Returns the resolved filename, returned by a registered DICOMCachedIOFileHandlePlugin or an empty str...
DICOMCachedIOFileHandleBase(const std::basic_string< CT > &str)
Copy constructor.
DICOMCachedIOFileHandleBase getOriginalFrameHandle() const
Returns the original file handle of a multi-frame handle; if the handle is no multi-frame handle then...
bool isMultiFrameHandle() const
Returns true if the handle is of the format "*" + fileHandlePathOrURL + "#<frameIdx>" with frameIndex...
bool fileExists(bool allowEmpty) const
Returns true if the file handle can be found as file on disk, otherwise false.
unsigned int getFrameIndex() const
Returns the unsigned index position of the referenced frame index if the handle is a multi-frame hand...
DICOMCachedIOFileHandleBase()
Default Constructor creating a handle with an empty string.
Class for FileHandleProvider for DICOM importing modules.
Header file for class resolving filenames from a given identifier (url,etc...) for DICOM importing mo...
Header file of class providing available DICOMCachedIOFileHandlePlugins which resolve filenames for D...
ML_UTILS_EXPORT int MLFileExists(const char *fileName)
Returns 1 if the given with name fileName exists, 0 otherwise or if fileName is NULL.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
#define ML_UINT32_MAX
Definition mlTypeDefs.h:191
DICOMCachedIOFileHandleBase< char > DICOMCachedIOFileHandle
"Forward" to DICOMCachedIOFileHandle.