2010-07-06 15:46:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
2010-07-06 20:55:05 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCData.h"
|
2011-03-26 13:52:33 +08:00
|
|
|
#include "CCFileUtils.h"
|
2010-07-06 10:19:51 +08:00
|
|
|
|
2010-07-19 11:42:53 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace std;
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-19 11:42:53 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCData::CCData(void)
|
2011-04-01 16:06:53 +08:00
|
|
|
: m_pData(NULL)
|
2010-07-06 10:19:51 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCData::~CCData(void)
|
2010-07-06 10:19:51 +08:00
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(m_pData);
|
2010-07-19 11:42:53 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCData* CCData::dataWithContentsOfFile(const string &strPath)
|
2010-07-19 11:42:53 +08:00
|
|
|
{
|
2011-03-29 11:41:44 +08:00
|
|
|
CCFileData data(strPath.c_str(), "rb");
|
|
|
|
unsigned long nSize = data.getSize();
|
|
|
|
unsigned char* pBuffer = data.getBuffer();
|
2010-07-19 11:42:53 +08:00
|
|
|
|
2010-11-29 10:49:43 +08:00
|
|
|
if (! pBuffer)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-19 11:42:53 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCData *pRet = new CCData();
|
2010-11-29 10:49:43 +08:00
|
|
|
pRet->m_pData = new char[nSize];
|
|
|
|
memcpy(pRet->m_pData, pBuffer, nSize);
|
2010-07-19 11:42:53 +08:00
|
|
|
|
2010-07-28 13:48:13 +08:00
|
|
|
return pRet;
|
2010-07-06 10:19:51 +08:00
|
|
|
}
|
2010-07-06 15:46:45 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void* CCData::bytes(void)
|
2010-07-19 11:42:53 +08:00
|
|
|
{
|
|
|
|
return m_pData;
|
|
|
|
}
|
2010-07-28 11:42:35 +08:00
|
|
|
|
2010-09-29 12:03:21 +08:00
|
|
|
//@todo implement
|
2011-03-07 17:11:57 +08:00
|
|
|
CCData* CCData::dataWithBytes(unsigned char *pBytes, int size)
|
2010-07-28 11:42:35 +08:00
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
CC_UNUSED_PARAM(pBytes);
|
|
|
|
CC_UNUSED_PARAM(size);
|
2010-07-28 11:42:35 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|