float Class::getNormalizedEncumbrance(const Ptr &ptr) const { float capacity = getCapacity(ptr); if (capacity == 0) return 1.f; return getEncumbrance(ptr) / capacity; }
double Advantage::consume() { double ret = getCapacity(); __capacity = -1; finish(); return ret; }
int getResidualCapacity(GraphFlow *g, int node1, int node2) { if(!inRange(g,node1) || !inRange(g,node2)) { printf("Error range in getResidualCapacity of GraphFlow!\n"); exit(-1); } return getCapacity(g,node1,node2) - getFlow(g,node1,node2); }
int str::printf(const char* pFormat, ...) { va_list args; va_start(args, pFormat); /** * Try to print into allocated memory, and if the number of characters * is greater than capacity, reallocate more memory, and print again * @note Our capacity doesn't include NULL char which we do have an * extra space for. */ #if STR_SUPPORT_FLOAT int len = vsnprintf(mpStr, getCapacity()+1, pFormat, args); #else int len = vsniprintf(mpStr, getCapacity()+1, pFormat, args); #endif /** * output is only written if len is greater than 0 and less * than our capacity. So if it is not written then retry: */ while(!mStackMem && !(len > 0 && len <= getCapacity())) { if (reserve(getCapacity() + getCapacity())) { #if STR_SUPPORT_FLOAT len = vsnprintf(mpStr, getCapacity()+1, pFormat, args); #else len = vsniprintf(mpStr, getCapacity()+1, pFormat, args); #endif } } va_end(args); return len; }
void setCapacity(unsigned newCapacity) { if (newCapacity < getCapacity()) { m_arrObjects.length = newCapacity; m_size = newCapacity; } else if (newCapacity > 0) { if (getCapacity() == 0) { m_arrObjects = m_allocator.allocateArray<T>(newCapacity, alignof(T)); return; } m_arrObjects = m_allocator.reallocateArray<T>(m_arrObjects, newCapacity, alignof(T)); ASSERT(m_arrObjects.start, "Reallocate failure"); } }
void GraphCut::setTerminalWeights() { for (int x = 0; x < _image->width(); x++) { for (int y = 0; y < _image->height(); y++) { float value = (*_image)(x, y); unsigned int nodeId = getNodeId(x, y); _graph.edit_tweights_wt( nodeId, getCapacity(value, _parameters->foregroundPrior), getCapacity(1.0f - value, 1.0f - _parameters->foregroundPrior)); } } }
/** @return Total number of bytes in the VertexBufferObject. */ GLsizei VertexBufferBuilder::getSizeInBytes() const { list<VertexAttribute>::const_iterator it; GLsizei sizeInBytes = 0; for (it=attributes.begin(); it!=attributes.end(); ++it) { sizeInBytes += sizeof(float) * it->getComponents(); } return sizeInBytes * getCapacity(); }
bool Inventory::checkCapacity(uint8 amount, PlayerObject* player, bool sendMsg) { if(player&&(getCapacity() - getHeadCount() < amount)) { if(sendMsg) gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "inv_full"), player); return false; } return true; }
void CircularBuffer::dump() const { size_t i, num = getCount(); printf("CircularBuffer type %d, count %d, capacity %d:\n", (int)type, (int)count, (int)getCapacity()); for (i=0; i<num; ++i) { printf("#%3u: ", (unsigned int)i); RawValue::show(stdout, type, count, getRawValue(i)); } }
int VNetwork::doNextStep(QGraphicsScene *scene) { Action action=algo->stepForward(); if (action.type == OUT_OF_HISTORY_ACTION) { return 1; } if (action.type == PUSH_ACTION) { addCapacity(action.from, action.to, -action.changeInCapacity); addCapacity(action.to, action.from, action.changeInCapacity); if (getCapacity(action.from, action.to) == 0) { scene->removeItem(VEdges[action.from][action.to]); } if (getCapacity(action.to, action.from)==action.changeInCapacity) { scene->addItem(VEdges[action.to][action.from]); } } if (action.type == UP_ACTION) { VNodes[action.node]-> up(action.changeInHeight); } return 0; }
/** * @brief isUnderConstraints * 是否满足小于Link中的capacity * @return {boolean} */ bool BulkLink::isUnderConstraints() { double sumFlow = 0; slist<BulkSession*>::iterator iter; for (iter = session_->begin(); iter != session_->end(); iter++) { sumFlow += (*iter)->flow_; } if (sumFlow < getCapacity()) { return true; } return false; }
/** * Returns a human-readable representation of a machine. * * @param machineId Machine's id. * @return Machine's representation for debugging purposes. */ std::string toString ( uint machineId ) const { assert ( exists ( machineId ) ); std::string output; output += " #" ; output += boost::lexical_cast<std::string> ( machineId ) ; output += ": n"; output += boost::lexical_cast<std::string> ( getNeighborhood ( machineId ) ) ; output += ", l"; output += boost::lexical_cast<std::string> ( getLocation ( machineId ) ) ; output += "\n"; output += " capacities : " ; for ( uint r = 0 ; r < _resources.size(); ++r ) { output += "r" ; output += boost::lexical_cast<std::string> ( r ); output += ":" ; output += boost::lexical_cast<std::string> ( getCapacity ( machineId, r ) ) ; output += " "; } output += "\n"; output += " saf. capacities : " ; for ( uint r = 0 ; r < _resources.size(); ++r ) { output += "r" ; output += boost::lexical_cast<std::string> ( r ); output += ":"; output += boost::lexical_cast<std::string> ( getSafetyCapacity ( machineId, r ) ) ; output += " "; } output += "\n"; output += " mov. cost : " ; for ( uint m = 0 ; m < size(); ++m ) { output += "m" ; output += boost::lexical_cast<std::string> ( m ); output += ":"; output += boost::lexical_cast<std::string> ( getMovingCost ( machineId, m ) ) ; output += " "; } output += "\n"; return output ; }
uint32 String::calcNewCapacity(uint32 nNewLength) const { int32 nCapacity = getCapacity(); if (nCapacity <= 0) { nCapacity = 16; } while (nCapacity < nNewLength) { nCapacity *= 2; } return nCapacity; }
int VNetwork::doPreviousStep(QGraphicsScene *scene) { Action action=algo->stepBack(); if (action.type == OUT_OF_HISTORY_ACTION) { return 1; } if (action.type == PUSH_ACTION) { std::cout << "It realy backward push\n"; if (getCapacity(action.from, action.to) == 0) { scene->addItem(VEdges[action.from][action.to]); } if (getCapacity(action.to, action.from)==action.changeInCapacity) { scene->removeItem(VEdges[action.to][action.from]); } addCapacity(action.from, action.to, action.changeInCapacity); addCapacity(action.to, action.from, -action.changeInCapacity); } if (action.type == UP_ACTION) { VNodes[action.node]-> up(-action.changeInHeight); } return 0; }
// Create a collation key from a bit array. CollationKey::CollationKey(const uint8_t* newValues, int32_t count) : UObject(), fFlagAndLength(count), fHashCode(kInvalidHashCode) { if (count < 0 || (newValues == NULL && count != 0) || (count > getCapacity() && reallocate(count, 0) == NULL)) { setToBogus(); return; } if (count > 0) { uprv_memcpy(getBytes(), newValues, count); } }
GUIParameterTableWindow* GUIParkingArea::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) { GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 4); // add items ret->mkItem("begin position [m]", false, myBegPos); ret->mkItem("end position [m]", false, myEndPos); ret->mkItem("occupancy [#]", true, getOccupancy()); ret->mkItem("capacity [#]", false, getCapacity()); // close building ret->closeBuilding(); return ret; }
void InMemoryStorage::insert(const Data& data, const time::milliseconds& mustBeFreshProcessingWindow) { // check if identical Data/Name already exists auto it = m_cache.get<byFullName>().find(data.getFullName()); if (it != m_cache.get<byFullName>().end()) return; //if full, double the capacity bool doesReachLimit = (getLimit() == getCapacity()); if (isFull() && !doesReachLimit) { // note: This is incorrect if 2*capacity overflows, but memory should run out before that size_t newCapacity = std::min(2 * getCapacity(), getLimit()); setCapacity(newCapacity); } //if full and reach limitation of the capacity, employ replacement policy if (isFull() && doesReachLimit) { evictItem(); } //insert to cache BOOST_ASSERT(m_freeEntries.size() > 0); // take entry for the memory pool InMemoryStorageEntry* entry = m_freeEntries.top(); m_freeEntries.pop(); m_nPackets++; entry->setData(data); if (m_scheduler != nullptr && mustBeFreshProcessingWindow > ZERO_WINDOW) { entry->scheduleMarkStale(*m_scheduler, mustBeFreshProcessingWindow); } m_cache.insert(entry); //let derived class do something with the entry afterInsert(entry); }
void NeoBattery::updateSysStatus() { charging = isCharging(); qLog(PowerManagement) << __PRETTY_FUNCTION__ << charging; int capacity = getCapacity(); battery->setCharging(charging); battery->setCharge(capacity); battery->setTimeRemaining(getTimeRemaining()); // stop the charging animation when fully charged and plugged in // otherwise it looks like it never gets full if (capacity > 98 && charging) battery->setCharging(false); }
float CoriFlow::getMeasure( void ) const { #ifdef __CORIFLOW_DEBUG std::cout << "[CoriFlow::test] -- DEBUG: Called." << std::endl; #endif char buffer[1000]; usleep( uDelay_ ); comHandler_->SendCommand( ":06030401210120" ); usleep( uDelay_ ); comHandler_->ReceiveString( buffer ); StripBuffer( buffer ); return ToInt(buffer)*getCapacity()/32000/60/(getDensity()*0.001); }
map<string,GLuint> VertexBufferBuilder::getOffsets() const { map<string,GLuint> offsets; list<VertexAttribute>::const_iterator it; GLuint offset = 0; GLsizei attributeSizeInBytes; for (it=attributes.begin(); it!=attributes.end(); ++it) { offsets[it->getName()] = offset; attributeSizeInBytes = sizeof(GLfloat) * it->getComponents(); if (isInterleaved()) { offset += attributeSizeInBytes; } else { offset += attributeSizeInBytes * getCapacity(); } } return offsets; }
void VNetwork::initSideData(GraphWidget* widget) { VNodes.resize(countOfNodes); VEdges.resize(countOfNodes); for (int i = 0; i < countOfNodes; ++i) { VEdges[i].resize(countOfNodes); } for (int i = 0; i < countOfNodes; ++i ) { VNodes[i] = new Node(widget, ((i == 0)? countOfNodes : 0) ); VNodes[i]->setPos(i,i*i); } VNodes.front()->setPos(-SCENE_WIDTH/2+30, 0); VNodes.back()->setPos(SCENE_WIDTH/2-30, 0); VNodes.front()->fix(); VNodes.back()->fix(); for (int i = 0; i < countOfNodes; ++i ) { for (int j = 0; j < countOfNodes; ++j) { VEdges[i][j] = new Edge(VNodes[i], VNodes[j], getCapacity(i, j)); } } }
/*! * \brief 文字列をコピーする */ void CoreString::copy(const char* text, int32_t len) throw(Exception) { if (getBuffer() == text) return; if (len == -1) len = GetLength(text); // バッファ容量が足りなければ拡張する int32_t capacity = getCapacity(); if (capacity < len) { setCapacity(len); } // 文字列コピー strncpy(getBuffer(), text, len); setLength(len); }
CollationKey::CollationKey(const CollationKey& other) : UObject(other), fFlagAndLength(other.getLength()), fHashCode(other.fHashCode) { if (other.isBogus()) { setToBogus(); return; } int32_t length = fFlagAndLength; if (length > getCapacity() && reallocate(length, 0) == NULL) { setToBogus(); return; } if (length > 0) { uprv_memcpy(getBytes(), other.getBytes(), length); } }
/*! * \brief 文字列を追加する */ void CoreString::append(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); } // 文字列追加 strncpy(getBuffer() + getLength(), text, len); setLength(newLen); }
void RenderAf::addTask( af::TaskExec * taskexec) { // If render was not busy it has become busy now if( false == isBusy()) { setBusy( true); m_task_start_finish_time = time( NULL); store(); } #ifdef AFOUTPUT AF_DEBUG << *taskexec; #endif m_tasks.push_back( taskexec); m_capacity_used += taskexec->getCapResult(); if( m_capacity_used > getCapacity() ) AF_ERR << "Capacity_used > host.capacity (" << m_capacity_used << " > " << m_host.m_capacity << ")"; }
void ClientMessage::ensureBufferSize(int32_t requiredCapacity) { if (isOwner) { int32_t currentCapacity = getCapacity(); if (requiredCapacity > currentCapacity) { // allocate new memory int32_t newSize = findSuitableCapacity(requiredCapacity, currentCapacity); // No need to keep the pointer in a smart pointer here byte *newBuffer = new byte[newSize]; memcpy(newBuffer, buffer, (size_t) currentCapacity); // swap the new buffer with the old one // free the old memory delete[] buffer; buffer = newBuffer; wrapForWrite(buffer, newSize, getIndex()); } } else { // Should never be here assert(0); } }
void Extractor::update(float frameTime) { if(getActive()) { //i rewrite the building logic because i need to take into account minerals ActorWithHealthBar::update(frameTime); if(anythingNearby&&getPower()) { if(game->getIdlePop() > 0 && getStaff() < getCapacity()) { modifyStaff(1); game->removeIdlePop(1); } } else if(getStaff() > 0) { modifyStaff(-1); game->addIdlePop(1); } if(getPower()) { game->spawnParticleCloud(getCenter(),graphicsNS::GRAY,1); if(anythingNearby) { if(minerals==nullptr||!minerals->getActive()) minerals=game->findMineableMinerals(this); if(minerals==nullptr) anythingNearby = false; else { game->addMinerals(minerals->mine(ExtractorNS::DEFAULT_MINING_RATE*frameTime*getEffectiveness())); game->spawnParticleCloud(getCenter(),graphicsNS::CYAN,1); } } } } }
Error Assembler::_reserve(size_t n) { size_t capacity = getCapacity(); if (n <= capacity) return kErrorOk; uint8_t* newBuffer; if (_buffer == NULL) newBuffer = static_cast<uint8_t*>(ASMJIT_ALLOC(n)); else newBuffer = static_cast<uint8_t*>(ASMJIT_REALLOC(_buffer, n)); if (newBuffer == NULL) return setError(kErrorNoHeapMemory); size_t offset = getOffset(); _buffer = newBuffer; _end = _buffer + n; _cursor = newBuffer + offset; return kErrorOk; }
const CollationKey& CollationKey::operator=(const CollationKey& other) { if (this != &other) { if (other.isBogus()) { return setToBogus(); } int32_t length = other.getLength(); if (length > getCapacity() && reallocate(length, 0) == NULL) { return setToBogus(); } if (length > 0) { uprv_memcpy(getBytes(), other.getBytes(), length); } fFlagAndLength = (fFlagAndLength & 0x80000000) | length; fHashCode = other.fHashCode; } return *this; }
/*! * \brief フォーマット */ void CoreString::formatV(const char* format, va_list arg) throw(Exception) { int32_t len; #if defined(__unix__) || defined(__APPLE__) va_list argCopy; va_copy(argCopy, arg); #endif do { char* p = getBuffer(); int32_t capacity = getCapacity(); #if defined(_WINDOWS) len = vsnprintf(p, capacity, format, arg); #else len = vsnprintf(p, capacity + 1, format, arg); // バッファサイズには終端の'\0'も含まれる #endif // if (len != -1) if (len != -1 && len <= capacity) break; p[capacity] = '\0'; #if defined(_WINDOWS) setCapacity(capacity + 256); #else setCapacity(len + 1); va_copy(arg, argCopy); #endif } while (true); setLength(len); }