XC Open source finite element analysis program
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/nucleo/EntCmd.h"
67 #include <vector>
68 #include <boost/python/list.hpp>
69 
70 namespace XC {
72 //
74 //
76 //
77 class ID: public EntCmd, public std::vector<int>
78  {
79  public:
80  typedef std::vector<int> v_int;
81  private:
82  static int ID_NOT_VALID_ENTRY;
83  public:
84  // constructors and destructor
85  ID(void);
86  explicit ID(const int &);
87  explicit ID(const v_int &);
88  ID(const boost::python::list &);
89  explicit ID(const std::set<int> &);
90  template <class InputIterator>
91  inline ID(InputIterator first, InputIterator last)
92  : EntCmd(), std::vector<int>(first,last) {}
93  inline virtual ~ID(){}
94 
95  // utility methods
96  inline int Size(void) const
97  { return size(); }
98  void Zero(void);
99  inline const int *getDataPtr(void) const
100  { return &(*this)[0]; }
101  inline int *getDataPtr(void)
102  { return &(*this)[0]; }
103  inline bool Nulo(void) const
104  { return empty(); }
105  int resize(const int &newSize);
106  const int &max(void) const;
107  const int &min(void) const;
108 
109  bool checkRange(const int &) const;
110  int &operator()(const int &);
111  const int &operator()(const int &) const;
112  inline int &operator[](const int &i)
113  { return this->at(i); }
114  inline const int &operator[](const int &i) const
115  { return this->at(i); }
116 
117 
118  int getLocation(const int &) const;
119  int getLocationOrdered(const int &) const; // for when insert was used to add elements
120  int removeValue(const int &);
121 
122  friend std::ostream &operator<<(std::ostream &, const ID &);
123  // friend istream &operator>>(istream &s, ID &V);
124 
125 
126  friend class UDP_Socket;
127  friend class TCP_Socket;
128  friend class TCP_SocketNoDelay;
129  friend class MPI_Channel;
130  };
131 
132 ID getIDFromIntPtr(const int *, const int &);
133 
134 std::ostream &operator<<(std::ostream &, const ID &);
135 
137 inline bool ID::checkRange(const int &i) const
138  {
139  const int sz= Size();
140  if((i < 0) || (i >= sz)) //Range checking.
141  {
142  std::cerr << "ID::(loc) - loc "
143  << i << " outside range 0 - " << sz-1 << std::endl;
144  return false;
145  }
146  else
147  return true;
148  }
149 
150 inline int &ID::operator()(const int &i)
151  {
152 #ifdef _G3DEBUG
153  // check if it is inside range [0,sz-1]
154  if(!checkRange(i))
155  return ID_NOT_VALID_ENTRY;
156 #endif
157  return (*this)[i];
158  }
159 
160 inline const int &ID::operator()(const int &i) const
161  {
162 #ifdef _G3DEBUG
163  // check if it is inside range [0,sz-1]
164  if(!checkRange(i))
165  return ID_NOT_VALID_ENTRY;
166 #endif
167 
168  return (*this)[i];
169  }
170 
171 } // end of XC namespace
172 
173 #endif
174 
175 
176 
bool checkRange(const int &) const
check if argument is inside range [0,sz-1]
Definition: ID.h:137
const int & min(void) const
Returns the minimum of vector components.
Definition: ID.cpp:174
int getLocation(const int &) const
Returns the position of &#39;value&#39; in the vector.
Definition: ID.cpp:106
MPI_Channel is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP p...
Definition: MPI_Channel.h:69
const int & max(void) const
Returns the maximum of vector components.
Definition: ID.cpp:170
DP_Socket is a sub-class of channel. It is implemented with Berkeley datagram sockets using the UDP p...
Definition: UDP_Socket.h:76
TCP_Socket is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP pr...
Definition: TCP_Socket.h:71
ID(void)
Standard constructor, sets size = 0;.
Definition: ID.cpp:68
Definition: ID.h:77
TCP_SocketNoDelay is a sub-class of channel. It is implemented with Berkeley stream sockets using the...
Definition: TCP_SocketNoDelay.h:72
================================================================================
Definition: ContinuaReprComponent.h:34