40 #include <RobotAPI/interface/aron.h>
50 main(
int argc,
char* argv[])
55 "An application interface for the aron and armem code generation");
57 std::string input_default =
"/path/to/some/xml/file.xml";
58 std::string output_default =
"/path/to/some/output/folder/";
61 "v,verbose",
"Enable verbose mode", cxxopts::value<bool>()->default_value(
"false"))(
62 "h,help",
"Print usage");
66 cxxopts::value<std::string>()->default_value(input_default))(
69 cxxopts::value<std::string>()->default_value(output_default))(
70 "I,include",
"include path",
cxxopts::value<std::vector<std::string>>());
73 "f,force",
"Enforce the generation", cxxopts::value<bool>()->default_value(
"false"));
75 auto result = options.
parse(argc, argv);
77 if (result.count(
"help"))
79 std::cout << options.
help() << std::endl;
83 bool verbose = result[
"v"].as<
bool>();
84 bool force = result[
"f"].as<
bool>();
86 std::string
filename = result[
"i"].as<std::string>();
87 std::string output = result[
"o"].as<std::string>();
89 if (
filename == input_default || output == output_default)
91 std::cout << options.
help() << std::endl;
97 std::cout <<
"Welcome to the AronCodeGenerator!" << std::endl;
98 std::cout <<
"Received the following parameters:" << std::endl;
99 std::cout <<
"- IO:" << std::endl;
100 std::cout <<
"-- Input: " <<
filename << std::endl;
101 std::cout <<
"-- Output: " << output << std::endl;
102 std::cout <<
"- Generation:" << std::endl;
103 std::cout <<
"-- Force: " << force << std::endl;
104 std::cout << std::endl;
109 std::cout <<
"Generating a new cpp file out of <" +
filename +
">" << std::endl;
112 std::filesystem::path input_file(
filename);
113 std::filesystem::path output_folder(output);
115 std::vector<std::filesystem::path> includePaths;
117 if (result.count(
"I") > 0)
119 for (
const auto& path : result[
"I"].as<std::vector<std::string>>())
121 includePaths.emplace_back(path);
126 if (!std::filesystem::exists(input_file) || !std::filesystem::is_regular_file(input_file))
128 std::cerr <<
"The input file does not exist or is not a regular file." << std::endl;
132 if (!std::filesystem::exists(output_folder) ||
133 !std::filesystem::is_directory(output_folder))
135 std::cerr <<
"The output folder does not exist or is not an directory." << std::endl;
139 if (input_file.extension().string() !=
".xml")
141 std::cerr <<
"The file you passed has the wrong type." << std::endl;
147 std::cout <<
"Parsing the XML file..." << std::endl;
151 reader.
parseFile(input_file, includePaths);
154 std::cout <<
"Parsing the XML file... done!" << std::endl;
157 std::cout <<
"--> They are: " << std::endl;
160 std::cout <<
"----> " << generateType.typeName << std::endl;
168 std::cout <<
"Running the type class generator..." << std::endl;
176 std::cout <<
"Running the type class generator... done!" << std::endl;
177 std::cout <<
"--> Found " << writer.
getTypeClasses().size() <<
" type objects."
179 std::cout <<
"--> They are: " << std::endl;
182 std::cout <<
"----> " <<
c->getName() << std::endl;
186 std::time_t current_time = std::time(0);
187 std::tm* now = std::localtime(¤t_time);
190 std::string fileDoc =
191 std::string(
"* This file is part of ArmarX. \n") +
"* \n" +
"* Copyright (C) 2012-" +
192 current_year +
", High Performance Humanoid Technologies (H2T), \n" +
193 "* Karlsruhe Institute of Technology (KIT), all rights reserved. \n" +
"* \n" +
194 "* ArmarX is free software; you can redistribute it and/or modify \n" +
195 "* it under the terms of the GNU General Public License version 2 as \n" +
196 "* published by the Free Software Foundation. \n" +
"* \n" +
197 "* ArmarX is distributed in the hope that it will be useful, but \n" +
198 "* WITHOUT ANY WARRANTY; without even the implied warranty of \n" +
199 "* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" +
200 "* GNU General Public License for more details. \n" +
"* \n" +
201 "* You should have received a copy of the GNU General Public License \n" +
202 "* along with this program. If not, see <http://www.gnu.org/licenses/>. \n" +
"* \n" +
203 "* @copyright http://www.gnu.org/licenses/gpl-2.0.txt \n" +
204 "* GNU General Public License \n" +
205 "* *********************************************************************** \n" +
206 "* WARNING: This file is autogenerated. \n" +
"* Original file: " +
filename +
" \n" +
207 "* Please do not edit since your changes may be overwritten on the next generation \n" +
208 "* If you have any questions please contact: Fabian Peller-Konrad (fabian dot "
209 "peller-konrad at kit dot edu) \n" +
210 "* ***********************************************************************";
220 std::cout <<
"Now exporting enums..." << std::endl;
223 w->body.line(
"/*************************************************************************");
224 w->body.line(
" * ALL GENERATED ENUMS ***************************************************");
225 w->body.line(
" ************************************************************************/");
230 std::string enum_file_generation_content = w->getString();
234 std::cout <<
"Now exporting enums... done!" << std::endl;
237 if (enums.size() > 0 && enum_file_generation_content ==
"")
239 std::cerr <<
"\033[31m"
240 <<
"Error code 11 - Found error in code generation. Aborting!"
241 <<
"\033[0m" << std::endl;
249 std::cout <<
"Now exporting classes..." << std::endl;
252 w->body.line(
"/* ************************************************************************");
253 w->body.line(
" * ALL GENERATED CLASSES *************************************************");
254 w->body.line(
" * ***********************************************************************/");
259 std::string class_file_generation_content =
260 simox::alg::remove_prefix(w->getString(), enum_file_generation_content);
264 std::cout <<
"Now exporting classes... done!" << std::endl;
267 if (classes.size() > 0 && class_file_generation_content ==
"")
269 std::cerr <<
"\033[31m"
270 <<
"Error code 21 - Found error in code generation. Aborting!"
271 <<
"\033[0m" << std::endl;
275 std::string new_file_full_content = w->getString();
277 std::string new_name_with_extension = input_file.filename().replace_extension(
"").string();
278 new_name_with_extension +=
".aron.generated.h";
279 std::string output_file_path = output +
"/" + new_name_with_extension;
280 std::filesystem::path output_file(output_file_path);
285 if (std::filesystem::exists(output_file))
287 std::ifstream ifs(output_file);
288 std::string file_content((std::istreambuf_iterator<char>(ifs)),
289 (std::istreambuf_iterator<char>()));
291 if (file_content == new_file_full_content)
295 std::cout <<
"\033[31m"
296 <<
"Error code 31 - File content not changed for <" +
297 output_file.string() +
">"
298 <<
"\033[0m" << std::endl;
306 ofs.open(output_file);
307 ofs << new_file_full_content;
312 std::cout <<
"\033[32m"
313 <<
"Finished generating <" + output_file.string() +
314 ">. The new file ist called <"
315 << output_file.string() <<
">"
316 <<
"\033[0m" << std::endl;
321 std::cerr <<
"\033[31m"
322 <<
"Error code 01 - Error in parsing cxxopts options: " << e.
what() <<
"\033[0m"