44// by Andrew O'Meara
55
66#include " XPtrList.h"
7+ #include < string.h>
78
89class XLongList ;
910
11+ inline float void_ptr_to_float (const void * value)
12+ {
13+ float result;
14+ memcpy ( &result, &value, sizeof ( result ) );
15+ return result;
16+ }
17+
18+ inline void * float_to_void_ptr (float value)
19+ {
20+ void * result = 0 ;
21+ memcpy ( &result, &value, sizeof ( value ) );
22+ return result;
23+ }
1024
1125class XFloatList {
1226
1327 public:
1428 XFloatList ( ListOrderingT inOrdering = cOrderNotImportant ); // See XPtrList.h for ListOrderingT choices
1529
1630 // See XPtrList.h for description of functions.
17- virtual long Add ( float inNum ) { return mList .Add ( *(( void **) & inNum) ); }
31+ virtual long Add ( float inNum ) { return mList .Add ( float_to_void_ptr ( inNum ) ); }
1832 virtual void Add ( const XFloatList& inList ) { mList .Add ( inList.mList ); }
1933 virtual bool RemoveElement ( long inIndex ) { return mList .RemoveElement ( inIndex ); }
2034 virtual void RemoveAll () { mList .RemoveAll (); }
21- virtual float Fetch ( long inIndex ) { long t = ( long ) mList .Fetch ( inIndex ); return *(( float *) &t); }
35+ virtual float Fetch ( long inIndex ) { return void_ptr_to_float ( mList .Fetch ( inIndex ) ); }
2236 virtual bool Fetch ( long inIndex, float * ioPtrDest ) const { return mList .Fetch ( inIndex, (void **)ioPtrDest ); }
2337 virtual long Count () const { return mList .Count (); }
2438
@@ -36,7 +50,7 @@ class XFloatList {
3650 // Smoothes all the floats in this list
3751 void GaussSmooth ( float inSigma );
3852
39- float operator [] ( const long inIndex ) { long t = ( long ) mList .Fetch ( inIndex ); return *(( float *) &t ); }
53+ float operator [] ( const long inIndex ) { return void_ptr_to_float ( mList .Fetch ( inIndex )); }
4054
4155 // Generic utility fcn to gauss-smooth a 1D curve.
4256 static void GaussSmooth ( float inSigma, long inN, float inSrceDest[] );
0 commit comments