1 // Copyright (C) 2007-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDCouplingMemArray.txx"
23 using namespace MEDCoupling;
25 template class MEDCoupling::MemArray<float>;
26 template class MEDCoupling::DataArrayTemplate<float>;
27 template class MEDCoupling::DataArrayTemplateClassic<float>;
28 template class MEDCoupling::DataArrayTemplateFP<float>;
29 template class MEDCoupling::DataArrayIterator<float>;
31 DataArrayFloat *DataArrayFloat::New()
33 return new DataArrayFloat;
36 DataArrayFloat *DataArrayFloat::deepCopy() const
38 return new DataArrayFloat(*this);
41 void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
43 int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
44 const float *data(begin());
46 stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
47 if(nbTuples*nbComp>=1)
49 stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
50 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
51 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
52 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
55 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
56 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
59 void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
61 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
62 stream << "DataArrayFloat C++ instance at " << this << ". ";
65 int nbOfCompo=(int)_info_on_compo.size();
68 int nbOfTuples=getNumberOfTuples();
69 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
70 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
73 stream << "Number of components : 0.";
76 stream << "*** No data allocated ****";
79 void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
81 const float *data(begin());
82 int nbOfTuples(getNumberOfTuples());
83 int nbOfCompo=(int)_info_on_compo.size();
84 std::ostringstream oss2; oss2 << "[";
86 std::string oss2Str(oss2.str());
88 for(int i=0;i<nbOfTuples && isFinished;i++)
93 for(int j=0;j<nbOfCompo;j++,data++)
96 if(j!=nbOfCompo-1) oss2 << ", ";
102 if(i!=nbOfTuples-1) oss2 << ", ";
103 std::string oss3Str(oss2.str());
104 if(oss3Str.length()<maxNbOfByteInRepr)
115 bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
117 if(!areInfoEqualsIfNotWhy(other,reason))
119 return _mem.isEqual(other._mem,prec,reason);
122 bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
125 return isEqualIfNotWhy(other,prec,tmp);
128 bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
131 return _mem.isEqual(other._mem,prec,tmp);
134 DataArrayFloatIterator *DataArrayFloat::iterator()
136 return new DataArrayFloatIterator(this);
139 DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator<float>(da)
143 DataArrayFloatTuple::DataArrayFloatTuple(float *pt, int nbOfComp):DataArrayTuple<float>(pt,nbOfComp)
147 std::string DataArrayFloatTuple::repr() const
149 std::ostringstream oss; oss.precision(7); oss << "(";
150 for(int i=0;i<_nb_of_compo-1;i++)
151 oss << _pt[i] << ", ";
152 oss << _pt[_nb_of_compo-1] << ")";
156 float DataArrayFloatTuple::floatValue() const
158 return this->zeValue();
162 * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef.
163 * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false.
164 * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
165 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
167 DataArrayFloat *DataArrayFloatTuple::buildDAFloat(int nbOfTuples, int nbOfCompo) const
169 return this->buildDA(nbOfTuples,nbOfCompo);