]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling/MEDCouplingSkyLineArray.cxx
Salome HOME
Small modif
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingSkyLineArray.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDCouplingSkyLineArray.hxx"
21
22 #include <sstream>
23
24 using namespace MEDCoupling;
25
26 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray():
27   _index( DataArrayInt::New() ), _value( DataArrayInt::New() )
28 {
29 }
30
31 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(const MEDCouplingSkyLineArray &myArray)
32 {
33   _index=myArray._index;
34   _value=myArray._value;
35 }
36
37 MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray()
38 {
39 }
40
41 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(DataArrayInt* index, DataArrayInt* value)
42 {
43   set( index, value );
44 }
45
46 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray( const std::vector<int>& index,
47                                                   const std::vector<int>& value ):
48   _index( DataArrayInt::New() ), _value( DataArrayInt::New() )
49 {
50   _index->reserve( index.size() );
51   _index->insertAtTheEnd( index.begin(), index.end() );
52   _value->reserve( value.size() );
53   _value->insertAtTheEnd( value.begin(), value.end() );
54 }
55
56 void MEDCouplingSkyLineArray::set( DataArrayInt* index, DataArrayInt* value )
57 {
58   _index=index;
59   _value=value;
60   if ( (DataArrayInt*)_index ) _index->incrRef();
61   else                         _index = DataArrayInt::New();
62   if ( (DataArrayInt*)_value ) _value->incrRef();
63   else                         _value = DataArrayInt::New();
64 }
65
66 DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const
67 {
68   return ((MEDCouplingSkyLineArray*)this)->_index;
69 }
70
71 DataArrayInt* MEDCouplingSkyLineArray::getValueArray() const
72 {
73   return ((MEDCouplingSkyLineArray*)this)->_value;
74 }
75
76 std::string MEDCouplingSkyLineArray::simpleRepr() const
77 {
78   std::ostringstream oss;
79   oss << "MEDCouplingSkyLineArray" << std::endl;
80   oss << "   Nb of items: " << getNumberOf() << std::endl;
81   oss << "   Nb of values: " << getLength() << std::endl;
82   oss << "   Index:" << std::endl;
83   oss << "   ";
84   const int * i = _index->begin();
85   for ( ; i != _index->end(); ++i )
86     oss << *i << " ";
87   oss << std::endl;
88   oss << "   Value:" << std::endl;
89   oss << "   ";
90   const int * v = _value->begin();
91   int cnt = 0;
92   for ( i = _index->begin(); v != _value->end(); ++v, ++cnt )
93     {
94       if ( cnt == *i )
95         {
96           oss << "| ";
97           ++i;
98         }
99       oss << *v << " ";
100     }
101   oss << std::endl;
102
103   return oss.str();
104 }