00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #pragma once
00025 #include <assert.h>
00026
00027 namespace RT
00028 {
00029 #define MAX_BARS_COUNT 1000
00030
00037 template <class T>
00038 class IDataSource
00039 {
00040 public:
00041 virtual ~IDataSource(){}
00042 virtual int init(T*,int) = 0;
00043
00045 virtual T* first() const = 0;
00047 virtual T* last() = 0;
00049 virtual T* next() = 0;
00051 virtual T* previous() = 0;
00053 virtual int count() const = 0;
00060 virtual void set(T* t,int idx) = 0;
00061 virtual void count(int) = 0;
00062
00064 virtual T& operator [] (int indx) = 0;
00065 };
00066
00073 template <class T>
00074 class TDataSource : public IDataSource<T>
00075 {
00076 public:
00077 TDataSource(){};
00078 virtual ~TDataSource(){};
00079
00086 TDataSource(T* begin,int count )
00087 {
00088 init( begin, count);
00089 }
00090
00091 virtual int init(T*,int);
00092
00093 virtual T* first() const;
00094 virtual T* last();
00095 virtual T* next();
00096 virtual T* previous();
00097 virtual void set(T*,int);
00098
00099 virtual int count() const;
00100 virtual void count(int);
00101 virtual T& operator[] (int indx);
00102
00103 private:
00104 int current_indx_;
00105 T* first_;
00106 int count_;
00107 };
00108
00109 template <class T>
00110 int TDataSource<T>::init(T* begin,int count)
00111 {
00112 assert(count <= MAX_BARS_COUNT);
00113 current_indx_ = 0;
00114 first_ = begin;
00115 count_ = count;
00116 return 0;
00117 }
00118
00119 template <class T>
00120 T* TDataSource<T>::first() const
00121 {
00122 return first_;
00123 }
00124
00125 template <class T>
00126 T* TDataSource<T>::last()
00127 {
00128 return &first_[count_-1];
00129 }
00130
00131 template <class T>
00132 T* TDataSource<T>::next()
00133 {
00134 if(current_indx_ == count_-1)
00135 return 0;
00136 else
00137 {
00138 current_indx_++;
00139 return &first_[current_indx_];
00140 }
00141 }
00142
00143 template <class T>
00144 T* TDataSource<T>::previous()
00145 {
00146 if(current_indx_ == 0)
00147 return 0;
00148 else
00149 {
00150 current_indx_--;
00151 return &first_[current_indx_];
00152 }
00153 }
00154
00155 template <class T>
00156 int TDataSource<T>::count() const
00157 {
00158 return count_;
00159 }
00160
00161 template <class T>
00162 void TDataSource<T>::set(T* value,int indx)
00163 {
00164 first_[indx] = *value;
00165 }
00166
00167 template <class T>
00168 void TDataSource<T>::count(int count)
00169 {
00170 assert(count >= 0 && count <= MAX_BARS_COUNT);
00171 if(current_indx_ > count-1)
00172 current_indx_ = count-1;
00173
00174 count_ = count;
00175 }
00176 template <class T>
00177 T& TDataSource<T>::operator[] (int indx)
00178 {
00179 assert(indx >= 0 && indx < MAX_BARS_COUNT);
00180 return first_[indx];
00181 }
00182
00183 typedef double DataType;
00184 typedef TDataSource<DataType> DataSource;
00185
00186 }