⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libg++.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
@end tableSet, Bag, and PQ classes possess@table @code@item Pix j = a.add(x) (or a.enq(x) for priority queues)add x to the collection, returning its Pix. The Pix of an itemcan change in collections where further additions and deletionsinvolve the actual movement of elements (currently in OXPSet,OXPBag, XPPQ, VOHSet), but in all other cases, an item's Pix maybe considered a permanent key to its location.@end table@node Headers, Builtin, Pix, Top@chapter Header files for interfacing C++ to CThe following files are provided so that C++ programmers mayinvoke common C library and system calls. The names and contentsof these files are subject to change in order to be compatiblewith the forthcoming GNU C library. Other files, not listedhere, are simply C++-compatible interfaces to corresponding Clibrary files.@table @file@item values.hA collection of constants defining the numbers of bits in builtintypes, minimum and maximum values, and the like. Most names arethe same as those found in @file{values.h} found on Sun systems.@item std.hA collection of common system calls and @file{libc.a} functions.Only those functions that can be declared without introducingnew type definitions (socket structures, for example) areprovided. Common @code{char*} functions (like @code{strcmp}) are amongthe declarations. All functions are declared along with theirlibrary names, so that they may be safely overloaded.@item string.hThis file merely includes @file{<std.h>}, where string functionprototypes are declared. This is a workaround for the fact thatsystem @file{string.h} and @file{strings.h} files often differin contents.@item osfcn.hThis file merely includes @file{<std.h>}, where system functionprototypes are declared. @item libc.hThis file merely includes @file{<std.h>}, where C library functionprototypes are declared. @item math.hA collection of prototypes for functions usually found inlibm.a, plus some @code{#define}d constants that appear to beconsistent with those provided in the AT&T version. The valueof @code{HUGE} should be checked before using. Declarations ofall common math functions are preceded with @code{overload}declarations, since these are commonly overloaded.@item stdio.hDeclaration of @code{FILE} (@code{_iobuf}), common macros (like@code{getc}), and function prototypes for @file{libc.a}functions that operate on @code{FILE*}'s. The value@code{BUFSIZ} and the declaration of @code{_iobuf} should bechecked before using.@item assert.hC++ versions of assert macros.@item generic.hString concatenation macros useful in creating generic classes.They are similar in function to the AT&T CC versions.@item new.hDeclarations of the default global operator new, the two-argumentplacement version, and associated error handlers.@end table@node Builtin, New, Headers, Top@chapter Utility functions for built in typesFiles @file{builtin.h} and corresponding @file{.cc} implementationfiles contain various convenientinline and non-inline utility functions. These include usefulenumeration types, such as @code{TRUE}, @code{FALSE} ,the typedefinition for pointers to libg++ error handling functions, andthe following functions.@table @code@item long abs(long x); double abs(double x);inline versions of abs. Note that the standard libc.a version,@code{int abs(int)} is @emph{not} declared as inline.@item void clearbit(long& x, long b);clears the b'th bit of x (inline).@item void setbit(long& x, long b);sets the b'th bit of x (inline)@item int testbit(long x, long b);returns the b'th bit of x (inline).@item int even(long y);returns true if x is even (inline).@item int odd(long y);returns true is x is odd (inline).@item int sign(long x); int sign(double x);returns -1, 0, or 1, indicating whether x is less than, equal to, orgreater than zero (inline).@item long gcd(long x, long y);returns the greatest common divisor of x and y.@item long lcm(long x, long y);returns the least common multiple of x and y.@item long lg(long x); returns the floor of the base 2 log of x.@item long pow(long x, long y); double pow(double x, long y);returns x to the integer power y using via the iterative O(log y)``Russian peasant'' method.@item long sqr(long x); double sqr(double x);returns x squared (inline).@item long sqrt(long y);returns the floor of the square root of x.@item unsigned int hashpjw(const char* s);a hash function for null-terminated char* strings using themethod described in Aho, Sethi, & Ullman, p 436.@item unsigned int multiplicativehash(int x);a hash function for integers that returns the lower bits of multiplying x by the golden ratio times pow(2, 32). See Knuth, Vol 3, p 508.@item unsigned int foldhash(double x);a hash function for doubles that exclusive-or's the first andsecond words of x, returning the result as an integer.@item double start_timer()Starts a process timer.@item double return_elapsed_time(double last_time)Returns the process time since last_time. If last_time == 0 returns the time since the last start_timer. Returns -1 if start_timer was not first called.@end tableFile @file{Maxima.h} includes versions of @code{MAX, MIN}for builtin types.File @file{compare.h} includes versions of @code{compare(x, y)}for builtin types. These return negative if the first argumentis less than the second, zero for equal, and positive for greater.@node New, IOStream, Builtin, Top@chapter Library dynamic allocation primitivesLibg++ contains versions of @code{malloc, free, realloc} that weredesigned to be well-tuned to C++ applications. The source file@file{malloc.c} contains some design and implementation details.Here are the major user-visible differences from most systemmalloc routines:@enumerate@itemThese routines @emph{overwrite} storage of freed space. Thismeans that it is never permissible to use a @code{delete}'dobject in any way. Doing so will either result in trappedfatal errors or random aborts within malloc, free, or realloc.@itemThe routines tend to perform well when a large numberof objects of the same size are allocated and freed. Youmay find that it is not worth it to create yourown special allocation schemes in such cases.@itemThe library sets top-level @code{operator new()} to call malloc and@code{operator delete()} to call free. Of course, you may override thesedefinitions in C++ programs by creating your own operators that willtake precedence over the library versions. However, if you do so, besure to define @emph{both} @code{operator new()} and @code{operatordelete()}.@itemThese routines do @emph{not} support the odd convention, maintained bysome versions of malloc, that you may call @code{realloc} with a pointerthat has been @code{free}'d.@itemThe routines automatically perform simple checks on @code{free}'dpointers that can often determine whether users have accidentallywritten beyond the boundaries of allocated space, resulting in a fatalerror.@itemThe function @code{malloc_usable_size(void* p)} returns the number ofbytes actually allocated for @code{p}. For a valid pointer (i.e., onethat has been @code{malloc}'d or @code{realloc}'d but not yet@code{free}'d) this will return a number greater than or equal to therequested size, else it will normally return 0. Unfortunately, anon-zero return can not be an absolutely perfect indication of lack oferror. If a chunk has been @code{free}'d but then re-allocated for adifferent purpose somewhere elsewhere, then @code{malloc_usable_size}will return non-zero. Despite this, the function can be very valuablefor performing run-time consistency checks.@item@code{malloc} requires 8 bytes of overhead per allocated chunk, plus ammaximum alignment adjustment of 8 bytes. The number of bytes of usablespace is exactly as requested, rounded to the nearest 8 byte boundary.@itemThe routines do @emph{not} contain any synchronization support formultiprocessing. If you perform global allocation on a sharedmemory multiprocessor, you should disable compilation and useof libg++ malloc in the distribution @file{Makefile} and use yoursystem version of malloc.@end enumerate@node IOStream, Stream, New, Top@chapter The new input/output classesThe iostream classes implement most of the features of AT&Tversion 2.0 iostream library classes, and most of the featuresof the ANSI X3J16 library draft (which is based on the AT&T design).The iostream classes replace all of the old stream classesin previous versions of libg++.  It is not totally compatible,so you will probably need to change your code in places.@c (THIS CHAPTER NEEDS WORK!  -FIXME)@section The @code{streambuf} layerThe lower level abstraction is the @code{streambuf} layer.A @code{streambuf} (or one of the classes derived from it)implements a character source and/or sink, usually with buffering.Classes derived from @code{streambuf} include:@itemize @bullet@itemA @code{filebuf} is used for reading and writing from files.@itemA @code{strstreambuf} can read and write from a string in main memory.The string buffer will be re-allocated as needed it, unless it is ``frozen''.@itemAn @code{indirectbuf} just forwards all read/writerequests to some other buffer.	@itemA @code{procbuf} can read from or write to a Unix process.@itemA @code{parsebuf} has some useful features for scanningtext:  It keeps track of line and column numbers, and itguarantees to remember at least the current line (with thelinefeeds at either end), so you can arbitrarily backupwithin that time.  WARNING:  The interface is likely to change.@itemAn @code{edit_streambuf} reads and writes into a region of an@code{edit_buffer} called an @code{edit_string}.  Emacs-like marks aresupported, and sub-strings are first-class functions.  WARNING: Theinterface is almost certain to change.@end itemize@section The istream and ostream classesThe stream layer provides an efficient, easy-to-use, and type-secureinterface between C++ and an underlying @code{streambuf}.Most C++ textbooks will at least given an overview ofthe stream classes.  Some libg++ specifics:@table @code@item istream::get(char* s, int maxlength, char terminator='\n')Behaves as described by Stroustrup. It reads at most maxlength charactersinto s, stopping when the terminator is read, and pushing theterminator back into the input stream.@item istream::getline(char* s, int maxlength, char terminator = '\n')Behaves like get, except that the terminator is read (and not pushed back),though it does not become part of the string.@item istream::gets(char** ss, char terminator = '\n')reads in a line (as in get) of unknown length, and placesit in a free-store allocated spot and attaches it to @code{ss}. Theprogrammer must take responsibility for deleting @code{*ss}when it is no longer needed.@item ostream::form(const char* format...)outputs @code{printf}-formated data.@end table@section The SFile class@code{SFile} (short for structure file) is provided both as a demonstrationof how to build derived classes from @code{iostream}, and as a useful class forprocessing files containing fixed-record-length binary data.  They arecreated with constructors with one additional argument declaring the size(in bytes, i.e., @code{sizeof} units) of the records.  @code{get}, willinput one record, @code{put} will output one, and the @code{[]} operator,as in @code{f[i]}, will position to the i'th record. If the file is beingused mainly for random access, it is often a good idea to eliminateinternal buffering via @code{setbuf} or @code{raw}. Here is an example:@smallexample            class record@{  friend class SFile;  char c; int i; double d;     // or anything at all@};void demo()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -