コード例 #1
0
ファイル: filterb.cpp プロジェクト: fw1121/paper-zhang2014
// Pos not required; used for sanity check
static void DeleteFirstInstanceFromIndex(int Kmer, int Pos)
	{
	if (-1 == Kmer)
		return;

	assert(Kmer >= 0 && Kmer < KmerIndexCount);

	INDEX_ENTRY *E = Heads[Kmer];

	if (E == 0)
		Quit("DFI Kmer=%d %s Pos=%d", Kmer, CodeToString(Kmer, k), Pos);
//	assert(E != 0);
	assert(0 == E->Prev);
	assert(Pos == E->Pos);

// Delete from index
	INDEX_ENTRY *NewHead = E->Next;
	if (NewHead == 0)
		{
		Heads[Kmer] = 0;
		Tails[Kmer] = 0;
		}
	else
		{
		assert(NewHead->Prev == E);
		NewHead->Prev = 0;
		}
	Heads[Kmer] = NewHead;

	AddToFreeList(E);
	}
コード例 #2
0
void CodeGenerator::match(string sym) { // 匹配函数
    string Now = CodeToString(Tokens[CurToken]);
    if(Now == sym) {
        CurToken ++;
    } else {
        printf("in line [%d] : expect %s!\n", CurLine(), sym.c_str());
        exit(0);
    }
    //printf("in Line [%d]:%d  Match %s\n", CurLine(), CurToken, sym.c_str());
}
コード例 #3
0
ファイル: PokemonCodec.cpp プロジェクト: h16o2u9u/rtoss
VOID CPokemonCodec::GetNickName(CString &szName)
{
	if(m_pPokemon == NULL)
		return;

	switch(m_pPokemon->Header.bNickNameLanguage)
	{
	case 0x00:		// an empty one
		szName = _T("");
		break;

	case 0x01:		// jp version
		CodeToString(szName, m_pPokemon->Header.bNickName, 5, 0xFF, lang_jp);
		break;

	default:		// en version
		CodeToString(szName, m_pPokemon->Header.bNickName, POKEMON_NICK_NAME_SIZE, 0xFF, lang_en);
		break;
	}
}
コード例 #4
0
ファイル: CodeDetector.cpp プロジェクト: goofwear/stepmania
void CodeDetector::RefreshCacheItems( RString sClass )
{
    if( sClass == "" )
        sClass = "CodeDetector";
    FOREACH_ENUM( Code, c )
    {
        InputQueueCode& item = g_CodeItems[c];
        const RString sCodeName = CodeToString(c);
        const RString sButtonsNames = THEME->GetMetric(sClass,sCodeName);

        item.Load( sButtonsNames );
    }
コード例 #5
0
ファイル: CodeDetector.cpp プロジェクト: BitMax/openitg
void CodeDetector::RefreshCacheItems( CString sClass )
{
	if( sClass == "" )
		sClass = "CodeDetector";
	FOREACH_Code( c )
	{
		CodeItem& item = g_CodeItems[c];
		const CString sCodeName = CodeToString(c);
		const CString sButtonsNames = THEME->GetMetric(sClass,sCodeName);

		item.Load( sButtonsNames );
	}
}
コード例 #6
0
ファイル: testAliHLTReadoutList.C プロジェクト: alisw/AliRoot
/**
 * Checks if the basic empty and clear methods work.
 */
bool CheckEmptyAndClear()
{
	AliHLTReadoutList rl;
	if (rl.Empty() != true)
	{
		cerr << "ERROR: AliHLTReadoutList::Empty returns false for an empty readout list." << endl;
		return false;
	}
	
	// Enable all the detectors and check this operation.
	rl.Enable(AliHLTReadoutList::kALLDET);
	for (int i = 0; i < kgNumberOfCodes; ++i)
	{
		if (i == 19) continue; // This is the test DDL. off by default.
		if (not rl.DetectorEnabled(kgDetCodes[i]))
		{
			cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) did not enable for "
				<< CodeToString(kgDetCodes[i]) << "." << endl;
			return false;
		}
	}
	if (rl.DetectorEnabled(AliHLTReadoutList::kDAQTEST))
	{
		cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) enabled bits"
			" for AliHLTReadoutList::kDAQTEST but should not have." << endl;
		return false;
	}
	
	rl.Clear();
	// Fetch the raw bits for the readout list structure and check that they
	// are all zero, since we should have disabled everything in the loop above.
	AliHLTEventDDL bits = rl;
	if (bits.fCount != (unsigned int)gkAliHLTDDLListSize)
	{
		cerr << "ERROR: Typecast operator AliHLTEventDDL () is not"
			" setting the fCount of the structure correctly." << endl;
		return false;
	}
	for (int j = 0; j < gkAliHLTDDLListSize; ++j)
	{
		if (bits.fList[j] != 0x0)
		{
			cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
				" bitfield structure is not zero as expected after a"
				" call to AliHLTReadoutList::Clear." << endl;
			return false;
		}
	}
	
	return true;
}
コード例 #7
0
ファイル: PokemonCodec.cpp プロジェクト: h16o2u9u/rtoss
VOID CPokemonCodec::GetCatcherName(CString &szCatcherName)
{
	if(m_pPokemon == NULL)
		return;

	if(m_pPokemon->Header.bNickNameLanguage == 0x00)
	{
		szCatcherName = _T("");
	}
	else
	{
		switch(m_dwLang)
		{
		case lang_jp:		// jp version
			CodeToString(szCatcherName, m_pPokemon->Header.bCatcherName, POKEMON_TRAINER_NAME_SIZE, 0xFF, lang_jp);
			break;

		default:		// en version
			CodeToString(szCatcherName, m_pPokemon->Header.bCatcherName, POKEMON_TRAINER_NAME_SIZE, 0xFF, lang_en);
			break;
		}
	}
}
コード例 #8
0
ファイル: PokemonTool.cpp プロジェクト: jiangzhengwenjz/rtoss
BOOL CodeToString(CString &szString, LPBYTE pbCode, DWORD cbCodeLength, BYTE bTerminatingCode, DWORD dwLang)
{
	LPTSTR	pStr = NULL;

	if(CodeToString(&pStr, pbCode, cbCodeLength, bTerminatingCode, dwLang) != 0)
	{
		szString = pStr;
		LocalFree(reinterpret_cast<HLOCAL>(pStr));
		szString.Replace(_T("\n"), _T("\r\n"));
		return TRUE;
	}
	else
	{
		szString.Empty();
		return FALSE;
	}
}
コード例 #9
0
ファイル: ShortcutChordCtrl.cpp プロジェクト: archmatrix/e
bool ShortcutChordCtrl::OnPreKeyUp(wxKeyEvent& event) {
	int id = event.GetKeyCode();

	// Ignore initial presses on modifier keys
	if (id == WXK_SHIFT || id == WXK_ALT || id == WXK_CONTROL ||
		id == WXK_WINDOWS_LEFT || id == WXK_WINDOWS_RIGHT)
	{
		return false;
	}

	int modifiers = event.GetModifiers();
	
#ifdef __WXMSW__
	// GetModifiers does not report the windows keys
	if (::GetKeyState(VK_LWIN) < 0) modifiers |= 0x0008; // wxMOD_META (Left Windows key)
	if (::GetKeyState(VK_RWIN) < 0) modifiers |= 0x0008; // wxMOD_META (Right Windows key)
#endif

	wxString binding = CodeToString(id, modifiers);

	wxString value = GetValue();
	if(value.Contains(wxT(" "))) {
		value = wxT("");
	}

	if(!value.empty()) {
		value = wxString::Format(wxT("%s %s"), value, binding);
	} else {
		value = binding;
	}

	m_binding = value;
	SetValue(value);

	event.StopPropagation();

	// wxLogDebug(wxT("Binding: %s"), m_binding.c_str());
	return true;
}
コード例 #10
0
// 函数块
void CodeGenerator::Block() {
    while(!isNext("}")) {
        CodeToken T = getToken();
        string value = T.value;
        if(value == "if") {
            If();
        } else if(value == "while") {
            While();
        } else if(value == "for") {
            For();
        } else if(value == "read") {
            match("("); addQuad("read", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "write") {
            match("("); addQuad("write", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "return") {
            addQuad("return", itos(getToken().num), "$", "$");   match(";");
        } else if(CodeToString(T) == "id") {
            CurToken--;
            Assign();
        } else {
            puts("函数块错误!!"); printf("in %d", CurLine()); exit(0);
        }
    }
}
コード例 #11
0
ファイル: testAliHLTReadoutList.C プロジェクト: alisw/AliRoot
/**
 * Tests enabling and disabling of different detectors.
 */
bool CheckEnablingDisabling()
{
	for (int i = 0; i < 10000; ++i)
	{
		// Get 3 random detector codes.
		int detNum[3] = {
			gRandom->Integer(kgNumberOfCodes),
			gRandom->Integer(kgNumberOfCodes),
			gRandom->Integer(kgNumberOfCodes)
		};
		int code[3] = {
			kgDetCodes[detNum[0]],
			kgDetCodes[detNum[1]],
			kgDetCodes[detNum[2]]
		};
		// make sure the codes are not duplicated.
		while (code[1] == code[0])
		{
			detNum[1] = gRandom->Integer(kgNumberOfCodes);
			code[1] = kgDetCodes[detNum[1]];
		}
		while (code[2] == code[1] or code[2] == code[0])
		{
			detNum[2] = gRandom->Integer(kgNumberOfCodes);
			code[2] = kgDetCodes[detNum[2]];
		}
		
		// Choose the number of codes to use, from 1 to max 3.
		int codeCount = gRandom->Integer(3) + 1;
		
		// Build up the detector code list for the AliHLTReadoutList constructor.
		int totalCode = 0;
		for (int j = 0; j < codeCount; ++j) totalCode |= code[j];
		
		AliHLTReadoutList rl(totalCode);
		if (rl.Empty() == true)
		{
			cerr << "ERROR: AliHLTReadoutList::Empty returns true for a non empty readout list." << endl;
			return false;
		}
		
		// Check that the correct detectors have been enabled and
		// that we can disable a detector correctly.
		for (int j = 0; j < codeCount; ++j)
		{
			if (rl.DetectorEnabled(code[j]) == false)
			{
				cerr << "ERROR: Detector was not enabled for "
					<< CodeToString(code[j]) << " by constructor." << endl;
				return false;
			}
			if (rl.DetectorDisabled(code[j]) == true)
			{
				cerr << "ERROR: DetectorDisabled returned and incorrect result"
					" when detectors enabled for "
					<< CodeToString(code[j]) << " by constructor." << endl;
				return false;
			}
			
			// Also check each bit individualy according to AliHLTDAQ values.
			int det = detNum[j];
			int maxddls = AliHLTDAQ::NumberOfDdls(det);
			for (int ddlindex = 0; ddlindex < maxddls; ++ddlindex)
			{
				int ddlid = AliHLTDAQ::DdlIDOffset(det) | (ddlindex & 0xFF);
				if (rl.IsDDLDisabled(ddlid))
				{
					cerr << "ERROR: Bit not set for DDL " << ddlid
						<< ", even though detector "
						<< AliHLTDAQ::OnlineName(det)
						<< " was enabled." << endl;
					return false;
				}
			}
			
			rl.Disable(code[j]);
			if (rl.DetectorEnabled(code[j]) == true)
			{
				cerr << "ERROR: AliHLTReadoutList::Disable(x) is not working for x = "
					<< CodeToString(code[j]) << "." << endl;
				return false;
			}
			if (rl.DetectorDisabled(code[j]) == false)
			{
				cerr << "ERROR: DetectorDisabled returned and incorrect result"
					" when calling AliHLTReadoutList::Disable(x) for "
					<< CodeToString(code[j]) << "." << endl;
				return false;
			}
		}
		
		// Fetch the raw bits for the readout list structure and check that they
		// are all zero, since we should have disabled everything in the loop above.
		AliHLTEventDDL bits = rl;
		for (int j = 0; j < gkAliHLTDDLListSize; ++j)
		{
			if (bits.fList[j] != 0x0)
			{
				cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
					" bitfield structure is not zero as expected." << endl;
				return false;
			}
		}
	}
	return true;
}
コード例 #12
0
bool CodeGenerator::isNext(string sym) {
    string Next = CodeToString(Tokens[CurToken]);
    if(Next == sym) return true;
    else return false;
}
コード例 #13
0
// 表达式
string CodeGenerator::Expr() {
    if(Tokens[CurToken].Type == String) {
        string res = newTemp("string");
        newConst("string", Tokens[CurToken].value);
        CurToken++;
        return res;
    }
    int L = CurToken, R;
    int cntBrac = 0;
    for(R = L; R < Tokens.size(); R++) {
        string val = Tokens[R].value;
        if(val == ";" || val == ")" && cntBrac == 0) break;
        if(val == "(") cntBrac++;
        if(val == ")") cntBrac--;
    }
    CurToken = R;

    map<string, int> Prior;
    Prior["("] = 10, Prior[")"] = 0;
    Prior["!"] = 1;
    Prior["%"] = Prior["*"] = Prior["/"] = 2;
    Prior["+"] = Prior["-"] = 3;
    Prior[">="] = Prior["<="] = Prior[">"] = Prior["<"] = 4;
    Prior["=="] = Prior["!="] = 5;
    Prior["&&"] = 6;
    Prior["||"] = 7;

    stack<string> Num, Op;
    for(int i = L; i < R; i++) {
        string Type = CodeToString(Tokens[i]);
        string val = Tokens[i].value;
        if(Type == "number" || Type == "id") {
            if(Type == "id") Num.push(val);
            else Num.push(newConst((string)(Tokens[i].Type == Integer ? "int" : "double"), itos(Tokens[i].num)));
        } else {
            if(val == "(") {
                Op.push(val);
            } else if(val == ")") {
                while(Op.top() != "(") {
                    string op = Op.top(); Op.pop();
                    string y = Num.top(); Num.pop();
                    if(op == "!") {
                        string res = newTemp(VarTable[y].Type); Num.push(res);
                        addQuad(op, y, "$", res);
                        continue;
                    }
                    string x = Num.top(); Num.pop();
                    string res = newTemp(VarTable[x].Type); Num.push(res);
                    if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
                        addQuad("J" + op, x, y, itos(CurLabel + 3));
                        addQuad("=", res, "0", res);
                        addQuad("J", "$", "$", itos(CurLabel + 2));
                        addQuad("=", res, "1", res);
                    } else {
                        addQuad(op, x, y, res);
                    }
                }
                Op.pop();
            } else {
                while(!Op.empty() && Prior[val] >= Prior[Op.top()]) {
                    string op = Op.top(); Op.pop();
                    string y = Num.top(); Num.pop();
                    if(op == "!") {
                        string res = newTemp(VarTable[y].Type); Num.push(res);
                        addQuad(op, y, "$", res);
                        continue;
                    }
                    string x = Num.top(); Num.pop();
                    string res = newTemp(VarTable[x].Type); Num.push(res);
                    if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
                        addQuad("J" + op, x, y, itos(CurLabel + 3));
                        addQuad("=", res, "0", res);
                        addQuad("J", "$", "$", itos(CurLabel + 2));
                        addQuad("=", res, "1", res);
                    } else {
                        addQuad(op, x, y, res);
                    }
                }
                Op.push(val);
            }
        }
    }
    while(!Op.empty()) {
        string op = Op.top(); Op.pop();
        string y = Num.top(); Num.pop();
        if(op == "!") {
            string res = newTemp(VarTable[y].Type); Num.push(res);
            addQuad(op, y, "$", res);
            continue;
        }
        string x = Num.top(); Num.pop();
        string res = newTemp(VarTable[x].Type); Num.push(res);
        if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
            addQuad("J" + op, x, y, itos(CurLabel + 3));
            addQuad("=", res, "0", res);
            addQuad("J", "$", "$", itos(CurLabel + 2));
            addQuad("=", res, "1", res);
        } else {
            addQuad(op, x, y, res);
        }
    }
    return Num.top();
}
コード例 #14
0
ファイル: filterb.cpp プロジェクト: fw1121/paper-zhang2014
static void LogLocations(int Kmer)
	{
	Log("LogLocations(%d %s)", Kmer, CodeToString(Kmer, k));
	for (DeclareListPtr(p) = GetListPtr(Kmer); NotEndOfList(p); p = GetListNext(p))
		Log(" [%d]=%d", p->Pos, StringToCode(SeqQ + p->Pos, k));
	}
コード例 #15
0
ファイル: filterb.cpp プロジェクト: fw1121/paper-zhang2014
static void ValidateIndex(const char *Seq, int WindowStart, int WindowEnd)
	{
	int FreeCount = 0;
	for (INDEX_ENTRY *p = FreeEntries; p != 0; p = p->Next)
		{
		if (++FreeCount > KmerWindowCount)
			Quit("Validate index failed free count");

		if (p->Kmer != -2 || p->Pos != -2)
			Quit("Validate index failed free != -2");

		const INDEX_ENTRY *pNext = p->Next;
		if (0 != pNext && pNext->Prev != p)
			Quit("Validate index failed free pNext->Prev != p");

		const INDEX_ENTRY *pPrev = p->Prev;
		if (0 != pPrev && pPrev->Next != p)
			Quit("Validate index failed free pPrev->Next != p");
		}

	for (int Pos = WindowStart; Pos < WindowEnd; ++Pos)
		{
		const int Kmer = GetKmer(Seq, Pos);
		if (-1 == Kmer)
			continue;
		for (DeclareListPtr(p) = GetListPtr(Kmer); NotEndOfList(p); p = GetListNext(p))
			{
			const int HitPos = GetListPos(p);
			if (HitPos == Pos)
				goto Found;
			}
		Quit("Validate index failed, pos not found");
	Found:;
		}

	int IndexedCount = 0;
	for (int Kmer = 0; Kmer < KmerIndexCount; ++Kmer)
		{
		INDEX_ENTRY *Head = Heads[Kmer];
		INDEX_ENTRY *Tail = Tails[Kmer];
		if (Head != 0 && Head->Prev != 0)
			Quit("Head->Prev != 0");
		if (Tail != 0 && Tail->Next != 0)
			Quit("Tail->Next != 0");
		if ((Head == 0) != (Tail == 0))
			Quit("Head / tail");
		int PrevHitPos = -1;
		int ListIndex = 0;
		for (DeclareListPtr(p) = GetListPtr(Kmer); NotEndOfList(p); p = GetListNext(p))
			{
			++IndexedCount;
			if (IndexedCount > KmerWindowCount)
				Quit("Valiate index failed, count");

			const INDEX_ENTRY *pNext = p->Next;
			if (Kmer != p->Kmer)
				Quit("Validate index failed, kmer");

			if (0 != pNext && pNext->Prev != p)
				Quit("Validate index failed pNext->Prev != p");

			const INDEX_ENTRY *pPrev = p->Prev;
			if (0 != pPrev && pPrev->Next != p)
				Quit("Validate index failed pPrev->Next != p");

			const int HitPos = GetListPos(p);
			if (HitPos < WindowStart || HitPos > WindowEnd)
				Quit("ValidateIndex failed, hit not in window kmer=%d %s",
				  Kmer, CodeToString(Kmer, k));

			int IsTail = (p->Next == 0);
			if (HitPos < PrevHitPos)
				Quit("Validate index failed, sort order Kmer=%d HitPos=%d PrevHitPos=%d ListIndex=%d IsTail=%d",
				  Kmer, HitPos, PrevHitPos, ListIndex, IsTail);

			PrevHitPos = HitPos;
			++ListIndex;
			}
		}
	if (IndexedCount > KmerWindowCount)
		Quit("Validate index failed, count [2]");
	}