www.pudn.com > terra-0_7.zip > Map.h
#ifndef MAP_INCLUDED // -*- C++ -*- #define MAP_INCLUDED #include#include #include "Geom.h" class Map { public: int width; int height; int depth; // in bits real min, max; real operator()(int i, int j) { return eval(i,j); } real operator()(real i, real j) { return eval((int)i,(int)j); } real eval(real i, real j) { return eval((int)i,(int)j); } virtual real eval(int i, int j) = 0; virtual void rawRead(istream&) = 0; virtual void textRead(istream&) = 0; virtual void *getBlock() { return NULL; } virtual void findLimits(); }; extern Map *readPGM(istream&); template class DirectMap : public Map { T *data; protected: inline T& ref(int i,int j) { #ifdef SAFETY assert(i>=0); assert(j>=0); assert(i ByteMap; typedef DirectMap ShortMap; typedef DirectMap WordMap; typedef DirectMap RealMap; template DirectMap ::DirectMap(int w, int h) { width = w; height = h; depth = sizeof(T) << 3; data = (T *)calloc(w*h, sizeof(T)); } template void DirectMap ::rawRead(istream& in) { char *loc = (char *)data; int target = width*height*sizeof(T); while( target>0 ) { in.read(loc, target); target -= in.gcount(); loc += in.gcount(); } } template void DirectMap ::textRead(istream& in) { for(int j=0;j > val; ref(i,j) = (T)val; } } #endif