CInputVirtualDevice* CInputDevice::CreateVariableVirtualDeviceFromThis(CInputActions* pcInputActions)
{
	CInputVirtualDevice*	pcVirtual;
	CInputSourceDesc*		pcSource;
	CInputDevices*			pcInputDevices;
	CChars					szTemp;
	CArrayIntAndPointer			apcSourceDescs;
	int						i;

	pcInputDevices = GetInputDevices();

	szTemp.Init(mszFriendlyName.Text());
	szTemp.Append(" Variable");
	pcVirtual = pcInputDevices->CreateVirtualDevice(szTemp.Text());
	szTemp.Kill();

	mcVariables.SetChords(pcVirtual->GetChords());

	apcSourceDescs.Init(8);
	mpcDesc->GetVariableChordDescs()->GetInputSourceDescs(&apcSourceDescs, mpcDesc);
	for (i = 0; i < apcSourceDescs.NumElements(); i++)
	{
		pcSource = (CInputSourceDesc*)apcSourceDescs.GetPtr(i);
		pcVirtual->AddSource(this, pcSource);
	}
	apcSourceDescs.Kill();
	pcVirtual->DoneAddingSources();
	GetInputDevices()->AddChords(pcVirtual, mpcDesc->GetVariableChordDescs(), this);
	pcInputDevices->UpdateCommonality();
	pcVirtual->Unstoppable();
	return pcVirtual;
}
Beispiel #2
0
BOOL CLogFile::FindHoles(CArrayIntAndPointer* papvOverlapping, filePos iPosition, filePos iLength)
{
	CArrayIntAndPointer				apvOverlappingSorted;
	int							i;
	CLogFileCommandWrite*	psWrite;
	int							eCommand;
	BOOL						bHoles;
	filePos						iEnd;

	if (iLength == 0)
	{
		return FALSE;
	}
	if (papvOverlapping->NumElements() == 0)
	{
		return FALSE;
	}

	apvOverlappingSorted.Init(1);
	apvOverlappingSorted.Copy(papvOverlapping);
	apvOverlappingSorted.QuickSort(CompareLogFileWrite);

	apvOverlappingSorted.Get(0, (void**)&psWrite, &eCommand);
	if (psWrite->iPosition > iPosition)
	{
		apvOverlappingSorted.Kill();
		return TRUE;
	}
	else
	{
		iEnd = psWrite->iPosition + psWrite->iSize -1;
	}

	bHoles = FALSE;
	for (i = 1; i < apvOverlappingSorted.NumElements(); i++)
	{
		apvOverlappingSorted.Get(i, (void**)&psWrite, &eCommand);
		if (psWrite->iPosition > (iEnd+1))
		{
			bHoles = TRUE;
			break;
		}
		iEnd = psWrite->iPosition + psWrite->iSize -1;
		if (iEnd >= (iPosition + iLength-1))
		{
			break;
		}
	}

	if (iEnd < (iPosition + iLength-1))
	{
		bHoles = TRUE;
	}

	apvOverlappingSorted.Kill();
	return bHoles;
}
Beispiel #3
0
filePos CLogFile::ReadNextTouchingWrites(int iWriteIndex, void* pvDest, filePos iSize, filePos iCount)
{
	CArrayIntAndPointer	apvOverlapping;
	BOOL			bAny;
	filePos			iByteSize;

	iByteSize = iSize * iCount;
	bAny = FindTouchingWriteCommands(iWriteIndex, &apvOverlapping, miPosition, iByteSize, TRUE);
	if (bAny)
	{
		CopyWritesToRead(&apvOverlapping, iByteSize, pvDest);
		apvOverlapping.Kill();
	}
	return iCount;
}
Beispiel #4
0
filePos CLogFile::Write(const void* pvSource, filePos iSize, filePos iCount)
{
	CArrayIntAndPointer			apvOverlapping;
	BOOL					bAny;
	filePos					iByteLength;
	CLogFileCommandWrite*	pcWrite;

	if (IsFileModeWritable(meFileMode))
	{
		mbTouched = TRUE;

		iByteLength = iSize * iCount;

		if (miLastWriteOpenIndex == -1)
		{
			bAny = FALSE;
		}
		else
		{
			bAny = FindTouchingWriteCommands(miLastWriteOpenIndex + 1, &apvOverlapping, miPosition, iByteLength, FALSE);
		}

		if (bAny)
		{
			AmalgamateOverlappingWrites(&apvOverlapping, pvSource, miPosition, iByteLength);
			apvOverlapping.Kill();
			miPosition += iByteLength;
		}
		else
		{
			pcWrite = AddWriteCommand(miPosition, (void*)pvSource, iByteLength);
			if (!pcWrite)
			{
				return 0;
			}

			miPosition += iByteLength;
		}
		UpdateLength();
		return iCount;
	}
	else
	{
		return 0;
	}
}
Beispiel #5
0
filePos CLogFile::ReadFirstTouchingWrites(int iWriteIndex, void* pvDest, filePos iSize, filePos iCount)
{
	CArrayIntAndPointer	apvOverlapping;
	BOOL			bAny;
	BOOL			bHoles;
	filePos			iBytesReadFromFile;
	filePos			iByteSize;

	iByteSize = iSize * iCount;
	bAny = FindTouchingWriteCommands(iWriteIndex, &apvOverlapping, miPosition, iByteSize, TRUE);
	if (bAny)
	{
		bHoles = FindHoles(&apvOverlapping, miPosition, iByteSize);
		if (bHoles)
		{
			iBytesReadFromFile = ReadFromBackingFile(pvDest, iSize, iCount);
		}

		CopyWritesToRead(&apvOverlapping, iByteSize, pvDest);
		apvOverlapping.Kill();
		return iCount;
	}
	else
	{
		if (miFileLength == 0)
		{
			return iCount;
		}
		else
		{
			iBytesReadFromFile = ReadWithNoTouchingWrites(pvDest, iSize, iCount);
			if (iBytesReadFromFile == iByteSize)
			{
				return iCount;
			}
			else
			{
				return 0;
			}
		}
	}
}
BOOL CCalculator::Expression(CCalcExpression** ppcExpression)
{
	BOOL				bOperator;
	BOOL				bOperand;
	BOOL				bFirst;
	CArrayIntAndPointer		cArray;
	CCalcOperator*		pcOperator;
	CCalcExpression*	pcOperand;

	cArray.Init(16);
	bFirst = TRUE;
	for (;;)
	{
		for (;;)
		{
			bOperator = Operator(&pcOperator);
			if (!bOperator)
			{
				break;
			}
			cArray.Add(pcOperator, 0);
		}

		bOperand = Operand(&pcOperand);
		if (!bOperand && !bOperator)
		{
			if (bFirst)
			{
				cArray.Kill();
				return FALSE;
			}
			else
			{
				BuildExpression(ppcExpression, &cArray);

				cArray.Kill();

				if (*ppcExpression == NULL)
				{
					return FALSE;
				}
				else
				{
					return TRUE;
				}
			}
		}
		cArray.Add(pcOperand, 0);
		bFirst = FALSE;
	}
}