Lens AI Profiler Cpp
modeloutput_parser.h
1 #ifndef MODELOUTPUT_PARSER_H
2 #define MODELOUTPUT_PARSER_H
3 #include <map>
4 #include <vector>
5 #include <string>
6 #include <type_traits>
7 
8 // Base class for parsers
10 public:
11  virtual ~ModelOutputParser() = default;
12 
13  // Default parsing method for raw outputs (if needed)
14  // virtual std::vector<std::pair<float, int>> parse(const void* raw_output) const = 0;
15 
16  // Template function to check if we need to pass-through or process the input dynamically
17  template <typename T>
18  auto processOutput(const T& output) const {
19  if constexpr (std::is_same_v<T, std::map<std::string, std::vector<std::string>>>) {
20  // If the input is already in the desired format, pass through
21  return passThrough(output);
22  } else {
23  // Otherwise, process the output (e.g., parsing raw output)
24  return parseRawOutput(output);
25  }
26  }
27 
28 protected:
29  // Pass-through method for already formatted output (no processing needed)
30  std::map<std::string, std::vector<std::string>> passThrough(const std::map<std::string, std::vector<std::string>>& output) const {
31  return output; // Return as-is
32  }
33 
34  // Example of processing raw output (could be for parsing, etc.)
35  virtual std::vector<std::pair<float, int>> parseRawOutput(const void* raw_output) const = 0;
36 };
37 #endif // MODEL_OUTPUT_PARSER_H
Definition: modeloutput_parser.h:9