Diffstat (limited to 'noncore/unsupported/libopie/pim/opimstate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/libopie/pim/opimstate.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/opimstate.cpp b/noncore/unsupported/libopie/pim/opimstate.cpp new file mode 100644 index 0000000..6fb2feb --- a/dev/null +++ b/noncore/unsupported/libopie/pim/opimstate.cpp | |||
@@ -0,0 +1,64 @@ | |||
1 | #include <qshared.h> | ||
2 | |||
3 | #include "opimstate.h" | ||
4 | |||
5 | /* | ||
6 | * for one int this does not make | ||
7 | * much sense but never the less | ||
8 | * we will do it for the future | ||
9 | */ | ||
10 | struct OPimState::Data : public QShared { | ||
11 | Data() : QShared(),state(Undefined) { | ||
12 | } | ||
13 | int state; | ||
14 | }; | ||
15 | |||
16 | OPimState::OPimState( int state ) { | ||
17 | data = new Data; | ||
18 | data->state = state; | ||
19 | } | ||
20 | OPimState::OPimState( const OPimState& st) : | ||
21 | data( st.data ) { | ||
22 | /* ref up */ | ||
23 | data->ref(); | ||
24 | } | ||
25 | OPimState::~OPimState() { | ||
26 | if ( data->deref() ) { | ||
27 | delete data ; | ||
28 | data = 0; | ||
29 | } | ||
30 | } | ||
31 | bool OPimState::operator==( const OPimState& st) { | ||
32 | if ( data->state == st.data->state ) return true; | ||
33 | |||
34 | return false; | ||
35 | } | ||
36 | OPimState &OPimState::operator=( const OPimState& st) { | ||
37 | st.data->ref(); | ||
38 | deref(); | ||
39 | data = st.data; | ||
40 | |||
41 | return *this; | ||
42 | } | ||
43 | void OPimState::setState( int st) { | ||
44 | copyInternally(); | ||
45 | data->state = st; | ||
46 | } | ||
47 | int OPimState::state()const { | ||
48 | return data->state; | ||
49 | } | ||
50 | void OPimState::deref() { | ||
51 | if ( data->deref() ) { | ||
52 | delete data; | ||
53 | data = 0l; | ||
54 | } | ||
55 | } | ||
56 | void OPimState::copyInternally() { | ||
57 | /* we need to change it */ | ||
58 | if ( data->count != 1 ) { | ||
59 | data->deref(); | ||
60 | Data* d2 = new Data; | ||
61 | d2->state = data->state; | ||
62 | data = d2; | ||
63 | } | ||
64 | } | ||