| [1669] | 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008 |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | #ifndef NETWORKBYTESTREAM_H |
|---|
| 29 | #define NETWORKBYTESTREAM_H |
|---|
| 30 | |
|---|
| 31 | #define DATA_TYPE unsigned char |
|---|
| 32 | |
|---|
| 33 | #include <string> |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | @author Oliver Scheuss <scheusso [at] ee.ethz.ch> |
|---|
| 38 | */ |
|---|
| 39 | class Bytestream{ |
|---|
| 40 | public: |
|---|
| 41 | Bytestream(); |
|---|
| 42 | Bytestream( unsigned int size ); |
|---|
| 43 | Bytestream( DATA_TYPE *data, unsigned int size, bool empty=false ); |
|---|
| 44 | ~Bytestream(); |
|---|
| 45 | |
|---|
| 46 | template <class T> Bytestream& operator<< ( T& data ) |
|---|
| 47 | { write(&data, sizeof(T)); return *this; } |
|---|
| 48 | template <class T> Bytestream& operator>> ( T& data ) |
|---|
| 49 | { read(&data, sizeof(T)); return *this; } |
|---|
| 50 | void write(void *data, unsigned int length); |
|---|
| 51 | void read(void *data, unsigned int length); |
|---|
| 52 | void readString(std::string& s); |
|---|
| 53 | |
|---|
| 54 | // specialisations |
|---|
| 55 | template <std::string&> Bytestream& operator<< ( std::string& s ){ write( s.c_str(), s.length()+1); return *this; } |
|---|
| 56 | template <std::string&> Bytestream& operator>> ( std::string& s ){ readString(s); return *this; } |
|---|
| 57 | |
|---|
| 58 | DATA_TYPE *getData(){ return data_; } |
|---|
| 59 | unsigned int getSize(){ return writeIterator_; } |
|---|
| 60 | |
|---|
| 61 | private: |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | // Membervariables |
|---|
| 65 | |
|---|
| 66 | private: |
|---|
| 67 | DATA_TYPE *data_; |
|---|
| 68 | unsigned int writeIterator_; |
|---|
| 69 | unsigned int readIterator_; |
|---|
| 70 | unsigned int maxSize_; |
|---|
| 71 | }; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | #endif |
|---|