Free Electron
RecordAV.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_RecordAV_h__
8 #define __data_RecordAV_h__
9 
10 namespace fe
11 {
12 
13 
14 template <class T>
15 class Accessor;
16 
17 /** @brief Reference to an instance of a Layout
18 
19  @ingroup data
20 
21  A record is simply a pointer to a Layout and a pointer to a
22  state block. A state block is a block of memory with Attributes laid
23  out as specified by a Layout object.
24  */
25 class FE_DL_EXPORT RecordAV
26 {
27 friend class WeakRecordAV;
28 friend class LayoutAV;
29 friend class RecordArrayAV;
30 
31  public:
32  RecordAV(I32 ignored=0);
33  RecordAV(const RecordAV &other);
34 virtual ~RecordAV(void);
35 
36  /** Return the Layout. */
37  sp<Layout> layout(void) const;
38 
39  RecordAV &operator=(const RecordAV &r_other);
40 
41  bool operator==(const RecordAV &r_other) const;
42  bool operator!=(const RecordAV &r_other) const;
43 
44  /** Return a unique runtime id (id-runtime, idr, since 'rid' has
45  other meaning. */
46  FE_UWORD idr(void) const;
47 
48  /** Return true if the Record points to a valid state block. */
49  bool isValid(void) const;
50  bool extractInstance(Instance &instance, const String &attrName);
51 
52  RecordAV clone(void);
53 
54  template <class T>
55  T &accessAttribute(FE_UWORD aLocator) const;
56 
57  void *rawAttribute(FE_UWORD aLocator) const;
58 
59  private:
60  void acquire(void);
61  void release(void);
62  void set(FE_UWORD aArrayIndex, sp<LayoutAV> a_spLayout);
63 
64  FE_UWORD arrayIndex(void) const { return m_arrayIndex; }
65 
66  private:
67  /// WARNING: this constructor avoids reference counting
68  //RecordAV(FE_UWORD aArrayIndex, LayoutAV *pLayout);
69 
71  FE_UWORD m_arrayIndex;
72 
73 static
74 const FE_DL_PUBLIC FE_UWORD ms_invalidIndex = (FE_UWORD)(-1);
75 };
76 
77 struct hash_record_av
78 { FE_UWORD operator()(const RecordAV r_rec) const
79  { return r_rec.idr() % 17191; } };
80 
81 inline bool operator<(const RecordAV &lhs, const RecordAV &rhs)
82 {
83  return (lhs.idr() < rhs.idr());
84 }
85 
86 class RecordAVInfo : public BaseType::Info
87 {
88  public:
89 virtual String print(void *instance);
90 virtual IWORD output(std::ostream &ostrm, void *instance, t_serialMode mode);
91 virtual void input(std::istream &istrm, void *instance, t_serialMode mode);
92 virtual IWORD iosize(void);
93 virtual bool getConstruct(void);
94 virtual void construct(void *instance);
95 virtual void destruct(void *instance);
96 };
97 
98 inline RecordAV::RecordAV(I32)
99 {
100  m_arrayIndex = ms_invalidIndex;
101 }
102 
103 
104 inline RecordAV::RecordAV(const RecordAV &other)
105 {
106  m_spLayout = other.m_spLayout;
107  m_arrayIndex = other.m_arrayIndex;
108  acquire();
109 }
110 
111 inline RecordAV::~RecordAV(void)
112 {
113  release();
114 }
115 
116 inline RecordAV &RecordAV::operator=(const RecordAV &other)
117 {
118  if(this != &other)
119  {
120  release();
121  m_spLayout = other.m_spLayout;
122  m_arrayIndex = other.m_arrayIndex;
123  acquire();
124  }
125  return *this;
126 }
127 
128 inline bool RecordAV::operator==(const RecordAV &other) const
129 {
130  if (m_spLayout != other.m_spLayout) { return false; }
131  return (m_arrayIndex == other.m_arrayIndex);
132 }
133 
134 inline bool RecordAV::operator!=(const RecordAV &other) const
135 {
136  if (m_spLayout != other.m_spLayout) { return true; }
137  return (m_arrayIndex != other.m_arrayIndex);
138 }
139 
140 inline void RecordAV::set(FE_UWORD aArrayIndex, sp<LayoutAV> a_spLayout)
141 {
142  release();
143  m_arrayIndex = aArrayIndex;
144  m_spLayout = a_spLayout;
145  acquire();
146 }
147 
148 inline FE_UWORD RecordAV::idr(void) const
149 {
150  return m_spLayout->idr(m_arrayIndex);
151 }
152 
153 template <class T>
154 inline T &RecordAV::accessAttribute(FE_UWORD aLocator) const
155 {
156 #if 0
157  return *(T *)(m_spLayout
158  ->m_attributeVector[m_spLayout->m_locatorTable[aLocator]]
159  ->raw_at(m_arrayIndex));
160 #endif
161  return *(T *)(m_spLayout->voidAccess(aLocator, m_arrayIndex));
162 }
163 
164 inline void *RecordAV::rawAttribute(FE_UWORD aLocator) const
165 {
166 #if 0
167  return (void *)(m_spLayout
168  ->m_attributeVector[m_spLayout->m_locatorTable[aLocator]]
169  ->raw_at(m_arrayIndex));
170 #endif
171  return (m_spLayout->voidAccess(aLocator, m_arrayIndex));
172 }
173 
174 inline sp<Layout> RecordAV::layout(void) const
175 {
176  return m_spLayout;
177 }
178 
179 inline void RecordAV::release(void)
180 {
181  if(m_arrayIndex != ms_invalidIndex)
182  {
183  m_spLayout->releaseArrayIndex(m_arrayIndex);
184  }
185 }
186 
187 inline void RecordAV::acquire(void)
188 {
189  if(m_arrayIndex != ms_invalidIndex)
190  {
191  m_spLayout->acquireArrayIndex(m_arrayIndex);
192  }
193 }
194 
195 inline bool RecordAV::isValid(void) const
196 {
197  return (m_arrayIndex != ms_invalidIndex);
198 }
199 
200 
201 } /* namespace */
202 
203 #endif /* __data_RecordAV_h__ */
204 
Homogeneous collection of Records.
Definition: RecordArrayAV.h:32
FE_UWORD idr(void) const
Return a unique runtime id (id-runtime, idr, since &#39;rid&#39; has other meaning.
Definition: RecordAV.h:148
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordAV.h:174
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
kernel
Definition: namespace.dox:3
BWORD operator!=(const DualString &s1, const DualString &s2)
Compare two DualString&#39;s (reverse logic)
Definition: DualString.h:229
BWORD operator==(const DualString &s1, const DualString &s2)
Compare two DualString&#39;s.
Definition: DualString.h:208
sp< LayoutAV > m_spLayout
WARNING: this constructor avoids reference counting.
Definition: RecordAV.h:70
Automatically reference-counted string container.
Definition: String.h:128
Reference to an instance of a Layout.
Definition: RecordAV.h:25
bool isValid(void) const
Return true if the Record points to a valid state block.
Definition: RecordAV.h:195
Record "type" definition.
Definition: LayoutAV.h:30
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordAV.h:17