datafile.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @file
  3. * @author Caleb Fangmeier <caleb@fangmeier.tech>
  4. * @version 0.1
  5. *
  6. * @section LICENSE
  7. *
  8. *
  9. * MIT License
  10. *
  11. * Copyright (c) 2017 Caleb Fangmeier
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy
  14. * of this software and associated documentation files (the "Software"), to deal
  15. * in the Software without restriction, including without limitation the rights
  16. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. * copies of the Software, and to permit persons to whom the Software is
  18. * furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in all
  21. * copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. * SOFTWARE.
  30. *
  31. * @section DESCRIPTION
  32. */
  33. #ifndef datafile_hpp
  34. #define datafile_hpp
  35. #include <vector>
  36. #include <string>
  37. #include <fstream>
  38. #include <iostream>
  39. namespace fv::util{
  40. struct DataFileDescriptor{
  41. std::string filename;
  42. std::string label;
  43. std::string category; //TODO: Populate this
  44. DataFileDescriptor(const std::string filename, const std::string label)
  45. :filename(filename), label(label),category("") { }
  46. DataFileDescriptor(const std::string line):category(""){
  47. std::string::size_type col_pos = line.find(":");
  48. if(col_pos == std::string::npos){
  49. this->filename = line;
  50. this->label = "";
  51. } else{
  52. this->filename = line.substr(0, col_pos);
  53. this->label = line.substr(col_pos+1);
  54. }
  55. }
  56. };
  57. // input list should be a file containing line-delineated filename for all Data
  58. // Files with an optional label separated by a comma.
  59. std::vector<DataFileDescriptor> read_input_list(const std::string &filename){
  60. std::ifstream istrm(filename, std::ios::in);
  61. std::string line;
  62. std::vector<DataFileDescriptor> dfds;
  63. std::string prefix = filename.substr(0, filename.find_last_of("/")+1);
  64. while(std::getline(istrm, line)){
  65. if(line[0] != '#')
  66. dfds.push_back(DataFileDescriptor(prefix+line));
  67. }
  68. return dfds;
  69. }
  70. }
  71. #endif // datafile_hpp