Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cStreamProgress.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cStreamProgress_H
7 #define _INC_cStreamProgress_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cOSHandle.h"
13 
14 namespace Gray
15 {
16  template< typename TYPE = STREAM_POS_t >
18  {
21 
22  public:
25 
26  public:
27  cStreamProgressT(TYPE nAmount = 0, TYPE nTotal = 0)
28  : m_nAmount(nAmount)
29  , m_nTotal(nTotal)
30  {
31  }
32  bool isComplete() const
33  {
34  if (m_nTotal == 0) // no idea.
35  return true;
36  if (m_nAmount >= m_nTotal)
37  return true;
38  return false;
39  }
40  float get_PercentFloat() const
41  {
44  if (m_nTotal == 0) // no idea.
45  return 0;
46  return (float)(((double)m_nAmount) / ((double)m_nTotal));
47  }
48  int get_PercentInt() const
49  {
51  if (m_nTotal == 0) // no idea.
52  return 0;
53  return (int)((m_nAmount*100) / m_nTotal);
54  }
55  bool isValidPercent() const
56  {
57  if (m_nTotal <= 0) // no idea.
58  return false;
59  return(m_nAmount <= m_nTotal);
60  }
61  void InitZero()
62  {
63  m_nAmount = 0;
64  m_nTotal = 0; // 0 = i have no idea how big the total is.
65  }
66  };
67 
69 
71  {
76 
77  friend class cStreamProgressChunk;
78  private:
79  // Stats
80  float m_nTotal;
81  float m_nAmount;
82 
83  public:
85  : m_nTotal(1.0f)
86  , m_nAmount(0.0f)
87  {}
88 
89  void InitPercent()
90  {
91  m_nTotal = 1.0f; // of everything.
92  m_nAmount = 0.0f;
93  }
94 #if 0
95  void put_PercentComplete( float fComplete = 1.0f )
96  {
97  m_nAmount = fComplete; // indicate we are done.
98  }
99 #endif
100  float get_PercentComplete() const
101  {
102  return m_nAmount; // return value <= 1.0f
103  }
104  float get_PercentChunk() const
105  {
106  return m_nTotal;
107  }
108  };
109 
111  {
114 
115  private:
116  cStreamProgressF& m_Prog;
117  cStreamProgressF m_ProgPrev;
118  int m_iChunk;
119  int m_iChunks;
120 
121  public:
122  cStreamProgressChunk(cStreamProgressF& prog, int iSubChunks, int iParentChunks = 1)
123  : m_Prog(prog)
124  , m_iChunk(0)
125  , m_iChunks(iSubChunks)
126  {
130  m_ProgPrev = m_Prog;
131  ASSERT(m_iChunks >= 0);
132  if (m_iChunks == 0)
133  {
134  prog.m_nTotal = 0;
135  }
136  else
137  {
138  prog.m_nTotal = (((float)iParentChunks) * prog.m_nTotal) / ((float)m_iChunks); // MULDIV
139  }
140  }
142  {
144  if (m_ProgPrev.m_nTotal >= 1.0f)
145  {
146  m_Prog.m_nTotal = m_Prog.m_nAmount = 1.0f; // i have no parent. we are done.
147  }
148  else
149  {
150  m_Prog = m_ProgPrev; // back out my changes and assume IncChunk() will be called from my parent.
151  }
152  }
153  void IncChunk(int iChunks = 1)
154  {
157  m_iChunk += iChunks;
158  if (m_iChunk > m_iChunks)
159  {
160  // this really shouldn't happen!
161  m_iChunk = m_iChunks;
162  }
163  m_Prog.m_nAmount += iChunks * m_Prog.m_nTotal;
164  }
165  };
166 
168  {
173 
175 
176  virtual HRESULT _stdcall onProgressCallback(const cStreamProgress& progress)
177  {
182  UNREFERENCED_REFERENCE(progress);
183  return S_OK; // S_OK=just keep going.
184  }
185  };
186 };
187 
188 #endif
#define IGNORE_WARN_ABSTRACT(c)
Definition: GrayCore.h:81
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define TYPE
Definition: StrT.cpp:38
#define DECLSPEC_NOVTABLE
Definition: SysTypes.h:322
#define UNREFERENCED_REFERENCE(x)
Definition: SysTypes.h:318
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cStreamProgress.h:111
~cStreamProgressChunk()
Definition: cStreamProgress.h:141
void IncChunk(int iChunks=1)
Definition: cStreamProgress.h:153
cStreamProgressChunk(cStreamProgressF &prog, int iSubChunks, int iParentChunks=1)
Definition: cStreamProgress.h:122
Definition: cStreamProgress.h:71
void InitPercent()
Definition: cStreamProgress.h:89
cStreamProgressF()
Definition: cStreamProgress.h:84
float get_PercentComplete() const
Definition: cStreamProgress.h:100
float get_PercentChunk() const
Definition: cStreamProgress.h:104
Definition: cStreamProgress.h:18
TYPE m_nTotal
Total size of the stream. 0 = i have no idea how big the total is.
Definition: cStreamProgress.h:24
cStreamProgressT(TYPE nAmount=0, TYPE nTotal=0)
Definition: cStreamProgress.h:27
float get_PercentFloat() const
Definition: cStreamProgress.h:40
bool isComplete() const
Definition: cStreamProgress.h:32
int get_PercentInt() const
Definition: cStreamProgress.h:48
TYPE m_nAmount
How far the stream has progressed toward m_nTotal.
Definition: cStreamProgress.h:23
void InitZero()
Definition: cStreamProgress.h:61
bool isValidPercent() const
Definition: cStreamProgress.h:55
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
cStreamProgressT< STREAM_POS_t > cStreamProgress
Definition: cStreamProgress.h:68
Definition: cStreamProgress.h:168
virtual HRESULT _stdcall onProgressCallback(const cStreamProgress &progress)
Definition: cStreamProgress.h:176