/Users/craigcornelius/Projects/SPRING Mac Release 0.2/space.h

Go to the documentation of this file.
00001 // $Id: space.h,v 1.11 2001/01/08 19:01:50 kevin Exp $
00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $
00003 
00004 #ifndef _SPACE_H_
00005 #define _SPACE_H_
00006 
00007 #ifdef _WIN32
00008 #else
00009 #include <netinet/in.h>
00010 #endif
00011 
00012 #include "socket.h"
00013 
00014 typedef union {
00015   unsigned long l;
00016   char c[4];
00017   float f;
00018 } uf_t;
00019 
00020 typedef union {
00021   unsigned short s;
00022   char c[2];
00023 } us_t;
00024 
00025 typedef char space_type;
00026 
00027 #define TYPE_QUIT     ((space_type) 0x80)
00028 #define TYPE_VOID     ((space_type) 0x81)
00029 #define TYPE_TRIANGLE ((space_type) 0x82)
00030 #define TYPE_INTERPOL ((space_type) 0x83)
00031 
00032 #define SEND_QUIT     ((space_type) 0x00)
00033 #define SEND_COORD    ((space_type) 0x01)
00034 
00035 inline long copy_float_to_buf(char *buf, double val)
00036 {
00037  static uf_t long_tmp;
00038  static int i;
00039 
00040  long_tmp.f = (float) val;
00041  long_tmp.l = htonl(long_tmp.l);
00042  for(i=0; i<4; i++)
00043   buf[i] = long_tmp.c[i];
00044  return long_tmp.l;
00045 }
00046 
00047 inline void copy_ushort_to_buf(char *buf, unsigned short val)
00048 {
00049  static us_t short_tmp;
00050  static int i;
00051 
00052  short_tmp.s = htons(val);
00053  for(i=0; i<2; i++)
00054   buf[i] = short_tmp.c[i];
00055 }
00056 
00057 inline long receive_float_from_buf(char *buf, double *val)
00058 {
00059  uf_t long_tmp;
00060  static int i;
00061 
00062  for(i=0; i<4; i++)
00063   long_tmp.c[i] = buf[i];
00064  long_tmp.l = ntohl(long_tmp.l);
00065  *val = (double) long_tmp.f;
00066  return long_tmp.l;
00067 }
00068 
00069 inline long hashdouble(double val)
00070 {
00071  uf_t long_tmp;
00072 
00073  long_tmp.f = (float) val;
00074  return long_tmp.l;
00075 }
00076 
00077 inline void receive_ushort_from_buf(char *buf, unsigned short *val)
00078 {
00079  static us_t short_tmp;
00080  static int i;
00081 
00082  for(i=0; i<2; i++)
00083   short_tmp.c[i] = buf[i];
00084  *val = ntohs(short_tmp.s);
00085 }
00086 
00087 inline float receive_long_from_buf(char *buf, long *val)
00088 {
00089  static uf_t long_tmp;
00090  static int i;
00091 
00092  for(i=0; i<4; i++)
00093   long_tmp.c[i] = buf[i];
00094  *val = ntohl(long_tmp.l);
00095  return long_tmp.f;
00096 }
00097 
00098 class space {
00099 
00100  public :
00101 
00102   virtual Point3D *get_force(Point3D *, Point3D *)=0;
00103 
00104   virtual int istouching()=0;
00105   
00106   virtual ~space()
00107   {
00108   }
00109 
00110   virtual void print_datas()=0;
00111 
00112   virtual void send_datas(Socket *s)=0;
00113 
00114   virtual void use_new_datas(char *buf, int size)=0;
00115 
00116   virtual void erase_all()=0;
00117 
00118   virtual long gethash()=0;
00119 };
00120 
00121 #endif

Generated on Thu Aug 30 11:03:15 2007 for SPRING Mac by  doxygen 1.5.3