本文整理汇总了C++中Poco类的典型用法代码示例。如果您正苦于以下问题:C++ Poco类的具体用法?C++ Poco怎么用?C++ Poco使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Poco类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: format
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");
}
示例2: compile
void compile(const std::string& path)
{
Page page;
FileInputStream srcStream(path);
PageReader pageReader(page, path);
pageReader.emitLineDirectives(_emitLineDirectives);
pageReader.parse(srcStream);
Path p(path);
config().setString("inputFileName", p.getFileName());
config().setString("inputFilePath", p.toString());
DateTime now;
config().setString("dateTime", DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));
std::string clazz;
if (page.has("page.class"))
{
clazz = page.get("page.class");
p.setBaseName(clazz);
}
else
{
clazz = p.getBaseName() + "Handler";
clazz[0] = Poco::Ascii::toUpper(clazz[0]);
}
std::auto_ptr<CodeWriter> pCodeWriter(createCodeWriter(page, clazz));
if (!_outputDir.empty())
{
p = Path(_outputDir, p.getBaseName());
}
p.setExtension("cpp");
std::string implPath = p.toString();
std::string implFileName = p.getFileName();
if (!_headerOutputDir.empty())
{
p = Path(_headerOutputDir, p.getBaseName());
}
p.setExtension("h");
std::string headerPath = p.toString();
std::string headerFileName = p.getFileName();
config().setString("outputFileName", implFileName);
config().setString("outputFilePath", implPath);
FileOutputStream implStream(implPath);
OutputLineEndingConverter implLEC(implStream);
writeFileHeader(implLEC);
pCodeWriter->writeImpl(implLEC, _headerPrefix + headerFileName);
config().setString("outputFileName", headerFileName);
config().setString("outputFilePath", headerPath);
FileOutputStream headerStream(headerPath);
OutputLineEndingConverter headerLEC(headerStream);
writeFileHeader(headerLEC);
pCodeWriter->writeHeader(headerLEC, headerFileName);
}
示例3: poco_information
/*!
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()));
}
}
示例4: m_version
XplDevice::XplDevice
(
string const& _vendorId,
string const& _deviceId,
string const& _version,
bool const _bFilterMsgs,
XplComms* _pComms
) :
m_version ( _version ),
m_bFilterMsgs ( _bFilterMsgs ),
m_pComms ( _pComms ),
m_bConfigRequired ( true ),
m_bInitialised ( false ),
m_heartbeatInterval ( 5 ),
m_nextHeartbeat ( 0 ),
m_bExitThread ( false ),
m_bWaitingForHub ( true ),
m_rapidHeartbeatCounter ( c_rapidHeartbeatTimeout/c_rapidHeartbeatFastInterval ),
devLog ( Logger::get ( "xplsdk.device" ) )
{
devLog.setLevel ("trace");
// Logger::setLevel("xplsdk.device", Message::PRIO_TRACE );
assert ( devLog.trace() );
m_vendorId = toLower ( _vendorId );
m_deviceId = toLower ( _deviceId );
m_instanceId = "default";
SetCompleteId();
m_hRxInterrupt = new Poco::Event ( false );
}
示例5: 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));
}
}
}
}
示例6: testRotateAtTimeMinLocal
void FileChannelTest::testRotateAtTimeMinLocal()
{
std::string name = filename();
try
{
AutoPtr<FileChannel> pChannel = new FileChannel(name);
pChannel->setProperty(FileChannel::PROP_TIMES, "local");
pChannel->setProperty(FileChannel::PROP_ROTATION, rotation<LocalDateTime>(MIN));
pChannel->open();
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
int min = DateTime().minute();
while (DateTime().minute() == min)
{
pChannel->log(msg);
Thread::sleep(1000);
}
pChannel->log(msg);
File f(name + ".0");
assert (f.exists());
}
catch (...)
{
remove(name);
throw;
}
remove(name);
}
示例7: testCat
void StringTest::testCat()
{
std::string s1("one");
std::string s2("two");
std::string s3("three");
std::string s4("four");
std::string s5("five");
std::string s6("six");
assert (cat(s1, s2) == "onetwo");
assert (cat(s1, s2, s3) == "onetwothree");
assert (cat(s1, s2, s3, s4) == "onetwothreefour");
assert (cat(s1, s2, s3, s4, s5) == "onetwothreefourfive");
assert (cat(s1, s2, s3, s4, s5, s6) == "onetwothreefourfivesix");
std::vector<std::string> vec;
assert (cat(std::string(), vec.begin(), vec.end()) == "");
assert (cat(std::string(","), vec.begin(), vec.end()) == "");
vec.push_back(s1);
assert (cat(std::string(","), vec.begin(), vec.end()) == "one");
vec.push_back(s2);
assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two");
vec.push_back(s3);
assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two,three");
}
示例8: text
void TextIteratorTest::testLatin1()
{
Latin1Encoding encoding;
std::string text("Latin1");
TextIterator it(text, encoding);
TextIterator end(text);
assert (it != end);
assert (*it++ == 'L');
assert (it != end);
assert (*it++ == 'a');
assert (it != end);
assert (*it++ == 't');
assert (it != end);
assert (*it++ == 'i');
assert (it != end);
assert (*it++ == 'n');
assert (it != end);
assert (*it++ == '1');
assert (it == end);
std::string empty;
it = TextIterator(empty, encoding);
end = TextIterator(empty);
assert (it == end);
}
示例9: testArithmetics
void DateTimeTest::testArithmetics()
{
DateTime dt1(2005, 1, 1, 0, 15, 30);
DateTime dt2(2005, 1, 2, 0, 15, 30);
Timespan s = dt2 - dt1;
assert (s.days() == 1);
DateTime dt3 = dt1 + s;
assert (dt3 == dt2);
dt3 -= s;
assert (dt3 == dt1);
dt1 += s;
assert (dt1 == dt2);
static const struct
{
int lineNum; // source line number
int year1; // operand/result date1 year
int month1; // operand/result date1 month
unsigned int day1; // operand/result date1 day
int numDays; // operand/result 'int' number of days
int year2; // operand/result date2 year
int month2; // operand/result date2 month
unsigned int day2; // operand/result date2 day
} data[] =
{
// - - - -first- - - - - - - second - - -
//line no. year month day numDays year month day
//------- ----- ----- ----- ------- ----- ----- -----
{ __LINE__, 1, 1, 1, 1, 1, 1, 2 },
{ __LINE__, 10, 2, 28, 1, 10, 3, 1 },
{ __LINE__, 100, 3, 31, 2, 100, 4, 2 },
{ __LINE__, 1000, 4, 30, 4, 1000, 5, 4 },
{ __LINE__, 1000, 6, 1, -31, 1000, 5, 1 },
{ __LINE__, 1001, 1, 1, -365, 1000, 1, 1 },
{ __LINE__, 1100, 5, 31, 30, 1100, 6, 30 },
{ __LINE__, 1200, 6, 30, 32, 1200, 8, 1 },
{ __LINE__, 1996, 2, 28, 367, 1997, 3, 1 },
{ __LINE__, 1997, 2, 28, 366, 1998, 3, 1 },
{ __LINE__, 1998, 2, 28, 365, 1999, 2, 28 },
{ __LINE__, 1999, 2, 28, 364, 2000, 2, 27 },
{ __LINE__, 1999, 2, 28, 1096, 2002, 2, 28 },
{ __LINE__, 2002, 2, 28, -1096, 1999, 2, 28 },
};
const int num_data = sizeof data / sizeof *data;
for (int di = 0; di < num_data; ++di)
{
const int line = data[di].lineNum;
const int num_days = data[di].numDays;
DateTime x = DateTime(data[di].year1, data[di].month1, data[di].day1);
const DateTime& X = x;
x += Timespan(num_days, 0, 0, 0, 0);
loop_1_assert(line, data[di].year2 == X.year());
loop_1_assert(line, data[di].month2 == X.month());
loop_1_assert(line, data[di].day2 == X.day());
}
}
示例10: testTranslate
void StringTest::testTranslate()
{
std::string s = "aabbccdd";
assert (translate(s, "abc", "ABC") == "AABBCCdd");
assert (translate(s, "abc", "AB") == "AABBdd");
assert (translate(s, "abc", "") == "dd");
assert (translate(s, "cba", "CB") == "BBCCdd");
assert (translate(s, "", "CB") == "aabbccdd");
}
示例11: 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;
}
示例12: delegate
DBEventHandler(RequestHandlerFactory& factory):
_session("SQLite", "sample.db"),
_factory(factory),
_notifier(_session)
/// Constructor; opens/initializes the database and associates
/// notification events with their respective handlers.
{
initDB();
_notifier.insert += delegate(this, &DBEventHandler::onInsert);
_notifier.update += delegate(this, &DBEventHandler::onUpdate);
}
示例13: 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");
}
示例14: testFIFOBuffer
void SocketTest::testFIFOBuffer()
{
Buffer<char> b(5);
b[0] = 'h';
b[1] = 'e';
b[2] = 'l';
b[3] = 'l';
b[4] = 'o';
FIFOBuffer f(5, true);
f.readable += delegate(this, &SocketTest::onReadable);
f.writable += delegate(this, &SocketTest::onWritable);
assert(0 == _notToReadable);
assert(0 == _readableToNot);
assert(0 == _notToWritable);
assert(0 == _writableToNot);
f.write(b);
assert(1 == _notToReadable);
assert(0 == _readableToNot);
assert(0 == _notToWritable);
assert(1 == _writableToNot);
EchoServer echoServer;
StreamSocket ss;
ss.connect(SocketAddress("localhost", echoServer.port()));
int n = ss.sendBytes(f);
assert (n == 5);
assert(1 == _notToReadable);
assert(1 == _readableToNot);
assert(1 == _notToWritable);
assert(1 == _writableToNot);
assert (f.isEmpty());
n = ss.receiveBytes(f);
assert (n == 5);
assert(2 == _notToReadable);
assert(1 == _readableToNot);
assert(1 == _notToWritable);
assert(2 == _writableToNot);
assert (f[0] == 'h');
assert (f[1] == 'e');
assert (f[2] == 'l');
assert (f[3] == 'l');
assert (f[4] == 'o');
f.readable -= delegate(this, &SocketTest::onReadable);
f.writable -= delegate(this, &SocketTest::onWritable);
ss.close();
}
示例15: checkODBCSetup
void ODBCAccessTest::checkODBCSetup()
{
static bool beenHere = false;
if (!beenHere)
{
beenHere = true;
bool driverFound = false;
bool dsnFound = false;
Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv)
{
if (((itDrv->first).find("Microsoft Access Driver") != std::string::npos))
{
std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl;
driverFound = true;
break;
}
}
if (!driverFound)
{
std::cout << "Driver NOT found, will throw." << std::endl;
throw NotFoundException("Microsoft Access ODBC driver.");
}
Utility::DSNMap::iterator itDSN = _dataSources.begin();
for (; itDSN != _dataSources.end(); ++itDSN)
{
if (((itDSN->first).find(_dsn) != std::string::npos) &&
((itDSN->second).find("Microsoft Access Driver") != std::string::npos))
{
std::cout << "DSN found: " << itDSN->first
<< " (" << itDSN->second << ')' << std::endl;
dsnFound = true;
break;
}
}
if (!dsnFound)
{
std::cout << "Access DSN NOT found, tests will fail." << std::endl;
return;
}
}
if (!_pSession)
format(_dbConnString, "DSN=%s;Uid=Admin;Pwd=;", _dsn);
}