Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AlephRegisteredAction.h

Go to the documentation of this file.
00001 
00002 //
00003 // CLASS AlephRegisteredAction
00004 // Registers an interactive function class to ALPHA++
00005 //
00006 // Author :  C. Delaere
00007 //
00009 
00010 #ifndef _ALEPHREGISTEREDACTION_H_
00011 #define _ALEPHREGISTEREDACTION_H_
00012 
00013 #include <vector>
00014 
00015 #if defined(__GNUC__)
00016 #pragma interface
00017 #endif
00018 
00019 class AlephAbstractInteractiveFunction;
00020 class AlephExManager;
00021 
00022 template<class Type>
00023 class AlephRegisteredAction
00024 {
00025         public:
00026                 AlephRegisteredAction();
00027                 virtual ~AlephRegisteredAction() {}
00028 };
00029 
00030 
00031 #if defined(__GNUC__)
00032 #pragma implementation
00033 #endif
00034 
00035 #include <typeinfo>
00036 #include "AlephAbstractInteractiveFunction.h"
00037 #include "AlephInteractiveHandler.h"
00038 
00039 template <class Type>
00040 AlephRegisteredAction<Type>::AlephRegisteredAction()
00041 {
00042         // instanciate the class
00043         Type* myclass = new Type(AlephInteractiveHandler::TheAlephInteractiveHandler());
00044         // check that it is an AlephAbstractInteractiveFunction
00045         AlephAbstractInteractiveFunction* mycheckedclass = dynamic_cast<AlephAbstractInteractiveFunction*>(myclass);
00046         if(mycheckedclass==NULL)
00047         {
00048                 cerr << "ERROR: tried to register the class " << typeid(myclass).name() << " as an AlephAbstractInteractiveFunction" << endl;
00049                 delete myclass;
00050                 return;
00051         }
00052         // check that it is not already registered
00053         string name = mycheckedclass->Name();
00054         for(vector<AlephAbstractInteractiveFunction*>::iterator existing = AlephInteractiveHandler::InteractiveFunctionsList.begin();
00055                         existing<AlephInteractiveHandler::InteractiveFunctionsList.end(); existing++)
00056                 if ((*existing)->Name() == name)
00057                 {
00058                         delete myclass;
00059                         return;
00060                 }
00061         // check if there is an old action for this code... if this is the case, delete it.
00062         int code = mycheckedclass->Code();
00063         for(vector<AlephAbstractInteractiveFunction*>::iterator existing = AlephInteractiveHandler::InteractiveFunctionsList.begin();
00064                         existing<AlephInteractiveHandler::InteractiveFunctionsList.end(); existing++)
00065                 if ((*existing)->Code() == code)
00066                 {
00067                         delete *existing;
00068                         *existing = myclass;
00069                         return;
00070                 }
00071         // add the class to the registry.
00072         AlephInteractiveHandler::InteractiveFunctionsList.push_back(myclass);
00073 }
00074 
00075 #endif

Generated at Wed Jun 18 17:19:09 2003 for ALPHA++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001