ID.h

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.10 $
00022 // $Date: 2005/11/23 22:37:43 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/matrix/ID.h,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 
00027 // Revision: A
00028 //
00029 // Description: This file contains the class definition for ID.
00030 // ID is a concrete class implementing the integer array abstraction.
00031 // ID objects are Vectors of integers which only need a few
00032 // operators defined on them.
00033 //
00034 // What: "@(#) ID.h, revA"
00035 
00036 
00037 #ifndef ID_h
00038 #define ID_h
00039 
00040 #include <OPS_Globals.h>
00041 
00042 class ID
00043 {
00044   public:
00045     // constructors and destructor
00046     ID();
00047     ID(int);
00048     ID(int size, int arraySize);
00049     ID(int *data, int size, bool cleanIt = false);
00050     ID(const ID &);    
00051     ~ID();
00052  
00053     // utility methods
00054     int Size(void) const;
00055     void Zero(void);
00056     int setData(int *newData, int size, bool cleanIt = false);
00057     int resize(int newSize);
00058     
00059     // overloaded operators
00060     inline int &operator()(int x);
00061     inline int operator()(int x) const;
00062     int &operator[](int);           
00063     
00064     ID &operator=(const ID  &V);
00065 
00066     int insert(int value);  // differs from using [] in that inserted in order
00067     int getLocation(int value) const;
00068     int getLocationOrdered(int value) const; // for when insert was used to add elements
00069     int removeValue(int value);
00070 
00071     friend OPS_Stream &operator<<(OPS_Stream &s, const ID &V);
00072     //    friend istream &operator>>(istream &s, ID &V);    
00073 
00074     friend class UDP_Socket;
00075     friend class TCP_Socket;
00076     friend class TCP_SocketNoDelay;
00077     friend class MPI_Channel;
00078     friend class MySqlDatastore;
00079     friend class BerkeleyDbDatastore;
00080     
00081   private:
00082     static int ID_NOT_VALID_ENTRY;
00083     int sz;
00084     int *data;
00085     int arraySize;
00086     int fromFree;
00087 };
00088 
00089 
00090 inline int 
00091 ID::Size(void) const {return sz;}
00092 
00093 inline int &
00094 ID::operator()(int x) 
00095 {
00096 #ifdef _G3DEBUG
00097   // check if it is inside range [0,sz-1]
00098   if (x < 0 || x >= sz) {
00099     opserr << "ID::(loc) - loc " << x << " outside range 0 - " <<  sz-1 << endln;
00100     return ID_NOT_VALID_ENTRY;
00101   }
00102 #endif
00103 
00104   
00105   return data[x];
00106 }
00107 
00108 inline int
00109 ID::operator()(int x) const 
00110 {
00111 #ifdef _G3DEBUG
00112   // check if it is inside range [0,sz-1]
00113   if (x < 0 || x >= sz) {
00114     opserr << "ID::(loc) - loc " << x << " outside range 0 - " <<  sz-1 << endln;
00115     return ID_NOT_VALID_ENTRY;
00116   }
00117 #endif
00118 
00119   return data[x];
00120 }
00121 
00122 #endif
00123 
00124 

Generated on Mon Oct 23 15:05:23 2006 for OpenSees by doxygen 1.5.0