EventAnalysis  1.0.0
ObjectConsumer.h
Go to the documentation of this file.
1 /*
2  * ObjectConsumer.h
3  *
4  * Created on: 22 Oct 2019
5  * Author: Nicola Mori
6  */
9 #ifndef OBJECTCONSUMER_H_
10 #define OBJECTCONSUMER_H_
11 
12 #include "core/Exception.h"
13 #include "core/ObserverPtr.h"
14 #include "data/ObjectCategory.h"
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 namespace EA {
21 
28 public:
30  ObjectConsumer() : _repr{std::make_shared<Representation>()} {}
31 
36  struct ConsumedObject {
37  std::string name;
39  std::string store;
40  bool optional;
41 
50  : name(""), category(ObjectCategory::NONE), store(""), optional(false), _prevAlt(nullptr), _nextAlt(nullptr) {}
51 
56  std::vector<observer_ptr<ConsumedObject>> GetAlternatives() const;
57 
58  private:
59  friend class ObjectConsumer;
60  // Pointers to alternative objects (bidirectional linked list with nullptr at the extrema)
62  };
63 
76  void DeclareConsumedObject(std::string name, ObjectCategory category, std::string store, bool optional = false);
77 
110  void DeclareAlternative(const std::string &name, ObjectCategory category, std::string store,
111  const std::string &alternativeName, ObjectCategory alternativeCategory,
112  std::string alternativeStore);
113 
114  // In-class exceptions
116  class UndeclaredObject : public Exception {
117  using Exception::Exception;
118  };
119 
121  using ConsumedObjects = std::vector<ConsumedObject>;
122 
130  const ConsumedObjects &GetConsumedObjects() const { return _repr->objs; }
131 
132 protected:
134  friend class ObjectConsumer;
135 
136  public:
138  };
139 
140  ObjectConsumer(const std::shared_ptr<Representation> &impl) : _repr{impl} {}
141  std::shared_ptr<Representation> &GetRepresentation() { return _repr; }
142 
143 private:
144  std::shared_ptr<Representation> _repr;
145 };
146 
147 } // namespace EA
148 
149 #endif /* OBJECTCONSUMER_H_ */
bool optional
Definition: ObjectConsumer.h:40
observer_ptr< ConsumedObject > _prevAlt
Definition: ObjectConsumer.h:61
Definition: ObjectConsumer.h:133
ObjectConsumer()
Constructor.
Definition: ObjectConsumer.h:30
ConsumedObject()
Constructor.
Definition: ObjectConsumer.h:49
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
std::vector< ConsumedObject > ConsumedObjects
Type for container of produced objects.
Definition: ObjectConsumer.h:121
Exception(std::string msg="")
Definition: Exception.h:31
Exception class for using undeclared objects as parameters of DeclareAlternative. ...
Definition: ObjectConsumer.h:116
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
ConsumedObjects objs
Definition: ObjectConsumer.h:137
const ConsumedObjects & GetConsumedObjects() const
Getter method for consumed objects.
Definition: ObjectConsumer.h:130
std::string name
Definition: ObjectConsumer.h:37
std::string store
Definition: ObjectConsumer.h:39
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
void DeclareConsumedObject(std::string name, ObjectCategory category, std::string store, bool optional=false)
Declare a consumed objects.
Definition: ObjectConsumer.cpp:18
std::shared_ptr< Representation > & GetRepresentation()
Definition: ObjectConsumer.h:141
observer_ptr< ConsumedObject > _nextAlt
Definition: ObjectConsumer.h:61
std::shared_ptr< Representation > _repr
Definition: ObjectConsumer.h:144
std::vector< observer_ptr< ConsumedObject > > GetAlternatives() const
Definition: ObjectConsumer.cpp:82
Descriptor structure for a consumed object.
Definition: ObjectConsumer.h:36
ObjectCategory category
Definition: ObjectConsumer.h:38
void DeclareAlternative(const std::string &name, ObjectCategory category, std::string store, const std::string &alternativeName, ObjectCategory alternativeCategory, std::string alternativeStore)
Declares two already declared objects as alternatives.
Definition: ObjectConsumer.cpp:43
ObjectConsumer(const std::shared_ptr< Representation > &impl)
Definition: ObjectConsumer.h:140
Definition: Exception.h:24
Interface for a class which consumes data objects.
Definition: ObjectConsumer.h:27