00001
#if !defined(__MEMORYSTORAGE_HPP)
00002
#define __MEMORYSTORAGE_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00055
00063
MemoryStorage(
MemoryIdentifierCref , IntCref , VoidPtr );
00064
00065
00066
00067
00068
00070
00071
bool operator==(
MemoryStorageCref )
const;
00072
00074
00075
operator MemoryIdentifierCref(
void )
const;
00076
00077
00078
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
00095
00096
if( Dword( ( BytePtr(theCurrentPointer) +
sizeof(T) ) -
00097 BytePtr(theBasePointer)) > Dword(theSize) )
00098 {
00099
throw BoundsException( LOCATION );
00100 }
00101
else
00102 {
00103 ;
00104 }
00105
00106
return ((T *)theCurrentPointer)[0];
00107 }
00108
00110
00111
template<
class T >
00112 operator T*(
void ) throw(
BoundsException )
00113 {
00114
00115
00116
if( Dword( ( BytePtr(theCurrentPointer) +
sizeof(T) ) -
00117 BytePtr(theBasePointer)) > Dword(theSize) )
00118 {
00119
throw BoundsException( LOCATION );
00120 }
00121
else
00122 {
00123 ;
00124 }
00125
00126
return ((T *)theCurrentPointer);
00127 }
00128
00129
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 ;
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
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 ;
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
00264
00265
00266
00267
00268
00269
00270
00271
00272