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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2010-07-06 10:19:51 +08:00
|
|
|
#include "NSData.h"
|
|
|
|
|
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
|
|
|
|
2010-07-06 10:19:51 +08:00
|
|
|
NSData::NSData(void)
|
|
|
|
{
|
2010-07-19 11:42:53 +08:00
|
|
|
m_pData = NULL;
|
2010-07-06 10:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NSData::~NSData(void)
|
|
|
|
{
|
2010-07-19 11:42:53 +08:00
|
|
|
if (m_pData)
|
|
|
|
{
|
|
|
|
delete[] m_pData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 13:48:13 +08:00
|
|
|
NSData* NSData::dataWithContentsOfFile(const string &strPath)
|
2010-07-19 11:42:53 +08:00
|
|
|
{
|
|
|
|
FILE *pFile;
|
2010-08-12 17:39:25 +08:00
|
|
|
if(!(pFile = fopen(strPath.c_str(), "rb")))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-19 11:42:53 +08:00
|
|
|
|
|
|
|
if (! pFile)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-19 14:11:35 +08:00
|
|
|
NSData *pRet = new NSData();
|
|
|
|
|
2010-07-19 11:42:53 +08:00
|
|
|
fseek(pFile, 0, SEEK_END);
|
|
|
|
|
|
|
|
int nSize = ftell(pFile);
|
|
|
|
|
2010-07-28 13:48:13 +08:00
|
|
|
fseek(pFile, 0, SEEK_SET);
|
|
|
|
|
|
|
|
pRet->m_pData = new char[nSize];
|
2010-07-19 11:42:53 +08:00
|
|
|
|
2010-07-28 13:48:13 +08:00
|
|
|
fread(pRet->m_pData, sizeof(char), nSize, pFile);
|
2010-07-19 11:42:53 +08:00
|
|
|
|
|
|
|
fclose(pFile);
|
|
|
|
|
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
|
|
|
|
2010-07-19 11:42:53 +08:00
|
|
|
void* NSData::bytes(void)
|
|
|
|
{
|
|
|
|
return m_pData;
|
|
|
|
}
|
2010-07-28 11:42:35 +08:00
|
|
|
|
|
|
|
///@todo implement
|
2010-08-25 11:44:26 +08:00
|
|
|
NSData* NSData::dataWithBytes(unsigned char *pBytes, int size)
|
2010-07-28 11:42:35 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|