#ifndef __YORICK_HELPERS_HPP #define __YORICK_HELPERS_HPP #include "config.hpp" #include #include namespace CosmoTool { class ProgressiveDoubleOutputImpl { public: virtual ~ProgressiveDoubleOutputImpl(); virtual void addDouble(double d) = 0; }; template class ProgressiveInputImpl { public: virtual ~ProgressiveInputImpl() {} virtual T read() = 0; virtual void seek(uint32_t *pos) = 0; }; template class ProgressiveOutputImpl { public: virtual ~ProgressiveOutputImpl() {} virtual void put(T a) = 0; }; class ProgressiveDoubleOutput { private: bool initialized; int *ref; ProgressiveDoubleOutputImpl *impl; friend ProgressiveDoubleOutput saveDoubleArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank); void decRef(); public: ProgressiveDoubleOutput(); ProgressiveDoubleOutput(ProgressiveDoubleOutputImpl *i); ProgressiveDoubleOutput(const ProgressiveDoubleOutput& o); ~ProgressiveDoubleOutput(); virtual void addDouble(double a); const ProgressiveDoubleOutput& operator=(const ProgressiveDoubleOutput& b); }; template class ProgressiveInput { private: int *ref; ProgressiveInputImpl *impl; void decRef() { if (ref == 0) return; (*ref)--; if (*ref == 0) { delete ref; delete impl; } impl = 0; ref = 0; } public: static ProgressiveInput loadArrayProgressive(const char *fname, uint32_t *&dimList, uint32_t& rank); ProgressiveInput() { impl = 0; ref = 0; } ProgressiveInput(ProgressiveInputImpl *i) { impl = i; ref = new int; *ref = 1; } ProgressiveInput(const ProgressiveInput& o) { ref = o.ref; impl = o.impl; (*ref)++; } ~ProgressiveInput() { decRef(); } T read() { return impl->read(); } void seek(uint32_t *pos) { impl->seek(pos); } const ProgressiveInput& operator=(const ProgressiveInput& b) { decRef(); ref = b.ref; impl = b.impl; if (ref != 0) (*ref)++; return *this; } }; template class ProgressiveOutput { private: int *ref; ProgressiveOutputImpl *impl; void decRef() { if (ref == 0) return; (*ref)--; if (*ref == 0) { delete ref; delete impl; } impl = 0; ref = 0; } public: static ProgressiveOutput saveArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank); ProgressiveOutput() { impl = 0; ref = 0; } ProgressiveOutput(ProgressiveOutputImpl *i) { impl = i; ref = new int; *ref = 1; } ProgressiveOutput(const ProgressiveOutput& o) { ref = o.ref; impl = o.impl; (*ref)++; } ~ProgressiveOutput() { decRef(); } void put(T a) { impl->put(a); } const ProgressiveOutput& operator=(const ProgressiveOutput& b) { decRef(); ref = b.ref; impl = b.impl; if (ref != 0) (*ref)++; return *this; } }; template void saveArray(const char *fname, T *array, uint32_t *dimList, uint32_t rank); template void loadArray(const char *fname, T*& array, uint32_t *& dimList, uint32_t& rank) throw (NoSuchFileException); ProgressiveDoubleOutput saveDoubleArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank); }; #endif