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