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>;
30 DataArrayFloat *DataArrayFloat::New()
32 return new DataArrayFloat;
35 DataArrayFloat *DataArrayFloat::deepCopy() const
37 return new DataArrayFloat(*this);
40 void DataArrayFloat::reprStream(std::ostream& stream) const
42 stream << "Name of float array : \"" << _name << "\"\n";
43 reprWithoutNameStream(stream);
46 void DataArrayFloat::reprZipStream(std::ostream& stream) const
48 stream << "Name of float array : \"" << _name << "\"\n";
49 reprZipWithoutNameStream(stream);
52 void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const
54 DataArray::reprWithoutNameStream(stream);
56 _mem.repr(getNumberOfComponents(),stream);
59 void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
61 int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
62 const float *data(begin());
64 stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
65 if(nbTuples*nbComp>=1)
67 stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
68 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
69 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
70 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
73 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
74 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
77 void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
79 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
80 stream << "DataArrayFloat C++ instance at " << this << ". ";
83 int nbOfCompo=(int)_info_on_compo.size();
86 int nbOfTuples=getNumberOfTuples();
87 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
88 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
91 stream << "Number of components : 0.";
94 stream << "*** No data allocated ****";
97 void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
99 const float *data(begin());
100 int nbOfTuples(getNumberOfTuples());
101 int nbOfCompo=(int)_info_on_compo.size();
102 std::ostringstream oss2; oss2 << "[";
104 std::string oss2Str(oss2.str());
105 bool isFinished=true;
106 for(int i=0;i<nbOfTuples && isFinished;i++)
111 for(int j=0;j<nbOfCompo;j++,data++)
114 if(j!=nbOfCompo-1) oss2 << ", ";
120 if(i!=nbOfTuples-1) oss2 << ", ";
121 std::string oss3Str(oss2.str());
122 if(oss3Str.length()<maxNbOfByteInRepr)
133 std::string DataArrayFloat::reprNotTooLong() const
135 std::ostringstream ret;
136 reprNotTooLongStream(ret);
140 void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const
142 stream << "Name of float array : \"" << _name << "\"\n";
143 reprNotTooLongWithoutNameStream(stream);
146 void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const
148 DataArray::reprWithoutNameStream(stream);
150 _mem.reprNotTooLong(getNumberOfComponents(),stream);
153 bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
155 if(!areInfoEqualsIfNotWhy(other,reason))
157 return _mem.isEqual(other._mem,prec,reason);
160 bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
163 return isEqualIfNotWhy(other,prec,tmp);
166 bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
169 return _mem.isEqual(other._mem,prec,tmp);
173 * Returns either a \a deep or \a shallow copy of this array. For more info see
174 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
175 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
176 * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
177 * == \a true) or \a this instance (if \a dCpy == \a false).
179 DataArrayFloat *DataArrayFloat::performCopyOrIncrRef(bool dCpy) const
181 return DataArrayTemplateClassic<float>::PerformCopyOrIncrRef(dCpy,*this);