00001
00002
00003
00004
00005
00006
00008 #include <algorithm>
00009
00010 #include "MessageService/MsgService.h"
00011 #include "MessageService/MsgFormat.h"
00012 #include "IoModules/IoDataStreamItr.h"
00013
00014 CVSID("$Id: IoDataStreamItr.cxx,v 1.12 2009/02/28 21:46:13 gmieg Exp $");
00015
00016
00017
00018 IoDataStreamItr::IoDataStreamItr():
00019 fSourceName(""),fFileListItr(fFileList.end()),fIsBOF(false) { }
00020
00021
00022
00023 IoDataStreamItr::IoDataStreamItr(const char* sourceName):
00024 fSourceName(sourceName),fFileListItr(fFileList.end()),fIsBOF(false) { }
00025
00026
00027
00028 IoDataStreamItr::~IoDataStreamItr() { }
00029
00030
00031
00032 int IoDataStreamItr::GoToEOF()
00033 {
00034 static const int BIG_NUMBER = 1000000;
00035 while (this->Increment(BIG_NUMBER)) { continue; }
00036 return 1;
00037 }
00038
00039
00040
00041 int IoDataStreamItr::DefineStream(const char* ,
00042 const char* ) { return 0; }
00043
00044
00045
00046 int IoDataStreamItr::Streams(const char* ) { return 0; }
00047
00048
00049
00050 int IoDataStreamItr::Select(const char* ,
00051 const char* ,
00052 bool ) { return 0; }
00053
00054
00055
00056 int IoDataStreamItr::SetSequenceMode(const char* ,
00057 Per::ESequenceMode ) { return 0; }
00058
00059
00060
00061 int IoDataStreamItr::SetPerOwnedDisabled(const char* ,
00062 bool ) { return 0; }
00063
00064
00065
00066 int IoDataStreamItr::SetTestMode(const char* ,
00067 bool ) { return 0; }
00068
00069
00070
00071 int IoDataStreamItr::SetWindow(const char*, double, double) { return 0; }
00072
00073
00074
00075 void IoDataStreamItr::SetPort(unsigned int ) { }
00076
00077
00078
00079 void IoDataStreamItr::SetTimeOut(unsigned int ) { }
00080
00081
00082
00083 int IoDataStreamItr::SetMaxFileRepeat(const char*, int) { return 0; }
00084
00085
00086
00087 int IoDataStreamItr::SetMeanMom(const char*, double) { return 0; }
00088
00089
00090
00091 int IoDataStreamItr::SetPushRandom(const char*, bool) { return 0; }
00092
00093
00094
00095 void IoDataStreamItr::SetRandomSeed(int) {}
00096
00097
00098
00099 void IoDataStreamItr::AddFile(const char* fullfilepathname, int at,
00100 const char* ) {
00101
00102
00103
00104
00105
00106
00107 std::string curf;
00108 if ( !fIsBOF && fFileList.size()>0) curf = (*fFileListItr);
00109
00110
00111 std::string f(fullfilepathname);
00112 if (at<0) {
00113 fFileList.push_back(f);
00114 }
00115 else if (at==0) {
00116 fFileList.push_front(f);
00117 }
00118 else {
00119 std::list<std::string>::iterator itr(fFileList.begin());
00120 std::list<std::string>::iterator itrEnd(fFileList.end());
00121 for (int i=0; (i<at && itr!=itrEnd); ++i, ++itr) continue;
00122 fFileList.insert(itr,f);
00123 }
00124
00125
00126 if ( fIsBOF || fFileList.size()==1) {
00127 fIsBOF = true;
00128 }
00129 else {
00130
00131 fFileListItr = std::find(fFileList.begin(),fFileList.end(),curf);
00132 fIsBOF = false;
00133 }
00134
00135 return;
00136
00137 }
00138
00139
00140
00141 void IoDataStreamItr::RemoveFile(const char* fullfilepathname,
00142 const char* ) {
00143
00144
00145
00146
00147
00148
00149 std::string curf; bool isBegin = false;
00150 if ( !fIsBOF && fFileListItr != fFileList.end() )
00151 curf = *fFileListItr;
00152 else if ( fIsBOF ) isBegin = true;
00153
00154 std::string f(fullfilepathname);
00155
00156 std::list<std::string>::iterator itr(fFileList.end());
00157 while ( !fFileList.empty() && itr != fFileList.begin() ) {
00158 itr--;
00159 if ( f == "*" || f == (*itr) ) {
00160 if ( fFileListItr == itr ) {
00161 MSG("Io",Msg::kWarning)
00162 << "Attempt to remove currently opened file\n" << (*itr)
00163 << " ignored." << endl;
00164 }
00165 else {
00166 fFileList.erase(itr);
00167 }
00168 }
00169 }
00170
00171
00172 if ( isBegin && !fFileList.empty() ) fIsBOF = true;
00173 else {
00174 fFileListItr = std::find(fFileList.begin(),fFileList.end(),curf);
00175 fIsBOF = false;
00176 }
00177
00178 return;
00179
00180 }
00181
00182
00183
00184 const char* IoDataStreamItr::GetCurrentFile(const char* )const{
00185
00186
00187
00188 std::string currentfilename;
00189 if ( !fIsBOF && fFileListItr != fFileList.end() )
00190 currentfilename = *fFileListItr;
00191 return currentfilename.c_str();
00192 }
00193
00194
00195
00196 JobCResult IoDataStreamItr::NextFile(int n, const char* ) {
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 if ( fFileList.empty() || (!fIsBOF && fFileListItr == fFileList.end()) ) {
00207 return JobCResult::kEndOfInputStream;
00208 }
00209
00210 this -> CloseFile();
00211 for ( int i = 0; i < n; i++ ) {
00212 if ( fIsBOF ) {
00213 fFileListItr = fFileList.begin();
00214 fIsBOF = false;
00215 }
00216 else fFileListItr++;
00217
00218
00219 if (fFileListItr == fFileList.end()) {
00220
00221 return JobCResult::kEndOfInputStream;
00222 }
00223 }
00224
00225 return this -> OpenFile();
00226
00227 }
00228
00229
00230
00231 JobCResult IoDataStreamItr::GoToFile(int n, const char* ) {
00232
00233
00234
00235
00236
00237
00238
00239 std::list<std::string>::iterator itr(fFileList.begin());
00240 std::list<std::string>::iterator itrEnd(fFileList.end());
00241 int i = 0;
00242 for ( ; i < n && itr != itrEnd; ++i,++itr) { continue; }
00243
00244 if ( i != n || itr == itrEnd ) {
00245
00246 MSG("Io",Msg::kWarning) <<
00247 "Request to goto file ["<< n <<"]. Only " << i <<" files loaded."<< endl;
00248 return JobCResult::kWarning;
00249 }
00250
00251 this -> CloseFile();
00252 fFileListItr = itr;
00253 fIsBOF = false;
00254
00255 return this -> OpenFile();
00256
00257 }
00258
00259
00260
00261 JobCResult IoDataStreamItr::GoToFile(const char* fullfilepathname,
00262 const char* ) {
00263
00264
00265
00266
00267
00268
00269
00270
00271 std::string f(fullfilepathname);
00272
00273 if (f == "") return this->GoToFile(0);
00274
00275 std::list<std::string>::iterator itr =
00276 std::find(fFileList.begin(), fFileList.end(), f);
00277
00278 if ( itr != fFileList.end() ) {
00279 MSG("Io",Msg::kDebug) << "Go to file '" << f << "'." << endl;
00280 this -> CloseFile();
00281 fFileListItr = itr;
00282 fIsBOF = false;
00283 return this -> OpenFile();
00284 }
00285
00286 MSG("Io",Msg::kWarning) << "File '" << f << "' not found in list." << endl;
00287 return JobCResult::kWarning;
00288
00289 }
00290
00291
00292
00293 JobCResult IoDataStreamItr::PrevFile(int n, const char* ) {
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 if ( fIsBOF ) {
00304 return JobCResult::kBeginOfInputStream;
00305 }
00306
00307 this -> CloseFile();
00308 for ( int i = 0; i < n; i++ ) {
00309 if ( fFileListItr == fFileList.begin() ) fIsBOF = true;
00310 else fFileListItr--;
00311
00312
00313 if ( fIsBOF ) {
00314
00315 return JobCResult::kBeginOfInputStream;
00316 }
00317 }
00318
00319 return this -> OpenFile();
00320
00321 }
00322
00323 std::ostream& IoDataStreamItr::ListFile(std::ostream& os,
00324 const char* ) const {
00325
00326
00327
00328
00329 int indx = 0;
00330 MsgFormat ifmt("%3i");
00331
00332 std::string s;
00333 s = "index file name";
00334 os << s << endl;
00335 int len = s.size();
00336 s = "===== ";
00337 os << s;
00338 for ( int i = s.size()+1; i < len; i++ ) os << "=";
00339 os << endl;
00340
00341 std::list<std::string>::const_iterator itr(fFileList.begin());
00342 std::list<std::string>::const_iterator itrEnd(fFileList.end());
00343 for (; itr!=itrEnd; itr++) {
00344 os << "[" << ifmt(indx++) << "] ";
00345 if (itr == fFileListItr) os << "*";
00346 else os << " ";
00347 os << (*itr) << endl;
00348 }
00349
00350 return os;
00351
00352 }
00353
00354
00355
00356
00357 JobCResult IoDataStreamItr::OpenFile() {
00358
00359
00360
00361
00362
00363 return JobCResult::kWarning;
00364
00365 }
00366
00367
00368
00369 void IoDataStreamItr::CloseFile() {
00370
00371
00372
00373
00374
00375 return;
00376
00377 }
00378
00379
00380
00381