xc
ID.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 ** OpenSees - Open System for Earthquake Engineering Simulation **
29 ** Pacific Earthquake Engineering Research Center **
30 ** **
31 ** **
32 ** (C) Copyright 1999, The Regents of the University of California **
33 ** All Rights Reserved. **
34 ** **
35 ** Commercial use of this program without express permission of the **
36 ** University of California, Berkeley, is strictly prohibited. See **
37 ** file 'COPYRIGHT' in main directory for information on usage and **
38 ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
39 ** **
40 ** Developed by: **
41 ** Frank McKenna (fmckenna@ce.berkeley.edu) **
42 ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
43 ** Filip C. Filippou (filippou@ce.berkeley.edu) **
44 ** **
45 ** ****************************************************************** */
46 
47 // $Revision: 1.10 $
48 // $Date: 2005/11/23 22:37:43 $
49 // $Source: /usr/local/cvs/OpenSees/SRC/utility/matrix/ID.h,v $
50 
51 
52 // Written: fmk
53 // Revision: A
54 //
55 // Description: This file contains the class definition for ID.
56 // ID is a concrete class implementing the integer array abstraction.
57 // ID objects are Vectors of integers which only need a few
58 // operators defined on them.
59 //
60 // What: "@(#) ID.h, revA"
61 
62 
63 #ifndef ID_h
64 #define ID_h
65 
66 #include "xc_utils/src/kernel/CommandEntity.h"
67 #include <vector>
68 #include <boost/python/list.hpp>
69 
70 namespace XC {
74 //
76 //
93 class ID: public CommandEntity, public std::vector<int>
94  {
95  public:
96  typedef std::vector<int> v_int;
97  private:
98  static int ID_NOT_VALID_ENTRY;
99  public:
100  // constructors and destructor
101  ID(void);
102  explicit ID(const int &);
103  explicit ID(const v_int &);
104  ID(const boost::python::list &);
105  explicit ID(const std::set<int> &);
106  template <class InputIterator>
107  inline ID(InputIterator first, InputIterator last)
108  : CommandEntity(), std::vector<int>(first,last) {}
109  inline virtual ~ID(){}
110 
111  // utility methods
113  inline int Size(void) const
114  { return size(); }
115  void Zero(void);
117  inline const int *getDataPtr(void) const
118  { return &(*this)[0]; }
120  inline int *getDataPtr(void)
121  { return &(*this)[0]; }
123  inline bool isEmpty(void) const
124  { return empty(); }
125  int resize(const int &newSize, const int &defaultValue= 0);
126  const int &max(void) const;
127  const int &min(void) const;
128 
129  bool checkRange(const int &) const;
130  int &operator()(const int &);
131  const int &operator()(const int &) const;
134  inline int &operator[](const int &i)
135  { return this->at(i); }
138  inline const int &operator[](const int &i) const
139  { return this->at(i); }
140 
141 
142  int getLocation(const int &) const;
143  int getLocationOrdered(const int &) const; // for when insert was used to add elements
144  int removeValue(const int &);
145 
146  friend std::ostream &operator<<(std::ostream &, const ID &);
147  // friend istream &operator>>(istream &s, ID &V);
148 
149 
150  friend class UDP_Socket;
151  friend class TCP_Socket;
152  friend class TCP_SocketNoDelay;
153  friend class MPI_Channel;
154  };
155 
156 ID getIDFromIntPtr(const int *, const int &);
157 
158 std::ostream &operator<<(std::ostream &, const ID &);
159 
161 inline bool ID::checkRange(const int &i) const
162  {
163  const int sz= Size();
164  if((i < 0) || (i >= sz)) //Range checking.
165  {
166  std::cerr << "ID::(loc) - loc "
167  << i << " outside range 0 - " << sz-1 << std::endl;
168  return false;
169  }
170  else
171  return true;
172  }
173 
177 inline int &ID::operator()(const int &i)
178  {
179 #ifdef _G3DEBUG
180  // check if it is inside range [0,sz-1]
181  if(!checkRange(i))
182  return ID_NOT_VALID_ENTRY;
183 #endif
184  return (*this)[i];
185  }
186 
190 inline const int &ID::operator()(const int &i) const
191  {
192 #ifdef _G3DEBUG
193  // check if it is inside range [0,sz-1]
194  if(!checkRange(i))
195  return ID_NOT_VALID_ENTRY;
196 #endif
197 
198  return (*this)[i];
199  }
200 
201 } // end of XC namespace
202 
203 #endif
204 
205 
206 
bool isEmpty(void) const
Returns true if the vector is empty.
Definition: ID.h:123
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:177
Vector of integers.
Definition: ID.h:93
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:117
const int & min(void) const
Returns the minimum of vector components.
Definition: ID.cpp:196
TCP_SocketNoDelay is a sub-class of channel.
Definition: TCP_SocketNoDelay.h:72
int * getDataPtr(void)
Returns a const pointer to the vector data.
Definition: ID.h:120
MPI_Channel is a sub-class of channel.
Definition: MPI_Channel.h:69
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
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:134
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:138
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:161
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
const int & max(void) const
Returns the maximum of vector components.
Definition: ID.cpp:192
int Size(void) const
Returns the vector size.
Definition: ID.h:113
ID(void)
Default constructor, sets size = 0;.
Definition: ID.cpp:68