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

/Go4CommandsBase/TGo4CommandProtoList.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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    // no demo commands in go4 release:
00034    //AddCommand (new TGo4CommandControl);
00035    //AddCommand (new TGo4CommandStartClient);
00036    //AddCommand (new TGo4SimpleCommand);
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       // is command in list?
00077          {
00078             //no, do nothing
00079             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00080          }
00081       else
00082          {
00083             // yes, create it it
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       // is command in list?
00102          {
00103             //no, do nothing
00104             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00105          }
00106       else
00107          {
00108             // yes, remove it
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       // is command already in list?
00126          {
00127             //no, add new command
00128             TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) Adding new go4 commandto array",__LINE__, __FILE__));
00129             fxCommandList->AddLast(com);
00130          }
00131       else
00132          {
00133             // yes, do nothing
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          // do not add  the same commands twice
00157       }
00158    return *this;
00159 }
00160 
00161 ClassImp(TGo4CommandProtoList)
00162 
00163 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:51 2005 for Go4-v2.10-5 by doxygen1.2.15