$treeview $search $mathjax
|
Palabos
Version 1.1
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /* This file is part of the Palabos library. 00002 * 00003 * Copyright (C) 2011 FlowKit Sarl 00004 * Avenue de Chailly 23 00005 * 1012 Lausanne, Switzerland 00006 * E-mail contact: contact@flowkit.com 00007 * 00008 * The most recent release of Palabos can be downloaded at 00009 * <http://www.palabos.org/> 00010 * 00011 * The library Palabos is free software: you can redistribute it and/or 00012 * modify it under the terms of the GNU Affero General Public License as 00013 * published by the Free Software Foundation, either version 3 of the 00014 * License, or (at your option) any later version. 00015 * 00016 * The library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Affero General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Affero General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 00026 #ifndef SERIALIZER_H 00027 #define SERIALIZER_H 00028 00029 #include "core/globalDefs.h" 00030 #include "core/util.h" 00031 00032 namespace plb { 00033 00034 struct DataSerializer { 00035 virtual ~DataSerializer() { } 00036 virtual DataSerializer* clone() const =0; 00037 virtual pluint getSize() const =0; 00038 virtual const char* getNextDataBuffer(pluint& bufferSize) const =0; 00039 virtual bool isEmpty() const =0; 00040 }; 00041 00042 struct DataUnSerializer { 00043 virtual ~DataUnSerializer() { } 00044 virtual DataUnSerializer* clone() const =0; 00045 virtual pluint getSize() const =0; 00046 virtual char* getNextDataBuffer(pluint& bufferSize) =0; 00047 virtual void commitData() =0; 00048 virtual bool isFull() const =0; 00049 }; 00050 00051 struct SerializedWriter { 00052 virtual ~SerializedWriter() { } 00053 virtual SerializedWriter* clone() const =0; 00054 virtual void writeHeader(pluint dataSize) =0; 00055 virtual void writeData(char const* dataBuffer, pluint bufferSize) =0; 00056 }; 00057 00058 00059 struct SerializedReader { 00060 virtual ~SerializedReader() { } 00061 virtual SerializedReader* clone() const =0; 00062 virtual void readHeader(pluint dataSize) const =0; 00063 virtual void readData(char* dataBuffer, pluint bufferSize) const =0; 00064 }; 00065 00068 template<typename T> 00069 class WriteToSerialArray : public SerializedWriter { 00070 public: 00071 WriteToSerialArray(T* array_, plint typedSize_); 00072 virtual WriteToSerialArray* clone() const; 00073 virtual void writeHeader(pluint dataSize); 00074 virtual void writeData(char const* dataBuffer, pluint bufferSize); 00075 private: 00076 char* array; 00077 plint typedSize; 00078 plint pos; 00079 }; 00080 00083 template<typename T> 00084 class ReadFromSerialArray : public SerializedReader { 00085 public: 00086 ReadFromSerialArray(T const* array_, plint typedSize_); 00087 virtual ReadFromSerialArray<T>* clone() const; 00088 virtual void readHeader(pluint dataSize) const; 00089 virtual void readData(char* dataBuffer, pluint bufferSize) const; 00090 private: 00091 char const* array; 00092 plint typedSize; 00093 mutable plint pos; 00094 }; 00095 00096 00097 void serializerToUnSerializer(DataSerializer const* serializer, DataUnSerializer* unSerializer); 00098 00099 void serializerToSink(DataSerializer const* serializer, SerializedWriter* sink); 00100 00101 void sourceToUnSerializer(SerializedReader const* source, DataUnSerializer* unSerializer); 00102 00103 00104 } // namespace plb 00105 00106 #endif // SERIALIZER_H
1.6.3
1.6.3