Exemple #1
0
STRING::STRING(const char* cstr) {
  if (cstr == NULL) {
    // Empty STRINGs contain just the "\0".
    memcpy(AllocData(1, kMinCapacity), "", 1);
  } else {
    int len = strlen(cstr) + 1;
    char* this_cstr = AllocData(len, len);
    memcpy(this_cstr, cstr, len);
  }
  assert(InvariantOk());
}
String::DataDesc* String::AllocDataCopy1(UPInt size, UPInt lengthIsSize,
                                         const char* pdata, UPInt copySize)
{
    String::DataDesc* pdesc = AllocData(size, lengthIsSize);
    memcpy(pdesc->Data, pdata, copySize);
    return pdesc;
}
Exemple #3
0
void nSurface::SetupSurface( E_COLOR_FORMAT ecfType, const Core::IDimension<u32> &dim, void *Data )
{
	m_ColorFormat = ECF_A8R8G8B8;
	m_Dimension = dim;
	m_nPitch = GetBitsPerPixels() / 8;

	// bug fixed: 
	// the previous code: m_pData = 0xbe70; now: m_pData = NULL;
	m_pData = NULL;
	AllocData();
	switch (ecfType)
	{
		case ECF_A8R8G8B8:
			{
				memcpy(m_pData, Data, dim.Width * dim.Height * m_nPitch);
			}

		case ECF_R8G8B8:
			{
				IColor color;
				for (u32 y=0; y<dim.Height; y++)
					for (u32 x=0; x<dim.Width; x++)
					{
						u32 i = (y * dim.Width + x)*3;
						u8 *col = &((u8 *)Data)[i];
						color.Set(col[0], col[1], col[2], 255);
						((u32 *)m_pData)[y * m_Dimension.Width + x] = color.Color;
					}
			}
	}
}
EventData::EventData( void const * inData, size_t const inSize ) :
	Data( NULL ),
	Size( 0 )
{
	AllocData( inSize );
	memcpy( Data, inData, Size );	
}
void    String::AssignString(const InitStruct& src, UPInt size)
{
    DataDesc*   poldData = GetData();
    DataDesc*   pnewData = AllocData(size, 0);
    src.InitString(pnewData->Data, size);
    SetData(pnewData);
    poldData->Release();
}
EventData & EventData::operator = ( EventData const & other ) 
{
	if ( &other != this ) {
		AllocData( other.GetSize() );
		memcpy( Data, other.GetData(), Size );
	}
	return *this;
}
Exemple #7
0
STRING::STRING(const STRING& str) {
  str.FixHeader();
  const STRING_HEADER* str_header  = str.GetHeader();
  int   str_used  = str_header->used_;
  char *this_cstr = AllocData(str_used, str_used);
  memcpy(this_cstr, str.GetCStr(), str_used);
  assert(InvariantOk());
}
String::DataDesc* String::AllocDataCopy2(UPInt size, UPInt lengthIsSize,
                                         const char* pdata1, UPInt copySize1,
                                         const char* pdata2, UPInt copySize2)
{
    String::DataDesc* pdesc = AllocData(size, lengthIsSize);
    memcpy(pdesc->Data, pdata1, copySize1);
    memcpy(pdesc->Data + copySize1, pdata2, copySize2);
    return pdesc;
}
Exemple #9
0
		UnicodeStringData(size_t nSize=0, size_t nDelta=0)
		{
			m_nDelta = nDelta? nDelta : __US_DELTA;
			m_nLength = 0;
			m_nRefCount = 1;
			m_pData = AllocData(nSize, m_nSize);
			//“ак как ни где выше в коде мы не готовы на случай что пам¤ти не хватит
			//то уж лучше и здесь не провер¤ть а сразу падать
			*m_pData = 0;
		}
void    String::operator = (const wchar_t* pwstr)
{
    DataDesc*   poldData = GetData();
    UPInt       size = pwstr ? (UPInt)UTF8Util::GetEncodeStringSize(pwstr) : 0;

    DataDesc*   pnewData = AllocData(size, 0);
    UTF8Util::EncodeString(pnewData->Data, pwstr);
    SetData(pnewData);
    poldData->Release();
}
void RedString::Empty(void)
{
    // Delete recreate the stored string
    DeleteData();
    data = AllocData(1);

    // Update the string size
    allocsize   = SizeForNumBlocks(1);
    contentsize = 0;
}
void    String::operator = (const wchar_t* pwstr)
{
    pwstr = pwstr ? pwstr : L"";

    DataDesc*   poldData = GetData();
    size_t      size = (size_t)UTF8Util::GetEncodeStringSize(pwstr);

    DataDesc*   pnewData = AllocData(size, 0);
    UTF8Util::EncodeString(pnewData->Data, pwstr);
    SetData(pnewData);
    poldData->Release();
}
Exemple #13
0
/**
******************************************************************************
* Name: CIccMpeEndAcs::CIccMpeEndAcs
* 
* Purpose: 
* 
* Args: 
* 
* Return: 
******************************************************************************/
CIccMpeEAcs::CIccMpeEAcs(const CIccMpeEAcs &elemAcs)
{
  m_signature = elemAcs.m_signature;
  m_nReserved = elemAcs.m_nReserved;

  m_nInputChannels = elemAcs.m_nInputChannels;
  m_nOutputChannels = elemAcs.m_nOutputChannels;

  AllocData(elemAcs.m_nDataSize);
  if (m_pData && elemAcs.m_nDataSize) {
    memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
  }
}
Exemple #14
0
/**
******************************************************************************
* Name: &CIccMpeBeginAcs::operator=
* 
* Purpose: 
* 
* Args: 
* 
* Return: 
******************************************************************************/
CIccMpeBAcs &CIccMpeBAcs::operator=(const CIccMpeBAcs &elemAcs)
{
  m_signature = elemAcs.m_signature;
  m_nReserved = elemAcs.m_nReserved;
  m_nInputChannels = elemAcs.m_nInputChannels;
  m_nOutputChannels = elemAcs.m_nOutputChannels;

  AllocData(elemAcs.m_nDataSize);
  if (m_pData && elemAcs.m_nDataSize) {
    memcpy(m_pData, elemAcs.m_pData, m_nDataSize);
  }

  return *this;
}
Exemple #15
0
	StringData(size_t nSize = 0, size_t nDelta = 0)
	{
		m_nDelta = (nDelta == 0 ? __US_DELTA : nDelta);

		m_nLength = 0;
		m_nRefCount = 1;

		m_pData = AllocData(nSize, &m_nSize);

		if ( m_pData )
			*m_pData = 0;
		else
			m_nSize = 0; //and what?
	}
Exemple #16
0
slong_t AStdMemFile::writedata(const void *buf, size_t bytes)
{
	slong_t bytes1 = -1;

	if (AllocData(bytes)) {
		bytes1 = MIN(bytes, AllocatedLength - Pos);
			
		memcpy(pData + Pos, buf, bytes1);
		
		Pos   += bytes1;
		Length = MAX(Length, Pos);
	}

	return bytes1;
}
Exemple #17
0
		void Inflate(size_t nSize)
		{
			if (nSize <= m_nSize)
				return;

			if (nSize >= m_nDelta << 3)
				nSize = nSize << 1;
			else
				nSize = (nSize/m_nDelta + 1) * m_nDelta;

			wchar_t *pOldData = m_pData;
			m_pData = AllocData(nSize, m_nSize);
			//“ак как ни где выше в коде мы не готовы на случай что пам¤ти не хватит
			//то уж лучше и здесь не провер¤ть а сразу падать
			wmemcpy(m_pData,pOldData,m_nLength);
			m_pData[m_nLength] = 0;
			FreeData(pOldData);
		}
Exemple #18
0
bool AStdMemFile::Base64Decode(const AString& str)
{
	sint_t nbytes;
	bool   success = false;

	Pos = Length = 0;

	if ((nbytes = str.Base64DecodeLength()) > 0) {
		if (AllocData(nbytes)) {
			if ((nbytes = str.Base64Decode(pData, AllocatedLength)) > 0) {
				Length  = Pos = nbytes;
				success = true;
			}
		}
	}

	return success;
}
Exemple #19
0
/**
******************************************************************************
* Name: CIccMpeAcs::Read
* 
* Purpose: 
* 
* Args: 
* 
* Return: 
******************************************************************************/
bool CIccMpeAcs::Read(icUInt32Number size, CIccIO *pIO)
{
  icTagTypeSignature sig;

  icUInt32Number headerSize = sizeof(icTagTypeSignature) + 
    sizeof(icUInt32Number) + 
    sizeof(icUInt16Number) + 
    sizeof(icUInt16Number) + 
    sizeof(icUInt32Number);

  if (headerSize > size)
    return false;

  if (!pIO) {
    return false;
  }

  if (!pIO->Read32(&sig))
    return false;

  if (!pIO->Read32(&m_nReserved))
    return false;

  if (!pIO->Read16(&m_nInputChannels))
    return false;

  if (!pIO->Read16(&m_nOutputChannels))
    return false;

  if (!pIO->Read32(&m_signature))
    return false;

  icUInt32Number dataSize = size - headerSize;

  if (!AllocData(dataSize))
    return false;

  if (dataSize) {
    if (pIO->Read8(m_pData, dataSize)!=(icInt32Number)dataSize)
      return false;
  }

  return true;
}
Exemple #20
0
STRING & STRING::operator=(const char* cstr) {
  STRING_HEADER* this_header = GetHeader();
  if (cstr) {
    int len = strlen(cstr) + 1;

    this_header->used_ = 0;  // dont bother copying data if need to realloc
    char* this_cstr = ensure_cstr(len);
    this_header = GetHeader();  // for realloc
    memcpy(this_cstr, cstr, len);
    this_header->used_ = len;
  } else {
    // Reallocate to same state as default constructor.
    DiscardData();
    // Empty STRINGs contain just the "\0".
    memcpy(AllocData(1, kMinCapacity), "", 1);
  }

  assert(InvariantOk());
  return *this;
}
RedString RedString::SubStr(const unsigned StartIndex, const unsigned Count) const
{
    RedString OutStr;

    if (StartIndex > LastContentIndex())
        return OutStr;

    unsigned LastSubStrIndex = StartIndex + (Count - 1);
    if (LastSubStrIndex > LastContentIndex())
        LastSubStrIndex = LastContentIndex();

    unsigned SubStrLength = LastSubStrIndex - StartIndex + 1;
    unsigned SubStrBlocksRequired = NumBlocksForSize(SubStrLength);

    OutStr.data = AllocData(SubStrBlocksRequired);
    OutStr.allocsize = SizeForNumBlocks(SubStrBlocksRequired);
    OutStr.contentsize = SubStrLength;
    strncpy(OutStr.data, &data[StartIndex], SubStrLength);
    OutStr.InitialiseNonContentChars();

    return OutStr;
}
const void* ArchiveReader::GetFileData_ZIP( size_t idx )
{
	if ( FExtractedFromArchive.count( ( int )idx ) > 0 ) { return FExtractedFromArchive[( int )idx]; }

	clPtr<MemFileWriter> FOut = CreateMemWriter( "mem_blob", FFileInfos[idx].FSize );

	void* DataPtr = NULL;

	if ( ExtractSingleFile( FRealFileNames[idx], "", NULL, NULL, FOut ) )
	{
		size_t Sz = static_cast<size_t>( FOut->GetFilePos() );

		clPtr<Blob> B = FOut->GetContainer();
		B->SafeResize( Sz );

		const void* BlobPtr = B->GetDataConst();
		DataPtr = AllocData( Sz );

		::memcpy( DataPtr, BlobPtr, Sz );
	}

	return DataPtr;
}
Exemple #23
0
BOOL DText::Create(STRCPTR data, TEXT_FORMAT fmt, UINT width /* = 0U */, BOOL warp /* = FALSE */, BOOL pre_alloc /* = FALSE */)
{
	if (m_Data)
		return FALSE;

	if (!CheckText(data, fmt, width, warp))
		return FALSE;

	if (pre_alloc) {
		m_Data = data;
	} else {
		m_Data = AllocData(data);
		if (!m_Data)
			return FALSE;
	}

	m_Attach = FALSE;
	m_Warp = warp;
	m_Width = width;
	m_Format = fmt;
	m_Length = DStrLen(m_Data);
	return TRUE;
}
bool CFarInetMessage::read( CMailbox * mailbox, DWORD dwMsgId, long encoding, bool headOnly )
{
  FreeParts();

  if ( headOnly )
  {
    m_Data.size = 1024;
    if ( mailbox->getMsgHead( dwMsgId, NULL, &m_Data.size ) != MV_OK )
      return false;
  }
  else
  {
    if ( mailbox->getMsg( dwMsgId, NULL, &m_Data.size ) != MV_OK )
      return false;
  }

  AllocData( m_Data.size );

  if ( headOnly )
  {
    if ( mailbox->getMsgHead( dwMsgId, m_Data.data, &m_Data.size ) != MV_OK )
      return false;
  }
  else
  {
    if ( mailbox->getMsg( dwMsgId, m_Data.data, &m_Data.size ) != MV_OK )
      return false;
  }

  bool result = Init( encoding );

  mailbox->getMsgInfo( dwMsgId, &m_Info );

  //m_Mailbox = Mailbox;

  return result;
}
Exemple #25
0
	CGamestatsData()
	{
		m_pKVData = NULL;
		m_bHaveData = false;
		AllocData();
	}
String::String(const InitStruct& src, UPInt size)
{
    pData = AllocData(size, 0);
    src.InitString(GetData()->Data, size);
}
Exemple #27
0
int ParseIHexLine( Parser_t *parser, const char *line )
{
    int                 i;
    FILE_ParsedData_t  *parsedData = &parser->parsedData;
    uint8_t            *data;

    ClearData( parsedData );

    if ( line[ 0 ] != ':' )
    {
        // In Intel Hex format, lines which don't start with ':' are
        // supposed to be ignored.

        return TRUE;
    }

    const char *s = &line[ 1 ];
    unsigned char  dataLen;

    if ( !GetByte( parser, &s, &dataLen, "count" ))
    {
        return FALSE;
    }

    data = AllocData( parsedData, dataLen );

    unsigned short  addr;
    if ( !GetWord( parser, &s, &addr, "addr" ))
    {
        return FALSE;
    }

    unsigned char recType;
    if ( !GetByte( parser, &s, &recType, "recType" ))
    {
        return FALSE;
    }

    unsigned char checksumCalc = dataLen + (( addr & 0xFF00 ) >> 8 ) + ( addr & 0x00FF ) + recType;

    for ( i = 0; i < dataLen; i++ ) 
    {
        if ( !GetByte( parser, &s, &data[ i ], "data" ))
        {
            return FALSE;
        }
        checksumCalc += data[ i ];
    }

    unsigned char checksumFound;

    if ( !GetByte( parser, &s, &checksumFound, "checksum" ))
    {
        return FALSE;
    }

    if ((unsigned char)( checksumCalc + checksumFound ) != 0 )
    {
        Error( parser, "found checksum 0x%02x, expecting 0x%02x", 
               checksumFound, 0 - checksumCalc );
        return FALSE;
    }

    switch ( recType )
    {
        case 0: // Data
        {
            parsedData->addr    = parser->addrBase + addr;
            parsedData->dataLen = dataLen;

            ParsedData( parser );
            break;
        }

        case 1: // EOF
        {
            Flush( parser );
            break;
        }

        case 2: // Segment
        {
            parser->addrBase = ((unsigned)data[ 0 ] << 12 ) | ((unsigned)data[ 1 ] << 4 );
            break;
        }

        case 3: // Entry Point
        {
            break;
        }

        default:
        {
            Error( parser, "Unrecognized record type: %d", recType );
            return FALSE;
        }
    }

    return TRUE;

} // ParseIHexLine
Exemple #28
0
int ParseSRecordLine( Parser_t *parser, const char *line )
{
    int                 i;
    FILE_ParsedData_t  *parsedData = &parser->parsedData;
    uint8_t            *data;

    ClearData( parsedData );

    if ( line[ 0 ] != 'S' )
    {
        Error( parser, "doesn't start with an 'S'" );
        return FALSE;
    }

    if ( !isdigit( line[ 1 ] ))
    {
        Error( parser, "expecting digit (0-9), found: '%c'", line[ 1 ]);
        return FALSE;
    }

    const char *s = &line[ 2 ];
    unsigned char  lineLen;

    if ( !GetByte( parser, &s, &lineLen, "count" ))
    {
        return FALSE;
    }

    data = AllocData( parsedData, lineLen );

    unsigned char checksumCalc = lineLen;

    for ( i = 0; i < ( lineLen - 1 ); i++ ) 
    {
        if ( !GetByte( parser, &s, &data[ i ], "data" ))
        {
            return FALSE;
        }
        checksumCalc += data[ i ];
    }
    checksumCalc = ~checksumCalc;

    unsigned char checksumFound;

    if ( !GetByte( parser, &s, &checksumFound, "checksum" ))
    {
        return FALSE;
    }

    if ( checksumFound != checksumCalc )
    {
        Error( parser, "found checksum 0x%02x, expecting 0x%02x", 
               checksumFound, checksumCalc );
        return FALSE;
    }

    switch ( line[ 1 ] )
    {
        case '0':
        {
            // Header Record - We ignore this for now

            Flush( parser );
            break;
        }

        case '1':   // 2 byte address
        case '2':   // 3 byte address
        case '3':   // 4 byte address
        {
            int addrIdx;

            int addrLen			= line[ 1 ] - '1' + 2;

            unsigned char *x = data;

            for ( addrIdx = 0; addrIdx < addrLen; addrIdx++ ) 
            {
                parsedData->addr <<= 8;
                parsedData->addr += *x++;
            }
            parsedData->dataLen = lineLen - addrLen - 1;
            memmove( data, x, parsedData->dataLen );

            ParsedData( parser );
            break;
        }

        case '5':   // Count of S1, S2, and S3 records
        {
            Flush( parser );
            break;
        }

        case '7':   // 2 byte address
        case '8':   // 3 byte address
        case '9':   // 4 byte address
        {
            // Start Address - currently ignored

            Flush( parser );
            break;
        }

        default:
        {
            Error( parser, "Unrecognized S-Record: S%c", line[ 1 ] );
            return FALSE;
        }
    }

    return TRUE;

} // ParseSRecordLine
Exemple #29
0
void MxBase::Alloc(const char *Name, unsigned RowCount, unsigned ColCount,
  const SeqDB *DB, unsigned IdA, unsigned IdB, const SeqData *SA, const SeqData *SB)
	{
	StartTimer(MxBase_Alloc);

	++m_AllocCount;
	if (m_AllocatedRowCount == 0)
		++m_ZeroAllocCount;

	if (DB != 0)
		{
		asserta(IdA != UINT_MAX);
		asserta(IdB != UINT_MAX);
		asserta(RowCount >= DB->GetSeqLength(IdA) + 1);
		asserta(ColCount >= DB->GetSeqLength(IdB) + 1);
		}
	if (RowCount > m_AllocatedRowCount || ColCount > m_AllocatedColCount)
		{
		if (m_AllocatedRowCount > 0)
			{
			if (opt_logmemgrows)
				Log("MxBase::Alloc grow %s %u x %u -> %u x %u, %s bytes\n",
				  Name, m_AllocatedRowCount, m_AllocatedColCount,
				  RowCount, ColCount,
				  IntToStr(GetBytes()));
			++m_GrowAllocCount;
			}

		m_TotalBytes -= GetBytes();

		PauseTimer(MxBase_Alloc);
		StartTimer(MxBase_FreeData);
		FreeData();
		EndTimer(MxBase_FreeData);
		StartTimer(MxBase_Alloc);

		unsigned N = max(RowCount + 16, m_AllocatedRowCount);
		unsigned M = max(ColCount + 16, m_AllocatedColCount);
		N = max(N, M);

		PauseTimer(MxBase_Alloc);
		StartTimer(MxBase_AllocData);
		AllocData(N, N);
		EndTimer(MxBase_AllocData);
		StartTimer(MxBase_Alloc);

		m_TotalBytes += GetBytes();
		if (m_TotalBytes > m_MaxBytes)
			m_MaxBytes = m_TotalBytes;
		}
	
	unsigned n = sizeof(m_Name)-1;
	strncpy(m_Name, Name, n);
	m_Name[n] = 0;
	m_RowCount = RowCount;
	m_ColCount = ColCount;
	m_SeqDB = DB;
	m_IdA = IdA;
	m_IdB = IdB;
	m_SA = SA;
	m_SB = SB;

	EndTimer(MxBase_Alloc);
	}
Exemple #30
0
STRING::STRING() {
  // Empty STRINGs contain just the "\0".
  memcpy(AllocData(1, kMinCapacity), "", 1);
}