CARMA C++
RegParser.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_REGPARSER_H
2 #define SZA_UTIL_REGPARSER_H
3 
11 #include <vector>
12 
15 #include "carma/szautil/String.h"
16 
17 #include "carma/szaarrayutils/szaregs.h"
18 
19 namespace sza {
20  namespace util {
21 
22  class RegParser {
23  public:
24 
25  struct RegSpecItem {
26  std::string regStr_;
27  bool hasCoordRange_;
28  CoordRange coordRange_;
29  bool hasIndexCoordRange_;
30  CoordRange indexCoordRange_;
31 
32  RegSpecItem() {
33  hasCoordRange_ = false;
34  hasIndexCoordRange_ = false;
35  };
36  };
37 
45  RegParser(bool archivedOnly_=false);
46 
50  virtual ~RegParser();
51 
55  std::vector<RegDescription> inputRegs(std::string regStr,
56  RegInputMode mode=REG_INPUT_RANGE,
57  bool tell=true,
58  bool extend=true,
59  bool splitIndices=false);
60 
65  std::vector<RegDescription> inputRegs(std::string regStr,
66  ArrayMap* arrayMap,
67  RegInputMode mode,
68  bool tell,
69  bool extend,
70  bool splitIndices=false,
71  bool doThrow=true);
72 
73  std::vector<RegDescription> inputRegsCarma(std::string regSpec,
74  ArrayMap* arrayMap,
75  RegInputMode mode,
76  bool tell,
77  bool extend,
78  bool splitIndices=false,
79  bool doThrow=true);
80 
93  std::vector<RegDescription> inputRegs(InputStream* stream,
94  bool tell,
95  ArrayMap* arraymap,
96  RegInputMode mode,
97  bool extend,
98  bool splitIndices=false,
99  bool doThrow=true);
100 
101  std::vector<RegDescription> inputRegsCarma(std::string regSpec,
102  bool tell,
103  ArrayMap* arraymap,
104  RegInputMode mode,
105  bool extend,
106  bool splitIndices=false,
107  bool doThrow=true);
108 
112  RegDescription inputReg(std::string regStr,
113  RegInputMode mode=REG_INPUT_RANGE,
114  bool tell=true,
115  bool extend=true);
116 
117  RegDescription inputRegCarma(std::string regStr,
118  bool tell,
119  RegInputMode mode,
120  bool extend,
121  ArrayMap* arraymap=0);
122 
126  RegDescription inputReg(InputStream* stream,
127  bool tell,
128  RegInputMode mode,
129  bool extend,
130  ArrayMap* arraymap=0);
131 
135  inline RegValidity validity() {
136  return validity_;
137  }
138 
142  static unsigned getSize(RegMapBlock* block, RegAspect aspect, bool extend);
143 
144  private:
145 
146  // An array map
147 
148  ArrayMapBase arrayMap_;
149 
150  RegValidity validity_; // The validity flag of the last read
151  // register specification
152 
153  bool archivedOnly_; // If true, offsets for the archived
154  // register map should be used.
155 
156  // True if the next token is a '.' followed by some string
157 
158  bool wordFollows(InputStream* stream);
159 
163  RegAspect checkAspect(InputStream* stream, bool throwIfNoMatch=true);
164  static RegAspect checkAspect(std::string str, bool throwIfNoMatch=true);
165  static RegAspect checkAspect(char* cstr, bool throwIfNoMatch=true);
166 
170  RegInteg checkInteg(InputStream* stream, bool throwIfNoMatch=true);
171  static RegInteg checkInteg(std::string str, bool throwIfNoMatch=true);
172  static RegInteg checkInteg(char* cstr, bool throwIfNoMatch=true);
173 
177  CoordRange readIndexRanges(InputStream* stream);
178 
182  Range<unsigned> readIndexRange(InputStream* stream);
183 
188  void checkValidityOfMode(RegInputMode mode, ArrRegMap* aregmap,
189  RegMapBoard* brd, RegMapBlock* blk,
190  CoordRange& range, unsigned size);
191 
192  void parseFromStream(InputStream* stream, char* regmap_name, char* board_name, char* block_name,
193  CoordRange& boardCoordRange,
194  CoordRange& coordRange,
195  RegAspect& aspect,
196  RegInteg& integ,
197  RegInputMode mode);
198 
199  void matchRegisters(ArrayMap* arrayMap,
200  char* regmap_name, char* board_name, char* block_name,
201  CoordRange& boardCoordRange,
202  CoordRange& coordRange,
203  RegAspect aspect,
204  RegInteg integ,
205  RegInputMode mode,
206  bool extend,
207  bool splitIndices,
208  std::vector<RegDescription>& regs);
209 
210  public:
211 
212  void parseFromString(std::string regSpec,
213  std::vector<std::string>& regmapNames,
214  std::vector<std::string>& boardNames,
215  std::vector<std::string>& blockNames,
216  CoordRange& coordRange,
217  RegAspect& aspect,
218  RegInteg& integ,
219  RegInputMode mode,
220  bool throwIfNoMatch=true);
221 
222  void matchRegisters(ArrayMap* arrayMap,
223  std::vector<std::string>& regmapNames,
224  std::vector<std::string>& boardNames,
225  std::vector<std::string>& blockNames,
226  CoordRange& coordRange,
227  RegAspect aspect,
228  RegInteg integ,
229  RegInputMode mode,
230  bool extend,
231  bool splitIndices,
232  std::vector<RegDescription>& regs);
233 
234  public:
235 
236  static std::vector<std::string> parseIntoPeriodSeparatedStrings(std::string regSpec);
237 
238  static std::vector<RegSpecItem> parseIntoPeriodSeparatedItems(std::string regSpec);
239 
240  static CoordRange parseCoordRange(String& str);
241  static CoordRange parseCoordRangeCarma(String& str);
242  static CoordRange parseIndexCoordRangeCarma(String& str);
243 
244  static RegSpecItem parseItem(std::string str);
245  static RegSpecItem parseItemCarma(std::string str);
246 
247  static std::vector<std::string> getExpandedNames(RegSpecItem& items);
248  static std::vector<std::string> concatenateItem(std::vector<std::string>& inNames, RegSpecItem& item);
249  static std::vector<std::string> getBoardNames(std::vector<RegSpecItem>& items);
250  static std::vector<std::string> getBlockNames(std::vector<RegSpecItem>& items);
251  static std::vector<std::string> getRegmapNames(std::vector<RegSpecItem>& items);
252 
253  }; // End class RegParser
254 
255  } // End namespace util
256 } // End namespace sza
257 
258 
259 
260 
261 #endif // End #ifndef SZA_UTIL_REGPARSER_H
Tagged: Mon Sep 27 21:37:46 UTC 2004.
Tagged: Wed May 12 09:30:13 PDT 2004.
Tagged: Fri Sep 17 15:51:07 PDT 2004.