JSONParseUtils.h 3.66 KB
//
//  JSONParseUtils.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 19.05.2017.
//
//

#ifndef JSONParseUtils_h
#define JSONParseUtils_h

#include "json/document.h"
#include <vector>
#include <string>
#include "cocos2d.h"

using namespace rapidjson;

class JSONParseUtils
{
public:
    
    static std::string loadJSONFromFile(const std::string& jsonFilePath);
    
        static bool hasMemberBool(const Value& json, const char* memberName);
        static bool hasMemberInt(const Value& json, const char* memberName);
        static bool hasMemberFloat(const Value& json, const char* memberName);
        static bool hasMemberString(const Value& json, const char* memberName);
        static bool hasMemberArray(const Value& json, const char* memberName);
        static bool hasMemberObject(const Value& json, const char* memberName);
    
    
        static bool hasMemberPoint(const Value& json, const char* memberName);
        static cocos2d::Point getMemberPoint(const Value& json, const char* memberName);
    
        static bool isPoint(const Value& json);
        static cocos2d::Point getPoint(const Value& json);
    
        static bool hasMemberSize(const Value& json, const char* memberName);
        static cocos2d::Point getMemberSize(const Value& json, const char* memberName);
    
        static bool isSize(const Value& json);
        static cocos2d::Size getSize(const Value& json);
    
        static bool hasMemberRect(const Value& json, const char* memberName);
        static cocos2d::Rect getMemberRect(const Value& json, const char* memberName);
    
        static bool isRect(const Value& json);
        static cocos2d::Rect getRect(const Value& json);
    
        static bool hasMemberColor3B(const Value& json, const char* memberName);
        static cocos2d::Color3B getMemberColor3B(const Value& json, const char* memberName);
    
        static bool isColor3B(const Value& json);
        static cocos2d::Color3B getColor3B(const Value& json);
    
        static bool hasMemberColor4F(const Value& json, const char* memberName);
        static cocos2d::Color4F getMemberColor4F(const Value& json, const char* memberName);
    
        static bool isColor4F(const Value& json);
        static cocos2d::Color4F getColor4F(const Value& json);
    
    
        static bool checkMemberBool(const Value& json, const char* memberName, bool expectedValue);
        static bool checkMemberFloat(const Value& json, const char* memberName, float expectedValue);
        static bool checkMemberInt(const Value& json, const char* memberName, int expectedValue);
        static bool checkMemberString(const Value& json, const char* memberName, std::string expectedValue);
    
//        static std::vector<rapidjson::Value*> parseValueArray(const Value& json, rapidjson::CrtAllocator* allocator);
        static std::vector<std::string> parseStringArray(const Value& json);
        static std::vector<float> parseFloatArray(const Value& json);
        static std::vector<int> parseIntArray(const Value& json);
        static std::vector<cocos2d::Point> parsePointArray(const Value& json);
        static std::vector<cocos2d::Size> parseSizeArray(const Value& json);
        static std::vector<cocos2d::Rect> parseRectArray(const Value& json);
    
        static std::vector<std::string> parseMemberStringArray(const Value& json, const char* memberName);
        static std::vector<float> parseMemberFloatArray(const Value& json, const char* memberName);
        static std::vector<int> parseMemberIntArray(const Value& json, const char* memberName);
        static std::vector<cocos2d::Point> parseMemberPointArray(const Value& json, const char* memberName);
};

#endif /* JSONParseUtils_h */