00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ARIAUTIL_H
00027 #define ARIAUTIL_H
00028
00029 #define _GNU_SOURCE 1
00030 #include <string>
00031
00032 #include <list>
00033 #include <math.h>
00034 #include <stdarg.h>
00035
00036 #if defined(_WIN32) || defined(WIN32)
00037 #include <sys/timeb.h>
00038 #include <sys/stat.h>
00039 #else
00040 #include <sys/types.h>
00041 #include <sys/stat.h>
00042 #include <sys/time.h>
00043 #include <unistd.h>
00044 #endif // ifndef win32
00045
00046 #include <time.h>
00047 #include "ariaTypedefs.h"
00048 #include "ArLog.h"
00049 #include "ArFunctor.h"
00050 #include "ArArgumentParser.h"
00051
00052 #include "ariaOSDef.h"
00053
00054 #ifndef M_PI
00055 #define M_PI 3.1415927
00056 #endif // of M_PI, windows has a function call instead of a define
00057
00059 class ArUtil
00060 {
00061 public:
00063 enum BITS {
00064 BIT0 = 0x1,
00065 BIT1 = 0x2,
00066 BIT2 = 0x4,
00067 BIT3 = 0x8,
00068 BIT4 = 0x10,
00069 BIT5 = 0x20,
00070 BIT6 = 0x40,
00071 BIT7 = 0x80,
00072 BIT8 = 0x100,
00073 BIT9 = 0x200,
00074 BIT10 = 0x400,
00075 BIT11 = 0x800,
00076 BIT12 = 0x1000,
00077 BIT13 = 0x2000,
00078 BIT14 = 0x4000,
00079 BIT15 = 0x8000,
00080 };
00081
00083 AREXPORT static void sleep(unsigned int ms);
00084
00086 AREXPORT static unsigned int getTime(void);
00087
00089
00094 template<class T> static void deleteSet(T begin, T end)
00095 {
00096 for (; begin != end; ++begin)
00097 {
00098 delete (*begin);
00099 }
00100 }
00101
00103
00108 template<class T> static void deleteSetPairs(T begin, T end)
00109 {
00110 for (; begin != end; ++begin)
00111 {
00112 delete (*begin).second;
00113 }
00114 }
00115
00117 static int findMin(int first, int second)
00118 { if (first < second) return first; else return second; }
00120 static int findMax(int first, int second)
00121 { if (first > second) return first; else return second; }
00122
00124 static double findMin(double first, double second)
00125 { if (first < second) return first; else return second; }
00127 static double findMax(double first, double second)
00128 { if (first > second) return first; else return second; }
00129
00131 AREXPORT static long sizeFile(const char *fileName);
00132
00134 AREXPORT static long sizeFile(std::string fileName);
00135
00137 AREXPORT static bool findFile(const char *fileName);
00138
00139
00140
00141
00142
00143
00144
00145
00146
00148 AREXPORT static void appendSlash(char *path, size_t pathLength);
00149
00151 AREXPORT static void fixSlashes(char *path, size_t pathLength);
00152
00154 AREXPORT static void fixSlashesForward(char *path, size_t pathLength);
00155
00157 AREXPORT static void fixSlashesBackward(char *path, size_t pathLength);
00158
00160 AREXPORT static void addDirectories(char *dest, size_t destLength,
00161 const char *baseDir,
00162 const char *insideDir);
00163
00165 AREXPORT static int strcmp(std::string str, std::string str2);
00166
00168 AREXPORT static int strcmp(std::string str, const char *str2);
00169
00171 AREXPORT static int strcmp(const char *str, std::string str2);
00172
00174 AREXPORT static int strcmp(const char *str, const char *str2);
00175
00177 AREXPORT static int strcasecmp(std::string str, std::string str2);
00178
00180 AREXPORT static int strcasecmp(std::string str, const char *str2);
00181
00183 AREXPORT static int strcasecmp(const char *str, std::string str2);
00184
00186 AREXPORT static int strcasecmp(const char *str, const char *str2);
00187
00189 AREXPORT static void escapeSpaces(char *dest, const char *src,
00190 size_t maxLen);
00191
00193 AREXPORT static bool stripQuotes(char *dest, const char *src,size_t destLen);
00194
00196 AREXPORT static void lower(char *dest, const char *src,
00197 size_t maxLen);
00199 AREXPORT static bool isOnlyAlphaNumeric(const char *str);
00200
00202 AREXPORT static bool isStrEmpty(const char *str);
00203
00205 AREXPORT static double atof(const char *nptr);
00206
00208 AREXPORT static const char *convertBool(int val);
00209
00211 AREXPORT static void functorPrintf(ArFunctor1<const char *> *functor,
00212 char *str, ...);
00213
00215 AREXPORT static void writeToFile(const char *str, FILE *file);
00216
00218 AREXPORT static bool getStringFromFile(const char *fileName,
00219 char *str, size_t strLen);
00223 enum REGKEY {
00224 REGKEY_CLASSES_ROOT,
00225 REGKEY_CURRENT_CONFIG,
00226 REGKEY_CURRENT_USER,
00227 REGKEY_LOCAL_MACHINE,
00228 REGKEY_USERS
00229 };
00230
00232 AREXPORT static bool getStringFromRegistry(REGKEY root,
00233 const char *key,
00234 const char *value,
00235 char *str,
00236 int len);
00237
00239 AREXPORT static bool findFirstStringInRegistry(const char* key, const char* value, char* str, int len) {
00240 if(!getStringFromRegistry(REGKEY_CURRENT_USER, key, value, str, len))
00241 return getStringFromRegistry(REGKEY_LOCAL_MACHINE, key, value, str, len);
00242 return true;
00243 }
00244
00245 AREXPORT static const char *COM1;
00246 AREXPORT static const char *COM2;
00247 AREXPORT static const char *COM3;
00248 AREXPORT static const char *COM4;
00249 AREXPORT static const char *TRUESTRING;
00250 AREXPORT static const char *FALSESTRING;
00251
00256 AREXPORT static void putCurrentYearInString(char* s, size_t len);
00261 AREXPORT static void putCurrentMonthInString(char* s, size_t len);
00266 AREXPORT static void putCurrentDayInString(char* s, size_t len);
00271 AREXPORT static void putCurrentHourInString(char* s, size_t len);
00276 AREXPORT static void putCurrentMinuteInString(char* s, size_t len);
00281 AREXPORT static void putCurrentSecondInString(char* s, size_t len);
00282
00298 AREXPORT static bool localtime(const time_t *timep, struct tm *result);
00299
00300
00305 AREXPORT static bool localtime(struct tm *result);
00306 };
00307
00309 class ArMath
00310 {
00311 public:
00312
00314
00320 static double addAngle(double ang1, double ang2)
00321 { return fixAngle(ang1 + ang2); }
00322
00324
00331 static double subAngle(double ang1, double ang2)
00332 { return fixAngle(ang1 - ang2); }
00333
00335
00341 static double fixAngle(double angle)
00342 {
00343 if (angle >= 360)
00344 angle = angle - 360.0 * (double)((int)angle / 360);
00345 if (angle < -360)
00346 angle = angle + 360.0 * (double)((int)angle / -360);
00347 if (angle <= -180)
00348 angle = + 180.0 + (angle + 180.0);
00349 if (angle > 180)
00350 angle = - 180.0 + (angle - 180.0);
00351 return angle;
00352 }
00353
00355
00360 static double degToRad(double deg) { return deg * M_PI / 180.0; }
00361
00363
00368 static double radToDeg(double rad) { return rad * 180.0 / M_PI; }
00369
00371
00376 static double cos(double angle) { return ::cos(ArMath::degToRad(angle)); }
00377
00379
00384 static double sin(double angle) { return ::sin(ArMath::degToRad(angle)); }
00385
00387
00391 static double tan(double angle) { return ::tan(ArMath::degToRad(angle)); }
00392
00394
00399 static double atan2(double y, double x)
00400 { return ArMath::radToDeg(::atan2(y, x)); }
00401
00403 static bool angleBetween(double angle, double startAngle, double endAngle)
00404 {
00405 angle = fixAngle(angle);
00406 startAngle = fixAngle(startAngle);
00407 endAngle = fixAngle(endAngle);
00408 if ((startAngle < endAngle && angle > startAngle && angle < endAngle) ||
00409 (startAngle > endAngle && (angle > startAngle || angle < endAngle)))
00410 return true;
00411 else
00412 return false;
00413 }
00414
00416
00420 static double fabs(double val)
00421 {
00422 if (val < 0.0)
00423 return -val;
00424 else
00425 return val;
00426 }
00427
00429
00434 static int roundInt(double val)
00435 {
00436 val += .49;
00437 if (val > INT_MAX)
00438 return (int) INT_MAX;
00439 else if (val < INT_MIN)
00440 return (int) INT_MIN;
00441 else
00442 return((int) floor(val));
00443 }
00444
00446
00451 static short roundShort(double val)
00452 {
00453 val += .49;
00454 if (val > 32767)
00455 return (short) 32767;
00456 else if (val < -32768)
00457 return (short) -32768;
00458 else
00459 return((short) floor(val));
00460 }
00461
00462
00464 static void pointRotate(double *x, double *y, double th)
00465 {
00466 double cs, sn, xt, yt;
00467 cs = cos(th);
00468 sn = sin(th);
00469 xt = *x;
00470 yt = *y;
00471 *x = cs*xt + sn*yt;
00472 *y = cs*yt - sn*xt;
00473 }
00474
00476 static long random(void)
00477 {
00478 #ifdef WIN32
00479 return(rand());
00480 #else
00481 return(lrand48());
00482 #endif
00483 }
00485
00492 static double distanceBetween(double x1, double y1, double x2, double y2)
00493 { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
00494
00496
00504 static double squaredDistanceBetween(double x1, double y1, double x2, double y2)
00505 { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); }
00506
00508 static double log2(double x)
00509 {
00510 #ifdef WIN32
00511 return log10(x) / 0.3010303;
00512 #else
00513 return log10(x) / 0.3010303;
00514
00515 #endif
00516 }
00517 };
00518
00520
00525 class ArPose
00526 {
00527 public:
00529
00536 ArPose(double x = 0, double y = 0, double th = 0)
00537 { myX = x; myY = y; myTh = th; }
00539 ArPose(const ArPose &pose) :
00540 myX(pose.myX), myY(pose.myY), myTh(pose.myTh) {}
00541
00543 virtual ~ArPose() {}
00545
00552 virtual void setPose(double x, double y, double th = 0)
00553 { setX(x); setY(y); setTh(th); }
00555
00556 virtual void setPose(ArPose position)
00557 {
00558 setX(position.getX());
00559 setY(position.getY());
00560 setTh(position.getTh());
00561 }
00563 void setX(double x) { myX = x; }
00565 void setY(double y) { myY = y; }
00567 void setTh(double th) { myTh = ArMath::fixAngle(th); }
00569 void setThRad(double th) { myTh = ArMath::fixAngle(ArMath::radToDeg(th)); }
00571 double getX(void) const { return myX; }
00573 double getY(void) const { return myY; }
00575 double getTh(void) const { return myTh; }
00577 double getThRad(void) const { return ArMath::degToRad(myTh); }
00579
00589 void getPose(double *x, double *y, double *th = NULL) const
00590 {
00591 if (x != NULL)
00592 *x = myX;
00593 if (y != NULL)
00594 *y = myY;
00595 if (th != NULL)
00596 *th = myTh;
00597 }
00599
00603 virtual double findDistanceTo(ArPose position) const
00604 {
00605 return ArMath::distanceBetween(getX(), getY(),
00606 position.getX(),
00607 position.getY());
00608 }
00609
00611
00618 virtual double squaredFindDistanceTo(ArPose position) const
00619 {
00620 return ArMath::squaredDistanceBetween(getX(), getY(),
00621 position.getX(),
00622 position.getY());
00623 }
00625
00629 virtual double findAngleTo(ArPose position) const
00630 {
00631 return ArMath::radToDeg(atan2(position.getY() - getY(),
00632 position.getX() - getX()));
00633 }
00635 virtual void log(void) const
00636 { ArLog::log(ArLog::Terse, "%.0f %.0f %.1f", myX, myY, myTh); }
00637
00639 virtual ArPose operator+(const ArPose& other)
00640 {
00641 return ArPose( myX + other.getX(), myY + other.getY(), ArMath::fixAngle(myTh + other.getTh()) );
00642 }
00643
00645 virtual ArPose operator-(const ArPose& other)
00646 {
00647 return ArPose( myX - other.getX(), myY - other.getY(), ArMath::fixAngle(myTh - other.getTh()) );
00648 }
00649
00650 protected:
00651 double myX;
00652 double myY;
00653 double myTh;
00654 };
00655
00656
00658
00673 class ArTime
00674 {
00675 public:
00677 ArTime() { setToNow(); }
00679 ~ArTime() {}
00680
00682 long mSecSince(ArTime since) const
00683 {
00684 long timeSince, timeThis;
00685
00686 timeSince = since.getSec() * 1000 + since.getMSec();
00687 timeThis = mySec * 1000 + myMSec;
00688 return timeSince - timeThis;
00689 }
00691 long secSince(ArTime since) const
00692 {
00693 return mSecSince(since)/1000;
00694 }
00696 long mSecTo(void) const
00697 {
00698 ArTime now;
00699 now.setToNow();
00700 return -mSecSince(now);
00701 }
00703 long secTo(void) const
00704 {
00705 return mSecTo()/1000;
00706 }
00708 long mSecSince(void) const
00709 {
00710 ArTime now;
00711 now.setToNow();
00712 return mSecSince(now);
00713 }
00715 long secSince(void) const
00716 {
00717 return mSecSince()/1000;
00718 }
00720 bool isBefore(ArTime testTime) const
00721 {
00722 if (mSecSince(testTime) < 0)
00723 return true;
00724 else
00725 return false;
00726 }
00728 bool isAt(ArTime testTime) const
00729 {
00730 if (mSecSince(testTime) == 0)
00731 return true;
00732 else
00733 return false;
00734 }
00736 bool isAfter(ArTime testTime) const
00737 {
00738 if (mSecSince(testTime) > 0)
00739 return true;
00740 else
00741 return false;
00742 }
00744 void setToNow(void)
00745 {
00746 #ifdef WIN32
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 long timeNow;
00757 timeNow = timeGetTime();
00758 mySec = timeNow / 1000;
00759 myMSec = timeNow % 1000;
00760 #else // if not win32
00761 struct timeval timeNow;
00762
00763 if (gettimeofday(&timeNow, NULL) == 0)
00764 {
00765 mySec = timeNow.tv_sec;
00766 myMSec = timeNow.tv_usec / 1000;
00767 }
00768 else
00769 ArLog::log(ArLog::Terse, "ArTime::setToNow: invalid return from gettimeofday.\n");
00770 #endif //linux
00771 }
00773 void addMSec(long ms)
00774 {
00775 unsigned long timeThis;
00776 timeThis = mySec * 1000 + myMSec;
00777 if (ms < 0 && (unsigned)abs(ms) > timeThis)
00778 {
00779 ArLog::log(ArLog::Terse, "ArTime::addMsec: tried to subtract too many milliseconds, would result in a negative time.");
00780 mySec = 0;
00781 myMSec = 0;
00782 }
00783 else
00784 {
00785 timeThis += ms;
00786 mySec = timeThis / 1000;
00787 myMSec = timeThis % 1000;
00788 }
00789 }
00791 void setSec(time_t sec) { mySec = sec; }
00793 void setMSec(time_t msec) { myMSec = msec; }
00795 time_t getSec(void) const { return mySec; }
00797 time_t getMSec(void) const { return myMSec; }
00799 void log(void) const
00800 { ArLog::log(ArLog::Terse, "Time: %ld.%ld", getSec(), getMSec()); }
00801 protected:
00802 time_t mySec;
00803 time_t myMSec;
00804
00805 };
00806
00808
00811 class ArPoseWithTime : public ArPose
00812 {
00813 public:
00814 ArPoseWithTime(double x = 0, double y = 0, double th = 0,
00815 ArTime thisTime = ArTime()) : ArPose(x, y, th)
00816 { myTime = thisTime; }
00817 virtual ~ArPoseWithTime() {}
00818 void setTime(ArTime newTime) { myTime = newTime; }
00819 void setTimeToNow(void) { myTime.setToNow(); }
00820 ArTime getTime(void) const { return myTime; }
00821 protected:
00822 ArTime myTime;
00823 };
00824
00826
00833 class ArSectors
00834 {
00835 public:
00837 ArSectors(int numSectors = 8)
00838 {
00839 mySectorSize = 360/numSectors;
00840 mySectors = new int[numSectors];
00841 myNumSectors = numSectors;
00842 clear();
00843 }
00845 virtual ~ArSectors() { delete mySectors; }
00847 void clear(void)
00848 {
00849 int i;
00850 for (i = 0; i < myNumSectors; i++)
00851 mySectors[i] = false;
00852 }
00854 void update(double angle)
00855 {
00856 int angleInt;
00857 angleInt = ArMath::roundInt(ArMath::fixAngle(angle) + 180);
00858 mySectors[angleInt / mySectorSize] = true;
00859 }
00861 bool didAll(void) const
00862 {
00863 int i;
00864 for (i = 0; i < myNumSectors; i++)
00865 if (mySectors[i] == false)
00866 return false;
00867 return true;
00868 }
00869 protected:
00870 int *mySectors;
00871 int myNumSectors;
00872 int mySectorSize;
00873 };
00874
00875
00876
00877
00879
00884 class ArLine
00885 {
00886 public:
00888 ArLine() {}
00890 ArLine(double a, double b, double c) { newParameters(a, b, c); }
00892 ArLine(double x1, double y1, double x2, double y2)
00893 { newParametersFromEndpoints(x1, y1, x2, y2); }
00895 virtual ~ArLine() {}
00897 void newParameters(double a, double b, double c)
00898 { myA = a; myB = b; myC = c; }
00900 void newParametersFromEndpoints(double x1, double y1, double x2, double y2)
00901 { myA = y1 - y2; myB = x2 - x1; myC = (y2 *x1) - (x2 * y1); }
00903 const double getA(void) const { return myA; }
00905 const double getB(void) const { return myB; }
00907 const double getC(void) const { return myC; }
00909
00914 bool intersects(const ArLine *line, ArPose *pose)
00915 {
00916 double x, y;
00917 double n;
00918 n = (line->getB() * getA()) - (line->getA() * getB());
00919
00920 if (fabs(n) < .0000000000001)
00921 {
00922 return false;
00923 }
00924
00925 x = ((line->getC() * getB()) - (line->getB() * getC())) / n;
00926 y = ((getC() * line->getA()) - (getA() * line->getC())) / n;
00927 pose->setPose(x, y);
00928 return true;
00929 }
00931 void makeLinePerp(const ArPose *pose, ArLine *line) const
00932 {
00933 line->newParameters(getB(), -getA(),
00934 (getA() * pose->getY()) - (getB() * pose->getX()));
00935 }
00936 protected:
00937 double myA, myB, myC;
00938 };
00939
00941
00942 class ArLineSegment
00943 {
00944 public:
00945 #ifndef SWIG
00946
00947 ArLineSegment() {}
00951 ArLineSegment(double x1, double y1, double x2, double y2)
00952 { newEndPoints(x1, y1, x2, y2); }
00953 #endif // SWIG
00954
00955 ArLineSegment(ArPose pose1, ArPose pose2)
00956 { newEndPoints(pose1.getX(), pose1.getY(), pose2.getX(), pose2.getY()); }
00957 virtual ~ArLineSegment() {}
00959 void newEndPoints(double x1, double y1, double x2, double y2)
00960 {
00961 myX1 = x1; myY1 = y1; myX2 = x2; myY2 = y2;
00962 myLine.newParametersFromEndpoints(myX1, myY1, myX2, myY2);
00963 }
00965 void newEndPoints(const ArPose& pt1, const ArPose& pt2)
00966 {
00967 newEndPoints(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
00968 }
00970 ArPose getEndPoint1(void) const { return ArPose(myX1, myY1); }
00972 ArPose getEndPoint2(void) const { return ArPose(myX2, myY2); }
00974
00979 bool intersects(const ArLine *line, ArPose *pose)
00980 {
00981
00982 if (myLine.intersects(line, &myIntersection) &&
00983 linePointIsInSegment(&myIntersection))
00984 {
00985 pose->setPose(myIntersection);
00986 return true;
00987 }
00988 else
00989 return false;
00990 }
00991
00993 bool intersects(ArLineSegment *line, ArPose *pose)
00994 {
00995
00996 if (myLine.intersects(line->getLine(), &myIntersection) &&
00997 linePointIsInSegment(&myIntersection) &&
00998 line->linePointIsInSegment(&myIntersection))
00999 {
01000 pose->setPose(myIntersection);
01001 return true;
01002 }
01003 else
01004 return false;
01005 }
01006 #ifndef SWIG
01007
01008
01015 bool getPerpPoint(ArPose pose, ArPose *perpPoint)
01016 {
01017 myLine.makeLinePerp(&pose, &myPerpLine);
01018 return intersects(&myPerpLine, perpPoint);
01019 }
01020 #endif
01021
01026 bool getPerpPoint(const ArPose *pose, ArPose *perpPoint)
01027 {
01028 myLine.makeLinePerp(pose, &myPerpLine);
01029 return intersects(&myPerpLine, perpPoint);
01030 }
01032
01039 double getPerpDist(const ArPose pose)
01040 {
01041 ArPose perpPose;
01042 myLine.makeLinePerp(&pose, &myPerpLine);
01043 if (!intersects(&myPerpLine, &perpPose))
01044 return -1;
01045 return (perpPose.findDistanceTo(pose));
01046 }
01048
01055 double getDistToLine(const ArPose pose)
01056 {
01057 ArPose perpPose;
01058 myLine.makeLinePerp(&pose, &myPerpLine);
01059 if (!intersects(&myPerpLine, &perpPose))
01060 {
01061 return ArUtil::findMin(
01062 ArMath::roundInt(getEndPoint1().findDistanceTo(pose)),
01063 ArMath::roundInt(getEndPoint2().findDistanceTo(pose)));
01064 }
01065 return (perpPose.findDistanceTo(pose));
01066 }
01068 const double getX1(void) const { return myX1; }
01070 const double getY1(void) const { return myY1; }
01072 const double getX2(void) const { return myX2; }
01074 const double getY2(void) const { return myY2; }
01076 const double getA(void) const { return myLine.getA(); }
01078 const double getB(void) const { return myLine.getB(); }
01080 const double getC(void) const { return myLine.getC(); }
01082 const bool linePointIsInSegment(ArPose *pose) const
01083 {
01084 return (((myX1 == myX2) ||
01085 (pose->getX() >= myX1 && pose->getX() <= myX2) ||
01086 (pose->getX() <= myX1 && pose->getX() >= myX2)) &&
01087 ((myY1 == myY2) ||
01088 (pose->getY() >= myY1 && pose->getY() <= myY2) ||
01089 (pose->getY() <= myY1 && pose->getY() >= myY2)));
01090 }
01091 const ArLine *getLine(void) const { return &myLine; }
01092 protected:
01093 double myX1, myY1, myX2, myY2;
01094 ArLine myLine;
01095 ArPose myIntersection;
01096 ArLine myPerpLine;
01097 };
01098
01100 class ArRunningAverage
01101 {
01102 public:
01104 AREXPORT ArRunningAverage(size_t numToAverage);
01106 AREXPORT ~ArRunningAverage();
01108 AREXPORT double getAverage(void) const;
01110 AREXPORT void add(double val);
01112 AREXPORT void clear(void);
01114 AREXPORT size_t getNumToAverage(void) const;
01116 AREXPORT void setNumToAverage(size_t numToAverage);
01117 protected:
01118 size_t myNumToAverage;
01119 double myTotal;
01120 size_t myNum;
01121 std::list<double> myVals;
01122 };
01123
01124
01125
01126 struct ArStrCaseCmpOp
01127 {
01128 public:
01129 bool operator() (const std::string &s1, const std::string &s2) const
01130 {
01131 return strcasecmp(s1.c_str(), s2.c_str()) < 0;
01132 }
01133 };
01134
01135 #if !defined(WIN32) && !defined(SWIG)
01136
01140 class ArDaemonizer
01141 {
01142 public:
01144 AREXPORT ArDaemonizer(int *argc, char **argv);
01146 AREXPORT ~ArDaemonizer();
01148 AREXPORT bool daemonize(void);
01150 AREXPORT bool forceDaemonize(void);
01152 AREXPORT void logOptions(void) const;
01154 bool isDaemonized(void) { return myIsDaemonized; }
01155 protected:
01156 ArArgumentParser myParser;
01157 bool myIsDaemonized;
01158 ArConstFunctorC<ArDaemonizer> myLogOptionsCB;
01159 };
01160 #endif // !win32 && !swig
01161
01162
01163
01165 class ArPriority
01166 {
01167 public:
01168 enum Priority
01169 {
01170 IMPORTANT,
01171 NORMAL,
01172 DETAILED,
01173 TRIVIAL = DETAILED,
01174
01175 LAST_PRIORITY = DETAILED
01176 };
01177
01178 enum {
01179 PRIORITY_COUNT = LAST_PRIORITY + 1
01180 };
01181
01182 AREXPORT static const char * getPriorityName(Priority priority);
01183 protected:
01184 static bool ourStringsInited;
01185 static std::map<Priority, std::string> ourPriorityNames;
01186 static std::string ourUnknownPriorityName;
01187 };
01188
01190
01193 class ArStringInfoHolder
01194 {
01195 public:
01197 ArStringInfoHolder(const char *name, ArTypes::UByte2 maxLength,
01198 ArFunctor2<char *, ArTypes::UByte2> *functor)
01199 { myName = name; myMaxLength = maxLength; myFunctor = functor; }
01201 virtual ~ArStringInfoHolder() {}
01203 const char *getName(void) { return myName.c_str(); }
01205 ArTypes::UByte2 getMaxLength(void) { return myMaxLength; }
01207 ArFunctor2<char *, ArTypes::UByte2> *getFunctor(void) { return myFunctor; }
01208 protected:
01209 std::string myName;
01210 ArTypes::UByte2 myMaxLength;
01211 ArFunctor2<char *, ArTypes::UByte2> *myFunctor;
01212 };
01213
01215 class ArStringInfoHolderFunctions
01216 {
01217 public:
01218 static void intWrapper(char * buffer, ArTypes::UByte2 bufferLen,
01219 ArRetFunctor<int> *functor, const char *format)
01220 { snprintf(buffer, bufferLen - 1, format, functor->invokeR());
01221 buffer[bufferLen-1] = '\0'; }
01222 static void doubleWrapper(char * buffer, ArTypes::UByte2 bufferLen,
01223 ArRetFunctor<double> *functor, const char *format)
01224 { snprintf(buffer, bufferLen - 1, format, functor->invokeR());
01225 buffer[bufferLen-1] = '\0'; }
01226 static void boolWrapper(char * buffer, ArTypes::UByte2 bufferLen,
01227 ArRetFunctor<bool> *functor, const char *format)
01228 { snprintf(buffer, bufferLen - 1, format,
01229 ArUtil::convertBool(functor->invokeR()));
01230 buffer[bufferLen-1] = '\0'; }
01231 static void stringWrapper(char * buffer, ArTypes::UByte2 bufferLen,
01232 ArRetFunctor<const char *> *functor,
01233 const char *format)
01234 { snprintf(buffer, bufferLen - 1, format, functor->invokeR());
01235 buffer[bufferLen-1] = '\0'; }
01236
01237 };
01238
01240 class ArCallbackList
01241 {
01242 public:
01244 AREXPORT ArCallbackList(const char *name = "",
01245 ArLog::LogLevel logLevel = ArLog::Verbose);
01247 AREXPORT virtual ~ArCallbackList();
01249 AREXPORT void addCallback(ArFunctor *functor, int position = 50);
01251 AREXPORT void remCallback(ArFunctor *functor);
01253 AREXPORT void setName(const char *name);
01255 AREXPORT void setLogLevel(ArLog::LogLevel logLevel);
01257 AREXPORT void invoke(void);
01258 protected:
01259 ArMutex myDataMutex;
01260 ArLog::LogLevel myLogLevel;
01261 std::string myName;
01262 std::map<int, ArFunctor *> myList;
01263 };
01264
01265 #endif // ARIAUTIL_H
01266
01267