C++ main module for emicrom Package  1.0
CORE_WritingFile.h
Go to the documentation of this file.
1 #ifndef CORE_WritingFile_H
2 #define CORE_WritingFile_H
3 
4 
5 #include "CORE_File.h"
6 
7 
8 #include "CORE_Exception.h"
9 
16 
17 class CORE_WritingFile : public CORE_File { // class
19 
20  // ATTRIBUTES
21 
22 
23 private:
24 
25 
26  ofstream *mF;
27 
28 
29 
30  // ASSOCIATIONS
31 
32 
33  // METHODS
34 
35 
36 public:
37  // CONSTRUCTORS
41 
42 
43 
44 
45  // DESTRUCTORS
49  virtual ~CORE_WritingFile(void);
50 
51 
52 public:
53  // NEW
56  inline static SP::CORE_WritingFile New(){
57  SP::CORE_WritingFile p(new CORE_WritingFile(),CORE_WritingFile::Delete());
58  p->setThis(p);
59  return p;
60  };
61 
62 
63 
64  // SET
65 
66 
67 
68 
73  virtual tBoolean open(const tString& fileName);
74 
79  tBoolean append(const tString& fileName);
80 
81 
84  virtual void close();
85 
89  virtual tULInt getCurrentIndex() const {
90  if (mF!=null) return mF->tellp();
91  return 0;
92  }
93 
98  virtual tBoolean moveTo(const tULInt& index) {
99  if (index>=getLength()) return false;
100  if (mF!=null) {
101  mF->seekp(index);
102  return true;
103  }
104  return false;
105  }
106 
111  virtual tBoolean translate(const tLInt& dx) {
112  return moveTo(getCurrentIndex()+dx);
113  }
114 
115 
118  inline ofstream& getStream() {
119  if ((mF==null) || (isClosed()))
120  throw CORE_Exception("common/core","CORE_WritingFile::getStream()",
121  "impossible to write in file because the file is not opened");
122  return *mF;
123  }
127  virtual tBoolean isEndOfFile() const {
128  if ((mF==null) || (isClosed())) return true;
129  return mF->eof();
130  }
134  template<class T>
135  ostream& operator << (const T& obj) {
136  if ((mF==null) || (isClosed()))
137  throw CORE_Exception("common/core","CORE_WritingFile::<<",
138  "impossible to write in file because the file is not opened");
139 
140  *mF<<obj;
141  setLength(mF->tellp());
142  return *mF;
143  };
144 
145 
146 };
147 
148 #endif
virtual tBoolean moveTo(const tULInt &index)
move the current index position of the file to index
Definition: CORE_WritingFile.h:98
ofstream & getStream()
get the stream
Definition: CORE_WritingFile.h:118
virtual tBoolean translate(const tLInt &dx)
translate the current index position of the file
Definition: CORE_WritingFile.h:111
virtual ~CORE_WritingFile(void)
destroy a CORE_File
Definition: CORE_WritingFile.cpp:10
virtual void close()
close the file
Definition: CORE_WritingFile.cpp:81
void setLength(const tULInt &l)
set the length of the file
Definition: CORE_File.h:98
virtual tBoolean open(const tString &fileName)
open file fileName for writing
Definition: CORE_WritingFile.cpp:20
const tBoolean & isClosed() const
return true if the file is closed @ return true if the file is closed
Definition: CORE_File.h:134
this class describes a file
Definition: CORE_File.h:15
#define tBoolean
Definition: types.h:139
#define tLInt
Definition: types.h:42
CORE_WritingFile()
build a CORE_File
Definition: CORE_WritingFile.cpp:5
#define null
Definition: types.h:144
ostream & operator<<(const T &obj)
writing operator
Definition: CORE_WritingFile.h:135
DEFINE_SPTR(CORE_WritingFile)
#define tULInt
Definition: types.h:39
virtual tBoolean isEndOfFile() const
test if the cursor is at the end of file
Definition: CORE_WritingFile.h:127
ofstream * mF
Definition: CORE_WritingFile.h:26
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
#define tString
Definition: types.h:135
static SP::CORE_WritingFile New()
create a CORE_out class
Definition: CORE_WritingFile.h:56
virtual tULInt getCurrentIndex() const
get the current index of the file
Definition: CORE_WritingFile.h:89
this class describes a writing file
Definition: CORE_WritingFile.h:17
tBoolean append(const tString &fileName)
open file fileName for appending
Definition: CORE_WritingFile.cpp:44
SP_OBJECT(CORE_WritingFile)
const tULInt & getLength() const
get the length of the file
Definition: CORE_File.h:91
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141