El 13/06/2011 19:54, brijesh.sharma@thomsonreuters.com escribió:

Hi,


Hi Brijesh,

Next time please include [multi_index] in the subject line so that people
in a position to help can quickly spot your post:

http://www.boost.org/community/policy.html#subject-line

 

Here is what I am trying to do

typedef DWORD DSIid;

enum DSType

{

  DSTypeNone = 0,

  DSTypeBegin,

  DSTypeRoot

}

               

struct SDSIOwnedByKey

{

                SDSIOwnedByKey(DSType DSTypeOwned, DSIid DSIidOwned, DSType DSTypeOwner, DSIid DSIidOwner)

                                : m_DSTypeOwned(DSTypeOwned), m_DSIidOwned(DSIidOwned), m_DSTypeOwner(DSTypeOwner), m_DSIidOwner(DSIidOwner)

                {

                }

 

                bool operator == (const SDSIOwnedByKey &rcComp) const

                {

                                return m_DSTypeOwned == rcComp.m_DSTypeOwned &&

                                                m_DSIidOwned == rcComp.m_DSIidOwned &&

                                                m_DSTypeOwner == rcComp.m_DSTypeOwner &&

                                                m_DSIidOwner == rcComp.m_DSIidOwner;

                }

DSType m_DSTypeOwned;

       DSIid         m_DSIidOwned;

       DSType m_DSTypeOwner;

       DSIid         m_DSIidOwner;

};            

 

class DataStore

{

typedef boost::multi_index_container<

    SDSIOwnedByKey,

    boost::multi_index::indexed_by<

    boost::multi_index::ordered_unique<boost::multi_index::tag<ByOwnedTypeOwnerTypeOwnerIdOwnedId>,

    boost::multi_index::composite_key<SDSIOwnedByKey, 

    boost::multi_index::member<SDSIOwnedByKey, DSType, &SDSIOwnedByKey::m_DSTypeOwned>,

    boost::multi_index::member<SDSIOwnedByKey, DSType, &SDSIOwnedByKey::m_DSTypeOwner>,

    boost::multi_index::member<SDSIOwnedByKey, DSIid, &SDSIOwnedByKey::m_DSIidOwner>,

    boost::multi_index::member<SDSIOwnedByKey, DSIid, &SDSIOwnedByKey::m_DSIidOwned>

    >, boost::multi_index::composite_key_compare<std::less<DSType>,std::less<DSType>, std::less<DSIid>, std::greater<DSIid>>

    >

    >

  > TOwnedBySort;

 

  typedef typename TOwnedBySort::index<ByOwnedTypeOwnerTypeOwnerIdOwnedId>::type OwnedBySort_ByOwnedTypeOwnerTypeOwnerId;

 

  TOwnedBySort m_oOwnedBySort;

 

};

 

 

Instead of

    >, boost::multi_index::composite_key_compare<std::less<DSType>,std::less<DSType>, std::less<DSIid>, std::greater<DSIid>>

 

I want to write a compare function that compared all the values in one function, like a complete record comparison something like

 

    >, boost::multi_index::composite_key_compare<SDSIOwnedByKey>

And have an appropriate function which would get the whole record to compare


If I understand you well, what you intend is basically equivalent to not using composite keys
and writing most of the stuff manually (if you use composite_key you're forced to use
composite_key_compare as well, both go hand in hand) Here's a sketch of what need to
be done:

  struct SDSIOwnedByKey
  {
    ...
    bool operator<(const SDSIOwnedByKey &rcComp)const
    {
      // This manually does the same job that composite_key and composite_key_compare
      // automatically did before; substitute with your own comparison criterion if needed.

      if(m_DSTypeOwned<rcComp.m_DSTypeOwned)return true;
      else if(rcComp.m_DSTypeOwned<m_DSTypeOwned)return false;
      else if(m_DSTypeOwner<rcComp.m_DSTypeOwner)return true;
      else if(rcComp.m_DSTypeOwner<m_DSTypeOwner)return false;
      else if(m_DSIidOwner<rcComp.m_DSIidOwner)return true;
      else if(rcComp.m_DSIidOwner<m_DSIidOwner)return false;
      else return m_DSIidOwned>rcComp.m_DSIidOwned;
    }    ...
  };

  ...

  typedef boost::multi_index_container<
    SDSIOwnedByKey,
    boost::multi_index::indexed_by<
      boost::multi_index::ordered_unique<
        boost::multi_index::tag<ByOwnedTypeOwnerTypeOwnerIdOwnedId>,
        boost::multi_index::identity<SDSIOwnedByKey> // SDSIOwnedByKey::operator < does the job
      >
    >
  > TOwnedBySort;

The drawback is that when you use the lookup functions of TOwnedBySort you
can no longer pass tuples (or partial tuples) of (m_DSTypeOwned,m_DSTypeOwner,
m_DSIidOwner, m_DSIidOwned) values but have to pass whole SDSIOwnedByKey's
instead.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at.
http://www.tid.es/ES/PAGINAS/disclaimer.aspx