Sun, 23 Feb 2014 17:45:34 +0200
- changed the PROPERTY macro to a simper version and brought some refactoring with it
88 | 1 | /* |
2 | Copyright 2012-2014 Santeri Piippo | |
3 | All rights reserved. | |
4 | ||
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions | |
7 | are met: | |
8 | ||
9 | 1. Redistributions of source code must retain the above copyright | |
10 | notice, this list of conditions and the following disclaimer. | |
11 | 2. Redistributions in binary form must reproduce the above copyright | |
12 | notice, this list of conditions and the following disclaimer in the | |
13 | documentation and/or other materials provided with the distribution. | |
14 | 3. The name of the author may not be used to endorse or promote products | |
15 | derived from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef BOTC_DATABUFFER_H | |
30 | #define BOTC_DATABUFFER_H | |
31 | ||
32 | #include <stdio.h> | |
33 | #include <string.h> | |
34 | #include "Main.h" | |
35 | #include "StringTable.h" | |
36 | ||
37 | // ============================================================================ | |
38 | // data_buffer: A dynamic data buffer. | |
39 | // | |
40 | // Notes: | |
41 | // | |
42 | // - A mark is a "pointer" to a particular position in the bytecode. The actual | |
43 | // permanent position cannot be predicted in any way or form, thus these things | |
44 | // are used to "mark" a position like that for future use. | |
45 | // | |
46 | // - A reference is another "mark" that references a mark. When the bytecode | |
47 | // is written to file, they are changed into their marks' current | |
48 | // positions. Marks themselves are never written to files, only refs are | |
49 | // | |
50 | class DataBuffer | |
51 | { | |
112
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
52 | PROPERTY (private, char*, Buffer, SetBuffer, STOCK_WRITE) |
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
53 | PROPERTY (private, int, AllocatedSize, SetAllocatedSize, STOCK_WRITE) |
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
54 | PROPERTY (private, char*, Position, SetPosition, STOCK_WRITE) |
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
55 | PROPERTY (private, List<ByteMark*>, Marks, SetMarks, STOCK_WRITE) |
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
56 | PROPERTY (private, List<MarkReference*>, References, SetReferences, STOCK_WRITE) |
88 | 57 | |
58 | public: | |
59 | DataBuffer (int size = 128); | |
60 | ~DataBuffer(); | |
61 | ||
62 | // ==================================================================== | |
63 | // Merge another data buffer into this one. | |
64 | // Note: @other is destroyed in the process! | |
65 | void MergeAndDestroy (DataBuffer* other); | |
66 | ||
67 | ByteMark* AddMark (String name); | |
91
427eb377d53e
- committed work so far done on expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
68 | MarkReference* AddReference (ByteMark* mark); |
88 | 69 | void CheckSpace (int bytes); |
96
3384d7aa036a
- ternary operator now works properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
70 | DataBuffer* Clone(); |
88 | 71 | void DeleteMark (int marknum); |
72 | void AdjustMark (ByteMark* mark); | |
73 | void OffsetMark (ByteMark* mark, int offset); | |
74 | ByteMark* FindMarkByName (const String& target); | |
75 | void Dump(); | |
96
3384d7aa036a
- ternary operator now works properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
76 | void TransferMarks (DataBuffer* other); |
88 | 77 | void WriteStringIndex (const String& a); |
78 | void WriteString (const String& a); | |
79 | void WriteByte (int8_t data); | |
80 | void WriteWord (int16_t data); | |
81 | void WriteDWord (int32_t data); | |
82 | void CopyBuffer (const DataBuffer* buf); | |
83 | ||
112
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
84 | inline int WrittenSize() const |
88 | 85 | { |
112
def56932f938
- changed the PROPERTY macro to a simper version and brought some refactoring with it
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
86 | return Position() - Buffer(); |
88 | 87 | } |
88 | }; | |
89 | ||
90 | #endif // BOTC_DATABUFFER_H |