Boost event processing boost. Signals

Source: Internet
Author: User

20130811 wcdj

When many developers hear the term 'event process', they will think of the GUI: click a button and the associated functions will be executed. Click itself is an event, and the function is the corresponding event processor. Of course, this mode is not limited to Gui. In general, any object can call special functions based on specific events. This chapter introduces
The boost. Signals Library provides a simple method to apply this mode in C ++.

Strictly speaking, boost. function libraries can also be used for event processing (http://blog.csdn.net/delphiwcdj/article/details/9564659 ). However, a major difference between boost. Function and boost. signals is that boost. signals can associate more than one event processor to a single event.
Therefore, boost. signals can better support event-driven development. When event processing is required, it should be the first choice.

Boost_000054_0/Boost/signals. HPP header file description:

#ifndef BOOST_SIGNAL_HPP#define BOOST_SIGNAL_HPP#ifndef BOOST_SIGNALS_NO_DEPRECATION_WARNING# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__)#  pragma message ("Warning: Boost.Signals is no longer being maintained and is now deprecated. Please switch to Boost.Signals2. To disable this warning message, define BOOST_SIGNALS_NO_DEPRECATION_WARNING.")# elif defined(__GNUC__) || defined(__HP_aCC) || defined(__SUNPRO_CC) || defined(__IBMCPP__)#  warning                  "Boost.Signals is no longer being maintained and is now deprecated. Please switch to Boost.Signals2. To disable this warning message, define BOOST_SIGNALS_NO_DEPRECATION_WARNING."# endif#endif

Test code:

#include <boost/signal.hpp> //#include <boost/signals2.hpp> #include <iostream> void func() { std::cout << "Hello, world!" << std::endl; } int main() { boost::signal<void ()> s; s.connect(func); s(); } 

When x86_64 uses boost_000054_0 to compile the link, an error is returned:

mba:signals gerryyang$ g++ singals.cpp -o singalsIn file included from singals.cpp:1:/usr/local/include/boost/signal.hpp:17:4: warning: #warning "Boost.Signals is no longer being maintained and is now deprecated. Please switch to Boost.Signals2. To disable this warning message, define BOOST_SIGNALS_NO_DEPRECATION_WARNING."Undefined symbols for architecture x86_64:  "boost::signals::connection::~connection()", referenced from:      _main in ccrwHjrA.o      boost::signals::detail::slot_base::data_t::~data_t()in ccrwHjrA.o  "boost::signals::detail::signal_base::signal_base(boost::function2<bool, boost::signals::detail::stored_group, boost::signals::detail::stored_group> const&, boost::any const&)", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::signal0(boost::last_value<void> const&, std::less<int> const&)in ccrwHjrA.o  "boost::signals::detail::signal_base::~signal_base()", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::signal0(boost::last_value<void> const&, std::less<int> const&)in ccrwHjrA.o      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::~signal0()in ccrwHjrA.o  "boost::signals::detail::named_slot_map::end()", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::operator()()in ccrwHjrA.o  "boost::signals::detail::named_slot_map::begin()", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::operator()()in ccrwHjrA.o  "boost::signals::detail::signal_base_impl::connect_slot(boost::any const&, boost::signals::detail::stored_group const&, boost::shared_ptr<boost::signals::detail::slot_base::data_t>, boost::signals::connect_position)", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::connect(boost::slot<boost::function<void ()()> > const&, boost::signals::connect_position)in ccrwHjrA.o  "boost::signals::detail::call_notification::call_notification(boost::shared_ptr<boost::signals::detail::signal_base_impl> const&)", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::operator()()in ccrwHjrA.o  "boost::signals::detail::call_notification::~call_notification()", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::operator()()in ccrwHjrA.o  "boost::signals::detail::slot_base::create_connection()", referenced from:      boost::slot<boost::function<void ()()> >::slot<void ()()>(void ( const&)())in ccrwHjrA.o  "boost::signals::trackable::~trackable()", referenced from:      boost::signal0<void, boost::last_value<void>, int, std::less<int>, boost::function<void ()()> >::~signal0()in ccrwHjrA.old: symbol(s) not found for architecture x86_64collect2: ld returned 1 exit status

Refer:

Chapter 4 event handling in http://zh.highscore.de/cpp/boost/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.