本文整理汇总了C++中Poco::delegate方法的典型用法代码示例。如果您正苦于以下问题:C++ Poco::delegate方法的具体用法?C++ Poco::delegate怎么用?C++ Poco::delegate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poco
的用法示例。
在下文中一共展示了Poco::delegate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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);
}
示例3: delegate
EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
_socket(socket),
_reactor(reactor),
_fifoIn(BUFFER_SIZE, true),
_fifoOut(BUFFER_SIZE, true)
{
Application& app = Application::instance();
app.logger().information("Connection from " + socket.peerAddress().toString());
_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onSocketReadable));
_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onSocketShutdown));
_fifoOut.readable += delegate(this, &EchoServiceHandler::onFIFOOutReadable);
_fifoIn.writable += delegate(this, &EchoServiceHandler::onFIFOInWritable);
}
示例4: testNotify
void FIFOBufferStreamTest::testNotify()
{
FIFOBuffer fb(18);
FIFOBufferStream iostr(fb);
assert (iostr.rdbuf()->fifoBuffer().isEmpty());
assert (0 == _readableToNot);
assert (0 == _notToReadable);
assert (0 == _writableToNot);
assert (0 == _notToWritable);
iostr.readable += delegate(this, &FIFOBufferStreamTest::onReadable);
iostr.writable += delegate(this, &FIFOBufferStreamTest::onWritable);
iostr << "This is a test " << 42 << std::ends << std::flush;
assert (iostr.rdbuf()->fifoBuffer().isFull());
assert (0 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (0 == _notToWritable);
char input[64];
iostr >> input;
assert (std::string("This") == input);
assert (iostr.rdbuf()->fifoBuffer().isEmpty());
assert (1 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (1 == _notToWritable);
iostr >> input;
assert (std::string("is") == input);
assert (1 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (1 == _notToWritable);
iostr >> input;
assert (std::string("a") == input);
assert (1 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (1 == _notToWritable);
iostr >> input;
assert (std::string("test") == input);
assert (1 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (1 == _notToWritable);
iostr >> input;
assert (std::string("42") == input);
assert (1 == _readableToNot);
assert (1 == _notToReadable);
assert (1 == _writableToNot);
assert (1 == _notToWritable);
iostr.clear();
assert (iostr.good());
iostr << "This is a test " << 42 << std::ends << std::flush;
assert (iostr.rdbuf()->fifoBuffer().isFull());
assert (1 == _readableToNot);
assert (2 == _notToReadable);
assert (2 == _writableToNot);
assert (1 == _notToWritable);
iostr.readable -= delegate(this, &FIFOBufferStreamTest::onReadable);
iostr.writable -= delegate(this, &FIFOBufferStreamTest::onWritable);
}
示例5: testFIFOBufferChar
void CoreTest::testFIFOBufferChar()
{
typedef FIFOBuffer::Type T;
FIFOBuffer f(20, true);
assert (f.isEmpty());
assert (!f.isFull());
Buffer<T> b(10);
std::vector<T> v;
f.readable += delegate(this, &CoreTest::onReadable);
f.writable += delegate(this, &CoreTest::onWritable);
for (T c = '0'; c < '0' + 10; ++c)
v.push_back(c);
std::memcpy(b.begin(), &v[0], sizeof(T) * v.size());
assert(0 == _notToReadable);
assert(0 == _readableToNot);
f.write(b);
assert(1 == _notToReadable);
assert(0 == _readableToNot);
assert (20 == f.size());
assert (10 == f.used());
assert (!f.isEmpty());
assert ('0' == f[0]);
assert ('1' == f[1]);
assert ('2' == f[2]);
assert ('3' == f[3]);
assert ('4' == f[4]);
assert ('5' == f[5]);
assert ('6' == f[6]);
assert ('7' == f[7]);
assert ('8' == f[8]);
assert ('9' == f[9]);
b.resize(5);
f.read(b, b.size());
assert (20 == f.size());
assert (5 == f.used());
assert (!f.isEmpty());
assert ('5' == f[0]);
assert ('6' == f[1]);
assert ('7' == f[2]);
assert ('8' == f[3]);
assert ('9' == f[4]);
try { T i = f[10]; fail ("must fail"); }
catch (InvalidAccessException&) { }
v.clear();
for (T c = 'a'; c < 'a' + 10; ++c)
v.push_back(c);
b.resize(10);
std::memcpy(b.begin(), &v[0], sizeof(T) * v.size());
f.write(b);
assert (20 == f.size());
assert (15 == f.used());
assert (!f.isEmpty());
assert ('5' == f[0]);
assert ('6' == f[1]);
assert ('7' == f[2]);
assert ('8' == f[3]);
assert ('9' == f[4]);
assert ('a' == f[5]);
assert ('b' == f[6]);
assert ('c' == f[7]);
assert ('d' == f[8]);
assert ('e' == f[9]);
assert ('f' == f[10]);
assert ('g' == f[11]);
assert ('h' == f[12]);
assert ('i' == f[13]);
assert ('j' == f[14]);
try { T i = f[15]; fail ("must fail"); }
catch (InvalidAccessException&) { }
f.read(b, 10);
assert (20 == f.size());
assert (5 == f.used());
assert (!f.isEmpty());
assert ('f' == f[0]);
assert ('g' == f[1]);
assert ('h' == f[2]);
assert ('i' == f[3]);
assert ('j' == f[4]);
try { T i = f[5]; fail ("must fail"); }
catch (InvalidAccessException&) { }
assert(1 == _notToReadable);
assert(0 == _readableToNot);
assert(0 == _notToWritable);
assert(0 == _writableToNot);
f.read(b, 6);
assert(1 == _notToReadable);
assert(1 == _readableToNot);
assert(0 == _notToWritable);
assert(0 == _writableToNot);
//.........这里部分代码省略.........