src/stringlist.h
author vb
Wed, 11 Mar 2015 11:52:14 +0100
changeset 98 9e3d28932e7b
child 113 4bee48270834
permissions -rw-r--r--
reorga
vb@98
     1
#pragma once
vb@98
     2
vb@98
     3
#include "dynamic_api.h"
vb@98
     4
vb@98
     5
#ifdef __cplusplus
vb@98
     6
extern "C" {
vb@98
     7
#endif
vb@98
     8
vb@98
     9
vb@98
    10
typedef struct _stringlist_t {
vb@98
    11
    char *value;
vb@98
    12
    struct _stringlist_t *next;
vb@98
    13
} stringlist_t;
vb@98
    14
vb@98
    15
vb@98
    16
// new_stringlist() - allocate a new stringlist
vb@98
    17
//
vb@98
    18
//  parameters:
vb@98
    19
//      value (in)        initial value as C string or NULL for empty list
vb@98
    20
//
vb@98
    21
//  return value:
vb@98
    22
//      pointer to stringlist_t object or NULL if out of memory
vb@98
    23
//
vb@98
    24
//  caveat:
vb@98
    25
//      the value is being copied before being added to the list
vb@98
    26
//      the original string is still being owned by the caller
vb@98
    27
vb@98
    28
DYNAMIC_API stringlist_t *new_stringlist(const char *value);
vb@98
    29
vb@98
    30
vb@98
    31
// stringlist_dup() - duplicate a stringlist
vb@98
    32
//
vb@98
    33
//  parameters:
vb@98
    34
//      src (in)            stringlist to copy
vb@98
    35
//
vb@98
    36
//  return value:
vb@98
    37
//      pointer to stringlist_t object or NULL if out of memory
vb@98
    38
vb@98
    39
DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
vb@98
    40
vb@98
    41
vb@98
    42
// stringlist_add() - add key to stringlist
vb@98
    43
//
vb@98
    44
//  parameters:
vb@98
    45
//      stringlist (in)     stringlist struct or NULL to create a new one
vb@98
    46
//      value (in)          value as C string
vb@98
    47
//
vb@98
    48
//  return value:
vb@98
    49
//      pointer to last element in stringlist or NULL if out of memory
vb@98
    50
//
vb@98
    51
//  caveat:
vb@98
    52
//      the value is being copied before being added to the list
vb@98
    53
//      the original string is still being owned by the caller
vb@98
    54
vb@98
    55
DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
vb@98
    56
vb@98
    57
vb@98
    58
// stringlist_append() - append stringlist to stringlist
vb@98
    59
//
vb@98
    60
//  parameters:
vb@98
    61
//      stringlist (in)     stringlist struct to append to
vb@98
    62
//      second (in)         stringlist struct to append
vb@98
    63
//
vb@98
    64
//  return value:
vb@98
    65
//      pointer to last element in stringlist or NULL if out of memory
vb@98
    66
//
vb@98
    67
//  caveat:
vb@98
    68
//      all values are being copied before being added to the list
vb@98
    69
//      the original values are still being owned by the caller
vb@98
    70
vb@98
    71
DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
vb@98
    72
        stringlist_t *second);
vb@98
    73
vb@98
    74
vb@98
    75
// stringlist_length() - get length of stringlist
vb@98
    76
//
vb@98
    77
//  parameters:
vb@98
    78
//      stringlist (in)     stringlist struct to determine length of
vb@98
    79
//
vb@98
    80
//  return value:
vb@98
    81
//      length of stringlist in number of elements
vb@98
    82
vb@98
    83
DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
vb@98
    84
vb@98
    85
vb@98
    86
// free_stringlist() - free memory occupied by stringlist
vb@98
    87
//
vb@98
    88
//  parameters:
vb@98
    89
//      stringlist (in)    stringlist to free
vb@98
    90
vb@98
    91
DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
vb@98
    92
vb@98
    93
vb@98
    94
#ifdef __cplusplus
vb@98
    95
}
vb@98
    96
#endif
vb@98
    97