1 // Copyright (C) 2007-2021 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 mcIdType nbTuples(getNumberOfTuples());
44 std::size_t nbComp(getNumberOfComponents());
45 const float *data(begin());
47 stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
48 if(nbTuples*nbComp>=1)
50 stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
51 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
52 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
53 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
56 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
57 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
60 void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
62 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
63 stream << "DataArrayFloat C++ instance at " << this << ". ";
66 std::size_t nbOfCompo=_info_on_compo.size();
69 mcIdType nbOfTuples=getNumberOfTuples();
70 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
71 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
74 stream << "Number of components : 0.";
77 stream << "*** No data allocated ****";
80 void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
82 const float *data(begin());
83 mcIdType nbOfTuples(getNumberOfTuples());
84 std::size_t nbOfCompo=_info_on_compo.size();
85 std::ostringstream oss2; oss2 << "[";
87 std::string oss2Str(oss2.str());
89 for(mcIdType i=0;i<nbOfTuples && isFinished;i++)
94 for(std::size_t j=0;j<nbOfCompo;j++,data++)
97 if(j!=nbOfCompo-1) oss2 << ", ";
103 if(i!=nbOfTuples-1) oss2 << ", ";
104 std::string oss3Str(oss2.str());
105 if(oss3Str.length()<maxNbOfByteInRepr)
116 bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
118 if(!areInfoEqualsIfNotWhy(other,reason))
120 return _mem.isEqual(other._mem,prec,reason);
123 bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
126 return isEqualIfNotWhy(other,prec,tmp);
129 bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
132 return _mem.isEqual(other._mem,prec,tmp);
135 DataArrayFloatIterator *DataArrayFloat::iterator()
137 return new DataArrayFloatIterator(this);
140 DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator<float>(da)
144 DataArrayFloatTuple::DataArrayFloatTuple(float *pt, std::size_t nbOfComp):DataArrayTuple<float>(pt,nbOfComp)
148 std::string DataArrayFloatTuple::repr() const
150 std::ostringstream oss; oss.precision(7); oss << "(";
151 for(std::size_t i=0;i<_nb_of_compo-1;i++)
152 oss << _pt[i] << ", ";
153 oss << _pt[_nb_of_compo-1] << ")";
157 float DataArrayFloatTuple::floatValue() const
159 return this->zeValue();
163 * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef.
164 * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false.
165 * 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
166 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
168 DataArrayFloat *DataArrayFloatTuple::buildDAFloat(std::size_t nbOfTuples, std::size_t nbOfCompo) const
170 return this->buildDA(nbOfTuples,nbOfCompo);