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

Last change on this file since 3583 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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