00001 #ifndef Impala_Core_Trec_ThreadVirtual_h
00002 #define Impala_Core_Trec_ThreadVirtual_h
00003
00004 #include "Core/Trec/Thread.h"
00005 #include "Core/VideoSet/TableShots.h"
00006 #include "Core/Column/Find.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015 namespace Impala
00016 {
00017 namespace Core
00018 {
00019 namespace Trec
00020 {
00021
00022
00023 class ThreadVirtual : public Thread
00024 {
00025 public:
00026
00027 ThreadVirtual(std::string threadName) :
00028 Thread("virtual_" + threadName)
00029 {
00030 }
00031
00032
00033 virtual int
00034 GetShot(int position)
00035 {
00036 if ((position < 0) || (position >= GetLength()))
00037 return -1;
00038
00039 for (int i=0; i<mThreads.size();i++)
00040 {
00041 if (position < mThreads[i]->GetLength())
00042 return mThreads[i]->GetShot(position);
00043 else
00044 position -= mThreads[i]->GetLength();
00045 }
00046 return -1;
00047 }
00048
00049 virtual int
00050 GetLength()
00051 {
00052 int length = 0;
00053 for (int i=0;i<mThreads.size();i++)
00054 length += mThreads[i]->GetLength();
00055 return length;
00056 }
00057
00058 virtual int
00059 GetShotAt(int shot, int offset)
00060 {
00061 int r = GetShotPosition(shot);
00062 return GetShot(r + offset);
00063 }
00064
00065 virtual int
00066 GetShotPosition(int shot)
00067 {
00068 int pos = 0;
00069 for (int i=0; i<mThreads.size();i++)
00070 {
00071 int r = mThreads[i]->GetShotPosition(shot);
00072 if (r != -1)
00073 return pos + r;
00074 else
00075 pos += mThreads[i]->GetLength();
00076 }
00077 return -1;
00078 }
00079
00080 virtual int
00081 GetType()
00082 {
00083 return VIRTUAL;
00084 }
00085
00086
00087 void
00088 AddThread(Thread *t)
00089 {
00090 if (t && !HasThread(t))
00091 mThreads.push_back(t);
00092 }
00093
00094 void
00095 RemoveThread(Thread *t)
00096 {
00097 std::vector<Thread*>::iterator i;
00098 bool somethingerased = true;
00099 while (somethingerased)
00100 {
00101 somethingerased = false;
00102 for (i = mThreads.begin(); i != mThreads.end(); i++)
00103 {
00104 if ((*i) == t)
00105 {
00106 mThreads.erase(i);
00107 somethingerased = true;
00108 break;
00109 }
00110 }
00111 }
00112 }
00113
00114 bool
00115 HasThread(Thread *t)
00116 {
00117 for (int i=0; i < mThreads.size(); i++)
00118 {
00119 if (mThreads[i] == t)
00120 return true;
00121 }
00122 return false;
00123 }
00124
00125
00126 private:
00127
00128 std::vector<Thread*> mThreads;
00129 ILOG_VAR_DEC;
00130
00131 };
00132
00133 ILOG_VAR_INIT(ThreadVirtual, Core.Trec);
00134
00135 }
00136 }
00137 }
00138
00139 #endif