2013-10-12 15:25:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
2013-10-12 15:25:45 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCDATA_H__
|
|
|
|
#define __CCDATA_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCPlatformMacros.h"
|
2013-12-23 13:45:31 +08:00
|
|
|
#include <stdint.h> // for ssize_t on android
|
|
|
|
#include <string> // for ssize_t on linux
|
2013-12-27 14:38:22 +08:00
|
|
|
#include "CCStdC.h" // for ssize_t on window
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-12-18 14:58:17 +08:00
|
|
|
class CC_DLL Data
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-12-18 14:58:17 +08:00
|
|
|
static const Data Null;
|
|
|
|
|
|
|
|
Data();
|
|
|
|
Data(const Data& other);
|
|
|
|
Data(Data&& other);
|
2013-10-12 15:25:45 +08:00
|
|
|
~Data();
|
2013-12-18 14:58:17 +08:00
|
|
|
|
|
|
|
// Assignment operator
|
|
|
|
Data& operator= (const Data& other);
|
|
|
|
Data& operator= (Data&& other);
|
|
|
|
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
unsigned char* getBytes() const;
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
ssize_t getSize() const;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2013-12-18 14:58:17 +08:00
|
|
|
/** Copies the buffer pointer and its size.
|
|
|
|
* @note This method will copy the whole buffer.
|
|
|
|
* Developer should free the pointer after invoking this method.
|
|
|
|
* @see Data::fastSet
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
2014-07-18 07:44:39 +08:00
|
|
|
void copy(const unsigned char* bytes, const ssize_t size);
|
2013-12-18 14:58:17 +08:00
|
|
|
|
2013-12-20 21:41:20 +08:00
|
|
|
/** Fast set the buffer pointer and its size. Please use it carefully.
|
2013-12-18 14:58:17 +08:00
|
|
|
* @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc',
|
|
|
|
* since in the destructor of Data, the buffer will be deleted by 'free'.
|
2013-12-20 21:41:20 +08:00
|
|
|
* @note 1. This method will move the ownship of 'bytes'pointer to Data,
|
|
|
|
* 2. The pointer should not be used outside after it was passed to this method.
|
2013-12-18 14:58:17 +08:00
|
|
|
* @see Data::copy
|
|
|
|
*/
|
|
|
|
void fastSet(unsigned char* bytes, const ssize_t size);
|
|
|
|
|
2013-12-20 21:41:20 +08:00
|
|
|
/** Clears data, free buffer and reset data size */
|
|
|
|
void clear();
|
|
|
|
|
2013-12-18 14:58:17 +08:00
|
|
|
/** Check whether the data is null. */
|
|
|
|
bool isNull() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void move(Data& other);
|
|
|
|
|
2013-10-12 15:25:45 +08:00
|
|
|
private:
|
|
|
|
unsigned char* _bytes;
|
2013-12-05 17:19:01 +08:00
|
|
|
ssize_t _size;
|
2013-10-12 15:25:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __CCDATA_H__
|