RcppExport SEXP classicRcppStringVectorExample(SEXP strvec) { SEXP rl = R_NilValue; // Use this when there is nothing to be returned. char *exceptionMesg = NULL; try { RcppStringVector orig(strvec); RcppStringVector vec(strvec); for (int i=0; i<orig.size(); i++) { std::transform(orig(i).begin(), orig(i).end(), vec(i).begin(), ::tolower); } // Build result set to be returned as a list to R. RcppResultSet rs; rs.add("result", vec); rs.add("original", orig); // Get the list to be returned to R. rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
bool dijkstra() { priority_queue<pair<double, pair<int, int> > > q; vi ent(sz(adj), -2); vd dist(sz(adj), INF); fu(u, sz(adj)) if (imb[u] >= delta) q.push(make_pair(0.0, make_pair(u, -1))); while (!q.empty()) { int u = q.top().second.first, f = q.top().second.second; double d = -q.top().first; q.pop(); if (ent[u] != -2) continue; dist[u] = d; ent[u] = f; for (int a : adj[u]) if (capres(a) >= delta) q.push(make_pair(-(dist[u] + rescost(a)), make_pair(dest[a], a))); } fu(u, sz(adj)) if (ent[u] != -2 && imb[u] <= -delta) { fu(v, sz(adj)) pot[v] += dist[v]; for (int a = ent[u]; a != -1; a = ent[orig(a)]) { flow[a] += delta; flow[inv(a)] -= delta; imb[dest[a]] += delta; imb[orig(a)] -= delta; } return true; } return false; }
// Recursive Delaunay Triangulation Procedure // Contains modifications for axis-switching division. void CDelaunay::build(int lo, int hi, EdgePointer *le, EdgePointer *re, int rows) { EdgePointer a, b, c, ldo, rdi, ldi, rdo, maxx, minx; int split, lowrows; int low, high; SitePointer s1, s2, s3; low = lo; high = hi; if ( low < (high-2) ) { // more than three elements; do recursion minx = sp[low]; maxx = sp[high]; if (rows == 1) { // time to switch axis of division spsorty( sp, low, high); rows = 65536; } lowrows = rows/2; split = low - 1 + (int) (0.5 + ((double)(high-low+1) * ((double)lowrows / (double)rows))); build( low, split, &ldo, &ldi, lowrows ); build( split+1, high, &rdi, &rdo, (rows-lowrows) ); doMerge(&ldo, ldi, rdi, &rdo); while (orig(ldo) != minx) { ldo = rprev(ldo); } while (orig(rdo) != maxx) { rdo = (SitePointer) lprev(rdo); } *le = ldo; *re = rdo; } else if (low >= (high - 1)) { // two or one points a = makeEdge(sp[low], sp[high]); *le = a; *re = (EdgePointer) sym(a); } else { // three points // 3 cases: triangles of 2 orientations, and 3 points on a line a = makeEdge((s1 = sp[low]), (s2 = sp[low+1])); b = makeEdge(s2, (s3 = sp[high])); splice((EdgePointer) sym(a), b); if (ccw(s1, s3, s2)) { c = connectLeft(b, a); *le = (EdgePointer) sym(c); *re = c; } else { *le = a; *re = (EdgePointer) sym(b); if (ccw(s1, s2, s3)) { // not colinear c = connectLeft(b, a); } } } }
void TestArmadilloSerialization(MatType& x) { // First save it. std::ofstream ofs("test", std::ios::binary); OArchiveType o(ofs); bool success = true; try { o << BOOST_SERIALIZATION_NVP(x); } catch (boost::archive::archive_exception& e) { success = false; } BOOST_REQUIRE_EQUAL(success, true); ofs.close(); // Now load it. MatType orig(x); success = true; std::ifstream ifs("test", std::ios::binary); IArchiveType i(ifs); try { i >> BOOST_SERIALIZATION_NVP(x); } catch (boost::archive::archive_exception& e) { success = false; } BOOST_REQUIRE_EQUAL(success, true); BOOST_REQUIRE_EQUAL(x.n_rows, orig.n_rows); BOOST_REQUIRE_EQUAL(x.n_cols, orig.n_cols); BOOST_REQUIRE_EQUAL(x.n_elem, orig.n_elem); for (size_t i = 0; i < x.n_cols; ++i) for (size_t j = 0; j < x.n_rows; ++j) if (double(orig(j, i)) == 0.0) BOOST_REQUIRE_SMALL(double(x(j, i)), 1e-8); else BOOST_REQUIRE_CLOSE(double(orig(j, i)), double(x(j, i)), 1e-8); remove("test"); }
// Quad-edge manipulation primitives EdgePointer CDelaunay::makeEdge(SitePointer origin, SitePointer destination) { EdgePointer temp, ans; temp = allocEdge(); ans = temp; onext(temp) = ans; orig(temp) = origin; onext(++temp) = (EdgePointer) (ans + 3); onext(++temp) = (EdgePointer) (ans + 2); orig(temp) = destination; onext(++temp) = (EdgePointer) (ans + 1); return(ans); }
void play() { for (int i = 0, s = m_inputs[0].count() ; i < s ; ++i ) { Photo& photo = m_inputs[0][i]; QDir targetDir(m_targetDirectory); QString magick; QString baseFilename = targetDir.filePath(photo.getTag(TAG_NAME)); QString ext; switch (m_fileType) { case OpSave::SaveFITS: ext = ".fits"; magick = "FITS"; break; case OpSave::SaveTIFF: ext = ".tif"; magick = "TIFF"; break; case OpSave::SaveJPEG: ext = ".jpg"; magick = "JPG"; break; } QFileInfo finfo(baseFilename + ext); if ( m_backup && finfo.exists() ) { QDateTime lastModified = finfo.lastModified(); QString ts = lastModified.toString("yyyy'-'dd'-'MM'T'hh':'mm':'ss'.'zzz'Z'"); QFile orig(baseFilename + ext); orig.rename(baseFilename + "-" + ts + ext); } QString filename = finfo.filePath(); photo.save(filename, magick); emitProgress(i, s, 0, 1); } emitSuccess(); }
void AmeJobMan::setPath(AmeJob *job, wxString &path, bool parent){ //synchronized(job){ if(job->check(jS_DOING)) return; //int status = jFAILED; wxFileName orig(job->getNewFilePath().Length()>0?job->getNewFilePath():job->getAbsolutePath()); wxString name; if(parent){ wxFileName pp = orig.GetPath(); //pp = pp.GetPath(); name += pp.GetFullName()+wxT(FILE_SEPARATOR); } name += orig.GetFullName(); wxString file = path+wxT(FILE_SEPARATOR)+name; if(job->getHealth()==jH_MISSING){ job->find(file); A.m_db->update(dJ, 1, job); } else if(updatePath(job, file)){ if(job->getNewFilePath().Length()>0) job->setStatus(jMOVEWAIT, true); // status = jMOVEWAIT; //else // status = jFINISHED; A.m_db->update(dJ, 1, job); } //} }
void GLWidget::mouseMoveEvent(QMouseEvent *event) { if (!select(event)){ glLoadIdentity(); int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); if (event->buttons() & Qt::LeftButton) { QMatrix4x4 mat(view[0],view[4],view[8],view[12],view[1],view[5],view[9],view[13],view[2],view[6],view[10],view[14],view[3],view[7],view[11],view[15]); QVector3D orig(0, 0, 0); QVector3D m = mat.map(orig); glTranslatef(m.x(), m.y(), m.z()); glRotatef(qSqrt(dx*dx+dy*dy)/2.0, dy, dx, 0); glTranslatef(-m.x(), -m.y(), -m.z()); } else if (event->buttons() & Qt::RightButton) { glTranslatef(dx/(float)width()*ar/scale, -dy/(float)height()/scale, 0); } lastPos = event->pos(); glPushMatrix(); glMultMatrixf(view); glGetFloatv(GL_MODELVIEW_MATRIX, view); glPopMatrix(); } updateGL(); }
int main () { kdb::KeySet orig (3, *kdb::Key ("user/key3/1", KEY_END), *kdb::Key ("user/key3/2", KEY_END), *kdb::Key ("user/key3/3", KEY_VALUE, "value", KEY_END), KS_END); kdb::KeySet flatCopy (orig); kdb::KeySet deepCopy = ksDeepCopy (orig); }
//TODO Return as string, so call stack could be used in dialogs. void printCallStack() { #ifdef LYX_CALLSTACK_PRINTING const int depth = 50; // get void*'s for all entries on the stack void* array[depth]; size_t size = backtrace(array, depth); char** messages = backtrace_symbols(array, size); for (size_t i = 0; i < size && messages != NULL; i++) { std::string orig(messages[i]); // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b] char* mangled = 0; for (char *p = messages[i]; *p; ++p) { if (*p == '(') { *p = 0; mangled = p + 1; } else if (*p == '+') { *p = 0; break; } } int err = 0; char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err); if (err == 0) { fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled); free((void*)demangled); } else { fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str()); } } #endif }
void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScalar dy) { SkCanvas* origCanvas = canvas; SkAutoCanvasRestore acr(canvas, true); SkISize size = SkISize::Make(fImage->width(), fImage->height()); SkAutoTUnref<SkSurface> surface; if (fShowFatBits) { // scale up so we don't clip rotations SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage->height() * 2, kOpaque_SkAlphaType); surface.reset(make_surface(canvas, info)); canvas = surface->getCanvas(); canvas->drawColor(SK_ColorWHITE); size.set(info.width(), info.height()); } else { canvas->translate(SkScalarHalf(fCell.width() - fImage->width()), SkScalarHalf(fCell.height() - fImage->height())); } this->drawTheImage(canvas, size, filter, dx, dy); if (surface) { SkAutoTUnref<SkImage> orig(surface->newImageSnapshot()); SkAutoTUnref<SkImage> zoomed(zoom_up(orig)); origCanvas->drawImage(zoomed, SkScalarHalf(fCell.width() - zoomed->width()), SkScalarHalf(fCell.height() - zoomed->height())); } }
bool capture(const std::string& re, std::string& src) { std::string pat, flags; pcrecpp::RE rx("^\\/(.*)\\/(.*)$", pcrecpp::UTF8()); if (rx.PartialMatch(re, &pat, &flags)) { if (src.empty()) // Check regexp return true; pcrecpp::RE_Options opts = _init_re_opts(flags); if (strstr(flags.c_str(), "g") != 0) { std::string orig(src); pcrecpp::StringPiece sp(orig); pcrecpp::RE re(pat, opts); _check_re_error(re); src.clear(); std::string s; while (re.FindAndConsume(&sp, &s)) src += s; } else { std::string tmp = src; src.clear(); pcrecpp::RE re(pat, opts); _check_re_error(re); re.PartialMatch(tmp, &src); } return true; } return false; }
nmethod* cacheProbingLookup::compileOrReuse() { nmethod* nm = findMethodToReuse(); if ( nm == cannotReuse ) { nm= compilingLookup::compileOrReuse(); updateCache(nm); return nm; } if ( nm == compileAndReuse ) { // compile in context of method holder and reuse MethodLookupKey orig(&key); key= canonical_key; nm= compilingLookup::compileOrReuse(); key= orig; updateCache(nm); updateCache(nm, &canonical_key); return nm; } // reuse nm const char *s= sprintName(NULL, selector()); if (PrintCompilation) lprintf("*Reusing NIC method %#lx for selector %s\n", nm, s); LOG_EVENT1("Reusing NIC method %#lx", nm); nm->addDeps(deps); updateCache(nm, &key); return nm; }
TEST_F(SHAPE, Moves) { std::vector<ade::DimT> junk = {8, 51, 73}; std::vector<ade::DimT> slist = {24, 11, 12, 16}; ade::Shape mvassign; ade::Shape mvassign2(junk); ade::Shape orig(slist); ade::Shape mv(std::move(orig)); std::vector<ade::DimT> mlist(mv.begin(), mv.end()); EXPECT_ARREQ(slist, mlist); for (uint8_t i = 0; i < ade::rank_cap; ++i) { EXPECT_EQ(1, orig.at(i)); } mvassign = std::move(mv); std::vector<ade::DimT> alist(mvassign.begin(), mvassign.end()); EXPECT_ARREQ(slist, alist); for (uint8_t i = 0; i < ade::rank_cap; ++i) { EXPECT_EQ(1, mv.at(i)); } mvassign2 = std::move(mvassign); std::vector<ade::DimT> alist2(mvassign2.begin(), mvassign2.end()); EXPECT_ARREQ(slist, alist2); for (uint8_t i = 0; i < ade::rank_cap; ++i) { EXPECT_EQ(1, mvassign.at(i)); } }
int main(int argc, char *argv[]) { (void) argc; (void) argv; int n = 10; pthread_t threads[n]; work_t work_items[n]; QImage image; QString orig("../../inf8601-scratchpad/res/bsod.png"); QString modz(orig + ".modz.png"); if (!image.load(orig)) { qDebug() << "error loading image"; return -1; } image = image.convertToFormat(QImage::Format_RGB32); for (int i = 0; i < n; i++) { work_items[i].n = n; work_items[i].rank = i; work_items[i].image = ℑ pthread_create(&threads[i], NULL, effect, &work_items[i]); } for (int i = 0; i < n; i++) { pthread_join(threads[i], NULL); } image.save(modz); return 0; }
bool QtestFromAccl(){ Quaternion orig(Vec3(1,0,0),toRad(45)); Vec3 accl(0,0,1); accl.rotateBy(orig); Quaternion res(Vec3(0,0,1), accl); return fuzzyQCompare(orig, res); }
int trap(vector<int>& height) { vector<int> orig(height); int peak = INT_MIN; int peakIndex = -1; for (int i = 0; i < height.size(); ++i) { if (height[i] > peak) { peak = height[i]; peakIndex = i; } } do { for (int i = 1; i < height.size()-1; ++i) { int leftPeak = get_peak_from_left(i-1, height, height[i]); int rightPeak = get_peak_from_right(i+1, height, height[i]); height[i] = min(leftPeak, rightPeak); } } while (!perfect_mountain(height, peakIndex)); print_vec(orig); print_vec(height); int capacity = 0; for (int i = 0; i < height.size(); ++i) { capacity += abs(height[i] - orig[i]); } return capacity; }
EdgePointer CDelaunay::connectRight(EdgePointer a, EdgePointer b) { EdgePointer ans; ans = makeEdge(dest(a), orig(b)); splice(ans, (EdgePointer) sym(a)); splice((EdgePointer) sym(ans), (EdgePointer) oprev(b)); return(ans); }
EdgePointer CDelaunay::connectLeft(EdgePointer a, EdgePointer b) { EdgePointer ans; ans = makeEdge(dest(a), orig(b)); splice(ans, (EdgePointer) lnext(a)); splice((EdgePointer) sym(ans), b); return(ans); }
void Scene::addLight(geovalue *pos, intensity *dif) { Vector3D u = Vector3D(0.5, 0.0 , 0.0); Vector3D v = Vector3D(0.0, 0.0 , 0.5); lights.push_back(new SquareLight(pos,u ,v , dif, 3, this)); Vector3D orig(Vector3D(pos) - (u * 0.5) - (v * 0.5)); objects.push_back(new SquareLightBody(orig, orig + u, orig + u + v, orig + v, dif, this)); currentCam = -1; }
LinearNorm(const LN& vList) { assert(vList.size() >= 2); norm.reserve(vList.size()); orig.reserve(vList.size()); for (auto i = vList.begin(); i != vList.end(); i++) { norm.push_back(i->norm()); orig.push_back(i->orig()); } }
void GameObject::rotate(float rAngle) { _vect.rotate(Coord2d<float>(0, 0), rAngle); Coord2d<float> orig(_rect.getSize(X) / 2.0f, _rect.getSize(Y) / 2.0f); for(PointList::iterator iter = _point.begin(); iter != _point.end(); ++iter) iter->rotate(orig, rAngle); }
void TestArmadilloSerialization(arma::Cube<CubeType>& x) { // First save it. std::ofstream ofs("test", std::ios::binary); OArchiveType o(ofs); bool success = true; try { o << BOOST_SERIALIZATION_NVP(x); } catch (boost::archive::archive_exception& e) { success = false; } BOOST_REQUIRE_EQUAL(success, true); ofs.close(); // Now load it. arma::Cube<CubeType> orig(x); success = true; std::ifstream ifs("test", std::ios::binary); IArchiveType i(ifs); try { i >> BOOST_SERIALIZATION_NVP(x); } catch (boost::archive::archive_exception& e) { success = false; } BOOST_REQUIRE_EQUAL(success, true); BOOST_REQUIRE_EQUAL(x.n_rows, orig.n_rows); BOOST_REQUIRE_EQUAL(x.n_cols, orig.n_cols); BOOST_REQUIRE_EQUAL(x.n_elem_slice, orig.n_elem_slice); BOOST_REQUIRE_EQUAL(x.n_slices, orig.n_slices); BOOST_REQUIRE_EQUAL(x.n_elem, orig.n_elem); for(size_t slice = 0; slice != x.n_slices; ++slice){ auto const &orig_slice = orig.slice(slice); auto const &x_slice = x.slice(slice); for (size_t i = 0; i < x.n_cols; ++i){ for (size_t j = 0; j < x.n_rows; ++j){ if (double(orig_slice(j, i)) == 0.0) BOOST_REQUIRE_SMALL(double(x_slice(j, i)), 1e-8); else BOOST_REQUIRE_CLOSE(double(orig_slice(j, i)), double(x_slice(j, i)), 1e-8); } } } remove("test"); }
QTransform RectToRect(const QRectF& from, const QRectF& to) { QPolygonF orig(from); orig.pop_back(); QPolygonF resize(to); resize.pop_back(); QTransform ret; QTransform::quadToQuad(orig, resize, ret); return ret; }
char Filters::OSISMorphSegmentation::processText(sword::SWBuf &text, const sword::SWKey * /*key*/, const sword::SWModule * /*module*/) { sword::SWBuf token; bool intoken = false; bool hide = false; sword::SWBuf orig( text ); const char *from = orig.c_str(); sword::XMLTag tag; for (text = ""; *from; ++from) { if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; if (!strncmp(token.c_str(), "seg ", 4) || !strncmp(token.c_str(), "/seg", 4)) { tag = token; if (!tag.isEndTag() && tag.getAttribute("type") && !strcmp("morph", tag.getAttribute("type"))) { //<seg type="morph"> start tag hide = (option == 0); //only hide if option is Off } if (hide) { //hides start and end tags as long as hide is set if (tag.isEndTag()) { //</seg> hide = false; } continue; //leave out the current token } } //end of seg tag handling text.append('<'); text.append(token); text.append('>'); // hide = false; //not right, because there may be child tags in seg. Only /seg may disable the seg hiding. continue; } //end of intoken part if (intoken) { //copy token token.append(*from); } else { //copy text which is not inside of a tag text.append(*from); } } return 0; }
bool TestBase::compare(const QImage& image, const QString& sFilename, const QString& sFilenameContrast, bool bExpectEqual) { QImage orig(sFilenameContrast); bool bEqual = (image == orig); if (bEqual != bExpectEqual) { qDebug() << "Comparison to" << sFilenameContrast << "failed. See" << sFilename; return false; } return true; }
void GLRenderWidget::createDefaultTextures() { QImage orig(":/images/opengl_logo.jpg"); QImage image = orig.mirrored(false, true); QImage pause(":/images/pause.png"); mDefaultTexture = bindTexture(image); mPauseTexture = bindTexture(pause); }
int main() { std::string orig("abc.bc"); std::string::const_iterator start, end; start = orig.begin(); end = orig.end(); boost::match_results<std::string::const_iterator> what; boost::regex reg(R"(([a-z]+)\.\1)"); bool found = regex_search(start, end, what, reg, boost::match_perl); std::cout << found; }
EAPI void evas_event_feed_key_down(Evas *e, const char *keyname, const char *key, const char *string, const char *compose, unsigned int timestamp, const void *data) { int evt = tsuite_event_type_get(EVAS_CALLBACK_KEY_DOWN); void (*orig) (Evas *e, const char *keyname, const char *key, const char *string, const char *compose, unsigned int timestamp, const void *data) = dlsym(RTLD_NEXT, __func__); #ifdef DEBUG_TSUITE printf("Calling %s timestamp=<%u>\n", __func__, timestamp); #endif if (!strcmp(key, shot_key)) { #ifdef DEBUG_TSUITE printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); #endif take_screenshot t = { timestamp, evas_list_find(e) }; if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t); orig(e, keyname, key, string, compose, timestamp, data); return; } if (vr_list && _hook_setting->recording) { /* Construct duplicate strings, free them when list if freed */ key_down_key_up t; t.timestamp = timestamp; t.keyname = eina_stringshare_add(keyname); t.key = eina_stringshare_add(key); t.string = eina_stringshare_add(string); t.compose = eina_stringshare_add(compose); t.n_evas = evas_list_find(e); if (t.n_evas >= 0) ADD_TO_LIST(evt, key_down_key_up, t); } orig(e, keyname, key, string, compose, timestamp, data); }
/*! Commits the contents written into this KDSaveFile to the target using \a mode. Returns true on success, otherwise false. The file will be closed during commit. \sa CommitMode */ bool KDSaveFile::commit( KDSaveFile::CommitMode mode ) { if( !d->tmpFile ) return false; const QString tmpfname = d->tmpFile->fileName(); flush(); delete d->tmpFile; // first step: backup the existing file (if any) QFile orig( d->filename ); QString backup; if( orig.exists() ) { backup = d->generateBackupName(); if( !orig.rename( backup ) ) { setErrorString( tr("Could not backup existing file %1: %2").arg( d->filename, orig.errorString() ) ); if ( mode != OverwriteExistingFile ) return false; } orig.setFileName( d->filename ); if( orig.exists() && !orig.remove() ) { setErrorString( tr( "Could not remove existing file %1: %2" ).arg( d->filename, orig.errorString() ) ); return false; } } // second step: rename the temp file to the target file name QFile target( tmpfname ); if( !target.rename( d->filename ) ) { setErrorString( target.errorString() ); return false; } #ifdef Q_OS_WIN makeFileHidden( d->filename, false ); #endif // third step, if the existing file is to be overwritten: remove the backup we created in first step if( mode == OverwriteExistingFile ) { QFile tmp( backup ); const bool removed = !tmp.exists() || tmp.remove( backup ); if ( !removed ) qWarning() << "Could not remove the backup: " << tmp.errorString(); } QIODevice::close(); return true; }