//To get the UINT8_MAX etc macros in C++: #define __STDC_LIMIT_MACROS #include class StopException { public: std::string reason; inline StopException(const std::string& _reason) : reason(_reason) { } }; #define occam_stop(pos, format, args...) \ do { \ EXTERNAL_CALLN (fprintf, stderr, "Program stopped at %s: " format "\n", pos, ##args); \ SetErr (); \ throw StopException(""); \ } while (0) #define NO_CIFCCSP #include "tock_support.h" #include #include #include #include #include #include #include #include #include inline blitz::Array string_to_array(char* c) { const size_t n = strlen(c) + 1; return blitz::Array((unsigned char*)c,blitz::shape(n),blitz::neverDeleteData); } class StreamWriter : public csp::CSProcess { private: std::ostream& out; csp::Chanin in; protected: virtual void run() { try { uint8_t c; while (true) { in >> c; out << c; } out.flush(); } catch (csp::PoisonException& e) { in.poison(); } } public: inline StreamWriter(std::ostream& _out,const csp::Chanin& _in) : out(_out),in(_in) { } }; //For tieing together chained tuples: template inline boost::tuple tie10(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, T9& t9, T10 t10) { return boost::tuple (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); } class tockAny : public boost::any { public: inline tockAny() {} inline tockAny(const tockAny& t) : boost::any(*(boost::any*)&t) { } template inline tockAny(T t) : boost::any(t) {} template inline operator T () const { return boost::any_cast(*this); } }; template < typename T, unsigned dims > class tockArray : public blitz::Array { public: inline tockArray(const tockArray& _array) : blitz::Array(*(blitz::Array*)&_array) {} inline tockArray(const tockAny& _any) : blitz::Array(*(blitz::Array*)& (tockArray)_any) {} template inline tockArray(const tockArray& _diffTypeArray) : blitz::Array( (T*) (_diffTypeArray.dataFirst()), (_diffTypeArray.shape() * (int)sizeof(U)) / (int)sizeof(T),blitz::neverDeleteData) {} template inline tockArray(const tockArray& _diffDimArray) : blitz::Array( (T*) (_diffDimArray.dataFirst()),blitz::shape(_diffDimArray.size()),blitz::neverDeleteData) {} template inline tockArray(U* u) : blitz::Array( (T*) u, sizeof(U) / sizeof(T),blitz::neverDeleteData) {} inline tockArray(T t) : blitz::Array(1) {(*this)(0) = t;} template inline tockArray(U u) : blitz::Array(u) {} template inline tockArray(U u,V v) : blitz::Array(u,v) {} template inline tockArray(U u,V v,W w) : blitz::Array(u,v,w) {} template inline tockArray(U u,V v,W w,X x) : blitz::Array(u,v,w,x) {} template inline tockArray(U u,V v,W w,X x,Y y) : blitz::Array(u,v,w,x,y) {} template inline tockArray(U u,V v,W w,X x,Y y,Z z) : blitz::Array(u,v,w,x,y,z) {} template inline tockArray(U u,V v,W w,X x,Y y,Z z,Z0 z0) : blitz::Array(u,v,w,x,y,z,z0) {} template inline tockArray(U u,V v,W w,X x,Y y,Z z,Z0 z0,Z1 z1) : blitz::Array(u,v,w,x,y,z,z0,z1) {} template inline tockArray(U u,V v,W w,X x,Y y,Z z,Z0 z0,Z1 z1,Z2 z2) : blitz::Array(u,v,w,x,y,z,z0,z1,z2) {} template inline tockArray(U u,V v,W w,X x,Y y,Z z,Z0 z0,Z1 z1,Z2 z2,Z3 z3) : blitz::Array(u,v,w,x,y,z,z0,z1,z2,z3) {} inline tockArray() {} inline tockArray& operator=(const tockArray& rhs) { resize(rhs.shape()); *((blitz::Array*)this) = *((blitz::Array*)&rhs); return *this; } inline tockArray& operator=(const tockAny& any) { return (*this = (tockArray)any); } inline tockArray& operator=(const T& t) { this->resize(blitz::shape(1)); (*this)(0) = t; return *this; } template operator U* () { return (U*)(void*)(this->dataFirst()); } template operator const U* const () { return (const U*)(const void*)(this->dataFirst()); } };