int main(){ /*make list and output file*/ ListHndl TheList = newList(); FILE *out = fopen("out.out", "w"); /*test empty in empty case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); printf("testing insert one number\n"); insertAtFront(TheList,(unsigned long*)25728); printf("%lu\n",(unsigned long)getFirst(TheList)); printf("%lu\n",(unsigned long)getLast(TheList)); /*should have same value*/ printf("testing list with three numbers\n"); insertAtFront(TheList,(unsigned long*)1589458); insertAtBack(TheList,(unsigned long*)35762111234); printf("%lu\n",(unsigned long)getFirst(TheList)); /*test empty in full case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test moving the current pointer around*/ moveFirst(TheList); moveNext(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); moveLast(TheList); movePrev(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); /*test printList*/ printList(out, TheList); /*test makeEmpty*/ makeEmpty(TheList); if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test inserting functions*/ insertAtFront(TheList,(unsigned long*)2); insertAtFront(TheList,(unsigned long*)1); insertAtFront(TheList,(unsigned long*)4); insertAtBack(TheList,(unsigned long*)4); moveLast(TheList); insertBeforeCurrent(TheList,(unsigned long*)3); printList(out,TheList); deleteFirst(TheList); deleteCurrent(TheList); deleteLast(TheList); printList(out,TheList); makeEmpty(TheList); printList(out,TheList); /*free list and close output file*/ freeList(&TheList); fclose(out); return 0; }
int main() { ListHndl intList; intList = newList(); int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; /* * Integer list testing * */ printHeading(" INTEGER LIST ", '#', 80); printList(stdout, intList); accessorTest("isEmpty", 1, isEmpty(intList)); for(int i = 0; i < 10; i++) { insertAtFront(intList, data[i]); mutatorTest("%s : data = %d", "insertAtFront", data[i]); } moveFirst(intList); for(int i = 0; i < 5; i++) { printList(stdout, intList); insertBeforeCurrent(intList, data[i]); mutatorTest("insertBeforeCurrent : data = %d", data[i]); moveNext(intList); } accessorTest("isEmpty", 0, isEmpty(intList)); printList(stdout, intList); moveFirst(intList); while( !offEnd(intList) ) { printList(stdout, intList); moveNext(intList); } moveLast(intList); while( !offEnd(intList) ) { printList(stdout, intList); movePrev(intList); } makeEmpty(intList); mutatorTest("makeEmpty( intList)"); printList(stdout, intList); accessorTest("isEmpty", 1, isEmpty(intList)); freeList(intList); return 0; }
void gTreeRow::moveBefore(char *key) { gTreeRow *row; if (!key || !*key) { moveLast(); return; } row = tree->getRow(key); if (!row) return; if (strcmp(row->parent(), parent())) return; gtk_tree_store_move_before(tree->store, dataiter, row->dataiter); }
void joyStickBusyWaitingMonitor( void ) { uint32_t i; while ( 1 ) { if ( ~(LPC_GPIO1->FIOPIN | ~UP ) ) { moveUp(); } else if ( ~(LPC_GPIO1->FIOPIN | ~DOWN) ) { moveDown(); } else if( ~(LPC_GPIO1->FIOPIN | ~FIRST ) ) { moveFirst(); } else if( ~(LPC_GPIO1->FIOPIN | ~LAST ) ) { moveLast(); } for ( i = 0; i < 100000; ++i ) { // Pause } } }
terrama2::core::DataSetSeries terrama2::core::DataAccessorJsonCemaden::getSeries( const std::string& uri, const Filter& filter, DataSetPtr dataSet, std::shared_ptr<terrama2::core::FileRemover> /*remover*/) const { QString codestacao = QString::fromStdString(getCodePropertyName(dataSet)); QString inputTimestampProperty = QString::fromStdString(getInputTimestampPropertyName(dataSet)); std::string timestampProperty = getTimestampPropertyName(dataSet); QStringList staticData = QString::fromStdString(getStaticDataProperties(dataSet)).split(','); QString code = QString::fromStdString(getDCPCode(dataSet)); auto dataSetType = std::make_shared<te::da::DataSetType>(code.toStdString()); dataSetType->add(new te::dt::DateTimeProperty(timestampProperty, te::dt::TIME_INSTANT_TZ, true)); auto teDataSet = std::make_shared<te::mem::DataSet>(dataSetType.get()); te::core::URI teUri(uri); std::string filePath = getFolderMask(dataSet) + "/" + getDataMask(dataSet); auto jsonStr = readFileContents(teUri.path()+filePath); QJsonDocument doc = QJsonDocument::fromJson(jsonStr.c_str()); auto readingsArray = doc.object()["cemaden"].toArray(); // iterate over readings // and populate the dataset for(auto reading : readingsArray) { auto obj = reading.toObject(); //check if this is the DCP we want if(obj[codestacao].toString() != code) continue; auto timestampStr = obj[inputTimestampProperty].toString().toStdString(); auto timestamp = terrama2::core::TimeUtils::stringToTimestamp(timestampStr, "%Y-%m-%d %H:%M:%S%F"); // filter by timestamp if((filter.discardBefore && (*filter.discardBefore > *timestamp)) || (filter.discardAfter && (*filter.discardAfter < *timestamp))) continue; // create new item auto item = std::unique_ptr<te::mem::DataSetItem>(new te::mem::DataSetItem(teDataSet.get())); // add item to the end of the dataset teDataSet->moveLast(); teDataSet->add(item.get()); // check if the item has data bool hasData = false; // add timestamp to dataset item->setDateTime(timestampProperty, static_cast<te::dt::TimeInstantTZ*>(timestamp->clone())); for(auto val = obj.begin(); val != obj.end(); ++val) { auto key = val.key(); // ignore static data if(staticData.contains(key) || key == codestacao || key.toStdString() == timestampProperty) continue; // property name auto keyStr = key.toStdString(); // check if the property is already registered in the dataset auto properties = dataSetType->getProperties(); auto it = std::find_if(properties.cbegin(), properties.cend(), [&keyStr](te::dt::Property* property){ return property->getName() == keyStr; }); if(it == properties.cend()) { // update dataSetType te::dt::SimpleProperty* property = new te::dt::SimpleProperty(keyStr, te::dt::DOUBLE_TYPE, false); dataSetType->add(property); // update memory dataset structure teDataSet->add(keyStr, te::dt::DOUBLE_TYPE); } // add property value item->setDouble(keyStr, val.value().toDouble()); hasData = true; } if(!hasData) { // remove the item if no data was inserted teDataSet->remove(item.get()); } item.release(); } terrama2::core::DataSetSeries serie; serie.dataSet = dataSet; serie.syncDataSet = std::make_shared<terrama2::core::SynchronizedDataSet>(teDataSet); serie.teDataSetType = dataSetType; return serie; }
int main (){ /***Exercise List constructor***/ ListHndl List; List = NULL; List = newList (); if(List){ printf("List Created\n"); }else{ printf("List Not Created\n"); } printf("isEmpty %d\n",isEmpty(List)); /*should print 1*/ /***Populate with test data***/ int i; for(i=0; i<=4; i++){ insertAtFront(List,i); } printList(stdout, List); printf("isEmpty %d\n",isEmpty(List)); /*should print 0*/ int j; for(j=5; j<=9; j++){ insertAtBack(List,j); } printList(stdout, List); /***Exercise all access functions***/ printf("offEnd %d\n",offEnd(List));/*should print 0*/ printf("atFirst %d\n",atFirst(List));/*should print 0*/ printf("atLast %d\n",atLast(List));/*should print 0*/ printf("getFirst %d\n", getFirst(List));/*should print 4*/ printf("getLast %d\n", getLast(List));/*should print 9*/ printf("getCurrent %d\n", getCurrent(List));/*should print 0*/ /***Exercise all removal manipulation functions***/ deleteLast(List); printList(stdout, List); printf("getLast %d\n", getLast(List));/*should print 8*/ deleteFirst(List); printList(stdout, List); printf("getFirst \n", getFirst(List));/*should print 3*/ deleteCurrent(List); printList(stdout, List); moveLast(List); printList(stdout, List); movePrev(List); printList(stdout, List); moveNext(List); printList(stdout, List); /***Exercise various edge cases***/ makeEmpty(List); insertAtFront(List, 40); moveFirst(List); deleteCurrent(List); insertAtFront(List, 41); insertAtBack(List, 42); moveFirst(List); insertBeforeCurrent(List, 43); printList(stdout, List); /***Exercise List destructors***/ deleteCurrent(List); printList(stdout, List); makeEmpty(List); printf("offEnd %d\n",offEnd(List));/*should print 1*/ freeList(&List); return(0); }