Merge branch 'develop' into newRenderer

This commit is contained in:
Ricardo Quesada 2013-12-12 09:14:30 -08:00
commit 4ab98ee8e7
58 changed files with 819 additions and 604 deletions

View File

@ -196,9 +196,9 @@ LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static
# define the macro to compile through support/zip_support/ioapi.c
LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_CPPFLAGS := -Wno-literal-suffix
LOCAL_CPPFLAGS := -Wno-literal-suffix -Wno-deprecated-declarations
LOCAL_EXPORT_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_EXPORT_CPPFLAGS := -Wno-literal-suffix
LOCAL_EXPORT_CPPFLAGS := -Wno-literal-suffix -Wno-deprecated-declarations
include $(BUILD_STATIC_LIBRARY)

View File

@ -47,9 +47,9 @@ Action::~Action()
CCLOGINFO("deallocing Action: %p - tag: %i", this, _tag);
}
const char* Action::description() const
std::string Action::description() const
{
return String::createWithFormat("<Action | Tag = %d>", _tag)->getCString();
return StringUtils::format("<Action | Tag = %d", _tag);
}
void Action::startWithTarget(Node *aTarget)

View File

@ -50,7 +50,7 @@ public:
* @js NA
* @lua NA
*/
const char* description() const;
std::string description() const;
/** returns a clone of action */
virtual Action* clone() const = 0;

View File

@ -77,7 +77,7 @@ void AnimationCache::removeAnimation(const std::string& name)
if (name.size()==0)
return;
_animations.remove(name);
_animations.erase(name);
}
Animation* AnimationCache::getAnimation(const std::string& name)

View File

@ -30,14 +30,14 @@ THE SOFTWARE.
NS_CC_BEGIN
ComponentContainer::ComponentContainer(Node *pNode)
: _components(NULL)
: _components(nullptr)
, _owner(pNode)
{
}
ComponentContainer::~ComponentContainer(void)
{
CC_SAFE_RELEASE(_components);
CC_SAFE_DELETE(_components);
}
Component* ComponentContainer::get(const char *pName) const
@ -47,7 +47,7 @@ Component* ComponentContainer::get(const char *pName) const
do {
CC_BREAK_IF(NULL == pName);
CC_BREAK_IF(NULL == _components);
pRet = dynamic_cast<Component*>(_components->objectForKey(pName));
pRet = _components->at(pName);
} while (0);
return pRet;
@ -60,18 +60,17 @@ bool ComponentContainer::add(Component *pCom)
CCASSERT(pCom->getOwner() == NULL, "Component already added. It can't be added again");
do
{
if (_components == NULL)
if (_components == nullptr)
{
_components = Dictionary::create();
_components->retain();
_components = new Map<std::string, Component*>();
_owner->scheduleUpdate();
}
Component *pComponent = dynamic_cast<Component*>(_components->objectForKey(pCom->getName()));
Component *pComponent = _components->at(pCom->getName());
CCASSERT(pComponent == NULL, "Component already added. It can't be added again");
CC_BREAK_IF(pComponent);
pCom->setOwner(_owner);
_components->setObject(pCom, pCom->getName());
_components->insert(pCom->getName(), pCom);
pCom->onEnter();
bRet = true;
} while(0);
@ -85,20 +84,16 @@ bool ComponentContainer::remove(const char *pName)
do
{
CC_BREAK_IF(!_components);
Object* pRetObject = NULL;
DictElement *pElement = NULL;
HASH_FIND_PTR(_components->_elements, pName, pElement);
if (pElement != NULL)
{
pRetObject = pElement->getObject();
}
Component *com = dynamic_cast<Component*>(pRetObject);
CC_BREAK_IF(!com);
auto iter = _components->find(pName);
CC_BREAK_IF(iter == _components->end());
auto com = iter->second;
com->onExit();
com->setOwner(NULL);
HASH_DEL(_components->_elements, pElement);
pElement->getObject()->release();
CC_SAFE_DELETE(pElement);
_components->erase(iter);
bRet = true;
} while(0);
return bRet;
@ -106,42 +101,40 @@ bool ComponentContainer::remove(const char *pName)
void ComponentContainer::removeAll()
{
if (_components != NULL)
if (_components != nullptr)
{
DictElement *pElement, *tmp;
HASH_ITER(hh, _components->_elements, pElement, tmp)
for (auto iter = _components->begin(); iter != _components->end(); ++iter)
{
HASH_DEL(_components->_elements, pElement);
((Component*)pElement->getObject())->onExit();
((Component*)pElement->getObject())->setOwner(NULL);
pElement->getObject()->release();
CC_SAFE_DELETE(pElement);
iter->second->onExit();
iter->second->setOwner(NULL);
}
_components->clear();
CC_SAFE_DELETE(_components);
_owner->unscheduleUpdate();
}
}
void ComponentContainer::alloc(void)
{
_components = Dictionary::create();
_components->retain();
_components = new Map<std::string, Component*>();
}
void ComponentContainer::visit(float fDelta)
{
if (_components != NULL)
if (_components != nullptr)
{
DictElement *pElement, *tmp;
HASH_ITER(hh, _components->_elements, pElement, tmp)
for (auto iter = _components->begin(); iter != _components->end(); ++iter)
{
((Component*)pElement->getObject())->update(fDelta);
iter->second->update(fDelta);
}
}
}
bool ComponentContainer::isEmpty() const
{
return (bool)(!(_components && _components->count()));
return (_components == nullptr || _components->empty());
}
NS_CC_END

View File

@ -25,7 +25,7 @@ THE SOFTWARE.
#ifndef __CC_FRAMEWORK_COMCONTAINER_H__
#define __CC_FRAMEWORK_COMCONTAINER_H__
#include "CCDictionary.h"
#include "CCMap.h"
NS_CC_BEGIN
@ -58,7 +58,7 @@ private:
void alloc(void);
private:
Dictionary *_components; ///< Dictionary of components
Map<std::string, Component*>* _components;
Node *_owner;
friend class Node;

View File

@ -54,34 +54,30 @@ Configuration::Configuration()
, _maxSamplesAllowed(0)
, _maxTextureUnits(0)
, _glExtensions(nullptr)
, _valueDict(nullptr)
{
}
bool Configuration::init()
{
_valueDict = Dictionary::create();
_valueDict->retain();
_valueDict->setObject(String::create( cocos2dVersion() ), "cocos2d.x.version");
_valueDict["cocos2d.x.version"] = Value(cocos2dVersion());
#if CC_ENABLE_PROFILERS
_valueDict->setObject(Bool::create(true), "cocos2d.x.compiled_with_profiler");
_valueDict["cocos2d.x.compiled_with_profiler"] = Value(true);
#else
_valueDict->setObject(Bool::create(false), "cocos2d.x.compiled_with_profiler");
_valueDict["cocos2d.x.compiled_with_profiler"] = Value(false);
#endif
#if CC_ENABLE_GL_STATE_CACHE == 0
_valueDict->setObject(Bool::create(false), "cocos2d.x.compiled_with_gl_state_cache");
_valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(false);
#else
_valueDict->setObject(Bool::create(true), "cocos2d.x.compiled_with_gl_state_cache");
_valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(true);
#endif
#ifdef DEBUG
_valueDict->setObject(String::create("DEBUG"), "cocos2d.x.build_type");
_valueDict["cocos2d.x.build_type"] = Value("DEBUG");
#else
_valueDict->setObject(String::create("RELEASE"), "cocos2d.x.build_type");
_valueDict["cocos2d.x.build_type"] = Value("RELEASE");
#endif
return true;
@ -89,17 +85,13 @@ bool Configuration::init()
Configuration::~Configuration()
{
_valueDict->release();
}
void Configuration::dumpInfo() const
{
// Dump
PrettyPrinter visitor(0);
_valueDict->acceptVisitor(visitor);
CCLOG("%s", visitor.getResult().c_str());
Value forDump = Value(_valueDict);
CCLOG("%s", forDump.getDescription().c_str());
// And Dump some warnings as well
#if CC_ENABLE_PROFILERS
@ -117,46 +109,46 @@ void Configuration::dumpInfo() const
void Configuration::gatherGPUInfo()
{
_valueDict->setObject(String::create((const char*)glGetString(GL_VENDOR)), "gl.vendor");
_valueDict->setObject(String::create((const char*)glGetString(GL_RENDERER)), "gl.renderer");
_valueDict->setObject(String::create((const char*)glGetString(GL_VERSION)), "gl.version");
_valueDict["gl.vendor"] = Value((const char*)glGetString(GL_VENDOR));
_valueDict["gl.renderer"] = Value((const char*)glGetString(GL_RENDERER));
_valueDict["gl.version"] = Value((const char*)glGetString(GL_VERSION));
_glExtensions = (char *)glGetString(GL_EXTENSIONS);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
_valueDict->setObject(Integer::create((int)_maxTextureSize), "gl.max_texture_size");
_valueDict["gl.max_texture_size"] = Value((int)_maxTextureSize);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_maxTextureUnits);
_valueDict->setObject(Integer::create((int)_maxTextureUnits), "gl.max_texture_units");
_valueDict["gl.max_texture_units"] = Value((int)_maxTextureUnits);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &_maxSamplesAllowed);
_valueDict->setObject(Integer::create((int)_maxSamplesAllowed), "gl.max_samples_allowed");
_valueDict["gl.max_samples_allowed"] = Value((int)_maxSamplesAllowed);
#endif
_supportsETC1 = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
_valueDict->setObject(Bool::create(_supportsETC1), "gl.supports_ETC1");
_valueDict["gl.supports_ETC1"] = Value(_supportsETC1);
_supportsS3TC = checkForGLExtension("GL_EXT_texture_compression_s3tc");
_valueDict->setObject(Bool::create(_supportsS3TC), "gl.supports_S3TC");
_valueDict["gl.supports_S3TC"] = Value(_supportsS3TC);
_supportsATITC = checkForGLExtension("GL_AMD_compressed_ATC_texture");
_valueDict->setObject(Bool::create(_supportsATITC), "gl.supports_ATITC");
_valueDict["gl.supports_ATITC"] = Value(_supportsATITC);
_supportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
_valueDict->setObject(Bool::create(_supportsPVRTC), "gl.supports_PVRTC");
_valueDict["gl.supports_PVRTC"] = Value(_supportsPVRTC);
_supportsNPOT = true;
_valueDict->setObject(Bool::create(_supportsNPOT), "gl.supports_NPOT");
_valueDict["gl.supports_NPOT"] = Value(_supportsNPOT);
_supportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888");
_valueDict->setObject(Bool::create(_supportsBGRA8888), "gl.supports_BGRA8888");
_valueDict["gl.supports_BGRA8888"] = Value(_supportsBGRA8888);
_supportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
_valueDict->setObject(Bool::create(_supportsDiscardFramebuffer), "gl.supports_discard_framebuffer");
_valueDict["gl.supports_discard_framebuffer"] = Value(_supportsDiscardFramebuffer);
_supportsShareableVAO = checkForGLExtension("vertex_array_object");
_valueDict->setObject(Bool::create(_supportsShareableVAO), "gl.supports_vertex_array_object");
_valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO);
CHECK_GL_ERROR_DEBUG();
}
@ -265,78 +257,27 @@ bool Configuration::supportsDiscardFramebuffer() const
bool Configuration::supportsShareableVAO() const
{
#if CC_TEXTURE_ATLAS_USE_VAO
return _supportsShareableVAO;
#else
return false;
#endif
#if CC_TEXTURE_ATLAS_USE_VAO
return _supportsShareableVAO;
#else
return false;
#endif
}
//
// generic getters for properties
//
const char *Configuration::getCString(const char *key, const char *defaultValue) const
const Value& Configuration::getValue(const std::string& key, const Value& defaultValue) const
{
Object *ret = _valueDict->objectForKey(key);
if (ret)
{
if (String *str=dynamic_cast<String*>(ret))
return str->getCString();
CCASSERT(false, "Key found, but from different type");
}
// XXX: Should it throw an exception ?
auto iter = _valueDict.find(key);
if (iter != _valueDict.end())
return _valueDict.at(key);
return defaultValue;
}
/** returns the value of a given key as a boolean */
bool Configuration::getBool(const char *key, bool defaultValue) const
void Configuration::setValue(const std::string& key, const Value& value)
{
Object *ret = _valueDict->objectForKey(key);
if (ret)
{
if (Bool *boolobj=dynamic_cast<Bool*>(ret))
return boolobj->getValue();
if (String *strobj=dynamic_cast<String*>(ret))
return strobj->boolValue();
CCASSERT(false, "Key found, but from different type");
}
// XXX: Should it throw an exception ?
return defaultValue;
}
/** returns the value of a given key as a double */
double Configuration::getNumber( const char *key, double defaultValue ) const
{
Object *ret = _valueDict->objectForKey(key);
if( ret )
{
if (Double *obj=dynamic_cast<Double*>(ret))
return obj->getValue();
if (Integer *obj=dynamic_cast<Integer*>(ret))
return obj->getValue();
if (String *strobj=dynamic_cast<String*>(ret))
return strobj->doubleValue();
CCASSERT(false, "Key found, but from different type");
}
// XXX: Should it throw an exception ?
return defaultValue;
}
Object * Configuration::getObject(const char *key) const
{
return _valueDict->objectForKey(key);
}
void Configuration::setObject(const char *key, Object *value)
{
_valueDict->setObject(value, key);
_valueDict[key] = value;
}
@ -345,20 +286,21 @@ void Configuration::setObject(const char *key, Object *value)
//
void Configuration::loadConfigFile(const char *filename)
{
Dictionary *dict = Dictionary::createWithContentsOfFile(filename);
CCASSERT(dict, "cannot create dictionary");
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(filename);
CCASSERT(!dict.empty(), "cannot create dictionary");
// search for metadata
bool validMetadata = false;
Object *metadata = dict->objectForKey("metadata");
if (metadata && dynamic_cast<Dictionary*>(metadata))
auto metadataIter = dict.find("metadata");
if (metadataIter != dict.end() && metadataIter->second.getType() == Value::Type::MAP)
{
Object *format_o = static_cast<Dictionary*>(metadata)->objectForKey("format");
// XXX: cocos2d-x returns Strings when importing from .plist. This bug will be addressed in cocos2d-x v3.x
if (format_o && dynamic_cast<String*>(format_o))
const auto& metadata = metadataIter->second.asValueMap();
auto formatIter = metadata.find("format");
if (formatIter != metadata.end())
{
int format = static_cast<String*>(format_o)->intValue();
int format = formatIter->second.asInt();
// Support format: 1
if (format == 1)
@ -374,22 +316,22 @@ void Configuration::loadConfigFile(const char *filename)
return;
}
Object *data = dict->objectForKey("data");
if (!data || !dynamic_cast<Dictionary*>(data))
auto dataIter = dict.find("data");
if (dataIter == dict.end() || dataIter->second.getType() != Value::Type::MAP)
{
CCLOG("Expected 'data' dict, but not found. Config file: %s", filename);
return;
}
// Add all keys in the existing dictionary
Dictionary *data_dict = static_cast<Dictionary*>(data);
DictElement* element;
CCDICT_FOREACH(data_dict, element)
const auto& dataMap = dataIter->second.asValueMap();
for (auto dataMapIter = dataMap.begin(); dataMapIter != dataMap.end(); ++dataMapIter)
{
if(! _valueDict->objectForKey( element->getStrKey() ))
_valueDict->setObject(element->getObject(), element->getStrKey());
else
CCLOG("Key already present. Ignoring '%s'", element->getStrKey());
if (_valueDict.find(dataMapIter->first) == _valueDict.end())
_valueDict[dataMapIter->first] = dataMapIter->second;
else
CCLOG("Key already present. Ignoring '%s'",dataMapIter->first.c_str());
}
}

View File

@ -29,10 +29,9 @@ THE SOFTWARE.
#include "CCObject.h"
#include "CCGL.h"
#include "CCString.h"
#include "CCValue.h"
#include <string>
NS_CC_BEGIN
/**
@ -116,23 +115,11 @@ public:
bool init();
/** returns the value of a given key as a string.
If the key is not found, it will return the default value */
const char* getCString(const char *key, const char *defaultValue = nullptr) const;
/** returns the value of a given key as a boolean.
If the key is not found, it will return the default value */
bool getBool(const char *key, bool defaultValue = false) const;
/** returns the value of a given key as a double.
If the key is not found, it will return the default value */
double getNumber(const char *key, double defaultValue = 0.0) const;
/** returns the value of a given key as a double */
Object * getObject(const char *key) const;
const Value& getValue(const std::string& key, const Value& defaultValue = Value::Null) const;
/** sets a new key/value pair in the configuration dictionary */
void setObject(const char *key, Object *value);
void setValue(const std::string& key, const Value& value);
/** dumps the current configuration on the console */
void dumpInfo() const;
@ -163,7 +150,7 @@ protected:
GLint _maxTextureUnits;
char * _glExtensions;
Dictionary *_valueDict;
ValueMap _valueDict;
};
// end of global group

View File

@ -534,13 +534,6 @@ CC_DEPRECATED_ATTRIBUTE static inline AffineTransform CCAffineTransformIdentity(
// CC prefix compatibility
CC_DEPRECATED_ATTRIBUTE typedef Object CCObject;
CC_DEPRECATED_ATTRIBUTE typedef Event CCEvent;
CC_DEPRECATED_ATTRIBUTE typedef Integer CCInteger;
CC_DEPRECATED_ATTRIBUTE typedef String CCString;
CC_DEPRECATED_ATTRIBUTE typedef Bool CCBool;
CC_DEPRECATED_ATTRIBUTE typedef Float CCFloat;
CC_DEPRECATED_ATTRIBUTE typedef Double CCDouble;
CC_DEPRECATED_ATTRIBUTE typedef Data CCData;
CC_DEPRECATED_ATTRIBUTE typedef Dictionary CCDictionary;
CC_DEPRECATED_ATTRIBUTE typedef DataVisitor CCDataVisitor;
CC_DEPRECATED_ATTRIBUTE typedef PrettyPrinter CCPrettyPrinter;
CC_DEPRECATED_ATTRIBUTE typedef Acceleration CCAcceleration;
@ -1024,11 +1017,28 @@ CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLBindVAO(GLuint vaoId) { GL::bindV
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLEnable( int flags ) { /* ignore */ };
CC_DEPRECATED_ATTRIBUTE typedef int ccGLServerState;
CC_DEPRECATED_ATTRIBUTE typedef Data CCData;
CC_DEPRECATED_ATTRIBUTE typedef __Set CCSet;
CC_DEPRECATED_ATTRIBUTE typedef __SetIterator CCSetIterator;
CC_DEPRECATED_ATTRIBUTE typedef __Set Set;
CC_DEPRECATED_ATTRIBUTE typedef __SetIterator SetIterator;
CC_DEPRECATED_ATTRIBUTE typedef __Array CCArray;
CC_DEPRECATED_ATTRIBUTE typedef __Array Array;
CC_DEPRECATED_ATTRIBUTE typedef __Dictionary Dictionary;
CC_DEPRECATED_ATTRIBUTE typedef __Dictionary CCDictionary;
CC_DEPRECATED_ATTRIBUTE typedef __Double Double;
CC_DEPRECATED_ATTRIBUTE typedef __Double CCDouble;
CC_DEPRECATED_ATTRIBUTE typedef __Float Float;
CC_DEPRECATED_ATTRIBUTE typedef __Float CCFloat;
CC_DEPRECATED_ATTRIBUTE typedef __Integer Integer;
CC_DEPRECATED_ATTRIBUTE typedef __Integer CCInteger;
CC_DEPRECATED_ATTRIBUTE typedef __Bool Bool;
CC_DEPRECATED_ATTRIBUTE typedef __Bool CCBool;
CC_DEPRECATED_ATTRIBUTE typedef __String CCString;
//CC_DEPRECATED_ATTRIBUTE typedef __String String;
NS_CC_END

View File

@ -187,34 +187,34 @@ void Director::setDefaultValues(void)
Configuration *conf = Configuration::getInstance();
// default FPS
double fps = conf->getNumber("cocos2d.x.fps", kDefaultFPS);
double fps = conf->getValue("cocos2d.x.fps", Value(kDefaultFPS)).asDouble();
_oldAnimationInterval = _animationInterval = 1.0 / fps;
// Display FPS
_displayStats = conf->getBool("cocos2d.x.display_fps", false);
_displayStats = conf->getValue("cocos2d.x.display_fps", Value(false)).asBool();
// GL projection
const char *projection = conf->getCString("cocos2d.x.gl.projection", "3d");
if (strcmp(projection, "3d") == 0)
std::string projection = conf->getValue("cocos2d.x.gl.projection", Value("3d")).asString();
if (projection == "3d")
_projection = Projection::_3D;
else if (strcmp(projection, "2d") == 0)
else if (projection == "2d")
_projection = Projection::_2D;
else if (strcmp(projection, "custom") == 0)
else if (projection == "custom")
_projection = Projection::CUSTOM;
else
CCASSERT(false, "Invalid projection value");
// Default pixel format for PNG images with alpha
const char *pixel_format = conf->getCString("cocos2d.x.texture.pixel_format_for_png", "rgba8888");
if (strcmp(pixel_format, "rgba8888") == 0)
std::string pixel_format = conf->getValue("cocos2d.x.texture.pixel_format_for_png", Value("rgba8888")).asString();
if (pixel_format == "rgba8888")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
else if(strcmp(pixel_format, "rgba4444") == 0)
else if(pixel_format == "rgba4444")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
else if(strcmp(pixel_format, "rgba5551") == 0)
else if(pixel_format == "rgba5551")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1);
// PVR v2 has alpha premultiplied ?
bool pvr_alpha_premultipled = conf->getBool("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", false);
bool pvr_alpha_premultipled = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).asBool();
Texture2D::PVRImagesHavePremultipliedAlpha(pvr_alpha_premultipled);
}

View File

@ -203,11 +203,11 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
if (type == GL_VERTEX_SHADER)
{
CCLOG("cocos2d: %s", getVertexShaderLog());
CCLOG("cocos2d: %s", getVertexShaderLog().c_str());
}
else
{
CCLOG("cocos2d: %s", getFragmentShaderLog());
CCLOG("cocos2d: %s", getFragmentShaderLog().c_str());
}
free(src);
@ -290,34 +290,35 @@ void GLProgram::use()
GL::useProgram(_program);
}
const char* GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
{
std::string ret;
GLint logLength = 0, charsWritten = 0;
infoFunc(object, GL_INFO_LOG_LENGTH, &logLength);
if (logLength < 1)
return 0;
return "";
char *logBytes = (char*)malloc(logLength);
logFunc(object, logLength, &charsWritten, logBytes);
String* log = String::create(logBytes);
ret = logBytes;
free(logBytes);
return log->getCString();
return ret;
}
const char* GLProgram::getVertexShaderLog() const
std::string GLProgram::getVertexShaderLog() const
{
return this->logForOpenGLObject(_vertShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
}
const char* GLProgram::getFragmentShaderLog() const
std::string GLProgram::getFragmentShaderLog() const
{
return this->logForOpenGLObject(_fragShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
}
const char* GLProgram::getProgramLog() const
std::string GLProgram::getProgramLog() const
{
return this->logForOpenGLObject(_program, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog);
}

View File

@ -214,26 +214,13 @@ public:
void setUniformsForBuiltins(const kmMat4 &modelView);
/** returns the vertexShader error log */
const char* getVertexShaderLog() const;
/** @deprecated. Use getVertexShaderLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* vertexShaderLog() const { return getVertexShaderLog(); }
std::string getVertexShaderLog() const;
/** returns the fragmentShader error log */
const char* getFragmentShaderLog() const;
/** @deprecated. Use getFragmentShaderLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* fragmentShaderLog() const{ return getFragmentShaderLog();}
std::string getFragmentShaderLog() const;
/** returns the program error log */
const char* getProgramLog() const;
/** @deprecated. Use getProgramLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* programLog() const { return getProgramLog(); }
std::string getProgramLog() const;
// reload all shaders, this function is designed for android
// when opengl context lost, so don't call it.
@ -245,7 +232,7 @@ private:
bool updateUniformLocation(GLint location, const GLvoid* data, unsigned int bytes);
const char* description() const;
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
const char* logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
private:
GLuint _program;

View File

@ -93,18 +93,19 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
{
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
Dictionary *dict = Dictionary::createWithContentsOfFile(pathStr.c_str());
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr.c_str());
CCASSERT(((String*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
CCASSERT(dict["version"].asInt() == 1, "Unsupported version. Upgrade cocos2d version");
std::string texturePathStr = relPathStr + ((String*)dict->objectForKey("textureFilename"))->getCString();
String *textureFilename = String::create(texturePathStr);
unsigned int width = ((String*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = ((String*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = ((String*)dict->objectForKey("firstChar"))->intValue();
std::string textureFilename = relPathStr + dict["textureFilename"].asString();
unsigned int width = dict["itemWidth"].asInt() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = dict["itemHeight"].asInt() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = dict["firstChar"].asInt();
this->initWithString(theString, textureFilename->getCString(), width, height, startChar);
this->initWithString(theString, textureFilename.c_str(), width, height, startChar);
return true;
}

View File

@ -40,6 +40,7 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
#include "CCDirector.h"
#include "CCTextureCache.h"
#include "ccUTF8.h"
#include "CCMap.h"
using namespace std;
@ -60,25 +61,24 @@ static unsigned short* copyUTF16StringN(unsigned short* str)
//
//FNTConfig Cache - free functions
//
static Dictionary* s_pConfigurations = NULL;
static Map<std::string, CCBMFontConfiguration*>* s_configurations = nullptr;
CCBMFontConfiguration* FNTConfigLoadFile(const std::string& fntFile)
{
CCBMFontConfiguration* ret = NULL;
if( s_pConfigurations == NULL )
if( s_configurations == nullptr )
{
s_pConfigurations = new Dictionary();
s_pConfigurations->init();
s_configurations = new Map<std::string, CCBMFontConfiguration*>();
}
ret = static_cast<CCBMFontConfiguration*>( s_pConfigurations->objectForKey(fntFile) );
ret = s_configurations->at(fntFile);
if( ret == NULL )
{
ret = CCBMFontConfiguration::create(fntFile.c_str());
if (ret)
{
s_pConfigurations->setObject(ret, fntFile);
s_configurations->insert(fntFile, ret);
}
}
@ -87,10 +87,10 @@ CCBMFontConfiguration* FNTConfigLoadFile(const std::string& fntFile)
void FNTConfigRemoveCache( void )
{
if (s_pConfigurations)
if (s_configurations)
{
s_pConfigurations->removeAllObjects();
CC_SAFE_RELEASE_NULL(s_pConfigurations);
s_configurations->clear();
CC_SAFE_DELETE(s_configurations);
}
}
@ -148,15 +148,15 @@ CCBMFontConfiguration::~CCBMFontConfiguration()
CC_SAFE_DELETE(_characterSet);
}
const char* CCBMFontConfiguration::description(void) const
std::string CCBMFontConfiguration::description(void) const
{
return String::createWithFormat(
return StringUtils::format(
"<CCBMFontConfiguration = " CC_FORMAT_PRINTF_SIZE_T " | Glphys:%d Kernings:%d | Image = %s>",
(size_t)this,
HASH_COUNT(_fontDefDictionary),
HASH_COUNT(_kerningDictionary),
_atlasName.c_str()
)->getCString();
);
}
void CCBMFontConfiguration::purgeKerningDictionary()
@ -183,6 +183,7 @@ void CCBMFontConfiguration::purgeFontDefDictionary()
std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string& controlFile)
{
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile);
String *contents = String::createWithContentsOfFile(fullpath.c_str());
CCASSERT(contents, "CCBMFontConfiguration::parseConfigFile | Open file error.");

View File

@ -137,7 +137,7 @@ public:
* @js NA
* @lua NA
*/
const char * description() const;
std::string description() const;
/** allocates a CCBMFontConfiguration with a FNT file */
static CCBMFontConfiguration * create(const std::string& FNTfile);

View File

@ -185,9 +185,9 @@ const std::string& LabelTTF::getString() const
return _string;
}
const char* LabelTTF::description() const
std::string LabelTTF::description() const
{
return String::createWithFormat("<LabelTTF | FontName = %s, FontSize = %.1f>", _fontName.c_str(), _fontSize)->getCString();
return StringUtils::format("<LabelTTF | FontName = %s, FontSize = %.1f>", _fontName.c_str(), _fontSize);
}
TextHAlignment LabelTTF::getHorizontalAlignment() const

View File

@ -70,7 +70,7 @@ public:
* @js NA
* @lua NA
*/
const char* description() const;
std::string description() const;
/** creates a LabelTTF with a font name and font size in points
@since v2.0.1

View File

@ -582,9 +582,9 @@ void Node::cleanup()
}
const char* Node::description() const
std::string Node::description() const
{
return String::createWithFormat("<Node | Tag = %d>", _tag)->getCString();
return StringUtils::format("<Node | Tag = %d", _tag);
}
// lazy allocs
@ -771,7 +771,7 @@ void Node::detachChild(Node *child, int childIndex, bool doCleanup)
// set parent nil at the end
child->setParent(nullptr);
_children.remove(childIndex);
_children.erase(childIndex);
}

View File

@ -53,7 +53,6 @@ class LabelProtocol;
class Scheduler;
class ActionManager;
class Component;
class Dictionary;
class ComponentContainer;
class EventDispatcher;
#ifdef CC_USE_PHYSICS
@ -157,7 +156,7 @@ public:
* @js NA
* @lua NA
*/
const char* description(void) const;
std::string description(void) const;
/// @} end of initializers

View File

@ -36,7 +36,7 @@ static NotificationCenter *s_sharedNotifCenter = NULL;
NotificationCenter::NotificationCenter()
: _scriptHandler(0)
{
_observers = Array::createWithCapacity(3);
_observers = __Array::createWithCapacity(3);
_observers->retain();
}
@ -128,7 +128,7 @@ void NotificationCenter::removeObserver(Object *target,const char *name)
int NotificationCenter::removeAllObservers(Object *target)
{
Object *obj = NULL;
Array *toRemove = Array::create();
__Array *toRemove = __Array::create();
CCARRAY_FOREACH(_observers, obj)
{
@ -179,7 +179,7 @@ void NotificationCenter::unregisterScriptObserver(Object *target,const char* nam
void NotificationCenter::postNotification(const char *name, Object *sender)
{
Array* ObserversCopy = Array::createWithCapacity(_observers->count());
__Array* ObserversCopy = __Array::createWithCapacity(_observers->count());
ObserversCopy->addObjectsFromArray(_observers);
Object* obj = NULL;
CCARRAY_FOREACH(ObserversCopy, obj)

View File

@ -121,7 +121,7 @@ private:
// variables
//
Array *_observers;
__Array *_observers;
int _scriptHandler;
};

View File

@ -255,7 +255,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
// reorder _children->array
child->retain();
_children.remove(oldIndex);
_children.erase(oldIndex);
_children.insert(newIndex, child);
child->release();

View File

@ -60,7 +60,7 @@ ProfilingTimer* Profiler::createAndAddTimerWithName(const char* timerName)
{
ProfilingTimer *t = new ProfilingTimer();
t->initWithName(timerName);
_activeTimers->setObject(t, timerName);
_activeTimers.insert(timerName, t);
t->release();
return t;
@ -68,32 +68,28 @@ ProfilingTimer* Profiler::createAndAddTimerWithName(const char* timerName)
void Profiler::releaseTimer(const char* timerName)
{
_activeTimers->removeObjectForKey(timerName);
_activeTimers.erase(timerName);
}
void Profiler::releaseAllTimers()
{
_activeTimers->removeAllObjects();
_activeTimers.clear();
}
bool Profiler::init()
{
_activeTimers = new Dictionary();
_activeTimers->init();
return true;
}
Profiler::~Profiler(void)
{
CC_SAFE_RELEASE(_activeTimers);
}
void Profiler::displayTimers()
{
DictElement* pElement = NULL;
CCDICT_FOREACH(_activeTimers, pElement)
for (auto iter = _activeTimers.begin(); iter != _activeTimers.end(); ++iter)
{
ProfilingTimer* timer = static_cast<ProfilingTimer*>(pElement->getObject());
ProfilingTimer* timer = iter->second;
log("%s", timer->description());
}
}
@ -143,7 +139,7 @@ void ProfilingTimer::reset()
void ProfilingBeginTimingBlock(const char *timerName)
{
Profiler* p = Profiler::getInstance();
ProfilingTimer* timer = static_cast<ProfilingTimer*>( p->_activeTimers->objectForKey(timerName) );
ProfilingTimer* timer = p->_activeTimers.at(timerName);
if( ! timer )
{
timer = p->createAndAddTimerWithName(timerName);
@ -161,7 +157,7 @@ void ProfilingEndTimingBlock(const char *timerName)
auto now = chrono::high_resolution_clock::now();
Profiler* p = Profiler::getInstance();
ProfilingTimer* timer = (ProfilingTimer*)p->_activeTimers->objectForKey(timerName);
ProfilingTimer* timer = p->_activeTimers.at(timerName);
CCASSERT(timer, "CCProfilingTimer not found");
@ -178,7 +174,7 @@ void ProfilingEndTimingBlock(const char *timerName)
void ProfilingResetTimingBlock(const char *timerName)
{
Profiler* p = Profiler::getInstance();
ProfilingTimer *timer = (ProfilingTimer*)p->_activeTimers->objectForKey(timerName);
ProfilingTimer *timer = p->_activeTimers.at(timerName);
CCASSERT(timer, "CCProfilingTimer not found");

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include <chrono>
#include "ccConfig.h"
#include "CCObject.h"
#include "CCDictionary.h"
#include "CCMap.h"
NS_CC_BEGIN
@ -94,7 +94,7 @@ public:
*/
void releaseAllTimers();
Dictionary* _activeTimers;
Map<std::string, ProfilingTimer*> _activeTimers;
};
class ProfilingTimer : public Object

View File

@ -949,7 +949,7 @@ void Scheduler::update(float dt)
SchedulerScriptHandlerEntry* eachEntry = _scriptHandlerEntries.at(i);
if (eachEntry->isMarkedForDeletion())
{
_scriptHandlerEntries.remove(i);
_scriptHandlerEntries.erase(i);
}
else if (!eachEntry->isPaused())
{

View File

@ -300,7 +300,7 @@ void SpriteFrameCache::removeUnusedSpriteFrames()
}
}
_spriteFrames.remove(toRemoveFrames);
_spriteFrames.erase(toRemoveFrames);
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
if( bRemoved )
@ -321,12 +321,12 @@ void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
if (!key.empty())
{
_spriteFrames.remove(key);
_spriteFrames.erase(key);
_spriteFramesAliases.erase(key);
}
else
{
_spriteFrames.remove(name);
_spriteFrames.erase(name);
}
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
@ -365,7 +365,7 @@ void SpriteFrameCache::removeSpriteFramesFromDictionary(ValueMap& dictionary)
}
}
_spriteFrames.remove(keysToRemove);
_spriteFrames.erase(keysToRemove);
}
void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
@ -382,7 +382,7 @@ void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
}
}
_spriteFrames.remove(keysToRemove);
_spriteFrames.erase(keysToRemove);
}
SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)

View File

@ -28,9 +28,10 @@ THE SOFTWARE.
#include "CCTextureAtlas.h"
#include "TGAlib.h"
#include "ccConfig.h"
#include "CCDictionary.h"
#include "CCInteger.h"
#include "CCDirector.h"
#include "CCString.h"
#include <sstream>
NS_CC_BEGIN
@ -55,8 +56,6 @@ bool TileMapAtlas::initWithTileFile(const std::string& tile, const std::string&
if( AtlasNode::initWithTileFile(tile, tileWidth, tileHeight, _itemsToRender) )
{
_posToAtlasIndex = new Dictionary();
_posToAtlasIndex->init();
this->updateAtlasValues();
this->setContentSize(Size((float)(_TGAInfo->width*_itemWidth),
(float)(_TGAInfo->height*_itemHeight)));
@ -78,7 +77,6 @@ TileMapAtlas::~TileMapAtlas()
{
tgaDestroy(_TGAInfo);
}
CC_SAFE_RELEASE(_posToAtlasIndex);
}
void TileMapAtlas::releaseMap()
@ -88,8 +86,6 @@ void TileMapAtlas::releaseMap()
tgaDestroy(_TGAInfo);
}
_TGAInfo = NULL;
CC_SAFE_RELEASE_NULL(_posToAtlasIndex);
}
void TileMapAtlas::calculateItemsToRender()
@ -133,7 +129,6 @@ void TileMapAtlas::loadTGAfile(const std::string& file)
void TileMapAtlas::setTile(const Color3B& tile, const Point& position)
{
CCASSERT(_TGAInfo != NULL, "tgaInfo must not be nil");
CCASSERT(_posToAtlasIndex != NULL, "posToAtlasIndex must not be nil");
CCASSERT(position.x < _TGAInfo->width, "Invalid position.x");
CCASSERT(position.y < _TGAInfo->height, "Invalid position.x");
CCASSERT(tile.r != 0, "R component must be non 0");
@ -150,10 +145,10 @@ void TileMapAtlas::setTile(const Color3B& tile, const Point& position)
// XXX: this method consumes a lot of memory
// XXX: a tree of something like that shall be implemented
Integer *num = (Integer*)_posToAtlasIndex->objectForKey(String::createWithFormat("%ld,%ld",
(long)position.x,
(long)position.y)->getCString());
this->updateAtlasValueAt(position, tile, num->getValue());
std::string key = StringUtils::toString(position.x) + "," + StringUtils::toString(position.y);
int num = _posToAtlasIndex[key].asInt();
this->updateAtlasValueAt(position, tile, num);
}
}
@ -252,9 +247,8 @@ void TileMapAtlas::updateAtlasValues()
{
this->updateAtlasValueAt(Point(x,y), value, total);
String *key = String::createWithFormat("%d,%d", x,y);
Integer *num = Integer::create(total);
_posToAtlasIndex->setObject(num, key->getCString());
std::string key = StringUtils::toString(x) + "," + StringUtils::toString(y);
_posToAtlasIndex[key] = total;
total++;
}

View File

@ -26,13 +26,12 @@ THE SOFTWARE.
#ifndef __CCTILE_MAP_ATLAS__
#define __CCTILE_MAP_ATLAS__
#include "CCAtlasNode.h"
#include "CCValue.h"
NS_CC_BEGIN
struct sImageTGA;
class Dictionary;
/**
* @addtogroup tilemap_parallax_nodes
@ -98,7 +97,7 @@ protected:
//! x,y to atlas dictionary
Dictionary* _posToAtlasIndex;
ValueMap _posToAtlasIndex;
//! numbers of tiles to render
int _itemsToRender;
/** TileMap info */

View File

@ -36,7 +36,7 @@ NS_CC_BEGIN
// std::vector implementation
// ----------------------------------------------------------------------------------
__Array::Array()
__Array::__Array()
: data(NULL)
{
init();
@ -483,7 +483,7 @@ __Array* __Array::createWithContentsOfFileThreadSafe(const char* fileName)
__Array* ret = __Array::createWithCapacity(static_cast<int>(arr.size()));
std::for_each(arr.cbegin(), arr.cend(), [&ret](const Value& value){
ret->addObject(String::create(value.asString()));
ret->addObject(__String::create(value.asString()));
});
return ret;

View File

@ -552,9 +552,6 @@ public:
// end of data_structure group
/// @}
CC_DEPRECATED_ATTRIBUTE typedef __Array CCArray;
CC_DEPRECATED_ATTRIBUTE typedef __Array Array;
NS_CC_END
#endif // __CCARRAY_H__

View File

@ -51,7 +51,7 @@ void AutoreleasePool::removeObject(Object* object)
{
for (unsigned int i = 0; i < object->_autoReleaseCount; ++i)
{
_managedObjectArray.removeObject(object, false);
_managedObjectArray.erase(object, false);
}
}
@ -111,7 +111,7 @@ PoolManager::~PoolManager()
// we only release the last autorelease pool here
_curReleasePool = 0;
_releasePoolStack.remove(0);
_releasePoolStack.erase(0);
}
void PoolManager::finalize()
@ -147,7 +147,7 @@ void PoolManager::pop()
if (count > 1)
{
_releasePoolStack.remove(count-1);
_releasePoolStack.erase(count-1);
// if(nCount > 1)
// {

View File

@ -34,16 +34,16 @@ NS_CC_BEGIN
* @{
*/
class CC_DLL Bool : public Object, public Clonable
class CC_DLL __Bool : public Object, public Clonable
{
public:
Bool(bool v)
__Bool(bool v)
: _value(v) {}
bool getValue() const {return _value;}
static Bool* create(bool v)
static __Bool* create(bool v)
{
Bool* pRet = new Bool(v);
__Bool* pRet = new __Bool(v);
if (pRet)
{
pRet->autorelease();
@ -54,9 +54,9 @@ public:
/* override functions */
virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); }
Bool* clone() const
__Bool* clone() const
{
return Bool::create(_value);
return __Bool::create(_value);
}
private:
bool _value;

View File

@ -74,7 +74,7 @@ static void printSceneGraph(int fd, Node* node, int level)
for(int i=0; i<level; ++i)
write(fd, "-", 1);
mydprintf(fd, " %s: z=%d, tag=%d\n", node->description(), node->getZOrder(), node->getTag());
mydprintf(fd, " %s: z=%d, tag=%d\n", node->description().c_str(), node->getZOrder(), node->getTag());
for(const auto& child: node->getChildren())
printSceneGraph(fd, child, level+1);

View File

@ -35,27 +35,27 @@
NS_CC_BEGIN
void DataVisitor::visit(const Bool *value)
void DataVisitor::visit(const __Bool *value)
{
visitObject(value);
}
void DataVisitor::visit(const Integer *value)
void DataVisitor::visit(const __Integer *value)
{
visitObject(value);
}
void DataVisitor::visit(const Float *value)
void DataVisitor::visit(const __Float *value)
{
visitObject(value);
}
void DataVisitor::visit(const Double *value)
void DataVisitor::visit(const __Double *value)
{
visitObject(value);
}
void DataVisitor::visit(const String *value)
void DataVisitor::visit(const __String *value)
{
visitObject(value);
}
@ -65,7 +65,7 @@ void DataVisitor::visit(const __Array *value)
visitObject(value);
}
void DataVisitor::visit(const Dictionary *value)
void DataVisitor::visit(const __Dictionary *value)
{
visitObject(value);
}
@ -103,35 +103,35 @@ void PrettyPrinter::visitObject(const Object *p)
_result += buf;
}
void PrettyPrinter::visit(const Bool * p)
void PrettyPrinter::visit(const __Bool * p)
{
char buf[50] = {0};
sprintf(buf, "%s", p->getValue() ? "true" : "false");
_result += buf;
}
void PrettyPrinter::visit(const Integer *p)
void PrettyPrinter::visit(const __Integer *p)
{
char buf[50] = {0};
sprintf(buf, "%d", p->getValue());
_result += buf;
}
void PrettyPrinter::visit(const Float *p)
void PrettyPrinter::visit(const __Float *p)
{
char buf[50] = {0};
sprintf(buf, "%f", p->getValue());
_result += buf;
}
void PrettyPrinter::visit(const Double *p)
void PrettyPrinter::visit(const __Double *p)
{
char buf[50] = {0};
sprintf(buf, "%lf", p->getValue());
_result += buf;
}
void PrettyPrinter::visit(const String *p)
void PrettyPrinter::visit(const __String *p)
{
_result += p->getCString();
}
@ -165,7 +165,7 @@ void PrettyPrinter::visit(const __Array *p)
_result += "</array>";
}
void PrettyPrinter::visit(const Dictionary *p)
void PrettyPrinter::visit(const __Dictionary *p)
{
_result += "\n";
_result += _indentStr;

View File

@ -31,13 +31,13 @@
NS_CC_BEGIN
class Object;
class Bool;
class Integer;
class Float;
class Double;
class String;
class __Bool;
class __Integer;
class __Float;
class __Double;
class __String;
class __Array;
class Dictionary;
class __Dictionary;
class __Set;
class Data;
@ -52,7 +52,7 @@ class Data;
* Use cases:
* - data serialization,
* - pretty printing of Object *
* - safe value reading from Array, Dictionary, Set
* - safe value reading from Array, __Dictionary, Set
*
* Usage:
* 1. subclass DataVisitor
@ -72,13 +72,13 @@ public:
/** default method, called from non-overloaded methods and for unrecognized objects */
virtual void visitObject(const Object *p) = 0;
virtual void visit(const Bool *p);
virtual void visit(const Integer *p);
virtual void visit(const Float *p);
virtual void visit(const Double *p);
virtual void visit(const String *p);
virtual void visit(const __Bool *p);
virtual void visit(const __Integer *p);
virtual void visit(const __Float *p);
virtual void visit(const __Double *p);
virtual void visit(const __String *p);
virtual void visit(const __Array *p);
virtual void visit(const Dictionary *p);
virtual void visit(const __Dictionary *p);
virtual void visit(const __Set *p);
virtual void visit(const Data *p);
};
@ -93,13 +93,13 @@ public:
virtual std::string getResult();
virtual void visitObject(const Object *p);
virtual void visit(const Bool * p);
virtual void visit(const Integer *p);
virtual void visit(const Float *p);
virtual void visit(const Double *p);
virtual void visit(const String *p);
virtual void visit(const __Bool * p);
virtual void visit(const __Integer *p);
virtual void visit(const __Float *p);
virtual void visit(const __Double *p);
virtual void visit(const __String *p);
virtual void visit(const __Array *p);
virtual void visit(const Dictionary *p);
virtual void visit(const __Dictionary *p);
virtual void visit(const __Set *p);
virtual void visit(const Data *p);
private:

View File

@ -68,27 +68,27 @@ DictElement::~DictElement()
}
// -----------------------------------------------------------------------
// Dictionary
// __Dictionary
Dictionary::Dictionary()
__Dictionary::__Dictionary()
: _elements(NULL)
, _dictType(kDictUnknown)
{
}
Dictionary::~Dictionary()
__Dictionary::~__Dictionary()
{
CCLOGINFO("deallocing Dictionary: %p", this);
CCLOGINFO("deallocing __Dictionary: %p", this);
removeAllObjects();
}
unsigned int Dictionary::count()
unsigned int __Dictionary::count()
{
return HASH_COUNT(_elements);
}
__Array* Dictionary::allKeys()
__Array* __Dictionary::allKeys()
{
int iKeyCount = this->count();
if (iKeyCount <= 0) return NULL;
@ -100,7 +100,7 @@ __Array* Dictionary::allKeys()
{
HASH_ITER(hh, _elements, pElement, tmp)
{
String* pOneKey = new String(pElement->_strKey);
__String* pOneKey = new __String(pElement->_strKey);
array->addObject(pOneKey);
CC_SAFE_RELEASE(pOneKey);
}
@ -109,7 +109,7 @@ __Array* Dictionary::allKeys()
{
HASH_ITER(hh, _elements, pElement, tmp)
{
Integer* pOneKey = new Integer(static_cast<int>(pElement->_intKey));
__Integer* pOneKey = new __Integer(static_cast<int>(pElement->_intKey));
array->addObject(pOneKey);
CC_SAFE_RELEASE(pOneKey);
}
@ -118,7 +118,7 @@ __Array* Dictionary::allKeys()
return array;
}
__Array* Dictionary::allKeysForObject(Object* object)
__Array* __Dictionary::allKeysForObject(Object* object)
{
int iKeyCount = this->count();
if (iKeyCount <= 0) return NULL;
@ -132,7 +132,7 @@ __Array* Dictionary::allKeysForObject(Object* object)
{
if (object == pElement->_object)
{
String* pOneKey = new String(pElement->_strKey);
__String* pOneKey = new __String(pElement->_strKey);
array->addObject(pOneKey);
CC_SAFE_RELEASE(pOneKey);
}
@ -144,7 +144,7 @@ __Array* Dictionary::allKeysForObject(Object* object)
{
if (object == pElement->_object)
{
Integer* pOneKey = new Integer(static_cast<int>(pElement->_intKey));
__Integer* pOneKey = new __Integer(static_cast<int>(pElement->_intKey));
array->addObject(pOneKey);
CC_SAFE_RELEASE(pOneKey);
}
@ -153,12 +153,12 @@ __Array* Dictionary::allKeysForObject(Object* object)
return array;
}
Object* Dictionary::objectForKey(const std::string& key)
Object* __Dictionary::objectForKey(const std::string& key)
{
// if dictionary wasn't initialized, return NULL directly.
if (_dictType == kDictUnknown) return NULL;
// Dictionary only supports one kind of key, string or integer.
// This method uses string as key, therefore we should make sure that the key type of this Dictionary is string.
// __Dictionary only supports one kind of key, string or integer.
// This method uses string as key, therefore we should make sure that the key type of this __Dictionary is string.
CCASSERT(_dictType == kDictStr, "this dictionary does not use string as key.");
Object* pRetObject = NULL;
@ -171,12 +171,12 @@ Object* Dictionary::objectForKey(const std::string& key)
return pRetObject;
}
Object* Dictionary::objectForKey(intptr_t key)
Object* __Dictionary::objectForKey(intptr_t key)
{
// if dictionary wasn't initialized, return NULL directly.
if (_dictType == kDictUnknown) return NULL;
// Dictionary only supports one kind of key, string or integer.
// This method uses integer as key, therefore we should make sure that the key type of this Dictionary is integer.
// __Dictionary only supports one kind of key, string or integer.
// This method uses integer as key, therefore we should make sure that the key type of this __Dictionary is integer.
CCASSERT(_dictType == kDictInt, "this dictionary does not use integer as key.");
Object* pRetObject = NULL;
@ -189,27 +189,27 @@ Object* Dictionary::objectForKey(intptr_t key)
return pRetObject;
}
const String* Dictionary::valueForKey(const std::string& key)
const __String* __Dictionary::valueForKey(const std::string& key)
{
String* pStr = dynamic_cast<String*>(objectForKey(key));
__String* pStr = dynamic_cast<__String*>(objectForKey(key));
if (pStr == NULL)
{
pStr = String::create("");
pStr = __String::create("");
}
return pStr;
}
const String* Dictionary::valueForKey(intptr_t key)
const __String* __Dictionary::valueForKey(intptr_t key)
{
String* pStr = dynamic_cast<String*>(objectForKey(key));
__String* pStr = dynamic_cast<__String*>(objectForKey(key));
if (pStr == NULL)
{
pStr = String::create("");
pStr = __String::create("");
}
return pStr;
}
void Dictionary::setObject(Object* pObject, const std::string& key)
void __Dictionary::setObject(Object* pObject, const std::string& key)
{
CCASSERT(key.length() > 0 && pObject != NULL, "Invalid Argument!");
if (_dictType == kDictUnknown)
@ -235,7 +235,7 @@ void Dictionary::setObject(Object* pObject, const std::string& key)
}
}
void Dictionary::setObject(Object* pObject, intptr_t key)
void __Dictionary::setObject(Object* pObject, intptr_t key)
{
CCASSERT(pObject != NULL, "Invalid Argument!");
if (_dictType == kDictUnknown)
@ -262,7 +262,7 @@ void Dictionary::setObject(Object* pObject, intptr_t key)
}
void Dictionary::removeObjectForKey(const std::string& key)
void __Dictionary::removeObjectForKey(const std::string& key)
{
if (_dictType == kDictUnknown)
{
@ -276,7 +276,7 @@ void Dictionary::removeObjectForKey(const std::string& key)
removeObjectForElememt(pElement);
}
void Dictionary::removeObjectForKey(intptr_t key)
void __Dictionary::removeObjectForKey(intptr_t key)
{
if (_dictType == kDictUnknown)
{
@ -289,31 +289,31 @@ void Dictionary::removeObjectForKey(intptr_t key)
removeObjectForElememt(pElement);
}
void Dictionary::setObjectUnSafe(Object* pObject, const std::string& key)
void __Dictionary::setObjectUnSafe(Object* pObject, const std::string& key)
{
pObject->retain();
DictElement* pElement = new DictElement(key.c_str(), pObject);
HASH_ADD_STR(_elements, _strKey, pElement);
}
void Dictionary::setObjectUnSafe(Object* pObject, const intptr_t key)
void __Dictionary::setObjectUnSafe(Object* pObject, const intptr_t key)
{
pObject->retain();
DictElement* pElement = new DictElement(key, pObject);
HASH_ADD_PTR(_elements, _intKey, pElement);
}
void Dictionary::removeObjectsForKeys(__Array* pKey__Array)
void __Dictionary::removeObjectsForKeys(__Array* pKey__Array)
{
Object* pObj = NULL;
CCARRAY_FOREACH(pKey__Array, pObj)
{
String* pStr = static_cast<String*>(pObj);
__String* pStr = static_cast<__String*>(pObj);
removeObjectForKey(pStr->getCString());
}
}
void Dictionary::removeObjectForElememt(DictElement* pElement)
void __Dictionary::removeObjectForElememt(DictElement* pElement)
{
if (pElement != NULL)
{
@ -323,7 +323,7 @@ void Dictionary::removeObjectForElememt(DictElement* pElement)
}
}
void Dictionary::removeAllObjects()
void __Dictionary::removeAllObjects()
{
DictElement *pElement, *tmp;
HASH_ITER(hh, _elements, pElement, tmp)
@ -335,7 +335,7 @@ void Dictionary::removeAllObjects()
}
}
Object* Dictionary::randomObject()
Object* __Dictionary::randomObject()
{
if (_dictType == kDictUnknown)
{
@ -346,11 +346,11 @@ Object* Dictionary::randomObject()
if (_dictType == kDictInt)
{
return objectForKey( static_cast<Integer*>(key)->getValue());
return objectForKey( static_cast<__Integer*>(key)->getValue());
}
else if (_dictType == kDictStr)
{
return objectForKey( static_cast<String*>(key)->getCString());
return objectForKey( static_cast<__String*>(key)->getCString());
}
else
{
@ -358,9 +358,9 @@ Object* Dictionary::randomObject()
}
}
Dictionary* Dictionary::create()
__Dictionary* __Dictionary::create()
{
Dictionary* ret = new Dictionary();
__Dictionary* ret = new __Dictionary();
if (ret && ret->init() )
{
ret->autorelease();
@ -368,21 +368,21 @@ Dictionary* Dictionary::create()
return ret;
}
bool Dictionary::init()
bool __Dictionary::init()
{
return true;
}
Dictionary* Dictionary::createWithDictionary(Dictionary* srcDict)
__Dictionary* __Dictionary::createWithDictionary(__Dictionary* srcDict)
{
return srcDict->clone();
}
static __Array* visitArray(const ValueVector& array);
static Dictionary* visitDict(const ValueMap& dict)
static __Dictionary* visitDict(const ValueMap& dict)
{
Dictionary* ret = new Dictionary();
__Dictionary* ret = new __Dictionary();
ret->init();
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
@ -403,7 +403,7 @@ static Dictionary* visitDict(const ValueMap& dict)
}
else
{
auto str = new String(iter->second.asString());
auto str = new __String(iter->second.asString());
ret->setObject(str, iter->first);
str->release();
}
@ -433,7 +433,7 @@ static __Array* visitArray(const ValueVector& array)
}
else
{
auto str = new String(value.asString());
auto str = new __String(value.asString());
ret->addObject(str);
str->release();
}
@ -442,17 +442,17 @@ static __Array* visitArray(const ValueVector& array)
return ret;
}
Dictionary* Dictionary::createWithContentsOfFileThreadSafe(const char *pFileName)
__Dictionary* __Dictionary::createWithContentsOfFileThreadSafe(const char *pFileName)
{
return visitDict(FileUtils::getInstance()->getValueMapFromFile(pFileName));
}
void Dictionary::acceptVisitor(DataVisitor &visitor)
void __Dictionary::acceptVisitor(DataVisitor &visitor)
{
return visitor.visit(this);
}
Dictionary* Dictionary::createWithContentsOfFile(const char *pFileName)
__Dictionary* __Dictionary::createWithContentsOfFile(const char *pFileName)
{
auto ret = createWithContentsOfFileThreadSafe(pFileName);
if (ret != nullptr)
@ -462,21 +462,21 @@ Dictionary* Dictionary::createWithContentsOfFile(const char *pFileName)
return ret;
}
bool Dictionary::writeToFile(const char *fullPath)
bool __Dictionary::writeToFile(const char *fullPath)
{
ValueMap dict;
DictElement* element = nullptr;
CCDICT_FOREACH(this, element)
{
dict[element->getStrKey()] = Value(static_cast<String*>(element->getObject())->getCString());
dict[element->getStrKey()] = Value(static_cast<__String*>(element->getObject())->getCString());
}
return FileUtils::getInstance()->writeToFile(dict, fullPath);
}
Dictionary* Dictionary::clone() const
__Dictionary* __Dictionary::clone() const
{
Dictionary* newDict = Dictionary::create();
__Dictionary* newDict = __Dictionary::create();
DictElement* element = NULL;
Object* tmpObj = NULL;

View File

@ -32,7 +32,7 @@ THE SOFTWARE.
NS_CC_BEGIN
class Dictionary;
class __Dictionary;
/**
* @addtogroup data_structures
@ -131,7 +131,7 @@ private:
Object* _object; // hash value
public:
UT_hash_handle hh; // makes this class hashable
friend class Dictionary; // declare Dictionary as friend class
friend class __Dictionary; // declare Dictionary as friend class
};
/** The macro for traversing dictionary
@ -163,15 +163,15 @@ public:
* pDict->setObject(pValue3, "key3");
*
* // Get the object for key
* String* pStr1 = (String*)pDict->objectForKey("key1");
* String* pStr1 = static_cast<String*>(pDict->objectForKey("key1"));
* log("{ key1: %s }", pStr1->getCString());
* Integer* pInteger = (Integer*)pDict->objectForKey("key3");
* Integer* pInteger = static_cast<Integer*>(pDict->objectForKey("key3"));
* log("{ key3: %d }", pInteger->getValue());
* @endcode
*
*/
class CC_DLL Dictionary : public Object, public Clonable
class CC_DLL __Dictionary : public Object, public Clonable
{
public:
/**
@ -179,14 +179,14 @@ public:
* @js NA
* @lua NA
*/
Dictionary();
__Dictionary();
/**
* The destructor of Dictionary
* @js NA
* @lua NA
*/
~Dictionary();
~__Dictionary();
/** Initializes the dictionary. It returns true if the initializations was successful.
* @js NA
@ -225,7 +225,7 @@ public:
* @return The object matches the key. You need to force convert it to the type you know.
* @code
* // Assume that the elements are String* pointers. Convert it by following code.
* String* pStr = (String*)pDict->objectForKey("key1");
* String* pStr = static_cast<String*>(pDict->objectForKey("key1"));
* // Do something about pStr.
* // If you don't know the object type, properly you need to use dynamic_cast<SomeType*> to check it.
* String* pStr2 = dynamic_cast<String*>(pDict->objectForKey("key1"));
@ -251,25 +251,25 @@ public:
/** Get the value according to the specified string key.
*
* @note Be careful to use this function since it assumes the objects in the dictionary are String pointer.
* @note Be careful to use this function since it assumes the objects in the dictionary are __String pointer.
* @param key The string key for searching
* @return An instance of String.
* It will return an empty string if the objects aren't String pointer or the key wasn't found.
* It will return an empty string if the objects aren't __String pointer or the key wasn't found.
* @see valueForKey(intptr_t)
* @js NA
*/
const String* valueForKey(const std::string& key);
const __String* valueForKey(const std::string& key);
/** Get the value according to the specified integer key.
*
* @note Be careful to use this function since it assumes the objects in the dictionary are String pointer.
* @note Be careful to use this function since it assumes the objects in the dictionary are __String pointer.
* @param key The string key for searching.
* @return An instance of String.
* It will return an empty string if the objects aren't String pointer or the key wasn't found.
* It will return an empty string if the objects aren't __String pointer or the key wasn't found.
* @see valueForKey(intptr_t)
* @js NA
*/
const String* valueForKey(intptr_t key);
const __String* valueForKey(intptr_t key);
/** Insert an object to dictionary, and match it with the specified string key.
*
@ -321,7 +321,7 @@ public:
/**
* Remove objects by an array of keys.
*
* @param pKey__Array The array contains keys to be removed.
* @param pKeyArray The array contains keys to be removed.
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
* removeObjectForElememt(DictElement*), removeAllObjects().
* @js NA
@ -364,7 +364,7 @@ public:
* @see createWithDictionary(Dictionary*), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*).
* @js NA
*/
static Dictionary* create();
static __Dictionary* create();
/**
* Create a dictionary with an existing dictionary.
@ -374,7 +374,7 @@ public:
* @see create(), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*).
* @js NA
*/
static Dictionary* createWithDictionary(Dictionary* srcDict);
static __Dictionary* createWithDictionary(__Dictionary* srcDict);
/**
* Create a dictionary with a plist file.
@ -383,7 +383,7 @@ public:
* @see create(), createWithDictionary(Dictionary*), createWithContentsOfFileThreadSafe(const char*).
* @js NA
*/
static Dictionary* createWithContentsOfFile(const char *pFileName);
static __Dictionary* createWithContentsOfFile(const char *pFileName);
/**
* Write a dictionary to a plist file.
@ -407,7 +407,7 @@ public:
* @js NA
* @lua NA
*/
static Dictionary* createWithContentsOfFileThreadSafe(const char *pFileName);
static __Dictionary* createWithContentsOfFileThreadSafe(const char *pFileName);
/* override functions
* @js NA
@ -418,7 +418,7 @@ public:
* @js NA
* @lua NA
*/
virtual Dictionary* clone() const;
virtual __Dictionary* clone() const;
private:
/**

View File

@ -34,16 +34,16 @@ NS_CC_BEGIN
* @{
*/
class CC_DLL Double : public Object, public Clonable
class CC_DLL __Double : public Object, public Clonable
{
public:
Double(double v)
__Double(double v)
: _value(v) {}
double getValue() const {return _value;}
static Double* create(double v)
static __Double* create(double v)
{
Double* pRet = new Double(v);
__Double* pRet = new __Double(v);
if (pRet)
{
pRet->autorelease();
@ -54,9 +54,9 @@ public:
/* override functions */
virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); }
Double* clone() const
__Double* clone() const
{
return Double::create(_value);
return __Double::create(_value);
}
private:
double _value;

View File

@ -34,16 +34,16 @@ NS_CC_BEGIN
* @{
*/
class CC_DLL Float : public Object, public Clonable
class CC_DLL __Float : public Object, public Clonable
{
public:
Float(float v)
__Float(float v)
: _value(v) {}
float getValue() const {return _value;}
static Float* create(float v)
static __Float* create(float v)
{
Float* pRet = new Float(v);
__Float* pRet = new __Float(v);
if (pRet)
{
pRet->autorelease();
@ -54,9 +54,9 @@ public:
/* override functions */
virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); }
Float* clone() const
__Float* clone() const
{
return Float::create(_value);
return __Float::create(_value);
}
private:

View File

@ -35,36 +35,36 @@ NS_CC_BEGIN
* @{
*/
class CC_DLL Integer : public Object, public Clonable
class CC_DLL __Integer : public Object, public Clonable
{
public:
static Integer* create(int v)
static __Integer* create(int v)
{
Integer* pRet = new Integer(v);
__Integer* pRet = new __Integer(v);
pRet->autorelease();
return pRet;
}
/**
* @js NA
*/
Integer(int v)
__Integer(int v)
: _value(v) {}
int getValue() const {return _value;}
/**
* @js NA
* @lua NA
*/
virtual ~Integer() {
CCLOGINFO("deallocing ~Integer: %p", this);
virtual ~__Integer() {
CCLOGINFO("deallocing ~__Integer: %p", this);
}
/* override functions */
virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); }
// overrides
virtual Integer* clone() const override
virtual __Integer* clone() const override
{
return Integer::create(_value);
return __Integer::create(_value);
}
private:

View File

@ -25,6 +25,8 @@ THE SOFTWARE.
#ifndef __CCMAP_H__
#define __CCMAP_H__
#include "ccMacros.h"
#include <vector>
#include <unordered_map>
#include <algorithm> // std::for_each
@ -40,12 +42,31 @@ template <class K, class V>
class CC_DLL Map
{
public:
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef std::unordered_map<K, V> RefMap;
typedef typename RefMap::iterator iterator;
typedef typename RefMap::const_iterator const_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
/** Default constructor */
Map<K, V>()
: _data()
{
CCLOGINFO("In the default constructor of Map!");
}
/** Contructor with capacity */
explicit Map<K, V>(int capacity)
: _data()
{
@ -53,6 +74,7 @@ public:
_data.reserve(capacity);
}
/** Copy constructor */
Map<K, V>(const Map<K, V>& other)
{
CCLOGINFO("In the copy constructor of Map!");
@ -60,40 +82,50 @@ public:
addRefForAllObjects();
}
/** Move constructor */
Map<K, V>(Map<K, V>&& other)
{
CCLOGINFO("In the move constructor of Map!");
_data = std::move(other._data);
}
/** Destructor
* It will release all objects in map.
*/
~Map<K, V>()
{
CCLOGINFO("In the destructor of Map!");
clear();
}
/** Sets capacity of current array */
/** Sets capacity of the map */
void reserve(int capacity)
{
_data.reserve(capacity);
}
/** Returns capacity of the array */
/** Returns capacity of the map */
size_t capacity() const
{
return _data.capacity();
}
/** The number of elements in the map. */
size_t size() const
{
return _data.size();
}
/** Returns a bool value indicating whether the map container is empty, i.e. whether its size is 0.
* @note This function does not modify the content of the container in any way.
* To clear the content of an array object, member function unordered_map::clear exists.
*/
bool empty() const
{
return _data.empty();
}
/** Returns all keys in the map */
std::vector<K> keys() const
{
std::vector<K> keys;
@ -108,6 +140,7 @@ public:
return keys;
}
/** Returns all keys that matches the object */
std::vector<K> keys(V object) const
{
std::vector<K> keys;
@ -123,40 +156,100 @@ public:
return keys;
}
V at(const K& key) const
/** @brief Returns a reference to the mapped value of the element with key k in the map.
* @note If key does not match the key of any element in the container, the function return nullptr.
* @param key Key value of the element whose mapped value is accessed.
* Member type K is the keys for the elements in the container. defined in Map<K, V> as an alias of its first template parameter (Key).
*/
const V at(const K& key) const
{
auto iter = _data.find(key);
if (iter != _data.end())
return iter->second;
return nullptr;
}
V at(const K& key)
{
auto iter = _data.find(key);
if (iter != _data.end())
return iter->second;
return nullptr;
}
/** @brief Searches the container for an element with 'key' as key and returns an iterator to it if found,
* otherwise it returns an iterator to Map<K, V>::end (the element past the end of the container).
* @param key Key to be searched for.
* Member type 'K' is the type of the keys for the elements in the container,
* defined in Map<K, V> as an alias of its first template parameter (Key).
*
*/
const_iterator find(const K& key) const
{
return _data.find(key);
}
iterator find(const K& key)
{
return _data.find(key);
}
/** @brief Inserts new elements in the map.
* @note If the container has already contained the key, this function will erase the old pair(key, object) and insert the new pair.
* @param key The key to be inserted.
* @param object The object to be inserted.
*/
void insert(const K& key, V object)
{
CCASSERT(object != nullptr, "Object is nullptr!");
remove(key);
erase(key);
_data.insert(std::make_pair(key, object));
object->retain();
}
void remove(const K& key)
/** @brief Removes an element with an iterator from the Map<K, V> container.
* @param position Iterator pointing to a single element to be removed from the Map<K, V>.
* Member type const_iterator is a forward iterator type.
*/
iterator erase(const_iterator position)
{
auto iter = _data.find(key);
CCASSERT(position != _data.cend(), "Invalid iterator!");
position->second->release();
return _data.erase(position);
}
/** @brief Removes an element with an iterator from the Map<K, V> container.
* @param k Key of the element to be erased.
* Member type 'K' is the type of the keys for the elements in the container,
* defined in Map<K, V> as an alias of its first template parameter (Key).
*/
size_t erase(const K& k)
{
auto iter = _data.find(k);
if (iter != _data.end())
{
iter->second->release();
_data.erase(iter);
return 1;
}
return 0;
}
void remove(const std::vector<K>& keys)
/** @brief Removes some elements with a vector which contains keys in the map.
* @param keys Keys of elements to be erased.
*/
void erase(const std::vector<K>& keys)
{
std::for_each(keys.cbegin(), keys.cend(), [this](const K& key){
this->remove(key);
this->erase(key);
});
}
/** All the elements in the Map<K,V> container are dropped:
* their reference count will be decreased, and they are removed from the container,
* leaving it with a size of 0.
*/
void clear()
{
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter)
@ -167,6 +260,9 @@ public:
_data.clear();
}
/** @brief Gets a random object in the map
* @return Returns the random object if the map isn't empty, otherwise it returns nullptr.
*/
V getRandomObject() const
{
if (!_data.empty())
@ -177,23 +273,6 @@ public:
return nullptr;
}
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef std::unordered_map<K, V> RefMap;
typedef typename RefMap::iterator iterator;
typedef typename RefMap::const_iterator const_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
// Don't uses operator since we could not decide whether it needs 'retain'/'release'.
// V& operator[] ( const K& key )
// {
@ -219,6 +298,7 @@ public:
// return _data.at(key);
// }
/** Copy assignment operator */
Map<K, V>& operator= ( const Map<K, V>& other )
{
CCLOGINFO("In the copy assignment operator of Map!");
@ -228,6 +308,7 @@ public:
return *this;
}
/** Move assignment operator */
Map<K, V>& operator= ( Map<K, V>&& other )
{
CCLOGINFO("In the move assignment operator of Map!");
@ -237,6 +318,7 @@ public:
protected:
/** Retains all the objects in the map */
void addRefForAllObjects()
{
for (auto iter = _data.begin(); iter != _data.end(); ++iter)

View File

@ -33,36 +33,36 @@ NS_CC_BEGIN
#define kMaxStringLen (1024*100)
String::String()
__String::__String()
:_string("")
{}
String::String(const char * str)
__String::__String(const char * str)
:_string(str)
{}
String::String(const std::string& str)
__String::__String(const std::string& str)
:_string(str)
{}
String::String(const String& str)
__String::__String(const __String& str)
:_string(str.getCString())
{}
String::~String()
__String::~__String()
{
CCLOGINFO("deallocing String: %p", this);
CCLOGINFO("deallocing __String: %p", this);
_string.clear();
}
String& String::operator= (const String& other)
__String& __String::operator= (const __String& other)
{
_string = other._string;
return *this;
}
bool String::initWithFormatAndValist(const char* format, va_list ap)
bool __String::initWithFormatAndValist(const char* format, va_list ap)
{
bool bRet = false;
char* pBuf = (char*)malloc(kMaxStringLen);
@ -76,7 +76,7 @@ bool String::initWithFormatAndValist(const char* format, va_list ap)
return bRet;
}
bool String::initWithFormat(const char* format, ...)
bool __String::initWithFormat(const char* format, ...)
{
bool bRet = false;
_string.clear();
@ -91,7 +91,7 @@ bool String::initWithFormat(const char* format, ...)
return bRet;
}
int String::intValue() const
int __String::intValue() const
{
if (length() == 0)
{
@ -100,7 +100,7 @@ int String::intValue() const
return atoi(_string.c_str());
}
unsigned int String::uintValue() const
unsigned int __String::uintValue() const
{
if (length() == 0)
{
@ -109,7 +109,7 @@ unsigned int String::uintValue() const
return (unsigned int)atoi(_string.c_str());
}
float String::floatValue() const
float __String::floatValue() const
{
if (length() == 0)
{
@ -118,7 +118,7 @@ float String::floatValue() const
return (float)atof(_string.c_str());
}
double String::doubleValue() const
double __String::doubleValue() const
{
if (length() == 0)
{
@ -127,7 +127,7 @@ double String::doubleValue() const
return atof(_string.c_str());
}
bool String::boolValue() const
bool __String::boolValue() const
{
if (length() == 0)
{
@ -141,27 +141,27 @@ bool String::boolValue() const
return true;
}
const char* String::getCString() const
const char* __String::getCString() const
{
return _string.c_str();
}
int String::length() const
int __String::length() const
{
return static_cast<int>(_string.length());
}
int String::compare(const char * pStr) const
int __String::compare(const char * pStr) const
{
return strcmp(getCString(), pStr);
}
void String::append(const std::string& str)
void __String::append(const std::string& str)
{
_string.append(str);
}
void String::appendWithFormat(const char* format, ...)
void __String::appendWithFormat(const char* format, ...)
{
va_list ap;
va_start(ap, format);
@ -178,7 +178,7 @@ void String::appendWithFormat(const char* format, ...)
}
__Array* String::componentsSeparatedByString(const char *delimiter)
__Array* __String::componentsSeparatedByString(const char *delimiter)
{
__Array* result = __Array::create();
@ -187,23 +187,23 @@ __Array* String::componentsSeparatedByString(const char *delimiter)
{
if(cutAt > 0)
{
result->addObject(String::create(_string.substr(0, cutAt)));
result->addObject(__String::create(_string.substr(0, cutAt)));
}
_string = _string.substr(cutAt + 1);
}
if(_string.length() > 0)
{
result->addObject(String::create(_string));
result->addObject(__String::create(_string));
}
return result;
}
bool String::isEqual(const Object* pObject)
bool __String::isEqual(const Object* pObject)
{
bool bRet = false;
const String* pStr = dynamic_cast<const String*>(pObject);
const __String* pStr = dynamic_cast<const __String*>(pObject);
if (pStr != NULL)
{
if (0 == _string.compare(pStr->_string))
@ -214,16 +214,16 @@ bool String::isEqual(const Object* pObject)
return bRet;
}
String* String::create(const std::string& str)
__String* __String::create(const std::string& str)
{
String* ret = new String(str);
__String* ret = new __String(str);
ret->autorelease();
return ret;
}
String* String::createWithData(const unsigned char* data, int nLen)
__String* __String::createWithData(const unsigned char* data, int nLen)
{
String* ret = NULL;
__String* ret = NULL;
if (data != NULL)
{
char* pStr = (char*)malloc(nLen+1);
@ -235,16 +235,16 @@ String* String::createWithData(const unsigned char* data, int nLen)
memcpy(pStr, data, nLen);
}
ret = String::create(pStr);
ret = __String::create(pStr);
free(pStr);
}
}
return ret;
}
String* String::createWithFormat(const char* format, ...)
__String* __String::createWithFormat(const char* format, ...)
{
String* ret = String::create("");
__String* ret = __String::create("");
va_list ap;
va_start(ap, format);
ret->initWithFormatAndValist(format, ap);
@ -253,25 +253,25 @@ String* String::createWithFormat(const char* format, ...)
return ret;
}
String* String::createWithContentsOfFile(const char* filename)
__String* __String::createWithContentsOfFile(const char* filename)
{
ssize_t size = 0;
unsigned char* data = 0;
String* ret = NULL;
__String* ret = NULL;
data = FileUtils::getInstance()->getFileData(filename, "rb", &size);
ret = String::createWithData(data, static_cast<int>(size));
ret = __String::createWithData(data, static_cast<int>(size));
free(data);
return ret;
}
void String::acceptVisitor(DataVisitor &visitor)
void __String::acceptVisitor(DataVisitor &visitor)
{
visitor.visit(this);
}
String* String::clone() const
__String* __String::clone() const
{
return String::create(_string);
return __String::create(_string);
}
NS_CC_END

View File

@ -31,6 +31,8 @@ THE SOFTWARE.
#include <stdarg.h>
#include <string>
#include <functional>
#include <sstream>
#include "CCObject.h"
NS_CC_BEGIN
@ -40,40 +42,40 @@ NS_CC_BEGIN
* @{
*/
class CC_DLL String : public Object, public Clonable
class CC_DLL __String : public Object, public Clonable
{
public:
/**
* @js NA
* @lua NA
*/
String();
__String();
/**
* @js NA
* @lua NA
*/
String(const char* str);
__String(const char* str);
/**
* @js NA
* @lua NA
*/
String(const std::string& str);
__String(const std::string& str);
/**
* @js NA
* @lua NA
*/
String(const String& str);
__String(const __String& str);
/**
* @js NA
* @lua NA
*/
virtual ~String();
virtual ~__String();
/* override assignment operator
* @js NA
* @lua NA
*/
String& operator= (const String& other);
__String& operator= (const __String& other);
/** init a string with format, it's similar with the c function 'sprintf'
* @js NA
@ -149,29 +151,29 @@ public:
* it means that you needn't do a release operation unless you retain it.
* @js NA
*/
static String* create(const std::string& str);
static __String* create(const std::string& str);
/** create a string with format, it's similar with the c function 'sprintf', the default buffer size is (1024*100) bytes,
* if you want to change it, you should modify the kMaxStringLen macro in String.cpp file.
* if you want to change it, you should modify the kMax__StringLen macro in __String.cpp file.
* @return A String pointer which is an autorelease object pointer,
* it means that you needn't do a release operation unless you retain it.
* @js NA
*/
static String* createWithFormat(const char* format, ...) CC_FORMAT_PRINTF(1, 2);
static __String* createWithFormat(const char* format, ...) CC_FORMAT_PRINTF(1, 2);
/** create a string with binary data
* @return A String pointer which is an autorelease object pointer,
* it means that you needn't do a release operation unless you retain it.
* @js NA
*/
static String* createWithData(const unsigned char* pData, int nLen);
static __String* createWithData(const unsigned char* pData, int nLen);
/** create a string with a file,
* @return A String pointer which is an autorelease object pointer,
* it means that you needn't do a release operation unless you retain it.
* @js NA
*/
static String* createWithContentsOfFile(const char* filename);
static __String* createWithContentsOfFile(const char* filename);
/**
* @js NA
* @lua NA
@ -181,7 +183,7 @@ public:
* @js NA
* @lua NA
*/
virtual String* clone() const;
virtual __String* clone() const;
private:
@ -192,15 +194,53 @@ public:
std::string _string;
};
struct StringCompare : public std::binary_function<String *, String *, bool> {
struct StringCompare : public std::binary_function<__String *, __String *, bool> {
public:
bool operator() (String * a, String * b) const {
bool operator() (__String * a, __String * b) const {
return strcmp(a->getCString(), b->getCString()) < 0;
}
};
#define StringMake(str) String::create(str)
#define ccs StringMake
#define ccs StringMake
class StringUtils
{
public:
template<typename T>
static std::string toString(T arg)
{
std::stringstream ss;
ss << arg;
return ss.str();
}
static std::string format(const char* format, ...) CC_FORMAT_PRINTF(1, 2)
{
#define CC_MAX_STRING_LENGTH (1024*100)
std::string ret;
va_list ap;
va_start(ap, format);
char* buf = (char*)malloc(CC_MAX_STRING_LENGTH);
if (buf != nullptr)
{
vsnprintf(buf, CC_MAX_STRING_LENGTH, format, ap);
ret = buf;
free(buf);
}
va_end(ap);
return ret;
}
};
CC_DEPRECATED_ATTRIBUTE typedef __String String;
// end of data_structure group
/// @}

View File

@ -27,6 +27,8 @@
NS_CC_BEGIN
const Value Value::Null;
Value::Value()
: _vectorData(new ValueVector())
, _mapData(new ValueMap())
@ -580,7 +582,7 @@ std::string Value::asString() const
ret << _baseData.doubleVal;
break;
case Type::BOOLEAN:
ret << _baseData.boolVal;
ret << (_baseData.boolVal ? "true" : "false");
break;
default:
break;
@ -588,6 +590,97 @@ std::string Value::asString() const
return ret.str();
}
static std::string getTabs(int depth)
{
std::string tabWidth;
for (int i = 0; i < depth; ++i)
{
tabWidth += "\t";
}
return tabWidth;
}
static std::string visit(const Value& v, int depth);
static std::string visitVector(const ValueVector& v, int depth)
{
std::stringstream ret;
if (depth > 0)
ret << "\n";
ret << getTabs(depth) << "[\n";
int i = 0;
for (const auto& child : v)
{
ret << getTabs(depth+1) << i << ": " << visit(child, depth + 1);
++i;
}
ret << getTabs(depth) << "]\n";
return ret.str();
}
static std::string visitMap(const ValueMap& v, int depth)
{
std::stringstream ret;
if (depth > 0)
ret << "\n";
ret << getTabs(depth) << "{\n";
for (auto iter = v.begin(); iter != v.end(); ++iter)
{
ret << getTabs(depth + 1) << iter->first << ": ";
ret << visit(iter->second, depth + 1);
}
ret << getTabs(depth) << "}\n";
return ret.str();
}
static std::string visit(const Value& v, int depth)
{
std::stringstream ret;
switch (v.getType())
{
case Value::Type::BYTE:
case Value::Type::INTEGER:
case Value::Type::FLOAT:
case Value::Type::DOUBLE:
case Value::Type::BOOLEAN:
case Value::Type::STRING:
ret << v.asString() << "\n";
break;
case Value::Type::VECTOR:
ret << visitVector(v.asValueVector(), depth);
break;
case Value::Type::MAP:
ret << visitMap(v.asValueMap(), depth);
break;
case Value::Type::INT_KEY_MAP:
break;
default:
break;
}
return ret.str();
}
std::string Value::getDescription()
{
std::string ret("\n");
ret += visit(*this, 0);
return ret;
}
void Value::clear()
{
_type = Type::NONE;

View File

@ -42,6 +42,8 @@ typedef std::unordered_map<int, Value> IntValueMap;
class Value
{
public:
static const Value Null;
Value();
explicit Value(unsigned char v);
explicit Value(int v);
@ -119,10 +121,11 @@ public:
inline Type getType() const { return _type; };
protected:
void clear();
std::string getDescription();
private:
void clear();
union
{
unsigned char byteVal;

View File

@ -37,13 +37,41 @@ template<class T>
class CC_DLL Vector
{
public:
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef typename std::vector<T>::reverse_iterator reverse_iterator;
typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
reverse_iterator rbegin() { return _data.rbegin(); }
const_reverse_iterator rbegin() const { return _data.rbegin(); }
reverse_iterator rend() { return _data.rend(); }
const_reverse_iterator rend() const { return _data.rend(); }
const_reverse_iterator crbegin() const { return _data.crbegin(); }
const_reverse_iterator crend() const { return _data.crend(); }
/** Constructor */
Vector<T>()
: _data()
{
}
/** creates an emptry Vector */
/** Constructor with a capacity */
explicit Vector<T>(int capacity)
: _data()
{
@ -51,12 +79,14 @@ public:
reserve(capacity);
}
/** Destructor */
~Vector<T>()
{
CCLOGINFO("In the destructor of Vector.");
clear();
}
/** Copy constructor */
Vector<T>(const Vector<T>& other)
{
CCLOGINFO("In the copy constructor!");
@ -71,6 +101,7 @@ public:
_data = std::move(other._data);
}
/** Copy assignment operator */
Vector<T>& operator=(const Vector<T>& other)
{
CCLOGINFO("In the copy assignment operator!");
@ -80,6 +111,7 @@ public:
return *this;
}
/** Move assignment operator */
Vector<T>& operator=(Vector<T>&& other)
{
CCLOGINFO("In the move assignment operator!");
@ -98,65 +130,93 @@ public:
// return _data[index];
// }
/** Sets capacity of current array */
void reserve(int capacity)
/** @brief Request a change in capacity
* @param capacity Minimum capacity for the vector.
* If n is greater than the current vector capacity,
* the function causes the container to reallocate its storage increasing its capacity to n (or greater).
*/
void reserve(int n)
{
_data.reserve(capacity);
_data.reserve(n);
}
/** Returns capacity of the array */
/** @brief Returns the size of the storage space currently allocated for the vector, expressed in terms of elements.
* @note This capacity is not necessarily equal to the vector size.
* It can be equal or greater, with the extra space allowing to accommodate for growth without the need to reallocate on each insertion.
* @return The size of the currently allocated storage capacity in the vector, measured in terms of the number elements it can hold.
*/
int capacity() const
{
return _data.capacity();
}
// Querying an Array
/** Returns element count of the array */
/** @brief Returns the number of elements in the vector.
* @note This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.
* @return The number of elements in the container.
*/
int size() const
{
return static_cast<int>(_data.size());
}
/** @brief Returns whether the vector is empty (i.e. whether its size is 0).
* @note This function does not modify the container in any way. To clear the content of a vector, see Vector<T>::clear.
*/
bool empty() const
{
return _data.empty();
}
/** Returns the maximum number of elements that the vector can hold. */
size_t max_size() const
{
return _data.max_size();
}
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
int getIndex(T object) const
{
int i = 0;
for (auto it = _data.begin(); it != _data.end(); ++it, ++i)
{
if (*it == object)
{
return i;
}
}
auto iter = std::find(_data.begin(), _data.end(), object);
if (iter != _data.end())
return iter - _data.begin();
return -1;
}
/** Returns an element with a certain index */
/** @brief Find the object in the vector.
* @return Returns an iterator to the first element in the range [first,last) that compares equal to val.
* If no such element is found, the function returns last.
*/
const_iterator find(T object) const
{
return std::find(_data.begin(), _data.end(), object);
}
iterator find(T object)
{
return std::find(_data.begin(), _data.end(), object);
}
/** Returns the element at position 'index' in the vector. */
T at(int index) const
{
CCASSERT( index >= 0 && index < size(), "index out of range in getObjectAtIndex()");
return _data[index];
}
/** Returns the first element in the vector. */
T front() const
{
return _data.front();
}
/** Returns the last element of the array */
/** Returns the last element of the vector. */
T back() const
{
return _data.back();
}
/** Returns a random element */
/** Returns a random element of the vector. */
T getRandomObject() const
{
if (!_data.empty())
@ -167,13 +227,13 @@ public:
return nullptr;
}
/** Returns a Boolean value that indicates whether object is present in array. */
/** Returns a Boolean value that indicates whether object is present in vector. */
bool contains(T object) const
{
return( std::find(_data.begin(), _data.end(), object) != _data.end() );
}
/** returns true if the the arrays are equal */
/** Returns true if the two vectors are equal */
bool equals(const Vector<T> &other)
{
size_t s = this->size();
@ -190,9 +250,13 @@ public:
return true;
}
// Adding Objects
/** Add a certain object */
// Adds objects
/** @brief Adds a new element at the end of the vector, after its current last element.
* @note This effectively increases the container size by one,
* which causes an automatic reallocation of the allocated storage space
* if -and only if- the new vector size surpasses the current vector capacity.
*/
void pushBack(T object)
{
CCASSERT(object != nullptr, "The object should not be nullptr");
@ -200,7 +264,7 @@ public:
object->retain();
}
/** Add all elements of an existing array */
/** Inserts all elements of an existing vector */
void insert(const Vector<T>& other)
{
for( auto it = other.begin(); it != other.end(); ++it ) {
@ -209,7 +273,12 @@ public:
}
}
/** Insert a certain object at a certain index */
/** @brief Insert a certain object at a certain index
* @note The vector is extended by inserting new elements before the element at the specified 'index',
* effectively increasing the container size by the number of elements inserted.
* This causes an automatic reallocation of the allocated storage space
* if -and only if- the new vector size surpasses the current vector capacity.
*/
void insert(int index, T object)
{
CCASSERT(index >= 0 && index <= size(), "Invalid index!");
@ -218,9 +287,11 @@ public:
object->retain();
}
// Removing Objects
// Removes Objects
/** Remove last object */
/** Removes the last element in the vector,
* effectively reducing the container size by one, decrease the referece count of the deleted object.
*/
void popBack()
{
CCASSERT(!_data.empty(), "no objects added");
@ -228,9 +299,12 @@ public:
_data.pop_back();
last->release();
}
/** Remove a certain object */
void removeObject(T object, bool toRelease = true)
/** @brief Remove a certain object.
* @param object The object to be removed.
* @param toRelease Whether to decrease the referece count of the deleted object.
*/
void erase(T object, bool toRelease = true)
{
CCASSERT(object != nullptr, "The object should not be nullptr");
auto iter = std::find(_data.begin(), _data.end(), object);
@ -240,16 +314,50 @@ public:
object->release();
}
/** Removes an element with a certain index */
void remove(int index)
/** @brief Removes from the vector with an iterator.
* @param position Iterator pointing to a single element to be removed from the vector.
* @return An iterator pointing to the new location of the element that followed the last element erased by the function call.
* This is the container end if the operation erased the last element in the sequence.
*/
iterator erase(iterator position)
{
CCASSERT(position >= _data.begin() && position < _data.end(), "Invalid position!");
(*position)->release();
return _data.erase(position);
}
/** @brief Removes from the vector with a range of elements ( [first, last) ).
* @param first The beginning of the range
* @param last The end of the range, the 'last' will not used, it's only for indicating the end of range.
* @return An iterator pointing to the new location of the element that followed the last element erased by the function call.
* This is the container end if the operation erased the last element in the sequence.
*/
iterator erase(const_iterator first, const_iterator last)
{
for (auto iter = first; iter != last; ++iter)
{
(*iter)->release();
}
return _data.erase(first, last);
}
/** @brief Removes from the vector with an index.
* @param index The index of the element to be removed from the vector.
* @return An iterator pointing to the new location of the element that followed the last element erased by the function call.
* This is the container end if the operation erased the last element in the sequence.
*/
iterator erase(int index)
{
CCASSERT(!_data.empty() && index >=0 && index < size(), "Invalid index!");
auto it = std::next( begin(), index );
(*it)->release();
_data.erase(it);
return _data.erase(it);
}
/** Removes all objects */
/** @brief Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.
* @note All the elements in the vector will be released (referece count will be decreased).
*/
void clear()
{
for( auto it = std::begin(_data); it != std::end(_data); ++it ) {
@ -290,18 +398,19 @@ public:
object->retain();
}
/** reverses the array */
/** reverses the vector */
void reverse()
{
std::reverse( std::begin(_data), std::end(_data) );
}
/** Shrinks the array so the memory footprint corresponds with the number of items */
/** Shrinks the vector so the memory footprint corresponds with the number of items */
void shrinkToFit()
{
_data.shrink_to_fit();
}
/** Traverses through the vector and applys the callback function for each element */
void forEach(const std::function<void(T)>& callback)
{
if (empty())
@ -312,6 +421,7 @@ public:
});
}
/** Traverses through the vector and applys the callback function for each element */
void forEach(const std::function<void(T)>& callback) const
{
if (empty())
@ -322,6 +432,7 @@ public:
});
}
/** Traverses through the vector in reversed order and applys the callback function for each element */
void forEachReverse(const std::function<void(T)>& callback)
{
if (empty())
@ -332,6 +443,7 @@ public:
});
}
/** Traverses through the vector in reversed order and applys the callback function for each element */
void forEachReverse(const std::function<void(T)>& callback) const
{
if (empty())
@ -342,6 +454,11 @@ public:
});
}
/** @brief Sorts all elements in the vector according the binary callback function.
* @param callback Binary function that accepts two elements in the vector as arguments,
* and returns a value convertible to bool.
* The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines.
*/
void sort(const std::function<bool(T, T)>& callback)
{
if (empty())
@ -352,35 +469,9 @@ public:
});
}
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef typename std::vector<T>::reverse_iterator reverse_iterator;
typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
reverse_iterator rbegin() { return _data.rbegin(); }
const_reverse_iterator rbegin() const { return _data.rbegin(); }
reverse_iterator rend() { return _data.rend(); }
const_reverse_iterator rend() const { return _data.rend(); }
const_reverse_iterator crbegin() const { return _data.crbegin(); }
const_reverse_iterator crend() const { return _data.crend(); }
protected:
/** Retains all the objects in the vector */
void addRefForAllObjects()
{
std::for_each(_data.begin(), _data.end(), [](T obj){

View File

@ -312,7 +312,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
if(bone->getParentBone())
{
bone->getParentBone()->getChildren().removeObject(bone);
bone->getParentBone()->getChildren().erase(bone);
bone->setParentBone(nullptr);
}

View File

@ -335,7 +335,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion)
bone->getDisplayManager()->setCurrentDecorativeDisplay(nullptr);
_children.removeObject(bone);
_children.erase(bone);
}
}

View File

@ -118,7 +118,7 @@ void HttpClient::networkThread()
if (!s_requestQueue->empty())
{
request = s_requestQueue->at(0);
s_requestQueue->remove(0);
s_requestQueue->erase(0);
}
s_requestQueueMutex.unlock();
@ -480,7 +480,7 @@ void HttpClient::dispatchResponseCallbacks()
if (!s_responseQueue->empty())
{
response = s_responseQueue->at(0);
s_responseQueue->remove(0);
s_responseQueue->erase(0);
}
s_responseQueueMutex.unlock();

View File

@ -672,7 +672,7 @@ void PhysicsBody::removeShape(PhysicsShape* shape, bool reduceMassAndMoment/* =
// set shape->_body = nullptr make the shape->setBody will not trigger the _body->removeShape function call.
shape->_body = nullptr;
shape->setBody(nullptr);
_shapes.removeObject(shape);
_shapes.erase(shape);
}
}

View File

@ -628,20 +628,22 @@ void PhysicsWorld::doAddBody(PhysicsBody* body)
void PhysicsWorld::addBodyOrDelay(PhysicsBody* body)
{
if (_delayRemoveBodies.getIndex(body) != CC_INVALID_INDEX)
auto removeBodyIter = _delayRemoveBodies.find(body);
if (removeBodyIter != _delayRemoveBodies.end())
{
_delayRemoveBodies.removeObject(body);
_delayRemoveBodies.erase(removeBodyIter);
return;
}
if (_info->isLocked())
{
if (_delayAddBodies.getIndex(body) == CC_INVALID_INDEX)
if (_delayAddBodies.find(body) == _delayAddBodies.end())
{
_delayAddBodies.pushBack(body);
_delayDirty = true;
}
}else
}
else
{
doAddBody(body);
}
@ -712,7 +714,7 @@ void PhysicsWorld::removeBody(PhysicsBody* body)
body->_joints.clear();
removeBodyOrDelay(body);
_bodies.removeObject(body);
_bodies.erase(body);
body->_world = nullptr;
}
@ -721,7 +723,7 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
{
if (_delayAddBodies.getIndex(body) != CC_INVALID_INDEX)
{
_delayAddBodies.removeObject(body);
_delayAddBodies.erase(body);
return;
}
@ -935,7 +937,7 @@ void PhysicsWorld::doRemoveBody(PhysicsBody* body)
// remove shaps
for (auto& shape : body->getShapes())
{
removeShape(dynamic_cast<PhysicsShape*>(shape));
removeShape(shape);
}
// remove body
@ -949,9 +951,8 @@ void PhysicsWorld::doRemoveJoint(PhysicsJoint* joint)
void PhysicsWorld::removeAllBodies()
{
for (auto& obj : _bodies)
for (auto& child : _bodies)
{
PhysicsBody* child = dynamic_cast<PhysicsBody*>(obj);
removeBodyOrDelay(child);
child->_world = nullptr;
}

@ -1 +1 @@
Subproject commit d8bd5f3e890e578deeeeb39889359935da7dc55c
Subproject commit dc780f0ca828c53d31c3daddf10606e187b197d6

View File

@ -149,7 +149,7 @@ void ccvector_to_luaval(lua_State* L,const cocos2d::Vector<T>& inValue)
{
long typeId = typeid(*obj).hash_code();
auto iter = g_luaType.find(typeId);
if (g_luaType.end() == iter)
if (g_luaType.end() != iter)
{
lua_pushnumber(L, (lua_Number)indexTable);
int ID = (obj) ? (int)obj->_ID : -1;

View File

@ -1 +1 @@
19467d03b8f48f5f1933d53c756dfda6ab9e7126
4604aa76ce1cd72165190c09b5eba4faf2efca40

View File

@ -16,8 +16,6 @@ class GLNode:public cocos2d::Node
virtual void draw();
};
TOLUA_API int tolua_Cocos2d_CCDrawNode_drawPolygon00(lua_State* tolua_S);
TOLUA_API int tolua_opengl_open(lua_State* tolua_S);
TOLUA_API int register_glnode_manual(lua_State* tolua_S);

View File

@ -207,7 +207,7 @@ void Control::removeTargetWithActionForControlEvent(Object* target, Handler acti
// Remove the corresponding invocation object
if (shouldBeRemoved)
{
eventInvocationList.removeObject(invocation, bDeleteObjects);
eventInvocationList.erase(invocation, bDeleteObjects);
}
});
}

View File

@ -242,7 +242,7 @@ TableViewCell *TableView::dequeueCell()
} else {
cell = _cellsFreed.at(0);
cell->retain();
_cellsFreed.remove(0);
_cellsFreed.erase(0);
cell->autorelease();
}
return cell;
@ -397,7 +397,7 @@ void TableView::_moveCellOutOfSight(TableViewCell *cell)
}
_cellsFreed.pushBack(cell);
_cellsUsed.removeObject(cell);
_cellsUsed.erase(cell);
_isUsedCellsDirty = true;
_indices->erase(cell->getIdx());

View File

@ -121,13 +121,13 @@ void ConfigurationQuery::onEnter()
{
ConfigurationBase::onEnter();
CCLOG("cocos2d version: %s", Configuration::getInstance()->getCString("cocos2d.version") );
CCLOG("OpenGL version: %s", Configuration::getInstance()->getCString("gl.version") );
CCLOG("cocos2d version: %s", Configuration::getInstance()->getValue("cocos2d.x.version").asString().c_str() );
CCLOG("OpenGL version: %s", Configuration::getInstance()->getValue("gl.version").asString().c_str() );
}
std::string ConfigurationQuery::subtitle()
{
return "Using getCString(). Check the console";
return "Check the console";
}
//------------------------------------------------------------------
@ -156,19 +156,19 @@ void ConfigurationDefault::onEnter()
{
ConfigurationBase::onEnter();
const char *c_value = Configuration::getInstance()->getCString("invalid.key", "no key");
if( strcmp(c_value, "no key") != 0 )
std::string c_value = Configuration::getInstance()->getValue("invalid.key", Value("no key")).asString();
if( c_value != "no key" )
CCLOG("1. Test failed!");
else
CCLOG("1. Test OK!");
bool b_value = Configuration::getInstance()->getBool("invalid.key", true);
bool b_value = Configuration::getInstance()->getValue("invalid.key", Value(true)).asBool();
if( ! b_value )
CCLOG("2. Test failed!");
else
CCLOG("2. Test OK!");
double d_value = Configuration::getInstance()->getNumber("invalid.key", 42.42);
double d_value = Configuration::getInstance()->getValue("invalid.key", Value(42.42)).asDouble();
if( d_value != 42.42 )
CCLOG("3. Test failed!");
else
@ -192,9 +192,9 @@ void ConfigurationSet::onEnter()
Configuration *conf = Configuration::getInstance();
conf->setObject("this.is.an.int.value", Integer::create(10) );
conf->setObject("this.is.a.bool.value", Bool::create(true) );
conf->setObject("this.is.a.string.value", String::create("hello world") );
conf->setValue("this.is.an.int.value", Value(10) );
conf->setValue("this.is.a.bool.value", Value(true) );
conf->setValue("this.is.a.string.value", Value("hello world") );
conf->dumpInfo();
}