Torque3D Documentation / _generateds / streamObject.cpp

streamObject.cpp

Engine/source/core/stream/streamObject.cpp

More...

Public Functions

ConsoleDocClass(StreamObject , "@brief Base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">streams.\n\n</a>" "You do not instantiate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classstreamobject/">StreamObject</a> directly. Instead, it is used as part of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classfilestreamobject/">FileStreamObject</a> and <a href="/coding/class/classzipobject/">ZipObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "support working with uncompressed and compressed files respectively." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//You cannot actually declare <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">StreamObject\n</a>" "// Instead)
DefineEngineMethod(StreamObject , copyFrom , bool , (SimObject *other) , "@brief Copy from another <a href="/coding/class/classstreamobject/">StreamObject</a> into this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">StreamObject\n\n</a>" "@param other The <a href="/coding/class/classstreamobject/">StreamObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> copy <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the copy was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">successful.\n</a>" )
DefineEngineMethod(StreamObject , getPosition , S32 , () , "@brief Gets the position in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The easiest way <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize this is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> think of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text file. If you have moved the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> by " "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. " "For StreamObject, when you read in the line the position is increased by the number of characters parsed, " "the null terminator, and <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">newline.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, 10 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the words, 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the space, 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the null terminator, and 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">newline\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(%position);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "//Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @return Number of bytes which stream has parsed so far, null terminators and newlines are <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">included\n</a>" " @see setPosition()" )
DefineEngineMethod(StreamObject , getStatus , const char * , () , "@brief Gets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> printable string form of the stream's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">status\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, one of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">following:\n\n</a>" " OK - <a href="/coding/class/classstream/">Stream</a> is active and no <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">errors\n\n</a>" " IOError - Something went wrong during read or writing the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" " EOS - End of <a href="/coding/class/classstream/">Stream</a> reached(mostly <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> reads)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " IllegalCall - An unsupported operation used. Always w/accompanied by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AssertWarn\n\n</a>" " Closed - Tried <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> operate on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> closed stream(or detached filter)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " UnknownError - Catch all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> an error of some <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">kind\n\n</a>" " Invalid - Entire stream is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">invalid\n\n</a>" )
DefineEngineMethod(StreamObject , getStreamSize , S32 , () , "@brief Gets the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> is dependent on the type of stream being used. If it is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream, returned <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> will " "be the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the file. If it is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> memory stream, it will be the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the allocated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffer.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bytes\n</a>" )
DefineEngineMethod(StreamObject , isEOF , bool , () , "@brief Tests <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the stream has reached the end of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n\n</a>" "This is an alternative name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> isEOS. Both functions are interchangeable. This simply exists " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> those familiar with some C++ <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> I/O <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">standards.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, false <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see isEOS()" )
DefineEngineMethod(StreamObject , isEOS , bool , () , "@brief Tests <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the stream has reached the end of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n\n</a>" "This is an alternative name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> isEOF. Both functions are interchangeable. This simply exists " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> those familiar with some C++ <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> I/O <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">standards.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, false <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see isEOF()" )
DefineEngineMethod(StreamObject , readLine , const char * , () , "@brief Read <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n\n</a>" "Emphasis on *line* )
DefineEngineMethod(StreamObject , readLongString , String , (S32 maxLength) , "@brief Read in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the given maximum number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param maxLength The maximum number of characters <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> read <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">in.\n</a>" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeLongString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )
DefineEngineMethod(StreamObject , readString , String , () , "@brief Read <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> maximum of 256 characters" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )
DefineEngineMethod(StreamObject , readSTString , String , (bool caseSensitive) , (false) , "@brief Read in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string and place it on the string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n\n</a>" "@param caseSensitive If false then case will not be taken into account when attempting " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> match the read in string with what is already in the string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n</a>" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )
DefineEngineMethod(StreamObject , setPosition , bool , (S32 newPosition) , "@brief Gets the position in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The easiest way <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize this is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> think of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text file. If you have moved the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> by " "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. " "For StreamObject, when you read in the line the position is increased by the number of characters parsed, " "the null terminator, and <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> newline. Using setPosition allows you <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> skip <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> specific points of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, which will bypass the first line <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">entirely\n</a>" "%fsObject.setPosition(12);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "//Read in the next <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">line\n</a>" "% line, should be \"Hello World\"\n" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(%line);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@return Number of bytes which stream has parsed so far, null terminators and newlines are <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">included\n</a>" " @see getPosition()" )
DefineEngineMethod(StreamObject , writeLine , void , (const char *line) , "@brief Write <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stream, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it was opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">writing.\n\n</a>" "There is no limit as <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> what kind of data you can write. Any format and data is allowable, not just text. " "Be careful of what you write, as whitespace, current values, and literals will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">preserved.\n\n</a>" " @param line The data we are writing out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> file." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n</a>" "% fsObject, it is created. If it does exist, the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cleared\n</a>" "%fsObject.open(\"./test.txt\", \"write\");\n\n" "// Write <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "%fsObject.writeLine(\"Hello World\");\n\n" "// Write another line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "%fsObject.writeLine(\"Documentation Rocks!\");\n\n" "// Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see readLine()" )
DefineEngineMethod(StreamObject , writeLongString , void , (S32 maxLength, const char *string) , "@brief Write out <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the maximum number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param maxLength The maximum number of characters that will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">written.\n</a>" "@param string The string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see readLongString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )
DefineEngineMethod(StreamObject , writeString , void , (const char *string, S32 maxLength) , (256) , "@brief Write out <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> default maximum length of 256 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param string The string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n</a>" "@param maxLength The maximum string length <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> default of 256 characters. This " "<a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> should not be larger than 256 as it is written <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stream as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">byte.\n</a>" "@see readString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

Detailed Description

Public Functions

ConsoleDocClass(StreamObject , "@brief Base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">streams.\n\n</a>" "You do not instantiate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classstreamobject/">StreamObject</a> directly. Instead, it is used as part of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classfilestreamobject/">FileStreamObject</a> and <a href="/coding/class/classzipobject/">ZipObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "support working with uncompressed and compressed files respectively." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//You cannot actually declare <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">StreamObject\n</a>" "// Instead)

DefineEngineMethod(StreamObject , copyFrom , bool , (SimObject *other) , "@brief Copy from another <a href="/coding/class/classstreamobject/">StreamObject</a> into this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">StreamObject\n\n</a>" "@param other The <a href="/coding/class/classstreamobject/">StreamObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> copy <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the copy was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">successful.\n</a>" )

DefineEngineMethod(StreamObject , getPosition , S32 , () , "@brief Gets the position in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The easiest way <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize this is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> think of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text file. If you have moved the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> by " "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. " "For StreamObject, when you read in the line the position is increased by the number of characters parsed, " "the null terminator, and <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">newline.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, 10 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the words, 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the space, 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the null terminator, and 1 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">newline\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(%position);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "//Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @return Number of bytes which stream has parsed so far, null terminators and newlines are <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">included\n</a>" " @see setPosition()" )

DefineEngineMethod(StreamObject , getStatus , const char * , () , "@brief Gets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> printable string form of the stream's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">status\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, one of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">following:\n\n</a>" " OK - <a href="/coding/class/classstream/">Stream</a> is active and no <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">errors\n\n</a>" " IOError - Something went wrong during read or writing the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" " EOS - End of <a href="/coding/class/classstream/">Stream</a> reached(mostly <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> reads)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " IllegalCall - An unsupported operation used. Always w/accompanied by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AssertWarn\n\n</a>" " Closed - Tried <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> operate on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> closed stream(or detached filter)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " UnknownError - Catch all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> an error of some <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">kind\n\n</a>" " Invalid - Entire stream is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">invalid\n\n</a>" )

DefineEngineMethod(StreamObject , getStreamSize , S32 , () , "@brief Gets the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> is dependent on the type of stream being used. If it is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream, returned <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> will " "be the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the file. If it is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> memory stream, it will be the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a> of the allocated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffer.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bytes\n</a>" )

DefineEngineMethod(StreamObject , isEOF , bool , () , "@brief Tests <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the stream has reached the end of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n\n</a>" "This is an alternative name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> isEOS. Both functions are interchangeable. This simply exists " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> those familiar with some C++ <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> I/O <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">standards.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, false <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see isEOS()" )

DefineEngineMethod(StreamObject , isEOS , bool , () , "@brief Tests <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the stream has reached the end of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n\n</a>" "This is an alternative name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> isEOF. Both functions are interchangeable. This simply exists " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> those familiar with some C++ <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> I/O <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">standards.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, false <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see isEOF()" )

DefineEngineMethod(StreamObject , readLine , const char * , () , "@brief Read <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n\n</a>" "Emphasis on *line* )

DefineEngineMethod(StreamObject , readLongString , String , (S32 maxLength) , "@brief Read in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the given maximum number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param maxLength The maximum number of characters <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> read <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">in.\n</a>" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeLongString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

DefineEngineMethod(StreamObject , readString , String , () , "@brief Read <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> maximum of 256 characters" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

DefineEngineMethod(StreamObject , readSTString , String , (bool caseSensitive) , (false) , "@brief Read in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string and place it on the string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n\n</a>" "@param caseSensitive If false then case will not be taken into account when attempting " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> match the read in string with what is already in the string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n</a>" "@return The string that was read from the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see writeString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

DefineEngineMethod(StreamObject , setPosition , bool , (S32 newPosition) , "@brief Gets the position in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n\n</a>" "The easiest way <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize this is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> think of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text file. If you have moved the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> by " "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. " "For StreamObject, when you read in the line the position is increased by the number of characters parsed, " "the null terminator, and <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> newline. Using setPosition allows you <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> skip <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> specific points of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading\n</a>" "% fsObject, which will bypass the first line <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">entirely\n</a>" "%fsObject.setPosition(12);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "//Read in the next <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">line\n</a>" "% line, should be \"Hello World\"\n" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(%line);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@return Number of bytes which stream has parsed so far, null terminators and newlines are <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">included\n</a>" " @see getPosition()" )

DefineEngineMethod(StreamObject , writeLine , void , (const char *line) , "@brief Write <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stream, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it was opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">writing.\n\n</a>" "There is no limit as <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> what kind of data you can write. Any format and data is allowable, not just text. " "Be careful of what you write, as whitespace, current values, and literals will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">preserved.\n\n</a>" " @param line The data we are writing out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> file." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n</a>" "% fsObject, it is created. If it does exist, the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cleared\n</a>" "%fsObject.open(\"./test.txt\", \"write\");\n\n" "// Write <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "%fsObject.writeLine(\"Hello World\");\n\n" "// Write another line <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "%fsObject.writeLine(\"Documentation Rocks!\");\n\n" "// Always remember <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> stream when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">finished\n</a>" "%fsObject.close();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see readLine()" )

DefineEngineMethod(StreamObject , writeLongString , void , (S32 maxLength, const char *string) , "@brief Write out <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the maximum number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param maxLength The maximum number of characters that will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">written.\n</a>" "@param string The string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream.\n</a>" "@see readLongString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

DefineEngineMethod(StreamObject , writeString , void , (const char *string, S32 maxLength) , (256) , "@brief Write out <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> default maximum length of 256 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">characters.\n\n</a>" "@param string The string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stream\n</a>" "@param maxLength The maximum string length <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write out with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> default of 256 characters. This " "<a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> should not be larger than 256 as it is written <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stream as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">byte.\n</a>" "@see readString()" "@note When working with these particular string reading and writing methods, the stream " "begins with the length of the string followed by the string itself, and does not include " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> terminator." )

IMPLEMENT_CONOBJECT(StreamObject )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "core/stream/streamObject.h"
 25#include "console/engineAPI.h"
 26
 27//-----------------------------------------------------------------------------
 28// Constructor/Destructor
 29//-----------------------------------------------------------------------------
 30
 31// This entire class has some major issues. Lots of bad characters when reading and
 32// writing. Stream doesn't seem to jump correctly. All in all this either needs
 33// to be deprecated, fixed, or someone explain to me what I'm doing wrong.
 34// Hard to document when it's not working. -Mich 7/16/2010
 35
 36StreamObject::StreamObject()
 37{
 38   mStream = NULL;
 39}
 40
 41StreamObject::StreamObject(Stream *stream)
 42{
 43   mStream = stream;
 44}
 45
 46StreamObject::~StreamObject()
 47{
 48}
 49
 50IMPLEMENT_CONOBJECT(StreamObject);
 51
 52ConsoleDocClass( StreamObject,
 53   "@brief Base class for working with streams.\n\n"
 54
 55   "You do not instantiate a StreamObject directly.  Instead, it is used as part of a FileStreamObject and ZipObject to "
 56   "support working with uncompressed and compressed files respectively."
 57
 58   "@tsexample\n"
 59   "// You cannot actually declare a StreamObject\n"
 60   "// Instead, use the derived class \"FileStreamObject\"\n"
 61   "%fsObject = FileStreamObject();\n"
 62   "@endtsexample\n\n"
 63
 64   "@see FileStreamObject for the derived class usable in script.\n"
 65   "@see ZipObject where StreamObject is used to read and write to files within a zip archive.\n"
 66
 67   "@ingroup FileSystem\n\n"
 68);
 69//-----------------------------------------------------------------------------
 70
 71bool StreamObject::onAdd()
 72{
 73   if(mStream == NULL)
 74   {
 75      Con::errorf("StreamObject::onAdd - StreamObject can not be instantiated from script.");
 76      return false;
 77   }
 78   return Parent::onAdd();
 79}
 80
 81//-----------------------------------------------------------------------------
 82// Public Methods
 83//-----------------------------------------------------------------------------
 84
 85const char * StreamObject::getStatus()
 86{
 87   if(mStream == NULL)
 88      return "";
 89
 90   switch(mStream->getStatus())
 91   {
 92      case Stream::Ok:
 93         return "Ok";
 94      case Stream::IOError:
 95         return "IOError";
 96      case Stream::EOS:
 97         return "EOS";
 98      case Stream::IllegalCall:
 99         return "IllegalCall";
100      case Stream::Closed:
101         return "Closed";
102      case Stream::UnknownError:
103         return "UnknownError";
104
105      default:
106         return "Invalid";
107   }
108}
109
110//-----------------------------------------------------------------------------
111
112const char * StreamObject::readLine()
113{
114   if(mStream == NULL)
115      return NULL;
116
117   static const U32 bufSize = 256;
118   char *buffer = Con::getReturnBuffer(bufSize);
119   mStream->readLine((U8 *)buffer, bufSize);
120   return buffer;
121}
122
123const char * StreamObject::readString()
124{
125   if(mStream == NULL)
126      return NULL;
127
128   char *buffer = Con::getReturnBuffer(256);
129   mStream->readString(buffer);
130   return buffer;
131}
132
133const char *StreamObject::readLongString(U32 maxStringLen)
134{
135   if(mStream == NULL)
136      return NULL;
137
138   char *buffer = Con::getReturnBuffer(maxStringLen + 1);
139   mStream->readLongString(maxStringLen, buffer);
140   return buffer;
141}
142
143//-----------------------------------------------------------------------------
144// Console Methods
145//-----------------------------------------------------------------------------
146
147DefineEngineMethod( StreamObject, getStatus, const char*, (),,
148   "@brief Gets a printable string form of the stream's status\n\n"
149   
150   "@tsexample\n"
151   "// Create a file stream object for reading\n"
152   "%fsObject = new FileStreamObject();\n\n"
153   "// Open a file for reading\n"
154   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
155   "// Get the status and print it\n"
156   "%status = %fsObject.getStatus();\n"
157   "echo(%status);\n\n"
158   "// Always remember to close a file stream when finished\n"
159   "%fsObject.close();\n"
160   "@endtsexample\n\n"
161
162   "@return String containing status constant, one of the following:\n\n"
163
164   "  OK - Stream is active and no file errors\n\n"
165
166   "  IOError - Something went wrong during read or writing the stream\n\n"
167
168   "  EOS - End of Stream reached (mostly for reads)\n\n"
169
170   "  IllegalCall - An unsupported operation used.  Always w/ accompanied by AssertWarn\n\n"
171
172   "  Closed - Tried to operate on a closed stream (or detached filter)\n\n"
173
174   "  UnknownError - Catch all for an error of some kind\n\n"
175
176   "  Invalid - Entire stream is invalid\n\n")
177{
178   return object->getStatus();
179}
180
181DefineEngineMethod( StreamObject, isEOS, bool, (),,
182   "@brief Tests if the stream has reached the end of the file\n\n"
183   
184   "This is an alternative name for isEOF. Both functions are interchangeable. This simply exists "
185   "for those familiar with some C++ file I/O standards.\n\n"
186
187   "@tsexample\n"
188   "// Create a file stream object for reading\n"
189   "%fsObject = new FileStreamObject();\n\n"
190   "// Open a file for reading\n"
191   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
192   "// Keep reading until we reach the end of the file\n"
193   "while( !%fsObject.isEOS() )\n"
194   "{\n"
195   "   %line = %fsObject.readLine();\n"
196   "   echo(%line);\n"
197   "}\n"
198   "// Made it to the end\n"
199   "echo(\"Finished reading file\");\n\n"
200   "// Always remember to close a file stream when finished\n"
201   "%fsObject.close();\n"
202   "@endtsexample\n\n"
203
204   "@return True if the parser has reached the end of the file, false otherwise\n"
205
206   "@see isEOF()")
207{
208   return object->isEOS();
209}
210
211DefineEngineMethod( StreamObject, isEOF, bool, (),,
212   "@brief Tests if the stream has reached the end of the file\n\n"
213   
214   "This is an alternative name for isEOS. Both functions are interchangeable. This simply exists "
215   "for those familiar with some C++ file I/O standards.\n\n"
216   
217   "@tsexample\n"
218   "// Create a file stream object for reading\n"
219   "%fsObject = new FileStreamObject();\n\n"
220   "// Open a file for reading\n"
221   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
222   "// Keep reading until we reach the end of the file\n"
223   "while( !%fsObject.isEOF() )\n"
224   "{\n"
225   "   %line = %fsObject.readLine();\n"
226   "   echo(%line);\n"
227   "}\n"
228   "// Made it to the end\n"
229   "echo(\"Finished reading file\");\n\n"
230   "// Always remember to close a file stream when finished\n"
231   "%fsObject.close();\n"
232   "@endtsexample\n\n"
233
234   "@return True if the parser has reached the end of the file, false otherwise\n"
235   
236   "@see isEOS()")
237{
238   return object->isEOS();
239}
240
241//-----------------------------------------------------------------------------
242
243DefineEngineMethod( StreamObject, getPosition, S32, (),,
244   "@brief Gets the position in the stream\n\n"
245   
246   "The easiest way to visualize this is to think of a cursor in a text file. If you have moved the cursor by "
247   "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. "
248   "For StreamObject, when you read in the line the position is increased by the number of characters parsed, "
249   "the null terminator, and a newline.\n\n"
250   
251   "@tsexample\n"
252   "// Create a file stream object for reading\n"
253   "%fsObject = new FileStreamObject();\n\n"
254   "// Open a file for reading\n"
255   "// This file contains two lines of text repeated:\n"
256   "// Hello World\n"
257   "// Hello World\n"
258   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
259   "// Read in the first line\n"
260   "%line = %fsObject.readLine();\n\n"
261   "// Get the position of the stream\n"
262   "%position = %fsObject.getPosition();\n\n"
263   "// Print the current position\n"
264   "// Should be 13, 10 for the words, 1 for the space, 1 for the null terminator, and 1 for the newline\n"
265   "echo(%position);\n\n"
266   "// Always remember to close a file stream when finished\n"
267   "%fsObject.close();\n"
268   "@endtsexample\n\n"
269
270   "@return Number of bytes which stream has parsed so far, null terminators and newlines are included\n"
271   
272   "@see setPosition()")
273{
274   return object->getPosition();
275}
276
277DefineEngineMethod( StreamObject, setPosition, bool, (S32 newPosition),,
278   "@brief Gets the position in the stream\n\n"
279   
280   "The easiest way to visualize this is to think of a cursor in a text file. If you have moved the cursor by "
281   "five characters, the current position is 5. If you move ahead 10 more characters, the position is now 15. "
282   "For StreamObject, when you read in the line the position is increased by the number of characters parsed, "
283   "the null terminator, and a newline. Using setPosition allows you to skip to specific points of the file.\n\n"
284   
285   "@tsexample\n"
286   "// Create a file stream object for reading\n"
287   "%fsObject = new FileStreamObject();\n\n"
288   "// Open a file for reading\n"
289   "// This file contains the following two lines:\n"
290   "// 11111111111\n"
291   "// Hello World\n"
292   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
293   "// Skip ahead by 12, which will bypass the first line entirely\n"
294   "%fsObject.setPosition(12);\n\n"
295   "// Read in the next line\n"
296   "%line = %fsObject.readLine();\n\n"
297   "// Print the line just read in, should be \"Hello World\"\n"
298   "echo(%line);\n\n"
299   "// Always remember to close a file stream when finished\n"
300   "%fsObject.close();\n"
301   "@endtsexample\n\n"
302
303   "@return Number of bytes which stream has parsed so far, null terminators and newlines are included\n"
304   
305   "@see getPosition()")
306{
307   return object->setPosition(newPosition);
308}
309
310DefineEngineMethod( StreamObject, getStreamSize, S32, (),,
311   "@brief Gets the size of the stream\n\n"
312   
313   "The size is dependent on the type of stream being used. If it is a file stream, returned value will "
314   "be the size of the file. If it is a memory stream, it will be the size of the allocated buffer.\n\n"
315      
316   "@tsexample\n"
317   "// Create a file stream object for reading\n"
318   "%fsObject = new FileStreamObject();\n\n"
319   "// Open a file for reading\n"
320   "// This file contains the following two lines:\n"
321   "// HelloWorld\n"
322   "// HelloWorld\n"
323   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
324   "// Found out how large the file stream is\n"
325   "// Then print it to the console\n"
326   "// Should be 22\n"
327   "%streamSize = %fsObject.getStreamSize();\n"
328   "echo(%streamSize);\n\n"
329   "// Always remember to close a file stream when finished\n"
330   "%fsObject.close();\n"
331   "@endtsexample\n\n"
332
333   "@return Size of stream, in bytes\n")
334{
335   return object->getStreamSize();
336}
337
338//-----------------------------------------------------------------------------
339DefineEngineMethod( StreamObject, readLine, const char*, (),,
340   "@brief Read a line from the stream.\n\n"
341   
342   "Emphasis on *line*, as in you cannot parse individual characters or chunks of data. "
343   "There is no limitation as to what kind of data you can read.\n\n"
344   
345   "@tsexample\n"
346   "// Create a file stream object for reading\n"
347   "// This file contains the following two lines:\n"
348   "// HelloWorld\n"
349   "// HelloWorld\n"
350   "%fsObject = new FileStreamObject();\n\n"
351   "%fsObject.open(\"./test.txt\", \"read\");\n\n"
352   "// Read in the first line\n"
353   "%line = %fsObject.readLine();\n\n"
354   "// Print the line we just read\n"
355   "echo(%line);\n\n"
356   "// Always remember to close a file stream when finished\n"
357   "%fsObject.close();\n"
358   "@endtsexample\n\n"
359
360   "@return String containing the line of data that was just read\n"
361   
362   "@see writeLine()")
363{
364   const char *str = object->readLine();
365   return str ? str : "";
366}
367
368DefineEngineMethod( StreamObject, writeLine, void, ( const char* line ),,
369   "@brief Write a line to the stream, if it was opened for writing.\n\n"
370   
371   "There is no limit as to what kind of data you can write. Any format and data is allowable, not just text. "
372   "Be careful of what you write, as whitespace, current values, and literals will be preserved.\n\n"
373
374   "@param line The data we are writing out to file."
375   
376   "@tsexample\n"
377   "// Create a file stream\n"
378   "%fsObject = new FileStreamObject();\n\n"
379   "// Open the file for writing\n"
380   "// If it does not exist, it is created. If it does exist, the file is cleared\n"
381   "%fsObject.open(\"./test.txt\", \"write\");\n\n"
382   "// Write a line to the file\n"
383   "%fsObject.writeLine(\"Hello World\");\n\n"
384   "// Write another line to the file\n"
385   "%fsObject.writeLine(\"Documentation Rocks!\");\n\n"
386   "// Always remember to close a file stream when finished\n"
387   "%fsObject.close();\n"
388   "@endtsexample\n\n"
389   
390   "@see readLine()")
391{
392   object->writeLine((U8 *)line);
393}
394
395//-----------------------------------------------------------------------------
396/* readSTString, readString, and readLongString need to be fixed or deprecated */
397DefineEngineMethod(StreamObject, readSTString, String, ( bool caseSensitive ), ( false ),
398   "@brief Read in a string and place it on the string table.\n\n"
399   "@param caseSensitive If false then case will not be taken into account when attempting "
400   "to match the read in string with what is already in the string table.\n"
401   "@return The string that was read from the stream.\n"
402   "@see writeString()"
403   
404   "@note When working with these particular string reading and writing methods, the stream "
405   "begins with the length of the string followed by the string itself, and does not include "
406   "a NULL terminator.")
407{
408   const char *str = object->readSTString(caseSensitive);
409   return str ? str : "";
410}
411
412DefineEngineMethod(StreamObject, readString, String, (),,
413   "@brief Read a string up to a maximum of 256 characters"
414   "@return The string that was read from the stream.\n"
415   "@see writeString()"
416   
417   "@note When working with these particular string reading and writing methods, the stream "
418   "begins with the length of the string followed by the string itself, and does not include "
419   "a NULL terminator.")
420{
421   const char *str = object->readString();
422   return str ? str : "";
423}
424
425DefineEngineMethod(StreamObject, readLongString, String, ( S32 maxLength ),,
426   "@brief Read in a string up to the given maximum number of characters.\n\n"
427   "@param maxLength The maximum number of characters to read in.\n"
428   "@return The string that was read from the stream.\n"
429   "@see writeLongString()"
430   
431   "@note When working with these particular string reading and writing methods, the stream "
432   "begins with the length of the string followed by the string itself, and does not include "
433   "a NULL terminator.")
434{
435   const char *str = object->readLongString(maxLength);
436   return str ? str : "";
437}
438
439DefineEngineMethod(StreamObject, writeLongString, void, ( S32 maxLength, const char* string ),,
440   "@brief Write out a string up to the maximum number of characters.\n\n"
441   "@param maxLength The maximum number of characters that will be written.\n"
442   "@param string The string to write out to the stream.\n"
443   "@see readLongString()"
444   
445   "@note When working with these particular string reading and writing methods, the stream "
446   "begins with the length of the string followed by the string itself, and does not include "
447   "a NULL terminator.")
448{
449   object->writeLongString(maxLength, string);
450}
451
452DefineEngineMethod(StreamObject, writeString, void, ( const char* string, S32 maxLength ), ( 256 ),
453   "@brief Write out a string with a default maximum length of 256 characters.\n\n"
454   "@param string The string to write out to the stream\n"
455   "@param maxLength The maximum string length to write out with a default of 256 characters.  This "
456   "value should not be larger than 256 as it is written to the stream as a single byte.\n"
457   "@see readString()"
458   
459   "@note When working with these particular string reading and writing methods, the stream "
460   "begins with the length of the string followed by the string itself, and does not include "
461   "a NULL terminator.")
462{
463   object->writeString(string, maxLength);
464}
465
466//-----------------------------------------------------------------------------
467
468DefineEngineMethod(StreamObject, copyFrom, bool, (SimObject* other),,
469   "@brief Copy from another StreamObject into this StreamObject\n\n"
470   "@param other The StreamObject to copy from.\n"
471   "@return True if the copy was successful.\n")
472{
473   StreamObject *so = dynamic_cast<StreamObject *>(other);
474   if(so == NULL)
475      return false;
476
477   return object->copyFrom(so);
478}
479