Changeset 249
- Timestamp:
- Mar 1, 2006 1:07:04 PM (18 years ago)
- Location:
- trunk/src/mesh
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mesh/element.cc
r244 r249 91 91 92 92 char * buf = new char[nbytes]; 93 serialize(buf, nbytes); 93 if (buf != NULL) 94 serialize(buf); 95 94 96 return buf; 95 97 } 96 98 97 99 RP_ERROR 98 RpElement::serialize(char* buf, int buflen) 99 { 100 int nbytes = this->numBytes(); 101 102 if (buf == NULL || buflen < (signed)(nbytes+2*sizeof(int))) { 103 RpAppendErr("RpNode::serialize: invalid buffer"); 100 RpElement::serialize(char* buf) 101 { 102 if (buf == NULL) { 103 RpAppendErr("RpNode::serialize: null buffer"); 104 104 RpPrintErr(); 105 return RP_ERR_ INVALID_ARRAY;105 return RP_ERR_NULL_PTR; 106 106 } 107 107 … … 123 123 } 124 124 125 // 126 // serialize only the nodes info 127 // returns pointer to next char in buf 128 // 129 char* 130 RpElement::serializeNodes(char* buf) 131 { 132 int nbytes = m_nodes.size() * sizeof(int); 133 134 if (buf == NULL) { 135 RpAppendErr("RpNode::serialize: null buffer"); 136 RpPrintErr(); 137 return buf; 138 } 139 140 // copy all nodes 141 memcpy((void *)buf, (void *)&(m_nodes[0]), nbytes); 142 143 return (char*)(buf+nbytes); 144 } 145 125 146 RP_ERROR 126 RpElement::deserialize (const char* buf)147 RpElement::deserializeNodes(const char* buf, int numNodes) 127 148 { 128 149 if (buf == NULL) { … … 132 153 } 133 154 155 char* ptr = (char*)buf; 156 157 for (int i=0; i < numNodes; i++) { 158 memcpy((void *)&(m_nodes[i]), (void *)ptr, sizeof(int)); 159 ptr += sizeof(int); 160 } 161 162 return RP_SUCCESS; 163 } 164 165 RP_ERROR 166 RpElement::deserialize(const char* buf) 167 { 168 if (buf == NULL) { 169 RpAppendErr("RpElement::deserialize: null buffer"); 170 RpPrintErr(); 171 return RP_ERR_NULL_PTR; 172 } 173 134 174 char * ptr = (char*)buf; 135 175 -
trunk/src/mesh/element.h
r245 r249 43 43 // id(int), numNodes(int), list of ids(int *) 44 44 char* serialize(); 45 RP_ERROR serialize(char* buf, int buflen); 45 char* serializeNodes(char* buf); 46 RP_ERROR serialize(char* buf); 47 RP_ERROR deserializeNodes(const char* buf, int numNodes); 46 48 RP_ERROR deserialize(const char* buf); 47 49 -
trunk/src/mesh/mesh.cc
r246 r249 253 253 } 254 254 255 // 256 // total number bytes in mesh object 257 // 258 // NOTE: this doesn't count the id 259 // 260 int RpMesh3d::numBytes() 261 { 262 // numberOfNodes + all nodes + numberOfElements + numNodesInElement + nodes in elements 263 264 int nnie = (*m_elemList)[0].numNodes(); 265 int num = 3*sizeof(int) + m_numNodes*3*sizeof(int) + m_numElements*nnie*sizeof(int); 266 267 return num; 268 } 269 255 270 // serialization 256 271 char* 257 RpMesh3d::serialize() 258 { 259 return NULL; 272 RpMesh3d::serialize(int& numbytes) 273 { 274 int nbytes = this->numBytes(); 275 276 char * buf = new char[nbytes]; 277 if (buf != NULL) { 278 serialize(buf, nbytes); 279 numbytes = nbytes; 280 } 281 282 return buf; 260 283 } 261 284 … … 263 286 RpMesh3d::serialize(char* buf, int buflen) 264 287 { 288 int nbytes = this->numBytes(); 289 int nnie = (*m_elemList)[0].numNodes(); 290 int i; 291 292 if (buf == NULL || buflen < nbytes) { 293 RpAppendErr("RpMesh3d::serialize: invalid buffer"); 294 RpPrintErr(); 295 return RP_ERR_INVALID_ARRAY; 296 } 297 298 char *ptr = buf; 299 300 // write number of nodes 301 memcpy((void *)ptr, (void *)&m_numNodes, sizeof(int)); 302 ptr += sizeof(int); 303 304 // write all nodes 305 for (i=0; i < m_numNodes; i++) { 306 m_nodeList[i].serialize(ptr); 307 ptr += 3* sizeof(int); 308 } 309 310 // write number of elements 311 memcpy((void *)ptr, (void *)&m_numElements, sizeof(int)); 312 ptr += sizeof(int); 313 314 // write number of nodes in each element 315 memcpy((void *)ptr, (void *)&nnie, sizeof(int)); 316 ptr += sizeof(int); 317 318 // write all elements 319 for (i=0; i < m_numElements; i++) { 320 (*m_elemList)[i].serializeNodes(ptr); 321 ptr += nnie * sizeof(int); 322 } 265 323 266 324 return RP_SUCCESS; … … 270 328 RpMesh3d::deserialize(const char* buf) 271 329 { 330 int i; 331 332 if (buf == NULL) { 333 RpAppendErr("RpMesh3d::deserialize: null buffer"); 334 RpPrintErr(); 335 return RP_ERR_INVALID_ARRAY; 336 } 337 338 char *ptr = (char*)buf; 339 int nnie; 340 341 // read number of nodes 342 memcpy((void *)&m_numNodes, (void*)ptr, sizeof(int)); 343 ptr += sizeof(int); 344 345 // read all nodes 346 for (i=0; i < m_numNodes; i++) { 347 m_nodeList[i].deserialize(ptr); 348 m_nodeList[i].id(i); 349 ptr += 3* sizeof(int); 350 } 351 352 // read number of elements 353 memcpy((void *)&m_numElements, (void*)ptr, sizeof(int)); 354 ptr += sizeof(int); 355 356 // number of nodes in each element 357 memcpy((void *)&nnie, (void *)ptr, sizeof(int)); 358 ptr += sizeof(int); 359 360 // read all elements 361 for (i=0; i < m_numElements; i++) { 362 (*m_elemList)[i].deserializeNodes(ptr, nnie); 363 (*m_elemList)[i].id(i); 364 ptr += nnie * sizeof(int); 365 } 366 272 367 return RP_SUCCESS; 273 368 } -
trunk/src/mesh/mesh.h
r246 r249 46 46 47 47 // serialization 48 char* serialize( );48 char* serialize(int& numbytes); 49 49 RP_ERROR serialize(char* buf, int buflen); 50 50 RP_ERROR deserialize(const char* buf); … … 70 70 vector<RpNode3d> m_nodeList; // list of node objects 71 71 vector<RpElement> * m_elemList; // ptr to a list of RpElement objects 72 73 int numBytes(); 72 74 }; 73 75 -
trunk/src/mesh/node2d.cc
r212 r249 16 16 17 17 char * buf = new char[len]; 18 serialize(buf , len);18 serialize(buf); 19 19 20 20 return buf; … … 32 32 // 33 33 RP_ERROR 34 RpNode2d::serialize(char* buf , int buflen)34 RpNode2d::serialize(char* buf) 35 35 { 36 if (buf == NULL || buflen < NodeDim*((signed)sizeof(int))) {36 if (buf == NULL) { 37 37 RpAppendErr("RpElement::deserialize: null buffer"); 38 38 RpPrintErr(); -
trunk/src/mesh/node2d.h
r247 r249 38 38 39 39 char* serialize(); 40 RP_ERROR serialize(char* buf , int buflen);40 RP_ERROR serialize(char* buf); 41 41 RP_ERROR deserialize(const char* buf); 42 42 -
trunk/src/mesh/node3d.cc
r230 r249 15 15 16 16 char * buf = new char[len]; 17 serialize(buf , len);17 serialize(buf); 18 18 19 19 return buf; … … 22 22 // 23 23 // actual function that does the serialization 24 // serialization order: 25 // x y z x y z ... 24 26 // 25 27 // Input: … … 31 33 // 32 34 RP_ERROR 33 RpNode3d::serialize(char* buf , int buflen)35 RpNode3d::serialize(char* buf) 34 36 { 35 if (buf == NULL || buflen < 3*((signed)sizeof(int))) {37 if (buf == NULL) { 36 38 RpAppendErr("RpElement::deserialize: null buffer"); 37 39 RpPrintErr(); -
trunk/src/mesh/node3d.h
r247 r249 45 45 46 46 char* serialize(); 47 RP_ERROR serialize(char* buf , int buflen);47 RP_ERROR serialize(char* buf); 48 48 RP_ERROR deserialize(const char* buf); 49 49
Note: See TracChangeset
for help on using the changeset viewer.