2013-06-06 12:02:54 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Chukong Technologies, Inc.
|
|
|
|
*
|
|
|
|
* http://www.cocostudio.com
|
|
|
|
* http://tools.cocoachina.com
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
* persons to whom the Software is furnished to do so, subject to the
|
|
|
|
* following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COCOSTUDIO_CSCONTENTJSONDICTIONARY_H
|
|
|
|
#define COCOSTUDIO_CSCONTENTJSONDICTIONARY_H
|
|
|
|
|
|
|
|
|
2013-10-16 11:19:01 +08:00
|
|
|
#include "json/json.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocostudio {
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
typedef enum _DicItemType
|
|
|
|
{
|
|
|
|
EDIC_TYPENULL = 0,
|
|
|
|
EDIC_TYPEINT,
|
|
|
|
EDIC_TYPEUINT,
|
|
|
|
EDIC_TYPEFLOAT,
|
|
|
|
EDIC_TYPESTRING,
|
|
|
|
EDIC_TYPEBOOLEN,
|
|
|
|
EDIC_TYPEARRAY,
|
|
|
|
EDIC_TYPEOBJECT
|
|
|
|
}DicItemType;
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
class JsonDictionary
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-09 19:51:26 +08:00
|
|
|
JsonDictionary();
|
2013-11-13 10:12:44 +08:00
|
|
|
virtual ~JsonDictionary();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
void initWithDescription(const char *pszDescription);
|
|
|
|
void insertItem(const char *pszKey, int nValue);
|
|
|
|
void insertItem(const char *pszKey, double fValue);
|
|
|
|
void insertItem(const char *pszKey, const char * pszValue);
|
2013-09-09 19:51:26 +08:00
|
|
|
void insertItem(const char *pszKey, JsonDictionary * subDictionary);
|
2013-06-06 12:02:54 +08:00
|
|
|
void insertItem(const char *pszKey, bool bValue);
|
|
|
|
bool deleteItem(const char *pszKey);
|
|
|
|
void cleanUp();
|
|
|
|
bool isKeyValidate(const char *pszKey);
|
|
|
|
|
|
|
|
int getItemIntValue(const char *pszKey, int nDefaultValue);
|
|
|
|
double getItemFloatValue(const char *pszKey, double fDefaultValue);
|
|
|
|
const char * getItemStringValue(const char *pszKey);
|
|
|
|
bool getItemBoolvalue(const char *pszKey, bool bDefaultValue);
|
2013-09-09 19:51:26 +08:00
|
|
|
JsonDictionary * getSubDictionary(const char *pszKey);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
std::string getDescription();
|
|
|
|
|
|
|
|
bool insertItemToArray(const char *pszArrayKey, int nValue);
|
|
|
|
bool insertItemToArray(const char *pszArrayKey, double fValue);
|
|
|
|
bool insertItemToArray(const char *pszArrayKey, const char * pszValue);
|
2013-09-09 19:51:26 +08:00
|
|
|
bool insertItemToArray(const char *pszArrayKey, JsonDictionary * subDictionary);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
int getArrayItemCount(const char *pszArrayKey);
|
|
|
|
int getIntValueFromArray(const char *pszArrayKey, int nIndex, int nDefaultValue);
|
|
|
|
double getFloatValueFromArray(const char *pszArrayKey, int nIndex, double fDefaultValue);
|
2013-09-09 19:51:26 +08:00
|
|
|
bool getBoolValueFromArray(const char *pszArrayKey, int nIndex, bool bDefaultValue);
|
2013-06-06 12:02:54 +08:00
|
|
|
const char * getStringValueFromArray(const char *pszArrayKey, int nIndex);
|
2013-09-09 19:51:26 +08:00
|
|
|
JsonDictionary *getSubItemFromArray(const char *pszArrayKey, int nIndex);
|
2013-06-06 12:02:54 +08:00
|
|
|
DicItemType getItemTypeFromArray(const char *pszArrayKey, int nIndex);
|
|
|
|
|
|
|
|
int getItemCount();
|
|
|
|
DicItemType getItemType(int nIndex);
|
|
|
|
DicItemType getItemType(const char *pszKey);
|
|
|
|
std::vector<std::string> getAllMemberNames();
|
|
|
|
|
|
|
|
protected:
|
2013-10-15 18:00:03 +08:00
|
|
|
Json::Value m_cValue;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-15 18:00:03 +08:00
|
|
|
void initWithValue(Json::Value& value);
|
|
|
|
inline bool isKeyValidate(const char *pszKey, Json::Value& root);
|
|
|
|
inline Json::Value * validateArrayItem(const char *pszArrayKey, int nIndex);
|
2013-06-06 12:02:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|