cfad47cfa3/tads3/vmtypedh.cpp

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#ifdef RCSID
2
static char RCSid[] =
3
"$Header: d:/cvsroot/tads/tads3/VMTYPEDH.CPP,v 1.2 1999/05/17 02:52:29 MJRoberts Exp $";
4
#endif
5
6
/* 
7
 *   Copyright (c) 1999, 2002 Michael J. Roberts.  All Rights Reserved.
8
 *   
9
 *   Please see the accompanying license file, LICENSE.TXT, for information
10
 *   on using and copying this software.  
11
 */
12
/*
13
Name
14
  vmtypedh.cpp - type manipulations for data holders
15
Function
16
  
17
Notes
18
  This is separated from vmtype.cpp so that these functions can be linked
19
  into an application without dragging in a bunch of things that other
20
  vmtype.cpp code depends upon.
21
Modified
22
  05/11/99 MJRoberts  - Creation
23
*/
24
25
#include "t3std.h"
26
#include "vmtype.h"
27
#include "vmglob.h"
28
#include "vmstack.h"
29
30
31
/* ------------------------------------------------------------------------ */
32
/*
33
 *   Portable data holder manipulation 
34
 */
35
36
/* 
37
 *   store a vm_val_t value in a portable data holder 
38
 */
39
void vmb_put_dh(char *buf, const vm_val_t *val)
40
{
41
    /* store the type code */
42
    buf[0] = (char)val->typ;
43
44
    /* store the value, in the appropriate type-dependent format */
45
    switch(val->typ)
46
    {
47
    case VM_OBJ:
48
        /* store the object ID as a UINT4 */
49
        oswp4(buf+1, val->val.obj);
50
        break;
51
52
    case VM_PROP:
53
        /* store the property ID as a UINT2 */
54
        oswp2(buf+1, val->val.prop);
55
        break;
56
57
    case VM_INT:
58
        /* store the integer as a UINT4 */
59
        oswp4(buf+1, val->val.intval);
60
        break;
61
62
    case VM_ENUM:
63
        /* store the enumerated constant value as a UINT4 */
64
        oswp4(buf+1, val->val.enumval);
65
        break;
66
67
    case VM_SSTRING:
68
    case VM_DSTRING:
69
    case VM_LIST:
70
    case VM_CODEOFS:
71
    case VM_FUNCPTR:
72
        /* store the offset value as a UINT4 */
73
        oswp4(buf+1, val->val.ofs);
74
        break;
75
76
    default:
77
        /* other types have no extra data or cannot be put into a DH */
78
        break;
79
    }
80
}
81
82
/*
83
 *   Get only the value portion of a vm_val_t from a portable data holder 
84
 */
85
void vmb_get_dh_val(const char *buf, vm_val_t *val)
86
{
87
    /* read the format appropriate to the type */
88
    switch((vm_datatype_t)buf[0])
89
    {
90
    case VM_OBJ:
91
        /* get the object ID from the UINT4 */
92
        val->val.obj = (vm_obj_id_t)t3rp4u(buf+1);
93
        break;
94
95
    case VM_PROP:
96
        /* get the property ID from the UINT2 */
97
        val->val.prop = (vm_prop_id_t)osrp2(buf+1);
98
        break;
99
100
    case VM_INT:
101
        /* get the integer from the UINT4 */
102
        val->val.intval = osrp4(buf+1);
103
        break;
104
105
    case VM_ENUM:
106
        /* get the enumerated constant value from the UINT4 */
107
        val->val.enumval = t3rp4u(buf+1);
108
        break;
109
110
    case VM_SSTRING:
111
    case VM_DSTRING:
112
    case VM_LIST:
113
    case VM_CODEOFS:
114
    case VM_FUNCPTR:
115
        /* get the offset value from the UINT4 */
116
        val->val.ofs = t3rp4u(buf+1);
117
        break;
118
119
    default:
120
        /* other types have no additional data or cannot be put in a DH */
121
        break;
122
    }
123
}
124