37 #include <boost/algorithm/string.hpp>
38 #include <boost/program_options.hpp>
45 namespace po = boost::program_options;
47 int main(
int argc,
char* argv[])
49 po::options_description desc(
"Available options");
51 (
"help,h",
"Produce this help message.")
52 (
"modules-list,l",
"Print the list of available modules.")
53 (
"modules-opt,p", po::value<string>(),
54 "Print options for a module.")
55 (
"module,m", po::value<vector<string> >(),
56 "Specify modules which are to be used.")
57 (
"verbose,v",
"Enable verbose mode.");
59 po::options_description hidden(
"Hidden options");
61 (
"input-file", po::value<vector<string> >(),
"Input filename");
63 po::options_description cmdline_options;
64 cmdline_options.add(hidden).add(desc);
66 po::options_description visible(
"Allowed options");
69 po::positional_options_description p;
70 p.add(
"input-file", -1);
76 po::store(po::command_line_parser(argc, argv).
77 options(cmdline_options).positional(p).run(), vm);
80 catch (
const std::exception& e)
82 cerr << e.what() << endl;
88 if (vm.count(
"modules-list"))
94 if (vm.count(
"modules-opt"))
97 boost::split(tmp1, vm[
"modules-opt"].as<string>(), boost::is_any_of(
":"));
101 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
102 <<
"together with the filename; for example in:vtk." << endl;
106 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
108 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
118 else if (tmp1[0] ==
"out")
122 else if (tmp1[0] ==
"proc")
130 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
135 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
136 cerr <<
"Usage: MeshConvert [options] inputfile.ext1 outputfile.ext2"
142 vector<string> inout = vm[
"input-file"].as<vector<string> >();
144 if (inout.size() < 2)
146 cerr <<
"ERROR: You must specify an input and output file." << endl;
161 vector<ModuleSharedPtr> modules;
162 vector<string> modcmds;
164 if (vm.count(
"verbose"))
166 mesh->m_verbose =
true;
169 if (vm.count(
"module"))
171 modcmds = vm[
"module"].as<vector<string> >();
175 modcmds.insert (modcmds.begin(), inout[0]);
176 modcmds.push_back(inout[1]);
178 for (
int i = 0; i < modcmds.size(); ++i)
185 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
187 if (i == 0 || i == modcmds.size() - 1)
198 if (tmp1.size() == 1)
200 int dot = tmp1[0].find_last_of(
'.') + 1;
201 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
203 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
207 module.second = tmp1[1];
208 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
215 module.second = tmp1[0];
220 modules.push_back(mod);
223 for (
int j = offset; j < tmp1.size(); ++j)
226 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
228 if (tmp2.size() == 1)
230 mod->RegisterConfig(tmp2[0],
"1");
232 else if (tmp2.size() == 2)
234 mod->RegisterConfig(tmp2[0], tmp2[1]);
238 cerr <<
"ERROR: Invalid module configuration: format is "
239 <<
"either :arg or :arg=val" << endl;
249 for (
int i = 0; i < modules.size(); ++i)
251 modules[i]->Process();
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
int main(int argc, char *argv[])
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
boost::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()