1 // Copyright (C) 2015-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author: Roman NIKOLAEV (roman.nikolaev@opencascade.com)
21 #ifndef __vtkJSONParser_h_
22 #define __vtkJSONParser_h_
28 #include <vtkObject.h>
32 class vtkJSONMetaNode;
33 class vtkJSONInfoNode;
35 //---------------------------------------------------
36 class VTK_EXPORT vtkJSONException : public std::exception
39 vtkJSONException(const char* reason);
40 ~vtkJSONException() noexcept;
41 const char* what() const noexcept;
47 class VTK_EXPORT vtkJSONParser : public vtkObject
50 static vtkJSONParser* New();
53 // Specifies the name of the file
54 vtkGetStringMacro(FileName);
55 vtkSetStringMacro(FileName);
57 virtual int Parse(vtkTable* theTable);
60 // Struct to store cursor information
61 //----------------------------------
82 // name of the file to read from
83 //----------------------------------
86 // current line and column
87 //----------------------------------
92 //----------------------------------
93 std::vector<Info> CInfoVector;
96 //----------------------------------
100 //----------------------------------
101 std::vector<vtkJSONNode*> Nodes;
102 vtkJSONNode* CurrentNode;
103 vtkJSONMetaNode* MetaNode;
106 //----------------------------------
107 std::vector<char> ExpectedCharacters;
110 //----------------------------------
113 bool ParseObjectList;
114 bool ShortNamesFilled;
116 // Last parced string
117 //----------------------------------
119 std::vector<const char*> Strings;
120 std::vector<const char*> CurrentList;
121 std::vector<const char*> ShortNames;
123 // Last parced values
124 //----------------------------------
128 vtkJSONParser(const vtkJSONParser&) = delete;
129 void operator=(const vtkJSONParser&) = delete;
131 vtkJSONMetaNode* GetMetaNode();
132 vtkJSONInfoNode* GetInfoNode();
148 void processCharacter(const char ch);
150 void processMetaNode();
151 void processInfoNode();
153 void readDoubleValue();
155 char* getString(long b, long e);
159 bool isDigitsAllowed();
161 void checkShortName(const char* unit);
163 void finalize(vtkTable* t);
167 void throwSimpleException(const char* message);
169 void throwException(const char* message);
171 void throwException(const char* message, int ln, int cn);
173 void throwException(const char* message, int ln);
175 #endif //__vtkJSONParser_h_