bool ON_Polyline::CreateStarPolygon(
    const ON_Circle& circle,
    double other_radius,
    int side_count
)
{
    bool rc = ( circle.IsValid() && side_count >= 3 && other_radius >= 0.0 )
              ? true
              : false;
    if ( rc )
    {
        SetCapacity(2*side_count+1);
        SetCount(2*side_count+1);
        double half_a = ON_PI/side_count;
        int i;
        ON_Circle other_circle = circle;
        other_circle.radius = other_radius;
        for ( i = 0; i < side_count; i++ )
        {
            m_a[i*2]   = circle.PointAt(half_a*2*i);
            m_a[i*2+1] = other_circle.PointAt(half_a*(1+2*i));
        }
        m_a[side_count*2] = m_a[0];
    }
    else
        Destroy();
    return rc;
}
Exemple #2
0
ON_BOOL32 ON_BrepLoopArray::Read( ON_BinaryArchive& file )
{
  Empty();
  ON__UINT32 tcode = 0;
  ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
  int count = 0;
  int i;
  int major_version = 0;
  int minor_version = 0;
  bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
  if (rc) {
    if (tcode != TCODE_ANONYMOUS_CHUNK)
      rc = false;
    if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
    if (rc) {
      if ( major_version==1 ) {
        if (rc) rc = file.ReadInt(&count);
        SetCapacity(count);
        for ( i = 0; i < count && rc ; i++ ) {
          ON_BrepLoop& loop = AppendNew();
          rc = loop.Read(file) ? true : false;
        }    
      }
      else {
        rc = 0;
      }
    }
    if ( !file.EndRead3dmChunk() )
      rc = false;
  }
  return rc;
}
Exemple #3
0
Bool CText::Serialize( CPersistentArchive& ar )
{
	Int16 version = 0;

	if( ar.BeginScope( WT("Text"), version ) == 0 )
	{
		ar.Serialize( m_Font, WT("Font") );
		ar.Serialize( m_Capacity, WT("Capacity") );

		ar.Serialize( m_Color, WT("Color") );
		ar.Serialize( m_Position, WT("Position") );
		ar.Serialize( m_FontSize, WT("FontSize") );
		ar.Serialize( m_TextLength, WT("TextLen") );

		if( ar.IsLoading() )
		{
			SetCapacity( m_Capacity );
			m_State.SetBit( nState_UpdateBuffer );
			m_State.SetBit( nState_RecreateBuffer );
		}

		ar.Serialize( m_Text.GetBuffer(), m_Capacity, WT("Text") );

		ar.EndScope();
	}
	return CManagedObject::Serialize( ar );
}
Exemple #4
0
/*
    TLFObjectList
*/
TLFObjectList::TLFObjectList()
{
    m_Count = 0;
    m_Capacity = 0;
    m_List = NULL;
    SetCapacity(0);
}
bool ON_BrepRegionArray::Read( ON_BinaryArchive& file )
{
    Empty();
    int count = 0;
    int i;
    int major_version = 0;
    int minor_version = 0;
    bool rc = file.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version );
    if (rc)
    {
        for(;;)
        {
            rc = (1 == major_version);
            if (!rc) break;
            if (rc) rc = file.ReadInt(&count);
            SetCapacity(count);
            for ( i = 0; i < count && rc ; i++ )
            {
                ON_BrepRegion& region = AppendNew();
                rc = region.Read(file)?true:false;
            }
            break;
        }
        if ( !file.EndRead3dmChunk() )
            rc = false;
    }
    return rc;
}
BOOL ON_BrepLoopArray::Read( ON_BinaryArchive& file )
{
  Empty();
  unsigned int tcode = 0;
  int count = 0;
  int i;
  int major_version = 0;
  int minor_version = 0;
  BOOL rc = file.BeginRead3dmChunk( &tcode, &i );
  if (rc) {
    if (tcode != TCODE_ANONYMOUS_CHUNK)
      rc = false;
    if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
    if (rc) {
      if ( major_version==1 ) {
        if (rc) rc = file.ReadInt(&count);
        SetCapacity(count);
        for ( i = 0; i < count && rc ; i++ ) {
          ON_BrepLoop& loop = AppendNew();
          rc = loop.Read(file);
        }
      }
      else {
        rc = 0;
      }
    }
    if ( !file.EndRead3dmChunk() )
      rc = false;
  }
  return rc;
}
Exemple #7
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords,const cxFrames *frames)
{
    CX_ASSERT(!Size().IsZero(), "size not set");
    cxInt size = frames->Num();
    SetCapacity(size);
    const cxInt *map = frames->Map();
    for(cxInt i = 0;i < size;i++){
        cxInt mapIdx = map[i];
        CX_ASSERT(mapIdx < coords->Size(), "map idx error");
        //get map tex
        cxTexCoord *coord = coords->At(mapIdx)->To<cxTexCoord>();
        if(coord->IsEmpty()){
            continue;
        }
        //trimmed box
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        if(bp.Size().IsZero()){
            continue;
        }
        //add render
        cxBoxRender &render = renders.Inc();
        render.SetVertices(bp);
        render.SetColor(Color());
        //get coord box
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetCoords(tbox);
    }
    return this;
}
FarString::FarStringData::FarStringData (const char *text, int length /*= -1*/)
  : fText (NULL), fCapacity (0), fRefCount (1)
{

  if (text)
  {
    if (length == -1)
      fLength = strlen (text);
    else
      fLength = length;
  }
  else
  {
    if (length == -1)
      fLength = 0;
    else
      fLength = length;
  }
  SetCapacity (fLength + 1);
  if (text)
  {
    far_assert_string( text, fLength );
    memcpy (fText, text, fLength );
    fText[ fLength ] = '\0';
  }
  else
  {
    *fText = '\0';
    fLength = 0;
  }
}
Exemple #9
0
 void GrowCapacity(sPtr n)
 {
     if(Last+n>End)
     {
         sPtr count = Last-First;
         SetCapacity(sMax(count+n,sMax(count*2,64/sizeof(T))));
     }
 }
Exemple #10
0
bool
nsTSubstring_CharT::SetLength( size_type length )
  {
    if (!SetCapacity(length))
      return false;

    mLength = length;
    return true;
  }
Exemple #11
0
CFreeList<DataType>::CFreeList( UInt32 size )
{
	m_NextFree = 0;
	m_Capacity = 0;
	m_ItemCount = 0;
	m_Array = NULL;
    m_MemoryHeap = &MemoryManager.GetBuddyHeap();
    SetCapacity( size );
}
Exemple #12
0
void CIntArray::Add(int val)
{
	if( aidx >= size )
	{
		SetCapacity(size+1);
	}
	arr[aidx] = val;
	++aidx;
}
bool
nsTSubstring_CharT::SetLength( size_type length, const fallible_t& )
  {
    if (!SetCapacity(length, fallible_t()))
      return false;

    mLength = length;
    return true;
  }
nsresult
SVGPointList::CopyFrom(const SVGPointList& rhs)
{
  if (!SetCapacity(rhs.Length())) {
    // Yes, we do want fallible alloc here
    return NS_ERROR_OUT_OF_MEMORY;
  }
  mItems = rhs.mItems;
  return NS_OK;
}
Exemple #15
0
void TMemoryStream::SetSize(const __int64 NewSize)
{
  __int64 OldPosition = FPosition;
  SetCapacity(NewSize);
  FSize = NewSize;
  if (OldPosition > NewSize)
  {
    Seek(0, Classes::soFromEnd);
  }
}
Exemple #16
0
cxAtlas *cxAtlas::SetScale9(const cxBox4F &sb)
{
    if(scalebox != sb){
        isscale9 = true;
        scalebox = sb;
        SetCapacity(9);
        SetDirty(DirtyModeTexture);
    }
    return this;
}
Exemple #17
0
void TLFObjectList::Grow()
{
    int Delta;
    if (m_Capacity > 64)
        Delta = m_Capacity / 4;
    else if (m_Capacity > 8)
        Delta = 16;
    else
        Delta = 4;
    SetCapacity(m_Capacity + Delta);    
}
Exemple #18
0
void TLFObjectList::Clear()
{
//    SetCount(0);
	for (int i = 0; i < this->m_Count; i++)
	{
		TLFObject* tmp = Get(i);
		delete tmp;
		tmp = NULL;
	}
	m_Count = 0;
    SetCapacity(0);
}
Exemple #19
0
void String::Resize(size_t newLength)
{
    if (!buffer)
    {
        // If zero length requested, do not allocate buffer yet
        if (!newLength)
            return;
        
        // Calculate initial capacity
        size_t capacity = newLength + 1;
        if (capacity < MIN_CAPACITY)
            capacity = MIN_CAPACITY;
        
        buffer = new char[capacity + 2 * sizeof(size_t)];
        SetCapacity(capacity);
    }
    else
    {
        size_t capacity = Capacity();

        if (newLength && capacity < newLength + 1)
        {
            // Increase the capacity with half each time it is exceeded
            while (capacity < newLength + 1)
                capacity += (capacity + 1) >> 1;
            
            char* newBuffer = new char[capacity + 2 * sizeof(size_t)];
            // Move the existing data to the new buffer, then delete the old buffer
            if (Length())
                CopyChars(newBuffer + 2 * sizeof(size_t), Buffer(), Length());
            delete[] buffer;
            
            buffer = newBuffer;
            SetCapacity(capacity);
        }
    }

    SetLength(newLength);
    Buffer()[newLength] = 0;
}
Exemple #20
0
CText::CText( const CTextFont& font, UInt32 capacity )
{
    m_Size = CVector2i( 0, 0 );
    m_FontSize = 1.0f;
    m_Font = (CTextFont*) &font;
    m_Color = CColor::White;
	m_Capacity = 0;
	SetCapacity( capacity );
    m_Text[0] = 0;
	m_TextLength = 0;
	m_CtrlCharCount = 0;
	m_State.SetBit( nState_RecreateBuffer );
}
Exemple #21
0
bool SLGMRecord::SetField(FIELD_IDENTIFIERS, void *FieldValue, UINT32 ArraySize)
    {
    switch(FieldID)
        {
        case 1: //flags1
            SetHeaderFlagMask(*(UINT32 *)FieldValue);
            break;
        case 3: //flags2
            SetHeaderUnknownFlagMask(*(UINT32 *)FieldValue);
            break;
        case 4: //eid
            EDID.Copy((STRING)FieldValue);
            break;
        case 5: //full
            FULL.Copy((STRING)FieldValue);
            break;
        case 6: //modPath
            MODL.Load();
            MODL->MODL.Copy((STRING)FieldValue);
            break;
        case 7: //modb
            MODL.Load();
            MODL->MODB.value = *(FLOAT32 *)FieldValue;
            break;
        case 8: //modt_p
            MODL.Load();
            MODL->MODT.Copy((UINT8ARRAY)FieldValue, ArraySize);
            break;
        case 9: //iconPath
            ICON.Copy((STRING)FieldValue);
            break;
        case 10: //script
            SCRI.value = *(FORMID *)FieldValue;
            return true;
        case 11: //value
            DATA.value.value = *(UINT32 *)FieldValue;
            break;
        case 12: //weight
            DATA.value.weight = *(FLOAT32 *)FieldValue;
            break;
        case 13: //soulType
            SetSoul(*(UINT8 *)FieldValue);
            break;
        case 14: //capacity
            SetCapacity(*(UINT8 *)FieldValue);
            break;
        default:
            break;
        }
    return false;
    }
Exemple #22
0
CText::CText( )
{
	m_Size = CVector2i( 0, 0 );
	m_FontSize = 1.0f;
	m_Color = CColor::White;
	m_Capacity = 0;
	SetCapacity( 128 );
	m_Text[0] = 0;
	m_TextLength = 0;
	m_CtrlCharCount = 0;
	m_State.SetBit( nState_RecreateBuffer );

	m_Font = &GraphicsManager.GetDefaultFont();
}
Exemple #23
0
bool ON_3dPointArray::Create( 
  int point_dimension,
  int bRational,
  int point_count,
  int point_stride,
  const float* points
  )
{
  bool rc = false;
  if (     point_dimension >= 2 && point_dimension <= 3 
        && point_count>0 && points 
        && point_stride >= bRational?(point_dimension+1):point_dimension )
  {
    rc = true;
    int i;
    ON_3dPoint q(0.0,0.0,0.0);
    ON_4dPoint h(0.0,0.0,0.0,1.0);
    m_count = 0;
    SetCapacity(point_count);
    SetCount(point_count);
    if ( bRational )
    {
      for ( i = 0; i < point_count; i++ )
      {
        h.x = points[0];
        h.y = points[1];
        if ( point_dimension == 3 )
          h.z = points[2];
        h.w = points[point_dimension];
        m_a[i] = h;
        points += point_stride;
      }
    }
    else
    {
      for ( i = 0; i < point_count; i++ )
      {
        q.x = points[0];
        q.y = points[1];
        if ( point_dimension == 3 )
          q.z = points[2];
        m_a[i] = q;
        points += point_stride;
      }
    }
  }
  else
    Destroy();
  return rc;
}
Exemple #24
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords)
{
    cxInt size = coords->Size();
    SetCapacity(size);
    for(cxInt i = 0;i < size;i++){
        cxBoxRender &render = renders.Inc();
        cxTexCoord *coord = coords->At(i)->To<cxTexCoord>();
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetVertices(bp);
        render.SetColor(Color());
        render.SetCoords(tbox);
    }
    return this;
}
Exemple #25
0
void
Filter::Append (byte value)
{
    ASSERT (FilterSize <= Capacity);
    FilterSize++;
    if (value != 0) { FilterCount++; }
    if( value == 1 && Data == NULL)
        return;
    if( value != 1 && Data == NULL)
        Allocate();
    else if (FilterSize > Capacity) {
        // Data array is full, extend it in chunks of 1000:
        SetCapacity(Capacity + 1000);
    }
    Data[FilterSize] = value;
}
Exemple #26
0
void TLFObjectList::SetCount(int NewCount)
{
    int i;
    if (NewCount < 0)
        return;  //DONE: here is error
    if (NewCount > m_Capacity)
        SetCapacity(NewCount);
    if (NewCount > m_Count)
        memset(&m_List[m_Count],0,(NewCount - m_Count)*sizeof(TLFObject**));
    else
        for (i = m_Count -1; i >= NewCount; i--)
        {
            Delete(i);
        }
    m_Count = NewCount;
}
Exemple #27
0
cudaError_t CudaAllocBuckets::Malloc(size_t size, void** p) {

	// Locate the bucket index and adjust the size of the allocation to the 
	// bucket size.
	int bucket = LocateBucket(size);
	if(bucket < NumBuckets)
		size = BucketSizes[bucket];

	// Peel off an already-allocated node and reuse it.
	MemList& list = _memLists[bucket];
	if(list.size() && list.front().priority != _priorityMap.end()) {
		MemList::iterator memIt = list.begin();
		
		_priorityMap.erase(memIt->priority);
		memIt->priority = _priorityMap.end();

		list.splice(list.end(), list, memIt);
		_committed += size;

		*p = memIt->address->first;
		return cudaSuccess;
	}

	// Shrink if this allocation would put us over the limit.
	Compact(size);
	 
	cudaError_t error = cudaSuccess;
	*p = 0;
	if(size) error = cudaMalloc(p, size);
	while((cudaErrorMemoryAllocation == error) && (_committed < _allocated)) {
		SetCapacity(_capacity - _capacity / 10);
		error = cudaMalloc(&p, size);
	}
	if(cudaSuccess != error) return error;

	MemList::iterator memIt = 
		_memLists[bucket].insert(_memLists[bucket].end(), MemNode());
	memIt->bucket = bucket;
	memIt->address = _addressMap.insert(std::make_pair(*p, memIt)).first;
	memIt->priority = _priorityMap.end();
	_allocated += size;
	_committed += size;

	return cudaSuccess;
}
Exemple #28
0
void String::Reserve(size_t newCapacity)
{
    size_t length = Length();
    if (newCapacity < length + 1)
        newCapacity = length + 1;
    if (newCapacity == Capacity())
        return;
    
    char* newBuffer = new char[newCapacity + 2 * sizeof(size_t)];
    // Move the existing data to the new buffer (including the end zero), then delete the old buffer
    if (length)
        CopyChars(newBuffer + 2 * sizeof(size_t), Buffer(), length + 1);
    delete[] buffer;

    buffer = newBuffer;
    SetLength(length);
    SetCapacity(newCapacity);
}
Exemple #29
0
ON_BOOL32 ON_BrepFaceArray::Read( ON_BinaryArchive& file )
{
  Empty();
  ON__UINT32 tcode = 0;
  ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
  int count = 0;
  int i;
  int major_version = 0;
  int minor_version = 0;
  bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
  if (rc) {
    if (tcode != TCODE_ANONYMOUS_CHUNK)
      rc = false;
    if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
    if (rc) {
      if ( major_version==1 ) 
      {
        if (rc) rc = file.ReadInt(&count);
        SetCapacity(count);
        for ( i = 0; i < count && rc ; i++ ) 
        {
          ON_BrepFace& face = AppendNew();
          rc = face.Read(file)?true:false;
        }    

        if ( minor_version >= 1 )
        {
          // chunk version 1.1 and later has face uuids
          for ( i = 0; i < count && rc; i++ )
          {
            rc = file.ReadUuid( m_a[i].m_face_uuid );
          }
        }
      }
      else 
      {
        rc = 0;
      }
    }
    if ( !file.EndRead3dmChunk() )
      rc = false;
  }
  return rc;
}
Exemple #30
0
ON_BOOL32 ON_SurfaceArray::Read( ON_BinaryArchive& file )
{
  int major_version = 0;
  int minor_version = 0;
  ON__UINT32 tcode = 0;
  ON__INT64 big_value = 0;
  int flag;
  Destroy();
  ON_BOOL32 rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
  if (rc) 
  {
    rc = ( tcode == TCODE_ANONYMOUS_CHUNK );
    if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
    if (rc && major_version == 1) {
      ON_Object* p;
      int count;
      ON_BOOL32 rc = file.ReadInt( &count );
      if (rc) {
        SetCapacity(count);
        SetCount(count);
        Zero();
        int i;
        for ( i = 0; rc && i < count && rc; i++ ) {
          flag = 0;
          rc = file.ReadInt(&flag);
          if (rc && flag==1) {
            p = 0;
            rc = file.ReadObject( &p ); // polymorphic surfaces
            m_a[i] = ON_Surface::Cast(p);
            if ( !m_a[i] )
              delete p;
          }
        }
      }
    }
    else {
      rc = false;
    }
    if ( !file.EndRead3dmChunk() )
      rc = false;
  }
  return rc;
}