ACE相关书籍
包含ACE多本资料
包含ACE相关主要书籍
源代码在线查看: ace 常用的类和样板 .txt
ACE 常用的类和样板
ACE_OS::strcasecmp 大小写比较
ACE_OS::strncasecmp n个字符大小写比较
ACE::execname (prog1); 执行prog1程序
ACE_OS_String::strdup 字符串深拷贝
ACE_OS::uname (&uname); 获取操作系统信息
ACE_Copy_Disabled 非拷贝基础类
ACE_DLL 动态库类
ACE_Process_Options
ACE_Env_Value 环境变量类
ACE_Obstack_T
ACE_Ptr 指针类
ACE_Refcounted_Auto_Ptr 指针引用计数与auto_ptr相同
ACE_Refcounted_Auto_Ptr_Rep
ACE_Auto_Basic_Ptr
ACE_Vector 提供了STL相似的vector
ACE_ARGV main参数处理类
ACE_ARGV cl (argv);
// My own stuff.
ACE_ARGV my;
// Add to my stuff.
my.add (ACE_TEXT ("-ORBEndpoint iiop://localhost:12345"));
// Print the contents of the combined .
for (int i = 0; i < a.argc (); i++)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%d) %s\n"),
i,
a.argv ()[i]));
ACE_Arg_Shifter 参数构造转换类
const int test_argc_size = 5;
int argl (test_argc_size);
const ACE_TCHAR *args[test_argc_size] = {
ACE_TEXT ("-known"),
ACE_TEXT ("-huh"),
ACE_TEXT ("-arg"),
ACE_TEXT ("-what"),
ACE_TEXT ("arg")
};
ACE_Arg_Shifter shifter (argl, args);
if (!shifter.is_anything_left ())
ACE_ERROR ((LM_ERROR, "is_anything_left() returned 0 at start.\n"));
static void consume_arg (int &argc, ACE_TCHAR *argv[])
{
ACE_Arg_Shifter arg_shifter (argc, argv);
if (arg_shifter.is_anything_left ())
arg_shifter.consume_arg (1);
// Once we initialize an arg_shifter, we must iterate through it all!
while ((arg_shifter.is_anything_left ()))
arg_shifter.ignore_arg (1);
}
ACE_Get_Opt 参数选项处理类
static void
parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("w:n:"));
int c;
while ((c = get_opt ()) != -1)
switch (c)
{
case 'w':
n_workers = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'n':
n_iterations = ACE_OS::atoi (get_opt.opt_arg ());
break;
default:
print_usage_and_die ();
break;
}
}
ACE_Atomic_Op 原子操作类
ACE_Atomic_Op foo (5);
long result = ++foo;
result = --foo;
ACE_Auto_IncDec 自动增加计数器
ACE_Adaptive_Lock 提供统一的锁API
ACE_SString 提供了简单的字串操作
ACE_WString 宽字符类
ACE_TString 字符类的typedef
char operator []
char &operator []
ACE_SString substring
ACE_SString substr
u_long hash
size_t length
void rep (char *s) 替换类中的指针
int strstr
ACE_Auto_String_Free 简单的字符串指针释放类
get 获取类中的指针
release 释放指针内存
reset 将类中的指针置0
ACE_Tokenizer 字串分割类
char buf[30];
ACE_OS::strcpy(buf, "William/Joseph/Hagins");
ACE_Tokenizer tok (buf);
tok.delimiter ('/');
for (char *p = tok.next (); p; p = tok.next ())
cout
输出
William/Joseph/Hagins
Joseph/Hagins
Hagins
UUID_Generator 唯一标识产生器,象COM的UUID
UUID* generateUUID()
ACE_Time_Value 定时器使用方法
ACE_Time_Value wait (0,
iterations * 1000 * 100); // Wait 'iter' msec
ACE_Time_Value tv = ACE_OS::gettimeofday () + wait;
ACE_Time_Value diff = ACE_OS::gettimeofday ();
diff = diff - tv; // tv should have been reset to time acquired
long diff_msec = diff.msec ();
// Wait a little longer each time
static long wait_secs = 3;
ACE_Time_Value wait = ACE_OS::gettimeofday ();
ACE_Time_Value begin = wait;
wait.sec (wait.sec () + wait_secs);
ACE_Auto_Event 象WIN32的事件类
ACE_Event
static void *
worker (void *)
{
for (int iterations = 1;
iterations iterations++)
{
ACE_Time_Value wait (0,
iterations * 1000 * 100); // Wait 'iter' msec
ACE_Time_Value tv = ACE_OS::gettimeofday () + wait;
if (evt.wait (&tv) == -1)
{
// verify that we have ETIME
ACE_ASSERT(ACE_OS::last_error() == ETIME);
++timeouts;
ACE_Time_Value diff = ACE_OS::gettimeofday ();
diff = diff - tv; // tv should have been reset to time acquired
long diff_msec = diff.msec ();
if (diff_msec > ACE_ALLOWED_SLACK)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Acquire fails time reset test\n")));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Diff btw now and returned time: %d ms\n"),
diff.msec ()));
test_result = 1;
}
// Hold the lock for a while.
ACE_OS::sleep (ACE_Time_Value (0,
(ACE_OS::rand () % 1000) * 1000));
evt.signal ();
}
ACE_Thread::yield ();
}
return 0;
}
ACE_Auto_IncDec
typedef ACE_Atomic_Op INTERLOCKED_INT;
static INTERLOCKED_INT current_threads_in_first_section;
static INTERLOCKED_INT current_threads_in_second_section;
static void *
worker (void *)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%t) worker starting\n")));
{ // First section.
typedef ACE_Atomic_Op INTERLOCKED_INT;
static INTERLOCKED_INT current_threads_in_first_section;
ACE_Auto_IncDec threads_in_section_auto_inc_dec
(current_threads_in_first_section);
// Wait according to the number of threads...
ACE_Time_Value pause (current_threads_in_first_section.value (),
0);
ACE_OS::sleep (pause);
}
{ // Second section.
ACE_Auto_IncDec threads_in_section_auto_inc_dec
(current_threads_in_second_section);
// Wait according to the number of threads inside the previous
// section...
ACE_Time_Value pause (current_threads_in_first_section.value (),
0);
ACE_OS::sleep (pause);
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%t) worker exiting\n")));
return 0;
}
ACE_Profile_Timer 性能定时器
ACE_Profile_Timer timer;
ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;
timer.start ();
timer.stop ();
timer.elapsed_time (elapsed_time);
ACE_High_Res_Timer 高精度定时器
ACE_High_Res_Timer timer;
timer.reset ();
timer.start ();
while (i--)
{
ptr = allocator.malloc (chunk_size);
allocator.free (ptr);
}
timer.stop ();
timer.elapsed_time (tc);
ACE_Base64 Base64编码类
ACE_Date_Time 时间类
ACE_Date_Time dt;
long month = dt.month ();
long day = dt.day ();
long year = dt.year ();
long hour = dt.hour ();
long minute = dt.minute ();
long seconds = dt.second ();
long usec = dt.microsec ();
ACE_Dirent_Selector 目录处理类
ACE_Thread_Manager 线程管理器
创建线程等待结束
ACE_Thread_Manager::instance()->spawn (wait_and_kill_dialog,m_pMainWnd);
ACE_Thread_Manager::instance()->wait();