Free Electron
LayoutSB.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_LayoutSB_h__
8 #define __data_LayoutSB_h__
9 
10 namespace fe
11 {
12 
13 
14 class Scope;
15 //class OffsetTable;
16 class RecordSB;
17 class BaseAccessor;
18 class StoreI;
19 
20 
21 /** @brief Record "type" definition
22 
23  @ingroup data
24 
25  A Layout is a definition of Attribute layout in Record instances.
26 
27  Layout objects can only be created via a Scope. For typical use
28  all operations on Layout objects are also done through Scope methods.
29 
30  @todo full data system guide
31  */
32 class FE_DL_EXPORT LayoutSB: public Layout, public Initialize<LayoutSB>,
33  public ClassSafe<GlobalHolder>
34 {
35  friend class RecordSB;
36  friend class WeakRecordSB;
37  friend class RecordArraySB;
38  friend class SegmentStore;
39  public:
40  LayoutSB(sp<Scope> &scope);
41  LayoutSB(sp<Scope> &scope, const String &name);
42  LayoutSB(Scope *pScope, const String &name);
43  private:
44  LayoutSB(const LayoutSB &other);
45  LayoutSB &operator=(const LayoutSB &other);
46  public:
47 virtual ~LayoutSB(void);
48  typedef FE_UWORD Offset;
49 
50 #if 1
51  private:
52  class OffsetTable : public Counted
53  {
54  public:
55  OffsetTable(void);
56  ~OffsetTable(void);
57 
58 
59  Offset *table(void) { return m_table; }
60 
61  void resize(unsigned int a_size);
62 
63  void attach(sp<LayoutSB> a_layout);
64  private:
65  std::vector< hp<LayoutSB> > m_layouts;
66  Offset *m_table;
67  unsigned int m_size;
68  };
69  friend class LayoutSB::OffsetTable;
70 #endif
71 
72 
73  public:
74  LayoutSB &copy(const LayoutSB &other);
75 virtual void initialize(void);
76 
77  /** Convienience function to Scope::populate */
78 virtual void populate(const String &attribute_name);
79  /** Convienience function to Scope::populate */
80 virtual void populate(const String &attribute_name,
81  const String &attribute_type);
82  /** Convienience function to Scope::populate. This particular one
83  does a check if the layout is locked and if so verifys the
84  exsitence of the attribute. */
85 virtual void populate(const BaseAccessor &accessor);
86  /** Convienience function to Scope::populate */
87 virtual void populate(sp<Attribute> spAttribute);
88  /** Convienience function to Scope::populate */
89  void populate(sp<LayoutSB> spLayoutSB);
90 
91 virtual void setName(const String &name);
92 virtual const String& name(void) const;
93 virtual const String verboseName(void) const;
94 
95 #ifdef FE_LOCK_SUPPRESSION
96  /** Set lock suppression. If lock suppression is on (true) then an
97  exception is thrown if locking is attempted. */
98  void suppressLock(bool suppression);
99  bool lockSuppressed(void) const;
100 #endif
101 
102 virtual void setConstruct(bool construct);
103 virtual const bool &construct(void) const;
104 
105 virtual hp<Scope>& scope(void);
106 
107 virtual void peek(Peeker &peeker);
108 
109 virtual FE_UWORD attributeCount(void) const {return (FE_UWORD)0;}
110 virtual sp<Attribute> attribute(FE_UWORD localIndex) { return sp<Attribute>(NULL); }
111 
112  RecordSB createRecord(void);
113 
114 virtual bool checkAttribute(FE_UWORD aLocator) const;
115 virtual bool checkAttributeStr(const String &a_name);
116 virtual void resizeLocatorTable(FE_UWORD aSize);
117 
118  void createRecord(RecordSB &r_new);
119  void freeRecord(RecordSB &r_old);
120 
121 virtual void notifyOfAttributeChange(sp<Depend> &depend);
122 
123  private:
124  void setOffsetTable(Offset *offset_table);
125  const Offset *offsetTable(void) const;
126  const Offset *rawOffsetTable(void) const;
127  void setSize(const FE_UWORD record_size);
128  /// Size of an instance of the layout
129  FE_UWORD size(void) const;
130 
131  void setLocked(bool locked);
132  const bool &locked(void) const;
133  void lock(void);
134 
135  void depAttributeCheck(sp<Depend> &depend);
136  void depRecordCheck(sp<Depend> &depend);
137 
138  void constructAttributes(void *stateBlock);
139  void destructAttributes(void *stateBlock);
140 
141  private:
142  LayoutSB(void);
143  void constructor(sp<Scope> &scope);
144 
145  void cacheIndices(void);
146  void setOffset(const FE_UWORD index, const Offset offset);
147 
148  unsigned int serialIndex(void) const { return m_serialIndex; }
149 
150  private:
151  String m_name;
152  bool m_init;
153  bool m_construct;
154  bool m_suppressLock;
155  Offset *m_pTable;
156  Offset m_size;
157  hp<Scope> m_hpScope;
158  std::vector<FE_UWORD> m_offsetIndex;
159  sp<StoreI> m_store;
160  sp<OffsetTable> m_offsetTable;
161  unsigned int m_serialIndex;
162 
163  public:
164 static
165 const FE_DL_PUBLIC Offset offsetNone = 0xFFFFFFFF;
166 
167 };
168 
169 #if FE_DATA_STORE==FE_SB
170 typedef LayoutSB LayoutDefault;
171 #endif
172 
173 inline bool LayoutSB::checkAttribute(FE_UWORD aLocator) const
174 {
175  return (offsetTable()[aLocator] != offsetNone);
176 }
177 
178 inline void LayoutSB::setName(const String &name)
179 {
180  SAFEGUARDCLASS;
181  m_name = name;
182 }
183 inline const String& LayoutSB::name(void) const
184 {
185  SAFEGUARDCLASS;
186  return m_name;
187 }
188 inline const String LayoutSB::verboseName(void) const
189 {
190  return "LayoutSB " + name();
191 }
192 
193 inline const bool &LayoutSB::locked(void) const
194 {
195  SAFEGUARDCLASS;
196  return m_init;
197 }
198 
199 inline void LayoutSB::setConstruct(bool construct)
200 {
201  SAFEGUARDCLASS;
202  m_construct = construct;
203 }
204 inline const bool &LayoutSB::construct(void) const
205 {
206  SAFEGUARDCLASS;
207  return m_construct;
208 }
209 
210 #if 1
211 inline void LayoutSB::setSize(const FE_UWORD size)
212 {
213  SAFEGUARDCLASS;
214  m_size = size;
215 }
216 inline FE_UWORD LayoutSB::size(void) const
217 {
218  SAFEGUARDCLASS;
219  return m_size;
220 }
221 #endif
222 
223 inline void LayoutSB::setOffsetTable(LayoutSB::Offset *offset_table)
224 {
225  SAFEGUARDCLASS;
226  m_pTable = offset_table;
227 }
228 
229 inline const LayoutSB::Offset *LayoutSB::offsetTable(void) const
230 {
231  //SAFEGUARDCLASS; // too slow /// @todo remove
232 #if FE_CODEGEN<=FE_DEBUG
233  if(!locked())
234  {
235  feX("LayoutSB::offsetTable",
236  "layout not locked");
237  }
238 #endif
239  return m_pTable;
240 }
241 
242 inline const LayoutSB::Offset *LayoutSB::rawOffsetTable(void) const
243 {
244  //SAFEGUARDCLASS; // too slow /// @todo remove
245  return m_pTable;
246 }
247 
248 #if 1
249 inline void LayoutSB::setOffset(const FE_UWORD index, const LayoutSB::Offset offset)
250 {
251  m_pTable[index] = offset;
252 }
253 #endif
254 
255 inline hp<Scope>& LayoutSB::scope(void)
256 {
257  SAFEGUARDCLASS;
258  return m_hpScope;
259 }
260 
261 } /* namespace */
262 
263 #endif /* __data_LayoutSB_h__ */
264 
Class level locking for thread safety.
Definition: Safe.h:213
Memory manager for state blocks.
Definition: SegmentStore.h:17
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
FE_UWORD size(void) const
Size of an instance of the layout.
Definition: LayoutSB.h:216
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
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Record "type" definition.
Definition: LayoutSB.h:32
Layout namespace.
Definition: Scope.h:71
Record "type" definition.
Definition: LayoutAV.h:30
Homogeneous collection of Records.
Definition: RecordArraySB.h:40
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordSB.h:17