00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include "ShStream.hpp"
00028 #include "ShProgram.hpp"
00029 #include "ShChannelNode.hpp"
00030 #include "ShSyntax.hpp"
00031 #include "ShAlgebra.hpp"
00032 #include "ShContext.hpp"
00033
00034 namespace SH {
00035
00036
00037 ShProgram connect(const ShChannelNodePtr& node, const ShProgram& program)
00038 {
00039 ShProgram nibble = SH_BEGIN_PROGRAM() {
00040 ShVariable out(node->clone(SH_OUTPUT));
00041
00042 ShVariable streamVar(node);
00043 ShStatement stmt(out, SH_OP_FETCH, streamVar);
00044 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00045 } SH_END_PROGRAM;
00046 return connect(nibble, program);
00047 }
00048
00049 ShStream::ShStream(const ShChannelNodePtr& channel)
00050 {
00051 append(channel);
00052 }
00053
00054 ShStream::NodeList::const_iterator ShStream::begin() const
00055 {
00056 return m_nodes.begin();
00057 }
00058
00059 ShStream::NodeList::const_iterator ShStream::end() const
00060 {
00061 return m_nodes.end();
00062 }
00063
00064 ShStream::NodeList::iterator ShStream::begin()
00065 {
00066 return m_nodes.begin();
00067 }
00068
00069 ShStream::NodeList::iterator ShStream::end()
00070 {
00071 return m_nodes.end();
00072 }
00073
00074 int ShStream::size() const
00075 {
00076 return m_nodes.size();
00077 }
00078
00079 void ShStream::append(const ShChannelNodePtr& node)
00080 {
00081 m_nodes.push_back(node);
00082 }
00083
00084 void ShStream::prepend(const ShChannelNodePtr& node)
00085 {
00086 m_nodes.push_front(node);
00087 }
00088
00089 ShStream combine(const ShStream& left, const ShStream& right)
00090 {
00091 ShStream stream = left;
00092 for (ShStream::NodeList::const_iterator I = right.begin(); I != right.end();
00093 ++I) {
00094 stream.append(*I);
00095 }
00096 return stream;
00097 }
00098
00099 ShStream operator&(const ShStream& left, const ShStream& right)
00100 {
00101 return combine(left, right);
00102 }
00103
00104
00105 ShProgram connect(const ShStream& stream, const ShProgram& program)
00106 {
00107 ShProgram p;
00108 p = program;
00109 for (ShStream::NodeList::const_iterator I = stream.begin();
00110 I != stream.end(); ++I) {
00111 p = connect(*I, p);
00112 }
00113 return p;
00114 }
00115
00116 ShProgram operator<<(const ShProgram& program, const ShStream& stream)
00117 {
00118 return connect(stream, program);
00119 }
00120
00121 ShStream& ShStream::operator=(const ShProgram& program)
00122 {
00123 ShEnvironment::backend->execute(program.node(), *this);
00124 return *this;
00125 }
00126
00127 }