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::DataArrayTemplateFP<float>;
29 DataArrayFloat *DataArrayFloat::New()
31 return new DataArrayFloat;
34 DataArrayFloat *DataArrayFloat::deepCopy() const
36 return new DataArrayFloat(*this);
39 void DataArrayFloat::reprStream(std::ostream& stream) const
41 stream << "Name of float array : \"" << _name << "\"\n";
42 reprWithoutNameStream(stream);
45 void DataArrayFloat::reprZipStream(std::ostream& stream) const
47 stream << "Name of float array : \"" << _name << "\"\n";
48 reprZipWithoutNameStream(stream);
51 void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const
53 DataArray::reprWithoutNameStream(stream);
55 _mem.repr(getNumberOfComponents(),stream);
58 void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
60 int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
61 const float *data(begin());
63 stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
64 if(nbTuples*nbComp>=1)
66 stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
67 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
68 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
69 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
72 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
73 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
76 void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
78 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
79 stream << "DataArrayFloat C++ instance at " << this << ". ";
82 int nbOfCompo=(int)_info_on_compo.size();
85 int nbOfTuples=getNumberOfTuples();
86 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
87 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
90 stream << "Number of components : 0.";
93 stream << "*** No data allocated ****";
96 void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
98 const float *data(begin());
99 int nbOfTuples(getNumberOfTuples());
100 int nbOfCompo=(int)_info_on_compo.size();
101 std::ostringstream oss2; oss2 << "[";
103 std::string oss2Str(oss2.str());
104 bool isFinished=true;
105 for(int i=0;i<nbOfTuples && isFinished;i++)
110 for(int j=0;j<nbOfCompo;j++,data++)
113 if(j!=nbOfCompo-1) oss2 << ", ";
119 if(i!=nbOfTuples-1) oss2 << ", ";
120 std::string oss3Str(oss2.str());
121 if(oss3Str.length()<maxNbOfByteInRepr)
132 std::string DataArrayFloat::reprNotTooLong() const
134 std::ostringstream ret;
135 reprNotTooLongStream(ret);
139 void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const
141 stream << "Name of float array : \"" << _name << "\"\n";
142 reprNotTooLongWithoutNameStream(stream);
145 void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const
147 DataArray::reprWithoutNameStream(stream);
149 _mem.reprNotTooLong(getNumberOfComponents(),stream);
152 bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
154 if(!areInfoEqualsIfNotWhy(other,reason))
156 return _mem.isEqual(other._mem,prec,reason);
159 bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
162 return isEqualIfNotWhy(other,prec,tmp);
165 bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
168 return _mem.isEqual(other._mem,prec,tmp);