示例#1
0
文件: pls.cpp 项目: Cougar/mythtv
 QList<QString> getKeys(const QString &section)
 {
     KeyValueList keylist = cfg[section];
     QList<QString> res;
     for (KeyValueList::iterator it = keylist.begin(); it != keylist.end(); it++)
         res.push_back((*it).first);
     return res;
 }
示例#2
0
文件: pls.cpp 项目: Cougar/mythtv
 QString getStrVal(const QString &section, const QString &key, const QString &def = "")
 {
     KeyValueList keylist = cfg[section];
     QString res = def;
     for (KeyValueList::iterator it = keylist.begin(); it != keylist.end(); it++)
     {
         if ((*it).first == key) 
         {
             res =(*it).second;
             break;
         }
     }
     return res;
 }
示例#3
0
int _tmain(int argc, _TCHAR* argv[])
{
    KeyValueList kvlist;
    txKeyValue v0 = {0,10};
    txKeyValue v1 = {1,11};
    txKeyValue v2 = {2,110};
    txKeyValue v3 = {3,100};
    kvlist.push_back(v0);
    kvlist.push_back(v1);
    kvlist.push_back(v3);

    KeyValueIt v0It = kvlist.begin();
    KeyValueIt v1It = v0It;
    v0It++;
    KeyValueIt v2It = v0It;
    v2It++;
    v2It++;

    // The following code are not right
    // the list iterator are not dereferencable
    //txKeyValue v2c = *v2It;
    //txKeyValue *pv2 = &(*v2It);

    kvlist.erase(v1It);

    printf("Key:%d--Value:%d \n", v0It->id, v0It->value );
    // printf("Key:%d--Value:%d \n", v2It->id, v2It->value );
    // printf("Key:%d--Value:%d \n", pv2->id, pv2->value );
    // printf("Key:%d--Value:%d \n", v1It->id, v1It->value );

    for ( KeyValueIt it=kvlist.begin(); it!=kvlist.end(); it++ ) {
        printf("Key:%d--value:%d \n", it->id, it->value);
    }

    return 0;
}
/*++
* @method: Client::getStringFromOAuthKeyValuePairs
*
* @description: this method builds a sorted string from key-value pairs
*
* @input: rawParamMap - key-value pairs map
*         paramsSeperator - sepearator, either & or ,
*
* @output: rawParams - sorted string of OAuth parameters
*
* @remarks: internal method
*
*--*/
bool Client::getStringFromOAuthKeyValuePairs( const KeyValuePairs& rawParamMap,
        std::string& rawParams,
        const std::string& paramsSeperator )
{
    rawParams.assign( "" );
    if( rawParamMap.size() )
    {
        KeyValueList keyValueList;
        std::string dummyStr;

        /* Push key-value pairs to a list of strings */
        keyValueList.clear();
        KeyValuePairs::const_iterator itMap = rawParamMap.begin();
        for( ; itMap != rawParamMap.end(); itMap++ )
        {
            dummyStr.assign( itMap->first );
            dummyStr.append( "=" );
            if( paramsSeperator == "," )
            {
                dummyStr.append( "\"" );
            }
            dummyStr.append( itMap->second );
            if( paramsSeperator == "," )
            {
                dummyStr.append( "\"" );
            }
            keyValueList.push_back( dummyStr );
        }

        /* Sort key-value pairs based on key name */
        keyValueList.sort();

        /* Now, form a string */
        dummyStr.assign( "" );
        KeyValueList::iterator itKeyValue = keyValueList.begin();
        for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
        {
            if( dummyStr.length() )
            {
                dummyStr.append( paramsSeperator );
            }
            dummyStr.append( itKeyValue->c_str() );
        }
        rawParams.assign( dummyStr );
    }
    return ( rawParams.length() ) ? true : false;
}