EventAnalysis  1.0.0
ObjectProducer.h
Go to the documentation of this file.
1 /*
2  * ObjectProducer.h
3  *
4  * Created on: 22 Oct 2019
5  * Author: Nicola Mori
6  */
9 #ifndef OBJECTPRODUCER_H_
10 #define OBJECTPRODUCER_H_
11 
12 #include "core/Exception.h"
13 #include "data/ObjectCategory.h"
14 #include "utils/Memory.h"
15 
16 #include <memory>
17 #include <string>
18 
19 #include <vector>
20 
21 namespace EA {
22 
29 public:
32 
34  virtual ~ObjectProducer() {}
35 
40  struct ProducedObject {
41  std::string name;
43  std::string alias;
44  std::string store;
45  ProducedObject() : name{""}, category{ObjectCategory::NONE}, alias{""}, store{""} {}
46  ProducedObject(const std::string &objName, const ObjectCategory objCategory, const std::string &objAlias,
47  const std::string &objStore)
48  : name{objName}, category{objCategory}, alias{objAlias}, store{objStore} {}
49  bool operator==(const ProducedObject &rhs) const {
50  return (name == rhs.name) && (category == rhs.category) && (alias == rhs.alias) && (store == rhs.store);
51  }
52  };
53 
68  void DeclareProducedObject(std::string name, ObjectCategory category, std::string alias, std::string store);
69 
70  // In-class exceptions
72  class BadName : public Exception {
74  };
76  class BadCategory : public Exception {
78  };
80  class AlreadyDeclared : public Exception {
82  };
83 
85  using ProducedObjects = std::vector<ProducedObject>;
86 
94  const ProducedObjects &GetProducedObjects() const { return _repr->objs; }
95 
107  virtual std::vector<std::string> FreeObjects(const std::vector<std::string> &objs, Memory::Status memStatus);
108 
109 protected:
111  friend class ObjectProducer;
113  };
114 
115  ObjectProducer(const std::shared_ptr<Representation> &impl) : _repr{impl} {}
116  std::shared_ptr<Representation> &GetRepresentation() { return _repr; }
117 
118 private:
119  std::shared_ptr<Representation> _repr;
120 };
121 
122 } // namespace EA
123 
124 #endif /* OBJECTPRODUCER_H_ */
Exception class for bad object category.
Definition: ObjectProducer.h:76
const ProducedObjects & GetProducedObjects() const
Getter method for produced objects.
Definition: ObjectProducer.h:94
std::string store
Definition: ObjectProducer.h:44
Exception(std::string msg="")
Definition: Exception.h:31
bool operator==(const ProducedObject &rhs) const
Definition: ObjectProducer.h:49
virtual ~ObjectProducer()
Destructor.
Definition: ObjectProducer.h:34
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
Descriptor structure for a produced object.
Definition: ObjectProducer.h:40
std::vector< ProducedObject > ProducedObjects
Type for container of produced objects.
Definition: ObjectProducer.h:85
Exception class for already declared objects.
Definition: ObjectProducer.h:80
std::shared_ptr< Representation > & GetRepresentation()
Definition: ObjectProducer.h:116
ProducedObjects objs
Definition: ObjectProducer.h:112
Definition: ObjectProducer.h:110
ProducedObject(const std::string &objName, const ObjectCategory objCategory, const std::string &objAlias, const std::string &objStore)
Definition: ObjectProducer.h:46
ObjectProducer()
Constructor.
Definition: ObjectProducer.cpp:18
ObjectCategory category
Definition: ObjectProducer.h:42
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
std::string alias
Definition: ObjectProducer.h:43
Exception class for bad object name.
Definition: ObjectProducer.h:72
std::string name
Definition: ObjectProducer.h:41
Interface for a class which produced data objects.
Definition: ObjectProducer.h:28
Status
Aliases for memory occupation levels.
Definition: Memory.h:23
ProducedObject()
Definition: ObjectProducer.h:45
Definition: Exception.h:24
void DeclareProducedObject(std::string name, ObjectCategory category, std::string alias, std::string store)
Declare a produced objects.
Definition: ObjectProducer.cpp:20
virtual std::vector< std::string > FreeObjects(const std::vector< std::string > &objs, Memory::Status memStatus)
Free the memory for given objects.
Definition: ObjectProducer.cpp:45
ObjectProducer(const std::shared_ptr< Representation > &impl)
Definition: ObjectProducer.h:115
std::shared_ptr< Representation > _repr
Definition: ObjectProducer.h:119