TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
RTabInt.h
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
16#ifndef RTabInt_included
17#define RTabInt_included
18
19
20#include <TRUSTArray.h>
21
22
23/*! @brief class RTabInt - Implements a resizable integer vector.
24 *
25 */
26
27class RTabInt : public Objet_U
28{
29
30 Declare_instanciable_sans_constructeur(RTabInt);
31
32
33public:
34
35 // Constructor and destructor
36 RTabInt(int n=0, int x=0);
37
38 // Size queries
39 inline int size() const;
40
41 inline void resize(int);
42 int search(int);
43 void add(int);
44 inline int& operator[](int i);
45 inline const int& operator[](int i) const ;
46 inline int& operator()(int i);
47 inline const int& operator()(int i) const ;
48
49 const ArrOfInt& donnees() const;
50
51private:
52 static int TB_;
53 int size_r_;
54 ArrOfInt data;
55 int min_data;
56 int max_data;
57
58};
59/*! @brief Returns the number of elements in the array.
60 *
61 * @return (int) number of elements
62 */
63inline int RTabInt::size() const
64{
65 return size_r_;
66}
67
68/*! @brief Resizes the array to hold at least n elements, growing by TB_ slots if needed.
69 *
70 * @param (int n) new minimum size
71 */
72inline void RTabInt::resize(int n)
73{
74 if(n>data.size_array())
75 {
76 int sz = data.size_array();
77 data.resize_array(n);
78 data.resize_array(sz+TB_);
79 for(int j=sz; j< sz+TB_; j++)
80 data[j] = -1;
81 }
82}
83
84
85/*! @brief Returns a reference to the element at index i.
86 *
87 * @param (int i) index
88 * @return (int&) reference to element
89 */
90inline int& RTabInt::operator[](int i)
91{
92 return data[i];
93}
94inline const int& RTabInt::operator[](int i) const
95{
96 return data[i];
97}
98
99/*! @brief Same as operator[]: returns a reference to the element at index i.
100 *
101 * @param (int i) index
102 * @return (int&) reference to element
103 */
104inline int& RTabInt::operator()(int i)
105{
106 return data[i];
107}
108inline const int& RTabInt::operator()(int i) const
109{
110 return data[i];
111}
112
113#endif//RTABINT
114
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
int size() const
Returns the number of elements in the array.
Definition RTabInt.h:63
void resize(int)
Resizes the array to hold at least n elements, growing by TB_ slots if needed.
Definition RTabInt.h:72
const ArrOfInt & donnees() const
Returns the underlying data array.
Definition RTabInt.cpp:65
int & operator()(int i)
Same as operator[]: returns a reference to the element at index i.
Definition RTabInt.h:104
int & operator[](int i)
Returns a reference to the element at index i.
Definition RTabInt.h:90
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