Advertisement
Guest User

Main.cpp

a guest
Jul 29th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <sys/stat.h>
  6.  
  7.  
  8. #include "ConvertToAStarMap.h"
  9.  
  10. inline bool fileExists (const std::string& name)
  11. {
  12.     std::ifstream f(name.c_str());
  13.  
  14.     return f.good();
  15. }
  16.  
  17. void usage()
  18. {
  19.     std::cout << "Usage: ProcessOdomMap input_map output_map" << std::endl;
  20. }
  21.  
  22. bool validateInput(int argc, char* argv[])
  23. {
  24.     if (argc != 3)
  25.     {
  26.         usage();
  27.        
  28.         return false;
  29.     }
  30.  
  31.     if (!fileExists(argv[1]))
  32.     {
  33.         std::cout << "The input file '" << argv[1] << "' doesn't exist" << std::endl;
  34.  
  35.         return false;
  36.     }
  37.  
  38.     if (fileExists(argv[2]))
  39.     {
  40.         std::cout << "The output file '" << argv[2] << "' already exist" << std::endl;
  41.  
  42.         return false;
  43.     }
  44.  
  45.     return true;
  46. }
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50.     if (!validateInput(argc, argv))
  51.     {
  52.         return -1;
  53.     }
  54.  
  55.     std::string output_file(argv[2]);
  56.  
  57.     std::ifstream input_file(argv[1]);
  58.     std::stringstream buffer;
  59.     buffer << input_file.rdbuf();
  60.  
  61.     ConvertToAStarMap convert;
  62.  
  63.     convert.Convert(buffer.str(), output_file);
  64.  
  65.     //std::string line = "-3.6,3.6;-3.5,2.6;-3.5,1.6;-3.5,0.6;-3.6,-0.4;-3.6,-1.4;-3.6,-2.4;-2.6,-3.4;-2.5,-2.4;-2.4,-1.4;-2.4,-0.4;-2.4,0.6;-2.4,1.6;-2.4,2.6;-1.6,3.6;-1.4,2.6;-1.5,1.6;-1.5,0.6;-1.6,-0.4;-1.5,-1.4;-1.5,-2.4;-1.5,-3.4;-0.5,-2.8;-0.4,-1.8;0.6,-1.5;0.6,-2.5;1.5,-1.5;1.6,-0.5;1.6,0.5;1.0,1.5;0.0,1.6;-0.4,2.6;0.6,2.6;1.6,3.4;2.6,2.4;2.6,1.4;2.6,0.4;2.5,-0.6;2.5,-1.6;2.5,-2.6;3.4,-1.6;3.5,-0.6;3.5,0.4;3.5,1.4;3.5,2.5;3.5,3.5;";
  66.     //convert.Convert(line);
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement