27 #ifndef PRE_MULTICONTAINER_HH
28 #define PRE_MULTICONTAINER_HH
42 template<
typename PreMultiContainerKeyT >
83 template<
typename ObjectT,
typename PreMultiContainerKeyT >
112 new_node_ptr->
obj_ptr_ =
new ObjectT;
113 ( *( new_node_ptr->
obj_ptr_ ) ) = ( *obj_ptr_ );
128 std::string msg =
"MCNode::setObjPtr: Invalid pointer.\n";
175 template<
typename PreMultiContainerKeyT >
229 template<
typename ObjectT >
230 void store(
const PreMultiContainerKeyT& obj_key,
231 const ObjectT& obj_reference );
240 template<
typename ObjectT >
241 bool retrieve(
const PreMultiContainerKeyT& obj_key,
242 ObjectT& obj_reference )
const;
250 template<
typename ObjectT >
251 void multiRetrieve( std::vector< std::pair< PreMultiContainerKeyT,
252 ObjectT > >& objs_vector )
const;
261 template<
typename ObjectT >
262 bool isStored(
const PreMultiContainerKeyT& obj_key )
const;
269 void remove(
const PreMultiContainerKeyT& obj_key );
274 typedef typename std::map< PreMultiContainerKeyT,
292 template<
typename PreMultiContainerKeyT >
298 template<
typename PreMultiContainerKeyT >
304 operator=( external );
307 template<
typename PreMultiContainerKeyT >
313 template<
typename PreMultiContainerKeyT >
317 typename IntContainerT::iterator it = container_instance_.begin();
318 typename IntContainerT::iterator it_end = container_instance_.end();
320 while( it != it_end ) {
326 container_instance_.clear();
330 template<
typename PreMultiContainerKeyT >
341 template<
typename PreMultiContainerKeyT >
353 template<
typename PreMultiContainerKeyT >
358 if( ( &ext_instance ) !=
this ) {
362 typename IntContainerT::iterator my_container_it =
363 container_instance_.begin();
364 typename IntContainerT::iterator my_container_it_end =
365 container_instance_.end();
367 while( my_container_it != my_container_it_end ) {
368 delete (my_container_it->second);
373 container_instance_.clear();
377 typename IntContainerT::const_iterator container_it =
379 typename IntContainerT::const_iterator container_it_end =
382 while( container_it != container_it_end ) {
383 container_instance_[ container_it->first ] =
384 container_it->second->clone();
397 template<
typename PreMultiContainerKeyT >
400 last_up_time_ = time( 0 );
403 template<
typename PreMultiContainerKeyT >
404 template<
typename ObjectT >
406 const PreMultiContainerKeyT& obj_key,
const ObjectT& obj_reference )
411 ObjectT* newobjptr =
new ObjectT;
412 ( *newobjptr ) = obj_reference;
418 typename IntContainerT::iterator container_it =
419 container_instance_.find( obj_key );
423 if( container_it == container_instance_.end() ) {
424 container_instance_[ obj_key ] = newnodeptr;
426 delete (container_it->second);
428 container_it->second = newnodeptr;
435 template<
typename PreMultiContainerKeyT >
436 template<
typename ObjectT >
438 const PreMultiContainerKeyT& obj_key, ObjectT& obj_reference )
const
441 typename IntContainerT::const_iterator container_it =
442 container_instance_.find( obj_key );
444 if( container_it == container_instance_.end() ) {
448 if(
typeid( ObjectT ).name() ==
449 container_it->second->getObjTypeInfo() ) {
453 container_it->second )->getObjPtr() ) );
463 template<
typename PreMultiContainerKeyT >
464 template<
typename ObjectT >
466 std::vector< std::pair< PreMultiContainerKeyT,
467 ObjectT > >& objs_vector )
const
471 typename IntContainerT::const_iterator container_it =
472 container_instance_.begin();
473 typename IntContainerT::const_iterator container_it_end =
474 container_instance_.end();
476 std::pair< PreMultiContainerKeyT, ObjectT > temp_pair;
478 while( container_it != container_it_end ) {
479 if(
typeid( ObjectT ).name() ==
480 container_it->second->getObjTypeInfo() ) {
482 temp_pair.first = container_it->first;
485 container_it->second )->getObjPtr() ) );
487 objs_vector.push_back( temp_pair );
495 template<
typename PreMultiContainerKeyT >
496 template<
typename ObjectT >
498 const PreMultiContainerKeyT& obj_key )
const
501 typename IntContainerT::const_iterator container_it =
502 container_instance_.find( obj_key );
504 if( container_it == container_instance_.end() ) {
508 if(
typeid( ObjectT ).name() ==
509 container_it->second->getObjTypeInfo() ) {
520 template<
typename PreMultiContainerKeyT >
522 const PreMultiContainerKeyT& obj_key )
525 typename IntContainerT::iterator container_it =
526 container_instance_.find( obj_key );
530 if( container_it != container_instance_.end() ) {
531 delete (container_it->second);
533 container_instance_.erase( container_it );
IntContainerT container_instance_
bool isStored(const PreMultiContainerKeyT &obj_key) const
std::string obj_type_str_
void multiRetrieve(std::vector< std::pair< PreMultiContainerKeyT, ObjectT > > &objs_vector) const
static Log * instance()
Returns the instance pointer, creating the object on the first call.
ObjectT * getObjPtr() const
const std::string & getObjTypeInfo() const
void error(const char *format,...)
'Error' level.
const PreMultiContainer< PreMultiContainerKeyT > & operator=(const PreMultiContainer< PreMultiContainerKeyT > &ext_instance)
void remove(const PreMultiContainerKeyT &obj_key)
bool retrieve(const PreMultiContainerKeyT &obj_key, ObjectT &obj_reference) const
void store(const PreMultiContainerKeyT &obj_key, const ObjectT &obj_reference)
void setObjPtr(ObjectT *ptr)
bool operator==(const PreMultiContainer< PreMultiContainerKeyT > &ext_instance) const
virtual MCNodeInterface< PreMultiContainerKeyT > * clone() const =0
std::map< PreMultiContainerKeyT, MCNodeInterface< PreMultiContainerKeyT > * > IntContainerT
virtual const std::string & getObjTypeInfo() const =0
MCNodeInterface< PreMultiContainerKeyT > * clone() const
MCNodeInterface(const MCNodeInterface< PreMultiContainerKeyT > &)
const MCNodeInterface< PreMultiContainerKeyT > & operator=(const MCNodeInterface< PreMultiContainerKeyT > &)
virtual ~MCNodeInterface()
bool operator!=(const PreMultiContainer< PreMultiContainerKeyT > &ext_instance) const