加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

我的Cocos2d-x学习笔记(十九)CCString、CCArray

发布时间:2020-12-14 21:25:40 所属栏目:百科 来源:网络整理
导读:一、CCString 代码如下: class CC_DLL CCString : public CCObject{public:CCString();CCString(const char* str);CCString(const std::string str);CCString(const CCString str);CCString operator= (const CCString other);/** convert to int value */i

一、CCString

代码如下:

class CC_DLL CCString : public CCObject
{
public:
	CCString();
	CCString(const char* str);
	CCString(const std::string& str);
	CCString(const CCString& str);
	CCString& operator= (const CCString& other);

	/** convert to int value */
	int intValue() const;

	/** convert to unsigned int value */
	unsigned int uintValue() const;

	/** convert to float value */
	float floatValue() const;

	/** convert to double value */
	double doubleValue() const;

	/** convert to bool value */
	bool boolValue() const;

	/** get the C string */
	const char* getCString() const;

	/** get the length of string */
	unsigned int length() const;

	/** compare to a c string */
	int compare(const char *) const;
	virtual CCObject* copyWithZone(CCZone* pZone);
	virtual bool isEqual(const CCObject* pObject);


	static CCString* create(const std::string& str);
	static CCString* createWithFormat(const char* format,...) CC_FORMAT_PRINTF(1,2);

	/** create a string with binary data
	*/
	static CCString* createWithData(const unsigned char* pData,unsigned long nLen);

	/** create a string with a file,*/
	static CCString* createWithContentsOfFile(const char* pszFileName);
public:
	std::string m_sString;
};


二、CCArray

代码如下:

class CC_DLL CCArray : public CCObject
{
public:
	/** Create an array */
	static CCArray* create();
	/** Create an array with some objects
	*/
	static CCArray* create(CCObject* pObject,...);
	/** Create an array with one object */
	static CCArray* createWithObject(CCObject* pObject);
	/** Create an array with capacity */
	static CCArray* createWithCapacity(unsigned int capacity);
	/** Create an array with an existing array */
	static CCArray* createWithArray(CCArray* otherArray);
	static CCArray* createWithContentsOfFile(const char* pFileName);
	static CCArray* createWithContentsOfFileThreadSafe(const char* pFileName);

	/** Returns element count of the array */
	unsigned int count() const;
	/** Returns capacity of the array */
	unsigned int capacity() const;
	/** Returns index of a certain object,return UINT_MAX if doesn't contain the object */
	unsigned int indexOfObject(CCObject* object) const;
	/** Returns an element with a certain index */
	CCObject* objectAtIndex(unsigned int index);
	/** Returns last element */
	CCObject* lastObject();
	/** Returns a random element */
	CCObject* randomObject();
	/** Returns a Boolean value that indicates whether object is present in array. */
	bool containsObject(CCObject* object) const;

	/** Add a certain object */
	void addObject(CCObject* object);
	/** Add all elements of an existing array */
	void addObjectsFromArray(CCArray* otherArray);
	/** Insert a certain object at a certain index */
	void insertObject(CCObject* object,unsigned int index);

	/** Remove last object */
	void removeLastObject(bool bReleaSEObj = true);
	/** Remove a certain object */
	void removeObject(CCObject* object,bool bReleaSEObj = true);
	/** Remove an element with a certain index */
	void removeObjectAtIndex(unsigned int index,bool bReleaSEObj = true);
	/** Remove all elements */
	void removeObjectsInArray(CCArray* otherArray);
	/** Remove all objects */
	void removeAllObjects();
	/** Fast way to remove a certain object */
	void fastRemoveObject(CCObject* object);
	/** Fast way to remove an element with a certain index */
	void fastRemoveObjectAtIndex(unsigned int index);

	/** Swap two elements */
	void exchangeObject(CCObject* object1,CCObject* object2);
	/** Swap two elements with certain indexes */
	void exchangeObjectAtIndex(unsigned int index1,unsigned int index2);

	/** Replace object at index with another object. */
	void replaceObjectAtIndex(unsigned int uIndex,CCObject* pObject,bool bReleaSEObject = true);

	/** Revers the array */
	void reverSEObjects();
	/* Shrinks the array so the memory footprint corresponds with the number of items */
	void reduceMemoryFootprint();
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读