1 | #ifndef __GRID1D_H__ |
---|
2 | #define __GRID1D_H__ |
---|
3 | |
---|
4 | // |
---|
5 | // class for 1D grid |
---|
6 | // |
---|
7 | |
---|
8 | #include <vector> |
---|
9 | #include <string> |
---|
10 | #include "serializable.h" |
---|
11 | #include "byte_order.h" |
---|
12 | #include "rp_types.h" |
---|
13 | #include "util.h" |
---|
14 | |
---|
15 | typedef double DataValType; |
---|
16 | |
---|
17 | class RpGrid1d : public RpSerializable { |
---|
18 | public: |
---|
19 | // constructors |
---|
20 | RpGrid1d(); |
---|
21 | RpGrid1d(const char* name); |
---|
22 | RpGrid1d(int size); |
---|
23 | RpGrid1d(const char* objectName, int size); |
---|
24 | RpGrid1d(DataValType* data, int size); // makes a copy of data |
---|
25 | |
---|
26 | // constructor for a regular grid with start point and delta |
---|
27 | RpGrid1d(DataValType startPoint, DataValType delta, int npts); |
---|
28 | |
---|
29 | virtual void objectName(const char* str); |
---|
30 | virtual const char* objectName(); |
---|
31 | virtual const char* objectType(); |
---|
32 | |
---|
33 | // return number of bytes needed for serialization |
---|
34 | virtual int numBytes(); |
---|
35 | |
---|
36 | // return number of points in grid |
---|
37 | virtual int size() { return numPoints(); }; |
---|
38 | |
---|
39 | // add all points to grid |
---|
40 | virtual RP_ERROR addAllPoints(DataValType* val, int nitems); |
---|
41 | |
---|
42 | // add one point to grid |
---|
43 | virtual void addPoint(DataValType val); |
---|
44 | |
---|
45 | // return number of points in grid |
---|
46 | |
---|
47 | // max num points that can be stored |
---|
48 | virtual int capacity() { return m_data.capacity(); } |
---|
49 | |
---|
50 | // change the size of the grid after grid is constructed |
---|
51 | virtual void resize(int npoints) { m_data.resize(npoints); } |
---|
52 | |
---|
53 | // return pointer to array of points |
---|
54 | virtual DataValType* getData(); |
---|
55 | |
---|
56 | // return copy of data array - caller must free memory when |
---|
57 | // not done |
---|
58 | virtual DataValType* getDataCopy(); |
---|
59 | |
---|
60 | virtual DataValType getData(int index); |
---|
61 | |
---|
62 | // serialize data |
---|
63 | // returns pointer to buffer |
---|
64 | // number of bytes (nbytes) set |
---|
65 | // |
---|
66 | virtual char * serialize(int& nbytes); |
---|
67 | virtual RP_ERROR doSerialize(char * buf, int nbytes); |
---|
68 | |
---|
69 | // deserialize data |
---|
70 | virtual RP_ERROR deserialize(const char* buf); |
---|
71 | virtual RP_ERROR doDeserialize(const char* buf); |
---|
72 | |
---|
73 | virtual void xmlString(std::string& str); |
---|
74 | virtual void print(); |
---|
75 | |
---|
76 | // delete all points |
---|
77 | virtual void clear(); |
---|
78 | |
---|
79 | // destructor |
---|
80 | virtual ~RpGrid1d() { }; |
---|
81 | |
---|
82 | virtual RpGrid1d operator=(const RpGrid1d& g); |
---|
83 | |
---|
84 | protected: |
---|
85 | int numPoints() { return m_data.size(); }; |
---|
86 | |
---|
87 | vector<DataValType> m_data; // array of doubles |
---|
88 | |
---|
89 | }; |
---|
90 | |
---|
91 | #endif |
---|