librnr  1.14.5
RoadNarrows Robotics Common Library 1
dliststr.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 /*! \file
3  *
4  * \brief Doubly linked list of character strings "inherited" from dlistvoid.
5  *
6  * \pkgsynopsis
7  * RoadNarrows Robotics Common Library 1
8  *
9  * \pkgcomponent{Library}
10  * librnr
11  *
12  * \pkgfile{rnr/dliststr.h}
13  *
14  * \author Robin Knight (robin.knight@roadnarrows.com)
15  *
16  * \pkgcopyright{2005-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
17  *
18  * \license{MIT}
19  *
20  * \EulaBegin
21  * See the README and EULA files for any copyright and licensing information.
22  * \EulaEnd
23  */
24 ////////////////////////////////////////////////////////////////////////////////
25 
26 #ifndef _RNR_DLISTSTR_H
27 #define _RNR_DLISTSTR_H
28 
29 #include <stdio.h>
30 #include <string.h>
31 
32 #include "rnr/new.h"
33 
34 #define DLIST_DNAME Str ///< dlist namespace name
35 #define DLIST_DTYPE char ///< dlist data type
36 
37 #include "rnr/dlistvoid.h"
38 
40 
41 
42 /*!
43  * \brief Node data comparator callback.
44  *
45  * \param sData1 Node 1 string data.
46  * \param sData2 Node 2 string data.
47  *
48  * \return Returns <0, 0, or >0 if pData1 is less than, equal, or greater than
49  * pData2, respectively.
50  */
51 static inline int DListStrDataCmp(const char *sData1, const char *sData2)
52 {
53  return strcmp(sData1, sData2);
54 }
55 
56 /*!
57  * \brief Node data delete callback.
58  *
59  * \param sData Node string data.
60  */
61 static inline void DListStrDataDelete(char *sData)
62 {
63  delete(sData);
64 }
65 
66 /*!
67  * \brief Print node data callback.
68  *
69  * \param fp File stream pointer.
70  * \param sData Node string data.
71  *
72  * \sa DListVoidPrint()
73  */
74 static inline void DListStrDataPrint(FILE *fp, char *sData)
75 {
76  if( sData != NULL )
77  {
78  fprintf(fp, "%s", sData);
79  }
80 }
81 
82 /*!
83  * \brief Allocator and initializer new empty string dlist with default
84  * callbacks.
85  *
86  * Default user string comparator function is strcmp().
87  * Default string data deallocator function is delete().
88  *
89  * \return Returns pointer to new dlist (head) on success.
90  */
91 static inline DListStr_T *DListStrNewDft()
92 {
93  return DListStrNew(DListStrDataCmp, DListStrDataDelete);
94 }
95 
97 
98 
99 #endif // _RNR_DLISTSTR_H
static void DListStrDataDelete(char *sData)
Node data delete callback.
Definition: dliststr.h:61
static int DListStrDataCmp(const char *sData1, const char *sData2)
Node data comparator callback.
Definition: dliststr.h:51
#define NULL
null pointer
Definition: rnrconfig.h:199
Memory allocation and deallocation declarations.
#define C_DECLS_BEGIN
C declaration block begin in C.
Definition: rnrconfig.h:71
Doubly linked list (dlist) of data pointers #defines, types, and declarations.
#define C_DECLS_END
C declaration block end in C.
Definition: rnrconfig.h:72
static DListStr_T * DListStrNewDft()
Allocator and initializer new empty string dlist with default callbacks.
Definition: dliststr.h:91
static void DListStrDataPrint(FILE *fp, char *sData)
Print node data callback.
Definition: dliststr.h:74