XC Open source finite element analysis program
IntPtrWrapper.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 
28 #ifndef IntPtrWrapper_h
29 #define IntPtrWrapper_h
30 
31 #include "xc_utils/src/nucleo/EntCmd.h"
32 #include <boost/python/list.hpp>
33 
34 namespace XC {
36 //
37 class IntPtrWrapper: public EntCmd
38  {
39  private:
40  static int ID_NOT_VALID_ENTRY;
41  int sz;
42  int *data;
43  int fromFree;
44  void libera(void);
45  void check_sizes(void);
47  IntPtrWrapper &operator=(const IntPtrWrapper &V);
48  public:
49  // constructors and destructor
50  IntPtrWrapper(void);
51  IntPtrWrapper(int *data, int size, bool cleanIt= false);
52  virtual ~IntPtrWrapper();
53 
54  // utility methods
55  inline int Size(void) const
56  { return sz; }
57  void Zero(void);
58  inline const int *getDataPtr(void) const
59  { return data; }
60  inline int *getDataPtr(void)
61  { return data; }
62  bool Nulo(void) const;
63  const int &max(void) const;
64  const int &min(void) const;
65 
66  bool checkRange(const int &) const;
67  int &at(const int &);
68  const int &at(const int &) const;
69  int &operator()(const int &);
70  const int &operator()(const int &) const;
71  int &operator[](const int &i)
72  { return at(i); }
73  const int &operator[](const int &i) const
74  { return at(i); }
75 
76  int setData(int *newData, int size, bool cleanIt = false);
77  int getLocation(int value) const;
78  int getLocationOrdered(int value) const; // for when insert was used to add elements
79  int removeValue(int value);
80 
81  friend std::ostream &operator<<(std::ostream &, const IntPtrWrapper &);
82 
83 
84  friend class UDP_Socket;
85  friend class TCP_Socket;
86  friend class TCP_SocketNoDelay;
87  friend class MPI_Channel;
88  };
89 
90 std::ostream &operator<<(std::ostream &, const IntPtrWrapper &);
91 
92 std::vector<int> id_to_std_vector(const IntPtrWrapper &);
93 
94 inline bool IntPtrWrapper::Nulo(void) const
95  { return (data== nullptr); }
96 
98 inline bool IntPtrWrapper::checkRange(const int &i) const
99  {
100  if((i < 0) || (i >= sz)) //Range checking.
101  {
102  std::cerr << "IntPtrWrapper::(loc) - loc "
103  << i << " outside range 0 - " << sz-1 << std::endl;
104  return false;
105  }
106  else
107  return true;
108  }
109 
110 inline int &IntPtrWrapper::at(const int &i)
111  {
112  if(checkRange(i))
113  return data[i];
114  else
115  return ID_NOT_VALID_ENTRY;
116  }
117 
118 inline const int &IntPtrWrapper::at(const int &i) const
119  {
120  if(checkRange(i))
121  return data[i];
122  else
123  return ID_NOT_VALID_ENTRY;
124  }
125 
126 
127 inline int &IntPtrWrapper::operator()(const int &i)
128  {
129 #ifdef _G3DEBUG
130  // check if it is inside range [0,sz-1]
131  if(!checkRange(i))
132  return ID_NOT_VALID_ENTRY;
133 #endif
134  return data[i];
135  }
136 
137 inline const int &IntPtrWrapper::operator()(const int &i) const
138  {
139 #ifdef _G3DEBUG
140  // check if it is inside range [0,sz-1]
141  if(!checkRange(i))
142  return ID_NOT_VALID_ENTRY;
143 #endif
144 
145  return data[i];
146  }
147 
148 } // end of XC namespace
149 
150 #endif
151 
152 
153 
IntPtrWrapper(void)
Standard constructor, sets size = 0;.
Definition: IntPtrWrapper.cc:88
MPI_Channel is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP p...
Definition: MPI_Channel.h:69
const int & min(void) const
Returns the minimum of vector components.
Definition: IntPtrWrapper.cc:264
DP_Socket is a sub-class of channel. It is implemented with Berkeley datagram sockets using the UDP p...
Definition: UDP_Socket.h:76
TCP_Socket is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP pr...
Definition: TCP_Socket.h:71
const int & max(void) const
Returns the maximum of vector components.
Definition: IntPtrWrapper.cc:260
std::vector< int > id_to_std_vector(const IntPtrWrapper &)
Convierte el vector en un std::vector<double>.
Definition: IntPtrWrapper.cc:307
Definition: IntPtrWrapper.h:37
bool checkRange(const int &) const
check if argument is inside range [0,sz-1]
Definition: IntPtrWrapper.h:98
TCP_SocketNoDelay is a sub-class of channel. It is implemented with Berkeley stream sockets using the...
Definition: TCP_SocketNoDelay.h:72
================================================================================
Definition: ContinuaReprComponent.h:34