WLength::WLength(const char *s) : auto_(false), unit_(Pixel), value_(-1) { char *end = 0; #ifndef WT_TARGET_JAVA value_ = strtod(s, &end); #else Utils::stringToDouble(s, &end, value_); #endif if (s == end) { LOG_ERROR("cannot parse CSS length: '" << s << "'"); auto_ = true; return; } std::string unit(end); boost::trim(unit); if (unit == "em") unit_ = FontEm; else if (unit == "ex") unit_ = FontEx; else if (unit.empty() || unit == "px") unit_ = Pixel; else if (unit == "in") unit_ = Inch; else if (unit == "cm") unit_ = Centimeter; else if (unit == "mm") unit_ = Millimeter; else if (unit == "pt") unit_ = Point; else if (unit == "pc") unit_ = Pica; else if (unit == "%") unit_ = Percentage; else { LOG_ERROR("unrecognized unit in '" << s << "'"); auto_ = true; value_ = -1; unit_ = Pixel; } }
carryover::carryover(const config& side) : add_(side["add"].to_bool()) , color_(side["color"]) , current_player_(side["current_player"]) , gold_(side["gold"].to_int()) , name_(side["name"]) , previous_recruits_() , recall_list_() , save_id_(side["save_id"]) { std::vector<std::string> temp_recruits = utils::split(side["previous_recruits"], ','); previous_recruits_.insert(temp_recruits.begin(), temp_recruits.end()); BOOST_FOREACH(const config& u, side.child_range("unit")){ recall_list_.push_back(unit(u)); } }
TransRec::TransRec(SrcKey _src, TransID transID, TransKind _kind, TCA _aStart, uint32_t _aLen, TCA _acoldStart, uint32_t _acoldLen, TCA _afrozenStart, uint32_t _afrozenLen, RegionDescPtr region, std::vector<TransBCMapping> _bcMapping, Annotations&& _annotations, bool _hasLoop) : bcMapping(_bcMapping) , annotations(std::move(_annotations)) , funcName(_src.func()->fullName()->data()) , src(_src) , md5(_src.func()->unit()->md5()) , aStart(_aStart) , acoldStart(_acoldStart) , afrozenStart(_afrozenStart) , aLen(_aLen) , acoldLen(_acoldLen) , afrozenLen(_afrozenLen) , bcStart(_src.offset()) , id(transID) , kind(_kind) , hasLoop(_hasLoop) { if (funcName.empty()) funcName = "Pseudo-main"; if (!region) return; assertx(!region->empty()); for (auto& block : region->blocks()) { auto sk = block->start(); blocks.emplace_back(Block{sk.unit()->md5(), sk.offset(), block->last().advanced().offset()}); } auto& firstBlock = *region->blocks().front(); for (auto const& pred : firstBlock.typePreConditions()) { guards.emplace_back(show(pred)); } }
QString MATMLReader::processUnits(QDomElement units) { QString unit(""); QDomNodeList children = units.childNodes(); for (int u=0;u<children.count();++u) { if (u!=0) unit += " "; QDomElement e = children.at(u).toElement(); int power = e.attribute("power", "1").toInt(); if (power==1) { unit += e.text(); } else { unit += e.text(); unit += "^"; unit += QString().setNum(power); } } return unit; }
TEST_F( TranslationUnitTest, GoToDeclarationWorks ) { fs::path path_to_testdata = fs::current_path() / fs::path( "testdata" ); fs::path test_file = path_to_testdata / fs::path( "goto.cpp" ); TranslationUnit unit( test_file.string(), std::vector< UnsavedFile >(), std::vector< std::string >(), clang_index_ ); Location location = unit.GetDeclarationLocation( 17, 3, std::vector< UnsavedFile >() ); EXPECT_EQ( 12, location.line_number_ ); EXPECT_EQ( 8, location.column_number_ ); EXPECT_TRUE( !location.filename_.empty() ); }
// The input is something like this: // 5.0000000000n 226.6820055575m 71.3468319456m -71.3468319456m // The first number is transient simulation time, the rest are variables that // need to be converted to double vector<double> Hspice::parse(string s) { vector<double> result; string word; string str = s; if (s.c_str()[s.length() - 1] == unluckyThirteen) { // guess what this does! str = s.substr(0, s.length() - 1); } stringstream stream(str); while (getline(stream, word, ' ')) { if (!is_only_ascii_whitespace(word)) { double d; stringstream ss(word); ss >> d; char c = word.c_str()[word.length() - 1]; d = d * unit(c); result.push_back(d); } }
void frame (float Vx, float Vy, float Vcx, float Vcy, float Wx, float Wy, float Wcx, float Wcy, mat result) { unit (result); mat R, T1; move(-Vcx, -Vcy, R); times(R, result, T1); set(T1, result); scaleOverPivot(Wx/Vx, Wy/Vy, R); times(R, result, T1); set(T1, result); reflectHorizontally(0, R); times(R, result, T1); set(T1, result); move(Wcx, Wcy, R); times(R, result, T1); set(T1, result); }
bool GunneboReaderProvider::refreshReaderList() { d_readers.clear(); std::vector<boost::shared_ptr<SerialPortXml> > ports; EXCEPTION_ASSERT_WITH_LOG(SerialPortXml::EnumerateUsingCreateFile(ports), LibLogicalAccessException, "Can't enumerate the serial port list."); for (std::vector<boost::shared_ptr<SerialPortXml> >::iterator i = ports.begin(); i != ports.end(); ++i) { boost::shared_ptr<GunneboReaderUnit> unit(new GunneboReaderUnit()); boost::shared_ptr<SerialPortDataTransport> dataTransport = boost::dynamic_pointer_cast<SerialPortDataTransport>(unit->getDataTransport()); dataTransport->setSerialPort(*i); unit->setReaderProvider(boost::weak_ptr<ReaderProvider>(shared_from_this())); d_readers.push_back(unit); } return true; }
int main() { int t; while (scanf("%d", &t) != -1) { for (int i = 0; i < t; i++) { long long int sum = 0,n; scanf("%I64d", &n); long long int grps = n / 3; for (int j = 1; j <= grps; j++) { sum += unit(j, n); } printf("%I64d", sum); } } }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif char a[MAXM],b[MAXM]; int cnt=0; init(); memset(p,-1,sizeof(p)); memset(d,0,sizeof(d)); while(scanf("%s %s",a,b)==2) { int pa=sear(a),pb=sear(b); if(pa==-1) { insert(a,cnt); pa=cnt++; } if(pb==-1) { insert(b,cnt); pb=cnt++; } unit(pa,pb); d[pa]++; d[pb]++; } bool flag=true; int p0=find(0); for(int i=1; i<cnt && flag; i++) { if(p0!=find(i)) flag=false; } int cnte=0; for(int i=0; i<cnt && flag; i++) { if(d[i]%2==1) cnte++; } if(flag && (cnte==0 || cnte==2)) printf("Possible\n"); else printf("Impossible\n"); return 0; }
void LocalAssetBrowser::AddBitmap_continued(AIFilePicker* filepicker) { if (!filepicker->hasFilename()) return; bool change_happened = false; std::vector<std::string> const& filenames(filepicker->getFilenames()); for(std::vector<std::string>::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { LocalBitmap unit(*filename); if (unit.getIfValidBool()) { loaded_bitmaps.push_back(unit); change_happened = true; } } if (change_happened) onChangeHappened(); }
void SourceGenerator::run() { beginDefineGuards(); writeInclude(getUnitFileBasename() + ".h"); writeInclude("../../utils/ccdictionarybuilder.h"); out() << "\n"; visitCursorChildren(clang_getTranslationUnitCursor(unit()), [this]() -> CXChildVisitResult { if (isGameRecord()) defineRecord(); if (isLocalNamespace()) return CXChildVisit_Recurse; return CXChildVisit_Continue; }); endDefineGuards(); }
istream &TVector::read(istream &in) { char buf[20],ch, ch2; in >> ch2; if (ch2 != 'I') { double x,y,z; in >> x >> ch >> y >> ch >> z; *this=TVector(x,y,z); if (ch2 == '<') unit(); } else {
void StartDialog::recentItemChanged( QIconViewItem *item ) { QString msg( recentFiles[item->index()] ); QFileInfo f( recentFiles[item->index()] ); uint s = f.size(); QString unit( "B" ); if( s > 1024 ) { s /= 1024; unit = "KB"; } if ( s > 1024 ) { s /= 1024; unit = "MB"; } QDateTime dt( f.lastModified() ); QString date( dt.toString( "MMMM dd hh:mm" )); msg = QString( "%1 (%2 %3) %4" ).arg(msg).arg(s).arg(unit).arg(date); fileInfoLabel->setText( msg ); }
TransRec::TransRec(SrcKey _src, TransKind _kind, TCA _aStart, uint32_t _aLen, TCA _acoldStart, uint32_t _acoldLen, TCA _afrozenStart, uint32_t _afrozenLen, RegionDescPtr region, std::vector<TransBCMapping> _bcMapping, bool _isLLVM) : bcMapping(_bcMapping) , funcName(_src.func()->fullName()->data()) , src(_src) , md5(_src.func()->unit()->md5()) , aStart(_aStart) , acoldStart(_acoldStart) , afrozenStart(_afrozenStart) , aLen(_aLen) , acoldLen(_acoldLen) , afrozenLen(_afrozenLen) , bcStart(_src.offset()) , id(0) , kind(_kind) , isLLVM(_isLLVM) { if (funcName.empty()) funcName = "Pseudo-main"; if (!region) return; assertx(!region->empty()); for (auto& block : region->blocks()) { auto sk = block->start(); blocks.emplace_back(Block{sk.unit()->md5(), sk.offset(), block->last().advanced().offset()}); } auto& firstBlock = *region->blocks().front(); auto guardRange = firstBlock.typePreds().equal_range(firstBlock.start()); for (; guardRange.first != guardRange.second; ++guardRange.first) { guards.emplace_back(show(guardRange.first->second)); } }
DllExport void DLLPublishToPython() { CyEnumsPythonInterface(); CyGamePythonInterface(); CyRandomPythonInterface(); CyTeamPythonInterface(); CyAreaPythonInterface(); CyStructsPythonInterface1(); CyMapPythonInterface(); CyMapGeneratorPythonInterface(); CySelectionGroupInterface(); CyArtFileMgrPythonInterface(); CyGameTextMgrInterface(); CyInfoPythonInterface1(); CyInfoPythonInterface2(); CyInfoPythonInterface3(); CyHallOfFameInterface(); CyGameCoreUtilsPythonInterface(); CyMessageControlInterface(); // // large interfaces which can be split across files if need be // python::class_<CyCity> city ("CyCity"); // define city class CyCityPythonInterface1(city); // publish it's methods python::class_<CyPlayer> player ("CyPlayer"); // define player class CyPlayerPythonInterface1(player); // publish it's methods CyPlayerPythonInterface2(player); // publish it's methods python::class_<CyUnit> unit ("CyUnit"); // define unit class CyUnitPythonInterface1(unit); // publish it's methods python::class_<CyPlot> plot ("CyPlot"); // define plot class CyPlotPythonInterface1(plot); // publish it's methods python::class_<CyGlobalContext> gc ("CyGlobalContext"); // define globals class CyGlobalContextPythonInterface1(gc); // publish it's methods CyGlobalContextPythonInterface2(gc); // publish it's methods CyGlobalContextPythonInterface3(gc); // publish it's methods CyGlobalContextPythonInterface4(gc); // publish it's methods }
void frame (float Vx, float Vy, float Vcx, float Vcy, float Wx, float Wy, float Wcx, float Wcy, mat &c){ unit(c); mat R, t; /// move(-Vcx, -Vcy, R); times(R, c, t); set(t,c); /// scalef(Wx / Vx, Wy / Vy, R); times(R, c, t); set(t,c); /// mirrorf( 1, 0, c); times(R, c, t); set(t,c); /// move(Wcx, Wcy, R); times(R, c, t); set(t,c); }
bool STidSTRReaderProvider::refreshReaderList() { //LOG(LogLevel::INFOS) << "Refreshing reader list..."); d_readers.clear(); std::vector<std::shared_ptr<SerialPortXml> > ports; EXCEPTION_ASSERT_WITH_LOG(SerialPortXml::EnumerateUsingCreateFile(ports), LibLogicalAccessException, "Can't enumerate the serial port list."); for (std::vector<std::shared_ptr<SerialPortXml> >::iterator i = ports.begin(); i != ports.end(); ++i) { std::shared_ptr<STidSTRReaderUnit> unit(new STidSTRReaderUnit()); std::shared_ptr<SerialPortDataTransport> dataTransport = std::dynamic_pointer_cast<SerialPortDataTransport>(unit->getDataTransport()); dataTransport->setSerialPort(*i); unit->setReaderProvider(std::weak_ptr<ReaderProvider>(shared_from_this())); d_readers.push_back(unit); //LOG(LogLevel::INFOS) << "--> Detected reader unit {%s}...", dynamic_cast<XmlSerializable*>(&(*unit))->serialize().c_str()); } return true; }
//内包判定 bool Quad2::contains(const t_Vec2& v) const { t_Vec2 n,p; ValueType dp; ValueType dp_sign=0; for(int i=0;i<4;i++){ //辺の法線 n=(pos[(i+1)%4]-pos[i]).normal(); //点へのベクトル p=v-pos[i]; //内積 dp=unit(dot_product(n,p)); //内積の符号が前回と違ったらfalse if(dp_sign==0)dp_sign=dp; else if(dp_sign*dp<0){ return false; } } return true; }
Future<unit> write_all(Reactor& reactor, StreamPtr out, Buffer data) { std::shared_ptr<Buffer> datap = std::make_shared<Buffer>(data); Completer<unit> completer; auto write_ready = [completer, datap, out]() { if(datap->size == 0) return; size_t len = out->write(*datap); *datap = datap->slice(len); if(datap->size == 0) completer.result(unit()); }; out->set_on_write_ready(write_ready); reactor.schedule(write_ready); return completer.future(); }
void AscentAP::SetLaunchAzimuth (double azimuth) { launch_azimuth = azimuth; // current launch location in local planet frame VECTOR3 pos, equ, dir, nml, ne, nd; double lng, lat, rad; double slng, clng, slat, clat; double saz = sin(azimuth), caz = cos(azimuth); OBJHANDLE hRef = vessel->GetGravityRef(); vessel->GetGlobalPos(pos); oapiGlobalToLocal (hRef, &pos, &equ); oapiLocalToEqu (hRef, equ, &lng, &lat, &rad); slng = sin(lng), clng = cos(lng), slat = sin(lat), clat = cos(lat); normalise(equ); // unit radius vector // launch direction in local planet frame dir = _V(-clng*slat*caz - slng*saz, clat*caz, -slng*slat*caz + clng*saz); // normal of orbital plane in local planet frame nml = crossp(dir, equ); // normal of equator plane in local planet frame ne = _V(0,1,0); // direction of ascending node nd = unit (crossp(nml, ne)); // orbit inclination tgt.inc = acos(dotp(nml, ne)); // longitude of ascending node tgt.lan = atan2(nd.z, nd.x); // rotation matrix from equator plane to target orbit plane double sinc = sin(tgt.inc), cinc = cos(tgt.inc); double slan = sin(tgt.lan), clan = cos(tgt.lan); MATRIX3 R1 = _M(1,0,0, 0,cinc,sinc, 0,-sinc,cinc); MATRIX3 R2 = _M(clan,0,-slan, 0,1,0, slan,0,clan); tgt.R = mul(R2,R1); }
CollisionData collideWithCircle( PointMovement const& p, Circle const& c, float time) { /* Let c be the centre of the circle, and let r be its radius. Then then * equation for the circle is * |x - c|^2 = r^2 * * Let v be the velocity of the point, and let p be the position of the * point. Then the position of the point after time t is * x = p + v t. * * Substituting that back in, the equation to be solved is: * |v t + p - c|^2 = r^2. * I.e. * A t^2 + B t + C = 0, * where * A = |v|^2, * B = 2 v . (p - c), and * C = |p - c|^2 - r^2. * * We are looking for the least positive solution to this where t < time. * If there is only one positive solution we may ingore it as this * corresponds to the case when the point is inside the ball. */ float A = magnitudeSquared(p.vel); float B = 2 * (dot(p.vel, p.pos - c.centre)); float C = magnitudeSquared(p.pos - c.centre) - c.radius * c.radius; /* If velocity is 0 don't collide with this algorithm * If there is at most one positive solution we don't collide. * If there are no solutions. */ if (A <= 0 or B > 0 or B * B - 4 * A * C < 0) { return {{0,0}, time}; } float t = (-B - std::sqrt(B * B - 4 * A * C)) / (2 * A); return { unit(c.centre - (p.pos + p.vel * t)), std::min(time, t) }; }
QVector<QPointF> vectorFrom2Points(QPointF p1, QPointF p2, int pad, int penWidth){ QPointF v = p2 - p1; //unit QVector2D unit(v); v = unit.normalized().toPointF(); v += v*(penWidth / 2. + pad); qreal angle = 3.1415926 / 2; qreal x1 = cos(angle)*v.x() - sin(angle)*v.y(); qreal y1 = cos(angle)*v.y() + sin(angle)*v.x(); QPointF vccw90 = QPointF(x1, y1); QVector<QPointF> vector; vector.append(p1 - v + vccw90); vector.append(p2 + v + vccw90); vector.append(p2 + v - vccw90); vector.append(p1 - v - vccw90); return vector; }
QPair<bool, QStringList> precompile(const PchInfo::Ptr &pchInfo) { // qDebug() << "*** Precompiling" << pchInfo->inputFileName() // << "into" << pchInfo->fileName() // << "with options" << pchInfo->options(); bool ok = false; Internal::Unit unit(pchInfo->inputFileName()); unit.setCompilationOptions(pchInfo->options()); unsigned parseOpts = CXTranslationUnit_ForSerialization | CXTranslationUnit_Incomplete; unit.setManagementOptions(parseOpts); unit.parse(); if (unit.isLoaded()) ok = CXSaveError_None == unit.save(pchInfo->fileName()); return qMakePair(ok, Internal::formattedDiagnostics(unit)); }
QModbusResponse QModbusServerPrivate::readBytes(const QModbusPdu &request, QModbusDataUnit::RegisterType unitType) { CHECK_SIZE_EQUALS(request); quint16 address, count; request.decodeData(&address, &count); if ((count < 0x0001) || (count > 0x007D)) { return QModbusExceptionResponse(request.functionCode(), QModbusExceptionResponse::IllegalDataValue); } // Get the requested range out of the registers. QModbusDataUnit unit(unitType, address, count); if (!q_func()->data(&unit)) { return QModbusExceptionResponse(request.functionCode(), QModbusExceptionResponse::IllegalDataAddress); } return QModbusResponse(request.functionCode(), quint8(count * 2), unit.values()); }
int main() { int n = 0; char c; f = fopen("9.txt", "r"); if (f == NULL) err("Eroare la fisier!"); while ((c = fgetc(f)) != EOF) text[n++] = c; fclose(f); pointer_urmator = text; do getNextToken(); while (lastToken->code != END); showAtoms(); initSymbols(&symbols); AddExtFunctions(); currentToken = tokens; unit(); afisareSymbols(&symbols); return 0; }
void RLBWT::append(char b) { bool increment = false; if(!m_rlString.empty()) { RLUnit& lastUnit = m_rlString.back(); if(lastUnit.getChar() == b && !lastUnit.isFull()) { lastUnit.incrementCount(); increment = true; } } if(!increment) { // Must add a new unit to the string RLUnit unit(b); m_rlString.push_back(unit); } ++m_numSymbols; }
int _tmain(int argc, _TCHAR* argv[]) { int i; info = new CInfoConsole(); CFileHandler in("scripts/flatbridge.cob"); CCobFile f(in, "jao"); CCobInstance unit(f, NULL); vector<long> params; params.push_back(0); //params.push_back(40); //i = unit.Call("Create", params); //i = unit.Call("Activate", params); i = unit.Call("Transbordement", params); if (i == 0) { printf("Script terminated\n"); for (i = 0; i < params.size(); ++i) { printf("Variable %i: %i\n", i, params[i]); } } LARGE_INTEGER starttime; QueryPerformanceCounter(&starttime); for (i = 0; i < 10; ++i) { GCobEngine.Tick(1500); //printf("tick\n"); } //unit.Tick(10); LARGE_INTEGER stop; QueryPerformanceCounter(&stop); printf("time: %ld\n", stop.QuadPart - starttime.QuadPart); int x=0; scanf("%i", &x); return 0; }
TEST(Simplifier, JumpFuse) { BCMarker dummy = BCMarker::Dummy(); IRUnit unit(test_context); Simplifier sim(unit); { // JmpZero(Eq(X, true)) --> JmpEq(X, false) auto taken = unit.defBlock(); auto lhs = unit.cns(true); auto rhs = unit.gen(Conjure, dummy, Type::Bool); auto eq = unit.gen(Eq, dummy, lhs, rhs->dst()); auto jmp = unit.gen(JmpZero, dummy, taken, eq->dst()); auto result = sim.simplify(jmp, false); EXPECT_EQ(nullptr, result.dst); EXPECT_EQ(2, result.instrs.size()); // This is a dead Eq instruction; an artifact of weirdness in the // implementation. Should go away. EXPECT_FALSE(result.instrs[0]->isControlFlow()); EXPECT_MATCH(result.instrs[1], JmpEq, taken, rhs->dst(), unit.cns(false)); } { // JmpNZero(Neq(X, Y)) --> JmpNeq(X, Y) auto taken = unit.defBlock(); auto x = unit.gen(Conjure, dummy, Type::Dbl); auto y = unit.gen(Conjure, dummy, Type::Dbl); auto neq = unit.gen(Neq, dummy, x->dst(), y->dst()); auto jmp = unit.gen(JmpNZero, dummy, taken, neq->dst()); auto result = sim.simplify(jmp, false); EXPECT_EQ(nullptr, result.dst); EXPECT_EQ(1, result.instrs.size()); EXPECT_MATCH(result.instrs[0], JmpNeq, taken, x->dst(), y->dst()); } }
QgsSymbolV2::OutputUnit QgsSymbolV2::outputUnit() const { QgsSymbolV2::OutputUnit unit( QgsSymbolV2::Mixed ); QgsSymbolLayerV2List::const_iterator it = mLayers.constBegin(); for ( ; it != mLayers.constEnd(); ++it ) { if ( it == mLayers.constBegin() ) { unit = ( *it )->outputUnit(); } else { if (( *it )->outputUnit() != unit ) { return QgsSymbolV2::Mixed; } } } return unit; }