22 #ifndef ASTSHIM_SOURCESINK_H 23 #define ASTSHIM_SOURCESINK_H 112 (*_ostreamPtr) << cstr;
116 return static_cast<bool>(*_ostreamPtr);
151 auto mode = doWrite ? std::ios_base::out : std::ios_base::in;
152 auto fstreamPtr = std::make_shared<std::fstream>(path, mode);
155 os <<
"Failed to open file \"" << path <<
"\" for " << (doWrite ?
"writing" :
"reading");
188 _istringstreamPtr = std::make_shared<std::istringstream>(
data);
189 _ostringstreamPtr = std::make_shared<std::ostringstream>();
204 _istringstreamPtr->clear();
205 _istringstreamPtr->str(getSinkData());
206 _ostringstreamPtr->str(
"");
225 auto ssptr =
reinterpret_cast<Stream *
>(astChannelData);
239 inline void sink(
const char *cstr) {
240 auto ssptr =
reinterpret_cast<Stream *
>(astChannelData);
242 auto isok = ssptr->
sink(cstr);
244 astSetStatus(AST__ATGER);
std::string getPath() const
Get the path to the file, as a string.
void setIsFits(bool isFits)
set isFits
std::string getSourceData() const
Get a copy of the text from the sink/output stream, without changing the stream.
bool hasStdStream()
Return true if this Stream has an input or output std::stream.
AST wrapper classes and functions.
std::string getSinkData() const
Get a copy of the text from the sink/output stream, without changing the stream.
Channel provides input/output of AST objects.
FileStream(std::string const &path, bool doWrite=false)
Construct a FileStream for reading or writing, but not both.
std::string _sourceStr
string containing a local copy of sourced data, so source can return a char * that won't disappear ri...
Stream & operator=(Stream const &)=default
bool sink(char const *cstr)
Sink (write) to the stream.
void sinkToSource()
Move output/sink data to input/source.
File-based source or sink (not both) for channels.
std::shared_ptr< std::istream > _istreamPtr
input stream
bool _isFits
is this a FITS stream?
Stream(std::istream *istreamPtr, std::ostream *ostreamPtr)
Construct a Stream from input and output std::streams.
bool getIsFits() const
get isfits
std::shared_ptr< std::ostream > _ostreamPtr
output stream
char const * source()
Source (read) from the stream.
String-based source and sink for channels.
StringStream(std::string const &data="")
Construct a StringStream.
A stream for ast::Channel.