1 /* $Id$ */ 2 /* Copyright (c) 2012-2016 Pierre Pronchery <khorben@defora.org> */ 3 /* This file is part of DeforaOS System libSystem */ 4 /* This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, version 3 of the License. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 17 18 #ifndef LIBSYSTEM_SYSTEM_VARIABLE_H 19 # define LIBSYSTEM_SYSTEM_VARIABLE_H 20 21 # include <stdint.h> 22 # include "buffer.h" 23 # include "string.h" 24 25 26 /* Variable */ 27 /* types */ 28 typedef struct _Variable Variable; 29 30 typedef enum _VariableType 31 { 32 VT_NULL = 0, 33 VT_BOOL, 34 VT_INT8, 35 VT_UINT8, 36 VT_INT16, 37 VT_UINT16, 38 VT_INT32, 39 VT_UINT32, 40 VT_INT64, 41 VT_UINT64, 42 VT_FLOAT, 43 VT_DOUBLE, 44 VT_BUFFER, 45 VT_STRING, 46 VT_ARRAY, 47 VT_COMPOUND 48 } VariableType; 49 50 typedef unsigned int VariableClass; 51 52 53 /* functions */ 54 Variable * variable_new(VariableType type, void const * value); 55 Variable * variable_new_array(VariableType type, size_t size, ...); 56 Variable * variable_new_arrayv(VariableType type, size_t size, void ** values); 57 Variable * variable_new_compound(String const * name, size_t members, ...); 58 Variable * variable_new_compoundv(String const * name, size_t members, 59 VariableType * types, void ** values); 60 Variable * variable_new_copy(Variable * variable); 61 Variable * variable_new_deserialize(size_t * size, char const * data); 62 Variable * variable_new_deserialize_buffer(size_t * size, 63 Buffer const * buffer); 64 Variable * variable_new_deserialize_type(VariableType type, size_t * size, 65 char const * data); 66 void variable_delete(Variable * variable); 67 68 69 /* accessors */ 70 int variable_get_as(Variable * variable, VariableType type, void * result); 71 VariableClass variable_get_class(Variable * variable); 72 VariableType variable_get_type(Variable * variable); 73 74 int variable_is_array(Variable * variable); 75 int variable_is_class(Variable * variable, VariableClass _class); 76 int variable_is_compound(Variable * variable); 77 int variable_is_instance(Variable * variable, String const * name); 78 int variable_is_scalar(Variable * variable); 79 int variable_is_type(Variable * variable, VariableType type); 80 81 int variable_set(Variable * variable, Variable * from); 82 int variable_set_from(Variable * variable, VariableType type, 83 void const * value); 84 85 /* useful */ 86 int variable_serialize(Variable * variable, Buffer * buffer, int type); 87 88 #endif /* !LIBSYSTEM_SYSTEM_VARIABLE_H */ 89