//main function int main() { //print out some application instructions printf("Enter some numbers that are bigger than 0 and smaller than %u\n", UINT_MAX); printf("If you enter the number 0 the applications will print out all given numbers as a sorted list\n\n---- Input --------------\n\n"); //declare a c-generic datatype List container; //initialize the list memset(&container, 0, sizeof(List)); construct(List, &container, sizeof(unsigned int), FREEOBJ); while(1) { //read out an element unsigned int* t=malloc(sizeof(unsigned int)); scanf("%u", t); //add it to the list push_back(List, &container, t, DYNAMIC); //break if zero is the input if(*t==0) break; } printf("\n\n---- Unsorted --------------\n\n"); //set print functions set_print(List, &container, print); //print all element in our list print_all(List, &container); //lets have fun with iterators (instead using print_all) printf("\n\n---- Iterators --------------\n\n"); ListIter* i = create(ListIter, &container); //check if it is empty - this will never happen if(!empty(List, &container)) { //place the iterator at the first element head(ListIter, i); do { printf("%u\n", *((unsigned int*)retrieve(ListIter, i))); }while(!next(ListIter, i)); } //give the memory free destroy(ListIter, i); printf("\n\n---- Sorted ASC --------------\n\n"); //set the sort functions set_compare(List, &container, intcmp); //use the in-place sort sort(List, &container); print_all(List, &container); //give the memory free destruct(List, &container); printf("\n\n"); return 0; }
ErrorCode MyQueue<T>::retrieve_and_serve(T& item) { ErrorCode ans = success; ans = retrieve(item); serve(); return ans; }
int main(void) { QueueVector object; QueueVectorIter *ptr; unsigned int x, y; unsigned int value; memset(&object, 0, sizeof (object)); x = RUNS; construct(QueueVector, &object,sizeof(x),FREEOBJ); set_alloc(QueueVector, &object, ckalloc); set_dealloc(QueueVector, &object, ckfree); set_compare(QueueVector, &object, intcmp); set_print(QueueVector, &object, print); for (y = 0; y < x; y++) { srand((x * y) / (x - y) + (x + y / x)); switch ((rand() % NUMCASES) + BASE) { case 0: case 10: case 11: case 1: case 12: case 13: case 2: case 14: value = rand() % BOUND; push(QueueVector, &object, &value, DYNAMIC); break; case 3: case 15: case 4: case 5: case 6: case 16: pop(QueueVector, &object); break; case 7: case 17: case 8: case 9: front(QueueVector, &object); break; default: break; }; } destruct(QueueVector, &object); fprintf(stderr, "Now testing the iterators!\n"); construct_func(QueueVector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp, print, memcpy); for (x = 0; x < RUNS; x++) { value = rand(); push(QueueVector, &object, &value, STATIC); } ptr = create(QueueVectorIter, &object); head(QueueVectorIter, ptr); do { value = *(unsigned int *) retrieve(QueueVectorIter, ptr); } while (!next(QueueVectorIter, ptr)); assign(QueueVectorIter, ptr, &object); tail(QueueVectorIter, ptr); do { value = *(unsigned int *) retrieve(QueueVectorIter, ptr); } while (!prev(QueueVectorIter, ptr)); for(x = 0; x < RUNS; x++) { switch(rand() % 2) { case 1: next(QueueVectorIter,ptr); break; case 2: prev(QueueVectorIter,ptr); break; } } destroy(QueueVectorIter, ptr); destruct(QueueVector, &object); return EXIT_SUCCESS; }
/* * Sets up for retrieving the possible collisions */ std::vector<std::weak_ptr<Entity>> QuadTree::retrievePossibleCollisions(std::shared_ptr<Entity>& entity) { std::vector<std::weak_ptr<Entity>> possibleCollisions; return retrieve(possibleCollisions, std::weak_ptr<Entity>(entity)); }
// 获取队头元素并出队 ErrorCode retrieve_and_serve(QueueEntry &item) { ErrorCode ss = retrieve(item); if (ss == underflow) return ss; return serve(); }
int jump(int pc, char * operand){ int j_pc = retrieve(&jumpTable, operand); return j_pc; }
static int queue_retrieve (lua_State *L) { return retrieve(L, checkqueue(L, 1), lua_toboolean(L, 2)); }
V8Proxy* V8Proxy::retrieve() { DOMWindow* window = retrieveWindow(currentContext()); ASSERT(window); return retrieve(window->frame()); }
V8Proxy* V8Proxy::retrieve(ScriptExecutionContext* context) { if (!context || !context->isDocument()) return 0; return retrieve(static_cast<Document*>(context)->frame()); }
// Returns if the word is in the trie. bool search(string key) { return retrieve(key, true); }
// Returns if there is any word in the trie // that starts with the given prefix. bool startsWith(string prefix) { return retrieve(prefix, false); }
int main(int argc, const char ** argv) { std::string path = "./protocol"; if (argc > 1) path = argv[1]; fs::path protocol; std::istringstream ss { path }; ss >> protocol; if (!fs::is_directory(protocol)) throw std::runtime_error { path + " is not a directory or doesn't exist" }; auto local = fs::current_path() / "cpp" ; if (fs::exists(local) && fs::is_directory(local)) fs::remove_all(local); fs::create_directory(local); fs::create_directory(local / "enums"); fs::create_directory(local / "messages"); fs::create_directory(local / "types"); fs::create_directory(local / "datacenter"); /* enums */ std::cout << "Translating enums..." << std::endl; for (fs::recursive_directory_iterator it { protocol / "enums" }; it != fs::recursive_directory_iterator { }; ++it) { if (!fs::is_regular_file(it->path()) || it->path().extension() != ".as") { if (fs::is_directory(it->path())) create_directory(compute(local, protocol, it->path())); continue; } enum_file f { std::ifstream { it->path().string() } }; f.parse(); make_cpp_file(f.cpp_output(), compute(local, protocol, it->path().parent_path()) / (to_cpp_case(f.class_name()) + ".hpp")); } /* messages / types */ std::cout << "Translating messages and types..." << std::endl; std::unordered_map<std::string, network_file> network; std::unordered_map<std::string, fs::path> paths; retrieve(network, paths, local, protocol, "messages"); retrieve(network, paths, local, protocol, "types"); for (auto && it : paths) { auto && f = network.at(it.first); make_cpp_file(f.cpp_output(network), it.second); } /* datacenter */ std::cout << "Translating datacenter..." << std::endl; std::unordered_map<std::string, datacenter_file> datacenter; paths.clear(); retrieve(datacenter, paths, local, protocol, "datacenter"); for (auto && it : paths) { auto && f = datacenter.at(it.first); make_cpp_file(f.cpp_output(datacenter), it.second); } return 0; }
int Search_Compatibility::retrieve(long category2_ids[],int size_of_array) { long resulting_categorys[size_of_array]; return retrieve(category2_ids,resulting_categorys,size_of_array); }
bool Search_Compatibility::retrieve(long &category2) { long resulting_category; return retrieve(category2, resulting_category); }
static int qags (const gsl_function * f, const double a, const double b, const double epsabs, const double epsrel, const size_t limit, gsl_integration_workspace * workspace, double *result, double *abserr, gsl_integration_rule * q) { double area, errsum; double res_ext, err_ext; double result0, abserr0, resabs0, resasc0; double tolerance; double ertest = 0; double error_over_large_intervals = 0; double reseps = 0, abseps = 0, correc = 0; size_t ktmin = 0; int roundoff_type1 = 0, roundoff_type2 = 0, roundoff_type3 = 0; int error_type = 0, error_type2 = 0; size_t iteration = 0; int positive_integrand = 0; int extrapolate = 0; int disallow_extrapolation = 0; struct extrapolation_table table; /* Initialize results */ initialise (workspace, a, b); *result = 0; *abserr = 0; if (limit > workspace->limit) { GSL_ERROR ("iteration limit exceeds available workspace", GSL_EINVAL) ; } /* Test on accuracy */ if (epsabs <= 0 && (epsrel < 50 * GSL_DBL_EPSILON || epsrel < 0.5e-28)) { GSL_ERROR ("tolerance cannot be acheived with given epsabs and epsrel", GSL_EBADTOL); } /* Perform the first integration */ q (f, a, b, &result0, &abserr0, &resabs0, &resasc0); set_initial_result (workspace, result0, abserr0); tolerance = GSL_MAX_DBL (epsabs, epsrel * fabs (result0)); if (abserr0 <= 100 * GSL_DBL_EPSILON * resabs0 && abserr0 > tolerance) { *result = result0; *abserr = abserr0; GSL_ERROR ("cannot reach tolerance because of roundoff error" "on first attempt", GSL_EROUND); } else if ((abserr0 <= tolerance && abserr0 != resasc0) || abserr0 == 0.0) { *result = result0; *abserr = abserr0; return GSL_SUCCESS; } else if (limit == 1) { *result = result0; *abserr = abserr0; GSL_ERROR ("a maximum of one iteration was insufficient", GSL_EMAXITER); } /* Initialization */ initialise_table (&table); append_table (&table, result0); area = result0; errsum = abserr0; res_ext = result0; err_ext = GSL_DBL_MAX; positive_integrand = test_positivity (result0, resabs0); iteration = 1; do { size_t current_level; double a1, b1, a2, b2; double a_i, b_i, r_i, e_i; double area1 = 0, area2 = 0, area12 = 0; double error1 = 0, error2 = 0, error12 = 0; double resasc1, resasc2; double resabs1, resabs2; double last_e_i; /* Bisect the subinterval with the largest error estimate */ retrieve (workspace, &a_i, &b_i, &r_i, &e_i); current_level = workspace->level[workspace->i] + 1; a1 = a_i; b1 = 0.5 * (a_i + b_i); a2 = b1; b2 = b_i; iteration++; q (f, a1, b1, &area1, &error1, &resabs1, &resasc1); q (f, a2, b2, &area2, &error2, &resabs2, &resasc2); area12 = area1 + area2; error12 = error1 + error2; last_e_i = e_i; /* Improve previous approximations to the integral and test for accuracy. We write these expressions in the same way as the original QUADPACK code so that the rounding errors are the same, which makes testing easier. */ errsum = errsum + error12 - e_i; area = area + area12 - r_i; tolerance = GSL_MAX_DBL (epsabs, epsrel * fabs (area)); if (resasc1 != error1 && resasc2 != error2) { double delta = r_i - area12; if (fabs (delta) <= 1.0e-5 * fabs (area12) && error12 >= 0.99 * e_i) { if (!extrapolate) { roundoff_type1++; } else { roundoff_type2++; } } if (iteration > 10 && error12 > e_i) { roundoff_type3++; } } /* Test for roundoff and eventually set error flag */ if (roundoff_type1 + roundoff_type2 >= 10 || roundoff_type3 >= 20) { error_type = 2; /* round off error */ } if (roundoff_type2 >= 5) { error_type2 = 1; } /* set error flag in the case of bad integrand behaviour at a point of the integration range */ if (subinterval_too_small (a1, a2, b2)) { error_type = 4; } /* append the newly-created intervals to the list */ update (workspace, a1, b1, area1, error1, a2, b2, area2, error2); if (errsum <= tolerance) { goto compute_result; } if (error_type) { break; } if (iteration >= limit - 1) { error_type = 1; break; } if (iteration == 2) /* set up variables on first iteration */ { error_over_large_intervals = errsum; ertest = tolerance; append_table (&table, area); continue; } if (disallow_extrapolation) { continue; } error_over_large_intervals += -last_e_i; if (current_level < workspace->maximum_level) { error_over_large_intervals += error12; } if (!extrapolate) { /* test whether the interval to be bisected next is the smallest interval. */ if (large_interval (workspace)) continue; extrapolate = 1; workspace->nrmax = 1; } if (!error_type2 && error_over_large_intervals > ertest) { if (increase_nrmax (workspace)) continue; } /* Perform extrapolation */ append_table (&table, area); qelg (&table, &reseps, &abseps); ktmin++; if (ktmin > 5 && err_ext < 0.001 * errsum) { error_type = 5; } if (abseps < err_ext) { ktmin = 0; err_ext = abseps; res_ext = reseps; correc = error_over_large_intervals; ertest = GSL_MAX_DBL (epsabs, epsrel * fabs (reseps)); if (err_ext <= ertest) break; } /* Prepare bisection of the smallest interval. */ if (table.n == 1) { disallow_extrapolation = 1; } if (error_type == 5) { break; } /* work on interval with largest error */ reset_nrmax (workspace); extrapolate = 0; error_over_large_intervals = errsum; } while (iteration < limit); *result = res_ext; *abserr = err_ext; if (err_ext == GSL_DBL_MAX) goto compute_result; if (error_type || error_type2) { if (error_type2) { err_ext += correc; } if (error_type == 0) error_type = 3; if (res_ext != 0.0 && area != 0.0) { if (err_ext / fabs (res_ext) > errsum / fabs (area)) goto compute_result; } else if (err_ext > errsum) { goto compute_result; } else if (area == 0.0) { goto return_error; } } /* Test on divergence. */ { double max_area = GSL_MAX_DBL (fabs (res_ext), fabs (area)); if (!positive_integrand && max_area < 0.01 * resabs0) goto return_error; } { double ratio = res_ext / area; if (ratio < 0.01 || ratio > 100.0 || errsum > fabs (area)) error_type = 6; } goto return_error; compute_result: *result = sum_results (workspace); *abserr = errsum; return_error: if (error_type > 2) error_type--; if (error_type == 0) { return GSL_SUCCESS; } else if (error_type == 1) { GSL_ERROR ("number of iterations was insufficient", GSL_EMAXITER); } else if (error_type == 2) { GSL_ERROR ("cannot reach tolerance because of roundoff error", GSL_EROUND); } else if (error_type == 3) { GSL_ERROR ("bad integrand behavior found in the integration interval", GSL_ESING); } else if (error_type == 4) { GSL_ERROR ("roundoff error detected in the extrapolation table", GSL_EROUND); } else if (error_type == 5) { GSL_ERROR ("integral is divergent, or slowly convergent", GSL_EDIVERGE); } else { GSL_ERROR ("could not integrate function", GSL_EFAILED); } }
void NBNodeCont::joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc) { for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) { std::set<NBNode*> cluster = *i; assert(cluster.size() > 1); Position pos; bool setTL; std::string id; TrafficLightType type; analyzeCluster(cluster, id, pos, setTL, type); if (!insert(id, pos)) { // should not fail WRITE_WARNING("Could not join junctions " + id); continue; } NBNode* newNode = retrieve(id); if (setTL) { NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, newNode, 0, type); if (!tlc.insert(tlDef)) { // actually, nothing should fail here delete tlDef; throw ProcessError("Could not allocate tls '" + id + "'."); } } // collect edges std::set<NBEdge*> allEdges; for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) { const EdgeVector& edges = (*j)->getEdges(); allEdges.insert(edges.begin(), edges.end()); } // remap and remove edges which are completely within the new intersection for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) { NBEdge* e = (*j); NBNode* from = e->getFromNode(); NBNode* to = e->getToNode(); if (cluster.count(from) > 0 && cluster.count(to) > 0) { for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) { if (e != *l) { (*l)->replaceInConnections(e, e->getConnections()); } } ec.erase(dc, e); allEdges.erase(j++); // erase does not invalidate the other iterators } else { ++j; } } // remap edges which are incoming / outgoing for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) { NBEdge* e = (*j); std::vector<NBEdge::Connection> conns = e->getConnections(); const bool outgoing = cluster.count(e->getFromNode()) > 0; NBNode* from = outgoing ? newNode : e->getFromNode(); NBNode* to = outgoing ? e->getToNode() : newNode; e->reinitNodes(from, to); // re-add connections which previously existed and may still valid. // connections to removed edges will be ignored for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) { e->addLane2LaneConnection((*k).fromLane, (*k).toEdge, (*k).toLane, NBEdge::L2L_USER, false, (*k).mayDefinitelyPass); } } // remove original nodes registerJoinedCluster(cluster); for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) { erase(*j); } } }
int put(int pc, char * operand){ int tmp = retrieve(&symbolTable, operand); printf("%d\n", tmp); return pc + 1; }
int main(void) { BinaryTree object,*dupe; BinaryTreeIter *ptr; BinaryTreeDFSIter *dfsptr; BinaryTreeBFSIter *bfsptr; unsigned int x, y; unsigned int value; memset(&object, 0, sizeof (object)); x = RUNS; construct(BinaryTree, &object,sizeof(x),FREEOBJ); set_alloc(BinaryTree, &object, ckalloc); set_dealloc(BinaryTree, &object, ckfree); set_compare(BinaryTree, &object, intcmp); set_print(BinaryTree, &object, print); for (y = 0; y < x; y++) { if (!(y % (RUNS/10))) fprintf(stderr, "."); srand((x * y) / (x - y) + (x + y / x)); switch ((rand() % NUMCASES) + BASE) { case 0: case 10: case 12: case 13: case 2: case 17: case 8: value = rand() % BOUND; insert(BinaryTree, &object, &value, STATIC); break; case 9: case 3: case 15: case 4: case 5: case 14: case 7: value = rand() % BOUND; delete(BinaryTree, &object,&value); break; case 11: case 1: case 6: case 16: /*value = rand() % BOUND; find(BinaryTree,&object,&value); break;*/ default: value = rand() % BOUND; insert(BinaryTree, &object, &value,STATIC); break; }; /*dump(BinaryTree,&object);*/ } printf("\n"); destruct(BinaryTree, &object); fprintf(stderr, "Now testing the iterators!\n"); construct_func(BinaryTree,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp, print, memcpy); for (x = 0; x < 15; x++) { if (!(x % (RUNS/10))) fprintf(stderr, "."); value = rand() % 30; convert(BinaryTree, &object, &value, sizeof(value),STATIC); } ptr = create(BinaryTreeIter, &object); head(BinaryTreeIter, ptr); do { value = *(unsigned int*)retrieve(BinaryTreeIter, ptr); /* printf("%d ",value);*/ } while (!next(BinaryTreeIter, ptr)); /*printf("\n");*/ assign(BinaryTreeIter, ptr, &object); tail(BinaryTreeIter, ptr); do { value = *(unsigned int*) retrieve(BinaryTreeIter, ptr); } while (!prev(BinaryTreeIter, ptr)); for(x = 0; x < RUNS; x++) { if (!(x % (RUNS/10))) fprintf(stderr, "."); switch(rand() % 2) { case 1: prev(BinaryTreeIter,ptr); break; case 0: next(BinaryTreeIter,ptr); break; default: break; } } printf("\n"); destroy(BinaryTreeIter, ptr); dupe = duplicate(BinaryTree,&object); ptr = create(BinaryTreeIter, dupe); head(BinaryTreeIter, ptr); do { value = *(unsigned int*)retrieve(BinaryTreeIter, ptr); /*printf("%d ",value);*/ } while (!next(BinaryTreeIter, ptr)); /*printf("\n");*/ assign(BinaryTreeIter, ptr, dupe); tail(BinaryTreeIter, ptr); do { value = *(unsigned int*) retrieve(BinaryTreeIter, ptr); } while (!prev(BinaryTreeIter, ptr)); for(x = 0; x < RUNS; x++) { if (!(x % (RUNS/10))) fprintf(stderr, "."); switch(rand() % 2) { case 1: prev(BinaryTreeIter,ptr); break; case 0: next(BinaryTreeIter,ptr); break; default: break; } } printf("\n"); destroy(BinaryTreeIter, ptr); bfsptr = create(BinaryTreeBFSIter,&object); do { value = *(unsigned int *)retrieve(BinaryTreeBFSIter, bfsptr); /*fprintf(stderr,"%d ",value);*/ }while(!next(BinaryTreeBFSIter,bfsptr)); /*printf("\n");*/ dfsptr = create(BinaryTreeDFSIter,&object); do { value = *(unsigned int *)retrieve(BinaryTreeDFSIter, dfsptr); /*fprintf(stderr,"%d ",value);*/ }while(!next(BinaryTreeDFSIter,dfsptr)); /*printf("\n");*/ destroy(BinaryTreeDFSIter,dfsptr); destroy(BinaryTreeBFSIter,bfsptr); destruct(BinaryTree, &object); destruct(BinaryTree,dupe); free(dupe); printf("\n"); return EXIT_SUCCESS; }
int jf(int pc, char * operand){ if(stackPop(&stack) == 1) return pc + 1; else return retrieve(&jumpTable, operand); }
const Object & operator* ( ) const { return retrieve( ); }
static int queue_front (lua_State *L) { return retrieve(L, checkqueue(L, 1), 1); }
/** * @param [in] index index of scanned device * @param [out] serial_id serial number of ftdi device * @return 0 on success<br>-1 on failure * @sa get_serial_id(unsigned int, std::string&), get_serial_id(std::string&) * , get_manufacturer(unsigned int, std::string&), get_manufacturer(std::string&) * , get_product(unsigned int, std::string&), get_product(std::string&) **/ int get_serial_id(unsigned int index, std::string &serial_id) { if( ! retrieved ) if( retrieve() < 0 ) return -1; if (descriptions.size() <= index) return -1; serial_id = descriptions[index]["serial_number"]; return 0; }
AMInt32 IAccountModel_Store(IAccountModel *pAcntModel) { ListIter *pIter = 0; AIMAccount *pAcnt = 0; AMInt32 rcSqlite = 0; AMChar *szSql = AMNULL; AMChar *szErrMsg = 0; sqlite3 *pDB = 0; if(AMFALSE == IAccountModel_IsDirt(pAcntModel)) return 0; if(0 == pAcntModel->listAcnt.size) return 0; rcSqlite = myADB_Open(IM_ACNT_DB, &pDB, AMFALSE); if(rcSqlite) { DPRINT("IAccountModel_Store: Can't Open DataBase for %s\n", sqlite3_errmsg(pDB)); sqlite3_close(pDB); return -1; } rcSqlite = sqlite3_exec(pDB, "BEGIN TRANSACTION;", 0, 0, &szErrMsg); if(SQLITE_OK != rcSqlite) { DPRINT("IAccountModel_Store:.......can not \"BEGIN TRANSACTION;\":%s\n",szErrMsg); sqlite3_free(szErrMsg); sqlite3_close(pDB); return -1; } rcSqlite = sqlite3_exec(pDB, SQL_CREATE_ACNT_TABLE, 0, 0, &szErrMsg); if( rcSqlite != SQLITE_OK ) { DPRINT("IAccountModel_Store: Can't \"CREATE TABLE _account(...);\": %s!\n", szErrMsg); sqlite3_free(szErrMsg); sqlite3_close(pDB); return -1; } rcSqlite = sqlite3_exec(pDB, "DELETE FROM _account;", 0, 0, &szErrMsg); if( SQLITE_OK != rcSqlite) { DPRINT("IAccountModel_Store: Can't \"DELETE FROM _account;\": %s!\n", szErrMsg); sqlite3_free(szErrMsg); sqlite3_close(pDB); } pIter = create(ListIter, &pAcntModel->listAcnt); tail(ListIter, pIter); do { pAcnt = (AIMAccount *)retrieve(ListIter, pIter); AMAssert(AMNULL != pAcnt); DPRINT("IAccountModel_Store......................%s\n", pAcnt->szID?pAcnt->szID:"0"); szSql = sqlite3_mprintf(SQL_INSERT_ACNT, pAcnt->szID, (pAcnt->uiFlag&0x01)?pAcnt->szToken:"0" , (pAcnt->szPhoneNum?pAcnt->szPhoneNum:"0"), pAcnt->uiFlag, pAcnt->ePresence , pAcnt->iGroupStamp, pAcnt->iContactStamp, pAcnt->iBlackStamp , pAcnt->iRevBlackStamp, pAcnt->szSigXML?pAcnt->szSigXML:"0"); if(AMNULL != szSql) { rcSqlite = sqlite3_exec(pDB, szSql, 0, 0, &szErrMsg); sqlite3_free(szSql); if( rcSqlite != SQLITE_OK ) { DPRINT("IAccountModel_Store..............: Can't INSERT for %s!\n", szErrMsg); sqlite3_free(szErrMsg); continue; } pAcnt->_iRid = sqlite3_last_insert_rowid(pDB); //更新新数据的_rid } else { sqlite3_close(pDB); destroy(ListIter, pIter); return -1; } } while (!prev(ListIter, pIter)); destroy(ListIter, pIter); rcSqlite = sqlite3_exec(pDB, "COMMIT TRANSACTION;", 0, 0, &szErrMsg); if(SQLITE_OK != rcSqlite) { DPRINT("IAccountModel_Store:..................can not \"COMMIT TRANSACTION;\":%s\n",szErrMsg); sqlite3_free(szErrMsg); sqlite3_close(pDB); return -1; } sqlite3_close(pDB); IAccountModel_ClearDirt(pAcntModel); DPRINT("IAccountModel_Store........................Ok\n"); return 0; }
/** * @param [in] index index of scanned device * @param [out] manufacturer manufacturer name of ftdi device * @return 0 on success<br>-1 on failure * @sa get_serial_id(unsigned int, std::string&), get_serial_id(std::string&) * , get_manufacturer(unsigned int, std::string&), get_manufacturer(std::string&) * , get_product(unsigned int, std::string&), get_product(std::string&) **/ int get_manufacturer (unsigned int index, std::string &manufacturer) { if( ! retrieved ) if( retrieve() < 0 ) return -1; if (descriptions.size() <= index) return -1; manufacturer = descriptions[index]["manufacturer"]; return 0; }
int List<DataType>::retrieveUnique(DataType &data) const { return(retrieve(data)); }
/** * @param [in] index index of scanned device * @param [out] product product name of ftdi device * @return 0 on success<br>-1 on failure * @sa get_serial_id(unsigned int, std::string&), get_serial_id(std::string&) * , get_manufacturer(unsigned int, std::string&), get_manufacturer(std::string&) * , get_product(unsigned int, std::string&), get_product(std::string&) **/ int get_product (unsigned int index, std::string &product) { if( ! retrieved ) if( retrieve() < 0 ) return -1; if (descriptions.size() <= index) return -1; product = descriptions[index]["product"]; return 0; }
int gsl_integration_qaws (gsl_function * f, const double a, const double b, gsl_integration_qaws_table * t, const double epsabs, const double epsrel, const size_t limit, gsl_integration_workspace * workspace, double *result, double *abserr) { double area, errsum; double result0, abserr0; double tolerance; size_t iteration = 0; int roundoff_type1 = 0, roundoff_type2 = 0, error_type = 0; /* Initialize results */ initialise (workspace, a, b); *result = 0; *abserr = 0; if (limit > workspace->limit) { GSL_ERROR ("iteration limit exceeds available workspace", GSL_EINVAL) ; } if (b <= a) { GSL_ERROR ("limits must form an ascending sequence, a < b", GSL_EINVAL) ; } if (epsabs <= 0 && (epsrel < 50 * GSL_DBL_EPSILON || epsrel < 0.5e-28)) { GSL_ERROR ("tolerance cannot be acheived with given epsabs and epsrel", GSL_EBADTOL); } /* perform the first integration */ { double area1, area2; double error1, error2; int err_reliable1, err_reliable2; double a1 = a; double b1 = 0.5 * (a + b); double a2 = b1; double b2 = b; qc25s (f, a, b, a1, b1, t, &area1, &error1, &err_reliable1); qc25s (f, a, b, a2, b2, t, &area2, &error2, &err_reliable2); if (error1 > error2) { append_interval (workspace, a1, b1, area1, error1); append_interval (workspace, a2, b2, area2, error2); } else { append_interval (workspace, a2, b2, area2, error2); append_interval (workspace, a1, b1, area1, error1); } result0 = area1 + area2; abserr0 = error1 + error2; } /* Test on accuracy */ tolerance = GSL_MAX_DBL (epsabs, epsrel * fabs (result0)); /* Test on accuracy, use 0.01 relative error as an extra safety margin on the first iteration (ignored for subsequent iterations) */ if (abserr0 < tolerance && abserr0 < 0.01 * fabs(result0)) { *result = result0; *abserr = abserr0; return GSL_SUCCESS; } else if (limit == 1) { *result = result0; *abserr = abserr0; GSL_ERROR ("a maximum of one iteration was insufficient", GSL_EMAXITER); } area = result0; errsum = abserr0; iteration = 2; do { double a1, b1, a2, b2; double a_i, b_i, r_i, e_i; double area1 = 0, area2 = 0, area12 = 0; double error1 = 0, error2 = 0, error12 = 0; int err_reliable1, err_reliable2; /* Bisect the subinterval with the largest error estimate */ retrieve (workspace, &a_i, &b_i, &r_i, &e_i); a1 = a_i; b1 = 0.5 * (a_i + b_i); a2 = b1; b2 = b_i; qc25s (f, a, b, a1, b1, t, &area1, &error1, &err_reliable1); qc25s (f, a, b, a2, b2, t, &area2, &error2, &err_reliable2); area12 = area1 + area2; error12 = error1 + error2; errsum += (error12 - e_i); area += area12 - r_i; if (err_reliable1 && err_reliable2) { double delta = r_i - area12; if (fabs (delta) <= 1.0e-5 * fabs (area12) && error12 >= 0.99 * e_i) { roundoff_type1++; } if (iteration >= 10 && error12 > e_i) { roundoff_type2++; } } tolerance = GSL_MAX_DBL (epsabs, epsrel * fabs (area)); if (errsum > tolerance) { if (roundoff_type1 >= 6 || roundoff_type2 >= 20) { error_type = 2; /* round off error */ } /* set error flag in the case of bad integrand behaviour at a point of the integration range */ if (subinterval_too_small (a1, a2, b2)) { error_type = 3; } } update (workspace, a1, b1, area1, error1, a2, b2, area2, error2); retrieve (workspace, &a_i, &b_i, &r_i, &e_i); iteration++; } while (iteration < limit && !error_type && errsum > tolerance); *result = sum_results (workspace); *abserr = errsum; if (errsum <= tolerance) { return GSL_SUCCESS; } else if (error_type == 2) { GSL_ERROR ("roundoff error prevents tolerance from being achieved", GSL_EROUND); } else if (error_type == 3) { GSL_ERROR ("bad integrand behavior found in the integration interval", GSL_ESING); } else if (iteration == limit) { GSL_ERROR ("maximum number of subdivisions reached", GSL_EMAXITER); } else { GSL_ERROR ("could not integrate function", GSL_EFAILED); } }
//============================================================================= // METHOD: SPELLipcMessageMailbox::retrieve //============================================================================= SPELLipcMessage SPELLipcMessageMailbox::retrieve( std::string id ) { return retrieve(id, 0); }
main(int argc, char **argv) { cout << "List l1;" << endl; List l1; cout << l1 << endl; cout << "insert(l1, DataItem);" << endl; for (int il = 0; il < atoi(argv[1]); il++) { DataItem *d = new DataItem(2*il); assert(d != 0); assert(insert(l1, d, STARTOFLIST) == OK); } cout << l1 << endl; cout << "List l2;" << endl; List l2; cout << l2 << endl; cout << "insert(l1, DataItem);" << endl; for (il = 0; il < atoi(argv[1]); il++) { DataItem *d = new DataItem(2*il); assert(d != 0); assert(insert(l2, d, ENDOFLIST) == OK); } cout << l2 << endl; cout << "locate(l1, DataItem(10), lp);" << endl; ListPosition lp; if (locate(l1, &DataItem(10), lp) == OK) cout << *lp << endl; else cout << "DataItem(10) not found." << endl; cout << "retrieve(l1, d, lp);" << endl; DataItem *d; if (retrieve(l1, d, lp) == OK) { cout << *d << endl; } else cout << "DataItem(10) not found." << endl; cout << "ListIterator li(l1);" << endl; ListIterator li(l1); while ((d = li()) != (DataItem *)0) { cout << *d << endl; } cout << "li = l2);" << endl; li = l2; while ((d = li()) != (DataItem *)0) { cout << *d << endl; } cout << "retrieveAndRemove(l1, d, STARTOFLIST);" << endl; while (retrieveAndRemove(l1, d, STARTOFLIST) == OK) { cout << "removed ..." << *d << endl; cout << "list remaining = " << l1 << endl; } cout << "retrieveAndRemove(l2, d, ENDOFLIST);" << endl; while (retrieveAndRemove(l2, d, ENDOFLIST) == OK) { cout << "removed ..." << *d << endl; cout << "list remaining = " << l2 << endl; } // all done return(0); }
bool hashTree::retrieve(char * key, data & aData) { return retrieve(root, key, aData); }