Free Electron
LayoutAV.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_LayoutAV_h__
8 #define __data_LayoutAV_h__
9 
10 
11 namespace fe
12 {
13 
14 class Scope;
15 class RecordAV;
16 class BaseAccessor;
17 
18 
19 /** @brief Record "type" definition
20 
21  @ingroup data
22 
23  A Layout is a definition of Attribute layout in Record instances.
24 
25  Layout objects can only be created via a Scope. For typical use
26  all operations on Layout objects are also done through Scope methods.
27 
28  @todo full data system guide
29  */
30 class FE_DL_EXPORT LayoutAV: public Layout, public Initialize<LayoutAV>,
31  public ClassSafe<GlobalHolder>
32 {
33 friend class RecordAV;
34 friend class WeakRecordAV;
35 friend class RecordArrayAV;
36 
37  public:
38  LayoutAV(sp<Scope> &scope);
39  LayoutAV(sp<Scope> &scope, const String &name);
40  LayoutAV(Scope *pScope, const String &name);
41  private:
42  LayoutAV(const LayoutAV &other);
43  LayoutAV &operator=(const LayoutAV &other);
44  public:
45 virtual ~LayoutAV(void);
46 
47  LayoutAV &copy(const LayoutAV &other);
48 virtual void initialize(void);
49 
50  /** Convienience function to Scope::populate */
51 virtual void populate(const String &attribute_name);
52  /** Convienience function to Scope::populate */
53 virtual void populate(const String &attribute_name,
54  const String &attribute_type);
55  /** Convienience function to Scope::populate. This particular one
56  does a check if the layout is locked and if so verifys the
57  exsitence of the attribute. */
58 virtual void populate(const BaseAccessor &accessor);
59  /** Convienience function to Scope::populate */
60 virtual void populate(sp<Attribute> spAttribute);
61  /** Convienience function to Scope::populate */
62  void populate(sp<LayoutAV> spLayout);
63 
64 virtual void setName(const String &name);
65 virtual const String& name(void) const;
66 virtual const String verboseName(void) const;
67 
68 virtual void setConstruct(bool construct);
69 virtual const bool &construct(void) const;
70 
71 virtual hp<Scope>& scope(void);
72 
73 
74 virtual void peek(Peeker &peeker);
75 
76 virtual FE_UWORD attributeCount(void) const;
77 virtual sp<Attribute> attribute(FE_UWORD localIndex);
78 
79 virtual bool checkAttribute(FE_UWORD a_locator) const;
80 virtual bool checkAttributeStr(const String &a_name);
81 virtual void resizeLocatorTable(FE_UWORD a_size);
82 
83  RecordAV createRecord(void);
84  void createRecord(RecordAV &r_new);
85 
86  //void freeRecord(RecordAV &r_old);
87  void freeArrayIndex(const FE_UWORD &aArrayIndex);
88 
89 virtual void notifyOfAttributeChange(sp<Depend> &depend);
90 
91  FE_UWORD avSize(void) { return m_avSize; }
92  void *baseOfAV(FE_UWORD a_locatorIndex);
93 
94  private:
95  LayoutAV(void);
96  void constructor(sp<Scope> &scope);
97 
98  void addMissingAttributes(void);
99  void assignDefaultAttributes(RecordAV &r_new);
100  void destructAttributes(const FE_UWORD &a_arrayIndex);
101 
102  Array< sp<BaseTypeVector> > &attributeVector(void);
103  Array< FE_UWORD > &locatorTable(void);
104 
105 const FE_UWORD &idr(const FE_UWORD &a_index) const;
106 
107  void acquireArrayIndex(const FE_UWORD &aArrayIndex);
108  void releaseArrayIndex(const FE_UWORD &aArrayIndex);
109 
110  unsigned int serialIndex(void) const { return m_serialIndex; }
111 
112  void startUsing(void);
113 
114  bool isExactlyBitset(const t_bitset a_bitset) override;
115  bool containsBitset(const t_bitset a_bitset) override;
116 
117  private:
118  void createRecords(RecordAV &r_new,U32 a_count);
119 
120  String m_name;
121  hp<Scope> m_hpScope;
122  Array< sp<BaseTypeVector> > m_attributeVector;
123  Array< FE_UWORD > m_locatorTable;
124  Array< FE_UWORD > m_idr;
125 #ifdef FE_AV_FASTITER_ENABLE
126  std::vector< FE_UWORD > m_bounce;
127  std::vector< FE_UWORD > m_bounceback;
128 #endif
129  std::set< FE_UWORD > m_freeList;
130  FE_UWORD m_avSize;
131  FE_UWORD m_allocSize;
134  bool m_construct;
135  unsigned int m_serialIndex;
136  bool m_in_use;
137  bool m_need_defaults;
138 
139  private:
140  void* voidAccess(const FE_UWORD &a_locatorIndex,
141  const FE_UWORD &a_arrayIndex) const;
142 
143 #ifdef FE_AV_FASTITER_ENABLE
144  bool existenceCheck(const FE_UWORD &a_locatorIndex,
145  const FE_UWORD &a_arrayIndex) const;
146 #endif
147 
148  public:
149 static
150 const FE_DL_PUBLIC FE_UWORD locatorNone = (FE_UWORD)(-1);
151 static
152 const FE_DL_PUBLIC FE_UWORD arrayindexNone = (FE_UWORD)(-1);
153 };
154 
155 #if FE_DATA_STORE==FE_AV
156 typedef LayoutAV LayoutDefault;
157 #endif
158 
159 #ifdef FE_AV_FASTITER_ENABLE
160 inline void *LayoutAV::voidAccess(const FE_UWORD &a_locatorIndex,
161  const FE_UWORD &a_arrayIndex) const
162 {
163  FEASSERT(m_locatorTable[a_locatorIndex]!=locatorNone);
164  FEASSERT(a_arrayIndex!=arrayindexNone);
165  FEASSERT(m_bounce[a_arrayIndex]>=0);
166  FEASSERT(m_locatorTable[a_locatorIndex]<m_attributeVector.size());
167  return (void *)(m_attributeVector[m_locatorTable[a_locatorIndex]]->raw_at(
168  m_bounce[a_arrayIndex]));
169 }
170 
171 inline bool LayoutAV::existenceCheck(const FE_UWORD &a_locatorIndex,
172  const FE_UWORD &a_arrayIndex) const
173 {
174  if(I32(a_locatorIndex) < 0) { return FALSE; }
175  if(a_locatorIndex >= m_locatorTable.size()) { return FALSE; }
176  if(I32(a_arrayIndex) < 0) { return FALSE; }
177  if(a_arrayIndex >= m_bounce.size()) { return FALSE; }
178  if(I32(m_bounce[a_arrayIndex]) < 0) { return FALSE; }
179 
180  //* size() is type size, not array size
181 // if(m_bounce[a_arrayIndex] >=
182 // m_attributeVector[m_locatorTable[a_locatorIndex]]->size())
183 // { return FALSE; }
184 
185  return true;
186 }
187 #else
188 inline void *LayoutAV::voidAccess(const FE_UWORD &a_locatorIndex,
189  const FE_UWORD &a_arrayIndex) const
190 {
191  FEASSERT(m_locatorTable[a_locatorIndex]!=locatorNone);
192  FEASSERT(a_arrayIndex!=arrayindexNone);
193  return (void *)(m_attributeVector[m_locatorTable[a_locatorIndex]]->raw_at(
194  a_arrayIndex));
195 }
196 #endif
197 
198 inline void *LayoutAV::baseOfAV(FE_UWORD a_locatorIndex)
199 {
200  return m_attributeVector[m_locatorTable[a_locatorIndex]]->raw_at(0);
201 }
202 
203 inline bool LayoutAV::checkAttribute(FE_UWORD aLocator) const
204 {
205  return (m_locatorTable[aLocator] != locatorNone);
206 }
207 
208 inline const FE_UWORD &LayoutAV::idr(const FE_UWORD &aIndex) const
209 {
210  return m_idr[aIndex];
211 }
212 
213 inline Array< sp<BaseTypeVector> > &LayoutAV::attributeVector(void)
214 {
215  return m_attributeVector;
216 }
217 
218 inline Array< FE_UWORD > &LayoutAV::locatorTable(void)
219 {
220  return m_locatorTable;
221 }
222 
223 //* WARNING cross-guarding with Scope can deadlock
224 
225 inline void LayoutAV::setName(const String &name)
226 {
227 // SAFEGUARDCLASS;
228  m_name = name;
229 }
230 inline const String& LayoutAV::name(void) const
231 {
232 // SAFEGUARDCLASS;
233  return m_name;
234 }
235 inline const String LayoutAV::verboseName(void) const
236 {
237  return "Layout " + name();
238 }
239 
240 inline void LayoutAV::setConstruct(bool construct)
241 {
242 // SAFEGUARDCLASS;
243  m_construct = construct;
244 }
245 inline const bool &LayoutAV::construct(void) const
246 {
247 // SAFEGUARDCLASS;
248  return m_construct;
249 }
250 
251 inline hp<Scope>& LayoutAV::scope(void)
252 {
253 // SAFEGUARDCLASS;
254  return m_hpScope;
255 }
256 
257 inline void LayoutAV::acquireArrayIndex(const FE_UWORD &aArrayIndex)
258 {
259  if(m_rc.isValid())
260  {
261 #ifndef FE_AV_FASTITER_ENABLE
262  m_rc->at(aArrayIndex)++;
263 #else
264  m_rc->at(m_bounce[aArrayIndex])++;
265 #endif
266  }
267  else
268  {
269  feX("RC is on by default, should not get here");
270  }
271 }
272 
273 inline void LayoutAV::releaseArrayIndex(const FE_UWORD &aArrayIndex)
274 {
275 //~ SAFEGUARDCLASS;
276 
277  if(m_rc.isValid())
278  {
279 #ifndef FE_AV_FASTITER_ENABLE
280  std::atomic<int> &rc = m_rc->at(aArrayIndex);
281 #else
282  std::atomic<int> &rc = m_rc->at(m_bounce[aArrayIndex]);
283 #endif
284  rc--;
285  if(rc == 0)
286  {
287  destructAttributes(aArrayIndex);
288  freeArrayIndex(aArrayIndex);
289  }
290  }
291 }
292 
293 } /* namespace */
294 
295 #endif /* __data_LayoutAV_h__ */
296 
Homogeneous collection of Records.
Definition: RecordArrayAV.h:32
Class level locking for thread safety.
Definition: Safe.h:213
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Type inspecific Accessor.
Definition: Accessor.h:26
Safe handle for shared pointer.
Definition: Handled.h:61
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
Reference to an instance of a Layout.
Definition: RecordAV.h:25
Layout namespace.
Definition: Scope.h:71
Record "type" definition.
Definition: LayoutAV.h:30
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordAV.h:17