Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXJSON.h
1 /********************************************************************************
2 * *
3 * J S O N R e a d e r & W r i t e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2013,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library 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. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXJSON_H
22 #define FXJSON_H
23 
24 namespace FX {
25 
26 
33 class FXAPI FXJSON {
34 public:
35  enum Error {
36  ErrOK,
46  ErrEnd
47  };
48  enum Flow {
49  Stream,
51  Pretty
52  };
53  enum Direction {
54  Stop = 0,
55  Save = 1,
56  Load = 2
57  };
58 protected:
59  FXchar *begptr; // Text buffer begin ptr
60  FXchar *endptr; // Text buffer end ptr
61  FXchar *sptr; // Text buffer start ptr
62  FXchar *rptr; // Text buffer read ptr
63  FXchar *wptr; // Text buffer write ptr
64  FXint token; // Token
65  FXint column; // Column number
66  FXint indent; // Indent level
67  FXint line; // Line number
68  FXint wrap; // Line wrap column
69  Direction dir; // Direction
70  FXuchar flow; // Output flow
71  FXuchar prec; // Float precision
72  FXuchar fmt; // Float format
73  FXuchar dent; // Indentation amount
74  FXbool owns; // Owns the buffer
75 private:
76  FXint next();
77  FXbool need(FXival n);
78  Error emit(const FXchar* str,FXint count);
79  Error emit(FXchar ch,FXint count);
80  Error loadString(FXString& str);
81  Error loadMap(FXVariant& var);
82  Error loadArray(FXVariant& var);
83  Error loadVariant(FXVariant& var);
84  Error saveString(const FXString& str);
85  Error saveMap(const FXVariant& var);
86  Error saveArray(const FXVariant& var);
87  Error saveVariant(const FXVariant& var);
88 private:
89  static const FXchar *const errors[];
90 private:
91  FXJSON(const FXJSON&){}
92  FXJSON &operator=(const FXJSON&);
93 public:
94 
98  FXJSON();
99 
104  FXJSON(FXchar* data,FXuval sz=4096,Direction d=Load);
105 
110  FXbool open(FXchar* data=NULL,FXuval size=4096,Direction d=Load);
111 
115  Direction direction() const { return dir; }
116 
120  FXuval size() const { return endptr-begptr; }
121 
126  Error load(FXVariant& variant);
127 
132  Error save(const FXVariant& variant);
133 
137  FXint getLine() const { return line; }
138 
142  FXint getColumn() const { return column; }
143 
145  static const FXchar* getError(Error err){ return errors[err]; }
146 
150  void setNumericPrecision(FXint p){ prec=p; }
151  FXint getNumericPrecision() const { return prec; }
152 
156  void setNumericFormat(FXint f){ fmt=f; }
157  FXint getNumericFormat() const { return fmt; }
158 
168  void setOutputFlow(FXint f){ flow=f; }
169  FXint getOutputFlow() const { return flow; }
170 
175  void setIndentation(FXint d){ dent=d; }
176  FXint getIndentation() const { return dent; }
177 
181  void setLineWrap(FXint w){ wrap=w; }
182  FXint getLineWrap() const { return wrap; }
183 
188  virtual FXbool fill();
189 
194  virtual FXbool flush();
195 
199  virtual FXbool close();
200 
204  virtual ~FXJSON();
205  };
206 
207 }
208 
209 #endif

Copyright © 1997-2016 Jeroen van der Zijp