C++ main module for emicrom Package  1.0
CORE_ReadingFile.h
Go to the documentation of this file.
1 #ifndef CORE_ReadingFile_H
2 #define CORE_ReadingFile_H
3 
4 
5 #include "CORE_File.h"
6 
7 #include "CORE_Exception.h"
8 
9 
10 
15 
16 class CORE_ReadingFile : public CORE_File { // class
18 
19  // ATTRIBUTES
20 
21 public:
22 
23 
24 private:
25 
26  ifstream *mF;
27 
28 
29  //for reading line
30  mutable tUInt mLen;
31  mutable char *mToken;
33 
34  // ASSOCIATIONS
35 
36 
37  // METHODS
38 
39 
40 public:
41  // CONSTRUCTORS
45 
46 
47 
48 
49  // DESTRUCTORS
53  virtual ~CORE_ReadingFile(void);
54 
55 
56 public:
57  // NEW
60  inline static SP::CORE_ReadingFile New(){
61  SP::CORE_ReadingFile p(new CORE_ReadingFile(),CORE_ReadingFile::Delete());
62  p->setThis(p);
63  return p;
64  };
65 
66 
67 
68  // SET
69 
70 
74  virtual tBoolean open(const tString& fileName);
75 
78  virtual void close();
79 
83  virtual tULInt getCurrentIndex() const {
84  if (mF!=null) return mF->tellg();
85  return 0;
86  }
87 
92  virtual tBoolean moveTo(const tULInt& index) {
93  if (index>=getLength()) return false;
94  if (mF!=null) {
95  mF->seekg(index);
96  return true;
97  }
98  return false;
99  }
100 
105  virtual tBoolean translate(const tLInt& dx) {
106  return moveTo(getCurrentIndex()+dx);
107  }
108 
109 
114  inline tBoolean readLine(tString& l) {
115  if (mF==null) return false;
116  mF->getline(mToken,mLen);
117  l=mToken;
118  return (!mF->eof());
119  }
120 
121 
128  virtual tString read(const tULInt& from,const tULInt& to);
129 
135  tString readTo(const tULInt& to) {
136  return read(getCurrentIndex(),to);
137  }
138 
144  virtual tString readChars(const tULInt& nChars) {
145  mCurrentIndex=getCurrentIndex();
146  tString ret=read(mCurrentIndex,mCurrentIndex+nChars);
147  return ret;
148  }
149 
150 
151 
160  virtual tBoolean search(const tString& word,const tULInt& from,const tULInt& to,tULInt& cur);
161 
169  inline tBoolean search(const tString& word,const tULInt& from,tULInt& cur) {
170  if (getLength()<=1) return false;
171  return search(word,from,getLength()-1,cur);
172  }
179  inline tBoolean search(const tString& word,tULInt& cur) {
180  if (getLength()<=1) return false;
181  return search(word,getCurrentIndex(),getLength()-1,cur);
182  }
183 
187  virtual tBoolean isEndOfFile() const {
188  if ((mF==null) || (isClosed())) return true;
189  return mF->eof();
190  }
191 
195  template<class T>
196  istream& operator >> (T& obj) {
197  if ((mF==null) || (isClosed()))
198  throw CORE_Exception("common/core","CORE_ReadingFile::>>",
199  "impossible to write in file because the file is not opened");
200  ASSERT_IN(mF!=null);
201  *mF>>obj;
202  return *mF;
203  };
204 
205 
206 };
207 
208 #endif
char * mToken
Definition: CORE_ReadingFile.h:31
virtual tBoolean search(const tString &word, const tULInt &from, const tULInt &to, tULInt &cur)
search the worf in file between position from and end
Definition: CORE_ReadingFile.cpp:112
virtual tBoolean open(const tString &fileName)
open file fileName for reading.
Definition: CORE_ReadingFile.cpp:25
CORE_ReadingFile()
build a CORE_File
Definition: CORE_ReadingFile.cpp:6
virtual tString read(const tULInt &from, const tULInt &to)
read the file between included position [from,to]
Definition: CORE_ReadingFile.cpp:66
virtual tULInt getCurrentIndex() const
get the current index of the file
Definition: CORE_ReadingFile.h:83
const tBoolean & isClosed() const
return true if the file is closed @ return true if the file is closed
Definition: CORE_File.h:134
tBoolean readLine(tString &l)
read the line into l
Definition: CORE_ReadingFile.h:114
this class describes a file
Definition: CORE_File.h:15
ifstream * mF
Definition: CORE_ReadingFile.h:26
#define tBoolean
Definition: types.h:139
virtual tBoolean moveTo(const tULInt &index)
move the current index position of the file to index
Definition: CORE_ReadingFile.h:92
virtual tBoolean translate(const tLInt &dx)
translate the current index position of the file
Definition: CORE_ReadingFile.h:105
#define tLInt
Definition: types.h:42
SP_OBJECT(CORE_ReadingFile)
#define null
Definition: types.h:144
this class describes a file open for reading
Definition: CORE_ReadingFile.h:16
tString readTo(const tULInt &to)
read the file until to index from the current index
Definition: CORE_ReadingFile.h:135
#define tULInt
Definition: types.h:39
tBoolean search(const tString &word, const tULInt &from, tULInt &cur)
search the word in file between from the from index of the file
Definition: CORE_ReadingFile.h:169
virtual ~CORE_ReadingFile(void)
destroy a CORE_File
Definition: CORE_ReadingFile.cpp:14
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
static SP::CORE_ReadingFile New()
create a CORE_out class
Definition: CORE_ReadingFile.h:60
istream & operator>>(T &obj)
reading operator
Definition: CORE_ReadingFile.h:196
DEFINE_SPTR(CORE_ReadingFile)
#define tUInt
Definition: types.h:33
virtual void close()
close the file
Definition: CORE_ReadingFile.cpp:57
tUInt mLen
Definition: CORE_ReadingFile.h:30
#define tString
Definition: types.h:135
tULInt mCurrentIndex
Definition: CORE_ReadingFile.h:32
virtual tString readChars(const tULInt &nChars)
read the n-chars files
Definition: CORE_ReadingFile.h:144
virtual tBoolean isEndOfFile() const
test if the cursor is at the end of file
Definition: CORE_ReadingFile.h:187
tBoolean search(const tString &word, tULInt &cur)
search the word in file from the current index
Definition: CORE_ReadingFile.h:179
const tULInt & getLength() const
get the length of the file
Definition: CORE_File.h:91
#define ASSERT_IN(a)
Definition: types.h:196
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141