//------------------------------// // Methods // //------------------------------// void PressureTable::AddVarName(string var) { VarNames.push_back(var); int size = VarNames.size(); pair<string,int> newElem(var,size-1); pair<map<string, int>::iterator, bool> test = VarNamesMap.insert( newElem ); if (test.second == false) { cerr << "Variable "<< var <<" already added"<< endl; throw(-1); } }
void MSVehicleContainer::add(SUMOTime time, const VehicleVector& cont) { VehicleHeap::iterator j = find_if(array.begin() + 1, array.begin() + currentSize + 1, DepartFinder(time)); if (currentSize == 0 || j == array.begin() + currentSize + 1) { VehicleDepartureVector newElem(time, VehicleVector(cont)); addReplacing(newElem); } else { VehicleVector& stored = (*j).second; stored.reserve(stored.size() + cont.size()); copy(cont.begin(), cont.end(), back_inserter(stored)); } }
void MSVehicleContainer::add(SUMOVehicle* veh) { // check whether a new item shall be added or the vehicle may be // added to an existing list VehicleHeap::iterator i = find_if(array.begin() + 1, array.begin() + currentSize + 1, DepartFinder(veh->getParameter().depart)); if (currentSize == 0 || i == array.begin() + currentSize + 1) { // a new heap-item is necessary VehicleDepartureVector newElem(veh->getParameter().depart, VehicleVector()); newElem.second.push_back(veh); addReplacing(newElem); } else { // add vehicle to an existing heap-item (*i).second.push_back(veh); } }
RESULT YaDiskRVFSDriver::moveElement(const QString& path, const QString& newParentId) { RESULT res = eERROR_GENERAL; QFileInfo qInfo(path); VFSCache* cache = WebMounter::getCache(); VFSCache::iterator elem = cache->find(qInfo.absoluteFilePath()); if(elem != cache->end()) { QString response; res = m_httpConnector->moveElement(elem->getId(), elem->getParentId(), newParentId, elem->getType(), response); if(res == eNO_ERROR) { VFSElement newElem(elem->getType() , elem->getPath() , elem->getName() , elem->getEditMetaUrl() , elem->getEditMediaUrl() , elem->getSrcUrl() , elem->getId() , newParentId , elem->getModified() , elem->getPluginName()); VFSCache::iterator iter = cache->begin(); for(iter; iter != cache->end(); ++iter) { if(iter->getId() == newParentId) break; } QString path = iter->getPath() + QString(QDir::separator()) + newElem.getName(); QFileInfo fInfo(path); newElem.setPath(fInfo.absoluteFilePath()); cache->erase(elem); cache->insert(newElem); } } return res; }
RESULT YaDiskRVFSDriver::renameElement(const QString& path, const QString& newTitle) { RESULT res = eERROR_GENERAL; QFileInfo qInfo(path); VFSCache* cache = WebMounter::getCache(); VFSCache::iterator elem = cache->find(qInfo.absoluteFilePath()); if(elem != cache->end()) { QString response; res = m_httpConnector->renameElement(elem->getId(), elem->getType(), newTitle, response); if(res == eNO_ERROR) { qInfo = qInfo.dir().absolutePath() + QString(QDir::separator()) + newTitle; VFSElement newElem(elem->getType() , qInfo.absoluteFilePath() , newTitle , elem->getEditMetaUrl() , elem->getEditMediaUrl() , elem->getSrcUrl() , elem->getId() , elem->getParentId() , elem->getModified() , elem->getPluginName()); cache->erase(elem); cache->insert(newElem); if(newElem.getType() == VFSElement::DIRECTORY) { updateChildrenPath(newElem); } } } return res; }
int main(void) { stackType * s = init(); if (s == NULL) return 0; /* * Using stack to store int */ printf("Integers...\n"); printf("Initial size: %d\n", s->nElem); int * v = NULL; int i = 0; for (i = 0; i <= 12; i++) { v = (int*) malloc(sizeof(int)); *v = i; push(s, (stackElem*) newElem((int *) v)); } printf("Size:%d\n", s->nElem); // Should cast first from void * to int * and then get // the content of the pointer. To avoid warnings. printf("Top: %d\n", *(int *) top(s)->value); printf("Tail: %d\n", *(int *) tail(s)->value); clear(s); /* * Using stack to store strings */ printf("\nStrings....\n"); printf("Initial size: %d\n", s->nElem); push(s, (stackElem*) newElem((char *) "banana")); push(s, (stackElem*) newElem((char *) "jajajaj && ddd")); push(s, (stackElem*) newElem((char *) "melao da maezinha")); printf("Size:%d\n", s->nElem); printf("Top: %s\n", (char *) top(s)->value); printf("Tail: %s\n", (char *) tail(s)->value); clear(s); /* * Using a user defined data type */ printf("\nx_type...\n"); printf("Initial size: %d\n", s->nElem); x_type * x = (x_type *) malloc(sizeof(x_type)); x->a = 1; x->b = 2.5; x->c = "polenta frita"; push(s, (stackElem*) newElem((x_type *) x)); x_type * y = (x_type *) malloc(sizeof(x_type)); y->a = 2; y->b = 1.5; y->c = "jujubinha"; push(s, (stackElem*) newElem((x_type *) y)); printf("Size:%d\n", s->nElem); x = (x_type *) top(s)->value; y = (x_type *) tail(s)->value; printf("Top: %d-%.2f-%s\n", x->a, x->b, x->c); printf("Tail: %d-%.2f-%s\n", y->a, y->b, y->c); clear(s); printf("\nFinal size: %d\n", s->nElem); return 1; }
void StateOverride::insertOverride(UInt32 uiSlot, StateChunk *pChunk) { ChunkElement newElem(uiSlot, pChunk); ChunkStoreIt cIt = std::lower_bound(_vChunks.begin(), _vChunks.end (), newElem ); if(cIt == _vChunks.end()) { _vChunks.insert(cIt, newElem); } else { if(cIt->first == uiSlot) { cIt->second = pChunk; } else { _vChunks.insert(cIt, newElem); } } if(pChunk == NULL) { return; } UInt32 uiKey1 = _uiKeyGen & Key1Mask; UInt32 uiKey2 = (_uiKeyGen & Key2Mask) >> 10; UInt32 uiKey3 = (_uiKeyGen & Key3Mask) >> 20; if(uiKey1 != InvalidKey && uiKey1 == uiSlot) { uiKey1 = (pChunk->getIgnore() == false) ? pChunk->getChunkId() : 0; _uiKeyMask &= ~Key1Mask; } else { uiKey1 = 0; } if(uiKey2 != InvalidKey && uiKey2 == uiSlot) { uiKey2 = (pChunk->getIgnore() == false) ? pChunk->getChunkId() : 0; _uiKeyMask &= ~Key2Mask; } else { uiKey2 = 0; } if(uiKey3 != InvalidKey && uiKey3 == uiSlot) { uiKey3 = (pChunk->getIgnore() == false) ? pChunk->getChunkId() : 0; _uiKeyMask &= ~Key3Mask; } else { uiKey3 = 0; } _uiSortKey = (uiKey1 & Key1Mask) | ((uiKey2 & Key1Mask) << 10) | ((uiKey3 & Key1Mask) << 20); }