irioCoreCpp Library Module  2.1.0
parserManager.h
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 #include <unordered_map>
6 #include <set>
7 #include <unordered_set>
8 #include <iostream>
9 
10 #include "bfp.h"
11 
12 namespace irio {
16 enum class GroupResource {
17  Common,
18  AI,
19  AO,
20  AuxAI,
21  AuxAO,
22  DI,
23  DO,
24  AuxDI,
25  AuxDO,
26  DMA,
27  DAQ,
28  IMAQ,
29  IO,
30  SG,
31  CRIO,
32  FlexRIO
33 };
34 
49  bool operator()(const std::string& a, const std::string& b) const;
50 };
51 
55 struct GroupInfo {
56  std::set<std::string, CustomStringComparator>
58  std::set<std::string, CustomStringComparator>
60  std::unordered_map<std::string, std::string>
63  GroupInfo();
64 };
65 
77  public:
83  explicit ParserManager(const bfp::BFP &bfp);
84 
95  bool findRegister(const std::string &resourceName,
96  const GroupResource &group, bfp::Register *reg,
97  const bool optional = false);
98 
109  bool findDMA(const std::string &resourceName,
110  const GroupResource &group, bfp::DMA *dma,
111  const bool optional = false);
112 
123  bool findRegisterAddress(const std::string &resourceName,
124  const GroupResource &group, std::uint32_t *address,
125  const bool optional = false);
126 
137  bool findDMANum(const std::string &resourceName,
138  const GroupResource &group, std::uint32_t *address,
139  const bool optional = false);
140 
154  bool findRegisterEnumAddress(const std::string &resourceName,
155  std::uint32_t nResource, const GroupResource &group,
156  std::unordered_map<std::uint32_t, const std::uint32_t> *mapInsert,
157  const bool optional = false);
158 
172  bool findDMAEnumNum(const std::string &resourceName,
173  std::uint32_t nResource, const GroupResource &group,
174  std::unordered_map<std::uint32_t, const std::uint32_t> *mapInsert,
175  const bool optional = false);
176 
187  const std::unordered_map<std::uint32_t, const std::uint32_t> &mapA,
188  const std::string &nameTermA,
189  const std::unordered_map<std::uint32_t, const std::uint32_t> &mapB,
190  const std::string &nameTermB,
191  const GroupResource &group);
192 
200  void logResourceError(const std::string &resourceName,
201  const std::string &errMsg,
202  const GroupResource &group);
203 
208  bool hasErrorOccurred() const;
209 
216  void printInfo(std::ostream &os = std::cout,
217  const bool onlyErrors = false) const;
218 
223  void printInfoError(std::ostream &os = std::cerr) const;
224 
229  void printInfoXML(const std::string& filename) const;
230 
236  void logResourceFound(const std::string &resourceName,
237  const GroupResource &group);
238 
244  void logResourceNotFound(const std::string &resourceName,
245  const GroupResource &group);
246 
247  private:
251  std::unordered_map<GroupResource, GroupInfo> m_groupInfo;
253  bool m_error = false;
254 };
255 
256 } // namespace irio
Responsible for managing the parsing of resources for a bitfile.
Definition: parserManager.h:76
void logResourceNotFound(const std::string &resourceName, const GroupResource &group)
Logs that a resource has not been found.
bool findRegister(const std::string &resourceName, const GroupResource &group, bfp::Register *reg, const bool optional=false)
Finds a register with the given resource name.
bool findDMAEnumNum(const std::string &resourceName, std::uint32_t nResource, const GroupResource &group, std::unordered_map< std::uint32_t, const std::uint32_t > *mapInsert, const bool optional=false)
Finds the DMA number of a DMA with the given name, The resource follows an enumeration naming convent...
void printInfoXML(const std::string &filename) const
Prints resources found, not found and incompatibilities in XML format.
void compareResourcesMap(const std::unordered_map< std::uint32_t, const std::uint32_t > &mapA, const std::string &nameTermA, const std::unordered_map< std::uint32_t, const std::uint32_t > &mapB, const std::string &nameTermB, const GroupResource &group)
Compares two resource maps and logs any differences.
bool m_error
True if some resource was not found.
bool findDMANum(const std::string &resourceName, const GroupResource &group, std::uint32_t *address, const bool optional=false)
Finds the DMA number of a resource with the given name.
bool hasErrorOccurred() const
Checks if an error has occurred during parsing.
bool findRegisterAddress(const std::string &resourceName, const GroupResource &group, std::uint32_t *address, const bool optional=false)
Finds the address of a register with the given resource name.
std::unordered_map< GroupResource, GroupInfo > m_groupInfo
Map to divide information of found resources per group.
void printInfo(std::ostream &os=std::cout, const bool onlyErrors=false) const
Prints resources found, not found and incompatibilities.
bfp::BFP m_bfp
The BFP object used by the parser manager.
void logResourceError(const std::string &resourceName, const std::string &errMsg, const GroupResource &group)
Logs an error related to a resource.
bool findRegisterEnumAddress(const std::string &resourceName, std::uint32_t nResource, const GroupResource &group, std::unordered_map< std::uint32_t, const std::uint32_t > *mapInsert, const bool optional=false)
Finds the address of a register with the given resource name.
ParserManager(const bfp::BFP &bfp)
Constructs a ParserManager object with the given BFP object.
void printInfoError(std::ostream &os=std::cerr) const
Prints resources not found and incompatibilities.
void logResourceFound(const std::string &resourceName, const GroupResource &group)
Logs that a resource has been found.
bool findDMA(const std::string &resourceName, const GroupResource &group, bfp::DMA *dma, const bool optional=false)
Finds a DMA with the given resource name.
BitFile Parser.
Definition: bfp.h:20
Class holding information about one DMA.
Definition: dma.h:16
Class holding information about one Register.
Definition: register.h:16
Custom string comparator for std::set.
Definition: parserManager.h:38
bool operator()(const std::string &a, const std::string &b) const
Overloaded function call operator for comparing two strings.
Contains information about found, not found, and error resources for a group.
Definition: parserManager.h:55
std::set< std::string, CustomStringComparator > found
Set of found resources.
Definition: parserManager.h:57
std::set< std::string, CustomStringComparator > notFound
Set of not found resources.
Definition: parserManager.h:59
std::unordered_map< std::string, std::string > error
Map of resource errors.
Definition: parserManager.h:61