当前位置: 首页>>代码示例>>C++>>正文


C++ Poco::format方法代码示例

本文整理汇总了C++中Poco::format方法的典型用法代码示例。如果您正苦于以下问题:C++ Poco::format方法的具体用法?C++ Poco::format怎么用?C++ Poco::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Poco的用法示例。


在下文中一共展示了Poco::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: scanInterface

/*!
	Scans an interface and enumerates all baos devices.
	It sends a search request as outlined in the BAOS 1.2 protocol
	documentation and waits for the responses. There are lots of
	magic numbers here and hard-coded offsets... See the spec
	for more information on what is happening here...

	We implement a receive timeout, and keep receiving until this
	timeout elapses. If this timeout is too fast, increase it to 500
	or 1000 for example.
*/
void BaosIpEnumerator::scanInterface(const NetworkInterface& networkInterface)
{
	poco_information(LOGGER(),
	                 format("Search devices on interface: %s (%s)",
	                        networkInterface.displayName(),
	                        networkInterface.address().toString()));

	try
	{
		// initialize socket
		MulticastSocket socket;
		socket.bind(SocketAddress(networkInterface.address(), 0));
		socket.setTimeToLive(DefaultMulticastTTL);

		// builds and sends a SEARCH_REQUEST to the socket
		sendSearchRequestFrame(socket);

		// wait for SEARCH_RESPONSES and collect it
		waitForSearchResponseFrames(socket);
	}
	catch (Poco::Exception& e)
	{
		poco_warning(LOGGER(), format("... search failed with error: %s", e.displayText()));
	}
}
开发者ID:weinzierl-engineering,项目名称:baos,代码行数:36,代码来源:BaosEnumerator.cpp

示例2: testBool

void FormatTest::testBool()
{
	bool b = true;
	std::string s = format("%b", b);
	assert (s == "1");

	b = false;
	s = format("%b", b);
	assert (s == "0");

	std::vector<Poco::Any> bv;
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);

	s.clear();
	format(s, "%b%b%b%b%b%b%b%b%b%b", bv);
	assert (s == "0101010101");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:26,代码来源:FormatTest.cpp

示例3: addDevice

void BaosIpEnumerator::addDevice(const std::vector<unsigned char>& buffer, const IPAddress& networkInterface)
{
	if (buffer.size() > 68)
	{
		const int svcdiblen = buffer.at(68);
		const std::string ipAddress = format("%d.%d.%d.%d", (int) buffer.at(8), (int) buffer.at(9), (int) buffer.at(10), (int) buffer.at(11));
		const std::string deviceName = extract(&buffer.at(38), 30);
		const int manOffset = 68 + svcdiblen;

		if (static_cast<std::size_t>(manOffset + 7) < buffer.size())
		{
			const unsigned short mancode = buffer.at(manOffset + 2) << 8 | buffer.at(manOffset + 3);
			const unsigned char protocol = buffer.at(manOffset + 6);
			const unsigned char version = buffer.at(manOffset + 7);

			if (mancode == 0x00C5 && protocol == 0xF0)
			{
				poco_information(LOGGER(),
				                 format("Found: %s %s %d",
				                        deviceName, ipAddress, static_cast<int>(version)));

				devices_.push_back(std::make_tuple(deviceName, networkInterface.toString(), ipAddress, version));
			}
		}
	}
}
开发者ID:weinzierl-engineering,项目名称:baos,代码行数:26,代码来源:BaosEnumerator.cpp

示例4: canConnect

bool ODBCTest::canConnect(const std::string& driver,
	std::string& dsn,
	std::string& uid,
	std::string& pwd,
	std::string& dbConnString,
	const std::string& db)
{
	Utility::DriverMap::iterator itDrv = _drivers.begin();
	for (; itDrv != _drivers.end(); ++itDrv)
	{
		if (((itDrv->first).find(driver) != std::string::npos))
		{
			std::cout << "Driver found: " << itDrv->first 
				<< " (" << itDrv->second << ')' << std::endl;
			break;
		}
	}

	if (_drivers.end() == itDrv) 
	{
		dsn = "";
		uid = "";
		pwd = "";
		dbConnString = "";
		std::cout << driver << " driver NOT found, tests not available." << std::endl;
		return false;
	}

	Utility::DSNMap dataSources;
	Utility::dataSources(dataSources);
	if (dataSources.size() > 0)
	{
		Utility::DSNMap::iterator itDSN = dataSources.begin();
		std::cout << dataSources.size() << " DSNs found, enumerating ..." << std::endl;
		for (; itDSN != dataSources.end(); ++itDSN)
		{
			if (itDSN->first == dsn && itDSN->second == driver)
			{
				std::cout << "DSN found: " << itDSN->first
					<< " (" << itDSN->second << ')' << std::endl;

				dbConnString = format("DSN=%s;UID=%s;PWD=%s;", dsn, uid, pwd);
				if (!db.empty())
					format(dbConnString, "DATABASE=%s;", db);

				return true;
			}
		}
	}
	else
		std::cout << "No DSNs found, will attempt DSN-less connection ..." << std::endl;

	dsn = "";
	return true;
}
开发者ID:Blonder,项目名称:poco,代码行数:55,代码来源:ODBCTest.cpp

示例5: testIndex

void FormatTest::testIndex()
{
	std::string s(format("%[1]d%[0]d", 1, 2));
	assert(s == "21");

	s = format("%[5]d%[4]d%[3]d%[2]d%[1]d%[0]d", 1, 2, 3, 4, 5, 6);
	assert(s == "654321");

	s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3);
	assert(s == "%2%3%1");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:11,代码来源:FormatTest.cpp

示例6: testChar

void FormatTest::testChar()
{
	char c = 'a';
	std::string s(format("%c", c));
	assert(s == "a");
	s = format("%2c", c);
	assert(s == " a");
	s = format("%-2c", c);
	assert(s == "a ");

	s = format("%c", std::string("foo"));
	assert(s == "[ERRFMT]");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:13,代码来源:FormatTest.cpp

示例7: canConnect

bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& dsn)
{
	Utility::DriverMap::iterator itDrv = _drivers.begin();
	for (; itDrv != _drivers.end(); ++itDrv)
	{
		if (((itDrv->first).find(driver) != std::string::npos))
		{
			std::cout << "Driver found: " << itDrv->first 
				<< " (" << itDrv->second << ')' << std::endl;
			break;
		}
	}

	if (_drivers.end() == itDrv) 
	{
		std::cout << driver << " driver NOT found, tests not available." << std::endl;
		return false;
	}

	Utility::DSNMap dataSources;
	Utility::dataSources(dataSources);
	Utility::DSNMap::iterator itDSN = dataSources.begin();
	for (; itDSN != dataSources.end(); ++itDSN)
	{
		if (itDSN->first == dsn && itDSN->second == driver)
		{
			std::cout << "DSN found: " << itDSN->first 
				<< " (" << itDSN->second << ')' << std::endl;
			format(_dbConnString, "DSN=%s", dsn);
			return true;
		}
	}

	// DSN not found, try connect without it
	format(_dbConnString, "DRIVER=%s;"
		"UID=admin;"
		"UserCommitSync=Yes;"
		"Threads=3;"
		"SafeTransactions=0;"
		"PageTimeout=5;"
		"MaxScanRows=8;"
		"MaxBufferSize=2048;"
		"FIL=MS Access;"
		"DriverId=25;"
		"DBQ=test.mdb;", driver);

	return true;
}
开发者ID:carvalhomb,项目名称:tsmells,代码行数:48,代码来源:ODBCAccessTest.cpp

示例8: dropObject

void ODBCSQLiteTest::dropObject(const std::string& type, const std::string& name)
{
	try
	{
		session() << format("DROP %s %s", type, name), now;
	}
	catch (StatementException& ex)
	{
		bool ignoreError = false;
		const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
		StatementDiagnostics::Iterator it = flds.begin();
		for (; it != flds.end(); ++it)
		{
			if (1 == it->_nativeError)//(no such table)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) 
		{
			std::cout << ex.toString() << std::endl;
			throw;
		}
	}
}
开发者ID:Blonder,项目名称:poco,代码行数:27,代码来源:ODBCSQLiteTest.cpp

示例9: dropTable

void ODBCOracleTest::dropTable(const std::string& tableName)
{
	try
	{
		*_pSession << format("DROP TABLE %s", tableName), now;
	}
	catch (StatementException& ex)
	{
		bool ignoreError = false;
		const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
		StatementDiagnostics::Iterator it = flds.begin();
		for (; it != flds.end(); ++it)
		{
			if (942 == it->_nativeError)//ORA-00942 (table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) 
		{
			std::cout << ex.displayText() << std::endl;
			throw;
		}
	}
}
开发者ID:tjizep,项目名称:treestore,代码行数:27,代码来源:ODBCOracleTest.cpp

示例10: testMultiple

void FormatTest::testMultiple()
{
	std::string s(format("aaa%dbbb%4dccc", 1, 2));
	assert (s == "aaa1bbb   2ccc");

	s = format("%%%d%%%d%%%d", 1, 2, 3);
	assert (s == "%1%2%3");
	
	s = format("%d%d%d%d", 1, 2, 3, 4);
	assert (s == "1234");

	s = format("%d%d%d%d%d", 1, 2, 3, 4, 5);
	assert (s == "12345");

	s = format("%d%d%d%d%d%d", 1, 2, 3, 4, 5, 6);
	assert (s == "123456");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:17,代码来源:FormatTest.cpp

示例11: testString

void FormatTest::testString()
{
	std::string foo("foo");
	std::string s(format("%s", foo));
	assert (s == "foo");
	
	s = format("%5s", foo);
	assert (s == "  foo");

	s = format("%-5s", foo);
	assert (s == "foo  ");

	s = format("%s%%a", foo);
	assert (s == "foo%a");

	s = format("'%s%%''%s%%'", foo, foo);
	assert (s == "'foo%''foo%'");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:18,代码来源:FormatTest.cpp

示例12: testFloatFix

void FormatTest::testFloatFix()
{
	double d = 1.5;
	std::string s(format("%f", d));
	assert (s.find("1.50") == 0);

	s = format("%10f", d);
	assert (s.find(" 1.50") != std::string::npos);

	s = format("%6.2f", d);
	assert (s == "  1.50");
	s = format("%-6.2f", d);
	assert (s == "1.50  ");
	
	float f = 1.5;
	s = format("%hf", f);
	assert (s.find("1.50") == 0);
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:18,代码来源:FormatTest.cpp

示例13: waitForSearchResponseFrames

void BaosIpEnumerator::waitForSearchResponseFrames(MulticastSocket& socket)
{
	std::vector<unsigned char> buffer;
	while (waitForRx(socket, buffer))
	{
		poco_trace(LOGGER(), format("Received search response: %s", LoggerFormatter::toHex(buffer)));
		addDevice(buffer, socket.address().host());
	}
}
开发者ID:weinzierl-engineering,项目名称:baos,代码行数:9,代码来源:BaosEnumerator.cpp

示例14: testFloatSci

void FormatTest::testFloatSci()
{
	double d = 1.5;
	std::string s(format("%e", d));
	assert (s.find("1.50") == 0);
	assert (s.find("0e+0") != std::string::npos);

	s = format("%20e", d);
	assert (s.find(" 1.50") != std::string::npos);
	assert (s.find("0e+0") != std::string::npos);

	s = format("%10.2e", d);
	assert (s == " 1.50e+000" || s == "  1.50e+00");
	s = format("%-10.2e", d);
	assert (s == "1.50e+000 " || s == "1.50e+00  ");
	s = format("%-10.2E", d);
	assert (s == "1.50E+000 " || s == "1.50E+00  ");
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:18,代码来源:FormatTest.cpp

示例15: testChar

void FormatTest::testChar()
{
	char c = 'a';
	std::string s(format("%c", c));
	assert (s == "a");
	s = format("%2c", c);
	assert (s == " a");
	s = format("%-2c", c);
	assert (s == "a ");
	
	try
	{
		s = format("%c", std::string("foo"));
		fail("bad argument - must throw");
	}
	catch (BadCastException&)
	{
	}
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:19,代码来源:FormatTest.cpp


注:本文中的Poco::format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。