[165] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Classe interpreteur de commande pour piapp
|
---|
| 3 | // Reza Aout 97 , Juillet,Aout 98
|
---|
| 4 | // LAL-IN2P3/CNRS
|
---|
| 5 |
|
---|
| 6 | #ifndef PIACMD_H_SEEN
|
---|
| 7 | #define PIACMD_H_SEEN
|
---|
| 8 |
|
---|
[293] | 9 | #include "machdefs.h"
|
---|
| 10 | #include <iostream.h>
|
---|
[165] | 11 | #include <fstream.h>
|
---|
| 12 | #include <string>
|
---|
[293] | 13 | #include <vector>
|
---|
[165] | 14 | #include <map>
|
---|
| 15 | #if defined(__KCC__)
|
---|
| 16 | using std::string ;
|
---|
[293] | 17 | #include <vector.h>
|
---|
[165] | 18 | #include <map.h>
|
---|
| 19 | #endif
|
---|
| 20 |
|
---|
| 21 | #include "dlftypes.h"
|
---|
| 22 |
|
---|
[293] | 23 |
|
---|
| 24 | // Classe definissant l'interface pour un executeur de commande
|
---|
| 25 | class CmdExecutor {
|
---|
| 26 | public:
|
---|
| 27 | virtual ~CmdExecutor() {} ;
|
---|
| 28 | // keyw : Le mot cle associe , args: Arguments de la commande
|
---|
| 29 | virtual int Execute(string& keyw, vector<string>& args)=0;
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | // Classe definissant l'interface pour un interpreteur de commande
|
---|
| 33 | class CmdInterpreter {
|
---|
| 34 | public:
|
---|
| 35 | virtual ~CmdInterpreter() {} ;
|
---|
| 36 | virtual string Name()=0;
|
---|
| 37 | virtual int Interpret(string& line)=0;
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | // Forward declaration of some classes ...
|
---|
[165] | 43 | class NamedObjMgr;
|
---|
| 44 | class PIStdImgApp;
|
---|
[293] | 45 | class Timer;
|
---|
| 46 | class PDynLinkMgr;
|
---|
| 47 | class PIAHelpWind;
|
---|
[165] | 48 |
|
---|
[293] | 49 | // ---------------------------------------------------------------------
|
---|
| 50 | // Classe Interpreteur de commande, gestionnaire de module chargeable,
|
---|
| 51 | // et de fonctions dynamiquement linke pour PIStdImgApp
|
---|
| 52 | // Permet de gerer plusieurs Interpreter differents
|
---|
| 53 | // ---------------------------------------------------------------------
|
---|
[165] | 54 |
|
---|
[330] | 55 | class PIAHelpWind; // Fenetre d'aide en ligne
|
---|
| 56 |
|
---|
[293] | 57 | class PIACmd : public CmdInterpreter {
|
---|
[165] | 58 | public:
|
---|
[293] | 59 | static PIACmd* GetInterpreter();
|
---|
[165] | 60 |
|
---|
[293] | 61 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app);
|
---|
| 62 | virtual ~PIACmd();
|
---|
| 63 | virtual string Name();
|
---|
| 64 |
|
---|
[330] | 65 | virtual void RegisterCommand(string& keyw, string& usage, CmdExecutor * ce,
|
---|
| 66 | string grp="Command");
|
---|
| 67 | virtual void RegisterHelp(string& keyw, string& usage, string& grp);
|
---|
[293] | 68 | virtual void LoadModule(string& fnameso, string& name);
|
---|
| 69 |
|
---|
| 70 | virtual void AddInterpreter(CmdInterpreter * cl);
|
---|
| 71 | virtual void SelInterpreter(string& name);
|
---|
| 72 |
|
---|
| 73 | virtual int Interpret(string& line);
|
---|
| 74 | virtual int ExecFile(string& file);
|
---|
| 75 |
|
---|
| 76 | virtual string& GetUsage(const string& kw);
|
---|
| 77 | virtual void ShowHelpWindow();
|
---|
| 78 |
|
---|
| 79 | inline CmdInterpreter* CurrentInterpreter() { return(curcmdi); }
|
---|
| 80 | inline CmdExecutor* BaseExecutor() { return(basexec); }
|
---|
| 81 | inline PIStdImgApp* GetImgApp() { return(mImgApp); }
|
---|
| 82 |
|
---|
[330] | 83 | // Pour utilisation par PIAHelpWind uniquement
|
---|
| 84 | virtual void UpdateHelpList(PIAHelpWind* hw, int gid);
|
---|
| 85 |
|
---|
[293] | 86 | protected:
|
---|
[330] | 87 | virtual int CheckHelpGrp(string& grp);
|
---|
| 88 |
|
---|
[165] | 89 | NamedObjMgr* mObjMgr;
|
---|
| 90 | PIStdImgApp* mImgApp;
|
---|
| 91 |
|
---|
[293] | 92 | CmdInterpreter* curcmdi;
|
---|
| 93 | CmdExecutor* basexec;
|
---|
| 94 |
|
---|
[330] | 95 | // Pour enregistrer la liste de commandes et leurs executeurs et le help
|
---|
| 96 | struct cmdex {int group; string us; CmdExecutor * cex; } ;
|
---|
| 97 | typedef map<string, int, less<string> > CmdHGroup; // Liste des groupes de commandes
|
---|
| 98 | CmdHGroup cmdhgrp;
|
---|
| 99 | int cmdgrpid; // Numero de groupe courant
|
---|
[293] | 100 | typedef map<string, cmdex, less<string> > CmdExmap;
|
---|
| 101 | CmdExmap cmdexmap;
|
---|
[330] | 102 | CmdExmap helpexmap; // Pour les helps sans commande
|
---|
[293] | 103 |
|
---|
| 104 | // Pour garder la liste des modules
|
---|
| 105 | typedef map<string, PDynLinkMgr* , less<string> > Modmap;
|
---|
| 106 | Modmap modmap;
|
---|
| 107 |
|
---|
| 108 | // Pour garder la liste des interpreteur
|
---|
| 109 | typedef map<string, CmdInterpreter*, less<string> > InterpMap;
|
---|
| 110 | InterpMap interpmap;
|
---|
| 111 |
|
---|
[165] | 112 | // Pour stocker les variables definies par l'interpreteur
|
---|
[293] | 113 | typedef map<string, string, less<string> > CmdVarList;
|
---|
[165] | 114 | CmdVarList mVars; // Liste des variables
|
---|
| 115 | ofstream hist; // History file
|
---|
| 116 | bool trace; // Trace flag
|
---|
| 117 | bool timing; // Display CPU Time
|
---|
| 118 | Timer* gltimer; // pour Display CPU Time
|
---|
| 119 |
|
---|
[293] | 120 | // Fenetre d'aide interactive
|
---|
| 121 | PIAHelpWind* helpwin;
|
---|
[165] | 122 |
|
---|
| 123 | };
|
---|
| 124 |
|
---|
[293] | 125 |
|
---|
| 126 |
|
---|
[165] | 127 | #endif
|
---|