Diffstat (limited to 'libopie2/opiepim/core/opimstate.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimstate.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimstate.cpp b/libopie2/opiepim/core/opimstate.cpp index 6fb2feb..1013a1c 100644 --- a/libopie2/opiepim/core/opimstate.cpp +++ b/libopie2/opiepim/core/opimstate.cpp | |||
@@ -1,28 +1,57 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qshared.h> | 29 | #include <qshared.h> |
2 | 30 | ||
3 | #include "opimstate.h" | 31 | #include "opimstate.h" |
4 | 32 | ||
33 | namespace Opie { | ||
5 | /* | 34 | /* |
6 | * for one int this does not make | 35 | * for one int this does not make |
7 | * much sense but never the less | 36 | * much sense but never the less |
8 | * we will do it for the future | 37 | * we will do it for the future |
9 | */ | 38 | */ |
10 | struct OPimState::Data : public QShared { | 39 | struct OPimState::Data : public QShared { |
11 | Data() : QShared(),state(Undefined) { | 40 | Data() : QShared(),state(Undefined) { |
12 | } | 41 | } |
13 | int state; | 42 | int state; |
14 | }; | 43 | }; |
15 | 44 | ||
16 | OPimState::OPimState( int state ) { | 45 | OPimState::OPimState( int state ) { |
17 | data = new Data; | 46 | data = new Data; |
18 | data->state = state; | 47 | data->state = state; |
19 | } | 48 | } |
20 | OPimState::OPimState( const OPimState& st) : | 49 | OPimState::OPimState( const OPimState& st) : |
21 | data( st.data ) { | 50 | data( st.data ) { |
22 | /* ref up */ | 51 | /* ref up */ |
23 | data->ref(); | 52 | data->ref(); |
24 | } | 53 | } |
25 | OPimState::~OPimState() { | 54 | OPimState::~OPimState() { |
26 | if ( data->deref() ) { | 55 | if ( data->deref() ) { |
27 | delete data ; | 56 | delete data ; |
28 | data = 0; | 57 | data = 0; |
@@ -41,24 +70,26 @@ OPimState &OPimState::operator=( const OPimState& st) { | |||
41 | return *this; | 70 | return *this; |
42 | } | 71 | } |
43 | void OPimState::setState( int st) { | 72 | void OPimState::setState( int st) { |
44 | copyInternally(); | 73 | copyInternally(); |
45 | data->state = st; | 74 | data->state = st; |
46 | } | 75 | } |
47 | int OPimState::state()const { | 76 | int OPimState::state()const { |
48 | return data->state; | 77 | return data->state; |
49 | } | 78 | } |
50 | void OPimState::deref() { | 79 | void OPimState::deref() { |
51 | if ( data->deref() ) { | 80 | if ( data->deref() ) { |
52 | delete data; | 81 | delete data; |
53 | data = 0l; | 82 | data = 0l; |
54 | } | 83 | } |
55 | } | 84 | } |
56 | void OPimState::copyInternally() { | 85 | void OPimState::copyInternally() { |
57 | /* we need to change it */ | 86 | /* we need to change it */ |
58 | if ( data->count != 1 ) { | 87 | if ( data->count != 1 ) { |
59 | data->deref(); | 88 | data->deref(); |
60 | Data* d2 = new Data; | 89 | Data* d2 = new Data; |
61 | d2->state = data->state; | 90 | d2->state = data->state; |
62 | data = d2; | 91 | data = d2; |
63 | } | 92 | } |
64 | } | 93 | } |
94 | |||
95 | } | ||