C++ main module for gpm Package  1.0
CORE_Out.h
Go to the documentation of this file.
1 #ifndef CORE_Out_H
2 #define CORE_Out_H
3 
4 
5 #include "CORE_Object.h"
6 #include "CORE_Integer.h"
7 #include "CORE_Real.h"
8 
9 
10 
11 
12 
20 
21 class CORE_Out : public CORE_Object { // class
23 
24  // ATTRIBUTES
25 
26  public:
27  static const tFlag NO_OUTPUT;
28  static const tFlag STRING_OUTPUT;
29  static const tFlag SCREEN_OUTPUT;
30  static const tFlag FILE_OUTPUT;
31  static const tFlag ALL_OUTPUT;
32 
33  static const tFlag APPEND;
34  static const tFlag CREATE;
35 
36  static const int ERROR_MSG;
37  static const int WARNING_MSG;
38  static const int DEBUG_MSG;
39 
40 
41 private:
42 
43  tBoolean mIsAborting;
44  tFlag mVerbose;
45 
46  //output
47  tFlag mOutputType;
48  ofstream *mOutputFile;
49  tString mOutputFileName;
50  std::stringstream *mOutputString;
51 
52 
53  // ASSOCIATIONS
54 
55 
56  // METHODS
57 
58 
59 protected:
60  // CONSTRUCTORS
63  CORE_Out();
64 
65 
66 
67 
68  // DESTRUCTORS
72  virtual ~CORE_Out(void);
73 
74 
75 public:
76  // NEW
79  inline static SP::CORE_Out New(){
80  SP::CORE_Out p(new CORE_Out(),CORE_Out::Delete());
81  p->setOutputType(NO_OUTPUT);
82  return p;
83  };
84 
87  inline static SP::CORE_Out New(const tFlag& outputType){
88  SP::CORE_Out p=New();
89  p->setOutputType(outputType);
90  return p;
91  };
92 
93 
94  // SET
95 
96 protected:
99  inline void setOutputType(const tFlag& type) {
100  mOutputType=type;
101  if (mOutputType==STRING_OUTPUT) {
102  if (mOutputString!=null) delete mOutputString;
103  mOutputString=new std::stringstream();
104  }
105  }
106 public:
109  void setOutputFile(const tString& fileName,const tFlag& mode);
112  inline void setOutputFile(const tString& fileName) {
113  setOutputFile(fileName,CREATE);
114  }
115 
118  void setVerbose(const int& f) {
119  mVerbose=f;
120  }
121 
122  // GET
123 
126  inline tString getOutputFileName() const {
127  return mOutputFileName;
128  }
129 
132  inline tString getOutputString() const {
133  if (mOutputString==null) return "";
134  return mOutputString->str();
135  }
136 
139  inline tBoolean isVerbose(const int& type) const {
140  return ((mVerbose & type) / type != 0 );
141  }
142 public:
143 
144  // OTHERS
147  virtual void print(const int& type,const tString& str);
150  inline void print(const tString& str) {
151  print(WARNING_MSG,str);
152  }
153 
156  inline void println(const int& type,const tString& str) {
157  print(type,str+"\n");
158  }
161  inline void println(const tString& str) {
162  print(str+"\n");
163  }
166  inline void println(const int& type) {
167  print(type,"\n");
168  }
171  inline void println() {
172  print("\n");
173  }
174 
177  virtual void print(const int& type,const tLong& str);
180  virtual void print(const int& type,const unsigned tLong& str);
181 
184  virtual void print(const int& type,const long double& str);
185 
186 
189  virtual void print(const int& type,const int& str);
190 
193  virtual void printInt(const int& type,const int& i) {
194  print(type,CORE_Integer::toString(i));
195  };
198  virtual void printInt(const int& i) {
199  print(WARNING_MSG,CORE_Integer::toString(i));
200  };
201 
204  virtual void printReal(const int& type,const tReal& i) {
205  print(type,CORE_Real::toString(i));
206  };
207 
210  virtual void printString(const int& type,const tString& str) {
211  print(type,str);
212  };
215  virtual void printString(const tString& str) {
216  print(WARNING_MSG,str);
217  };
218 
221  virtual void printTime(const int& type);
224  inline void printTime() {
225  printTime(ERROR_MSG);
226  }
229  static tString getTime();
230 
233  virtual void printError(const tString& str);
236  virtual void printWarning(const tString& str);
237 
238 
241  virtual void abort(){mIsAborting=true;};
245  return mIsAborting;
246  };
247 
250  virtual void setAction(const tFlag& type,
251  const vector<tString>& args){
252 
253  int n=args.size();
254  for(int i=0;i<n;i++) {
255  print("args["+CORE_Integer::toString(i)+"]="+args[i]+"\n");
256  }
257  };
258 
259 
260 
265  virtual void ask(const tString& question,tString& ret);
266 
271  virtual void ask(const tString& question,int& ret);
272 
275  friend CORE_Out& operator << (CORE_Out& out,const CORE_Object& obj) {
276  out.print(WARNING_MSG,obj.toString());
277  return out;
278  };
281  friend CORE_Out& operator << (CORE_Out& out,const tString& obj) {
282  out.print(WARNING_MSG,obj);
283  return out;
284  };
285 
288  friend CORE_Out& operator << (CORE_Out& out,const int& obj) {
289  out.print(WARNING_MSG,obj);
290  return out;
291  };
294  friend CORE_Out& operator << (CORE_Out& out,const tLong& obj) {
295  out.print(WARNING_MSG,obj);
296  return out;
297  };
300  friend CORE_Out& operator << (CORE_Out& out,const unsigned tLong& obj) {
301  out.print(WARNING_MSG,obj);
302  return out;
303  };
306  friend CORE_Out& operator << (CORE_Out& out,const long double& obj) {
307  out.print(WARNING_MSG,obj);
308  return out;
309  };
310 
311 
312 };
313 
314 #endif
tBoolean isVerbose(const int &type) const
return true if the type is printed
Definition: CORE_Out.h:139
static const tFlag CREATE
Definition: CORE_Out.h:34
tString getOutputString() const
get the output string
Definition: CORE_Out.h:132
static SP::CORE_Out New(const tFlag &outputType)
create a CORE_out class
Definition: CORE_Out.h:87
tString getOutputFileName() const
get the output file name
Definition: CORE_Out.h:126
void setOutputType(const tFlag &type)
set outputType
Definition: CORE_Out.h:99
virtual void ask(const tString &question, tString &ret)
ask a question
Definition: CORE_Out.cpp:57
void println(const int &type)
print with a new end line
Definition: CORE_Out.h:166
friend CORE_Out & operator<<(CORE_Out &out, const CORE_Object &obj)
print Operators
Definition: CORE_Out.h:275
virtual void print(const int &type, const tString &str)
print
Definition: CORE_Out.cpp:103
CORE_Out()
build a CORE_Out
Definition: CORE_Out.cpp:18
void setOutputFile(const tString &fileName, const tFlag &mode)
set output file
Definition: CORE_Out.cpp:37
static const tFlag SCREEN_OUTPUT
Definition: CORE_Out.h:29
virtual void printString(const int &type, const tString &str)
print a string
Definition: CORE_Out.h:210
virtual void printError(const tString &str)
print error
Definition: CORE_Out.cpp:201
#define tBoolean
Definition: types.h:35
static const int ERROR_MSG
Definition: CORE_Out.h:36
virtual void printWarning(const tString &str)
print warning
Definition: CORE_Out.cpp:213
tBoolean isAborting() const
abort
Definition: CORE_Out.h:244
virtual void printReal(const int &type, const tReal &i)
print a real
Definition: CORE_Out.h:204
static const tFlag ALL_OUTPUT
Definition: CORE_Out.h:31
#define null
Definition: types.h:13
void printTime()
print time
Definition: CORE_Out.h:224
void setOutputFile(const tString &fileName)
set output file
Definition: CORE_Out.h:112
virtual void printInt(const int &type, const int &i)
print an integer
Definition: CORE_Out.h:193
virtual void abort()
abort
Definition: CORE_Out.h:241
static SP::CORE_Out New()
create a CORE_out class
Definition: CORE_Out.h:79
#define tLong
Definition: types.h:29
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:176
virtual void printString(const tString &str)
print a string
Definition: CORE_Out.h:215
virtual void printInt(const int &i)
print an integer
Definition: CORE_Out.h:198
static const tFlag FILE_OUTPUT
Definition: CORE_Out.h:30
static tString getTime()
get time
Definition: CORE_Out.cpp:67
void print(const tString &str)
print
Definition: CORE_Out.h:150
static const int DEBUG_MSG
Definition: CORE_Out.h:38
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
virtual ~CORE_Out(void)
destroy a CORE_Out
Definition: CORE_Out.cpp:28
abstract base class for most classes.
Definition: CORE_Object.h:30
static const tFlag NO_OUTPUT
Definition: CORE_Out.h:27
void println()
print with a new end line
Definition: CORE_Out.h:171
#define tString
Definition: types.h:36
tString toString() const
return the string associated to the real
Definition: CORE_Real.h:89
static const tFlag APPEND
Definition: CORE_Out.h:33
DEFINE_SPTR(CORE_Out)
static const tFlag STRING_OUTPUT
Definition: CORE_Out.h:28
void println(const int &type, const tString &str)
print with a new end line
Definition: CORE_Out.h:156
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
static const int WARNING_MSG
Definition: CORE_Out.h:37
void println(const tString &str)
print with a new end line
Definition: CORE_Out.h:161
virtual void print()
print the class
Definition: CORE_Object.h:221
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:101
#define tReal
Definition: types.h:18
void setVerbose(const int &f)
set the type of message to print
Definition: CORE_Out.h:118
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14
virtual void setAction(const tFlag &type, const vector< tString > &args)
set the action
Definition: CORE_Out.h:250