PLearn 0.1
|
#include <PStream.h>
Public Types | |
enum | mode_t { plearn_ascii, plearn_binary, raw_ascii, raw_binary, pretty_ascii } |
plearn_ascii and plearn_binary are used on output to determine in which format to write stuff. More... | |
enum | compr_mode_t { compr_none, compr_double_as_float, compr_sparse, compr_lossy_sparse } |
Compression mode (mostly used by binary serialization of sequences of floats or doubles, such as TMat<real>) (Used on output only; autodetect on read). More... | |
typedef PStream &(* | pl_pstream_manip )(PStream &) |
typedef's for PStream manipulators | |
typedef int | streamsize |
typedef's for compatibility w/ old libraries | |
typedef ios | ios_base |
Public Member Functions | |
PStream () | |
PStream (streambuftype *sb) | |
constructor from a PStreamBuf | |
PStream (istream *pin_, bool own_pin_=false) | |
ctor. from an istream (I) | |
PStream (ostream *pout_, bool own_pout_=false) | |
ctor. from an ostream (O) | |
PStream (iostream *pios_, bool own_pios_=false) | |
ctor. from an iostream (IO) | |
PStream (istream *pin_, ostream *pout_, bool own_pin_=false, bool own_pout_=false) | |
ctor. from an istream and an ostream (IO) | |
virtual | ~PStream () |
Default copy ctor. should be fine now. | |
void | setBufferCapacities (streamsize inbuf_capacity, streamsize outbuf_capacity, streamsize unget_capacity) |
mode_t | setInMode (mode_t m) |
mode_t | setOutMode (mode_t m) |
void | setMode (mode_t m) |
void | clearOutMap () |
void | clearInMap () |
void | clearInOutMaps () |
mode_t | switchToPLearnOutMode () |
if outmode is raw_ascii or raw_binary, it will be switched to corresponding plearn_ascii, resp. | |
PStream & | operator>> (mode_t m) |
PStream & | operator<< (mode_t m) |
PStream & | operator= (const PStream &pios) |
PStream & | operator= (streambuftype *streambuf) |
bool | operator== (const PStream &other) |
void | writeAsciiNum (char x) |
void | writeAsciiNum (unsigned char x) |
void | writeAsciiNum (signed char x) |
void | writeAsciiNum (short x) |
void | writeAsciiNum (unsigned short x) |
void | writeAsciiNum (int x) |
void | writeAsciiNum (unsigned int x) |
void | writeAsciiNum (long x) |
void | writeAsciiNum (unsigned long x) |
void | writeAsciiNum (long long x) |
void | writeAsciiNum (unsigned long long x) |
void | writeAsciiNum (float x) |
void | writeAsciiNum (double x) |
void | readAsciiNum (char &x) |
void | readAsciiNum (unsigned char &x) |
void | readAsciiNum (signed char &x) |
void | readAsciiNum (short &x) |
void | readAsciiNum (unsigned short &x) |
void | readAsciiNum (int &x) |
void | readAsciiNum (unsigned int &x) |
void | readAsciiNum (long &x) |
void | readAsciiNum (unsigned long &x) |
void | readAsciiNum (long long &x) |
void | readAsciiNum (unsigned long long &x) |
void | readAsciiNum (float &x) |
void | readAsciiNum (double &x) |
void | writeAsciiHexNum (unsigned char x) |
Writes the corresponding 2 hex digits (ex: 0A ) | |
template<class I > | |
void | writeBinaryNum (I x) |
Writes base types to PLearn binary format TODO: forbid this mechanism for arbitrary classes? | |
template<class I , class J > | |
void | readBinaryNumAs (J &x, bool inverted_byte_order) |
Reads a J element, optionnally swaps its endianness, and returns an I. | |
template<class I > | |
void | readBinaryNum (I &x, unsigned char typecode) |
Reads base types from PLearn binary format. | |
bool | eof () const |
bool | good () const |
operator void * () const | |
!!! | |
bool | operator! () const |
Test whether a PStream is in an invalid state. | |
const char * | getFloatFormat () const |
Getters/Setters for the printf format strings for writeAsciiNum for float and double. | |
const char * | getDoubleFormat () const |
void | setFloatFormat (const char *f) |
void | setDoubleFormat (const char *f) |
int | get () |
The folowing methods are 'forwarded' from {i|o}stream. | |
PStream & | get (char &c) |
The folowing methods are 'forwarded' from {i|o}stream. | |
PStream & | getline (string &line, char delimitor='\n') |
Delimitor is read from stream but not appended to string. | |
string | getline () |
int | peek () |
The folowing methods are 'forwarded' from {i|o}stream. | |
PStream & | putback (char c) |
If you put back the result of a call to get(), make sure it is not EOF. | |
PStream & | unget () |
Put back the last character read by the get() or read() methods. | |
PStream & | unread (const char *p, streamsize n) |
PStream & | unread (const char *p) |
PStream & | unread (const string &s) |
PStream & | read (char *s, streamsize n) |
PStream & | read (string &s, streamsize n) |
string | readAll () |
Reads until an EOF is found, and returns the whole content as a string. | |
void | readExpected (char expect) |
Reads the next character and launches a PLERROR if it is different from expect. | |
void | readExpected (char *expect) |
Reads character one by one, comparing it with the sequence in expect (until terminating null character in expect). | |
void | readExpected (const string &expect) |
Reads character one by one, comparing it with the sequence in expect. | |
streamsize | readUntil (char *buf, streamsize n, char stop_char) |
Reads characters into buf until n characters have been read, or end-of-file has been reached, or the next character in the stream is the stop_char. | |
streamsize | readUntil (char *buf, streamsize n, const char *stop_chars) |
Reads characters into buf until n characters have been read, or end-of-file has been reached, or the next character in the stream is one of the stop_chars (null terminated string). | |
PStream & | write (const char *s, streamsize n) |
PStream & | put (char c) |
PStream & | put (unsigned char c) |
PStream & | put (int x) |
PStream & | flush () |
PStream & | endl () |
PStream & | write (const char *s) |
PStream & | write (const string &s) |
void | skipRestOfLine () |
reads everything until ' ' (also consumes the ' ') | |
void | skipBlanks () |
skips any blanks (space, tab, newline) | |
void | skipBlanksAndComments () |
skips any blanks (space, tab, newline) and comments starting with # | |
void | skipBlanksAndCommentsAndSeparators () |
skips any blanks, # comments, and separators (',' and ';') | |
void | skipAll (const char *chars_to_skip) |
skips all occurences of any of the given characters | |
int | smartReadUntilNext (const string &stoppingsymbols, string &characters_read, bool ignore_brackets=false, bool skip_comments=true) |
Reads characters from stream, until we meet one of the stopping symbols at the current "level". | |
int | count (char c) |
Count the number of occurrences of a character in the stream. | |
PStream & | operator>> (float &x) |
PStream & | operator>> (double &x) |
PStream & | operator>> (string &x) |
PStream & | operator>> (char *x) |
PStream & | operator>> (char &x) |
PStream & | operator>> (signed char &x) |
PStream & | operator>> (unsigned char &x) |
PStream & | operator>> (bool &x) |
PStream & | operator>> (short &x) |
PStream & | operator>> (unsigned short &x) |
PStream & | operator>> (int &x) |
PStream & | operator>> (unsigned int &x) |
PStream & | operator>> (long &x) |
PStream & | operator>> (unsigned long &x) |
PStream & | operator>> (long long &x) |
PStream & | operator>> (unsigned long long &x) |
PStream & | operator>> (pl_pstream_manip func) |
PStream & | operator<< (float x) |
PStream & | operator<< (double x) |
PStream & | operator<< (const char *x) |
Warning: string output will be formatted according to outmode (if you want to output a raw string use the write method instead) | |
PStream & | operator<< (const void *x) |
Overload to print out raw pointers in the form 0x???????? | |
PStream & | operator<< (const string &x) |
Warning: string output will be formatted according to outmode (if you want to output a raw string use the write method instead) (unless you're in raw_ascii or raw_binary mode!) | |
PStream & | operator<< (char x) |
PStream & | operator<< (signed char x) |
PStream & | operator<< (unsigned char x) |
PStream & | operator<< (bool x) |
PStream & | operator<< (short x) |
PStream & | operator<< (unsigned short x) |
PStream & | operator<< (int x) |
PStream & | operator<< (unsigned int x) |
PStream & | operator<< (long x) |
PStream & | operator<< (unsigned long x) |
PStream & | operator<< (long long x) |
PStream & | operator<< (unsigned long long x) |
PStream & | operator<< (pl_pstream_manip func) |
Static Public Member Functions | |
static PStream::mode_t | parseModeT (const string &str) |
Parse a string and return the equivalent PStream::mode_t. | |
Public Attributes | |
mode_t | inmode |
mode for input formatting | |
map< unsigned int, void * > | copies_map_in |
format flags for input | |
mode_t | outmode |
mode for output formatting | |
map< void *, unsigned int > | copies_map_out |
format flags for output | |
bool | implicit_storage |
If true, then Mat and Vec will be serialized with their elements in place, If false, they will have an explicit pointer to a storage. | |
compr_mode_t | compression_mode |
Determines the way data is compressed, if any. | |
bool | remote_plearn_comm |
Should be true if this stream is used to communicate with a remote PLearn host. | |
Static Public Attributes | |
static bool | windows_endl = false |
If true, we should emit windows end of line( ) | |
Private Types | |
typedef PP< PStreamBuf > | inherited |
typedef PStreamBuf | streambuftype |
Private Attributes | |
const char * | format_float |
Current format string for floats. | |
const char * | format_double |
Current format string for doubles. | |
Static Private Attributes | |
static const char * | format_float_default = "%.8g" |
Default format string for floats. | |
static const char * | format_double_default = "%.15g" |
Default format string for doubles. |
PStream: This class defines a type of stream that should be used for all I/O within PLearn. It supports most operations available for standard C++ streams, plus:
typedef PP<PStreamBuf> PLearn::PStream::inherited [private] |
typedef ios PLearn::PStream::ios_base |
typedef PStream&(* PLearn::PStream::pl_pstream_manip)(PStream &) |
typedef PStreamBuf PLearn::PStream::streambuftype [private] |
typedef int PLearn::PStream::streamsize |
Compression mode (mostly used by binary serialization of sequences of floats or doubles, such as TMat<real>) (Used on output only; autodetect on read).
plearn_ascii and plearn_binary are used on output to determine in which format to write stuff.
On input however, they are equivalent, as the right format is automatically detected.
plearn_ascii |
PLearn ascii serialization format (can be mixed with plearn_binary) |
plearn_binary |
PLearn binary serialization format (can be mixed with plearn_ascii) |
raw_ascii |
Raw C++ ascii output without additional separators (direct output to underlying ostream) |
raw_binary |
Simply writes the bytes as they are in memory. |
pretty_ascii |
Ascii pretty print (in particular for Vec and Mat, formatted output without size info) |
PLearn::PStream::PStream | ( | ) |
Definition at line 179 of file PStream.cc.
:inherited(0), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
PLearn::PStream::PStream | ( | streambuftype * | sb | ) |
constructor from a PStreamBuf
Definition at line 190 of file PStream.cc.
:inherited(sb), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
PLearn::PStream::PStream | ( | istream * | pin_, |
bool | own_pin_ = false |
||
) |
ctor. from an istream (I)
Definition at line 203 of file PStream.cc.
:inherited(new StdPStreamBuf(pin_,own_pin_)), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
PLearn::PStream::PStream | ( | ostream * | pout_, |
bool | own_pout_ = false |
||
) |
ctor. from an ostream (O)
Definition at line 215 of file PStream.cc.
:inherited(new StdPStreamBuf(pout_,own_pout_)), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
ctor. from an iostream (IO)
Definition at line 227 of file PStream.cc.
:inherited(new StdPStreamBuf(pios_,own_pios_)), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
PLearn::PStream::PStream | ( | istream * | pin_, |
ostream * | pout_, | ||
bool | own_pin_ = false , |
||
bool | own_pout_ = false |
||
) |
ctor. from an istream and an ostream (IO)
Definition at line 239 of file PStream.cc.
:inherited(new StdPStreamBuf(pin_,pout_,own_pin_,own_pout_)), inmode(plearn_ascii), outmode(plearn_ascii), format_float (format_float_default), format_double(format_double_default), implicit_storage(true), compression_mode(compr_none), remote_plearn_comm(false) {}
PLearn::PStream::~PStream | ( | ) | [virtual] |
void PLearn::PStream::clearInMap | ( | ) | [inline] |
Definition at line 245 of file PStream.h.
{ copies_map_in.clear(); }
void PLearn::PStream::clearInOutMaps | ( | ) | [inline] |
Definition at line 248 of file PStream.h.
Referenced by PLearn::checkWrappedObjects(), and PLearn::RemotePLearnServer::clearMaps().
{ clearInMap(); clearOutMap(); }
void PLearn::PStream::clearOutMap | ( | ) | [inline] |
Definition at line 242 of file PStream.h.
Referenced by PLearn::_tostring_static_pstream_().
{ copies_map_out.clear(); }
int PLearn::PStream::count | ( | char | c | ) |
Count the number of occurrences of a character in the stream.
Definition at line 488 of file PStream.cc.
Referenced by PLearn::MultiInstanceVMatrix::build_().
{ char ch = get(); int counter = 0; while (ch != EOF) { if (ch == c) counter++; ch = get(); } return counter; }
PStream& PLearn::PStream::endl | ( | ) | [inline] |
Definition at line 606 of file PStream.h.
References PLearn::flush().
Referenced by PLearn::endl(), and printobj().
{ if(windows_endl) put('\r'); put('\n'); flush(); return *this; }
bool PLearn::PStream::eof | ( | ) | const [inline] |
Definition at line 429 of file PStream.h.
Referenced by PLearn::MultiInstanceVMatrix::build_(), PLearn::LIBSVMSparseVMatrix::build_(), PLearn::DictionaryVMatrix::build_(), PLearn::ConditionalDictionary::build_(), PLearn::VMatLanguage::generateCode(), PLearn::TVec< T >::input(), PLearn::VMatLanguage::preprocess(), PLearn::RealMapping::read(), PLearn::readSequence(), and PLearn::VMatLanguage::staticPreprocess().
{ return ptr->eof(); }
PStream& PLearn::PStream::flush | ( | ) | [inline] |
Definition at line 600 of file PStream.h.
References flush().
Referenced by PLearn::_tostring_static_pstream_(), PLearn::TextProgressBarPlugin::addProgressBar(), PLearn::Object::asString(), PLearn::Object::asStringRemoteTransmit(), PLearn::diff(), flush(), PLearn::flush(), PLearn::Gnuplot::flush(), PLearn::GhostScript::flush(), PLearn::Object::getOption(), PLearn::openUrl(), PLearn::PLMathTest::perform(), PLearn::ServerCommand::run(), PLearn::RemoteTrampoline::sendRemoteMethodResult(), PLearn::RemoteTrampoline::sendRemoteMethodVoidResult(), PLearn::test_write(), PLearn::test_write_unbuffered(), PLearn::RowMapSparseMatrix< real >::transposeProduct(), PLearn::TextProgressBarPlugin::update(), PLearn::ServerLogStreamBuf::write_(), and PLearn::OptionBase::writeIntoString().
{ ptr->flush(); return *this; }
int PLearn::PStream::get | ( | ) | [inline] |
The folowing methods are 'forwarded' from {i|o}stream.
Definition at line 473 of file PStream.h.
Referenced by PLearn::binread_(), PLearn::countNonBlankLinesOfFile(), PLearn::RemotePLearnServer::expectResults(), PLearn::getAfterSkipBlanks(), PLearn::getAfterSkipBlanksAndComments(), PLearn::Object::newread(), PLearn::operator>>(), PLearn::peekAfterSkipBlanks(), PLearn::plotVMats(), PLearn::VMatLanguage::preprocess(), PLearn::TVec< PP< RegressionTreeNode > >::read(), PLearn::TMat< pair< real, real > >::read(), PLearn::SmoothedProbSparseMatrix::read(), PLearn::RealMapping::read(), PLearn::DoubleAccessSparseMatrix< T >::read(), PLearn::TextFilesVMatrix::readAndCheckOptionName(), PLearn::readAndMacroProcess(), PLearn::readFooter(), PLearn::readHeader(), PLearn::readMap(), PLearn::readObject(), PLearn::readPriorityQueue(), PLearn::readSequence(), PLearn::readSet(), PLearn::readWhileMatches(), PLearn::PLearnServer::run(), PLearn::skipBlanksAndComments(), PLearn::skipRestOfLine(), PLearn::VMatLanguage::staticPreprocess(), PLearn::test_read(), and PLearn::PLearnService::watchServers().
{ return ptr->get(); }
PStream& PLearn::PStream::get | ( | char & | c | ) | [inline] |
const char* PLearn::PStream::getDoubleFormat | ( | ) | const [inline] |
Definition at line 466 of file PStream.h.
{ return format_double; }
const char* PLearn::PStream::getFloatFormat | ( | ) | const [inline] |
Getters/Setters for the printf format strings for writeAsciiNum for float and double.
By default, this is "%.8g" for float, and "%.18g" for double. NOTE: these strings must remain accessible for the lifetime of the PStream. In particular, they (generally) should not come from a string c_str().
Definition at line 465 of file PStream.h.
{ return format_float; }
Delimitor is read from stream but not appended to string.
Definition at line 484 of file PStream.h.
References c.
Referenced by PLearn::MultiInstanceVMatrix::build_(), PLearn::LIBSVMSparseVMatrix::build_(), PLearn::DictionaryVMatrix::build_(), PLearn::AsciiVMatrix::build_(), PLearn::execute(), PLearn::getNextNonBlankLine(), PLearn::VMatrix::getSavedFieldInfos(), PLearn::loadAscii(), PLearn::loadAsciiSingleBinaryDescriptor(), PLearn::Object::newread(), PLearn::openUrl(), PLearn::pgetline(), PLearn::VMatLanguage::preprocess(), PLearn::RealMapping::read(), PLearn::readAndMacroProcess(), PLearn::readObject(), and PLearn::VMatLanguage::staticPreprocess().
{ line.clear(); int c = get(); while (c != EOF && c != delimitor) { line += (char)c; c = get(); } return *this; }
string PLearn::PStream::getline | ( | ) | [inline] |
bool PLearn::PStream::good | ( | ) | const [inline] |
Definition at line 432 of file PStream.h.
Referenced by PLearn::PLearnService::connectToServers(), PLearn::RemotePLearnServer::deleteAllObjectsAsync(), PLearn::execute(), PLearn::Plide::executePyPLearn(), PLearn::getNextNonBlankLine(), PLearn::loadAscii(), PLearn::VMatrix::loadStringMapping(), PLearn::VMatrix::lockMetaDataDir(), PLearn::PPath::metaprotocolToMetapath(), PLearn::VMatLanguage::preprocess(), PLearn::readAndMacroProcess(), PLearn::RunCommand::run(), PLearn::PyPLearnScript::run(), PLearn::PLearnServer::run(), PLearn::VMatLanguage::staticPreprocess(), and PLearn::test_read().
PLearn::PStream::operator void * | ( | ) | const [inline] |
bool PLearn::PStream::operator! | ( | ) | const [inline] |
PStream & PLearn::PStream::operator<< | ( | const string & | x | ) |
Warning: string output will be formatted according to outmode (if you want to output a raw string use the write method instead) (unless you're in raw_ascii or raw_binary mode!)
Definition at line 1660 of file PStream.cc.
References operator<<().
{ const char* array = x.c_str(); operator<<(array); return *this; }
Definition at line 1769 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(unsigned int)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
Definition at line 1667 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, and raw_binary.
{ switch(outmode) { case plearn_ascii: if(x) put('1'); else put('0'); put(' '); break; case raw_ascii: case pretty_ascii: case raw_binary: case plearn_binary: if(x) put('1'); else put('0'); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | float | x | ) |
Definition at line 1894 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(float)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | double | x | ) |
Definition at line 1919 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(double)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | const char * | x | ) |
Warning: string output will be formatted according to outmode (if you want to output a raw string use the write method instead)
Definition at line 1601 of file PStream.cc.
References c, i, outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, PLearn::strlen(), and write().
{ int l = (int)strlen(x); switch(outmode) { case PStream::raw_ascii: case PStream::pretty_ascii: case PStream::raw_binary: write(x); break; case PStream::plearn_ascii: case PStream::plearn_binary: { put('"'); for(int i=0; i<l; i++) { char c = x[i]; if(c=='"' || c=='\\') // escape quote and backslash put('\\'); put(c); } put('"'); put(' '); } break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | const void * | x | ) |
Overload to print out raw pointers in the form 0x????????
Definition at line 1635 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, and write().
{ switch(outmode) { case PStream::raw_ascii: case PStream::pretty_ascii: case PStream::raw_binary: case PStream::plearn_ascii: case PStream::plearn_binary: { char buffer[1000]; snprintf(buffer, 1000, "%p ", x); buffer[999] = '\0'; write(buffer); break; } default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | char | x | ) |
Definition at line 1542 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, and writeBinaryNum().
{ switch(outmode) { case raw_ascii: case raw_binary: case pretty_ascii: put(x); break; case plearn_ascii: put('\''); put(x); put('\''); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | signed char | x | ) |
Definition at line 1567 of file PStream.cc.
References operator<<().
{ operator<<(char(x)); return *this; }
PStream & PLearn::PStream::operator<< | ( | unsigned long long | x | ) |
Definition at line 1869 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(unsigned long long)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | unsigned char | x | ) |
Definition at line 1573 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, and writeBinaryNum().
{ switch(outmode) { case raw_ascii: put(x); put(' '); break; case raw_binary: put(x); break; case pretty_ascii: case plearn_ascii: put('\''); put(x); put('\''); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | short | x | ) |
Definition at line 1694 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(short)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | unsigned short | x | ) |
Definition at line 1719 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(unsigned short)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
Definition at line 1744 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(int)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | long | x | ) |
Definition at line 1794 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(long)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | unsigned long | x | ) |
Definition at line 1819 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(unsigned long)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator<< | ( | long long | x | ) |
Definition at line 1844 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, put(), raw_ascii, raw_binary, write(), writeAsciiNum(), and writeBinaryNum().
{ switch(outmode) { case raw_binary: write(reinterpret_cast<char *>(&x), sizeof(long long)); break; case raw_ascii: case pretty_ascii: writeAsciiNum(x); break; case plearn_ascii: writeAsciiNum(x); put(' '); break; case plearn_binary: writeBinaryNum(x); break; default: PLERROR("In PStream::operator<< unknown outmode!!!!!!!!!"); break; } return *this; }
PStream& PLearn::PStream::operator<< | ( | pl_pstream_manip | func | ) | [inline] |
Definition at line 847 of file PStream.cc.
References compression_mode, implicit_storage, inmode, PLearn::PP< PStreamBuf >::operator=(), and outmode.
{ if(this != &pios) { inherited::operator=((const inherited&)pios); inmode = pios.inmode; outmode = pios.outmode; implicit_storage = pios.implicit_storage; compression_mode = pios.compression_mode; } return *this; }
PStream& PLearn::PStream::operator= | ( | streambuftype * | streambuf | ) | [inline] |
Definition at line 280 of file PStream.h.
{ inherited::operator=(streambuf); return *this; }
Definition at line 286 of file PStream.h.
References PLearn::operator==().
{ return PP<PStreamBuf>::operator==(other); }
PStream & PLearn::PStream::operator>> | ( | float & | x | ) |
Definition at line 1469 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(float)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | double & | x | ) |
Definition at line 1504 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(double)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | string & | x | ) |
Definition at line 1037 of file PStream.cc.
References c, PLearn::find(), inmode, peek(), plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, PLearn::raw_wordseparators(), skipBlanksAndComments(), unget(), and PLearn::wordseparators().
{ switch(inmode) { case PStream::raw_ascii: case PStream::raw_binary: case PStream::pretty_ascii: { skipBlanksAndComments(); int c = get(); x.clear(); // As long as we don't meet a (raw) wordseparator (or eof)... while (c!=EOF && raw_wordseparators().find(c)==string::npos) { x += static_cast<char>(c); c = get(); } unget(); } break; case PStream::plearn_ascii: case PStream::plearn_binary: { skipBlanksAndComments(); int c = peek(); if(c=='"') // it's a quoted string "..." { x.resize(0); c = get(); // skip the quote c = get(); // get the next character while(c!='"' && c!=EOF) { if(c=='\\') // escaped character { c = get(); switch (c) { case 'n': x += '\n'; break; case 't': x += '\t'; break; case 'r': x += '\r'; break; case '0': x += '\0'; break; case 'a': x += '\a'; break; case 'b': x += '\b'; break; case 'v': x += '\v'; break; case 'f': x += '\f'; break; default: x += static_cast<char>(c); break; } } else x += static_cast<char>(c); c = get(); } if(c==EOF) PLERROR("In read(istream&, string&) unterminated quoted string"); c = get(); if(!isspace(c)) // skip following blank if any unget(); } else // it's a single word without quotes { x.resize(0); c= get(); while(c != EOF && wordseparators().find(c)==string::npos) // as long as we don't meet a wordseparator (or eof)... { x+= static_cast<char>(c); c= get(); } if(!isspace(c)) unget(); } } break; default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | char * | x | ) |
Definition at line 936 of file PStream.cc.
References c, i, inmode, peek(), plearn_ascii, plearn_binary, PLERROR, pretty_ascii, putback(), raw_ascii, raw_binary, skipBlanksAndComments(), unget(), and PLearn::wordseparators().
{ if(!x) PLERROR("In PStream::operator>>(char*) character array must already be allocated to put the read string in"); switch(inmode) { case PStream::raw_ascii: case PStream::raw_binary: case PStream::pretty_ascii: { skipBlanksAndComments(); int i=0; // pos within the string int c = get(); while (c!=EOF && wordseparators().find(c)==string::npos) // as long as we don't meet a wordseparator (or eof)... { x[i++] = static_cast<char>(c); c = get(); } x[i++] = 0; unget(); } break; case PStream::plearn_ascii: case PStream::plearn_binary: { skipBlanksAndComments(); int c = peek(); int i=0; // pos within the string if(c=='"') // it's a quoted string "..." { c = get(); // skip the quote c = get(); // get the next character while(c!='"' && c!=EOF) { if(c=='\\') // escaped character { c = get(); switch (c) { case 'n': x[i++] = '\n'; break; case 't': x[i++] = '\t'; break; case 'r': x[i++] = '\r'; break; case '0': x[i++] = '\0'; break; case 'a': x[i++] = '\a'; break; case 'b': x[i++] = '\b'; break; case 'v': x[i++] = '\v'; break; case 'f': x[i++] = '\f'; break; default: x[i++] = static_cast<char>(c); break; } } else x[i++]= static_cast<char>(c); c = get(); } if(c==EOF) PLERROR("In read(istream&, char*) unterminated quoted string"); if(!isspace(c)) putback(c); } else // it's a single word without quotes { c= get(); while(c != EOF && wordseparators().find(c)==string::npos) // as long as we don't meet a wordseparator (or eof)... { x[i++]= static_cast<char>(c); c= get(); } if(!isspace(c)) unget(); } x[i++] = 0; } break; default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | char & | x | ) |
Definition at line 862 of file PStream.cc.
References inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, skipBlanks(), skipBlanksAndCommentsAndSeparators(), and x.
{ switch(inmode) { case raw_binary: get(x); break; case pretty_ascii: case raw_ascii: skipBlanks(); get(x); break; case plearn_ascii: case plearn_binary: skipBlanksAndCommentsAndSeparators(); get(x); if (x == '\'') // ascii case (between single quotes) { get(x); get(); } else if (x == 0x01) // plearn_binary case get(x); break; default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | unsigned char & | x | ) |
Definition at line 901 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), skipBlanks(), and skipBlanksAndCommentsAndSeparators().
{ switch(inmode) { case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(unsigned char)); break; case raw_ascii: skipBlanks(); read(reinterpret_cast<char *>(&x), sizeof(unsigned char)); break; case pretty_ascii: case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); char c = get(); if (c == '\'') // ascii { read(reinterpret_cast<char *>(&x), sizeof(unsigned char)); get(); } else if (c == 0x02) // plearn_binary read(reinterpret_cast<char *>(&x), sizeof(unsigned char)); else x = (unsigned char)c; break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
Definition at line 1136 of file PStream.cc.
References a, c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, skipBlanksAndCommentsAndSeparators(), and u.
{ int parsed = -1; char c; switch(inmode) { case raw_ascii: case pretty_ascii: case raw_binary: case plearn_ascii: case plearn_binary: skipBlanksAndCommentsAndSeparators(); c = get(); if(c=='1') parsed = 1; else if(c=='0') parsed = 0; else if(c=='T') { char r = get(); char u = get(); char e = get(); if ( r == 'r' && u == 'u' && e == 'e' ) parsed = 1; } else if(c=='F') { char a = get(); char l = get(); char s = get(); char e = get(); if ( a == 'a' && l == 'l' && s == 's' && e == 'e' ) parsed = 0; } if ( parsed == -1 ) PLERROR("In PStream::operator>>(bool &x) wrong format for bool, must be one " "of characters 0 or 1 or unquoted strings True or False" ); else x = (parsed != 0); break; default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
Definition at line 1259 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(int)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
Definition at line 1294 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(unsigned int)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | long & | x | ) |
Definition at line 1329 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(long)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | long long & | x | ) |
Definition at line 1399 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(long long)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | unsigned long long & | x | ) |
Definition at line 1434 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(unsigned long long)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream& PLearn::PStream::operator>> | ( | pl_pstream_manip | func | ) | [inline] |
PStream & PLearn::PStream::operator>> | ( | unsigned long & | x | ) |
Definition at line 1364 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(unsigned long)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | short & | x | ) |
Definition at line 1189 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(short)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | unsigned short & | x | ) |
Definition at line 1224 of file PStream.cc.
References c, inmode, plearn_ascii, plearn_binary, PLERROR, pretty_ascii, raw_ascii, raw_binary, read(), readAsciiNum(), readBinaryNum(), skipBlanks(), skipBlanksAndCommentsAndSeparators(), and unget().
{ switch(inmode) { case raw_ascii: case pretty_ascii: skipBlanks(); readAsciiNum(x); break; case raw_binary: read(reinterpret_cast<char *>(&x), sizeof(unsigned short)); break; case plearn_ascii: case plearn_binary: { skipBlanksAndCommentsAndSeparators(); int c = get(); if(c>0x00 && c<0x20) // plearn_binary { readBinaryNum(x, c); } else // plearn_ascii { unget(); readAsciiNum(x); } break; } default: PLERROR("In PStream::operator>> unknown inmode!!!!!!!!!"); break; } return *this; }
PStream & PLearn::PStream::operator>> | ( | signed char & | x | ) |
Definition at line 893 of file PStream.cc.
References c, and operator>>().
{ char c; operator>>(c); x = (signed char)c; return *this; }
PStream::mode_t PLearn::PStream::parseModeT | ( | const string & | str | ) | [static] |
Parse a string and return the equivalent PStream::mode_t.
Definition at line 280 of file PStream.cc.
References PLDEPRECATED, plearn_ascii, plearn_binary, and PLERROR.
Referenced by PLearn::HyperLearner::build_().
{ PStream::mode_t mode; if(str_mode.empty()) { PLDEPRECATED("The use of an empty string as PStream mode to default to" " 'plearn_ascii' is deprecated, please use 'plearn_ascii' " "directly"); mode = PStream::plearn_ascii; } else if(str_mode=="plearn_ascii") mode = PStream::plearn_ascii; else if(str_mode=="plearn_binary") mode = PStream::plearn_binary; else PLERROR("In PStream::parseModeT(%s): invalid mode", str_mode.c_str()); return mode; }
int PLearn::PStream::peek | ( | ) | [inline] |
The folowing methods are 'forwarded' from {i|o}stream.
It read from the stream without advancing in it. I.E. Multiple successive peek() will return the same data.
Definition at line 502 of file PStream.h.
Referenced by PLearn::VMatrix::getSavedSizes(), PLearn::TVec< T >::input(), PLearn::loadAscii(), PLearn::loadAsciiSingleBinaryDescriptor(), PLearn::Object::newread(), operator>>(), PLearn::operator>>(), PLearn::peekAfterSkipBlanksAndComments(), PLearn::TVec< PP< RegressionTreeNode > >::read(), PLearn::TMat< pair< real, real > >::read(), PLearn::readAndMacroProcess(), PLearn::readMap(), PLearn::readObject(), PLearn::readPriorityQueue(), PLearn::readSequence(), PLearn::readSet(), PLearn::test_read(), and PLearn::PLearnService::watchServers().
{ return ptr->peek(); }
PStream& PLearn::PStream::put | ( | unsigned char | c | ) | [inline] |
PStream& PLearn::PStream::put | ( | char | c | ) | [inline] |
Definition at line 587 of file PStream.h.
References put().
Referenced by PLearn::binwrite_(), PLearn::RemotePLearnServer::newObject(), PLearn::RemotePLearnServer::newObjectAsync(), operator<<(), PLearn::operator<<(), put(), PLearn::VMatrix::saveCMAT(), PLearn::test_write(), PLearn::TMat< pair< real, real > >::write(), writeAsciiHexNum(), writeAsciiNum(), PLearn::GhostScript::writeBitmapHexString1Bit(), PLearn::writeMap(), PLearn::writePriorityQueue(), PLearn::writeSequence(), and PLearn::writeSet().
PStream& PLearn::PStream::putback | ( | char | c | ) | [inline] |
If you put back the result of a call to get(), make sure it is not EOF.
Definition at line 506 of file PStream.h.
References putback().
Referenced by PLearn::Object::newread(), operator>>(), putback(), readUntil(), skipAll(), skipBlanks(), skipBlanksAndComments(), skipBlanksAndCommentsAndSeparators(), and PLearn::test_read().
PStream& PLearn::PStream::read | ( | string & | s, |
streamsize | n | ||
) | [inline] |
PStream& PLearn::PStream::read | ( | char * | s, |
streamsize | n | ||
) | [inline] |
Definition at line 534 of file PStream.h.
Referenced by PLearn::binread_(), PLearn::binread_as(), PLearn::loadFileAsString(), PLearn::VMatrix::lockMetaDataDir(), operator>>(), PLearn::TMat< pair< real, real > >::read(), PLearn::readSequence(), and PLearn::test_read().
string PLearn::PStream::readAll | ( | ) |
Reads until an EOF is found, and returns the whole content as a string.
Definition at line 300 of file PStream.cc.
References PLearn::PP< PStreamBuf >::ptr, and PLearn::PStreamBuf::read().
Referenced by PLearn::HelpSystem::helpEpilogueHTML(), PLearn::HelpSystem::helpIndexHTML(), and PLearn::HelpSystem::helpPrologueHTML().
{ const int bufsz= 4096; char buf[bufsz]; string s= ""; int nread= ptr->read(buf, bufsz); while(nread > 0) { s.append(buf, nread); nread= ptr->read(buf, bufsz); } return s; }
void PLearn::PStream::readAsciiNum | ( | unsigned short & | x | ) |
Definition at line 668 of file PStream.cc.
References readAsciiNum().
{ unsigned long dx; readAsciiNum(dx); x = (unsigned short)(dx); }
void PLearn::PStream::readAsciiNum | ( | int & | x | ) |
Definition at line 675 of file PStream.cc.
References readAsciiNum().
{ long dx; readAsciiNum(dx); x = int(dx); }
void PLearn::PStream::readAsciiNum | ( | unsigned int & | x | ) |
Definition at line 682 of file PStream.cc.
References readAsciiNum().
{ unsigned long dx; readAsciiNum(dx); x = (unsigned int)(dx); }
void PLearn::PStream::readAsciiNum | ( | long & | x | ) |
Definition at line 689 of file PStream.cc.
References c, PLERROR, skipBlanks(), unget(), and x.
{ skipBlanks(); x = 0; char c = get(); bool negate = false; if (c == '-') { negate = true; c = get(); } else if (c == '+') c = get(); if(!isdigit(c)) PLERROR("In readAsciiNum: not a valid ascii number, expected a digit, but read %c (ascii code %d)",c,c); do { x = x*10 + c-'0'; c = get(); } while(isdigit(c)); unget(); if(negate) x = -x; }
void PLearn::PStream::readAsciiNum | ( | unsigned long & | x | ) |
Definition at line 717 of file PStream.cc.
References c, skipBlanks(), and unget().
{ skipBlanks(); x = 0; char c = get(); while(isdigit(c)) { x = x*10 + c-'0'; c = get(); } unget(); }
void PLearn::PStream::readAsciiNum | ( | unsigned long long & | x | ) |
Definition at line 759 of file PStream.cc.
References c, skipBlanks(), and unget().
{ skipBlanks(); x = 0; char c = get(); while(isdigit(c)) { x *= 10; x += c-'0'; c = get(); } unget(); }
void PLearn::PStream::readAsciiNum | ( | float & | x | ) |
Definition at line 773 of file PStream.cc.
References readAsciiNum().
{ double dx; readAsciiNum(dx); x = float(dx); }
void PLearn::PStream::readAsciiNum | ( | double & | x | ) |
Definition at line 780 of file PStream.cc.
References c, MISSING_VALUE, PLERROR, PSTREAM_BUF_SIZE, skipBlanks(), unget(), and x.
{ static const char* error_msg = "Bug while reading file and expecting a double"; char tmpbuf[PSTREAM_BUF_SIZE]; skipBlanks(); int l=0; bool opposite = false; char c = get(); if (c == '-') { tmpbuf[l++] = c; opposite = true; c = get(); } else if (c == '+') // skip + sign c = get(); bool E_seen= false; bool sign_seen= false; bool dot_seen= false; switch(c) { case '?': x = MISSING_VALUE; break; case 'n': case 'N': if(toupper(get())=='A' && toupper(get())=='N') x = MISSING_VALUE; else PLERROR(error_msg); break; case 'i': case 'I': if (toupper(get())=='N' && toupper(get())=='F') { x = numeric_limits<double>::infinity(); if(opposite) x = -x; } else PLERROR(error_msg); break ; default: while(isdigit(c) || ((c=='e' || c=='E') && !E_seen) //only one E || ((c=='-' || c=='+') && E_seen && !sign_seen)//one sign, after E || (c=='.' && !E_seen && !dot_seen))//one dot, before E { if(c=='e' || c=='E') E_seen= true; if(c=='+' || c=='-') sign_seen= true; if(c=='.') dot_seen= true; tmpbuf[l++] = c; c = get(); } tmpbuf[l] = '\0'; unget(); sscanf(tmpbuf,"%lf",&x); if(l==0) PLERROR("In PStream::readAsciiNum - we read (%c) while we " "expected a digit", c); break; } }
void PLearn::PStream::readAsciiNum | ( | long long & | x | ) |
Definition at line 730 of file PStream.cc.
References c, PLERROR, skipBlanks(), unget(), and x.
{ skipBlanks(); x = 0; char c = get(); bool negate = false; if (c == '-') { negate = true; c = get(); } else if (c == '+') c = get(); if(!isdigit(c)) PLERROR("In readAsciiNum: not a valid ascii number, expected a digit, but read %c (ascii code %d)",c,c); do { x *= 10; x += c-'0'; c = get(); } while(isdigit(c)); unget(); if(negate) x = -x; }
void PLearn::PStream::readAsciiNum | ( | unsigned char & | x | ) |
Definition at line 647 of file PStream.cc.
References readAsciiNum().
{ long dx; readAsciiNum(dx); x = (unsigned char)(dx); }
void PLearn::PStream::readAsciiNum | ( | char & | x | ) |
Definition at line 640 of file PStream.cc.
Referenced by PLearn::operator>>(), operator>>(), and readAsciiNum().
{ long dx; readAsciiNum(dx); x = char(dx); }
void PLearn::PStream::readAsciiNum | ( | signed char & | x | ) |
Definition at line 654 of file PStream.cc.
References readAsciiNum().
{ long dx; readAsciiNum(dx); x = (signed char)(dx); }
void PLearn::PStream::readAsciiNum | ( | short & | x | ) |
Definition at line 661 of file PStream.cc.
References readAsciiNum().
{ long dx; readAsciiNum(dx); x = short(dx); }
void PLearn::PStream::readBinaryNum | ( | I & | x, |
unsigned char | typecode | ||
) | [inline] |
Reads base types from PLearn binary format.
Definition at line 370 of file PStream.h.
References BIG_ENDIAN_ORDER, PLearn::byte_order(), PLearn::endianswap(), LITTLE_ENDIAN_ORDER, PLERROR, PLearn::read(), and x.
Referenced by operator>>().
{ // If typecode corresponds to I's typecode if (typecode==TypeTraits<I>::little_endian_typecode()) { read(reinterpret_cast<char*>(&x), sizeof(I)); #ifdef BIGENDIAN endianswap(&x); #endif } else if (typecode==TypeTraits<I>::big_endian_typecode()) { read(reinterpret_cast<char*>(&x), sizeof(I)); #ifdef LITTLEENDIAN endianswap(&x); #endif } // Else, we need to try all the different types else if (typecode==TypeTraits<int8_t>::little_endian_typecode()) readBinaryNumAs<int8_t>(x, false); else if (typecode==TypeTraits<uint8_t>::little_endian_typecode()) readBinaryNumAs<uint8_t>(x, false); else if (typecode==TypeTraits<int16_t>::little_endian_typecode()) readBinaryNumAs<int16_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<int16_t>::big_endian_typecode()) readBinaryNumAs<int16_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<uint16_t>::little_endian_typecode()) readBinaryNumAs<uint16_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<uint16_t>::big_endian_typecode()) readBinaryNumAs<uint16_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<int32_t>::little_endian_typecode()) readBinaryNumAs<int32_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<int32_t>::big_endian_typecode()) readBinaryNumAs<int32_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<uint32_t>::little_endian_typecode()) readBinaryNumAs<uint32_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<uint32_t>::big_endian_typecode()) readBinaryNumAs<uint32_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<int64_t>::little_endian_typecode()) readBinaryNumAs<int64_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<int64_t>::big_endian_typecode()) readBinaryNumAs<int64_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<uint64_t>::little_endian_typecode()) readBinaryNumAs<uint64_t>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<uint64_t>::big_endian_typecode()) readBinaryNumAs<uint64_t>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<float>::little_endian_typecode()) readBinaryNumAs<float>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<float>::big_endian_typecode()) readBinaryNumAs<float>(x, byte_order()==LITTLE_ENDIAN_ORDER); else if (typecode==TypeTraits<double>::little_endian_typecode()) readBinaryNumAs<double>(x, byte_order()==BIG_ENDIAN_ORDER); else if (typecode==TypeTraits<double>::big_endian_typecode()) readBinaryNumAs<double>(x, byte_order()==LITTLE_ENDIAN_ORDER); else PLERROR("In PStream readBinaryNum: Unknown typecode '%c' (%x)", typecode, typecode); }
void PLearn::PStream::readBinaryNumAs | ( | J & | x, |
bool | inverted_byte_order | ||
) | [inline] |
Reads a J element, optionnally swaps its endianness, and returns an I.
Definition at line 336 of file PStream.h.
References PLearn::endianswap(), PLearn::endl(), PLERROR, and PLearn::read().
{ I y; read(reinterpret_cast<char*>(&y), sizeof(I)); if (inverted_byte_order) endianswap(&y); #ifdef __INTEL_COMPILER #pragma warning(disable:1682) // Yes, I know that "implicit conversion of a 64-bit integral type to a smaller // integral type (potential portability problem)", but the conversion is // explicit here. #endif x = static_cast<J>(y); // Check if there was a conversion problem (sign or overflow) if (static_cast<I>(x) != y || (!(numeric_limits<J>::is_signed) && chkUnsigned<numeric_limits<I>::is_signed>::notOk(y))) { std::stringstream error; error << "In PStream::readBinaryNumAs, overflow error: " << std::endl << "unable to read value \"" << y << "\"" << "into a " << TypeTraits<I>::name() << std::endl; PLERROR( error.str().c_str() ); } #ifdef __INTEL_COMPILER #pragma warning(default:1682) #endif }
void PLearn::PStream::readExpected | ( | char | expect | ) |
Reads the next character and launches a PLERROR if it is different from expect.
Definition at line 318 of file PStream.cc.
Referenced by PLearn::operator>>(), and readExpected().
void PLearn::PStream::readExpected | ( | const string & | expect | ) |
Reads character one by one, comparing it with the sequence in expect.
Throws a PLERROR as soon as the character read differs from the character expected.
Definition at line 331 of file PStream.cc.
References i, and readExpected().
void PLearn::PStream::readExpected | ( | char * | expect | ) |
Reads character one by one, comparing it with the sequence in expect (until terminating null character in expect).
Throws a PLERROR as soon as the character read differs from the character expected.
Definition at line 325 of file PStream.cc.
References c, and readExpected().
{ for(char c = *expect; c!=0; c=*expect++) readExpected(c); }
streamsize PLearn::PStream::readUntil | ( | char * | buf, |
streamsize | n, | ||
const char * | stop_chars | ||
) |
Reads characters into buf until n characters have been read, or end-of-file has been reached, or the next character in the stream is one of the stop_chars (null terminated string).
Returns the total number of characters put into buf. The stopping character met is not extracted from the stream.
Definition at line 360 of file PStream.cc.
{ streamsize nread = 0; while(nread<n) { int c = get(); if(c==EOF) break; if(strchr(stop_chars, c)) { putback(c); break; } *buf++ = (char)c; ++nread; } return nread; }
streamsize PLearn::PStream::readUntil | ( | char * | buf, |
streamsize | n, | ||
char | stop_char | ||
) |
Reads characters into buf until n characters have been read, or end-of-file has been reached, or the next character in the stream is the stop_char.
Returns the total number of characters put into buf. The stopping character met is not extracted from the stream.
Definition at line 339 of file PStream.cc.
Referenced by PLearn::TextFilesVMatrix::readAndCheckOptionName().
{ streamsize nread = 0; while(nread<n) { int c = get(); if(c==EOF) break; if((char)c == stop_char) { putback(c); break; } *buf++ = (char)c; ++nread; } return nread; }
void PLearn::PStream::setBufferCapacities | ( | streamsize | inbuf_capacity, |
streamsize | outbuf_capacity, | ||
streamsize | unget_capacity | ||
) | [inline] |
Definition at line 216 of file PStream.h.
Referenced by PLearn::get_perr(), PLearn::test_negchar(), PLearn::test_read(), PLearn::test_write(), and PLearn::test_write_unbuffered().
{ ptr->setBufferCapacities(inbuf_capacity, outbuf_capacity, unget_capacity); }
void PLearn::PStream::setDoubleFormat | ( | const char * | f | ) | [inline] |
Definition at line 468 of file PStream.h.
Referenced by PLearn::vmatmain().
{ format_double = f; }
void PLearn::PStream::setFloatFormat | ( | const char * | f | ) | [inline] |
Definition at line 467 of file PStream.h.
Referenced by PLearn::vmatmain().
{ format_float = f; }
void PLearn::PStream::setMode | ( | mode_t | m | ) | [inline] |
Definition at line 239 of file PStream.h.
References m.
Referenced by PLearn::PLearnServer::ascii(), PLearn::PLearnServer::binary(), PLearn::ModuleTester::build_(), PLearn::PLearnServer::callFunction(), PLearn::get_perr(), PLearn::get_pin(), PLearn::get_pio(), PLearn::get_pout(), PLearn::openMPI(), PLearn::openSocket(), PLearn::openString(), PLearn::openUrl(), PLearn::ObjectGraphIteratorTest::perform(), PLearn::ServerCommand::run(), and PLearn::PLearnServer::run().
Definition at line 232 of file PStream.h.
References m.
Referenced by PLearn::_tostring_static_pstream_(), PLearn::PL_LogPluginInterceptor::getStream(), and PLearn::PL_LogPluginPStream::getStream().
void PLearn::PStream::skipAll | ( | const char * | chars_to_skip | ) |
void PLearn::PStream::skipBlanks | ( | ) |
skips any blanks (space, tab, newline)
Definition at line 446 of file PStream.cc.
Referenced by PLearn::LIBSVMSparseVMatrix::build_(), PLearn::DictionaryVMatrix::build_(), PLearn::VMatrix::getSavedSizes(), PLearn::VMatrix::loadStringMapping(), operator>>(), readAsciiNum(), PLearn::readSequence(), and PLearn::ws().
{ int c = get(); while(c!=EOF && (c==' ' || c=='\t' || c=='\n' || c=='\r')) c = get(); if(c!=EOF) putback(c); }
void PLearn::PStream::skipBlanksAndComments | ( | ) |
skips any blanks (space, tab, newline) and comments starting with #
Definition at line 455 of file PStream.cc.
References c, putback(), and skipRestOfLine().
Referenced by PLearn::PLearnService::connectToServers(), PLearn::RemotePLearnServer::expectResults(), PLearn::Object::newread(), operator>>(), PLearn::operator>>(), PLearn::TVec< PP< RegressionTreeNode > >::read(), PLearn::TMat< pair< real, real > >::read(), PLearn::TextFilesVMatrix::readAndCheckOptionName(), PLearn::readSequence(), and PLearn::ws().
{ int c = get(); while(c!=EOF) { if(c=='#') skipRestOfLine(); else if(c!=' ' && c!='\t' && c!='\n' && c!='\r') break; c = get(); } if(c!=EOF) putback(c); }
void PLearn::PStream::skipBlanksAndCommentsAndSeparators | ( | ) |
skips any blanks, # comments, and separators (',' and ';')
Definition at line 470 of file PStream.cc.
References c, putback(), and skipRestOfLine().
Referenced by PLearn::Plide::executePyPLearn(), PLearn::TVec< T >::input(), PLearn::Object::newread(), operator>>(), PLearn::operator>>(), PLearn::TVec< PP< RegressionTreeNode > >::read(), PLearn::TMat< pair< real, real > >::read(), PLearn::SmoothedProbSparseMatrix::read(), PLearn::DoubleAccessSparseMatrix< T >::read(), PLearn::readMap(), PLearn::readObject(), PLearn::readPriorityQueue(), PLearn::readSequence(), PLearn::readSet(), PLearn::RunCommand::run(), and PLearn::PyPLearnScript::run().
{ int c = get(); while(c!=EOF) { if(c=='#') skipRestOfLine(); else if(c!=' ' && c!='\t' && c!='\n' && c!='\r' && c!=';' && c!=',') break; c = get(); } if(c!=EOF) putback(c); }
void PLearn::PStream::skipRestOfLine | ( | ) |
reads everything until '
' (also consumes the '
')
Definition at line 439 of file PStream.cc.
References c.
Referenced by skipBlanksAndComments(), skipBlanksAndCommentsAndSeparators(), and smartReadUntilNext().
{ int c = get(); while(c!='\n' && c!=EOF) c=get(); }
int PLearn::PStream::smartReadUntilNext | ( | const string & | stoppingsymbols, |
string & | characters_read, | ||
bool | ignore_brackets = false , |
||
bool | skip_comments = true |
||
) |
Reads characters from stream, until we meet one of the stopping symbols at the current "level".
i.e. any opening parenthesis, bracket, brace or quote will open a next level and we'll be back to the current level only *after* we meet the corresponding closing parenthesis, bracket, brace or quote. All characters read, except the stoppingsymbol, will be *appended* to characters_read. The stoppingsymbol is read and returned, but not appended to characters_read. Comments starting with # until the end of line may be skipped (as if they were not part of the stream)
Definition at line 381 of file PStream.cc.
References c, and skipRestOfLine().
Referenced by PLearn::VecStatsCollector::getStat(), PLearn::StatsCollector::getStat(), PLearn::LiftStatsCollector::getStat(), PLearn::VMatLanguage::preprocess(), and PLearn::readAndMacroProcess().
{ int c; while( (c=get()) != EOF) { if(stoppingsymbols.find(c)!=string::npos) break; else if(skip_comments && c=='#') // skip until end of line skipRestOfLine(); else { if(characters_read.length() == characters_read.capacity()) characters_read.reserve(characters_read.length()*2); //don't realloc© every time a char is appended... characters_read+= static_cast<char>(c); switch(c) { case '(': smartReadUntilNext(")", characters_read, ignore_brackets, skip_comments); characters_read+= ')'; break; case '[': if(!ignore_brackets) { smartReadUntilNext("]", characters_read, ignore_brackets, skip_comments); characters_read+= ']'; } break; case '{': smartReadUntilNext("}", characters_read, ignore_brackets, skip_comments); characters_read+= '}'; break; case '"': smartReadUntilNext("\"", characters_read, ignore_brackets, false); characters_read+= '"'; break; case '\\': // we consider backslash an escape character, c=get(); // thus the next character is read and appended without being interpreted if(c!=EOF) characters_read += static_cast<char>(c); break; } } } return c; }
PStream::mode_t PLearn::PStream::switchToPLearnOutMode | ( | ) |
if outmode is raw_ascii or raw_binary, it will be switched to corresponding plearn_ascii, resp.
plearn_binary. The old mode will be returned, so that you can call setOutMode to revert to the old mode when finished
Definition at line 259 of file PStream.cc.
References outmode, plearn_ascii, plearn_binary, pretty_ascii, raw_ascii, and raw_binary.
Referenced by PLearn::operator<<().
{ mode_t oldmode = outmode; switch(outmode) { case PStream::raw_ascii: case PStream::pretty_ascii: outmode = PStream::plearn_ascii; break; case PStream::raw_binary: outmode = PStream::plearn_binary; break; default: break; } return oldmode; }
PStream& PLearn::PStream::unget | ( | ) | [inline] |
Put back the last character read by the get() or read() methods.
You can only call this method once (use the unread() method if you want to put back more than one character).
Definition at line 515 of file PStream.h.
References unget().
Referenced by operator>>(), PLearn::peekAfterSkipBlanks(), PLearn::RealMapping::read(), readAsciiNum(), PLearn::readWhileMatches(), PLearn::skipBlanksAndComments(), and unget().
{ ptr->unget(); return *this; }
PStream& PLearn::PStream::unread | ( | const char * | p, |
streamsize | n | ||
) | [inline] |
Definition at line 521 of file PStream.h.
References unread().
Referenced by PLearn::readObject(), PLearn::test_read(), and unread().
PStream& PLearn::PStream::unread | ( | const char * | p | ) | [inline] |
Definition at line 527 of file PStream.h.
References PLearn::strlen(), and unread().
Referenced by unread().
{ return unread(p, streamsize(strlen(p))); }
PStream& PLearn::PStream::unread | ( | const string & | s | ) | [inline] |
PStream& PLearn::PStream::write | ( | const char * | s, |
streamsize | n | ||
) | [inline] |
Definition at line 581 of file PStream.h.
Referenced by PLearn::binwrite_(), PLearn::RemotePLearnServer::deleteAllObjectsAsync(), PLearn::RemotePLearnServer::deleteObjectAsync(), PLearn::RemoteProgressBarPlugin::killProgressBar(), PLearn::RemotePLearnServer::newObject(), PLearn::RemotePLearnServer::newObjectAsync(), PLearn::Object::newwrite(), PLearn::openUrl(), operator<<(), PLearn::operator<<(), PLearn::Object::prepareToSendResults(), PLearn::PLearnServer::printHelp(), PLearn::RemoteProgressBarPlugin::printTitle(), PLearn::PLearnServer::run(), PLearn::RemotePLearnServer::sendFunctionCallHeader(), PLearn::RemotePLearnServer::sendMethodCallHeader(), PLearn::test_negchar(), PLearn::test_write(), PLearn::test_write_unbuffered(), PLearn::RemoteProgressBarPlugin::update(), PLearn::TVec< PP< RegressionTreeNode > >::write(), PLearn::TMat< pair< real, real > >::write(), PLearn::SmoothedProbSparseMatrix::write(), PLearn::DoubleAccessSparseMatrix< T >::write(), PLearn::ServerLogStreamBuf::write_(), writeAsciiNum(), PLearn::writeMap(), PLearn::writePriorityQueue(), PLearn::writeSequence(), and PLearn::writeSet().
PStream& PLearn::PStream::write | ( | const string & | s | ) | [inline] |
Definition at line 623 of file PStream.h.
References PLearn::write().
{ write(s.data(), streamsize(s.length())); return *this; }
PStream& PLearn::PStream::write | ( | const char * | s | ) | [inline] |
Definition at line 617 of file PStream.h.
References PLearn::strlen(), and PLearn::write().
{ write(s, streamsize(strlen(s))); return *this; }
void PLearn::PStream::writeAsciiHexNum | ( | unsigned char | x | ) |
Writes the corresponding 2 hex digits (ex: 0A )
Definition at line 499 of file PStream.cc.
Referenced by PLearn::GhostScript::writeBitmapHexString1Bit(), PLearn::GhostScript::writeBitmapHexString24Bits(), and PLearn::GhostScript::writeBitmapHexString8Bits().
{ int d = x>>4; put(d<0x0A ?(d+'0') :(d-0x0A+'A')); d = x & 0x0F; put(d<0x0A ?(d+'0') :(d-0x0A+'A')); }
void PLearn::PStream::writeAsciiNum | ( | short | x | ) |
Definition at line 529 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%hd", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | long long | x | ) |
Definition at line 571 of file PStream.cc.
References put(), writeAsciiNum(), and zero.
{ long long zero(0); if(x>=zero) writeAsciiNum((unsigned long long)x); else { put('-'); writeAsciiNum((unsigned long long) -x); } }
void PLearn::PStream::writeAsciiNum | ( | long | x | ) |
Definition at line 557 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%ld", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | float | x | ) |
Definition at line 604 of file PStream.cc.
References format_float, PLearn::is_missing(), PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ if(is_missing(x)) write("nan"); else if (isinf(x)) { if (x < 0) write("-inf"); else write("inf"); } else { char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), format_float, x); write(tmpbuf, streamsize(strlen(tmpbuf))); } }
void PLearn::PStream::writeAsciiNum | ( | signed char | x | ) |
Definition at line 522 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%d", (int)x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | unsigned short | x | ) |
Definition at line 536 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%hu", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | unsigned long | x | ) |
Definition at line 564 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%lu", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | char | x | ) |
Definition at line 508 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
Referenced by operator<<(), and writeAsciiNum().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%d", (int)x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | unsigned char | x | ) |
Definition at line 515 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%d", (int)x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | int | x | ) |
Definition at line 543 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%d", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | unsigned long long | x | ) |
Definition at line 583 of file PStream.cc.
References n, put(), write(), and zero.
{ unsigned long long zero(0); if(x==zero) put('0'); else { char buf[30]; char* p = buf+29; int n = 0; while(x>zero) { *p-- = '0'+char(x%10); x /= 10; ++n; } ++p; write(p,n); } }
void PLearn::PStream::writeAsciiNum | ( | unsigned int | x | ) |
Definition at line 550 of file PStream.cc.
References PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), "%u", x); write(tmpbuf, streamsize(strlen(tmpbuf))); }
void PLearn::PStream::writeAsciiNum | ( | double | x | ) |
Definition at line 622 of file PStream.cc.
References format_double, PLearn::is_missing(), PSTREAM_BUF_SIZE, PLearn::strlen(), and write().
{ if(is_missing(x)) write("nan"); else if (isinf(x)) { if (x < 0) write("-inf"); else write("inf"); } else { char tmpbuf[PSTREAM_BUF_SIZE]; snprintf(tmpbuf, sizeof(tmpbuf), format_double, x); write(tmpbuf, streamsize(strlen(tmpbuf))); } }
void PLearn::PStream::writeBinaryNum | ( | I | x | ) | [inline] |
Writes base types to PLearn binary format TODO: forbid this mechanism for arbitrary classes?
Definition at line 324 of file PStream.h.
References PLearn::write().
Referenced by operator<<().
{ #ifdef BIGENDIAN put(TypeTraits<I>::big_endian_typecode()); #else put(TypeTraits<I>::little_endian_typecode()); #endif write((char*)&x, sizeof(I)); }
Determines the way data is compressed, if any.
Definition at line 183 of file PStream.h.
Referenced by operator=().
map<unsigned int, void *> PLearn::PStream::copies_map_in |
format flags for input
copies map for input
Definition at line 152 of file PStream.h.
Referenced by PLearn::operator>>(), PLearn::readObject(), and PLearn::PLearnServer::run().
map<void *, unsigned int> PLearn::PStream::copies_map_out |
format flags for output
copies map for output
Definition at line 161 of file PStream.h.
Referenced by PLearn::RemotePLearnServer::clearMaps(), PLearn::RemotePLearnServer::link(), PLearn::operator<<(), PLearn::ObjectGraphIteratorTest::perform(), PLearn::PLearnServer::run(), and PLearn::RemotePLearnServer::unlink().
const char* PLearn::PStream::format_double [private] |
Current format string for doubles.
Definition at line 168 of file PStream.h.
Referenced by writeAsciiNum().
const char * PLearn::PStream::format_double_default = "%.15g" [static, private] |
const char* PLearn::PStream::format_float [private] |
Current format string for floats.
Definition at line 165 of file PStream.h.
Referenced by writeAsciiNum().
const char * PLearn::PStream::format_float_default = "%.8g" [static, private] |
If true, then Mat and Vec will be serialized with their elements in place, If false, they will have an explicit pointer to a storage.
Definition at line 180 of file PStream.h.
Referenced by PLearn::PLearnServer::callFunction(), PLearn::PLearnServer::implicit_storage(), operator=(), PLearn::save(), PLearn::TVec< PP< RegressionTreeNode > >::write(), and PLearn::TMat< pair< real, real > >::write().
mode for input formatting
Definition at line 146 of file PStream.h.
Referenced by operator=(), operator>>(), PLearn::operator>>(), PLearn::TVec< PP< RegressionTreeNode > >::read(), PLearn::TMat< pair< real, real > >::read(), PLearn::SmoothedProbSparseMatrix::read(), PLearn::DoubleAccessSparseMatrix< T >::read(), PLearn::readSequence(), and PLearn::ws().
mode for output formatting
Definition at line 155 of file PStream.h.
Referenced by PLearn::binwrite_(), PLearn::Learner::default_vlog(), PLearn::GhostScript::GhostScript(), PLearn::Gnuplot::Gnuplot(), PLearn::VVec::newwrite(), PLearn::StatsCollector::newwrite(), PLearn::RealMapping::newwrite(), operator<<(), PLearn::operator<<(), operator=(), switchToPLearnOutMode(), PLearn::TextProgressBarPlugin::TextProgressBarPlugin(), PLearn::TVec< PP< RegressionTreeNode > >::write(), PLearn::TMat< pair< real, real > >::write(), PLearn::SmoothedProbSparseMatrix::write(), PLearn::DoubleAccessSparseMatrix< T >::write(), and PLearn::writeSequence().
Should be true if this stream is used to communicate with a remote PLearn host.
Will serialize options accordingly.
Definition at line 187 of file PStream.h.
Referenced by PLearn::Object::asStringRemoteTransmit(), PLearn::Object::newwrite(), PLearn::PLearnServer::PLearnServer(), PLearn::RemotePLearnServer::RemotePLearnServer(), PLearn::PLearnServer::~PLearnServer(), and PLearn::RemotePLearnServer::~RemotePLearnServer().
bool PLearn::PStream::windows_endl = false [static] |
If true, we should emit windows end of line(
)
Definition at line 190 of file PStream.h.
Referenced by PLearn::global_options().