Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_memory.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Memory
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_MEMORY_H__
10 #define __AFW_MEMORY_H__
11 
12 
22 #include "afw_minimal.h"
23 
30 
39 #define afw_memory_copy(to, from) \
40 memcpy((to), (from), sizeof(*(to)))
41 
42 
47 #define afw_memory_clear(to) \
48 memset((to), 0, sizeof(*(to)))
49 
50 
51 
60 AFW_DEFINE_STATIC_INLINE(const afw_memory_t *)
62  const afw_byte_t *ptr,
63  afw_size_t size,
64  const afw_pool_t *p,
65  afw_xctx_t *xctx)
66 {
67  afw_memory_t *result;
68 
69  result = afw_pool_malloc_type(p, afw_memory_t, xctx);
70  result->ptr = ptr;
71  result->size = size;
72  return result;
73 }
74 
75 
76 
87 AFW_DEFINE_STATIC_INLINE(void *)
88 afw_memory_dup(const void *from,
89  apr_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
90 {
91  void *result;
92 
93  if (size == 0) return NULL;
94  result = afw_pool_malloc(p, size, xctx);
95  memcpy(result, from, size);
96  return result;
97 }
98 
99 
100 
102 typedef struct {
103  const afw_pool_t *p; /* Temporary pool used by memory writer. */
104  void *context; /* Context to pass to callback. */
105  afw_write_cb_t callback; /* Write callback function. */
107 
108 
109 
117 AFW_DECLARE(void)
118 afw_memory_encode_base64(afw_utf8_t *encoded, const afw_memory_t *memory,
119  const afw_pool_t *p, afw_xctx_t *xctx);
120 
121 
122 
130 AFW_DECLARE(void)
132  afw_memory_t *memory,
133  const afw_utf8_t *encoded,
134  const afw_pool_t *p, afw_xctx_t *xctx);
135 
136 
137 
145 AFW_DECLARE(void)
147  afw_utf8_t *encoded,
148  const afw_memory_t *memory,
149  const afw_pool_t *p, afw_xctx_t *xctx);
150 
151 
152 
160 AFW_DECLARE(void)
162  afw_memory_t *memory,
163  const afw_utf8_t *encoded,
164  const afw_pool_t *p, afw_xctx_t *xctx);
165 
166 
167 
176  const afw_pool_t *p, afw_xctx_t *xctx);
177 
178 
188  const afw_memory_writer_t *writer, afw_xctx_t *xctx);
189 
190 
191 
202  const afw_memory_writer_t *writer,
203  void *context,
204  afw_write_cb_t callback,
205  afw_xctx_t *xctx);
206 
207 
208 
215 AFW_DECLARE(const afw_memory_t *)
217  const afw_memory_writer_t *writer, afw_xctx_t *xctx);
218 
219 
220 AFW_END_DECLARES
221 
224 #endif /* __AFW_MEMORY_H__ */
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Adaptive Framework Minimal Header.
unsigned char afw_byte_t
A byte of memory (unsigned).
Definition: afw_common.h:208
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
Definition: afw_common.h:1226
void afw_memory_decode_base64(afw_memory_t *memory, const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode memory to a base64 string.
Definition: afw_memory.c:223
afw_size_t afw_memory_writer_retrieve_using_callback_and_release(const afw_memory_writer_t *writer, void *context, afw_write_cb_t callback, afw_xctx_t *xctx)
Retrieve memory as using callback.
Definition: afw_memory.c:418
void afw_memory_encode_printable_hex(afw_utf8_t *encoded, const afw_memory_t *memory, const afw_pool_t *p, afw_xctx_t *xctx)
Encode memory to a printable hex string.
Definition: afw_memory.c:310
afw_size_t afw_memory_writer_get_current_size(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
Definition: afw_memory.c:401
const afw_memory_t * afw_memory_writer_retrieve_and_release(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
Definition: afw_memory.c:441
void afw_memory_encode_base64(afw_utf8_t *encoded, const afw_memory_t *memory, const afw_pool_t *p, afw_xctx_t *xctx)
Encode memory to as base64 string.
Definition: afw_memory.c:185
const afw_memory_writer_t * afw_memory_create_writer(const afw_pool_t *p, afw_xctx_t *xctx)
Create a memory writer.
Definition: afw_memory.c:377
const afw_memory_t * afw_memory_create(const afw_byte_t *ptr, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Create a afw_memory_t struct for a ptr and size.
Definition: afw_memory.h:61
void afw_memory_decode_printable_hex(afw_memory_t *memory, const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode memory to a printable hex string.
Definition: afw_memory.c:337
void * afw_memory_dup(const void *from, apr_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Duplicate a block of memory into specified pool.
Definition: afw_memory.h:88
#define afw_pool_malloc(instance, size, xctx)
Call method malloc of interface afw_pool.
#define afw_pool_malloc_type(instance, type, xctx)
Macro to allocate uncleared memory to hold type in pool.
Definition: afw_pool.h:182
Struct for memory pointer and size.
Definition: afw_common.h:505
Return value from afw_memory_create_writer().
Definition: afw_memory.h:102
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.