-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWall.hpp
104 lines (91 loc) · 2.73 KB
/
Wall.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright Kabuki Starship� <kabukistarship.com>; all rights reserved.
#pragma once
#ifndef SCRIPT2_WALL_CODE
#define SCRIPT2_WALL_CODE
#include <_Config.h>
#if SEAM >= SCRIPT2_DIC
#include "Door.hpp"
#include "Op.hpp"
#include "Array.hpp"
namespace _ {
/* A group of slots that all go to the same Room.
Only one single wall is required for a Chinese Room, but when more memory is
needed a new Wall may be created and destroyed dynamically.
@code
+--------------+
| Terminals |
| v |
|vvvvvvvvvvvvvv|
| Boofer |
|^^^^^^^^^^^^^^|
| ^ |
| TStack of |
| Doors |
| Offsets |
|--------------|
| Header |
+--------------+
@endcode */
template<typename ISZ, typename ISY>
class TWall : public Operand {
public:
enum {
BytesMin = 512, //< Min functional Wall size.
};
private:
TStack<ISZ> doors_; //< The doors in the room.
virtual ~TWall() {
if (is_dynamic_) {
CHA* socket = TPtr<CHA>(&doors_);
delete[] socket;
}
}
/* Constructs a wall from the given socket. */
TWall(ISW bytes = BytesMin) : is_dynamic_(true) {
bytes = bytes < BytesMin ? (ISC)BytesMin : bytes;
bytes = TAlignUp<ISD, ISW>(bytes);
ISW size_words = (bytes >> sizeof(void*)) + 3;
IUW *socket = new IUW[size_words],
*aligned_boofer = TPtrUp<IUW>(socket);
//< Shift 3 to divide by 8. The extra 3 elements are for aligning memory
//< on 16 and 32-bit systems.
bytes -= sizeof(IUW) * (aligned_boofer - socket);
origin = socket;
doors_ = TPtr<TStack<ISZ>>(aligned_boofer);
TStackInit(socket, bytes >> sizeof(IUW));
}
/* Constructs a wall from the given socket. */
TWall(IUW* socket, ISW bytes) {
IUW* aligned_boofer = TPtrUp<IUW>(socket);
//< Shift 3 to divide by 8. The extra 3 elements are for aligning memory
//< on 16 and 32-bit systems.
bytes -= sizeof(IUW) * (aligned_boofer - socket);
origin = socket;
doors_ = TPtr<TStack<ISZ>>(aligned_boofer);
TStackInit(socket, bytes >> sizeof(IUW));
}
/* Gets the size of the wall in bytes. */
ISW GetSizeBytes() {
return bytes_;
}
/* Gets a pointer to the array of pointers to Door(). */
TStack<ISZ>* Doors() {
return &doors_;
}
/* Gets the Door from the Door at the given index. */
TDoor<ISZ> GetDoor(ISY index) { return 0; }
/* Adds a Door to the slot.
@return Returns nil if the Door is full and a pointer to the Door in the
socket upon success. */
ISC OpenDoor(Door * door) { return 0; }
/* Deletes the Door from the Door at the given index. */
BOL CloseDoor(ISY index) { return false; }
/* Prints the given Door to the stream. */
template<typename Printer>
Printer& PrintTo(Printer & o) {
return o;
}
};
} //< namespace _
#endif
#endif