|
Boost Users : |
Subject: [Boost-users] Boost:multi-index Question on usage of project & modify_key
From: Ramesh (rramesh1_at_[hidden])
Date: 2009-01-14 19:55:40
Hello.
I am using projection technique & modify_key in one of my member functions:
Assuming I have the following data in the container:
ObjId ObjIp ObjIndex pMyObj
-------------------------------------------------------------------------------------
ID1 10.10.1.2 1 0x10239032
ID2 10.10.1.3 2 0x23423423
ID3 10.10.1.4 3 0x23132423
The member function 'UpdateKeyObjId' accepts the value on column 3 as
key & changes the corresponding value
for the field in Column 1.
My code seems to work fine for all rows except the last row. When I
use modify key on the last record, the app crashes at
the highlighted line. I am not sure if my usage of project &
modify_key right, could someone please point out if there
are any errors in the usage?
Thanks
/R
struct MyMap
{
std::string ObjId;
unsigned long ObjIp;
unsigned long ObjIndex;
MyObj *pMyObj;
MyMap(std::string param_ObjId, unsigned long param_ObjIp,
unsigned long param_ObjIndex, MyObj* param_pMyObj):
ObjId(param_ObjId), ObjIp(param_ObjIp),
ObjIndex(param_ObjIndex), pMyObj(param_pMyObj) {}
~MyMap(){
ObjId.erase();
ObjIp = 0;
ObjIndex = 0;
pMyObj = 0;
}
};
struct ObjId{};
struct ObjIp{};
struct ObjIndex{};
typedef multi_index_container<
MyMap,
indexed_by<
ordered_unique<
tag <ObjId>, BOOST_MULTI_INDEX_MEMBER(MyMap,std::string,ObjId)>,
ordered_non_unique<
tag<ObjIp>,BOOST_MULTI_INDEX_MEMBER(MyMap,unsigned long,ObjIp)>,
ordered_unique<
tag<ObjIndex>,BOOST_MULTI_INDEX_MEMBER(MyMap,unsigned long,ObjIndex)>
>
> tMyObjMap;
class MyObjContainer{
private:
tMyObjMap MyContainer;
public:
UpdateKeyObjId(unsigned long, std::string);
};
bool MyObjContainer::UpdateKeyObjId(unsigned long param_ObjIndex,
std::string param_ObjId) {
typedef tMyObjMap::index<ObjIndex>::type tMyObjMapByIndex;
tMyObjMapByIndex& ObjIndex_index = MyContainer.get<ObjIndex>();
tMyObjMap::index_iterator<ObjIndex>::type it =
ObjIndex_index.find(param_ObjIndex);
typedef tMyObjMap::index<ObjId>::type tMyObjMapById;
tMyObjMapById::iterator ObjIdit = MyContainer.project<0>(it);
// Use the modify_key method to update the ObjIp key with new value
return MyContainer.get<0>().modify_key(ObjIdit, ll::_1 = param_ObjId);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net