TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
RTabInt.cpp
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#include <RTabInt.h>
16
17
18Implemente_instanciable_sans_constructeur(RTabInt,"RTabInt",Objet_U);
19
20int RTabInt::TB_ = 1000;
21
22/*! @brief printOn
23 *
24 */
26{
27 os << data;
28 return os;
29}
30
31/*! @brief readOn
32 *
33 */
35{
36 is >> data;
37 size_r_ = data.size_array();
38 return is;
39}
40
41
42/*! @brief Constructor: initializes the array with n elements set to x, plus TB_ extra slots.
43 *
44 * @param (int n) initial number of elements
45 * @param (int x) initial value for each element
46 */
47RTabInt::RTabInt(int n, int x)
48{
49 data.resize_array(n+TB_);
50 int i;
51 int init=-1;
52 for(i=0; i<n; i++)
53 data[i] = x;
54 for(i=n; i<n+TB_; i++)
55 data[i] = init;
56 size_r_ = n;
57 min_data=init;
58 max_data=init;
59}
60
61/*! @brief Returns the underlying data array.
62 *
63 * @return (const ArrOfInt&) the data array
64 */
65const ArrOfInt& RTabInt::donnees() const
66{
67 return data;
68}
69
70/*! @brief Appends the value i at the end of the array; grows by TB_ slots if needed.
71 *
72 * @param (int i) value to append
73 */
74void RTabInt::add(int i)
75{
76 int sz = data.size_array();
77 if(size_r_ == sz)
78 {
79 data.resize_array(sz+TB_);
80 data[size_r_] = i;
81 size_r_++;
82 for(int j=size_r_; j< sz+TB_; j++)
83 data[j] = -1;
84 }
85 else
86 {
87 data[size_r_] = i;
88 size_r_++;
89 }
90 if (i<min_data)
91 min_data=i;
92 else if (i>max_data)
93 max_data=i;
94}
95
96/*! @brief Searches for an element equal to i in the array. Returns the value if found, -1 otherwise.
97 *
98 * @param (int i) value to search for
99 * @return (int) the value if found, -1 otherwise
100 */
102{
103 if (i<min_data || i>max_data)
104 return -1;
105 int cpt=0;
106 while((cpt<size_r_) && (data[cpt]!=i))
107 cpt++;
108 if(cpt==size_r_)
109 return -1;
110 else
111 return data[cpt];
112}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class RTabInt - Implements a resizable integer vector.
Definition RTabInt.h:28
const ArrOfInt & donnees() const
Returns the underlying data array.
Definition RTabInt.cpp:65
RTabInt(int n=0, int x=0)
Constructor: initializes the array with n elements set to x, plus TB_ extra slots.
Definition RTabInt.cpp:47
void add(int)
Appends the value i at the end of the array; grows by TB_ slots if needed.
Definition RTabInt.cpp:74
int search(int)
Searches for an element equal to i in the array. Returns the value if found, -1 otherwise.
Definition RTabInt.cpp:101
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const