MeVisLab Toolbox Reference
mlTextStringParserTools.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//----------------------------------------------------------------------------------
5
10//----------------------------------------------------------------------------------
11#pragma once
12
14#include <mlModuleIncludes.h>
15
16ML_START_NAMESPACE
17
19namespace TextStringParserTools {
20
22 extern ML_MLToDicomTools_EXPORT const char * const CacheLineSep;
23
28 const std::string &lineEndStr);
29
36 ML_MLToDicomTools_EXPORT std::string extractLine(const std::string &source,
37 MLErrorCode &err,
38 size_t &readPos);
39
44 const std::string &parseFormatStr,
45 std::string &targetVal,
46 size_t &readPos);
47
50 const std::string &parseFormatStr,
51 int &targetVal,
52 size_t &readPos);
53
56 const std::string &parseFormatStr,
57 MLint &targetVal,
58 size_t &readPos);
59
62 const std::string &parseFormatStr,
63 MLuint64 &targetVal,
64 size_t &readPos);
65
71 const std::string &parseFormatStr,
72 MLdouble &val,
73 size_t &readPos);
74
80 const std::string &parseFormatStr,
81 MLdouble &val0,
82 MLdouble &val1,
83 MLdouble &val2,
84 MLdouble &val3,
85 size_t &readPos);
86
91 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
92 MLErrorCode extractLine6T(const std::string &srcStr,
93 const std::string &parseFormatStr,
94 T1 &val0,
95 T2 &val1,
96 T3 &val2,
97 T4 &val3,
98 T5 &val4,
99 T6 &val5,
100 int NUM_ELEMS,
101 size_t &readPos)
102 {
104 std::string workLine = extractLine(srcStr, err, readPos);
105 int numScans = -1;
106 if (ML_RESULT_OK == err) {
107
108// Disable warnings about nonliteral string formats, because the following routines calculate the formats.
109#if defined(__GNUC__)
110 #pragma GCC diagnostic push
111 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
112#endif
113#ifdef _MSC_VER
114 #pragma warning( push )
115 // Corresponding windows warning for the upper one on gcc.
116 #pragma warning( disable : 4774)
117#endif
118
119 numScans = sscanf(workLine.c_str(), parseFormatStr.c_str(),
120 &val0, &val1, &val2, &val3, &val4, &val5);
121#ifdef _MSC_VER
122 #pragma warning( pop )
123#endif
124#if defined(__GNUC__)
125 #pragma GCC diagnostic pop
126#endif
127 }
128
129 if ((ML_RESULT_OK != err) || (numScans != NUM_ELEMS)) {
131 }
132 return err;
133 }
134
144 const std::string &introStr,
145 size_t chunkSize,
146 std::string &readStr,
147 size_t &readPos);
148
153 PagedImage &imgProps,
154 size_t &readPos);
156};
157
158ML_END_NAMESPACE
Project global and OS specific declarations.
#define ML_MLToDicomTools_EXPORT
Only for diagnostic purposes.
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
#define ML_FILE_OR_DATA_STRUCTURE_CORRUPTED
The content of a file or another data structure is not organized as expected by the program.
Definition mlTypeDefs.h:978
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:715
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:723
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
double MLdouble
Definition mlTypeDefs.h:216
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
ML_MLToDicomTools_EXPORT const char *const CacheLineSep
Separator between cache file lines. Has a terminator at the line end for simple line end detection.
ML_MLToDicomTools_EXPORT std::string extractLine(const std::string &source, MLErrorCode &err, size_t &readPos)
Extraction from std::string.
ML_MLToDicomTools_EXPORT std::string toPagedImgStr(const PagedImage &imgProps, const std::string &lineEndStr)
Converts a PagedImage property description to a std::string and returns it.
MLErrorCode extractLine6T(const std::string &srcStr, const std::string &parseFormatStr, T1 &val0, T2 &val1, T3 &val2, T4 &val3, T5 &val4, T6 &val5, int NUM_ELEMS, size_t &readPos)
Extracts one line starting at readPos, reads parseFormatStr and writes it into val[0-5]; readPos is i...
ML_MLToDicomTools_EXPORT MLErrorCode extractStringChunk(const std::string &srcStr, const std::string &introStr, size_t chunkSize, std::string &readStr, size_t &readPos)
Expects introString at position readPos in srcStr, then a string of size chunkSize and a terminating ...
ML_MLToDicomTools_EXPORT MLErrorCode extractPagedImgPropsFromString(const std::string &srcStr, PagedImage &imgProps, size_t &readPos)
Reads one line starting at readPos, sets imgProps from read data and increments readPos to position a...