[GEM-cvs] SF.net SVN: pd-gem:[2567] trunk/Gem/src/Base
Brought to you by:
zmoelnig
From: <zmo...@us...> - 2008-08-19 16:51:50
|
Revision: 2567 http://pd-gem.svn.sourceforge.net/pd-gem/?rev=2567&view=rev Author: zmoelnig Date: 2008-08-19 16:51:57 +0000 (Tue, 19 Aug 2008) Log Message: ----------- constified a bit Modified Paths: -------------- trunk/Gem/src/Base/CPPExtern.cpp trunk/Gem/src/Base/CPPExtern.h trunk/Gem/src/Base/GemPixUtil.cpp trunk/Gem/src/Base/GemPixUtil.h trunk/Gem/src/Base/GemState.h trunk/Gem/src/Base/GemVector.cpp trunk/Gem/src/Base/GemVector.h trunk/Gem/src/Base/GemVersion.cpp trunk/Gem/src/Base/GemVersion.h Modified: trunk/Gem/src/Base/CPPExtern.cpp =================================================================== --- trunk/Gem/src/Base/CPPExtern.cpp 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/CPPExtern.cpp 2008-08-19 16:51:57 UTC (rev 2567) @@ -65,7 +65,7 @@ ///////////////////////////////////////////////////////// CPPExtern :: ~CPPExtern() { } -void CPPExtern :: post(const char*fmt,...) +void CPPExtern :: post(const char*fmt,...) const { char buf[MAXPDSTRING]; va_list ap; @@ -78,7 +78,7 @@ ::post("%s", buf); } } -void CPPExtern :: verbose(const int level, const char*fmt,...) +void CPPExtern :: verbose(const int level, const char*fmt,...) const { char buf[MAXPDSTRING]; va_list ap; @@ -101,7 +101,7 @@ #endif } -void CPPExtern :: error(const char*fmt,...) +void CPPExtern :: error(const char*fmt,...) const { char buf[MAXPDSTRING]; va_list ap; Modified: trunk/Gem/src/Base/CPPExtern.h =================================================================== --- trunk/Gem/src/Base/CPPExtern.h 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/CPPExtern.h 2008-08-19 16:51:57 UTC (rev 2567) @@ -151,9 +151,9 @@ public: // these call pd's print-functions, and eventually prepend the object's name - void post(const char*format, ...); - void verbose(const int level, const char*format, ...); - void error(const char*format, ...); /* internally uses pd_error() */ + void post(const char*format, ...) const; + void verbose(const int level, const char*format, ...) const; + void error(const char*format, ...) const; /* internally uses pd_error() */ private: static bool checkGemVersion(int major, int minor); Modified: trunk/Gem/src/Base/GemPixUtil.cpp =================================================================== --- trunk/Gem/src/Base/GemPixUtil.cpp 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemPixUtil.cpp 2008-08-19 16:51:57 UTC (rev 2567) @@ -174,7 +174,8 @@ } -GEM_EXTERN void imageStruct::copy2ImageStruct(imageStruct *to){ +GEM_EXTERN void imageStruct::copy2ImageStruct(imageStruct *to) const +{ if (!to || !this || !this->data) { error("GEM: Someone sent a bogus pointer to copy2ImageStruct"); if (to) to->data = NULL; @@ -203,7 +204,8 @@ format, type, notowned); } -GEM_EXTERN void imageStruct::copy2Image(imageStruct *to) { +GEM_EXTERN void imageStruct::copy2Image(imageStruct *to) const +{ if (!to || !this || !this->data) { error("GEM: Someone sent a bogus pointer to copy2Image"); @@ -1590,7 +1592,8 @@ } -GEM_EXTERN void imageStruct::getRGB(int X, int Y, unsigned char*r, unsigned char*g, unsigned char*b) { +GEM_EXTERN void imageStruct::getRGB(int X, int Y, unsigned char*r, unsigned char*g, unsigned char*b) const +{ unsigned char red=0, green=0, blue=0; int position = (X+(upsidedown?(ysize-Y):Y)*xsize); unsigned char*pixels=data+position*csize; @@ -1648,7 +1651,8 @@ if(g)*g=green; if(b)*b=blue; } -GEM_EXTERN void imageStruct::getGrey(int X, int Y, unsigned char*g) { +GEM_EXTERN void imageStruct::getGrey(int X, int Y, unsigned char*g) const +{ unsigned char grey=0; int position = (X+(upsidedown?(ysize-Y):Y)*xsize); unsigned char*pixels=data+position*csize; @@ -1681,7 +1685,8 @@ } if(g)*g=grey; } -GEM_EXTERN void imageStruct::getYUV(int X, int Y, unsigned char*y, unsigned char*u, unsigned char*v) { +GEM_EXTERN void imageStruct::getYUV(int X, int Y, unsigned char*y, unsigned char*u, unsigned char*v) const +{ unsigned char luma=0, chromaU=128, chromaV=128; int position = (X+(upsidedown?(ysize-Y):Y)*xsize); unsigned char*pixels=data+position*csize; Modified: trunk/Gem/src/Base/GemPixUtil.h =================================================================== --- trunk/Gem/src/Base/GemPixUtil.h 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemPixUtil.h 2008-08-19 16:51:57 UTC (rev 2567) @@ -125,7 +125,7 @@ * you should use chRed instead of 0 (because it might not be 0) */ // heck, why are X&Y swapped ?? (JMZ) - inline unsigned char GetPixel(int Y, int X, int C) + inline unsigned char GetPixel(int Y, int X, int C) const { return(data[Y * xsize * csize + X * csize + C]); } ////////// @@ -140,9 +140,9 @@ ///////// // gets the color of a pixel - void getRGB(int X, int Y, unsigned char*r, unsigned char*g, unsigned char*b); - void getGrey(int X, int Y, unsigned char*g); - void getYUV(int X, int Y, unsigned char*y, unsigned char*u, unsigned char*v); + void getRGB(int X, int Y, unsigned char*r, unsigned char*g, unsigned char*b) const; + void getGrey(int X, int Y, unsigned char*g) const; + void getYUV(int X, int Y, unsigned char*y, unsigned char*u, unsigned char*v) const; /* following will set the whole image-data to either black or white * the size of the image-data is NOT xsize*ysize*csize but datasize @@ -168,8 +168,8 @@ * but often it is enough to just copy the meta-data (without pixel-data) * into a new imageStruct */ - void copy2Image(imageStruct *to); - void copy2ImageStruct(imageStruct *to); // copy the imageStruct (but not the actual data) + void copy2Image(imageStruct *to) const; + void copy2ImageStruct(imageStruct *to) const; // copy the imageStruct (but not the actual data) /* this is a sort of better copy2Image, * which only copies the imageStruct-data if it is needed */ Modified: trunk/Gem/src/Base/GemState.h =================================================================== --- trunk/Gem/src/Base/GemState.h 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemState.h 2008-08-19 16:51:57 UTC (rev 2567) @@ -130,13 +130,13 @@ // Constructor GemState(); - float texCoordX(int num) { + float texCoordX(int num) const { if (texture && numTexCoords > num) return texCoords[num].s; else return 0.; } - float texCoordY(int num) { + float texCoordY(int num) const { if (texture && numTexCoords > num) return texCoords[num].t; else return 0.; Modified: trunk/Gem/src/Base/GemVector.cpp =================================================================== --- trunk/Gem/src/Base/GemVector.cpp 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemVector.cpp 2008-08-19 16:51:57 UTC (rev 2567) @@ -30,21 +30,21 @@ CVector3::CVector3(float X, float Y, float Z) : x(X), y(Y), z(Z) {} // Here we overload the + operator so we can add vectors together -CVector3 CVector3::operator+(CVector3 vVector) +CVector3 CVector3::operator+(CVector3 vVector) const { // Return the added vectors result. return CVector3(vVector.x + x, vVector.y + y, vVector.z + z); } // Here we overload the - operator so we can subtract vectors -CVector3 CVector3::operator-(CVector3 vVector) +CVector3 CVector3::operator-(CVector3 vVector) const { // Return the subtracted vectors result return CVector3(x - vVector.x, y - vVector.y, z - vVector.z); } // Here we overload the - operator so we can negate a vector -CVector3 CVector3::operator-() +CVector3 CVector3::operator-() const { // Return the subtracted vectors result return CVector3(-x, -y, -z); @@ -52,7 +52,7 @@ // Here we overload the * operator so we can multiply by scalars -CVector3 CVector3::operator*(float num) +CVector3 CVector3::operator*(float num) const { // Return the scaled vector return CVector3(x * num, y * num, z * num); @@ -60,13 +60,13 @@ // Here we overload the * operator so we can dot-multiply // note: i chose dot-multiplication because this can be done consistently for vectors of any length // but i don't know whether this is "the right way" to do -float CVector3::operator*(CVector3 vVector) +float CVector3::operator*(CVector3 vVector) const { // Return the scaled vector return (x*vVector.x+y*vVector.y+z*vVector.z); } // cross-multiplication -CVector3 CVector3::cross(CVector3 vVector) +CVector3 CVector3::cross(CVector3 vVector) const { CVector3 vCross; // The vector to hold the cross product vCross.x = ((y * vVector.z) - (z * vVector.y)); // Get the X value @@ -78,7 +78,7 @@ // Here we overload the / operator so we can divide by a scalar -CVector3 CVector3::operator/(float num) +CVector3 CVector3::operator/(float num) const { // Return the scale vector return CVector3(x / num, y / num, z / num); @@ -87,19 +87,19 @@ // here we calculate the absolute-value of the vector -float CVector3::abs() +float CVector3::abs() const { return sqrt(x*x+y*y+z*z); } // here we calculate the square of the absolute-value of the vector -float CVector3::abs2() +float CVector3::abs2() const { return (x*x+y*y+z*z); } // here we normalize the vector -CVector3 CVector3::normalize() +CVector3 CVector3::normalize() const { CVector3 vNormal; float InvMagnitude = 1.f / abs(); // Get the magnitude @@ -112,7 +112,8 @@ } // compares to vectores and resturns true is they are equal (within a certain threshold) // An epsilon that works fairly well is 0.000001. -bool CVector3::equals(CVector3 vVector, float epsilon){ +bool CVector3::equals(CVector3 vVector, float epsilon) const +{ return (fabsf(x - vVector.x) < epsilon && fabsf(y - vVector.y) < epsilon && fabsf(z - vVector.z) < epsilon); Modified: trunk/Gem/src/Base/GemVector.h =================================================================== --- trunk/Gem/src/Base/GemVector.h 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemVector.h 2008-08-19 16:51:57 UTC (rev 2567) @@ -38,38 +38,38 @@ CVector3(float X, float Y, float Z); // Here we overload the + operator so we can add vectors together - CVector3 operator+(CVector3 vVector); + CVector3 operator+(CVector3 vVector) const; // Here we overload the - operator so we can subtract vectors - CVector3 operator-(CVector3 vVector); + CVector3 operator-(CVector3 vVector) const; // Here we overload the - operator so we can negate the vector - CVector3 operator-(); + CVector3 operator-() const; // Here we overload the * operator so we can multiply by scalars - CVector3 operator*(float num); + CVector3 operator*(float num) const; // Here we overload the * operator so we can dot-multiply - float operator*(CVector3 vVector); + float operator*(CVector3 vVector) const; // cross-multiplication - CVector3 cross(CVector3 vVector); + CVector3 cross(CVector3 vVector) const; // Here we overload the / operator so we can divide by a scalar - CVector3 operator/(float num); + CVector3 operator/(float num) const; // here we calculate the absolute-value of the vector - float abs(); + float abs() const; // here we calculate the square of the absolute-value of the vector - float abs2(); + float abs2() const; // here we normalize the vector - CVector3 normalize(); + CVector3 normalize() const; // here we compare 2 vectors on approx. equality - bool equals(CVector3 vVector, float epsilon); + bool equals(CVector3 vVector, float epsilon) const; }; Modified: trunk/Gem/src/Base/GemVersion.cpp =================================================================== --- trunk/Gem/src/Base/GemVersion.cpp 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemVersion.cpp 2008-08-19 16:51:57 UTC (rev 2567) @@ -13,7 +13,7 @@ #include "GemVersion.h" -const char* GemVersion :: versionString() { +const char* const GemVersion :: versionString() { return ( "" STRINGIFY(GEM_VERSION_MAJOR) "." STRINGIFY(GEM_VERSION_MINOR) "." STRINGIFY(GEM_VERSION_BUGFIX) \ " " STRINGIFY(GEM_VERSION_CODENAME) ); } Modified: trunk/Gem/src/Base/GemVersion.h =================================================================== --- trunk/Gem/src/Base/GemVersion.h 2008-07-30 17:53:54 UTC (rev 2566) +++ trunk/Gem/src/Base/GemVersion.h 2008-08-19 16:51:57 UTC (rev 2567) @@ -10,7 +10,7 @@ class GEM_EXTERN GemVersion { public: - const static char* versionString(void); + const static char* const versionString(void); static bool versionCheck(int major, int minor); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |