Salome HOME
d525524f1a73363ff8bac89ae193804392523d6f
[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() ), _values( DataArrayInt::New() ), _sub_values( DataArrayInt::New() )
28 {
29 }
30
31 MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray()
32 {
33 }
34
35 MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New()
36 {
37   return new MEDCouplingSkyLineArray();
38 }
39
40 MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New( const std::vector<int>& index,
41                                                        const std::vector<int>& value )
42 {
43   MEDCouplingSkyLineArray * ret = new MEDCouplingSkyLineArray();
44   ret->_index->reserve( index.size() );
45   ret->_index->insertAtTheEnd( index.begin(), index.end() );
46   ret->_values->reserve( value.size() );
47   ret->_values->insertAtTheEnd( value.begin(), value.end() );
48   return ret;
49 }
50
51 MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New( DataArrayInt* index, DataArrayInt* value )
52 {
53   MEDCouplingSkyLineArray* ret = new MEDCouplingSkyLineArray();
54   ret->set(index, value);
55   return ret;
56 }
57
58
59 std::size_t MEDCouplingSkyLineArray::getHeapMemorySizeWithoutChildren() const
60 {
61   return _index->getHeapMemorySizeWithoutChildren()+_values->getHeapMemorySizeWithoutChildren()+_sub_values->getHeapMemorySizeWithoutChildren();
62 }
63
64 std::vector<const BigMemoryObject *> MEDCouplingSkyLineArray::getDirectChildrenWithNull() const
65 {
66   std::vector<const BigMemoryObject *> ret;
67   ret.push_back(_index);
68   ret.push_back(_values);
69   ret.push_back(_sub_values);
70   return ret;
71 }
72
73
74 void MEDCouplingSkyLineArray::set( DataArrayInt* index, DataArrayInt* value )
75 {
76   _index=index;
77   _values=value;
78   if ( (DataArrayInt*)_index ) _index->incrRef();
79   else                         _index = DataArrayInt::New();
80   if ( (DataArrayInt*)_values ) _values->incrRef();
81   else                         _values = DataArrayInt::New();
82 }
83
84 DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const
85 {
86   return ((MEDCouplingSkyLineArray*)this)->_index;
87 }
88
89 DataArrayInt* MEDCouplingSkyLineArray::getValuesArray() const
90 {
91   return ((MEDCouplingSkyLineArray*)this)->_values;
92 }
93
94 std::string MEDCouplingSkyLineArray::simpleRepr() const
95 {
96   std::ostringstream oss;
97   oss << "MEDCouplingSkyLineArray" << std::endl;
98   oss << "   Nb of items: " << getNumberOf() << std::endl;
99   oss << "   Nb of values: " << getLength() << std::endl;
100   oss << "   Index:" << std::endl;
101   oss << "   ";
102   const int * i = _index->begin();
103   for ( ; i != _index->end(); ++i )
104     oss << *i << " ";
105   oss << std::endl;
106   oss << "   Value:" << std::endl;
107   oss << "   ";
108   const int * v = _values->begin();
109   int cnt = 0;
110   for ( i = _index->begin(); v != _values->end(); ++v, ++cnt )
111     {
112       if ( cnt == *i )
113         {
114           oss << "| ";
115           ++i;
116         }
117       oss << *v << " ";
118     }
119   oss << std::endl;
120
121   return oss.str();
122 }