#ifndef _INCLUDED_L3_TOOL_H #define _INCLUDED_L3_TOOL_H // Copyright (C) Krzysztof Bosak, 1999-03-18...1999-10-01 // All rights reserved. // kbosak@box43.pl // http://www.kbosak.prv.pl // *Smart Portable Tools* #include #include #include #include #include #include "l3_array.h" #include "l3_str.h" #include "l3_port.h" const double _PI=3.1415926535897932384626433832795; const double _PIx2=_PI*2; const double _PIdiv2=_PI/2; const double _DEG2RAD=_PI/180; const double _RAD2DEG=180/_PI; #ifdef PLATFORM_HAS_FILESYSTEM void OpenFile(ifstream & str, const TextString & fname) { str.open(fname.c_str(), ios::in|ios::nocreate); if(str.fail()) { cerr<<"Error: "< int Pfind_min(const basearray & a) { assert(a.size()>0); const int asm3=a.size()-3; int index=0; int i; for(i=1; i int Pfind_max(const basearray& a) { assert(a.size()>0); const int asm3=a.size()-3; int index=0; int i; for(i=1; i stribuf(source.length()+1); strncpy(&stribuf[0], source.c_str(), static_cast(source.length()+1)); char * str=&stribuf[0]; for(int counter=0; *str!='\0' && counter<=stribuf.size(); counter++) { *str=static_cast(toupper(*str)); str++; } stribuf.back()=0; return TextString(&stribuf[0]); } void PStrupr(char *str) { while(*str!=0) { *str=static_cast(toupper(*str)); str++; } } void PStrlwr(char *str) { while(*str!='\0') { *str=static_cast(tolower(*str)); str++; } } template inline void PSwap(a & i, b & j) { const a k=i; i=j; j=k; } template inline a PMin(const a i, const b j) { if(i inline a PMax(const a i, const b j) { if(i>j) return i; return j; } template inline type PMin(const type i, const type j, const type k) { const type & ret=(i inline type PMax(const type i, const type j, const type k) { const type& ret=(i>j ? i : j); if(ret>k) return ret; return k; } template inline void PSaturate(const a i, b & j, const c k) { assert(i<=k); if(j inline bool PIsBetween(const a i, const b j, const c k) { if(j>=i&& j<=k) return true; if(j>=k&& j<=i) return true; return false; } template class PAverage { type _sum; int _count; public: inline PAverage() : _sum(0), _count(0) { } inline void Reset() { _sum=0; _count=0; } inline type Value() const { if(_count!=0) { return _sum/static_cast(_count); } else { return static_cast(0); } } inline int Count() const { return _count; } inline void Add(const type & value) { _sum+=value; _count++; } }; template class PStatisticalMoments { basearray _data; PAverage _average; public: inline void Reset() { _data.setsize(0); _average.Reset(); } inline type Average() const { return _average.Value(); } inline type Variance() const { if(_average.Count()>1) { const type average=_average.Value(); type variance=0; for(int i=0; i<_data.size(); i++) { const type temp=_data[i]-average; variance+=temp*temp; } variance/=(_average.Count()-1); return variance; } else { return static_cast(0); } } inline int Count() const { return _average.Count(); } inline void Add(const type & value) { _average.Add(value); if(_data.capacity()==_data.size()) { _data.reserve(_data.capacity()<<1); } _data.setsize(_data.size()+1); _data[_data.size()-1]=value; } }; template inline void PCenter(a i, b& j, c& k, d l) { a wide=k-j; a maxwide=l-i; if(wide>maxwide) wide=maxwide; j=(maxwide-wide)/2; k=l-j; } #endif //_INCLUDED_L3_TOOL_H