static PyObject* Preprocessor_iter(Preprocessor *pp) { try { return (PyObject*)create_iterator(pp); } catch (...) { set_python_exception(); return NULL; } }
char *get_header_value(List *hdr_list,char *name){ Iterator *iterp; header *hdrp; iterp=create_iterator(hdr_list); while(iterp->has_next(iterp->currptr)){ hdrp=(header *)iterp->next(&iterp->currptr); if(str_loosecompare(hdrp->name,name)==0){ return hdrp->value; } } return NULL; }
int main() { Hash_map hash_map; Data data; Iterator iter; int i, correct= 1; int sorted_offsets[NUM]= {7, 8, 9, 2, 0, 3, 4, 6, 1, 5}; mcheck_pedantic(NULL); hash_map= create_example_hash_map(); iter= create_iterator(hash_map); for (i= 0; i < 5 && correct; i++) { data= next(&iter); if ((int) *((long *) data) != sorted_offsets[i]) correct= 0; } if (!get(&hash_map, (Key) (long) 'a', &data) || data != (Data) 7 || !get(&hash_map, (Key) (long) 'q', &data) || data != (Data) 0 || !get(&hash_map, (Key) (long) 'c', &data) || data != (Data) 9) correct= 0; reset(&iter); for (i= 0; i < NUM && correct; i++) { data= next(&iter); if ((int) *((long *) data) != sorted_offsets[i]) correct= 0; } if (correct && !has_next(iter)) printf("Correct values were accessed when iterating! :)\n"); else printf("Incorrect results occurred when iterating. :(\n"); clear(&hash_map); clear_iterator(&iter); if (mallinfo().uordblks != 0) printf("Memory leak of %d bytes. :(\n", mallinfo().uordblks); else printf("No memory leak detected. :)\n"); return 0; }
void create_iterator_linked_list(struct linked_list_t *linked_list, struct iterator_t **iterator_pointer) { /* allocates the iterator */ struct iterator_t *iterator; /* creates the iterator */ create_iterator(&iterator); /* sets the linked list in the structure */ iterator->structure = (void *) linked_list; /* sets the get next function in the iterator */ iterator->get_next_function = get_next_iterator_linked_list; /* resets the iterator */ reset_iterator_linked_list(linked_list, iterator); /* sets the iterator in the iterator pointer */ *iterator_pointer = iterator; }
void Invoice::print(InvoicePrinter& printer) { printer.print_header("I N V O I C E"); printer.print_string("Description", true); printer.print_string("Unit Price", false); printer.print_string("Qty", false); printer.print_string("Total Price", false); double amount_due = 0; for (ItemIterator iter = create_iterator(); !iter.is_done(); iter.next()) { Item* it = iter.get(); printer.print_string(it->get_description(), true); printer.print_number(it->get_unit_price(), 2); printer.print_number(it->get_quantity(), 0); printer.print_number(it->get_total_price(), 2); amount_due = amount_due + it->get_total_price(); } printer.print_footer("AMOUNT DUE:", amount_due); }
struct ipset_iterator * ipset_iterate_networks(struct ip_set *set, bool desired_value) { return create_iterator(set, desired_value, true); }
struct ipset_iterator * ipset_iterate(struct ip_set *set, bool desired_value) { return create_iterator(set, desired_value, false); }
/** * Funcion de hilo, donde se hacen las peticiones de gasolina a los servidores. */ void *pedir_gas() { int respuesta, envio; /*Tiempo de respuesta del centro y si enviara la gasolina*/ iterator it = NULL; /*Iterador sobre la cola de prioridad*/ distr cent; /*Para el chequeo de la cola*/ /*Itera sobre todos los centros hasta conseguir uno disponible*/ for (cent = next_it(it = create_iterator(centros)); ; cent = next_it(it)) { /*Si ya reviso todos los elementos, volvemos a comenzar*/ if (cent == NULL) { usleep(5 * MINUTO); it = create_iterator(centros); continue; } envio = conectar_centro('g', cent->puerto, cent->DNS); /*Si logro una conexion*/ if (envio != -1) { /*Si se enviara la gasolina*/ if (envio) { sem_wait(&semf); fprintf(out, "Peticion: %d, %s, Positiva\n", tiempo, cent->nombre); sem_post(&semf); break; /*Si NO se enviara la gasolina*/ } else { sem_wait(&semf); fprintf(out, "Peticion: %d, %s, Negativa\n", tiempo, cent->nombre); sem_post(&semf); } } } /*Tiempo de respuesta en llegar la gasolina*/ respuesta = cent->pr; usleep(respuesta * MINUTO); /*Wait para accesar a 'gas' y 'pet'*/ sem_wait(&sem); /*Agrega la carga del envio e indica que la peticion fue atendida*/ gas += CARGA; --pet; sem_wait(&semf); fprintf(out, "Llegada de la gandola: %d, %d\n", tiempo, gas); /*Si el tanque se lleno*/ if (gas == max) { fprintf(out, "Tanque full: %d\n", tiempo); } sem_post(&semf); /*Signal para liberar 'gas' y 'pet'*/ sem_post(&sem); pthread_exit(NULL); }
ipset_iterator_t * ipset_iterate_networks(ip_set_t *set, gboolean desired_value) { return create_iterator(set, desired_value, TRUE); }
ipset_iterator_t * ipset_iterate(ip_set_t *set, gboolean desired_value) { return create_iterator(set, desired_value, FALSE); }