Exemplo n.º 1
0
 inline std::ostream& operator<<(
     std::ostream& os, const rdma_thread_print_helper&)
 {
     if (hpx::threads::get_self_id()==hpx::threads::invalid_thread_id) {
         os << "------------------ ";
     }
     else {
         hpx::threads::thread_data *dummy =
             hpx::this_thread::get_id().native_handle().get();
         os << hexpointer(dummy);
     }
     os << nhex(12) << std::this_thread::get_id() << " cpu "
        << decnumber(sched_getcpu());
     return os;
 }
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// 取得格式結果
nstring GetResult(IN const nstring &szFormat, IN const nstring &szData)
{
	if(szFormat.empty())
		return szData;

	if(szData.empty())
		return __T("");

	nstring szResult;
	nstring::const_iterator Itor = szFormat.begin();
	nstring::size_type Width = 0;
	bool bOct = false;
	bool bHex1 = false;
	bool bHex2 = false;
	bool bZero = false;
	bool bAlign = false; // 對齊旗標, true表示靠左對齊, false表示靠右對齊

	// 檢查旗標
	while(Itor != szFormat.end() && _tcschr(__T("oxX0LR"), *Itor))
	{
		switch(*Itor++)
		{
		case __T('o'): bOct = true; break;
		case __T('x'): bHex1 = true; break;
		case __T('X'): bHex2 = true; break;
		case __T('0'): bZero = true; break;
		case __T('L'): bAlign = true; break;
		case __T('R'): bAlign = false; break;
		default: break;
		}//switch
	}//while

	// 取得寬度
	{
		nstring szWidth;

		while(Itor != szFormat.end() && _istdigit(*Itor))
			szWidth += *Itor++;

		nton(szWidth, Width);
		Width = std::max(Width, szData.size());
	}

	// 內容設置
	{
		int iData = 0;

		nton(szData, iData);

		if(bOct && iData != 0)
			szResult = noct(iData);

		if(bHex1 && iData != 0)
			szResult = nhex(iData);

		if(bHex2 && iData != 0)
			szResult = nsupper(nhex(iData));
	}

	if(szResult.empty())
		szResult = szData;

	// 內容填充
	if(Width > szResult.size())
	{
		if(bAlign)
			szResult.insert(szResult.end(), Width - szResult.size(), __T(' '));
		else
			szResult.insert(szResult.begin(), Width - szResult.size(), bZero ? __T('0') : __T(' '));
	}//if

	return szResult;
}