Exemplo n.º 1
0
CollIndex NACollection<T>::resize(CollIndex newSize)
{
  if (newSize == maxLength_ OR
      newSize < usedLength_)
    // no need to resize or impossible to resize
    return maxLength_;
  else
    {
      
      // increment the size in larger chunks to avoid
      // many expensive resize calls
      if (newSize > maxLength_ AND
	  newSize/3 < (maxLength_+2)/2)
	{
	  newSize = 3 * (maxLength_+2)/2;
	}
  
      // shouldn't even come close to this
#ifndef PRIV_SRL 
      assert (newSize < MAX_COLL_INDEX);
#endif // PRIV_SRL 

      // use a temp collection with the new size
      NACollection<T> newOne(heap_,newSize);
    
#ifndef PRIV_SRL 
      assert(newSize >= usedLength_);
#endif // PRIV_SRL 

      for (CollIndex i = FIRST_COLL_INDEX; i < usedLength_; i++)
	{
	  newOne.usages_[i] = usages_[i];
	  if (usages_[i] != UNUSED_COLL_ENTRY)
	    {
	      newOne.arr_[i] = arr_[i];
	    }
	}
      
      // now just deallocate the old arrays and take the new
      // arrays and maxLength_
      deallocate();
      usages_        = newOne.usages_;
      arr_           = newOne.arr_;
      maxLength_     = newOne.maxLength_;
      
      // make sure the destructor of newOne won't mess things up
      newOne.usages_     = NULL;
      newOne.arr_        = NULL;
      newOne.usedLength_ = 0;
      newOne.maxLength_  = 0;
      
      return maxLength_;
    }
}
Exemplo n.º 2
0
bool album_db::loadFromText(string file_name)
{
    ifstream textFile;
    textFile.open(file_name.data());

    albums.clear();

    if (textFile.is_open())
    {
        string line;
        while ( getline(textFile,line) )
        {
            std::istringstream buf(line);
            std::istream_iterator<string> beg(buf), end;
            vector<string> tokens(beg, end);

            if(line.at(0) == '\t')
            {
                Album last = albums.at(albums.size()-1);
                string id = tokens.at(0) , duration = tokens.at(2) , price = tokens.at(3);
                last.addNewTrack(atoi(id.c_str()),tokens.at(1),atof(duration.c_str()),atof(price.c_str()));
                albums.pop_back();
                albums.push_back(last);
            }
            else
            {
                string id = tokens.at(0) , price = tokens.at(3);
                Album newOne(atoi(id.c_str()),tokens.at(1),tokens.at(2),atof(price.c_str()));
                albums.push_back(newOne);
            }

        }

        textFile.close();
        return true;
    }

    textFile.close();
    return false;
}
Exemplo n.º 3
0
Panorama::Panorama(PntR2& flappyCenter) : mpFlappyBird(NULL), mplstRectBarriers(NULL){
    newOne(flappyCenter);
}