- Timestamp:
- Aug 28, 2009, 5:54:24 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/objects/Makefile.in
r1528 r1560 18 18 axis \ 19 19 curve \ 20 dxReader \ 20 21 dxWriter \ 21 22 floatBuffer \ -
trunk/examples/objects/app-fermi/fermi1.cc
r1542 r1560 74 74 75 75 // do it the easy way, 76 // create a plot toadd to the library76 // create a plot and add to the library 77 77 // p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc); 78 78 79 Rappture::Plot *p1 = new Rappture::Plot( );79 Rappture::Plot *p1 = new Rappture::Plot(lib); 80 80 p1->add(nPts,fArr,EArr,"",curveLabel,curveDesc); 81 81 p1.propstr("xlabel","Fermi-Dirac Factor"); 82 82 p1.propstr("ylabel","Energy"); 83 83 p1.propstr("yunits","eV"); 84 85 // add the plot to the library86 lib.put(p1);87 84 88 85 … … 91 88 // c1->axis("xaxis","xlabel","xdesc","units","scale",dataArr,nPts); 92 89 93 Rappture::Curve *c1 = new Rappture::Curve( "output.curve(FDF)");90 Rappture::Curve *c1 = new Rappture::Curve(lib,"FDF"); 94 91 c1->label(curveLabel); 95 92 c1->desc(curveDesc); -
trunk/examples/objects/app-fermi/fermi2.cc
r1542 r1560 25 25 Rappture::Number *T = NULL; 26 26 Rappture::Number *Ef = NULL; 27 double E = 0.0;28 27 double dE = 0.0; 29 28 double kT = 0.0; 30 29 double Emin = 0.0; 31 30 double Emax = 0.0; 32 double f = 0.0; 31 size_t nPts = 200; 32 double E[nPts]; 33 double f[nPts]; 33 34 34 35 // create a rappture library from the file filePath … … 55 56 Emax = Ef->value("eV") + 10*kT; 56 57 57 dE = 0.005*(Emax-Emin);58 dE = (1.0/nPts)*(Emax-Emin); 58 59 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; 63 63 f = 1.0/(1.0 + exp((E - Ef)/kT)); 64 f Buf.append(f);65 E Buf.append(E);64 fArr[idx] = f; 65 EArr[idx] = E; 66 66 rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating"); 67 67 } 68 const double *fArr = fBuf.data();69 const double *EArr = EBuf.data();70 size_t nPts = fBuf.nmemb();71 68 72 69 const char *curveLabel = "Fermi-Dirac Curve" … … 75 72 // do it the easy way, 76 73 // create a plot to add to the library 74 // plot is registered with lib upon object creation 77 75 // p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc); 78 76 79 Rappture::Plot *p1 = new Rappture::Plot( );77 Rappture::Plot *p1 = new Rappture::Plot(lib); 80 78 p1->add(nPts,fArr,EArr,"",curveLabel,curveDesc); 81 79 p1.propstr("xlabel","Fermi-Dirac Factor"); … … 83 81 p1.propstr("yunits","eV"); 84 82 85 // add the plot to the library86 lib.put(p1);87 88 89 // or do it the harder way,90 // create a curve to add to the library91 // 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 library100 lib.put(c1);101 102 83 lib.result(); 103 84 104 85 // clean up memory 105 86 delete lib; 87 delete T; 88 delete Ef; 106 89 delete p1; 107 delete c1;108 90 109 91 return 0; -
trunk/examples/objects/curve/curve.cc
r1528 r1560 1 1 #include <iostream> 2 2 #include "RpCurve.h" 3 4 size_t indent = 0; 5 size_t tabstop = 4; 3 6 4 7 int test( … … 34 37 } 35 38 36 std::cout << "xml: " << n->xml( ) << std::endl;39 std::cout << "xml: " << n->xml(indent,tabstop) << std::endl; 37 40 return 0; 38 41 } -
trunk/examples/objects/histogram/histogram.cc
r1528 r1560 36 36 h3->yaxis("ylabel3","ydesc3","yunits3"); 37 37 38 size_t indent = 0; 39 size_t tabstop = 4; 38 40 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)); 42 44 43 45 return 0; -
trunk/examples/objects/number/Makefile.in
r1386 r1560 34 34 FILES = \ 35 35 $(srcdir)/number.cc \ 36 $(srcdir)/number_1_0_in.xml \ 36 37 Makefile 37 38 -
trunk/examples/objects/number/number.cc
r1528 r1560 1 1 #include <iostream> 2 #include <errno.h> 3 #include <fstream> 4 #include <sys/stat.h> 2 5 #include "RpNumber.h" 6 7 size_t indent = 0; 8 size_t tabstop = 4; 3 9 4 10 int 5 11 printNumber(Rappture::Number *n) 6 12 { 13 std::cout << "name: " << n->name() << std::endl; 7 14 std::cout << "path: " << n->path() << std::endl; 8 15 std::cout << "label: " << n->label() << std::endl; … … 13 20 std::cout << "max: " << n->max() << std::endl; 14 21 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 26 int 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 44 int 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 60 size_t 61 readFile ( 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 } 106 int 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 146 int 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 178 int 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; 17 211 } 18 212 19 213 int main() 20 214 { 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 8 8 const char *received) 9 9 { 10 if (strcmp(expected,received) != 0) { 10 if ((!expected && received) || 11 (expected && !received) || 12 (expected && received && strcmp(expected,received) != 0)) { 11 13 printf("Error: %s\n", testname); 12 14 printf("\t%s\n", desc); … … 114 116 115 117 const char *path = "input.group(tabs).number(mynum).current"; 116 const char *expected = "";118 const char *expected = NULL; 117 119 const char *received = NULL; 118 120 … … 773 775 // FIXME: add test for parent get/set functions 774 776 // 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 775 784 776 785 int main() -
trunk/examples/objects/plot/plot.cc
r1528 r1560 41 41 std::printf("curveCnt = %zu\n",curveCnt); 42 42 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)); 44 47 45 48 /* -
trunk/examples/objects/scatter/scatter.cc
r1528 r1560 41 41 std::printf("curveCnt = %zu\n",curveCnt); 42 42 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)); 44 46 45 47 /* -
trunk/examples/objects/tree/tree.c
r1528 r1560 14 14 Rp_Tree t; 15 15 16 Rp_TreeCreate(treeName, t);16 Rp_TreeCreate(treeName,&t); 17 17 received = Rp_TreeName(t); 18 18 … … 28 28 } 29 29 30 int 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 58 int 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 89 int 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 124 int 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 163 int 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 30 198 int main() 31 199 { 32 200 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 34 34 FILES = \ 35 35 $(srcdir)/xmlparser.cc \ 36 $(srcdir)/xmlparser_1_0_in.xml \ 37 $(srcdir)/xmlparser_1_0_out.xml \ 38 $(srcdir)/xmlparser_2_0_in.xml \ 36 39 $(srcdir)/tool.xml \ 37 40 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 7 size_t 8 readFile ( 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 54 int 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 82 int 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 123 int 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 = "\ 135 run.tool.about Press Simulate to view results.\n\ 136 run.tool.command tclsh @tool/fermi.tcl @driver\n\ 137 run.input.number(Ef).about.label Fermi Level\n\ 138 run.input.number(Ef).about.description Energy at center of distribution.\n\ 139 run.input.number(Ef).units eV\n\ 140 run.input.number(Ef).min -10eV\n\ 141 run.input.number(Ef).max 10eV\n\ 142 run.input.number(Ef).default 0eV\n\ 143 run.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 171 int 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 210 int 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 249 int 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 = "\ 261 run.tool.about Press Simulate to view results.\n\ 262 run.tool.command tclsh @tool/fermi.tcl @driver\n\ 263 run.input.number(Ef).about.label Fermi Level\n\ 264 run.input.number(Ef).about.description Energy at center of distribution.\n\ 265 run.input.number(Ef).units eV\n\ 266 run.input.number(Ef).min -10eV\n\ 267 run.input.number(Ef).max 10eV\n\ 268 run.input.number(Ef).default 0eV\n\ 269 run.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 302 int 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(); 198 310 199 311 return 0; -
trunk/src/core/RpSimpleBuffer.h
r1527 r1560 81 81 SimpleBuffer operator+(const SimpleBuffer& b) const; 82 82 SimpleBuffer<T>& operator+=(const SimpleBuffer<T>& b); 83 T operator[](size_t offset); 83 84 virtual ~SimpleBuffer(); 84 85 … … 241 242 242 243 /** 244 * Operator [] 245 * @param index into the buffer 246 */ 247 template<class T> 248 T 249 SimpleBuffer<T>::operator[](size_t idx) 250 { 251 return (_buf+idx); 252 } 253 254 255 /** 243 256 * Destructor 244 257 */ -
trunk/src/objects/Makefile.in
r1528 r1560 48 48 LN = ln -s 49 49 50 # RpDXReader.h \ 51 # RpDXWriter.h \ 52 50 53 HEADERS = \ 51 54 RpAccessor.h \ … … 62 65 RpHistogram.h \ 63 66 RpNumber.h \ 67 RpParserXML.h \ 64 68 RpPath.h \ 65 69 RpPlot.h \ … … 72 76 LOCAL_HEADERS = \ 73 77 RpHash.h 78 79 # RpDXReader.o \ 80 # RpDXWriter.o \ 74 81 75 82 OBJS = \ … … 86 93 RpHistogram.o \ 87 94 RpNumber.o \ 95 RpParserXML.o \ 88 96 RpPath.o \ 89 97 RpPlot.o \ -
trunk/src/objects/RpAccessor.h
r1528 r1560 71 71 Accessor<const char *>::operator() (const char *val) 72 72 { 73 if (val == NULL) { 74 return; 75 } 76 73 77 size_t len = strlen(val); 74 78 char *tmp = new char[len+1]; -
trunk/src/objects/RpArray1D.cc
r1528 r1560 180 180 181 181 const char * 182 Array1D::xml( )182 Array1D::xml(size_t indent, size_t tabstop) 183 183 { 184 184 return ""; -
trunk/src/objects/RpArray1D.h
r1528 r1560 41 41 static const char type[]; 42 42 43 const char *xml( void);43 const char *xml(size_t indent, size_t tabstop); 44 44 const int is(void) const; 45 45 -
trunk/src/objects/RpAxisMarker.cc
r1528 r1560 139 139 140 140 const char * 141 AxisMarker::xml( )141 AxisMarker::xml(size_t indent, size_t tabstop) 142 142 { 143 size_t l1width = indent + tabstop; 144 const char *sp = ""; 145 143 146 _tmpBuf.clear(); 144 147 145 148 _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); 151 155 152 156 _tmpBuf.append("\0",1); -
trunk/src/objects/RpAxisMarker.h
r1528 r1560 39 39 double at (void) const; 40 40 41 const char *xml( );41 const char *xml(size_t indent, size_t tabstop); 42 42 const int is(void) const; 43 43 -
trunk/src/objects/RpBoolean.cc
r1528 r1560 65 65 66 66 const char * 67 Boolean::xml( )67 Boolean::xml(size_t indent, size_t tabstop) 68 68 { 69 size_t l1width = indent + tabstop; 70 size_t l2width = indent + (2*tabstop); 71 const char *sp = ""; 72 69 73 Path p(path()); 70 74 _tmpBuf.clear(); … … 73 77 74 78 _tmpBuf.appendf( 75 " <boolean id=\"%s\">\n\76 77 <label>%s</label>\n\78 <description>%s</description>\n\79 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); 84 88 85 89 return _tmpBuf.bytes(); -
trunk/src/objects/RpBoolean.h
r1528 r1560 34 34 Accessor<int> cur; 35 35 36 const char *xml( );36 const char *xml(size_t indent, size_t tabstop); 37 37 const int is() const; 38 38 }; -
trunk/src/objects/RpChoice.cc
r1528 r1560 150 150 151 151 const char * 152 Choice::xml() 153 { 152 Choice::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 154 159 Path p(path()); 155 160 _tmpBuf.clear(); 156 161 157 162 _tmpBuf.appendf( 158 " <choice id='%s'>\n\159 160 <label>%s</label>\n\161 <description>%s</description>\n\162 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); 164 169 165 170 Rp_ChainLink *l = NULL; … … 168 173 option *op = (option *)Rp_ChainGetValue(l); 169 174 _tmpBuf.appendf( 170 " 171 172 <label>%s</label>\n\173 <description>%s</description>\n\174 175 <value>%s</value>\n\176 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); 178 183 l = Rp_ChainNextLink(l); 179 184 } 180 185 181 186 _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); 186 191 187 192 return _tmpBuf.bytes(); -
trunk/src/objects/RpChoice.h
r1528 r1560 41 41 Choice& delOption ( const char *label); 42 42 43 const char *xml( );43 const char *xml(size_t indent, size_t tabstop); 44 44 const int is() const; 45 45 -
trunk/src/objects/RpCurve.cc
r1528 r1560 259 259 260 260 const char * 261 Curve::xml() 262 { 261 Curve::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 263 267 Path p(path()); 264 268 … … 267 271 268 272 const double *dataArr[dims()]; 273 const char *type = propstr("type"); 269 274 270 275 _tmpBuf.clear(); 271 276 272 277 _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); 279 286 280 287 for (size_t dim=0; dim < dims(); dim++) { … … 283 290 dataArr[dim] = tmpAxis->data(); 284 291 _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", 291 298 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); 296 303 for (size_t idx=0; idx < nmemb; idx++) { 297 304 for(size_t dim=0; dim < dims(); dim++) { … … 300 307 _tmpBuf.append("\n",1); 301 308 } 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); 304 311 305 312 return _tmpBuf.bytes(); -
trunk/src/objects/RpCurve.h
r1528 r1560 48 48 size_t dims() const; 49 49 50 const char *xml( );50 const char *xml(size_t indent, size_t tabstop); 51 51 const int is() const; 52 52 -
trunk/src/objects/RpHistogram.cc
r1528 r1560 315 315 316 316 const char * 317 Histogram::xml() 318 { 317 Histogram::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 319 323 Path p(path()); 320 324 … … 327 331 328 332 _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); 335 340 336 341 for (size_t dim=0; dim < dims(); dim++) { … … 342 347 } 343 348 _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", 349 354 tmpAxis->name(), tmpAxis->label(), tmpAxis->desc(), 350 tmpAxis->units(), tmpAxis->scale() );355 tmpAxis->units(), tmpAxis->scale(),l1width,l2width,sp); 351 356 352 357 if (_markerList != NULL) { … … 355 360 AxisMarker *m = (AxisMarker *) Rp_ChainGetValue(l); 356 361 if (strcmp(tmpAxis->name(),m->axisName()) == 0) { 357 _tmpBuf.append(m->xml( ));362 _tmpBuf.append(m->xml(indent+tabstop,tabstop)); 358 363 } 359 364 l = Rp_ChainNextLink(l); 360 365 } 361 366 } 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); 366 371 for (size_t idx=0; idx < nmemb; idx++) { 367 372 for (size_t dim=0; dim < dims(); dim++) { … … 370 375 _tmpBuf.append("\n",1); 371 376 } 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); 374 379 375 380 return _tmpBuf.bytes(); -
trunk/src/objects/RpHistogram.h
r1528 r1560 73 73 size_t nbins(void) const; 74 74 75 const char *xml( );75 const char *xml(size_t indent, size_t tabstop); 76 76 const int is(void) const; 77 77 -
trunk/src/objects/RpNumber.cc
r1528 r1560 15 15 #include "RpUnits.h" 16 16 #include "RpSimpleBuffer.h" 17 #include "RpUnitsCInterface.h" 18 #include "RpParserXML.h" 19 #include "RpPath.h" 17 20 18 21 using namespace Rappture; … … 24 27 _presets (NULL) 25 28 { 29 // FIXME: empty names should be autoname'd 30 this->name(""); 26 31 this->path(""); 27 32 this->label(""); … … 31 36 this->min(0.0); 32 37 this->max(0.0); 33 // need to set thisto the None unit38 // FIXME: empty units should be set to the None unit 34 39 // this->units(units); 35 40 } 36 41 37 Number::Number(const char * path, const char *units, double val)42 Number::Number(const char *name, const char *units, double val) 38 43 : Object (), 39 44 _minSet (0), … … 43 48 const RpUnits *u = NULL; 44 49 45 this->path(path); 50 this->name(name); 51 this->path(""); 46 52 this->label(""); 47 53 this->desc(""); … … 58 64 } 59 65 60 Number::Number(const char * path, const char *units, double val,66 Number::Number(const char *name, const char *units, double val, 61 67 double min, double max, const char *label, 62 68 const char *desc) … … 68 74 const RpUnits *u = NULL; 69 75 70 this->path(path); 76 this->name(name); 77 this->path(""); 71 78 this->label(label); 72 79 this->desc(desc); … … 112 119 this->units(o.units()); 113 120 114 // need to copy _presets121 // FIXME: need to copy _presets 115 122 } 116 123 … … 225 232 226 233 return *this; 234 } 235 236 Number& 237 Number::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); 227 260 } 228 261 … … 276 309 277 310 const char * 278 Number::xml() 279 { 311 Number::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 280 317 Path p(path()); 281 318 _tmpBuf.clear(); 282 319 283 320 _tmpBuf.appendf( 284 " <number id='%s'>\n\285 286 <label>%s</label>\n\287 <description>%s</description>\n\288 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); 291 328 292 329 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); 294 331 } 295 332 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); 297 334 } 298 335 299 336 _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); 304 341 305 342 return _tmpBuf.bytes(); 306 343 } 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 352 void 353 Number::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 /* 403 Rp_TreeNode 404 tree() 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 /* 418 void 419 tree( 420 Rp_TreeNode root) 421 { 422 if (root == NULL) { 423 // FIXME: setup error 424 } 425 } 426 */ 307 427 308 428 /**********************************************************************/ … … 321 441 322 442 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 450 void 451 Number::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 473 void 474 Number::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 496 void 497 Number::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 519 void 520 Number::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 323 537 // -------------------------------------------------------------------- // 324 538 -
trunk/src/objects/RpNumber.h
r1528 r1560 22 22 23 23 Number(); 24 Number(const char * path, const char *units, double val);24 Number(const char *name, const char *units, double val); 25 25 26 Number(const char * path, const char *units, double val,26 Number(const char *name, const char *units, double val, 27 27 double min, double max, const char *label, 28 28 const char *desc); … … 52 52 double val, const char *units); 53 53 54 Number& addPreset(const char *label, const char *desc, 55 const char *val); 56 54 57 Number& delPreset(const char *label); 55 58 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 57 67 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); 58 73 59 74 private: -
trunk/src/objects/RpObject.cc
r1528 r1560 25 25 26 26 Object::Object ( 27 const char *name, 27 28 const char *path, 28 29 const char *label, … … 31 32 const char *color ) 32 33 { 34 this->name(name); 33 35 this->path(path); 34 36 this->label(label); … … 40 42 Object::Object(const Object& o) 41 43 { 44 name(o.name()); 42 45 path(o.path()); 43 46 label(o.label()); … … 58 61 59 62 const char* 63 Object::name() const 64 { 65 return propstr("name"); 66 } 67 68 void 69 Object::name(const char *p) 70 { 71 propstr("name",p); 72 } 73 74 const char* 60 75 Object::path() const 61 76 { … … 201 216 } 202 217 218 if (val == NULL) { 219 // no value provided, no value stored. 220 // FIXME: raise error. 221 return; 222 } 223 203 224 // set the value 204 225 // FIXME: this is suspect, 205 226 // want to use void's and void*'s but c++ wont let me 206 227 // g++ says there is no delete[] for void* 228 // FIXME: can probably just get the length and use property() fxn 207 229 size_t l = strlen(val); 208 230 str = new char[l+1]; … … 276 298 277 299 const char * 278 Object::xml( ) const300 Object::xml(size_t indent, size_t tabstop) const 279 301 { 280 302 return NULL; -
trunk/src/objects/RpObject.h
r1528 r1560 24 24 public: 25 25 Object (); 26 Object (const char *path, 26 Object (const char *name, 27 const char *path, 27 28 const char *label, 28 29 const char *desc, … … 31 32 Object (const Object& o); 32 33 virtual ~Object(); 34 35 const char *name(void) const; 36 void name(const char *p); 33 37 34 38 const char *path(void) const; … … 45 49 46 50 const char *color(void) const; 47 void color(const char * );51 void color(const char *p); 48 52 49 53 // void *icon(void) const; … … 66 70 67 71 // 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; 69 73 70 74 // set the object properties based on Rappture1.1 xml text -
trunk/src/objects/RpPath.cc
r1528 r1560 23 23 #include "RpChainHelper.h" 24 24 #include <cstring> 25 #include <cstdlib> 25 26 26 27 using namespace Rappture; … … 60 61 _ifs = b._ifs; 61 62 63 //FIXME: i think this is broken 62 64 Rp_ChainCopy (_pathList, b._pathList, Rp_ChainCharCpyFxn); 63 65 } … … 105 107 _ifs = '.'; 106 108 _pathList = Rp_ChainCreate(); 109 _currLink = Rp_ChainFirstLink(_pathList); 107 110 return; 108 111 } … … 134 137 int end, 135 138 int idOpenParen, 136 int idCloseParen) 139 int idCloseParen, 140 size_t degree) 137 141 { 138 142 componentStruct *c = new componentStruct(); … … 143 147 c->type = NULL; 144 148 c->id = NULL; 149 c->degree = degree; 145 150 146 151 if (idOpenParen < idCloseParen) { … … 171 176 the type and id of the third component are both blank. 172 177 for the above example paths, the id field of the first 173 components, the in dexcomponent, is NULL.178 components, the input component, is NULL. 174 179 i don't think there is a way to get a NULL type right now. 175 180 */ … … 215 220 int idCloseParen = -1; 216 221 componentStruct *c = NULL; 222 size_t degree = 1; 223 char *newEnd = NULL; 217 224 218 225 Rp_Chain *compList = Rp_ChainCreate(); … … 227 234 } else if (p[end] == ')') { 228 235 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); 229 250 } else if (p[end] == _ifs) { 230 c = __createComponent(p,start,end,idOpenParen,idCloseParen );251 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 231 252 if (c != NULL) { 232 253 Rp_ChainAppend(compList,c); … … 240 261 } 241 262 242 c = __createComponent(p,start,end,idOpenParen,idCloseParen );263 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 243 264 if (c != NULL) { 244 265 Rp_ChainAppend(compList,c); … … 335 356 } 336 357 358 bool 359 Path::eof () 360 { 361 return (_currLink == NULL); 362 } 363 364 Path& 365 Path::first () 366 { 367 _currLink = Rp_ChainFirstLink(_pathList); 368 return *this; 369 } 370 371 Path& 372 Path::prev () 373 { 374 if (_currLink) { 375 _currLink = Rp_ChainPrevLink(_currLink); 376 } 377 return *this; 378 } 379 380 Path& 381 Path::next () 382 { 383 if (_currLink) { 384 _currLink = Rp_ChainNextLink(_currLink); 385 } 386 return *this; 387 } 388 389 Path& 390 Path::last () 391 { 392 _currLink = Rp_ChainLastLink(_pathList); 393 return *this; 394 } 395 396 size_t 397 Path::count () 398 { 399 return Rp_ChainGetLength(_pathList); 400 } 401 337 402 const char * 338 403 Path::component(void) 339 404 { 340 405 Rp_ChainLink *l = NULL; 341 size_t len = 0; 342 406 407 /* 343 408 tmpBuf.clear(); 344 409 … … 348 413 } 349 414 350 l = Rp_ChainLastLink(_pathList);415 l = _currLink; 351 416 352 417 if (l == NULL) { … … 363 428 364 429 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); 369 435 } 370 436 371 437 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. 380 479 tmpBuf.append("\0",1); 381 480 … … 426 525 Rp_ChainDestroy(addList); 427 526 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; 430 530 431 531 if (l != NULL) { 432 532 componentStruct *last = (componentStruct *) Rp_ChainGetValue(l); 433 533 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 } 439 540 440 541 __updateBuffer(); … … 448 549 Rp_ChainLink *l = NULL; 449 550 551 /* 450 552 tmpBuf.clear(); 451 553 … … 455 557 } 456 558 457 l = Rp_ChainLastLink(_pathList);559 l = _currLink; 458 560 459 561 if (l == NULL) { … … 476 578 477 579 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; 478 599 } 479 600 … … 490 611 componentStruct *last = NULL; 491 612 492 // update the last component from the current path493 l = Rp_ChainLastLink(_pathList);613 // update the current component from the current path 614 l = _currLink; 494 615 495 616 if (l != NULL) { … … 499 620 // append the new component onto the current path 500 621 last = new componentStruct; 501 Rp_ChainAppend(_pathList,last);622 _currLink = Rp_ChainAppend(_pathList,last); 502 623 tmp = new char[1]; 503 624 *tmp = '\0'; … … 520 641 Rp_ChainLink *l = NULL; 521 642 643 /* 522 644 tmpBuf.clear(); 523 645 … … 527 649 } 528 650 529 l = Rp_ChainLastLink(_pathList);651 l = _currLink; 530 652 531 653 if (l == NULL) { … … 548 670 549 671 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; 550 691 } 551 692 … … 563 704 564 705 // update the last component from the current path 565 l = Rp_ChainLastLink(_pathList);706 l = _currLink; 566 707 567 708 if (l != NULL) { … … 571 712 // append the new component onto the current path 572 713 last = new componentStruct; 573 Rp_ChainAppend(_pathList,last);714 _currLink = Rp_ChainAppend(_pathList,last); 574 715 last->id = NULL; 575 716 } … … 593 734 tmpBuf.clear(); 594 735 595 last = Rp_ChainLastLink(_pathList);736 last = _currLink; 596 737 l = Rp_ChainFirstLink(_pathList); 597 738 while (l != last) { … … 685 826 } 686 827 828 size_t 829 Path::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 848 void 849 Path::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 687 877 const char * 688 878 Path::path(void) … … 696 886 if (p != NULL) { 697 887 _pathList = __parse(p); 888 _currLink = Rp_ChainLastLink(_pathList); 698 889 __updateBuffer(); 699 890 } -
trunk/src/objects/RpPath.h
r1528 r1560 48 48 Path& add(const char *el); // turns input into input.number(blah) 49 49 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(); 50 57 51 58 // turns input.number(blah) into number(blah) 52 const char *component(void); // get component of the path53 void component(const char *p); // set component of the path59 const char *component(void); // get component of the current component 60 void component(const char *p); // set component of the current component 54 61 55 62 // turns input.number(blah) into blah 56 const char *id(void); // get the id of the path57 void id(const char *p); // set the id of the path63 const char *id(void); // get the id of the current component 64 void id(const char *p); // set the id of the current component 58 65 59 66 // turns input.number(blah) into number 60 const char *type(void); // get the type of the path61 void type(const char *p); // set the type of the path67 const char *type(void); // get the type of the current component 68 void type(const char *p); // set the type of the current component 62 69 63 70 // 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 66 77 67 78 const char *path(void); // get the path … … 73 84 const char *type; 74 85 const char *id; 86 size_t degree; 75 87 } componentStruct; 76 88 … … 80 92 Rp_Chain *__parse(const char *p); 81 93 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); 83 96 void __deleteComponent(componentStruct *c); 84 97 85 98 char _ifs; 86 99 Rp_Chain *_pathList; 100 Rp_ChainLink *_currLink; 87 101 SimpleCharBuffer b; 88 102 SimpleCharBuffer tmpBuf; -
trunk/src/objects/RpPlot.cc
r1528 r1560 258 258 259 259 const char * 260 Plot::xml( )260 Plot::xml(size_t indent, size_t tabstop) 261 261 { 262 262 … … 302 302 } 303 303 304 _tmpBuf.append(c->xml( ));304 _tmpBuf.append(c->xml(indent,tabstop)); 305 305 _tmpBuf.append("\n",1); 306 306 l = Rp_ChainNextLink(l); -
trunk/src/objects/RpPlot.h
r1528 r1560 42 42 Curve *getNthCurve(size_t n) const; 43 43 44 const char *xml( );44 const char *xml(size_t indent, size_t tabstop); 45 45 const int is() const; 46 46 -
trunk/src/objects/RpScatter.cc
r1528 r1560 23 23 this->desc(""); 24 24 this->group(""); 25 propstr("type","scatter"); 25 26 } 26 27 … … 32 33 this->desc(""); 33 34 this->group(""); 35 propstr("type","scatter"); 34 36 } 35 37 … … 42 44 this->desc(desc); 43 45 this->group(group); 46 propstr("type","scatter"); 44 47 } 45 48 … … 71 74 */ 72 75 76 /* 73 77 const char * 74 Scatter::xml( )78 Scatter::xml(size_t indent, size_t tabstop) 75 79 { 76 80 // FIXME: the xml function should just read an array … … 122 126 return _tmpBuf.bytes(); 123 127 } 128 */ 124 129 125 130 /**********************************************************************/ -
trunk/src/objects/RpScatter.h
r1528 r1560 33 33 virtual ~Scatter(); 34 34 35 const char *xml();35 // const char *xml(); 36 36 const int is() const; 37 37 -
trunk/src/objects/RpString.cc
r1528 r1560 78 78 79 79 const char * 80 String::xml( )80 String::xml(size_t indent, size_t tabstop) 81 81 { 82 size_t l1width = indent + tabstop; 83 size_t l2width = indent + (2*tabstop); 84 const char *sp = ""; 85 82 86 Path p(path()); 83 87 _tmpBuf.clear(); 84 88 85 89 _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); 97 102 98 103 return _tmpBuf.bytes(); -
trunk/src/objects/RpString.h
r1528 r1560 39 39 Accessor<size_t> height; 40 40 41 const char *xml( );41 const char *xml(size_t indent, size_t tabstop); 42 42 const int is() const; 43 43 -
trunk/src/objects/RpTree.c
r1528 r1560 220 220 */ 221 221 static Node * 222 NewNode(TreeObject *treeObjPtr, CONST char *name, int inode)222 NewNode(TreeObject *treeObjPtr, CONST char *name, size_t inode) 223 223 { 224 224 Node *nodePtr; … … 840 840 Node *nodePtr; /* Node to be inserted. */ 841 841 TreeObject *treeObjPtr; 842 int inode;842 size_t inode; 843 843 int isNew; 844 844 … … 890 890 * be inserted. */ 891 891 CONST char *name, /* Name of node. */ 892 int inode,/* Requested id of the new node. If a892 size_t inode, /* Requested id of the new node. If a 893 893 * node by this id already exists in the 894 894 * tree, no node is created. */ … … 1004 1004 1005 1005 Rp_TreeNode 1006 Rp_TreeGetNode(TreeClient *clientPtr, unsigned int inode)1006 Rp_TreeGetNode(TreeClient *clientPtr, size_t inode) 1007 1007 { 1008 1008 TreeObject *treeObjPtr = clientPtr->treeObject; … … 1099 1099 label = Rp_TreeGetKey(string); 1100 1100 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 */ 1121 Rp_TreeNode 1122 Rp_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) { 1101 1129 if (label == nodePtr->label) { 1102 1130 return nodePtr; … … 1481 1509 } 1482 1510 1511 /* 1512 * commented out to avoid compiler warnings about function not being used 1513 */ 1514 /* 1483 1515 static int 1484 1516 ParseParentheses( … … 1487 1519 char **rightPtr) 1488 1520 { 1489 register char *p; 1490 char *left, *right; 1521 register char *p = NULL; 1522 char *left = NULL; 1523 char *right = NULL; 1491 1524 1492 1525 left = right = NULL; … … 1510 1543 return RP_OK; 1511 1544 } 1545 */ 1512 1546 1513 1547 //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 // 1548 int 1549 Rp_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 1524 1560 // if (ParseParentheses(string, &left, &right) != TCL_OK) { 1525 1561 // return TCL_ERROR; 1526 1562 // } 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 } 1537 1573 1538 1574 //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 // 1575 int 1576 Rp_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 1550 1588 // if (ParseParentheses(string, &left, &right) != RP_OK) { 1551 1589 // return RP_ERROR; 1552 1590 // } 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 } 1565 1601 1566 1602 //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 // 1603 int 1604 Rp_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 1576 1614 // if (ParseParentheses(string, &left, &right) != RP_OK) { 1577 1615 // return RP_ERROR; 1578 1616 // } 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 } 1588 1626 1589 1627 //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 // 1628 int 1629 Rp_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 1596 1636 // if (ParseParentheses(string, &left, &right) != RP_OK) { 1597 1637 // return FALSE; 1598 1638 // } 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 } 1609 1649 1610 1650 Rp_TreeKey … … 1955 1995 // return RP_OK; 1956 1996 //} 1997 1998 int 1999 Rp_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 } 1957 2025 1958 2026 void … … 3031 3099 RebuildTable(nodePtr); 3032 3100 } 3033 3101 } else { 3034 3102 Value *prevPtr; 3035 3103 -
trunk/src/objects/RpTree.h
r1528 r1560 192 192 193 193 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. */ 195 196 196 197 unsigned short depth; /* The depth of this node in the tree. */ … … 281 282 Rp_TreeNode parent, CONST char *name, int position)); 282 283 EXTERN 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)); 284 285 285 286 EXTERN int Rp_TreeDeleteNode _ANSI_ARGS_((Rp_Tree tree, Rp_TreeNode node)); … … 288 289 Rp_TreeNode parent, Rp_TreeNode before)); 289 290 290 EXTERN Rp_TreeNode Rp_TreeGetNode _ANSI_ARGS_((Rp_Tree tree, 291 unsigned int inode)); 291 EXTERN Rp_TreeNode Rp_TreeGetNode _ANSI_ARGS_((Rp_Tree tree, size_t inode)); 292 292 293 293 EXTERN Rp_TreeNode Rp_TreeFindChild _ANSI_ARGS_((Rp_TreeNode parent, 294 CONST char *name)); 295 296 EXTERN Rp_TreeNode Rp_TreeFindChildNext _ANSI_ARGS_((Rp_TreeNode child, 294 297 CONST char *name)); 295 298 … … 391 394 Rp_TreeApplyProc *proc, ClientData clientData)); 392 395 396 EXTERN int Rp_TreeApplyXML _ANSI_ARGS_((Rp_TreeNode root, 397 Rp_TreeApplyProc *proc, ClientData clientData)); 398 393 399 EXTERN int Rp_TreeSortNode _ANSI_ARGS_((Rp_Tree tree, Rp_TreeNode node, 394 400 Rp_TreeCompareNodesProc *proc)); … … 399 405 // EXTERN int Rp_TreeExists _ANSI_ARGS_((CONST char *name)); 400 406 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 410 EXTERN int Rp_TreeGetTokenFromToken _ANSI_ARGS_(( 411 CONST Rp_Tree tree, Rp_Tree *newToken)); 403 412 404 413 EXTERN void Rp_TreeReleaseToken _ANSI_ARGS_((Rp_Tree tree));
Note: See TracChangeset
for help on using the changeset viewer.