Salome HOME
Create insitu library.
[modules/paravis.git] / src / Plugins / JSONReader / ParaViewPlugin / vtkJSONReader.h
1 // Copyright (C) 2015-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author: Roman NIKOLAEV (roman.nikolaev@opencascade.com)
20
21 #ifndef __vtkJSONReader_h_
22 #define __vtkJSONReader_h_
23
24 #include "vtk_jsoncpp.h" // For json parser
25 #include "vtkTableAlgorithm.h"
26
27
28 //---------------------------------------------------
29 class VTK_EXPORT vtkJSONException : public std::exception {
30  public:
31     vtkJSONException(const char *reason);
32     ~vtkJSONException() throw ();
33     const char* what() const throw();
34  protected:
35   std::string Reason;
36 };
37
38 class vtkStringArray;
39
40 class VTK_EXPORT vtkJSONReader: public vtkTableAlgorithm
41 {
42 public:
43   static vtkJSONReader* New();
44   vtkTypeMacro(vtkJSONReader, vtkTableAlgorithm)
45   void PrintSelf(ostream& os, vtkIndent indent);
46
47   // Description:
48   // Specifies the name of the file
49   vtkGetStringMacro(FileName);
50   vtkSetStringMacro(FileName);
51
52
53   // Description:
54   // Request Data
55   virtual int RequestData(vtkInformation*, 
56                           vtkInformationVector**,
57                           vtkInformationVector*);
58
59 protected:
60   // Decription:
61   // Parse the Json Value corresponding to the root data from the file
62   virtual void Parse(Json::Value& root, vtkTable *theTable);
63
64   // Decription:
65   // Verify if file exists and can be read by the parser
66   // If exists, parse into Jsoncpp data structure
67   int CanParseFile(const char *fname, Json::Value &root);
68
69 protected:
70   vtkJSONReader();
71   ~vtkJSONReader();  
72   // name of the file to read from
73   char*            FileName;
74
75 private:
76   vtkJSONReader(const vtkJSONReader&); // Not implemented.
77   void operator=(const vtkJSONReader&); // Not implemented.
78 };
79
80 #endif //__vtkJSONReader_h_