FEDEM Solver  R8.0
Source code of the dynamics solver
FFaTokenizer.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_TOKENIZER_H
14 #define FFA_TOKENIZER_H
15 
16 #include <vector>
17 #include <string>
18 #include <cstdio>
19 #include <iostream>
20 
21 class FFaTokenInput;
22 
23 
31 class FFaTokenizer : public std::vector<std::string>
32 {
33 public:
38  FFaTokenizer(char entryBegin, char entryEnd, char separator = ',')
39  : eb(entryBegin), ee(entryEnd), ts(separator), iAmStrippingQuotes(true) {}
40 
47  FFaTokenizer(FILE* tokenFile, char entryBegin, char entryEnd,
48  char separator = ',', bool sq = true)
49  : eb(entryBegin), ee(entryEnd), ts(separator), iAmStrippingQuotes(sq)
50  {
51  this->createTokens(tokenFile);
52  }
53 
60  FFaTokenizer(std::istream& tokenStream, char entryBegin, char entryEnd,
61  char separator = ',', bool sq = true)
62  : eb(entryBegin), ee(entryEnd), ts(separator), iAmStrippingQuotes(sq)
63  {
64  this->createTokens(tokenStream);
65  }
66 
73  FFaTokenizer(const std::string& tokenString, char entryBegin, char entryEnd,
74  char separator = ',', bool sq = true)
75  : eb(entryBegin), ee(entryEnd), ts(separator), iAmStrippingQuotes(sq)
76  {
77  this->createTokens(tokenString.begin(), tokenString.end());
78  }
79 
81  virtual ~FFaTokenizer() {}
82 
84  std::string::const_iterator createTokens(std::string::const_iterator tBegin,
85  std::string::const_iterator tEnd);
86 
87 protected:
89  void createTokens(FILE* tokenFile);
91  void createTokens(std::istream& tokenStream);
93  int createTokens(FFaTokenInput& tokenData);
94 
95 private:
96  char eb;
97  char ee;
98  char ts;
99 
101 };
102 
103 #endif
Base class for generic token input.
Definition: FFaTokenizer.C:23
Class creating a one-level token hierarchy.
Definition: FFaTokenizer.H:32
FFaTokenizer(FILE *tokenFile, char entryBegin, char entryEnd, char separator=',', bool sq=true)
Constructor parsing the tokens from a file.
Definition: FFaTokenizer.H:47
std::string::const_iterator createTokens(std::string::const_iterator tBegin, std::string::const_iterator tEnd)
Creates tokens from a string range.
Definition: FFaTokenizer.C:124
char ts
Token separator.
Definition: FFaTokenizer.H:98
char ee
End character.
Definition: FFaTokenizer.H:97
char eb
Start character.
Definition: FFaTokenizer.H:96
FFaTokenizer(char entryBegin, char entryEnd, char separator=',')
The constructor defines the start, stop and separator characters.
Definition: FFaTokenizer.H:38
FFaTokenizer(std::istream &tokenStream, char entryBegin, char entryEnd, char separator=',', bool sq=true)
Constructor parsing the tokens from an input stream.
Definition: FFaTokenizer.H:60
FFaTokenizer(const std::string &tokenString, char entryBegin, char entryEnd, char separator=',', bool sq=true)
Constructor parsing the tokens from a string.
Definition: FFaTokenizer.H:73
virtual ~FFaTokenizer()
Empty destructor.
Definition: FFaTokenizer.H:81
bool iAmStrippingQuotes
If true, strip "-characters from tokens.
Definition: FFaTokenizer.H:100