Data Conversion
[libbu (utility functions)]

Collaboration diagram for Data Conversion:


Files

file  convert.c
 Routines to translate data formats. The data formats are:.

Defines

#define CV_CHANNEL_MASK   0x00ff
#define CV_HOST_MASK   0x0100
#define CV_SIGNED_MASK   0x0200
#define CV_TYPE_MASK   0x1c00
#define CV_CONVERT_MASK   0x6000
#define CV_TYPE_SHIFT   10
#define CV_CONVERT_SHIFT   13
#define CV_8   0x0400
#define CV_16   0x0800
#define CV_32   0x0c00
#define CV_64   0x1000
#define CV_D   0x1400
#define CV_CLIP   0x0000
#define CV_NORMAL   0x2000
#define CV_LIT   0x4000
#define IND_NOTSET   0
#define IND_BIG   1
#define IND_LITTLE   2
#define IND_ILL   3
#define IND_CRAY   4

Functions

int bu_cv_itemlen (int cookie)
int bu_cv_cookie (char *in)
int bu_cv_optimize (int cookie)
int bu_cv_w_cookie (genptr_t out, int outcookie, size_t size, genptr_t in, int incookie, int count)
 convert with cookie
int bu_cv_ntohss (signed short *, size_t, genptr_t, int)
int bu_cv_ntohus (unsigned short *, size_t, genptr_t, int)
int bu_cv_ntohsl (signed long int *, size_t, genptr_t, int)
int bu_cv_ntohul (unsigned long int *, size_t, genptr_t, int)
int bu_cv_htonss (genptr_t, size_t, signed short *, int)
int bu_cv_htonus (genptr_t, size_t, unsigned short *, int)
int bu_cv_htonsl (genptr_t, size_t, long *, int)
int bu_cv_htonul (genptr_t, size_t, unsigned long *, int)
void bu_cv_fmt_cookie (char *buf, size_t buflen, int cookie)
void bu_cv_pr_cookie (char *title, int cookie)
int cv (genptr_t out, char *outfmt, size_t size, genptr_t in, char *infmt, int count)
 convert from one format to another.
int bu_cv_optimize (register int cookie)
int bu_cv_itemlen (register int cookie)
int bu_cv_ntohss (register short int *out, size_t size, register genptr_t in, int count)
 Network TO Host Signed Short.
int bu_cv_ntohus (register short unsigned int *out, size_t size, register genptr_t in, int count)
int bu_cv_ntohsl (register long int *out, size_t size, register genptr_t in, int count)
int bu_cv_ntohul (register long unsigned int *out, size_t size, register genptr_t in, int count)
int bu_cv_htonss (genptr_t out, size_t size, register short int *in, int count)
int bu_cv_htonus (genptr_t out, size_t size, register short unsigned int *in, int count)
int bu_cv_htonsl (genptr_t out, size_t size, register long int *in, int count)
int bu_cv_htonul (genptr_t out, size_t size, register long unsigned int *in, int count)

Define Documentation

#define CV_CHANNEL_MASK   0x00ff
 

Definition at line 437 of file bu.h.

Referenced by bu_cv_fmt_cookie().

#define CV_HOST_MASK   0x0100
 

Definition at line 438 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_itemlen(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_SIGNED_MASK   0x0200
 

Definition at line 439 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_TYPE_MASK   0x1c00
 

Definition at line 440 of file bu.h.

Referenced by bu_cv_fmt_cookie(), bu_cv_itemlen(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_CONVERT_MASK   0x6000
 

Definition at line 441 of file bu.h.

Referenced by bu_cv_fmt_cookie().

#define CV_TYPE_SHIFT   10
 

Definition at line 443 of file bu.h.

Referenced by bu_cv_itemlen().

#define CV_CONVERT_SHIFT   13
 

Definition at line 444 of file bu.h.

#define CV_8   0x0400
 

Definition at line 446 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_16   0x0800
 

Definition at line 447 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_32   0x0c00
 

Definition at line 448 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_64   0x1000
 

Definition at line 449 of file bu.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define CV_D   0x1400
 

Definition at line 450 of file bu.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_CLIP   0x0000
 

Definition at line 452 of file bu.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define CV_NORMAL   0x2000
 

Definition at line 453 of file bu.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define CV_LIT   0x4000
 

Definition at line 454 of file bu.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define IND_NOTSET   0
 

Definition at line 456 of file bu.h.

Referenced by bu_cv_optimize().

#define IND_BIG   1
 

Definition at line 457 of file bu.h.

Referenced by bu_cv_optimize().

#define IND_LITTLE   2
 

Definition at line 458 of file bu.h.

#define IND_ILL   3
 

Definition at line 459 of file bu.h.

#define IND_CRAY   4
 

Definition at line 460 of file bu.h.

Referenced by bu_cv_optimize().


Function Documentation

int bu_cv_itemlen int  cookie  ) 
 

Referenced by bu_cv_w_cookie(), and rt_hf_import().

int bu_cv_cookie char *  in  ) 
 

Definition at line 86 of file convert.c.

References CV_16, CV_32, CV_64, CV_8, CV_CLIP, CV_D, CV_HOST_MASK, CV_LIT, CV_NORMAL, and CV_SIGNED_MASK.

Referenced by cv(), rt_binunif_export5(), rt_binunif_import5(), and rt_hf_import().

int bu_cv_optimize int  cookie  ) 
 

Referenced by bu_cv_w_cookie(), rt_binunif_export5(), rt_binunif_import5(), and rt_hf_import().

int bu_cv_w_cookie genptr_t  out,
int  outcookie,
size_t  size,
genptr_t  in,
int  incookie,
int  count
 

convert with cookie

bu_cv_w_cookie

Parameters:
in input pointer
incookie input format cookie.
count number of entries to convert.
out output pointer.
outcookie output format cookie.
size size of output buffer in bytes;
A worst case would be: ns16 on vax to ns32
        ns16    -> hs16
                -> hd
                -> hs32
                -> ns32
The worst case is probably the easiest to deal with because all steps are done. The more difficult cases are when only a subset of steps need to be done.

Method:
        HOSTDBL defined as true or false
        if ! hostother then
                hostother = (Indian == IND_BIG) ? SAME : DIFFERENT;
        fi
        if (infmt == double) then
                if (HOSTDBL == SAME) {
                        inIsHost = host;
                fi
        else
                if (hostother == SAME) {
                        inIsHost = host;
                fi
        fi
        if (outfmt == double) then
                if (HOSTDBL == SAME) {
                        outIsHost == host;
        else
                if (hostother == SAME) {
                        outIsHost = host;
                fi
        fi
        if (infmt == outfmt) {
                if (inIsHost == outIsHost) {
                        copy(in,out)
                        exit
                else if (inIsHost == net) {
                        ntoh?(in,out);
                        exit
                else
                        hton?(in,out);
                        exit
                fi
        fi

        while not done {
                from = in;

                if (inIsHost == net) {
                        ntoh?(from,t1);
                        from = t1;
                fi
                if (infmt != double ) {
                        if (outIsHost == host) {
                                to = out;
                        else
                                to = t2;
                        fi
                        castdbl(from,to);
                        from = to;
                fi

                if (outfmt == double ) {
                        if (outIsHost == net) {
                                hton?(from,out);
                        fi
                else
                        if (outIsHost == host) {
                                dblcast(from,out);
                        else
                                dblcast(from,t3);
                                hton?(t3,out);
                        fi
                fi
        done

Definition at line 698 of file convert.c.

References bcopy, bu_cv_htonsl(), bu_cv_htonss(), bu_cv_htonul(), bu_cv_htonus(), bu_cv_itemlen(), bu_cv_ntohsl(), bu_cv_ntohss(), bu_cv_ntohul(), bu_cv_ntohus(), bu_cv_optimize(), bu_malloc(), CV_16, CV_32, CV_8, CV_D, CV_HOST_MASK, CV_SIGNED_MASK, CV_TYPE_MASK, htond(), ntohd(), and void().

Referenced by cv(), rt_binunif_export5(), rt_binunif_import5(), and rt_hf_import().

Here is the call graph for this function:

int bu_cv_ntohss signed short *  ,
size_t  ,
genptr_t  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_ntohus unsigned short *  ,
size_t  ,
genptr_t  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_ntohsl signed long int *  ,
size_t  ,
genptr_t  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_ntohul unsigned long int *  ,
size_t  ,
genptr_t  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_htonss genptr_t  ,
size_t  ,
signed short *  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_htonus genptr_t  ,
size_t  ,
unsigned short *  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_htonsl genptr_t  ,
size_t  ,
long *  ,
int 
 

Referenced by bu_cv_w_cookie().

int bu_cv_htonul genptr_t  ,
size_t  ,
unsigned long *  ,
int 
 

Referenced by bu_cv_w_cookie().

void bu_cv_fmt_cookie char *  buf,
size_t  buflen,
int  cookie
 

Definition at line 178 of file convert.c.

References CV_16, CV_32, CV_64, CV_8, CV_CHANNEL_MASK, CV_CLIP, CV_CONVERT_MASK, CV_D, CV_HOST_MASK, CV_LIT, CV_NORMAL, CV_SIGNED_MASK, and CV_TYPE_MASK.

Referenced by bu_cv_pr_cookie().

void bu_cv_pr_cookie char *  title,
int  cookie
 

Definition at line 291 of file convert.c.

References bu_cv_fmt_cookie().

Here is the call graph for this function:

int cv genptr_t  out,
char *  outfmt,
size_t  size,
genptr_t  in,
char *  infmt,
int  count
 

convert from one format to another.

c v

Parameters:
in input pointer
out output pointer
count number of entries to convert.
size size of output buffer.
infmt input format
outfmt output format

Definition at line 313 of file convert.c.

References bu_cv_cookie(), and bu_cv_w_cookie().

Referenced by rt_eto_curve(), rt_eto_plot(), rt_eto_prep(), and rt_eto_tess().

Here is the call graph for this function:

int bu_cv_optimize register int  cookie  ) 
 

C V _ O P T I M I Z E

It is always more efficient to handle host data, rather than network. If host and network formats are the same, and the request was for network format, modify the cookie to request host format.

Definition at line 329 of file convert.c.

References CV_HOST_MASK, CV_TYPE_MASK, IND_BIG, IND_CRAY, IND_NOTSET, and int.

int bu_cv_itemlen register int  cookie  ) 
 

C V _ I T E M L E N

Returns the number of bytes each "item" of type "cookie" occupies.

Definition at line 392 of file convert.c.

References CV_HOST_MASK, CV_TYPE_MASK, CV_TYPE_SHIFT, and int.

int bu_cv_ntohss register short int *  out,
size_t  size,
register genptr_t  in,
int  count
 

Network TO Host Signed Short.

bu_cv_ntohss

It is assumed that this routine will only be called if there is real work to do. Ntohs does no checking to see if it is reasonable to do any conversions.

Parameters:
in generic pointer for input.
count number of shorts to be generated.
out short pointer for output
size number of bytes of space reserved for out.
Returns:
number of conversions done.

Definition at line 425 of file convert.c.

int bu_cv_ntohus register short unsigned int *  out,
size_t  size,
register genptr_t  in,
int  count
 

Definition at line 450 of file convert.c.

int bu_cv_ntohsl register long int *  out,
size_t  size,
register genptr_t  in,
int  count
 

Definition at line 470 of file convert.c.

References int.

int bu_cv_ntohul register long unsigned int *  out,
size_t  size,
register genptr_t  in,
int  count
 

Definition at line 494 of file convert.c.

References int.

int bu_cv_htonss genptr_t  out,
size_t  size,
register short int *  in,
int  count
 

Definition at line 518 of file convert.c.

References val.

int bu_cv_htonus genptr_t  out,
size_t  size,
register short unsigned int *  in,
int  count
 

Definition at line 539 of file convert.c.

References val.

int bu_cv_htonsl genptr_t  out,
size_t  size,
register long int *  in,
int  count
 

Definition at line 560 of file convert.c.

References val.

int bu_cv_htonul genptr_t  out,
size_t  size,
register long unsigned int *  in,
int  count
 

Definition at line 583 of file convert.c.

References val.


Generated on Mon Sep 18 01:25:46 2006 for BRL-CAD by  doxygen 1.4.6