void mechanicalBoard1PcWaitForInstruction(void) {
    // Analyze data from the Console (Specific to PC)
    while (consoleInputStream.availableData(&consoleInputStream)) {
        unsigned char c = consoleInputStream.readChar(&consoleInputStream);
        consoleInputBuffer.outputStream.writeChar(&(consoleInputBuffer.outputStream), c);
        if (c == 13) {
            appendCRLF(&consoleOutputStream);
        }
        consoleOutputStream.writeChar(&consoleOutputStream, c);
    }

    // Analyse from the ConsoleBuffer
    handleStreamInstruction(
        &consoleInputBuffer,
        &consoleOutputBuffer,
        &consoleOutputStream,
        &consoleOutputStream,
        &filterRemoveCRLF,
        NULL);

    if (!singleModeActivated) {
        // Analyse data from the I2C
        handleStreamInstruction(
            &i2cSlaveInputBuffer,
            &i2cSlaveOutputBuffer,
            NULL,
            NULL,
            &filterRemoveCRLF,
            NULL);
    }
}
Example #2
0
void
VFont::Read ()
{
  if (! characterTable.empty() || dviInfo.notLoadable)
    {
      return;
    }

  dviInfo.notLoadable = true;

  InputStream stream (dviInfo.fileName.c_str());

  trace_vfont->WriteFormattedLine
    ("libdvi",
     T_("reading vf file %s"),
     Q_(dviInfo.fileName));

  if (stream.ReadByte() != pre)
    {
      FATAL_DVI_ERROR ("VFont::Read",
		       T_("Not a VF file."),
		       dviInfo.fileName.c_str());
    }

  ReadPreamble (stream);
  ReadFontDefsAndCharPackets (stream);
  ReadPostamble (stream);
  
  dviInfo.notLoadable = false;
}
Example #3
0
    inline void read (InputStream& input)
    {
		//DBG("read from MinMaxColourValue");
        minValue = input.readByte();
        maxValue = input.readByte();
		input.read ((void*)&colour, sizeof(Colour));
    }
Example #4
0
void spatial_index<Value, Filter, InputStream>::query_first_n_impl(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count)
{
    if (results.size() == count) return;
    int offset = read_ndr_integer(in);
    box2d<double> node_ext;
    read_envelope(in, node_ext);
    int num_shapes = read_ndr_integer(in);
    if (!filter.pass(node_ext))
    {
        in.seekg(offset + num_shapes * sizeof(Value) + 4, std::ios::cur);
        return;
    }

    for (int i = 0; i < num_shapes; ++i)
    {
        Value item;
        in.read(reinterpret_cast<char*>(&item), sizeof(Value));
        if (results.size() < count) results.push_back(std::move(item));
    }
    int children = read_ndr_integer(in);
    for (int j = 0; j < children; ++j)
    {
        query_first_n_impl(filter, in, results, count);
    }
}
Example #5
0
boost::optional<Tree> Parser::parseFile(InputStream& is)
{
    typedef
        boost::spirit::classic::position_iterator<InputStream::const_iterator, boost::spirit::classic::file_position>
        PosIterator;

    PosIterator iter(is.begin(), is.end(), is.file());
    PosIterator end;

    rask::cst::Grammar<PosIterator> grammar(logger_);
    cst::Tree cst;

    bool r = boost::spirit::qi::phrase_parse(iter, end, grammar, boost::spirit::ascii::space, cst);

    if (r && iter == end && logger_.errors().empty() && cst.functions.size() > 0)
    {
        return cst;
    }
    else
    {
        if (iter == end && logger_.errors().empty())
        {
            logger_.log(error::Message::missingMainFunction(Position(is.file())));
        }

        return boost::none;
    }
}
Example #6
0
void spatial_index<Value, Filter, InputStream, BBox>::query_node(Filter const& filter, InputStream& in, std::vector<Value>& results)
{
    int offset = read_ndr_integer(in);
    typename spatial_index<Value, Filter, InputStream, BBox>::bbox_type node_ext;
    read_envelope(in, node_ext);
    int num_shapes = read_ndr_integer(in);
    if (!filter.pass(node_ext))
    {
        in.seekg(offset + num_shapes * sizeof(Value) + 4, std::ios::cur);
        return;
    }

    for (int i = 0; i < num_shapes; ++i)
    {
        Value item;
        in.read(reinterpret_cast<char*>(&item), sizeof(Value));
        results.push_back(std::move(item));
    }

    int children = read_ndr_integer(in);
    for (int j = 0; j < children; ++j)
    {
        query_node(filter, in, results);
    }
}
Example #7
0
bool ObjectWrapper::read( InputStream& is, osg::Object& obj )
{
    bool readOK = true;
    for ( SerializerList::iterator itr=_serializers.begin();
          itr!=_serializers.end(); ++itr )
    {
        BaseSerializer* serializer = itr->get();
        if ( serializer->_firstVersion <= is.getFileVersion() &&
             is.getFileVersion() <= serializer->_lastVersion)
        {
            if ( !serializer->read(is, obj) )
            {
                OSG_WARN << "ObjectWrapper::read(): Error reading property "
                                    << _name << "::" << (*itr)->getName() << std::endl;
                readOK = false;
            }
        }
        else
        {
            // OSG_NOTICE<<"Ignoring serializer due to version mismatch"<<std::endl;
        }
    }

    for ( FinishedObjectReadCallbackList::iterator itr=_finishedObjectReadCallbacks.begin();
          itr!=_finishedObjectReadCallbacks.end();
          ++itr )
     {
         (*itr)->objectRead(is, obj);
     }
    
    return readOK;
}
int OutputStream::writeFromInputStream (InputStream& source,
                                        int numBytesToWrite)
{
    if (numBytesToWrite < 0)
        numBytesToWrite = 0x7fffffff;

    int numWritten = 0;

    while (numBytesToWrite > 0 && ! source.isExhausted())
    {
        char buffer [8192];

        const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));

        if (num == 0)
            break;

        write (buffer, num);

        numBytesToWrite -= num;
        numWritten += num;
    }

    return numWritten;
}
Example #9
0
void motorBoardWaitForInstruction(void) {

    // delaymSec(MOTOR_BOARD_PC_DELAY_CONSOLE_ANALYZE_MILLISECONDS);

    // Analyze data from the Console (Specific to PC)
    while (consoleInputStream.availableData(&consoleInputStream)) {
        unsigned char c = consoleInputStream.readChar(&consoleInputStream);
        consoleInputBuffer.outputStream.writeChar(&(consoleInputBuffer.outputStream), c);
        if (c == 13) {
            appendCRLF(&consoleOutputStream);
        }
        consoleOutputStream.writeChar(&consoleOutputStream, c);
    }

    // Analyse from the ConsoleBuffer
    handleStreamInstruction(
        &consoleInputBuffer,
        &consoleOutputBuffer,
        &consoleOutputStream,
        &filterRemoveCRLF,
        NULL);

    if (!singleModeActivated) {
        // Analyse data from the I2C
        handleStreamInstruction(
            &i2cSlaveInputBuffer,
            &i2cSlaveOutputBuffer,
            NULL,
            &filterRemoveCRLF,
            NULL);
    }

    handleInstructionAndMotion();
}
Example #10
0
void input_reader(png_structp png_ptr, png_bytep data, png_size_t length) {
  InputStream *istr = (InputStream*)png_get_io_ptr(png_ptr);
  
  int ct = istr->ReadChars(length, data);
  if(ct != length)
      png_error(png_ptr, "unexpected EOF");
}
Example #11
0
File: my.cpp Project: wuhua988/icm
void
demo::package::__read(InputStream& __is)
{
  __is.read_string(str1);
  __is.read_long(length);
  __is.read_short(op);
}
Example #12
0
const var var::readFromStream (InputStream& input)
{
    const int numBytes = input.readCompressedInt();

    if (numBytes > 0)
    {
        switch (input.readByte())
        {
            case 1:     return var (input.readInt());
            case 2:     return var (true);
            case 3:     return var (false);
            case 4:     return var (input.readDouble());
            case 5:
            {
                MemoryOutputStream mo;
                mo.writeFromInputStream (input, numBytes - 1);
                return var (mo.toUTF8());
            }

            default:    input.skipNextBytes (numBytes - 1); break;
        }
    }

    return var::null;
}
bool SoundFile::openRead(InputStream& stream)
{
    // If the file is already opened, first close it
    if (m_file)
        sf_close(m_file);

    // Prepare the memory I/O structure
    SF_VIRTUAL_IO io;
    io.get_filelen = &Stream::getLength;
    io.read        = &Stream::read;
    io.seek        = &Stream::seek;
    io.tell        = &Stream::tell;

    // Initialize the stream data
    m_stream.source = &stream;
    m_stream.size = stream.getSize();

    // Make sure that the stream's reading position is at the beginning
    stream.seek(0);

    // Open the sound file
    SF_INFO fileInfo;
    fileInfo.format = 0;
    m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_stream);
    if (!m_file)
    {
        err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
        return false;
    }

    // Initialize the internal state from the loaded information
    initialize(fileInfo);

    return true;
}
void mfparamtest(){
	InputStream inS;
	MFParam mfPar;
	vector<vector<double>> * surodata;
	vector<vector<vector<double>>> *mfParam;
	inS.getOrigWindowN();
	surodata=inS.getSurWindowN();
	cout<< "this is surrogate data"<<endl;
	for (auto i: *surodata){
		for (auto j:i){
			cout << j<< " ";
		}
	}

	mfParam=mfPar.getMfparam(surodata);
	cout<<endl<<"this is power"<<endl;
	vector<vector<double>> *pw=mfPar.getPower();
	for (auto i: *(pw)){
		for (auto j: i){
			cout << j<< " ";
		}
	}
	cout <<endl<<"this is mf params coming out of MFParam" <<endl;
	for (auto i:*mfParam){
		for (auto j: i){
			for (auto k: j){
				cout << k << " ";
			}
		}
	}
}
std::string stream_sucker( InputStream& stream )
{
#if ADOBE_PLATFORM_MAC
    const char platform_lf('\r');
#else
    const char platform_lf('\n'); // Windows seems to handle this fine
#endif

    std::string result;

    if ( stream.is_open() )
    {
        stream.unsetf(std::ios_base::skipws);
        
        std::istream_iterator<char> first(stream);
        std::istream_iterator<char> last;
        
        while (first != last) {
            if (is_line_end(first, last))
            {
                result.append(1, platform_lf);
                continue;
            }
            result.append(1, *first);
            ++first;
        }
    }

    return result;
}
Example #16
0
size_t readSome_inner(InputStream& is, void *buf, size_t size, typename enable_if<is_convertible<InputStream, std::istream>::value>::type* = 0)
{
	is.read(static_cast<char *>(buf), size);
	const std::streamsize readSize = is.gcount();
	if (readSize < 0) throw cybozu::Exception("stream:readSome_inner:bad readSize") << size << readSize;
	if (readSize > 0xffffffff && size_t(-1) == 0xffffffff) throw cybozu::Exception("stream:readSome_inner:too large") << readSize;
	return static_cast<size_t>(readSize);
}
InputStream createInputCompressedFileStream(const std::string &fileName)
{
	InputStream inputStream;
	boost::shared_ptr<InputCompressedFileStreamBuffer> inputBuffer(new InputCompressedFileStreamBuffer(fileName));

	inputStream.setBuffer(inputBuffer);
	return inputStream;
}
        UserDefinedChunk (InputStream& input, int64 size)
        {
            // a user defined chunk contains 16 bytes of a UUID first
            uuid[1] = input.readInt64BigEndian();
            uuid[0] = input.readInt64BigEndian();

            input.skipNextBytes (size - 16);
        }
Example #19
0
static unsigned long Stream_ReadFunc(FT_Stream stream, unsigned long offset, unsigned char*  buffer, unsigned long count)
{
	InputStream *pSource;

	pSource = (InputStream *)stream->descriptor.pointer;
	pSource->Seek(offset, SEEK_SET);
	return pSource->Read(buffer, count);
}
Example #20
0
hdfsFile hdfsOpenFile(hdfsFS fs, const char * path, int flags, int bufferSize,
                      short replication, tOffset blocksize) {
    PARAMETER_ASSERT(fs && path && strlen(path) > 0, NULL, EINVAL);
    PARAMETER_ASSERT(bufferSize >= 0 && replication >= 0 && blocksize >= 0, NULL, EINVAL);
    PARAMETER_ASSERT(!(flags & O_RDWR) && !((flags & O_EXCL) && (flags & O_CREAT)), NULL, ENOTSUP);
    HdfsFileInternalWrapper * file = NULL;
    OutputStream * os = NULL;
    InputStream * is = NULL;

    try {
        file = new HdfsFileInternalWrapper();

        if ((flags & O_CREAT) || (flags & O_APPEND) || (flags & O_WRONLY)) {
            int internalFlags = 0;

            if (flags & O_CREAT)  {
                internalFlags |= Hdfs::Create;
            } else if ((flags & O_APPEND) && (flags & O_WRONLY)) {
                internalFlags |= Hdfs::Create;
                internalFlags |= Hdfs::Append;
            } else if (flags & O_WRONLY) {
                internalFlags |= Hdfs::Create;
                internalFlags |= Hdfs::Overwrite;
            }

            if (flags & O_SYNC) {
                internalFlags |= Hdfs::SyncBlock;
            }

            file->setInput(false);
            os = new OutputStream;
            os->open(fs->getFilesystem(), path, internalFlags, 0777, false, replication,
                     blocksize);
            file->setStream(os);
        } else {
            file->setInput(true);
            is = new InputStream;
            is->open(fs->getFilesystem(), path, true);
            file->setStream(is);
        }

        return file;
    } catch (const std::bad_alloc & e) {
        delete file;
        delete os;
        delete is;
        SetErrorMessage("Out of memory");
        errno = ENOMEM;
    } catch (...) {
        delete file;
        delete os;
        delete is;
        SetLastException(Hdfs::current_exception());
        handleException(Hdfs::current_exception());
    }

    return NULL;
}
Example #21
0
unsigned int StandardPackage::getCrc(const std::string &fileName)
{
	InputStream strm = createInputFileStream(fileName);
	if(strm.getSize() != 0)
	{
		return 0xFFFFFFFF;
	}
	return 0;
}
Example #22
0
void Disassembler::Disassemble(InputStream &cboStream, OutputStream &outputStream)
{
	const auto pos = cboStream.GetPosition();
	CboValidator validator;
	CboValidator::Result result = validator.Validate(cboStream);
	cboStream.SetPosition(pos);
	DisassemblerCore disassembler(result, mAllocator, cboStream, outputStream);
	disassembler.Disassemble();
}
Example #23
0
box2d<double> spatial_index<Value, Filter, InputStream>::bounding_box(InputStream& in)
{
    if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
    in.seekg(16 + 4, std::ios::beg);
    box2d<double> box;
    read_envelope(in, box);
    in.seekg(0, std::ios::beg);
    return box;
}
 AudioDescriptionChunk (InputStream& input)
 {
     sampleRate          = input.readDoubleBigEndian();
     formatID            = (uint32) input.readIntBigEndian();
     formatFlags         = (uint32) input.readIntBigEndian();
     bytesPerPacket      = (uint32) input.readIntBigEndian();
     framesPerPacket     = (uint32) input.readIntBigEndian();
     channelsPerFrame    = (uint32) input.readIntBigEndian();
     bitsPerChannel      = (uint32) input.readIntBigEndian();
 }
Example #25
0
	void serializeSection(InputStream& stream,SectionType expectedType,SerializeSection serializeSectionBody)
	{
		wavmAssert((SectionType)*stream.peek(sizeof(SectionType)) == expectedType);
		stream.advance(sizeof(SectionType));
		Uptr numSectionBytes = 0;
		serializeVarUInt32(stream,numSectionBytes);
		MemoryInputStream sectionStream(stream.advance(numSectionBytes),numSectionBytes);
		serializeSectionBody(sectionStream);
		if(sectionStream.capacity()) { throw FatalSerializationException("section contained more data than expected"); }
	}
    //==============================================================================
    static StringPairArray parseInformationChunk (InputStream& input)
    {
        StringPairArray infoStrings;
        const uint32 numEntries = (uint32) input.readIntBigEndian();

        for (uint32 i = 0; i < numEntries; ++i)
            infoStrings.set (input.readString(), input.readString());

        return infoStrings;
    }
Example #27
0
BBox spatial_index<Value, Filter, InputStream, BBox>::bounding_box(InputStream& in)
{
    static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
    if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
    in.seekg(16 + 4, std::ios::beg);
    typename spatial_index<Value, Filter, InputStream, BBox>::bbox_type box;
    read_envelope(in, box);
    in.seekg(0, std::ios::beg);
    return box;
}
Example #28
0
	void File::ParseName(InputStream& s, CStringW& name)
	{
		name.Empty();

		for(int c = s.SkipWhiteSpace(); iswcsym(c); c = s.PeekChar())
		{
			if(name.IsEmpty() && iswdigit(c)) s.ThrowError(_T("'name' cannot start with a number"));
			name += (WCHAR)s.GetChar();
		}
	}
Example #29
0
int main() {
  Stream stream;

  stream.Set();
  cout << stream.Get() << endl;

  InputStream istream;
  cout << "> " << flush;
  istream.Set();
  cout << istream.Get() << endl;
}
Example #30
0
void readHeader(InputStream& is, header& h) {

	h.first = is.inputBits(32);

	for (uint32 i = 0; i < 8; i++) {
		h.increments[i] = is.inputBits(8);
	}

	h.fileSize = is.inputBits(32);
	h.tempSize = is.inputBits(32);
}