commsfwtools/commstools/utracedecoder/src/messagedefparser/contextidentifier.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <cassert>
       
    17 #include <string>
       
    18 #include <iostream>
       
    19 #include <sstream>
       
    20 #include <iomanip>
       
    21 
       
    22 #include "messagedefparser\contextidentifier.h"
       
    23 
       
    24 namespace Parser
       
    25 {
       
    26 
       
    27 void CContextIdentifier::AddMember(TMember* aMember)
       
    28     {
       
    29     assert(aMember);
       
    30     assert(aMember->iMemberType->Type() == Parser::EPadTypeIdentifier || aMember->iMemberName[0] != 0);
       
    31     assert(!FindMember(aMember->iMemberName));
       
    32     iMembers.push_back(aMember);
       
    33     aMember->iOffset = iSize;
       
    34     iSize += aMember->iMemberType->TotalSize() * aMember->iArraySize;
       
    35     }
       
    36 
       
    37 
       
    38 void CContextIdentifier::SetBaseContext(const CContextIdentifier* aBaseContext)
       
    39     {
       
    40     iBaseContext = aBaseContext;
       
    41     }
       
    42 
       
    43 
       
    44 int CContextIdentifier::TotalSize() const
       
    45     {
       
    46     if (iBaseContext)
       
    47         {
       
    48         return Size() + iBaseContext->TotalSize();
       
    49         }
       
    50     else
       
    51         {
       
    52         return Size();
       
    53         }
       
    54     }
       
    55 
       
    56 
       
    57 const TMember* CContextIdentifier::FindMember(const std::string& aName)
       
    58     {
       
    59     unsigned int i;
       
    60     TMember* tmp;
       
    61 
       
    62     if (aName[0] == 0)
       
    63         {
       
    64         return NULL;
       
    65         }
       
    66 
       
    67     for (i=0; i<iMembers.size(); i++)
       
    68         {
       
    69         tmp = iMembers.at(i);
       
    70         if (!_strcmpi(tmp->iMemberName.c_str(), aName.c_str()))
       
    71             {
       
    72             return tmp;
       
    73             }
       
    74         }
       
    75     return NULL;
       
    76     }
       
    77 
       
    78 
       
    79 void CContextIdentifier::Describe(const unsigned char* aData, unsigned int aLength, const void* aOptions, std::ostream& aOutput) const
       
    80     {
       
    81     int baseSize = 0;
       
    82     if (iBaseContext)
       
    83         {
       
    84         baseSize = iBaseContext->TotalSize();
       
    85         iBaseContext->Describe(aData, baseSize, NULL, aOutput);
       
    86         }
       
    87 
       
    88     unsigned int i;
       
    89     TMember* member;
       
    90     for (i=0; i<iMembers.size(); i++)
       
    91         {
       
    92         member = iMembers.at(i);
       
    93         if (member->iMemberName[0] != 0) // padding members have no name
       
    94             {
       
    95             aOutput << "[" + std::string(member->iMemberName) + "=";
       
    96             member->iMemberType->Describe(aData + baseSize + member->iOffset, member->iMemberType->Size(), member->iIdentifierOptions, aOutput);
       
    97             aOutput << "] ";
       
    98             }
       
    99         }
       
   100     }
       
   101 
       
   102 } // namespace Parser
       
   103