Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

Thread.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Trec_Thread_h
00002 #define Impala_Core_Trec_Thread_h
00003 
00004 #include <string>
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Trec
00011 {
00012 
00013 
00014 class Thread
00015 {
00016 public:
00017 
00018     Thread(CString name)
00019     {
00020         mName = name;
00021     }
00022 
00023     String
00024     GetName()
00025     {
00026         return mName;
00027     }
00028 
00029     // all functions below return -1 if not applicable
00030 
00031     // Set the origin in "dynamic" threads
00032     virtual void
00033     SetOrigin(int shot)
00034     {
00035     }
00036 
00037     virtual int
00038     GetFirstShot()
00039     {
00040         return GetShot(0);
00041     }
00042 
00043     virtual int
00044     GetShot(int position) = 0;
00045 
00046     virtual int
00047     GetLength() = 0;
00048 
00049     virtual bool
00050     Contains(int shot)
00051     {
00052         return GetShotPosition(shot) != -1;
00053     }
00054 
00055     virtual int
00056     GetNextShot(int shot)
00057     {
00058         return GetShotAt(shot, 1);
00059     }
00060 
00061     virtual int
00062     GetPrevShot(int shot)
00063     {
00064         return GetShotAt(shot, -1);
00065     }
00066 
00067     virtual int
00068     GetShotAt(int shot, int offset) = 0;
00069 
00070     virtual int
00071     GetShotAtWhileSkipping(int shot, int offset, Thread* skipthese)
00072     {
00073         if (offset == 0)
00074             return GetShotAt(shot, offset);
00075 
00076         int pos = GetShotPosition(shot);
00077         if (pos == -1)
00078             return -1;
00079 
00080         int dir = 1;
00081         if (offset < 0)
00082         {
00083             dir = -1;
00084             offset = -offset;
00085         }
00086         int len = GetLength();
00087         while (offset > 0)
00088         {
00089             pos += dir;
00090             if ((pos < 0) || (pos >= len))
00091                 return -1;
00092             int shot = GetShot(pos);
00093             if (!skipthese->Contains(shot))
00094                 offset--;
00095         }
00096         return GetShot(pos);
00097     }
00098 
00099     virtual int
00100     GetShotPosition(int shot) = 0;
00101 
00102     virtual int
00103     GetType()
00104     {
00105         return UNDEFINED;
00106     }
00107 
00108 protected:
00109 
00110     String mName;
00111 
00112 public:
00113     static const int UNDEFINED = 0;
00114     static const int RANK = 1;
00115     static const int SHOTS = 2;
00116     static const int BOOKMARK = 3;
00117     static const int TIME = 4;
00118     static const int VISUAL = 5;
00119     static const int HISTORY = 6;
00120     static const int VIRTUAL = 7;
00121 
00122     ILOG_VAR_DEC;
00123 };
00124 ILOG_VAR_INIT(Thread, Core.Trec);
00125 
00126 
00127 } // namespace Trec
00128 } // namespace Core
00129 } // namespace Impala
00130 
00131 #endif

Generated on Fri Mar 19 09:31:26 2010 for ImpalaSrc by  doxygen 1.5.1