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  template <class InputIterator>
109  inline ID(InputIterator first, InputIterator last)
110  : CommandEntity(), std::vector<int>(first,last) {}
111  inline virtual ~ID(){}
112 
113  // utility methods
115  inline int Size(void) const
116  { return size(); }
117  void Zero(void);
119  inline const int *getDataPtr(void) const
120  { return &(*this)[0]; }
122  inline int *getDataPtr(void)
123  { return &(*this)[0]; }
125  inline bool isEmpty(void) const
126  { return empty(); }
127  int resize(const int &newSize, const int &fill_value= 0);
128  void fill(const int &fill_value);
129  const int &max(void) const;
130  const int &min(void) const;
131 
132  bool checkRange(const int &) const;
133  int &operator()(const int &);
134  const int &operator()(const int &) const;
137  inline int &operator[](const int &i)
138  { return this->at(i); }
141  inline const int &operator[](const int &i) const
142  { return this->at(i); }
143 
144 
145  int getLocation(const int &) const;
146  int getLocationOrdered(const int &) const; // for when insert was used to add elements
147  int removeValue(const int &);
148  void reverse(void);
149  ID getReversed(void) const;
150 
151 
152  boost::python::list getPyList(void) const;
153  void setPyList(const boost::python::list &);
154  boost::python::dict getPyDict(void) const;
155  void setPyDict(const boost::python::dict &);
156 
157  friend std::ostream &operator<<(std::ostream &, const ID &);
158  // friend istream &operator>>(istream &s, ID &V);
159 
160 
161  friend class UDP_Socket;
162  friend class TCP_Socket;
163  friend class TCP_SocketNoDelay;
164  friend class MPI_Channel;
165  };
166 
167 ID getIDFromIntPtr(const int *, const int &);
168 
169 std::ostream &operator<<(std::ostream &, const ID &);
170 
172 inline bool ID::checkRange(const int &i) const
173  {
174  const int sz= Size();
175  if((i < 0) || (i >= sz)) //Range checking.
176  {
177  std::cerr << "ID::(loc) - loc "
178  << i << " outside range 0 - " << sz-1 << std::endl;
179  return false;
180  }
181  else
182  return true;
183  }
184 
188 inline int &ID::operator()(const int &i)
189  {
190 #ifdef _G3DEBUG
191  // check if it is inside range [0,sz-1]
192  if(!checkRange(i))
193  return ID_NOT_VALID_ENTRY;
194 #endif
195  return (*this)[i];
196  }
197 
201 inline const int &ID::operator()(const int &i) const
202  {
203 #ifdef _G3DEBUG
204  // check if it is inside range [0,sz-1]
205  if(!checkRange(i))
206  return ID_NOT_VALID_ENTRY;
207 #endif
208 
209  return (*this)[i];
210  }
211 
212 } // end of XC namespace
213 
214 #endif
215 
216 
217 
bool isEmpty(void) const
Returns true if the vector is empty.
Definition: ID.h:125
boost::python::list getPyList(void) const
Return the vector values in a Python list.
Definition: ID.cpp:241
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:188
int resize(const int &newSize, const int &fill_value=0)
Changes the size of the array.
Definition: ID.cpp:187
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:119
const int & min(void) const
Returns the minimum of vector components.
Definition: ID.cpp:216
TCP_SocketNoDelay is a sub-class of channel.
Definition: TCP_SocketNoDelay.h:73
int * getDataPtr(void)
Returns a const pointer to the vector data.
Definition: ID.h:122
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:262
MPI_Channel is a sub-class of channel.
Definition: MPI_Channel.h:70
int getLocation(const int &) const
Returns the position of &#39;value&#39; in the vector.
Definition: ID.cpp:116
int removeValue(const int &)
Remove value from the array.
Definition: ID.cpp:160
void reverse(void)
Reverse sequence.
Definition: ID.cpp:175
void fill(const int &fill_value)
Fills the array with the argument.
Definition: ID.cpp:204
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:137
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:141
void Zero(void)
Zeros out the ID, i.e.
Definition: ID.cpp:109
bool checkRange(const int &) const
check if argument is inside range [0,sz-1]
Definition: ID.h:172
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:270
ID getReversed(void) const
Return the reversed sequence.
Definition: ID.cpp:179
void setPyList(const boost::python::list &)
Populate the vector with the values of the given list.
Definition: ID.cpp:251
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:212
CommandEntity(CommandEntity *owr=nullptr)
Default constructor.
Definition: CommandEntity.cc:40
int Size(void) const
Returns the vector size.
Definition: ID.h:115
ID(void)
Default constructor, sets size = 0;.
Definition: ID.cpp:68