Changeset 5a7c0e6 in mainline for uspace/app/bithenge/transform.h
- Timestamp:
- 2012-07-27T01:09:05Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6e34bd0
- Parents:
- 43788b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.h
r43788b2 r5a7c0e6 51 51 typedef struct { 52 52 /** @privatesection */ 53 } bithenge_transform_context_t; 53 bithenge_node_t **params; 54 int num_params; 55 } bithenge_scope_t; 54 56 55 57 /** Operations that may be provided by a transform. */ 56 58 typedef struct bithenge_transform_ops { 57 59 /** @copydoc bithenge_transform_t::bithenge_transform_apply */ 58 int (*apply)(bithenge_transform_t *self, 59 bithenge_transform_context_t *context, bithenge_node_t *in, 60 bithenge_node_t **out); 60 int (*apply)(bithenge_transform_t *self, bithenge_scope_t *scope, 61 bithenge_node_t *in, bithenge_node_t **out); 61 62 /** @copydoc bithenge_transform_t::bithenge_transform_prefix_length */ 62 63 int (*prefix_length)(bithenge_transform_t *self, 63 bithenge_transform_context_t *context, bithenge_blob_t *blob, 64 aoff64_t *out); 64 bithenge_scope_t *scope, bithenge_blob_t *blob, aoff64_t *out); 65 65 /** Destroy the transform. 66 66 * @param self The transform. */ 67 67 void (*destroy)(bithenge_transform_t *self); 68 /** The number of parameters required. */ 69 int num_params; 68 70 } bithenge_transform_ops_t; 69 71 70 /** Initialize a transform context. It must be destroyed with @a 71 * bithenge_transform_context_destroy after it is used. 72 * @param[out] context The context to initialize. */ 73 static inline void bithenge_transform_context_init( 74 bithenge_transform_context_t *context) 75 { 76 } 77 78 /** Destroy a transform context. 79 * @param context The context to destroy. 80 * @return EOK on success or an error code from errno.h. */ 81 static inline void bithenge_transform_context_destroy( 82 bithenge_transform_context_t *context) 83 { 72 /** Initialize a transform scope. It must be destroyed with @a 73 * bithenge_scope_destroy after it is used. 74 * @param[out] scope The scope to initialize. */ 75 static inline void bithenge_scope_init(bithenge_scope_t *scope) 76 { 77 scope->params = NULL; 78 scope->num_params = 0; 79 } 80 81 /** Destroy a transform scope. 82 * @param scope The scope to destroy. 83 * @return EOK on success or an error code from errno.h. */ 84 static inline void bithenge_scope_destroy(bithenge_scope_t *scope) 85 { 86 for (int i = 0; i < scope->num_params; i++) 87 bithenge_node_dec_ref(scope->params[i]); 88 free(scope->params); 89 } 90 91 /** Allocate parameters. The parameters must then be set with @a 92 * bithenge_scope_set_param. 93 * @param scope The scope in which to allocate parameters. 94 * @param num_params The number of parameters to allocate. 95 * @return EOK on success or an error code from errno.h. */ 96 static inline int bithenge_scope_alloc_params(bithenge_scope_t *scope, 97 int num_params) 98 { 99 scope->params = malloc(sizeof(*scope->params) * num_params); 100 if (!scope->params) 101 return ENOMEM; 102 scope->num_params = num_params; 103 return EOK; 104 } 105 106 /** Set a parameter. Takes a reference to @a value. Note that range checking is 107 * not done in release builds. 108 * @param scope The scope in which to allocate parameters. 109 * @param i The index of the parameter to set. 110 * @param value The value to store in the parameter. 111 * @return EOK on success or an error code from errno.h. */ 112 static inline int bithenge_scope_set_param( bithenge_scope_t *scope, int i, 113 bithenge_node_t *node) 114 { 115 assert(scope); 116 assert(i >= 0 && i < scope->num_params); 117 scope->params[i] = node; 118 return EOK; 119 } 120 121 /** Get a parameter. Note that range checking is not done in release builds. 122 * @param scope The scope to get the parameter from. 123 * @param i The index of the parameter to set. 124 * @param[out] out Stores a new reference to the parameter. 125 * @return EOK on success or an error code from errno.h. */ 126 static inline int bithenge_scope_get_param(bithenge_scope_t *scope, int i, 127 bithenge_node_t **out) 128 { 129 assert(scope); 130 assert(i >= 0 && i < scope->num_params); 131 *out = scope->params[i]; 132 bithenge_node_inc_ref(*out); 133 return EOK; 134 } 135 136 /** Get the number of parameters required by a transform. Takes ownership of 137 * nothing. 138 * @param self The transform. 139 * @return The number of parameters required. */ 140 static inline int bithenge_transform_num_params(bithenge_transform_t *self) 141 { 142 assert(self); 143 assert(self->ops); 144 return self->ops->num_params; 84 145 } 85 146 … … 87 148 * @memberof bithenge_transform_t 88 149 * @param self The transform. 89 * @param context The context.150 * @param scope The scope. 90 151 * @param in The input tree. 91 152 * @param[out] out Where the output tree will be stored. 92 153 * @return EOK on success or an error code from errno.h. */ 93 154 static inline int bithenge_transform_apply(bithenge_transform_t *self, 94 bithenge_transform_context_t *context, bithenge_node_t *in, 95 bithenge_node_t **out) 96 { 97 assert(self); 98 assert(self->ops); 99 return self->ops->apply(self, context, in, out); 155 bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out) 156 { 157 assert(self); 158 assert(self->ops); 159 return self->ops->apply(self, scope, in, out); 100 160 } 101 161 … … 106 166 * @memberof bithenge_transform_t 107 167 * @param self The transform. 108 * @param context The context.168 * @param scope The scope. 109 169 * @param blob The blob. 110 170 * @param[out] out Where the prefix length will be stored. … … 112 172 * errno.h. */ 113 173 static inline int bithenge_transform_prefix_length(bithenge_transform_t *self, 114 bithenge_transform_context_t *context, bithenge_blob_t *blob, 115 aoff64_t *out) 174 bithenge_scope_t *scope, bithenge_blob_t *blob, aoff64_t *out) 116 175 { 117 176 assert(self); … … 119 178 if (!self->ops->prefix_length) 120 179 return ENOTSUP; 121 return self->ops->prefix_length(self, context, blob, out);180 return self->ops->prefix_length(self, scope, blob, out); 122 181 } 123 182
Note:
See TracChangeset
for help on using the changeset viewer.