Example #1
0
std::string BinaryInput::readStringNewline() {
    int64 n = 0;

    if ((m_pos + m_alreadyRead + n) < (m_length - 1)) {
        prepareToRead(1);
    }

    if ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) &&
         ! isNewline(m_buffer[m_pos + n])) {

        ++n;
        while ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) &&
                ! isNewline(m_buffer[m_pos + n])) {

            prepareToRead(1);
            ++n;
        }
    }

    const std::string s = readString(n);

    // Consume the newline
    char firstNLChar = readUInt8();

    // Consume the 2nd newline
    if (isNewline(m_buffer[m_pos + 1]) && (m_buffer[m_pos + 1] != firstNLChar)) {
        readUInt8();
    }

    return s;
}
Example #2
0
void BinaryInput::readBytes(void* bytes, int64 n) {
    prepareToRead(n);
    debugAssert(isValidPointer(bytes));

    memcpy(bytes, buffer + pos, n);
    pos += n;
}
    int writePendingData()
    {
        const int numToDo = getTotalSize() / 4;

        int start1, size1, start2, size2;
        prepareToRead (numToDo, start1, size1, start2, size2);

        if (size1 <= 0)
            return 10;

        writer->writeFromAudioSampleBuffer (buffer, start1, size1);

        const ScopedLock sl (thumbnailLock);
        if (receiver != nullptr)
            receiver->addBlock (samplesWritten, buffer, start1, size1);

        samplesWritten += size1;

        if (size2 > 0)
        {
            writer->writeFromAudioSampleBuffer (buffer, start2, size2);

            if (receiver != nullptr)
                receiver->addBlock (samplesWritten, buffer, start2, size2);

            samplesWritten += size2;
        }

        finishedRead (size1 + size2);
        return 0;
    }
Example #4
0
std::string BinaryInput::readString() {
    int64 n = 0;

    if ((int64)pos + (int64)alreadyRead + n < (int64)length - 1) {
        prepareToRead(1);
    }

    if (((int64)pos + (int64)alreadyRead + (int64)n < length - 1) && (buffer[pos + n] != '\0')) {
        ++n;
        while (((int64)pos + (int64)alreadyRead + n < (int64)length - 1) && (buffer[pos + n] != '\0')) {
            prepareToRead(1);
            ++n;
        }
    }

    // Consume NULL
    ++n;

    return readString(n);
}
Example #5
0
void Dialog::acceptConnection() {
    delete createHostDialog;
    if (readWriteSocket != nullptr) {
        delete readWriteSocket;
    }
    readWriteSocket = listenSocket->nextPendingConnection();
    isHost = true;
    player = Map::Black;
    prepareToRead();
    //prepareGameWidget();
    //connect(readWriteSocket, SIGNAL(readyRead()), this, SLOT());
}
Example #6
0
void Dialog::beginJoinHost() {
    QString IP = IPEdit->text();
    delete joinHostDialog;
    if (readWriteSocket != nullptr) {
        delete readWriteSocket;
    }
    readWriteSocket = new QTcpSocket();
    readWriteSocket->connectToHost(QHostAddress(IP), PORT);
    isHost = false;
    player = Map::White;
    connect(readWriteSocket, SIGNAL(connected()), this, SLOT(prepareToRead()));
    //connect(readWriteSocket, SIGNAL(readyRead()), this, SLOT());
}
Example #7
0
std::string BinaryInput::readString() {
    int64 n = 0;

    if ((m_pos + m_alreadyRead + n) < (m_length - 1)) {
        prepareToRead(1);
    }

    if ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) &&
         (m_buffer[m_pos + n] != '\0')) {

        ++n;
        while ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) &&
                (m_buffer[m_pos + n] != '\0')) {

            prepareToRead(1);
            ++n;
        }
    }

    // Consume NULL
    ++n;

    return readString(n);
}
Example #8
0
std::string DataBlockFile::getData()
{
    if (!exists())
        return std::string();

    prepareToRead();

    QDataStream stream(&m_file);
 //   std::cerr << "DataBlockFile::getData() : file size = " << m_file.size() << std::endl;
    char* tmp = new char[m_file.size()];
    stream.readRawData(tmp, m_file.size());
    std::string res(tmp, m_file.size());
    delete[] tmp;

    return res;
}
Example #9
0
uint64 BinaryInput::readUInt64() {
    prepareToRead(8);
    uint8 out[8];

    if (swapBytes) {
        out[0] = buffer[pos + 7];
        out[1] = buffer[pos + 6];
        out[2] = buffer[pos + 5];
        out[3] = buffer[pos + 4];
        out[4] = buffer[pos + 3];
        out[5] = buffer[pos + 2];
        out[6] = buffer[pos + 1];
        out[7] = buffer[pos + 0];
    } else {
        *(uint64*)out = *(uint64*)(buffer + pos);
    }

    pos += 8;
    return *(uint64*)out;
}
Example #10
0
std::string BinaryInput::readString(int64 n) {
    prepareToRead(n);
    debugAssertM((pos + n) <= length, "Read past end of file");

    char *s = (char*)System::malloc(n + 1);
    assert(s != NULL);

    memcpy(s, buffer + pos, n);
    // There may not be a null, so make sure
    // we add one.
    s[n] = '\0';

    std::string out = s;
    System::free(s);
    s = NULL;

    pos += n;

    return out;

}
Example #11
0
//! Writes char data to the file from the supplied buffer
bool MrcFileImpl::writeCharData(unsigned char* buffer, unsigned int numSamples, unsigned int variable)
{
	if (m_OpenMode == Read)
		return false;

	if (variable>=m_NumVariables ||
		m_VariableTypes[variable]!=Char) {
		// no good
		return false;
	}

	prepareToRead(variable);

	// write out the data
	if ((int)numSamples != m_File.writeBlock((char*)buffer, numSamples)) {
		return false;
	}

	incrementPosition(numSamples);
	return true;
}
/* It is not feasible to turn off the pulses before checking the output of
 * the sensor because an interrupt might fire and cause the sensor check to
 * happen too late.
 */
void Zumo32U4ProximitySensors::read()
{
    prepareToRead();

    for (uint8_t i = 0; i < numSensors; i++)
    {
        dataArray[i].withRightLeds = 0;
        dataArray[i].withLeftLeds = 0;
    }

    for (uint8_t i = 0; i < numLevels; i++)
    {
        uint16_t brightness = levelsArray[i];

        Zumo32U4IRPulses::start(Zumo32U4IRPulses::Left, brightness, period);
        delayMicroseconds(pulseOnTimeUs);
        for (uint8_t i = 0; i < numSensors; i++)
        {
            if (!digitalReadSafe(dataArray[i].pin, 1))
            {
                dataArray[i].withLeftLeds++;
            }
        }
        Zumo32U4IRPulses::stop();
        delayMicroseconds(pulseOffTimeUs);

        Zumo32U4IRPulses::start(Zumo32U4IRPulses::Right, brightness, period);
        delayMicroseconds(pulseOnTimeUs);
        for (uint8_t i = 0; i < numSensors; i++)
        {
            if (!digitalReadSafe(dataArray[i].pin, 1))
            {
                dataArray[i].withRightLeds++;
            }
        }
        Zumo32U4IRPulses::stop();
        delayMicroseconds(pulseOffTimeUs);
    }
}
Example #13
0
//! Reads double data from the file into the supplied buffer
bool MrcFileImpl::readDoubleData(double* buffer, unsigned int numSamples, unsigned int variable)
{
	if (m_OpenMode == Write)
		return false;

	if (variable>=m_NumVariables ||
		m_VariableTypes[variable]!=Double) {
		// no good
		return false;
	}

	prepareToRead(variable);

	// read in the data
	if ((int)(numSamples*sizeof(double)) != m_File.readBlock((char*)buffer, numSamples*sizeof(double))) {
		return false;
	}
	if (m_MustSwap) swapByteOrder(buffer, numSamples);

	incrementPosition(numSamples);
	return true;
}
Example #14
0
//! Writes float data to the file from the supplied buffer
bool MrcFileImpl::writeFloatData(float* buffer, unsigned int numSamples, unsigned int variable)
{
	if (m_OpenMode == Read)
		return false;

	if (variable>=m_NumVariables ||
		m_VariableTypes[variable]!=Float) {
		// no good
		return false;
	}

	prepareToRead(variable);

	if (m_MustSwap) swapByteOrder(buffer, numSamples);

	// write out the data
	if (((int)numSamples*sizeof(float)) != m_File.writeBlock((char*)buffer, numSamples*sizeof(float))) {
		return false;
	}

	incrementPosition(numSamples);
	return true;
}