My Project: openb3dlib.mod/openb3d/src/bank.h Source File

My Project

bank.h
Go to the documentation of this file.
1 #ifndef BANK_H
2 #define BANK_H
3
4 /*
5 * bank.h
6 * iminib3d
7 *
8 * Created by Simon Harrison.
9 * Copyright Si Design. All rights reserved.
10 *
11 */
12
13
14 #include <cstring>
15 //using namespace std;
16 #include <cstdlib>
17
18
19 class Bank{
20
21 public:
22
23 Bank(){};
24
25 void* buffer;
26 int size;
27
28 static Bank* CreateBank(int size){
29
30 Bank* bank=new Bank;
31 bank->buffer=(void*)malloc(size);
32
33 bank->size=size;
34
35 return bank;
36
37 }
38
39 static void CopyBank(Bank* src_bank,int src_offset,Bank* des_bank,int des_offset,int count){
40
41 std::memmove((char*)des_bank->buffer+des_offset,(char*)src_bank->buffer+src_offset,count);
42
43 }
44
45 void FreeBank(){
46
47 free(buffer);
48 delete this;
49 return;
50
51 }
52
53 void ResizeBank(int size){
54
55 buffer=(void*)realloc(buffer,size);
56
57 size=size;
58
59 }
60
61 int BankSize(){
62
63 return size;
64
65 }
66
67 void PokeByte(int offset,char c){
68
69 if(offset>=0 && offset<size){
70
71 ((char*)buffer+offset)[0]=c;
72
73 }
74
75 return;
76
77 }
78
79 void PokeShort(int offset,short s){
80
81 if(offset>=0 && offset<size-1){
82
83 ((short*)buffer+offset)[0]=s;
84
85 }
86
87 return;
88
89 }
90
91 void PokeInt(int offset,int i){
92
93 if(offset>=0 && offset<size-3){
94
95 ((int*)buffer+offset/4)[0]=i;
96
97 }
98
99 return;
100
101 }
102
103 void PokeFloat(int offset,float f){
104
105 if(offset>=0 && offset<size-3){
106
107 ((float*)buffer+offset/4)[0]=f;
108
109 }
110
111 return;
112
113 }
114
115 char PeekByte(int offset){
116
117 if(offset>=0 && offset<size){
118
119 return ((char*)buffer+offset)[0];
120
121 }
122
123 return 0;
124
125 }
126
127 short PeekShort(int offset){
128
129 if(offset>=0 && offset<size-1){
130
131 return ((short*)buffer+offset)[0];
132
133 }
134
135 return 0;
136
137 }
138
139 int PeekInt(int offset){
140
141 if(offset>=0 && offset<size-3){
142
143 return ((int*)buffer+offset/4)[0];
144
145 }
146
147 return 0;
148
149 }
150
151 float PeekFloat(int offset){
152
153 if(offset>=0 && offset<size-3){
154
155 return ((float*)buffer+offset/4)[0];
156
157 }
158
159 return 0;
160
161 }
162
163 };
164
165 #endif
Bank::ResizeBank
void ResizeBank(int size)
Definition: bank.h:53
Bank::PeekShort
short PeekShort(int offset)
Definition: bank.h:127
Bank::PokeByte
void PokeByte(int offset, char c)
Definition: bank.h:67
Bank::buffer
void * buffer
Definition: bank.h:23
Bank::CreateBank
static Bank * CreateBank(int size)
Definition: bank.h:28
Bank::PeekInt
int PeekInt(int offset)
Definition: bank.h:139
Bank::size
int size
Definition: bank.h:26
Bank::PeekFloat
float PeekFloat(int offset)
Definition: bank.h:151
Bank
Definition: bank.h:19
Bank::BankSize
int BankSize()
Definition: bank.h:61
Bank::PokeFloat
void PokeFloat(int offset, float f)
Definition: bank.h:103
Bank::CopyBank
static void CopyBank(Bank *src_bank, int src_offset, Bank *des_bank, int des_offset, int count)
Definition: bank.h:39
Bank::PokeInt
void PokeInt(int offset, int i)
Definition: bank.h:91
Bank::PeekByte
char PeekByte(int offset)
Definition: bank.h:115
Bank::Bank
Bank()
Definition: bank.h:23
Bank::PokeShort
void PokeShort(int offset, short s)
Definition: bank.h:79
Bank::FreeBank
void FreeBank()
Definition: bank.h:45