class MemoryCell
1: //MemoryCell.hpp
2: //Specification *and* implementation file for the MemoryCell class.
3:
4: //A class for simulating a memory cell, which stored a single copy
5: //of the value of an object of type ObjectType.
6: template<typename ObjectType>
7: class MemoryCell
8: {
9: public:
10:
11: explicit MemoryCell(const ObjectType& initialValue = ObjectType());
12: /**<
13: @pre none
14: @post A MemoryCell object containing initialValue, or the default
15: value of type ObjectType if no initialValue is supplied, has been
16: constructed.
17: */
18:
19: const ObjectType& StoredValue() const;
20: /**<
21: @pre self has been delcared.
22: @post Returns a constant reference to the value stored in self.
23: */
24:
25: void StoreValue(const ObjectType& value);
26: /**<
27: @pre self has been declared.
28: @post Stores the contents of "value" in self, overwriting any
29: previous contents.
30: */
31:
32: private:
33:
34: ObjectType storedValue;
35: };
36:
37:
38: template<class ObjectType>
39: MemoryCell<ObjectType>::MemoryCell(const ObjectType& initialValue)
40: :storedValue(initialValue)
41: {}
42:
43:
44: template<class ObjectType>
45: const ObjectType& MemoryCell<ObjectType>::StoredValue() const
46: {
47: return storedValue;
48: }
49:
50:
51: template<class ObjectType>
52: void MemoryCell<ObjectType>::StoreValue(const ObjectType& value)
53: {
54: storedValue = value;
55: }