string format(const string& str1, const unsigned int& arg1, const string& arg2) { string token1("{0}"); string token2("{1}"); string newString(str1); newString = substitute(newString, token1, (int) arg1); newString = substitute(newString, token2, arg2); return newString; }
string format(const string& str1, const unsigned int& arg1, const string& arg2, const string& arg3) { string token1("{0}"); string token2("{1}"); string token3("{2}"); string newString(str1); newString = substitute(newString, token1, rr::toString(arg1)); newString = substitute(newString, token2, arg2); newString = substitute(newString, token3, arg3); return newString; }
string format(const string& str1, const string& arg1, const string& arg2, const string& arg3, const string& arg4) { string token1("{0}"); string token2("{1}"); string token3("{2}"); string token4("{3}"); string newString(str1); newString = substitute(newString, token1, arg1); newString = substitute(newString, token2, arg2); newString = substitute(newString, token3, arg3); newString = substitute(newString, token4, arg4); return newString; }
void Lexer::token(Token &t) { if ( file.fd() < 0) t.Type( Token::eof); else { token2(t); if (t.Type() == Token::eof) file.Close(); } lasttokentype=t.Type(); if (maildrop.embedded_mode) switch (lasttokentype) { case Token::tokento: case Token::tokencc: case Token::btstring: case Token::tokenxfilter: case Token::dotlock: case Token::flock: case Token::logfile: case Token::log: { Buffer errmsg; errmsg="maildrop: '"; errmsg += t.Name(); errmsg += "' disabled in embedded mode.\n"; errmsg += '\0'; error((const char *)errmsg); t.Type( Token::error ); break; } default: break; } if (VerboseLevel() > 8) { Buffer debug; debug="Tokenized "; debug += t.Name(); debug += '\n'; debug += '\0'; error((const char *)debug); } }
void testServiceRegistry::hierarchyTest() { art::AssertHandler ah; std::vector<fhicl::ParameterSet> pss; { fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 1; ps.addParameter("value", value); pss.push_back(ps); } art::ServiceToken token1(art::ServiceRegistry::createSet(pss)); pss.clear(); { fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); } art::ServiceToken token2(art::ServiceRegistry::createSet(pss)); art::ServiceRegistry::Operate operate1(token1); { art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy->value() == 1); } { art::ServiceRegistry::Operate operate2(token2); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy->value() == 2); } { art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy->value() == 1); } }
int main() { edm::EDGetTokenT<int> token1; if(!token1.isUnitialized() || !(token1.index() == 0xFFFFFFFF)) { std::cout << "EDGetTokenT no argument constructor failed 1" << std::endl; abort(); } edm::EDGetTokenT<int> token2(11); if(token2.isUnitialized() || !(token2.index() == 11)) { std::cout << "EDGetTokenT 1 argument constructor failed 2" << std::endl; abort(); } edm::EDGetToken token10; if(!token10.isUnitialized() || !(token10.index() == 0xFFFFFFFF)) { std::cout << "EDGetToken no argument constructor failed 10" << std::endl; abort(); } edm::EDGetToken token11(100); if(token11.isUnitialized() || !(token11.index() == 100)) { std::cout << "EDGetToken 1 argument constructor failed 11" << std::endl; abort(); } edm::EDGetToken token12(token2); if(token12.isUnitialized() || !(token12.index() == 11)) { std::cout << "EDGetToken 1 argument constructor failed 12" << std::endl; abort(); } }
void testServiceRegistry::externalServiceTest() { art::AssertHandler ah; { std::unique_ptr<DummyService> dummyPtr(new DummyService); dummyPtr->value_ = 2; art::ServiceToken token(art::ServiceRegistry::createContaining(dummyPtr)); { art::ServiceRegistry::Operate operate(token); art::ServiceHandle<DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value_ == 2); } { std::vector<fhicl::ParameterSet> pss; fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); art::ServiceToken token(art::ServiceRegistry::createSet(pss)); art::ServiceToken token2(art::ServiceRegistry::createContaining(dummyPtr, token, art::serviceregistry::kOverlapIsError)); art::ServiceRegistry::Operate operate(token2); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value() == 2); } } { std::unique_ptr<DummyService> dummyPtr(new DummyService); std::shared_ptr<art::serviceregistry::ServiceWrapper<DummyService> > wrapper(new art::serviceregistry::ServiceWrapper<DummyService>(dummyPtr)); art::ServiceToken token(art::ServiceRegistry::createContaining(wrapper)); wrapper->get().value_ = 2; { art::ServiceRegistry::Operate operate(token); art::ServiceHandle<DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value_ == 2); } { std::vector<fhicl::ParameterSet> pss; fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); art::ServiceToken token(art::ServiceRegistry::createSet(pss)); art::ServiceToken token2(art::ServiceRegistry::createContaining(dummyPtr, token, art::serviceregistry::kOverlapIsError)); art::ServiceRegistry::Operate operate(token2); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value() == 2); } } }
void CUT_PBASE_T_USBDI_1231::DeviceInsertedL(TUint aDeviceHandle) { OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1231_DEVICEINSERTEDL_ENTRY, this ); OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP04, "====> DeviceInsertedL entry priority = %d", RThread().Priority()); iInterface0Resumed = EFalse; Cancel(); // Cancel the timer TInt err(KErrNone); iDeviceHandle = aDeviceHandle; iActorFDF->Monitor(); // Validate that device is as expected CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); if (testDevice.SerialNumber().Compare(TestCaseId()) != 0) { // Incorrect device for this test case RDebug::Printf( "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)", KErrNotFound, &testDevice.SerialNumber(), &TestCaseId()); // Start the connection timeout again TimeoutIn(30); OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1231_DEVICEINSERTEDL_EXIT, this ); return; } // Check tree now CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceA")) == KErrNone); // Perform the correct test step switch (iCaseStep) { case EInProcess: { TUint32 token1(0); TUint32 token2(0); OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP05, "Obtaining token for interface 0"); err = testDevice.Device().GetTokenForInterface(0, token1); if (err != KErrNone) { RDebug::Printf( "<Error %d> Token for interface 0 could not be retrieved", err); return TestFailed(err); } OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP06, "Token 1 (%d) retrieved", token1); OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP07, "Opening interface 0"); err = iUsbInterface0.Open(token1); // Alternate interface setting 0 if (err != KErrNone) { RDebug::Printf( "<Error %d> Interface 0 could not be opened", err); return TestFailed(err); } OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP08, "Interface 0 opened"); OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP09, "Obtaining token for interface 1"); err = testDevice.Device().GetTokenForInterface(1, token2); if (err != KErrNone) { RDebug::Printf( "<Error %d> Token for interface 1 could not be retrieved", err); return TestFailed(err); } OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP10, "Opening interface 1"); err = iUsbInterface1.Open(token2); // Alternate interface setting 0 if (err != KErrNone) { RDebug::Printf( "<Error %d> Interface 1 could not be opened", err); return TestFailed(err); } OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1231_DCUT_PBASE_T_USBDI_1231_DUP11, "Interface 1 opened"); ResumeWhenSuspending(); } break; default: TestFailed(KErrCorrupt); break; } OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1231_DEVICEINSERTEDL_EXIT_DUP01, this ); }
int main(int argc, char *argv[]) { { std::string s = "a b\"MID\" c d"; std::vector<std::string> result; unsigned int ret = stringTokenize(s, ' ', &result); assert(ret == 4); assert(result.size() == 4); assert(result[0] == "a"); assert(result[1] == "b\"MID\""); assert(result[2] == "c"); assert(result[3] == "d"); ret = stringTokenize(s, "\" ", &result); assert(result.size() == 6); assert(result[0] == "a"); assert(result[1] == "b"); assert(result[2] == "MID"); assert(result[3] == ""); assert(result[4] == "c"); assert(result[5] == "d"); s = ""; ret = stringTokenize(s, " ", &result); assert(result.size() == 1); assert(result[0] == ""); } { std::string s = "a b\"MID\" c d"; std::string piece; std::vector<std::string> result; StringTokenizer st1(s, ' '); while (st1.next(&piece)) { // printf("piece = %s\n", piece.c_str()); result.push_back(piece); } assert(result.size() == 4); assert(result[0] == "a"); assert(result[1] == "b\"MID\""); assert(result[2] == "c"); assert(result[3] == "d"); result.clear(); StringTokenizer st2(s, "\" "); while (st2.next(&piece)) { printf("piece = %s\n", piece.c_str()); result.push_back(piece); } assert(result.size() == 6); assert(result[0] == "a"); assert(result[1] == "b"); assert(result[2] == "MID"); assert(result[3] == ""); assert(result[4] == "c"); assert(result[5] == "d"); result.clear(); s = ""; StringTokenizer st3(s, " "); while (st3.next(&piece)) { result.push_back(piece); } assert(result.size() == 0); } { std::string s = ""; std::string res = stringStrip(s); assert(res.size() == 0); s = " "; res = stringStrip(s); assert(res.size() == 0); } { std::string s = "a b\"MID\" c d"; std::vector<std::string> result; unsigned int ret = stringNaturalTokenize(s, ' ', &result); assert(ret == 4); assert(result.size() == 4); assert(result[0] == "a"); assert(result[1] == "b\"MID\""); assert(result[2] == "c"); assert(result[3] == "d"); ret = stringNaturalTokenize(s, "\" ", &result); assert(result.size() == 5); assert(result[0] == "a"); assert(result[1] == "b"); assert(result[2] == "MID"); assert(result[3] == "c"); assert(result[4] == "d"); s = ""; ret = stringNaturalTokenize(s, " ", &result); assert(result.size() == 0); } { std::string s = "a b\"MID\" c d"; std::vector<std::string> result; StringTokenizer token(s, ' '); std::string ret; assert(token.next(&ret)); assert(ret == "a"); assert(token.next(&ret)); assert(ret == "b\"MID\""); assert(token.next(&ret)); assert(ret == "c"); assert(token.next(&ret)); assert(ret == "d"); assert(!token.next(&ret)); } { std::string s = "a b\"MID\" c d"; std::vector<std::string> result; StringTokenizer token(s, "\" "); std::string ret; assert(token.next(&ret)); assert(ret == "a"); assert(token.next(&ret)); assert(ret == "b"); assert(token.next(&ret)); assert(ret == "MID"); assert(token.next(&ret)); assert(ret == ""); assert(token.next(&ret)); assert(ret == "c"); assert(token.next(&ret)); assert(ret == "d"); assert(!token.next(&ret)); } { std::string s = ""; std::vector<std::string> result; StringTokenizer token(s, " "); std::string ret; assert(!token.next(&ret)); } { std::string s = "a b\"MID\" c d"; std::vector<std::string> result; StringTokenizer token(s, ' '); int ret = token.naturalTokenize(&result); assert(ret == 4); assert(result.size() == 4); assert(result[0] == "a"); assert(result[1] == "b\"MID\""); assert(result[2] == "c"); assert(result[3] == "d"); StringTokenizer token2(s, "\" "); ret = token2.naturalTokenize(&result); assert(result.size() == 5); assert(result[0] == "a"); assert(result[1] == "b"); assert(result[2] == "MID"); assert(result[3] == "c"); assert(result[4] == "d"); s = ""; StringTokenizer token3(s, " "); ret = token3.naturalTokenize(&result); assert(result.size() == 0); } return 0; }
GameBoard::GameBoard(QObject *parent) : QObject(parent) { // START PLACE std::shared_ptr<BoardPlace> start(new CornerPlace(0,QString("START"))); placesVector.push_back(start); // SALONIKI CityPlace* saloniki = new CityPlace(1,QString("SALONIKI"),100.0); saloniki->init(5, 25, 50, 100, 300, 500, 100, 100); placesVector.push_back(std::shared_ptr<BoardPlace>(saloniki)); // CHANCE placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(2,QString("CHANCE1")))); // ATENY CityPlace* ateny = new CityPlace(3,QString("ATENY"),120.0); ateny->init(10, 30, 60, 150, 400, 600, 100, 100); placesVector.push_back(std::shared_ptr<BoardPlace>(ateny)); // PARKING TaxPlace* parking = new TaxPlace(4, QString("PARKING TAX")); parking->init(400.0,QString("You have to pay parking fee")); placesVector.push_back(std::shared_ptr<BoardPlace>(parking)); // SOUTH RAILWAY RailwayPlace* southRailway = new RailwayPlace(5, QString("SOUTH RAILWAY"), 400.0); southRailway->initPayments(); placesVector.push_back(std::shared_ptr<BoardPlace>(southRailway)); // NEAPOL CityPlace* neapol = new CityPlace(6,QString("NEAPOL"),200.0); neapol->init(20, 60, 100, 300, 500, 800, 100, 100); placesVector.push_back(std::shared_ptr<BoardPlace>(neapol)); // CHANCE placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(7,QString("CHANCE2")))); // MEDIOLAN CityPlace* mediolan = new CityPlace(8,QString("MEDIOLAN"),250.0); mediolan->init(25, 80, 150, 300, 600, 800, 100, 100); placesVector.push_back(std::shared_ptr<BoardPlace>(mediolan)); // ROME CityPlace* rome = new CityPlace(9,QString("ROME"),290.0); rome->init(30, 100, 200, 350, 800, 1000, 100, 100); placesVector.push_back(std::shared_ptr<BoardPlace>(rome)); // VISITING PRISON std::shared_ptr<BoardPlace> visiting(new CornerPlace(10,QString("FOR VISITORS"))); placesVector.push_back(visiting); // BARCELONA CityPlace* barcelona = new CityPlace(11,QString("BARCELONA"),300.0); barcelona->init(30, 100, 250, 500, 900, 1200, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(barcelona)); // POWER STATION CounterPlace* electricStation = new CounterPlace(12, QString("ELECTRIC STATION"), 10, 300.0); placesVector.push_back(std::shared_ptr<BoardPlace>(electricStation)); // SEWILLA CityPlace* sewilla = new CityPlace(13, QString("SEWILLA"),320.0); sewilla->init(30, 120, 300, 700, 1000, 1300, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(sewilla)); // MADRYT CityPlace* madryt = new CityPlace(14, QString("MADRYT"),330.0); madryt->init(35, 125, 310, 800, 1100, 1400, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(madryt)); // WEST RAILWAY RailwayPlace* westRailway = new RailwayPlace(15, QString("WAST RAILWAY"), 400.0); placesVector.push_back(std::shared_ptr<BoardPlace>(westRailway)); // LIVERPOOL CityPlace* liverpool = new CityPlace(16, QString("LIVERPOOL"),370.0); liverpool->init(35, 140, 350, 1000, 1200, 1600, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(liverpool)); // CHANCE 3 placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(17,QString("CHANCE3")))); // GLASGOW CityPlace* glasgow = new CityPlace(18, QString("GLASGOW"),380.0); glasgow->init(40, 150, 400, 1100, 1500, 1900, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(glasgow)); // LONDON CityPlace* london = new CityPlace(19, QString("LONDON"),400.0); london->init(45, 160, 450, 1200, 1600, 2000, 200, 200); placesVector.push_back(std::shared_ptr<BoardPlace>(london)); // FREE PARKING std::shared_ptr<BoardPlace> freeParking(new CornerPlace(20, QString("FREE PARKING"))); placesVector.push_back(freeParking); // ROTTERDAM CityPlace* rotterdam = new CityPlace(21, QString("ROTTERDAM"), 440.0); rotterdam->init(45, 180, 500, 1300, 1700, 2100, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(rotterdam)); // CHANCE 4 placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(22,QString("CHANCE4")))); // BRUSSEL CityPlace* brussel = new CityPlace(23, QString("ROTTERDAM"), 440.0); brussel->init(45, 180, 550, 1350, 1750, 2200, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(brussel)); // AMSTERDAM CityPlace* amsterdam = new CityPlace(24, QString("AMSTERDAM"), 480.0); amsterdam->init(50, 200, 600, 1400, 1800, 2250, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(amsterdam)); // NORTH RAILWAY RailwayPlace* northRailway = new RailwayPlace(25, QString("NORTH RAILWAY"), 400.0); placesVector.push_back(std::shared_ptr<BoardPlace>(northRailway)); // MALMO CityPlace* malmo = new CityPlace(26, QString("MALMO"), 520.0); malmo->init(50, 220, 660, 1600, 1950, 2300, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(malmo)); // GOTEBORG CityPlace* goteborg = new CityPlace(27, QString("GOTEBORG"), 520.0); goteborg->init(50, 220, 660, 1600, 1950, 2300, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(goteborg)); // WATERWORKS CounterPlace* waterworks = new CounterPlace(28, QString("WATERWORKS"), 10, 300.0); placesVector.push_back(std::shared_ptr<BoardPlace>(waterworks)); // SZTOKHOLM CityPlace* sztokholm = new CityPlace(29, QString("SZTOKHOLM"), 550.0); sztokholm->init(50, 250, 700, 1800, 2000, 2400, 300, 300); placesVector.push_back(std::shared_ptr<BoardPlace>(sztokholm)); // PRISON std::shared_ptr<BoardPlace> prison(new CornerPlace(30, QString("PRISON"))); placesVector.push_back(prison); // FRANKFURT CityPlace* frankfurt = new CityPlace(31, QString("FRANKFURT"), 600.0); frankfurt->init(55, 250, 660, 1800, 2200, 2600, 400, 400); placesVector.push_back(std::shared_ptr<BoardPlace>(frankfurt)); // KOLONY CityPlace* kolony = new CityPlace(32, QString("KOLONY"), 600.0); kolony->init(55, 250, 660, 1800, 2200, 2600, 400, 400); placesVector.push_back(std::shared_ptr<BoardPlace>(kolony)); // CHANCE 5 placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(33,QString("CHANCE5")))); // BONN CityPlace* bonn = new CityPlace(34, QString("BONN"), 650.0); bonn->init(60, 300, 700, 2000, 2400, 2800, 400, 400); placesVector.push_back(std::shared_ptr<BoardPlace>(bonn)); // EAST RAILWAY RailwayPlace* eastRailway = new RailwayPlace(35, QString("EAST RAILWAY"), 400.0); placesVector.push_back(std::shared_ptr<BoardPlace>(eastRailway)); // CHANCE 6 placesVector.push_back(std::shared_ptr<BoardPlace>(new ChancePlace(36,QString("CHANCE6")))); // INSBRUCK CityPlace* insbruck = new CityPlace(37, QString("INSBRUCK"), 700.0); insbruck->init(70, 350, 900, 2200, 2800, 3500, 400, 400); placesVector.push_back(std::shared_ptr<BoardPlace>(insbruck)); // INCOME TAX TaxPlace* incomeTax = new TaxPlace(38, QString("INCOME TAX")); parking->init(200.0,QString("You have to pay income tax")); placesVector.push_back(std::shared_ptr<BoardPlace>(incomeTax)); // VIENNA CityPlace* vienna = new CityPlace(39, QString("VIENNA"), 800.0); vienna->init(100, 400, 1400, 2500, 3000, 4000, 400, 400); placesVector.push_back(std::shared_ptr<BoardPlace>(vienna)); Q_ASSERT(placesVector.size() == 40); // TOKENS CONSTRUCTION QPointer<Token> token0(new Token(0, placesVector, this)); tokens.push_back(token0); QPointer<Token> token1(new Token(1, placesVector, this)); tokens.push_back(token1); QPointer<Token> token2(new Token(2, placesVector, this)); tokens.push_back(token2); QPointer<Token> token3(new Token(3, placesVector, this)); tokens.push_back(token3); QPointer<Token> token4(new Token(4, placesVector, this)); tokens.push_back(token4); // TOKENS SIGNALS AND SLOTS for (auto a : tokens) { bool result1 = QObject::connect(a, SIGNAL(startGame()), this, SLOT(startGame())); Q_ASSERT(result1); } bool res1 = QObject::connect(&playerFactory, SIGNAL(playerReady(std::shared_ptr<Player>)), this, SLOT(addPlayer(std::shared_ptr<Player>))); bool res2 = QObject::connect(&playerFactory, SIGNAL(removePlayerFromBoard(int)), this, SLOT(handleRemovePlayerRequest(int))); }