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