Tulip  6.0.0
Large graphs analysis and drawing
YajlFacade.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #include <string>
22 
23 #include <tulip/tulipconf.h>
24 
25 namespace tlp {
26 class PluginProgress;
27 }
28 
29 struct yajl_gen_t;
30 
31 /**
32  * @brief A Simple C++ wrapper around the C library 'yajl' parsing capabilities.
33  *
34  * It uses callbacks to signal what is being parsed (map start and end, strings, ...), and this
35  *class is intended to be subclassed,
36  * with the subclass overriding the callbacks to process the events.
37  **/
38 class TLP_SCOPE YajlParseFacade {
39 public:
40  YajlParseFacade(tlp::PluginProgress *progress = nullptr);
41 
42  virtual ~YajlParseFacade() {}
43  /**
44  * @brief Parses a JSON file.
45  * Once this function is called, the callbacks (all the parse* functions) will get called when the
46  *corresponding event happens.
47  *
48  * @param filename The file to parse.
49  * @return void
50  **/
51  void parse(const std::string &filename);
52  void parse(const unsigned char *data, int length);
53 
54  virtual void parseNull();
55  virtual void parseBoolean(bool boolVal);
56  virtual void parseInteger(long long integerVal);
57  virtual void parseDouble(double doubleVal);
58  virtual void parseNumber(const char *numberVal, size_t numberLen);
59  virtual void parseString(std::string &value);
60  virtual void parseMapKey(std::string &value);
61  virtual void parseStartMap();
62  virtual void parseEndMap();
63  virtual void parseStartArray();
64  virtual void parseEndArray();
65 
66  bool parsingSucceeded() const;
67  std::string errorMessage() const;
68  static std::string yajlVersion();
69 
70 protected:
71  tlp::PluginProgress *_progress;
72  bool _parsingSucceeded;
73  std::string _errorMessage;
74 };
75 
76 class YajlWriteFacade {
77 public:
78  YajlWriteFacade();
79  ~YajlWriteFacade();
80 
81  std::string generatedString();
82 
83  void writeInteger(long long int number);
84  void writeDouble(double number);
85  void writeNumber(const char *str, size_t len);
86  void writeString(const std::string &text);
87  void writeNull();
88  void writeBool(bool value);
89  void writeMapOpen();
90  void writeMapClose();
91  void writeArrayOpen();
92  void writeArrayClose();
93 
94  void beautifyString(bool beautify);
95 
96 protected:
97  yajl_gen_t *_generator;
98 };
99 ///@endcond
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...