source: trunk/src/mesh/element.h @ 222

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

added xmlString. Changes in several functions.

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