Salome HOME
87f1bae2d0f9cedc715688efa98eadef054578db
[modules/med.git] / src / MEDCoupling / MEDCouplingSkyLineArray.cxx
1 // Copyright (C) 2007-2015  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 using namespace ParaMEDMEM;
23
24 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray():
25   _index( DataArrayInt::New() ), _value( DataArrayInt::New() )
26 {
27 }
28
29 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(const MEDCouplingSkyLineArray &myArray)
30 {
31   _index=myArray._index;
32   _value=myArray._value;
33 }
34
35 MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray()
36 {
37 }
38
39 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(DataArrayInt* index, DataArrayInt* value)
40 {
41   set( index, value );
42 }
43
44 MEDCouplingSkyLineArray::MEDCouplingSkyLineArray( const std::vector<int>& index,
45                                                   const std::vector<int>& value ):
46   _index( DataArrayInt::New() ), _value( DataArrayInt::New() )
47 {
48   _index->reserve( index.size() );
49   _index->insertAtTheEnd( index.begin(), index.end() );
50   _value->reserve( value.size() );
51   _value->insertAtTheEnd( value.begin(), value.end() );
52 }
53
54 void MEDCouplingSkyLineArray::set( DataArrayInt* index, DataArrayInt* value )
55 {
56   _index=index;
57   _value=value;
58   if ( (DataArrayInt*)_index ) _index->incrRef();
59   else                         _index = DataArrayInt::New();
60   if ( (DataArrayInt*)_value ) _value->incrRef();
61   else                         _value = DataArrayInt::New();
62 }
63
64 DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const
65 {
66   return ((MEDCouplingSkyLineArray*)this)->_index;
67 }
68
69 DataArrayInt* MEDCouplingSkyLineArray::getValueArray() const
70 {
71   return ((MEDCouplingSkyLineArray*)this)->_value;
72 }
73
74 std::string MEDCouplingSkyLineArray::simpleRepr() const
75 {
76   std::ostringstream oss;
77   oss << "MEDCouplingSkyLineArray" << std::endl;
78   oss << "   Nb of items: " << getNumberOf() << std::endl;
79   oss << "   Nb of values: " << getLength() << std::endl;
80   oss << "   Index:" << std::endl;
81   oss << "   ";
82   const int * i = _index->begin();
83   for ( ; i != _index->end(); ++i )
84     oss << *i << " ";
85   oss << std::endl;
86   oss << "   Value:" << std::endl;
87   oss << "   ";
88   const int * v = _value->begin();
89   int cnt = 0;
90   for ( i = _index->begin(); v != _value->end(); ++v, ++cnt )
91     {
92       if ( cnt == *i )
93         {
94           oss << "| ";
95           ++i;
96         }
97       oss << *v << " ";
98     }
99   oss << std::endl;
100
101   return oss.str();
102 }