996
|
1 #ifndef boof_h_
|
|
2 #define boof_h_
|
|
3
|
|
4 /* A boolpit is an infinite array of bools (growable at both ends) */
|
|
5 /* boof.h - by Sam Hughes - boof@samuelhughes.com */
|
|
6
|
|
7 #include <string>
|
|
8 #include <iostream>
|
|
9 #include <vector>
|
|
10
|
|
11 class boolpit {
|
|
12
|
|
13 unsigned char * beg_;
|
|
14 unsigned char * mid_;
|
|
15 unsigned char * end_;
|
|
16
|
|
17 public:
|
|
18
|
|
19 boolpit();
|
|
20 boolpit(const boolpit & copyee);
|
|
21 ~boolpit();
|
|
22
|
|
23 boolpit & operator=(const boolpit & assignee);
|
|
24
|
|
25 void set(size_t offset, int i);
|
|
26 int get(size_t offset);
|
|
27 void flip(size_t offset);
|
|
28
|
|
29 private:
|
|
30 void copy(const boolpit & copyee);
|
|
31 void grow_and_accommodate(unsigned char * & p);
|
|
32
|
|
33
|
|
34 };
|
|
35
|
|
36 class boofer {
|
|
37 struct size_triad {
|
|
38 size_t lpos, rjump, bjump;
|
|
39 size_triad(size_t a, size_t b, size_t c)
|
|
40 : lpos(a), rjump(b), bjump(c) {}
|
|
41 };
|
|
42
|
|
43 std::string prog_;
|
|
44 std::vector<size_triad> brace_pos_;
|
|
45
|
|
46 public:
|
|
47 boofer(std::istream & istr);
|
|
48 void execute(std::istream & in, std::ostream & out) const;
|
|
49
|
|
50
|
|
51
|
|
52 };
|
|
53
|
|
54
|
|
55 #endif
|