Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opimstate.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) The Main Author <main-author@whereever.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 #include "opimstate.h"
00030 
00031 /* QT */
00032 #include <qshared.h>
00033 
00034 namespace Opie {
00035 /*
00036  * for one int this does not make
00037  * much sense but never the less
00038  * we will do it for the future
00039  */
00040 struct OPimState::Data : public QShared {
00041     Data() : QShared(),state(Undefined) {
00042     }
00043     int state;
00044 };
00045 
00046 OPimState::OPimState( int state ) {
00047     data = new Data;
00048     data->state = state;
00049 }
00050 OPimState::OPimState( const OPimState& st) :
00051     data( st.data ) {
00052     /* ref up */
00053     data->ref();
00054 }
00055 OPimState::~OPimState() {
00056     if ( data->deref() ) {
00057         delete data ;
00058         data = 0;
00059     }
00060 }
00061 bool OPimState::operator==( const OPimState& st) {
00062     if ( data->state == st.data->state ) return true;
00063 
00064     return false;
00065 }
00066 OPimState &OPimState::operator=( const OPimState& st) {
00067     st.data->ref();
00068     deref();
00069     data = st.data;
00070 
00071     return *this;
00072 }
00073 void OPimState::setState( int st) {
00074     copyInternally();
00075     data->state = st;
00076 }
00077 int OPimState::state()const {
00078     return data->state;
00079 }
00080 void OPimState::deref() {
00081     if ( data->deref() ) {
00082         delete data;
00083         data = 0l;
00084     }
00085 }
00086 void OPimState::copyInternally() {
00087     /* we need to change it */
00088     if ( data->count != 1 ) {
00089         data->deref();
00090         Data* d2 = new Data;
00091         d2->state = data->state;
00092         data = d2;
00093     }
00094 }
00095 
00096 }

Generated on Sat Nov 5 16:16:22 2005 for OPIE by  doxygen 1.4.2