// =====================================================================
//  $Id: TModuleSpecified.cc,v 1.4 2004/03/07 10:30:31 goiwai Exp $
//  $Name: CLDAQ-1-14-06 $
//  $Log: TModuleSpecified.cc,v $
//  Revision 1.4  2004/03/07 10:30:31  goiwai
//  ROOTに組みこむためのおまじないマクロを埋めこみました。
//  全てにおいて完全に動作するわけではありません。
//
//  Revision 1.3  2003/10/06 17:02:40  goiwai
//  *** empty log message ***
//
//  Revision 1.2  2003/07/30 16:19:10  goiwai
//  ファイルにコミットログをつけることにしました.
//
// =====================================================================
#include "TModuleSpecified.hh"

TModuleSpecified::TModuleSpecified()
  : theModuleID(), theGroupIDs(), theModule( 0 )
{
  theGroupIDs.clear();
}

TModuleSpecified::TModuleSpecified( const Tstring& id, const TstringList& groups, TModule* module )
  : theModuleID( id ), theGroupIDs( groups ), theModule( module )
{;}

TModuleSpecified::TModuleSpecified( const TModuleSpecified& right )
  : theModuleID( right.theModuleID ), theGroupIDs( right.theGroupIDs ),
    theModule( right.theModule )
{;}

TModuleSpecified::~TModuleSpecified()
{;}

const TModuleSpecified& TModuleSpecified::operator=( const TModuleSpecified& right )
{
  theModuleID = right.theModuleID;
  theGroupIDs = right.theGroupIDs;
  theModule = right.theModule;
  return *this;
}

Tbool TModuleSpecified::operator==( const TModuleSpecified& right ) const
{
  Tbool retval = Ttrue;
  retval &= ( theModuleID == right.theModuleID );
  retval &= ( theGroupIDs == right.theGroupIDs );
  retval &= ( theModule == right.theModule );
  return retval;
}

Tbool TModuleSpecified::operator!=( const TModuleSpecified& right ) const
{
  Tbool retval = Tfalse;
  retval |= ( theModuleID != right.theModuleID );
  retval |= ( theGroupIDs != right.theGroupIDs );
  retval |= ( theModule != right.theModule );
  return retval;
}

Tbool TModuleSpecified::IsSameGroup( const TstringList& groups )
{
  for ( Tsize_t i = 0; i < theGroupIDs.size(); i ++ ) {
    for ( Tsize_t j = 0; j < groups.size(); j ++ ) {
      if ( theGroupIDs[ i ] == groups[ j ] ) {
	return Ttrue;
      }
    }
  }
  return Tfalse;
}

Tbool TModuleSpecified::IsSameGroup( const TModuleSpecified& spec )
{
  return IsSameGroup( spec.GetGroupIDs() );
}

Tbool TModuleSpecified::IsSameGroup( const Tstring& group )
{
  TstringList groups;
  groups.push_back( group );
  return IsSameGroup( groups );
}

Tostream& operator<<( Tostream& tos, const TModuleSpecified& right )
{
  tos << "ID: " << right.theModuleID << ", ";
  tos << "GID(s): ";
  Tsize_t ngroups = right.theGroupIDs.size();
  for ( Tsize_t i = 0; i < ngroups; i ++ ) {
    tos << right.theGroupIDs[ i ] << ", ";
  }
  tos << right.theModule << Tflush;
  return tos;
}

#ifdef __CLDAQ_ROOT_DLL
    ClassImp(TModuleSpecified)
#endif
