axmol/cocos/base/CCData.h

134 lines
3.7 KiB
C
Raw Normal View History

2013-10-12 15:25:45 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
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__
#include "platform/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
2014-09-10 07:50:02 +08:00
#include "platform/CCStdC.h" // for ssize_t on window
2013-10-12 15:25:45 +08:00
NS_CC_BEGIN
2015-03-19 10:33:11 +08:00
/**
2015-03-24 11:15:40 +08:00
* @addtogroup base
* @js NA
* @lua NA
*/
class CC_DLL Data
2013-10-12 15:25:45 +08:00
{
public:
/**
* This parameter is defined for convenient reference if a null Data object is needed.
*/
static const Data Null;
/**
* Constructor of Data.
*/
Data();
/**
* Copy constructor of Data.
*/
Data(const Data& other);
/**
* Copy constructor of Data.
*/
Data(Data&& other);
/**
* Destructor of Data.
*/
2013-10-12 15:25:45 +08:00
~Data();
/**
* Overroads of operator=.
*/
Data& operator= (const Data& other);
/**
* Overroads of operator=.
*/
Data& operator= (Data&& other);
2013-10-12 15:25:45 +08:00
/**
* Gets internal bytes of Data. It will retrun the pointer directly used in Data, so don't delete it.
*
* @return Pointer of bytes used internal in Data.
2013-10-12 15:25:45 +08:00
*/
unsigned char* getBytes() const;
2013-10-12 15:25:45 +08:00
/**
* Gets the size of the bytes.
*
* @return The size of bytes of Data.
2013-10-12 15:25:45 +08:00
*/
2013-12-05 17:19:01 +08:00
ssize_t getSize() const;
2013-10-12 15:25:45 +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-20 21:41:20 +08:00
/** Fast set the buffer pointer and its size. Please use it carefully.
* @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.
* @see Data::copy
*/
void fastSet(unsigned char* bytes, const ssize_t size);
/**
* Clears data, free buffer and reset data size.
*/
2013-12-20 21:41:20 +08:00
void clear();
/**
* Check whether the data is null.
*
* @return True if the the Data is null, false if not.
*/
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
};
2015-03-24 11:15:40 +08:00
/** @} */
2013-10-12 15:25:45 +08:00
NS_CC_END
#endif // __CCDATA_H__