Exemplo n.º 1
0
static void split_vec(PathVector &full_vec, PathVector &new_vec,
                                                       const Path &split_path){
  PathVector old_full;
  old_full.insert(old_full.begin(),full_vec.begin(),full_vec.end());
  full_vec.erase(full_vec.begin(),full_vec.end());
  
  for( PathVector::const_iterator path=old_full.begin() ; path!=old_full.end()
                                                              ; path++ ){
    if(starts_with(*path,split_path))
      new_vec.push_back(*path);
    else
      full_vec.push_back(*path);
  }
}
Exemplo n.º 2
0
static bool contains(const PathVector &vec, const Path &path){
  for( PathVector::const_iterator comp_path=vec.begin() ; comp_path!=vec.end() ;comp_path++ ){
    if(compPath(*comp_path,path)==compPath(path,*comp_path))
      return true;
  }
  return false;
}
Exemplo n.º 3
0
/**
 * Clean up paths that lead nowhere and the root path.
 * @param source_id ID of the root node.
 * @param paths Paths to be cleaned up.
 */
void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths)
{
	Path *source = paths[source_id];
	paths[source_id] = NULL;
	for (PathVector::iterator i = paths.begin(); i != paths.end(); ++i) {
		Path *path = *i;
		if (path == NULL) continue;
		if (path->GetParent() == source) path->Detach();
		while (path != source && path != NULL && path->GetFlow() == 0) {
			Path *parent = path->GetParent();
			path->Detach();
			if (path->GetNumChildren() == 0) {
				paths[path->GetNode()] = NULL;
				delete path;
			}
			path = parent;
		}
	}
	delete source;
	paths.clear();
}
Exemplo n.º 4
0
		std::string ContextGen::printable(const PathVector& val)
		{
			std::string res;

			if(val.empty())
				return "(empty vector)";
			else
				res = "(vector)";

			Color col(getColorMode());

			for(PathVector::const_iterator it = val.begin(); it != val.end(); ++it)
			{
				res.append(col.red("\n   * "));
				if(it->isNative()) res.append(col.yellow("[NATIVE] "));
				else if(it->isForeign()) res.append(col.yellow("[FOREIGN] "));
				else res.append(col.yellow("[NEITHER] ")); // is ok, if windows parity build and unix path with windows backend
				res.append(it->get());
			}

			return res;
		}
Exemplo n.º 5
0
void BuildPackage( const std::string& FolderName, std::string FileName )
{
    if( FileName.empty() )
    {
        fs::path Path( FolderName );
        FileName = Path.filename().string() + ".pkg";
    }
    AutoFile f( new OsFile( FileName, std::ios_base::out | std::ios_base::trunc ) );
    PackageWriter writer( f );
    PathVector Paths;
    fs::path Dir( FolderName );
    BuildFilesList( Dir, Paths );
    fs::path BasePath = Dir.is_absolute() ? Dir : fs::current_path() / FolderName;
    for( PathVector::const_iterator i = Paths.begin(), e = Paths.end(); i != e; ++i )
    {
        const fs::path& RelPath = *i;
        const fs::path PathInPack = RelativePath( BasePath, RelPath );
        LOG( "Adding %s as %s\n", RelPath.string().c_str(), PathInPack.string().c_str() );
        writer.Add( RelPath, PathInPack );
    }
    writer.Save();
    LOG( "All done." );
}
Exemplo n.º 6
0
static void fill_data(NXhandle handle, Data &data, PathVector &data_tree,
                                                    const PrintConfig &config){
  // local variables to put stuff in
  Path units_path;
  Path signal_path;
  PathVector attr_paths;

  // sort out everything
  for( PathVector::const_iterator path=data_tree.begin() ; path!=data_tree.end() ; path++ ){
    Node end_node=*((*path).rbegin());
    if(end_node.type==ATTR){
      if(end_node.name=="units"){
        units_path=*path;
      }else if(end_node.name=="signal"){
        signal_path=*path;
      }else{
        attr_paths.push_back(*path);
      }
    }else{
      data.path=*path;
      data.name=end_node.name;
      //data.type=end_node.type;
    }
  }

  // get the attributes and fill the structure
  data.units=read_attr_as_string(handle,units_path,config);
  data.signal=read_int_attr(handle,signal_path);

  // get the unknown attributes
  for( PathVector::const_iterator path=attr_paths.begin() ; path!=attr_paths.end() ; path++ ){
    string value=read_attr_as_string(handle,*path,config);
    string key=(*path).rbegin()->name;
    
    data.unknown[key]=value;
  }

  // ----- from here down  gets the data

  // open up to the right place
  open_path(handle,data.path);

  // get the rank, dimensions and type
  if(NXgetinfo(handle,&data.rank,data.dims,&data.type)!=NX_OK){
    close_path(handle,data.path);
    throw "NXgetinfo failed";
  }

  // allocate space for the data
  if(NXmalloc(&data.data,data.rank,data.dims,data.type)!=NX_OK){
    close_path(handle,data.path);
    throw "NXmalloc failed";
  }

  // retrieve the data from the file
  if(NXgetdata(handle,data.data)!=NX_OK){
    close_path(handle,data.path);
    throw "NXgetdata failed";
  }

  // close the path
  close_path(handle,data.path);
}
Exemplo n.º 7
0
static void fill_axis(NXhandle handle, Axis &axis, PathVector &tree,
                                                    const PrintConfig &config){
  axis.name=(axis.path.rbegin())->name;
  axis.type=-1;
  axis.dims[0]=-1;

  Path units_path;
  Path primary_path;
  Path axis_path;
  PathVector attr_paths;

  // sort out everything
  for( PathVector::const_iterator path=tree.begin() ; path!=tree.end() ; 
                                                                      path++ ){
    Node end_node=*((*path).rbegin());
    if(end_node.type==ATTR){
      if(end_node.name=="units"){
        units_path=*path;
      }else if(end_node.name=="primary"){
        primary_path=*path;
      }else if(end_node.name=="axis"){
        axis_path=*path;
      }else{
        attr_paths.push_back(*path);
      }
    }
  }

  // get the attributes and fill the structure
  if(units_path.size()>0)
    axis.units=read_attr_as_string(handle,units_path,config);
  if(axis_path.size()>0)
    axis.axis=read_int_attr(handle,axis_path);
  if(primary_path.size()>0)
    axis.primary=read_int_attr(handle,primary_path);
  else
    axis.primary=-1;

  // get the unknown attributes
  for( PathVector::const_iterator path=attr_paths.begin() ; path!=attr_paths.end() ; path++ ){
    string value=read_attr_as_string(handle,*path,config);
    string key=(*path).rbegin()->name;

    axis.unknown[key]=value;
  }

  // -- from here down gets the data
  open_path(handle,axis.path);

  // get the rank, dimensions and type
  int rank;
  if(NXgetinfo(handle,&rank,axis.dims,&axis.type)!=NX_OK){
    close_path(handle,axis.path);
    throw "NXgetinfo failed";
  }

  if(rank>1){
    close_path(handle,axis.path);
    throw "RANK>1";
  }

  // allocate space for the data
  if(NXmalloc(&axis.data,rank,axis.dims,axis.type)!=NX_OK){
    close_path(handle,axis.path);
    throw "NXmalloc failed";
  }

  // retrieve the data from the file
  if(NXgetdata(handle,axis.data)!=NX_OK){
    close_path(handle,axis.path);
    throw "NXgetdata failed";
  }

  // close the path
  close_path(handle,axis.path);
}