Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7459 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Apr 30, 2006, 1:50:25 PM (19 years ago)
Author:
rennerc
Message:

finished some SynchronizeableVars classes

Location:
branches/network/src/lib/network
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/synchronizeable.cc

    r7445 r7459  
    121121void Synchronizeable::varChangeHandler( std::list<int> & id )
    122122{
    123 #warning implement this
    124123}
    125124
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.cc

    r7446 r7459  
    4343int SynchronizeableBool::writeToBuf( byte * buf, int maxLength )
    4444{
    45 #warning implement this
     45  assert( maxLength >= 1 );
     46 
     47  buf[0] = ( *vPtrIn ) ? 1 : 0;
     48 
     49  return 1;
    4650}
    4751
     
    5458int SynchronizeableBool::readFromBuf( byte * buf, int maxLength )
    5559{
    56 #warning implement this
     60  assert( maxLength >= 1 );
     61 
     62  *vPtrOut = buf[0] != 0;
     63 
     64  return 1;
    5765}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.h

    r7444 r7459  
    1818    virtual int readFromBuf( byte * buf, int maxLength );
    1919   
     20    /**
     21     * check if writeToBuf will return the same size every time
     22     * @return true if same size every time
     23     */
     24    virtual bool hasStaticSize(){ return true; };
     25   
    2026  private:
    2127    bool * vPtrIn;       //!< pointer to data (read)
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.cc

    r7444 r7459  
    1616
    1717#include "synchronizeable_float.h"
     18#include "converter.h"
    1819
    1920
     
    2223 * @todo this constructor is not jet implemented - do it
    2324*/
    24 SynchronizeableFloat::SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 0, permission, priority )
     25SynchronizeableFloat::SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, FLOATSIZE, permission, priority )
    2526{
    2627  this->vPtrIn = ptrIn;
     
    4445int SynchronizeableFloat::writeToBuf( byte * buf, int maxLength )
    4546{
    46 #warning implement this
     47  int res = Converter::floatToByteArray( *vPtrIn, buf, maxLength );
     48 
     49  assert( res == FLOATSIZE );
     50 
     51  return res;
    4752}
    4853
     
    5560int SynchronizeableFloat::readFromBuf( byte * buf, int maxLength )
    5661{
    57 #warning implement this
     62  assert( maxLength >= FLOATSIZE );
     63 
     64  int res = Converter::byteArrayToFloat( buf, vPtrOut );
     65 
     66  assert( res == FLOATSIZE );
     67 
     68  return res;
    5869}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.h

    r7444 r7459  
    1717    virtual int writeToBuf( byte * buf, int maxLength );
    1818    virtual int readFromBuf( byte * buf, int maxLength );
     19       
     20    /**
     21     * check if writeToBuf will return the same size every time
     22     * @return true if same size every time
     23     */
     24    virtual bool hasStaticSize(){ return true; };
    1925   
    2026  private:
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.cc

    r7444 r7459  
    1616
    1717#include "synchronizeable_int.h"
     18#include "converter.h"
    1819
    1920
     
    4445int SynchronizeableInt::writeToBuf( byte * buf, int maxLength )
    4546{
    46 #warning implement this
     47  int res = Converter::intToByteArray( *vPtrIn, buf, maxLength );
     48 
     49  assert( res == INTSIZE );
     50 
     51  return res;
    4752}
    4853
     
    5560int SynchronizeableInt::readFromBuf( byte * buf, int maxLength )
    5661{
    57 #warning implement this
     62  assert( maxLength >= INTSIZE );
     63 
     64  int res = Converter::byteArrayToInt( buf, vPtrOut );
     65 
     66  assert( res == INTSIZE );
     67 
     68  return res;
    5869}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.h

    r7444 r7459  
    1818    virtual int readFromBuf( byte * buf, int maxLength );
    1919   
     20    /**
     21     * check if writeToBuf will return the same size every time
     22     * @return true if same size every time
     23     */
     24    virtual bool hasStaticSize(){ return true; };
     25   
    2026  private:
    2127    int * vPtrIn;       //!< pointer to data (read)
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc

    r7444 r7459  
    1616
    1717#include "synchronizeable_quaternion.h"
     18#include "converter.h"
    1819
    1920
    2021/**
    2122 * standard constructor
    22  * @todo this constructor is not jet implemented - do it
    23 */
    24 SynchronizeableQuaternion::SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 0, permission, priority )
     23 */
     24SynchronizeableQuaternion::SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 4*INTSIZE, permission, priority )
    2525{
    2626  this->vPtrIn = ptrIn;
     
    3131/**
    3232 * standard deconstructor
    33 */
     33 */
    3434SynchronizeableQuaternion::~SynchronizeableQuaternion ()
    3535{
     
    4444int SynchronizeableQuaternion::writeToBuf( byte * buf, int maxLength )
    4545{
    46 #warning implement this
     46  int n = 0;
     47  int res;
     48 
     49  res = Converter::floatToByteArray( vPtrIn->v.x, buf, maxLength - n );
     50  assert( res > 0 );
     51  n += res;
     52 
     53  res = Converter::floatToByteArray( vPtrIn->v.y, buf, maxLength - n );
     54  assert( res > 0 );
     55  n += res;
     56 
     57  res = Converter::floatToByteArray( vPtrIn->v.z, buf, maxLength - n );
     58  assert( res > 0 );
     59  n += res;
     60 
     61  res = Converter::floatToByteArray( vPtrIn->w, buf, maxLength - n );
     62  assert( res > 0 );
     63  n += res;
     64 
     65  assert( 4*FLOATSIZE == n );
     66 
     67  return n;
    4768}
    4869
     
    5576int SynchronizeableQuaternion::readFromBuf( byte * buf, int maxLength )
    5677{
    57 #warning implement this
     78  assert( maxLength >= 4*FLOATSIZE );
     79 
     80  float x,y,z,w;
     81 
     82  int res;
     83  int n = 0;
     84 
     85  res += Converter::byteArrayToFloat( buf + n, &x );
     86  assert( res > 0 );
     87  n += res;
     88 
     89  res += Converter::byteArrayToFloat( buf + n, &x );
     90  assert( res > 0 );
     91  n += res;
     92 
     93  res += Converter::byteArrayToFloat( buf + n, &x );
     94  assert( res > 0 );
     95  n += res;
     96 
     97  res += Converter::byteArrayToFloat( buf + n, &w );
     98  assert( res > 0 );
     99  n += res;
     100 
     101  *vPtrOut = Quaternion( Vector(x, y, z), w );
     102 
     103  assert( res == 4*FLOATSIZE );
     104  return res;
    58105}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h

    r7444 r7459  
    1919    virtual int writeToBuf( byte * buf, int maxLength );
    2020    virtual int readFromBuf( byte * buf, int maxLength );
     21       
     22    /**
     23     * check if writeToBuf will return the same size every time
     24     * @return true if same size every time
     25     */
     26    virtual bool hasStaticSize(){ return true; };
    2127   
    2228  private:
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc

    r7444 r7459  
    1616
    1717#include "synchronizeable_string.h"
     18#include "converter.h"
    1819
    1920
     
    4445int SynchronizeableString::writeToBuf( byte * buf, int maxLength )
    4546{
    46 #warning implement this
     47  int res = Converter::stringToByteArray( *vPtrIn, buf, maxLength );
     48 
     49  assert( res > 0 );
     50 
     51  return res;
    4752}
    4853
     
    5560int SynchronizeableString::readFromBuf( byte * buf, int maxLength )
    5661{
    57 #warning implement this
     62  int res = Converter::byteArrayToString( buf, *vPtrOut, maxLength );
     63 
     64  assert( res > 0 );
     65 
     66  return res;
    5867}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.h

    r7444 r7459  
    2020    virtual int readFromBuf( byte * buf, int maxLength );
    2121   
     22       
     23    /**
     24     * check if writeToBuf will return the same size every time
     25     * @return true if same size every time
     26     */
     27    virtual bool hasStaticSize(){ return false; };
     28   
    2229  private:
    2330    std::string * vPtrIn;       //!< pointer to data (read)
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc

    r7444 r7459  
    2424SynchronizeableVar::SynchronizeableVar ( void * ptrIn, void * ptrOut, std::string name, int length, int permission, int priority)
    2525{
     26  assert( ptrIn );
     27  assert( ptrOut );
     28 
    2629  this->ptrIn = ptrIn;
    2730  this->ptrOut = ptrOut;
     
    4144}
    4245
    43 /**
    44  * write var data to byte buffer
    45  * @param buf pointer to write to
    46  * @param maxLength writeToBuf will not write more than maxLength bytes
    47  * @return number bytes written
    48  */
    49 int SynchronizeableVar::writeToBuf( byte * buf, int maxLength )
    50 {
    51 #warning implement this
    52 }
    53 
    54 /**
    55  * read var data from byte buffer
    56  * @param buf pointer to read from
    57  * @param maxLength readFromBuf will not read more than maxLength bytes
    58  * @return number bytes read
    59  */
    60 int SynchronizeableVar::readFromBuf( byte * buf, int maxLength )
    61 {
    62 #warning implement this
    63 }
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.h

    r7444 r7459  
    2222    inline bool beWatched(){ return this->bWatched; }
    2323   
    24     virtual int writeToBuf( byte * buf, int maxLength );
    25     virtual int readFromBuf( byte * buf, int maxLength );
     24    /**
     25     * write var data to byte buffer
     26     * @param buf pointer to write to
     27     * @param maxLength writeToBuf will not write more than maxLength bytes
     28     * @return number bytes written
     29     */
     30    virtual int writeToBuf( byte * buf, int maxLength ) = 0;
     31   
     32    /**
     33     * read var data from byte buffer
     34     * @param buf pointer to read from
     35     * @param maxLength readFromBuf will not read more than maxLength bytes
     36     * @return number bytes read
     37     */
     38    virtual int readFromBuf( byte * buf, int maxLength ) = 0;
     39   
     40    /**
     41     * check if writeToBuf will return the same size every time
     42     * @return true if same size every time
     43     */
     44    virtual bool hasStaticSize() = 0;
    2645   
    2746    /**
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.cc

    r7444 r7459  
    1616
    1717#include "synchronizeable_vector.h"
     18#include "converter.h"
    1819
    1920
     
    2223 * @todo this constructor is not jet implemented - do it
    2324*/
    24 SynchronizeableVector::SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 0, permission, priority )
     25SynchronizeableVector::SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 3*FLOATSIZE, permission, priority )
    2526{
    2627  this->vPtrIn = ptrIn;
     
    4445int SynchronizeableVector::writeToBuf( byte * buf, int maxLength )
    4546{
    46 #warning implement this
     47  int n = 0;
     48  int res;
     49 
     50  res = Converter::floatToByteArray( vPtrIn->x, buf, maxLength - n );
     51  assert( res > 0 );
     52  n += res;
     53 
     54  res = Converter::floatToByteArray( vPtrIn->y, buf, maxLength - n );
     55  assert( res > 0 );
     56  n += res;
     57 
     58  res = Converter::floatToByteArray( vPtrIn->z, buf, maxLength - n );
     59  assert( res > 0 );
     60  n += res;
     61 
     62  assert( 3*FLOATSIZE == n );
     63 
     64  return n;
    4765}
    4866
     
    5573int SynchronizeableVector::readFromBuf( byte * buf, int maxLength )
    5674{
    57 #warning implement this
     75  assert( maxLength >= 3*FLOATSIZE );
     76 
     77  float x,y,z;
     78 
     79  int res;
     80  int n = 0;
     81 
     82  res += Converter::byteArrayToFloat( buf + n, &x );
     83  assert( res > 0 );
     84  n += res;
     85 
     86  res += Converter::byteArrayToFloat( buf + n, &x );
     87  assert( res > 0 );
     88  n += res;
     89 
     90  res += Converter::byteArrayToFloat( buf + n, &x );
     91  assert( res > 0 );
     92  n += res;
     93 
     94  *vPtrOut = Vector( x, y, z );
     95 
     96  assert( res == 3*FLOATSIZE );
     97  return res;
    5898}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.h

    r7444 r7459  
    2020    virtual int readFromBuf( byte * buf, int maxLength );
    2121   
     22    /**
     23     * check if writeToBuf will return the same size every time
     24     * @return true if same size every time
     25     */
     26    virtual bool hasStaticSize(){ return true; };
     27   
    2228  private:
    2329    Vector * vPtrIn;       //!< pointer to data (read)
Note: See TracChangeset for help on using the changeset viewer.