Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable_var/synchronizeable_int.cc @ 10578

Last change on this file since 10578 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 1.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christoph Renner
13   co-programmer: ...
14*/
15
16
17#include "synchronizeable_int.h"
18#include "converter.h"
19
20#include <cassert>
21
22/**
23 * standard constructor
24 * @todo this constructor is not jet implemented - do it
25*/
26SynchronizeableInt::SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, INTSIZE, permission, priority )
27{
28  this->vPtrIn = ptrIn;
29  this->vPtrOut = ptrOut;
30}
31
32
33/**
34 * standard deconstructor
35*/
36SynchronizeableInt::~SynchronizeableInt ()
37{
38}
39
40/**
41 * write var data to byte buffer
42 * @param buf pointer to write to
43 * @param maxLength writeToBuf will not write more than maxLength bytes
44 * @return number bytes written
45 */
46int SynchronizeableInt::writeToBuf( byte * buf, int maxLength )
47{
48  int res = Converter::intToByteArray( *vPtrIn, buf, maxLength );
49
50  assert( res == INTSIZE );
51
52  return res;
53}
54
55/**
56 * read var data from byte buffer
57 * @param buf pointer to read from
58 * @param maxLength readFromBuf will not read more than maxLength bytes
59 * @return number bytes read
60 */
61int SynchronizeableInt::readFromBuf( byte * buf, int maxLength )
62{
63  assert( maxLength >= INTSIZE );
64
65  int oldVal = *vPtrOut;
66
67  int res = Converter::byteArrayToInt( buf, vPtrOut );
68
69  setHasChanged( oldVal != *vPtrOut );
70
71  assert( res == INTSIZE );
72
73  return res;
74}
75
76
77/**
78 * print out variable value
79 */
80void SynchronizeableInt::debug( )
81{
82  printf( "SYNCHRONIZEABLE_VAR: %s IN: %d OUT: %d\n", name.c_str(), *vPtrIn, *vPtrOut );
83}
84
Note: See TracBrowser for help on using the repository browser.