libopie PIM API Documentation

opimstate.cpp

Go to the documentation of this file.
00001 #include <qshared.h>
00002 
00003 #include "opimstate.h"
00004 
00005 /*
00006  * for one int this does not make
00007  * much sense but never the less
00008  * we will do it for the future
00009  */
00010 struct OPimState::Data : public QShared {
00011     Data() : QShared(),state(Undefined) {
00012     }
00013     int state;
00014 };
00015 
00016 OPimState::OPimState( int state ) {
00017     data = new Data;
00018     data->state = state;
00019 }
00020 OPimState::OPimState( const OPimState& st) :
00021     data( st.data ) {
00022     /* ref up */
00023     data->ref();
00024 }
00025 OPimState::~OPimState() {
00026     if ( data->deref() ) {
00027         delete data ;
00028         data = 0;
00029     }
00030 }
00031 bool OPimState::operator==( const OPimState& st) {
00032     if ( data->state == st.data->state ) return true;
00033 
00034     return false;
00035 }
00036 OPimState &OPimState::operator=( const OPimState& st) {
00037     st.data->ref();
00038     deref();
00039     data = st.data;
00040 
00041     return *this;
00042 }
00043 void OPimState::setState( int st) {
00044     copyInternally();
00045     data->state = st;
00046 }
00047 int OPimState::state()const {
00048     return data->state;
00049 }
00050 void OPimState::deref() {
00051     if ( data->deref() ) {
00052         delete data;
00053         data = 0l;
00054     }
00055 }
00056 void OPimState::copyInternally() {
00057     /* we need to change it */
00058     if ( data->count != 1 ) {
00059         data->deref();
00060         Data* d2 = new Data;
00061         d2->state = data->state;
00062         data = d2;
00063     }
00064 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:21 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001