DictionaryHelper.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __DICTIONARYHELPER_H__
  21. #define __DICTIONARYHELPER_H__
  22. #include "json/document-wrapper.h"
  23. #include "editor-support/cocostudio/CocosStudioExport.h"
  24. #define DICTOOL DictionaryHelper::getInstance()
  25. namespace cocostudio {
  26. /**
  27. * @js NA
  28. * @lua NA
  29. */
  30. class CC_STUDIO_DLL DictionaryHelper
  31. {
  32. public:
  33. DictionaryHelper();
  34. ~DictionaryHelper();
  35. static DictionaryHelper* getInstance();
  36. static void destroyInstance();
  37. const rapidjson::Value& getSubDictionary_json(const rapidjson::Value &root, const char* key);
  38. const rapidjson::Value& getSubDictionary_json(const rapidjson::Value &root, const char* key, int idx);
  39. const rapidjson::Value& getSubDictionary_json(const rapidjson::Value &root, int idx);
  40. int getIntValue_json(const rapidjson::Value& root, const char* key, int def = 0);
  41. float getFloatValue_json(const rapidjson::Value& root,const char* key, float def = 0.0f);
  42. bool getBooleanValue_json(const rapidjson::Value& root,const char* key, bool def = false);
  43. const char* getStringValue_json(const rapidjson::Value& root,const char* key, const char *def = NULL);
  44. int getArrayCount_json(const rapidjson::Value& root,const char* key, int def = 0);
  45. int getIntValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, int def = 0);
  46. float getFloatValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, float def = 0.0f);
  47. bool getBoolValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, bool def = false);
  48. const char* getStringValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, const char *def = NULL);
  49. const rapidjson::Value &getDictionaryFromArray_json(const rapidjson::Value &root, const char* key,int idx);
  50. bool checkObjectExist_json(const rapidjson::Value &root);
  51. bool checkObjectExist_json(const rapidjson::Value &root, const char* key);
  52. bool checkObjectExist_json(const rapidjson::Value &root, int index);
  53. };
  54. }
  55. #endif /* defined(__CocoGUI__DictionaryHelper__) */