Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
void Apollo::KeyValueList::operator=(KeyValueList& l)
{
  List::Empty();

  for (KeyValueElem* e = 0; (e = l.nextElem(e)) != 0; ) {
    switch (e->getType()) {
      case ValueElem::TypeInt: add(e->getKey(), e->getInt()); break;
      case ValueElem::TypeString: add(e->getKey(), e->getString()); break;
      case ValueElem::TypeHandle: add(e->getKey(), e->getHandle()); break;
    }
  }
}
/*++
* @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;
}
Example #5
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;
}
void
SonarAvoidParameters::operator <<= (const KeyValueList& _params)
{
  Super::operator <<= (_params);

  QString str = _params.getValue("MinDistance");
  if (str.length() != 0)
    minDistance = str.toInt();
  str = _params.getValue("HaltDistance");
  if (str.length() != 0)
    haltDistance = str.toInt();
  str = _params.getValue("LeftSonar");
  if (str.length() != 0)
    leftSonar = str.toInt();
  str = _params.getValue("RightSonar");
  if (str.length() != 0)
    rightSonar = str.toInt();
  str = _params.getValue("Translation");
  if (str.length() != 0)
    translation = str.toInt();
  str = _params.getValue("Rotation");
  if (str.length() != 0)
    rotation = Miro::deg2Rad(str.toDouble());
}
Example #7
0
    void parse(const char *d, int l)
    {
        const char *ptr = d;
        int line = 1;
        bool done = l <= 0;

        QString current_section = "";
        KeyValueList keyvals;

        while(!done)
        {
            switch(*ptr)
            {
                case '\0':
                    done = true;
                    break;
                case '#':
                {
                    const char *end = strchr(ptr, '\n');
                    if (!end) done = true;
                    ptr = end;
                    break;
                }
                case '\n':
                    ptr ++;
                    line ++;
                    break;
                case '[':
                {
                    ptr ++;
                    const char *nl = strchr(ptr, '\n');
                    const char *end = strchr(ptr, ']');

                    if (!nl) nl = d + l;

                    if (!end || nl < end)
                    {
                        VERBOSE(VB_IMPORTANT, QString("CfgReader:: Badly formatted section, line %1").arg(line));
                        done = true;
                    }

                    if (current_section.length() > 0)
                    {
                        cfg[current_section] = keyvals;
                        keyvals = KeyValueList();
                    }

                    current_section = std::string(ptr, end - ptr).c_str();
                    if (current_section.length() == 0)
                    {
                        VERBOSE(VB_IMPORTANT, QString("CfgReader:: Badly formatted section, line %1").arg(line));
                        done = true;
                    }
                    ptr = end + 1;
                    break;
                }
                default:
                {
                    if (current_section.length() > 0)
                    {
                        const char *eq = strchr(ptr, '=');
                        const char *nl = strchr(ptr, '\n');

                        if (!nl) nl = d + l;

                        if (!eq || nl < eq) 
                        {
                            VERBOSE(VB_IMPORTANT, QString("CfgReader:: Badly formatted line %1").arg(line));
                            done = true;
                        }
                        else
                        {
                            QString key = string(ptr, eq - ptr).c_str();
                            QString val = string(eq + 1, nl - eq - 1).c_str();
                            keyvals.push_back(KeyValue(key, val));
                            ptr = nl;
                        }
                    }
                    else
                    {
                        VERBOSE(VB_IMPORTANT, QString("CfgReader:: Badly formatted line %1").arg(line));
                        done = true;
                    }
                    break;
                }
            }

            if (ptr - d == l) 
                done = true;
        }

        if (current_section.length() > 0)
            cfg[current_section] = keyvals;
    }