Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utYAMLconfig.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifdef HAVE_YAMLCPP
  2. #include "yaml-cpp/yaml.h"
  3. #include "yaml-cpp/eventhandler.h"
  4. #include <fstream>
  5. #include <iostream>
  6. #include <vector>
  7. struct Params {
  8. bool hasFile;
  9. std::string fileName;
  10. };
  11. Params ParseArgs(int argc, char **argv) {
  12. Params p;
  13. std::vector<std::string> args(argv + 1, argv + argc);
  14. return p;
  15. }
  16. class NullEventHandler: public YAML::EventHandler
  17. {
  18. public:
  19. virtual void OnDocumentStart(const YAML::Mark&) {}
  20. virtual void OnDocumentEnd() {}
  21. virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
  22. virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
  23. virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
  24. virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
  25. virtual void OnSequenceEnd() {}
  26. virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
  27. virtual void OnMapEnd() {}
  28. };
  29. void parse(std::istream& input)
  30. {
  31. try {
  32. YAML::Node doc = YAML::Load(input);
  33. std::cout << doc << "\n";
  34. } catch(const YAML::Exception& e) {
  35. std::cerr << e.what() << "\n";
  36. }
  37. }
  38. int main(int argc, char **argv)
  39. {
  40. Params p = ParseArgs(argc, argv);
  41. if(argc > 1) {
  42. std::ifstream fin;
  43. fin.open(argv[1]);
  44. parse(fin);
  45. } else {
  46. parse(std::cin);
  47. }
  48. return 0;
  49. }
  50. #else
  51. int main() {
  52. }
  53. #endif