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
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,
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,
58 size_t &readPos);
59
62 const std::string &parseFormatStr,
64 size_t &readPos);
65
71 const std::string &parseFormatStr,
72 MLdouble &val,
73 size_t &readPos);
74
80 const std::string &parseFormatStr,
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
114 numScans = sscanf(workLine.c_str(), parseFormatStr.c_str(),
115 &val0, &val1, &val2, &val3, &val4, &val5);
116
117#if defined(__GNUC__)
118#pragma GCC diagnostic pop
119#endif
120 }
121
122 if ((ML_RESULT_OK != err) || (numScans != NUM_ELEMS)) {
124 }
125 return err;
126 }
127
137 const std::string &introStr,
138 size_t chunkSize,
139 std::string &readStr,
140 size_t &readPos);
141
147 size_t &readPos);
149};
150
Project global and OS specific declarations.
#define ML_MLToDicomTools_EXPORT
Only for diagnostic purposes.
Class which represents an image, which manages properties of an image and image data which is located...
#define ML_FILE_OR_DATA_STRUCTURE_CORRUPTED
The content of a file or another data structure is not organized as expected by the program; this may...
Definition mlTypeDefs.h:979
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:724
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition mlTypeDefs.h:425
double MLdouble
Definition mlTypeDefs.h:217
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
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...