Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Examples

MemoryStorage.hpp

00001 #if !defined(__MEMORYSTORAGE_HPP) 00002 #define __MEMORYSTORAGE_HPP 00003 00004 /* 00005 CoreLinux++ 00006 Copyright (C) 1999,2000 CoreLinux Consortium 00007 00008 The CoreLinux++ Library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public License as 00010 published by the Free Software Foundation; either version 2 of the 00011 License, or (at your option) any later version. 00012 00013 The CoreLinux++ Library Library is distributed in the hope that it will 00014 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public 00019 License along with the GNU C Library; see the file COPYING.LIB. If not, 00020 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #if !defined(__COMMON_HPP) 00025 #include <Common.hpp> 00026 #endif 00027 00028 #if !defined(__TRANSIENTSTORAGE_HPP) 00029 #include <TransientStorage.hpp> 00030 #endif 00031 00032 #if !defined(__BOUNDSEXCEPTION_HPP) 00033 #include <BoundsException.hpp> 00034 #endif 00035 00036 namespace corelinux 00037 { 00038 DECLARE_CLASS( MemoryStorage ); 00039 00047 class MemoryStorage : public TransientStorage, Synchronized 00048 { 00049 00050 public: 00051 00052 00053 // 00054 // Constructors and destructor 00055 // 00063 MemoryStorage( MemoryIdentifierCref , IntCref , VoidPtr ); 00064 00065 // 00066 // Operator overloads 00067 // 00068 00070 00071 bool operator==( MemoryStorageCref ) const; 00072 00074 00075 operator MemoryIdentifierCref( void ) const; 00076 00077 // 00078 // Accessors 00079 // 00080 00082 00083 void operator+( Int ) throw( BoundsException ); 00084 00086 00087 void operator-( Int ) throw( BoundsException ); 00088 00090 00091 template< class T > 00092 operator T( void ) throw( BoundsException ) 00093 { 00094 // Bounds check first 00095 00096 if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) - 00097 BytePtr(theBasePointer)) > Dword(theSize) ) 00098 { 00099 throw BoundsException( LOCATION ); 00100 } 00101 else 00102 { 00103 ; // do nothing 00104 } 00105 00106 return ((T *)theCurrentPointer)[0]; 00107 } 00108 00110 00111 template< class T > 00112 operator T*( void ) throw( BoundsException ) 00113 { 00114 // Bounds check first 00115 00116 if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) - 00117 BytePtr(theBasePointer)) > Dword(theSize) ) 00118 { 00119 throw BoundsException( LOCATION ); 00120 } 00121 else 00122 { 00123 ; // do nothing 00124 } 00125 00126 return ((T *)theCurrentPointer); 00127 } 00128 // 00129 // Mutators 00130 // 00132 00133 template< class T > 00134 T & operator=( T & aT ) throw( BoundsException ) 00135 { 00136 if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) - 00137 BytePtr(theBasePointer)) > Dword(theSize) ) 00138 { 00139 throw BoundsException( LOCATION ); 00140 } 00141 else 00142 { 00143 ; // do nothing 00144 } 00145 00146 GUARD; 00147 std::memmove( theCurrentPointer, &aT, sizeof(T) ); 00148 00149 return aT; 00150 } 00151 00153 00154 MemoryStorageRef operator[]( Int offset ) 00155 throw( BoundsException ); 00156 // 00157 // Traversal operations 00158 // 00159 00167 template < class Type, class Xexec > 00168 void forEach( Xexec aExec ) throw ( Assertion ) 00169 { 00170 REQUIRE( aExec != NULLPTR ); 00171 00172 GUARD; 00173 00174 Type *pType( (Type *)theBasePointer ); 00175 Int maxCount( theSize / sizeof( Type ) ); 00176 00177 for( Int x = 0; x < maxCount; ++x, ++pType ) 00178 { 00179 (*aExec)(pType); 00180 } 00181 } 00182 00183 00191 template < class Type, class Xexec, class Test > 00192 void forEach( Xexec aExec, Test aTest ) 00193 throw ( Assertion ) 00194 { 00195 REQUIRE( aExec != NULLPTR ); 00196 REQUIRE( aTest != NULLPTR ); 00197 00198 GUARD; 00199 00200 Type *pType( (Type *)theBasePointer ); 00201 Int maxCount( theSize / sizeof( Type ) ); 00202 00203 for( Int x = 0; x < maxCount; ++x, ++pType ) 00204 { 00205 if( (*aTest)(pType) == true ) 00206 { 00207 (*aExec)(pType); 00208 } 00209 else 00210 { 00211 ; // do nothing 00212 } 00213 } 00214 } 00215 00216 00217 protected: 00218 00219 00220 friend class Memory; 00221 00223 00224 MemoryStorage( void ) throw( Assertion ); 00225 00227 00228 MemoryStorage( MemoryStorageCref ); 00229 00231 00232 virtual ~MemoryStorage( void ); 00233 00235 00236 MemoryStorageRef operator=( MemoryStorageCref ); 00237 00239 00240 VoidPtr getBasePointer( void ); 00241 00242 private: 00243 00245 00246 MemoryIdentifier theIdentifier; 00247 00249 00250 Int theSize; 00251 00253 00254 VoidPtr theBasePointer; 00255 00257 00258 VoidPtr theCurrentPointer; 00259 }; 00260 00261 } 00262 00263 #endif // if !defined(__MEMORYSTORAGE_HPP) 00264 00265 /* 00266 Common rcs information do not modify 00267 $Author: frankc $ 00268 $Revision: 1.4 $ 00269 $Date: 2000/06/10 01:32:17 $ 00270 $Locker: $ 00271 */ 00272

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium