📄 hints
字号:
In this example, we want to refer to objects from the user-defined class {\tt Database} by their names sothe name of the database object is the key to the table.To accommodate the {\tt Map} class need for hashing on the key,the name is represented by a {\tt String} and thehash function is the library {\tt hashpjw} functiondeclared in {\tt builtin.h}Thus {\tt $<$K$>$} is {\tt String},{\tt $<$B$>$} is {\tt Database}, and{\tt $<$BP$>$} is {\tt Databasep}.For this example, the lookup mechanism used is resizablehash tables which have type {\tt VHMap} so{\tt $<$M$>$} is {\tt VHMap}.\begin{enumerate}\item The {\tt Map} classes expect to geta function called {\tt HStringHASH} that takes an argument of type {\tt String} so {\tt hashpjw} was wrapped inside{\tt HStringHASH}. Similarly, {\tt HStringEQ} is a wrapperfor the {\tt HString} class operator $=$.(The $=$ operator is inherited from the {\tt String}class).The function headers for {\tt HStringHASH} and {\tt HStringEQ} go into {\tt HString.defs.h}and the function bodies into {\tt HString.defs.cc}.\item {\tt DEFAULT\_INITIAL\_CAPACITY} was set to {\tt 1021}in {\tt HString.defs.h}. You must use the identifier{\tt DEFAULT\_INITIAL\_CAPACITY} to be consistent withthe {\tt Map} classes.\item Define {\tt Databasep} as a pointer to class{\tt Database} in {\tt Database.h}.An identifier other than {\tt Databasep} wouldalso be acceptable. You just can't use {\tt Database*}.\item {\tt genclass -2 HString ref Databasep val Map} \\produces {\tt HString.Databasep.Map.h} and \\{\tt HString.Databasep.Map.cc}.\item Edit {\tt HString.Databasep.Map.h} toinclude {\tt HString.defs.h} and \\ {\tt Database.h}.\item {\tt genclass -2 HString ref Databasep val VHMap} \\produces {\tt HString.Databasep.VHMap.h} and \\{\tt HString.Databasep.VHMap.cc}.\end{enumerate}\end{document}1,,Return-Path: <dl@g.oswego.edu>Received: from rocky.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0) id AA26086; Sat, 3 Feb 90 07:05:17 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.19) id AA09020; Sat, 3 Feb 90 07:04:44 ESTReceived: from life.ai.mit.edu by nisc.nyser.net (5.61/2.1-NYSERNet NISC) id AA24615; Sat, 3 Feb 90 07:00:07 -0500Received: from oswego.Oswego.EDU by life.ai.mit.edu (4.0/AI-4.10) id AA04153; Sat, 3 Feb 90 07:00:15 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.19) id AA16111; Sat, 3 Feb 90 07:02:52 ESTReceived: by g.oswego.edu (4.0/SMI-4.0) id AA26081; Sat, 3 Feb 90 07:03:03 ESTDate: Sat, 3 Feb 90 07:03:03 ESTFrom: dl@g.oswego.edu (Doug Lea)Message-Id: <9002031203.AA26081@g.oswego.edu>To: ngo%tammy@harvard.harvard.eduCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Tom Ngo's message of Fri, 2 Feb 90 23:42:54 EST <9002030548.AA00886@life.ai.mit.edu>Subject: Should "operator =" be made to return *this, by convention?Reply-To: dl@oswego.oswego.edu*** EOOH ***Return-Path: <dl@g.oswego.edu>Date: Sat, 3 Feb 90 07:03:03 ESTFrom: dl@g.oswego.edu (Doug Lea)To: ngo%tammy@harvard.harvard.eduCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Tom Ngo's message of Fri, 2 Feb 90 23:42:54 EST <9002030548.AA00886@life.ai.mit.edu>Subject: Should "operator =" be made to return *this, by convention?Reply-To: dl@oswego.oswego.edu> > C programmers are accustomed to expecting = to return the value> assigned. However, in a few classes--for example, String, Integer> and Rational-- operator == returns void. Is there a good reason> for this? Could they be made to return String&, Integer& and> Rational& *this without causing problems?> The reason that X= (+=, -=, etc.) and = operators return void is tofacilitate simple subclassing. While `utility' classes like String,Integer, etc., are not designed for extensive subclassing (since nomembers are virtual (which, in turn is motivated by efficiencyconsiderations)), it is often convenient to create simple subclasseslike class Line : public String. If you do this, then it is mostdesirable that inherited operators return void. Otherwise, unexpectedtype matches often occur. For example, if operator << (ostream&,Line&) were redefined for Line, but op += were inherited from String,and had return value String&, then { Line l; ...; cout << (l += "\n"); } would invoke op << (ostream&, String&), which is probably notwhat anyone would have in mind. This is avoided by having String::+=return void, making this usage illegal.Problems like this outweigh the syntactic convenience of supportingmultiple right-associative uses of X= and =. A good rule of thumbabout all this is that no non-virtual member functions shouldever return *this by reference. (This rule is broken in a few placesin libg++ for various reasons though.)-Doug1,,Return-Path: <dl@g.oswego.edu>Received: from rocky.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0) id AA00741; Thu, 18 Jan 90 06:01:53 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.18) id AA22159; Thu, 18 Jan 90 06:02:51 ESTReceived: from life.ai.mit.edu by nisc.nyser.net (5.61/2.1-NYSERNet NISC) id AA22988; Thu, 18 Jan 90 05:56:52 -0500Received: from oswego.Oswego.EDU by life.ai.mit.edu (4.0/AI-4.10) id AA00267; Thu, 18 Jan 90 05:58:24 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.18) id AA16327; Thu, 18 Jan 90 06:01:51 ESTReceived: by g.oswego.edu (4.0/SMI-4.0) id AA00738; Thu, 18 Jan 90 06:00:57 ESTDate: Thu, 18 Jan 90 06:00:57 ESTFrom: dl@g.oswego.edu (Doug Lea)Message-Id: <9001181100.AA00738@g.oswego.edu>To: allen@sscvx1.ssc.govCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Michael Allen's message of Wed, 17 Jan 90 14:56:32 CST <9001172056.AA01056@mdtf05.gov>Subject: compiling libg++-1.36.3 with g++-1.36.3 on sun4Reply-To: dl@oswego.oswego.edu*** EOOH ***Return-Path: <dl@g.oswego.edu>Date: Thu, 18 Jan 90 06:00:57 ESTFrom: dl@g.oswego.edu (Doug Lea)To: allen@sscvx1.ssc.govCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Michael Allen's message of Wed, 17 Jan 90 14:56:32 CST <9001172056.AA01056@mdtf05.gov>Subject: compiling libg++-1.36.3 with g++-1.36.3 on sun4Reply-To: dl@oswego.oswego.edu> 2) several files get flagged as a warning that a volatile funtion does> return, which appears to be false.Not quite false, but deserving of explanation:libg++ does not (yet) use the experimental g++ exception handlingfacilities (they are still too new: Too many things would have to beredone if the EH features change). So the only exception strategy isfor error traps like Integer::error() to call the function pointed toby lib_error_handler (see builtin.h). By default, this points todefault_two_arg_error_handler, which prints a message on stderr andaborts. But it *can* be reset to do anything at all, and need notabort execution. On the other hand, *some* (not all) error() memberfunctions are used in a way that preclude any kind of sensiblecontinuation even if error() returns. I mark these as `volatile',since the compiler might as well act as if they cannot return: This isdefensible in that even if (*lib_error_handler) returns, things aregoing so wrong that you are no worse off if the compiler generates(usually faster) code assuming execution aborts. The compilercorrectly warns about these.Again, saner strategies will be employed when the C++ exceptionhandling situation stabilizes.-Doug1,,Summary-line: 8-Jul rocket!dove@uunet.UU.NET #install suggestionsReceived: from uunet.uu.net by g.Oswego.EDU (4.0/Osw4.1.21) id AA03815; Sun, 8 Jul 90 13:35:21 EDTReceived: from rocket.UUCP by uunet.uu.net (5.61/1.14) with UUCP id AA04848; Sun, 8 Jul 90 13:30:17 -0400Received: from peach.sanders.com by rocket.sanders.com (4.0/SMI-4.0) id AA08275; Sun, 8 Jul 90 13:26:44 EDTDate: Sun, 8 Jul 90 13:26:44 EDTFrom: rocket!dove@uunet.UU.NET (Webster Dove)Message-Id: <9007081726.AA08275@rocket.sanders.com>Received: by peach.sanders.com (4.0/SMI-4.0) id AA02268; Sun, 8 Jul 90 13:26:43 EDTTo: uunet!g.oswego.edu!dl@uunet.UU.NETIn-Reply-To: Doug Lea's message of Sun, 8 Jul 90 09:16:05 EDT <9007081316.AA03717@g>Subject: install suggestions*** EOOH ***Date: Sun, 8 Jul 90 13:26:44 EDTFrom: rocket!dove@uunet.UU.NET (Webster Dove)To: uunet!g.oswego.edu!dl@uunet.UU.NETIn-Reply-To: Doug Lea's message of Sun, 8 Jul 90 09:16:05 EDT <9007081316.AA03717@g>Subject: install suggestionsThe following are two scripts for making relative shadow trees. Thefirst is adapted from X11R3 to use relative rather than absolute paths(so the stuff can be moved without breaking). The second is writtenin csh because I know that better.In general, I take a GNU release and expand it in a directory. Then Icreate subdirectory "src" and move everything into it. I backupsrc/Makefile (mv Makefile{,-dist}) and make site/arch/os specific onesrc/Makefile-sun3-os4. Then I make subdirectory build-sun3-os4 (e.g.build-sun3-os4) parallel to src, and setup the shadow tree from insidebuild-sun3-os4 using "lndir ../src".You can just setup your distributions to start at top level with ./src/,README, ./lndir and ./lndir_make_links.The one thing I would like added is that site (e.g. pathnames) andarch/os (compiler switches) specific things be included into theMakefile with include rather than with direct modification. With thatapproach, and docs on how to write the "make.site-include" andmake.archos-include" I could much more easily upgrade to a new releaseand maintain the archos distinction.--- /local/bin/lndir (a shell script) ---#!/bin/sh## lndir - create shadow link tree## If your master sources are located in /usr/src/X and you would like# your link tree to be in /usr/local/src/new-X, do the following:## % mkdir /usr/local/src/new-X# % cd /usr/local/src/new-X# % lndir ../X## NOTES## 7/19/89 dove# use for relative links. Uses aux script lndir_make_links#DIRFROM=$1USAGE="Usage: cd todir; $0 fromdir"if [ ! $# = 1 ] ; then echo "$USAGE" exit 1fiif [ ! -d $DIRFROM ]then echo "$USAGE" exit 1fi## Get the relative directory names#DIRLIST=`(cd $DIRFROM;find . \( -type d ! -name 'RCS' \) -print)`start_dir=`pwd`## Make sure the src and dest are not the same.#pwd=`pwd`if [ `(cd $DIRFROM; pwd)` = $pwd ]then echo "FROM and TO are identical!" exit 1fi## build the tree of directories in the destination.#for dir in $DIRLISTdo if [ ! $dir = . ] then mkdir $dir fidoneecho lndir_make_links $DIRFROMexec lndir_make_links $DIRFROM---- /local/bin/lndir_make_links (csh script) ---#!/bin/csh -f -b## A secondary script called from lndir that actually links the# files from the remote directory and recurses if necessary.#if ( $#argv != 1 ) then echo "$0 error: args $*" exit 1endifset fromdir = $argv[1]set pwd=`pwd`if ( x`(cd $fromdir; pwd)` == x$pwd ) then echo "FROM and TO are identical!" exit 1endifforeach i ( `ls $fromdir` ) if ( -f $fromdir/$i ) ln -s $fromdir/$i .endset nonomatchset next_dirs=`glob */.`unset nonomatchif ( "$next_dirs" != "*/." ) then# echo $next_dirs foreach i ($next_dirs) (cd $i;lndir_make_links ../$fromdir/$i) endendif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -