C++ main module for mmsd 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 
49  ofstream *mOutputFile;
50  std::stringstream *mOutputString;
51 
52  tString mOutputFileName;
53 
54 
55  // ASSOCIATIONS
56 
57 
58  // METHODS
59 
60 
61 protected:
62  // CONSTRUCTORS
65  CORE_Out();
66 
67 
68 
69 
70  // DESTRUCTORS
74  virtual ~CORE_Out(void);
75 
76 
77 public:
78  // NEW
81  inline static SP::CORE_Out New(){
82  SP::CORE_Out p(new CORE_Out(),CORE_Out::Delete());
83  p->setOutputType(NO_OUTPUT);
84  return p;
85  };
86 
89  inline static SP::CORE_Out New(const tFlag& outputType){
90  SP::CORE_Out p=New();
91  p->setOutputType(outputType);
92  return p;
93  };
94 
95 
96  // SET
97 
98 protected:
101  inline void setOutputType(const tFlag& type) {
102  mOutputType=type;
103  if (mOutputType==STRING_OUTPUT) {
104  if (mOutputString!=null) delete mOutputString;
105  mOutputString=new std::stringstream();
106  }
107  }
108 public:
111  void setOutputFile(const tString& fileName,const tFlag& mode);
114  inline void setOutputFile(const tString& fileName) {
115  setOutputFile(fileName,CREATE);
116  }
117 
120  void setVerbose(const int& f) {
121  mVerbose=f;
122  }
123 
124  // GET
125 
128  inline tString getOutputFileName() const {
129  return mOutputFileName;
130  }
131 
134  inline tString getOutputString() const {
135  if (mOutputString==null) return "";
136  return mOutputString->str();
137  }
138 
141  inline tBoolean isVerbose(const int& type) const {
142  return ((mVerbose & type) / type != 0 );
143  }
144 public:
145 
146  // OTHERS
149  virtual void print(const int& type,const tString& str);
152  inline void print(const tString& str) {
153  print(WARNING_MSG,str);
154  }
155 
158  inline void println(const int& type,const tString& str) {
159  print(type,str+"\n");
160  }
163  inline void println(const tString& str) {
164  print(str+"\n");
165  }
168  inline void println(const int& type) {
169  print(type,"\n");
170  }
173  inline void println() {
174  print("\n");
175  }
176 
179  virtual void print(const int& type,const long long int& str);
182  virtual void print(const int& type,const unsigned long long int& str);
185  virtual void print(const int& type,const long int& str);
188  virtual void print(const int& type,const unsigned long int& str);
189 
192  virtual void print(const int& type,const long double& str);
193 
194 
197  virtual void print(const int& type,const int& str);
198 
201  virtual void printInt(const int& type,const int& i) {
202  print(type,CORE_Integer::toString(i));
203  };
206  virtual void printInt(const int& i) {
207  print(WARNING_MSG,CORE_Integer::toString(i));
208  };
209 
212  virtual void printReal(const int& type,const tReal& i) {
213  print(type,CORE_Real::toString(i));
214  };
215 
218  virtual void printString(const int& type,const tString& str) {
219  print(type,str);
220  };
223  virtual void printString(const tString& str) {
224  print(WARNING_MSG,str);
225  };
226 
229  virtual void printTime(const int& type);
232  inline void printTime() {
233  printTime(ERROR_MSG);
234  }
237  static tString getTime();
238 
241  virtual void printError(const tString& str);
244  virtual void printWarning(const tString& str);
245 
246 
249  virtual void abort(){mIsAborting=true;};
253  return mIsAborting;
254  };
255 
258  virtual void setAction(const tFlag& type,
259  const vector<tString>& args){
260 
261  int n=args.size();
262  for(int i=0;i<n;i++) {
263  print("args["+CORE_Integer::toString(i)+"]="+args[i]+"\n");
264  }
265  };
266 
267 
268 
273  virtual void ask(const tString& question,tString& ret);
274 
279  virtual void ask(const tString& question,int& ret);
280 
283  friend CORE_Out& operator << (CORE_Out& out,const CORE_Object& obj) {
284  out.print(WARNING_MSG,obj.toString());
285  return out;
286  };
289  friend CORE_Out& operator << (CORE_Out& out,const tString& obj) {
290  out.print(WARNING_MSG,obj);
291  return out;
292  };
293 
296  friend CORE_Out& operator << (CORE_Out& out,const int& obj) {
297  out.print(WARNING_MSG,obj);
298  return out;
299  };
302  friend CORE_Out& operator << (CORE_Out& out,const long long int & obj) {
303  out.print(WARNING_MSG,obj);
304  return out;
305  };
308  friend CORE_Out& operator << (CORE_Out& out,const unsigned long long int& obj) {
309  out.print(WARNING_MSG,obj);
310  return out;
311  };
314  friend CORE_Out& operator << (CORE_Out& out,const long int & obj) {
315  out.print(WARNING_MSG,obj);
316  return out;
317  };
320  friend CORE_Out& operator << (CORE_Out& out,const unsigned long int& obj) {
321  out.print(WARNING_MSG,obj);
322  return out;
323  };
326  friend CORE_Out& operator << (CORE_Out& out,const long double& obj) {
327  out.print(WARNING_MSG,obj);
328  return out;
329  };
330 
331 
332 };
333 
334 #endif
tBoolean isVerbose(const int &type) const
return true if the type is printed
Definition: CORE_Out.h:141
static const tFlag CREATE
Definition: CORE_Out.h:34
tString getOutputString() const
get the output string
Definition: CORE_Out.h:134
static SP::CORE_Out New(const tFlag &outputType)
create a CORE_out class
Definition: CORE_Out.h:89
tString getOutputFileName() const
get the output file name
Definition: CORE_Out.h:128
void setOutputType(const tFlag &type)
set outputType
Definition: CORE_Out.h:101
virtual void ask(const tString &question, tString &ret)
ask a question
Definition: CORE_Out.cpp:62
void println(const int &type)
print with a new end line
Definition: CORE_Out.h:168
friend CORE_Out & operator<<(CORE_Out &out, const CORE_Object &obj)
print Operators
Definition: CORE_Out.h:283
virtual void print(const int &type, const tString &str)
print
Definition: CORE_Out.cpp:109
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:42
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:218
virtual void printError(const tString &str)
print error
Definition: CORE_Out.cpp:246
#define tBoolean
Definition: types.h:48
static const int ERROR_MSG
Definition: CORE_Out.h:36
virtual void printWarning(const tString &str)
print warning
Definition: CORE_Out.cpp:258
tBoolean isAborting() const
abort
Definition: CORE_Out.h:252
virtual void printReal(const int &type, const tReal &i)
print a real
Definition: CORE_Out.h:212
static const tFlag ALL_OUTPUT
Definition: CORE_Out.h:31
#define null
Definition: types.h:13
void printTime()
print time
Definition: CORE_Out.h:232
void setOutputFile(const tString &fileName)
set output file
Definition: CORE_Out.h:114
virtual void printInt(const int &type, const int &i)
print an integer
Definition: CORE_Out.h:201
virtual void abort()
abort
Definition: CORE_Out.h:249
static SP::CORE_Out New()
create a CORE_out class
Definition: CORE_Out.h:81
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:203
virtual void printString(const tString &str)
print a string
Definition: CORE_Out.h:223
virtual void printInt(const int &i)
print an integer
Definition: CORE_Out.h:206
static const tFlag FILE_OUTPUT
Definition: CORE_Out.h:30
static tString getTime()
get time
Definition: CORE_Out.cpp:72
void print(const tString &str)
print
Definition: CORE_Out.h:152
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:173
#define tString
Definition: types.h:49
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:158
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:163
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:102
#define tReal
Definition: types.h:18
void setVerbose(const int &f)
set the type of message to print
Definition: CORE_Out.h:120
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:258