00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4CommandProtoList.h"
00017
00018 #include <iostream.h>
00019
00020 #include "Go4LockGuard/TGo4LockGuard.h"
00021 #include "Go4Log/TGo4Log.h"
00022 #include "TGo4Command.h"
00023 #include "Go4CommandsBase.h"
00024
00025 TGo4CommandProtoList::TGo4CommandProtoList(const char* name) :
00026 TNamed(name,"This is a TGo4CommandProtoList")
00027 {
00028 TRACE((14,"TGo4CommandProtoList::TGo4CommandProtoList(Text_t*) ctor",__LINE__, __FILE__));
00029
00030 fxListMutex=new TMutex;
00031 fxCommandList= new TObjArray;
00032 fxIterator=fxCommandList->MakeIterator();
00033
00034
00035
00036
00037 }
00038
00039 TGo4CommandProtoList::~TGo4CommandProtoList()
00040 {
00041 TRACE((14,"TGo4CommandProtoList::~TGo4CommandProtoList() dtor",__LINE__, __FILE__));
00042 {
00043 TGo4LockGuard listguard(fxListMutex);
00044 fxCommandList->Delete();
00045 delete fxCommandList;
00046 delete fxIterator;
00047 }
00048 delete fxListMutex;
00049 }
00050
00051 void TGo4CommandProtoList::ShowCommands()
00052 {
00053 TRACE((12,"TGo4CommandProtoList::ShowCommands()",__LINE__, __FILE__));
00054
00055 {
00056 TGo4LockGuard listguard(fxListMutex);
00057 TGo4Command* com;
00058 fxIterator->Reset();
00059 TGo4Log::Debug(" CommandProtoList Showing the known commands:");
00060 cout << " Name: \t| Description:"<<endl;
00061 while((com= (TGo4Command*) fxIterator->Next())!=0)
00062 {
00063 cout << " "<< com->GetName()<<"\t| "<<com->What()<<endl;
00064 }
00065 }
00066 }
00067
00068 TGo4Command* TGo4CommandProtoList::MakeCommand(const char* name)
00069 {
00070 TRACE((12,"TGo4CommandProtoList::MakeCommand(Text_t*)",__LINE__, __FILE__));
00071 TGo4Command* rev=0;
00072 {
00073 TGo4LockGuard listguard(fxListMutex);
00074 TObject* obj=fxCommandList->FindObject(name);
00075 if(obj==0)
00076
00077 {
00078
00079 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00080 }
00081 else
00082 {
00083
00084 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) cloning command",__LINE__, __FILE__));
00085 rev= (TGo4Command*) obj->Clone();
00086
00087 }
00088 }
00089
00090 return rev;
00091
00092 }
00093
00094 void TGo4CommandProtoList::RemoveCommand(const char* name)
00095 {
00096 TRACE((12,"TGo4CommandProtoList::RemoveCommand(Text_t*)",__LINE__, __FILE__));
00097 {
00098 TGo4LockGuard listguard(fxListMutex);
00099 TObject* obj=fxCommandList->FindObject(name);
00100 if(obj==0)
00101
00102 {
00103
00104 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00105 }
00106 else
00107 {
00108
00109 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) removing command from array",__LINE__, __FILE__));
00110 fxCommandList->Remove(obj);
00111 fxCommandList->Compress();
00112 fxCommandList->Expand(fxCommandList->GetLast()+1);
00113 delete obj;
00114 }
00115 }
00116 }
00117
00118
00119 void TGo4CommandProtoList::AddCommand(TGo4Command* com)
00120 {
00121 TRACE((12,"TGo4CommandProtoList::AddCommand(TGo4Command*)",__LINE__, __FILE__));
00122 {
00123 TGo4LockGuard listguard(fxListMutex);
00124 if(fxCommandList->FindObject(com)==0)
00125
00126 {
00127
00128 TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) Adding new go4 commandto array",__LINE__, __FILE__));
00129 fxCommandList->AddLast(com);
00130 }
00131 else
00132 {
00133
00134 TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) command was already in array",__LINE__, __FILE__));
00135 }
00136 }
00137 }
00138
00139 TGo4CommandProtoList& TGo4CommandProtoList::operator+=(const TGo4CommandProtoList& two)
00140 {
00141 if(this!=&two)
00142 {
00143 TGo4LockGuard outerguard(two.fxListMutex);
00144 TIterator* twoiter= two.fxCommandList->MakeIterator();
00145 twoiter->Reset();
00146 TGo4Command* com;
00147 while ( (com=dynamic_cast<TGo4Command*>( twoiter->Next() ) ) !=0)
00148 {
00149 AddCommand(com);
00150 }
00151 delete twoiter;
00152 cout <<"CommandProtoList "<< GetName() <<"used operator += for adding list " << two.GetName() << endl;
00153 }
00154 else
00155 {
00156
00157 }
00158 return *this;
00159 }
00160
00161 ClassImp(TGo4CommandProtoList)
00162
00163