Changeset 270 for trunk/src/mesh


Ignore:
Timestamp:
Mar 3, 2006 7:37:18 AM (18 years ago)
Author:
cxsong
Message:

added copy array functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mesh/byte_order.h

    r266 r270  
    22#define __RP_BYTEORDER_H__
    33
     4//#include <stdio.h>
    45#include <string.h>
    56
     
    1920        // If the machine calling this function uses big endian byte order,
    2021        // bytes are flipped.
    21         static void OrderCopy(const ValType& src_val, ValType& dst_val)
     22        static void OrderCopy(const ValType* src_val, ValType* dst_val)
    2223        {
    23                 unsigned char* src = (unsigned char *)&src_val;
    24                 unsigned char* dst = (unsigned char *)&dst_val;
     24                unsigned char* src = (unsigned char *)src_val;
     25                unsigned char* dst = (unsigned char *)dst_val;
    2526       
    2627                // our software will use little endian
     
    5152                        unsigned int i;
    5253                        for (i=0; i<sizeof(ValType); i++)
    53                                 memcpy((void*)&dst, (void*)&src, sizeof(ValType));
     54                                memcpy((void*)dst, (void*)src, sizeof(ValType));
    5455                }
    5556        };
    5657
     58        // copy an array of ValType elements
     59        static void OrderCopyArray(const ValType* src_val, ValType* dst_val, int nitems)
     60        {
     61                for (int i=0; i < nitems; i++)
     62                        OrderCopy(&(src_val[i]), &(dst_val[i]));
     63        };
     64
    5765        // swap bytes in place, src altered for BE machine.
    58         static void Flip(ValType& src_val)
     66        static void Flip(ValType* src_val)
    5967        {
    6068                ValType val;
    61                 Copy(src_val, val);
    62                 memcpy((void*)&src_val, (void*)&val, sizeof(ValType));
     69                Copy(src_val, &val);
     70                memcpy((void*)src_val, (void*)&val, sizeof(ValType));
    6371        };
     72
     73        static void FlipArray(ValType* src_val, int nitems)
     74        {
     75                for (int i=0; i < nitems; i++)
     76                        Flip(&(src_val[i]));
     77        }
    6478
    6579        operator ValType () const
Note: See TracChangeset for help on using the changeset viewer.