#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/member.hpp>
#include <string>
#include <iostream>
//#include <boost/multi_index/identity.hpp>
using namespace boost::multi_index;
//tags
struct NR_PCI {};
struct NR_FREQ_REF {};
struct NR_MOID {};
struct nr_cell_relation
{
uint16_t id;
uint16_t nr_freq_ref;
uint16_t pci;
uint64_t nrCellIdentity;
};
typedef multi_index_container<
nr_cell_relation,
indexed_by<
sequenced<>,
// ordered_unique<identity<nr_cell_relation> >,
ordered_unique< tag<NR_PCI>, member< nr_cell_relation, uint16_t, &nr_cell_relation::pci > >,
ordered_unique< tag<NR_MOID>, member< nr_cell_relation, uint16_t, &nr_cell_relation::id > > > > nr_anr_nrt_t;
nr_anr_nrt_t nr_anr_nrt;
bool pci_entry_exits(uint16_t pci)
{
auto &pci_index = nr_anr_nrt.get<NR_PCI>();
auto itr = pci_index.find(pci);
if (itr != pci_index.end())
{
std::cout<<"PCI MAP Entry Exist: PCI"<<itr->pci<<std::endl;
return true;
}
std::cout<<"PCI MAP Entry Not Exist: PCI"<<pci<<std::endl;
return false;
}
bool mo_id_entry_exits(uint16_t id)
{
auto &pci_index = nr_anr_nrt.get<NR_MOID>();
auto itr = pci_index.find(id);
if (itr != pci_index.end())
{
std::cout<<"MOID Entry Exist: MOID:"<<itr->id<<":PCI:"<<itr->pci<<std::endl;
return true;
}
std::cout<<"MOID Entry Not Exist: MOID"<<id<<std::endl;
return false;
}
int main()
{
if (!pci_entry_exits(304))
{
nr_anr_nrt.push_back({1, 2, 304, 1234566});
}
if (!pci_entry_exits(301))
{
nr_anr_nrt.push_back({4, 1, 301, 1234567});
}
if (!pci_entry_exits(303))
{
nr_anr_nrt.push_back({2, 2, 303, 1234569});
}
if (!pci_entry_exits(302))
{
nr_anr_nrt.push_back({3, 1, 302, 1234568});
}
if (!pci_entry_exits(302))
{
nr_anr_nrt.push_back({5, 1, 302, 1234568});
}
if (mo_id_entry_exits(4))
{
nr_anr_nrt.push_back({4, 1, 302, 1234568});
}
std::cout<<"NRT DUMP with PCI KEY:"<<std::endl;
auto it = nr_anr_nrt.get<NR_PCI>().begin();
for (; it != nr_anr_nrt.get<NR_PCI>().end(); ++it)
{
std::cout << "MOID:"<<it->id<<"\tFreq_Ref:"<<it->nr_freq_ref<<"\tNR_PCI:"<<it->pci<<std::endl;
}
std::cout<<"NRT DUMP with MOID KEY:"<<std::endl;
auto itr = nr_anr_nrt.get<NR_MOID>().begin();
for (; itr != nr_anr_nrt.get<NR_MOID>().end(); ++itr)
{
std::cout << "MOID:"<<itr->id<<"\tFreq_Ref:"<<itr->nr_freq_ref<<"\tNR_PCI:"<<itr->pci<<std::endl;
}
std::cout<<"NRT DUMP ORDER OF INSERTION:"<<std::endl;
auto it_r = nr_anr_nrt.begin();
for (; it_r != nr_anr_nrt.end(); ++it_r)
{
std::cout << "MOID:"<<it_r->id<<"\tFreq_Ref:"<<it_r->nr_freq_ref<<"\tNR_PCI:"<<it_r->pci<<std::endl;
}
}
Description: The program is implemented for accessing multi index container using single unique key.
Problem statement: how to implement, whenever situation arises to access multi_index container using multiple keys like std::pair<key1, key2> or even tuple like std::tuple<key1, key2, key3> using composite_key.