Changeset 1581 for trunk/src/objects


Ignore:
Timestamp:
Oct 17, 2009, 9:01:23 PM (15 years ago)
Author:
dkearney
Message:

updates for the rappture objects, object examples, and object apis. small fix for rpunits c interface to check string length. there should probably be more of these checks in the c interface, but units should also be rewritten. added folders to separate out octave2 and octave3 app-fermi examples

Location:
trunk/src/objects
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/objects/Makefile.in

    r1566 r1581  
    6565                RpHistogram.h \
    6666                RpLibObj.h \
     67                RpLibStorage.h \
    6768                RpNumber.h \
    6869                RpParserXML.h \
     
    7273                RpScatter.h \
    7374                RpString.h \
     75                RpTest.h \
    7476                RpTree.h \
    7577                RpObjConfig.h \
     
    9597                RpHistogram.o \
    9698                RpLibObj.o \
     99                RpLibStorage.o \
    97100                RpNumber.o \
    98101                RpParserXML.o \
     
    102105                RpScatter.o \
    103106                RpString.o \
     107                RpTest.o \
    104108                RpTree.o \
    105109                RpUtils2.o \
  • trunk/src/objects/RpLibObj.cc

    r1566 r1581  
    2525#include <time.h>
    2626#include <cctype>
     27#include <fstream>
    2728
    2829using namespace Rappture;
     
    4142Library::__libInit()
    4243{
    43     _objList = Rp_ChainCreate();
     44    _status.addContext("Rappture::Library::__libInit");
    4445    return;
    4546}
     
    4849Library::__libFree()
    4950{
    50     if (_objList != NULL) {
    51         Rp_ChainLink *l = NULL;
    52         Rappture::Object *objVal = NULL;
    53         l = Rp_ChainFirstLink(_objList);
    54         while(l) {
    55             objVal = (Rappture::Object *) Rp_ChainGetValue(l);
    56             delete objVal;
    57             objVal = NULL;;
    58             l = Rp_ChainNextLink(l);
    59         }
    60         Rp_ChainDestroy(_objList);
    61         _objList = NULL;
    62     }
    6351    return;
    6452}
     
    8573    // FIXME: add error check for Rp_ParserXmlParse
    8674
    87     // convert xml tree into chain of rappture objects
    88     Rp_Chain *tmpObjList = Rp_ChainCreate();
    89     __parseTree2ObjectList(p,tmpObjList);
     75    //_objStorage.backup();
     76    _objStorage.clear();
     77    __parseTree2ObjectList(p);
     78    /*
    9079    if (!_status) {
    91         __libFree();
    92         _objList = tmpObjList;
    93     }
     80        _objStorage.save();
     81    } else {
     82        _objStorage.restore()
     83    }
     84    */
    9485
    9586    return _status;
     
    10798    }
    10899
     100    // null terminate string holding file
     101    fileBuf.append("\0",1);
     102
    109103    loadXml(fileBuf.bytes());
    110104
    111105    return _status;
     106}
     107
     108Library &
     109Library::value (
     110    const char *key,
     111    void *storage,
     112    size_t numHints,
     113    ...)
     114{
     115    _status.addContext("Rappture::Library::value");
     116    Rappture::Object *o = _objStorage.find(key);
     117
     118    if (o == NULL) {
     119        _status.addError("Error while retrieving object "
     120            "with key \"%s\": object does not exist", key);
     121        return *this;
     122    }
     123
     124    va_list arg;
     125
     126    va_start(arg,numHints);
     127    o->vvalue(storage,numHints,arg);
     128    _status = o->outcome();
     129    va_end(arg);
     130
     131    return *this;
    112132}
    113133
     
    115135Library::xml() const
    116136{
     137    _status.addContext("Rappture::Library::xml");
    117138    Rp_ParserXml *p = Rp_ParserXmlCreate();
    118139    Rp_ChainLink *l = NULL;
    119140
    120     l = Rp_ChainFirstLink(_objList);
     141    const Rp_Chain *objList = _objStorage.contains();
     142
     143    l = Rp_ChainFirstLink(objList);
    121144
    122145    while (l != NULL) {
    123146        Rappture::Object *o = (Rappture::Object *) Rp_ChainGetValue(l);
    124         o->dump(RPCONFIG_TREE,(ClientData)p);
     147        if (o != NULL) {
     148            // FIXME: we can remove the if statement when
     149            // LibraryStorage is fixed to clean up holes
     150            // in the object chain.
     151            o->dump(RPCONFIG_TREE,(ClientData)p);
     152        }
    125153        l = Rp_ChainNextLink(l);
    126154    }
     
    130158
    131159void
    132 Library::__parseTree2ObjectList(
    133     Rp_ParserXml *p,
    134     Rp_Chain *retObjList)
     160Library::__parseTree2ObjectList(Rp_ParserXml *p)
    135161{
    136162    _status.addContext("Rappture::Library::__parseTree2ObjectList");
     
    141167    }
    142168
    143     if (retObjList == NULL) {
    144         _status.addError("return object list is NULL");
    145         return;
    146     }
    147 
    148     // get the children nodes of "tool", "input", and "output"
    149169    Rp_Chain *children = Rp_ChainCreate();
     170
     171    // parse out the tool information
    150172    // Rp_ParserXmlChildren(p, "tool", NULL, children);
     173    // if there is a child called tool, grab its
     174    //      title                   char *
     175    //      about                   char *
     176    //      command                 char *
     177    //      limits.cputime          double
     178    //      layout                  char *
     179    //      control                 char *
     180    //      analyzer                char *
     181    //      reportJobFailures       int
     182
     183    // get the children nodes of "input", and "output"
    151184    Rp_ParserXmlChildren(p, "input", NULL, children);
    152185    Rp_ParserXmlChildren(p, "output", NULL, children);
     
    164197            Rappture::Number *obj = new Rappture::Number();
    165198            obj->configure(RPCONFIG_TREE,(void*)p);
    166             Rp_ChainAppend(retObjList,(void*)obj);
     199            _objStorage.store(obj->name(),obj);
     200            _objStorage.link(obj->name(),obj->path());
     201            // Rp_ChainAppend(retObjList,(void*)obj);
     202
     203        // FIXME: add code to check for strings, choices,
     204        //        groups, curves, notes, images, molecules...
     205        //        all of the rappture object types
    167206        } else {
    168207            _status.addError("unrecognized object type: %s",label);
     
    178217}
    179218
     219
     220
    180221Outcome &
    181222Library::outcome() const
     
    184225}
    185226
     227int
     228Library::error() const
     229{
     230    return (int) _status;
     231}
     232
     233/*
     234Outcome &
     235Library::result(int status)
     236{
     237    Rappture::SimpleCharBuffer tmpBuf;
     238    std::fstream file;
     239    const char *xmlText = NULL;
     240    time_t t = 0;
     241    struct tm* timeinfo = NULL;
     242    timestamp = "";
     243    std::string username = "";
     244    std::string hostname = "";
     245    char *user = NULL;
     246
     247    tmpBuf.appendf("run%i.xml",(int)time(&t));
     248    file.open(tmpBuf.bytes(),std::ios::out);
     249
     250//    put("tool.version.rappture.revision",
     251//        "$LastChangedRevision: 1527 $");
     252//    put("tool.version.rappture.modified",
     253//        "$LastChangedDate: 2009-06-22 15:38:49 -0400"
     254//        " (Mon, 22 Jun 2009) $");
     255//    if ( "" == get("tool.version.rappture.language") ) {
     256//        put("tool.version.rappture.language","c++");
     257//    }
     258
     259    // generate a timestamp for the run file
     260    timeinfo = localtime(&t);
     261    timestamp = std::string(ctime(&t));
     262    // erase the 24th character because it is a newline
     263    timestamp.erase(24);
     264    // concatinate the timezone
     265    timestamp.append(" ");
     266#ifdef _WIN32
     267    timestamp.append(_tzname[_daylight]);
     268    // username is left blank for windows because i dont know
     269    // how to retrieve username on win32 environment.
     270    username = "";
     271    hostname = "";
     272#else
     273    timestamp.append(timeinfo->tm_zone);
     274    user = getenv("USER");
     275    if (user != NULL) {
     276        username = std::string(user);
     277    } else {
     278        user = getenv("LOGNAME");
     279        if (user != NULL) {
     280            username = std::string(user);
     281        }
     282    }
     283#endif
     284
     285    // add the timestamp to the run file
     286//    put("output.time", timestamp);
     287//    put("output.status",exitStatus);
     288//    put("output.user",username);
     289//    put("output.host",hostname);
     290
     291    if ( file.is_open() ) {
     292        xmlText = xml();
     293        if (xmlText == NULL) {
     294        }
     295        file << xmlText;
     296        // check to make sure there were no
     297        // errors while writing the run.xml file.
     298        if (   (!file.good())
     299            || (strlen(xmlText) != ((long)file.tellp()-(long)1))
     300           ) {
     301             status.error("Error while writing run file");
     302             status.addContext("RpLibrary::result()");
     303        }
     304        file.close();
     305    }
     306    else {
     307        status.error("Error while opening run file");
     308        status.addContext("RpLibrary::result()");
     309    }
     310    std::printf("=RAPPTURE-RUN=>%s\n",outputFile.bytes());
     311}
     312*/
     313
    186314const Rp_Chain *
    187315Library::contains() const
    188316{
    189     return _objList;
    190 }
     317    return _objStorage.contains();
     318}
     319
  • trunk/src/objects/RpLibObj.h

    r1566 r1581  
    3232#include "RpChain.h"
    3333#include "RpParserXML.h"
     34#include "RpLibStorage.h"
     35#include <cstdarg>
    3436
    3537namespace Rappture {
     
    4648
    4749
    48         // Library *value(const char *key, void *storage);
     50        Library &value(const char *key, void *storage,
     51            size_t numHints, ...);
    4952
    5053        // Rp_Chain *diff(Library *lib);
    5154
    52         // Library *remove (const char *key);
     55        // Library &remove (const char *key);
    5356
    5457        const char *xml() const;
    5558
    5659        Outcome &outcome() const;
     60        int error() const;
    5761
    58         // Library *result(int status);
     62        // Outcome &result(int status);
    5963
    6064        const Rp_Chain *contains() const;
    6165    private:
    62         Rp_Chain *_objList;
    63         // Rp_HashTable _objHash;
    64         mutable Rappture::Outcome _status;
     66        LibraryStorage _objStorage;
     67        mutable Outcome _status;
    6568
    6669        void __libInit();
    6770        void __libFree();
    68         void __parseTree2ObjectList(Rp_ParserXml *p, Rp_Chain *retObjList);
     71        void __parseTree2ObjectList(Rp_ParserXml *p);
    6972
    7073}; // end class Library
  • trunk/src/objects/RpNumber.cc

    r1569 r1581  
    2424     _minSet (0),
    2525     _maxSet (0),
     26     _defSet (0),
     27     _curSet (0),
    2628     _presets (NULL)
    2729{
     
    4345     _minSet (0),
    4446     _maxSet (0),
     47     _defSet (0),
     48     _curSet (0),
    4549     _presets (NULL)
    4650{
     
    6973      _minSet (0),
    7074      _maxSet (0),
     75      _defSet (0),
     76      _curSet (0),
    7177      _presets (NULL)
    7278{
     
    110116    : Object (o),
    111117      _minSet (o._minSet),
    112       _maxSet (o._maxSet)
     118      _maxSet (o._maxSet),
     119      _defSet (o._defSet),
     120      _curSet (o._curSet)
    113121{
    114122    this->def(o.def());
     
    139147}
    140148
     149int
     150Number::minset() const
     151{
     152    return _minSet;
     153}
     154
     155int
     156Number::maxset() const
     157{
     158    return _maxSet;
     159}
     160
     161int
     162Number::defset() const
     163{
     164    return _defSet;
     165}
     166
     167int
     168Number::curset() const
     169{
     170    return _curSet;
     171}
     172
    141173/**********************************************************************/
    142174// METHOD: convert()
     
    146178 */
    147179
    148 int
     180Outcome&
    149181Number::convert(const char *to)
    150182{
    151183    const RpUnits* toUnit = NULL;
    152184    const RpUnits* fromUnit = NULL;
    153     double convertedVal = cur();
    154     int err = 0;
     185
     186    _status.addContext("Rappture::Number::convert");
     187
     188    if (to == NULL) {
     189        return _status;
     190    }
     191
     192    if (strcmp(units(),to) == 0) {
     193        return _status;
     194    }
    155195
    156196    // make sure all units functions accept char*'s
    157197    toUnit = RpUnits::find(std::string(to));
    158198    if (!toUnit) {
    159         // should raise error!
    160         // conversion not defined because unit does not exist
    161         return convertedVal;
     199        _status.addError("conversion not defined, unit \"%s\" does not exist",to);
     200        return _status;
    162201    }
    163202
    164203    fromUnit = RpUnits::find(std::string(units()));
    165204    if (!fromUnit) {
    166         // should raise error!
    167         // conversion not defined because unit does not exist
    168         return convertedVal;
     205        _status.addError("conversion not defined, unit \"%s\" does not exist",to);
     206        return _status;
    169207    }
    170208
    171209    // perform the conversion
     210    int err = 0;
     211    double convertedVal;
     212
    172213    convertedVal = fromUnit->convert(toUnit,def(), &err);
    173     if (!err) {
     214    if (err) {
     215        _status.addError("undefined error while converting %s to %s",
     216            (fromUnit->getUnitsName()).c_str(),
     217            (toUnit->getUnitsName()).c_str());
     218    } else {
    174219        def(convertedVal);
    175220    }
    176221
    177222    convertedVal = fromUnit->convert(toUnit,cur(), &err);
    178     if (!err) {
     223    if (err) {
     224        _status.addError("undefined error while converting %s to %s",
     225            (fromUnit->getUnitsName()).c_str(),
     226            (toUnit->getUnitsName()).c_str());
     227    } else {
    179228        cur(convertedVal);
    180229    }
    181230
    182     return err;
     231    return _status;
    183232}
    184233
     
    188237/**
    189238 * does not change the value of the object
    190  * error code is returned
    191  */
    192 
    193 int
    194 Number::value(const char *to, double *value) const
    195 {
    196     return 1;
     239 * error code is set on trouble
     240 */
     241
     242double
     243Number::value(const char *to) const
     244{
     245    const RpUnits* toUnit = NULL;
     246    const RpUnits* fromUnit = NULL;
     247
     248    _status.addContext("Rappture::Number::value");
     249
     250    double val = 0.0;
     251
     252    if (_defSet) {
     253        val = def();
     254    }
     255
     256    if (_curSet) {
     257        val = cur();
     258    }
     259
     260    if (to == NULL) {
     261        return val;
     262    }
     263
     264    if (strcmp(units(),to) == 0) {
     265        return val;
     266    }
     267
     268    // make sure all units functions accept char*'s
     269    toUnit = RpUnits::find(std::string(to));
     270    if (!toUnit) {
     271        _status.addError("conversion not defined, unit \"%s\" does not exist",to);
     272        return val;
     273    }
     274
     275    fromUnit = RpUnits::find(std::string(units()));
     276    if (!fromUnit) {
     277        _status.addError("conversion not defined, unit \"%s\" does not exist",to);
     278        return val;
     279    }
     280
     281    // perform the conversion
     282    int err = 0;
     283    double convertedVal = fromUnit->convert(toUnit,val, &err);
     284    if (err) {
     285        _status.addError("undefined error while converting %s to %s",
     286            (fromUnit->getUnitsName()).c_str(),
     287            (toUnit->getUnitsName()).c_str());
     288        return cur();
     289    }
     290
     291    return convertedVal;
     292}
     293
     294/**********************************************************************/
     295// METHOD: vvalue()
     296/// Get the value of this object based on provided hints
     297/**
     298 * does not change the value of the object
     299 * currently recognized hints:
     300 *  units
     301 * error code is set on trouble
     302 */
     303
     304void
     305Number::vvalue(void *storage, size_t numHints, va_list arg) const
     306{
     307    char buf[1024];
     308    char *hintCopy = NULL;
     309    size_t hintLen = 0;
     310
     311    char *hint = NULL;
     312    const char *hintKey = NULL;
     313    const char *hintVal = NULL;
     314
     315    double *ret = (double *) storage;
     316
     317    *ret = 0.0;
     318
     319    if (_defSet) {
     320        *ret = def();
     321    }
     322
     323    if (_curSet) {
     324        *ret = cur();
     325    }
     326
     327    while (numHints > 0) {
     328        numHints--;
     329        hint = va_arg(arg, char *);
     330        hintLen = strlen(hint);
     331        if (hintLen < 1024) {
     332            hintCopy = buf;
     333        } else {
     334            // buf too small, allocate some space
     335            hintCopy = new char[hintLen];
     336        }
     337        strcpy(hintCopy,hint);
     338
     339        // parse the hint into a key and value
     340        __hintParser(hintCopy,&hintKey,&hintVal);
     341
     342        // evaluate the hint key
     343        if (('u' == *hintKey) &&
     344            (strcmp("units",hintKey) == 0)) {
     345            *ret = value(hintVal);
     346
     347        }
     348
     349        if (hintCopy != buf) {
     350            // clean up memory
     351            delete hintCopy;
     352        }
     353    }
     354    return;
    197355}
    198356
     
    300458}
    301459
    302 /**********************************************************************/
    303 // METHOD: configure(ClientData c)
    304 /// construct a number object from the provided tree
    305 /**
    306  * construct a number object from the provided tree
    307  */
    308 
    309 void
    310 Number::configure(size_t as, ClientData c)
    311 {
    312     if (as == RPCONFIG_XML) {
    313         __configureFromXml(c);
    314     } else if (as == RPCONFIG_TREE) {
    315         __configureFromTree(c);
    316     }
    317 }
    318 
    319 /**********************************************************************/
    320 // METHOD: configureFromXml(const char *xmltext)
    321 /// configure the object based on Rappture1.1 xmltext
    322 /**
    323  * Configure the object based on the provided xml
    324  */
    325 
    326 void
    327 Number::__configureFromXml(ClientData c)
    328 {
    329     const char *xmltext = (const char *)c;
    330     if (xmltext == NULL) {
    331         // FIXME: setup error
    332         return;
    333     }
    334 
    335     Rp_ParserXml *p = Rp_ParserXmlCreate();
    336     Rp_ParserXmlParse(p, xmltext);
    337     configure(RPCONFIG_TREE, p);
    338 
    339     return;
    340 }
    341 
    342460void
    343461Number::__configureFromTree(ClientData c)
     
    394512
    395513/**********************************************************************/
    396 // METHOD: dump(size_t as, void *p)
    397 /// construct a number object from the provided tree
    398 /**
    399  * construct a number object from the provided tree
    400  */
    401 
    402 void
    403 Number::dump(size_t as, ClientData p)
    404 {
    405     if (as == RPCONFIG_XML) {
    406         __dumpToXml(p);
    407     } else if (as == RPCONFIG_TREE) {
    408         __dumpToTree(p);
    409     }
    410 }
    411 
    412 /**********************************************************************/
    413 // METHOD: dumpToXml(ClientData p)
    414 /// configure the object based on Rappture1.1 xmltext
    415 /**
    416  * Configure the object based on the provided xml
    417  */
    418 
    419 void
    420 Number::__dumpToXml(ClientData c)
     514// METHOD: dumpToTree(ClientData p)
     515/// dump the object to a Rappture1.1 based tree
     516/**
     517 * Dump the object to a Rappture1.1 based tree
     518 */
     519
     520void
     521Number::__dumpToTree(ClientData c)
    421522{
    422523    if (c == NULL) {
     
    425526    }
    426527
    427     ClientDataXml *d = (ClientDataXml *)c;
    428     Rp_ParserXml *parser = Rp_ParserXmlCreate();
    429     __dumpToTree(parser);
    430     _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser));
    431     d->retStr = _tmpBuf.bytes();
    432     Rp_ParserXmlDestroy(&parser);
    433 }
    434 
    435 /**********************************************************************/
    436 // METHOD: dumpToTree(ClientData p)
    437 /// dump the object to a Rappture1.1 based tree
    438 /**
    439  * Dump the object to a Rappture1.1 based tree
    440  */
    441 
    442 void
    443 Number::__dumpToTree(ClientData c)
    444 {
    445     if (c == NULL) {
    446         // FIXME: setup error
    447         return;
    448     }
    449 
    450528    Rp_ParserXml *parser = (Rp_ParserXml *)c;
    451529
     
    463541    Rp_ParserXmlPutF(parser,p.path(),"%s",label());
    464542
     543    p.type("description");
     544    Rp_ParserXmlPutF(parser,p.path(),"%s",desc());
     545
    465546    p.del();
    466     p.add("description");
    467     Rp_ParserXmlPutF(parser,p.path(),"%s",desc());
    468 
    469     p.del();
    470     p.del();
    471     p.add("units");
     547    p.type("units");
    472548    Rp_ParserXmlPutF(parser,p.path(),"%s",units());
    473549
    474550
    475551    if (_minSet) {
    476         p.del();
    477         p.add("min");
    478         Rp_ParserXmlPutF(parser,p.path(),"%g",min());
     552        p.type("min");
     553        Rp_ParserXmlPutF(parser,p.path(),"%g%s",min(),units());
    479554    }
    480555
    481556    if (_maxSet) {
    482         p.del();
    483         p.add("max");
    484         Rp_ParserXmlPutF(parser,p.path(),"%g",max());
    485     }
    486 
    487     p.del();
    488     p.add("default");
    489     Rp_ParserXmlPutF(parser,p.path(),"%g",def());
    490 
    491     p.del();
    492     p.add("current");
    493     Rp_ParserXmlPutF(parser,p.path(),"%g",cur());
    494 
    495     // still need to add presets
     557        p.type("max");
     558        Rp_ParserXmlPutF(parser,p.path(),"%g%s",max(),units());
     559    }
     560
     561    p.type("default");
     562    Rp_ParserXmlPutF(parser,p.path(),"%g%s",def(),units());
     563
     564    p.type("current");
     565    Rp_ParserXmlPutF(parser,p.path(),"%g%s",cur(),units());
     566
     567    // process presets
     568    p.type("preset");
     569    p.add("label");
     570    Rp_ChainLink *l = Rp_ChainFirstLink(_presets);
     571    while (l != NULL) {
     572        struct preset *presetObj = (struct preset *) Rp_ChainGetValue(l);
     573
     574        p.type("label");
     575        Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->label());
     576        //p.type("description");
     577        //Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->desc());
     578        // p.type("units");
     579        // Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->units());
     580        p.type("value");
     581        Rp_ParserXmlPutF(parser,p.path(),"%g%s",presetObj->val(),presetObj->units());
     582
     583        p.prev();
     584        p.degree(p.degree()+1);
     585        p.next();
     586
     587        l = Rp_ChainNextLink(l);
     588    }
     589
    496590    return;
    497591}
     
    512606
    513607
     608void
     609Number::__convertFromString(
     610    const char *val,
     611    double *ret)
     612{
     613    if (val == NULL) {
     614        return;
     615    }
     616
     617    if (ret == NULL) {
     618        return;
     619    }
     620
     621    double numericVal = 0.0;
     622    if (units()) {
     623        // convert the provided string into
     624        // the objects default units
     625        int err = 0;
     626        std::string strVal;
     627        strVal = RpUnits::convert(val,units(),RPUNITS_UNITS_OFF,&err);
     628        if (err) {
     629            _status.addError("Unknown error while converting units");
     630        }
     631
     632        char *endPtr = NULL;
     633        numericVal = strtod(strVal.c_str(),&endPtr);
     634        if (endPtr == strVal.c_str()) {
     635            // no conversion was performed
     636            _status.addError("Could not convert \"%s\" into a number",
     637                strVal.c_str());
     638        } else if (endPtr == (strVal.c_str()+strVal.length())) {
     639            *ret = numericVal;
     640        } else {
     641            // the whole string could not be converted to a number
     642            // signal error?
     643            _status.addError("Could not convert \"%s\" of \"%s\"into a number",
     644                endPtr, strVal.c_str());
     645        }
     646    } else {
     647        // try to figure out the units
     648        // store units and return the numeric value to the user
     649        const char *foundUnits = NULL;
     650        __valUnitsSplit(val,&numericVal,&foundUnits);
     651        units(foundUnits);
     652        *ret = numericVal;
     653    }
     654
     655}
     656
     657void
     658Number::__valUnitsSplit(
     659    const char *inStr,
     660    double *val,
     661    const char **units)
     662{
     663    if (inStr == NULL) {
     664        return;
     665    }
     666
     667    if (val == NULL) {
     668        return;
     669    }
     670
     671    if (units == NULL) {
     672        return;
     673    }
     674
     675    char *endPtr = NULL;
     676    *val = strtod(inStr,&endPtr);
     677    if (endPtr == inStr) {
     678        // no conversion was performed
     679        _status.addError("Could not convert \"%s\" into a number", inStr);
     680    } else if (endPtr == (inStr+strlen(inStr))) {
     681        // the whole string was used in the numeric conversion
     682        // set units to NULL
     683        *units = NULL;
     684    } else {
     685        // the whole string could not be converted to a number
     686        // we assume the rest of the string are the units
     687        *units = endPtr;
     688    }
     689}
     690
    514691/**********************************************************************/
    515692// METHOD: minFromStr()
     
    524701{
    525702    double numericVal = 0;
    526     int err = 0;
    527 
    528     numericVal = rpConvertDbl(val,units(),&err);
    529 
    530     if (!err) {
     703
     704    if (val == NULL) {
     705        return;
     706    }
     707
     708    __convertFromString(val,&numericVal);
     709
     710    if (!_status) {
    531711        min(numericVal);
    532     } else {
    533         // FIXME: add error code
    534     }
     712        _minSet = 1;
     713    }
     714
    535715}
    536716
     
    547727{
    548728    double numericVal = 0;
    549     int err = 0;
    550 
    551     numericVal = rpConvertDbl(val,units(),&err);
    552 
    553     if (!err) {
     729
     730    if (val == NULL) {
     731        return;
     732    }
     733
     734    __convertFromString(val,&numericVal);
     735
     736    if (!_status) {
    554737        max(numericVal);
    555     } else {
    556         // FIXME: add error code
    557     }
     738        _maxSet = 1;
     739    }
     740
    558741}
    559742
     
    570753{
    571754    double numericVal = 0;
    572     int err = 0;
    573 
    574     numericVal = rpConvertDbl(val,units(),&err);
    575 
    576     if (!err) {
     755
     756    if (val == NULL) {
     757        return;
     758    }
     759
     760    __convertFromString(val,&numericVal);
     761
     762    if (!_status) {
    577763        def(numericVal);
    578     } else {
    579         // FIXME: add error code
    580     }
     764        _defSet = 1;
     765    }
     766
    581767}
    582768
     
    593779{
    594780    double numericVal = 0;
    595     int err = 0;
    596 
    597     numericVal = rpConvertDbl(val,units(),&err);
    598 
    599     if (!err) {
     781
     782    if (val == NULL) {
     783        return;
     784    }
     785
     786    __convertFromString(val,&numericVal);
     787
     788    if (!_status) {
    600789        cur(numericVal);
    601     } else {
    602         // FIXME: add error code
    603     }
     790        _curSet = 1;
     791    }
     792
    604793}
    605794
  • trunk/src/objects/RpNumber.h

    r1569 r1581  
    3939        void units(const char *p);
    4040
     41        int minset() const;
     42        int maxset() const;
     43        int defset() const;
     44        int curset() const;
     45
    4146        // convert the value stored in this object to specified units
    4247        // does not return the converted value
    4348        // error code is returned
    44         int convert(const char *to);
     49        Outcome& convert(const char *to);
    4550
    4651        // get the value of this object converted to specified units
    4752        // does not change the value of the object
    4853        // error code is returned
    49         int value(const char *units, double *value) const;
     54        double value(const char *units) const;
     55        void vvalue(void *storage, size_t numHints, va_list arg) const;
    5056
    5157        Number& addPreset(const char *label, const char *desc,
     
    5763        Number& delPreset(const char *label);
    5864
    59 
    60         void configure(size_t as, ClientData c);
    61         void dump(size_t as, ClientData c);
    6265
    6366        const int is() const;
     
    7376        int _minSet;
    7477        int _maxSet;
     78        int _defSet;
     79        int _curSet;
    7580
    7681        // hash or linked list of preset values
     
    8489        };
    8590
    86         void __configureFromXml(ClientData c);
    8791        void __configureFromTree(ClientData c);
    88         void __dumpToXml(ClientData c);
    8992        void __dumpToTree(ClientData c);
     93
     94        void __convertFromString(const char *val, double *ret);
     95        void __valUnitsSplit( const char *inStr, double *val,
     96                const char **units);
    9097};
    9198
  • trunk/src/objects/RpObject.cc

    r1569 r1581  
    1616#include "RpObject.h"
    1717#include "RpHashHelper.h"
     18#include <cstring>
    1819
    1920using namespace Rappture;
     
    251252    delete[] tmp;
    252253    tmp = NULL;
     254    return;
     255}
     256
     257void
     258Object::__hintParser(
     259    char *hint,
     260    const char **hintKey,
     261    const char **hintVal) const
     262{
     263
     264    // hints are null terminated strings with a hint key
     265    // and hint value separated by an equal sign.
     266    // they take the following form:
     267    // hintKey=hintVal
     268    // this function does change the original hint string.
     269
     270    char *v = NULL;
     271
     272    if (hint == NULL) {
     273        return;
     274    }
     275
     276    v = strchrnul(hint,'=');
     277    *hintKey = hint;
     278    if ((*v == '\0') || (*(v+1) == '\0')) {
     279        // incomplete hint string
     280        *hintVal = NULL;
     281    } else {
     282        *v = '\0';
     283        *hintVal = v+1;
     284    }
     285
     286    return;
     287}
     288
     289void
     290Object::vvalue(void *storage, size_t numHints, va_list arg) const
     291{
     292    // bland objects take no hints
     293    char buf[1024];
     294    char *hintCopy = NULL;
     295    size_t hintLen = 0;
     296
     297    char *hint = NULL;
     298    const char *hintKey = NULL;
     299    const char *hintVal = NULL;
     300
     301    while (numHints > 0) {
     302        numHints--;
     303        hint = va_arg(arg, char *);
     304        hintLen = strlen(hint);
     305        if (hintLen < 1024) {
     306            hintCopy = buf;
     307        } else {
     308            hintCopy = new char[hintLen+1];
     309        }
     310        strcpy(hintCopy,hint);
     311        __hintParser(hintCopy,&hintKey,&hintVal);
     312        if (hintCopy != buf) {
     313            delete hintCopy;
     314        }
     315    }
    253316    return;
    254317}
     
    297360}
    298361
     362/*
    299363const char *
    300364Object::xml(size_t indent, size_t tabstop) const
     
    302366    return NULL;
    303367}
     368*/
    304369
    305370/*
     
    311376*/
    312377
     378/**********************************************************************/
     379// METHOD: configure(ClientData c)
     380/// construct an object from the provided tree
     381/**
     382 * construct an object from the provided tree
     383 */
     384
    313385void
    314386Object::configure(size_t as, ClientData c)
    315387{
    316     return;
    317 }
    318 
    319 void
    320 Object::dump(size_t as, ClientData c)
    321 {
    322     return;
     388    if (as == RPCONFIG_XML) {
     389        __configureFromXml(c);
     390    } else if (as == RPCONFIG_TREE) {
     391        __configureFromTree(c);
     392    }
     393}
     394
     395/**********************************************************************/
     396// METHOD: configureFromXml(const char *xmltext)
     397/// configure the object based on Rappture1.1 xmltext
     398/**
     399 * Configure the object based on the provided xml
     400 */
     401
     402void
     403Object::__configureFromXml(ClientData c)
     404{
     405    const char *xmltext = (const char *)c;
     406    if (xmltext == NULL) {
     407        // FIXME: setup error
     408        return;
     409    }
     410
     411    Rp_ParserXml *p = Rp_ParserXmlCreate();
     412    Rp_ParserXmlParse(p, xmltext);
     413    __configureFromTree(p);
     414
     415    return;
     416}
     417
     418void
     419Object::__configureFromTree(ClientData c)
     420{
     421    Rp_ParserXml *p = (Rp_ParserXml *)c;
     422    if (p == NULL) {
     423        // FIXME: setup error
     424        return;
     425    }
     426
     427    Rp_TreeNode node = Rp_ParserXmlElement(p,NULL);
     428
     429    Rappture::Path pathObj(Rp_ParserXmlNodePath(p,node));
     430
     431    path(pathObj.parent());
     432    name(Rp_ParserXmlNodeId(p,node));
     433
     434    pathObj.clear();
     435    pathObj.add("about");
     436    pathObj.add("label");
     437    label(Rp_ParserXmlGet(p,pathObj.path()));
     438    pathObj.type("description");
     439    desc(Rp_ParserXmlGet(p,pathObj.path()));
     440    pathObj.type("hints");
     441    hints(Rp_ParserXmlGet(p,pathObj.path()));
     442    pathObj.type("color");
     443    color(Rp_ParserXmlGet(p,pathObj.path()));
     444
     445    return;
     446}
     447
     448/**********************************************************************/
     449// METHOD: dump(size_t as, void *p)
     450/// construct a number object from the provided tree
     451/**
     452 * construct a number object from the provided tree
     453 */
     454
     455void
     456Object::dump(size_t as, ClientData p)
     457{
     458    if (as == RPCONFIG_XML) {
     459        __dumpToXml(p);
     460    } else if (as == RPCONFIG_TREE) {
     461        __dumpToTree(p);
     462    }
     463}
     464
     465/**********************************************************************/
     466// METHOD: dumpToXml(ClientData p)
     467/// configure the object based on Rappture1.1 xmltext
     468/**
     469 * Configure the object based on the provided xml
     470 */
     471
     472void
     473Object::__dumpToXml(ClientData c)
     474{
     475    if (c == NULL) {
     476        // FIXME: setup error
     477        return;
     478    }
     479
     480    ClientDataXml *d = (ClientDataXml *)c;
     481    Rp_ParserXml *parser = Rp_ParserXmlCreate();
     482    __dumpToTree(parser);
     483    _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser));
     484    d->retStr = _tmpBuf.bytes();
     485    Rp_ParserXmlDestroy(&parser);
     486}
     487
     488/**********************************************************************/
     489// METHOD: dumpToTree(ClientData p)
     490/// dump the object to a Rappture1.1 based tree
     491/**
     492 * Dump the object to a Rappture1.1 based tree
     493 */
     494
     495void
     496Object::__dumpToTree(ClientData c)
     497{
     498    if (c == NULL) {
     499        // FIXME: setup error
     500        return;
     501    }
     502
     503    Rp_ParserXml *parser = (Rp_ParserXml *)c;
     504
     505    Path p;
     506
     507    p.parent(path());
     508    p.last();
     509
     510    p.add("object");
     511    p.id(name());
     512
     513    p.add("about");
     514
     515    p.add("label");
     516    Rp_ParserXmlPutF(parser,p.path(),"%s",label());
     517
     518    p.type("description");
     519    Rp_ParserXmlPutF(parser,p.path(),"%s",desc());
     520
     521    p.type("hints");
     522    Rp_ParserXmlPutF(parser,p.path(),"%s", hints());
     523
     524    p.type("color");
     525    Rp_ParserXmlPutF(parser,p.path(),"%s", color());
     526
     527    return;
     528}
     529
     530Outcome &
     531Object::outcome() const
     532{
     533    return _status;
    323534}
    324535
  • trunk/src/objects/RpObject.h

    r1569 r1581  
    1414#include "RpInt.h"
    1515#include "RpHash.h"
     16#include "RpOutcome.h"
    1617#include "RpAccessor.h"
    1718#include "RpBuffer.h"
     
    1920#include "RpParserXML.h"
    2021#include "RpObjConfig.h"
     22#include <cstdarg>
    2123
    2224namespace Rappture {
     
    7173        void propremove (const char *key);
    7274
     75        // return the value of object based on provided hints
     76        virtual void vvalue (void *storage, size_t numHints, va_list arg) const;
     77
    7378        // get the Rappture1.1 xml text for this object
    74         virtual const char *xml(size_t indent, size_t tabstop) const;
    75 
    76         // set the object properties based on Rappture1.1 xml text
    77         // virtual void xml(const char *xmltext);
     79        // virtual const char *xml(size_t indent, size_t tabstop) const;
    7880
    7981        // configure the object properties based on Rappture1.1 xml text
     
    8183        virtual void dump(size_t as, ClientData c);
    8284
     85        virtual Outcome &outcome() const;
    8386        virtual const int is() const;
    8487
     
    8891        SimpleCharBuffer _tmpBuf;
    8992
     93        /// status of the object
     94        mutable Rappture::Outcome _status;
     95
     96        virtual void __hintParser(char *hint,
     97            const char **hintKey, const char **hintVal) const;
     98
     99        virtual void __configureFromXml(ClientData c);
     100        virtual void __configureFromTree(ClientData c);
     101        virtual void __dumpToXml(ClientData c);
     102        virtual void __dumpToTree(ClientData c);
    90103    private:
    91104
  • trunk/src/objects/RpParserXML.cc

    r1568 r1581  
    7070    Rp_TreeGetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE,(void **)&value);
    7171
    72     // strip trailing spaces
    73     int i = 0;
    74     for (i = strlen(value)-1; i >= 0; i--) {
    75         if (isspace(value[i])) {
    76             value[i] = '\0';
    77         } else {
    78             break;
    79         }
    80     }
    81 
    82     // strip leading spaces
    83     int j = 0;
    84     for (j = 0; j < i; j++) {
    85         if (isspace(value[j])) {
    86             value[j] = '\0';
    87         } else {
    88             break;
    89         }
    90     }
    91 
    92     if (j > 0) {
    93         // reallocate the trimmed string
    94         char *newValue = new char[i-j+1+1];
    95         strcpy(newValue,value+j);
    96         Rp_TreeSetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE,(void *)newValue);
    97         delete value;
    98         value = NULL;
     72    if (value != NULL) {
     73        // strip trailing spaces
     74        int i = 0;
     75        for (i = strlen(value)-1; i >= 0; i--) {
     76            if (isspace(value[i])) {
     77                value[i] = '\0';
     78            } else {
     79                break;
     80            }
     81        }
     82
     83        // strip leading spaces
     84        int j = 0;
     85        for (j = 0; j < i; j++) {
     86            if (isspace(value[j])) {
     87                value[j] = '\0';
     88            } else {
     89                break;
     90            }
     91        }
     92
     93        if (j > 0) {
     94            // reallocate the trimmed string
     95            char *newValue = new char[i-j+1+1];
     96            strcpy(newValue,value+j);
     97            Rp_TreeSetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE,
     98                (void *)newValue);
     99            delete value;
     100            value = NULL;
     101        }
    99102    }
    100103
     
    218221}
    219222
     223int
     224Rp_ParserXmlNodeIdentify(
     225    Rp_ParserXml *p,
     226    Rp_TreeNode n,
     227    const char *name,
     228    const char *id)
     229{
     230    int criteriaMet = 0;
     231    int criteriaTotal = 0;
     232
     233    if (n) {
     234        if (name) {
     235            criteriaTotal++;
     236            if (strcmp(name,Rp_TreeNodeLabel(n)) == 0) {
     237                criteriaMet++;
     238            }
     239        }
     240        if (id) {
     241            criteriaTotal++;
     242            const char *nodeId = NULL;
     243            Rp_TreeGetValue(p->tree,n,Rp_ParserXml_Field_ID,
     244                (void **)&nodeId);
     245            if (strcmp(id,nodeId) == 0) {
     246                criteriaMet++;
     247            }
     248        }
     249    }
     250
     251    // check if all of the eligable criteria have been met
     252    int retVal = 0;
     253    if (criteriaMet == criteriaTotal) {
     254        retVal = 0;
     255    } else {
     256        retVal = 1;
     257    }
     258
     259    return retVal;
     260
     261}
     262
     263void
     264Rp_ParserXmlFindChild(
     265    Rp_ParserXml *p,
     266    Rp_TreeNode parent,
     267    const char *childName,
     268    const char *childId,
     269    size_t degree,
     270    Rp_TreeNode *child,
     271    size_t *numFound)
     272{
     273    // this function is only concerned with the question:
     274    // is a node with a matching name, id, and degree a
     275    // child of the provided parent node?
     276    // if so return it.
     277    // this function does not create new nodes.
     278
     279    if (child == NULL) {
     280        return;
     281    }
     282
     283    if (numFound == NULL) {
     284        return;
     285    }
     286
     287    *numFound = 0;
     288    *child = Rp_TreeFindChild(parent,childName);
     289    if (*child == NULL) {
     290        // no nodes with the name childName exist
     291        return;
     292    }
     293
     294    while (*child != NULL) {
     295        if (Rp_ParserXmlNodeIdentify(p,*child,childName,childId) == 0) {
     296            // found a child with the correct name and id
     297            (*numFound)++;
     298            if (degree == *numFound) {
     299                // found a node with the correct degree
     300                break;
     301            }
     302        }
     303
     304        // check the next child for the correct name and id
     305        *child = Rp_TreeNextSibling(*child);
     306    }
     307
     308    return;
     309}
     310
    220311Rp_TreeNode
    221312Rp_ParserXmlSearch(
     
    227318    Rp_TreeNode parent = NULL;
    228319    Rp_TreeNode child = NULL;
    229     size_t degree = 0;
    230320
    231321    if (p == NULL) {
     
    244334
    245335        const char *childName = pathObj.type();
    246         const char *searchChildId = pathObj.id();
    247 
    248         child = Rp_TreeFindChild(parent,childName);
     336        const char *childId = pathObj.id();
     337        size_t childDegree = pathObj.degree();
     338
     339        size_t foundCnt = 0;
     340        Rp_ParserXmlFindChild(p, parent, childName, childId,
     341            childDegree, &child, &foundCnt);
     342
    249343        if (child == NULL) {
    250344            // no nodes with the name childName exist
    251345            // FIXME: use the RPXML_CREATE flag
    252346            if (create) {
    253                 for (size_t i = 1; i <= pathObj.degree(); i++) {
     347                for (size_t i = foundCnt; i < pathObj.degree(); i++) {
    254348                    child = Rp_ParserXmlCreateNode(p, parent,
    255                                 childName, searchChildId);
     349                                childName, childId);
    256350                    if (child == NULL) {
     351                        // error while creating the child node
     352                        // signal error
    257353                        break;
    258354                    }
    259355                }
    260356            } else {
    261                 fprintf(stderr,"invalid path %s at %s\n",path,childName);
     357                // fprintf(stderr,"invalid path %s at %s\n",path,childName);
    262358                break;
    263359            }
    264         }
    265 
    266         //FIXME: rewrite the child id search logic
    267         const char *id = NULL;
    268         Rp_TreeGetValue(p->tree,child, Rp_ParserXml_Field_ID,(void **)&id);
    269         while (searchChildId && id) {
    270 
    271             // check for matching child id and degree
    272             if ((*searchChildId == *id) &&
    273                 (strcmp(searchChildId,id) == 0)) {
    274                 // found child with matching id
    275                 // check degree
    276                 degree++;
    277                 if (degree == pathObj.degree()) {
    278                     // degrees match, return result
    279                     break;
    280                 }
    281             }
    282 
    283             // check the next child to see if it has the correct id
    284             child = Rp_TreeNextSibling(child);
    285             if (child == NULL) {
    286                 // end of the sibling list
    287                 // create new node? or return NULL pointer
    288                 // FIXME: use the RPXML_CREATE flag
    289                 if (create) {
    290                     child = Rp_ParserXmlCreateNode(p, parent,
    291                                 childName, searchChildId);
    292                     if (child == NULL) {
    293                         break;
    294                     }
    295                 } else {
    296                     // exit, child not found
    297                     break;
    298                 }
    299             }
    300             id = NULL;
    301             Rp_TreeGetValue(p->tree,child,Rp_ParserXml_Field_ID,(void **)&id);
    302360        }
    303361
  • trunk/src/objects/RpParserXML.h

    r1566 r1581  
    2929
    3030void Rp_ParserXmlParse(Rp_ParserXml *p, const char *xml);
     31int Rp_ParserXmlNodeIdentify(Rp_ParserXml *p, Rp_TreeNode n,
     32    const char *name, const char *id);
     33void Rp_ParserXmlFindChild( Rp_ParserXml *p, Rp_TreeNode parent,
     34    const char *childName, const char *childId, size_t degree,
     35    Rp_TreeNode *child, size_t *numFound);
    3136Rp_TreeNode Rp_ParserXmlSearch( Rp_ParserXml *p, const char *path, int create);
    3237const char *Rp_ParserXmlGet(Rp_ParserXml *p, const char *path);
  • trunk/src/objects/RpPath.cc

    r1569 r1581  
    134134Path::__createComponent(
    135135    const char *p,
    136     int start,
    137     int end,
     136    int typeStart,
     137    int typeEnd,
    138138    int idOpenParen,
    139139    int idCloseParen,
     
    149149    c->degree = degree;
    150150
     151    typeLen = typeEnd - typeStart;
    151152    if (idOpenParen < idCloseParen) {
    152153        // user specified an id
    153         typeLen = idOpenParen - start;
    154154        idLen = idCloseParen - idOpenParen - 1;
    155     } else {
    156         // no id found
    157         typeLen = end - start;
    158155    }
    159156
     
    183180    if (typeLen >= 0) {
    184181        tmp = new char[typeLen+1];
    185         strncpy(tmp,(p+start),typeLen);
     182        strncpy(tmp,(p+typeStart),typeLen);
    186183        tmp[typeLen] = '\0';
    187184        c->type = tmp;
     
    215212Path::__parse(const char *p)
    216213{
    217     int start = 0;
    218     int end = 0;
     214    int typeStart = 0;
     215    int typeEnd = -1;       // typeEnd must be less than typeStart
     216                            // so we can check if there was a type
     217    int curr = 0;
    219218    int idOpenParen = -1;
    220219    int idCloseParen = -1;
     
    229228    }
    230229
    231     while (p[end] != '\0') {
    232         if (p[end] == '(') {
    233             idOpenParen = end;
    234         } else if (p[end] == ')') {
    235             idCloseParen = end;
     230    while (p[curr] != '\0') {
     231        if (p[curr] == '(') {
     232            idOpenParen = curr;
     233            typeEnd = curr;
     234        } else if (p[curr] == ')') {
     235            idCloseParen = curr;
    236236        } else if ( (idOpenParen <= idCloseParen) &&
    237                     (end != 0) &&
    238                     (p[end] >= '0') &&
    239                     (p[end] <= '9') ) {
    240             degree = (size_t) strtod(p+end, &newEnd);
     237                    (curr != 0) &&
     238                    (p[curr] >= '0') &&
     239                    (p[curr] <= '9') ) {
     240            // we are not inside the parens
     241            // we are not at the start of the string
     242            // the value is a digit
     243            if (idOpenParen == idCloseParen) {
     244                // we are before any possible parens
     245                // and after the type
     246                typeEnd = curr;
     247            }
     248            degree = (size_t) strtod(p+curr, &newEnd);
    241249            if (degree == 0) {
    242250                // interpret degree of 0 same as degree of 1
     
    247255                newEnd -= 2;
    248256            }
    249             end += newEnd - (p + end);
    250         } else if (p[end] == _ifs) {
    251             c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree);
     257            curr += newEnd - (p + curr);
     258        } else if ( (p[curr] == _ifs) &&
     259                    ((idOpenParen == idCloseParen) ||
     260                     (idOpenParen < idCloseParen)) ) {
     261            // we see the _ifs
     262            // we are not inside of the parens for the id tag
     263            if (typeEnd < typeStart) {
     264                // we didn't come across the end
     265                // of the type string, so set it here.
     266                typeEnd = curr;
     267            }
     268            c = __createComponent(p,typeStart,typeEnd,idOpenParen,idCloseParen,degree);
    252269            if (c != NULL) {
    253270                Rp_ChainAppend(compList,c);
    254271            }
    255272
    256             start = end+1;
     273            typeStart = curr+1;
    257274            idOpenParen = -1;
    258275            idCloseParen = -1;
    259         }
    260         end++;
    261     }
    262 
    263     c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree);
     276            degree = 1;
     277        }
     278        curr++;
     279    }
     280
     281    if (typeEnd < typeStart) {
     282        // < takes care of cases where there is no
     283        // id and no degree, but there is still a type
     284        typeEnd = curr;
     285    }
     286    c = __createComponent(p,typeStart,typeEnd,idOpenParen,idCloseParen,degree);
    264287    if (c != NULL) {
    265288        Rp_ChainAppend(compList,c);
     
    291314                b.append(c->type,len);
    292315            }
     316        }
     317
     318        if (c->degree > 1) {
     319            b.appendf("%i",c->degree);
    293320        }
    294321
     
    428455    Rp_ChainLink *l = NULL;
    429456
    430     /*
    431     tmpBuf.clear();
    432 
    433     if (_pathList == NULL) {
    434         tmpBuf.append("\0",1);
    435         return tmpBuf.bytes();
    436     }
    437 
    438     l = _currLink;
    439 
    440     if (l == NULL) {
    441         tmpBuf.append("\0",1);
    442         return tmpBuf.bytes();
    443     }
    444 
    445     componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
    446 
    447     if (c == NULL) {
    448         tmpBuf.append("\0",1);
    449         return tmpBuf.bytes();
    450     }
    451 
    452     if (c->type != NULL) {
    453         tmpBuf.appendf("%s",c->type);
    454     }
    455 
    456     if (c->degree != 1) {
    457         tmpBuf.appendf("%zu",c->degree);
    458     }
    459 
    460     if (c->id != NULL) {
    461         tmpBuf.appendf("(%s)",c->id);
    462     }
    463 
    464     // incase none of the above if statements are hit.
    465     tmpBuf.append("\0",1);
    466 
    467     return tmpBuf.bytes();
    468     */
    469 
    470 
    471457    if (_pathList == NULL) {
    472458        return NULL;
     
    571557{
    572558    Rp_ChainLink *l = NULL;
    573 
    574     /*
    575     tmpBuf.clear();
    576 
    577     if (_pathList == NULL) {
    578         tmpBuf.append("\0",1);
    579         return tmpBuf.bytes();
    580     }
    581 
    582     l = _currLink;
    583 
    584     if (l == NULL) {
    585         tmpBuf.append("\0",1);
    586         return tmpBuf.bytes();
    587     }
    588 
    589     componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
    590 
    591     if (c == NULL) {
    592         tmpBuf.append("\0",1);
    593         return tmpBuf.bytes();
    594     }
    595 
    596     if (c->id) {
    597         tmpBuf.append(c->id);
    598     }
    599 
    600     tmpBuf.append("\0",1);
    601 
    602     return tmpBuf.bytes();
    603     */
    604559
    605560    if (_pathList == NULL) {
     
    664619    Rp_ChainLink *l = NULL;
    665620
    666     /*
    667     tmpBuf.clear();
    668 
    669     if (_pathList == NULL) {
    670         tmpBuf.append("\0",1);
    671         return tmpBuf.bytes();
    672     }
    673 
    674     l = _currLink;
    675 
    676     if (l == NULL) {
    677         tmpBuf.append("\0",1);
    678         return tmpBuf.bytes();
    679     }
    680 
    681     componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);
    682 
    683     if (c == NULL) {
    684         tmpBuf.append("\0",1);
    685         return tmpBuf.bytes();
    686     }
    687 
    688     if (c->type) {
    689         tmpBuf.append(c->type);
    690     }
    691 
    692     tmpBuf.append("\0",1);
    693 
    694     return tmpBuf.bytes();
    695     */
    696 
    697621    if (_pathList == NULL) {
    698622        return NULL;
  • trunk/src/objects/RpPlot.cc

    r1569 r1581  
    249249}
    250250
    251 /**********************************************************************/
    252 // METHOD: configure(Rp_ParserXml *c)
    253 /// construct a number object from the provided tree
    254 /**
    255  * construct a number object from the provided tree
    256  */
    257 
    258 void
    259 Plot::configure(size_t as, ClientData c)
    260 {
    261     if (as == RPCONFIG_XML) {
    262         __configureFromXml(c);
    263     } else if (as == RPCONFIG_TREE) {
    264         __configureFromTree(c);
    265     }
    266 }
    267 
    268 /**********************************************************************/
    269 // METHOD: configureFromXml(const char *xmltext)
    270 /// configure the object based on Rappture1.1 xmltext
    271 /**
    272  * Configure the object based on the provided xml
    273  */
    274 
    275 void
    276 Plot::__configureFromXml(ClientData c)
    277 {
    278     const char *xmltext = (const char *) c;
    279     if (xmltext == NULL) {
    280         // FIXME: setup error
    281         return;
    282     }
    283 
    284     Rp_ParserXml *p = Rp_ParserXmlCreate();
    285     Rp_ParserXmlParse(p, xmltext);
    286     configure(RPCONFIG_TREE, p);
    287 
    288     return;
    289 }
     251
     252/**********************************************************************/
     253// METHOD: configureFromTree(ClientData p)
     254/// configure the object from a Rappture1.1 based tree
     255/**
     256 * Configure the object from a Rappture1.1 based tree
     257 */
    290258
    291259// FIXME: this is an incomplete definition of how to
     
    309277
    310278    return;
    311 }
    312 
    313 /**********************************************************************/
    314 // METHOD: dump(size_t as, void *p)
    315 /// construct a number object from the provided tree
    316 /**
    317  * construct a number object from the provided tree
    318  */
    319 
    320 void
    321 Plot::dump(size_t as, ClientData c)
    322 {
    323     if (as == RPCONFIG_XML) {
    324         __dumpToXml(c);
    325     } else if (as == RPCONFIG_TREE) {
    326         __dumpToTree(c);
    327     }
    328 }
    329 
    330 /**********************************************************************/
    331 // METHOD: dumpToXml(ClientData c)
    332 /// configure the object based on Rappture1.1 xmltext
    333 /**
    334  * Configure the object based on the provided xml
    335  */
    336 
    337 void
    338 Plot::__dumpToXml(ClientData c)
    339 {
    340     if (c == NULL) {
    341         // FIXME: setup error
    342         return;
    343     }
    344 
    345     ClientDataXml *d = (ClientDataXml *) c;
    346     Rp_ParserXml *parser = Rp_ParserXmlCreate();
    347     __dumpToTree(parser);
    348     _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser));
    349     d->retStr = _tmpBuf.bytes();
    350     Rp_ParserXmlDestroy(&parser);
    351279}
    352280
  • trunk/src/objects/RpPlot.h

    r1569 r1581  
    4242        Curve *getNthCurve(size_t n) const;
    4343
    44         void configure(size_t as, ClientData p);
    45         void dump(size_t as, ClientData p);
    46 
    4744        const int is() const;
    4845
     
    6360        static int __curveCopyFxn(void **to, void *from);
    6461
    65         void __configureFromXml(ClientData c);
    6662        void __configureFromTree(ClientData c);
    67         void __dumpToXml(ClientData c);
    6863        void __dumpToTree(ClientData c);
    6964};
Note: See TracChangeset for help on using the changeset viewer.