Free Electron
Accessor.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_Accessor_h__
8 #define __data_Accessor_h__
9 
10 #if FE_CODEGEN<FE_DEBUG
11 #define FE_ATTRIBUTE_DEBUG
12 #define FE_ACCESSOR_DEBUG
13 #endif
14 
15 namespace fe
16 {
17 
18 /** @brief Type inspecific Accessor.
19 
20  An accessor is a type of functor that is bound to a particular attribute.
21  It is useful for attribute specific operations, most notably accessing a
22  attribute within a record. An accessor can also be used to check if a
23  attribute exists in a Record, RecordArray, Bag, or Layout. An accessor is
24  also a convienient way to setup attributes in a Scope.
25  */
26 class FE_DL_EXPORT BaseAccessor
27 {
28  public:
29  class FE_DL_PUBLIC Exception : public ::fe::Exception
30  {
31  public:
32  Exception(const char *a_message) : ::fe::Exception(a_message) {}
33  };
34 
35  BaseAccessor(void);
36  ~BaseAccessor(void);
37  /** initialize functions setup the accessor but do not setup anything
38  with the Scope. */
39  void initialize( sp<Scope> scope,
40  const String &attribute);
41  /** initialize functions setup the accessor but do not setup anything
42  with the Scope. */
43  void initialize( Scope *pScope,
44  const String &attribute);
45  /** initialize functions setup the accessor but do not setup anything
46  with the Scope. */
47  void initialize( sp<Scope> scope,
48  sp<Attribute> spAttribute);
49  /** setup functions setup the accessor and also setup the Scope. */
50  void setup( sp<Scope> spScope,
51  const String &attribute);
52  /** setup functions setup the accessor and also setup the Scope. */
53  void setup( sp<Scope> scope,
54  const String &attribute,
55  const String &attributetype);
56  /** setup the accessor and populate the named Layout,
57  creating the Layout if neccessary */
58  void populate( sp<Scope> spScope,
59  const String &layout,
60  const String &attribute);
61 
62  sp<Scope> scope(void) const;
63 
64  bool operator==(const BaseAccessor &other) const;
65  bool operator<(const BaseAccessor &other) const;
66 
67  BaseAccessor &operator=(const BaseAccessor &other);
68  operator FE_UWORD() const;
69  FE_UWORD index(void) const;
70 
71 
72  /** Return true if @em record has attribute */
73  bool check(const RecordSB& r) const;
74  /** Return true if @em record has attribute */
75  bool check(const WeakRecordSB& r) const;
76  /** Return true if @em record has attribute */
77  bool check(RecordSB *pR) const;
78  /** Return true if @em spRA has attribute */
79  bool check(sp<RecordArraySB>& rspRA) const;
80  /** Return true if @em rRA has attribute */
81  bool check(RecordArraySB &rRA) const;
82  /** Return true if @em spL has attribute */
83  bool check(sp<LayoutSB>& rspL) const;
84  /** Return true if @em L has attribute */
85  bool check(LayoutSB &rL) const;
86 
87  /** Return true if @em record has attribute */
88  bool check(const RecordAV& r) const;
89  /** Return true if @em record has attribute */
90  bool check(const WeakRecordAV& r) const;
91  /** Return true if @em record has attribute */
92  bool check(RecordAV *pR) const;
93  /** Return true if @em spRA has attribute */
94  bool check(sp<RecordArrayAV>& rspRA) const;
95  /** Return true if @em rRA has attribute */
96  bool check(RecordArrayAV &rRA) const;
97  /** Return true if @em spL has attribute */
98  bool check(sp<LayoutAV>& rspL) const;
99  /** Return true if @em L has attribute */
100  bool check(LayoutAV &rL) const;
101 
102  bool check(sp<Layout>& rspL) const;
103  bool check(Layout &rL) const;
104 
105 
106  /** Return the attribute this accessor is for */
107  sp<Attribute> attribute(void) const;
108  const String &name(void) const;
109 
110  /** optionally bind to a record */
111  void bind(const WeakRecord &a_record) { m_optional_record = a_record; }
112 
113  void typeCheck(const String &attribute);
114 
115  protected:
116  FE_UWORD m_index;
117  hp<Scope> m_hpScope;
118  TypeInfo m_typeInfo;
119  WeakRecord m_optional_record;
120 };
121 
122 
123 /** @brief The main data access class for the data system.
124 
125  @ingroup data
126  */
127 template <class T>
128 class FE_DL_EXPORT Accessor : public BaseAccessor
129 {
130  public:
131  Accessor(void);
132  Accessor(sp<Scope> scope, const String &attribute);
133  ~Accessor(void);
134 
135  Accessor(const Accessor<T> &other);
136 
137  Accessor<T> &operator=(const Accessor<T> &other);
138 
139 
140  /** Return the attribute. Checking for existence is not done */
141  T &operator()(const RecordSB& r);
142  /** Return the attribute. Checking for existence is not done */
143 const T operator()(const RecordSB& r) const;
144  /** Return the attribute. Checking for existence is not done */
145  T &operator()(const WeakRecordSB &r);
146  /** Return the attribute. Checking for existence is not done */
147 const T operator()(const WeakRecordSB &r) const;
148  /** Return the attribute. Checking for existence is not done */
149  T &operator()(RecordSB *record);
150  /** Return the attribute. Checking for existence is not done */
151  T &operator()(sp<RecordArraySB>& rspRA, FE_UWORD index);
152  /** Return the attribute. Checking for existence is not done */
153 const T &operator()(sp<RecordArraySB>& rspRA, FE_UWORD index) const;
154  /** Return the attribute. Checking for existence is not done */
155  T &operator()(hp<RecordArraySB>& rhpRA, FE_UWORD index);
156 
157  /** Return the attribute. Checking for existence is done.
158  If the attribute does not exist then an Exception is thrown */
159  T &operator()(const RecordSB& r, const char *message);
160 
161  /** Return true if the attribute exists in @em record. Return the
162  attribute data in @data */
163  bool queryAttribute(const RecordSB& r, T *&data);
164  /** Return true if the attribute exists in @em record. Return the
165  attribute data in @data */
166  bool queryAttribute(const WeakRecordSB r, T *&data);
167  T *queryAttribute(const RecordSB& r);
168  /** Return a pointer to the attribute if it exists in @em record.
169  Otherwise return NULL */
170  T *queryAttribute(const WeakRecordSB r);
171  /** Return a pointer to the attribute if it exists in @em record.
172  Otherwise return NULL */
173  T *queryAttribute(RecordSB *pR);
174  /** Return a pointer to the attribute if it exists in @em record
175  indexed into the RecordArraySB.
176  Otherwise return NULL */
177  T *queryAttribute(sp<RecordArraySB>& rspRA, FE_UWORD index);
178 
179  /** Return the attribute. Checking for existence is not done */
180  T &operator()(const RecordAV& r);
181  /** Return the attribute. Checking for existence is not done */
182 const T operator()(const RecordAV& r) const;
183  /** Return the attribute. Checking for existence is not done */
184  T &operator()(const WeakRecordAV &r);
185  /** Return the attribute. Checking for existence is not done */
186 const T operator()(const WeakRecordAV &r) const;
187  /** Return the attribute. Checking for existence is not done */
188  T &operator()(RecordAV *record);
189  /** Return the attribute. Checking for existence is not done */
190  T &operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index);
191  /** Return the attribute. Checking for existence is not done */
192 const T &operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index) const;
193  /** Return the attribute. Checking for existence is not done */
194  T &operator()(hp<RecordArrayAV>& rhpRA, FE_UWORD index);
195 
196  /** Return the attribute. Checking for existence is done.
197  If the attribute does not exist then an Exception is thrown */
198  T &operator()(const RecordAV& r, const char *message);
199 
200  /** Return true if the attribute exists in @em record. Return the
201  attribute data in @data */
202  bool queryAttribute(const RecordAV& r, T *&data);
203  /** Return true if the attribute exists in @em record. Return the
204  attribute data in @data */
205  bool queryAttribute(const WeakRecordAV r, T *&data);
206  T *queryAttribute(const RecordAV& r);
207  /** Return a pointer to the attribute if it exists in @em record.
208  Otherwise return NULL */
209  T *queryAttribute(const WeakRecordAV r);
210  /** Return a pointer to the attribute if it exists in @em record.
211  Otherwise return NULL */
212  T *queryAttribute(RecordAV *pR);
213  /** Return a pointer to the attribute if it exists in @em record
214  indexed into the RecordArrayAV.
215  Otherwise return NULL */
216  T *queryAttribute(sp<RecordArrayAV>& rspRA, FE_UWORD index);
217 
218  bool operator()(const RecordAV& record, T &data);
219  bool operator()(const WeakRecordAV& record, T &data);
220  bool operator()(const RecordSB& record, T &data);
221  bool operator()(const WeakRecordSB& record, T &data);
222 
223  void registerDefault(T *pT);
224 
225  T *operator()(const sp<LayoutAV> &spLayout);
226 
227  Accessor<T> &operator=(const T &a_value)
228  {
229  (*this)(BaseAccessor::m_optional_record) = a_value;
230  return *this;
231  }
232  T *operator*(void)
233  {
234  return &((*this)(BaseAccessor::m_optional_record));
235  }
236  operator T&()
237  {
238  return (*this)(BaseAccessor::m_optional_record);
239  }
240  T &c_val(void)
241  {
242  return (*this)(BaseAccessor::m_optional_record);
243  }
244 
245  private:
246  T *m_pT;
247 };
248 
249 template <>
250 class FE_DL_EXPORT Accessor<void> : public BaseAccessor
251 {
252  public:
253  Accessor(void)
254  {
255  m_typeInfo = TypeInfo(getTypeId<void>());
256  }
257  Accessor(sp<Scope> scope, const String &attribute)
258  {
259  m_typeInfo = TypeInfo(getTypeId<void>());
260  setup(scope, attribute);
261  }
262  ~Accessor(void)
263  {
264  }
265 };
266 
267 
268 /*****************************************************************************
269 IMPLEMENTATION
270 *****************************************************************************/
271 
272 
273 inline bool BaseAccessor::operator==(const BaseAccessor &other) const
274 {
275  if(m_index != other.m_index) { return false; }
276  if(!(m_hpScope == other.m_hpScope)) { return false; }
277  return true;
278 }
279 
280 inline bool BaseAccessor::operator<(const BaseAccessor &other) const
281 {
282  return (m_index < other.m_index);
283 }
284 
285 
286 inline BaseAccessor::operator FE_UWORD() const
287 {
288  return m_index;
289 }
290 
291 inline FE_UWORD BaseAccessor::index(void) const
292 {
293  return m_index;
294 }
295 
296 #ifdef FE_ATTRIBUTE_DEBUG
297 #define FE_SCOPE_CHECK(s) \
298  if(!m_hpScope.isValid()) \
299  { \
300  feX("FE_SCOPE_CHECK", \
301  "Accessor for \'%s\' is not initialized", \
302  s->attribute(m_index)->name().c_str()); \
303  } \
304  if(s != m_hpScope) \
305  { \
306  feX("FE_SCOPE_CHECK", \
307  "Accessor for \'%s\' is not bound to the same scope as Record", \
308  m_hpScope->attribute(m_index)->name().c_str()); \
309  }
310 #else
311 #define FE_SCOPE_CHECK(s) /* NOOP */
312 #endif
313 
314 inline bool BaseAccessor::check(const RecordSB& record) const
315 {
316  FE_SCOPE_CHECK(record.layout()->scope());
317  return record.layout()->checkAttribute(m_index);
318 }
319 
320 inline bool BaseAccessor::check(const WeakRecordSB& record) const
321 {
322  FE_SCOPE_CHECK(record.layout()->scope());
323  return record.layout()->checkAttribute(m_index);
324 }
325 
326 inline bool BaseAccessor::check(RecordSB *record) const
327 {
328  FE_SCOPE_CHECK(record->layout()->scope());
329  return record->layout()->checkAttribute(m_index);
330 }
331 
332 inline bool BaseAccessor::check(sp<RecordArraySB>& rspRA) const
333 {
334  FE_SCOPE_CHECK(rspRA->layout()->scope());
335  return rspRA->layout()->checkAttribute(m_index);
336 }
337 
338 inline bool BaseAccessor::check(RecordArraySB &rRA) const
339 
340 {
341  FE_SCOPE_CHECK(rRA.layout()->scope());
342  return rRA.layout()->checkAttribute(m_index);
343 }
344 
345 inline bool BaseAccessor::check(sp<LayoutSB>& rspL) const
346 {
347  FE_SCOPE_CHECK(rspL->scope());
348  return rspL->checkAttribute(m_index);
349 }
350 
351 inline bool BaseAccessor::check(LayoutSB &rL) const
352 {
353  FE_SCOPE_CHECK(rL.scope());
354  return rL.checkAttribute(m_index);
355 }
356 
357 inline bool BaseAccessor::check(sp<LayoutAV>& rspL) const
358 {
359  FE_SCOPE_CHECK(rspL->scope());
360  return rspL->checkAttribute(m_index);
361 }
362 
363 inline bool BaseAccessor::check(LayoutAV &rL) const
364 {
365  FE_SCOPE_CHECK(rL.scope());
366  return rL.checkAttribute(m_index);
367 }
368 
369 inline bool BaseAccessor::check(sp<Layout>& rspL) const
370 {
371  FE_SCOPE_CHECK(rspL->scope());
372  return rspL->checkAttribute(m_index);
373 }
374 
375 inline bool BaseAccessor::check(Layout &rL) const
376 {
377  FE_SCOPE_CHECK(rL.scope());
378  return rL.checkAttribute(m_index);
379 }
380 
381 inline bool BaseAccessor::check(const RecordAV& record) const
382 {
383  FE_SCOPE_CHECK(record.layout()->scope());
384  return record.layout()->checkAttribute(m_index);
385 }
386 
387 inline bool BaseAccessor::check(const WeakRecordAV& record) const
388 {
389  FE_SCOPE_CHECK(record.layout()->scope());
390  return record.layout()->checkAttribute(m_index);
391 }
392 
393 inline bool BaseAccessor::check(RecordAV *record) const
394 {
395  FE_SCOPE_CHECK(record->layout()->scope());
396  return record->layout()->checkAttribute(m_index);
397 }
398 
399 inline bool BaseAccessor::check(sp<RecordArrayAV>& rspRA) const
400 {
401  FE_SCOPE_CHECK(rspRA->layout()->scope());
402  return rspRA->layout()->checkAttribute(m_index);
403 }
404 
405 inline bool BaseAccessor::check(RecordArrayAV &rRA) const
406 
407 {
408  FE_SCOPE_CHECK(rRA.layout()->scope());
409  return rRA.layout()->checkAttribute(m_index);
410 }
411 
412 
413 template <class T>
414 inline Accessor<T>::Accessor(void)
415 {
416  m_pT = NULL;
417  m_typeInfo = TypeInfo(getTypeId<T>());
418 }
419 
420 template <class T>
421 inline Accessor<T>::Accessor(sp<Scope> scope, const String &attribute)
422 {
423  m_pT = NULL;
424  m_typeInfo = TypeInfo(getTypeId<T>());
425  setup(scope, attribute);
426 }
427 
428 template <class T>
429 inline Accessor<T>::~Accessor(void)
430 {
431 }
432 
433 #ifdef FE_ATTRIBUTE_DEBUG
434 #define FE_ATTRIBUTE_CHECK(r) \
435  if(!check(r)) \
436  { \
437  feX("FE_ATTRIBUTE_CHECK", \
438  "invalid access: \'%s\' is not in \'%s\'", \
439  m_hpScope->attribute(m_index)->name().c_str(), \
440  r.layout()->name().c_str()); \
441  }
442 #else
443 #define FE_ATTRIBUTE_CHECK(r) /* NOOP */
444 #endif
445 
446 #ifdef FE_ATTRIBUTE_DEBUG
447 #define FE_ATTRIBUTE_TYPECHECK(r) \
448  sp<TypeMaster> spTM = m_hpScope->typeMaster(); \
449  sp<BaseType> spType = spTM->lookupType(TypeInfo(getTypeId<T>())); \
450  if(spType != m_hpScope->attribute(m_index)->type()) \
451  { \
452  feX("FE_ATTRIBUTE_TYPECHECK", \
453  "accessor on \'%s\' type mismatch \'%s\' is not \'%s\'\n", \
454  m_hpScope->attribute(m_index)->name().c_str(), \
455  spTM->reverseLookup(spType).c_str(), \
456  spTM->reverseLookup(m_hpScope->attribute(m_index)->type()). \
457  c_str()); \
458  }
459 #else
460 #define FE_ATTRIBUTE_TYPECHECK(r) /* NOOP */
461 #endif
462 
463 template <class T>
464 inline Accessor<T>::Accessor(const Accessor<T> &other)
465 {
466  if(&other != this)
467  {
468  m_index = other.m_index;
469  m_hpScope = other.m_hpScope;
470  m_typeInfo = other.m_typeInfo;
471  m_pT = other.m_pT;
472  }
473 }
474 
475 template <class T>
476 inline Accessor<T> &Accessor<T>::operator=(const Accessor<T> &other)
477 {
478  if(&other != this)
479  {
480  m_index = other.m_index;
481  m_hpScope = other.m_hpScope;
482  m_typeInfo = other.m_typeInfo;
483  m_pT = other.m_pT;
484  }
485  return *this;
486 }
487 
488 template <class T>
489 inline T &Accessor<T>::operator()(const RecordSB& record)
490 {
491  FE_ATTRIBUTE_CHECK(record);
492  FE_ATTRIBUTE_TYPECHECK(record);
493 
494  return record.accessAttribute<T>(m_index);
495 }
496 
497 template <class T>
498 inline const T Accessor<T>::operator()(const RecordSB& record) const
499 {
500  FE_ATTRIBUTE_CHECK(record);
501  FE_ATTRIBUTE_TYPECHECK(record);
502  return record.accessAttribute<T>(m_index);
503 }
504 
505 template <class T>
506 inline T &Accessor<T>::operator()(const WeakRecordSB &record)
507 {
508  FE_ATTRIBUTE_CHECK(record);
509  FE_ATTRIBUTE_TYPECHECK(record);
510  return record.accessAttribute<T>(m_index);
511 }
512 
513 template <class T>
514 inline const T Accessor<T>::operator()(const WeakRecordSB &record) const
515 {
516  FE_ATTRIBUTE_CHECK(record);
517  FE_ATTRIBUTE_TYPECHECK(record);
518  return record.accessAttribute<T>(m_index);
519 }
520 
521 template <class T>
523 {
524  FE_ATTRIBUTE_CHECK((*record));
525  FE_ATTRIBUTE_TYPECHECK(*record);
526  return record->accessAttribute<T>(m_index);
527 }
528 
529 
530 template <class T>
531 inline T &Accessor<T>::operator()(const RecordSB& record, const char *message)
532 {
533  if(!record.isValid())
534  {
535  feX(e_invalidPointer,
536  (message!=NULL)?message:"",
537  "invalid record in access of %s",
538  m_hpScope->attribute(m_index)->name().c_str());
539  }
540  if(!check(record))
541  {
542  feX(e_cannotFind,
543  (message!=NULL)?message:"",
544  "%s not found in layout %s",
545  m_hpScope->attribute(m_index)->name().c_str(),
546  record.layout()->name().c_str());
547  }
548  return record.accessAttribute<T>(m_index);
549 }
550 
551 
552 template <class T>
553 inline const T &Accessor<T>::operator()(sp<RecordArraySB>& rspRA, FE_UWORD index) const
554 {
555  FE_ATTRIBUTE_CHECK((*rspRA));
556  return rspRA->accessAttribute<T>(m_index, index);
557 }
558 
559 template <class T>
560 inline T &Accessor<T>::operator()(sp<RecordArraySB>& rspRA, FE_UWORD index)
561 {
562  FE_ATTRIBUTE_CHECK((*rspRA));
563  return rspRA->accessAttribute<T>(m_index, index);
564 }
565 
566 template <class T>
567 inline T &Accessor<T>::operator()(hp<RecordArraySB>& rhpRA, FE_UWORD index)
568 {
569  FE_ATTRIBUTE_CHECK((*rhpRA));
570  return rhpRA->accessAttribute<T>(m_index, index);
571 }
572 
573 template <class T>
574 inline bool Accessor<T>::queryAttribute(const RecordSB& record, T *&data)
575 {
576  if(!check(record))
577  {
578  return false;
579  }
580  data = &(operator()(record));
581  return true;
582 }
583 
584 template <class T>
585 inline bool Accessor<T>::queryAttribute(const WeakRecordSB record, T *&data)
586 {
587  if(!check(record))
588  {
589  return false;
590  }
591  data = &(operator()(record));
592  return true;
593 }
594 
595 template <class T>
596 inline T *Accessor<T>::queryAttribute(const RecordSB& record)
597 {
598  if(!check(record))
599  {
600  return m_pT;
601  }
602  return &(operator()(record));
603 }
604 
605 template <class T>
607 {
608  if(!check(record))
609  {
610  return m_pT;
611  }
612  return &(operator()(record));
613 }
614 
615 template <class T>
616 inline T *Accessor<T>::queryAttribute(sp<RecordArraySB>& rspRA, FE_UWORD index)
617 {
618  if(!check(rspRA))
619  {
620  return m_pT;
621  }
622  return &(operator()(rspRA,index));
623 }
624 
625 template <class T>
627 {
628  if(!check(record))
629  {
630  return m_pT;
631  }
632  return &(operator()(record));
633 }
634 
635 #if 1
636 template <class T>
637 inline T *Accessor<T>::operator()(const sp<LayoutAV> &spLayout)
638 {
639  return (T *)(spLayout->baseOfAV(m_index));
640 }
641 
642 
643 template <class T>
644 inline T &Accessor<T>::operator()(const RecordAV& record)
645 {
646  FE_ATTRIBUTE_CHECK(record);
647  FE_ATTRIBUTE_TYPECHECK(record);
648 
649  return record.accessAttribute<T>(m_index);
650 }
651 
652 template <class T>
653 inline const T Accessor<T>::operator()(const RecordAV& record) const
654 {
655  FE_ATTRIBUTE_CHECK(record);
656  FE_ATTRIBUTE_TYPECHECK(record);
657  return record.accessAttribute<T>(m_index);
658 }
659 
660 template <class T>
661 inline T &Accessor<T>::operator()(const WeakRecordAV &record)
662 {
663  FE_ATTRIBUTE_CHECK(record);
664  FE_ATTRIBUTE_TYPECHECK(record);
665  return record.accessAttribute<T>(m_index);
666 }
667 
668 template <class T>
669 inline const T Accessor<T>::operator()(const WeakRecordAV &record) const
670 {
671  FE_ATTRIBUTE_CHECK(record);
672  FE_ATTRIBUTE_TYPECHECK(record);
673  return record.accessAttribute<T>(m_index);
674 }
675 
676 template <class T>
678 {
679  FE_ATTRIBUTE_CHECK((*record));
680  FE_ATTRIBUTE_TYPECHECK(*record);
681  return record->accessAttribute<T>(m_index);
682 }
683 
684 template <class T>
685 inline bool Accessor<T>::operator()(const RecordSB& record, T &data)
686 {
687  if(!check(record))
688  {
689  return false;
690  }
691  data = (operator()(record));
692  return true;
693 }
694 
695 template <class T>
696 inline bool Accessor<T>::operator()(const WeakRecordSB& record, T &data)
697 {
698  if(!check(record))
699  {
700  return false;
701  }
702  data = (operator()(record));
703  return true;
704 }
705 
706 template <class T>
707 inline T &Accessor<T>::operator()(const RecordAV& record, const char *message)
708 {
709  if(!record.isValid())
710  {
711  feX(e_invalidPointer,
712  (message!=NULL)?message:"",
713  "invalid record in access of %s",
714  m_hpScope->attribute(m_index)->name().c_str());
715  }
716  if(!check(record))
717  {
718  feX(e_cannotFind,
719  (message!=NULL)?message:"",
720  "%s not found in layout %s",
721  m_hpScope->attribute(m_index)->name().c_str(),
722  record.layout()->name().c_str());
723  }
724  return record.accessAttribute<T>(m_index);
725 }
726 
727 
728 template <class T>
729 inline const T &Accessor<T>::operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index) const
730 {
731  FE_ATTRIBUTE_CHECK((*rspRA));
732  return rspRA->accessAttribute<T>(m_index, index);
733 }
734 
735 template <class T>
736 inline T &Accessor<T>::operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index)
737 {
738  FE_ATTRIBUTE_CHECK((*rspRA));
739  return rspRA->accessAttribute<T>(m_index, index);
740 }
741 
742 template <class T>
743 inline T &Accessor<T>::operator()(hp<RecordArrayAV>& rhpRA, FE_UWORD index)
744 {
745  FE_ATTRIBUTE_CHECK((*rhpRA));
746  return rhpRA->accessAttribute<T>(m_index, index);
747 }
748 
749 template <class T>
750 inline bool Accessor<T>::queryAttribute(const RecordAV& record, T *&data)
751 {
752  if(!check(record))
753  {
754  return false;
755  }
756  data = &(operator()(record));
757  return true;
758 }
759 
760 template <class T>
761 inline bool Accessor<T>::queryAttribute(const WeakRecordAV record, T *&data)
762 {
763  if(!check(record))
764  {
765  return false;
766  }
767  data = &(operator()(record));
768  return true;
769 }
770 
771 template <class T>
772 inline T *Accessor<T>::queryAttribute(const RecordAV& record)
773 {
774  if(!check(record))
775  {
776  return m_pT;
777  }
778  return &(operator()(record));
779 }
780 
781 template <class T>
783 {
784  if(!check(record))
785  {
786  return m_pT;
787  }
788  return &(operator()(record));
789 }
790 
791 #if 1
792 template <class T>
793 inline T *Accessor<T>::queryAttribute(sp<RecordArrayAV>& rspRA, FE_UWORD index)
794 {
795  if(!check(rspRA))
796  {
797  return m_pT;
798  }
799  return &(operator()(rspRA,index));
800 }
801 #endif
802 
803 template <class T>
805 {
806  if(!check(record))
807  {
808  return m_pT;
809  }
810  return &(operator()(record));
811 }
812 #endif
813 
814 template <class T>
815 inline void Accessor<T>::registerDefault(T *pT)
816 {
817  m_pT = pT;
818 }
819 
820 template <class T>
821 class FE_DL_EXPORT AccessorReadOnly : public BaseAccessor
822 {
823  public:
824  AccessorReadOnly(void);
825  AccessorReadOnly(sp<Scope> scope, const String &attribute);
826  ~AccessorReadOnly(void);
827 
828  AccessorReadOnly(const Accessor<T> &other);
829 
830  AccessorReadOnly<T> &operator=(const AccessorReadOnly<T> &other);
831 
832 
833  /** Return the attribute. Checking for existence is not done */
834 const T operator()(const RecordSB& r) const;
835  /** Return the attribute. Checking for existence is not done */
836 const T operator()(const WeakRecordSB &r) const;
837  /** Return the attribute. Checking for existence is not done */
838 const T &operator()(sp<RecordArraySB>& rspRA, FE_UWORD index) const;
839 
840  /** Return true if the attribute exists in @em record. Return the
841  attribute data in @data */
842  bool queryAttribute(const RecordSB& r, T *&data);
843  /** Return true if the attribute exists in @em record. Return the
844  attribute data in @data */
845  bool queryAttribute(const WeakRecordSB r, T *&data);
846 
847  /** Return the attribute. Checking for existence is not done */
848 const T operator()(const RecordAV& r) const;
849  /** Return the attribute. Checking for existence is not done */
850 const T operator()(const WeakRecordAV &r) const;
851  /** Return the attribute. Checking for existence is not done */
852 const T &operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index) const;
853 
854  /** Return true if the attribute exists in @em record. Return the
855  attribute data in @data */
856  bool queryAttribute(const RecordAV& r, T *&data);
857  /** Return true if the attribute exists in @em record. Return the
858  attribute data in @data */
859  bool queryAttribute(const WeakRecordAV r, T *&data);
860 
861  bool operator()(const RecordAV& record, T &data);
862  bool operator()(const WeakRecordAV& record, T &data);
863  bool operator()(const RecordSB& record, T &data);
864  bool operator()(const WeakRecordSB& record, T &data);
865 
866  void registerDefault(T *pT);
867 
868  private:
869  T *m_pT;
870 };
871 
872 template <class T>
873 inline AccessorReadOnly<T>::AccessorReadOnly(void)
874 {
875  m_pT = NULL;
876  m_typeInfo = TypeInfo(getTypeId<T>());
877 }
878 
879 template <class T>
880 inline AccessorReadOnly<T>::AccessorReadOnly(sp<Scope> scope, const String &attribute)
881 {
882  m_pT = NULL;
883  m_typeInfo = TypeInfo(getTypeId<T>());
884  setup(scope, attribute);
885 }
886 
887 template <class T>
888 inline AccessorReadOnly<T>::~AccessorReadOnly(void)
889 {
890 }
891 
892 template <class T>
893 inline AccessorReadOnly<T>::AccessorReadOnly(const Accessor<T> &other)
894 {
895  if(&other != this)
896  {
897  m_index = other.m_index;
898  m_hpScope = other.m_hpScope;
899  m_typeInfo = other.m_typeInfo;
900  m_pT = other.m_pT;
901  }
902 }
903 
904 template <class T>
905 inline AccessorReadOnly<T>& AccessorReadOnly<T>::operator=(
906  const AccessorReadOnly<T>& other)
907 {
908  if(&other != this)
909  {
910  m_index = other.m_index;
911  m_hpScope = other.m_hpScope;
912  m_typeInfo = other.m_typeInfo;
913  m_pT = other.m_pT;
914  }
915  return *this;
916 }
917 
918 template <class T>
919 inline const T AccessorReadOnly<T>::operator()(const RecordSB& record) const
920 {
921  FE_ATTRIBUTE_CHECK(record);
922  FE_ATTRIBUTE_TYPECHECK(record);
923  return record.accessAttribute<T>(m_index);
924 }
925 
926 template <class T>
927 inline const T AccessorReadOnly<T>::operator()(const WeakRecordSB &record) const
928 {
929  FE_ATTRIBUTE_CHECK(record);
930  FE_ATTRIBUTE_TYPECHECK(record);
931  return record.accessAttribute<T>(m_index);
932 }
933 
934 template <class T>
935 inline const T &AccessorReadOnly<T>::operator()(sp<RecordArraySB>& rspRA, FE_UWORD index) const
936 {
937  FE_ATTRIBUTE_CHECK((*rspRA));
938  return rspRA->accessAttribute<T>(m_index, index);
939 }
940 
941 template <class T>
942 inline bool AccessorReadOnly<T>::queryAttribute(const RecordSB& record, T *&data)
943 {
944  if(!check(record))
945  {
946  return false;
947  }
948  data = &(operator()(record));
949  return true;
950 }
951 
952 template <class T>
953 inline bool AccessorReadOnly<T>::queryAttribute(const WeakRecordSB record, T *&data)
954 {
955  if(!check(record))
956  {
957  return false;
958  }
959  data = &(operator()(record));
960  return true;
961 }
962 
963 template <class T>
964 inline const T AccessorReadOnly<T>::operator()(const RecordAV& record) const
965 {
966  FE_ATTRIBUTE_CHECK(record);
967  FE_ATTRIBUTE_TYPECHECK(record);
968  return record.accessAttribute<T>(m_index);
969 }
970 
971 
972 template <class T>
973 inline const T AccessorReadOnly<T>::operator()(const WeakRecordAV &record) const
974 {
975  FE_ATTRIBUTE_CHECK(record);
976  FE_ATTRIBUTE_TYPECHECK(record);
977  return record.accessAttribute<T>(m_index);
978 }
979 
980 template <class T>
981 inline bool AccessorReadOnly<T>::operator()(const RecordSB& record, T &data)
982 {
983  if(!check(record))
984  {
985  return false;
986  }
987  data = (operator()(record));
988  return true;
989 }
990 
991 template <class T>
992 inline bool AccessorReadOnly<T>::operator()(const WeakRecordSB& record, T &data)
993 {
994  if(!check(record))
995  {
996  return false;
997  }
998  data = (operator()(record));
999  return true;
1000 }
1001 
1002 
1003 template <class T>
1004 inline const T &AccessorReadOnly<T>::operator()(sp<RecordArrayAV>& rspRA, FE_UWORD index) const
1005 {
1006  FE_ATTRIBUTE_CHECK((*rspRA));
1007  return rspRA->accessAttribute<T>(m_index, index);
1008 }
1009 
1010 
1011 template <class T>
1012 inline bool AccessorReadOnly<T>::queryAttribute(const RecordAV& record, T *&data)
1013 {
1014  if(!check(record))
1015  {
1016  return false;
1017  }
1018  data = &(operator()(record));
1019  return true;
1020 }
1021 
1022 template <class T>
1023 inline bool AccessorReadOnly<T>::queryAttribute(const WeakRecordAV record, T *&data)
1024 {
1025  if(!check(record))
1026  {
1027  return false;
1028  }
1029  data = &(operator()(record));
1030  return true;
1031 }
1032 
1033 
1034 template <class T>
1035 inline void AccessorReadOnly<T>::registerDefault(T *pT)
1036 {
1037  m_pT = pT;
1038 }
1039 
1040 template <class T>
1041 class FE_DL_EXPORT AccessorW : public Accessor<T> { };
1042 
1043 template <class T>
1044 class FE_DL_EXPORT AccessorR : public AccessorReadOnly<T> { };
1045 
1046 } /* namespace */
1047 
1048 #endif /* __data_Accessor_h__ */
1049 
sp< Layout > layout(void)
Return the Layout.
Definition: RecordArraySB.h:221
Homogeneous collection of Records.
Definition: RecordArrayAV.h:32
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordAV.h:174
bool isValid(void) const
Return true if the Record points to a valid state block.
Definition: RecordSB.h:184
kernel
Definition: namespace.dox:3
bool queryAttribute(const RecordSB &r, T *&data)
Return true if the attribute exists in record.
Definition: Accessor.h:574
const sp< LayoutSB > & layout(void) const
Return the Layout.
Definition: WeakRecordSB.h:251
Generic exception carrying a fe::String payload.
Definition: Exception.h:34
The main data access class for the data system.
Definition: Accessor.h:128
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordSB.h:189
C++ type_info wrapper.
Definition: Type.h:20
void bind(const WeakRecord &a_record)
optionally bind to a record
Definition: Accessor.h:111
Type inspecific Accessor.
Definition: Accessor.h:26
Safe handle for shared pointer.
Definition: Handled.h:61
BWORD operator==(const DualString &s1, const DualString &s2)
Compare two DualString&#39;s.
Definition: DualString.h:208
Automatically reference-counted string container.
Definition: String.h:128
const sp< LayoutAV > & layout(void) const
Return the Layout.
Definition: WeakRecordAV.h:249
bool check(const RecordSB &r) const
Return true if record has attribute.
Definition: Accessor.h:314
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Reference to an instance of a Layout.
Definition: RecordAV.h:25
Record "type" definition.
Definition: LayoutSB.h:32
Layout namespace.
Definition: Scope.h:71
bool isValid(void) const
Return true if the Record points to a valid state block.
Definition: RecordAV.h:195
T & operator()(const RecordSB &r)
Return the attribute.
Definition: Accessor.h:489
Record "type" definition.
Definition: LayoutAV.h:30
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordAV.h:17
sp< Layout > layout(void)
Return the Layout.
Definition: RecordArrayAV.h:257
Homogeneous collection of Records.
Definition: RecordArraySB.h:40
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordSB.h:17