From: Christian P. <cp...@se...> - 2004-12-31 15:21:37
|
Hi ! The new I/O code (pclasses2) should now be usable - please test it. Currently available IODevice's: System::Pipe - Anonymous pipe's System::File - File I/O class System::ProcessIO - Used to comminucate with child processes through anonymous pipes. Net::Socket - Used for Network communication Cause the I/O architecture is fully polymorphic, you can now write fully I/O device independent code: -- cut -- void copy(IODevice& src, IODevice& dest) { while(!src.eof()) { char tmp[1024]; size_t read = src.read(tmp, sizeof(tmp)); dest.write(tmp, read); } } // copy test.txt to process stdin File f("test.txt", File::Read); Process proc("tmpbin"); proc.start(Process::RedirectAll); // copy data ... copy(f, proc.processIO()); -- cut -- Cool eh? Missing devices: Memory(Mapped)File, NamedPipe, SerialDevice, ParallelDevice(?) IOStream should also work - please test it, cause documentation about extending std::streambuf is rare on the net, it's likely to fail. -- cut -- File f("test.txt", File::Read); // open "test.txt" for reading IOStream strm(f); // create I/O stream std::string str; strm >> str; // read string from test.txt -- cut -- Greetings, Christian |