1 /* _______________________________________________________________________ 2 3 Surfpack: A Software Library of Multidimensional Surface Fitting Methods 4 Copyright (c) 2006, Sandia National Laboratories. 5 This software is distributed under the GNU Lesser General Public License. 6 For more information, see the README file in the top Surfpack directory. 7 _______________________________________________________________________ */ 8 9 10 #include "surfpack_system_headers.h" 11 #include "AxesBounds.h" 12 #include "SurfpackParser.h" 13 class SurfData; 14 class ParsedCommand; 15 class SurfpackParser; 16 class SurfpackModel; 17 18 class SurfpackInterpreter 19 { 20 public: 21 SurfpackInterpreter(); 22 ~SurfpackInterpreter(); 23 void execute(const std::string* input_string = 0, 24 const std::string* output_string = 0); 25 void commandLoop(std::ostream& os = std::cout, std::ostream& es = std::cerr); 26 void execCreateAxes(ParamMap& args); 27 void execCreateSample(ParamMap& args); 28 void execCreateSurface(ParamMap& args); 29 void execEvaluate(ParamMap& args); 30 void execFitness(ParamMap& args); 31 void execLoad(ParamMap& args); 32 void execLoadData(ParamMap& args); 33 void execLoadSurface(ParamMap& args); 34 void execSave(ParamMap& args); 35 void execSaveData(ParamMap& args); 36 void execSaveSurface(const SurfpackModel* model, const std::string& filename); 37 void execShellCommand(ParamMap& args); 38 39 ///\todo Collapse all of these conversion functions into one template function 40 static int asInt(const std::string& arg); 41 static std::string asStr(const std::string& arg); 42 static double asDbl(const std::string& arg); 43 static VecUns asVecUns(const std::string& arg); 44 static VecStr asVecStr(const std::string& arg); 45 static int asInt(const std::string& arg, bool& valid); 46 static std::string asStr(const std::string& arg, bool& valid); 47 static double asDbl(const std::string& arg, bool& valid); 48 static VecUns asVecUns(const std::string& arg, bool& valid); 49 static VecStr asVecStr(const std::string& arg, bool& valid); 50 protected: 51 class command_error 52 { 53 public: 54 command_error(const std::string& msg_in = "", 55 const std::string& cmdstring_in = "") msg(msg_in)56 : msg(msg_in), cmdstring(cmdstring_in) {} print()57 void print() { std::cerr << "Error in " << cmdstring << ": " 58 << msg << std::endl; } 59 protected: 60 std::string msg; 61 std::string cmdstring; 62 }; 63 public: 64 typedef std::pair<std::string, SurfData*> SurfDataSymbol; 65 typedef std::map<std::string, SurfData*> SurfDataMap; 66 typedef std::pair<std::string, AxesBounds*> AxesBoundsSymbol; 67 typedef std::map<std::string, AxesBounds*> AxesBoundsMap; 68 typedef std::pair<std::string, SurfpackModel*> SurfpackModelSymbol; 69 typedef std::map<std::string, SurfpackModel*> SurfpackModelMap; 70 71 private: 72 struct SymbolTable 73 { 74 SurfDataMap dataVars; 75 SurfpackModelMap modelVars; 76 AxesBoundsMap axesVars; 77 ~SymbolTable(); 78 SurfpackModel* lookupModel(const std::string); 79 SurfData* lookupData(const std::string); 80 AxesBounds* lookupAxes(const std::string); 81 }; 82 83 struct SymbolTable symbolTable; 84 SurfpackParser& parser; 85 }; 86 87