C++ main module for emicrom 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 #include "CORE_String.h"
9 
10 
11 
12 
13 
21 
22 class CORE_Out : public CORE_Object { // class
24 
25  // ATTRIBUTES
26 
27  public:
28  //for printing in string
29  static const tFlag STRING_OUTPUT;
30  //for printing in screen
31  static const tFlag SCREEN_OUTPUT;
32  //for printing in file
33  static const tFlag FILE_OUTPUT;
34 
35  //output file mode : append to file
36  static const tFlag APPEND;
37  //output file mode : create file
38  static const tFlag CREATE;
39 
40  //print only error
41  static const tFlag ERROR_MSG;
42  //print only warning
43  static const tFlag WARNING_MSG;
44  //print only DEBUG
45  static const tFlag DEBUG_MSG;
46  //print only comment
47  static const tFlag COMMENT_MSG;
48 
49  //true to print error or screen
51 
52 private:
53 
55 
56 
58 
59  // mVerbose= (mError+2*(mWarning+2*(mDebug+2*mComment)))
62 
63  //mOutput =(mScreen+2*(mFile+2*String))
66 
67  //file output
70 
73 
74  ofstream *mOutputFile;
75 
76  //string output
77  std::stringstream *mOutputString;
78 
79 
80  // ASSOCIATIONS
81 
82 
83  // METHODS
84 
85 
86 public:
87  // CONSTRUCTORS
90  CORE_Out();
91 
92 
93 
94 
95  // DESTRUCTORS
99  virtual ~CORE_Out(void);
100 
101 
102 public:
103  // NEW
107  inline static SP::CORE_Out New(){
108  SP::CORE_Out p(new CORE_Out(),CORE_Out::Delete());
109  p->setOutput("000");//no outout
110  return p;
111  };
112 
116  inline static SP::CORE_Out New(const tString& outputType){
117  SP::CORE_Out p=New();
118  p->setOutput(outputType);
119  return p;
120  };
128  inline static SP::CORE_Out New(const tFlag& outputType){
129  SP::CORE_Out p=New();
130  p->setOutput(outputType);
131  return p;
132  };
133 
134 
135 private:
138  void release();
139 
140  // SET
141 public:
146  inline static void setPrintedType(const tFlag& type) {
147  mPrintedType=type;
148  }
157  inline void setVerbose(const tFlag& f) {
158  setVerbose(CORE_Integer::toBinString<4>(f));
159  }
160 
175  void setVerbose(const tString& f);
176 
188  inline void setOutput(const tFlag& type) {
189  setOutput(CORE_Integer::toBinString<3>(type));
190  }
205  void setOutput(const tString& type);
214  void setOutputBit(const tUChar& index, const tBoolean& v);
215 
218  void backup();
221  void restore();
222 
225  void reset();
226 
227 private:
228  void createStreams();
229 
230 public:
233  void setOutputFile(const tString& fileName,const tFlag& mode);
236  inline void setOutputFile(const tString& fileName) {
237  setOutputFile(fileName,CREATE);
238  }
239 
242  inline void update() {
243  createStreams();
244  }
245 
246 
247  // GET
252  inline static const tFlag& getPrintedType() {
253  return mPrintedType;
254  }
259  inline tBoolean isVerbose(const tFlag& type) {
260  return ((mVerbose & type ) / type == 1);
261  }
266  inline tBoolean isOutput(const tFlag& type) {
267  return ((mOutput & type ) / type == 1);
268  }
269 
270 
274  inline ofstream& getOutputFile() {
275  return *mOutputFile;
276  };
283  inline const tFlag& getOutput() {
284  return mOutput;
285  };
286 
290  inline tString getOutputFileName() const {
291  return mOutputFileName;
292  }
293 
297  inline tString getOutputString() const {
298  if (mOutputString==null) return "";
299  return mOutputString->str();
300  }
301 
305  inline tString str() const {
306  return getOutputString();
307  }
308 
309 
310 
311 public:
312 
313  // OTHERS
314 
315 
316  public:
320  virtual void printInt(const tInteger& i) {
321  genericPrint(mPrintedType,i);
322  }
323 
327  virtual void printString(const tString& message) {
328  genericPrint(mPrintedType,message);
329  };
330 
335  virtual void print(const tFlag& type,const tString& message) {
336  genericPrint(type,message);
337  }
342  virtual void println(const tFlag& type,const tString& message) {
343  genericPrint(type,message+"\n");
344  }
348  virtual void print(const tString& message) {
349  genericPrint(mPrintedType,message);
350  }
354  virtual void println(const tString& message) {
355  genericPrint(mPrintedType,message+"\n");
356  }
357 
358 
362  virtual void printTime(const tFlag& type) {
363  genericPrint(type,getTime());
364  }
367  inline void printTime() {
368  printTime(mPrintedType);
369  }
370 
374  static tString getTime();
375 
376 
377 
380  virtual void abort(){mIsAborting=true;};
385  return mIsAborting;
386  };
387 
392  virtual void printArgs(const tFlag& type,
393  const vector<tString>& args){
394 
395  tUIndex i,n=args.size();
396  for(i=0;i<n;i++) {
397  print(type,"args["+CORE_Integer::toString(i)+"]="+args[i]+"\n");
398  }
399  };
400 
401 
402 
407  virtual void ask(const tString& question,tString& ret);
408 
413  virtual void ask(const tString& question,tInteger& ret);
414 
415 
416 
417  // templated printed methods
418  // =========================
419 private:
424  template<class T>
425  CORE_Out& templatedPrint(const tFlag& type,const T& str) {
426 
427  if (!isVerbose(type)) return (*this);
428 
429  //prefix depending on type
430  tString prefix="";
431  if (type==WARNING_MSG) {
432  prefix="WARNING:\t";
433  }else if (type==ERROR_MSG) {
434  prefix="ERROR:\t";
435  if (IS_ERROR_MESSAGE_PRINTED_ON_SCREEN) cerr << prefix<<str<<flush;
436  }else if (type==DEBUG_MSG) {
437  prefix="DEBUG:\t";
438  }
439 
440  if (isOutput(SCREEN_OUTPUT) || ((type==ERROR_MSG) && IS_ERROR_MESSAGE_PRINTED_ON_SCREEN ) ) cout << prefix<<str<<flush;
441  if (isOutput(FILE_OUTPUT)) (*mOutputFile) << prefix<<str<<flush;
442  if (isOutput(STRING_OUTPUT)) (*mOutputString) << prefix<<str<<flush;
443 
444  return (*this);
445  }
446 
447 
448 
449  // << operators
450  // =============
451 
458  return out.genericPrint(mPrintedType,obj.toString());
459  };
465  friend CORE_Out& operator << (CORE_Out& out,const tString& obj) {
466  return out.genericPrint(mPrintedType,obj);
467  };
468 
474  friend CORE_Out& operator << (CORE_Out& out,const tBoolean& obj) {
475  return out.genericPrint(mPrintedType,CORE_String::boolean2String(obj));
476  };
477 
483  friend CORE_Out& operator << (CORE_Out& out,const tChar& obj) {
484 
485  return out.genericPrint(mPrintedType,obj);
486  };
492  friend CORE_Out& operator << (CORE_Out& out,const tChar* obj) {
493  return out.genericPrint(mPrintedType,obj);
494  };
500  friend CORE_Out& operator << (CORE_Out& out,const tUChar& obj) {
501  return out.genericPrint(mPrintedType,obj);
502  };
503 
509  friend CORE_Out& operator << (CORE_Out& out,const tSInt& obj) {
510  return out.genericPrint(mPrintedType,obj);
511  };
517  friend CORE_Out& operator << (CORE_Out& out,const tUSInt& obj) {
518  return out.genericPrint(mPrintedType,obj);
519  };
525  friend CORE_Out& operator << (CORE_Out& out,const tInt& obj) {
526  return out.genericPrint(mPrintedType,obj);
527  };
533  friend CORE_Out& operator << (CORE_Out& out,const tUInt& obj) {
534  return out.genericPrint(mPrintedType,obj);
535  };
536 
542  friend CORE_Out& operator << (CORE_Out& out,const tLInt & obj) {
543  return out.genericPrint(mPrintedType,obj);
544  };
550  friend CORE_Out& operator << (CORE_Out& out,const tULInt& obj) {
551  return out.genericPrint(mPrintedType,obj);
552  };
558  friend CORE_Out& operator << (CORE_Out& out,const tLLInt & obj) {
559  return out.genericPrint(mPrintedType,obj);
560  };
566  friend CORE_Out& operator << (CORE_Out& out,const tULLInt& obj) {
567  return out.genericPrint(mPrintedType,obj);
568  };
574  friend CORE_Out& operator << (CORE_Out& out,const tFloat& obj) {
575  return out.genericPrint(mPrintedType,obj);
576  };
582  friend CORE_Out& operator << (CORE_Out& out,const tDouble& obj) {
583  return out.genericPrint(mPrintedType,obj);
584  };
585 
591  friend CORE_Out& operator << (CORE_Out& out,const tLDouble& obj) {
592  return out.genericPrint(mPrintedType,obj);
593  };
599  friend CORE_Out& operator << (CORE_Out& out,const tFComplex& obj) {
600  return out.genericPrint(mPrintedType,obj);
601  };
607  friend CORE_Out& operator << (CORE_Out& out,const tDComplex& obj) {
608  return out.genericPrint(mPrintedType,obj);
609  };
615  friend CORE_Out& operator << (CORE_Out& out,const tLDComplex& obj) {
616  return out.genericPrint(mPrintedType,obj);
617  };
618 
619  // methods to specialized << operator
620  // ==================================
621 
622 public:
628  virtual CORE_Out& genericPrint(const tFlag& type,const CORE_Object& obj) {
629  return templatedPrint(type,obj.toString());
630  };
636  virtual CORE_Out& genericPrint(const tFlag& type,const tString& obj) {
637  return templatedPrint(type,obj);
638  };
639 
645  virtual CORE_Out& genericPrint(const tFlag& type,const tBoolean& obj) {
647  };
648 
654  virtual CORE_Out& genericPrint(const tFlag& type,const tChar& obj) {
655 
656  return templatedPrint(type,obj);
657  };
663  virtual CORE_Out& genericPrint(const tFlag& type,const tChar* obj) {
664  return templatedPrint(type,obj);
665  };
671  virtual CORE_Out& genericPrint(const tFlag& type,const tUChar& obj) {
672  return templatedPrint(type,obj);
673  };
674 
680  virtual CORE_Out& genericPrint(const tFlag& type,const tSInt& obj) {
681  return templatedPrint(type,obj);
682  };
688  virtual CORE_Out& genericPrint(const tFlag& type,const tUSInt& obj) {
689  return templatedPrint(type,obj);
690  };
696  virtual CORE_Out& genericPrint(const tFlag& type,const tInt& obj) {
697  return templatedPrint(type,obj);
698  };
704  virtual CORE_Out& genericPrint(const tFlag& type,const tUInt& obj) {
705  return templatedPrint(type,obj);
706  };
707 
713  virtual CORE_Out& genericPrint(const tFlag& type,const tLInt & obj) {
714  return templatedPrint(type,obj);
715  };
721  virtual CORE_Out& genericPrint(const tFlag& type,const tULInt& obj) {
722  return templatedPrint(type,obj);
723  };
729  virtual CORE_Out& genericPrint(const tFlag& type,const tLLInt & obj) {
730  return templatedPrint(type,obj);
731  };
737  virtual CORE_Out& genericPrint(const tFlag& type,const tULLInt& obj) {
738  return templatedPrint(type,obj);
739  };
745  virtual CORE_Out& genericPrint(const tFlag& type,const tFloat& obj) {
746  return templatedPrint(type,obj);
747  };
753  virtual CORE_Out& genericPrint(const tFlag& type,const tDouble& obj) {
754  return templatedPrint(type,obj);
755  };
756 
762  virtual CORE_Out& genericPrint(const tFlag& type,const tLDouble& obj) {
763  return templatedPrint(type,obj);
764  };
770  virtual CORE_Out& genericPrint(const tFlag& type,const tFComplex& obj) {
771  return templatedPrint(type,obj);
772  };
778  virtual CORE_Out& genericPrint(const tFlag& type,const tDComplex& obj) {
779  return templatedPrint(type,obj);
780  };
786  virtual CORE_Out& genericPrint(const tFlag& type,const tLDComplex& obj) {
787  return templatedPrint(type,obj);
788  };
789 
790 
794  virtual tString toString() const {
795  tString ret="log :\n";
796  ret+="\t file mode:"+CORE_Integer::toString((int)mOutputFileMode)+" APPEND="+CORE_Integer::toString((int)APPEND)+" CREATE="+CORE_Integer::toString((int)CREATE)+"\n";
797  ret+="\t file name:"+mOutputFileName+"\n";
798  ret+="\t verbose:"+CORE_Integer::toString((int)mVerbose)+" FILE="+CORE_Integer::toString((int)FILE_OUTPUT)+" STRING="+CORE_Integer::toString((int)STRING_OUTPUT)+" SCREEN="+CORE_Integer::toString((int)SCREEN_OUTPUT)+"\n";
799  return ret;
800  }
801 };
802 
803 #endif
tFlag mOutput
Definition: CORE_Out.h:64
static const tFlag CREATE
Definition: CORE_Out.h:38
static tBoolean IS_ERROR_MESSAGE_PRINTED_ON_SCREEN
Definition: CORE_Out.h:50
static tString boolean2String(const tBoolean &c)
return the string representation true or false of boolean c
Definition: CORE_String.h:460
static SP::CORE_Out New(const tFlag &outputType)
create a CORE_out class on string,file or/and std outputs
Definition: CORE_Out.h:128
CORE_Out & templatedPrint(const tFlag &type, const T &str)
print the msg value for the type in {ERROR_MSG, WARNING_MSG, DEBUG_MSG , COMMENt_MSG} on th eoutput ...
Definition: CORE_Out.h:425
tFlag mOutputFileMode_back
Definition: CORE_Out.h:71
#define tLDouble
Definition: types.h:54
void release()
de-allocate the memory
Definition: CORE_Out.cpp:51
void setVerbose(const tFlag &f)
set the type of verbose of the int conversion of the binary form CDWE
Definition: CORE_Out.h:157
virtual void ask(const tString &question, tString &ret)
ask a question
Definition: CORE_Out.cpp:174
#define tDouble
Definition: types.h:52
const tFlag & getOutput()
get output type
Definition: CORE_Out.h:283
virtual void println(const tFlag &type, const tString &message)
print the message with an end of line
Definition: CORE_Out.h:342
virtual CORE_Out & genericPrint(const tFlag &type, const tLLInt &obj)
print Operators
Definition: CORE_Out.h:729
friend CORE_Out & operator<<(CORE_Out &out, const CORE_Object &obj)
print Operators
Definition: CORE_Out.h:457
virtual void printString(const tString &message)
print a string
Definition: CORE_Out.h:327
tBoolean isAborting() const
abort
Definition: CORE_Out.h:384
virtual CORE_Out & genericPrint(const tFlag &type, const tString &obj)
print Operators
Definition: CORE_Out.h:636
void update()
update the output
Definition: CORE_Out.h:242
static const tFlag & getPrintedType()
get the default printed type of message to print
Definition: CORE_Out.h:252
#define tFloat
Definition: types.h:50
CORE_Out()
build a CORE_Out
Definition: CORE_Out.cpp:24
void setOutputFile(const tString &fileName, const tFlag &mode)
set output file
Definition: CORE_Out.cpp:167
static const tFlag SCREEN_OUTPUT
Definition: CORE_Out.h:31
static const tFlag DEBUG_MSG
Definition: CORE_Out.h:45
tFlag mVerbose_back
Definition: CORE_Out.h:61
#define tUSInt
Definition: types.h:28
virtual void printTime(const tFlag &type)
print time
Definition: CORE_Out.h:362
virtual CORE_Out & genericPrint(const tFlag &type, const tDComplex &obj)
print Operators
Definition: CORE_Out.h:778
static SP::CORE_Out New(const tString &outputType)
create a CORE_out class on string,file or/and std outputs
Definition: CORE_Out.h:116
#define tFComplex
Definition: types.h:57
#define tBoolean
Definition: types.h:139
virtual void printInt(const tInteger &i)
print an integer
Definition: CORE_Out.h:320
void backup()
backup the output
Definition: CORE_Out.cpp:87
tFlag mVerbose
Definition: CORE_Out.h:60
tBoolean mIsAborting
Definition: CORE_Out.h:54
#define tLInt
Definition: types.h:42
virtual CORE_Out & genericPrint(const tFlag &type, const CORE_Object &obj)
print Operators
Definition: CORE_Out.h:628
tFlag mOutputFileMode
Definition: CORE_Out.h:68
tString getOutputFileName() const
get the output file name
Definition: CORE_Out.h:290
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
static const tFlag WARNING_MSG
Definition: CORE_Out.h:43
static void setPrintedType(const tFlag &type)
set the type of message to print
Definition: CORE_Out.h:146
#define null
Definition: types.h:144
#define tDComplex
Definition: types.h:60
void printTime()
print time
Definition: CORE_Out.h:367
void setOutputFile(const tString &fileName)
set output file
Definition: CORE_Out.h:236
void createStreams()
Definition: CORE_Out.cpp:138
virtual void abort()
abort the process
Definition: CORE_Out.h:380
static SP::CORE_Out New()
create a CORE_out class : no output by default
Definition: CORE_Out.h:107
virtual CORE_Out & genericPrint(const tFlag &type, const tUChar &obj)
print Operators
Definition: CORE_Out.h:671
tBoolean isVerbose(const tFlag &type)
return true if the printed type is type
Definition: CORE_Out.h:259
virtual CORE_Out & genericPrint(const tFlag &type, const tULInt &obj)
print Operators
Definition: CORE_Out.h:721
#define tULInt
Definition: types.h:39
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:203
static tFlag mPrintedType
Definition: CORE_Out.h:57
virtual CORE_Out & genericPrint(const tFlag &type, const tSInt &obj)
print Operators
Definition: CORE_Out.h:680
static const tFlag COMMENT_MSG
Definition: CORE_Out.h:47
void setOutput(const tFlag &type)
set outputType of the int conversion of the binary form : SFO
Definition: CORE_Out.h:188
tString str() const
get the output string
Definition: CORE_Out.h:305
tString getOutputString() const
get the output string
Definition: CORE_Out.h:297
#define tLLInt
Definition: types.h:47
virtual CORE_Out & genericPrint(const tFlag &type, const tUSInt &obj)
print Operators
Definition: CORE_Out.h:688
static const tFlag FILE_OUTPUT
Definition: CORE_Out.h:33
static tString getTime()
get time
Definition: CORE_Out.cpp:184
void reset()
reset the output
Definition: CORE_Out.cpp:65
#define tSInt
Definition: types.h:30
virtual CORE_Out & genericPrint(const tFlag &type, const tLInt &obj)
print Operators
Definition: CORE_Out.h:713
virtual CORE_Out & genericPrint(const tFlag &type, const tLDComplex &obj)
print Operators
Definition: CORE_Out.h:786
virtual CORE_Out & genericPrint(const tFlag &type, const tChar &obj)
print Operators
Definition: CORE_Out.h:654
virtual CORE_Out & genericPrint(const tFlag &type, const tLDouble &obj)
print Operators
Definition: CORE_Out.h:762
virtual void print(const tString &message)
print a string
Definition: CORE_Out.h:348
#define tUChar
Definition: types.h:20
#define tUInt
Definition: types.h:33
tBoolean isOutput(const tFlag &type)
return true if the output is selected
Definition: CORE_Out.h:266
virtual CORE_Out & genericPrint(const tFlag &type, const tFComplex &obj)
print Operators
Definition: CORE_Out.h:770
tString mOutputFileName_back
Definition: CORE_Out.h:72
virtual CORE_Out & genericPrint(const tFlag &type, const tULLInt &obj)
print Operators
Definition: CORE_Out.h:737
virtual CORE_Out & genericPrint(const tFlag &type, const tDouble &obj)
print Operators
Definition: CORE_Out.h:753
#define tUIndex
Definition: types.h:126
void setOutputBit(const tUChar &index, const tBoolean &v)
set only the bit value at index to v of the output type
Definition: CORE_Out.cpp:133
virtual CORE_Out & genericPrint(const tFlag &type, const tFloat &obj)
print Operators
Definition: CORE_Out.h:745
virtual void printArgs(const tFlag &type, const vector< tString > &args)
print args
Definition: CORE_Out.h:392
virtual ~CORE_Out(void)
destroy a CORE_Out
Definition: CORE_Out.cpp:45
abstract base class for most classes.
Definition: CORE_Object.h:53
#define tString
Definition: types.h:135
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:326
static const tFlag APPEND
Definition: CORE_Out.h:36
#define tChar
Definition: types.h:23
DEFINE_SPTR(CORE_Out)
ofstream * mOutputFile
Definition: CORE_Out.h:74
static const tFlag STRING_OUTPUT
Definition: CORE_Out.h:29
static CORE_Out & out()
get the output
Definition: CORE_Object.h:198
static const tFlag ERROR_MSG
Definition: CORE_Out.h:41
std::stringstream * mOutputString
Definition: CORE_Out.h:77
this class describes the output by default write on standart output
Definition: CORE_Out.h:22
virtual CORE_Out & genericPrint(const tFlag &type, const tBoolean &obj)
print Operators
Definition: CORE_Out.h:645
virtual CORE_Out & genericPrint(const tFlag &type, const tChar *obj)
print Operators
Definition: CORE_Out.h:663
#define tLDComplex
Definition: types.h:63
tFlag mOutput_back
Definition: CORE_Out.h:65
tString mOutputFileName
Definition: CORE_Out.h:69
#define tULLInt
Definition: types.h:45
virtual void println(const tString &message)
print a string and an end of line
Definition: CORE_Out.h:354
virtual CORE_Out & genericPrint(const tFlag &type, const tInt &obj)
print Operators
Definition: CORE_Out.h:696
#define tInt
Definition: types.h:35
void restore()
restore the ouput from the last backup
Definition: CORE_Out.cpp:93
ofstream & getOutputFile()
get output
Definition: CORE_Out.h:274
#define tInteger
Definition: types.h:90
virtual CORE_Out & genericPrint(const tFlag &type, const tUInt &obj)
print Operators
Definition: CORE_Out.h:704
virtual void print(const tFlag &type, const tString &message)
print a string
Definition: CORE_Out.h:335
virtual tString toString() const
return the string representation of the class
Definition: CORE_Out.h:794
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74