POCO C++ Libraries 简介

Introduction

 

The POCO C++ Libraries are a collection of open source C++ class libraries that simplify and accelerate the development of network-centric, portable applications in C++. The libraries integrate perfectly with the C++ Standard Library and fill many of the functional gaps left open by it. Their modular and efficient design and implementation makes the POCO C++ Libraries extremely well suited for embedded development, an area where the C++ programming language is becoming increasingly popular, due to its suitability for both low-level (device I/O, interrupt handlers, etc.) and high-level object-oriented development. Of course, POCO is also ready for enterprise-level challenges.

POCO consists of four core libraries, and a number of add-on libraries. The core libraries are Foundation, XML, Util and Net. Two of the add-on libraries are NetSSL, providing SSL support for the network classes in the Net library, and Data, a library for uniformly accessing different SQL databases. POCO aims to be for network-centric, cross-platform C++ software development what Apple's Cocoa is for Mac development, or Ruby on Rails is for Web development — a powerful, yet easy and fun to use platform to build your applications upon. POCO is built strictly using standard ANSI/ISO C++, including the standard library. The contributors attempt to find a good balance between using advanced C++ features and keeping the classes comprehensible and the code clean, consistent and easy to maintain.

The Foundation Library

 

The Foundation library makes up the heart of POCO. It contains the underlying platform abstraction layer, as well as frequently used utility classes and functions. The Foundation library contains types for fixed-size integers, functions for converting integers between byte orders, an Poco::Any class (based on boost::Any), utilities for error handling and debugging, including various exception classes and support for assertions. Also available are a number of classes for memory management, including reference counting based smart pointers, as well as classes for buffer management and memory pools. For string handling, POCO contains a number of functions that among other things, trim strings, perform case insensitive comparisons and case conversions. Basic support for Unicode text is also available in the form of classes that convert text between different character encodings, including UTF-8 and UTF-16. Support for formatting and parsing numbers is there, including a typesafe variant of sprintf. Regular expressions based on the well-known PCRE library (http://www.pcre.org) are provided as well.

POCO gives you classes for handling dates and times in various variants. For accessing the file system, POCO has Poco::File and Poco::Path classes, as well as a Poco::DirectoryIterator class. In many applications, some parts of the application need to tell other parts that something has happened. In POCO, Poco::NotificationCenter, Poco::NotificationQueue and events (similar to C# events) make this easy. The following example shows how POCO events can be used. In this example, class Source has a public event named theEvent, having an argument of type int. Subscribers can subscribe by calling operator += and unsubscribe by calling operator -=, passing a pointer to an object and a pointer to a member function. The event can be fired by calling operator (), as its done in Source::fireEvent().

  

The stream classes available in POCO have already been mentioned. These are augmented by Poco::BinaryReader and Poco::BinaryWriter for writing binary data to streams, automatically and transparently handling byte order issues.

In complex multithreaded applications, the only way to find problems or bugs is by writing extensive logging information. POCO provides a powerful and extensible logging framework that supports filtering, routing to different channels, and formatting of log messages. Log messages can be written to the console, a file, the Windows Event Log, the Unix syslog daemon, or to the network. If the channels provided by POCO are not sufficient, it is easy to extend the logging framework with new classes.

For loading (and unloading) shared libraries at runtime, POCO has a low-level Poco::SharedLibrary class. Based on it is the Poco::ClassLoader class template and supporting framework, allowing dynamic loading and unloading of C++ classes at runtime, similar to what's available to Java and .NET developers. The class loader framework also makes it a breeze to implement plug-in support for applications in a platform-independent way.

Finally, POCO Foundation contains multithreading abstractions at different levels. Starting with a Poco::Thread class and the usual synchronization primitives (Poco::Mutex, Poco::ScopedLock, Poco::Event, Poco::Semaphore, Poco::RWLock), a Poco::ThreadPool class and support for thread-local storage, also high level abstractions like active objects are available. Simply speaking, an active object is an object that has methods executing in their own thread. This makes asynchronous member function calls possible — call a member function, while the function executes, do a bunch of other things, and, eventually, obtain the function's return value. The following example shows how this is done in POCO. The ActiveAdder class in defines an active method add(), implemented by the addImpl() member function. Invoking the active method in main() yields an Poco::ActiveResult (also known as a future), that eventually receives the function's return value.

  

 

The XML Library

 

The POCO XML library provides support for reading, processing and writing XML. Following one's of POCO's guiding principles — don't try to reinvent things that already work — POCO's XML library supports the industry-standard SAX (version 2) and DOM interfaces, familiar to many developers with XML experience. SAX, the Simple API for XML (http://www.saxproject.org), defines an event-based interface for reading XML. A SAX-based XML parser reads through the XML document and notifies the application whenever it encounters an element, character data, or other XML artifact. A SAX parser does not need to load the complete XML document into memory, so it can be used to parse huge XML files efficiently. In contrast, DOM (Document Object Model, http://www.w3.org/DOM/) gives the application complete access to an XML document, using a tree-style object hierarchy. For this to work, the DOM parser provided by POCO has to load the entire document into memory. To reduce the memory footprint of the DOM document, the POCO DOM implementation uses string pooling, storing frequently occuring strings such as element and attribute names only once. The XML library is based on the Expat open source XML parser library (http://www.libexpat.org). Built on top of Expat are the SAX interfaces, and built on top of the SAX interfaces is the DOM implementation. For strings, the XML library uses std::string, with characters encoded in UTF-8. This makes interfacing the XML library to other parts of the application easy. Support for XPath and XSLT will be available in a future release.

 

 

The Util Library

 

The Util library has a somewhat misleading name, as it basically contains a framework for creating command-line and server applications. Included is support for handling command line arguments (validation, binding to configuration properties, etc.) and managing configuration information. Different configuration file formats are supported — Windows-style INI files, Java-style property files, XML files and the Windows registry.

For server applications, the framework provides transparent support for Windows services and Unix daemons. Every server application can be registered and run as a Windows service, with no extra code required. Of course, all server applications can still be executed from the command line, which makes testing and debugging easier.

 

 

The Net Library

 

POCO's Net library makes it easy to write network-based applications. No matter whether your application simply needs to send data over a plain TCP socket, or whether your application needs a full-fledged built-in HTTP server, you will find something useful in the Net library.

At the lowest level, the Net library contains socket classes, supporting TCP stream and server sockets, UDP sockets, multicast sockets, ICMP and raw sockets. If your application needs secure sockets, these are available in the NetSSL library, implemented using OpenSSL (http://www.openssl.org). Based on the socket classes are two frameworks for building TCP servers — one for multithreaded servers (one thread per connection, taken from a thread pool), one for servers based on the Acceptor-Reactor pattern. The multithreaded Poco::Net::TCPServer class and its supporting framework are also the foundation for POCO's HTTP server implementation (Poco::Net::HTTPServer). On the client side, the Net library provides classes for talking to HTTP servers, for sending and receiving files using the FTP protocol, for sending mail messages (including attachments) using SMTP and for receiving mail from a POP3 server.

 

 

Putting It All Together

 

The following example shows the implementation of a simple HTTP server using the POCO libraries. The server returns a HTML document showing the current date and time. The application framework is used to build a server application that can run as a Windows service, or Unix daemon process. Of course, the same executable can also directly be started from the shell. For use with the HTTP server framework, a TimeRequestHandler class is defined that servers incoming requests by returning a HTML document containing the current date and time. Also, for each incoming request, a message is logged using the logging framework. Together with the TimeRequestHandler class, a corresponding factory class, TimeRequestHandlerFactory is needed; an instance of the factory is passed to the HTTP server object. The HTTPTimeServer application class defines a command line argument help by overriding the defineOptions() member function of Poco::Util::ServerApplication. It also reads in the default application configuration file (in initialize()) and obtains the value of some configuration properties in main(), before starting the HTTP server.

  

下载

http://pocoproject.org/download/

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMake的指令"target_link_libraries"用于将一个或多个目标与一个或多个库文件进行链接。通过这个指令,我们可以将目标和所需的库文件关联起来,以便在编译和链接过程中正确地引用库函数。 具体用法如下: target_link_libraries(target_name library_name1 library_name2 ...) 其中,target_name是要与库文件关联的目标的名称,而library_name1、library_name2等是要链接的库文件的名称。 例如,如果我们想要将名为sample的目标与curl、glib和m等库文件进行链接,可以使用以下指令: target_link_libraries(sample PUBLIC CURL::curl glib m) 在使用target_link_libraries指令时,我们可以通过定义Third_part_lib参数来指定每个第三方库的名称,具体的库名称可以在库的说明文档中找到。需要注意的是,在链接库文件之前,我们需要确保这些库文件已经正确地安装并可以被找到。 总结起来,CMake的target_link_libraries指令用于将目标与库文件进行链接,以便在编译和链接过程中使用库函数。通过指定目标名称和库文件名称,我们可以将它们关联起来,实现正确的链接。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [C++-Cmake指令:target_link_libraries](https://blog.csdn.net/u013250861/article/details/127939663)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值