Changeset 302 for trunk/src


Ignore:
Timestamp:
Mar 9, 2006, 1:12:05 PM (19 years ago)
Author:
cxsong
Message:

updated using RpSerializable?

Location:
trunk/src/mesh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mesh/grid2d.cc

    r279 r302  
    8181
    8282        // total length = tagEncode + tagCompress + num + data
    83         char * buf = (char*) malloc(numVals*sizeof(DataValType) + sizeof(int) + 2);
     83        char * buf = (char*) new char[numVals*sizeof(DataValType) + sizeof(int) + 2];
    8484        if (buf == NULL) {
    8585                RpAppendErr("RpGrid2d::serialize: malloc failed");
  • trunk/src/mesh/test_grid1d.cc

    r298 r302  
    11#include <stdio.h>
     2#include "serializer.h"
    23#include "grid1d.h"
    34
     
    2728};
    2829
     30void writeToFile(char* buf, int len, const char* filename)
     31{
     32        if (buf != NULL) {
     33                FILE* fp = fopen(filename, "w");
     34                fwrite(buf, 1, len, fp);
     35                fclose(fp);
     36        }
     37}
     38
    2939int main()
    3040{
    31         int i, j, err;
     41        int i, j, err, nbytes;
    3242
    3343        printf("Testing RpGrid1d\n");
    3444
    35         printf("Testing constructor\n");
    36         RpGrid1d grid1("output.grid(g1d)", 20);
     45        RpGrid1d* grid1 = new RpGrid1d("output.grid(g1d)", 20);
     46        grid1->addAllPoints(&(points[0]), 20);
    3747
    38         printf("vector size: %d\n", grid1.size());
    39         printf("capacity: %d\n", grid1.capacity());
     48        char* buf = grid1->serialize(nbytes);
     49        writeToFile(buf, nbytes, "out.grid1");
    4050
    41         printf("Testing addAllPoints\n");
    42         grid1.addAllPoints(&(points[0]), 20);
     51        delete [] buf;
     52        //buf = NULL;
    4353
    44         printf("vector size: %d\n", grid1.size());
     54        printf("Testing serializer\n");
    4555
    46         printf("Testing print\n");
    47         grid1.print();
     56        RpSerializer myvis;
    4857
    49         printf("Testing serialize\n");
     58        myvis.addObject(grid1);
    5059
    51         int nbytes;
    52         char* buf = grid1.serialize(nbytes);
    53         printf("nbytes=%d\n", nbytes);
     60        RpGrid1d* ptr = (RpGrid1d*) myvis.getObject(grid1->objectName());
    5461
    55         FILE* fp = fopen("out.grid", "w");
    56         fwrite(buf, 1, nbytes, fp);
    57         fclose(fp);
     62        if (ptr == NULL)
     63                printf("%s not found\n", grid1->objectName());
    5864
    59         printf("Testing print\n");
    60         grid1.print();
     65        myvis.print();
    6166
    62         printf("Testing deserialize\n");
     67        buf = myvis.serialize();
    6368
    64         RpGrid1d * grid2 = new RpGrid1d("test.path");
    65         grid2->deserialize(buf);
    66 
    67         printf("Testing getData\n");
    68        
    69 //      double* ptr = grid2->getDataCopy();
    70         double* ptr = grid2->getData();
    71         for (i=0; i<grid2->size(); i++) {
    72                 printf("%.12f\n", ptr[i]);
    73         }
    74 
     69        nbytes = myvis.numBytes();
     70        writeToFile(buf, nbytes, "out.g1");
    7571
    7672
Note: See TracChangeset for help on using the changeset viewer.