本文整理汇总了C++中SharedBuffer::data方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedBuffer::data方法的具体用法?C++ SharedBuffer::data怎么用?C++ SharedBuffer::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedBuffer
的用法示例。
在下文中一共展示了SharedBuffer::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setTo
status_t String16::insert(size_t pos, const char16_t* chrs, size_t len)
{
const size_t myLen = size();
if (myLen == 0) {
return setTo(chrs, len);
return NO_ERROR;
} else if (len == 0) {
return NO_ERROR;
}
if (pos > myLen) pos = myLen;
#if 0
printf("Insert in to %s: pos=%d, len=%d, myLen=%d, chrs=%s\n",
String8(*this).string(), pos,
len, myLen, String8(chrs, len).string());
#endif
SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
->editResize((myLen+len+1)*sizeof(char16_t));
if (buf) {
char16_t* str = (char16_t*)buf->data();
if (pos < myLen) {
memmove(str+pos+len, str+pos, (myLen-pos)*sizeof(char16_t));
}
memcpy(str+pos, chrs, len*sizeof(char16_t));
str[myLen+len] = 0;
mString = str;
#if 0
printf("Result (%d chrs): %s\n", size(), String8(*this).string());
#endif
return NO_ERROR;
}
return NO_MEMORY;
}
示例2: getEmptyString
static char16_t* allocFromUTF8(const char* u8str, size_t u8len)
{
if (u8len == 0) return getEmptyString();
const uint8_t* u8cur = (const uint8_t*) u8str;
const ssize_t u16len = utf8_to_utf16_length(u8cur, u8len);
if (u16len < 0) {
return getEmptyString();
}
SharedBuffer* buf = SharedBuffer::alloc(sizeof(char16_t)*(u16len+1));
if (buf) {
u8cur = (const uint8_t*) u8str;
char16_t* u16str = (char16_t*)buf->data();
utf8_to_utf16(u8cur, u8len, u16str);
//printf("Created UTF-16 string from UTF-8 \"%s\":", in);
//printHexData(1, str, buf->size(), 16, 1);
//printf("\n");
return u16str;
}
return getEmptyString();
}
示例3: substituteResourceDeliveryTimerFired
void DocumentLoader::substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*)
{
if (m_pendingSubstituteResources.isEmpty())
return;
ASSERT(m_frame && m_frame->page());
if (m_frame->page()->defersLoading())
return;
SubstituteResourceMap copy;
copy.swap(m_pendingSubstituteResources);
SubstituteResourceMap::const_iterator end = copy.end();
for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
RefPtr<ResourceLoader> loader = it->first;
SubstituteResource* resource = it->second.get();
if (resource) {
SharedBuffer* data = resource->data();
loader->didReceiveResponse(resource->response());
loader->didReceiveData(data->data(), data->size(), data->size(), true);
loader->didFinishLoading();
} else {
// A null resource means that we should fail the load.
// FIXME: Maybe we should use another error here - something like "not in cache".
loader->didFail(loader->cannotShowURLError());
}
}
}
示例4: refEncodedData
SkData* ImageFrameGenerator::refEncodedData()
{
// SkData is returned only when full image (encoded) data is received. This is important
// since DeferredImageDecoder::setData is called only once with allDataReceived set to true,
// and after that m_data->m_readBuffer.data() is not changed. See also RELEASE_ASSERT used in
// ThreadSafeDataTransport::data().
SharedBuffer* buffer = 0;
bool allDataReceived = false;
m_data->data(&buffer, &allDataReceived);
if (!allDataReceived)
return nullptr;
{
// Prevents concurrent access to m_encodedData creation.
MutexLocker lock(m_decodeMutex);
if (m_encodedData) {
m_encodedData->ref();
return m_encodedData;
}
// m_encodedData is created with initial reference count == 1. ImageFrameGenerator always holds one
// reference to m_encodedData, as it prevents write access in SkData::writable_data.
m_encodedData = SkData::NewWithProc(buffer->data(), buffer->size(), sharedSkDataReleaseCallback, m_data.get());
// While m_encodedData is referenced, prevent disposing m_data and its content.
// it is dereferenced in sharedSkDataReleaseCallback, called when m_encodedData gets dereferenced.
m_data->ref();
}
// Increase the reference, caller must decrease it. One reference is always kept by ImageFrameGenerator and released
// in destructor.
m_encodedData->ref();
return m_encodedData;
}
示例5: initialize_string16
void initialize_string16()
{
SharedBuffer* buf = SharedBuffer::alloc(sizeof(char16_t));
char16_t* str = (char16_t*)buf->data();
*str = 0;
gEmptyStringBuf = buf;
gEmptyString = str;
}
示例6: getBytesWithOffset
size_t getBytesWithOffset(void *info, void* buffer, size_t offset, size_t count)
{
SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
size_t availBytes = count;
if (offset + count > sharedBuffer->size())
availBytes -= (offset + count) - sharedBuffer->size();
memcpy(buffer, sharedBuffer->data() + offset, availBytes);
return availBytes;
}
示例7: editArrayImpl
void* VectorImpl::editArrayImpl()
{
if (mStorage) {
const SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage);
SharedBuffer* editable = sb->attemptEdit();
if (editable == 0) {
// If we're here, we're not the only owner of the buffer.
// We must make a copy of it.
editable = SharedBuffer::alloc(sb->size());
// Fail instead of returning a pointer to storage that's not
// editable. Otherwise we'd be editing the contents of a buffer
// for which we're not the only owner, which is undefined behaviour.
LOG_ALWAYS_FATAL_IF(editable == NULL);
_do_copy(editable->data(), mStorage, mCount);
release_storage();
mStorage = editable->data();
}
}
return mStorage;
}
示例8:
char* String8::lockBuffer(size_t size)
{
SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
->editResize(size + 1);
if (buf) {
char* str = (char*)buf->data();
mString = str;
return str;
}
return NULL;
}
示例9: allocateBuckets
void* BasicHashtableImpl::allocateBuckets(size_t count) const {
size_t bytes = count * mBucketSize;
SharedBuffer* sb = SharedBuffer::alloc(bytes);
LOG_ALWAYS_FATAL_IF(!sb, "Could not allocate %u bytes for hashtable with %u buckets.",
uint32_t(bytes), uint32_t(count));
void* buckets = sb->data();
for (size_t i = 0; i < count; i++) {
Bucket& bucket = bucketAt(buckets, i);
bucket.cookie = 0;
}
return buckets;
}
示例10: edit
SharedBuffer* SharedBuffer::edit() const
{
if (onlyOwner()) {
return const_cast<SharedBuffer*>(this);
}
SharedBuffer* sb = alloc(mSize);
if (sb) {
memcpy(sb->data(), data(), size());
release();
}
return sb;
}
示例11: sharedBufferGetBytesAtPosition
size_t sharedBufferGetBytesAtPosition(void* info, void* buffer, off_t position, size_t count)
{
SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
size_t sourceSize = sharedBuffer->size();
if (position >= sourceSize)
return 0;
const char* source = sharedBuffer->data() + position;
size_t amount = min<size_t>(count, sourceSize - position);
memcpy(buffer, source, amount);
return amount;
}
示例12: memmove
status_t String16::setTo(const char16_t* other, size_t len)
{
SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
->editResize((len+1)*sizeof(char16_t));
if (buf) {
char16_t* str = (char16_t*)buf->data();
memmove(str, other, len*sizeof(char16_t));
str[len] = 0;
mString = str;
return NO_ERROR;
}
return NO_MEMORY;
}
示例13: initialize_string8
void initialize_string8()
{
#ifdef LIBUTILS_NATIVE
// Bite me, Darwin!
gDarwinIsReallyAnnoying = gDarwinCantLoadAllObjects;
#endif
SharedBuffer* buf = SharedBuffer::alloc(1);
char* str = (char*)buf->data();
*str = 0;
gEmptyStringBuf = buf;
gEmptyString = str;
}
示例14: createFontCustomPlatformData
std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer& buffer)
{
static FT_Library library;
if (!library && FT_Init_FreeType(&library)) {
library = nullptr;
return nullptr;
}
FT_Face freeTypeFace;
if (FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer.data()), buffer.size(), 0, &freeTypeFace))
return nullptr;
return std::make_unique<FontCustomPlatformData>(freeTypeFace, buffer);
}
示例15: canHandleImage
static bool canHandleImage(const SharedBuffer& _data)
{
// We need at least 4 bytes to figure out what kind of image we're dealing with.
if (_data.size() < 4)
return false;
QByteArray data = QByteArray::fromRawData(_data.data(), _data.size());
QBuffer buffer(&data);
if (!buffer.open(QBuffer::ReadOnly))
return false;
return !QImageReader::imageFormat(&buffer).isEmpty();
}