PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
PFileParser.h
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #ifndef __PFILE_PARSER_H__
8 #define __PFILE_PARSER_H__
9 
10 #include <iostream>
11 #include <vector>
12 #include <map>
13 
14 #include "PPath.h"
15 
16 #include "PParseSeqDef.h"
17 #include "PLocation.h"
18 
21  public:
22  PFileParser();
23  virtual ~PFileParser();
24 
25  bool open(const PPath & fileName);
26 
27  void setWhiteSpace(const PString & whiteSpace);
28  void setSeparator(const PString & separator);
29  void setFileContent(const PString & fileContent);
30  void setEscapeChar(char escapeChar);
31  void setLocation(const PLocation & location);
32  void setLine(size_t currentLine);
33  void setColumn(size_t currentCol);
34  bool isEndOfFile() const;
35 
36  void pushPosition();
37  void popPosition();
38  void clear();
39 
40  bool isChSpace() const;
41  bool isChSeparator() const;
42  char getEscapeChar() const;
43 
44  PPath getFileName() const;
46  PString getNextToken(PString & skippedStr);
47 
48  char getNextChar();
49 
50  PString getUntilKey(const PString & patern);
52  PString getUntilKeyWithoutPaternExclude(const PString & patern, const PString & strNotBeforeEndPatern);
53  PString getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern, const PString & allowedCharAfterBegin);
54  PString getUntilKeyWithoutPaternRecurseExclude(const PString & patern, const PString & beginPatern,
55  const PString & echapExpr);
56  PString getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern);
57  PString getStrComposedOf(const PString & charset);
58  PString getCurrentRow() const;
59 
60  bool isMatch(const PString & patern);
61  bool isMatchRewind(const PString & patern);
62  bool isMatchSeq(const PVecString & patern, bool alwaysPopBack = false);
63  bool isMatch(const PString & patern, const PString & forbiddenCharBefore);
64  bool isMatchToken(const PString & patern);
65  PString isMatch(const PVecString & patern);
66  PString isMatchToken(const PVecString & patern);
67 
68  template<typename T>
69  bool isMatchToken(PString & matchKey, T & matchValue, const std::map<PString, T> & patern);
70 
71  PString isMatch(const std::vector<PVecString > & patern);
72  PString isMatch(const PParseSeq & seq);
73 
74  bool isWhiteSpace();
75  void skipWhiteSpace();
76  void skipChars(const PString & chToSkip);
77  PString getWhiteSpace() const;
78  PString getSeparator() const;
79  char getCurrentCh() const;
80  char getPrevCh() const;
81  size_t getLine() const;
82  size_t getColumn() const;
83 
84  size_t getNbTotalChar() const;
85  size_t getCurrentCharIdx() const;
86  size_t getLineIndentation();
87 
88  PLocation getLocation() const;
89 
90  friend std::ostream & operator << (std::ostream & out, const PFileParser & other);
91 
92  private:
94  void incrementCurrentLine();
95  void incrementCurrentChar(size_t nbChar = 1lu);
115  std::vector<size_t> p_vecPosition;
117  std::vector<size_t> p_vecLine;
120 };
121 
122 #include "PFileParser_impl.h"
123 
124 #endif
std::vector< PString > PVecString
Definition: PString.h:96
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
Definition: PFileParser.cpp:43
size_t getLine() const
Fonction qui renvoie le numéro de la ligne courante.
PFileParser()
Constructeur de PFileParser.
Definition: PFileParser.cpp:11
std::vector< size_t > p_vecPosition
Vector of all the checkpoint positions in the text file (added with pushPosition() and removed with p...
Definition: PFileParser.h:115
virtual ~PFileParser()
Destructeur de PFileParser.
Definition: PFileParser.cpp:16
void skipChars(const PString &chToSkip)
Skip the characters in the given string.
bool isWhiteSpace()
Says if the current char is a white space.
bool isMatchSeq(const PVecString &patern, bool alwaysPopBack=false)
Match a sequence of token in a vector.
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
Definition: PFileParser.cpp:24
bool isChSpace() const
Dis si le caractère courant est un caractère blanc.
bool p_dontSkipSpace
Say if we don't want to skip the spaces.
Definition: PFileParser.h:119
PString getUntilKeyWithoutPaternExclude(const PString &patern, const PString &strNotBeforeEndPatern)
Parse a string until the patern is found, only if it has not strNotBeforeEndPatern before it.
PString getCurrentRow() const
Get the current parsed row.
size_t getColumn() const
Fonction qui renvoie le numéro de la colonne du caractère courant.
PString getNextToken()
Get the next token.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void incrementCurrentChar(size_t nbChar=1lu)
Increment the current caracter.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
Definition: PFileParser.cpp:58
void clear()
Clear the save position of the parser in ther current file.
PString getWhiteSpace() const
renvoie la liste des caractères blancs
PString getSeparator() const
renvoie la liste des caractères séparateurs
PString getUntilKeyWithoutPaternRecurse(const PString &patern, const PString &beginPatern, const PString &allowedCharAfterBegin)
Get the string until end sequence and take account recursive patern (embeded strings)
void setLine(size_t currentLine)
Set the current line of the PFileParser.
Definition: PFileParser.cpp:74
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
PString p_listSeparator
liste des séparateurs
Definition: PFileParser.h:111
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
Definition: PFileParser.cpp:35
bool isMatchRewind(const PString &patern)
Do a isMatch and then go back at the previous position.
std::vector< size_t > p_vecLine
Vector of all the checkpoint rows in the text file (added with pushPosition() and removed with popPos...
Definition: PFileParser.h:117
bool isMatchToken(const PString &patern)
Says if the patern match with the current caracters of the PFileParser but treats the string as a tok...
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
char getCurrentCh() const
Renvoie le caractère courant.
char p_echapChar
Echap caracter.
Definition: PFileParser.h:113
size_t getLineIndentation()
Get the current line indentation.
void popPosition()
Get to the last saved position of the PFileParser in the current file.
Definition: PFileParser.cpp:99
size_t p_nbTotalChar
Nombre de caractères total.
Definition: PFileParser.h:103
PPath p_fileName
Nom du fichier que l'on veut parser.
Definition: PFileParser.h:97
PString getUntilKey(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise.
void initialisationPFileParser()
Fonction d'initialisation du PFileParser.
void incrementCurrentLine()
Increment the current line.
PString p_fileContent
Contenu du fichier de configuration.
Definition: PFileParser.h:99
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.
PPath getFileName() const
Fonction qui renvoie le nom du fichier que l'on a ouvert.
bool isChSeparator() const
Dis si le caractère courant est un séparateur.
void setColumn(size_t currentCol)
Set the current column of the PFileParser.
Definition: PFileParser.cpp:81
size_t p_currentLineFirstColumn
Number of the first column caracter of the current line.
Definition: PFileParser.h:107
void setLocation(const PLocation &location)
Set the current location of the PFileParser.
Definition: PFileParser.cpp:65
PString p_listWhiteSpace
liste des espaces blancs
Definition: PFileParser.h:109
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.
friend std::ostream & operator<<(std::ostream &out, const PFileParser &other)
Définition de l'opérateur de flux sortant.
void setFileContent(const PString &fileContent)
Set the file content.
Definition: PFileParser.cpp:50
void pushPosition()
Remember the current position of the PFileParser in the current file.
Definition: PFileParser.cpp:93
size_t p_currentChar
Numéro du caractère courant.
Definition: PFileParser.h:101
size_t p_currentLine
Numéro de la ligne courante.
Definition: PFileParser.h:105
PString getUntilKeyWithoutPaternRecurseExclude(const PString &patern, const PString &beginPatern, const PString &echapExpr)
Get the string until end sequence and take account recursive patern (embeded strings)
char getPrevCh() const
Renvoie le caractère courant.
size_t getCurrentCharIdx() const
Return the index of the current character.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
char getEscapeChar() const
Gets the escape character of the PFileParser.
size_t getNbTotalChar() const
Return the number of characters in the current opened file.
char getNextChar()
Fonction qui renvoie le prochain caractère du fichier courant.
Classe qui permet de décrire une localisation, avec un nom de fichier et une ligne.
Definition: PLocation.h:15
Parsing sequence.
Definition: PParseSeq.h:77
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16