ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PdmsParser.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "PdmsTools.h"
11 
12 // system
13 #include <map>
14 #include <string>
15 
16 using namespace PdmsTools;
17 
19 
22 class PdmsLexer {
23 public:
24  PdmsLexer();
25  virtual ~PdmsLexer() {}
26 
27  virtual bool initializeSession();
28  bool gotoNextToken();
29  void finish() { stop = true; }
30  virtual void closeSession(bool destroyLoadedObject = false);
31 
32  PointCoordinateType valueFromBuffer();
33  const char *nameFromBuffer() const;
34 
35  virtual void printWarning(const char *str) = 0;
36 
37  Token getCurrentToken() const { return currentToken; }
38  PdmsObjects::GenericItem *getLoadedObject() const { return loadedObject; }
39  const char *getBufferContent() const { return tokenBuffer; }
40  void setLoadedObject(PdmsObjects::GenericItem *o) { loadedObject = o; }
41 
42 protected:
45  static const int c_max_buff_size = 2048;
46 
49  char tokenBuffer[c_max_buff_size];
50  char nextBuffer[c_max_buff_size];
51  std::map<std::string, Token> dictionary;
52  bool stop;
54 
55  void pushIntoDictionary(const char *str, Token token, int minSize = 0);
56  virtual void parseCurrentToken();
57  virtual void skipComment() = 0;
58  virtual void skipHandleCommand() = 0;
59  virtual bool moveForward();
60 };
61 
62 // Pdms file session
63 class PdmsFileSession : public PdmsLexer {
64 protected:
65  std::string m_filename;
67  bool m_eol;
68  bool m_eof;
69  FILE *m_file;
70 
71 public:
72  PdmsFileSession(const std::string &filename);
73  virtual ~PdmsFileSession() { closeSession(); }
74  virtual bool initializeSession() override;
75  virtual void closeSession(bool destroyLoadedObject = false) override;
76  virtual void printWarning(const char *str) override;
77 
78 protected:
79  virtual void parseCurrentToken() override;
80  virtual bool moveForward() override;
81  virtual void skipComment() override;
82  virtual void skipHandleCommand() override;
83 };
84 
85 // PDMS Parser
93 class PdmsParser {
94 public:
96  PdmsParser();
97  ~PdmsParser();
98 
99  void reset();
100  void linkWithSession(PdmsLexer *s);
101  bool parseSessionContent();
102  PdmsObjects::GenericItem *getLoadedObject(bool forgetIt = true);
103 
104 protected:
105  bool processCurrentToken();
106 
111 };
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
std::string filename
virtual ~PdmsFileSession()
Definition: PdmsParser.h:73
std::string m_filename
Definition: PdmsParser.h:65
PDMS Lexer.
Definition: PdmsParser.h:22
PdmsObjects::GenericItem * getLoadedObject() const
Definition: PdmsParser.h:38
bool stop
Definition: PdmsParser.h:52
const char * getBufferContent() const
Definition: PdmsParser.h:39
std::map< std::string, Token > dictionary
Definition: PdmsParser.h:51
char metaGroupMask
Definition: PdmsParser.h:53
virtual void skipHandleCommand()=0
virtual ~PdmsLexer()
Definition: PdmsParser.h:25
virtual void printWarning(const char *str)=0
void finish()
Definition: PdmsParser.h:29
PdmsObjects::GenericItem * loadedObject
Definition: PdmsParser.h:47
void setLoadedObject(PdmsObjects::GenericItem *o)
Definition: PdmsParser.h:40
Token getCurrentToken() const
Definition: PdmsParser.h:37
virtual void skipComment()=0
Token currentToken
Definition: PdmsParser.h:48
void reset()
PdmsLexer * session
Definition: PdmsParser.h:107
PdmsObjects::GenericItem * currentItem
Definition: PdmsParser.h:109
PdmsCommands::Command * currentCommand
Definition: PdmsParser.h:108
PdmsObjects::GenericItem * root
Definition: PdmsParser.h:110