| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef VMSTRBUF_H |
| 21 |
#define VMSTRBUF_H |
| 22 |
|
| 23 |
#include "t3std.h" |
| 24 |
#include "vmtype.h" |
| 25 |
#include "vmglob.h" |
| 26 |
#include "vmobj.h" |
| 27 |
#include "vmundo.h" |
| 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 |
struct vm_strbuf_ext |
| 59 |
{ |
| 60 |
|
| 61 |
static vm_strbuf_ext *alloc_ext(VMG_ class CVmObjStringBuffer *self, |
| 62 |
int32_t alo, int32_t inc); |
| 63 |
|
| 64 |
|
| 65 |
static vm_strbuf_ext *expand_ext(VMG_ class CVmObjStringBuffer *self, |
| 66 |
vm_strbuf_ext *old_ext, |
| 67 |
int32_t new_len); |
| 68 |
|
| 69 |
|
| 70 |
int32_t len; |
| 71 |
|
| 72 |
|
| 73 |
int32_t alo; |
| 74 |
|
| 75 |
|
| 76 |
int32_t inc; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
wchar_t buf[1]; |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
enum strbuf_undo_action |
| 92 |
{ |
| 93 |
|
| 94 |
STRBUF_UNDO_INS, |
| 95 |
|
| 96 |
|
| 97 |
STRBUF_UNDO_DEL, |
| 98 |
|
| 99 |
|
| 100 |
STRBUF_UNDO_REPL |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
class CVmObjStringBuffer: public CVmObject |
| 110 |
{ |
| 111 |
friend class CVmMetaclassStringBuffer; |
| 112 |
|
| 113 |
public: |
| 114 |
|
| 115 |
static class CVmMetaclass *metaclass_reg_; |
| 116 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 117 |
|
| 118 |
|
| 119 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 120 |
{ |
| 121 |
|
| 122 |
return (meta == metaclass_reg_ |
| 123 |
|| CVmObject::is_of_metaclass(meta)); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
static int is_string_buffer_obj(VMG_ vm_obj_id_t obj) |
| 128 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 129 |
|
| 130 |
|
| 131 |
static vm_obj_id_t create(VMG_ int in_root_set, int32_t alo, int32_t inc); |
| 132 |
|
| 133 |
|
| 134 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 135 |
uint argc); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 142 |
const uchar **pc_ptr, uint *argc, |
| 143 |
vm_prop_id_t prop) |
| 144 |
{ |
| 145 |
return CVmObject:: |
| 146 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
virtual void reserve_const_data(VMG_ class CVmConstMapper *mapper, |
| 151 |
vm_obj_id_t self) |
| 152 |
{ |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
virtual void convert_to_const_data(VMG_ class CVmConstMapper *, |
| 158 |
vm_obj_id_t) |
| 159 |
{ |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
void notify_delete(VMG_ int in_root_set); |
| 165 |
|
| 166 |
|
| 167 |
void set_prop(VMG_ class CVmUndo *undo, |
| 168 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 169 |
|
| 170 |
|
| 171 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 172 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
void notify_new_savept() { } |
| 179 |
|
| 180 |
|
| 181 |
void apply_undo(VMG_ struct CVmUndoRecord *rec); |
| 182 |
|
| 183 |
|
| 184 |
void discard_undo(VMG_ struct CVmUndoRecord *); |
| 185 |
|
| 186 |
|
| 187 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 188 |
|
| 189 |
|
| 190 |
void mark_refs(VMG_ uint) { } |
| 191 |
|
| 192 |
|
| 193 |
void remove_stale_weak_refs(VMG0_) { } |
| 194 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 195 |
|
| 196 |
|
| 197 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 198 |
|
| 199 |
|
| 200 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 201 |
const char *ptr, size_t siz); |
| 202 |
|
| 203 |
|
| 204 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 205 |
|
| 206 |
|
| 207 |
void save_to_file(VMG_ class CVmFile *fp); |
| 208 |
|
| 209 |
|
| 210 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 211 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
int is_changed_since_load() const { return TRUE; } |
| 219 |
|
| 220 |
|
| 221 |
int index_val_q(VMG_ vm_val_t *result, |
| 222 |
vm_obj_id_t self, |
| 223 |
const vm_val_t *index_val); |
| 224 |
|
| 225 |
|
| 226 |
int set_index_val_q(VMG_ vm_val_t *new_container, |
| 227 |
vm_obj_id_t self, |
| 228 |
const vm_val_t *index_val, |
| 229 |
const vm_val_t *new_val); |
| 230 |
|
| 231 |
|
| 232 |
void add_entry(VMG_ const vm_val_t *key, const vm_val_t *val); |
| 233 |
|
| 234 |
|
| 235 |
void set_or_add_entry(VMG_ const vm_val_t *key, const vm_val_t *val); |
| 236 |
|
| 237 |
|
| 238 |
virtual const char *cast_to_string(VMG_ vm_obj_id_t self, |
| 239 |
vm_val_t *new_str) const; |
| 240 |
|
| 241 |
|
| 242 |
virtual int equals(VMG_ vm_obj_id_t self, const vm_val_t *val, int) const; |
| 243 |
|
| 244 |
|
| 245 |
int equals_str(const char *str) const; |
| 246 |
|
| 247 |
|
| 248 |
virtual int compare_to(VMG_ vm_obj_id_t self, const vm_val_t *val) const; |
| 249 |
|
| 250 |
|
| 251 |
int compare_str(const char *str) const; |
| 252 |
|
| 253 |
|
| 254 |
virtual uint calc_hash(VMG_ vm_obj_id_t self, int ) const; |
| 255 |
|
| 256 |
|
| 257 |
int32_t utf8_length() const; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
void to_utf8(char *buf, int32_t &idx, int32_t &bytelen); |
| 278 |
|
| 279 |
|
| 280 |
void ensure_space(VMG_ int32_t len); |
| 281 |
|
| 282 |
|
| 283 |
void ensure_added_space(VMG_ int32_t len) |
| 284 |
{ ensure_space(vmg_ get_ext()->len + len); } |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
const wchar_t *get_buf() const { return get_ext()->buf; } |
| 291 |
|
| 292 |
|
| 293 |
size_t get_len() const { return get_ext()->len; } |
| 294 |
|
| 295 |
protected: |
| 296 |
|
| 297 |
vm_strbuf_ext *get_ext() const { return (vm_strbuf_ext *)ext_; } |
| 298 |
|
| 299 |
|
| 300 |
const char *substr_to_string( |
| 301 |
VMG_ vm_val_t *new_str, int32_t idx, int32_t len) const; |
| 302 |
|
| 303 |
|
| 304 |
void adjust_args(int32_t *idx, int32_t *len, int32_t *ins) const; |
| 305 |
|
| 306 |
|
| 307 |
void splice_move(VMG_ int32_t idx, int32_t del, int32_t ins); |
| 308 |
|
| 309 |
|
| 310 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 311 |
|
| 312 |
|
| 313 |
CVmObjStringBuffer() { ext_ = 0; } |
| 314 |
|
| 315 |
|
| 316 |
CVmObjStringBuffer(VMG_ int32_t alo, int32_t inc); |
| 317 |
|
| 318 |
|
| 319 |
void insert_text(VMG_ vm_obj_id_t self, |
| 320 |
int32_t idx, const wchar_t *src, int32_t chars, int undo) |
| 321 |
{ splice_text(vmg_ self, idx, 0, src, chars, undo); } |
| 322 |
|
| 323 |
|
| 324 |
void insert_char(VMG_ vm_obj_id_t self, |
| 325 |
int32_t idx, wchar_t ch, int undo) |
| 326 |
{ splice_text(vmg_ self, idx, 0, &ch, 1, undo); } |
| 327 |
|
| 328 |
|
| 329 |
void insert_text(VMG_ vm_obj_id_t self, |
| 330 |
int32_t idx, const char *src, int32_t bytes, int undo) |
| 331 |
{ splice_text(vmg_ self, idx, 0, src, bytes, undo); } |
| 332 |
|
| 333 |
|
| 334 |
void delete_text(VMG_ vm_obj_id_t self, |
| 335 |
int32_t idx, int32_t chars, int undo) |
| 336 |
{ splice_text(vmg_ self, idx, chars, (wchar_t *)0, 0, undo); } |
| 337 |
|
| 338 |
|
| 339 |
void splice_text(VMG_ vm_obj_id_t self, |
| 340 |
int32_t idx, int32_t del_chars, |
| 341 |
const wchar_t *src, int32_t ins_chars, int undo); |
| 342 |
void splice_text(VMG_ vm_obj_id_t self, |
| 343 |
int32_t idx, int32_t del_chars, |
| 344 |
const char *src, int32_t ins_bytes, int undo); |
| 345 |
|
| 346 |
|
| 347 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 348 |
|
| 349 |
|
| 350 |
int getp_len(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 351 |
|
| 352 |
|
| 353 |
int getp_char_at(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 354 |
|
| 355 |
|
| 356 |
int getp_append(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 357 |
|
| 358 |
|
| 359 |
int getp_copyChars(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 360 |
|
| 361 |
|
| 362 |
int getp_insert(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 363 |
|
| 364 |
|
| 365 |
int getp_delete(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 366 |
|
| 367 |
|
| 368 |
int getp_splice(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 369 |
|
| 370 |
|
| 371 |
int getp_substr(VMG_ vm_obj_id_t, vm_val_t *, uint *); |
| 372 |
|
| 373 |
|
| 374 |
void add_undo_rec(VMG_ vm_obj_id_t self, |
| 375 |
enum strbuf_undo_action action, |
| 376 |
int32_t idx, int32_t old_len, int32_t new_len); |
| 377 |
|
| 378 |
|
| 379 |
static int (CVmObjStringBuffer::*func_table_[])(VMG_ vm_obj_id_t self, |
| 380 |
vm_val_t *retval, uint *argc); |
| 381 |
}; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
class CVmMetaclassStringBuffer: public CVmMetaclass |
| 389 |
{ |
| 390 |
public: |
| 391 |
|
| 392 |
const char *get_meta_name() const { return "stringbuffer/030000"; } |
| 393 |
|
| 394 |
|
| 395 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 396 |
{ |
| 397 |
new (vmg_ id) CVmObjStringBuffer(); |
| 398 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 403 |
{ |
| 404 |
new (vmg_ id) CVmObjStringBuffer(); |
| 405 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 410 |
{ return CVmObjStringBuffer::create_from_stack(vmg_ pc_ptr, argc); } |
| 411 |
|
| 412 |
|
| 413 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 414 |
const uchar **pc_ptr, uint *argc, |
| 415 |
vm_prop_id_t prop) |
| 416 |
{ |
| 417 |
return CVmObjStringBuffer:: |
| 418 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 419 |
} |
| 420 |
}; |
| 421 |
|
| 422 |
#endif |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
VM_REGISTER_METACLASS(CVmObjStringBuffer) |