appkit  1.5.1
RoadNarrows Robotics Application Kit
CmdCore.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_appkit
8 //
9 // File: CmdCore.h
10 //
11 /*! \file
12  *
13  * \brief Command line core data types.
14  *
15  * \author Robin Knight (robin.knight@roadnarrows.com)
16  *
17  * \par Copyright
18  * \h_copy 2016-2017. RoadNarrows LLC.\n
19  * http://www.roadnarrows.com\n
20  * All Rights Reserved
21  *
22  * \par License:
23  * MIT
24  */
25 /*
26  * @EulaBegin@
27  *
28  * Permission is hereby granted, without written agreement and without
29  * license or royalty fees, to use, copy, modify, and distribute this
30  * software and its documentation for any purpose, provided that
31  * (1) The above copyright notice and the following two paragraphs
32  * appear in all copies of the source code and (2) redistributions
33  * including binaries reproduces these notices in the supporting
34  * documentation. Substantial modifications to this software may be
35  * copyrighted by their authors and need not follow the licensing terms
36  * described here, provided that the new terms are clearly indicated in
37  * all files where they apply.
38  *
39  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
40  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
41  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
42  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
43  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
44  * THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
47  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
48  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
49  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
50  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
51  *
52  * @EulaEnd@
53  */
54 ////////////////////////////////////////////////////////////////////////////////
55 
56 #ifndef _RNR_CMD_CORE_H
57 #define _RNR_CMD_CORE_H
58 
59 #include <stdio.h>
60 #include <unistd.h>
61 #include <stdlib.h>
62 #include <ctype.h>
63 
64 #include <iostream>
65 #include <string>
66 
67 #include <rnr/rnrconfig.h>
68 
69 /*!
70  * \brief RoadNarrows Robotics
71  */
72 namespace rnr
73 {
74  /*!
75  * \brief Commands
76  */
77  namespace cmd
78  {
79  /*!
80  * \brief User available command description structure.
81  *
82  * This structure is provided as a convenience for application development.
83  * It is external to the core CommandLine functionality.
84  */
85  struct CmdDesc
86  {
87  std::string name; ///< command name
88  std::string syntax; ///< parsable command extended usage syntax
89  std::string synopsis; ///< short command synopsis
90  std::string longdesc; ///< long command description
91  };
92 
93  const int AOk = OK; ///< (0) A-Ok, no error, success, good
94 
95  /*!
96  * \defgroup cmd_ecodes Command Error Codes
97  * \{
98  */
99  const int EError = -1; ///< general, unspecified error
100  const int EEoF = -2; ///< end of file
101  const int ERead = -3; ///< read error
102  const int EAmbigCmd = -4; ///< ambiguous command
103  const int EUnknownCmd = -5; ///< unknown, unmatched command
104  const int EBadSyntax = -6; ///< bad syntax
105  const int ENoExec = -7; ///< cannot execute
106  const int EArgv0 = -8; ///< not this command argv0
107  const int ENoOp = -9; ///< no operation
108  const int EBadVal = -10; ///< bad value
109 
110  const int NumOfECodes = 10; ///< number of error codes.
111  /*! \} */
112 
113  /*!
114  * \brief Special values.
115  */
116  const int NoUid = -1; ///< no unique id
117  const int NoIndex = -1; ///< no index
118 
119  /*!
120  * \brief Variable argument symbol names.
121  */
122  const char* const ArgSymLiteral = "literal"; ///< literal constant
123  const char* const ArgSymWord = "word"; ///< non-whitespace seq
124  const char* const ArgSymMultiWord = "multiword"; ///< any sequence
125  const char* const ArgSymIdentifier = "identifier"; ///< identifier
126  const char* const ArgSymBoolean = "bool"; ///< boolean (bool)
127  const char* const ArgSymInteger = "int"; ///< integer (long)
128  const char* const ArgSymFpn = "fpn"; ///< fpn (double)
129  const char* const ArgSymFile = "file"; ///< file path
130  const char* const ArgSymRegEx = "re"; ///< regular expression
131 
132  //
133  // Special string values.
134  //
135  extern const std::string emptystring; ///< "" empty string
136  extern const std::string undefstring; ///< "undef" string
137 
138  /*!
139  * \brief Reserved command line data section namespaces.
140  */
141  const char* const DataSectNsCore = "core"; ///< core data section ns
142  const char* const DataSectNsOS = "os"; ///< OS data section ns
143  const char* const DataSectNsNet = "net"; ///< network data section ns
144 
145  /*!
146  * \brief Core data section type.
147  */
149  {
150  bool m_bQuit; ///< command-line should [not] quit
151  bool m_bBacktrace; ///< do [not] backtrace command line parsing
152 
153  /*!
154  * \brief Default contructor.
155  */
157  {
158  m_bQuit = false;
159  m_bBacktrace = false;
160  }
161 
162  /*!
163  * \brief Deallocate (delete) allocated (new) core data section.
164  *
165  * \param p Pointer to data section object.
166  */
167  static void dealloc(void *p);
168  };
169 
170  /*!
171  * \brief Handy Dandy Name-Value Pair entry structure.
172  */
174  {
175  const char* m_sName; ///< name
176  int m_nValue; ///< value
177  };
178 
179  /*!
180  * \brief Test if string is a valid identifier.
181  *
182  * Identifiers adhere to the C syntax.
183  *
184  * \param [in] str String to test.
185  *
186  * \return Returns true or false.
187  */
188  bool isIdentifier(const std::string &str);
189 
190  } // namespace cmd
191 } // namespace rnr
192 
193 #endif // _RNR_CMD_CORE_H
const char *const ArgSymFpn
fpn (double)
Definition: CmdCore.h:128
const int EUnknownCmd
unknown, unmatched command
Definition: CmdCore.h:103
const int NumOfECodes
number of error codes.
Definition: CmdCore.h:110
std::string name
command name
Definition: CmdCore.h:87
std::string synopsis
short command synopsis
Definition: CmdCore.h:89
const char *const DataSectNsNet
network data section ns
Definition: CmdCore.h:143
const int EAmbigCmd
ambiguous command
Definition: CmdCore.h:102
std::string longdesc
long command description
Definition: CmdCore.h:90
const char *const ArgSymLiteral
Variable argument symbol names.
Definition: CmdCore.h:122
const char *const DataSectNsCore
Reserved command line data section namespaces.
Definition: CmdCore.h:141
const int NoUid
Special values.
Definition: CmdCore.h:116
const int EError
general, unspecified error
Definition: CmdCore.h:99
User available command description structure.
Definition: CmdCore.h:85
const char *const ArgSymFile
file path
Definition: CmdCore.h:129
const char *const ArgSymMultiWord
any sequence
Definition: CmdCore.h:124
const std::string undefstring
"undef" string
const char *const ArgSymIdentifier
identifier
Definition: CmdCore.h:125
const char * m_sName
name
Definition: CmdCore.h:175
const char *const ArgSymRegEx
regular expression
Definition: CmdCore.h:130
const int ENoExec
cannot execute
Definition: CmdCore.h:105
const int ERead
read error
Definition: CmdCore.h:101
const int EBadSyntax
bad syntax
Definition: CmdCore.h:104
const int NoIndex
no index
Definition: CmdCore.h:117
const int AOk
(0) A-Ok, no error, success, good
Definition: CmdCore.h:93
const int EBadVal
bad value
Definition: CmdCore.h:108
DataSectCore()
Default contructor.
Definition: CmdCore.h:156
const char *const DataSectNsOS
OS data section ns.
Definition: CmdCore.h:142
Handy Dandy Name-Value Pair entry structure.
Definition: CmdCore.h:173
const int EArgv0
not this command argv0
Definition: CmdCore.h:106
bool m_bBacktrace
do [not] backtrace command line parsing
Definition: CmdCore.h:151
bool isIdentifier(const std::string &str)
Test if string is a valid identifier.
const char *const ArgSymWord
non-whitespace seq
Definition: CmdCore.h:123
RoadNarrows Robotics.
Definition: Camera.h:74
std::string syntax
parsable command extended usage syntax
Definition: CmdCore.h:88
Core data section type.
Definition: CmdCore.h:148
const char *const ArgSymBoolean
boolean (bool)
Definition: CmdCore.h:126
const char *const ArgSymInteger
integer (long)
Definition: CmdCore.h:127
const int ENoOp
no operation
Definition: CmdCore.h:107
const std::string emptystring
"" empty string
Definition: CmdCore.cxx:82
bool m_bQuit
command-line should [not] quit
Definition: CmdCore.h:150
const int EEoF
end of file
Definition: CmdCore.h:100