/// \brief /// Inserts an element into this collection and increases its refcounter inline void Insert(RCCLASS *pElement, int iInsertBefore) { VASSERT(pElement); pElement->AddRef(); EnsureCapacity(VPointerArrayHelpers::GetAlignedElementCount(m_iCapacity,m_iCount+1)); VPointerArrayHelpers::InsertPointer((void **)m_ppElements,m_iCount,pElement,iInsertBefore); }
HRESULT D3DVertexCacher::FillSpans(jint spanCount, jint *spans) { HRESULT res; float x1, y1, x2, y2; UINT reqVerts = spanCount*2*3/*vertices per span: two triangles*/; if (spanCount == 0) { return S_OK; } do { UINT vertsInBatch = min(6*(MAX_BATCH_SIZE/6), reqVerts); if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, vertsInBatch))) { reqVerts -= vertsInBatch; do { x1 = ((float)*(spans++)); y1 = ((float)*(spans++)); x2 = ((float)*(spans++)); y2 = ((float)*(spans++)); ADD_TRIANGLE_XYC(x1, y1, x2, y1, x1, y2, color); ADD_TRIANGLE_XYC(x1, y2, x2, y1, x2, y2, color); vertsInBatch -= 6; } while (vertsInBatch > 0); } } while (reqVerts > 0 && SUCCEEDED(res)); return res; }
/// \brief /// Uniquely adds the passed elements to this collection inline VRefCountedCollection<RCCLASS>& operator += ( const VRefCountedCollection<RCCLASS>& other ) { EnsureCapacity(Count() + other.Count()); // might overestimate though for (int i=0;i<other.Count();i++) AddUnique(other.GetAt(i)); return *this; }
HRESULT D3DVertexCacher::FillParallelogram(float fx11, float fy11, float dx21, float dy21, float dx12, float dy12) { HRESULT res; if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) { // correct texel to pixel mapping; see D3DContext::SetTransform() // for non-id tx case if (pCtx->IsIdentityTx()) { fx11 -= 0.5f; fy11 -= 0.5f; } dx21 += fx11; dy21 += fy11; float fx22 = dx21 + dx12; float fy22 = dy21 + dy12; dx12 += fx11; dy12 += fy11; ADD_TRIANGLE_XYUVC(fx11, fy11, dx21, dy21, dx12, dy12, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, color); ADD_TRIANGLE_XYUVC(dx12, dy12, dx21, dy21, fx22, fy22, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, color); } return res; }
bool VMenuItemCollection::Build(VWindowBase *pOwner, TiXmlElement *pNode, const char *szPath, bool bWrite) { // first count int iCount = 0; for (TiXmlElement *pItemNode=pNode->FirstChildElement("control"); pItemNode; pItemNode=pItemNode->NextSiblingElement("control") ) iCount++; EnsureCapacity(iCount); // build all items ("control" nodes) for (TiXmlElement *pItemNode=pNode->FirstChildElement("control"); pItemNode; pItemNode=pItemNode->NextSiblingElement("control") ) { const char *szClassName = XMLHelper::Exchange_String(pItemNode,"class",NULL,bWrite); VASSERT(szClassName != NULL && szClassName[0]); // must be defined! VType *pType = Vision::GetTypeManager()->GetType(szClassName); VASSERT(pType && "Control class not available"); if (!pType) continue; VDlgControlBase *pItem = (VDlgControlBase *)pType->CreateInstance(); // sanity check if (!pItem->IsOfType(Vision::GetTypeManager()->GetType("VDlgControlBase"))) Vision::Error.FatalError("class '%s' is not derived from base class VDlgControlBase",szClassName); pItem->SetParent(pOwner); pItem->Build(pItemNode,szPath,bWrite); pItem->OnBuildFinished(); this->Add(pItem); } return true; }
HRESULT D3DVertexCacher::DrawTexture(float x1, float y1, float x2, float y2, float u11, float v11, float u12, float v12, float u21, float v21, float u22, float v22) { HRESULT res; if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) { // correct texel to pixel mapping; see D3DContext::SetTransform() // for non-id tx case if (pCtx->IsIdentityTx()) { x1 -= 0.5f; y1 -= 0.5f; x2 -= 0.5f; y2 -= 0.5f; } ADD_TRIANGLE_XYUVUVC(x1, y1, x2, y1, x1, y2, u11, v11, u12, v11, u11, v12, u21, v21, u22, v21, u21, v22, color); ADD_TRIANGLE_XYUVUVC(x1, y2, x2, y1, x2, y2, u11, v12, u12, v11, u12, v12, u21, v22, u22, v21, u22, v22, color); } return res; }
void InteropOutputStream::CopyAndShift(const int8_t* src, int32_t off, int32_t len) { EnsureCapacity(pos + len); memcpy(data + pos, src + off, len); Shift(len); }
void Buffer::MoveMem( unsigned int iSrcPos, unsigned int iSrcSize, unsigned int iToPos ) { if ( iSrcSize == 0 ) return; EnsureCapacity( iToPos + iSrcSize ); memmove( GetBase( iToPos ), GetBase( iSrcPos ), iSrcSize ); }
HRESULT D3DVertexCacher::DrawScanlines(jint scanlineCount, jint *scanlines) { HRESULT res; float x1, x2, y; UINT reqVerts = scanlineCount*2/*vertices per line*/; if (scanlineCount == 0) { return S_OK; } do { UINT vertsInBatch = min(2*(MAX_BATCH_SIZE/2), reqVerts); if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, vertsInBatch))) { reqVerts -= vertsInBatch; do { x1 = ((float)*(scanlines++)) +HV_FF3; x2 = ((float)*(scanlines++)) +HV_FF2; y = ((float)*(scanlines++)) +HV_FF1; ADD_LINE_XYC(x1, y, x2, y, color); vertsInBatch -= 2; } while (vertsInBatch > 0); } } while (reqVerts > 0 && SUCCEEDED(res)); return res; }
HRESULT D3DVertexCacher::DrawRect(int x1, int y1, int x2, int y2) { HRESULT res; if ((x2 - x1) < 2 || (y2 - y1) < 2) { return FillRect(x1, y1, x2+1, y2+1); } if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, 4*2))) { float fx1 = (float)x1; float fy1 = (float)y1; float fx2 = (float)x2; float fy2 = (float)y2; // horiz: top left - top right ADD_LINE_XYC(fx1+HV_FF3, fy1+HV_FF1, fx2-1.0f+HV_FF2, fy1+HV_FF1,color); // horiz: bottom left - bottom right ADD_LINE_XYC(fx1+1.0f+HV_FF3, fy2+HV_FF1, fx2+HV_FF2, fy2+HV_FF1,color); // vert : top right - bottom right ADD_LINE_XYC(fx2+HV_FF1, fy1+HV_FF3, fx2+HV_FF1, fy2-1.0f+HV_FF2,color); // vert : top left - bottom left ADD_LINE_XYC(fx1+HV_FF1, fy1+1.0f+HV_FF3, fx1+HV_FF1, fy2+HV_FF2,color); } return res; }
/// \brief /// Ensures the number of elements accessible in the collection matches iCount. /// /// If the current count is bigger, nothing is done. /// If the current count is smaller the additional entries are initialized with NULL. /// /// \param iCount /// The new number of elements to be accessible in the collection. inline void EnsureCount(int iCount) { if (m_iCount >= iCount) return; EnsureCapacity(iCount); m_iCount = iCount; }
/// \brief /// Assignment operator: Copies the collection and handles refcounting gracefully inline VRefCountedCollection<RCCLASS>& operator = ( const VRefCountedCollection<RCCLASS>& other ) { Clear(); EnsureCapacity(other.Count()); for (int i=0;i<other.Count();i++) Add(other.GetAt(i)); return *this; }
/// \brief /// Adds an element to this collection, increases its refcounter and returns its index in the collection. inline int Add(RCCLASS *pElement) { VASSERT(pElement); pElement->AddRef(); EnsureCapacity(VPointerArrayHelpers::GetAlignedElementCount(m_iCapacity,m_iCount+1)); m_ppElements[m_iCount++] = pElement; return m_iCount-1; }
void MemoryStream::EnsureSize(const uint32_t additionalSize) { uint32_t newSize = GetSize() + additionalSize; if (newSize > m_capacity) { EnsureCapacity(newSize); } }
AutoBuffer::AutoBuffer( int iInitialSize ) { m_pData = NULL; m_iSize = 0; m_iWritten = 0; m_iPos = 0; EnsureCapacity( iInitialSize ); }
AutoPtr<IRowBuilder> MatrixCursor::NewRow() { mColumnCount++; Int32 endIndex = mRowCount * mColumnCount; EnsureCapacity(endIndex); Int32 start = endIndex - mColumnCount; AutoPtr<IRowBuilder> builder = new RowBuilder(start, endIndex, this); return builder; }
void ipcMessageWriter::PutInt16(PRUint16 val) { if (EnsureCapacity(sizeof(PRUint16))) { PRUint8 temp[2]; *(PRUint16*)temp = val; *mBufPtr++ = temp[0]; *mBufPtr++ = temp[1]; } }
PRUint32 ipcMessageWriter::PutBytes(const void* src, PRUint32 n) { if (EnsureCapacity(n)) { memcpy(mBufPtr, src, n); mBufPtr += n; return n; } return 0; }
void MemoryStream::SetSize(const uint32_t newSize) { if (newSize > m_capacity) { EnsureCapacity(newSize); } m_size = newSize; m_position = 0; }
void Buffer::Write( const void* pData, unsigned int iSize ) { if ( iSize == 0 ) { return; } if ( !EnsureCapacity( m_iPos + iSize ) ) { return; } memcpy( GetCurrent(), pData, iSize ); m_iPos += iSize; m_iWritten = Bootil::Max( m_iWritten, m_iPos ); }
int32_t InteropOutputStream::Reserve(int32_t num) { EnsureCapacity(pos + num); int32_t res = pos; Shift(num); return res; }
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& o) { EnsureCapacity(o.m_bufferCapacity); if ( m_secure && o.m_bufferSize < m_bufferSize ) Clean(m_buffer+o.m_bufferSize, m_bufferSize-o.m_bufferSize); ::memcpy(m_buffer, o.m_buffer, o.m_bufferSize); m_bufferSize = o.m_bufferSize; return *this; }
int VertexUtil::Append(std::vector<VertexPositionNormalTexture>& rDst, const int dstIndex, const std::vector<VertexPositionNormalTexture>& src) { const int vertexCount = src.size(); EnsureCapacity(rDst, dstIndex + vertexCount); for (int i = 0; i < vertexCount; ++i) { rDst[dstIndex + i] = src[i]; } return vertexCount; }
void ipcMessageWriter::PutInt32(PRUint32 val) { if (EnsureCapacity(sizeof(PRUint32))) { PRUint8 temp[4]; *(PRUint32*)temp = val; *mBufPtr++ = temp[0]; *mBufPtr++ = temp[1]; *mBufPtr++ = temp[2]; *mBufPtr++ = temp[3]; } }
/// \brief /// Ensures that the actual element count (as checked by SetAt()/GetAt()) is no less than iCount, fills the extra elements with NULL. inline void EnsureSize(int iCount) { if (iCount > m_iCapacity) { EnsureCapacity(iCount); } for (; m_iCount < iCount; ++m_iCount) { m_ppElements[m_iCount] = NULL; } }
int CBirthdays::Add(MCONTACT hContact, HANDLE hClistIcon) { if ( !Contains(hContact)) { EnsureCapacity(); TBirthdayContact *item = (TBirthdayContact *) malloc(sizeof(TBirthdayContact)); item->hContact = hContact; item->hClistIcon = hClistIcon; birthdays[count++] = item; return 0; } return -1; }
HRESULT D3DVertexCacher::DrawParallelogramAA(float ox11, float oy11, float ox21, float oy21, float ox12, float oy12, float ix11, float iy11, float ix21, float iy21, float ix12, float iy12) { HRESULT res; DECLARE_MATRIX(om); DECLARE_MATRIX(im); GET_INVERTED_MATRIX(im, ix11, iy11, ix21, iy21, ix12, iy12, // inner parallelogram is degenerate // therefore it encloses no area // fill outer return FillParallelogramAA(ox11, oy11, ox21, oy21, ox12, oy12)); GET_INVERTED_MATRIX(om, ox11, oy11, ox21, oy21, ox12, oy12, return D3D_OK); if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) { float ox = ox11, oy = oy11; float ow = 0.0f, oh = 0.0f; ADJUST_PGRAM(ox, ox21, ow); ADJUST_PGRAM(oy, oy21, oh); ADJUST_PGRAM(ox, ox12, ow); ADJUST_PGRAM(oy, oy12, oh); float ox11 = floor(ox); float oy11 = floor(oy); float ox22 = ceil(ox + ow); float oy22 = ceil(oy + oh); float ou11, ov11, ou12, ov12, ou21, ov21, ou22, ov22; TRANSFORM(om, ou11, ov11, ox11, oy11); TRANSFORM(om, ou21, ov21, ox22, oy11); TRANSFORM(om, ou12, ov12, ox11, oy22); TRANSFORM(om, ou22, ov22, ox22, oy22); float iu11, iv11, iu12, iv12, iu21, iv21, iu22, iv22; TRANSFORM(im, iu11, iv11, ox11, oy11); TRANSFORM(im, iu21, iv21, ox22, oy11); TRANSFORM(im, iu12, iv12, ox11, oy22); TRANSFORM(im, iu22, iv22, ox22, oy22); ADD_TRIANGLE_XYUVUVC(ox11, oy11, ox22, oy11, ox11, oy22, ou11, ov11, ou21, ov21, ou12, ov12, iu11, iv11, iu21, iv21, iu12, iv12, color); ADD_TRIANGLE_XYUVUVC(ox11, oy22, ox22, oy11, ox22, oy22, ou12, ov12, ou21, ov21, ou22, ov22, iu12, iv12, iu21, iv21, iu22, iv22, color); } return res; }
int VertexUtil::Append(std::vector<VertexPositionNormalTexture>& rDst, const int dstIndex, const std::vector<VertexPositionNormalTexture>& src, const Vector3& modVector) { const int vertexCount = src.size(); EnsureCapacity(rDst, dstIndex + vertexCount); for (int i = 0; i < vertexCount; ++i) { VertexPositionNormalTexture val = src[i]; val.Position += modVector; rDst[dstIndex + i] = val; } return vertexCount; }
ECode MatrixCursor::AddRow( /* [in] */ const ArrayOf<IInterface*>& columnValues) { if (columnValues.GetLength() != mColumnCount) { // throw new IllegalArgumentException("columnNames.length = " // + columnCount + ", columnValues.length = " // + columnValues.length); return E_ILLEGAL_ARGUMENT_EXCEPTION; } Int32 start = mRowCount++ * mColumnCount; EnsureCapacity(start + mColumnCount); for(Int32 i = 0; i < mColumnCount; i++) { (*mData)[start + i] = columnValues[i]; } return NOERROR; }
HRESULT D3DVertexCacher::FillRect(int x1, int y1, int x2, int y2) { HRESULT res; if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) { float fx1 = (float)x1; float fy1 = (float)y1; float fx2 = (float)x2; float fy2 = (float)y2; ADD_TRIANGLE_XYUVC(fx1, fy1, fx2, fy1, fx1, fy2, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, color); ADD_TRIANGLE_XYUVC(fx1, fy2, fx2, fy1, fx2, fy2, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, color); } return res; }