Hi
Joaquin,
Seems the problem
was happening when I call add and my add method tries to first find out
whether that id is
already present in container or not. It is not during remove method
call.
I was concentrating
on wrong portion of the code before. Anyways, I have changed
and
put some print out
in code also at the end I have included output that comes. I have
changed
container to ordered
index as you have said, but seems to be the same problem. It seems
that it is core
dumping on following line:
bool Procedure_Pool::find_by_id(Procedure *
_procedure)
{
LD_TRACE("Procedure_Pool::find_by_id");
ACE_ASSERT(_procedure
!= 0);
ACE_DEBUG((LM_DEBUG, "PROCEDURE TO FIND: %d\n",
_procedure->id()));
Procedure_By_Id::iterator it
=
procedure_by_id_.find(_procedure->id());
ACE_DEBUG((LM_DEBUG,
"AFTER FIND CALL\n"));
return (it !=
procedure_by_id_.end());
}
Please let me know if I am doing something wrong here.
Also, let me know if you
need any more information. Please see debug output at
the end of the email.
Thanks
Priyank
#ifndef
PROCEDURE_POOL_H
#define PROCEDURE_POOL_H
/**
*
Identifier pool of procedure. This procedure will be un-sorted
* hashed
index provided by procedures unique id retuned by procedure.
* It
internally uses boost hashed index for indexing the procedures
* in
procedure pool.
*
* @author Priyank Patel
* @since
Mar 30, 2006
*/
#include
<boost/multi_index_container.hpp>
#include
<boost/multi_index/member.hpp>
#include
<boost/multi_index/ordered_index.hpp>
#include
<boost/multi_index/hashed_index.hpp>
#include
<boost/config.hpp>
#include <boost/utility.hpp>
#include
<boost/shared_ptr.hpp>
#include
<boost/multi_index/key_extractors.hpp>
#include "Procedure.h"
using
boost::multi_index_container;
using namespace
boost::multi_index;
/**
*
Defines tag used for procedure id.
*/
struct procedure_id_tag
{
};
class
Procedure_Pool: boost::noncopyable {
private:
/**
* Type definition for
multi index container.
*/
typedef
multi_index_container<
Procedure*,
indexed_by<
ordered_unique<
tag<procedure_id_tag>,
const_mem_fun<Procedure, int, &Procedure::id>
>
>
> Procedure_Hashed_Pool;
/**
* Type definition for indexing based on procedure id tag.
*/
typedef Procedure_Hashed_Pool::index<procedure_id_tag>::type
Procedure_By_Id;
public:
/**
* Constructor.
*/
Procedure_Pool(): pool_(),
procedure_by_id_(pool_.get<procedure_id_tag>())
{
}
/**
* Adds specified procedure in this
pool.
* It will intenally used procedures id() method to index
procedure.
* @param _procedure Procedure to be added in this
pool
* @return Success (0) or Failure (-1) based on addition happened
or not
*/
int add_by_id(Procedure *
_procedure);
/**
* Removes procedure from this
pool.
* @param _procedure procedure that needs to be removed
* @return Success (0) or Failure (1) based on removal happend or not
*/
int remove_by_id(Procedure * _procedure);
/**
*
Retrieves procedure based on specified id.
* @param _id
Identifier
* @return Procedure Pointer to procedure. Returns 0 if
procedure not found
*/
Procedure * find_by_id(int
_id);
private:
/**
* Returns true if
procedure is present otherwise returns false.
* @param _procedure
procedure that needs to found
* @return true if found or false if not
found
*/
bool find_by_id(Procedure *
_procedure);
/**
* boost multiindex object that is associated
with this pool.
*/
Procedure_Hashed_Pool
pool_;
/**
* Refernece of pool that is indexed by procedure
id tag.
*/
Procedure_By_Id
&procedure_by_id_;
};
#endif
#include
"../include/Procedure_Pool.h"
int
Procedure_Pool::add_by_id(Procedure *
_procedure)
{
LD_TRACE("Procedure_Pool::add_by_id");
ACE_ASSERT(_procedure
!= 0);
ACE_DEBUG((LM_DEBUG, "FIND CALL FROM
ADD\n"));
if (!find_by_id(_procedure)) {
//
procedure not
found
procedure_by_id_.insert(_procedure);
//
debug info
ACE_DEBUG((LM_DEBUG, "Added procedure : %d \n",
_procedure->id()));
// return success
return
0;
} else {
// error
ACE_ERROR((LD_ERROR
"%N:%l Error in adding procedure : %d \n",
_procedure->id()));
// return failure
return
-1;
}
}
int
Procedure_Pool::remove_by_id(Procedure *
_procedure)
{
LD_TRACE("Procedure_Pool::remove_by_id");
ACE_ASSERT(_procedure
!= 0);
ACE_DEBUG((LM_DEBUG, "FIND CALL FROM REMOVE\n"));
if
(find_by_id(_procedure)) {
// procedure
found
procedure_by_id_.erase(_procedure->id());
ACE_DEBUG((LM_DEBUG,
"Removed procedure : %d \n", _procedure->id()));
return
0;
} else {
ACE_ERROR((LD_ERROR "%N:%l Error in removing
procedure : %d \n", _procedure->id()));
return
-1;
}
}
Procedure *
Procedure_Pool::find_by_id(int
_id)
{
LD_TRACE("Procedure_Pool::find_by_id");
Procedure_By_Id::iterator
it = procedure_by_id_.find(_id);
if (it != procedure_by_id_.end())
{
ACE_DEBUG((LM_DEBUG, "%N:%l Found procedure for id: %d \n",
_id));
return *it;
}
ACE_ERROR((LD_ERROR "%N:%l
Not able to found procedure for id: %d \n", _id));
// return
null
return 0;
}
bool
Procedure_Pool::find_by_id(Procedure *
_procedure)
{
LD_TRACE("Procedure_Pool::find_by_id");
ACE_ASSERT(_procedure
!= 0);
ACE_DEBUG((LM_DEBUG, "PROCEDURE TO FIND:
%d\n", _procedure->id()));
Procedure_By_Id::iterator it =
procedure_by_id_.find(_procedure->id());
ACE_DEBUG((LM_DEBUG, "AFTER
FIND CALL\n"));
return (it !=
procedure_by_id_.end());
}
Debug
Output:
==========