Focus on ACE

订阅 ace-china
电子邮件:
浏览存于 groups.google.com 上的所有帖子

C++博客 首页 新随笔 联系 聚合 管理
  64 Posts :: 3 Stories :: 22 Comments :: 0 Trackbacks
//  TestHaspMap.cpp : Defines the entry point for the console application.
//

#include 
" stdafx.h "
#include 
" ACE/Basic_Types.h "
#include 
" ACE/Map_Manager.h "
#include 
" ACE/SString.h "
#include 
" ACE/Log_Msg.h "
#include 
" ACE/Null_Mutex.h "

class  PhoneNumber
{
public :
    PhoneNumber(
const   char *  number):number_(number)
    {

    }
    
const   char *  getNumber( void )
    {
        
return  number_.c_str();
    }
private :
    ACE_SString  number_; 
};



typedef ACE_UINT16 CONNECTION_ID;

typedef ACE_Null_Mutex MAP_MUTEX;

typedef ACE_Map_Manager
< CONNECTION_ID,PhoneNumber * , MAP_MUTEX >
   CONNECTION_MAP;

typedef ACE_Map_Iterator
< CONNECTION_ID, PhoneNumber * , MAP_MUTEX >
     CONNECTION_MAP_ITERATOR;

typedef ACE_Map_Entry
< CONNECTION_ID, PhoneNumber *>
    CONNECTION_MAP_ENTRY;

typedef ACE_Map_Manager
< CONNECTION_ID,CONNECTION_MAP * ,MAP_MUTEX >
     MAP_MAP;

typedef ACE_Map_Iterator
< CONNECTION_ID, CONNECTION_MAP * , MAP_MUTEX >
MAP_MAP_ITERATOR;

typedef ACE_Map_Entry
< CONNECTION_ID, CONNECTION_MAP *>
MAP_MAP_ENTRY;


int  ACE_TMAIN( int  argc, _TCHAR *  argv[])
{


    CONNECTION_MAP connection_map;
    PhoneNumber  me(
" 13717928*** " );
    PhoneNumber  office(
" 010-82378*** " );

    PhoneNumber  home(
" 13366686** " );
    
int  result  =   - 1 ;
    result 
=  connection_map.bind( 1 , & me);
     ACE_ASSERT(result 
==   0 );
    result 
=   connection_map.bind( 2 , & office);
    ACE_ASSERT(result 
==   0 );
    result 
=   connection_map.bind( 3 , & home);
    ACE_ASSERT(result 
==   0 );
    result 
=  connection_map.bind( 5 , & home);
    ACE_ASSERT(result 
==   0 );

    connection_map.unbind(
3 );
    CONNECTION_MAP_ITERATOR it(connection_map);
  
    
for  (CONNECTION_MAP_ENTRY  * =   0 ;
        it.next (i) 
!=   0 ;
        it.advance ())
    {
        PhoneNumber
*  phone  =  i -> int_id_;
        ACE_DEBUG((LM_INFO,ACE_TEXT(
" 连接号码 %d, 电话号码 %s\n " ),
            i
-> ext_id_,
            phone
-> getNumber()));
    }

   PhoneNumber
*  any_phone  =   0 ;
   CONNECTION_ID any_id 
=   5 ;

    result 
=  connection_map.find(any_id,any_phone);
   
if ( result  !=    - 1 )
   {
       ACE_DEBUG((LM_INFO,ACE_TEXT(
" 连接号码 %d, 电话号码 %s\n " ),
           any_id,
           any_phone
-> getNumber()));
   } 
   
else
   {
       ACE_DEBUG((LM_INFO,ACE_TEXT(
" 连接号码 %d, 电话号码 %s\n " ),
           any_id,
           
" not found. " ));
   }

   MAP_MAP map_map;
   map_map.bind(
1 , & connection_map);
   size_t n 
=  map_map.current_size();
   MAP_MAP_ITERATOR map_it(map_map);

   
for  (MAP_MAP_ENTRY  * =   0 ;
       map_it.next (j) 
!=   0 ;
       map_it.advance ())
   {
       CONNECTION_MAP
*  cur_map  =  j -> int_id_;
        size_t count 
=  cur_map -> current_size();
         PhoneNumber
*  any_phone2  =   0 ;
         
if  (cur_map -> find( 2 ,any_phone2) !=- 1 )
         {
             ACE_DEBUG((LM_INFO,ACE_TEXT(
" 内部map中电话号码 %s\n " ),
                 any_phone2
-> getNumber()));
         }
   }

    
return   0 ;
}

posted on 2006-07-13 13:39 Stone Jiang 阅读(3304) 评论(1)  编辑 收藏 引用 所属分类: ACE

Feedback

# re: ACE_Hash_Map的使用示例 2006-09-18 11:48 x11
ft,这是ACE_Map不是ACE_Hash_Map啊  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理