Beispiel #1
0
//-----------------------------------------------------------------
//
// METHOD:
//     Country* Country::Find( RTI::ObjectHandle objectId )
//
// PURPOSE:
//     Looks through the extent to find the Country instance
//     with the passed in object Id.
//
// RETURN VALUES:
//     Pointer to country object that has the specified
//     ObjectHandle. 
//
// HISTORY:
//     1) Created 11/6/96
//     2) Updated to RTI 1.3 3/26/98
//
//-----------------------------------------------------------------
Country* Country::Find( RTI::ObjectHandle objectId )
{
   Country *pCountry = NULL;

   for ( unsigned int i = 0; i < Country::ms_extentCardinality; i++ )
   {
      pCountry = Country::ms_countryExtent[ i ];

      if ( pCountry && pCountry->GetInstanceId() == objectId ) {
	break;
      } else {
	pCountry = NULL;
      }
   }

   return pCountry;
}
Beispiel #2
0
//-----------------------------------------------------------------
//
// METHOD:
//     Country::~Country()
//
// PURPOSE:
//     Virtual destructor. Frees memory allocated for m_name and
//     removes this instance from the extent.
//
//     Note: Removing an element from the extent causes the array
//           to be collapsed so as to not have any gaps.  Some
//           elements will have new indices within the extent
//           after this occurs.
//
// RETURN VALUES:
//     None. 
//
// HISTORY:
//     1) Created 11/6/96
//     2) Updated to RTI 1.3 3/26/98
//
//-----------------------------------------------------------------
Country::~Country()
{
   Country *pCountry = NULL;
   unsigned int ndx = 0;

   //-----------------------------------------------------------------
   // Find the position in the extent for this instance.  The
   // zero'th position always hold the local instance.
   //-----------------------------------------------------------------
   for ( ndx = 0; ndx < Country::ms_extentCardinality; ndx++ )
   {
      pCountry = Country::ms_countryExtent[ ndx ];

      if ( pCountry && pCountry->GetInstanceId() == this->GetInstanceId() )
      {
         break;
      }
   }

   if ( pCountry )
   {
      //-----------------------------------------------------------------
      // First thing to do is move the rest of the Country objects
      // one position up in the collection and then reduce the
      // cardinality by one.
      //-----------------------------------------------------------------
      for ( unsigned int i=ndx; (i < Country::ms_extentCardinality)
                       && (Country::ms_countryExtent[ i ] != NULL); i++ )
      {
         Country::ms_countryExtent[ i ] = Country::ms_countryExtent[ i+1 ];
      }

      Country::ms_extentCardinality = Country::ms_extentCardinality - 1;

      //-----------------------------------------------------------------
      // If the instance was found in the 0th position then this is the
      // local Country instance so we should delete it from the federation
      // execution.
      //-----------------------------------------------------------------
      if ( ms_rtiAmb && ndx==0 )
      {
         //-----------------------------------------------------------------
         // this call returns an event retraction handle but we don't
         // support event retraction so no need to store it.
         //-----------------------------------------------------------------
         (void) ms_rtiAmb->deleteObjectInstance( this->GetInstanceId(),
                                                 this->GetLastTimePlusLookahead(),
                                                 NULL );
      }
      else
      {
         //-----------------------------------------------------------------
         // Otherwise, this is a remote object that removeObject was called
         // on.
         //-----------------------------------------------------------------
         //We don't need to do anything here 
      }
   }
 
   delete [] m_name;
}