plugin/poi/geonames/provider/src/Entry.cpp
author David Caabeiro <david.caabeiro@seqpoint.com>
Fri, 25 Jun 2010 12:50:05 +0200
changeset 0 c316ab048e9d
permissions -rw-r--r--
First public commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     1
/*
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     2
 * Name        : Entry.cpp
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     3
 * Description : Encapsulates a findNearbyWikipedia entry
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     4
 * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     5
 * Website     : http://OpenMAR.org
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     6
 *
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     7
 * Copyright (c) 2010 David Caabeiro
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     8
 *
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
     9
 * All rights reserved. This program and the accompanying materials are made available 
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    10
 * under the terms of the Eclipse Public License v1.0 which accompanies this 
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    11
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    12
 *
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    13
 */
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    14
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    15
#include "Entry.h"
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    16
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    17
CEntry* CEntry::NewL()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    18
{
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    19
    CEntry* self = new(ELeave) CEntry;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    20
    CleanupStack::PushL(self);
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    21
    self->ConstructL();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    22
    CleanupStack::Pop(self);
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    23
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    24
    return self;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    25
}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    26
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    27
CEntry::~CEntry()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    28
{}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    29
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    30
CEntry::CEntry()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    31
{}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    32
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    33
void CEntry::ConstructL()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    34
{}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    35
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    36
void CEntry::Reset()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    37
{
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    38
    iTitle.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    39
    iSummary.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    40
    iElevation.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    41
    iLat.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    42
    iLng.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    43
    iWikipediaUrl.Zero();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    44
}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    45
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    46
void CEntry::EnterState(const TDesC8& aTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    47
{
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    48
    _LIT8(KTitleTag, "title");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    49
    _LIT8(KSummaryTag, "summary");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    50
//    _LIT8(KFeatureTag, "feature");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    51
    _LIT8(KElevationTag, "elevation");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    52
    _LIT8(KLatTag, "lat");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    53
    _LIT8(KLngTag, "lng");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    54
    _LIT8(KWikipediaUrlTag, "wikipediaUrl");
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    55
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    56
    if (aTag == KTitleTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    57
        iState = ETitle;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    58
    else if (aTag == KSummaryTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    59
        iState = ESummary;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    60
    else if (aTag == KElevationTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    61
        iState = EElevation;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    62
    else if (aTag == KLatTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    63
        iState = ELat;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    64
    else if (aTag == KLngTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    65
        iState = ELng;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    66
    else if (aTag == KWikipediaUrlTag)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    67
        iState = EWikipediaUrl;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    68
    else
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    69
        iState = EUnknown;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    70
}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    71
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    72
void CEntry::ExitState()
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    73
{
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    74
    iState = EUnknown;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    75
}
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    76
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    77
void CEntry::FeedState(const TDesC8& aBytes)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    78
{
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    79
    switch (iState)
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    80
    {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    81
        case ETitle:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    82
        {   
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    83
            TInt space = iTitle.MaxLength() - iTitle.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    84
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    85
            iTitle.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    86
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    87
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    88
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    89
        case ESummary:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    90
        {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    91
            TInt space = iSummary.MaxLength() - iSummary.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    92
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    93
            iSummary.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    94
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    95
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    96
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    97
        case EElevation:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    98
        {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
    99
            TInt space = iElevation.MaxLength() - iElevation.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   100
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   101
            iElevation.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   102
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   103
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   104
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   105
        case ELat:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   106
        {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   107
            TInt space = iLat.MaxLength() - iLat.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   108
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   109
            iLat.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   110
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   111
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   112
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   113
        case ELng:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   114
        {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   115
            TInt space = iLng.MaxLength() - iLng.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   116
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   117
            iLng.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   118
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   119
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   120
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   121
        case EWikipediaUrl:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   122
        {
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   123
            TInt space = iWikipediaUrl.MaxLength() - iWikipediaUrl.Length();
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   124
            TInt min = Min(space, aBytes.Length());
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   125
            iWikipediaUrl.Append(aBytes.Left(min));
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   126
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   127
        }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   128
    
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   129
        default:
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   130
            break;
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   131
    }
c316ab048e9d First public commit
David Caabeiro <david.caabeiro@seqpoint.com>
parents:
diff changeset
   132
}