00001 00002 // 00003 // Title : Array.h 00004 // Project : OSCAR Version 2.0 00005 // Created : 00006 // Author : Chetan Kapoor 00007 // Platforms : All 00008 // Copyright : Copyright) The University of Texas at Austin, 2002. All rights reserved. 00009 // 00010 // This software and documentation constitute an unpublished work 00011 // and contain valuable trade secrets and proprietary information 00012 // belonging to the University. None of the foregoing material may be 00013 // copied or duplicated or disclosed without the express, written 00014 // permission of University. THE UNIVERSITY EXPRESSLY DISCLAIMS ANY 00015 // AND ALL WARRANTIES CONCERNING THIS SOFTWARE AND DOCUMENTATION, 00016 // INCLUDING ANY WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 00017 // PARTICULAR PURPOSE, AND WARRANTIES OF PERFORMANCE, AND ANY WARRANTY 00018 // THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE. 00019 // NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF 00020 // THE SOFTWARE OR DOCUMENTATION. Under no circumstances shall the 00021 // University be liable for incidental, special, indirect, direct or 00022 // consequential damages or loss of profits, interruption of business, 00023 // or related expenses which may arise from use of software or documentation, 00024 // including but not limited to those resulting from defects in software 00025 // and/or documentation, or loss or inaccuracy of data of any kind. 00026 // 00027 // Purpose : Class Definition for parametrized array class. 00028 // 00029 //----------------------------------------------------------------------------- 00030 // 00031 // $Revisions$ 00032 // Added a copy method that works like operator equal but returns a bool so errors 00033 // can be passed. Mark Tisius 3/14/03 00034 // 00035 // $Log: Array.h,v $ 00036 // Revision 1.10 2005/03/14 22:04:12 pmarch 00037 // Added to namespace OSCAR and removed "RR" from front of class names. 00038 // 00039 // Revision 1.9 2004/07/29 20:16:45 chetan 00040 // Minor changes to compile under g++ with -Wall and -pedantic warning flags enabled 00041 // 00042 // Revision 1.8 2004/07/26 22:25:16 chetan 00043 // Made changes to compile with Warning Level 4 and also under the latest C++ standard. Also made compilable with VC extensions turned off 00044 // 00045 // Revision 1.7 2004/06/04 21:58:35 chetan 00046 // using namespace std in CommIncludes.h was removed. std:: was added anywhere STL components such as iostream and vector were being used 00047 // 00048 // Revision 1.6 2004/05/26 20:02:03 pmarch 00049 // Added /defgroup and /ingroup tags. 00050 // 00051 // Revision 1.5 2003/09/09 17:13:15 eswint 00052 // - Changed #include "Math/..." to #include "..." 00053 // 00054 // Revision 1.4 2003/09/04 22:46:31 eswint 00055 // - Added non-const GetArray method for speedy data read/write access 00056 // 00057 // Revision 1.3 2003/08/25 16:54:47 eswint 00058 // - Made construction from Type[] explicit 00059 // 00060 // Revision 1.2 2003/08/18 15:49:02 eswint 00061 // Changed the .at method for array to maintain const-ness: one version for non-const array object, another for const object. Compiler determines which method to use. 00062 // 00063 // Revision 1.1 2003/08/18 15:23:44 eswint 00064 // Initial Commit 00065 // 00066 // 00067 // Notes 00068 // Source Code adapted from 'C++ Primer by Lippman, Second Edition' 00069 // 00071 #ifndef Array_hpp 00072 #define Array_hpp 00073 00074 #include "Base/Base.h" 00075 00077 namespace OSCAR { 00078 00087 template <class Type> 00088 class Array 00089 { 00090 public: 00091 00102 explicit Array(unsigned int sz, const Type* array = 0); 00103 00111 Array(const Array<Type>& rhs); 00112 00118 virtual ~Array(void); 00119 00129 Array<Type>& operator=(const Array<Type>& rhs); 00130 00131 00143 bool Copy(const Array<Type>& arrayToCopy); 00144 00145 00152 unsigned int GetSize() const; 00153 00161 bool Grow(unsigned int growth); 00162 00163 00172 bool Output(std::ostream& out) const; 00173 00182 bool Input(std::istream& in); 00183 00192 Type& at(unsigned int index); 00193 00202 const Type& at(unsigned int index) const; 00203 00214 Type& operator[](unsigned int index); 00215 00226 const Type& operator[](unsigned int index) const; 00227 00234 const Type* GetArray() const; 00235 00242 Type* GetArray(); 00243 00244 protected: 00245 00246 unsigned int size; //size of the array 00247 00248 Type *element; //pointer to a Type object 00249 00259 void init(unsigned int size, const Type* array = 0); 00260 00267 Array(); 00268 00269 }; //End of Array definition 00270 00280 template <class Type> 00281 extern std::ostream& operator<<(std::ostream& os, const Array<Type>& a); 00282 00292 template <class Type> 00293 extern std::istream& operator>>(std::istream& is, Array<Type>& a); 00294 00304 std::istream& operator>>(std::istream& is, bool& b); 00305 00306 #include "Array.ipp" 00307 } 00308 00309 #endif // #ifndef Array_hpp
| RRG Homepage | OSCAR Overview | OSCAR Tutorials | Simulations |