static aoi_type xl_get_vers_discriminator_type() { static aoi_type type = 0; if (type == 0) { aoi_struct *type_struct; type = (aoi_type) mustmalloc(sizeof(aoi_type_u)); type->kind = AOI_STRUCT; type_struct = &(type->aoi_type_u_u.struct_def); /* Allocate and fill in the structure type slots. */ type_struct->slots.slots_len = 2; type_struct->slots.slots_val = ((aoi_struct_slot *) mustmalloc(sizeof(aoi_struct_slot) * type_struct->slots.slots_len)); type_struct->slots.slots_val[0].name = "prog_code"; type_struct->slots.slots_val[0].type = new_int(0, 4294967295U); type_struct->slots.slots_val[1].name = "vers_code"; type_struct->slots.slots_val[1].type = new_int(0, 4294967295U); } return type; }
static aoi_type xl_typedef(definition *def_ptr, typedef_def def) { /* * This should be an indirect to the appropriate type, be it structure, * union, enum, etc. It will also possible be an array/pointer to that * structure (requires deeper indirection old_prefix is necessary for * forward references). */ aoi_type component_type, result_type; int array_maximum; /* First, build the component type. */ component_type = xl_td_buildtype(def_ptr, def.old_type); if (def.rel == REL_ALIAS) return component_type; else if (def.rel == REL_POINTER) return make_optional(component_type); if (!strcmp(def.old_type, "string") || !strcmp(def.old_type, "opaque")) /* * `xl_td_buildtype' builds strings and opaques as variable * length arrays. We need to reset the array bounds below. */ result_type = component_type; else if ((def.rel == REL_VECTOR) || (def.rel == REL_ARRAY)) { /* It's an array. */ result_type = (aoi_type) mustmalloc(sizeof(aoi_type_u)); result_type->kind = AOI_ARRAY; result_type->aoi_type_u_u.array_def.element_type = component_type; result_type->aoi_type_u_u.array_def.flgs = AOI_ARRAY_FLAG_NONE; } else panic("Unknown typedef type %d in `xl_typedef'.", def.rel); /* * At this point we are dealing with a REL_VECTOR or a REL_ARRAY. * We need to determine the array's length. */ array_maximum = xl_eval(def_ptr, def.array_max); switch (def.rel) { case REL_VECTOR: result_type->aoi_type_u_u.array_def.length_type = new_int(array_maximum, 0); break; case REL_ARRAY: result_type->aoi_type_u_u.array_def.length_type = new_int(0, array_maximum); break; default: panic("Unknown array type %d in `xl_typedef'.", def.rel); break; } return result_type; }
int main(int argc,char ** argv){ int * visitado,otimo; Tour pop[TAMPOP], * melhor; struct tms before,after; if(argc != 3){ printf("USO : %s 'instancia' 'otimo' \n\n",argv[0]); return 1; } otimo = atoi(argv[2]); times(&before); read(argv[1],d,n); visitado = new_int(n); init_int(visitado,n); pop[0] = rand_tour(); pop[1] = rand_tour(); createSet(); LinKernighan(pop[0]); LinKernighan(pop[1]); pop[2] = new_tour(); pop[2]->c = new_int(n); pop[2]->pos = new_int(n); pop[3] = new_tour(); pop[3]->c = new_int(n); pop[3]->pos = new_int(n); PMX(pop[2],pop[3],pop[0],pop[1]); LinKernighan(pop[2]); LinKernighan(pop[3]); printf("PAI 1 : \n"); print_tour(pop[0]); printf("PAI 2 : \n"); print_tour(pop[1]); printf("FILHO 1 : \n"); print_tour(pop[2]); printf("FILHO 2 : \n"); print_tour(pop[3]); melhor = &pop[0]; //print_tour(melhor); times(&after); double tempo = (double)(after.tms_utime - before.tms_utime)/(double)100; double gap = ((double)((*(melhor))->cost-otimo)/(double) otimo) * 100.0; printf("%s\t%.2lfs\t%d\t%d\t%.3lf\n",argv[1],tempo,otimo,(*(melhor))->cost,gap); //printf("System time: %ld seconds\n", after.tms_stime - before.tms_stime); return 0; }
/******************** class arraytypedecl ********************/ arraytypedecl::arraytypedecl(bool interleaved, typedecl * indextype, typedecl * elementtype) : typedecl(), interleaved(interleaved), indextype(indextype), elementtype(elementtype) { Error.CondError(!indextype->issimple(), "Array index type must be a simple type."); if (elementtype->name == NULL) symtab->declare_global(ltable.enter(tsprintf("_type_%d", new_int() ) ), elementtype); numbits = indextype->getsize() * elementtype->getbitsalloc(); bitsalloc = numbits; // classify array type according to scalarset involvement if (indextype->getstructure() == typedecl::NoScalarset) structure = elementtype->getstructure(); else if (indextype->getstructure() == typedecl::ScalarsetVariable) if (elementtype->getstructure() == typedecl::NoScalarset) structure = typedecl::ScalarsetArrayOfFree; else if (elementtype->getstructure() == typedecl::ScalarsetVariable) structure = typedecl::ScalarsetArrayOfScalarset; else structure = typedecl::Complex; else Error.Error("Complex type as index to array."); }
int Resource::RegisterSymbol(char *symbol, arg_type_t type, void *data) { arg_list_t *sym; arg_list_t *sym_name; if (!symbol || !symbol[0]) { return -1; } switch (type) { case FUNC: printf("You can't bind functions using generic binding\n"); return -2; break; case INT: new_int(&sym, *((int *)data)); break; case FLOAT: new_float(&sym, *((float *)data)); break; case CSTRING: mlisp_new_string(&sym, (char *)data); break; default: mlisp_new_adt(&sym, type, data); } mlisp_new_string(&sym_name, symbol); Bind(sym_name, sym); return 0; }
int main() { LIST *list = DList_create(); int i = 0; for(i = 0 ; i < 10 ; ++ i) { int *p = new_int(i * 10 - 5); printf("append %d\n" , *p); DList_append(list , p); if(i % 3 == 0) { int *q = (int *)DList_delete(list); printf("delete %d\n" , *q); free(q); } } printf("list for each : \n"); DList_foreach(list , print_int , NULL); printf("\n"); printf("list size is %d\n" , DList_size(list)); printf("list get head is %d\n" , *(int *)DList_getHead(list)); printf("list get rear is %d\n" , *(int *)DList_getRear(list)); DList_destory(list); return 0; }
static aoi_interface xl_new_prog_interface(definition *def_ptr, char *code) { /* This builds an empty interface to represent a program. */ aoi_interface res; res.idl = AOI_IDL_SUN; res.code_type = new_int(0, 4294967295U); res.code = aoi_new_const_int(xl_eval(def_ptr, code)); res.parents.parents_len = 0; res.ops.ops_len = 0; res.attribs.attribs_len = 0; res.excepts.excepts_len = 0; res.op_code_type = new_int(0, 4294967295U); return res; }
static int handle_integer(void *ctx, long integerVal) { struct parse_context *pctx = (struct parse_context *)ctx; Var v; v = new_int((int)integerVal); PUSH(pctx->top, v); return 1; }
int main() { unique_ptr<int> v1 = new_int(); unique_ptr<int, array_deleter<int> > v2 = new_int_array(); unique_ptr<int, void(*)(void *)> v3 = malloc_int(); std::cout << *v1 << std::endl; v1.reset(NULL); return 0; }
static aoi_interface xl_new_vers_interface(definition *def_ptr, int prog_ref, char *vers_code) { /* This builds an interface to represent a version. */ aoi_interface res; aoi_const_struct *discriminator; aoi_type prog_binding; aoi_const prog_code; /* * First, make sure we're inheriting from a program, and extract the * program's discriminator code. */ prog_binding = outaoi.defs.defs_val[prog_ref].binding; if (prog_binding->kind != AOI_INTERFACE) panic("`xl_new_vers_interface' received a bogus `prog_ref'."); prog_code = prog_binding->aoi_type_u_u.interface_def.code; res.idl = AOI_IDL_SUN; /* * Construct the union discriminator value. * XXX --- Say something about why we use a struct here. */ res.code = aoi_new_const(AOI_CONST_STRUCT); discriminator = &(res.code->aoi_const_u_u.const_struct); discriminator->aoi_const_struct_len = 2; discriminator->aoi_const_struct_val = ((aoi_const *) mustmalloc(sizeof(aoi_const) * discriminator->aoi_const_struct_len)); discriminator->aoi_const_struct_val[0] = prog_code; discriminator->aoi_const_struct_val[1] = aoi_new_const_int(xl_eval(def_ptr, vers_code)); res.code_type = xl_get_vers_discriminator_type(); /* Inherit the parent program. */ res.parents.parents_len = 1; res.parents.parents_val = (aoi_type *) mustmalloc(sizeof(aoi_type)); res.parents.parents_val[0] = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res.parents.parents_val[0]->kind = AOI_INDIRECT; res.parents.parents_val[0]->aoi_type_u_u.indirect_ref = prog_ref; /* Initialize the remaining interface fields. */ res.ops.ops_len = 0; res.attribs.attribs_len = 0; res.excepts.excepts_len = 0; res.op_code_type = new_int(0, 4294967295U); return res; }
pctl::pctl(pctl * subf1, pctl * subf2, expr * ap, pctl_type pctltype, int until_bound, expr * prob_bound) :subformula1(subf1), subformula2(subf2), atomic_proposition(ap), pctltype(pctltype), code(new_int() + 1), until_bound(until_bound) { Error.CondError(pctltype == AP_PCTL && ap->has_side_effects(), "Atomic propositions in PCTL formulas must not have side effects."); if (prob_bound != NULL) this->prob_bound = prob_bound->getrvalue(); }
/******************** class vardecl ********************/ vardecl::vardecl(typedecl * type) : decl(), type(type) { if (type->name == NULL) symtab->declare_global(ltable.enter(tsprintf("_type_%d", new_int())), type); offset =::offset; ::offset += type->getbitsalloc(); if (args->no_compression) { if (type->getbitsalloc() % 8 != 0) Error.Error("Internal error, byte aligned allocation failed."); } }
save_kine() { char base[128]; int fmat=1; sprintf(base,"frame"); #ifdef NOGIF #else new_int("format:1-ppm,2-gif",&fmat); #endif new_string("Base file name",base); if(strlen(base)>0) save_movie(base,fmat); }
void new_lookup_com(int i) { char file[128]; int index, ok, status; double xlo, xhi; int npts; char newform[80]; index = select_table(); if (index == -1) return; if (i == 1) { view_table(index); return; } if (my_table[index].flag == 1) { strcpy(file, my_table[index].filename); status = file_selector("Load table", file, "*.tab"); if (status == 0) return; ok = load_table(file, index); if (ok == 1) strcpy(my_table[index].filename, file); } if (my_table[index].flag == 2) { npts = my_table[index].n; xlo = my_table[index].xlo; xhi = my_table[index].xhi; strcpy(newform, my_table[index].filename); new_int("Auto-evaluate? (1/0)", &my_table[index].autoeval); new_int("NPts: ", &npts); new_float("Xlo: ", &xlo); new_float("Xhi: ", &xhi); new_string("Formula :", newform); create_fun_table(npts, xlo, xhi, newform, index); } }
int main(int argc, char **argv) { void *print_me(); void* q = (void *)malloc(5*sizeof(void*)); void* ptr = q; int * i = new_int(4); ptr = (void *)i; int *j = new_int(9); ptr ++; ptr = (void*)j; ptr = NULL; int k=0; void *p = q; for(k=0; k<2; k++){ int * my_int = (int *)p; printf("pos %d, value %d\n", k,*my_int); } void *print_me(); //printf("Start\n"); //printf("Number of args: %d\n", argc); //int a = 0; //printf("true %d\n", (a == 0)); //printf("false %d\n", (a != 0)); //run(); //printf("Done\n"); return (0); }
static aoi_type xl_const(definition *def_ptr, const_def def) { /* * Constants are UNTYPED in XDR. This causes some pretty hokey * problems in the optimizer, so they are constrained to be * dereferenceable if used. This means that you can't just say * `const a = b', unless `b' is declared as `const b = 1'. */ aoi_type res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_CONST; res->aoi_type_u_u.const_def.type = new_int(-2147483647-1, ~0U); res->aoi_type_u_u.const_def.value = xl_deref_const(def_ptr, def, 0); return res; }
void froz_cline_stuff_com(int i) { int delay=200; if(n_nstore==0)start_ncline(); switch(i){ case 0: if(NULL_HERE==0)return; add_froz_cline(X_n,num_x_n,null_ix,Y_n,num_y_n,null_iy); break; case 1: clear_froz_cline(); break; case 3: new_int("Delay (msec)",&delay); if(delay<=0)delay=0; redraw_froz_cline(delay); break; case 2: do_range_clines(); break; } }
/******************** class multisettypedecl ********************/ multisettypedecl::multisettypedecl(bool interleaved, expr * e, typedecl * elementtype) : typedecl(), interleaved(interleaved), elementtype(elementtype), msclist(NULL) { Error.CondError(!e->hasvalue(), "CONST declaration requires constant expression."); maximum_size = e->getvalue(); if (elementtype->name == NULL) symtab->declare_global(ltable.enter(tsprintf("_type_%d", new_int() ) ), elementtype); if (!args->no_compression) { numbits = maximum_size * elementtype->getbitsalloc() + maximum_size * 2; } else { numbits = maximum_size * elementtype->getbitsalloc() + maximum_size * 8; } bitsalloc = numbits; mu_type = (maximum_size > 254 ? "mu__long" : "mu__byte"); // CeilLog2(maximum_size+2); // classify array type according to scalarset involvement if (elementtype->getstructure() == typedecl::NoScalarset) structure = typedecl::MultisetOfFree; // else if ( elementtype->getstructure() == typedecl::ScalarsetVariable ) // structure = typedecl::MultisetOfScalarset; else structure = typedecl::Complex; }
main() { struct al *l; int *u; l = al_create(5); al_add(l, new_int(1)); al_add(l, new_int(2)); al_add(l, new_int(3)); printf("%d\n", al_resize(l, 3)); al_dump(l); al_insertat(l, 0, new_int(4)); al_dump(l); printf("%d\n", al_insertat(l, 6, NULL)); printf("%d\n", al_insertat(l, 3, new_int(5))); al_dump(l); printf("%d\n", al_removeat(l, 5)); printf("%d\n", al_removeat(l, 4)); printf("%d\n", al_insertat(l, 2, u = new_int(6))); al_dump(l); printf("%d\n", al_remove(l, u)); al_dump(l); free(l); return 0; }
int vector_test() { typedef std::vector<int> MyStdVector; typedef typename MyShmVector::value_type IntType; std::string process_name; test::get_process_id_name(process_name); const int Memsize = 65536; const char *const shMemName = process_name.c_str(); const int max = 100; { //Compare several shared memory vector operations with std::vector //Create shared memory shared_memory_object::remove(shMemName); try{ ManagedSharedMemory segment(create_only, shMemName, Memsize); segment.reserve_named_objects(100); //Shared memory allocator must be always be initialized //since it has no default constructor MyShmVector *shmvector = segment.template construct<MyShmVector>("MyShmVector") (segment.get_segment_manager()); MyStdVector *stdvector = new MyStdVector; shmvector->resize(100); stdvector->resize(100); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(200); stdvector->resize(200); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType new_int(i); shmvector->insert(shmvector->end(), boost::interprocess::move(new_int)); stdvector->insert(stdvector->end(), i); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; typename MyShmVector::iterator shmit(shmvector->begin()); typename MyStdVector::iterator stdit(stdvector->begin()); typename MyShmVector::const_iterator cshmit = shmit; ++shmit; ++stdit; shmvector->erase(shmit); stdvector->erase(stdit); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; { //Initialize values IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); BOOST_STATIC_ASSERT((::boost::interprocess::is_movable<boost::interprocess::test::movable_int>::value == true)); aux_vect[i] = boost::interprocess::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmvector->insert(shmvector->end() ,::boost::interprocess::make_move_iterator(&aux_vect[0]) ,::boost::interprocess::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0, j = static_cast<int>(shmvector->size()); i < j; ++i){ shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); aux_vect[i] = boost::interprocess::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmvector->insert(shmvector->begin() ,::boost::interprocess::make_move_iterator(&aux_vect[0]) ,::boost::interprocess::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->begin(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } shmvector->reserve(shmvector->size()*2); stdvector->reserve(stdvector->size()*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; IntType push_back_this(1); shmvector->push_back(boost::interprocess::move(push_back_this)); stdvector->push_back(int(1)); shmvector->push_back(IntType(1)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; if(!copyable_only(shmvector, stdvector ,detail::bool_<!is_movable<IntType>::value>())){ return 1; } shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType insert_this(i); shmvector->insert(shmvector->begin(), boost::interprocess::move(insert_this)); stdvector->insert(stdvector->begin(), i); shmvector->insert(shmvector->begin(), IntType(i)); stdvector->insert(stdvector->begin(), int(i)); } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; //Test insertion from list { std::list<int> l(50, int(1)); shmvector->insert(shmvector->begin(), l.begin(), l.end()); stdvector->insert(stdvector->begin(), l.begin(), l.end()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->assign(l.begin(), l.end()); stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } /* std::size_t cap = shmvector->capacity(); shmvector->reserve(cap*2); stdvector->reserve(cap*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; */ delete stdvector; segment.template destroy<MyShmVector>("MyShmVector"); segment.shrink_to_fit_indexes(); if(!segment.all_memory_deallocated()) return 1; } catch(std::exception &ex){ shared_memory_object::remove(shMemName); std::cout << ex.what() << std::endl; return 1; } } shared_memory_object::remove(shMemName); std::cout << std::endl << "Test OK!" << std::endl; return 0; }
int list_test (bool copied_allocators_equal = true) { typedef std::list<int> MyStdList; typedef typename MyBoostList::value_type IntType; const int max = 100; typedef list_push_data_function<DoublyLinked> push_data_t; BOOST_TRY{ MyBoostList *boostlist = new MyBoostList; MyStdList *stdlist = new MyStdList; if(push_data_t::execute(max, boostlist, stdlist)){ return 1; } boostlist->erase(boostlist->begin()++); stdlist->erase(stdlist->begin()++); if(!CheckEqualContainers(boostlist, stdlist)) return 1; if(list_pop_back_function<DoublyLinked>::execute(boostlist, stdlist)){ return 1; } boostlist->pop_front(); stdlist->pop_front(); if(!CheckEqualContainers(boostlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } boostlist->assign(boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(&aux_vect[50])); stdlist->assign(&aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(boostlist, stdlist)) return 1; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } boostlist->assign(boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0])) ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[50]))); stdlist->assign(&aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } if(copied_allocators_equal){ boostlist->sort(); stdlist->sort(); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } boostlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(boostlist, stdlist)) return 1; boostlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(boostlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } typename MyBoostList::iterator old_begin = boostlist->begin(); typename MyBoostList::iterator it_insert = boostlist->insert(boostlist->begin() ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(&aux_vect[50])); if(it_insert != boostlist->begin() || std::distance(it_insert, old_begin) != 50) return 1; stdlist->insert(stdlist->begin(), &aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(boostlist, stdlist)) return 1; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } old_begin = boostlist->begin(); it_insert = boostlist->insert(boostlist->end() ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0])) ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[50]))); if(std::distance(it_insert, boostlist->end()) != 50) return 1; stdlist->insert(stdlist->end(), &aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } boostlist->unique(); stdlist->unique(); if(!CheckEqualContainers(boostlist, stdlist)) return 1; if(copied_allocators_equal){ boostlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } for(int i = 0; i < max; ++i){ IntType new_int(i); boostlist->insert(boostlist->end(), boost::move(new_int)); stdlist->insert(stdlist->end(), i); if(!test::CheckEqualContainers(boostlist, stdlist)) return 1; } if(!test::CheckEqualContainers(boostlist, stdlist)) return 1; boostlist->resize(25); stdlist->resize(25); boostlist->resize(50); stdlist->resize(50); boostlist->resize(0); stdlist->resize(0); if(!CheckEqualContainers(boostlist, stdlist)) return 1; if(push_data_t::execute(max, boostlist, stdlist)){ return 1; } { MyBoostList otherboostlist(boostlist->get_allocator()); MyStdList otherstdlist; int listsize = (int)boostlist->size(); if(push_data_t::execute(listsize, boostlist, stdlist)){ return 1; } if(copied_allocators_equal){ boostlist->splice(boostlist->begin(), otherboostlist); stdlist->splice(stdlist->begin(), otherstdlist); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } listsize = (int)boostlist->size(); if(push_data_t::execute(listsize, boostlist, stdlist)){ return 1; } if(push_data_t::execute(listsize, &otherboostlist, &otherstdlist)){ return 1; } if(copied_allocators_equal){ boostlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(boostlist, stdlist)) return 1; otherboostlist.sort(std::greater<IntType>()); otherstdlist.sort(std::greater<int>()); if(!CheckEqualContainers(&otherboostlist, &otherstdlist)) return 1; boostlist->merge(otherboostlist, std::greater<IntType>()); stdlist->merge(otherstdlist, std::greater<int>()); if(!CheckEqualContainers(boostlist, stdlist)) return 1; } if(!list_copyable_only(boostlist, stdlist ,container_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){ return 1; } } delete boostlist; delete stdlist; } BOOST_CATCH(...){ BOOST_RETHROW; } BOOST_CATCH_END return 0; }
static int handle_string(void *ctx, const unsigned char *stringVal, unsigned int stringLen) { struct parse_context *pctx = (struct parse_context *)ctx; var_type type; Var v; const char *val = (const char *)stringVal; size_t len = (size_t)stringLen; if (MODE_EMBEDDED_TYPES == pctx->mode && TYPE_NONE != (type = valid_type(&val, &len))) { switch (type) { case TYPE_OBJ: { char *p; if (*val == '#') val++; v.type = TYPE_OBJ; v.v.num = strtol(val, &p, 10); break; } case TYPE_INT: { char *p; v = new_int(strtol(val, &p, 10)); break; } case TYPE_FLOAT: { char *p; v = new_float(strtod(val, &p)); break; } case TYPE_ERR: { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_ERR; int err = parse_error(temp); v.v.err = err > -1 ? err : E_NONE; break; } case TYPE_STR: { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_STR; v.v.str = str_dup(temp); break; } default: panic("Unsupported type in handle_string()"); } } else { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_STR; v.v.str = str_dup(temp); } PUSH(pctx->top, v); return 1; }
//DOC_FUNC_DEF(flex_getchar DG_FLEX_READCHAR) long flex_getchar(parser_master_t*p) { // EOF== was end, EOF-1==was end but rewinded BEGIN_FUNCTION(flex_getchar,2); long fgetc_needed =0; char return_char='z'; long return_size=1; long * flex_num_chars_x; long * array_pos_x; long debug_false_char=0; col_t**xstring; flex_num_chars_x = &p->current_text_heap->flex_num_chars; array_pos_x = &p->current_text_heap->array_pos; xstring=(col_t**)&(p->current_text_heap->xstring); ASSERT(DER(xstring)); if (*array_pos_x==*flex_num_chars_x) { //read from file char received_char[251];//={0,0}; col_t*c; if(p->current_text_heap->eof_flag==EOF||p->current_text_heap->eof_flag==EOF-1){ // EOF== was end, EOF-1==was end but rewinded p->current_text_heap->eof_flag=EOF;// must again be EOF to inform flex no more input goto end1; } fgetc_needed=1; c=misc_get_next_ahead(p->current_text_heap);//after push misc_ahead_xstring the scanner must be restarted because we know nothing about internal scanner buffer // received_char[1] = 0; if(c){ received_char[0]=DER(val_xstring(c)); return_size=1; }else if(p->current_text_heap->file_ptr){ received_char[0] = 'Z'; return_size=fread(received_char,1,1,p->current_text_heap->file_ptr); /* return_size=read(fileno(p->current_text_heap->file_ptr),received_char,250); */ }else{ received_char[0] = EOF; debug_false_char=1,return_size=0; } if(c)col_unbound_col(c); if(return_size){ col_t* add_str01=col_new_xstring2(return_size+1,received_char,return_size); DER(xstring)=concat_xstring(DER(xstring),add_str01); /* if (!received_char[0]) */ /* { */ /* //this is the same as else, for '\0' */ /* received_char[0]=65; */ /* DER(xstring)=concat_xstring(DER(xstring),NEW_XSTRING_CONST(received_char)); */ /* DER(val_xstring(DER(xstring))+*flex_num_chars_x)=0; */ /* } */ /* else */ /* { */ /* DER(xstring)=concat_xstring(DER(xstring),NEW_XSTRING_CONST(received_char)); */ /* } */ (*array_pos_x)+=return_size; } }else{ //read from the buffer if(p->current_text_heap->eof_flag==EOF){ // EOF== was end, EOF-1==was end but rewinded // the scanner will see EOF!=EOF-1 and accept the next char p->current_text_heap->eof_flag=EOF-1; } } if(return_size){ return_char = DER(val_xstring(DER(xstring))+*flex_num_chars_x); (*flex_num_chars_x)++; } if (return_char=='\n' #if defined APPL_MAIN_APPLICATION_IDENTIFIER_CPP2 && APPL_MAIN_APPLICATION_IDENTIFIER_CPP2!=0 && !cmd_ln_args_state && (fgetc_needed||(part_text_partial_flag&&!p->current_text_heap->file_ptr)) #endif ) { col_t *i1,*i2; long result =aa_unset_col_col((col_t*)(p->current_text_heap->cnt_nl),i1=new_int((*flex_num_chars_x)-1)); result =aa_assign((col_t*)(p->current_text_heap->cnt_nl),i1,i2=new_int(p->current_text_heap->cnt_nl_length),RETURN_NULL_IF_EXISTS); ASSERT(result); if(!result) { col_unbound_col(i1); col_unbound_col(i2); } p->current_text_heap->cnt_nl_length++; } MISC_MACRO_AFTER_FLEX_GET_CHAR(); if (return_size==0) { //empty buffer and ( end of file or no file) p->current_text_heap->eof_flag=EOF; } /* else */ /* { */ /* p->current_text_heap->eof_flag=0; */ /* } */ end1: DEBUG_DUMP_CHAR(2,return_char); DEBUG_DUMP_INT(2,p->current_text_heap->eof_flag); DEBUG_DUMP_INT(2,debug_false_char); DEBUG_DUMP_INT(2,p->current_text_heap->array_pos); DEBUG_DUMP_INT(2,p->current_text_heap->flex_num_chars); // ASSERT(!debug_false_char); END_FUNCTION(flex_getchar,return return_char;,2);
int main() { printf("%d\n", new_int()); printf("%d\n", *new_int_ptr()); return 0; }
arg_list_t *Resource::Symbol() { int i = 0, j; arg_list_t *a; bool string = false; bool fp = false; float f; arg_list_t *adt; _symbol[0] = 0; if (Is('"')) { Lex(); string = true; } // Mongoose 2001.11.09: Best handle for? grouped (func (func if (Is('(')) { return Function(arg_peek(&_stack)); } while (string || (i == 0 && _look == '-') || isatoz(_look) || isAtoZ(_look) || isdigit(_look) || ismisc(_look)) { if (i < (int)_symbol_len) { _symbol[i++] = _look; _symbol[i] = 0; } if (string && Is('"')) { i--; _symbol[i] = 0; Lex(); break; } Lex(); if (string) { continue; } if (Is('.')) { fp = true; for (j = 0; j < i; j++) { if (!j && _symbol[j] == '-') continue; if (!isdigit(_symbol[j])) break; } if (i == j) { _symbol[i++] = _look; _symbol[i] = 0; Lex(); } } // Mongoose 2002.01.23, Hhhmm... fixes -100.00 and -100, // but is it 'good idea'? if (Is('-') && i == 0) { _symbol[i++] = _look; _symbol[i] = 0; Lex(); } } #ifdef DEBUG_RESOURCE_SYMBOL printf("%s\n", _symbol); #endif if (isnumeric(_symbol, &f)) { if (fp) { new_float(&a, f); } else { new_int(&a, (int)f); } } else { // Mongoose 2002.01.21, FIXME support ADTs and etc too if (Lookup(_symbol, &i)) { new_int(&a, i); } else if (Lookup(_symbol, &f)) { new_float(&a, f); } else if (string) { mlisp_new_string(&a, _symbol); } else if (Lookup(_symbol, &adt)) { mlisp_new_adt(&a, adt->type, adt->data); } else { // Mongoose 2002.01.21, FIXME: hack to handle old string // use for def symbols mlisp_new_string(&a, _symbol); } } return a; }
int main(int argc, char *argv[]) { char *all_in, *group_in, *subclass_in, *order_in ; char *family_in, *genus_in, *species_in, *tri_in, *show_infras ; char *loc_in, *x_in, *y_in ; request_level_t request_level ; char name_html[128], *name_plain ; char qstr[512] ; void *qd ; taxon *root ; taxon *group_p, *subc_p, *ord_p, *fam_p, *gen_p, *spec_p, *tri_p, *quad_p ; int has_orders, has_subclasses ; int is_ext = !strcmp(argv[0], "b98_list_ext") ? 1 : 0 ; /* get CGI vars */ decode_query_string(11, "all", &all_in, "group", &group_in, "subclass", &subclass_in, "order", &order_in, "family", &family_in, "genus", &genus_in, "species", &species_in, "tri", &tri_in, "loc", &loc_in, "x", &x_in, "y", &y_in) ; /* process mouse click */ if (nonempty(x_in)) { loc_in = map_convert_xy_to_name(atoi(x_in), atoi(y_in), MAP_DIR, MAP_NAME, "abbr") ; if (!nonempty(loc_in)) return_nothing() ; } /* determine "request level" of request */ if (nonempty(all_in)) request_level = ALL ; else if (nonempty(group_in)) request_level = GROUP ; else if (nonempty(subclass_in)) request_level = SUBCLASS ; else if (nonempty(order_in)) request_level = ORDER ; else if (nonempty(family_in)) request_level = FAMILY ; else if (nonempty(genus_in)) { if (nonempty(species_in)) if (nonempty(tri_in)) request_level = TRI ; else request_level = SPECIES ; else request_level = GENUS ; } else request_level = ERROR ; /* build MG query string */ switch(request_level) { case ALL: sprintf(qstr, "qqall") ; break; case GROUP: sprintf(qstr, "qqgrp%s", group_in) ; break ; case SUBCLASS: sprintf(qstr, "qqsbc%s", subclass_in) ; break ; case ORDER: sprintf(qstr, "qqord%s", order_in) ; break ; case FAMILY: sprintf(qstr, "qqfam%s", family_in) ; break ; case GENUS: sprintf(qstr, "qqgen%s", genus_in) ; break ; case SPECIES: case TRI: /* eliminate dashes in species names */ { char *temp_s, *dash_loc ; temp_s = strdup(species_in) ; if ((dash_loc = strchr(temp_s, '-')) != NULL) strcpy(dash_loc, dash_loc+1) ; sprintf(qstr, "qqgen%s&qqspe%s", genus_in, temp_s) ; free(temp_s) ; if (request_level == TRI) { temp_s = strdup(tri_in) ; if ((dash_loc = strchr(temp_s, '-')) != NULL) strcpy(dash_loc, dash_loc+1) ; sprintf(qstr+strlen(qstr), "&qqtri%s", temp_s) ; free(temp_s) ; } } break ; } if (nonempty(loc_in)) sprintf(qstr+strlen(qstr), "&qqloc%s", loc_in) ; /* execute MG query */ mg_bool_query(qstr, MG_COLL_DIR, MG_COLL_NAME, &qd) ; /* process MG query results */ if (mg_get_num_returned(qd) == 0) return_nothing() ; root = NULL ; { char s[256] ; void *lp=NULL ; int docnum ; do { clear_name_vars() ; docnum = mg_get_doc_num(qd) ; mg_setup_doc_line_producer(qd, docnum, &lp) ; while (mg_dlp_more_lines(lp)) { if (!strncmp(s, "qqgrp", 5)) strcpy(group_out, s+5) ; else if (!strncmp(s, "qqsbc", 5)) strcpy(subclass_out, s+5) ; else if (!strncmp(s, "qqord", 5)) strcpy(order_out, s+5) ; else if (!strncmp(s, "qqfam", 5)) strcpy(family_out, s+5) ; else if (!strncmp(s, "qqgen", 5)) strcpy(genus_out, s+5) ; else if (!strncmp(s, "qqhyb", 5)) hybrid = (!strncmp(s+5, "yes", 3) ? 1 : 0) ; else if (!strncmp(s, "qqspr", 5)) strcpy(species_out, s+5) ; else if (!strncmp(s, "qqtrs", 5)) strcpy(trirank_out, s+5) ; else if (!strncmp(s, "qqtrr", 5)) strcpy(tri_out, s+5) ; else if (!strncmp(s, "qqqus", 5)) strcpy(quadrank_out, s+5) ; else if (!strncmp(s, "qqqur", 5)) strcpy(quad_out, s+5) ; mg_dlp_next_line(lp, s) ; } switch (group_out[0]) { case 'P': group_p = insert_taxon_item(&root, "1Pteridophytes", NULL, 1) ; break ; case 'G': group_p = insert_taxon_item(&root, "2Gymnosperms", NULL, 1) ; break ; case 'M': group_p = insert_taxon_item(&root, "3Monocots", NULL, 1) ; break ; case 'D': group_p = insert_taxon_item(&root, "4Dicots", NULL, 1) ; break ; } subc_p = insert_taxon_child(group_p, subclass_out, NULL, 1) ; ord_p = insert_taxon_child(subc_p, order_out, NULL, 1) ; fam_p = insert_taxon_child(ord_p, family_out, NULL, 1) ; gen_p = insert_taxon_child(fam_p, genus_out, NULL, 1) ; spec_p = insert_taxon_child(gen_p, species_out, new_int(hybrid), 1) ; if (nonempty(tri_out)) { tri_p = insert_taxon_child(spec_p, tri_out, new_int(!strcmp(trirank_out, "var") ? 1 : 0), 1) ; if (nonempty(quad_out)) { quad_p = insert_taxon_child(tri_p, quad_out, new_int(!strcmp(quadrank_out, "var") ? 1 : 0), 1) ; } } } while (mg_goto_next_doc(qd)) ; } /* generate HTML page */ /* HTTP header */ return_header("text/html") ; build_name(name_html, request_level, 0) ; name_plain = strip_tags(name_html) ; puts("<html>") ; puts("<head>") ; printf("<title>BONAP Distribution Data: ") ; if (request_level == SPECIES || request_level == TRI) printf("subspecies/varieties ") ; else printf("taxa ") ; printf("of %s", name_plain) ; if (nonempty(loc_in)) printf(" in %s", map_convert_region_name(MAP_DIR, MAP_NAME, "abbr", "name", loc_in)) ; else puts(" in the US") ; puts("</title>") ; puts("</head>") ; puts("<body bgcolor=\"#ffffff\">") ; if (is_ext) ext_header() ; printf("<h1>") ; if (request_level == SPECIES || request_level == TRI) printf("Subspecies/varieties ") ; else printf("Taxa ") ; printf("of %s", name_html) ; if (nonempty(loc_in)) printf(" in %s", map_convert_region_name(MAP_DIR, MAP_NAME, "abbr", "name", loc_in)) ; else puts(" in the US") ; printf("</h1>") ; if (request_level > GROUP) { if (request_level <= GENUS) name_html[0] = toupper(name_html[0]) ; printf("%s is a member of the %s group", name_html, (root->name)+1) ; if (request_level > SUBCLASS) if (strcmp(root->nextlevel->name, "none")) printf(", subclass %s", root->nextlevel->name) ; if (request_level > ORDER) if (strcmp(root->nextlevel->nextlevel->name, "none")) printf(", order %s", root->nextlevel->nextlevel->name) ; if (request_level > FAMILY) printf(", family %s", root->nextlevel->nextlevel->nextlevel->name) ; /* Don't really need to mention genus because it's obvious from the species name */ /* if (request_level > GENUS) printf(", genus <i>%s</i>", root->nextlevel->nextlevel->nextlevel->nextlevel->name) ; */ puts(".<p>") ; } if (request_level <= ALL) puts("<ul>") ; group_p = root ; while (group_p != NULL) { if (request_level <= ALL) printf("%s<br>\n", (group_p->name)+1) ; subc_p = group_p->nextlevel ; has_subclasses = (strcmp(subc_p->name, "none") != 0) ; if (request_level <= GROUP) if (has_subclasses) puts("<ul>") ; while (subc_p != NULL) { strcpy(subclass_out, subc_p->name) ; if (request_level <= GROUP && has_subclasses) { build_name(name_html, SUBCLASS, 1) ; printf("<b>%s</b>", name_html) ; puts("<br>") ; } ord_p = subc_p->nextlevel ; has_orders = (strcmp(ord_p->name, "none") != 0) ; if (request_level <= SUBCLASS) if (has_orders) puts("<ul>") ; while (ord_p != NULL) { strcpy(order_out, ord_p->name) ; if (request_level <= SUBCLASS && has_orders) { build_name(name_html, ORDER, 1) ; printf("<b>%s</b><br>\n", name_html) ; } fam_p = ord_p->nextlevel ; if (request_level <= ORDER) puts("<ul>") ; while (fam_p != NULL) { strcpy(family_out, fam_p->name) ; if (request_level <= ORDER) { build_name(name_html, FAMILY, 1) ; printf("<b>%s</b><br>\n", name_html) ; } gen_p = fam_p->nextlevel ; if (request_level <= FAMILY) puts("<ul>") ; while (gen_p != NULL) { strcpy(genus_out, gen_p->name) ; if (request_level <= FAMILY) { build_name(name_html, GENUS, 1) ; printf("<b>%s</b> ", name_html) ; printf("<a href=\"%s?colldir=%s&collname=%s&" "query=%s\">(checklist entries)</a>", RULED_HTML_QUERY_URL, CHECKLIST_COLL_DIR, CHECKLIST_COLL_NAME, gen_p->name) ; printf(" <a href=\"%s?genus=%s\">(map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out) ; puts("<br>") ; } spec_p = gen_p->nextlevel ; if (request_level <= GENUS) puts("<ul>") ; while (spec_p != NULL) { strcpy(species_out, spec_p->name) ; hybrid = *((int *)(spec_p->other_data)) ; if (request_level <= GENUS) { build_name(name_html, SPECIES, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?colldir=%s&collname=%s&" "query=%s%%26%s\">(checklist entry)</a>", RULED_HTML_QUERY_URL, CHECKLIST_COLL_DIR, CHECKLIST_COLL_NAME, gen_p->name, spec_p->name) ; printf(" <a href=\"%s?genus=%s&species=%s\">(species " "map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out) ; if (spec_p->nextlevel != NULL) printf(" <a href=\"%s?genus=%s&species=%s&show_infras=yes\">" "(infras map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out) ; printf("<br>\n") ; } if (spec_p->nextlevel != NULL) puts("<ul>") ; tri_p = spec_p->nextlevel ; while (tri_p != NULL) { strcpy(tri_out, tri_p->name) ; strcpy(trirank_out, *((int *)(tri_p->other_data)) ? "var" : "ssp") ; build_name(name_html, TRI, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?genus=%s&species=%s&tri=%s\">" "(infra map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out) ; if (tri_p->nextlevel != NULL) printf(" <a href=\"%s?genus=%s&species=%s&tri=%s" "&show_infras=yes\">(subinfras map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out) ; puts("<br>") ; if (tri_p->nextlevel != NULL) puts("<ul>") ; quad_p = tri_p->nextlevel ; while (quad_p != NULL) { strcpy(quad_out, quad_p->name) ; strcpy(quadrank_out, *((int *)(quad_p->other_data)) ? "var" : "ssp") ; build_name(name_html, QUAD, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?genus=%s&species=%s&tri=%s&quad=%s\">" "(subinfra map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out, quad_out) ; puts("<br>") ; step_taxon(quad_p) ; } if (tri_p->nextlevel != NULL) puts("</ul>") ; step_taxon(tri_p) ; } if (spec_p->nextlevel != NULL) puts("</ul>") ; step_taxon(spec_p) ; } if (request_level <= GENUS) puts("</ul>") ; step_taxon(gen_p) ; } if (request_level <= FAMILY) puts("</ul>") ; step_taxon(fam_p) ; } if (request_level <= ORDER) puts("</ul>") ; step_taxon(ord_p) ; } if (request_level <= SUBCLASS) if (has_orders) puts("</ul>") ; step_taxon(subc_p) ; } if (request_level <= GROUP) if (has_subclasses) puts("</ul>") ; step_taxon(group_p) ; } if (request_level <= ALL) puts("</ul>") ; puts("</body>" "</html>") ; }
int vector_test() { typedef std::vector<int> MyStdVector; typedef typename MyBoostVector::value_type IntType; const int max = 100; { try{ MyBoostVector *boostvector = new MyBoostVector; MyStdVector *stdvector = new MyStdVector; boostvector->resize(100); stdvector->resize(100); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(200); stdvector->resize(200); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType new_int(i); boostvector->insert(boostvector->end(), boost::move(new_int)); stdvector->insert(stdvector->end(), i); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; typename MyBoostVector::iterator boostit(boostvector->begin()); typename MyStdVector::iterator stdit(stdvector->begin()); typename MyBoostVector::const_iterator cboostit = boostit; ++boostit; ++stdit; boostvector->erase(boostit); stdvector->erase(stdit); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; { //Initialize values IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); BOOST_STATIC_ASSERT((boost::container::test::is_copyable<boost::container::test::movable_int>::value == false)); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } boostvector->insert(boostvector->end() ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0, j = static_cast<int>(boostvector->size()); i < j; ++i){ boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } boostvector->insert(boostvector->begin() ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->begin(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } /* boostvector->reserve(boostvector->size()*2); stdvector->reserve(stdvector->size()*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; */ boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; IntType push_back_this(1); boostvector->push_back(boost::move(push_back_this)); stdvector->push_back(int(1)); boostvector->push_back(IntType(1)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; if(!vector_copyable_only(boostvector, stdvector ,containers_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){ return 1; } boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType insert_this(i); boostvector->insert(boostvector->begin(), boost::move(insert_this)); stdvector->insert(stdvector->begin(), i); boostvector->insert(boostvector->begin(), IntType(i)); stdvector->insert(stdvector->begin(), int(i)); } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; //Test insertion from list { std::list<int> l(50, int(1)); boostvector->insert(boostvector->begin(), l.begin(), l.end()); stdvector->insert(stdvector->begin(), l.begin(), l.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->assign(l.begin(), l.end()); stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } /* std::size_t cap = boostvector->capacity(); boostvector->reserve(cap*2); stdvector->reserve(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->clear(); stdvector->clear(); boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; */ delete stdvector; delete boostvector; } catch(std::exception &ex){ std::cout << ex.what() << std::endl; return 1; } } std::cout << std::endl << "Test OK!" << std::endl; return 0; }
int list_test (bool copied_allocators_equal = true) { typedef std::list<int> MyStdList; typedef typename MyShmList::value_type IntType; const int max = 100; typedef list_push_data_function<DoublyLinked> push_data_t; try{ MyShmList *shmlist = new MyShmList; MyStdList *stdlist = new MyStdList; if(push_data_t::execute(max, shmlist, stdlist)){ return 1; } shmlist->erase(shmlist->begin()++); stdlist->erase(stdlist->begin()++); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(list_pop_back_function<DoublyLinked>::execute(shmlist, stdlist)){ return 1; } shmlist->pop_front(); stdlist->pop_front(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmlist->assign(boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(&aux_vect[50])); stdlist->assign(&aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } if(copied_allocators_equal){ shmlist->sort(); stdlist->sort(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } shmlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; shmlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmlist->insert(shmlist->begin() ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(&aux_vect[50])); stdlist->insert(stdlist->begin(), &aux_vect2[0], &aux_vect2[50]); } shmlist->unique(); stdlist->unique(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(copied_allocators_equal){ shmlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } for(int i = 0; i < max; ++i){ IntType new_int(i); shmlist->insert(shmlist->end(), boost::move(new_int)); stdlist->insert(stdlist->end(), i); if(!test::CheckEqualContainers(shmlist, stdlist)) return 1; } if(!test::CheckEqualContainers(shmlist, stdlist)) return 1; shmlist->resize(25); stdlist->resize(25); shmlist->resize(50); stdlist->resize(50); shmlist->resize(0); stdlist->resize(0); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(push_data_t::execute(max, shmlist, stdlist)){ return 1; } { MyShmList othershmlist(shmlist->get_allocator()); MyStdList otherstdlist; int listsize = (int)shmlist->size(); if(push_data_t::execute(listsize, shmlist, stdlist)){ return 1; } if(copied_allocators_equal){ shmlist->splice(shmlist->begin(), othershmlist); stdlist->splice(stdlist->begin(), otherstdlist); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } listsize = (int)shmlist->size(); if(push_data_t::execute(listsize, shmlist, stdlist)){ return 1; } if(push_data_t::execute(listsize, &othershmlist, &otherstdlist)){ return 1; } if(copied_allocators_equal){ shmlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; othershmlist.sort(std::greater<IntType>()); otherstdlist.sort(std::greater<int>()); if(!CheckEqualContainers(&othershmlist, &otherstdlist)) return 1; shmlist->merge(othershmlist, std::greater<IntType>()); stdlist->merge(otherstdlist, std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } if(!list_copyable_only(shmlist, stdlist ,containers_detail::bool_<!is_movable<IntType>::value>())){ return 1; } } delete shmlist; delete stdlist; } catch(...){ throw; } return 0; }
static aoi_type xl_td_buildtype(definition *def_ptr, char *type) { aoi_type res; if (!strcmp(type, "float")) { res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_FLOAT; res->aoi_type_u_u.float_def.bits = 32; } else if (!strcmp(type, "double")) { res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_FLOAT; res->aoi_type_u_u.float_def.bits = 64; } else if (!strcmp(type, "char")) { res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_CHAR; res->aoi_type_u_u.char_def.bits = 8; res->aoi_type_u_u.char_def.flags = AOI_CHAR_FLAG_NONE; } else if (!strcmp(type, "u_char")) { res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_CHAR; res->aoi_type_u_u.char_def.bits = 8; res->aoi_type_u_u.char_def.flags = AOI_CHAR_FLAG_UNSIGNED; } else if (!strcmp(type, "void")) { res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_VOID; } else if (!strcmp(type, "string")) { aoi_type chr, len; res = (aoi_type)mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_ARRAY; res->aoi_type_u_u.array_def.flgs = AOI_ARRAY_FLAG_NULL_TERMINATED_STRING; chr = (aoi_type)mustmalloc(sizeof(aoi_type_u)); chr->kind = AOI_CHAR; chr->aoi_type_u_u.char_def.bits = 8; chr->aoi_type_u_u.char_def.flags = AOI_CHAR_FLAG_NONE; len = new_int(0, 4294967295U); res->aoi_type_u_u.array_def.element_type = chr; res->aoi_type_u_u.array_def.length_type = len; } else if (!strcmp(type, "opaque")) { aoi_type chr, len; res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_ARRAY; res->aoi_type_u_u.array_def.flgs = AOI_ARRAY_FLAG_OPAQUE; chr = (aoi_type) mustmalloc(sizeof(aoi_type_u)); chr->kind = AOI_INTEGER; chr->aoi_type_u_u.integer_def.min = 0; chr->aoi_type_u_u.integer_def.range = 255U; len = new_int(0, 4294967295U); res->aoi_type_u_u.array_def.element_type = chr; res->aoi_type_u_u.array_def.length_type = len; } else if (!strcmp(type, "int") || !strcmp(type, "long")) res = new_int(-2147483647-1, ~0U); else if (!strcmp(type, "u_int") || !strcmp(type, "u_long")) res = new_int(0, ~0U); else if (!strcmp(type, "short")) res = new_int(-32768, 65535); else if (!strcmp(type, "u_short")) res = new_int(0, 65535); else if (!strcmp(type, "bool")) res = new_int(0, 1); else { /* * At this point, it had better be a reference, and it should * already exist in the file. If not, we're dead... */ int ref = aoi_name(def_ptr, type, NO_CREATE); if (ref < 0) panic("Undefined type `%s'.", type); res = (aoi_type) mustmalloc(sizeof(aoi_type_u)); res->kind = AOI_INDIRECT; res->aoi_type_u_u.indirect_ref = ref; } return res; }
int vector_test() { typedef std::vector<int> MyStdVector; typedef typename MyBoostVector::value_type IntType; const int max = 100; if(!test_range_insertion<MyBoostVector>()){ return 1; } { BOOST_TRY{ MyBoostVector *boostvector = new MyBoostVector; MyStdVector *stdvector = new MyStdVector; boostvector->resize(100); stdvector->resize(100); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(200); stdvector->resize(200); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType new_int(i); boostvector->insert(boostvector->end(), boost::move(new_int)); stdvector->insert(stdvector->end(), i); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; typename MyBoostVector::iterator boostit(boostvector->begin()); typename MyStdVector::iterator stdit(stdvector->begin()); typename MyBoostVector::const_iterator cboostit = boostit; (void)cboostit; ++boostit; ++stdit; boostvector->erase(boostit); stdvector->erase(stdit); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; { //Initialize values IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); BOOST_STATIC_ASSERT((boost::container::test::is_copyable<boost::container::test::movable_int>::value == false)); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } typename MyBoostVector::iterator insert_it = boostvector->insert(boostvector->end() ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(aux_vect + 50)); if(std::size_t(std::distance(insert_it, boostvector->end())) != 50) return 1; stdvector->insert(stdvector->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0, j = static_cast<int>(boostvector->size()); i < j; ++i){ boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } { boostvector->resize(100); stdvector->resize(100); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-i); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -i; } typename MyBoostVector::size_type old_size = boostvector->size(); typename MyBoostVector::iterator insert_it = boostvector->insert(boostvector->begin() + old_size/2 ,boost::make_move_iterator(&aux_vect[0]) ,boost::make_move_iterator(aux_vect + 50)); if(boostvector->begin() + old_size/2 != insert_it) return 1; stdvector->insert(stdvector->begin() + old_size/2, aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0; i < 50; ++i){ IntType new_int(-i); aux_vect[i] = boost::move(new_int); } for(int i = 0; i < 50; ++i){ aux_vect2[i] = -i; } old_size = boostvector->size(); //Now try with input iterators instead insert_it = boostvector->insert(boostvector->begin() + old_size/2 ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0])) ,boost::make_move_iterator(make_input_from_forward_iterator(aux_vect + 50)) ); if(boostvector->begin() + old_size/2 != insert_it) return 1; stdvector->insert(stdvector->begin() + old_size/2, aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } /* //deque has no reserve boostvector->reserve(boostvector->size()*2); stdvector->reserve(stdvector->size()*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; */ boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; { //push_back with not enough capacity IntType push_back_this(1); boostvector->push_back(boost::move(push_back_this)); stdvector->push_back(int(1)); boostvector->push_back(IntType(1)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } { //test back() const IntType test_this(1); if(test_this != boostvector->back()) return 1; } { //pop_back with enough capacity boostvector->pop_back(); boostvector->pop_back(); stdvector->pop_back(); stdvector->pop_back(); IntType push_back_this(1); boostvector->push_back(boost::move(push_back_this)); stdvector->push_back(int(1)); boostvector->push_back(IntType(1)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } if(!vector_copyable_only(boostvector, stdvector ,container_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){ return 1; } boostvector->erase(boostvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType insert_this(i); boostvector->insert(boostvector->begin(), boost::move(insert_this)); stdvector->insert(stdvector->begin(), i); boostvector->insert(boostvector->begin(), IntType(i)); stdvector->insert(stdvector->begin(), int(i)); } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; //Test insertion from list { std::list<int> l(50, int(1)); typename MyBoostVector::iterator it_insert = boostvector->insert(boostvector->begin(), l.begin(), l.end()); if(boostvector->begin() != it_insert) return 1; stdvector->insert(stdvector->begin(), l.begin(), l.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->assign(l.begin(), l.end()); stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->clear(); stdvector->clear(); boostvector->assign(make_input_from_forward_iterator(l.begin()), make_input_from_forward_iterator(l.end())); stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } /* deque has no reserve or capacity std::size_t cap = boostvector->capacity(); boostvector->reserve(cap*2); stdvector->reserve(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->clear(); stdvector->clear(); boostvector->shrink_to_fit(); MyStdVector(*stdvector).swap(*stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; */ delete stdvector; delete boostvector; } BOOST_CATCH(std::exception &ex){ #ifndef BOOST_NO_EXCEPTIONS std::cout << ex.what() << std::endl; #endif return 1; } BOOST_CATCH_END }