source: trunk/src/mesh/grid1d.h @ 254

Last change on this file since 254 was 254, checked in by cxsong, 19 years ago

modified serialization/deserializaiton functions, added xmlString, print, capacity, etc.

File size: 1.3 KB
Line 
1#ifndef __GRID1D_H__
2#define __GRID1D_H__
3
4//
5// class for 1D grid
6//
7
8#include <vector>
9#include "util.h"
10
11class RpGrid1d {
12public:
13        // constructors
14        RpGrid1d();
15        RpGrid1d(int size);
16        RpGrid1d(double* data, int size); // makes a copy of data
17        RpGrid1d(const char* buf); // instantiate with byte stream
18
19        // add all points to grid
20        RP_ERROR addAllPoints(double* val, int nitems);
21
22        // add one point to grid
23        void addPoint(double val);
24
25        // return number of points in grid
26        int numPoints() { return m_data.size(); }
27
28        // max num points that can be stored
29        int capacity() { return m_data.capacity(); }
30
31        // change the size of the grid after grid is constructed
32        void resize(int npoints) { m_data.resize(npoints); }
33
34        // serialize data
35        // If no input parameters are provided, byte stream will be binary
36        // without compression.
37        //
38        char * serialize(int& nbytes, RP_ENCODE_ALG eflag=RP_NO_ENCODING,
39                         RP_COMPRESSION cflag=RP_NO_COMPRESSION);
40
41        RP_ERROR serialize(char * buf, int nbytes,
42                        RP_ENCODE_ALG eflag=RP_NO_ENCODING,
43                        RP_COMPRESSION cflag=RP_NO_COMPRESSION);
44
45        RP_ERROR deserialize(const char* buf);
46
47        void xmlString(std::string& str);
48        void print();
49
50        // destructor
51        virtual ~RpGrid1d() { };
52
53        // TODO
54        //virtual int xmlPut() { };
55        //virtual int xmlGet() { };
56
57private:
58        vector<double> m_data; // array of doubles
59};
60
61#endif
Note: See TracBrowser for help on using the repository browser.