Changeset 1560


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.

Location:
trunk
Files:
9 added
42 edited

Legend:

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

    r1528 r1560  
    1818                axis \
    1919                curve \
     20                dxReader \
    2021                dxWriter \
    2122                floatBuffer \
  • trunk/examples/objects/app-fermi/fermi1.cc

    r1542 r1560  
    7474
    7575    // do it the easy way,
    76     // create a plot to add to the library
     76    // create a plot and add to the library
    7777    // p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
    7878
    79     Rappture::Plot *p1 = new Rappture::Plot();
     79    Rappture::Plot *p1 = new Rappture::Plot(lib);
    8080    p1->add(nPts,fArr,EArr,"",curveLabel,curveDesc);
    8181    p1.propstr("xlabel","Fermi-Dirac Factor");
    8282    p1.propstr("ylabel","Energy");
    8383    p1.propstr("yunits","eV");
    84 
    85     // add the plot to the library
    86     lib.put(p1);
    8784
    8885
     
    9188    // c1->axis("xaxis","xlabel","xdesc","units","scale",dataArr,nPts);
    9289
    93     Rappture::Curve *c1 = new Rappture::Curve("output.curve(FDF)");
     90    Rappture::Curve *c1 = new Rappture::Curve(lib,"FDF");
    9491    c1->label(curveLabel);
    9592    c1->desc(curveDesc);
  • trunk/examples/objects/app-fermi/fermi2.cc

    r1542 r1560  
    2525    Rappture::Number *T  = NULL;
    2626    Rappture::Number *Ef = NULL;
    27     double E            = 0.0;
    2827    double dE           = 0.0;
    2928    double kT           = 0.0;
    3029    double Emin         = 0.0;
    3130    double Emax         = 0.0;
    32     double f            = 0.0;
     31    size_t nPts         = 200;
     32    double E[nPts];
     33    double f[nPts];
    3334
    3435    // create a rappture library from the file filePath
     
    5556    Emax = Ef->value("eV") + 10*kT;
    5657
    57     dE = 0.005*(Emax-Emin);
     58    dE = (1.0/nPts)*(Emax-Emin);
    5859
    59     Rappture::SimpleDoubleBuffer fBuf;
    60     Rappture::SimpleDoubleBuffer EBuf;
    61 
    62     for (E = Emin; E < Emax; E = E + dE) {
     60    E = Emin;
     61    for (size_t idx = 0; idx < nPts; idx++) {
     62        E = E + dE;
    6363        f = 1.0/(1.0 + exp((E - Ef)/kT));
    64         fBuf.append(f);
    65         EBuf.append(E);
     64        fArr[idx] = f;
     65        EArr[idx] = E;
    6666        rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
    6767    }
    68     const double *fArr = fBuf.data();
    69     const double *EArr = EBuf.data();
    70     size_t nPts = fBuf.nmemb();
    7168
    7269    const char *curveLabel = "Fermi-Dirac Curve"
     
    7572    // do it the easy way,
    7673    // create a plot to add to the library
     74    // plot is registered with lib upon object creation
    7775    // p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
    7876
    79     Rappture::Plot *p1 = new Rappture::Plot();
     77    Rappture::Plot *p1 = new Rappture::Plot(lib);
    8078    p1->add(nPts,fArr,EArr,"",curveLabel,curveDesc);
    8179    p1.propstr("xlabel","Fermi-Dirac Factor");
     
    8381    p1.propstr("yunits","eV");
    8482
    85     // add the plot to the library
    86     lib.put(p1);
    87 
    88 
    89     // or do it the harder way,
    90     // create a curve to add to the library
    91     // c1->axis("xaxis","xlabel","xdesc","units","scale",dataArr,nPts);
    92 
    93     Rappture::Curve *c1 = new Rappture::Curve("output.curve(FDF)");
    94     c1->label(curveLabel);
    95     c1->desc(curveDesc);
    96     c1->axis("xaxis","Fermi-Dirac Factor","","","",fArr,nPts);
    97     c1->axis("yaxis","Energy","","eV","",EArr,nPts);
    98 
    99     // add the curve to the library
    100     lib.put(c1);
    101 
    10283    lib.result();
    10384
    10485    // clean up memory
    10586    delete lib;
     87    delete T;
     88    delete Ef;
    10689    delete p1;
    107     delete c1;
    10890
    10991    return 0;
  • trunk/examples/objects/curve/curve.cc

    r1528 r1560  
    11#include <iostream>
    22#include "RpCurve.h"
     3
     4size_t indent = 0;
     5size_t tabstop = 4;
    36
    47int test(
     
    3437    }
    3538
    36     std::cout << "xml: " << n->xml() << std::endl;
     39    std::cout << "xml: " << n->xml(indent,tabstop) << std::endl;
    3740    return 0;
    3841}
  • trunk/examples/objects/histogram/histogram.cc

    r1528 r1560  
    3636    h3->yaxis("ylabel3","ydesc3","yunits3");
    3737
     38    size_t indent = 0;
     39    size_t tabstop = 4;
    3840
    39     std::printf("xml: %s\n",h1->xml());
    40     std::printf("xml: %s\n",h2->xml());
    41     std::printf("xml: %s\n",h3->xml());
     41    std::printf("xml: %s\n",h1->xml(indent,tabstop));
     42    std::printf("xml: %s\n",h2->xml(indent,tabstop));
     43    std::printf("xml: %s\n",h3->xml(indent,tabstop));
    4244
    4345    return 0;
  • trunk/examples/objects/number/Makefile.in

    r1386 r1560  
    3434FILES   = \
    3535                $(srcdir)/number.cc \
     36                $(srcdir)/number_1_0_in.xml \
    3637                Makefile
    3738
  • trunk/examples/objects/number/number.cc

    r1528 r1560  
    11#include <iostream>
     2#include <errno.h>
     3#include <fstream>
     4#include <sys/stat.h>
    25#include "RpNumber.h"
     6
     7size_t indent = 0;
     8size_t tabstop = 4;
    39
    410int
    511printNumber(Rappture::Number *n)
    612{
     13    std::cout << "name: " << n->name() << std::endl;
    714    std::cout << "path: " << n->path() << std::endl;
    815    std::cout << "label: " << n->label() << std::endl;
     
    1320    std::cout << "max: " << n->max() << std::endl;
    1421    std::cout << "units: " << n->units() << std::endl;
    15     std::cout << "xml: " << n->xml() << std::endl;
    16     return 0;
     22    std::cout << "xml:\n" << n->xml(indent,tabstop) << std::endl;
     23    return 0;
     24}
     25
     26int testStringVal(
     27    const char *testname,
     28    const char *desc,
     29    const char *expected,
     30    const char *received)
     31{
     32    if ((!expected && received) ||
     33        (expected && !received) ||
     34        (expected && received && strcmp(expected,received) != 0)) {
     35        printf("Error: %s\n", testname);
     36        printf("\t%s\n", desc);
     37        printf("\texpected \"%s\"\n",expected);
     38        printf("\treceived \"%s\"\n",received);
     39        return 1;
     40    }
     41    return 0;
     42}
     43
     44int testDoubleVal(
     45    const char *testname,
     46    const char *desc,
     47    double expected,
     48    double received)
     49{
     50    if (expected != received) {
     51        printf("Error: %s\n", testname);
     52        printf("\t%s\n", desc);
     53        printf("\texpected \"%g\"\n",expected);
     54        printf("\treceived \"%g\"\n",received);
     55        return 1;
     56    }
     57    return 0;
     58}
     59
     60size_t
     61readFile (
     62    const char *filePath,
     63    const char **buf)
     64{
     65    if (buf == NULL) {
     66        fprintf(stderr,"buf is NULL while opening file \"%s\"", filePath);
     67        return 0;
     68    }
     69
     70    FILE *f;
     71    f = fopen(filePath, "rb");
     72    if (f == NULL) {
     73        fprintf(stderr,"can't open \"%s\": %s", filePath, strerror(errno));
     74        return 0;
     75    }
     76    struct stat stat;
     77    if (fstat(fileno(f), &stat) < 0) {
     78        fprintf(stderr,"can't stat \"%s\": %s", filePath, strerror(errno));
     79        return 0;
     80    }
     81    off_t size;
     82    size = stat.st_size;
     83    char* memblock;
     84    memblock = new char [size+1];
     85    if (memblock == NULL) {
     86        fprintf(stderr,"can't allocate %zu bytes for file \"%s\": %s",
     87            size, filePath, strerror(errno));
     88        fclose(f);
     89        return 0;
     90    }
     91
     92    size_t nRead;
     93    nRead = fread(memblock, sizeof(char), size, f);
     94    fclose(f);
     95
     96    if (nRead != (size_t)size) {
     97        fprintf(stderr,"can't read %zu bytes from \"%s\": %s", size, filePath,
     98            strerror(errno));
     99        return 0;
     100    }
     101
     102    memblock[size] = '\0';
     103    *buf = memblock;
     104    return nRead;
     105}
     106int number_0_0 ()
     107{
     108    const char *testdesc = "test number full constructor";
     109    const char *testname = "number_0_0";
     110    int retVal = 0;
     111
     112    const char *name = "temp";
     113    const char *units = "K";
     114    double def = 300;
     115    double min = 0;
     116    double max = 1000;
     117    const char *label = "mylabel";
     118    const char *desc = "mydesc";
     119
     120    Rappture::Number *n = NULL;
     121
     122    n = new Rappture::Number(name,units,def,min,max,label,desc);
     123
     124    if (n == NULL) {
     125        printf("Error: %s\n", testname);
     126        printf("\t%s\n", testdesc);
     127        printf("\terror creating number object\n");
     128        retVal = 1;
     129    }
     130
     131    retVal |= testStringVal(testname,testdesc,name,n->name());
     132    retVal |= testStringVal(testname,testdesc,units,n->units());
     133    retVal |= testDoubleVal(testname,testdesc,def,n->def());
     134    retVal |= testDoubleVal(testname,testdesc,min,n->min());
     135    retVal |= testDoubleVal(testname,testdesc,max,n->max());
     136    retVal |= testStringVal(testname,testdesc,label,n->label());
     137    retVal |= testStringVal(testname,testdesc,desc,n->desc());
     138
     139    if (n != NULL) {
     140        delete n;
     141    }
     142
     143    return retVal;
     144}
     145
     146int number_0_1 ()
     147{
     148    const char *testdesc = "test number constuctor";
     149    const char *testname = "number_0_0";
     150    int retVal = 0;
     151
     152    const char *name = "eV";
     153    const char *units = "eV";
     154    double def = 1.4;
     155
     156    Rappture::Number *n = NULL;
     157
     158    n = new Rappture::Number(name,units,def);
     159
     160    if (n == NULL) {
     161        printf("Error: %s\n", testname);
     162        printf("\t%s\n", testdesc);
     163        printf("\terror creating number object\n");
     164        retVal = 1;
     165    }
     166
     167    retVal |= testStringVal(testname,testdesc,name,n->name());
     168    retVal |= testStringVal(testname,testdesc,units,n->units());
     169    retVal |= testDoubleVal(testname,testdesc,def,n->def());
     170
     171    if (n != NULL) {
     172        delete n;
     173    }
     174
     175    return retVal;
     176}
     177
     178int number_1_0 ()
     179{
     180    const char *testdesc = "test constructing number from xml";
     181    const char *testname = "number_1_0";
     182    const char *filePath = "number_1_0_in.xml";
     183    int retVal = 0;
     184
     185    const char *buf = NULL;
     186    readFile(filePath,&buf);
     187
     188    const char *name = "Ef";
     189    const char *units = "eV";
     190    double def = 0;
     191    double cur = 5;
     192    double min = -10;
     193    double max = 10;
     194    const char *label = "Fermi Level";
     195    const char *desc = "Energy at center of distribution.";
     196
     197    Rappture::Number n;
     198
     199    n.xml(buf);
     200
     201    retVal |= testStringVal(testname,testdesc,name,n.name());
     202    retVal |= testStringVal(testname,testdesc,units,n.units());
     203    retVal |= testDoubleVal(testname,testdesc,def,n.def());
     204    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
     205    retVal |= testDoubleVal(testname,testdesc,min,n.min());
     206    retVal |= testDoubleVal(testname,testdesc,max,n.max());
     207    retVal |= testStringVal(testname,testdesc,label,n.label());
     208    retVal |= testStringVal(testname,testdesc,desc,n.desc());
     209
     210    return retVal;
    17211}
    18212
    19213int main()
    20214{
    21     Rappture::Number *n = NULL;
    22 
    23     n = new Rappture::Number("input.number(temperature)","K",300,
    24                              0,1000,"mylabel","mydesc");
    25 
    26     printNumber(n);
    27 
    28     Rappture::Number n1("input.number(eV)","eV",1.4);
    29     printNumber(&n1);
    30 
    31     delete n;
    32 
    33     return 0;
    34 }
     215    number_0_0();
     216    number_0_1();
     217    number_1_0();
     218
     219    return 0;
     220}
  • trunk/examples/objects/path/path.cc

    r1528 r1560  
    88    const char *received)
    99{
    10     if (strcmp(expected,received) != 0) {
     10    if ((!expected && received) ||
     11        (expected && !received) ||
     12        (expected && received && strcmp(expected,received) != 0)) {
    1113        printf("Error: %s\n", testname);
    1214        printf("\t%s\n", desc);
     
    114116
    115117    const char *path = "input.group(tabs).number(mynum).current";
    116     const char *expected = "";
     118    const char *expected = NULL;
    117119    const char *received = NULL;
    118120
     
    773775// FIXME: add test for parent get/set functions
    774776// FIXME: add test for path get/set functions
     777// FIXME: add test for changing the curr location
     778//        using first,last,next,prev and checking
     779//        comp, type, parent,id fxns
     780// FIXME: add test for numbered paths
     781//        input.number2
     782//        input.number2(eee)
     783//        input.number(eee)2
    775784
    776785int main()
  • trunk/examples/objects/plot/plot.cc

    r1528 r1560  
    4141    std::printf("curveCnt = %zu\n",curveCnt);
    4242
    43     std::printf("xml: %s\n",p1->xml());
     43    size_t indent = 0;
     44    size_t tabstop = 4;
     45
     46    std::printf("xml: %s\n",p1->xml(indent,tabstop));
    4447
    4548/*
  • trunk/examples/objects/scatter/scatter.cc

    r1528 r1560  
    4141    std::printf("curveCnt = %zu\n",curveCnt);
    4242
    43     std::printf("xml: %s\n",p1->xml());
     43    size_t indent = 0;
     44    size_t tabstop = 4;
     45    std::printf("xml: %s\n",p1->xml(indent,tabstop));
    4446
    4547/*
  • trunk/examples/objects/tree/tree.c

    r1528 r1560  
    1414    Rp_Tree t;
    1515
    16     Rp_TreeCreate(treeName,t);
     16    Rp_TreeCreate(treeName,&t);
    1717    received = Rp_TreeName(t);
    1818
     
    2828}
    2929
     30int tree_1_0 ()
     31{
     32    const char *desc = "test creation of tree node";
     33    const char *testname = "tree_1_0";
     34
     35    const char *treeName = "mytree";
     36    const char *nodeName = "mynode";
     37    const char *expected = "mynode";
     38    const char *received = NULL;
     39
     40    Rp_Tree t;
     41    Rp_TreeNode n = NULL;
     42
     43    Rp_TreeCreate(treeName,&t);
     44    n = Rp_TreeCreateNode(t, Rp_TreeRootNode(t), nodeName, 0);
     45    received = Rp_TreeNodeLabel(n);
     46
     47    if (strcmp(expected,received) != 0) {
     48        printf("Error: %s\n", testname);
     49        printf("\t%s\n", desc);
     50        printf("\texpected \"%s\"\n",expected);
     51        printf("\treceived \"%s\"\n",received);
     52        return 1;
     53    }
     54
     55    return 0;
     56}
     57
     58int tree_2_0 ()
     59{
     60    const char *desc = "test creation of tree node with single child";
     61    const char *testname = "tree_2_0";
     62
     63    const char *treeName = "mytree";
     64    const char *parentNodeName = "myparentnode";
     65    const char *childNodeName = "mychildnode";
     66    const char *expected = "mychildnode";
     67    const char *received = NULL;
     68
     69    Rp_Tree t;
     70    Rp_TreeNode parent = NULL;
     71    Rp_TreeNode child = NULL;
     72
     73    Rp_TreeCreate(treeName,&t);
     74    parent = Rp_TreeCreateNode(t, Rp_TreeRootNode(t), parentNodeName, 0);
     75    child = Rp_TreeCreateNode(t, parent, childNodeName, 0);
     76    received = Rp_TreeNodeLabel(child);
     77
     78    if (strcmp(expected,received) != 0) {
     79        printf("Error: %s\n", testname);
     80        printf("\t%s\n", desc);
     81        printf("\texpected \"%s\"\n",expected);
     82        printf("\treceived \"%s\"\n",received);
     83        return 1;
     84    }
     85
     86    return 0;
     87}
     88
     89int tree_2_1 ()
     90{
     91    const char *desc = "test creation of tree node with multiple children";
     92    const char *testname = "tree_2_1";
     93
     94    const char *treeName = "mytree";
     95    const char *parentNodeName = "myparentnode";
     96    size_t expected = 5;
     97    size_t received = 0;
     98
     99    Rp_Tree t;
     100    Rp_TreeNode parent = NULL;
     101
     102    Rp_TreeCreate(treeName,&t);
     103    parent = Rp_TreeCreateNode(t, Rp_TreeRootNode(t), parentNodeName, 0);
     104
     105    Rp_TreeCreateNode(t, parent, "child1", 0);
     106    Rp_TreeCreateNode(t, parent, "child2", 0);
     107    Rp_TreeCreateNode(t, parent, "child3", 0);
     108    Rp_TreeCreateNode(t, parent, "child4", 0);
     109    Rp_TreeCreateNode(t, parent, "child5", 0);
     110
     111    received = Rp_TreeNodeDegree(parent);
     112
     113    if (expected != received) {
     114        printf("Error: %s\n", testname);
     115        printf("\t%s\n", desc);
     116        printf("\texpected \"%zu\"\n",expected);
     117        printf("\treceived \"%zu\"\n",received);
     118        return 1;
     119    }
     120
     121    return 0;
     122}
     123
     124int tree_2_2 ()
     125{
     126    const char *desc = "test search for child node";
     127    const char *testname = "tree_2_2";
     128
     129    const char *treeName = "mytree";
     130    const char *parentNodeName = "myparentnode";
     131    const char *childNodeName = "mychildnode";
     132    const char *expected = "mychildnode";
     133    const char *received = NULL;
     134
     135    Rp_Tree t;
     136    Rp_TreeNode parent = NULL;
     137    Rp_TreeNode foundChild = NULL;
     138
     139    Rp_TreeCreate(treeName,&t);
     140    parent = Rp_TreeCreateNode(t, Rp_TreeRootNode(t), parentNodeName, 0);
     141
     142    Rp_TreeCreateNode(t, parent, "child1", 0);
     143    Rp_TreeCreateNode(t, parent, "child2", 0);
     144    Rp_TreeCreateNode(t, parent, "child3", 0);
     145    Rp_TreeCreateNode(t, parent, childNodeName, 0);
     146    Rp_TreeCreateNode(t, parent, "child4", 0);
     147    Rp_TreeCreateNode(t, parent, "child5", 0);
     148
     149    foundChild = Rp_TreeFindChild(parent,childNodeName);
     150    received = Rp_TreeNodeLabel(foundChild);
     151
     152    if (strcmp(expected,received) != 0) {
     153        printf("Error: %s\n", testname);
     154        printf("\t%s\n", desc);
     155        printf("\texpected \"%s\"\n",expected);
     156        printf("\treceived \"%s\"\n",received);
     157        return 1;
     158    }
     159
     160    return 0;
     161}
     162
     163int tree_3_0 ()
     164{
     165    const char *desc = "test adding node with string value";
     166    const char *testname = "tree_3_0";
     167
     168    const char *treeName = "mytree";
     169    const char *parentNodeName = "myparentnode";
     170    const char *childNodeName = "mychildnode";
     171    const char *childNodeValue = "quick brown fox";
     172    const char *expected = "quick brown fox1";
     173    const char *received = NULL;
     174
     175    Rp_Tree t;
     176    Rp_TreeNode parent = NULL;
     177    Rp_TreeNode child = NULL;
     178
     179    Rp_TreeCreate(treeName,&t);
     180    parent = Rp_TreeCreateNode(t, Rp_TreeRootNode(t), parentNodeName, 0);
     181
     182    child = Rp_TreeCreateNode(t, parent, childNodeName, 0);
     183    Rp_TreeSetValue(t,child,"value",(void *)childNodeValue);
     184
     185    Rp_TreeGetValue(t,child,"value",(void **)&received);
     186
     187    if (strcmp(expected,received) != 0) {
     188        printf("Error: %s\n", testname);
     189        printf("\t%s\n", desc);
     190        printf("\texpected \"%s\"\n",expected);
     191        printf("\treceived \"%s\"\n",received);
     192        return 1;
     193    }
     194
     195    return 0;
     196}
     197
    30198int main()
    31199{
    32200    tree_0_0();
    33 
    34     return 0;
    35 }
     201    tree_1_0();
     202    tree_2_0();
     203    tree_2_1();
     204    tree_2_2();
     205    tree_3_0();
     206
     207    // add test case where two children have the same name but different ids
     208
     209    return 0;
     210}
  • trunk/examples/objects/xmlparser/Makefile.in

    r1528 r1560  
    3434FILES   = \
    3535                $(srcdir)/xmlparser.cc \
     36                $(srcdir)/xmlparser_1_0_in.xml \
     37                $(srcdir)/xmlparser_1_0_out.xml \
     38                $(srcdir)/xmlparser_2_0_in.xml \
    3639                $(srcdir)/tool.xml \
    3740                Makefile
  • trunk/examples/objects/xmlparser/xmlparser.cc

    r1528 r1560  
    1 #include <stdio.h>
    2 #include <expat.h>
    3 #include <string.h>
    4 #include "RpInt.h"
    5 #include "RpChain.h"
    6 #include "RpPath.h"
    7 #include "RpNumber.h"
    8 
    9 #define BUFFSIZE        8192
    10 
    11 char Buff[BUFFSIZE];
    12 
    13 typedef struct {
    14     int skip;
    15     int depth;
    16     Rappture::Path *path;
    17     Rp_Chain *c;
    18     void *lastObj;
    19     int lastObjType;
    20     Rappture::Object *v;
    21 } Parseinfo;
    22 
    23 void
    24 init_info(Parseinfo *info) {
    25     info->skip = 0;
    26     info->depth = 1;
    27     info->path = new Rappture::Path();
    28     info->c = Rp_ChainCreate();
    29     info->lastObj = NULL;
    30     info->lastObjType = 0;
    31     info->v = NULL;
    32 }
    33 
    34 int
    35 should_skip(Parseinfo *inf, const char *el, const char **attr) {
    36     int skip = 0;
    37 
    38     if ( (*el == 's') && (strcmp("string",el) == 0) ) {
    39         skip = 1;
    40     }
    41 
    42     return skip;
    43 }
    44 
    45 static void XMLCALL
    46 start(void *data, const char *el, const char **attr)
    47 {
    48     Parseinfo *inf = (Parseinfo *) data;
    49 
    50     if ( (*el == 'i') && (strcmp("input",el) == 0) ) {
    51         inf->path->add(el);
    52     } else if ( (*el == 'n') && (strcmp("number",el) == 0) ) {
    53         inf->path->add(el);
    54         // null units kills number
    55         // Rappture::Number *n = new Rappture::Number(inf->path->path(NULL),NULL,0.0);
    56         Rappture::Number *n = new Rappture::Number(inf->path->path(),"",0.0);
    57         Rp_ChainAppend(inf->c,n);
    58         inf->v = n;
    59     } else {
    60         // add the tags to the hash table of the last object we created.
    61         // this means new objects must be declared here,
    62         // or they will become part of the last recognized object
    63         // this could lead to major problems.
    64         // we have no way to ignore stuff we don't recognize
    65 
    66         inf->path->add(el);
    67         if (inf->v) {
    68             // inf->v->property(el,);
    69         }
    70     }
    71 
    72     inf->depth++;
    73 }
    74 
    75 static void XMLCALL
    76 end(void *data, const char *el)
    77 {
    78     Parseinfo *inf = (Parseinfo *) data;
    79     inf->path->del();
    80     inf->depth--;
    81     // pop object off the end of the inf->c chain
    82     // add object to the tree object
    83 }
    84 
    85 void
    86 rawstart(void *data, const char *el, const char **attr) {
    87     Parseinfo *inf = (Parseinfo *) data;
    88 
    89     if (! inf->skip) {
    90         if (should_skip(inf, el, attr)) {
    91             inf->skip = inf->depth;
    92         }
    93         else {
    94             start(inf, el, attr);     /* This does rest of start handling */
    95         }
    96     }
    97 
    98     inf->depth++;
    99 }  /* End of rawstart */
    100 
    101 void
    102 rawend(void *data, const char *el) {
    103     Parseinfo *inf = (Parseinfo *) data;
    104 
    105     inf->depth--;
    106 
    107     if (! inf->skip) {
    108         end(inf, el);              /* This does rest of end handling */
    109     }
    110 
    111     if (inf->skip == inf->depth) {
    112         inf->skip = 0;
    113     }
    114 }  /* End rawend */
    115 
    116 /*
    117 void
    118 char_handler(void* data, XML_Char const* s, int len)
    119 {
    120     int total = 0;
    121     int total_old = 0;
    122     scew_element* current = NULL;
    123     Parseinfo *inf = (Parseinfo *) data;
    124 
    125     if (inf == NULL) {
    126         return;
    127     }
    128 
    129     if (inf->v == NULL)
    130     {
    131         return;
    132     }
    133 
    134     if (current->contents != NULL)
    135     {
    136         total_old = scew_strlen(current->contents);
    137     }
    138     total = (total_old + len + 1) * sizeof(XML_Char);
    139     current->contents = (XML_Char*) realloc(current->contents, total);
    140 
    141     if (total_old == 0)
    142     {
    143         current->contents[0] = '\0';
    144     }
    145 
    146     scew_strncat(current->contents, s, len);
    147 }
    148 */
    149 
    150 
    151 int
    152 main(int argc, char *argv[])
    153 {
    154     Parseinfo info;
    155     XML_Parser p = XML_ParserCreate(NULL);
    156     if (! p) {
    157         fprintf(stderr, "Couldn't allocate memory for parser\n");
    158         exit(-1);
    159     }
    160 
    161     init_info(&info);
    162     XML_SetUserData(p,&info);
    163 
    164     XML_SetElementHandler(p, rawstart, rawend);
    165     //XML_SetDefaultHandler(p, char_handler);
    166 
    167     for (;;) {
    168         int done;
    169         int len;
    170 
    171         len = fread(Buff, 1, BUFFSIZE, stdin);
    172         if (ferror(stdin)) {
    173             fprintf(stderr, "Read error\n");
    174             exit(-1);
    175         }
    176         done = feof(stdin);
    177 
    178         if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
    179             fprintf(stderr, "Parse error at line %lu:\n%s\n",
    180                     XML_GetCurrentLineNumber(p),
    181                     XML_ErrorString(XML_GetErrorCode(p)));
    182             exit(-1);
    183         }
    184 
    185         if (done) {
    186             break;
    187         }
    188     }
    189 
    190     Rp_ChainLink *lv = NULL;
    191     Rappture::Number *n = NULL;
    192     lv = Rp_ChainFirstLink(info.c);
    193     while (lv) {
    194         n = (Rappture::Number *) Rp_ChainGetValue(lv);
    195         printf("%s\n",n->xml());
    196         lv = Rp_ChainNextLink(lv);
    197     }
     1#include <iostream>
     2#include <errno.h>
     3#include <fstream>
     4#include <sys/stat.h>
     5#include "RpParserXML.h"
     6
     7size_t
     8readFile (
     9    const char *filePath,
     10    const char **buf)
     11{
     12    if (buf == NULL) {
     13        fprintf(stderr,"buf is NULL while opening file \"%s\"", filePath);
     14        return 0;
     15    }
     16
     17    FILE *f;
     18    f = fopen(filePath, "rb");
     19    if (f == NULL) {
     20        fprintf(stderr,"can't open \"%s\": %s", filePath, strerror(errno));
     21        return 0;
     22    }
     23    struct stat stat;
     24    if (fstat(fileno(f), &stat) < 0) {
     25        fprintf(stderr,"can't stat \"%s\": %s", filePath, strerror(errno));
     26        return 0;
     27    }
     28    off_t size;
     29    size = stat.st_size;
     30    char* memblock;
     31    memblock = new char [size+1];
     32    if (memblock == NULL) {
     33        fprintf(stderr,"can't allocate %zu bytes for file \"%s\": %s",
     34            size, filePath, strerror(errno));
     35        fclose(f);
     36        return 0;
     37    }
     38
     39    size_t nRead;
     40    nRead = fread(memblock, sizeof(char), size, f);
     41    fclose(f);
     42
     43    if (nRead != (size_t)size) {
     44        fprintf(stderr,"can't read %zu bytes from \"%s\": %s", size, filePath,
     45            strerror(errno));
     46        return 0;
     47    }
     48
     49    memblock[size] = '\0';
     50    *buf = memblock;
     51    return nRead;
     52}
     53
     54int xmlparser_0_0 ()
     55{
     56    const char *desc = "test creating xml parser";
     57    const char *testname = "xmlparser_0_0";
     58    int retVal = 0;
     59
     60    const char *expected = "initialized ParserXml Object";
     61    const char *received = NULL;
     62
     63    Rp_ParserXml *p = NULL;
     64
     65    p = Rp_ParserXmlCreate();
     66
     67    if (p == NULL) {
     68        printf("Error: %s\n", testname);
     69        printf("\t%s\n", desc);
     70        printf("\texpected \"%s\"\n",expected);
     71        printf("\treceived \"%s\"\n",received);
     72        retVal = 1;
     73    }
     74
     75    if (p) {
     76        Rp_ParserXmlDestroy(&p);
     77    }
     78
     79    return retVal;
     80}
     81
     82int xmlparser_1_0 ()
     83{
     84    const char *desc = "test sending xml text to xml parser";
     85    const char *testname = "xmlparser_1_0";
     86    const char *infile = "xmlparser_1_0_in.xml";
     87    const char *outfile = "xmlparser_1_0_out.xml";
     88    int retVal = 0;
     89
     90    const char *xmltext = NULL;
     91    const char *expected = NULL;
     92
     93    readFile(infile,&xmltext);
     94    readFile(outfile,&expected);
     95
     96    const char *received = NULL;
     97
     98    Rp_ParserXml *p = NULL;
     99
     100    p = Rp_ParserXmlCreate();
     101
     102    Rp_ParserXmlParse(p, xmltext);
     103
     104    received = Rp_ParserXmlXml(p);
     105
     106
     107    if (strcmp(expected,received) != 0) {
     108        printf("Error: %s\n", testname);
     109        printf("\t%s\n", desc);
     110        printf("\texpected %zu bytes: \"%s\"\n",strlen(expected), expected);
     111        printf("\treceived %zu bytes: \"%s\"\n",strlen(received), received);
     112        retVal = 1;
     113    }
     114
     115    if (p) {
     116        Rp_ParserXmlDestroy(&p);
     117    }
     118
     119    return retVal;
     120}
     121
     122
     123int xmlparser_2_0 ()
     124{
     125    const char *desc = "test printing xml as path/val combos";
     126    const char *testname = "xmlparser_2_0";
     127    const char *infile = "xmlparser_2_0_in.xml";
     128    int retVal = 0;
     129
     130    const char *xmltext = NULL;
     131
     132    readFile(infile,&xmltext);
     133
     134    const char *expected = "\
     135run.tool.about Press Simulate to view results.\n\
     136run.tool.command tclsh @tool/fermi.tcl @driver\n\
     137run.input.number(Ef).about.label Fermi Level\n\
     138run.input.number(Ef).about.description Energy at center of distribution.\n\
     139run.input.number(Ef).units eV\n\
     140run.input.number(Ef).min -10eV\n\
     141run.input.number(Ef).max 10eV\n\
     142run.input.number(Ef).default 0eV\n\
     143run.input.number(Ef).current 0eV\n";
     144
     145    const char *received = NULL;
     146
     147    Rp_ParserXml *p = NULL;
     148
     149    p = Rp_ParserXmlCreate();
     150
     151    Rp_ParserXmlParse(p, xmltext);
     152
     153    received = Rp_ParserXmlPathVal(p);
     154
     155
     156    if (strcmp(expected,received) != 0) {
     157        printf("Error: %s\n", testname);
     158        printf("\t%s\n", desc);
     159        printf("\texpected %zu bytes: \"%s\"\n",strlen(expected), expected);
     160        printf("\treceived %zu bytes: \"%s\"\n",strlen(received), received);
     161        retVal = 1;
     162    }
     163
     164    if (p) {
     165        Rp_ParserXmlDestroy(&p);
     166    }
     167
     168    return retVal;
     169}
     170
     171int xmlparser_3_0 ()
     172{
     173    const char *desc = "test getting xml value";
     174    const char *testname = "xmlparser_3_0";
     175    const char *infile = "xmlparser_2_0_in.xml";
     176    int retVal = 0;
     177
     178    const char *xmltext = NULL;
     179
     180    readFile(infile,&xmltext);
     181
     182    const char *expected = "0eV";
     183
     184    const char *received = NULL;
     185
     186    Rp_ParserXml *p = NULL;
     187
     188    p = Rp_ParserXmlCreate();
     189
     190    Rp_ParserXmlParse(p, xmltext);
     191
     192    received = Rp_ParserXmlGet(p,"input.number(Ef).current");
     193
     194
     195    if (strcmp(expected,received) != 0) {
     196        printf("Error: %s\n", testname);
     197        printf("\t%s\n", desc);
     198        printf("\texpected %zu bytes: \"%s\"\n",strlen(expected), expected);
     199        printf("\treceived %zu bytes: \"%s\"\n",strlen(received), received);
     200        retVal = 1;
     201    }
     202
     203    if (p) {
     204        Rp_ParserXmlDestroy(&p);
     205    }
     206
     207    return retVal;
     208}
     209
     210int xmlparser_4_0 ()
     211{
     212    const char *desc = "test putting xml value";
     213    const char *testname = "xmlparser_4_0";
     214    const char *infile = "xmlparser_2_0_in.xml";
     215    int retVal = 0;
     216
     217    const char *xmltext = NULL;
     218
     219    readFile(infile,&xmltext);
     220
     221    const char *expected = "hi mom";
     222
     223    const char *received = NULL;
     224
     225    Rp_ParserXml *p = NULL;
     226
     227    p = Rp_ParserXmlCreate();
     228
     229    Rp_ParserXmlParse(p, xmltext);
     230
     231    Rp_ParserXmlPut(p,"input.number(gg).current","hi mom",0);
     232    received = Rp_ParserXmlGet(p,"input.number(gg).current");
     233
     234    if (strcmp(expected,received) != 0) {
     235        printf("Error: %s\n", testname);
     236        printf("\t%s\n", desc);
     237        printf("\texpected %zu bytes: \"%s\"\n",strlen(expected), expected);
     238        printf("\treceived %zu bytes: \"%s\"\n",strlen(received), received);
     239        retVal = 1;
     240    }
     241
     242    if (p) {
     243        Rp_ParserXmlDestroy(&p);
     244    }
     245
     246    return retVal;
     247}
     248
     249int xmlparser_5_0 ()
     250{
     251    const char *desc = "test printing xml with degrees of presets";
     252    const char *testname = "xmlparser_5_0";
     253    const char *infile = "xmlparser_5_0_in.xml";
     254    int retVal = 0;
     255
     256    const char *xmltext = NULL;
     257
     258    readFile(infile,&xmltext);
     259
     260    const char *expected = "\
     261run.tool.about Press Simulate to view results.\n\
     262run.tool.command tclsh @tool/fermi.tcl @driver\n\
     263run.input.number(Ef).about.label Fermi Level\n\
     264run.input.number(Ef).about.description Energy at center of distribution.\n\
     265run.input.number(Ef).units eV\n\
     266run.input.number(Ef).min -10eV\n\
     267run.input.number(Ef).max 10eV\n\
     268run.input.number(Ef).default 0eV\n\
     269run.input.number(Ef).current 0eV\n";
     270
     271    const char *received = NULL;
     272
     273    Rp_ParserXml *p = NULL;
     274
     275    p = Rp_ParserXmlCreate();
     276
     277    Rp_ParserXmlParse(p, xmltext);
     278
     279    received = Rp_ParserXmlPathVal(p);
     280
     281
     282    if (strcmp(expected,received) != 0) {
     283        printf("Error: %s\n", testname);
     284        printf("\t%s\n", desc);
     285        printf("\texpected %zu bytes: \"%s\"\n",strlen(expected), expected);
     286        printf("\treceived %zu bytes: \"%s\"\n",strlen(received), received);
     287        retVal = 1;
     288    }
     289
     290    if (p) {
     291        Rp_ParserXmlDestroy(&p);
     292    }
     293
     294    return retVal;
     295}
     296
     297// FIXME: test what happens when parser sees self closing tag <tag/>
     298// FIXME: test get function
     299// FIXME: test put function
     300// FIXME: look into why Rp_ParserXmlPathVal hits some nodes twice in gdb
     301
     302int main()
     303{
     304    xmlparser_0_0();
     305    xmlparser_1_0();
     306    xmlparser_2_0();
     307    xmlparser_3_0();
     308    xmlparser_4_0();
     309    xmlparser_5_0();
    198310
    199311    return 0;
  • trunk/src/core/RpSimpleBuffer.h

    r1527 r1560  
    8181    SimpleBuffer     operator+(const SimpleBuffer& b) const;
    8282    SimpleBuffer<T>& operator+=(const SimpleBuffer<T>& b);
     83    T operator[](size_t offset);
    8384    virtual ~SimpleBuffer();
    8485
     
    241242
    242243/**
     244 * Operator []
     245 * @param index into the buffer
     246 */
     247template<class T>
     248T
     249SimpleBuffer<T>::operator[](size_t idx)
     250{
     251    return (_buf+idx);
     252}
     253
     254
     255/**
    243256 * Destructor
    244257 */
  • trunk/src/objects/Makefile.in

    r1528 r1560  
    4848LN              = ln -s
    4949
     50#               RpDXReader.h \
     51#               RpDXWriter.h \
     52
    5053HEADERS = \
    5154                RpAccessor.h \
     
    6265                RpHistogram.h \
    6366                RpNumber.h \
     67                RpParserXML.h \
    6468                RpPath.h \
    6569                RpPlot.h \
     
    7276LOCAL_HEADERS = \
    7377                RpHash.h
     78
     79#               RpDXReader.o \
     80#               RpDXWriter.o \
    7481
    7582OBJS = \
     
    8693                RpHistogram.o \
    8794                RpNumber.o \
     95                RpParserXML.o \
    8896                RpPath.o \
    8997                RpPlot.o \
  • trunk/src/objects/RpAccessor.h

    r1528 r1560  
    7171Accessor<const char *>::operator() (const char *val)
    7272{
     73    if (val == NULL) {
     74        return;
     75    }
     76
    7377    size_t len = strlen(val);
    7478    char *tmp = new char[len+1];
  • trunk/src/objects/RpArray1D.cc

    r1528 r1560  
    180180
    181181const char *
    182 Array1D::xml()
     182Array1D::xml(size_t indent, size_t tabstop)
    183183{
    184184    return "";
  • trunk/src/objects/RpArray1D.h

    r1528 r1560  
    4141    static const char type[];
    4242
    43     const char *xml(void);
     43    const char *xml(size_t indent, size_t tabstop);
    4444    const int is(void) const;
    4545
  • trunk/src/objects/RpAxisMarker.cc

    r1528 r1560  
    139139
    140140const char *
    141 AxisMarker::xml()
     141AxisMarker::xml(size_t indent, size_t tabstop)
    142142{
     143    size_t l1width = indent + tabstop;
     144    const char *sp = "";
     145
    143146    _tmpBuf.clear();
    144147
    145148    _tmpBuf.appendf(
    146 "        <marker>\n\
    147             <at>%g</at>\n\
    148             <label>%s</label>\n\
    149             <style>%s</style>\n\
    150         <marker>\n",_at,label(),_style);
     149"%6$*4$s<marker>\n\
     150%6$*5$s<at>%1$g</at>\n\
     151%6$*5$s<label>%2$s</label>\n\
     152%6$*5$s<style>%3$s</style>\n\
     153%6$*4$s<marker>\n",
     154        _at,label(),_style,indent,l1width,sp);
    151155
    152156    _tmpBuf.append("\0",1);
  • trunk/src/objects/RpAxisMarker.h

    r1528 r1560  
    3939        double at (void) const;
    4040
    41         const char *xml();
     41        const char *xml(size_t indent, size_t tabstop);
    4242        const int is(void) const;
    4343
  • trunk/src/objects/RpBoolean.cc

    r1528 r1560  
    6565
    6666const char *
    67 Boolean::xml()
     67Boolean::xml(size_t indent, size_t tabstop)
    6868{
     69    size_t l1width = indent + tabstop;
     70    size_t l2width = indent + (2*tabstop);
     71    const char *sp = "";
     72
    6973    Path p(path());
    7074    _tmpBuf.clear();
     
    7377
    7478    _tmpBuf.appendf(
    75 "<boolean id=\"%s\">\n\
    76     <about>\n\
    77         <label>%s</label>\n\
    78         <description>%s</description>\n\
    79     </about>\n\
    80     <default>%i</default>\n\
    81     <current>%i</current>\n\
    82 </boolean>",
    83        p.id(),label(),desc(),def(),cur());
     79"%9$*6$s<boolean id=\"%1$s\">\n\
     80%9$*7$s<about>\n\
     81%9$*8$s<label>%2$s</label>\n\
     82%9$*8$s<description>%3$s</description>\n\
     83%9$*7$s</about>\n\
     84%9$*7$s<default>%4$i</default>\n\
     85%9$*7$s<current>%5$i</current>\n\
     86%9$*6$s</boolean>",
     87       p.id(),label(),desc(),def(),cur(),indent,l1width,l2width,sp);
    8488
    8589    return _tmpBuf.bytes();
  • trunk/src/objects/RpBoolean.h

    r1528 r1560  
    3434        Accessor<int> cur;
    3535
    36         const char *xml();
     36        const char *xml(size_t indent, size_t tabstop);
    3737        const int is() const;
    3838};
  • trunk/src/objects/RpChoice.cc

    r1528 r1560  
    150150
    151151const char *
    152 Choice::xml()
    153 {
     152Choice::xml(size_t indent, size_t tabstop)
     153{
     154    size_t l1width = indent + tabstop;
     155    size_t l2width = indent + (2*tabstop);
     156    size_t l3width = indent + (3*tabstop);
     157    const char *sp = "";
     158
    154159    Path p(path());
    155160    _tmpBuf.clear();
    156161
    157162    _tmpBuf.appendf(
    158 "<choice id='%s'>\n\
    159     <about>\n\
    160         <label>%s</label>\n\
    161         <description>%s</description>\n\
    162     </about>\n",
    163        p.id(),label(),desc());
     163"%7$*4$s<choice id='%1$s'>\n\
     164%7$*5$s<about>\n\
     165%7$*6$s<label>%2$s</label>\n\
     166%7$*6$s<description>%3$s</description>\n\
     167%7$*5$s</about>\n",
     168       p.id(),label(),desc(),indent,l1width,l2width,sp);
    164169
    165170    Rp_ChainLink *l = NULL;
     
    168173        option *op = (option *)Rp_ChainGetValue(l);
    169174        _tmpBuf.appendf(
    170 "    <option>\n\
    171         <about>\n\
    172             <label>%s</label>\n\
    173             <description>%s</description>\n\
    174         </about>\n\
    175         <value>%s</value>\n\
    176     </option>\n",
    177            op->label(),op->desc(),op->val());
     175"%7$*4$s<option>\n\
     176%7$*5$s<about>\n\
     177%7$*6$s<label>%1$s</label>\n\
     178%7$*6$s<description>%2$s</description>\n\
     179%7$*5$s</about>\n\
     180%7$*5$s<value>%3$s</value>\n\
     181%7$*4$s</option>\n",
     182           op->label(),op->desc(),op->val(),l1width,l2width,l3width,sp);
    178183        l = Rp_ChainNextLink(l);
    179184    }
    180185
    181186    _tmpBuf.appendf(
    182 "    <default>%s</default>\n\
    183     <current>%s</current>\n\
    184 </choice>",
    185        def(),cur());
     187"%5$*4$s<default>%1$s</default>\n\
     188%5$*4$s<current>%2$s</current>\n\
     189%5$*3$s</choice>",
     190       def(),cur(),indent,l1width,sp);
    186191
    187192    return _tmpBuf.bytes();
  • trunk/src/objects/RpChoice.h

    r1528 r1560  
    4141        Choice& delOption ( const char *label);
    4242
    43         const char *xml();
     43        const char *xml(size_t indent, size_t tabstop);
    4444        const int is() const;
    4545
  • trunk/src/objects/RpCurve.cc

    r1528 r1560  
    259259
    260260const char *
    261 Curve::xml()
    262 {
     261Curve::xml(size_t indent, size_t tabstop)
     262{
     263    size_t l1width = indent + tabstop;
     264    size_t l2width = indent + (2*tabstop);
     265    const char *sp = "";
     266
    263267    Path p(path());
    264268
     
    267271
    268272    const double *dataArr[dims()];
     273    const char *type = propstr("type");
    269274
    270275    _tmpBuf.clear();
    271276
    272277    _tmpBuf.appendf(
    273 "<curve id=\"%s\">\n\
    274     <about>\n\
    275         <group>%s</group>\n\
    276         <label>%s</label>\n\
    277         <description>%s</description>\n\
    278     </about>\n", p.id(),group(),label(),desc());
     278"%9$*6$s<curve id=\"%1$s\">\n\
     279%9$*7$s<about>\n\
     280%9$*8$s<group>%2$s</group>\n\
     281%9$*8$s<label>%3$s</label>\n\
     282%9$*8$s<description>%4$s</description>\n\
     283%9$*8$s<type>%5$s</type>\n\
     284%9$*7$s</about>\n",
     285        p.id(),group(),label(),desc(),type,indent,l1width,l2width,sp);
    279286
    280287    for (size_t dim=0; dim < dims(); dim++) {
     
    283290        dataArr[dim] = tmpAxis->data();
    284291        _tmpBuf.appendf(
    285 "    <%s>\n\
    286         <label>%s</label>\n\
    287         <description>%s</description>\n\
    288         <units>%s</units>\n\
    289         <scale>%s</scale>\n\
    290     </%s>\n",
     292"%8$*6$s<%1$s>\n\
     293%8$*7$s<label>%2$s</label>\n\
     294%8$*7$s<description>%3$s</description>\n\
     295%8$*7$s<units>%4$s</units>\n\
     296%8$*7$s<scale>%5$s</scale>\n\
     297%8$*6$s</%1$s>\n",
    291298        tmpAxis->name(), tmpAxis->label(), tmpAxis->desc(),
    292         tmpAxis->units(), tmpAxis->scale(), tmpAxis->name());
    293     }
    294 
    295     _tmpBuf.append("    <component>\n        <xy>\n");
     299        tmpAxis->units(), tmpAxis->scale(),l1width,l2width,sp);
     300    }
     301
     302    _tmpBuf.appendf("%3$*1$s<component>\n%3$*2$s<xy>\n",l1width,l2width,sp);
    296303    for (size_t idx=0; idx < nmemb; idx++) {
    297304        for(size_t dim=0; dim < dims(); dim++) {
     
    300307        _tmpBuf.append("\n",1);
    301308    }
    302     _tmpBuf.append("        </xy>\n    </component>\n</curve>");
    303     _tmpBuf.append("\0",1);
     309    _tmpBuf.appendf("%4$*3$s</xy>\n%4$*2$s</component>\n%4$*1$s</curve>",
     310        indent, l1width, l2width, sp);
    304311
    305312    return _tmpBuf.bytes();
  • trunk/src/objects/RpCurve.h

    r1528 r1560  
    4848        size_t dims() const;
    4949
    50         const char *xml();
     50        const char *xml(size_t indent, size_t tabstop);
    5151        const int is() const;
    5252
  • trunk/src/objects/RpHistogram.cc

    r1528 r1560  
    315315
    316316const char *
    317 Histogram::xml()
    318 {
     317Histogram::xml(size_t indent, size_t tabstop)
     318{
     319    size_t l1width = indent + tabstop;
     320    size_t l2width = indent + (2*tabstop);
     321    const char *sp = "";
     322
    319323    Path p(path());
    320324
     
    327331
    328332    _tmpBuf.appendf(
    329 "<histogram id=\"%s\">\n\
    330     <about>\n\
    331         <group>%s</group>\n\
    332         <label>%s</label>\n\
    333         <description>%s</description>\n\
    334     </about>\n", p.id(),group(),label(),desc());
     333"%8$*5$s<histogram id=\"%1$s\">\n\
     334%8$*6$s<about>\n\
     335%8$*7$s<group>%2$s</group>\n\
     336%8$*7$s<label>%3$s</label>\n\
     337%8$*7$s<description>%4$s</description>\n\
     338%8$*6$s</about>\n",
     339        p.id(),group(),label(),desc(),indent,l1width,l2width,sp);
    335340
    336341    for (size_t dim=0; dim < dims(); dim++) {
     
    342347        }
    343348        _tmpBuf.appendf(
    344 "    <%s>\n\
    345         <label>%s</label>\n\
    346         <description>%s</description>\n\
    347         <units>%s</units>\n\
    348         <scale>%s</scale>\n",
     349"%8$*6$s<%1$s>\n\
     350%8$*7$s<label>%2$s</label>\n\
     351%8$*7$s<description>%3$s</description>\n\
     352%8$*7$s<units>%4$s</units>\n\
     353%8$*7$s<scale>%5$s</scale>\n",
    349354        tmpAxis->name(), tmpAxis->label(), tmpAxis->desc(),
    350         tmpAxis->units(), tmpAxis->scale());
     355        tmpAxis->units(), tmpAxis->scale(),l1width,l2width,sp);
    351356
    352357        if (_markerList != NULL) {
     
    355360                AxisMarker *m = (AxisMarker *) Rp_ChainGetValue(l);
    356361                if (strcmp(tmpAxis->name(),m->axisName()) == 0) {
    357                     _tmpBuf.append(m->xml());
     362                    _tmpBuf.append(m->xml(indent+tabstop,tabstop));
    358363                }
    359364                l = Rp_ChainNextLink(l);
    360365            }
    361366        }
    362         _tmpBuf.appendf("    </%s>\n",tmpAxis->name());
    363     }
    364 
    365     _tmpBuf.append("    <component>\n        <xhw>\n");
     367        _tmpBuf.appendf("%3$*2$s</%1$s>\n",tmpAxis->name(),l1width,sp);
     368    }
     369
     370    _tmpBuf.appendf("%3$*1$s<component>\n%3$*2$s<xhw>\n",l1width,l2width,sp);
    366371    for (size_t idx=0; idx < nmemb; idx++) {
    367372        for (size_t dim=0; dim < dims(); dim++) {
     
    370375        _tmpBuf.append("\n",1);
    371376    }
    372     _tmpBuf.append("        </xhw>\n    </component>\n</curve>");
    373     _tmpBuf.append("\0",1);
     377    _tmpBuf.appendf("%4$*3$s</xhw>\n%4$*2$s</component>\n%4$*1$s</curve>",
     378        indent,l1width,l2width,sp);
    374379
    375380    return _tmpBuf.bytes();
  • trunk/src/objects/RpHistogram.h

    r1528 r1560  
    7373        size_t nbins(void) const;
    7474
    75         const char *xml();
     75        const char *xml(size_t indent, size_t tabstop);
    7676        const int is(void) const;
    7777
  • trunk/src/objects/RpNumber.cc

    r1528 r1560  
    1515#include "RpUnits.h"
    1616#include "RpSimpleBuffer.h"
     17#include "RpUnitsCInterface.h"
     18#include "RpParserXML.h"
     19#include "RpPath.h"
    1720
    1821using namespace Rappture;
     
    2427     _presets (NULL)
    2528{
     29    // FIXME: empty names should be autoname'd
     30    this->name("");
    2631    this->path("");
    2732    this->label("");
     
    3136    this->min(0.0);
    3237    this->max(0.0);
    33     // need to set this to the None unit
     38    // FIXME: empty units should be set to the None unit
    3439    // this->units(units);
    3540}
    3641
    37 Number::Number(const char *path, const char *units, double val)
     42Number::Number(const char *name, const char *units, double val)
    3843   : Object (),
    3944     _minSet (0),
     
    4348    const RpUnits *u = NULL;
    4449
    45     this->path(path);
     50    this->name(name);
     51    this->path("");
    4652    this->label("");
    4753    this->desc("");
     
    5864}
    5965
    60 Number::Number(const char *path, const char *units, double val,
     66Number::Number(const char *name, const char *units, double val,
    6167               double min, double max, const char *label,
    6268               const char *desc)
     
    6874    const RpUnits *u = NULL;
    6975
    70     this->path(path);
     76    this->name(name);
     77    this->path("");
    7178    this->label(label);
    7279    this->desc(desc);
     
    112119    this->units(o.units());
    113120
    114     // need to copy _presets
     121    // FIXME: need to copy _presets
    115122}
    116123
     
    225232
    226233    return *this;
     234}
     235
     236Number&
     237Number::addPreset(const char *label, const char *desc, const char *val)
     238{
     239    double valval = 0.0;
     240    const char *valunits = "";
     241    char *endptr = NULL;
     242    int result = 0;
     243
     244    std::string vstr = RpUnits::convert(val,"",RPUNITS_UNITS_OFF,&result);
     245    if (result) {
     246        // probably shouldnt trust this result
     247        fprintf(stderr,"error in RpUnits::convert in addPreset\n");
     248    }
     249    size_t len = vstr.length();
     250    valunits = val+len;
     251
     252    valval = strtod(val,&endptr);
     253    if ( (endptr == val) || (endptr != valunits) ) {
     254        // error? strtod was not able to find the same
     255        // units location as RpUnits::convert
     256        fprintf(stderr,"error while parsing units in addPreset\n");
     257    }
     258
     259    return addPreset(label,desc,valval,valunits);
    227260}
    228261
     
    276309
    277310const char *
    278 Number::xml()
    279 {
     311Number::xml(size_t indent, size_t tabstop)
     312{
     313    size_t l1width = indent + (1*tabstop);
     314    size_t l2width = indent + (2*tabstop);
     315    const char *sp = "";
     316
    280317    Path p(path());
    281318    _tmpBuf.clear();
    282319
    283320    _tmpBuf.appendf(
    284 "<number id='%s'>\n\
    285     <about>\n\
    286         <label>%s</label>\n\
    287         <description>%s</description>\n\
    288     </about>\n\
    289     <units>%s</units>\n",
    290        p.id(),label(),desc(),units());
     321"%8$*5$s<number id='%1$s'>\n\
     322%8$*6$s<about>\n\
     323%8$*7$s<label>%2$s</label>\n\
     324%8$*7$s<description>%3$s</description>\n\
     325%8$*6$s</about>\n\
     326%8$*6$s<units>%4$s</units>\n",
     327       p.id(),label(),desc(),units(),indent,l1width,l2width,sp);
    291328
    292329    if (_minSet) {
    293         _tmpBuf.appendf("    <min>%g%s</min>\n", min(),units());
     330        _tmpBuf.appendf("%4$*3$s<min>%1$g%2$s</min>\n", min(),units(),l1width,sp);
    294331    }
    295332    if (_maxSet) {
    296         _tmpBuf.appendf("    <max>%g%s</max>\n", max(),units());
     333        _tmpBuf.appendf("%4$*3$s<max>%1$g%2$s</max>\n", max(),units(),l1width,sp);
    297334    }
    298335
    299336    _tmpBuf.appendf(
    300 "    <default>%g%s</default>\n\
    301     <current>%g%s</current>\n\
    302 </number>",
    303        def(),units(),cur(),units());
     337"%6$*5$s<default>%1$g%3$s</default>\n\
     338%6$*5$s<current>%2$g%3$s</current>\n\
     339%6$*4$s</number>",
     340       def(),cur(),units(),indent,l1width,sp);
    304341
    305342    return _tmpBuf.bytes();
    306343}
     344
     345/**********************************************************************/
     346// METHOD: xml(const char *xmltext)
     347/// configure the object based on Rappture1.1 xmltext
     348/**
     349 * Configure the object based on the provided xml
     350 */
     351
     352void
     353Number::xml(const char *xmltext)
     354{
     355    Rp_ParserXml *p = NULL;
     356
     357    p = Rp_ParserXmlCreate();
     358
     359    Rp_ParserXmlParse(p, xmltext);
     360
     361    Rp_TreeNode node = Rp_ParserXmlElement(p,NULL);
     362    name(Rp_ParserXmlNodeId(p,node));
     363    label(Rp_ParserXmlGet(p,"about.label"));
     364    desc(Rp_ParserXmlGet(p,"about.description"));
     365    units(Rp_ParserXmlGet(p,"units"));
     366    minFromStr(Rp_ParserXmlGet(p,"min"));
     367    maxFromStr(Rp_ParserXmlGet(p,"max"));
     368    defFromStr(Rp_ParserXmlGet(p,"default"));
     369    curFromStr(Rp_ParserXmlGet(p,"current"));
     370
     371    // collect info about the preset values
     372    Rp_Chain *childChain = Rp_ChainCreate();
     373    Rp_ParserXmlChildren(p,NULL,"preset",childChain);
     374    Rp_ChainLink *l = Rp_ChainFirstLink(childChain);
     375    while (l != NULL) {
     376        Rp_TreeNode presetNode = (Rp_TreeNode) Rp_ChainGetValue(l);
     377        Rp_ParserXmlBaseNode(p,presetNode);
     378
     379        const char *presetlabel = Rp_ParserXmlGet(p,"label");
     380        const char *presetdesc = Rp_ParserXmlGet(p,"description");
     381        const char *presetvalue = Rp_ParserXmlGet(p,"value");
     382        addPreset(presetlabel,presetdesc,presetvalue);
     383
     384
     385        l = Rp_ChainNextLink(l);
     386    }
     387
     388    Rp_ChainDestroy(childChain);
     389
     390    // return the base node to the tree root
     391    Rp_ParserXmlBaseNode(p,NULL);
     392}
     393
     394/**********************************************************************/
     395// METHOD: tree()
     396/// return the object as a tree
     397/**
     398 * Represent the object as a tree.
     399 * An Rp_TreeNode is returned.
     400 */
     401
     402/*
     403Rp_TreeNode
     404tree()
     405{
     406    return NULL;
     407}
     408*/
     409
     410/**********************************************************************/
     411// METHOD: tree(Rp_TreeNode root)
     412/// construct a number object from the provided tree
     413/**
     414 * construct a number object from the provided tree
     415 */
     416
     417/*
     418void
     419tree(
     420    Rp_TreeNode root)
     421{
     422    if (root == NULL) {
     423        // FIXME: setup error
     424    }
     425}
     426*/
    307427
    308428/**********************************************************************/
     
    321441
    322442
     443/**********************************************************************/
     444// METHOD: minFromStr()
     445/// xml helper function to receive min value as a string
     446/**
     447 * convert string to value and units and store as min
     448 */
     449
     450void
     451Number::minFromStr(
     452    const char *val)
     453{
     454    double numericVal = 0;
     455    int err = 0;
     456
     457    numericVal = rpConvertDbl(val,units(),&err);
     458
     459    if (!err) {
     460        min(numericVal);
     461    } else {
     462        // FIXME: add error code
     463    }
     464}
     465
     466/**********************************************************************/
     467// METHOD: maxFromStr()
     468/// xml helper function to receive max value as a string
     469/**
     470 * convert string to value and units and store as max
     471 */
     472
     473void
     474Number::maxFromStr(
     475    const char *val)
     476{
     477    double numericVal = 0;
     478    int err = 0;
     479
     480    numericVal = rpConvertDbl(val,units(),&err);
     481
     482    if (!err) {
     483        max(numericVal);
     484    } else {
     485        // FIXME: add error code
     486    }
     487}
     488
     489/**********************************************************************/
     490// METHOD: defFromStr()
     491/// xml helper function to receive default value as a string
     492/**
     493 * convert string to value and units and store as default
     494 */
     495
     496void
     497Number::defFromStr(
     498    const char *val)
     499{
     500    double numericVal = 0;
     501    int err = 0;
     502
     503    numericVal = rpConvertDbl(val,units(),&err);
     504
     505    if (!err) {
     506        def(numericVal);
     507    } else {
     508        // FIXME: add error code
     509    }
     510}
     511
     512/**********************************************************************/
     513// METHOD: currFromStr()
     514/// xml helper function to receive current value as a string
     515/**
     516 * convert string to value and units and store as current
     517 */
     518
     519void
     520Number::curFromStr(
     521    const char *val)
     522{
     523    double numericVal = 0;
     524    int err = 0;
     525
     526    numericVal = rpConvertDbl(val,units(),&err);
     527
     528    if (!err) {
     529        cur(numericVal);
     530    } else {
     531        // FIXME: add error code
     532    }
     533}
     534
     535
     536
    323537// -------------------------------------------------------------------- //
    324538
  • trunk/src/objects/RpNumber.h

    r1528 r1560  
    2222
    2323        Number();
    24         Number(const char *path, const char *units, double val);
     24        Number(const char *name, const char *units, double val);
    2525
    26         Number(const char *path, const char *units, double val,
     26        Number(const char *name, const char *units, double val,
    2727               double min, double max, const char *label,
    2828               const char *desc);
     
    5252                          double val, const char *units);
    5353
     54        Number& addPreset(const char *label, const char *desc,
     55                          const char *val);
     56
    5457        Number& delPreset(const char *label);
    5558
    56         const char* xml();
     59        const char* xml(size_t indent, size_t tabstop);
     60        void xml(const char *xmltext);
     61
     62        /*
     63        Rp_TreeNode tree();
     64        void tree(Rp_TreeNode root);
     65        */
     66
    5767        const int is() const;
     68
     69        void minFromStr(const char *val);
     70        void maxFromStr(const char *val);
     71        void defFromStr(const char *val);
     72        void curFromStr(const char *val);
    5873
    5974    private:
  • trunk/src/objects/RpObject.cc

    r1528 r1560  
    2525
    2626Object::Object (
     27    const char *name,
    2728    const char *path,
    2829    const char *label,
     
    3132    const char *color   )
    3233{
     34    this->name(name);
    3335    this->path(path);
    3436    this->label(label);
     
    4042Object::Object(const Object& o)
    4143{
     44    name(o.name());
    4245    path(o.path());
    4346    label(o.label());
     
    5861
    5962const char*
     63Object::name() const
     64{
     65    return propstr("name");
     66}
     67
     68void
     69Object::name(const char *p)
     70{
     71    propstr("name",p);
     72}
     73
     74const char*
    6075Object::path() const
    6176{
     
    201216    }
    202217
     218    if (val == NULL) {
     219        // no value provided, no value stored.
     220        // FIXME: raise error.
     221        return;
     222    }
     223
    203224    // set the value
    204225    // FIXME: this is suspect,
    205226    // want to use void's and void*'s but c++ wont let me
    206227    // g++ says there is no delete[] for void*
     228    // FIXME: can probably just get the length and use property() fxn
    207229    size_t l = strlen(val);
    208230    str = new char[l+1];
     
    276298
    277299const char *
    278 Object::xml() const
     300Object::xml(size_t indent, size_t tabstop) const
    279301{
    280302    return NULL;
  • trunk/src/objects/RpObject.h

    r1528 r1560  
    2424    public:
    2525        Object ();
    26         Object (const char *path,
     26        Object (const char *name,
     27                const char *path,
    2728                const char *label,
    2829                const char *desc,
     
    3132        Object (const Object& o);
    3233        virtual ~Object();
     34
     35        const char *name(void) const;
     36        void name(const char *p);
    3337
    3438        const char *path(void) const;
     
    4549
    4650        const char *color(void) const;
    47         void color(const char *);
     51        void color(const char *p);
    4852
    4953        // void *icon(void) const;
     
    6670
    6771        // get the Rappture1.1 xml text for this object
    68         virtual const char *xml() const;
     72        virtual const char *xml(size_t indent, size_t tabstop) const;
    6973
    7074        // set the object properties based on Rappture1.1 xml text
  • 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    }
  • trunk/src/objects/RpPath.h

    r1528 r1560  
    4848    Path& add(const char *el);  // turns input into input.number(blah)
    4949    Path& del();                // turns input.number(blah) into input
     50    bool eof();
     51
     52    Path& first();
     53    Path& prev();
     54    Path& next();
     55    Path& last();
     56    size_t count();
    5057
    5158    // turns input.number(blah) into number(blah)
    52     const char *component(void);    // get component of the path
    53     void component(const char *p);  // set component of the path
     59    const char *component(void);    // get component of the current component
     60    void component(const char *p);  // set component of the current component
    5461
    5562    // turns input.number(blah) into blah
    56     const char *id(void);       // get the id of the path
    57     void id(const char *p);     // set the id of the path
     63    const char *id(void);       // get the id of the current component
     64    void id(const char *p);     // set the id of the current component
    5865
    5966    // turns input.number(blah) into number
    60     const char *type(void);     // get the type of the path
    61     void type(const char *p);   // set the type of the path
     67    const char *type(void);     // get the type of the current component
     68    void type(const char *p);   // set the type of the current component
    6269
    6370    // turns input.number(blah) into input
    64     const char *parent(void);   // get the parent of the path
    65     void parent(const char *p); // set the parent of the path
     71    const char *parent(void);   // get the parent of the current component
     72    void parent(const char *p); // set the parent of the current component
     73
     74    // turns input.number2(blah) into 2
     75    size_t degree(void);        // get the degree of the current component
     76    void degree(size_t degree); // set the degree of the current component
    6677
    6778    const char *path(void);     // get the path
     
    7384        const char *type;
    7485        const char *id;
     86        size_t degree;
    7587    } componentStruct;
    7688
     
    8092    Rp_Chain *__parse(const char *p);
    8193    componentStruct *__createComponent(const char *p, int start,
    82                         int end, int idOpenParen, int idCloseParen);
     94                        int end, int idOpenParen, int idCloseParen,
     95                        size_t degree);
    8396    void __deleteComponent(componentStruct *c);
    8497
    8598    char _ifs;
    8699    Rp_Chain *_pathList;
     100    Rp_ChainLink *_currLink;
    87101    SimpleCharBuffer b;
    88102    SimpleCharBuffer tmpBuf;
  • trunk/src/objects/RpPlot.cc

    r1528 r1560  
    258258
    259259const char *
    260 Plot::xml()
     260Plot::xml(size_t indent, size_t tabstop)
    261261{
    262262
     
    302302        }
    303303
    304         _tmpBuf.append(c->xml());
     304        _tmpBuf.append(c->xml(indent,tabstop));
    305305        _tmpBuf.append("\n",1);
    306306        l = Rp_ChainNextLink(l);
  • trunk/src/objects/RpPlot.h

    r1528 r1560  
    4242        Curve *getNthCurve(size_t n) const;
    4343
    44         const char *xml();
     44        const char *xml(size_t indent, size_t tabstop);
    4545        const int is() const;
    4646
  • trunk/src/objects/RpScatter.cc

    r1528 r1560  
    2323    this->desc("");
    2424    this->group("");
     25    propstr("type","scatter");
    2526}
    2627
     
    3233    this->desc("");
    3334    this->group("");
     35    propstr("type","scatter");
    3436}
    3537
     
    4244    this->desc(desc);
    4345    this->group(group);
     46    propstr("type","scatter");
    4447}
    4548
     
    7174 */
    7275
     76/*
    7377const char *
    74 Scatter::xml()
     78Scatter::xml(size_t indent, size_t tabstop)
    7579{
    7680// FIXME: the xml function should just read an array
     
    122126    return _tmpBuf.bytes();
    123127}
     128*/
    124129
    125130/**********************************************************************/
  • trunk/src/objects/RpScatter.h

    r1528 r1560  
    3333        virtual ~Scatter();
    3434
    35         const char *xml();
     35        // const char *xml();
    3636        const int is() const;
    3737
  • trunk/src/objects/RpString.cc

    r1528 r1560  
    7878
    7979const char *
    80 String::xml()
     80String::xml(size_t indent, size_t tabstop)
    8181{
     82    size_t l1width = indent + tabstop;
     83    size_t l2width = indent + (2*tabstop);
     84    const char *sp = "";
     85
    8286    Path p(path());
    8387    _tmpBuf.clear();
    8488
    8589    _tmpBuf.appendf(
    86 "<string id='%s'>\n\
    87     <about>\n\
    88         <label>%s</label>\n\
    89         <description>%s</description>\n\
    90         <hints>%s</hints>\n\
    91     </about>\n\
    92     <size>%ix%i</size>\n\
    93     <default>%s</default>\n\
    94     <current>%s</current>\n\
    95 </string>\n",
    96        p.id(),label(),desc(),hints(),width(),height(),def(),cur());
     90"%12$*9$s<string id='%1$s'>\n\
     91%12$*10$s<about>\n\
     92%12$*11$s<label>%2$s</label>\n\
     93%12$*11$s<description>%3$s</description>\n\
     94%12$*11$s<hints>%4$s</hints>\n\
     95%12$*10$s</about>\n\
     96%12$*10$s<size>%5$ix%6$i</size>\n\
     97%12$*10$s<default>%7$s</default>\n\
     98%12$*10$s<current>%8$s</current>\n\
     99%12$*9$s</string>\n",
     100       p.id(),label(),desc(),hints(),width(),height(),def(),cur(),
     101       indent, l1width, l2width, sp);
    97102
    98103    return _tmpBuf.bytes();
  • trunk/src/objects/RpString.h

    r1528 r1560  
    3939    Accessor<size_t> height;
    4040
    41     const char *xml();
     41    const char *xml(size_t indent, size_t tabstop);
    4242    const int is() const;
    4343
  • trunk/src/objects/RpTree.c

    r1528 r1560  
    220220 */
    221221static Node *
    222 NewNode(TreeObject *treeObjPtr, CONST char *name, int inode)
     222NewNode(TreeObject *treeObjPtr, CONST char *name, size_t inode)
    223223{
    224224    Node *nodePtr;
     
    840840    Node *nodePtr;  /* Node to be inserted. */
    841841    TreeObject *treeObjPtr;
    842     int inode;
     842    size_t inode;
    843843    int isNew;
    844844
     
    890890                             * be inserted. */
    891891    CONST char *name,       /* Name of node. */
    892     int inode,              /* Requested id of the new node. If a
     892    size_t inode,           /* Requested id of the new node. If a
    893893                             * node by this id already exists in the
    894894                             * tree, no node is created. */
     
    10041004
    10051005Rp_TreeNode
    1006 Rp_TreeGetNode(TreeClient *clientPtr, unsigned int inode)
     1006Rp_TreeGetNode(TreeClient *clientPtr, size_t inode)
    10071007{
    10081008    TreeObject *treeObjPtr = clientPtr->treeObject;
     
    10991099    label = Rp_TreeGetKey(string);
    11001100    for (nodePtr = parentPtr->first; nodePtr != NULL; nodePtr = nodePtr->next) {
     1101        if (label == nodePtr->label) {
     1102            return nodePtr;
     1103        }
     1104    }
     1105    return NULL;
     1106}
     1107
     1108/*
     1109 *----------------------------------------------------------------------
     1110 *
     1111 * Rp_TreeFindChildNext --
     1112 *
     1113 *  Searches for the next named node in a parent's chain of siblings.
     1114 *
     1115 *
     1116 * Results:
     1117 *  If found, the child node is returned, otherwise NULL.
     1118 *
     1119 *----------------------------------------------------------------------
     1120 */
     1121Rp_TreeNode
     1122Rp_TreeFindChildNext(Node *childPtr, CONST char *string)
     1123{
     1124    Rp_TreeKey label;
     1125    register Node *nodePtr;
     1126
     1127    label = Rp_TreeGetKey(string);
     1128    for (nodePtr = childPtr->next; nodePtr != NULL; nodePtr = nodePtr->next) {
    11011129        if (label == nodePtr->label) {
    11021130            return nodePtr;
     
    14811509}
    14821510
     1511/*
     1512 * commented out to avoid compiler warnings about function not being used
     1513 */
     1514/*
    14831515static int
    14841516ParseParentheses(
     
    14871519    char **rightPtr)
    14881520{
    1489     register char *p;
    1490     char *left, *right;
     1521    register char *p = NULL;
     1522    char *left = NULL;
     1523    char *right = NULL;
    14911524
    14921525    left = right = NULL;
     
    15101543    return RP_OK;
    15111544}
     1545*/
    15121546
    15131547//FIXME: commented out because it calls Rp_TreeGetArrayValue
    1514 //int
    1515 //Rp_TreeGetValue(
    1516 //    TreeClient *clientPtr,
    1517 //    Node *nodePtr,
    1518 //    CONST char *string,     /* String identifying the field in node. */
    1519 //    void **objPtrPtr)
    1520 //{
    1521 //    char *left, *right;
    1522 //    int result;
    1523 //
     1548int
     1549Rp_TreeGetValue(
     1550    TreeClient *clientPtr,
     1551    Node *nodePtr,
     1552    CONST char *string,     /* String identifying the field in node. */
     1553    void **objPtrPtr)
     1554{
     1555    char *left = NULL;
     1556    char *right = NULL;
     1557    int result;
     1558
     1559// uncomment after Rp_TreeGetArrayValue is fixed
    15241560//    if (ParseParentheses(string, &left, &right) != TCL_OK) {
    15251561//        return TCL_ERROR;
    15261562//    }
    1527 //    if (left != NULL) {
    1528 //        *left = *right = '\0';
    1529 //        result = Rp_TreeGetArrayValue(clientPtr, nodePtr, string, left + 1, objPtrPtr);
    1530 //        *left = '(', *right = ')';
    1531 //    } else {
    1532 //        result = Rp_TreeGetValueByKey(clientPtr, nodePtr,
    1533 //                    Rp_TreeGetKey(string), objPtrPtr);
    1534 //    }
    1535 //    return result;
    1536 //}
     1563    if (left != NULL) {
     1564        *left = *right = '\0';
     1565        // result = Rp_TreeGetArrayValue(clientPtr, nodePtr, string, left + 1, objPtrPtr);
     1566        *left = '(', *right = ')';
     1567    } else {
     1568        result = Rp_TreeGetValueByKey(clientPtr, nodePtr,
     1569                    Rp_TreeGetKey(string), objPtrPtr);
     1570    }
     1571    return result;
     1572}
    15371573
    15381574//FIXME: commented out because it calls Rp_TreeSetArrayValue
    1539 //int
    1540 //Rp_TreeSetValue(
    1541 //    TreeClient *clientPtr,
    1542 //    Node *nodePtr,          /* Node to be updated. */
    1543 //    CONST char *string,     /* String identifying the field in node. */
    1544 //    void *valueObjPtr)      /* New value of field. If NULL, field
    1545 //                             * is deleted. */
    1546 //{
    1547 //    char *left, *right;
    1548 //    int result;
    1549 //
     1575int
     1576Rp_TreeSetValue(
     1577    TreeClient *clientPtr,
     1578    Node *nodePtr,          /* Node to be updated. */
     1579    CONST char *string,     /* String identifying the field in node. */
     1580    void *valueObjPtr)      /* New value of field. If NULL, field
     1581                             * is deleted. */
     1582{
     1583    char *left = NULL;
     1584    char *right = NULL;
     1585    int result;
     1586
     1587// uncomment after Rp_TreeSetArrayValue is fixed
    15501588//    if (ParseParentheses(string, &left, &right) != RP_OK) {
    15511589//        return RP_ERROR;
    15521590//    }
    1553 //    if (left != NULL) {
    1554 //        *left = *right = '\0';
    1555 //        result = Rp_TreeSetArrayValue(clientPtr, nodePtr, string, left + 1, valueObjPtr);
    1556 //        fprintf(stderr, "Rp_TreeSetArrayValue not supported\n", name);
    1557 //
    1558 //        *left = '(', *right = ')';
    1559 //    } else {
    1560 //        result = Rp_TreeSetValueByKey(clientPtr, nodePtr,
    1561 //                    Rp_TreeGetKey(string), valueObjPtr);
    1562 //    }
    1563 //    return result;
    1564 //}
     1591    if (left != NULL) {
     1592        *left = *right = '\0';
     1593        //result = Rp_TreeSetArrayValue(clientPtr, nodePtr, string, left + 1, valueObjPtr);
     1594        *left = '(', *right = ')';
     1595    } else {
     1596        result = Rp_TreeSetValueByKey(clientPtr, nodePtr,
     1597                    Rp_TreeGetKey(string), valueObjPtr);
     1598    }
     1599    return result;
     1600}
    15651601
    15661602//FIXME: commented out because it calls Rp_TreeUnsetArrayValue
    1567 //int
    1568 //Rp_TreeUnsetValue(
    1569 //    TreeClient *clientPtr,
    1570 //    Node *nodePtr,          /* Node to be updated. */
    1571 //    CONST char *string)     /* String identifying the field in node. */
    1572 //{
    1573 //    char *left, *right;
    1574 //    int result;
    1575 //
     1603int
     1604Rp_TreeUnsetValue(
     1605    TreeClient *clientPtr,
     1606    Node *nodePtr,          /* Node to be updated. */
     1607    CONST char *string)     /* String identifying the field in node. */
     1608{
     1609    char *left = NULL;
     1610    char *right = NULL;
     1611    int result;
     1612
     1613// uncomment after Rp_TreeUnsetArrayValue is fixed
    15761614//    if (ParseParentheses(string, &left, &right) != RP_OK) {
    15771615//        return RP_ERROR;
    15781616//    }
    1579 //    if (left != NULL) {
    1580 //        *left = *right = '\0';
    1581 //        result = Rp_TreeUnsetArrayValue(clientPtr, nodePtr, string, left + 1);
    1582 //        *left = '(', *right = ')';
    1583 //    } else {
    1584 //        result = Rp_TreeUnsetValueByKey(clientPtr, nodePtr, Rp_TreeGetKey(string));
    1585 //    }
    1586 //    return result;
    1587 //}
     1617    if (left != NULL) {
     1618        *left = *right = '\0';
     1619        // result = Rp_TreeUnsetArrayValue(clientPtr, nodePtr, string, left + 1);
     1620        *left = '(', *right = ')';
     1621    } else {
     1622        result = Rp_TreeUnsetValueByKey(clientPtr, nodePtr, Rp_TreeGetKey(string));
     1623    }
     1624    return result;
     1625}
    15881626
    15891627//FIXME: commented out because it calls Rp_TreeArrayValueExists
    1590 //int
    1591 //Rp_TreeValueExists(TreeClient *clientPtr, Node *nodePtr, CONST char *string)
    1592 //{
    1593 //    char *left, *right;
    1594 //    int result;
    1595 //
     1628int
     1629Rp_TreeValueExists(TreeClient *clientPtr, Node *nodePtr, CONST char *string)
     1630{
     1631    char *left = NULL;
     1632    char *right = NULL;
     1633    int result;
     1634
     1635// uncomment after Rp_TreeArrayValueExists is fixed
    15961636//    if (ParseParentheses(string, &left, &right) != RP_OK) {
    15971637//        return FALSE;
    15981638//    }
    1599 //    if (left != NULL) {
    1600 //        *left = *right = '\0';
    1601 //        result = Rp_TreeArrayValueExists(clientPtr, nodePtr, string, left + 1);
    1602 //        *left = '(', *right = ')';
    1603 //    } else {
    1604 //        result = Rp_TreeValueExistsByKey(clientPtr, nodePtr,
    1605 //                Rp_TreeGetKey(string));
    1606 //    }
    1607 //    return result;
    1608 //}
     1639    if (left != NULL) {
     1640        *left = *right = '\0';
     1641        // result = Rp_TreeArrayValueExists(clientPtr, nodePtr, string, left + 1);
     1642        *left = '(', *right = ')';
     1643    } else {
     1644        result = Rp_TreeValueExistsByKey(clientPtr, nodePtr,
     1645                Rp_TreeGetKey(string));
     1646    }
     1647    return result;
     1648}
    16091649
    16101650Rp_TreeKey
     
    19551995//    return RP_OK;
    19561996//}
     1997
     1998int
     1999Rp_TreeGetTokenFromToken(
     2000    TreeClient *fromClientPtr, // old client from which to base the new client
     2001    TreeClient **clientPtrPtr) // new client
     2002{
     2003    TreeClient *clientPtr;
     2004    TreeObject *treeObjPtr;
     2005
     2006    if (fromClientPtr == NULL) {
     2007        fprintf(stderr, "can't create new token from null token\n");
     2008        return RP_ERROR;
     2009    }
     2010
     2011    treeObjPtr = fromClientPtr->treeObject;
     2012    if (treeObjPtr == NULL) {
     2013        fprintf(stderr, "can't find a tree object based on provided client\n");
     2014        return RP_ERROR;
     2015    }
     2016    clientPtr = NewTreeClient(treeObjPtr);
     2017    if (clientPtr == NULL) {
     2018        fprintf(stderr, "can't allocate token for tree \"%s\"",
     2019            treeObjPtr->name);
     2020        return RP_ERROR;
     2021    }
     2022    *clientPtrPtr = clientPtr;
     2023    return RP_OK;
     2024}
    19572025
    19582026void
     
    30313099            RebuildTable(nodePtr);
    30323100        }
    3033         } else {
     3101    } else {
    30343102        Value *prevPtr;
    30353103
  • trunk/src/objects/RpTree.h

    r1528 r1560  
    192192
    193193    unsigned int nChildren; /* # of children for this node. */
    194     unsigned int inode;     /* Serial number of the node. */
     194    // unsigned int inode;     /* Serial number of the node. */
     195    size_t inode;           /* Serial number of the node. */
    195196
    196197    unsigned short depth;   /* The depth of this node in the tree. */
     
    281282        Rp_TreeNode parent, CONST char *name, int position));
    282283EXTERN Rp_TreeNode Rp_TreeCreateNodeWithId _ANSI_ARGS_((Rp_Tree tree,
    283         Rp_TreeNode parent, CONST char *name, int position, int inode));
     284        Rp_TreeNode parent, CONST char *name, size_t inode, int position));
    284285
    285286EXTERN int Rp_TreeDeleteNode _ANSI_ARGS_((Rp_Tree tree, Rp_TreeNode node));
     
    288289        Rp_TreeNode parent, Rp_TreeNode before));
    289290
    290 EXTERN Rp_TreeNode Rp_TreeGetNode _ANSI_ARGS_((Rp_Tree tree,
    291         unsigned int inode));
     291EXTERN Rp_TreeNode Rp_TreeGetNode _ANSI_ARGS_((Rp_Tree tree, size_t inode));
    292292
    293293EXTERN Rp_TreeNode Rp_TreeFindChild _ANSI_ARGS_((Rp_TreeNode parent,
     294        CONST char *name));
     295
     296EXTERN Rp_TreeNode Rp_TreeFindChildNext _ANSI_ARGS_((Rp_TreeNode child,
    294297        CONST char *name));
    295298
     
    391394        Rp_TreeApplyProc *proc, ClientData clientData));
    392395
     396EXTERN int Rp_TreeApplyXML _ANSI_ARGS_((Rp_TreeNode root,
     397        Rp_TreeApplyProc *proc, ClientData clientData));
     398
    393399EXTERN int Rp_TreeSortNode _ANSI_ARGS_((Rp_Tree tree, Rp_TreeNode node,
    394400        Rp_TreeCompareNodesProc *proc));
     
    399405// EXTERN int Rp_TreeExists _ANSI_ARGS_((CONST char *name));
    400406
    401 EXTERN int Rp_TreeGetToken _ANSI_ARGS_((CONST char *name,
    402         Rp_Tree *treePtr));
     407// EXTERN int Rp_TreeGetToken _ANSI_ARGS_((CONST char *name,
     408//         Rp_Tree *treePtr));
     409
     410EXTERN int Rp_TreeGetTokenFromToken _ANSI_ARGS_((
     411        CONST Rp_Tree tree, Rp_Tree *newToken));
    403412
    404413EXTERN void Rp_TreeReleaseToken _ANSI_ARGS_((Rp_Tree tree));
Note: See TracChangeset for help on using the changeset viewer.