Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARRAYDENSEWRAPPERREADER_HPP_
00021 #define ARRAYDENSEWRAPPERREADER_HPP_
00022
00023 template<class Wrapper>
00024 class Reader<Wrapper, ArrayDenseWrapper>
00025 {
00026 public:
00027 static void read(std::string& in, Wrapper& wrapper) {
00028 std::string uncompressed;
00029 char *p;
00030 miINT32_t *tag = reinterpret_cast<miINT32_t*>(&in[0]);
00031
00032 if (*tag == miCOMPRESSED) {
00033
00034 z_stream strm;
00035 strm.zalloc = Z_NULL;
00036 strm.zfree = Z_NULL;
00037 strm.opaque = Z_NULL;
00038 strm.avail_in = 0;
00039 strm.next_in = Z_NULL;
00040 inflateInit(&strm);
00041
00042 miINT32_t matrixtag[2];
00043 strm.next_in = reinterpret_cast<Bytef*>(&in[8]);
00044 strm.avail_in = *(tag+1);
00045 strm.next_out = reinterpret_cast<Bytef*>(matrixtag);
00046 strm.avail_out = 8;
00047 inflate(&strm, Z_NO_FLUSH);
00048
00049
00050 uncompressed.reserve(matrixtag[1]);
00051 strm.next_out = reinterpret_cast<Bytef*>(&uncompressed[0]);
00052 strm.avail_out = matrixtag[1];
00053 inflate(&strm, Z_NO_FLUSH);
00054
00055 p = &uncompressed[0];
00056 } else {
00057 p = &in[8];
00058 }
00059
00060
00061 const miUINT32_t *flags = reinterpret_cast<miUINT32_t*>(p+8);
00062 bool isComplex = ((*flags & 2048) != 0);
00063 wrapper.isComplex(isComplex);
00064 p += 16;
00065
00066
00067 miINT32_t *size = reinterpret_cast<miINT32_t*>(p);
00068 miINT32_t sizeLength = *(size+1);
00069
00070 miINT32_t rows = *(size+2);
00071 miINT32_t cols = *(size+3);
00072 wrapper.size(rows, cols);
00073 p += 8 + (sizeLength+7)/8*8;
00074
00075
00076
00077 miINT32_t *nameTag = reinterpret_cast<miINT32_t*>(p);
00078 miINT32_t nameLength = *(nameTag+1);
00079 std::string name(p+8, nameLength);
00080 wrapper.name(name);
00081 p += 8 + (nameLength+7)/8*8;
00082
00083
00084 miINT32_t *prTag = reinterpret_cast<miINT32_t*>(p);
00085 miMATRIX_class realType = *prTag;
00086 wrapper.realType(realType);
00087 miINT32_t prLength = *(prTag+1);
00088 memcpy(wrapper.pr(), p+8, prLength);
00089 p += 8 + (prLength+7)/8*8;
00090
00091
00092 if (isComplex && wrapper.pi() != NULL) {
00093 miINT32_t *piTag = reinterpret_cast<miINT32_t*>(p);
00094 miMATRIX_class imagType = *piTag;
00095 wrapper.imagType(imagType);
00096 miINT32_t piLength = *(piTag+1);
00097 memcpy(wrapper.pi(), p+8, piLength);
00098 p += (piLength+7)/8*8;
00099 }
00100
00101 }
00102 };
00103
00104 #endif