Poco入门介绍1.Poco库简介官方网站: /index.htmlPOCO C++库是开源的用于简化和加速C++开发面向网络、可移植应用程序的C++库集,POCO库和C++标准库可以很好的集成并填补了C++标准库缺乏的功能空隙。
POCO库的模块化、高效的设计及实现使得POCO特别适合嵌入式开发。
核心库是: Foundation, XML, Util 和 Net. 附加库中其中2个是NetSSL和Data,NetSSL 为Net库中的网络类提供SSL支持, Data库提供访问不同SQL数据库的一致性接口支持的平台:Microsoft WindowsLinuxMac OS XHP-UX,Solaris,AIX*Embedded Linux(UcLibc,glibc)iOSWinodows Embedded CEQNX2.常用功能点> Any and DynamicAny classes> Cache framework> Cryptography (cryptographic hashes, encryption based on OpenSSL)> Date and Time classes> Events (signal/slot mechanism) and notifications framework> FTP client for transferring files> Filesystem classes for platform-independent path manipulation,directory listing and globing > HTML form handling> HTTP server and client (also secure), C++ Server Page Compiler> Logging framework> Multithreading: basic threads and synchronization and advanced facilities (thread pool, active objects, work queues, etc.)> POP3 client for receiving mail> Platform Abstraction: write once, compile and run on multiple platforms> Processes and IPC> Reactor framework> Regular expressions (based on PCRE)> SMTP client for sending mail> SQL database access (SQLite, MySQL, ODBC)> SSL/TLS support based on OpenSSL> Shared library and class loading>Smart pointers and memory management (buffer, pool)> Sockets and raw sockets> Stream classes for Base64 and HexBinary encoding/decoding, compression (zlib), line ending conversion, reading/writing tomemory, etc> String formatting and string utilities> TCP server framework (multithreaded)> Text encodings and conversions> Tuples> URI handling> UTF-8 and Unicode support> UUID handling and generation> XML parsing (SAX2 and DOM) and XML generation> Zip file manipulation2.编译安装2.1 windows下的编译安装2.1.1 Visual Studio 2008 下的编译安装---省略演示2.1.2 Eclipse 下的编译安装---演示为主1.安装MinGW+msys cygwin2.安装eclipse3.设置eclipse编译工具链2.2 unix/linux平台下的编译安装主要步骤如下:1.2.3.HelloWorld 开发自己的第一个应用3.1构建自己的工程a.创建工程目录hellWorldb.创建目录include src 目录helloWorld/include/srcMakefilec. 创建hellWorld.cpp文件3.2编写Makefile警告:Objects,target,target_version,target_libs变量最末尾一定不能有空格,否则编译会出现异常3.3 编译Gmake shared_release3.4 运行3.5 调试4.核心模块介绍4.1.跨平台编译包编译脚本目录$POCO_BASE/build常见的修改:POCO_BASE 定义poco代码目录OSARCH_64BITS =1 定义64位编译模式SRCDIR = src makefile与.cpp的位置INCDIR = include .h文件夹LIBDIR = lib lib文件夹BINDIR = bin bin文件夹OBJDIR = obj/$(OSNAME)/$(OSARCH)DEPDIR = .dep/$(OSNAME)/$(OSARCH)LIBPATH = $(POCO_BUILD)/$(LIBDIR)BINPATH = $(POCO_BUILD)/$(COMPONENT)/$(BINDIR) -->建议改为$(BINDIR)OBJPATH = $(POCO_BUILD)/$(COMPONENT)/$(OBJDIR)-->可以不用管)$(OBJDIR)DEPPATH = $(POCO_BUILD)/$(COMPONENT)/$(DEPDIR)-->依赖文件目录)$(DEPDIR)系统自带的编译指令:all: $(DEFAULT_TARGET)all_static: static_debug static_releaseall_shared: shared_debug shared_releaseall_debug: static_debug shared_debugall_release: static_release shared_release自定义编译指令:CFLAGS += -gCXXFLAGS += -gPOCO_FLAGS +=COMMONFLAGS = -DPOCO_BUILD_HOST=$(HOSTNAME) $(POCO_FLAGS)添加额外的头文件路径:POCO_ADD_INCLUDE += $(ORACLE_HOME)/precomp/public $(ORACLE_HOME)/rdbms/public $(ORACLE_HOME)/rdbms/demoPOCO_ADD_LIBRARY +=$(ORACLE_HOME)/$(OraLib)添加额外的链接库非POCO编译出来的库SYSLIBS +=-locci -lclntsh编译方式:gmake shared_releasegmake shared_debuggmake static_releasegmake static_debuggmake all_releasegmake all_debuggmake all4.2.Foundation库4.2.1 core 模块a.Platform abstraction1.统一了各个平台的数据类型比如long ,int ,long long 等,参考types.h2.平台的big-endian和little-endian 参考ByteOrder.h3.平台类型相关信息platform.hb. Memory Management1.智能指针(smart pointer)和共享指针(shared pointer) 参考AutoPtr.h,SharedPtr.h2.据以引用计数器的垃圾回收机制AtomicCounter.h,refCountedObject.h3.单件类(singleton objects) SingletonHolder.hc.String Utilities字符串的比较(大小写转换,大小写无关转换,去除空白符号,字符转换和连接,分拆),参考String.h,StringTokenizer.hd.Error Handling1. 断言类,类似assert,主要使用宏断言,比如poco_asert(myPtr);参考Bugcheck.h2.异常类, 了解Poco::exception结构,使用POCO_DECLARE_EXCEPTION宏,参考Exception.h4.2.2.streamspass4.2.3.Threadingpass4.2.4.DateTimea.Timestamp 微秒级精度,对gettimeofday()封装,参考Timestamp.hb.Stopwatch 计时器,参考Stopwatch.hc.DateTime 日历时间,参考DateTime.hd.日历时间的格式转换DateTimeFormat,DateTimeFormatter,DateTimeParser 等e.日历时区Timezonef.本地时间LocalDateTime4.2.5 FileSystem与平台无关的文件,目录的操作类。
a.File类,读取文件的相关信息,比如权限,大小,日期,文件的删除,拷贝等b.Path 类,文件目录的解析,目录创建等c.DirectoryIterator类,遍历指定目录下的文件列表d.TemporaryFile 类,临时文件创建,删除等4.2.6 Logging可以输出到多个目的地(console,log files,Unix Syslog,Windows Event Log,remote logging)主要是定义日志文件格式logging.loggers.root.channel.class = ConsoleChannel = globallogging.loggers.app.channel.class =SplitterChannellogging.loggers.app.channel.channels=c1,logfile#日志global.testApp=global.testApp#logging.loggers.mylogger.channel=file2logging.filename=${logging.dir}\\${}.log#定义日志格式logging.formatters.formatter1.class = PatternFormatterlogging.formatters.formatter1.times=locallogging.formatters.formatter1.pattern =[%y/%m/%d %H:%M:%S][${application.month}][%q]-%t#定义日志输出地,输出地名称输出的格式logging.channels.c1.class = ConsoleChannellogging.channels.c1.formatter =formatter1logging.channels.logfile.class=FileChannellogging.channels.logfile.times=locallogging.channels.logfile.formatter=formatter1logging.channels.logfile.path=${system.env.HOME}/Download/${application.n ame}_${application.month}.log#rotationlogging.channels.logfile.rotation=daily#file2logging.channels.file2.class=FileChannellogging.channels.file2.times=local#archive number|timestamplogging.channels.file2.archive=numberlogging.channels.file2.class=FileChannellogging.channels.file2.formatter=formatter1logging.channels.file2.path=${}_${application.month}_a.log logging.channels.file2.rotation=dailypress=true#purge purgeAge|purgeCountlogging.loggers.root.level = debuglogging.loggers.root.channel.class = SplitterChannel///以channel开头的属性logging.loggers.root.channel.channel1 = consoleChannellogging.loggers.root.channel.channel2 = fileChannel也可以配置成logging.loggers.root.channel.channels=consoleChannel,fileChannel///定义控制台通道logging.channels.consoleChannel.class = ConsoleChannellogging.channels.consoleChannel.formatter = f1///定义文件通道logging.channels.fileChannel.class = FileChannellogging.channels.fileChannel.path = mantid.loglogging.channels.fileChannel.formatter.class = PatternFormatter\n" logging.channels.fileChannel.formatter.pattern= %Y-%m-%d %H:%M:%S,%i [%I] %p %s - %t///定义消息格式logging.formatters.f1.class = PatternFormatterlogging.formatters.f1.pattern = %s-[%p] %t4.2.7 Processes4.2.8 Shared Libraries4.2.9 Notifications4.2.10 Event4.2.11 Crypt4.2.12 Text4.2.13 Regular Expressions4.3.XML库Xml解析器是对expat解析库的包装。