📄 commoncpp2.texi
字号:
@node Daemons@section Daemons@cindex Daemons@findex pdetach@cindex slogDaemon support consists of two GNU Common C++ features. The first isthe "pdetach" function. This function provides a simple and portablemeans to fork/detach a process into a daemon. In addition, the "slog"object is provided.@tindex Slog@cindex slog@cindex clog@findex Slog::operator<<"slog" is an object which behaves very similar to the Standard C++"clog". The key difference is that the "slog" object sends it'soutput to the system logging daemon (typically syslogd) rather thanthrough stderr. "slog" can be streamed with the << operator just like"clog". "slog" can also accept arguments to specify logging severitylevel, etc.@c -----------------------------------------------------------------------@node Persistence@section Persistence@cindex PersistenceThe GNU Common C++ Persistence library was designed with one thoughtforemost - namely that large interlinked structures should be easilyserializable. The current implementation is @emph{not} endian safe,and so, whilst it should in theory be placed in the "Extras" section,the codebase itself is considered stable enough to be part of the maindistribution.@tindex Persistence::BaseObject@findex IMPLEMENT_PERSISTENCE@findex DECLARE_PERSISTENCEThe Persistence library classes are designed to provide a quick andeasy way to make your data structures serializable. The only way ofdoing this safely is to inherit your classes from the provided classPersistence::BaseObject. The macros "IMPLEMENT_PERSISTENCE" and"DECLARE_PERSISTENCE" provide all the function prototypes andimplementation details you may require to get your code off theground.@c -----------------------------------------------------------------------@node Configuration and Misc.@section Configuration and Misc.@cindex Configuration and Misc.@tindex MemPagerThere are a number of odd and specialized utility classes found inCommon C++. The most common of these is the "MemPager" class. Thisis basically a class to enable page-grouped "cumulative" memoryallocation; all accumulated allocations are dropped during thedestructor. This class has found it's way in a lot of other utilityclasses in GNU Common C++.@tindex KeydataThe most useful of the misc. classes is the Keydata class. This classis used to load and then hold "keyword = value" pairs parsed from atext based "config" file that has been divided into "[sections]".Keydata can also load a table of "initialization" values for keywordpairs that were not found in the external file.One typically derives an application specific keydata class to load aspecific portion of a known config file and initialize it's values.One can then declare a global instance of these objects and haveconfiguration data initialized automatically as the executable isloaded.Hence, if I have a "[paths]" section in a "/etc/server.conf" file, Imight define something like:@example@cartoucheclass KeyPaths : public Keydata@{public: KeyPaths() : Keydata("/server/paths") @{ static KEYDEF *defvalues = @{ @{"datafiles", "/var/server"@}, @{NULL, NULL@}@}; // @r{override with [paths] from "~/.serverrc" if avail.} Load("~server/paths"); Load(defvalues); @}@};KeyPaths keypaths;@end cartouche@end example@c -----------------------------------------------------------------------@node Numbers and Dates@section Numbers and Dates@cindex Numbers and Dates@tindex Number@tindex ZNumber@tindex Date@tindex DateNumber@emph{TODO.} This section will explain the number manipulation classes(@code{Number} and @code{ZNumber}, as well as the data related classes(@code{Date} and @code{DateNumber}).@c -----------------------------------------------------------------------@node URL Streams@section URL Streams@cindex URL Streams@tindex URLStream@cindex URL related functions@emph{TODO.} This section will explain the URLStream class, as well asthe following URL related functions:@ftable @code@item URLStream@item urlDecode@item urlEncode@item b64Decode@item b64Encode@end ftableIn the meantime you can have a look at the @file{urlfetch.cpp} demo,which is a good example of use of URLStream to retrieve documents fromURLs.@c -----------------------------------------------------------------------@node XML Streams and RPC@section XML Streams and RPC@cindex XML Streams and RPC@tindex XMLStream@tindex XMLRPC@emph{TODO.} This section will explain the XML streams parsing(@code{XMLStream} class) and XML RPC (@code{XMLRPC} class) facilitiesof Common C++. In the meantime, you can have a look at the@file{xmlfetch.cpp} demo, which defines a basic XML parser for URLstreams.@c -----------------------------------------------------------------------@node Exceptions@section Exceptions@cindex Exceptions@tindex Exception@tindex std::exception@emph{TODO.} This section will explain the exception model of CommonC++, based on the @code{Exception} class, derived from std::exception.@tindex Exception@tindex IOException@tindex SockException@tindex DirException@tindex DSOException@tindex FIFOException@tindex PipeException@tindex FileException@tindex FTPException@tindex SerException@tindex ThrException@tindex PersistExceptionOther exception classes that will be commented are:@code{IOException}, @code{SockException}, @code{DirException},@code{DSOException}, @code{FIFOException}, @code{PipeException},@code{FileException}, @code{FTPException}, @code{SerException},@code{ThrException} and @code{PersistException}. In the meantime youcan have a look at the exception class hierarchy on the referencemanual.@c -----------------------------------------------------------------------@node Templates@section Templates@cindex Templates@tindex objCounter@tindex objList@tindex objMap@tindex keyMap]@tindex objSync@tindex cstring@tindex cistring@tindex Pointer@tindex Counter@findex abs@emph{TODO.} This section will explain the template subsistem ofCommon C++.@c -----------------------------------------------------------------------@node Extras@chapter Extras@cindex Extras@emph{TODO: this is rather outdated.}At the time of the release of GNU Common C++ 1.0, it was deemed thatseveral class libraries either were incomplete or still experimental,and the 1.0 designation seemed very inappropriate for these libraries.I also wanted to have a mechanism to later add new GNU Common C++class libraries without having to disrupt or add experimental codeinto the main GNU Common C++ release.To resolve this issue, a second package has been created, and is namedGNU "GNU Common C++ Extras". The extras package simply holds classframeworks that are still not considered "mature" or "recommended".This package can be downloaded, compiled, and installed, after GNUCommon C++ itself. Many of the class libraries appearing in theextras package are likely to appear in GNU Common C++ proper at somefuture date, and should be considered usable in their current form.They are made available both to support continued development of GNUCommon C++ proper and because, while not yet mature, they areconsidered "useful" in some manner.The initial GNU Common C++ "extras" package consisted of twolibraries; Common C++ "scripting" and "math". The scripting library(-lccscript) is the GNU Bayonne scripting engine which is used as anear-realtime event driven embedded scripting engine for "callback"driven state-event server applications. The Bayonne scripting enginedirectly uses C++ inheritance to extend the Bayonne dialect forapplication specific features and is used as a core technology in theGNU Bayonne, DBS, and Meridian telephony servers and as part of the afree home automation project. There has been some discussion aboutfolding the GNU Bayonne scripting concepts around a more conventionalscripting language, and so this package currently remains in "extras"rather than part of GNU Common C++ itself.The other package found in the initial "extras" distribution is theCommon C++ math libraries. These are still at a VERY early stage ofdevelopment, and may well be depreciated if another suitable free C++math/numerical analysis package comes along.@c -----------------------------------------------------------------------@node Serverlets@chapter Serverlets@cindex ServerletsServerlets are a concept popularized with Java and web servers. Thereis a broad abstract architectural concept of serverlets or pluginsthat one also finds in my GNU Common C++ projects, though they are notdirectly defined as part of GNU Common C++ itself.A GNU Common C++ "serverlet" comes about in a Common C++ serverproject, such as the Bayonne telephony server, where one wishes todefine functionality for alternate hardware or API's in alternatedshared object files that are selected at runtime, or to add "plugins"to enhance functionality. A serverlet is defined in this sense as a"DSO" loaded "-module" object file which is linked at runtime againsta server process that exports it's base classes using"-export-dynamic". The "server" image then acts as a carrier for theruntime module's base functionality.Modules, or "serverlets", defined in this way do not need to becompiled with position independent code. The module is only used witha specific server image and so the runtime address is only resolvedonce rather than at different load addresses for different arbitraryprocesses.I recommend that GNU Common C++ based "servers" which publish andexport base classes in this manner for plugins should also have aserver specific "include" file which can be installed in the cc++include directory.@c -----------------------------------------------------------------------@node Compiler Options@chapter Compiler Options@cindex Compiler Options@cindex automake@cindex autoconf@cindex configuration@cindex config.h@cindex ccgnu2-configGNU Common C++ does a few things special with automake and autoconf.When the Common C++ library is built, it saves a number of compileroptions that can be retrieved by an application being configured touse GNU Common C++. These options can be retrieved from the standardoutput of the @command{ccgnu2-config} script, which is installed in themachine binaries path.This is done to assure the same compiler options are used to buildyour application that were in effect when GNU Common C++ itself wasbuilt. Since linkage information is also saved in this manner, thismeans your application's "configure" script does not have to gothrough the entire process of testing for libraries or GNU Common C++related compiler options all over again. Finally, GNU Common C++saves it's own generated @file{config.h} file in@file{cc++/config.h}@footnote{On Win32 systems, a specific@file{config.h} located under the win32/cc++/ directory is used andinstalled.}.@command{ccgnu2-config} has the following options (which are shown ifyou type @command{ccgnu2-config --help}):@exampleUsage: ccgnu2-config [OPTIONS]Options: [--prefix] [--version] [--flags] [--libs] [--gnulibs] [--iolibs] [--extlibs] [--stdlibs] [--includes]@end exampleFor a basic usage of Common C++, you just need the options given bythe following command: @command{ccgnu2-config --flags --stdlibs},whose output should be something like this:@examplefoo@@bar:~/$ ccgnu2-config --flags --stdlibs-I/usr/local/include/cc++2 -I/usr/local/include -D_GNU_SOURCE-L/usr/local/lib -lccext2 -lccgnu2 -lxml2 -lz -ldl -pthread@end exampleNote that this is just an example, the concrete output on your systemwill probably differ. The first output line (corresponding to@code{--flags}) tells what directories must be added to the compilerinclude path, as well as global symbol definitions(@code{_GNU_SOURCE}) needed to compile with Common C++. The secondoutput line (corresponding to @code{--stdlibs}) gives the linkeroptions, both additional library path and libraries that must belinked. @code{ccgnu2} and @code{ccext2} are the two libraries CommonC++ currently consists of. The other libraries shown in the exampleare dependencies of Common C++.The list shown below tells what information is given by each of theoptions that can be specified to @command{ccgnu2-config}. It alsospecifies what would be the output corresponding to the example givenbefore.@table @code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -