ShStreamImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHSTREAMLISTIMPL_HPP
00021 #define SHSTREAMLISTIMPL_HPP
00022 
00023 #include "ShStream.hpp"
00024 #include "ShChannel.hpp"
00025 
00026 namespace SH {
00027 
00028 template<typename T>
00029 ShStream::ShStream(const ShChannel<T>& channel)
00030 {
00031   m_nodes.push_back(channel.node());
00032 }
00033 
00034 template<typename T>
00035 void ShStream::append(const ShChannel<T>& channel)
00036 {
00037   m_nodes.push_back(channel.node());
00038 }
00039 
00040 template<typename T>
00041 void ShStream::prepend(const ShChannel<T>& channel)
00042 {
00043   m_nodes.push_front(channel.node());
00044 }
00045 
00046 // Ways to form a combined stream
00047 template<typename T1, typename T2>
00048 ShStream combine(const ShChannel<T1>& left, const ShChannel<T2>& right)
00049 {
00050   ShStream stream(left);
00051   stream.append(right);
00052   return stream;
00053 }
00054 
00055 template<typename T2>
00056 ShStream combine(const ShStream& left, const ShChannel<T2>& right)
00057 {
00058   ShStream stream = left;
00059   stream.append(right);
00060   return stream;
00061 }
00062 
00063 template<typename T1>
00064 ShStream combine(const ShChannel<T1>& left, const ShStream& right)
00065 {
00066   ShStream stream = right;
00067   stream.prepend(left);
00068   return stream;
00069 }
00070 
00071 // Aliases for combine
00072 template<typename T1, typename T2>
00073 ShStream operator&(const ShChannel<T1>& left, const ShChannel<T2>& right)
00074 {
00075   return combine(left, right);
00076 }
00077 
00078 template<typename T2>
00079 ShStream operator&(const ShStream& left, const ShChannel<T2>& right)
00080 {
00081   return combine(left, right);
00082 }
00083 
00084 template<typename T1>
00085 ShStream operator&(const ShChannel<T1>& left, const ShStream& right)
00086 {
00087   return combine(left, right);
00088 }
00089 
00090 }
00091 #endif

Generated on Thu Feb 16 14:51:38 2006 for Sh by  doxygen 1.4.6