Ignore:
Timestamp:
Aug 28, 2009 5:54:24 AM (15 years ago)
Author:
dkearney
Message:

updates to the object system, fixed up tree and xml parser objects, added some basic tests for them and adopted number object to accept xml text and configure itself from the parsed xml. added fermi3.cc example program which contains suggested interface from apps meeting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/objects/RpPath.cc

    r1528 r1560  
    2323#include "RpChainHelper.h"
    2424#include <cstring>
     25#include <cstdlib>
    2526
    2627using namespace Rappture;
     
    6061    _ifs = b._ifs;
    6162
     63    //FIXME: i think this is broken
    6264    Rp_ChainCopy (_pathList, b._pathList, Rp_ChainCharCpyFxn);
    6365}
     
    105107    _ifs = '.';
    106108    _pathList = Rp_ChainCreate();
     109    _currLink = Rp_ChainFirstLink(_pathList);
    107110    return;
    108111}
     
    134137    int end,
    135138    int idOpenParen,
    136     int idCloseParen)
     139    int idCloseParen,
     140    size_t degree)
    137141{
    138142    componentStruct *c = new componentStruct();
     
    143147    c->type = NULL;
    144148    c->id = NULL;
     149    c->degree = degree;
    145150
    146151    if (idOpenParen < idCloseParen) {
     
    171176        the type and id of the third component are both blank.
    172177        for the above example paths, the id field of the first
    173         components, the index component, is NULL.
     178        components, the input component, is NULL.
    174179        i don't think there is a way to get a NULL type right now.
    175180    */
     
    215220    int idCloseParen = -1;
    216221    componentStruct *c = NULL;
     222    size_t degree = 1;
     223    char *newEnd = NULL;
    217224
    218225    Rp_Chain *compList = Rp_ChainCreate();
     
    227234        } else if (p[end] == ')') {
    228235            idCloseParen = end;
     236        } else if ( (idOpenParen <= idCloseParen) &&
     237                    (end != 0) &&
     238                    (p[end] >= '0') &&
     239                    (p[end] <= '9') ) {
     240            degree = (size_t) strtod(p+end, &newEnd);
     241            if (degree == 0) {
     242                // interpret degree of 0 same as degree of 1
     243                degree = 1;
     244            }
     245            // check if we consumed the _ifs
     246            if (*(newEnd-1) == _ifs) {
     247                newEnd -= 2;
     248            }
     249            end += newEnd - (p + end);
    229250        } else if (p[end] == _ifs) {
    230             c = __createComponent(p,start,end,idOpenParen,idCloseParen);
     251            c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree);
    231252            if (c != NULL) {
    232253                Rp_ChainAppend(compList,c);
     
    240261    }
    241262
    242     c = __createComponent(p,start,end,idOpenParen,idCloseParen);
     263    c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree);
    243264    if (c != NULL) {
    244265        Rp_ChainAppend(compList,c);
     
    335356}
    336357
     358bool
     359Path::eof ()
     360{
     361    return (_currLink == NULL);
     362}
     363
     364Path&
     365Path::first ()
     366{
     367    _currLink = Rp_ChainFirstLink(_pathList);
     368    return *this;
     369}
     370
     371Path&
     372Path::prev ()
     373{
     374    if (_currLink) {
     375        _currLink = Rp_ChainPrevLink(_currLink);
     376    }
     377    return *this;
     378}
     379
     380Path&
     381Path::next ()
     382{
     383    if (_currLink) {
     384        _currLink = Rp_ChainNextLink(_currLink);
     385    }
     386    return *this;
     387}
     388
     389Path&
     390Path::last ()
     391{
     392    _currLink = Rp_ChainLastLink(_pathList);
     393    return *this;
     394}
     395
     396size_t
     397Path::count ()
     398{
     399    return Rp_ChainGetLength(_pathList);
     400}
     401
    337402const char *
    338403Path::component(void)
    339404{
    340405    Rp_ChainLink *l = NULL;
    341     size_t len = 0;
    342 
     406
     407    /*
    343408    tmpBuf.clear();
    344409
     
    348413    }
    349414
    350     l = Rp_ChainLastLink(_pathList);
     415    l = _currLink;
    351416
    352417    if (l == NULL) {
     
    363428
    364429    if (c->type != NULL) {
    365         len = strlen(c->type);
    366         if (len > 0) {
    367             tmpBuf.append(c->type,len);
    368         }
     430        tmpBuf.appendf("%s",c->type);
     431    }
     432
     433    if (c->degree != 1) {
     434        tmpBuf.appendf("%zu",c->degree);
    369435    }
    370436
    371437    if (c->id != NULL) {
    372         tmpBuf.append("(",1);
    373         len = strlen(c->id);
    374         if (len > 0) {
    375             tmpBuf.append(c->id,len);
    376         }
    377         tmpBuf.append(")",1);
    378     }
    379 
     438        tmpBuf.appendf("(%s)",c->id);
     439    }
     440
     441    // incase none of the above if statements are hit.
     442    tmpBuf.append("\0",1);
     443
     444    return tmpBuf.bytes();
     445    */
     446
     447
     448    if (_pathList == NULL) {
     449        return NULL;
     450    }
     451
     452    l = _currLink;
     453
     454    if (l == NULL) {
     455        return NULL;
     456    }
     457
     458    componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
     459
     460    if (c == NULL) {
     461        return NULL;
     462    }
     463
     464    tmpBuf.clear();
     465
     466    if (c->type != NULL) {
     467        tmpBuf.appendf("%s",c->type);
     468    }
     469
     470    if (c->degree != 1) {
     471        tmpBuf.appendf("%zu",c->degree);
     472    }
     473
     474    if (c->id != NULL) {
     475        tmpBuf.appendf("(%s)",c->id);
     476    }
     477
     478    // incase none of the above if statements are hit.
    380479    tmpBuf.append("\0",1);
    381480
     
    426525    Rp_ChainDestroy(addList);
    427526
    428     // remove the last component from the current path
    429     l = Rp_ChainLastLink(_pathList);
     527    // swap the current component from the current path
     528    // with the component from the provided path.
     529    l = _currLink;
    430530
    431531    if (l != NULL) {
    432532        componentStruct *last = (componentStruct *) Rp_ChainGetValue(l);
    433533        delete last;
    434         Rp_ChainDeleteLink(_pathList,l);
    435     }
    436 
    437     // append the new component onto the current path
    438     Rp_ChainAppend(_pathList,aLcomp);
     534        Rp_ChainSetValue(l,aLcomp);
     535    } else {
     536        // add a new component as a link
     537        // point _currLink to the new component
     538        _currLink = Rp_ChainAppend(_pathList,aLcomp);
     539    }
    439540
    440541    __updateBuffer();
     
    448549    Rp_ChainLink *l = NULL;
    449550
     551    /*
    450552    tmpBuf.clear();
    451553
     
    455557    }
    456558
    457     l = Rp_ChainLastLink(_pathList);
     559    l = _currLink;
    458560
    459561    if (l == NULL) {
     
    476578
    477579    return tmpBuf.bytes();
     580    */
     581
     582    if (_pathList == NULL) {
     583        return NULL;
     584    }
     585
     586    l = _currLink;
     587
     588    if (l == NULL) {
     589        return NULL;
     590    }
     591
     592    componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
     593
     594    if (c == NULL) {
     595        return NULL;
     596    }
     597
     598    return c->id;
    478599}
    479600
     
    490611    componentStruct *last = NULL;
    491612
    492     // update the last component from the current path
    493     l = Rp_ChainLastLink(_pathList);
     613    // update the current component from the current path
     614    l = _currLink;
    494615
    495616    if (l != NULL) {
     
    499620        // append the new component onto the current path
    500621        last = new componentStruct;
    501         Rp_ChainAppend(_pathList,last);
     622        _currLink = Rp_ChainAppend(_pathList,last);
    502623        tmp = new char[1];
    503624        *tmp = '\0';
     
    520641    Rp_ChainLink *l = NULL;
    521642
     643    /*
    522644    tmpBuf.clear();
    523645
     
    527649    }
    528650
    529     l = Rp_ChainLastLink(_pathList);
     651    l = _currLink;
    530652
    531653    if (l == NULL) {
     
    548670
    549671    return tmpBuf.bytes();
     672    */
     673
     674    if (_pathList == NULL) {
     675        return NULL;
     676    }
     677
     678    l = _currLink;
     679
     680    if (l == NULL) {
     681        return NULL;
     682    }
     683
     684    componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
     685
     686    if (c == NULL) {
     687        return NULL;
     688    }
     689
     690    return c->type;
    550691}
    551692
     
    563704
    564705    // update the last component from the current path
    565     l = Rp_ChainLastLink(_pathList);
     706    l = _currLink;
    566707
    567708    if (l != NULL) {
     
    571712        // append the new component onto the current path
    572713        last = new componentStruct;
    573         Rp_ChainAppend(_pathList,last);
     714        _currLink = Rp_ChainAppend(_pathList,last);
    574715        last->id = NULL;
    575716    }
     
    593734    tmpBuf.clear();
    594735
    595     last = Rp_ChainLastLink(_pathList);
     736    last = _currLink;
    596737    l = Rp_ChainFirstLink(_pathList);
    597738    while (l != last) {
     
    685826}
    686827
     828size_t
     829Path::degree()
     830{
     831    Rp_ChainLink *l = NULL;
     832
     833    l = _currLink;
     834
     835    if (l == NULL) {
     836        return 0;
     837    }
     838
     839    componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
     840
     841    if (c == NULL) {
     842        return 0;
     843    }
     844
     845    return c->degree;
     846}
     847
     848void
     849Path::degree(size_t d)
     850{
     851    if (d == 0) {
     852        d = 1;
     853    }
     854
     855    Rp_ChainLink *l = NULL;
     856    componentStruct *last = NULL;
     857
     858    // update the current component from the current path
     859    l = _currLink;
     860
     861    if (l != NULL) {
     862        last = (componentStruct *) Rp_ChainGetValue(l);
     863    } else {
     864        // append the new component onto the current path
     865        last = new componentStruct;
     866        _currLink = Rp_ChainAppend(_pathList,last);
     867    }
     868
     869    // adjust the degree field
     870    last->degree = d;
     871
     872    __updateBuffer();
     873
     874    return;
     875}
     876
    687877const char *
    688878Path::path(void)
     
    696886    if (p != NULL) {
    697887        _pathList = __parse(p);
     888        _currLink = Rp_ChainLastLink(_pathList);
    698889        __updateBuffer();
    699890    }
Note: See TracChangeset for help on using the changeset viewer.