2013-08-22 11:05:06 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-29 08:06:41 +08:00
|
|
|
#include <string.h>
|
2012-09-17 14:27:17 +08:00
|
|
|
#include "CCData.h"
|
2013-08-22 11:05:06 +08:00
|
|
|
#include "platform/CCCommon.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-05-29 08:06:41 +08:00
|
|
|
NS_CC_BEGIN
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Data::Data(unsigned char *pBytes, const unsigned long nSize)
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_size = nSize;
|
|
|
|
_bytes = new unsigned char[_size];
|
|
|
|
memcpy(_bytes, pBytes, _size);
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Data::Data(Data *pData)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_size = pData->_size;
|
|
|
|
_bytes = new unsigned char[_size];
|
|
|
|
memcpy(_bytes, pData->_bytes, _size);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Data::~Data()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-08-22 11:05:06 +08:00
|
|
|
CCLOGINFO("deallocing Data: %p", this);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(_bytes);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
unsigned char* Data::getBytes() const
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _bytes;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
unsigned long Data::getSize() const
|
2013-04-09 02:58:50 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _size;
|
2013-04-09 02:58:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-29 08:06:41 +08:00
|
|
|
NS_CC_END
|