source: Sophya/trunk/SophyaPI/DemoPIApp/exmodule.cc@ 1338

Last change on this file since 1338 was 1338, checked in by ansari, 25 years ago

Creation du module DemoPIApp - Macro de demo pour (s)piapp - Reza 20/11/2000

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#include "machdefs.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream.h>
5#include <math.h>
6
7#include <typeinfo>
8
9#include <vector>
10#include <string>
11
12#include "piacmd.h"
13#include "nobjmgr.h"
14#include "pistdimgapp.h"
15
16
17// Exemple de module chargeable ds piapp
18
19// Declaration de la fonction d'activation et de desactivation du module
20extern "C" {
21void exmodule_init();
22void exmodule_end();
23}
24
25
26// Une classe commande-executor, permettant d'enregistrer de
27// nouvelles commandes a piapp
28class exmoduleExecutor : public CmdExecutor {
29public:
30 exmoduleExecutor();
31 virtual ~exmoduleExecutor();
32 // Execute s'occupe de l'execution effective des commandes
33 virtual int Execute(string& keyw, vector<string>& args, string& toks);
34};
35
36/* --Methode-- */
37exmoduleExecutor::exmoduleExecutor()
38{
39
40PIACmd * mpiac;
41NamedObjMgr omg;
42mpiac = omg.GetImgApp()->CmdInterpreter();
43
44// On enregistre deux nouvelles commandes
45string hgrp = "ExModuleCmd";
46// commande excmd1
47string kw = "excmd1";
48string usage = "exmd1: Appel Print pour obj1 \n" ;
49usage += "Usage: excmd1 obj1 ";
50mpiac->RegisterCommand(kw, usage, this, hgrp);
51// commande excmd2
52kw = "excmd2";
53usage = "exmd2: Appel Print pour obj1 et obj2 \n" ;
54usage += "Usage: excmd2 obj1 obj2";
55mpiac->RegisterCommand(kw, usage, this, hgrp);
56
57}
58
59/* --Methode-- */
60exmoduleExecutor::~exmoduleExecutor()
61{
62}
63
64/* --Methode-- */
65int exmoduleExecutor::Execute(string& kw, vector<string>& tokens, string&)
66{
67
68NamedObjMgr omg;
69if (kw == "excmd1") {
70 if (tokens.size() < 1) {
71 cout << "Usage: excmd1 obj1" << endl;
72 return(0);
73 }
74 omg.PrintObj(tokens[0]);
75 }
76else if (kw == "excmd2") {
77 if (tokens.size() < 2) {
78 cout << "Usage: excmd2 obj1 obj2" << endl;
79 return(0);
80 }
81 omg.PrintObj(tokens[0]);
82 omg.PrintObj(tokens[1]);
83 }
84
85return(0);
86
87}
88
89static exmoduleExecutor * piaerex = NULL;
90/* Nouvelle-Fonction */
91void exmodule_init()
92{
93// Fonction d'initialisation du module
94// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
95if (piaerex) delete piaerex;
96piaerex = new exmoduleExecutor;
97}
98
99/* Nouvelle-Fonction */
100void exmodule_end()
101{
102// Desactivation du module
103if (piaerex) delete piaerex;
104piaerex = NULL;
105}
106
Note: See TracBrowser for help on using the repository browser.