Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
dynashell_util.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Program: dynashell
6 //
7 // File: dynashell_util.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-01-12 10:56:06 -0700 (Mon, 12 Jan 2015) $
12  * $Rev: 3845 $
13  *
14  * \brief Dynamixel shell utilities.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2011-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _DYNASHELL_UTIL_H
50 #define _DYNASHELL_UTIL_H
51 
52 #include <stdio.h>
53 
54 #include <cstring>
55 #include <iostream>
56 #include <fstream>
57 #include <vector>
58 
59 #include "rnr/rnrconfig.h"
60 #include "rnr/opts.h"
61 #include "rnr/log.h"
62 
63 #include "Dynamixel/Dynamixel.h"
64 #include "Dynamixel/DynaComm.h"
65 #include "Dynamixel/DynaChain.h"
66 
67 using namespace std;
68 
69 
70 // ----------------------------------------------------------------------------
71 // Macros and Types
72 // ----------------------------------------------------------------------------
73 
74 /*!
75  * \brief Allocate a new duplicated string convenience macro.
76  *
77  * \param s The null-terminated string to duplicate.
78  *
79  * \return Returns pointer to allocated string if s is not NULL and the
80  * length of s \h_gt 0.\n Otherwise returns NULL.
81  */
82 #define NEWSTR(s) newstr(s)
83 
84 /*!
85  * \brief Delete an allocated string convenience macro.
86  *
87  * The value s is set to NULL after deletion.
88  *
89  * \param s Pointer to the string to delete.
90  */
91 #define DELSTR(s) do { if( s != NULL ) { delstr(s); s = NULL; } } while(0)
92 
93 /*!
94  * \brief Delete an allocated object convenience macro.
95  *
96  * The value p is set to NULL after deletion.
97  *
98  * \param p Pointer to the object to delete.
99  */
100 #define DELOBJ(p) do { if( p != NULL ) { delete p; p = NULL; } } while(0)
101 
102 
103 // ----------------------------------------------------------------------------
104 // Function Prototypes
105 // ----------------------------------------------------------------------------
106 
107 /*!
108  * \brief Allocate a new duplicated string utility.
109  *
110  * \param s String to duplicate.
111  *
112  * \return Returns pointer to allocated string if s is not NULL and the
113  * length of s \h_gt 0.\n Otherwise returns NULL.
114  */
115 inline char *newstr(const char *s)
116 {
117  char *t;
118  if( (s != NULL) && (*s != 0) )
119  {
120  t = new char[strlen(s)+1];
121  strcpy(t, s);
122  }
123  else
124  {
125  t = NULL;
126  }
127  return t;
128 }
129 
130 /*!
131  * \brief A safer string delete utility.
132  *
133  * \param s String to delete.
134  */
135 inline void delstr(const char *s)
136 {
137  if( s != NULL )
138  {
139  delete[] (char *)s;
140  }
141 }
142 
143 #endif // _DYNASHELL_UTIL_H
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
Definition: t.py:1
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
void delstr(const char *s)
A safer string delete utility.
RoadNarrows Dynamixel Top-Level Package Header File.
char * newstr(const char *s)
Allocate a new duplicated string utility.