Free Electron
AsciiReader.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __data_AsciiReader_h__
8 #define __data_AsciiReader_h__
9 namespace fe
10 {
11 namespace data
12 {
13 
14 
15 class FE_DL_EXPORT AsciiReader : public Reader
16 {
17  public:
18  AsciiReader(sp<Scope> spScope);
19 virtual ~AsciiReader(void);
20 virtual sp<RecordGroup> input(std::istream &istrm);
21 
22  private:
23  enum BlockType
24  {
25  e_none,
26  e_record,
27  e_group,
28  e_defaultgroup,
29  e_template,
30  e_attribute,
31  e_layout,
32  e_info,
33  e_end,
34  e_comment
35  };
36  class Token
37  {
38  public:
39  Token(void)
40  {
41  m_pBlock = NULL;
42  }
43  ~Token(void)
44  {
45  if(m_pBlock) { deallocate(m_pBlock); }
46  }
47  Token(const Token &other)
48  {
49  m_pBlock = NULL;
50  copy(other);
51  }
52  Token &operator=(const Token &other)
53  {
54  if(&other == this) { return *this; }
55  copy(other);
56  return *this;
57  }
58  void create(int sz)
59  {
60  if(m_pBlock) { deallocate(m_pBlock); }
61  m_size = sz;
62  m_pBlock = allocate(m_size);
63  }
64  void copy(const Token &other)
65  {
66  if(m_pBlock) { deallocate(m_pBlock); }
67  if(other.m_pBlock)
68  {
69  m_pBlock = allocate(other.m_size);
70  m_size = other.m_size;
71  memcpy(m_pBlock, other.m_pBlock, m_size);
72  }
73  m_string = other.m_string;
74  m_args = other.m_args;
75  }
76  String m_string;
77  String m_args;
78  void *m_pBlock;
79  int m_size;
80  bool isString(void) const
81  { return (m_pBlock==NULL);}
82  void clear(void)
83  {
84  m_string = "";
85  m_args = "";
86  if(m_pBlock) { deallocate(m_pBlock); }
87  m_pBlock = NULL;
88  }
89  operator String &()
90  {
91  if(!isString()) { feX("token not string"); }
92  return m_string;
93  }
94  operator const String &() const
95  {
96  if(!isString()) { feX("token not string"); }
97  return m_string;
98  }
99  operator void *()
100  {
101  if(isString()) { feX("token is string"); }
102  return m_pBlock;
103  }
104  const char *c_str(void)
105  {
106  if(isString()) { return m_string.c_str(); }
107  else return "[binary]";
108  }
109  String args(void) const
110  {
111  if(!isString()) { feX("token not string"); }
112  return m_args;
113  }
114  String &str(void)
115  {
116  if(!isString()) { feX("token not string"); }
117  return m_string;
118  }
119  };
120 
121  bool readToken(std::istream &a_istrm, Token &a_token);
122  //void readAttribute(std::istream &a_istrm);
123  //void readInfo(std::istream &a_istrm);
124  void dispatchBlock(BlockType a_type,
125  const Token& token,
126  Array<Token> &a_tokens);
127  void handleGroup(Array<Token> &a_tokens,
128  const Token& token);
129  void handleAttribute(Array<Token> &a_tokens);
130  void handleLayout(Array<Token> &a_tokens);
131  void handleTemplate(Array<Token> &a_tokens);
132  void handleRecord(Array<Token> &a_tokens);
133  void handleInfo(Array<Token> &a_tokens);
134  void handleComment(Array<Token> &a_tokens);
135  void handleEnd(Array<Token> &a_tokens);
136 
137  protected:
138  struct AttributeInfo
139  {
140  String m_name;
141  std::list<String> m_typenames;
142  sp<Attribute> m_spAttribute;
143  FE_UWORD m_index;
144  };
145  typedef std::map<String, AttributeInfo> t_attrinfo;
146  struct LayoutInfo
147  {
148  sp<Layout> m_spLayout;
149  t_attrinfo m_attributeInfos;
150  };
151  typedef std::map<String, LayoutInfo> t_id_layoutinfo;
152 // TODO: AJW: do this back wiring in a faster way -- Accessor-per is slow
153 // TODO: AJW: apply new backwiring to Binary version
154  struct RecordWiringInfo
155  {
156  Record m_record;
157  Accessor<Record> m_aRecord;
158  String m_id;
159  };
160  typedef std::list<RecordWiringInfo> t_wiring;
161 
162  struct WeakRecordWiringInfo
163  {
164  Record m_record;
165  Accessor<WeakRecord> m_aRecord;
166  String m_id;
167  };
168  typedef std::list<WeakRecordWiringInfo> t_wk_wiring;
169 
170 #if 0
171  void readLayout(std::istream &istrm);
172  void readAttribute(std::istream &istrm);
173  void readState(std::istream &istrm);
174  void readRecord(std::istream &istrm, LayoutInfo &l_i);
175  void readRecordGroup(std::istream &istrm);
176  void wireRecords(void);
177  void recordGroupsToArrays(void);
178  void skip(std::istream &istrm, int skipsize);
179 #endif
180  void fail(const String &a_message);
181  void reset(void);
182 
183  void wireRecords(void);
184  void recordGroupsToArrays(void);
185 #if 0
186  void tokenize(Array<String> &a_tokens,
187  std::string &a_string);
188 #endif
189 
190 typedef std::map<String, Record> t_str_r;
191 typedef std::map<String, sp<RecordGroup> > t_id_rg;
192 typedef std::map<String, sp<RecordArray> > t_id_ra;
193 
194  t_id_layoutinfo m_layoutInfos;
195  t_id_rg m_rgs;
196  t_id_ra m_ras;
197  t_str_r m_rs;
198  t_attrinfo m_attrInfos;
199  t_wiring m_wiringList;
200  t_wk_wiring m_wkWiringList;
201  sp<Scope> m_spScope;
202  sp<BaseType> m_spRecordGroupType;
203  sp<BaseType> m_spRecordArrayType;
204  sp<BaseType> m_spRecordType;
205  sp<BaseType> m_spWeakRecordType;
206  std::vector< sp<RecordGroup> > m_spDefaultRGs;
207  sp<RecordGroup> m_spDefaultRG;
208 
209  sp<Scope> findScope(const String &a_name);
210 
211  unsigned int m_next_subst_id;
212  String m_subst_id;
213 };
214 
215 
216 } /* namespace */
217 } /* namespace */
218 
219 #endif /* __data_AsciiReader_h__ */
kernel
Definition: namespace.dox:3