4 * Copyright (c) 2008 Vincent Geddes
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #ifndef __ST_ARRAY_H__
26 #define __ST_ARRAY_H__
29 #include <st-object.h>
31 #define ST_ARRAYED_OBJECT(oop) ((struct st_arrayed_object *) st_detag_pointer (oop))
32 #define ST_ARRAY(oop) ((struct st_array *) st_detag_pointer (oop))
33 #define ST_FLOAT_ARRAY(oop) ((struct st_float_array *) st_detag_pointer (oop))
34 #define ST_WORD_ARRAY(oop) ((struct st_word_array *) st_detag_pointer (oop))
35 #define ST_BYTE_ARRAY(oop) ((struct st_byte_array *) st_detag_pointer (oop))
37 struct st_arrayed_object
39 struct st_header header
;
45 struct st_arrayed_object header
;
52 struct st_arrayed_object header
;
59 struct st_arrayed_object header
;
66 struct st_arrayed_object header
;
71 bool st_byte_array_equal (st_oop object
, st_oop other
);
72 st_uint
st_byte_array_hash (st_oop object
);
73 st_oop
st_array_allocate (st_oop
class, st_uint size
);
74 st_oop
st_float_array_allocate (st_oop
class, int size
);
75 st_oop
st_word_array_allocate (st_oop
class, int size
);
76 st_oop
st_byte_array_allocate (st_oop
class, int size
);
79 st_arrayed_object_size (st_oop object
)
81 return ST_ARRAYED_OBJECT (object
)->size
;
85 static inline st_oop
*
86 st_array_elements (st_oop object
)
88 return ST_ARRAY (object
)->elements
;
92 st_array_at (st_oop object
, int i
)
94 return (ST_ARRAY (object
)->elements
- 1)[i
];
98 st_array_at_put (st_oop object
, int i
, st_oop value
)
100 (ST_ARRAY (object
)->elements
- 1)[i
] = value
;
103 static inline st_uint
*
104 st_word_array_elements (st_oop object
)
106 return ST_WORD_ARRAY (object
)->elements
;
109 static inline st_uint
110 st_word_array_at (st_oop object
, int i
)
112 return ST_WORD_ARRAY (object
)->elements
[i
- 1];
116 st_word_array_at_put (st_oop object
, int i
, st_uint value
)
118 ST_WORD_ARRAY (object
)->elements
[i
- 1] = value
;
121 static inline st_uchar
*
122 st_byte_array_bytes (st_oop object
)
124 return ST_BYTE_ARRAY (object
)->bytes
;
127 static inline st_uchar
128 st_byte_array_at (st_oop object
, int i
)
130 return st_byte_array_bytes (object
)[i
- 1];
134 st_byte_array_at_put (st_oop object
, int i
, st_uchar value
)
136 st_byte_array_bytes (object
)[i
- 1] = value
;
139 static inline double *
140 st_float_array_elements (st_oop array
)
142 return ST_FLOAT_ARRAY (array
)->elements
;
146 st_float_array_at (st_oop array
, int i
)
148 return ST_FLOAT_ARRAY (array
)->elements
[i
- 1];
152 st_float_array_at_put (st_oop array
, int i
, double value
)
154 ST_FLOAT_ARRAY (array
)->elements
[i
- 1] = value
;
157 #endif /* __ST_ARRAY_H__ */