コード例 #1
0
		void Instance::Language::Load(wcstring const path)
		{
			if (!path || !*path)
			{
				Paths paths;
				EnumerateResources( paths );

				if (paths.empty())
					throw Exception( L"language\\english.nlg file not found!" );

				Paths::const_iterator it( paths.begin() );

				for (Paths::const_iterator end(paths.end()); it != end; ++it)
				{
					if (it->File() == L"english.nlg")
						break;
				}

				if (it == paths.end())
					it = paths.begin();

				if (!resource.Load( it->Ptr() ))
					throw Exception( L"Failed to load language plugin file!" );
			}
			else if (!resource.Load( path ))
			{
				Load( NULL );
			}
		}
コード例 #2
0
ファイル: rbclipper.cpp プロジェクト: jvdp/rbclipper
static VALUE
rbclipper_execute_internal(VALUE self, ClipType cliptype,
                           VALUE subjfill, VALUE clipfill, VALUE resulttype)
{
  if (NIL_P(subjfill)) {
    subjfill = ID2SYM(id_even_odd);
  }

  if (NIL_P(clipfill)) {
      clipfill = ID2SYM(id_even_odd);
  }

  if (NIL_P(resulttype)) {
    resulttype = ID2SYM(id_polygons);
  }

  double inv_multiplier = 1.0 / NUM2LONG(rb_iv_get(self, "@multiplier"));

  VALUE r = rb_ary_new();
  if (resulttype == ID2SYM(id_polygons)) {
      Paths solution;
      XCLIPPER(self)->Execute((ClipType) cliptype,
                              solution,
                              sym_to_filltype(subjfill),
                              sym_to_filltype(clipfill));
      for(Paths::iterator i = solution.begin(); i != solution.end(); ++i) {
        VALUE sub = rb_ary_new();
        for(Path::iterator p = i->begin(); p != i->end(); ++p) {
          rb_ary_push(sub, rb_ary_new3(2, DBL2NUM(p->X * inv_multiplier), DBL2NUM(p->Y * inv_multiplier)));
        }
        rb_ary_push(r, sub);
      }
  }
  return r;
}
コード例 #3
0
ファイル: rbclipper.cpp プロジェクト: jvdp/rbclipper
static VALUE
rbclipper_offset_polygons(int argc, VALUE* argv, VALUE self)
{
    double multiplier = NUM2DBL(rb_iv_get(self, "@multiplier"));
    double inv_multiplier = 1.0 / multiplier;
    VALUE polygonsValue, deltaValue, joinTypeValue, endTypeValue;

    rb_scan_args(argc, argv, "31", &polygonsValue, &deltaValue, &joinTypeValue, &endTypeValue);

    Paths polygons;
    for(long i = 0; i != RARRAY_LEN(polygonsValue); i++) {
        VALUE sub = rb_ary_entry(polygonsValue, i);
        Check_Type(sub, T_ARRAY);

        ClipperLib::Path tmp;
        ary_to_polygon(sub, &tmp, multiplier);
        polygons.push_back(tmp);
    }

    Paths resultPaths;

    XCLIPPEROFFSET(self)->AddPaths(polygons, sym_to_jointype(joinTypeValue), sym_to_endtype(endTypeValue));
    XCLIPPEROFFSET(self)->Execute(resultPaths, NUM2DBL(deltaValue) * multiplier);

    VALUE r = rb_ary_new();
    for(Paths::iterator i = resultPaths.begin(); i != resultPaths.end(); ++i) {
        VALUE sub = rb_ary_new();
        for(Path::iterator p = i->begin(); p != i->end(); ++p) {
            rb_ary_push(sub, rb_ary_new3(2, DBL2NUM(p->X * inv_multiplier), DBL2NUM(p->Y * inv_multiplier)));
        }
        rb_ary_push(r, sub);
    }
    return r;
}
コード例 #4
0
ファイル: ShapeRecord.cpp プロジェクト: BrandRegard/gnash
    /// Compute total number of edges
    static size_t computeNumberOfEdges(const Paths& paths)
    {
        size_t count=0;
        for (Paths::const_iterator i = paths.begin(), e = paths.end();
                i != e; ++i) {

            count += i->size();
        }
        return count;
    }
コード例 #5
0
ファイル: Application.cpp プロジェクト: gideonmay/minervagis
void Application::_parseCommandLine()
{
  typedef boost::filesystem::path Path;
  typedef std::vector<std::string> Paths;

  boost::program_options::options_description baseOptions ( "Options" );
  baseOptions.add_options()
      ( "cache-directory", boost::program_options::value<std::string>(), "Specify the cache directory file." );

  boost::program_options::options_description hidden ( "Hidden options" );
  hidden.add_options()
    ( "files", boost::program_options::value<Paths>(), "files");

  boost::program_options::options_description allOptions;
  allOptions.add ( baseOptions ).add ( hidden );

  boost::program_options::positional_options_description p;
  p.add("files", -1);

  // Get the command line arguments.
  using Usul::CommandLine::Arguments;

  boost::program_options::variables_map vm;
  boost::program_options::store (
    boost::program_options::command_line_parser ( Arguments::instance().argc(), Arguments::instance().argv() ).
    options ( allOptions ).positional(p).allow_unregistered().run(), vm );

  // Check for the cache directory.
  if ( vm.count ( "cache-directory" ) )
  {
    const std::string cacheDirectory ( vm["cache-directory"].as<std::string>() );
    std::cout << "Setting cache directory to " << cacheDirectory << std::endl;
    Minerva::Core::DiskCache::instance().cacheDirectory ( cacheDirectory );
  }

  Paths filenames;

  if ( vm.count ( "files" ) )
  {
    filenames = vm["files"].as<Paths>();
  }

  // Have to load the config files now. Remove them from the arguments.
  Paths configs;
  
  Path ext ( ".jconf" );
  std::remove_copy_if ( filenames.begin(), filenames.end(), std::back_inserter ( configs ),
		        boost::lambda::bind ( static_cast<Path::string_type (*) ( const Path& )> ( &boost::filesystem::extension ), boost::lambda::_1 ) != ext );

  this->_loadConfigFiles ( configs );

  // Load the model files.
  this->_loadModelFiles ( filenames );
}
コード例 #6
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
/** Find every pair of overlapping paths. */
static Overlaps findOverlaps(const Graph& g, const Paths& paths)
{
	SeedMap seedMap = makeSeedMap(paths);

	Overlaps overlaps;
	for (Paths::const_iterator it = paths.begin();
			it != paths.end(); ++it) {
		unsigned i = it - paths.begin();
		findOverlaps(g, paths, seedMap, Vertex(i, false), overlaps);
		findOverlaps(g, paths, seedMap, Vertex(i, true), overlaps);
	}
	return overlaps;
}
コード例 #7
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
/** Add the path overlap edges to the specified graph. */
static void addPathOverlapEdges(Graph& g,
		const Paths& paths, const vector<string>& pathIDs,
		const Overlaps& overlaps)
{
	typedef graph_traits<Graph>::vertex_descriptor V;
	const bool allowParallelEdge = opt::mode == opt::ASSEMBLE;

	// Add the path vertices.
	g_contigNames.unlock();
	for (Paths::const_iterator it = paths.begin();
			it != paths.end(); ++it) {
		const ContigPath& path = *it;
		const string& id = pathIDs[it - paths.begin()];
		if (!path.empty()) {
			V u = merge(g, path.begin(), path.end());
			put(vertex_name, g, u, id);
		}
	}
	g_contigNames.lock();

	// Remove the single-end contigs that are in paths.
	for (Paths::const_iterator it = paths.begin();
			it != paths.end(); ++it)
		remove_vertex_if(g, it->begin(), it->end(),
				not1(std::mem_fun_ref(&ContigNode::ambiguous)));

	// Add the path edges.
	for (Overlaps::const_iterator it = overlaps.begin();
			it != overlaps.end(); ++it) {
		V u = it->source.descriptor();
		V v = it->target.descriptor();
		if (allowParallelEdge || !edge(u, v, g).second)
			add_edge(u, v, it->distance, static_cast<DG&>(g));
		else if (opt::verbose > 0)
			cerr << "ambiguous overlap: " << get(vertex_name, g, u)
				<< " -> " << get(vertex_name, g, v) << '\n';
	}
}
コード例 #8
0
ファイル: eclass.cpp プロジェクト: clbr/netradiant
    void visit(const char* name, const EntityClassScanner& table) const
    {
      Paths paths;
      EntityClassQuake3_constructDirectory(baseDirectory, table.getExtension(), paths);
      if(!string_equal(baseDirectory, gameDirectory))
      {
        EntityClassQuake3_constructDirectory(gameDirectory, table.getExtension(), paths);
      }

      for(Paths::iterator i = paths.begin(); i != paths.end(); ++i)
      {
        EntityClassesLoadFile(table, (*i).second)((*i).first.c_str());
      }
    }
コード例 #9
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
/** Assemble overlapping paths. */
static void assembleOverlappingPaths(Graph& g,
		Paths& paths, vector<string>& pathIDs)
{
	if (paths.empty())
		return;

	// Find overlapping paths.
	Overlaps overlaps = findOverlaps(g, paths);
	addPathOverlapEdges(g, paths, pathIDs, overlaps);

	// Create a property map of path overlaps.
	OverlapMap overlapMap;
	for (Overlaps::const_iterator it = overlaps.begin();
			it != overlaps.end(); ++it)
		overlapMap.insert(OverlapMap::value_type(
				OverlapMap::key_type(
					it->source.descriptor(),
					it->target.descriptor()),
				it->overlap));

	// Assemble unambiguously overlapping paths.
	Paths merges;
	assemble_if(g, back_inserter(merges),
			IsPathOverlap(g, overlapMap, IsPositive<Graph>(g)));

	// Merge overlapping paths.
	g_contigNames.unlock();
	assert(!pathIDs.empty());
	setNextContigName(pathIDs.back());
	for (Paths::const_iterator it = merges.begin();
			it != merges.end(); ++it) {
		string name = createContigName();
		if (opt::verbose > 0)
			cerr << name << '\t' << *it << '\n';
		Vertex u(paths.size(), false);
		put(vertex_name, g, u.descriptor(), name);
		pathIDs.push_back(name);
		paths.push_back(mergePaths(paths, overlapMap, *it));

		// Remove the merged paths.
		for (ContigPath::const_iterator it2 = it->begin();
				it2 != it->end(); ++it2) {
			if (isPath(*it2))
				paths[it2->id() - Vertex::s_offset].clear();
		}
	}
	g_contigNames.lock();
}
コード例 #10
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
/** Index the first and last contig of each path to facilitate finding
 * overlaps between paths. */
static SeedMap makeSeedMap(const Paths& paths)
{
	SeedMap seedMap;
	for (Paths::const_iterator it = paths.begin();
			it != paths.end(); ++it) {
		if (it->empty())
			continue;
		assert(!it->front().ambiguous());
		seedMap.insert(make_pair(it->front(),
					Vertex(it - paths.begin(), false)));
		assert(!it->back().ambiguous());
		seedMap.insert(make_pair(it->back() ^ 1,
					Vertex(it - paths.begin(), true)));
	}
	return seedMap;
}
コード例 #11
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
/** Find the largest overlap for each contig and remove it. */
static void trimOverlaps(Paths& paths, const Overlaps& overlaps)
{
	vector<unsigned> removed[2];
	removed[0].resize(paths.size());
	removed[1].resize(paths.size());

	for (Overlaps::const_iterator it = overlaps.begin();
			it != overlaps.end(); ++it) {
		unsigned& a = removed[!it->source.sense][it->source.id];
		unsigned& b = removed[it->target.sense][it->target.id];
		a = max(a, it->overlap);
		b = max(b, it->overlap);
	}

	for (Paths::iterator it = paths.begin(); it != paths.end(); ++it)
		removeContigs(*it, removed[0][it - paths.begin()],
				it->size() - removed[1][it - paths.begin()]);
}
Path Grasp_Calculator::calc_poly_centroid(Paths polygons)
{
    std::vector<IntPoint> sums;
    for (std::vector<Path>::iterator poly = polygons.begin(); poly != polygons.end(); ++poly)
    {
        IntPoint sum;
        sum.X = 0;
        sum.Y = 0;
        cInt fuck_u_Cpp = 0;
        for (std::vector<IntPoint>::iterator ip = poly->begin(); ip != poly->end(); ++ip, fuck_u_Cpp++)
        {
            sum.X += ip->X;
            sum.Y += ip->Y;
        }
        sum.X = sum.X / fuck_u_Cpp;
        sum.Y = sum.Y / fuck_u_Cpp;
        sums.push_back(sum);
    }
    return sums;
}
コード例 #13
0
ファイル: PathManager.cpp プロジェクト: Joelone/smaa-ogre
void PathManager::init()
{
	/// Search for the OGRE plugin folder
	ogre_plugin_dir = "";
	
	 // Use environment variable, if present
	char *plugindir = getenv("OGRE_PLUGIN_DIR");
	if (plugindir)
	{
		ogre_plugin_dir = plugindir;
		return;
	}
	
	#ifdef _WIN32
		// Windows: we assume the ogre plugins are in the directory the program is run from (".")
		ogre_plugin_dir = ".";
	#else
		// Linux: Check a list of common path names
		typedef std::vector<boost::filesystem::path> Paths;
		Paths dirs;
		#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
			dirs.push_back("/usr/local/lib64");
			dirs.push_back("/usr/lib64");
		#else
			dirs.push_back("/usr/local/lib32");
			dirs.push_back("/usr/lib32");
		#endif
		dirs.push_back("/usr/local");
		dirs.push_back("/usr/lib");
		// Loop through the paths and pick the first one that contains a plugin
		for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
			if (boost::filesystem::exists(*p / "OGRE/RenderSystem_GL.so")) {
				ogre_plugin_dir = (*p / "OGRE").string();
				break;
			} else if (boost::filesystem::exists(*p / "ogre/RenderSystem_GL.so")) {
				ogre_plugin_dir = (*p / "ogre").string();
				break;
			}
		}
	#endif
}
コード例 #14
0
ファイル: pathmanager.cpp プロジェクト: jsj2008/stuntrally
void PATHMANAGER::Init(std::ostream & info_output, std::ostream & error_output)
{
	typedef std::vector<fs::path> Paths;

	// Set Ogre plugins dir
	{
		ogre_plugin_dir = "";
		char *plugindir = getenv("OGRE_PLUGIN_DIR");
		if (plugindir) {
			ogre_plugin_dir = plugindir;
		#ifndef _WIN32
		} else if (fs::exists(fs::path(OGRE_PLUGIN_DIR) / "RenderSystem_GL.so")) {
			ogre_plugin_dir = OGRE_PLUGIN_DIR;
		#endif
		} else {
			#ifdef _WIN32
			ogre_plugin_dir = ".";
			#else
			Paths dirs;
			#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
			dirs.push_back("/usr/local/lib64");
			dirs.push_back("/usr/lib64");
			#else
			dirs.push_back("/usr/local/lib32");
			dirs.push_back("/usr/lib32");
			#endif
			dirs.push_back("/usr/local");
			dirs.push_back("/usr/lib");
			// Loop through the paths and pick the first one that contain a plugin
			for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
				if (fs::exists(*p / "OGRE/RenderSystem_GL.so")) {
					ogre_plugin_dir = (*p / "OGRE").string();
					break;
				} else if (fs::exists(*p / "ogre/RenderSystem_GL.so")) {
					ogre_plugin_dir = (*p / "ogre").string();
					break;
				}
			}
			#endif
		}
	}

	fs::path shortDir = "stuntrally";
	// Figure out the user's home directory
	{
		home_dir = "";
		#ifndef _WIN32 // POSIX
			char *homedir = getenv("HOME");
			if (homedir == NULL)
			{
				home_dir = "/home/";
				homedir = getenv("USER");
				if (homedir == NULL) {
					homedir = getenv("USERNAME");
					if (homedir == NULL) {
						error_output << "Could not find user's home directory!" << std::endl;
						home_dir = "/tmp/";
					}
				}
			}
		#else // Windows
			char *homedir = getenv("USERPROFILE");
			if (homedir == NULL) homedir = "data"; // WIN 9x/Me
		#endif
		home_dir += homedir;
	}

	// Find user's config dir
	#ifndef _WIN32 // POSIX
	{
		char const* conf = getenv("XDG_CONFIG_HOME");
		if (conf) user_config_dir = (fs::path(conf) / "stuntrally").string();
		else user_config_dir = (fs::path(home_dir) / ".config" / "stuntrally").string();
	}
	#else // Windows
	{
		// Open AppData directory
		std::string str;
		ITEMIDLIST* pidl;
		char AppDir[MAX_PATH];
		HRESULT hRes = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl);
		if (hRes == NOERROR)
		{
			SHGetPathFromIDList(pidl, AppDir);
			int i;
			for (i = 0; AppDir[i] != '\0'; i++) {
				if (AppDir[i] == '\\') str += '/';
				else str += AppDir[i];
			}
			user_config_dir = (fs::path(str) / "stuntrally").string();
		}
	}
	#endif
	// Create user's config dir
	CreateDir(user_config_dir, error_output);

	// Find user's data dir (for additional data)
	#ifdef _WIN32
	user_data_dir = user_config_dir;  // APPDATA/stuntrally
	#else
	{
		fs::path shareDir = SHARED_DATA_DIR;
		char const* xdg_data_home = getenv("XDG_DATA_HOME");
		user_data_dir = (xdg_data_home ? xdg_data_home / shortDir : fs::path(home_dir) / ".local" / shareDir).string();
	}
	#endif
	// Create user's data dir and its children
	CreateDir(user_data_dir, error_output);
	CreateDir(GetTrackRecordsPath(), error_output);
	CreateDir(GetScreenShotDir(), error_output);
	CreateDir(GetTrackPathUser(), error_output);  // user tracks
	CreateDir(GetTrackPathUser()+"/_previews", error_output);
	CreateDir(GetReplayPath(), error_output);
	CreateDir(GetGhostsPath(), error_output);

	// Find game data dir and defaults config dir
	char *datadir = getenv("STUNTRALLY_DATA_ROOT");
	if (datadir)
		game_data_dir = std::string(datadir);
	else
	{	fs::path shareDir = SHARED_DATA_DIR;
		Paths dirs;

		// Adding users data dir
		// TODO: Disabled for now until this is handled properly
		//dirs.push_back(user_data_dir);

		// Adding relative path from installed executable
		dirs.push_back(execname().parent_path().parent_path() / shareDir);
		// Adding relative path for running from sources
		dirs.push_back(execname().parent_path().parent_path() / "data");
		dirs.push_back(execname().parent_path().parent_path());
		dirs.push_back(execname().parent_path() / "data");
		dirs.push_back(execname().parent_path());
		#ifndef _WIN32
		// Adding XDG_DATA_DIRS
		{
			char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
			std::istringstream iss(xdg_data_dirs ? xdg_data_dirs : "/usr/local/share/:/usr/share/");
			for (std::string p; std::getline(iss, p, ':'); dirs.push_back(p / shortDir)) {}
		}
		#endif
		// TODO: Adding path from config file

		// Loop through the paths and pick the first one that contain some data
		for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
			// Data dir
			if (fs::exists(*p / "hud")) game_data_dir = p->string();
			// Config dir
			if (fs::exists(*p / "config"))
				game_config_dir = (*p / "config").string();
			// Check if both are found
			if (!game_data_dir.empty() && !game_config_dir.empty()) break;
		}
	}

	// Find cache dir
	#ifdef _WIN32
	cache_dir = user_config_dir + "/cache";  // APPDATA/stuntrally/cache
	#else
	char const* xdg_cache_home = getenv("XDG_CACHE_HOME");
	cache_dir = (xdg_cache_home ? xdg_cache_home / shortDir : fs::path(home_dir) / ".cache" / shortDir).string();
	#endif
	// Create cache dir
	CreateDir(cache_dir, error_output);
	CreateDir(GetShaderCacheDir(), error_output);

	// Print diagnostic info
	std::stringstream out;
	out << "--- Directories: ---" << ogre_plugin_dir << std::endl;
	out << "Ogre plugin:  " << ogre_plugin_dir << std::endl;
	out << "Home:         " << home_dir << std::endl;
	out << "Default cfg:  " << GetGameConfigDir() << std::endl;
	out << "User cfg:     " << GetUserConfigDir() << std::endl;
	out << "Data:         " << GetDataPath() << std::endl;
	out << "User data:    " << GetUserDataDir() << std::endl;
	out << "Cache:        " << GetCacheDir() << std::endl;
	out << "Shader cache: " << GetShaderCacheDir() << std::endl;
	out << "Log:          " << GetLogDir() << std::endl;
	info_output << out.str();
}
コード例 #15
0
ファイル: pcircle.cpp プロジェクト: nphuc/alg
void PSP(Paths&ps) {
    PSI psi;
    for(psi=ps.begin(); psi!=ps.end(); ++psi) {
        PP(*psi);
    }
}
コード例 #16
0
void PATHMANAGER::Init(bool log_paths)
{
	typedef vector<fs::path> Paths;

	// Set Ogre plugins dir
	{
		ogre_plugin = "";
		char *plugindir = getenv("OGRE_PLUGIN_DIR");
		if (plugindir) {
			ogre_plugin = plugindir;
		} else {
			#ifdef _WIN32
			ogre_plugin = ".";
			#else
			ogre_plugin = OGRE_PLUGIN_DIR_REL;
			#endif
		}
	}

	fs::path stuntrally = "stuntrally";
	// Figure out the user's home directory
	{
		home_dir = "";
		#ifndef _WIN32 // POSIX
			char *homedir = getenv("HOME");
			if (homedir == NULL)
			{
				home_dir = "/home/";
				homedir = getenv("USER");
				if (homedir == NULL) {
					homedir = getenv("USERNAME");
					if (homedir == NULL) {
						cerr << "Could not find user's home directory!" << endl;
						home_dir = "/tmp/";
					}
				}
			}
		#else // Windows
			char *homedir = getenv("USERPROFILE");
			if (homedir == NULL) homedir = "data"; // WIN 9x/Me
		#endif
		home_dir += homedir;
	}

	// Find user's config dir
	#ifndef _WIN32 // POSIX
	{
		char const* conf = getenv("XDG_CONFIG_HOME");
		if (conf) user_config = (fs::path(conf) / stuntrally).string();
		else user_config = (fs::path(home_dir) / ".config" / stuntrally).string();
	}
	#else // Windows
	{
		// Open AppData directory
		string str;
		ITEMIDLIST* pidl;
		char AppDir[MAX_PATH];
		HRESULT hRes = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, &pidl);
		if (hRes == NOERROR)
		{
			SHGetPathFromIDList(pidl, AppDir);
			int i;
			for (i = 0; AppDir[i] != '\0'; ++i) {
				if (AppDir[i] == '\\') str += '/';
				else str += AppDir[i];
			}
			user_config = (fs::path(str) / stuntrally).string();
		}
	}
	#endif
	// Create user's config dir
	CreateDir(user_config);

	// Find user's data dir (for additional data)
	#ifdef _WIN32
	user_data = user_config;  // APPDATA/stuntrally
	#else
	{
		char const* xdg_data_home = getenv("XDG_DATA_HOME");
		user_data = (xdg_data_home ? xdg_data_home / stuntrally
					: fs::path(home_dir) / ".local/share" / stuntrally).string();
	}
	#endif

	// Create user's data dir and its children
	///--------------------------------------------------
	CreateDir(user_data);
	CreateDir(Records());
	CreateDir(Ghosts());
	
	CreateDir(Replays());
	CreateDir(Screenshots());
	CreateDir(TracksUser());  // user tracks

	CreateDir(DataUser());  // user data


	// Find game data dir and defaults config dir
	char *datadir = getenv("STUNTRALLY_DATA_ROOT");
	if (datadir)
		game_data = string(datadir);
	else
	{	fs::path shareDir = SHARED_DATA_DIR;
		Paths dirs;

		// Adding users data dir
		// TODO: Disabled for now until this is handled properly
		//dirs.push_back(user_data_dir);

		// Adding relative path for running from sources
		dirs.push_back(execname().parent_path().parent_path() / "data");
		dirs.push_back(execname().parent_path().parent_path());
		dirs.push_back(execname().parent_path() / "data");
		dirs.push_back(execname().parent_path());
		// Adding relative path from installed executable
		dirs.push_back(execname().parent_path().parent_path() / shareDir);
		#ifndef _WIN32
		// Adding XDG_DATA_DIRS
		{
			char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
			istringstream iss(xdg_data_dirs ? xdg_data_dirs : "/usr/local/share/:/usr/share/");
			for (string p; getline(iss, p, ':'); dirs.push_back(p / stuntrally)) {}
		}
		#endif
		// TODO: Adding path from config file

		//  Loop through the paths and pick the first one that contain some data
		for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p)
		{	//  Data dir
			if (fs::exists(*p / "hud"))
				game_data = p->string();
			//  Config dir
			if (fs::exists(*p / "config"))
				game_config = (*p / "config").string();
			//  Check if both are found
			if (!game_data.empty() && !game_config.empty())  break;
		}
	}


	//  Subdirs for each sim_mode
	///--------------------------------------------------
	list <string> li;
	PATHMANAGER::DirList(PATHMANAGER::CarSim(), li);
	for (list <string>::iterator i = li.begin(); i != li.end(); ++i)
	{
		CreateDir(Records()+"/"+*i);
		CreateDir(Ghosts()+"/"+*i);
	}

	// Find cache dir
	#ifdef _WIN32
	cache_dir = user_config + "/cache";  // APPDATA/stuntrally/cache
	#else
	char const* xdg_cache_home = getenv("XDG_CACHE_HOME");
	cache_dir = (xdg_cache_home ? xdg_cache_home / stuntrally
				: fs::path(home_dir) / ".cache" / stuntrally).string();
	#endif
	// Create cache dir
	CreateDir(CacheDir());
	CreateDir(CacheDir()+"/tracks");
	CreateDir(ShaderDir());

	// Print diagnostic info
	if (log_paths)
	{
		info << "Paths info" << endl;
		info << "-------------------------" << endl;
		info << "Ogre plugin:  " << ogre_plugin << endl;
		info << "Data:         " << Data() << endl;
		//info << "Default cfg:  " << GetGameConfigDir() << endl;
		info << "Home:         " << home_dir << endl;
		info << "User cfg,log: " << UserConfigDir() << endl;
		info << "User data:    " << user_data << endl;
		info << "Cache:        " << CacheDir() << endl;
		info << "-------------------------";
	}
}
コード例 #17
0
LatexGenerator::LatexGenerator(const Paths &paths,
                               const Cordinate maxValues,
                               const vector<char> &pieces,
                               const vector<Cordinate> &obstacles,
                               const string &outputFilename)
{
   ofstream out(outputFilename.c_str());
   out << "\\documentclass[12pt]{article}" << endl;
   out << "\\usepackage{chessboard}" << endl;
   out << "\\usepackage{chessfss}" << endl;
   out << "\\begin{document}" << endl;

	out << "\\chessboard[setpieces={";
   int numPieces(0);
   for (size_t i = 0; i < pieces.size(); i++)
   {
      if (pieces.at(i) == ' ' || pieces.at(i) == 'X') 
         continue;
      if (numPieces != 0) out << ',';
      out << pieces.at(i);
      out << _Alphabets.at(i%maxValues.first);
      out << (i/maxValues.first + 1);
      numPieces++;
   }
   out << "}";
   if (!obstacles.empty())
   {
      out << ",pgfstyle={text},text=X,markfields={";
      for (size_t i = 0; i < obstacles.size(); i++)
      {
         if (i!=0) out << ',';
         out << _Alphabets.at(obstacles.at(i).first-1) << obstacles.at(i).second;
      }
      out << "}";
   }
   if (!paths.empty())
   {
      system("mkdir -p lg_temp");
      int offset(0);
      cout << "Generating temp files" << endl;
      for (Paths::const_iterator itr = paths.begin(); itr != paths.end(); ++itr)
      {
         stringstream ss;
         ss << "./lg_temp/" << offset;
         ofstream out(ss.str().c_str());

         const string &currentPath(*itr);
         for (size_t j = 0; j < currentPath.size(); j++)
         {
            if (isdigit(currentPath.at(j)))
               out << currentPath.at(j);
            else if (currentPath.at(j) == ',')
               out << ' ';
            else if (currentPath.at(j) == ')')
               out << endl;
         }
         out.close();
         offset++;
      }
      cout << "DONE Generating temp files" << endl;

      out << ",pgfstyle={straightmove},";
      out << "markmoves={";
      cout << "Generating moves" << endl;
      bool isFirst(true);
      for (size_t i = 0; i < paths.size(); i++)
      {
         cout << "Generating move " << i << endl;
         stringstream ss;
         ss << "./lg_temp/" << i;
         ifstream in(ss.str().c_str());
         int a1(0), a2(0);
         int b1(0), b2(0);
         bool isNewFile(true);
         while (!in.eof())
         {
            if (isNewFile)
            {
               in >> a1;
               in >> a2;
            }
            in >> b1;
            in >> b2;
            if (in.eof()) break;
            if(!isFirst)
            {
               out << ',';
            }
            out << _Alphabets.at(a1-1) << a2 << "-" << _Alphabets.at(b1-1) << b2;
            a1 = b1;
            a2 = b2;
            isFirst = false;
            isNewFile = false;
         }
         cout << "DONE Generating move " << i << endl;
      }
      cout << "DONE Generating moves" << endl;
      out << "}, arrow=to, linewidth=0.1em" << endl;
   }
コード例 #18
0
ファイル: PathOverlap.cpp プロジェクト: bcgsc/abyss
int main(int argc, char** argv)
{
	string commandLine;
	{
		ostringstream ss;
		char** last = argv + argc - 1;
		copy(argv, last, ostream_iterator<const char *>(ss, " "));
		ss << *last;
		commandLine = ss.str();
	}

	if (!opt::db.empty())
		opt::metaVars.resize(3);

	bool die = false;
	for (int c; (c = getopt_long(argc, argv,
					shortopts, longopts, NULL)) != -1;) {
		istringstream arg(optarg != NULL ? optarg : "");
		switch (c) {
			case '?': die = true; break;
			case 'g': arg >> opt::graphPath; break;
			case 'k': arg >> opt::k; break;
			case 'r': arg >> opt::repeatContigs; break;
			case 'v': opt::verbose++; break;
			case OPT_HELP:
				cout << USAGE_MESSAGE;
				exit(EXIT_SUCCESS);
			case OPT_VERSION:
				cout << VERSION_MESSAGE;
				exit(EXIT_SUCCESS);
			case OPT_DB:
				arg >> opt::db; break;
			case OPT_LIBRARY:
				arg >> opt::metaVars[0]; break;
			case OPT_STRAIN:
				arg >> opt::metaVars[1]; break;
			case OPT_SPECIES:
				arg >> opt::metaVars[2]; break;
		}
		if (optarg != NULL && !arg.eof()) {
			cerr << PROGRAM ": invalid option: `-"
				<< (char)c << optarg << "'\n";
			exit(EXIT_FAILURE);
		}
	}

	if (opt::k <= 0) {
		cerr << PROGRAM ": missing -k,--kmer option\n";
		die = true;
	}

	if (argc - optind < 2) {
		cerr << PROGRAM ": missing arguments\n";
		die = true;
	} else if (argc - optind > 2) {
		cerr << PROGRAM ": too many arguments\n";
		die = true;
	}

	if (die) {
		cerr << "Try `" << PROGRAM
			<< " --help' for more information.\n";
		exit(EXIT_FAILURE);
	}

	const char *adjPath = argv[optind++];
	if (opt::verbose > 0)
		cerr << "Reading `" << adjPath << "'..." << endl;
	ifstream fin(adjPath);
	assert_good(fin, adjPath);
	Graph g;
	fin >> g;
	Vertex::s_offset = g.num_vertices() / 2;

	string pathsFile(argv[optind++]);
	vector<string> pathIDs;
	Paths paths = readPaths(g, pathsFile, pathIDs);

	switch (opt::mode) {
	  case opt::OVERLAP:
		// Find overlapping paths, do not assemble.
		addPathOverlapEdges(g, paths, pathIDs,
				findOverlaps(g, paths));
		paths.clear();
		if (opt::graphPath.empty())
			opt::graphPath = "-";
		break;

	  case opt::ASSEMBLE:
		// Assemble overlapping paths.
		assembleOverlappingPaths(g, paths, pathIDs);
		break;

	  case opt::TRIM:
		// Trim overlapping paths.
		trimOverlaps(g, paths);
		// Remove paths consisting of a single contig.
		for_each_if(paths.begin(), paths.end(),
				mem_fun_ref(&ContigPath::clear),
				compose1(
					bind2nd(equal_to<ContigPath::size_type>(), 1),
					mem_fun_ref(&ContigPath::size)));
		// Add the paths to the graph.
		addPathOverlapEdges(g, paths, pathIDs, Overlaps());
		break;
	}

	// Output the paths.
	for (Paths::const_iterator it = paths.begin();
			it != paths.end(); ++it) {
		if (it->empty())
			continue;
		assert(it->size() != 1);
		cout << pathIDs[it - paths.begin()] << '\t' << *it << '\n';
	}
	assert(cout.good());

	// Output the graph.
	if (!opt::graphPath.empty()) {
		ofstream fout;
		ostream& out = opt::graphPath == "-" ? cout
		   	: (fout.open(opt::graphPath.c_str()), fout);
		assert_good(out, opt::graphPath);
		write_graph(out, g, PROGRAM, commandLine);
		assert_good(out, opt::graphPath);
	}

	// Output the repeat contigs.
	if (!opt::repeatContigs.empty()) {
		sort(s_trimmedContigs.begin(), s_trimmedContigs.end());
		s_trimmedContigs.erase(
				unique(s_trimmedContigs.begin(),
					s_trimmedContigs.end()), s_trimmedContigs.end());
		ofstream out(opt::repeatContigs.c_str());
		assert_good(out, opt::repeatContigs);
		for (vector<ContigID>::const_iterator it
				= s_trimmedContigs.begin();
				it != s_trimmedContigs.end(); ++it)
			out << get(g_contigNames, *it) << '\n';
		assert_good(out, opt::repeatContigs);
	}

	if (!opt::db.empty()) {
		init(db,
				opt::db,
				opt::verbose,
				PROGRAM,
				opt::getCommand(argc, argv),
				opt::metaVars);
		addToDb(db, "SS", opt::ss);
		addToDb(db, "K", opt::k);
	}

	return 0;
}
コード例 #19
0
ファイル: plot.cpp プロジェクト: jmundack/linguistic_geometry
Plot::Plot(const Paths &paths,
           const Cordinate maxValues,
           const Cordinate start,
           const Cordinate end,
           const std::vector<Cordinate> &obstacles,
           const string &outputFilename)
{
   cout << "Plotting start : " << start.first << "," << start.second << " to end : " << end.first << "," << end.second << endl;
    system("mkdir -p temp");
   int offset(0);
   for (Paths::const_iterator itr = paths.begin(); itr != paths.end(); ++itr)
   {
       stringstream ss;
       ss << "./temp/" << offset;
      ofstream out(ss.str().c_str());

      const string &currentPath(*itr);
      for (size_t j = 0; j < currentPath.size(); j++)
      {
         if (isdigit(currentPath.at(j)))
            out << currentPath.at(j);
         else if (currentPath.at(j) == ',')
            out << ' ';
         else if (currentPath.at(j) == ')')
            out << endl;
      }
      out.close();
      offset++;
   }
   ofstream profile("profile.gnu");
   profile << "set term jpeg" << endl;
   profile << "set out \'" << outputFilename << "'" << endl;
   profile << "set xrange[0.5:" << float(maxValues.first) +0.5 << "]" << endl;
   profile << "set yrange[0.5:" << float(maxValues.second) +0.5 << "]" << endl;
   profile << "set grid" << endl;
//   profile << "set object circle at " << start.first << "," << start.second << " size 0.2 fillcolor rgbcolor \'red\' fill solid" << endl;
//   profile << "set object circle at " << end.first << "," << end.second << " size 0.2 fillcolor rgbcolor \'red\' fill solid" << endl;
   for (size_t i = 0; i < obstacles.size(); i++)
   {
       const pair<int,int> &ob(obstacles.at(i));
       profile << "set object rect from "  << ob.first-0.5 << "," << ob.second - 0.5 << " to "
                  << ob.first+0.5 << "," << ob.second + 0.5 << " fc rgbcolor \'gray\'" << endl;
   }

   profile << "set xtics (";
   for (int i = 0; i < maxValues.first; i++)
   {
       if (i!=0)
           profile << ',';
       profile << "'" << i+1 << "'" << (float(i)+0.5);
   }
   profile << ")" << endl;
   profile << "set ytics (";
   for (int i = 0; i < maxValues.second; i++)
   {
       if (i!=0)
           profile << ',';
       profile << "'" << i+1 << "'" << (float(i)+0.5);
   }
   profile << ")" << endl;
   profile << "plot ";
   for (size_t i = 0; i < paths.size(); i++)
   {
       if (i !=0)
           profile << ",";
       profile << "'" << "temp/" << i << "\' w linespoints lc \'red\' title \'\' ";
   }
   profile.close();
   system("gnuplot < profile.gnu");
   string openJpeg = "gnome-open " + outputFilename;
   system(openJpeg.c_str());
}
コード例 #20
0
ファイル: mp3d.cpp プロジェクト: JoeBargo/enh
int main(int argc, char* argv[]) {
  // Parse any command-line options.
  namespace po = boost::program_options;
  po::options_description desc("Allowed options");
  desc.add_options()
    ("help", "show help")
    ("debug-httpd", po::value<bool>(&mp3d_debug_httpd), "show httpd debug output")
    ("root", po::value<std::string>(&mp3d_music_root), "root of file system mp3 tree")
    ("port", po::value<int>(&mp3d_port), "httpd port number")
  ;
  po::variables_map args;
  po::store(po::parse_command_line(argc, argv, desc), args);
  po::notify(args);
  if (args.count("help")) {
    std::cout << desc << std::endl;
    return 1;
  }

  // Index all the mp3s.
  Paths paths;
  find_mp3_files(mp3d_music_root, paths);
  std::cerr << ".mp3 files found: " << paths.size() << std::endl;

  int old_percentage = -1;
  size_t id = 0;
  for (Paths::const_iterator it = paths.begin(); it != paths.end(); ++it) {
    Mp3Info mp3;
    mp3.filename = (*it).string();

    const ID3_Tag tag(mp3.filename.c_str());

    ID3_Tag::ConstIterator* it = tag.CreateIterator();
    for (size_t i = 0; i < tag.NumFrames(); ++i) {
      const ID3_Frame* frame = it->GetNext();
      if (frame != 0) {
        std::string* dst;
        switch (frame->GetID()) {
        case ID3FID_ALBUM: dst = &mp3.album; break;
        case ID3FID_LEADARTIST: dst = &mp3.artist; break;
        case ID3FID_TITLE: dst = &mp3.title; break;
        default: continue;
        }
        char* text = ID3_GetString(frame, ID3FN_TEXT);
        dst->assign(text);
        ID3_FreeString(text);
      }
    }
    
    // FIXME: maybe a hash, to enable bookmarks?
    mp3.id = id++;
    
    all_mp3s.push_back(mp3);
    
    // Show progress. Not really useful when we're not debugging.
    // FIXME: start the web server straight away, and say "Indexing..." there.
    const int new_percentage = (100*all_mp3s.size())/paths.size();
    if (new_percentage != old_percentage) {
      std::cout << "\rScanned: " << new_percentage << "%" << std::flush;
      old_percentage = new_percentage;
    }
  }
  std::cout << "\r.mp3 files scanned: " << all_mp3s.size() << std::endl;

  // Set up the static files we need to serve.
  read_static_file("/static/add.png",
                   "/usr/share/icons/gnome/16x16/actions/gtk-add.png");
  read_static_file("/static/play.png",
                   "/usr/share/icons/gnome/16x16/actions/gtk-media-play-ltr.png");
  read_static_file("/static/remove.png",
                   "/usr/share/icons/gnome/16x16/actions/gtk-remove.png");
  static_file_map["/static/site.css"] = make_css();
  
  // Start the mp3 player thread.
  boost::thread mp3_player_thread(mp3_play_loop);
  
  // Start the HTTP server.
  std::cerr << "Starting HTTP server on port " << mp3d_port << "..." << std::endl;
  const int mhd_flags = MHD_USE_SELECT_INTERNALLY;
  MHD_Daemon* daemon = MHD_start_daemon(mhd_flags, mp3d_port, 0, 0, &handle_request, 0, MHD_OPTION_END);
  if (daemon == 0) {
    fail("MHD_start_daemon failed!");
  }
  
  getchar(); // Wait for the user to hit enter.
  
  MHD_stop_daemon(daemon);
  //mp3_player_thread.join();
  return 0;
}