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 ARRAYSPARSEWRAPPERREADER_HPP_
00021 #define ARRAYSPARSEWRAPPERREADER_HPP_
00022
00023 template<class Wrapper>
00024 class Reader<Wrapper, ArraySparseWrapper>
00025 {
00026
00027 public:
00028 static void read(std::string& in, Wrapper& wrapper) {
00029 std::string uncompressed;
00030 char *p;
00031 miINT32_t *tag = reinterpret_cast<miINT32_t*>(&in[0]);
00032
00033 if (*tag == miCOMPRESSED) {
00034
00035 z_stream strm;
00036 strm.zalloc = Z_NULL;
00037 strm.zfree = Z_NULL;
00038 strm.opaque = Z_NULL;
00039 strm.avail_in = 0;
00040 strm.next_in = Z_NULL;
00041 inflateInit(&strm);
00042
00043 miINT32_t matrixtag[2];
00044 strm.next_in = reinterpret_cast<Bytef*>(&in[8]);
00045 strm.avail_in = *(tag+1);
00046 strm.next_out = reinterpret_cast<Bytef*>(matrixtag);
00047 strm.avail_out = 8;
00048 inflate(&strm, Z_NO_FLUSH);
00049
00050
00051 uncompressed.reserve(matrixtag[1]);
00052 strm.next_out = reinterpret_cast<Bytef*>(&uncompressed[0]);
00053 strm.avail_out = matrixtag[1];
00054 inflate(&strm, Z_NO_FLUSH);
00055
00056 p = &uncompressed[0];
00057 } else {
00058 p = &in[8];
00059 }
00060
00061
00062 const miUINT32_t *flags = reinterpret_cast<miUINT32_t*>(p+8);
00063 bool isComplex = ((*flags & 2048) != 0);
00064 wrapper.isComplex(isComplex);
00065 miUINT32_t nnz = *(flags+1);
00066 wrapper.nnz(nnz);
00067 p += 16;
00068
00069
00070 miINT32_t *size = reinterpret_cast<miINT32_t*>(p);
00071 miINT32_t sizeLength = *(size+1);
00072
00073 miINT32_t rows = *(size+2);
00074 miINT32_t cols = *(size+3);
00075 wrapper.size(rows, cols);
00076 p += 8 + (sizeLength+7)/8*8;
00077
00078
00079
00080 miINT32_t *nameTag = reinterpret_cast<miINT32_t*>(p);
00081 miINT32_t nameLength = *(nameTag+1);
00082 std::string name(p+8, nameLength);
00083 wrapper.name(name);
00084 p += 8 + (nameLength+7)/8*8;
00085
00086
00087 miINT32_t *ir = reinterpret_cast<miINT32_t*>(p+8);
00088
00089 memcpy(wrapper.ir(), ir, 4*nnz);
00090 p += 8 + (4*nnz+7)/8*8;
00091
00092
00093 miINT32_t *jc = reinterpret_cast<miINT32_t*>(p+8);
00094
00095 memcpy(wrapper.jc(), jc, 4*(cols+1));
00096 p += 8 + (4*(cols+1)+7)/8*8;
00097
00098
00099 miINT32_t *prTag = reinterpret_cast<miINT32_t*>(p);
00100 miMATRIX_class realType = *prTag;
00101 wrapper.realType(realType);
00102 miINT32_t prLength = *(prTag+1);
00103 memcpy(wrapper.pr(), p+8, prLength);
00104 p += 8 + (prLength+7)/8*8;
00105
00106
00107 if (isComplex && wrapper.pi() != NULL) {
00108 miINT32_t *piTag = reinterpret_cast<miINT32_t*>(p);
00109 miMATRIX_class imagType = *piTag;
00110 wrapper.imagType(imagType);
00111 miINT32_t piLength = *(piTag+1);
00112 memcpy(wrapper.pi(), p+8, piLength);
00113 p += (piLength+7)/8*8;
00114 }
00115
00116
00117 }
00118
00119 };
00120
00121 #endif