Changeset b8d45e9e in mainline for uspace/app/bithenge/transform.h
- Timestamp:
- 2012-08-02T21:06:59Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0f8062a4
- Parents:
- cb4a66d2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.h
rcb4a66d2 rb8d45e9e 76 76 } bithenge_transform_ops_t; 77 77 78 /** Initialize a transform scope. It must be destroyed with @a79 * bithenge_scope_destroy after it is used.80 * @param[out] scope The scope to initialize. */81 static inline void bithenge_scope_init(bithenge_scope_t *scope)82 {83 scope->num_params = 0;84 scope->params = NULL;85 scope->current_node = NULL;86 }87 88 /** Destroy a transform scope.89 * @param scope The scope to destroy.90 * @return EOK on success or an error code from errno.h. */91 static inline void bithenge_scope_destroy(bithenge_scope_t *scope)92 {93 bithenge_node_dec_ref(scope->current_node);94 for (int i = 0; i < scope->num_params; i++)95 bithenge_node_dec_ref(scope->params[i]);96 free(scope->params);97 }98 99 /** Copy a scope.100 * @param[out] out The scope to fill in; must have been initialized with @a101 * bithenge_scope_init.102 * @param scope The scope to copy.103 * @return EOK on success or an error code from errno.h. */104 static inline int bithenge_scope_copy(bithenge_scope_t *out,105 bithenge_scope_t *scope)106 {107 out->params = malloc(sizeof(*out->params) * scope->num_params);108 if (!out->params)109 return ENOMEM;110 memcpy(out->params, scope->params, sizeof(*out->params) *111 scope->num_params);112 out->num_params = scope->num_params;113 for (int i = 0; i < out->num_params; i++)114 bithenge_node_inc_ref(out->params[i]);115 out->current_node = scope->current_node;116 if (out->current_node)117 bithenge_node_inc_ref(out->current_node);118 return EOK;119 }120 121 /** Set the current node being created. Takes a reference to @a node.122 * @param scope The scope to set the current node in.123 * @param node The current node being created.124 * @return EOK on success or an error code from errno.h. */125 static inline void bithenge_scope_set_current_node(bithenge_scope_t *scope,126 bithenge_node_t *node)127 {128 bithenge_node_dec_ref(scope->current_node);129 scope->current_node = node;130 }131 132 /** Get the current node being created, which may be NULL.133 * @param scope The scope to get the current node from.134 * @return The node being created, or NULL. */135 static inline bithenge_node_t *bithenge_scope_get_current_node(136 bithenge_scope_t *scope)137 {138 if (scope->current_node)139 bithenge_node_inc_ref(scope->current_node);140 return scope->current_node;141 }142 143 /** Allocate parameters. The parameters must then be set with @a144 * bithenge_scope_set_param. This must not be called on a scope that already145 * has parameters.146 * @param scope The scope in which to allocate parameters.147 * @param num_params The number of parameters to allocate.148 * @return EOK on success or an error code from errno.h. */149 static inline int bithenge_scope_alloc_params(bithenge_scope_t *scope,150 int num_params)151 {152 scope->params = malloc(sizeof(*scope->params) * num_params);153 if (!scope->params)154 return ENOMEM;155 scope->num_params = num_params;156 for (int i = 0; i < num_params; i++)157 scope->params[i] = NULL;158 return EOK;159 }160 161 /** Set a parameter. Takes a reference to @a value. Note that range checking is162 * not done in release builds.163 * @param scope The scope in which to allocate parameters.164 * @param i The index of the parameter to set.165 * @param value The value to store in the parameter.166 * @return EOK on success or an error code from errno.h. */167 static inline int bithenge_scope_set_param( bithenge_scope_t *scope, int i,168 bithenge_node_t *node)169 {170 assert(scope);171 assert(i >= 0 && i < scope->num_params);172 scope->params[i] = node;173 return EOK;174 }175 176 /** Get a parameter. Note that range checking is not done in release builds.177 * @param scope The scope to get the parameter from.178 * @param i The index of the parameter to set.179 * @param[out] out Stores a new reference to the parameter.180 * @return EOK on success or an error code from errno.h. */181 static inline int bithenge_scope_get_param(bithenge_scope_t *scope, int i,182 bithenge_node_t **out)183 {184 assert(scope);185 assert(i >= 0 && i < scope->num_params);186 *out = scope->params[i];187 bithenge_node_inc_ref(*out);188 return EOK;189 }190 191 78 /** Get the number of parameters required by a transform. This number is used 192 79 * by the parser and param-wrapper. Takes ownership of nothing. … … 245 132 int bithenge_transform_prefix_apply(bithenge_transform_t *, bithenge_scope_t *, 246 133 bithenge_blob_t *, bithenge_node_t **, aoff64_t *); 247 int bithenge_new_ param_transform(bithenge_transform_t **,134 int bithenge_new_scope_transform(bithenge_transform_t **, 248 135 bithenge_transform_t *, int); 249 136 int bithenge_new_struct(bithenge_transform_t **, … … 252 139 bithenge_transform_t **, size_t); 253 140 141 void bithenge_scope_init(bithenge_scope_t *); 142 void bithenge_scope_destroy(bithenge_scope_t *); 143 int bithenge_scope_copy(bithenge_scope_t *, bithenge_scope_t *); 144 void bithenge_scope_set_current_node(bithenge_scope_t *, bithenge_node_t *); 145 bithenge_node_t *bithenge_scope_get_current_node(bithenge_scope_t *); 146 int bithenge_scope_alloc_params(bithenge_scope_t *, int); 147 int bithenge_scope_set_param(bithenge_scope_t *, int, bithenge_node_t *); 148 int bithenge_scope_get_param(bithenge_scope_t *, int, bithenge_node_t **); 149 254 150 #endif 255 151
Note:
See TracChangeset
for help on using the changeset viewer.