HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROP_Verbose.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: ROP_Verbose.h ( ROP_Verbose Library, C++)
7  *
8  * COMMENTS: Keeps track of an output stream and other flags about how to
9  * output data.
10  */
11 
12 #ifndef __ROP_Verbose__
13 #define __ROP_Verbose__
14 
15 #include "ROP_API.h"
16 #include <SYS/SYS_Math.h>
17 #include <SYS/SYS_Types.h>
18 #include <iostream>
19 
21 public:
22  ROP_Verbose(std::ostream *os=NULL)
23  : myStream(os),
24  myLevel(1),
25  myAlfred(false)
26  {
27  }
29  : myStream(s.myStream),
30  myLevel(s.myLevel),
31  myAlfred(s.myAlfred)
32  {
33  }
35  {
36  }
37 
38  /// Clear (i.e. set the stream to null & clear levels
39  void clear()
40  {
41  myStream = NULL;
42  myLevel = 1;
43  myAlfred = false;
44  }
45 
46  /// Check to see if the stream is valid
47  bool isValid() const { return myStream != NULL; }
48 
49  /// Check verbosity level. For example:
50  /// @code
51  /// if (verbose.isLevel(2))
52  /// detailedInformation();
53  /// else if (verbose.isLevel(1))
54  /// briefInformation();
55  /// @endcode
56  bool isLevel(int level) const
57  { return myStream && level <= myLevel; }
58 
59  /// Assignment operator
61  {
62  myStream = s.myStream;
63  myLevel = s.myLevel;
64  myAlfred = s.myAlfred;
65  return *this;
66  }
67 
68  /// Copy from a source verbose or clear if the source is NULL
69  void setFrom(const ROP_Verbose *s)
70  {
71  if (s)
72  *this = *s;
73  else
74  clear();
75  }
76 
77  /// @{
78  /// Manage the output stream
79  std::ostream *getStream() const { return myStream; }
80  void setStream(std::ostream *s) { myStream = s; }
81  /// @}
82 
83  /// @{
84  /// Manage the verbosity level
85  int getLevel() const { return myLevel; }
86  void setLevel(int level) { myLevel = level; }
87  /// @}
88 
89  /// @{
90  /// Manage the alfred flag (turns on alfred style progress)
91  bool getAlfred() const { return myAlfred; }
92  void setAlfred(bool flag=true) { myAlfred = flag; }
93  /// @}
94 
95  /// Print out progress (@c percent should be 0-1)
96  void showProgress(fpreal percent) const
97  {
98  if (myStream && myAlfred)
99  {
100  int pct;
101  pct = SYSclamp((int)(percent*100 + 0.5), 0, 100);
102  *myStream << "ALF_PROGRESS " << pct << "%\n";
103  myStream->flush();
104  }
105  }
106 
107  /// Print out progress based on counts
108  void showProgress(int current, int total) const
109  {
110  if (total)
111  showProgress((fpreal)current/(fpreal)total);
112  }
113 
114 private:
115  std::ostream *myStream;
116  int myLevel;
117  bool myAlfred;
118 };
119 
120 #endif
void setAlfred(bool flag=true)
Definition: ROP_Verbose.h:92
bool isLevel(int level) const
Definition: ROP_Verbose.h:56
void setStream(std::ostream *s)
Definition: ROP_Verbose.h:80
GLint level
Definition: glcorearb.h:108
GLdouble s
Definition: glad.h:3009
bool getAlfred() const
Definition: ROP_Verbose.h:91
void clear()
Clear (i.e. set the stream to null & clear levels.
Definition: ROP_Verbose.h:39
#define ROP_API
Definition: ROP_API.h:10
int getLevel() const
Definition: ROP_Verbose.h:85
ROP_Verbose(std::ostream *os=NULL)
Definition: ROP_Verbose.h:22
void setFrom(const ROP_Verbose *s)
Copy from a source verbose or clear if the source is NULL.
Definition: ROP_Verbose.h:69
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:1057
ROP_Verbose & operator=(const ROP_Verbose &s)
Assignment operator.
Definition: ROP_Verbose.h:60
bool isValid() const
Check to see if the stream is valid.
Definition: ROP_Verbose.h:47
fpreal64 fpreal
Definition: SYS_Types.h:277
void showProgress(fpreal percent) const
Print out progress (percent should be 0-1)
Definition: ROP_Verbose.h:96
std::ostream * getStream() const
Definition: ROP_Verbose.h:79
ROP_Verbose(const ROP_Verbose &s)
Definition: ROP_Verbose.h:28
void setLevel(int level)
Definition: ROP_Verbose.h:86
void showProgress(int current, int total) const
Print out progress based on counts.
Definition: ROP_Verbose.h:108