Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
YajlFacade.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 
22 #include <string>
23 
24 #include <tulip/tulipconf.h>
25 
26 namespace tlp {
27 class PluginProgress;
28 }
29 
30 struct yajl_gen_t;
31 
32 /**
33  * @brief A Simple C++ wrapper around the C library 'yajl' parsing capabilities.
34  *
35  * It uses callbacks to signal what is being parsed (map start and end, strings, ...), and this 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=NULL);
41 
42  virtual ~YajlParseFacade() {
43  }
44  /**
45  * @brief Parses a JSON file.
46  * Once this function is called, the callbacks (all the parse* functions) will get called when the corresponding event happens.
47  *
48  * @param filename The file to parse.
49  * @return void
50  **/
51  void parse(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(const std::string& value);
60  virtual void parseMapKey(const 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 
69 protected:
70  tlp::PluginProgress* _progress;
71  bool _parsingSucceeded;
72  std::string _errorMessage;
73 };
74 
75 class YajlWriteFacade {
76 public:
77  YajlWriteFacade();
78  ~YajlWriteFacade();
79 
80  std::string generatedString();
81 
82  void writeInteger(long long int number);
83  void writeDouble(double number);
84  void writeNumber(const char* str, size_t len);
85  void writeString(const std::string& text);
86  void writeNull();
87  void writeBool(bool value);
88  void writeMapOpen();
89  void writeMapClose();
90  void writeArrayOpen();
91  void writeArrayClose();
92 
93  void beautifyString(bool beautify);
94 
95 protected:
96  yajl_gen_t* _generator;
97 };
98 ///@endcond
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...