00001 #ifndef __SOURCETRANSFORM_H__
00002 #define __SOURCETRANSFORM_H__
00003
00004
00005
00006 #include "Source.h"
00007 #include "Registry.h"
00008 #include "libRefCount.h"
00009
00010 #undef DEBUG
00011 #define DEBUG 0
00012 #include "libDebug.h"
00013
00014 typedef RegistryOf<Parameter> RegistryOfInitialSteps;
00015
00016 template<class DATA, int DIMENSIONALITY, class PRECISION, class SOURCE>
00017 class SourceTransformOf: public SourceOf<DATA, DIMENSIONALITY, PRECISION>
00018 {
00019 protected:
00020 SOURCE* m_psource;
00021 mutable PointOf<DIMENSIONALITY, PRECISION> m_ptSize;
00022
00023 protected:
00024 SourceTransformOf() :
00025 SourceOf<DATA, DIMENSIONALITY, PRECISION> ()
00026 {
00027 m_psource = NULL;
00028 }
00029
00030 SourceTransformOf(const SourceTransformOf<DATA, DIMENSIONALITY, PRECISION,
00031 SOURCE>&src) :
00032 SourceOf<DATA, DIMENSIONALITY, PRECISION> (src)
00033 {
00034 m_psource = src.m_psource;
00035 ClaimPointer(m_psource);
00036 }
00037
00038 virtual ~SourceTransformOf() __attribute__((always_inline))
00039 {
00040 ReleasePointer(m_psource);
00041 }
00042
00043 public:
00044
00045 SOURCE* PSource()
00046 {
00047 return m_psource;
00048 }
00049
00050 const SOURCE* PSource() const
00051 {
00052 return m_psource;
00053 }
00054
00055 void SetSource(SOURCE* psource)
00056 {
00057 ChangePointer(m_psource, psource);
00058 }
00059
00060 void WipeSource()
00061 {
00062 m_psource = NULL;
00063 }
00064
00065 virtual String Describe() const
00066 {
00067 return (_LINE + "SourceTransformOf(" + DIMENSIONALITY + "D)" + LINE_
00068 + this->DescribeCommon());
00069 }
00070
00071 virtual String DescribeCommon() const
00072 {
00073 return _INDENT + (_LINE + "size: " + this->Size().Describe() + LINE_
00074 + this->m_psource->Describe());
00075 }
00076
00077 virtual void RegisterParameters(RegistryOfParameters& reg)=0;
00078
00079 virtual void RegisterDataAsParameters(RegistryOfParameters& reg)
00080 {
00081 m_psource->RegisterDataAsParameters(reg);
00082 }
00083
00084 const PointOf<DIMENSIONALITY, PRECISION>& Size() const
00085 {
00086 return m_ptSize;
00087 }
00088
00089 virtual PointOf<DIMENSIONALITY, PRECISION> Bound(const PointOf<
00090 DIMENSIONALITY, PRECISION>& pt) const
00091 {
00092 return pt.Bound(PointOf<DIMENSIONALITY, PRECISION> (PRECISION(0)),
00093 this->Size());
00094 }
00095
00096 virtual void PrepareForAccessAction() const
00097 {
00098 this->m_ptSize = this->PSource()->Size();
00099 }
00100
00101 virtual void PrepareForAccess() const
00102 {
00103
00104 m_psource->PrepareForAccess();
00105
00106
00107 this->PrepareForAccessAction();
00108 }
00109
00110 virtual void SerializeSelf(Stream& st) const=0;
00111
00112 virtual void DeserializeSelf(Stream& st)=0;
00113
00114 void Serialize(Stream& st) const
00115 {
00116 SerializeSelf(st);
00117 ::SerializePointer(st, this->m_psource);
00118 }
00119
00120 void Deserialize(Stream &st)
00121 {
00122 DeserializeSelf(st);
00123 ::DeserializePointer(st, this->m_psource);
00124 }
00125
00126 };
00127
00128 template<class DATA, class PRECISION, class SUBSOURCE>
00129 inline void Get(const SourceTransformOf<DATA, 3, PRECISION, SUBSOURCE>& src, DATA& dataOut, const PRECISION& nX, const PRECISION& nY)
00130 {
00131 src.VirtualGet(dataOut, nX, nY);
00132 }
00133
00134 template<class DATA, class PRECISION, class SUBSOURCE>
00135 inline void Set(SourceTransformOf<DATA, 3, PRECISION, SUBSOURCE>& src, const PRECISION& nX, const PRECISION& nY, const DATA& data)
00136 {
00137 src.VirtualSet(nX, nY, data);
00138 }
00139
00140 template<class DATA, class PRECISION, class SUBSOURCE>
00141 inline void Get(const SourceTransformOf<DATA, 3, PRECISION, SUBSOURCE>& src, DATA& dataOut, const PRECISION& nX, const PRECISION& nY, const PRECISION& nZ)
00142 {
00143 src.VirtualGet(dataOut, nX, nY, nZ);
00144 }
00145
00146 template<class DATA, class PRECISION, class SUBSOURCE>
00147 inline void Set(SourceTransformOf<DATA, 3, PRECISION, SUBSOURCE>& src, const PRECISION& nX, const PRECISION& nY, const PRECISION& nZ, const DATA& data)
00148 {
00149 src.VirtualSet(nX, nY, nZ, data);
00150 }
00151
00152
00153
00154
00155
00156 #define COMMA ,
00157
00158 #define MAKE_TYPECHANGE_ASSISTANT( \
00159 _name,_class,_data,_dims,_precision,_code,... \
00160 ) \
00161 template <class SOURCE> \
00162 inline _class<_data,_dims,_precision,SOURCE> * \
00163 _name(__VA_ARGS__ SOURCE* psrcIn) \
00164 { \
00165 typedef _class<_data,_dims,_precision,SOURCE> SRC_OUT; \
00166 \
00167 SRC_OUT *psrcOut=new SRC_OUT; \
00168 psrcOut->SetSource(psrcIn); \
00169 _code; \
00170 HandoffPointer(psrcOut); \
00171 return psrcOut; \
00172 }
00173
00174 #define MAKE_ASSISTANT(_name,_class,_code,...) \
00175 MAKE_TYPECHANGE_ASSISTANT( \
00176 _name, \
00177 _class, \
00178 TypeOfData(SOURCE), \
00179 TypeOfDimensionality(SOURCE), \
00180 TypeOfPrecision(SOURCE), \
00181 _code, \
00182 ##__VA_ARGS__ \
00183 );
00184
00185 #endif // __SOURCETRANSFORM_H__