xc
ID.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 ** OpenSees - Open System for Earthquake Engineering Simulation **
30 ** Pacific Earthquake Engineering Research Center **
31 ** **
32 ** **
33 ** (C) Copyright 1999, The Regents of the University of California **
34 ** All Rights Reserved. **
35 ** **
36 ** Commercial use of this program without express permission of the **
37 ** University of California, Berkeley, is strictly prohibited. See **
38 ** file 'COPYRIGHT' in main directory for information on usage and **
39 ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
40 ** **
41 ** Developed by: **
42 ** Frank McKenna (fmckenna@ce.berkeley.edu) **
43 ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
44 ** Filip C. Filippou (filippou@ce.berkeley.edu) **
45 ** **
46 ** ****************************************************************** */
47 
48 // $Revision: 1.10 $
49 // $Date: 2005/11/23 22:37:43 $
50 // $Source: /usr/local/cvs/OpenSees/SRC/utility/matrix/ID.h,v $
51 
52 
53 // Written: fmk
54 // Revision: A
55 //
56 // Description: This file contains the class definition for ID.
57 // ID is a concrete class implementing the integer array abstraction.
58 // ID objects are Vectors of integers which only need a few
59 // operators defined on them.
60 //
61 // What: "@(#) ID.h, revA"
62 
63 
64 #ifndef ID_h
65 #define ID_h
66 
67 #include "utility/kernel/CommandEntity.h"
68 #include <vector>
69 #include <set>
70 #include <boost/python/list.hpp>
71 
72 namespace XC {
76 //
78 //
95 class ID: public CommandEntity, public std::vector<int>
96  {
97  public:
98  typedef std::vector<int> v_int;
99  private:
100  static int ID_NOT_VALID_ENTRY;
101  public:
102  // constructors and destructor
103  ID(void);
104  explicit ID(const int &);
105  explicit ID(const v_int &);
106  ID(const boost::python::list &);
107  explicit ID(const std::set<int> &);
108  explicit ID(const std::initializer_list<int> &);
109  template <class InputIterator>
110  inline ID(InputIterator first, InputIterator last)
111  : CommandEntity(), std::vector<int>(first,last) {}
112  inline virtual ~ID(){}
113 
114  // utility methods
116  inline int Size(void) const
117  { return size(); }
118  void Zero(void);
120  inline const int *getDataPtr(void) const
121  { return this->data(); }
123  inline int *getDataPtr(void)
124  { return this->data(); }
126  inline bool isEmpty(void) const
127  { return empty(); }
128  int resize(const int &newSize, const int &fill_value= 0);
129  void fill(const int &fill_value);
130  const int &max(void) const;
131  const int &min(void) const;
132 
133  bool checkRange(const int &) const;
134  int &operator()(const int &);
135  const int &operator()(const int &) const;
138  inline int &operator[](const int &i)
139  { return this->at(i); }
142  inline const int &operator[](const int &i) const
143  { return this->at(i); }
144 
145 
146  int getLocation(const int &) const;
147  int getLocationOrdered(const int &) const; // for when insert was used to add elements
148  int removeValue(const int &);
149  void reverse(void);
150  ID getReversed(void) const;
151 
152 
153  boost::python::list getPyList(void) const;
154  void setPyList(const boost::python::list &);
155  boost::python::dict getPyDict(void) const;
156  void setPyDict(const boost::python::dict &);
157 
158  friend std::ostream &operator<<(std::ostream &, const ID &);
159  // friend istream &operator>>(istream &s, ID &V);
160 
161 
162  friend class UDP_Socket;
163  friend class TCP_Socket;
164  friend class TCP_SocketNoDelay;
165  friend class MPI_Channel;
166  };
167 
168 ID getIDFromIntPtr(const int *, const int &);
169 
170 std::ostream &operator<<(std::ostream &, const ID &);
171 
173 inline bool ID::checkRange(const int &i) const
174  {
175  const int sz= Size();
176  if((i < 0) || (i >= sz)) //Range checking.
177  {
178  std::cerr << "ID::(loc) - loc "
179  << i << " outside range 0 - " << sz-1 << std::endl;
180  return false;
181  }
182  else
183  return true;
184  }
185 
189 inline int &ID::operator()(const int &i)
190  {
191 #ifdef _G3DEBUG
192  // check if it is inside range [0,sz-1]
193  if(!checkRange(i))
194  return ID_NOT_VALID_ENTRY;
195 #endif
196  return (*this)[i];
197  }
198 
202 inline const int &ID::operator()(const int &i) const
203  {
204 #ifdef _G3DEBUG
205  // check if it is inside range [0,sz-1]
206  if(!checkRange(i))
207  return ID_NOT_VALID_ENTRY;
208 #endif
209 
210  return (*this)[i];
211  }
212 
213 } // end of XC namespace
214 
215 #endif
216 
217 
218 
bool isEmpty(void) const
Returns true if the vector is empty.
Definition: ID.h:126
boost::python::list getPyList(void) const
Return the vector values in a Python list.
Definition: ID.cpp:249
int & operator()(const int &)
Returns a reference to the element at position i in the container (does not range checking unless _G3...
Definition: ID.h:189
int resize(const int &newSize, const int &fill_value=0)
Changes the size of the array.
Definition: ID.cpp:195
Vector of integers.
Definition: ID.h:95
TCP_Socket is a sub-class of channel.
Definition: TCP_Socket.h:71
const int * getDataPtr(void) const
Returns a const pointer to the vector data.
Definition: ID.h:120
const int & min(void) const
Returns the minimum of vector components.
Definition: ID.cpp:224
TCP_SocketNoDelay is a sub-class of channel.
Definition: TCP_SocketNoDelay.h:73
int getLocationOrdered(const int &) const
Returns the position of the given vvalue in the vector assuming its values are ordered.
Definition: ID.cpp:136
int * getDataPtr(void)
Returns a const pointer to the vector data.
Definition: ID.h:123
Objet that can execute python scripts.
Definition: CommandEntity.h:40
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: ID.cpp:270
MPI_Channel is a sub-class of channel.
Definition: MPI_Channel.h:70
int getLocation(const int &) const
Returns the position of the given value in the vector.
Definition: ID.cpp:120
int removeValue(const int &)
Remove value from the array.
Definition: ID.cpp:168
void reverse(void)
Reverse sequence.
Definition: ID.cpp:183
void fill(const int &fill_value)
Fills the array with the argument.
Definition: ID.cpp:212
int & operator[](const int &i)
Returns a reference to the element at position i in the container (does range checking => slower than...
Definition: ID.h:138
const int & operator[](const int &i) const
Returns a reference to the element at position i in the container (does range checking => slower than...
Definition: ID.h:142
void Zero(void)
Zeros out the ID, i.e.
Definition: ID.cpp:113
bool checkRange(const int &) const
check if argument is inside range [0,sz-1]
Definition: ID.h:173
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: ID.cpp:278
ID getReversed(void) const
Return the reversed sequence.
Definition: ID.cpp:187
void setPyList(const boost::python::list &)
Populate the vector with the values of the given list.
Definition: ID.cpp:259
DP_Socket is a sub-class of channel.
Definition: UDP_Socket.h:76
const int & max(void) const
Returns the maximum of vector components.
Definition: ID.cpp:220
CommandEntity(CommandEntity *owr=nullptr)
Default constructor.
Definition: CommandEntity.cc:40
int Size(void) const
Returns the vector size.
Definition: ID.h:116
ID(void)
Default constructor, sets size = 0;.
Definition: ID.cpp:67