1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 #ifndef __H5TRANSFORMEDDATA_HXX__ 17 #define __H5TRANSFORMEDDATA_HXX__ 18 19 #include "H5BasicData.hxx" 20 21 namespace org_modules_hdf5 22 { 23 24 template <typename T, typename U> 25 class H5TransformedData : public H5Data 26 { 27 28 protected: 29 30 U * transformedData; 31 32 public: 33 H5TransformedData(H5Object & _parent,const hsize_t _totalSize,const hsize_t _dataSize,const hsize_t _ndims,const hsize_t * _dims,T * _data,const hsize_t _stride,const size_t _offset,const bool _dataOwner)34 H5TransformedData(H5Object & _parent, const hsize_t _totalSize, const hsize_t _dataSize, const hsize_t _ndims, const hsize_t * _dims, T * _data, const hsize_t _stride, const size_t _offset, const bool _dataOwner) : H5Data(_parent, _totalSize, _dataSize, _ndims, _dims, _data, _stride, _offset, _dataOwner) 35 { 36 transformedData = new U[totalSize]; 37 38 if (stride == 0) 39 { 40 for (unsigned int i = 0; i < (unsigned int)totalSize; i++) 41 { 42 transformedData[i] = (U)(_data[i]); 43 } 44 } 45 else 46 { 47 char * __data = (char *)_data; 48 for (unsigned int i = 0; i < (unsigned int)totalSize; i++) 49 { 50 transformedData[i] = (U)(*((T *)(__data + offset))); 51 __data += stride; 52 } 53 } 54 } 55 ~H5TransformedData()56 virtual ~H5TransformedData() 57 { 58 delete[] transformedData; 59 } 60 getData() const61 virtual void * getData() const 62 { 63 return transformedData; 64 } 65 printData(std::ostream & os,const unsigned int pos,const unsigned int indentLevel) const66 virtual void printData(std::ostream & os, const unsigned int pos, const unsigned int indentLevel) const 67 { 68 os << transformedData[pos]; 69 } 70 toScilab(void * pvApiCtx,const int lhsPosition,int * parentList=0,const int listPosition=0,const bool flip=true) const71 virtual void toScilab(void * pvApiCtx, const int lhsPosition, int * parentList = 0, const int listPosition = 0, const bool flip = true) const 72 { 73 U * newData = 0; 74 75 if (ndims == 0) 76 { 77 H5BasicData<U>::create(pvApiCtx, lhsPosition, 1, 1, static_cast<U *>(getData()), parentList, listPosition); 78 } 79 else if (ndims == 1) 80 { 81 H5BasicData<U>::alloc(pvApiCtx, lhsPosition, 1, (int)*dims, parentList, listPosition, &newData); 82 memcpy(static_cast<void *>(newData), static_cast<void *>(transformedData), totalSize * sizeof(U)); 83 } 84 else 85 { 86 if (ndims == 2) 87 { 88 if (flip) 89 { 90 H5BasicData<U>::alloc(pvApiCtx, lhsPosition, (int)dims[1], (int)dims[0], parentList, listPosition, &newData); 91 } 92 else 93 { 94 H5BasicData<U>::alloc(pvApiCtx, lhsPosition, (int)dims[0], (int)dims[1], parentList, listPosition, &newData); 95 } 96 97 H5DataConverter::C2FHypermatrix(2, dims, 0, static_cast<U *>(getData()), newData); 98 } 99 else 100 { 101 int * list = getHypermatrix(pvApiCtx, lhsPosition, parentList, listPosition, flip); 102 H5BasicData<U>::alloc(pvApiCtx, lhsPosition, (int)totalSize, 1, list, 3, &newData); 103 H5DataConverter::C2FHypermatrix((int)ndims, dims, totalSize, static_cast<U *>(getData()), newData, flip); 104 } 105 } 106 } 107 dump(std::map<haddr_t,std::string> & alreadyVisited,const unsigned int indentLevel) const108 virtual std::string dump(std::map<haddr_t, std::string> & alreadyVisited, const unsigned int indentLevel) const 109 { 110 return H5DataConverter::dump(alreadyVisited, indentLevel, (int)ndims, dims, *this); 111 } 112 }; 113 } 114 115 #endif // __H5TRANSFORMEDDATA_HXX__ 116