TF++, Miscellaneous classes and modules in C++:

◆ test_swap()

template<class T >
void test_swap ( )

Function template to test dry byte swapping.

Parameters
Tgeneric type to be used during test

This function tages no argument and returns nothing. All output will be written to stdout.

See also
I/O byte swapping facility.
Examples:
tests/fortraniotest.cc.

Definition at line 71 of file fortraniotest.cc.

References tfxx::ioswap::IOUnion< T >::bytes, tfxx::ioswap::swap(), and tfxx::ioswap::IOUnion< T >::value.

72 {
74  T v1,v2;
75  const int nbytes=sizeof(T);
76  char charpool[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
77  char charresult[26];
78  assert(nbytes<26);
79  for (int i=0; i<nbytes; i++)
80  {
81  u1.bytes[i]=charpool[i];
82  charresult[i]=charpool[i];
83  }
84  charresult[nbytes]='\0';
85  cout << "in: ";
86  cout.width(10);
87  cout << charresult;
88  // take the long way (using these types explicitely)
89  v1=u1.value;
90  v2=tfxx::ioswap::swap(v1);
91  u2.value=v2;
92  for (int i=0; i<nbytes; i++)
93  {
94  charresult[i]=u2.bytes[i];
95  }
96  charresult[nbytes]='\0';
97  cout << " out: ";
98  cout.width(12);
99  cout << charresult << endl;
100 }
char bytes[sizeof(T)]
Definition: bytesex.h:100
T swap(const T &value)
How to swap any generic type.
Definition: bytesex.h:138
Here is the call graph for this function: