Offer_Iterators_T.cpp

Go to the documentation of this file.
00001 // $Id: Offer_Iterators_T.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #ifndef TAO_OFFER_ITERATORS_T_CPP
00004 #define TAO_OFFER_ITERATORS_T_CPP
00005 
00006 #include "orbsvcs/Trader/Offer_Iterators_T.h"
00007 
00008 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 template <class MAP_LOCK_TYPE>
00011 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>::
00012 TAO_Register_Offer_Iterator (TAO_Offer_Database<MAP_LOCK_TYPE> &db,
00013                              const TAO_Property_Filter& pfilter)
00014   : TAO_Offer_Iterator (pfilter),
00015     db_ (db)
00016 {
00017 }
00018 
00019 template <class MAP_LOCK_TYPE>
00020 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>::
00021 ~TAO_Register_Offer_Iterator (void)
00022 {
00023   while (! this->offer_ids_.is_empty ())
00024     {
00025       CosTrading::OfferId offer_id = 0;
00026       this->offer_ids_.dequeue_head (offer_id);
00027 
00028       CORBA::string_free (offer_id);
00029     }
00030 }
00031 
00032 template <class MAP_LOCK_TYPE> void
00033 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>::
00034 add_offer (CosTrading::OfferId id,
00035            const CosTrading::Offer* /* offer */)
00036 {
00037   this->offer_ids_.enqueue_tail (id);
00038 }
00039 
00040 template <class MAP_LOCK_TYPE> CORBA::ULong
00041 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>::
00042 max_left (void)
00043 {
00044   return static_cast<CORBA::ULong> (this->offer_ids_.size ());
00045 }
00046 
00047 template <class MAP_LOCK_TYPE> CORBA::Boolean
00048 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>::
00049 next_n (CORBA::ULong n,
00050         CosTrading::OfferSeq_out offers)
00051 {
00052   CORBA::ULong ret_offers = 0;
00053 
00054   CORBA::ULong max_possible_offers_in_sequence =
00055     (n <  this->offer_ids_.size ()) ? n :
00056        static_cast<CORBA::ULong> (this->offer_ids_.size ());
00057 
00058   ACE_NEW_THROW_EX (offers,
00059                     CosTrading::OfferSeq,
00060                     CORBA::NO_MEMORY ());
00061 
00062   offers->length (max_possible_offers_in_sequence);
00063 
00064   // While there are entries left and we haven't filled <offers>
00065   // with requested number.
00066   while (! this->offer_ids_.is_empty ()
00067          && n > ret_offers)
00068     {
00069       // If offer is found, put it into the sequence.
00070       // remove this id irrespective of whether the offer is found
00071       // or not.
00072       CosTrading::OfferId id = 0;
00073       this->offer_ids_.dequeue_head (id);
00074 
00075       CosTrading::OfferId_var offerid_var (id);
00076       CosTrading::Offer* offer = this->db_.lookup_offer (id);
00077 
00078       if (offer != 0)
00079         this->pfilter_.filter_offer (offer,
00080                                      offers[ret_offers++]);
00081     }
00082 
00083   // Reset the length to the correct value
00084   offers->length (ret_offers);
00085 
00086   return static_cast<CORBA::Boolean> (ret_offers != 0);
00087 }
00088 
00089 TAO_END_VERSIONED_NAMESPACE_DECL
00090 
00091 #endif /* TAO_REGISTER_OFFER_ITERATOR_CPP */

Generated on Tue Feb 2 17:49:26 2010 for TAO_CosTrader by  doxygen 1.4.7