CoreLinux++  0.4.32
MemoryStorage.hpp
1 #if !defined(__MEMORYSTORAGE_HPP)
2 #define __MEMORYSTORAGE_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 1999,2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined(__COMMON_HPP)
25 #include <Common.hpp>
26 #endif
27 
28 #if !defined(__TRANSIENTSTORAGE_HPP)
29 #include <TransientStorage.hpp>
30 #endif
31 
32 #if !defined(__BOUNDSEXCEPTION_HPP)
33 #include <BoundsException.hpp>
34 #endif
35 
36 namespace corelinux
37 {
38  DECLARE_CLASS( MemoryStorage );
39 
48  {
49 
50  public:
51 
52 
53  //
54  // Constructors and destructor
55  //
63  MemoryStorage( MemoryIdentifierCref , IntCref , VoidPtr );
64 
65  //
66  // Operator overloads
67  //
68 
70 
71  bool operator==( MemoryStorageCref ) const;
72 
74 
75  operator MemoryIdentifierCref( void ) const;
76 
77  //
78  // Accessors
79  //
80 
82 
83  void operator+( Int ) throw( BoundsException );
84 
86 
87  void operator-( Int ) throw( BoundsException );
88 
90 
91  template< class T >
92  operator T( void ) throw( BoundsException )
93  {
94  // Bounds check first
95 
96  if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) -
97  BytePtr(theBasePointer)) > Dword(theSize) )
98  {
99  throw BoundsException( LOCATION );
100  }
101  else
102  {
103  ; // do nothing
104  }
105 
106  return ((T *)theCurrentPointer)[0];
107  }
108 
110 
111  template< class T >
112  operator T*( void ) throw( BoundsException )
113  {
114  // Bounds check first
115 
116  if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) -
117  BytePtr(theBasePointer)) > Dword(theSize) )
118  {
119  throw BoundsException( LOCATION );
120  }
121  else
122  {
123  ; // do nothing
124  }
125 
126  return ((T *)theCurrentPointer);
127  }
128  //
129  // Mutators
130  //
132 
133  template< class T >
134  T & operator=( T & aT ) throw( BoundsException )
135  {
136  if( Dword( ( BytePtr(theCurrentPointer) + sizeof(T) ) -
137  BytePtr(theBasePointer)) > Dword(theSize) )
138  {
139  throw BoundsException( LOCATION );
140  }
141  else
142  {
143  ; // do nothing
144  }
145 
146  GUARD;
147  std::memmove( theCurrentPointer, &aT, sizeof(T) );
148 
149  return aT;
150  }
151 
153 
154  MemoryStorageRef operator[]( Int offset )
155  throw( BoundsException );
156  //
157  // Traversal operations
158  //
159 
167  template < class Type, class Xexec >
168  void forEach( Xexec aExec ) throw ( Assertion )
169  {
170  REQUIRE( aExec != NULLPTR );
171 
172  GUARD;
173 
174  Type *pType( (Type *)theBasePointer );
175  Int maxCount( theSize / sizeof( Type ) );
176 
177  for( Int x = 0; x < maxCount; ++x, ++pType )
178  {
179  (*aExec)(pType);
180  }
181  }
182 
183 
191  template < class Type, class Xexec, class Test >
192  void forEach( Xexec aExec, Test aTest )
193  throw ( Assertion )
194  {
195  REQUIRE( aExec != NULLPTR );
196  REQUIRE( aTest != NULLPTR );
197 
198  GUARD;
199 
200  Type *pType( (Type *)theBasePointer );
201  Int maxCount( theSize / sizeof( Type ) );
202 
203  for( Int x = 0; x < maxCount; ++x, ++pType )
204  {
205  if( (*aTest)(pType) == true )
206  {
207  (*aExec)(pType);
208  }
209  else
210  {
211  ; // do nothing
212  }
213  }
214  }
215 
216 
217  protected:
218 
219 
220  friend class Memory;
221 
223 
224  MemoryStorage( void ) throw( Assertion );
225 
227 
229 
231 
232  virtual ~MemoryStorage( void );
233 
235 
237 
239 
240  VoidPtr getBasePointer( void );
241 
242  private:
243 
245 
246  MemoryIdentifier theIdentifier;
247 
249 
250  Int theSize;
251 
253 
254  VoidPtr theBasePointer;
255 
257 
258  VoidPtr theCurrentPointer;
259  };
260 
261 }
262 
263 #endif // if !defined(__MEMORYSTORAGE_HPP)
264 
265 /*
266  Common rcs information do not modify
267  $Author: frankc $
268  $Revision: 1.4 $
269  $Date: 2000/06/10 01:32:17 $
270  $Locker: $
271 */
272 
T & operator=(T &aT)
Data assignment.
Definition: MemoryStorage.hpp:134
MemoryStorage is type of Storage characterized as transient and high speed.
Definition: MemoryStorage.hpp:47
TransientStorage type is an area of storage that will not be saved across system initializations.
Definition: TransientStorage.hpp:41
MemoryStorage(void)
Default is never called.
Definition: MemoryStorage.cpp:33
bool operator==(MemoryStorageCref) const
Compares identifier.
Definition: MemoryStorage.cpp:95
void forEach(Xexec aExec)
forEach invokes the callers method to perform whatever operation they want on the type reference in t...
Definition: MemoryStorage.hpp:168
BoundsException is a type of StorageException, characterized when access to a storage object is inval...
Definition: BoundsException.hpp:42
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
ScalarIdentifier provides a templated interface for declaring CoreLinux Identifiers for simple scalar...
Definition: ScalarIdentifiers.hpp:37
MemoryStorageRef operator[](Int offset)
Subscript offset operator.
Definition: MemoryStorage.cpp:143
void operator-(Int)
Decrement current pointer.
Definition: MemoryStorage.cpp:126
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
void forEach(Xexec aExec, Test aTest)
forEach that invokes the callers method if the callers test method returns true
Definition: MemoryStorage.hpp:192
Memory is high speed transient storage managed by the operating system, for both itself and user proc...
Definition: Memory.hpp:100
void operator+(Int)
Increment current pointer.
Definition: MemoryStorage.cpp:109
VoidPtr getBasePointer(void)
Internal reference to base.
Definition: MemoryStorage.cpp:153
virtual ~MemoryStorage(void)
Virtual destructor.
Definition: MemoryStorage.cpp:78

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