コード例 #1
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::Concat(ArrayBase *outResult,const char *inSecond,int inLen)
{
   char *ptr =  outResult->GetBase();
   int n = length * GetElementSize();
   memcpy(ptr,mBase,n);
   ptr += n;
   memcpy(ptr,inSecond,inLen*GetElementSize());

}
コード例 #2
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::EnsureSize(int inSize) const
{
   int s = inSize;
   if (s>length)
   {
      if (s>mAlloc)
      {
         mAlloc = s*3/2 + 10;
         int bytes = mAlloc * GetElementSize();
         if (mBase)
         {
            mBase = (char *)hx::GCRealloc(mBase, bytes );
         }
         else if (AllocAtomic())
         {
            mBase = (char *)hx::NewGCPrivate(0,bytes);
         }
         else
         {
            mBase = (char *)hx::NewGCBytes(0,bytes);
         }
      }
      length = s;
   }
}
コード例 #3
0
ファイル: cpu_buffer.cpp プロジェクト: Mapotempo/omim
void CPUBuffer::Seek(uint32_t elementNumber)
{
  uint32_t offsetFromBegin = GetElementSize() * elementNumber;
  ASSERT(Data() + offsetFromBegin <= Data() + m_memory->size(), ());
  TBase::Seek(elementNumber);
  m_memoryCursor = NonConstData() + offsetFromBegin;
}
コード例 #4
0
ファイル: cpu_buffer.cpp プロジェクト: Mapotempo/omim
CPUBuffer::CPUBuffer(uint8_t elementSize, uint32_t capacity)
  : TBase(elementSize, capacity)
{
  uint32_t memorySize = my::NextPowOf2(GetCapacity() * GetElementSize());
  m_memory = SharedBufferManager::instance().reserveSharedBuffer(memorySize);
  m_memoryCursor = NonConstData();
}
コード例 #5
0
ファイル: execute.c プロジェクト: Distrotech/libiodbc
static SQLLEN
_ConvParam (STMT_t *pstmt, PPARM pparm, SQLULEN row, BOOL bOutput)
{
  SQLLEN octetLen;
  void *value;
  SQLLEN *pInd = NULL;
  SQLLEN elementSize = 0;

  if (pparm->pm_c_type != SQL_C_WCHAR)
    return 0;

  elementSize = GetElementSize (pparm);

  if (pstmt->bind_type)
    {
      /* row-wise binding of parameters in force */
      if (pparm->pm_pOctetLength)
	octetLen = *(SQLLEN *) ((char *) pparm->pm_pOctetLength
	    + row * pstmt->bind_type);
      else
        octetLen = pparm->pm_size;

      if (pparm->pm_pInd)
        pInd = (SQLLEN *) ((char *) pparm->pm_pInd
	        + row * pstmt->bind_type);
    }
  else
    {
      octetLen = pparm->pm_pOctetLength ? pparm->pm_pOctetLength[row] : pparm->pm_size;
      if (pparm->pm_pInd)
        pInd = pparm->pm_pInd + row;
    }

  if (!pInd || (pInd && *pInd == SQL_NULL_DATA))
    return 0;

  if (octetLen == SQL_DATA_AT_EXEC || octetLen <= SQL_LEN_DATA_AT_EXEC_OFFSET)
    {
      value = NULL;
    }
  else
    value = pparm->pm_data;

  if (value == NULL)
    return 0;

  if (pstmt->bind_type)
    /* row-wise binding of parameters in force */
    value = (char *) pparm->pm_data + row * pstmt->bind_type;
  else
    value = (char *) pparm->pm_data + row * elementSize;

  if (bOutput)
    _Conv_A2W(value, pInd, elementSize);
  else
    _Conv_W2A(value, pInd, elementSize);
  return octetLen;

}
コード例 #6
0
ファイル: ExpressionVM.cpp プロジェクト: ezEngine/ezEngine
void ezExpression::Stream::ValidateDataSize(ezUInt32 uiNumInstances, const char* szDataName) const
{
  ezUInt32 uiElementSize = GetElementSize();
  ezUInt32 uiExpectedSize = m_uiByteStride * (uiNumInstances - 1) + uiElementSize;

  EZ_ASSERT_DEV(m_Data.GetCount() >= uiExpectedSize, "{0} data size must be {1} bytes or more. Only {2} bytes given", szDataName,
                uiExpectedSize, m_Data.GetCount());
}
コード例 #7
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::RemoveElement(int inPos)
{
   if (inPos<length)
   {
      int s = GetElementSize();
      memmove(mBase + inPos*s, mBase+inPos*s + s, (length-inPos-1)*s );
      __SetSize(length-1);
   }

}
コード例 #8
0
ファイル: Array.cpp プロジェクト: motion-twin/hxcpp
int ArrayBase::Memcmp(ArrayBase *inOther)
{
   int bytesA = length * GetElementSize();
   int bytesB = inOther->length * inOther->GetElementSize();
   int common = bytesA<bytesB ? bytesA : bytesB;
   int result = memcmp(mBase, inOther->mBase, common);
   if (result)
      return result;
   return bytesA - bytesB;
}
コード例 #9
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::Insert(int inPos)
{
   if (inPos>=length)
      __SetSize(length+1);
   else
   {
      __SetSize(length+1);
      int s = GetElementSize();
      memmove(mBase + inPos*s + s, mBase+inPos*s, (length-inPos-1)*s );
   }
}
コード例 #10
0
ファイル: cpu_buffer.cpp プロジェクト: Mapotempo/omim
void CPUBuffer::UploadData(void const * data, uint32_t elementCount)
{
  uint32_t byteCountToCopy = GetElementSize() * elementCount;
#ifdef DEBUG
  // Memory check
  ASSERT(GetCursor() + byteCountToCopy <= Data() + m_memory->size(), ());
#endif

  memcpy(GetCursor(), data, byteCountToCopy);
  TBase::UploadData(elementCount);
}
コード例 #11
0
ファイル: primvar.cpp プロジェクト: JT-a/USD
void
UsdGeomPrimvar::GetDeclarationInfo(TfToken *name, SdfValueTypeName *typeName,
                                 TfToken *interpolation, 
                                 int *elementSize) const
{
    TF_VERIFY(name && typeName && interpolation && elementSize);

    // We don't have any more efficient access pattern yet, but at least
    // we're still saving client some code
    *name = GetBaseName();
    *typeName = GetTypeName();
    *interpolation = GetInterpolation();
    *elementSize = GetElementSize();
}
コード例 #12
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::__SetSize(int inSize)
{
   if (inSize<length)
   {
      int s = GetElementSize();
      memset(mBase + inSize*s, 0, (length-inSize)*s);
      length = inSize;
   }
   else if (inSize>length)
   {
      EnsureSize(inSize);
      length = inSize;
   }
}
コード例 #13
0
ファイル: GLBuffer.cpp プロジェクト: jhaberstro/joh-engine
 void GLBuffer::SetData(void* source, uint32_t size, uint32_t offset) {
     GLenum target = ResourceTypeToGLTarget(GetType());
     GLenum glusage = ResourceUsageToGLUsage(GetUsage());
     JOH_ASSERT(source != 0, "source data is null");
     JOH_ASSERTF(target != 0, "Error calculating OpenGL target for ResourceType: %i", GetType());
     JOH_ASSERTF(glusage != 0, "Error calculating OpenGL usage for ResourceUsage: %i", GetUsage());
     
     glBindBuffer(target, handle_);
     if (offset == 0) {
         glBufferData(target, size, source, glusage);
         uint32_t elementSize = GetElementSize();
         count_ = size / elementSize;
     }
     else {
         JOH_ASSERT(offset + size <= GetSize(), "offset and size together extends beyond the buffer's allocated memory");
         glBufferSubData(target, offset, size, source);
     }
 }
コード例 #14
0
ファイル: _main_config.c プロジェクト: caoqing32/deviation
int create_element()
{
    int i;
    u16 x,y,w,h;
    for (i = 0; i < NUM_ELEMS; i++)
        if (! ELEM_USED(pc.elem[i]))
            break;
    if (i == NUM_ELEMS)
        return -1;
    y = 1;
    GetElementSize(lp.newelem, &w, &h);
    x = (LCD_WIDTH - w) / 2;
    y = (((LCD_HEIGHT - HEADER_Y) - h) / 2) + HEADER_Y;
    memset(&pc.elem[i], 0, sizeof(struct elem));
    ELEM_SET_X(pc.elem[i], x);
    ELEM_SET_Y(pc.elem[i], y);
    ELEM_SET_TYPE(pc.elem[i], lp.newelem);
    return i;
}
コード例 #15
0
				void* Buff::GetBuffer()
				{
 					if(m_pBuffer==NULL){
						System*	pSys	=	static_cast<System*>(m_pFactoryMgr);

						D3DFORMAT	fmt		=	(	GetElementSize()	==	4				)?D3DFMT_INDEX32	:D3DFMT_INDEX16;
						D3DPOOL		pool	=	(	m_Info.usage		==	enUSAGE_DYNAMIC	)?D3DPOOL_DEFAULT	:D3DPOOL_MANAGED;
						DWORD		dwUsage	=	(	m_Info.usage		==	enUSAGE_DYNAMIC	)?D3DUSAGE_DYNAMIC	:0;

						HRESULT	hr	=	pSys->GetDevice()->CreateIndexBuffer(GetBufferSize(),dwUsage,fmt,pool,&m_pBuffer,NULL);
						
					}
					if(!m_bDirty)
						return	m_pBuffer;
					
					if(m_Info.InitData!=NULL){
						void*	pDest	=	NULL;
						enumBufferFillState	state	=	enBFS_OK;
						HRESULT	hr	=	m_pBuffer->Lock(0,GetBufferSize(),(void**)&pDest,D3DLOCK_DISCARD);
						if(hr == S_OK){
							memcpy(pDest,m_Info.InitData,GetBufferSize());
							m_pBuffer->Unlock();
							SAF_DA(m_Info.InitData);
							m_bDirty	=	false;
							return	m_pBuffer;
						}

					}else	if(m_Info.pCB!=NULL){
						if(m_Info.pCB->IsLoad(this)){
							void*	pOutBuffer		=	NULL;
							U32		uiBufferSize	=	GetBufferSize();
							HRESULT	hr	=	m_pBuffer->Lock(0,uiBufferSize,(void**)&pOutBuffer,D3DLOCK_DISCARD);
							if(SUCCEEDED(hr)){
								m_Info.pCB->OnFill(pOutBuffer,uiBufferSize,this);
								m_pBuffer->Unlock();
								m_bDirty	=	false;
								return	m_pBuffer;
							}
						}
					}
					return	NULL;
				}
コード例 #16
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::__SetSizeExact(int inSize)
{
   if (inSize!=length || inSize!=mAlloc)
   {
      int bytes = inSize * GetElementSize();
      if (mBase)
      {
         mBase = (char *)hx::GCRealloc(mBase, bytes );
      }
      else if (AllocAtomic())
      {
         mBase = (char *)hx::NewGCPrivate(0,bytes);
      }
      else
      {
         mBase = (char *)hx::NewGCBytes(0,bytes);
      }
      mAlloc = length = inSize;
   }
}
コード例 #17
0
ファイル: Array.cpp プロジェクト: motion-twin/hxcpp
void ArrayBase::Blit(int inDestElement, ArrayBase *inSourceArray, int inSourceElement, int inElementCount)
{
   int srcSize = inSourceArray->GetElementSize();
   int srcElems = inSourceArray->length;
   if (inDestElement<0 || inSourceElement<0 || inSourceElement+inElementCount>srcElems)
      hx::Throw( HX_CSTRING("blit out of bounds") );
   if (srcSize!=GetElementSize())
      hx::Throw( HX_CSTRING("blit array mismatch") );

   int newSize = inDestElement + inElementCount;
   if (newSize>length)
      __SetSize(newSize);

   const char *src = inSourceArray->mBase + inSourceElement*srcSize;
   char *dest = mBase + inDestElement*srcSize;
   int len = inElementCount*srcSize;
   if (src+len < dest || dest+len<src)
      memcpy(dest,src,len);
   else
      memmove(dest,src,len);
}
コード例 #18
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::Slice(ArrayBase *outResult,int inPos,int inEnd)
{
   if (inPos<0)
   {
      inPos += length;
      if (inPos<0)
         inPos =0;
   }
   if (inEnd<0)
      inEnd += length;
   if (inEnd>length)
      inEnd = length;
   int n = inEnd - inPos;
   if (n<=0)
      outResult->__SetSize(0);
   else
   {
      outResult->__SetSize(n);
      int s = GetElementSize();
      memcpy(outResult->mBase, mBase+inPos*s, n*s);
   }
}
コード例 #19
0
ファイル: Array.cpp プロジェクト: motion-twin/hxcpp
// Set numeric values to 0, pointers to null, bools to false
void ArrayBase::zero(Dynamic inFirst, Dynamic inCount)
{
   int first = inFirst==null() ? 0 : inFirst->__ToInt();
   if (first<0)
      first+=length;
   if (first<0 || first>=length)
      return;

   int count = length;
   if (inCount!=null())
      count = inCount->__ToInt();
   if (count<0)
      count += length;
   if (count<0)
      return;

   if (first+count > length)
      count = length - first;

   int size = GetElementSize();
   memset(mBase + first*size, 0, count*size);
}
コード例 #20
0
ファイル: Array.cpp プロジェクト: bjitivo/hxcpp
void ArrayBase::Splice(ArrayBase *outResult,int inPos,int inLen)
{
   if (inPos>=length)
   {
      return;
   }
   else if (inPos<0)
   {
      inPos += length;
      if (inPos<0)
         inPos =0;
   }
   if (inLen<0)
      return;
   if (inPos+inLen>length)
      inLen = length - inPos;

   outResult->__SetSize(inLen);
   int s = GetElementSize();
   memcpy(outResult->mBase, mBase+inPos*s, s*inLen);
   memmove(mBase+inPos*s, mBase + (inPos+inLen)*s, (length-(inPos+inLen))*s);
   __SetSize(length-inLen);
}
コード例 #21
0
    SharedPtr<uint8> GLFrameBuffer::readFrameBufferData(int32 x, int32 y, uint32 width, uint32 height, ElementFormat format) {
        GLint prevBuffer;
        glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevBuffer);
        
#if defined(UKN_OSX_REQUEST_OPENGL_32_CORE_PROFILE)
        glBindBuffer(GL_FRAMEBUFFER, mFBO);
#else
        CHECK_GL_CALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO));
#endif
        
        if(width == 0)
            width = this->getViewport().width;
        if(height == 0)
            height = this->getViewport().height;
        
        uint8* texData = new uint8[width * height * GetElementSize(format)];
        CHECK_GL_CALL(glReadPixels(x,
                     y,
                     width,
                     height,
                     element_format_to_gl_format(format),
                     element_format_to_gl_element_type(format),
                     texData));
        
        if(glGetError() != GL_NO_ERROR) {
            log_error("GLGraphicDevice: error when read pixels");
        }
        
#if defined(UKN_OSX_REQUEST_OPENGL_32_CORE_PROFILE)
        CHECK_GL_CALL(glBindBuffer(GL_FRAMEBUFFER, prevBuffer));
#else
        CHECK_GL_CALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, prevBuffer));
#endif
        
        return SharedPtr<uint8>(texData);
    }
コード例 #22
0
ファイル: BulkData.cpp プロジェクト: kidaa/UnrealEngineVR
/**
 * Serialize just the bulk data portion to/ from the passed in memory.
 *
 * @param	Ar					Archive to serialize with
 * @param	Data				Memory to serialize either to or from
 */
void FUntypedBulkData::SerializeBulkData( FArchive& Ar, void* Data )
{
	// skip serializing of unused data
	if( BulkDataFlags & BULKDATA_Unused )
	{
		return;
	}

	// Skip serialization for bulk data of zero length
	const int32 BulkDataSize = GetBulkDataSize();
	if(BulkDataSize == 0)
	{
		return;
	}

	// Allow backward compatible serialization by forcing bulk serialization off if required. Saving also always uses single
	// element serialization so errors or oversight when changing serialization code is recoverable.
	bool bSerializeInBulk = true;
	if( RequiresSingleElementSerialization( Ar ) 
	// Set when serialized like a lazy array.
	|| (BulkDataFlags & BULKDATA_ForceSingleElementSerialization) 
	// We use bulk serialization even when saving 1 byte types (texture & sound bulk data) as an optimization for those.
	|| (Ar.IsSaving() && (GetElementSize() > 1) ) )
	{
		bSerializeInBulk = false;
	}

	// Raw serialize the bulk data without any possiblity for potential endian conversion.
	if( bSerializeInBulk )
	{
		// Serialize data compressed.
		if( BulkDataFlags & BULKDATA_SerializeCompressed )
		{
			Ar.SerializeCompressed( Data, GetBulkDataSize(), GetDecompressionFlags());
		}
		// Uncompressed/ regular serialization.
		else
		{
			Ar.Serialize( Data, GetBulkDataSize() );
		}
	}
	// Serialize an element at a time via the virtual SerializeElement function potentialy allowing and dealing with 
	// endian conversion. Dealing with compression makes this a bit more complex as SerializeCompressed expects the 
	// full data to be compresed en block and not piecewise.
	else
	{
		// Serialize data compressed.
		if( BulkDataFlags & BULKDATA_SerializeCompressed )
		{
			// Placeholder for to be serialized data.
			TArray<uint8> SerializedData;
			
			// Loading, data is compressed in archive and needs to be decompressed.
			if( Ar.IsLoading() )
			{
				// Create space for uncompressed data.
				SerializedData.Empty( GetBulkDataSize() );
				SerializedData.AddUninitialized( GetBulkDataSize() );

				// Serialize data with passed in archive and compress.
				Ar.SerializeCompressed( SerializedData.GetData(), SerializedData.Num(), GetDecompressionFlags());
				
				// Initialize memory reader with uncompressed data array and propagate forced byte swapping
				FMemoryReader MemoryReader( SerializedData, true );
				MemoryReader.SetByteSwapping( Ar.ForceByteSwapping() );

				// Serialize each element individually via memory reader.				
				for( int32 ElementIndex=0; ElementIndex<ElementCount; ElementIndex++ )
				{
					SerializeElement( MemoryReader, Data, ElementIndex );
				}
			}
			// Saving, data is uncompressed in memory and needs to be compressed.
			else if( Ar.IsSaving() )
			{			
				// Initialize memory writer with blank data array and propagate forced byte swapping
				FMemoryWriter MemoryWriter( SerializedData, true );
				MemoryWriter.SetByteSwapping( Ar.ForceByteSwapping() );

				// Serialize each element individually via memory writer.				
				for( int32 ElementIndex=0; ElementIndex<ElementCount; ElementIndex++ )
				{
					SerializeElement( MemoryWriter, Data, ElementIndex );
				}

				// Serialize data with passed in archive and compress.
				Ar.SerializeCompressed( SerializedData.GetData(), SerializedData.Num(), GetDecompressionFlags() );
			}
		}
		// Uncompressed/ regular serialization.
		else
		{
			// We can use the passed in archive if we're not compressing the data.
			for( int32 ElementIndex=0; ElementIndex<ElementCount; ElementIndex++ )
			{
				SerializeElement( Ar, Data, ElementIndex );
			}
		}
	}
}
コード例 #23
0
ファイル: BulkData.cpp プロジェクト: kidaa/UnrealEngineVR
/**
 * Returns the size of the bulk data in bytes.
 *
 * @return Size of the bulk data in bytes
 */
int32 FUntypedBulkData::GetBulkDataSize() const
{
	return GetElementCount() * GetElementSize();
}
コード例 #24
0
ファイル: cpu_buffer.cpp プロジェクト: Mapotempo/omim
uint32_t CPUBuffer::GetCurrentElementNumber() const
{
  uint32_t pointerDiff = static_cast<uint32_t>(GetCursor() - Data());
  ASSERT(pointerDiff % GetElementSize() == 0, ());
  return pointerDiff / GetElementSize();
}
コード例 #25
0
//---------------------------------------------------------------------------
UEProperty::Info UEStructProperty::GetInfo() const
{
	return Info::Create(PropertyType::CustomStruct, GetElementSize(), true, "struct " + MakeUniqueCppName(GetStruct()));
}