JSON.h 4.0 KB

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