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::reprStream(std::ostream& stream) const
43 stream << "Name of float array : \"" << _name << "\"\n";
44 reprWithoutNameStream(stream);
47 void DataArrayFloat::reprZipStream(std::ostream& stream) const
49 stream << "Name of float array : \"" << _name << "\"\n";
50 reprZipWithoutNameStream(stream);
53 void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const
55 DataArray::reprWithoutNameStream(stream);
57 _mem.repr(getNumberOfComponents(),stream);
60 void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
62 int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
63 const float *data(begin());
65 stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
66 if(nbTuples*nbComp>=1)
68 stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
69 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
70 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
71 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
74 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
75 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
78 void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
80 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
81 stream << "DataArrayFloat C++ instance at " << this << ". ";
84 int nbOfCompo=(int)_info_on_compo.size();
87 int nbOfTuples=getNumberOfTuples();
88 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
89 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
92 stream << "Number of components : 0.";
95 stream << "*** No data allocated ****";
98 void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
100 const float *data(begin());
101 int nbOfTuples(getNumberOfTuples());
102 int nbOfCompo=(int)_info_on_compo.size();
103 std::ostringstream oss2; oss2 << "[";
105 std::string oss2Str(oss2.str());
106 bool isFinished=true;
107 for(int i=0;i<nbOfTuples && isFinished;i++)
112 for(int j=0;j<nbOfCompo;j++,data++)
115 if(j!=nbOfCompo-1) oss2 << ", ";
121 if(i!=nbOfTuples-1) oss2 << ", ";
122 std::string oss3Str(oss2.str());
123 if(oss3Str.length()<maxNbOfByteInRepr)
134 std::string DataArrayFloat::reprNotTooLong() const
136 std::ostringstream ret;
137 reprNotTooLongStream(ret);
141 void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const
143 stream << "Name of float array : \"" << _name << "\"\n";
144 reprNotTooLongWithoutNameStream(stream);
147 void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const
149 DataArray::reprWithoutNameStream(stream);
151 _mem.reprNotTooLong(getNumberOfComponents(),stream);
154 bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
156 if(!areInfoEqualsIfNotWhy(other,reason))
158 return _mem.isEqual(other._mem,prec,reason);
161 bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
164 return isEqualIfNotWhy(other,prec,tmp);
167 bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
170 return _mem.isEqual(other._mem,prec,tmp);
174 * Returns either a \a deep or \a shallow copy of this array. For more info see
175 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
176 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
177 * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
178 * == \a true) or \a this instance (if \a dCpy == \a false).
180 DataArrayFloat *DataArrayFloat::performCopyOrIncrRef(bool dCpy) const
182 return DataArrayTemplateClassic<float>::PerformCopyOrIncrRef(dCpy,*this);
185 DataArrayFloatIterator *DataArrayFloat::iterator()
187 return new DataArrayFloatIterator(this);
190 DataArrayFloatIterator::DataArrayFloatIterator(DataArrayFloat *da):DataArrayIterator<float>(da)
194 DataArrayFloatTuple::DataArrayFloatTuple(float *pt, int nbOfComp):DataArrayTuple<float>(pt,nbOfComp)
198 std::string DataArrayFloatTuple::repr() const
200 std::ostringstream oss; oss.precision(7); oss << "(";
201 for(int i=0;i<_nb_of_compo-1;i++)
202 oss << _pt[i] << ", ";
203 oss << _pt[_nb_of_compo-1] << ")";
207 float DataArrayFloatTuple::floatValue() const
209 return this->zeValue();
213 * This method returns a newly allocated instance the caller should dealed with by a MEDCoupling::DataArrayFloat::decrRef.
214 * This method performs \b no copy of data. The content is only referenced using MEDCoupling::DataArrayFloat::useArray with ownership set to \b false.
215 * 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
216 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
218 DataArrayFloat *DataArrayFloatTuple::buildDAFloat(int nbOfTuples, int nbOfCompo) const
220 return this->buildDA(nbOfTuples,nbOfCompo);