本文整理汇总了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()));
}
}
示例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");
}
示例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));
}
}
}
}
示例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;
}
示例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");
}
示例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]");
}
示例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;
}
示例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;
}
}
}
示例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;
}
}
}
示例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");
}
示例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%'");
}
示例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);
}
示例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());
}
}
示例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 ");
}
示例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&)
{
}
}