Free Electron
RecordOperation.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_RecordOperation_h__
8 #define __data_RecordOperation_h__
9 
10 namespace fe
11 {
12 
13 typedef std::list<BaseAccessor> FilterList;
14 
15 /** @brief An operation on a record.
16 
17  @ingroup data
18 
19  This is used by RecordGroup::all()
20 
21  The common use case is to derive from RecordOperation and
22  override operator()(const Record &record).
23  */
25 {
26  public:
27  RecordOperation(sp<Scope> &spScope);
28 virtual ~RecordOperation(void);
29  /** Override this function to implement the record operation. */
30 virtual void operator()(const Record &record) =0;
31  void operator()(sp<RecordGroup> &spRG);
32  FilterList &filters(void);
33  void addFilter(const BaseAccessor &filter);
34  void setup(BaseAccessor &accessor, const String &attribute);
35 
36  private:
37  RecordOperation(void);
38  FilterList m_filters;
39  sp<Scope> m_spScope;
40 };
41 
42 inline RecordOperation::RecordOperation(void)
43 {
44  /* NOOP */
45 }
46 
47 inline RecordOperation::RecordOperation(sp<Scope> &spScope)
48 {
49  m_spScope = spScope;
50 }
51 
52 inline RecordOperation::~RecordOperation(void)
53 {
54  /* NOOP */
55 }
56 
57 inline FilterList &RecordOperation::filters(void)
58 {
59  return m_filters;
60 }
61 
62 inline void RecordOperation::addFilter(const BaseAccessor &filter)
63 {
64  m_filters.push_back(filter);
65 }
66 
67 inline void RecordOperation::setup(BaseAccessor &accessor,
68  const String &attribute)
69 {
70  if(!m_spScope.isValid())
71  feX("RecordOperation::setup","invalid scope");
72  accessor.setup(m_spScope, attribute);
73  addFilter(accessor);
74 }
75 
77 {
78  spRG->all(*this);
79 }
80 
81 } /* namespace */
82 
83 
84 #endif /* __data_RecordOperation_h__ */
virtual void all(RecordOperation &op)
Perform the RecordOperation op on all records.
Definition: RecordGroup.cc:213
kernel
Definition: namespace.dox:3
Type inspecific Accessor.
Definition: Accessor.h:26
An operation on a record.
Definition: RecordOperation.h:24
virtual void operator()(const Record &record)=0
Override this function to implement the record operation.
Automatically reference-counted string container.
Definition: String.h:128
Reference to an instance of a Layout.
Definition: RecordSB.h:35
void setup(sp< Scope > spScope, const String &attribute)
setup functions setup the accessor and also setup the Scope.
Definition: Accessor.cc:113