Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ippCommandParser.h

Go to the documentation of this file.
00001 // 
00002 // DISCLAIMER: 
00003 //  This software was produced by the National Institute of Standards 
00004 //  and Technology (NIST), an agency of the U.S. government, and by statute is 
00005 //  not subject to copyright in the United States.  Recipients of this 
00006 //  software assume all responsibility associated with its operation,
00007 //  modification,maintenance, and subsequent redistribution. 
00008 //
00009 //  See NIST Administration Manual 4.09.07 b and Appendix I. 
00010 #pragma once 
00011 
00012 
00013 
00014 #define INITARGS 64
00015 
00016 #include "ippdme/ippCommandNameType.h"
00017 #include "ippdme/ippTag.h"
00018 #include "ippdme/ippErrorNameType.h"
00019 #include "ippdme/Command/ippCommand.h"
00020 #include "ippdme/Parser/ippParserCmdErrorId.h"
00021 #include <vector>
00022 #include <string>
00023 
00024 /* argItemType
00025 
00026 argItemType is an enumeration of the types of component that may be in
00027 an argument list.  Periods, commas, empty parentheses, and parentheses
00028 with doubles in them are included, as well as etags, keywords,
00029 doubles, ints, and strings.  
00030 
00031 Example 1. For the command GoTo(X(20), Y(15)), there are five argument
00032 components, and the types are:
00033 ARGKEYWORD, ARGPARENDOUBLE, ARGCOMMA, ARGKEYWORD, ARGPARENDOUBLE.
00034 
00035 Example 2. For the command OnPtMeasReport(X(), Y(), Z()) there are eight
00036 argument components, and the types are: ARGKEYWORD, ARGPARENEMPTY, ARGCOMMA,
00037 ARGKEYWORD, ARGPARENEMPTY, ARGCOMMA, ARGKEYWORD, ARGPARENEMPTY.
00038 
00039 Example 3. For the command GetProp(Tool.PtMeasPar.Accel()), there are six
00040 argument components, and the types are:
00041 ARGKEYWORD, ARGDOT, ARGKEYWORD, ARGDOT, ARGKEYWORD, ARGPARENEMPTY.
00042 
00043 The ARGETAG type appears correctly only as the argument to StopDaemon.
00044 
00045 The ARGIJK type appears correctly only as an argument to PtMeas.
00046 
00047 The ARGINT type is not defined. Where a number must be an integer (as
00048 in several scan commands), it is read as a double and later checked
00049 for being an integer.
00050 
00051 */
00052 
00053 typedef enum ippArgItemType {
00054   ARGCOMMA      = ',', 
00055   ARGDOT        = '.',
00056   ARGDOUBLE     = '#',
00057   ARGETAG       = 't', 
00058   ARGIJK        = 'v',
00059   ARGKEYWORD    = 'k',
00060   ARGPARENEMPTY = 'E',
00061   ARGPARENDOUBLE ='D',
00062   ARGSTRING      ='s',
00063 };
00064 
00065 /*******************************************************************/
00066 
00067 /* parserCmd
00068 
00069 To use the parser, the setInput() method must first be called to copy an
00070 input string into the parser's inputArray. An alternative would be to
00071 have a string as an argument to the parseXXX methods. Copying to
00072 inputArray takes time, but it prevents the parser from messing up the
00073 original string.
00074 
00075 parseTag() parses the tag, and sets the parser's isEvent, tag,
00076 tagType, and errorCode.  It is intended that if getParserErr() is OK
00077 (no error in the tag) following the call to parseTag(), the caller
00078 will:
00079 
00080 1. check that the tag returned by getTag() is not in use.
00081 2. call getIsEvent() to determine if the tag is an event tag.
00082 3. put the command string on fast queue or the slow queue of the world.
00083 
00084 When it is time to execute a command string (because it is at the head
00085 of a queue), parseCommand() should be called to parse the command
00086 string and build an instance of a command.
00087 
00088 After calling parseCommand(), the caller should call getParserErr()
00089 to see if there was an error. If the returned error code is not OK,
00090 the caller can call getErrorMessageString(buffer) to get an error message
00091 that describes the error. The buffer should be at least 100 chars long.
00092 If no error occurs until after the name of the command is parsed, the
00093 name of the command is given at the beginning of the error message.
00094 
00095 If the error code is OK, the caller can start processing the ippCommand
00096 instance.
00097 
00098 */
00099 class ippCommand;
00100 
00101 EXPIMP_TEMPLATE template class IPPDME_EXT_CLASS std::allocator<ippArgItemType>;
00102 EXPIMP_TEMPLATE template class IPPDME_EXT_CLASS std::vector<ippArgItemType>;
00103 EXPIMP_TEMPLATE template class IPPDME_EXT_CLASS std::allocator<ippOtherKeyType>;
00104 EXPIMP_TEMPLATE template class IPPDME_EXT_CLASS std::vector<ippOtherKeyType>;
00105 
00106 class IPPDME_EXT_CLASS ippCommandParser
00107 {
00108 public:
00109   // constructor
00110   ippCommandParser();
00111 
00112   // destructor
00113   virtual ~ippCommandParser();
00114 
00115   // @return  the error message associated with the latest error found during parsing
00116   std::string getErrorMessageString() const; // might add length argument
00117 
00118 
00119   bool getIsEvent() const {return _isEvent;}
00120 
00121   ippParserCmdErrorId getParserErr()const{return _errorCode;}
00122   
00123   void parseTag();
00124   int getTag() const{return _tag;}
00125   
00126   // @return the parsed commend or a null pointer if the parsing has failed
00127   ippCommandPtr  parseCommand();
00128   
00131   void setInput(const char * input);
00132 
00133   
00134 private:
00135 
00136   int _argCount;                         //<! number of argument components
00137   std::vector<double>  _argDoubles;       //<! array of doubles for arguments
00138   unsigned int _argInt;                  //<! used only for tag numbers
00139   std::vector<ippOtherKeyType> _argKeywords;         //<! array of keywords for arguments
00140   int _argSize;                          //<! size of argDoubles, argKeywords, etc. 
00141   std::vector<std::string> _argStrings;  //<! array of pointers to strings for arguments
00142   std::vector<ippArgItemType> _argTypes; //<! array of argument types
00143   int _arrayIndex;                       //<! current index for inputArray
00144   ippCommandNameType _commandName;       //<! enumeration value of command
00145   ippParserCmdErrorId   _errorCode;      //<! parser error code
00146   char _inputArray[IPPSIZE];             //<! array to put command in for parsing
00147   bool _isEvent;                         //<! flag indicating event command
00148   int _tag;                              //<! tag number of command being parsed
00149 
00150 
00151    void makeArraysBigger();
00152 
00153   ippCommandPtr makeCommand();
00154   ippCommandPtr makeAbortE();
00155   ippCommandPtr makeAlignPart();
00156   ippCommandPtr makeAlignTool();
00157   ippCommandPtr makeCenterPart();
00158   ippCommandPtr makeChangeTool();
00159   ippCommandPtr makeClearAllErrors();
00160   ippCommandPtr makeDisableUser();
00161   ippCommandPtr makeEnableUser();
00162   ippCommandPtr makeEndSession();
00163   ippCommandPtr makeEnumAllProp();
00164   ippCommandPtr makeEnumProp();
00165   ippCommandPtr makeEnumTools();
00166   ippCommandPtr makeFindTool();
00167   ippCommandPtr makeGet();
00168   ippCommandPtr makeGetChangeToolAction();
00169   ippCommandPtr makeGetCoordSystem();
00170   ippCommandPtr makeGetCsyTransformation();
00171   ippCommandPtr makeGetDMEVersion();
00172   ippCommandPtr makeGetErrorInfo();
00173   ippCommandPtr makeGetErrStatusE();
00174   ippCommandPtr makeGetMachineClass();
00175   ippCommandPtr makeGetProp();
00176   ippCommandPtr makeGetPropE();
00177   ippCommandPtr makeGetXtdErrStatus();
00178   ippCommandPtr makeGoTo();
00179   ippCommandPtr makeHome();
00180   ippCommandPtr makeIsHomed();
00181   ippCommandPtr makeIsUserEnabled();
00182   ippCommandPtr makeLockAxis();
00183   ippCommandPtr makeOnMoveReportE();
00184   ippCommandPtr makeOnPtMeasReport();
00185   ippCommandPtr makeOnScanReport();
00186   ippCommandPtr makePtMeas();
00187   ippCommandPtr makeReQualify();
00188   ippCommandPtr makeScanInCylEndIsPlane();
00189   ippCommandPtr makeScanInCylEndIsSphere();
00190   ippCommandPtr makeScanInPlaneEndIsCyl();
00191   ippCommandPtr makeScanInPlaneEndIsPlane();
00192   ippCommandPtr makeScanInPlaneEndIsSphere();
00193   ippCommandPtr makeScanOnCircle();
00194   ippCommandPtr makeScanOnCircleHint();
00195   ippCommandPtr makeScanOnLine();
00196   ippCommandPtr makeScanOnLineHint();
00197   ippCommandPtr makeScanUnknownHint();
00198   ippCommandPtr makeScanUnknownDensity();
00199   ippCommandPtr makeSetCoordSystem();
00200   ippCommandPtr makeSetCsyTransformation();
00201   ippCommandPtr makeSetProp();
00202   ippCommandPtr makeSetTool();
00203   ippCommandPtr makeStartSession();
00204   ippCommandPtr makeStopAllDaemons();
00205   ippCommandPtr makeStopDaemon();
00206   ippCommandPtr makeTiltCenterPart();
00207   ippCommandPtr makeTiltPart();
00208 
00209   ippCommandPtr makeEnumToolCollection();
00210   ippCommandPtr makeEnumAllToolCollections();
00211   ippCommandPtr makeOpenToolCollection();
00212   ippCommandPtr makeSaveActiveCoordSystem();
00213   ippCommandPtr makeLoadCoordSystem();
00214   ippCommandPtr makeDeleteCoordSystem();
00215   ippCommandPtr makeEnumCoordSystems();
00216   ippCommandPtr makeGetNamedCsyTransformation();
00217   ippCommandPtr makeSaveNamedCsyTransformation();
00218   ippCommandPtr makeScanOnCurveDensity();
00219   ippCommandPtr makeScanOnCurveHint();
00220   ippCommandPtr makeScanOnCurve();
00221   ippCommandPtr makeScanOnHelix(); 
00222   ippCommandPtr makePtMeasSelfCenter(); 
00223   ippCommandPtr makePtMeasSelfCenterLocked(); 
00224 
00225 
00226   void parseCmdArguments();
00227   void parseCmdName();
00228   void parseData(); // parse a series of numbers
00229   void parseKeyword();
00230   void parseNumber(ippArgItemType type);
00231   void parseString();
00232   void unSpaceInputArray();
00233 
00234 
00235 private:
00236   bool CheckOptionalArgument(
00237     int& n,
00238     bool& hasArgument,
00239     ippOtherKeyType type1,
00240     ippOtherKeyType type2,
00241     ippParserCmdErrorId errorIfDuplicated  
00242   );
00243   bool CheckOptionalArgument(
00244     int& n,
00245     bool& hasArgument,
00246     ippOtherKeyType type,
00247     ippParserCmdErrorId errorIfDuplicated  
00248   );
00249   bool CheckOptionalArgumentValue(
00250     int& n,
00251     bool& hasArgument,
00252     ippOtherKeyType type,
00253     ippParserCmdErrorId errorIfDuplicated,
00254     ippParserCmdErrorId errorIfNotFollowedByNumberInParens,
00255     double& value
00256   );
00257   bool CheckOptionalArgumentValue(
00258     int& n,
00259     bool& hasArgument,
00260     ippOtherKeyType type1,
00261     ippOtherKeyType type2,
00262     ippParserCmdErrorId errorIfDuplicated,
00263     ippParserCmdErrorId errorIfNotFollowedByNumberInParens,
00264     double& value
00265   );
00266   bool CheckOptionalArgumentValue(
00267     int& n,
00268     bool& hasArgument,
00269     ippOtherKeyType type,
00270     ippParserCmdErrorId errorIfDuplicated,
00271     ippParserCmdErrorId errorIfNotFollowedByNumberInParens,
00272     double& valueI,
00273     double& valueJ,
00274     double& valueK
00275   );
00276   bool CheckOptionalArgumentValue(
00277     int& n,
00278     bool& hasArgument,
00279     ippOtherKeyType type1,
00280     ippParserCmdErrorId errorIfDuplicated,
00281     ippParserCmdErrorId errorIfNotFollowedByBooleanInParens,
00282     bool& value
00283   );
00284 
00285   double getValue(int index) const;
00286 
00287 private:
00288   ippCommandParser(const ippCommandParser&);
00289   void operator=(const ippCommandParser&);
00290 };

Generated on Wed Nov 8 00:19:58 2006 for IPPDME by  doxygen 1.4.1