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


C++ EventListener类代码示例

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


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

示例1: dispatchEvent

bool EventDispatcher::dispatchEvent( Event& event )
{
	event.setSender( this );

	EventDispatcher::EventListeners::iterator iter = listeners_.begin();
	EventDispatcher::EventListeners::iterator endIter = listeners_.end();
	EventListener* el;
	// std::cout << "event dispatched: " << event.getType() << std::endl;
	while (iter != endIter)
	{
		el = (*iter);
		// std::cout << "listener of " << el->getType() << std::endl;
		// std::cout << "comparsion result: " << (el->getType().compare(event.getType()) == 1) << std::endl;
		if (el->getType().compare(event.getType()) == 0)
		{
			if (!el->exec(event))
			{
				return false;
			}
		}
		
		++iter;
	}

	return true;
}
开发者ID:OggYiu,项目名称:rag-engine,代码行数:26,代码来源:EventDispatcher.cpp

示例2: assert

void EventManager::writeCallback(int fd, short ev, void* arg)
{
	assert(ev == EV_WRITE && instance()->writes.count(fd));

	EventListener* eh = static_cast<EventListener*>(arg);
	eh->onWrite(fd);
}
开发者ID:BackupTheBerlios,项目名称:ddc,代码行数:7,代码来源:EventManager.cpp

示例3: CPPUNIT_ASSERT

void EventListenerFixture::Should_Return_Correct_EventHandler_Function( )
{
	EventListener< Mock_EventSubject >* fullEventListener = static_cast< EventListener< Mock_EventSubject >* >( _eventListener );

	CPPUNIT_ASSERT( &Mock_EventSubject::EventHandler == fullEventListener->GetHandlerFunctor( ) );
	CPPUNIT_ASSERT( &Mock_EventSubject::FalseEventHandler != fullEventListener->GetHandlerFunctor( ) );
}
开发者ID:venkatarajasekhar,项目名称:viper,代码行数:7,代码来源:EventListenerFixture.cpp

示例4: lock

void KEventObject::FireEvent(const char* event, const ValueList& args)
{
    // Make a copy of the listeners map here, because firing the event might
    // take a while and we don't want to block other threads that just need
    // too add event listeners.
    EventListenerList listenersCopy;
    {
        Poco::FastMutex::ScopedLock lock(this->listenersMutex);
        listenersCopy = listeners;
    }

    KObjectRef thisObject(this, true);
    EventListenerList::iterator li = listenersCopy.begin();
    while (li != listenersCopy.end())
    {
        EventListener* listener = *li++;
        if (listener->Handles(event))
        {
            try
            {
                if (!listener->Dispatch(thisObject, args, true))
                {
                    // Stop event dispatch if callback tells us
                    break;
                }
            }
            catch (ValueException& e)
            {
                this->ReportDispatchError(e.ToString());
                break;
            }
        }
    }
}
开发者ID:ErNavi,项目名称:TideSDK,代码行数:34,代码来源:event_object.cpp

示例5: perror

static void *serial_thread_handler(void *arg)
{
    Connector *thiz = (Connector *)arg;
    EventListener listener = thiz->open_listener;
    PrivInfo *priv = (PrivInfo *)thiz->priv;

    if ((priv->fd = open(priv->serial_port, O_RDWR | O_NOCTTY)) == -1)
    {
        if (listener.cb_func != NULL)
        {
            listener.cb_func(strerror(errno), listener.ctx);
        }
        perror("open serial fail");
    }

    serial_set_raw_mode(priv->fd);
    serial_set_speed(priv->fd, priv->baud_rate);
    serial_set_parity(priv->fd, DATA_BITS, PARITY_TYPE, STOP_BITS);

    priv->status = 1;

    if (listener.cb_func != NULL)
    {
        listener.cb_func(NULL, listener.ctx);
    }

    pthread_exit(NULL);
}
开发者ID:Collyboy,项目名称:joycar,代码行数:28,代码来源:connector_serial.c

示例6: notify

void Event::notify(){
	for (std::set<EventListener*>::iterator it=listeners.begin(); it!=listeners.end();){
		EventListener* e = *it;
		it++; // Increment before calling handler in case the handler removes this listener,
		      // which would invalidate the iterator.
		e->handler();
	}
}
开发者ID:nonolith,项目名称:connect,代码行数:8,代码来源:event.cpp

示例7:

EventReciever::~EventReciever()
{
	// unplug any EventListeners that points to this object
	for(EventListener* l = _listeners.first(); _listeners.canMove(); l = _listeners.next()){
		if (l != 0)
		  l->_unplug();
	}
}
开发者ID:mumme74,项目名称:mgui,代码行数:8,代码来源:event.cpp

示例8:

  void	EventListener::Function::operator()(EventListener const& eventListener)
  {
    if (eventListener.getType() == this->_type)
      {
	eventListener.execute(this->_widget, this->_event);
	++this->_executed;
      }
  }
开发者ID:Frozenhorns,项目名称:project,代码行数:8,代码来源:EventListener.cpp

示例9: notifyObservers

void InputManager::notifyObservers(QuadrantID q, EventType e)
{
    // iterate through and call onEvent for each listener
    std::list<EventListener *>::iterator it;
    for (it = observers.begin(); it != observers.end(); ++it) {
        EventListener *observer = (*it);
        observer->onEvent(q, e);
    }
}
开发者ID:garrisoh,项目名称:Simon-ConCATination,代码行数:9,代码来源:inputmanager.cpp

示例10: getEventListeners

EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType)
{
    const EventListenerVector& entry = getEventListeners(eventType);
    for (size_t i = 0; i < entry.size(); ++i) {
        EventListener* listener = entry[i].listener.get();
        if (listener->isAttribute() && listener->belongsToTheCurrentWorld())
            return listener;
    }
    return 0;
}
开发者ID:ericwilligers,项目名称:blink,代码行数:10,代码来源:EventTarget.cpp

示例11: onended

void AudioScheduledSourceNode::notifyEnded()
{
    EventListener* listener = onended();
    if (!listener)
        return;

    RefPtr<Event> event = Event::create(eventNames().endedEvent, FALSE, FALSE);
    event->setTarget(this);
    listener->handleEvent(context()->scriptExecutionContext(), event.get());
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:10,代码来源:AudioScheduledSourceNode.cpp

示例12: getEventListeners

EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType)
{
    const EventListenerVector& entry = getEventListeners(eventType);
    for (const auto& eventListener : entry) {
        EventListener* listener = eventListener.listener.get();
        if (listener->isAttribute() && listener->belongsToTheCurrentWorld())
            return listener;
    }
    return 0;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:10,代码来源:EventTarget.cpp

示例13: lock

void EventHandler::_broadcast(AmigoEvent &e)
{
    std::lock_guard<std::mutex> lock(_mutex);
	std::vector<EventListener*>::iterator it;
	for(it=_listeners.begin(); it!=_listeners.end(); it++)
	{
		EventListener *l = *it;
		l->onEvent(e);
	}
}
开发者ID:gfbipnet,项目名称:amigoclient,代码行数:10,代码来源:EventHandler.cpp

示例14: removeListener

// removes any listeners that points to the same reciever and reciever callback method
// the Listener object created here doesn't have to be the same object that was added to addListener
// deleteObj is used if the EventListener whas created with new 
void EventSender::removeListener(EventListener &listener, bool deleteObj /*= false*/) {
	listener._sender = this;
	int32_t idx =  _listeners.indexOf(&listener);
	if (idx > -1){
		EventListener* l = _listeners[idx];
		l->_unplug();
		if (deleteObj)
			delete l;
	}
}
开发者ID:mumme74,项目名称:mgui,代码行数:13,代码来源:event.cpp

示例15: main

int main()
{
    //Test case 1 : Shouldn't throw
    {
        try
        {
            EventListener listener;
            EventConsumer consumer(listener);

            listener.on_connect().set_function([](Connection&){});
            consumer.on_disconnect().set_function([](Connection&){});
            consumer.on_server_disconnect().set_function([](TCPServer&){});
            consumer.on_event().set_function([](Connection&, const Event&){});

            consumer.bind("hellomsg").set_function([](Connection&, const Event&){});

            listener.run();
            listener.join();
        }
        catch(Exception& e)
        {
            ASSERT(false, "Test case 1 failed: \n" << e.what());
        }
    }

#define TEST_THROW(n, slot, lambda)                             \
    {                                                           \
        try                                                     \
        {                                                       \
            EventListener listener;                             \
            EventConsumer consumer1(listener);                  \
            EventConsumer consumer2(listener);                  \
                                                                \
            consumer1.slot.set_function(lambda);                \
            consumer2.slot.set_function(lambda);                \
                                                                \
            listener.run();                                     \
            listener.join();                                    \
                                                                \
            ASSERT(false, "Test case " n " failed: "            \
                   "collision not detected.");                  \
        }                                                       \
        catch(Exception& e)                                     \
        {}                                                      \
    }

    //Test cases 3-6 : Should throw
    TEST_THROW("3", on_disconnect(), [](Connection&){});
    TEST_THROW("4", on_server_disconnect(), [](TCPServer&){});
    TEST_THROW("5", on_event(), [](Connection&, const Event&){});
    TEST_THROW("6", bind("hellomsg"), [](Connection&, const Event&){});

    return EXIT_SUCCESS;
}
开发者ID:Zenol,项目名称:sednl,代码行数:54,代码来源:eventcollision.cpp


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