javaextensions/location/landmarks/src/clapiaddressinfo.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Holds Location API address information
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INTERNAL INCLUDES
       
    20 #include    "clapiaddressinfo.h"
       
    21 #include    "lapipanics.h"
       
    22 #include    "mlapilandmark.h"
       
    23 #include    "logger.h"
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CLAPIAddressInfo::NewL
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CLAPIAddressInfo* CLAPIAddressInfo::NewL()
       
    30 {
       
    31     JELOG2(EJavaLocation);
       
    32     CLAPIAddressInfo* self = CLAPIAddressInfo::NewLC();
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35 }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CLAPIAddressInfo::NewLC
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CLAPIAddressInfo* CLAPIAddressInfo::NewLC()
       
    42 {
       
    43     JELOG2(EJavaLocation);
       
    44     CLAPIAddressInfo* self = new(ELeave) CLAPIAddressInfo();
       
    45     CleanupStack::PushL(self);
       
    46     return self;
       
    47 }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CLAPIAddressInfo::~CLAPIAddressInfo
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CLAPIAddressInfo::~CLAPIAddressInfo()
       
    54 {
       
    55     JELOG2(EJavaLocation);
       
    56     iValues.ResetAndDestroy();
       
    57     iIds.Close();
       
    58 }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CLAPIAddressInfo::ValueCount
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 TInt CLAPIAddressInfo::ValueCount() const
       
    65 {
       
    66     JELOG2(EJavaLocation);
       
    67     return iIds.Count();
       
    68 }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CLAPIAddressInfo::SetValueL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CLAPIAddressInfo::SetValueL(TInt aFieldId, const TDesC* aValue)
       
    75 {
       
    76     JELOG2(EJavaLocation);
       
    77     __ASSERT_DEBUG(aFieldId > 0 && aFieldId <= ELAPINumAddressInfos,
       
    78                    LAPIError::Panic(ELAPIPanicInvalidFieldId));
       
    79 
       
    80     TInt error = KErrNone;
       
    81     TInt index = iIds.Find(aFieldId);
       
    82     HBufC* value = aValue ? aValue->AllocLC() : NULL;
       
    83     // The information already exists in this info so replace the existing
       
    84     // Remove the old value because the pointer array owns the object
       
    85     if (index != KErrNotFound)
       
    86     {
       
    87         delete iValues[index];
       
    88         iValues.Remove(index);
       
    89         iValues.InsertL(value, index);
       
    90         // Do not leave yet since "value" may be in cleanup stack
       
    91         error = iIds.Insert(aFieldId, index);
       
    92     }
       
    93     else // New information, append to the end
       
    94     {
       
    95         iValues.AppendL(value);
       
    96         // Do not leave yet since "value" may be in cleanup stack
       
    97         error = iIds.Append(aFieldId);
       
    98     }
       
    99 
       
   100     // Pop the value if it was added to the cleanup stack
       
   101     if (value)
       
   102     {
       
   103         CleanupStack::Pop(value);
       
   104     }
       
   105 
       
   106     // Check the error and keep the arrays in sync with each other
       
   107     if (error != KErrNone)
       
   108     {
       
   109         delete iValues[index];
       
   110         iValues.Remove(index);
       
   111         User::Leave(error);
       
   112     }
       
   113 }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CLAPIAddressInfo::Value
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 const TDesC* CLAPIAddressInfo::Value(TInt aFieldId) const
       
   120 {
       
   121     JELOG2(EJavaLocation);
       
   122     TInt index = iIds.Find(aFieldId);
       
   123     if (index != KErrNotFound)
       
   124     {
       
   125         return iValues[index];
       
   126     }
       
   127 
       
   128     return NULL; // Not found
       
   129 }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CLAPIAddressInfo::CLAPIAddressInfo
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CLAPIAddressInfo::CLAPIAddressInfo()
       
   136 {
       
   137     JELOG2(EJavaLocation);
       
   138 }
       
   139 
       
   140 // End of file