JSON.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include "Text.h"
  3. #include "Array.h"
  4. namespace Framework
  5. {
  6. namespace JSON
  7. {
  8. enum JSONType
  9. {
  10. NULL_,
  11. BOOLEAN,
  12. NUMBER,
  13. STRING,
  14. ARRAY,
  15. OBJECT
  16. };
  17. class JSONArray;
  18. class JSONObject;
  19. class JSONValue
  20. {
  21. private:
  22. JSONType type;
  23. protected:
  24. __declspec( dllexport ) JSONValue( JSONType type );
  25. public:
  26. __declspec( dllexport ) JSONValue();
  27. __declspec( dllexport ) JSONType getType() const;
  28. __declspec( dllexport ) virtual Text toString() const;
  29. };
  30. class JSONBool : public JSONValue
  31. {
  32. private:
  33. bool b;
  34. public:
  35. __declspec( dllexport ) JSONBool( bool b );
  36. __declspec( dllexport ) bool getBool() const;
  37. __declspec( dllexport ) Text toString() const override;
  38. };
  39. class JSONNumber : public JSONValue
  40. {
  41. private:
  42. double number;
  43. public:
  44. __declspec( dllexport ) JSONNumber( double num );
  45. __declspec( dllexport ) double getNumber() const;
  46. __declspec( dllexport ) Text toString() const override;
  47. };
  48. class JSONString : public JSONValue
  49. {
  50. private:
  51. Text string;
  52. public:
  53. __declspec( dllexport ) JSONString( Text string );
  54. __declspec( dllexport ) Text getString() const;
  55. __declspec( dllexport ) Text toString() const override;
  56. };
  57. class JSONArray : public JSONValue
  58. {
  59. private:
  60. Array< JSONValue > *array;
  61. public:
  62. __declspec( dllexport ) JSONArray();
  63. __declspec( dllexport ) JSONArray( Text string );
  64. __declspec( dllexport ) JSONArray( const JSONArray &arr );
  65. __declspec( dllexport ) ~JSONArray();
  66. __declspec( dllexport ) JSONArray &operator=( const JSONArray &arr );
  67. __declspec( dllexport ) void addValue( JSONValue value );
  68. __declspec( dllexport ) JSONValue getValue( int i ) const;
  69. __declspec( dllexport ) int getLength() const;
  70. __declspec( dllexport ) Text toString() const override;
  71. };
  72. class JSONObject : public JSONValue
  73. {
  74. private:
  75. Array< Text > *fields;
  76. Array< JSONValue > *values;
  77. public:
  78. __declspec( dllexport ) JSONObject();
  79. __declspec( dllexport ) JSONObject( Text string );
  80. __declspec( dllexport ) JSONObject( const JSONObject &obj );
  81. __declspec( dllexport ) ~JSONObject();
  82. __declspec( dllexport ) JSONObject &operator=( const JSONObject &obj );
  83. __declspec( dllexport ) bool addValue( Text field, JSONValue value );
  84. __declspec( dllexport ) bool removeValue( Text field );
  85. __declspec( dllexport ) bool hasValue( Text field );
  86. __declspec( dllexport ) JSONValue getValue( Text field );
  87. __declspec( dllexport ) Iterator< Text > getFields();
  88. __declspec( dllexport ) Iterator< JSONValue > getValues();
  89. __declspec( dllexport ) Text toString() const override;
  90. };
  91. namespace Parser
  92. {
  93. __declspec( dllexport ) int findObjectEndInArray( const char *str );
  94. __declspec( dllexport ) Text removeWhitespace( const char *str );
  95. __declspec( dllexport ) JSONValue getValue( const char *str );
  96. __declspec( dllexport ) int findFieldEndInObject( const char *str );
  97. __declspec( dllexport ) int findValueEndInObject( const char *str );
  98. };
  99. }
  100. }