summaryrefslogtreecommitdiffstats
path: root/src/mercury/include/mercury_proc_string.h
blob: 764eb20167e1a97b52f6d679f84c7c6ac4b93629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (C) 2013-2020 Argonne National Laboratory, Department of Energy,
 *                    UChicago Argonne, LLC and The HDF Group.
 * All rights reserved.
 *
 * The full copyright notice, including terms governing use, modification,
 * and redistribution, is contained in the COPYING file that can be
 * found at the root of the source code distribution tree.
 */

#ifndef MERCURY_PROC_STRING_H
#define MERCURY_PROC_STRING_H

#include "mercury_proc.h"
#include "mercury_string_object.h"

/*************************************/
/* Public Type and Struct Definition */
/*************************************/

typedef const char *hg_const_string_t;
typedef char *      hg_string_t;

/*****************/
/* Public Macros */
/*****************/

/*********************/
/* Public Prototypes */
/*********************/

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Generic processing routine.
 *
 * \param proc [IN/OUT]         abstract processor object
 * \param data [IN/OUT]         pointer to data
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
static HG_INLINE hg_return_t hg_proc_hg_const_string_t(hg_proc_t proc, void *data);

/**
 * Generic processing routine.
 *
 * \param proc [IN/OUT]         abstract processor object
 * \param data [IN/OUT]         pointer to data
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
static HG_INLINE hg_return_t hg_proc_hg_string_t(hg_proc_t proc, void *data);

/**
 * Generic processing routine.
 *
 * \param proc [IN/OUT]         abstract processor object
 * \param string [IN/OUT]       pointer to string
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
HG_PUBLIC hg_return_t hg_proc_hg_string_object_t(hg_proc_t proc, void *string);

/************************************/
/* Local Type and Struct Definition */
/************************************/

/*---------------------------------------------------------------------------*/
static HG_INLINE hg_return_t
hg_proc_hg_const_string_t(hg_proc_t proc, void *data)
{
    hg_string_object_t string;
    hg_const_string_t *strdata = (hg_const_string_t *)data;
    hg_return_t        ret     = HG_SUCCESS;

    switch (hg_proc_get_op(proc)) {
        case HG_ENCODE:
            hg_string_object_init_const_char(&string, *strdata, 0);
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            hg_string_object_free(&string);
            break;
        case HG_DECODE:
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            *strdata = hg_string_object_swap(&string, 0);
            hg_string_object_free(&string);
            break;
        case HG_FREE:
            hg_string_object_init_const_char(&string, *strdata, 1);
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            break;
        default:
            break;
    }

done:
    return ret;
}

/*---------------------------------------------------------------------------*/
static HG_INLINE hg_return_t
hg_proc_hg_string_t(hg_proc_t proc, void *data)
{
    hg_string_object_t string;
    hg_string_t *      strdata = (hg_string_t *)data;
    hg_return_t        ret     = HG_SUCCESS;

    switch (hg_proc_get_op(proc)) {
        case HG_ENCODE:
            hg_string_object_init_char(&string, *strdata, 0);
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            hg_string_object_free(&string);
            break;
        case HG_DECODE:
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            *strdata = hg_string_object_swap(&string, 0);
            hg_string_object_free(&string);
            break;
        case HG_FREE:
            hg_string_object_init_char(&string, *strdata, 1);
            ret = hg_proc_hg_string_object_t(proc, &string);
            if (ret != HG_SUCCESS)
                goto done;
            break;
        default:
            break;
    }

done:
    return ret;
}

#ifdef __cplusplus
}
#endif

#endif /* MERCURY_PROC_STRING_H */