[191] | 1 | #ifndef __RP_ELEMENT_H__ |
---|
| 2 | #define __RP_ELEMENT_H__ |
---|
| 3 | |
---|
| 4 | #include <iostream> |
---|
| 5 | #include <vector> |
---|
| 6 | #include "util.h" |
---|
| 7 | |
---|
[194] | 8 | // |
---|
| 9 | // RpElement is defined as a list of nodes (by id) connected with each other |
---|
| 10 | // in a mesh. |
---|
| 11 | // |
---|
[191] | 12 | class RpElement { |
---|
| 13 | public: |
---|
| 14 | |
---|
[218] | 15 | // constructor, set number of nodes and/or element id |
---|
| 16 | RpElement(int numNodes, int id=0); |
---|
[191] | 17 | |
---|
[194] | 18 | // instantiate from byte stream: |
---|
[202] | 19 | // id(int), numNodes(int), list of node ids(int *) |
---|
[194] | 20 | RpElement(const char* buf); |
---|
| 21 | |
---|
[191] | 22 | // add a node to element |
---|
| 23 | void addNode(int nodeName); |
---|
| 24 | |
---|
[194] | 25 | // add all the nodes to element |
---|
| 26 | RP_ERROR addNodes(const int* nodes, int numNodes); |
---|
[191] | 27 | |
---|
| 28 | // get node id's |
---|
[202] | 29 | RP_ERROR getNodeIdList(int* list, int& len); |
---|
[191] | 30 | |
---|
| 31 | int id() { return m_id; }; |
---|
| 32 | void id(int id) { m_id = id; }; |
---|
| 33 | |
---|
[218] | 34 | int numNodes() { return m_nodes.size(); }; |
---|
[202] | 35 | |
---|
| 36 | // serialize |
---|
| 37 | // id(int), numNodes(int), list of ids(int *) |
---|
[191] | 38 | char* serialize(); |
---|
[202] | 39 | RP_ERROR serialize(char* buf, int buflen); |
---|
| 40 | RP_ERROR deserialize(const char* buf); |
---|
[191] | 41 | |
---|
[218] | 42 | // serialize RpElement object into xml text |
---|
| 43 | void xmlString(std::string& xmlText); |
---|
[191] | 44 | void print(); |
---|
| 45 | |
---|
| 46 | virtual ~RpElement() { }; |
---|
| 47 | |
---|
| 48 | // TODO |
---|
| 49 | // void xmlPut(); |
---|
| 50 | // void xmlGet(); |
---|
| 51 | |
---|
[218] | 52 | protected: |
---|
| 53 | // constructors, default to 8 nodes |
---|
| 54 | RpElement(); |
---|
| 55 | |
---|
[191] | 56 | private: |
---|
| 57 | int m_id; |
---|
[194] | 58 | vector<int> m_nodes; // list of node ids |
---|
[202] | 59 | |
---|
| 60 | // total number of bytes in an element: |
---|
| 61 | // bytes for all node ids + element id + numberOfNodes |
---|
| 62 | int numBytes() { |
---|
| 63 | return ((m_nodes.size()) * sizeof(int) + 2*sizeof(int)); |
---|
| 64 | }; |
---|
[191] | 65 | }; |
---|
| 66 | |
---|
| 67 | #endif |
---|