コード例 #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
ファイル: path_util.cpp プロジェクト: paulmecklenburg/svg2nc
bool SubtractFrom(const Paths &a, Paths *b) {
  if (a.empty() || b->empty())
    return true;
  Clipper c;
  return c.AddPaths(*b, ptSubject, true) &&
    c.AddPaths(a, ptClip, true) &&
    c.Execute(ctDifference, *b);
}
コード例 #3
0
ファイル: TerraGenerator.cpp プロジェクト: Euphe/utymap
// process the rest area.
void TerraGenerator::buildBackground(Path& tileRect)
{
    backGroundClipper_.AddPath(tileRect, ptSubject, true);
    Paths background;
    backGroundClipper_.Execute(ctDifference, background, pftNonZero, pftNonZero);
    backGroundClipper_.Clear();

    if (!background.empty())
        populateMesh(background, createRegionContext(style_, ""));
}
コード例 #4
0
ファイル: bfsDiGraphTest.cpp プロジェクト: dendibakh/Misc
		bool equalStacks(Paths<DiGraph>::VertexStack lhs, Paths<DiGraph>::VertexStack rhs)
		{
			if (lhs.size() != rhs.size())
				return false;
			while (!lhs.empty())
			{
				if (lhs.top() != rhs.top())
					return false;
				lhs.pop();
				rhs.pop();
			}
			return true;
		}
コード例 #5
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();
}
コード例 #6
0
ファイル: path_util.cpp プロジェクト: paulmecklenburg/svg2nc
bool UnionInto(const Paths &paths, Paths *result) {
  if (paths.empty())
    return true;

  if (result->empty()) {
    *result = paths;
    return true;
  }

  Clipper c;
  if (!c.AddPaths(*result, ptSubject, true) ||
      !c.AddPaths(paths, ptClip, true)) {
    return false;
  }
  Paths solution;
  if (!c.Execute(ctUnion, solution)) {
    return false;
  }
  result->swap(solution);
  return true;
}
コード例 #7
0
		void Instance::Language::EnumerateResources(Paths& paths) const
		{
			for (uint i=0; i < 2 && paths.empty(); ++i)
			{
				struct FileFinder
				{
					WIN32_FIND_DATA data;
					HANDLE const handle;

					FileFinder(wcstring const path)
					: handle(::FindFirstFile( path, &data )) {}

					~FileFinder()
					{
						if (handle != INVALID_HANDLE_VALUE)
							::FindClose( handle );
					}
				};

				Path path( Instance::GetExePath(i ? L"*.*" : L"language\\*.*") );

				FileFinder findFile( path.Ptr() );

				if (findFile.handle != INVALID_HANDLE_VALUE)
				{
					do
					{
						if (!(findFile.data.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_DIRECTORY)))
						{
							path.File() = findFile.data.cFileName;

							if (path.Extension() == L"nlg")
								paths.push_back( path );
						}
					}
					while (::FindNextFile( findFile.handle, &findFile.data ));
				}
			}
		}
コード例 #8
0
ファイル: infer.cpp プロジェクト: gadomski/entwine
void Kernel::infer(std::vector<std::string> args)
{
    if (args.empty())
    {
        std::cout << getUsageString() << std::flush;
        return;
    }

    if (args.size() == 1)
    {
        if (args[0] == "help" || args[0] == "-h" || args[0] == "--help")
        {
            std::cout << getUsageString() << std::flush;
            return;
        }
    }

    // TODO Allow multiple.
    Paths paths;

    std::size_t threads(4);
    Json::Value jsonReprojection;
    std::string user;
    std::string tmpPath("tmp");
    bool trustHeaders(true);

    std::string output;

    std::size_t a(0);

    while (a < args.size())
    {
        const std::string arg(args[a]);

        if (arg.front() != '-')
        {
            // If this is not an option argument, use it as the path.
            if (paths.empty())
            {
                paths.push_back(arg);
            }
            else
            {
                throw std::runtime_error(
                        "Only one path allowed - found both '" +
                        paths.front() + "' and '" + arg + "'");
            }
        }
        else if (arg == "-a")
        {
            if (++a < args.size())
            {
                tmpPath = args[a];
            }
            else
            {
                throw std::runtime_error("Invalid tmp specification");
            }
        }
        else if (arg == "-o")
        {
            if (++a < args.size())
            {
                output = args[a] + ".entwine-inference";
            }
            else
            {
                throw std::runtime_error("Invalid output specification");
            }
        }
        else if (arg == "-r")
        {
            if (++a < args.size())
            {
                const bool onlyOutput(
                        a + 1 >= args.size() ||
                        args[a + 1].front() == '-');

                if (onlyOutput)
                {
                    jsonReprojection["out"] = args[a];
                }
                else
                {
                    jsonReprojection["in"] = args[a];
                    jsonReprojection["out"] = args[++a];
                }
            }
            else
            {
                throw std::runtime_error("Invalid reprojection argument");
            }
        }
        else if (arg == "-h")
        {
            jsonReprojection["hammer"] = true;
        }
        else if (arg == "-x")
        {
            trustHeaders = false;
        }
        else if (arg == "-t")
        {
            if (++a < args.size())
            {
                threads = Json::UInt64(std::stoul(args[a]));
            }
            else
            {
                throw std::runtime_error("Invalid thread count specification");
            }
        }
        else if (arg == "-u")
        {
            if (++a < args.size())
            {
                user = args[a];
            }
            else
            {
                throw std::runtime_error("Invalid AWS user argument");
            }
        }

        ++a;
    }

    entwine::arbiter::fs::mkdirp(tmpPath);

    std::unique_ptr<Reprojection> reprojection;

    if (jsonReprojection.isMember("out"))
    {
        reprojection.reset(new Reprojection(jsonReprojection));
    }

    Json::Value arbiterConfig;
    arbiterConfig["s3"]["profile"] = user;

    auto arbiter(std::make_shared<entwine::arbiter::Arbiter>(arbiterConfig));

    const auto reprojString(getReprojString(reprojection.get()));
    const auto trustHeadersString(trustHeaders ? "yes" : "no");

    std::cout << "Inferring from: " << paths.front() << std::endl;
    std::cout << "\tTemp path: " << tmpPath << std::endl;
    std::cout << "\tThreads: " << threads << std::endl;
    std::cout << "\tReprojection: " << reprojString << std::endl;
    std::cout << "\tTrust file headers? " << trustHeadersString << std::endl;

    const bool allowDelta(true);
    const bool verbose(true);
    const bool cesiumify(false);

    Inference inference(
            paths,
            reprojection.get(),
            trustHeaders,
            allowDelta,
            tmpPath,
            threads,
            verbose,
            cesiumify,
            arbiter.get());

    inference.go();

    if (output.size())
    {
        std::cout << "Writing details to " << output << "..." << std::endl;
        Json::Value json(inference.toJson());
        arbiter->put(output, json.toStyledString());
    }

    std::cout << "Schema: " << inference.schema() << std::endl;
    std::cout << "Bounds: " << inference.bounds() << std::endl;
    std::cout << "Points: " << commify(inference.numPoints()) << std::endl;

    if (reprojection)
    {
        std::cout << "Reprojection: " << *reprojection << std::endl;
    }

    if (const auto delta = inference.delta())
    {
        std::cout << "Scale:  " << delta->scale() << std::endl;
        std::cout << "Offset: " << delta->offset() << std::endl;
    }
}
コード例 #9
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;
   }
コード例 #10
0
ファイル: tilesetter.cpp プロジェクト: CruzR/wc3lib
int main(int argc, char *argv[])
{
	// Set the current locale.
	setlocale(LC_ALL, "");
	// Set the text message domain.
	bindtextdomain("tilesetter", LOCALE_DIR);
	textdomain("tilesetter");

	static const char* version = "0.1";
	std::cout << boost::format(_("Tilesetter version %1%")) % version << std::endl;
	std::cout << _(
	"Copyright (C) 2009 by Tamino Dauth\n"
	"[email protected]\n"
	"\n"
	"This program is free software; you can redistribute it and/or modify\n"
	"it under the terms of the GNU General Public License as published by\n"
	"the Free Software Foundation; either version 2 of the License, or\n"
	"(at your option) any later version.\n"
	"\n"
	"This program is distributed in the hope that it will be useful,\n"
	"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
	"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
	"GNU General Public License for more details.\n"
	"\n"
	"You should have received a copy of the GNU General Public License\n"
	"along with this program; if not, write to the\n"
	"Free Software Foundation, Inc.,\n"
	"59 Temple Place - Suite 330, Boston, MA  02111-1307, USA."
	) << std::endl;

	typedef std::vector<boost::filesystem::path> Paths;
	typedef std::vector<std::string> Strings;
	// TODO throws exception when using escaped white spaces! - string work around
	Strings environmentStrings;
	Paths environments;

	const boost::program_options::command_line_style::style_t pstyle = boost::program_options::command_line_style::style_t(
	boost::program_options::command_line_style::unix_style
	);

	boost::program_options::options_description desc("Allowed options");
	desc.add_options()
	("version,V", _("Shows current version of tilesetter."))
	("help,h",_("Shows this text."))
	// options

	// operations
	("reassign,r", _("Reads ground and cliff types from the first environment file and assigns them to all following."))

	// input
	("files,f", boost::program_options::value<Strings>(&environmentStrings), _("Expected environment files."))
	;

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

	boost::program_options::variables_map vm;

	try
	{
		boost::program_options::store(boost::program_options::command_line_parser(argc, argv).style(pstyle).options(desc).positional(p).run(), vm);
	}
	catch (std::exception &exception)
	{
		std::cerr << boost::format(_("Error while parsing program options: \"%1%\"")) % exception.what() << std::endl;

		return EXIT_FAILURE;
	}

	boost::program_options::notify(vm);

	// WORKAROUND
	environments.resize(environmentStrings.size());
	environments.assign(environmentStrings.begin(), environmentStrings.end());

	if (vm.count("version"))
	{
		std::cout << boost::format(_(
		"tilesetter %1%.\n"
		"Copyright © 2009 Tamino Dauth\n"
		"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
		"This is free software: you are free to change and redistribute it.\n"
		"There is NO WARRANTY, to the extent permitted by law."
		)) % version << std::endl;

		return EXIT_SUCCESS;
	}

	if (vm.count("help"))
	{
		std::cout << desc << std::endl;
		std::cout << _("\nReport bugs to [email protected] or on https://wc3lib.org") << std::endl;

		return EXIT_SUCCESS;
	}

	if (environments.empty())
	{
		std::cerr << _("Missing environments arguments.") << std::endl;

		return EXIT_FAILURE;
	}

	if (vm.count("reassign"))
	{
		boost::ptr_vector<map::Environment> envs;
		envs.reserve(environments.size());

		BOOST_FOREACH(Paths::const_reference path, environments)
		{
			if (!boost::filesystem::is_regular_file(path))
			{
				std::cerr << boost::format(_("File %1% does not seem to be a regular file.")) % path << std::endl;

				return EXIT_FAILURE;
			}

			boost::filesystem::ifstream ifstream;
			ifstream.exceptions(boost::filesystem::ifstream::badbit | boost::filesystem::ifstream::failbit | boost::filesystem::ifstream::eofbit);

			try
			{
				ifstream.open(path, std::ios::in | std::ios::binary);
				std::auto_ptr<map::Environment> env(new map::Environment());
				env->read(ifstream);
				envs.push_back(env);
			}
			catch (std::exception &exception)
			{
				std::cerr << boost::format(_("Error occured while opening file %1%:\n\"%2%\"")) % path % exception.what() << std::endl;

				return EXIT_FAILURE;
			}
		}

		if (envs.size() < 2)
		{
			std::cerr << _("We need at least 2 environments.") << std::endl;

			return EXIT_FAILURE;
		}

		for (std::size_t i = 1; i < envs.size(); ++i)
		{
			envs[i].cliffTilesetsIds().assign(envs[0].cliffTilesetsIds().begin(), envs[0].cliffTilesetsIds().end());
			envs[i].groundTilesetsIds().assign(envs[0].groundTilesetsIds().begin(), envs[0].groundTilesetsIds().end());

			boost::filesystem::ofstream ofstream;
			ofstream.exceptions(boost::filesystem::ofstream::badbit | boost::filesystem::ofstream::failbit | boost::filesystem::ofstream::eofbit);

			try
			{
				ofstream.open(environments[i], std::ios::out | std::ios::binary);
				envs[i].write(ofstream);
			}
			catch (std::exception &exception)
			{
				std::cerr << boost::format(_("Error occured while saving file %1%:\n\"%2%\"")) % environments[i] % exception.what() << std::endl;

				return EXIT_FAILURE;
			}
		}
	}
コード例 #11
0
ファイル: main.cpp プロジェクト: JanKolomaznik/MedV4D
int
main( int argc, char** argv)
{
  fs::path full_path( fs::initial_path<fs::path>() );

  if ( argc > 1 )
    full_path = fs::system_complete( fs::path( argv[1], fs::native ) );
  else
    PrintUsage();

  // specification of hi, low date of studies
  if( argc > 2)
  {
    string s(argv[2]);
    if( s.compare( "--info") == 0 )
    {
      entryCont.infoOnly = true;
    }
    else
    {
      if( argc > 3)
      {
        entryCont.dateFrom = argv[2];
        entryCont.dateTo = argv[3];
      }
      else
        PrintUsage();
    }
  }

  // recursively (through queue) go through all files in subtree
  // of specified directory specified

  try {
    if ( fs::is_directory( full_path ) )
    {
      paths.push( full_path);
    }
    else // must be a file
    {
      entryCont.SolveFile( full_path.string(), "buddy" );
    }

    fs::path currPath;
    while( ! paths.empty() )
    {
      currPath = paths.front();
      SolveDir( currPath);
      paths.pop(); // remove this dir from queue
    }
    
  } catch( std::exception &ex) {
    LOG( ex.what());
  }

  // flush info
  {
    ofstream o("output.txt");
    entryCont.FlushMaps( o);
    o.close();
  }
  
  return 0;
}