xc
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/kernel/CommandEntity.h"
32 #include <boost/python/list.hpp>
33 #include <vector>
34 
35 namespace XC {
37 //
38 class IntPtrWrapper: public CommandEntity
39  {
40  private:
41  static int ID_NOT_VALID_ENTRY;
42  int sz;
43  int *data;
44  int fromFree;
45  void free_mem(void);
46  void check_sizes(void);
48  IntPtrWrapper &operator=(const IntPtrWrapper &V);
49  public:
50  // constructors and destructor
51  IntPtrWrapper(void);
52  IntPtrWrapper(int *data, int size, bool cleanIt= false);
53  virtual ~IntPtrWrapper();
54 
55  // utility methods
56  inline int Size(void) const
57  { return sz; }
58  void Zero(void);
59  inline const int *getDataPtr(void) const
60  { return data; }
61  inline int *getDataPtr(void)
62  { return data; }
63  bool isEmpty(void) const;
64  const int &max(void) const;
65  const int &min(void) const;
66 
67  bool checkRange(const int &) const;
68  int &at(const int &);
69  const int &at(const int &) const;
70  int &operator()(const int &);
71  const int &operator()(const int &) const;
72  int &operator[](const int &i)
73  { return at(i); }
74  const int &operator[](const int &i) const
75  { return at(i); }
76 
77  int setData(int *newData, int size, bool cleanIt = false);
78  int getLocation(int value) const;
79  int getLocationOrdered(int value) const; // for when insert was used to add elements
80  int removeValue(int value);
81 
82  friend std::ostream &operator<<(std::ostream &, const IntPtrWrapper &);
83 
84 
85  friend class UDP_Socket;
86  friend class TCP_Socket;
87  friend class TCP_SocketNoDelay;
88  friend class MPI_Channel;
89  };
90 
91 std::ostream &operator<<(std::ostream &, const IntPtrWrapper &);
92 
93 std::vector<int> id_to_std_vector(const IntPtrWrapper &);
94 
95 inline bool IntPtrWrapper::isEmpty(void) const
96  { return (data== nullptr); }
97 
99 inline bool IntPtrWrapper::checkRange(const int &i) const
100  {
101  if((i < 0) || (i >= sz)) //Range checking.
102  {
103  std::cerr << "IntPtrWrapper::(loc) - loc "
104  << i << " outside range 0 - " << sz-1 << std::endl;
105  return false;
106  }
107  else
108  return true;
109  }
110 
111 inline int &IntPtrWrapper::at(const int &i)
112  {
113  if(checkRange(i))
114  return data[i];
115  else
116  return ID_NOT_VALID_ENTRY;
117  }
118 
119 inline const int &IntPtrWrapper::at(const int &i) const
120  {
121  if(checkRange(i))
122  return data[i];
123  else
124  return ID_NOT_VALID_ENTRY;
125  }
126 
127 
128 inline int &IntPtrWrapper::operator()(const int &i)
129  {
130 #ifdef _G3DEBUG
131  // check if it is inside range [0,sz-1]
132  if(!checkRange(i))
133  return ID_NOT_VALID_ENTRY;
134 #endif
135  return data[i];
136  }
137 
138 inline const int &IntPtrWrapper::operator()(const int &i) const
139  {
140 #ifdef _G3DEBUG
141  // check if it is inside range [0,sz-1]
142  if(!checkRange(i))
143  return ID_NOT_VALID_ENTRY;
144 #endif
145 
146  return data[i];
147  }
148 
149 } // end of XC namespace
150 
151 #endif
152 
153 
154 
const int & min(void) const
Returns the minimum of vector components.
Definition: IntPtrWrapper.cc:264
IntPtrWrapper(void)
Standard constructor, sets size = 0;.
Definition: IntPtrWrapper.cc:88
TCP_Socket is a sub-class of channel.
Definition: TCP_Socket.h:71
TCP_SocketNoDelay is a sub-class of channel.
Definition: TCP_SocketNoDelay.h:72
const int & max(void) const
Returns the maximum of vector components.
Definition: IntPtrWrapper.cc:260
bool checkRange(const int &) const
check if argument is inside range [0,sz-1]
Definition: IntPtrWrapper.h:99
MPI_Channel is a sub-class of channel.
Definition: MPI_Channel.h:69
std::vector< int > id_to_std_vector(const IntPtrWrapper &)
Convierte el vector en un std::vector<double>.
Definition: IntPtrWrapper.cc:307
Definition: IntPtrWrapper.h:38
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
DP_Socket is a sub-class of channel.
Definition: UDP_Socket.h:76