libsrc/do2.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: do2.cxx,v $
00032  * Revision 1.15  2004/09/11 13:59:21  jrush
00033  * Changed all fprintf's to stderr to use the Nana library L() macro.  Also
00034  * removed a 2-3 minor compiler warnings.
00035  *
00036  * Revision 1.14  2004/09/04 16:02:17  jrush
00037  * Added Doxygen headers before each and every function definition.
00038  *
00039  * Revision 1.13  2004/09/03 11:38:30  jrush
00040  * Began adding extensive commenting to functions.
00041  *
00042  * Revision 1.12  2002/07/14 08:35:23  jrush
00043  * Replace gerror(), qerror() with assert()
00044  *
00045  * Revision 1.11  2002/05/28 04:22:29  jrush
00046  * Adjusted source files to comply with GPL licensing.
00047  *
00048  * Revision 1.10  2002/04/12 11:56:43  jrush
00049  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00050  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00051  *
00052  * Revision 1.9  2002/04/10 18:01:54  jrush
00053  * Renamed class typeisa to IStreamAddr.
00054  *
00055  * Revision 1.8  2002/04/09 21:45:46  jrush
00056  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00057  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00058  * up the type/class tree.
00059  *
00060  * Revision 1.7  2002/04/06 20:42:50  jrush
00061  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00062  *
00063  * Revision 1.6  2002/04/06 17:05:57  jrush
00064  * Switched from referring to 'task' for a client connection to 'session',
00065  * and converted the typetask typedef/struct into a Session C++ class.
00066  *
00067  * Revision 1.5  2002/04/06 15:01:17  jrush
00068  * Changed INT to just 'int'.
00069  *
00070  * Revision 1.4  2002/04/06 14:06:19  jrush
00071  * Added more debugging messages as I work on getting docopy() to work.
00072  *
00073  * Revision 1.3  2002/04/02 18:45:12  jrush
00074  * Purely cosmetic changes.
00075  *
00076  * Revision 1.2  2002/02/14 09:27:43  jrush
00077  * Cleaned up source:
00078  *
00079  * 1. ran thru the indent tool to achieve a standard look,
00080  * 2. added structured comments at top for use with DOxygen reporting
00081  *    as well as CVS keywords,
00082  * 3. fixed compiler warnings re ambiguous assign/compares,
00083  *    needed casts and unused/uninitialized variables,
00084  * 4. fixed funcs that didn't specify a return type,
00085  * 5. centralized prototypes in protos.h, removing incomplete ones,
00086  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00087  * 7. fixed initializer nesting in tumbler constants,
00088  * 8. renamed vars that conflict with C++ keywords (new, this),
00089  * 9. fixed global/extern confusion re some global vars.
00090  *
00091  */
00092 
00093 #include "udanax.h"
00094 
00101     // Convert the specification set into a set of spans into the I-stream.
00102     bool
00103 specset2ispanset(
00104     Session      *sess,          
00105     typespecset   specset,
00106     typeispanset *ispansetptr,
00107     int           type)
00108 {
00109     //UNUSED typeispanset *save = ispansetptr;
00110 
00111     *ispansetptr = NULL;
00112     for (; specset; specset = (typespec *) ((typeitemheader *) specset)->next) {
00113 
00114         if (((typeitemheader *) specset)->itemid == ISPANID) {
00115             L("specset2ispanset, found an ISPANID\n");
00116 
00117             *ispansetptr = (typeispanset) specset;
00118             ispansetptr = (typeispanset *) & ((typeitemheader *) specset)->next;
00119 
00120         } else if (((typeitemheader *) specset)->itemid == VSPECID) {
00121             L("specset2ispanset, found an VSPECID\n");
00122 
00123             assert(!iszerotumbler(&((typevspec *) specset)->docisa)); // ERROR: retrieve called with docisa 0
00124 
00125             typeorgl docorgl;
00126             if (!(findorgl(sess, granf, &((typevspec *) specset)->docisa, &docorgl, type) /*BERT*/
00127             && (ispansetptr = vspanset2ispanset(sess, docorgl, ((typevspec *) specset)->vspanset, ispansetptr)))) {
00128                 return false;        /* zzzz */
00129             }
00130         }
00131     }
00132     return true;
00133 }
00134 
00141     bool
00142 tumbler2spanset(
00143     Session     *sess,          
00144     IStreamAddr *tumblerptr,
00145     typespanset *spansetptr)
00146 {
00147     typespan *spanptr = new(sess) typespan;
00148 //    typespan *spanptr = (typespan *) sess->alloc(sizeof(typespan));
00149 
00150     spanptr->next   = NULL;
00151     spanptr->itemid = ISPANID;
00152 
00153     movetumbler(tumblerptr, &spanptr->stream);
00154 
00155     tumblerclear(&spanptr->width);
00156     tumblerincrement(&spanptr->width, tumblerlength(tumblerptr) - 1 /* zzzzz */ , 1,
00157                      &spanptr->width);
00158     *spansetptr = spanptr;
00159 
00160     return true;
00161 }
00162 
00169     void
00170 makehint(
00171     int          typeabove,
00172     int          typebelow,
00173     int          typeofatom,
00174     IStreamAddr *isaptr,
00175     typehint    *hintptr)
00176 {
00177     hintptr->supertype = typeabove;
00178     hintptr->subtype   = typebelow;
00179     hintptr->atomtype  = typeofatom;
00180 
00181     movetumbler(isaptr, &hintptr->hintisa);
00182 }
00183 
00190     void
00191 validhint(typehint *hintptr)
00192 {
00193     if ((hintptr->supertype < NODE)
00194         || (hintptr->supertype > DOCUMENT)
00195         || (hintptr->subtype   < ACCOUNT)
00196         || (hintptr->subtype   > ATOM)
00197         || (hintptr->atomtype  < 0)
00198         || (hintptr->atomtype  > 2)
00199         || (hintptr->subtype   < hintptr->supertype)
00200         || ((hintptr->subtype - hintptr->supertype) > 1)
00201         || ((hintptr->subtype == ATOM) == !hintptr->atomtype)) {
00202 
00203 #ifndef DISTRIBUTION
00204 /* L("bad hint: supertype = %d subtype = %d atomtype = %d\n", hintptr->supertype, hintptr->subtype,
00205  * hintptr->atomtype); L("hintisa = "); puttumbler(stderr, &hintptr->hintisa); */
00206         assert(0); // bad hint
00207 #else
00208         assert(0);
00209 #endif
00210     }
00211 }
00212 
00219     bool /* vsa 1 if zenf, else w/in vspan of fullcrum */
00220 acceptablevsa(
00221     Tumbler  *vsaptr,
00222     typeorgl  orglptr)
00223 {
00224     L("--acceptablevsa is a NOP--\n");
00225     return true;
00226 }
00227 
00234     bool
00235 insertendsetsinspanf(
00236     Session       *sess,          
00237     typespanf      spanfptr,
00238     IStreamAddr   *linkisaptr,
00239     typesporglset  fromsporglset,
00240     typesporglset  tosporglset,
00241     typesporglset  threesporglset)
00242 {
00243     if (!(insertspanf(sess, spanfptr, linkisaptr, fromsporglset, LINKFROMSPAN)
00244           && insertspanf(sess, spanfptr, linkisaptr, tosporglset, LINKTOSPAN)))
00245         return false;
00246 
00247     if (threesporglset) {
00248         if (!insertspanf(sess, spanfptr, linkisaptr, threesporglset, LINKTHREESPAN)) {
00249             return false;
00250         }
00251     }
00252     return true;
00253 }
00254 
00261     bool
00262 insertendsetsinorgl(
00263     Session       *sess,          
00264     Tumbler       *linkisaptr,
00265     typeorgl       link,
00266     Tumbler       *fromvsa,
00267     typesporglset  fromsporglset,
00268     Tumbler       *tovsa,
00269     typesporglset  tosporglset,
00270     Tumbler       *threevsa,
00271     typesporglset  threesporglset)
00272 {
00273     if (!(insertpm(sess, linkisaptr, link, fromvsa, fromsporglset)
00274           && insertpm(sess, linkisaptr, link, tovsa, tosporglset))) {
00275         return false;
00276     }
00277 
00278     if (threevsa && threesporglset) {
00279         if (!insertpm(sess, linkisaptr, link, threevsa, threesporglset))
00280             return false;
00281 
00282     } else {
00283 #ifndef DISTRIBUTION
00284         L("leaving INSERTENDSETSINORGL 4\n");
00285         L(" threevsa ptr= %x threesporglset ptr = %x threesvsa = \n", (int) threevsa, (int) threesporglset);
00286         dumptumbler(threevsa);
00287 #endif
00288     }
00289 
00290     return true;
00291 }
00292 
00299     bool
00300 findnextlinkvsa(
00301     Session     *sess,          
00302     IStreamAddr *docisaptr,
00303     Tumbler     *vsaptr)
00304 {
00305     Tumbler vspanreach, firstlink;
00306     typevspan vspan;
00307 
00308     tumblerclear(&firstlink);
00309     tumblerincrement(&firstlink, 0, 2, &firstlink);
00310     tumblerincrement(&firstlink, 1, 1, &firstlink);
00311 
00312     doretrievedocvspan(sess, docisaptr, &vspan);
00313 
00314     tumbleradd(&vspan.stream, &vspan.width, &vspanreach);
00315 
00316     if (tumblercmp(&vspanreach, &firstlink) == LESS)
00317         movetumbler(&firstlink, vsaptr);
00318     else
00319         movetumbler(&vspanreach, vsaptr);
00320 
00321     return true;
00322 }
00323 
00330     bool
00331 setlinkvsas(
00332     Tumbler *fromvsaptr,
00333     Tumbler *tovsaptr,
00334     Tumbler *threevsaptr)
00335 {
00336     tumblerclear(fromvsaptr);
00337     tumblerincrement(fromvsaptr, 0, 1, fromvsaptr);
00338     tumblerincrement(fromvsaptr, 1, 1, fromvsaptr);
00339 
00340     tumblerclear(tovsaptr);
00341     tumblerincrement(tovsaptr, 0, 2, tovsaptr);
00342     tumblerincrement(tovsaptr, 1, 1, tovsaptr);
00343 
00344     if (threevsaptr) {
00345         tumblerclear(threevsaptr);
00346         tumblerincrement(threevsaptr, 0, 3, threevsaptr);
00347         tumblerincrement(threevsaptr, 1, 1, threevsaptr);
00348     }
00349 
00350     return true;
00351 }
00352 
00359     bool
00360 ispansetandspecsets2spanpairset(
00361     Session *sess,          
00362     typeispanset ispanset,
00363     typespecset specset1,
00364     typespecset specset2,
00365     typespanpairset *pairsetptr)
00366 {
00367 #ifndef DISTRIBUTION
00368     L("entering ispansetandspecsets2spanpairset\n");
00369 #endif
00370 
00371     if (ispanset == NULL) {
00372         *pairsetptr = NULL;
00373 
00374 #ifndef DISTRIBUTION
00375         L("ispanset NULL, no relation\n");
00376 #endif
00377 
00378     } else {
00379         restrictspecsetsaccordingtoispans(sess, ispanset, &specset1, &specset2);
00380         makespanpairset(sess, ispanset, specset1, specset2, pairsetptr);
00381 
00382 #ifndef DISTRIBUTION
00383         foo("after makespanpairset\n");
00384         if (debug)
00385             dumpspanpairset(*pairsetptr);
00386 #endif
00387 
00388     }
00389 
00390 #ifndef DISTRIBUTION
00391     L("leaving ispansetandspecsets2spanpairset\n");
00392 #endif
00393 
00394     return true;
00395 }

Generated on Sun Aug 21 04:18:14 2005 for Udanax-Green by doxygen1.3.4