Functions | Variables

data_conversion.c File Reference

#include "utility.h"
Include dependency graph for data_conversion.c:

Go to the source code of this file.

Functions

int gs_swap_int (int *x)
int gs_swap_int_nop (int *x)
int gs_swap_int_undef (int *x)
int gs_swap_float (float *f)
int gs_swap_float_nop (float *x)
int gs_swap_float_undef (float *x)
int gs_swap_double (double *d)
int gs_swap_double_nop (double *d)
int gs_swap_double_undef (double *d)

Variables

gs_int_swap_f gs_int_swap_func [4][4]
gs_float_swap_f gs_float_swap_func [4][4]
gs_double_swap_f gs_double_swap_func [4][4]

Detailed Description

This file contains routines for performing conversions between different machine representations.

The arrays of function pointers are indexed by the byte order part of the data signature such that the value at (m,n) is the function that converts between byte order 'm' and byte order 'n'.

Definition in file data_conversion.c.


Function Documentation

int gs_swap_double ( double *  d  ) 

Swaps the bytes in a double.

Parameters:
d -- pointer to the double to be swapped
Returns:
0 on success, -1 on failure

Definition at line 173 of file data_conversion.c.

{
  int i, size = sizeof(double)-1;
  char *p, tmp;

  p = (char*)d;

  for(i=size;i>size/2;i--) {
    tmp = p[i];
    p[i] = p[size-i];
    p[size-i] = tmp;
  }

  return 0;
}

int gs_swap_double_nop ( double *  d  ) 

Does nothing. This is used along the diagonal of the conversion matrix since that represents a conversion between the same representations.

Parameters:
d -- pointer to the double to be swapped
Returns:
0 on success, -1 on failure. currently always returns 0.

Definition at line 201 of file data_conversion.c.

{
  return 0;
}

int gs_swap_double_undef ( double *  d  ) 

Does nothing. This is used in the conversion matrix in places where we have not implemented a conversion between the two representations.

Parameters:
d -- pointer to the double to be swapped
Returns:
0 on success, -1 on failure. currently always returns -1.

Definition at line 218 of file data_conversion.c.

{
  ERRPRINTF("Error: this conversion is undefined\n");
  return -1;
}

int gs_swap_float ( float *  f  ) 

Swaps the bytes in a float.

Parameters:
x -- pointer to the float to be swapped
Returns:
0 on success, -1 on failure

Definition at line 113 of file data_conversion.c.

{
  int i, size = sizeof(float)-1;
  char *p, tmp;

  p = (char*)f;

  for(i=size;i>size/2;i--) {
    tmp = p[i];
    p[i] = p[size-i];
    p[size-i] = tmp;
  }

  return 0;
}

int gs_swap_float_nop ( float *  x  ) 

Does nothing. This is used along the diagonal of the conversion matrix since that represents a conversion between the same representations.

Parameters:
x -- pointer to the float to be swapped
Returns:
0 on success, -1 on failure. currently always returns 0.

Definition at line 141 of file data_conversion.c.

{
  return 0;
}

int gs_swap_float_undef ( float *  x  ) 

Does nothing. This is used in the conversion matrix in places where we have not implemented a conversion between the two representations.

Parameters:
x -- pointer to the float to be swapped
Returns:
0 on success, -1 on failure. currently always returns -1.

Definition at line 158 of file data_conversion.c.

{
  ERRPRINTF("Error: this conversion is undefined\n");
  return -1;
}

int gs_swap_int ( int *  x  ) 

Swaps the bytes in an integer.

Parameters:
x -- pointer to the integer to be swapped
Returns:
0 on success, -1 on failure

Definition at line 50 of file data_conversion.c.

{
  switch(sizeof(int)) {
    case 4:
      *x = ((*x & 0xFF) << 24) |
           ((*x & 0xFF00) << 8) |
           ((*x & 0xFF0000) >> 8) |
           ((*x & 0xFF000000) >> 24);
      return 0;
    case 2:
      *x = ((*x & 0xFF) << 8) | 
           ((*x & 0xFF00) >> 8);
      return 0;
    default:
      ERRPRINTF("Error: unexpected int size\n");
      return -1;
  }
}

int gs_swap_int_nop ( int *  x  ) 

Does nothing. This is used along the diagonal of the conversion matrix since that represents a conversion between the same representations.

Parameters:
x -- pointer to the integer to be swapped
Returns:
0 on success, -1 on failure. currently always returns 0.

Definition at line 81 of file data_conversion.c.

{
  return 0;
}

int gs_swap_int_undef ( int *  x  ) 

Does nothing. This is used in the conversion matrix in places where we have not implemented a conversion between the two representations.

Parameters:
x -- pointer to the integer to be swapped
Returns:
0 on success, -1 on failure. currently always returns -1.

Definition at line 98 of file data_conversion.c.

{
  ERRPRINTF("Error: this conversion is undefined\n");
  return -1;
}


Variable Documentation

gs_double_swap_f gs_double_swap_func[4][4]
Initial value:
 {
   {gs_swap_double_nop,   gs_swap_double_undef, gs_swap_double_undef, gs_swap_double},
   {gs_swap_double_undef, gs_swap_double_nop,   gs_swap_double_undef, gs_swap_double_undef},
   {gs_swap_double_undef, gs_swap_double_undef, gs_swap_double_nop,   gs_swap_double_undef},
   {gs_swap_double,       gs_swap_double_undef, gs_swap_double_undef, gs_swap_double_nop}}

Array of double byte swapping functions

Definition at line 35 of file data_conversion.c.

gs_float_swap_f gs_float_swap_func[4][4]
Initial value:
 {
   {gs_swap_float_nop,   gs_swap_float_undef, gs_swap_float_undef, gs_swap_float},
   {gs_swap_float_undef, gs_swap_float_nop,   gs_swap_float_undef, gs_swap_float_undef},
   {gs_swap_float_undef, gs_swap_float_undef, gs_swap_float_nop,   gs_swap_float_undef},
   {gs_swap_float,       gs_swap_float_undef, gs_swap_float_undef, gs_swap_float_nop}}

Array of float byte swapping functions

Definition at line 27 of file data_conversion.c.

gs_int_swap_f gs_int_swap_func[4][4]
Initial value:
 {
   {gs_swap_int_nop,   gs_swap_int_undef, gs_swap_int_undef, gs_swap_int},
   {gs_swap_int_undef, gs_swap_int_nop,   gs_swap_int_undef, gs_swap_int_undef},
   {gs_swap_int_undef, gs_swap_int_undef, gs_swap_int_nop,   gs_swap_int_undef},
   {gs_swap_int,       gs_swap_int_undef, gs_swap_int_undef, gs_swap_int_nop}}

Array of integer byte swapping functions

Definition at line 19 of file data_conversion.c.