コード例 #1
0
            TEST_F(ClientSetTest, testToArray) {
                ASSERT_TRUE(set->add("item1"));
                ASSERT_TRUE(set->add("item2"));
                ASSERT_TRUE(set->add("item3"));
                ASSERT_TRUE(set->add("item4"));
                ASSERT_FALSE(set->add("item4"));

                std::vector<std::string> items = set->toArray();

                ASSERT_EQ((size_t)4, items.size());
                ASSERT_TRUE(itemExists(items, "item1"));
                ASSERT_TRUE(itemExists(items, "item2"));
                ASSERT_TRUE(itemExists(items, "item3"));
                ASSERT_TRUE(itemExists(items, "item4"));
            }
コード例 #2
0
ファイル: FoursquareModel.cpp プロジェクト: Earthwings/marble
void FoursquareModel::parseFile( const QByteArray& file )
{
    QScriptValue data;
    QScriptEngine engine;
    // Qt requires parentheses around JSON
    data = engine.evaluate( '(' + QString::fromUtf8( file ) + ')' );
    data = data.property("response");
    
    // Parse if any result exists
    if ( data.property( "venues" ).isArray() ) {
        QScriptValueIterator iterator( data.property( "venues" ) );
        // Add items to the list
        QList<AbstractDataPluginItem*> items;
        do {
            iterator.next();
            QString id = iterator.value().property( "id" ).toString();
            QString name = iterator.value().property( "name" ).toString();
            QString category = iterator.value().property( "categories" ).property( 0 ).property( "name" ).toString();
            QString address = iterator.value().property( "location" ).property( "address" ).toString();
            QString city = iterator.value().property( "location" ).property( "city" ).toString();
            QString country = iterator.value().property( "location" ).property( "country" ).toString();
            double latitude = iterator.value().property( "location" ).property( "lat" ).toString().toDouble();
            double longitude = iterator.value().property( "location" ).property( "lng" ).toString().toDouble();
            int usersCount = iterator.value().property( "stats" ).property( "usersCount" ).toInteger();
            
            QScriptValue categoryIcon = iterator.value().property( "categories" ).property( 0 ).property( "icon" );
            QString iconUrl;
            QString largeIconUrl;
            if ( categoryIcon.isValid() ) {
                iconUrl = categoryIcon.property( "prefix" ).toString()
                        + "32" // That's the icon size hardcoded
                        + categoryIcon.property( "name" ).toString();
                        
                largeIconUrl = categoryIcon.property( "prefix" ).toString()
                        + "64" // Larger icon
                        + categoryIcon.property( "name" ).toString();
            }

            if( !itemExists( id ) ) {
                GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
                FoursquareItem *item = new FoursquareItem( this );
                item->setId( id );
                item->setCoordinate( coordinates );
                item->setTarget( "earth" );
                item->setName( name );
                item->setCategory( category );
                item->setAddress( address );
                item->setCity( city );
                item->setCountry( country );
                item->setUsersCount( usersCount );
                item->setCategoryIconUrl( iconUrl );
                item->setCategoryLargeIconUrl( largeIconUrl );
                
                items << item;
            }
        }
        while ( iterator.hasNext() );
        addItemsToList( items );
    }
}
コード例 #3
0
                TEST_F(RawPointerSetTest, testToArray) {
                    ASSERT_TRUE(set->add("item1"));
                    ASSERT_TRUE(set->add("item2"));
                    ASSERT_TRUE(set->add("item3"));
                    ASSERT_TRUE(set->add("item4"));
                    ASSERT_FALSE(set->add("item4"));

                    std::auto_ptr<client::DataArray<std::string> > array = set->toArray();

                    ASSERT_EQ((size_t)4, array->size());
                    std::vector<std::string> items;

                    for (size_t i = 0; i < array->size(); ++i) {
                        std::auto_ptr<std::string> item = array->release(i);
                        ASSERT_NE((std::string *)NULL, item.get());
                        items.push_back(*item);
                    }
                    
                    ASSERT_TRUE(itemExists(items, "item1"));
                    ASSERT_TRUE(itemExists(items, "item2"));
                    ASSERT_TRUE(itemExists(items, "item3"));
                    ASSERT_TRUE(itemExists(items, "item4"));
                }
コード例 #4
0
ファイル: file.c プロジェクト: BackupTheBerlios/gltron-svn
char* getFullPath(char *filename) {
  char *path;

  int i;
  for(i = 0; i < n_dirs; i++) {
    path = malloc(strlen(dirs[i]) + 1 + strlen(filename) + 1);
    sprintf(path, "%s%c%s", dirs[i], SEPERATOR, filename);
    printf("checking '%s'...", path);
    if (itemExists (path) ) {
      printf("ok\n");
      return path;
    }
    free(path);
    printf("unsuccessful\n");
  }
  return NULL;
}
コード例 #5
0
ファイル: EarthquakeModel.cpp プロジェクト: KDE/marble
void EarthquakeModel::parseFile( const QByteArray& file )
{
    QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
    QJsonValue earthquakesValue = jsonDoc.object().value(QStringLiteral("earthquakes"));

    // Parse if any result exists
    if (earthquakesValue.isArray()) {
        // Add items to the list
        QList<AbstractDataPluginItem*> items;

        QJsonArray earthquakeArray = earthquakesValue.toArray();
        for (int earthquakeIndex = 0; earthquakeIndex < earthquakeArray.size(); ++earthquakeIndex) {
            QJsonObject levelObject = earthquakeArray[earthquakeIndex].toObject();

            // Converting earthquake's properties from JSON to appropriate types
            const QString eqid = levelObject.value(QStringLiteral("eqid")).toString(); // Earthquake's ID
            const double longitude = levelObject.value(QStringLiteral("lng")).toDouble();
            const double latitude = levelObject.value(QStringLiteral("lat")).toDouble();
            const double magnitude = levelObject.value(QStringLiteral("magnitude")).toDouble();
            const QString dateString = levelObject.value(QStringLiteral("datetime")).toString();
            const QDateTime date = QDateTime::fromString(dateString, QStringLiteral("yyyy-MM-dd hh:mm:ss"));
            const double depth = levelObject.value(QStringLiteral("depth")).toDouble();

            if( date <= m_endDate && date >= m_startDate && magnitude >= m_minMagnitude ) {
                if( !itemExists( eqid ) ) {
                    // If it does not exists, create it
                    GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
                    EarthquakeItem *item = new EarthquakeItem( this );
                    item->setId( eqid );
                    item->setCoordinate( coordinates );
                    item->setMagnitude( magnitude );
                    item->setDateTime( date );
                    item->setDepth( depth );
                    items << item;
                }
            }
        }

        addItemsToList( items );
    }
}
コード例 #6
0
void DirMappingWidget::slotAdd()
{
  KURL local;
  local.setDirectory(m_edLocalDir->url()); 

  KURL remote;
  remote.setDirectory(m_edRemoteDir->text());

  if(m_edLocalDir->url().isEmpty() || !local.isValid())
  {
    KMessageBox::sorry(this, i18n("\"Local dir\" is not valid."));
    return;
  }

  if(m_edRemoteDir->text().isEmpty() || !remote.isValid())
  {
    KMessageBox::sorry(this, i18n("\"Remote dir\" is not valid."));
    return;
  }

  QString l = m_edLocalDir->url();
  if(!l.endsWith("/"))
  {
    l += "/";
  }

  if(itemExists(l))
  {
    KMessageBox::sorry(this, i18n("\"Local dir\" already exists."));
    return;
  }

  addMapping(m_edLocalDir->url(), m_edRemoteDir->text());

  m_listView->clearSelection();

  m_edLocalDir->clear();
  m_edRemoteDir->clear();
}
コード例 #7
0
ファイル: Database.cpp プロジェクト: manu88/Broadway_Core
bool Database::parseFile(const std::string &fileName , const char delim)
{
    if (!FileSystem::fileExists( fileName))
        return false;
    
    FILE* file = fopen(fileName.c_str() , "r");
    
    if (!file)
        return false;
    
    char line[256];
    
    int count = 0;
    while (fgets(line, sizeof(line), file))
    {
        std::stringstream ss(line);
        std::string item = "";
        std::string val = "";
        
        if ( strncmp(line, "#", 1 ) != 0 ) // skipped if begin with '#' ( commantary )
        {
            
            std::getline(ss, item, delim);
            std::getline(ss, val, delim);
            
            if ( !StringOperations::isEmpty( item) && !StringOperations::isEmpty( val )) // acceptable pair item/value, ie. not empty
            {
                bool overwrite = true;
                
                
                if ( item.find("+") != std::string::npos )
                {
                    
                    
                    item.erase(item.end() -1);
                    
                    overwrite = false;
                }
                if (delim != ' ' )
                {
                    item.erase( remove_if(  item.begin(), item.end(), ::isspace ), item.end());
                    
                    /* trim value, ie remove leading & trailing spaces */
                    val = StringOperations::trim( val , " \t\n" );
                    
                    if (!StringOperations::contains(val, "\""))
                    {
                    }
                    
                    else // quoted token
                    {
                        // si un seul " trouvé et dans la premiere moité de la chaine, considérée comme premier,
                        // sinon considéré comme second
                        const std::string::size_type halfSize = val.size() / 2;
                        
                        std::string::size_type first  = 0;
                        
                        first = val.find( "\"", first );
                        
                        std::string::size_type second = first + 1 ;
                        
                        second = val.find( "\"", second );
                        
                        if ( second == std::string::npos)
                        {
                            const std::string::size_type pos = first;
                            if ( pos < halfSize)
                            {
                                val.append("\"");
                                second = val.size() -1;
                            }
                            else
                            {
                                second = pos;
                                first = 0;
                                val.insert(0, "\"");
                            }
                            
                        }
                        
                        val.erase( val.begin() + second  , val.end() );
                        val.erase( val.begin()           , val.begin() +  first +1 );
                        
                    }
                }
                
                if (val != "" ) // valid ( &nice ) pair
                {
                    if ( itemExists( item )) // existant
                    {
                        
                        
                        auto pos = findItemPosition( item );
                        std::string oldVal = getValueForItemName(item)->getString();
                        
                        if ( pos != _dataList.end() )
                        {
                            _dataList.erase( pos);
                            count--;
                            
                            if (!overwrite) // on écrase la valeur
                            {
                                
                                
                                val += " " + oldVal;
                                
                            }
                        }
                        
                    }
                    
                    count++;
                    insertValue ( item , Variant( val ) );
                }
            }
            
        }
        
    }
    
    if ( count != (int) _dataList.size() )
    {
        /*list size and iter count don't match */
        DEBUG_ASSERT( false );
        
    }
    
    fclose(file);
    
    return true;
}