Example #1
0
void *String::internalAlloc(uint32 nNewLength)
{
	void *pMemoryBlock;
	if (m_pString)
	{
        pMemoryBlock = ((int32 *) m_pString) - 2;
        
        if (nNewLength > getCapacity())
        {
            uint32 nCapacity = calcNewCapacity(nNewLength);
            pMemoryBlock = xRealloc(pMemoryBlock, sizeof(XCHAR)*(nCapacity + 1));
            m_pString = (XCHAR *) (((int32 *)pMemoryBlock) + 2);
            setCapacity(nCapacity);
        }
	}
	else
	{
        uint32 nCapacity = calcNewCapacity(nNewLength);
		pMemoryBlock = xAlloc(sizeof(StringData) + sizeof(XCHAR)*(nCapacity + 1));
        m_pString = (XCHAR *) (((int32 *)pMemoryBlock) + 2);
        setCapacity(nCapacity);
        *(((int32 *) m_pString) - 1) = 1;
	}

	m_pString[ nNewLength ] = 0;

	return pMemoryBlock;
}
Example #2
0
void BackForwardList::setEnabled(bool enabled)
{
    m_enabled = enabled;
    if (!enabled) {
        int capacity = m_capacity;
        setCapacity(0);
        setCapacity(capacity);
    }
}
Example #3
0
void Storage::resize(const Store &other )
{
  setCapacity( other.capacity() );

  for( auto& goodType : good::all() )
  {
    setCapacity( goodType, other.capacity( goodType ) );
  }
}
Example #4
0
Emigrant::Emigrant( CityPtr city ) : Immigrant( city )
{
  setCapacity( defaultPeoples );

  _walkerType = WT_EMIGRANT;
  _walkerGraphic = WG_PUSHER2;
}
Example #5
0
/*! This is the constructor for this class. It sets the stamina, effort and
    recovery on the supplied values.
    \param dSta new stamina value (default 4000.0)
    \param dEff new effort value (default 1.0)
    \param dRec new recovery value (default 1.0)*/
Stamina::Stamina( double dSta, double dEff, double dRec , double dCap)
{
  setStamina ( dSta );
  setEffort  ( dEff );
  setRecovery( dRec );
  setCapacity( dCap );
}
Example #6
0
void Extractor::create(VECTOR2 loc)
{
	Building::create(loc);
	minerals = nullptr;
	anythingNearby = true;
	setCapacity(ExtractorNS::CAPACITY);
}
template <class T> T& Set<T>::addNoAssign(const T& value)
{
    FW_ASSERT(!contains(value));

    // Empty => allocate.

    if (!m_capacity)
        setCapacity(0);

    // Exceeds MaxUsagePct => rehash.

    else if ((S64)m_numNonEmpty * 100 >= (S64)m_capacity * MaxUsagePct)
    {
        int cap = m_capacity;
        if ((S64)m_numItems * 100 >= (S64)cap * ThrUsagePct)
            cap <<= 1;
        rehash(cap);
    }

    // Find slot.

    S32 hashValue = hash<T>(value) >> 1;
    int slot = findSlot(value, hashValue, true);
    FW_ASSERT(m_hashes[slot] < 0);

    // Add item.

    m_numItems++;
    if (m_hashes[slot] == Empty)
        m_numNonEmpty++;

    m_hashes[slot] = hashValue;
    return m_values[slot];
}
Example #8
0
/**
* @brief 在缓冲区尾部添加
*/
void MCircularBuffer::pushBack(char* pItem, std::size_t startPos, std::size_t len)
{
	if (!canAddData(len)) // 存储空间必须要比实际数据至少多 1
	{
		uint32 closeSize = MDynBufResizePolicy::getCloseSize(len + size(), capacity());
		setCapacity(closeSize);
	}

	if (isLinearized())
	{
		if (len <= (m_pStorageBuffer->m_iCapacity - m_tail))
		{
			std::memcpy(m_pStorageBuffer->m_storage + m_tail, pItem + startPos, len);
		}
		else
		{
			std::memcpy(m_pStorageBuffer->m_storage + m_tail, pItem + startPos, m_pStorageBuffer->m_iCapacity - m_tail);
			std::memcpy(m_pStorageBuffer->m_storage + 0, pItem + m_pStorageBuffer->m_iCapacity - m_tail, len - (m_pStorageBuffer->m_iCapacity - m_tail));
		}
	}
	else
	{
		std::memcpy(m_pStorageBuffer->m_storage + m_tail, pItem + startPos, len);
	}

	m_tail += len;
	m_tail %= m_pStorageBuffer->m_iCapacity;

	m_pStorageBuffer->m_size += len;
}
	void FloatAttributeUpdater::pop()
	{
		m_data.resize(m_data.size() - getFloatsPerItem());
		
		if (m_data.size() < m_capacity/4 * getFloatsPerItem() && m_autoShrink)
			setCapacity(m_capacity/2);
	}
Example #10
0
/**
* @brief 在缓冲区头部添加
*/
void MCircularBuffer::pushFront(char* pItem, std::size_t startPos, std::size_t len)
{
	if (!canAddData(len)) // 存储空间必须要比实际数据至少多 1
	{
		uint32 closeSize = MDynBufResizePolicy::getCloseSize(len + size(), capacity());
		setCapacity(closeSize);
	}

	if (isLinearized())
	{
		if (len <= m_head)
		{
			std::memcpy(m_pStorageBuffer->m_storage + m_head - len, pItem + startPos, len);
		}
		else
		{
			std::memcpy(m_pStorageBuffer->m_storage + 0, pItem + startPos + len - m_head, m_head);
			std::memcpy(m_pStorageBuffer->m_storage + m_pStorageBuffer->m_iCapacity - (len - m_head), pItem + 0, len - m_head);
		}
	}
	else
	{
		std::memcpy(m_pStorageBuffer->m_storage + m_head - len, pItem + startPos + 0, len);
	}

	if (len <= m_head)
	{
		m_head -= (uint32)len;
	}
	else
	{
		m_head = m_pStorageBuffer->m_iCapacity - ((uint32)len - m_head);
	}
	m_pStorageBuffer->m_size += (uint32)len;
}
Example #11
0
 void shrink(unsigned minCapacity)
 {
   if (minCapacity < getCapacity())
   {
     setCapacity(minCapacity);
   }
 }
Example #12
0
/*!
 * \brief   文字列を挿入する
 */
void CoreString::insert(int32_t pos, const char* text, int32_t len) throw(Exception)
{
    if (getBuffer() == text)
        return;

    if (len == -1)
        len = GetLength(text);

    // バッファ容量が足りなければ拡張する
    int32_t capacity = getCapacity();
    int32_t newLen = getLength() + len;

    if (capacity < newLen)
    {
        setCapacity(newLen);
    }

    // 文字列挿入
    char* p = getBuffer();

    memmove(
        p + pos + len,
        p + pos,
        getLength() - pos);

    memcpy(
        p + pos,
        text,
        len);

    setLength(newLen);
}
Example #13
0
 Vector(unsigned initialCapacity = VECTOR_DEFAULT_CAPACITY, BaseAllocator& allocator = MemGlobals::GetDefaultAllocator(), bool growable = true)
   : m_allocator(allocator)
   , m_growable(growable)
 {
   setCapacity(initialCapacity);
   memset(m_arrObjects.start, 0, m_arrObjects.length);
 }
void BitSet::load(ByteInputStream &s) {
  UINT64 capacity64;
  s.getBytesForced((BYTE*)&capacity64, sizeof(capacity64));
  CHECKUINT64ISVALIDSIZET(capacity64)
  setCapacity((size_t)capacity64);
  s.getBytesForced((BYTE*)m_p, sizeof(Atom) * getAtomCount((size_t)capacity64));
}
Example #15
0
static void init(DynamicArray* array, int capacity)
{
    assert(capacity > 0);
    array->data = NULL;
    array->size = 0;
    setCapacity(array, capacity);
}
Example #16
0
Menu::Menu(){
   this -> arrayButton = (Button **)calloc( sizeof(Button) , 3 ); 
   this -> next = 0;
   setUpdated( false ); 
   setPaintHorizontal( false );
   setCapacity( 3 );      
   setSelectedButton( 0 ); 
}
capCollectionElementArray & capCollectionElementArray::operator = (const capCollectionElementArray & inSource) {
  removeAllObjects () ;
  setCapacity (inSource.mCount) ;
  for (uint32_t i=0 ; i<inSource.mCount ; i++) {
    addObject (inSource.objectAtIndex (i COMMA_HERE)) ;
  }
  return *this ;
}
Example #18
0
//!
//! Detach raw vector from instance. The returned vector is allocated
//! from the heap and is to be freed by the caller using the delete[]
//! operator when done. Instance is now disabled and must not be used
//! further.
//!
D64Vec::item_t* D64Vec::detachRaw()
{
    item_t* raw = item_;
    item_ = 0;
    numItems_ = 0;
    setCapacity(INVALID_CAP);
    return raw;
}
Example #19
0
	void grow(Array<T>& array, vol minCapacity)
	{
		vol capacity = 2 * array.capacity + 2;
		if (capacity < minCapacity)
			capacity = minCapacity;

		setCapacity(array, capacity);
	}
Example #20
0
	void grow(Queue<T>& queue, vol minCapacity)
	{
		vol newCapacity = 2 * length(queue.data) + 2;
		if (newCapacity < minCapacity)
			newCapacity = minCapacity;

		setCapacity(queue, newCapacity);
	}
Example #21
0
ByteArray &ByteArray::setData(const BYTE *data, size_t size) {
  cleanup();
  if(size > 0) {
    setCapacity(size);
    m_size = size;
    memcpy(m_data, data, size);
  }
  return *this;
}
capCollectionElementArray::capCollectionElementArray (const capCollectionElementArray & inSource) :
mArray (NULL),
mCapacity (0),
mCount (0) {
  setCapacity (inSource.mCount) ;
  for (uint32_t i=0 ; i<inSource.mCount ; i++) {
    addObject (inSource.objectAtIndex (i COMMA_HERE)) ;
  }
}
Example #23
0
void dyAdd(DynamicArray* array, TYPE value)
{
    if (array->size >= array->capacity)
    {
        setCapacity(array, 2 * array->capacity);
    }
    array->data[array->size] = value;
    array->size++;
}
Example #24
0
/*!
 * \brief   UTF-16LEをUTF-8に変換する
 */
void CoreString::conv(const wchar_t* text)
{
    int32_t len = Util::toUTF8(nullptr, 0, text);

    setCapacity(len);
    Util::toUTF8(getBuffer(), len + 1, text);

    setLength(len);
}
Example #25
0
void ArrayImpl::clear() {
  for(size_t i = 0; i < m_size; i++) {
    m_objectManager->deleteObject(m_elem[i]);
  }
//  memset(m_elem,0,m_size * sizeof(m_elem[0]));
  m_size = 0;
  setCapacity(10);
  m_updateCount++;
}
Example #26
0
void ConsoleHistory::setCapacityFromRHistsize()
{
   std::string histSize = ::core::system::getenv("R_HISTSIZE");
   if (!histSize.empty())
   {
      setCapacity(
         safe_convert::stringTo<std::size_t>(histSize, capacity()));
   }
}
Example #27
0
 void grow(unsigned minCapacity)
 {
   if (m_growable)
   {
     while (minCapacity > getCapacity())
     {
       setCapacity(getCapacity() * 2);
     }
   }
 }
Example #28
0
	void Patches::_expandMem( int spaceNeeded )
	{
		int capacity = m_capacity==0?c_defaultCapacity:m_capacity;
		
		
		while( capacity - m_size < spaceNeeded )
			capacity += capacity;
	
		setCapacity(capacity);
	}
Example #29
0
void ByteArray::load(ByteInputStream &s) {
  clear();
  size_t size;
  s.getBytesForced((BYTE*)&size, sizeof(size));
  if(size) {
    setCapacity(size);
    s.getBytesForced(m_data, size);
    m_size = size;
  }
}
Example #30
0
int maxFlow(void)
{
  int i,totflow;
  setCapacity();
  initialize();
  while(augment());
  for(totflow=0,i=0;i<=n;i++)
    totflow+=f[0][i];
  return totflow;
}