コード例 #1
0
std::unique_ptr<cResultsBucket> cResultsBucket::Split()
{
    m_IndexBitsSz++;
    std::size_t code = GetFirstBits((1 << (m_IndexBitsSz -1)) | m_HeaderEntry[0].hash);
    std::unique_ptr<cResultsBucket> newbucket(new cResultsBucket(code));
    newbucket->m_IndexBitsSz = m_IndexBitsSz;

    //use this block to delete old_bucket in a natural way(by going out of scope)
    //before deleting the file from disk
    {
        cResultsBucket old_bucket(INT_MAX);
        old_bucket.m_IndexBitsSz = m_IndexBitsSz;

        for(std::size_t idx = 0; idx < m_Entries; idx++)
        {
            std::string params(m_MappedFile.data() + m_HeaderEntry[idx].offset);
            std::string result(m_MappedFile.data() + m_HeaderEntry[idx].offset + params.size() + 1);
            if(true == GetIndexBit(m_HeaderEntry[idx].hash))
                newbucket->SaveResult(m_HeaderEntry[idx].hash, params, result);
            else
                old_bucket.SaveResult(m_HeaderEntry[idx].hash, params, result);
        }
        (*this) = old_bucket;
    }

    std::stringstream converter;
    converter << INT_MAX;
    std::string temp_file = DB_PATH + converter.str();
    boost::filesystem::path temp_path(temp_file);
    boost::filesystem::remove(temp_path);

    return newbucket;
};
コード例 #2
0
// v0.1 clean_files: move images to deprecated 
DCStatus DataCleaner::clean_files(const vector<bool> files_label, const int dir_id)
{
  int files_num = files_label.size();
  int erro;
  string temp_path(this->root_dir_);
  temp_path +='/';
  temp_path += (this->image_dir_[dir_id].second).c_str();
  temp_path += '/';
  string temp_path_old(temp_path.c_str());
  temp_path += "deprecated";
  if ((erro = mkdir(temp_path.c_str(),0777)) < 0)
  {
    cout<<"DataCleaner::clean_files: mkdir failed"<<endl;
    exit(0);
  }
  temp_path += '/';
  string temp_path_new(temp_path.c_str());
  for(int i = 0; i < files_num ; i++)
  {
    if (!files_label[i])
    {
      string file_path_old(temp_path_old.c_str());
      file_path_old += this->images_[dir_id][i].c_str();
      string file_path_new(temp_path_new.c_str());
      file_path_new += this->images_[dir_id][i].c_str();
      if((erro = rename(file_path_old.c_str(), file_path_new.c_str())) < 0)
      {
        cout<<"DataCleaner::clean_files: rename failed"<<endl;
      }
    }
  }
}
コード例 #3
0
bool FindProjectIncludeDirectory::set_base_directory(const std::string &path, bool is_engine_dir) {
    if (!boost::filesystem::is_directory(path)) {
        std::cerr << "Cannot find project path:" << path << std::endl;
        return false;
    }

    boost::filesystem::path temp_path(path);
    if (is_engine_dir) {
        m_engine_directory = temp_path;
    } else {
        m_project_directory = temp_path;
    }

    return true;
}
コード例 #4
0
DCStatus DataCleaner::scan_alfeatures(const char* path)
{
    int dir_num = this->image_dir_.size();
    cout<< dir_num <<endl;
    for(int i = 0; i < dir_num ; i++)
    {
      string temp_path(path);
      temp_path += '/';
      temp_path += (this->image_dir_[i].second).c_str();
      if (scan_features(temp_path.c_str(), this->image_dir_[i].first) != DC_SUCCESS)
      {
        cout<<"Finished " << i <<" "<< this->image_dir_[i].first<<" features scanning"<<endl;
        return DC_FAILED;
      }
    }
    return DC_SUCCESS;
}
コード例 #5
0
DCStatus DataCleaner::scan_alimages(const char* path, int dir_id)
{ 
    DIR *root_dp;
    struct dirent *d_info;
    struct stat d_stat;   
    if ((root_dp = opendir(path)) == NULL)
    {
      cout<<"DataCleaner::scan_alimages: Open directory failed"<<endl;
      return DC_FAILED;
    }

    while((d_info = readdir(root_dp)) != 0)
    {
      if (!strcmp(d_info->d_name, ".") || (!strcmp(d_info->d_name, "..")))
        continue;
      
      string temp_path(path);
      temp_path += '/';
      temp_path += d_info->d_name;
  
      if (lstat(temp_path.c_str(), &d_stat) < 0)
      {
        cout<<"DataCleaner::scan_alimages: lstat file failed"<<endl;
        return DC_FAILED;
      }
      else
      {
        if(S_ISREG(d_stat.st_mode))
        {
            if (dir_id == -1)
            {
              cout<<"wrong root dir"<<endl;
              return DC_FAILED;
            } 
            string temp_image(d_info->d_name);
            this->images_[dir_id].push_back(temp_image);
        }
        else if (S_ISDIR(d_stat.st_mode))
        {
          string temp_image_dir(d_info->d_name);
          this->next_dir_id_++;
          this->image_dir_.push_back(make_pair(this->next_dir_id_,temp_image_dir));

          vector<string> new_dir;
          vector<ImgFeature*> new_feature_dir;
          vector<int> new_representative_dir;
          this->images_.push_back(new_dir);
          this->image_features_.push_back(new_feature_dir);
          this->image_representative_.push_back(new_representative_dir);

         if (scan_alimages(temp_path.c_str(),this->next_dir_id_) != DC_SUCCESS)
         {
           return DC_FAILED;
         }
        }
        else
        {
          cout<<"DataCleaner::scan_files: Wrong type file"<<endl;
        }
      }
    }
    closedir(root_dp);
    return DC_SUCCESS; 
}