librnr  1.14.5
RoadNarrows Robotics Common Library 1
example_dlist.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Common Library 1
4 //
5 // File: example_dlist.h
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2010-03-24 10:19:36 -0600 (Wed, 24 Mar 2010) $
10  * $Rev: 307 $
11  *
12  * \brief Example of a "derived" DListVoid doubly-linked lists.
13  *
14  * \author Robin Knight (robin.knight@roadnarrows.com)
15  *
16  * \pkgcopyright{2007-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
17  */
18 // Permission is hereby granted, without written agreement and without
19 // license or royalty fees, to use, copy, modify, and distribute this
20 // software and its documentation for any purpose, provided that
21 // (1) The above copyright notice and the following two paragraphs
22 // appear in all copies of the source code and (2) redistributions
23 // including binaries reproduces these notices in the supporting
24 // documentation. Substantial modifications to this software may be
25 // copyrighted by their authors and need not follow the licensing terms
26 // described here, provided that the new terms are clearly indicated in
27 // all files where they apply.
28 //
29 // IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
30 // OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
31 // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
32 // DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
33 // EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
34 // THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
37 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
38 // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
39 // "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
40 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
41 //
42 ////////////////////////////////////////////////////////////////////////////////
43 
44 #include <stdio.h>
45 
46 #include "rnr/rnrconfig.h"
47 #include "rnr/new.h"
48 
49 #define DLIST_DNAME Zoo ///< derived dlist name space (i.e. DListZoo<x>)
50 #define DLIST_DTYPE Zoo_T ///< derived dlist user data type
51 
52 /*!
53  * \brief Zoo Type.
54  */
55 typedef struct
56 {
57  int m_nZid; ///< zoo animal unique id
58  const char *m_sSciName; ///< zoo animal scientific name
59  const char *m_sComName; ///< zoo animal common name
60  char *m_sPetName; ///< zoo animal pet (pr) name
61 } Zoo_T;
62 
63 #include "rnr/dlistvoid.h" ///< define "derived" data and functions
64 
65 /*!
66  * \brief Node zoo data comparator callback.
67  *
68  * \param pData1 Zoo node data 1.
69  * \param pData2 Zoo node data 2.
70  *
71  * \returns \h_lt 0, 0, or \h_gt 0 if pData1 is less than, equal to, or greater
72  * than pData2, respectively.
73  */
74 static inline int DListZooDataCmp(const Zoo_T *pData1, const Zoo_T *pData2)
75 {
76  return strcmp(pData1->m_sPetName, pData2->m_sPetName);
77 }
78 
79 /*!
80  * \brief Node zoo data delete callback.
81  *
82  * \param pData Zoo node data.
83  */
84 static inline void DListZooDataDelete(Zoo_T *pData)
85 {
86  delete(pData->m_sPetName);
87  delete(pData);
88 }
89 
90 /*!
91  * \brief Node zoo data print callback.
92  *
93  * \param fp File pointer.
94  * \param pData Zoo node data.
95  */
96 static inline void DListZooDataPrint(FILE *fp, Zoo_T *pData)
97 {
98  if( pData != NULL )
99  {
100  fprintf(fp, "%03d \"%s\": %s (%s)",
101  pData->m_nZid, pData->m_sPetName, pData->m_sSciName, pData->m_sComName);
102  }
103 }
static int DListZooDataCmp(const Zoo_T *pData1, const Zoo_T *pData2)
Node zoo data comparator callback.
Definition: example_dlist.h:74
Zoo Type.
Definition: example_dlist.h:55
static void DListZooDataDelete(Zoo_T *pData)
Node zoo data delete callback.
Definition: example_dlist.h:84
const char * m_sComName
zoo animal common name
Definition: example_dlist.h:59
#define NULL
null pointer
Definition: rnrconfig.h:199
Memory allocation and deallocation declarations.
char * m_sPetName
zoo animal pet (pr) name
Definition: example_dlist.h:60
Doubly linked list (dlist) of data pointers #defines, types, and declarations.
RoadNarrows Robotics common configuration file.
static void DListZooDataPrint(FILE *fp, Zoo_T *pData)
Node zoo data print callback.
Definition: example_dlist.h:96
const char * m_sSciName
zoo animal scientific name
Definition: example_dlist.h:58
int m_nZid
zoo animal unique id
Definition: example_dlist.h:57