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

Last change on this file since 279 was 279, checked in by cxsong, 18 years ago

misc changes

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