# kabc Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# geo.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <qdatastream.h>
    00022
    00023 #include "geo.h"
    00024
    00025 using namespace KABC;
    00026
    00027 Geo::Geo() :
    00028   mLatitude( 0 ), mLongitude( 0 ), mValidLat( false ), mValidLong( false )
    00029 {
    00030 }
    00031
    00032 Geo::Geo( float latitude, float longitude ) :
    00033   mLatitude( latitude ), mLongitude( longitude ),
    00034   mValidLat( true ), mValidLong( true )
    00035 {
    00036 }
    00037
    00038 void Geo::setLatitude( float latitude )
    00039 {
    00040   mLatitude = latitude;
    00041   mValidLat = true;
    00042 }
    00043
    00044 float Geo::latitude() const
    00045 {
    00046   return mLatitude;
    00047 }
    00048
    00049 void Geo::setLongitude( float longitude)
    00050 {
    00051   mLongitude = longitude;
    00052   mValidLong = true;
    00053 }
    00054
    00055 float Geo::longitude() const
    00056 {
    00057   return mLongitude;
    00058 }
    00059
    00060 bool Geo::isValid() const
    00061 {
    00062   return mValidLat && mValidLong;
    00063 }
    00064
    00065 bool Geo::operator==( const Geo &g ) const
    00066 {
    00067   if ( !g.isValid() && !isValid() ) return true;
    00068   if ( !g.isValid() || !isValid() ) return false;
    00069   if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return true;
    00070   return false;
    00071 }
    00072
    00073 bool Geo::operator!=( const Geo &g ) const
    00074 {
    00075   if ( !g.isValid() && !isValid() ) return false;
    00076   if ( !g.isValid() || !isValid() ) return true;
    00077   if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return false;
    00078   return true;
    00079 }
    00080
    00081 QString Geo::asString() const
    00082 {
    00083   return "(" + QString::number(mLatitude) + "," + QString::number(mLongitude) + ")";
    00084 }
    00085
    00086 QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
    00087 {
    00088     return s << (float)geo.mLatitude << (float)geo.mLongitude;
    00089 }
    00090
    00091 QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
    00092 {
    00093     s >> geo.mLatitude >> geo.mLongitude;
    00094
    00095     geo.mValidLat = true;
    00096     geo.mValidLong = true;
    00097
    00098     return s;
    00099 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:20 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001