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 
13 #include "MLMLToDicomToolsSystem.h"
14 #include <mlModuleIncludes.h>
15 
16 ML_START_NAMESPACE
17 
19 namespace TextStringParserTools {
20 
22  extern ML_MLToDicomTools_EXPORT const char * const CacheLineSep;
23 
27  ML_MLToDicomTools_EXPORT std::string toPagedImgStr(const PagedImage &imgProps,
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 
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 
146  PagedImage &imgProps,
147  size_t &readPos);
149 };
150 
151 ML_END_NAMESPACE
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...
Definition: mlPagedImage.h:70
#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:1081
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition: mlTypeDefs.h:826
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
double MLdouble
Definition: mlTypeDefs.h:223
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
boost::graph_traits< ml_graph_ptr >::vertex_descriptor source(graph_traits< ml_graph_ptr >::edge_descriptor e, const ml_graph_ptr)
Returns the vertex descriptor for u of the edge (u,v) represented by e.
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 toPagedImgStr(const PagedImage &imgProps, const std::string &lineEndStr)
Converts a PagedImage property description to a std::string and returns it.
ML_MLToDicomTools_EXPORT MLErrorCode extractLine(const std::string &srcStr, const std::string &parseFormatStr, MLdouble &val0, MLdouble &val1, MLdouble &val2, MLdouble &val3, size_t &readPos)
Extracts one line starting at readPos, reads parseFormatStr and writes it into val[0-3]; readPos is i...
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...