25 #ifndef TBX_RES_RESBASE_H_
26 #define TBX_RES_RESBASE_H_
31 #include "resstruct.h"
42 struct ResRelocationTable
45 ResRelocation *_relocs;
47 ResRelocationTable() : _size(0), _relocs(0) {};
48 ResRelocationTable(
const ResRelocationTable &other);
49 ~ResRelocationTable() {
delete [] _relocs;}
51 ResRelocationTable &operator=(
const ResRelocationTable &other);
54 void erase(
int offset);
57 void offsets_to_pointers(
char *body,
char *strings,
char *msgs)
const;
58 void pointers_to_offsets(
char *body,
char *strings,
char *msgs)
const;
59 void fix_text_pointers(
bool string_table,
char *body,
const char *new_strings,
const char *old_strings,
const char *from,
int by);
60 void fix_all_pointers(
char *new_body,
const char *old_body,
const char *new_strings,
const char *old_strings,
const char *new_messages,
const char *old_messages);
61 void fix_after_insert(
char *new_body,
const char *old_body,
int offset,
int count);
80 ResRelocationTable _reloc_table;
85 ResData(ResDataHeader header,
char *strings,
int num_reloc, ResRelocation *relocs);
86 ResData(
const ResData &other);
90 int reloc_size()
const {
return _reloc_table._size;}
91 int strings_size()
const {
return _strings_size;}
92 const char *strings()
const {
return _strings;}
93 int messages_size()
const {
return _messages_size;}
94 const char *messages()
const {
return _messages;}
96 void calculate_string_sizes(
const char *body);
98 const char *text(
const char *body,
int offset)
const {
return (
char *)(*(
int *)(body + offset));}
99 int text_len(
const char *body,
int offset)
const;
100 void text(
char *body,
int offset,
const char *new_text,
int len,
bool is_string);
101 void text(
char *body,
int offset, std::string msg,
bool is_string)
103 text(body, offset, msg.c_str(), msg.size(), is_string);
106 int number(
const char *body,
int offset)
const
108 return *((
int *)(body + offset));
110 void number(
char *body,
int offset,
int value)
112 *((
int *)(body+offset)) = value;
115 void init_text(
char *body,
int offset,
const char *value,
bool is_string);
116 void init_sprite_area_ref(
char *body,
int offset);
117 void init_object_ref(
char *body,
int offset);
119 void copy_used(
char *body,
const char *old_body,
const ResRelocationTable ©_table);
124 void pointers_to_offsets(
char *body)
const
126 _reloc_table.pointers_to_offsets(body, _strings, _messages);
129 void offsets_to_pointers(
char *body)
const
131 _reloc_table.offsets_to_pointers(body, _strings, _messages);
134 ResData *component_data(
char *new_body,
char *copy_body,
int offset,
int size)
const;
135 void add_data_from(
char *body,
int offset,
const char *from_body,
const ResData *from_data);
136 void remove_data(
char *body,
int offset,
int size);
137 void fix_offsets(
char *new_body,
const char *old_body,
int offset,
int diff);
139 static ResData *copy_from_read_only(
char *new_header,
char *readonly_header);
140 static ResData *copy_component_from_read_only(
char *new_body,
char *readonly_header,
int offset,
int size);
142 void write(std::ostream &file)
const;
145 char *remove_chars(
char *body,
bool string_table,
const char *where,
int num);
146 char *insert_chars(
char *body,
bool string_table,
const char *where,
int num);
147 void copy_strings_and_messages(
char *new_body,
const char *copy_body);
167 ResRelocationTable *_type_reloc_table;
173 ResImpl(
void *object_header,
int body_offset,
int size);
174 ResImpl(
void *object_header,
int body_offset,
int size, ResData *data);
175 ResImpl(
const ResImpl &other);
176 ResImpl(
const ResImpl &other,
bool copy_read_only);
181 char *header() {
return _header;}
182 const char *header()
const {
return _header;}
183 char *body() {
return _body;}
184 const char *body()
const {
return _body;}
185 const ResData *data()
const {
return _data;}
186 int size()
const {
return _size;}
188 const char *text(
int offset)
const {
return (
char *)(*(
int *)(_body + offset));}
189 int text_len(
int offset)
const;
190 void text(
int offset,
const char *new_text,
int len,
bool is_string)
192 if (_data == 0) _data =
new ResData();
193 _data->text(_body, offset, new_text, ((new_text == 0) ? 0 : len), is_string);
196 void text(
int offset, std::string msg,
bool is_string)
198 text(offset, msg.c_str(), msg.size(), is_string);
201 void text_with_length(
int offset,
const char *new_text,
int max_length,
bool is_string);
202 void text_with_length(
int offset,
const std::string &new_text,
int max_length,
bool is_string)
204 if (max_length <= (
int)new_text.size()) max_length = (
int)new_text.size()+1;
205 text_with_length(offset, new_text.c_str(), max_length, is_string);
208 int int_value(
int offset)
const;
209 void int_value(
int offset,
int value);
210 unsigned int uint_value(
int offset)
const;
211 void uint_value(
int offset,
unsigned int value);
213 unsigned short ushort_value(
int offset)
const;
214 void ushort_value(
int offset,
unsigned short value);
216 unsigned char byte_value(
int offset)
const;
217 void byte_value(
int offset,
unsigned char value);
219 bool flag(
int offset,
int mask)
const;
220 void flag(
int offset,
int mask,
bool on);
222 int flag_value(
int offset,
int mask)
const;
223 void flag_value(
int offset,
int mask,
int value);
225 void init_text(
int offset,
const char *value,
bool is_string);
226 void init_sprite_area_ref(
int offset);
227 void init_object_ref(
int offset);
229 ResData *component_data(
char *new_body,
int offset,
int size)
const;
234 bool read_only()
const {
return (_ref_count == -1);}
239 bool unique()
const {
return (_ref_count == 1);}
241 void insert(
int offset,
const ResImpl *insert_impl);
242 void replace(
int offset,
int old_size,
const ResImpl *rep_impl);
243 void erase(
int offset,
int size);
277 const char *
string(
int offset)
const;
278 void string(
int offset,
const char *value);
279 void string(
int offset, std::string value);
294 const char *
message(
int offset)
const;
295 void message(
int offset,
const char *value);
296 void message(
int offset, std::string value);
325 void uint_value(
int offset,
unsigned int value);
334 void byte_value(
int offset,
unsigned char value);
352 bool flag(
int offset,
int mask)
const {
return _impl->flag(offset, mask);}
353 void flag(
int offset,
int mask,
bool on);
363 void flag_value(
int offset,
int mask,
int value);
Type
Relocation type enumeration.
Definition: resstruct.h:68
int flag_value(int offset, int mask) const
Get the bits for the given mask.
Definition: resbase.h:362
void init_string(int offset, const char *value)
Initialise a string in a constructor helper.
Definition: resbase.cc:1725
void init_object_ref(int offset)
Initialise an object reference.
Definition: resbase.cc:1756
Base class for objects, gadgets and menu items from ressources.
Definition: resbase.h:252
void message_with_length(int offset, const char *value, int length=-1)
Assign a message where the length is at offset+4.
Definition: resbase.cc:1639
unsigned short ushort_value(int offset) const
Get a unsigned short value.
Definition: resbase.h:342
virtual void make_writeable()=0
Make object writeable, call before any change.
void string_with_length(int offset, const char *value, int length=-1)
Assign a string where the length is at offset+4.
Definition: resbase.cc:1591
bool flag(int offset, int mask) const
Check if any of the bits in a mask are set.
Definition: resbase.h:352
ResBase(ResImpl *impl)
Create from internal resource implementation.
Definition: resbase.h:262
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
const char * string(int offset) const
Return a string at the given offset.
Definition: resbase.cc:1555
unsigned char byte_value(int offset) const
Get a byte value.
Definition: resbase.h:333
void message_with_length(int offset, const std::string &value, int length=-1)
Assign a message where the length is at offset+4.
Definition: resbase.h:306
void init_sprite_area_ref(int offset)
Initialise a sprite area reference.
Definition: resbase.cc:1746
unsigned int uint_value(int offset) const
Get an unsigned integer value.
Definition: resbase.h:324
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
virtual ~ResBase()
Destructor.
Definition: resbase.cc:1524
void string_with_length(int offset, const std::string &value, int length=-1)
Assign a string where the length is at offset+4.
Definition: resbase.h:290
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
ResImpl * _impl
Internal Resource implementation.
Definition: resbase.h:255
void init_message(int offset, const char *value)
Initialise a message in a constructor helper.
Definition: resbase.cc:1736