-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathProgress.cpp
73 lines (59 loc) · 1.82 KB
/
Progress.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Copyright (C) Wojciech Jarosz <wjarosz@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE.txt file.
//
#include "Progress.h"
#include <iostream>
AtomicProgress::AtomicProgress(bool createState, float totalPercentage) :
m_numSteps(1),
m_percentageOfParent(totalPercentage),
m_stepPercent(m_numSteps == 0 ? totalPercentage : totalPercentage / m_numSteps),
m_atomicState(createState ? std::make_shared<AtomicPercent32>(0.f) : nullptr)
{
}
//
//AtomicProgress::AtomicProgress(AtomicPercent32 * state, float totalPercentage) :
// m_numSteps(1),
// m_percentageOfParent(totalPercentage),
// m_stepPercent(m_numSteps == 0 ? totalPercentage : totalPercentage / m_numSteps),
// m_atomicState(state), m_isStateOwner(false)
//{
//
//}
AtomicProgress::AtomicProgress(const AtomicProgress & parent, float percentageOfParent) :
m_numSteps(1),
m_percentageOfParent(parent.m_percentageOfParent * percentageOfParent),
m_stepPercent(m_numSteps == 0 ? m_percentageOfParent : m_percentageOfParent / m_numSteps),
m_atomicState(parent.m_atomicState)
{
}
void AtomicProgress::resetProgress(float p)
{
if (!m_atomicState)
return;
*m_atomicState = p;
}
float AtomicProgress::progress() const
{
if (!m_atomicState)
return -1.f;
return float(*m_atomicState);
}
void AtomicProgress::setAvailablePercent(float availablePercent)
{
m_percentageOfParent = availablePercent;
m_stepPercent = m_numSteps == 0 ? availablePercent : availablePercent / m_numSteps;
}
void AtomicProgress::setNumSteps(int numSteps)
{
m_numSteps = numSteps;
m_stepPercent = m_numSteps == 0 ? m_percentageOfParent : m_percentageOfParent / m_numSteps;
}
AtomicProgress& AtomicProgress::operator+=(int steps)
{
if (!m_atomicState)
return *this;
*m_atomicState += steps * m_stepPercent;
return *this;
}